-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5c47a6
commit 0242f32
Showing
4 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.3.32825.248 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleSpeedometer", "SimpleSpeedometer\SimpleSpeedometer.csproj", "{BF76E509-3DE2-494B-A5A4-F55046D00121}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{BF76E509-3DE2-494B-A5A4-F55046D00121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{BF76E509-3DE2-494B-A5A4-F55046D00121}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{BF76E509-3DE2-494B-A5A4-F55046D00121}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{BF76E509-3DE2-494B-A5A4-F55046D00121}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {53A09449-DF98-4CF7-A9C5-4C518132D8C3} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.IO; | ||
|
||
using IVSDKDotNet; | ||
using IVSDKDotNet.Direct3D9; | ||
using static IVSDKDotNet.Native.Natives; | ||
|
||
namespace SimpleSpeedometer { | ||
public class Main : Script { | ||
|
||
#region Variables | ||
private D3DGraphics gfx; | ||
private D3DResource digitsTexture; | ||
private D3DResource pinTexture; | ||
|
||
private bool allowDrawing, disableInMP, playerInCar; | ||
private int texturesAlpha; | ||
|
||
private bool useMPH, doFading; | ||
private string skin; | ||
private int fadingInSpeed, fadingOutSpeed; | ||
private float digitsAndPinSizeWidth, digitsAndPinSizeHeight; | ||
private float digitsAndPinOffsetX, digitsAndPinOffsetY; | ||
private float speed; | ||
#endregion | ||
|
||
#region Constructor | ||
public Main() | ||
{ | ||
Initialized += Main_Initialized; | ||
Tick += Main_Tick; | ||
} | ||
#endregion | ||
|
||
private void Main_Initialized(object sender, EventArgs e) | ||
{ | ||
// Create a new D3DGraphics object for this Script. | ||
gfx = new D3DGraphics(this); | ||
gfx.OnInit += Gfx_OnInit; | ||
gfx.OnDeviceEndScene += Gfx_OnDeviceEndScene; | ||
|
||
// Load settings file and get things from the settings file | ||
if (Settings.Load()) | ||
{ | ||
// Main | ||
useMPH = Settings.GetBoolean("Main", "UseMPH", true); | ||
disableInMP = Settings.GetBoolean("Main", "DisableInMP", false); | ||
|
||
// Style | ||
skin = Settings.GetValue("Style", "Skin", "Default"); | ||
doFading = Settings.GetBoolean("Style", "DoFading", true); | ||
fadingInSpeed = Settings.GetInteger("Style", "FadingInSpeed", 4); | ||
fadingOutSpeed = Settings.GetInteger("Style", "FadingOutSpeed", 6); | ||
|
||
// Size | ||
digitsAndPinSizeWidth = Settings.GetFloat("Size", "DigitsAndPinSizeWidth", 128f); | ||
digitsAndPinSizeHeight = Settings.GetFloat("Size", "DigitsAndPinSizeHeight", 128f); | ||
|
||
// Offset | ||
digitsAndPinOffsetX = Settings.GetFloat("Offset", "DigitsAndPinOffsetX", 64f); | ||
digitsAndPinOffsetY = Settings.GetFloat("Offset", "DigitsAndPinOffsetY", 64f); | ||
} | ||
} | ||
|
||
private void Gfx_OnInit(IntPtr device) | ||
{ | ||
string digitsFilePath = string.Format("{0}\\{1}\\digits.png", ScriptResourceFolder, skin); | ||
string pinFilePath = string.Format("{0}\\{1}\\pin.png", ScriptResourceFolder, skin); | ||
|
||
// Check if both files exists | ||
if (!File.Exists(digitsFilePath) || !File.Exists(pinFilePath)) | ||
{ | ||
CGame.Console.PrintWarning(string.Format("[SimpleSpeedometer] Please make sure that 'digits.png' and 'pin.png' exists in the SimpleSpeedometer\\{0} folder. Mod will be aborted.", skin)); | ||
Abort(); | ||
return; | ||
} | ||
|
||
// Create digits texture | ||
D3DResult r = gfx.CreateD3D9Texture(device, digitsFilePath); | ||
if (r.Error != null) | ||
{ | ||
CGame.Console.PrintError(string.Format("[SimpleSpeedometer] An error occured while trying to create 'digits' texture! Details: {0}", r.Error.ToString())); | ||
} | ||
else | ||
{ | ||
digitsTexture = r.DXObject as D3DResource; | ||
} | ||
|
||
// Create pin texture | ||
r = gfx.CreateD3D9Texture(device, pinFilePath); | ||
if (r.Error != null) | ||
{ | ||
CGame.Console.PrintError(string.Format("[SimpleSpeedometer] An error occured while trying to create 'pin' texture! Details: {0}", r.Error.ToString())); | ||
} | ||
else | ||
{ | ||
pinTexture = r.DXObject as D3DResource; | ||
} | ||
} | ||
private void Gfx_OnDeviceEndScene(IntPtr device) | ||
{ | ||
// If drawing is not allowed then return out of this method. | ||
if (!allowDrawing) | ||
return; | ||
// If radar is off then return out if this method. | ||
if (CMenuManager.Display.RadarMode == 0) | ||
return; | ||
|
||
// Get rotation value for the pin based on the current vehicle speed | ||
float rot = speed * ((float)Math.PI / 112.5f); | ||
|
||
// Gets the radar rectangle | ||
RectangleF rect = CGame.GetRadarRectangle(); | ||
|
||
// Fading | ||
if (IS_PAUSE_MENU_ACTIVE()) | ||
{ | ||
// Force fade textures out for pause menu | ||
if (doFading) | ||
{ | ||
if (!(texturesAlpha <= 0)) | ||
texturesAlpha -= fadingOutSpeed; | ||
if (texturesAlpha < 0) | ||
texturesAlpha = 0; | ||
} | ||
else | ||
{ | ||
texturesAlpha = 0; | ||
} | ||
} | ||
else | ||
{ | ||
// Fade textures in only if player is in car | ||
if (playerInCar) | ||
{ | ||
if (doFading) | ||
{ | ||
if (!(texturesAlpha >= 255)) | ||
texturesAlpha += fadingInSpeed; | ||
if (texturesAlpha > 255) | ||
texturesAlpha = 255; | ||
} | ||
else | ||
{ | ||
texturesAlpha = 255; | ||
} | ||
} | ||
} | ||
|
||
// Draw digits and pin | ||
if (!(texturesAlpha <= 0)) | ||
{ | ||
gfx.DrawTexture(device, digitsTexture, new RectangleF(rect.X - digitsAndPinOffsetX, rect.Y - digitsAndPinOffsetY, rect.Width + digitsAndPinSizeWidth, rect.Height + digitsAndPinSizeHeight), Color.FromArgb(texturesAlpha, Color.White)); | ||
gfx.DrawTexture(device, pinTexture, new RectangleF(rect.X - digitsAndPinOffsetX, rect.Y - digitsAndPinOffsetY, rect.Width + digitsAndPinSizeWidth, rect.Height + digitsAndPinSizeHeight), rot, Color.FromArgb(texturesAlpha, Color.White)); | ||
} | ||
} | ||
|
||
private void Main_Tick(object sender, EventArgs e) | ||
{ | ||
// If is mp session then reset stuff and return | ||
if (IS_NETWORK_SESSION() && disableInMP) | ||
{ | ||
allowDrawing = false; | ||
return; | ||
} | ||
|
||
// Get current vehicle of player | ||
CVehicle veh = CPed.FromPointer(CPlayerInfo.FindPlayerPed()).GetVehicle(); | ||
if (veh != null) | ||
{ | ||
// Get the vehicle handle of the current vehicle the player is in | ||
uint handle = CPools.GetVehiclePool().GetIndex(veh.GetUIntPtr()); | ||
|
||
// Get the speed of the vehicle | ||
GET_CAR_SPEED((int)handle, out speed); | ||
|
||
// Convert speed to MPH/KMH based on the ini setting | ||
speed = speed * (useMPH ? 2.3f : 3.6f); | ||
|
||
// Allow drawing the digits and pin textures | ||
allowDrawing = true; | ||
playerInCar = true; | ||
} | ||
else | ||
{ | ||
// Set player is not in car anymore | ||
playerInCar = false; | ||
|
||
// Force fade textures out | ||
if (!(texturesAlpha <= 0)) | ||
{ | ||
if (doFading) | ||
texturesAlpha -= fadingOutSpeed; | ||
else | ||
texturesAlpha = 0; | ||
} | ||
else | ||
{ | ||
// Set variable to 0 just in case it is below 0 | ||
texturesAlpha = 0; | ||
|
||
// Set the speed to 0 if the player is not currently in a vehicle | ||
speed = 0f; | ||
|
||
// Do not allow drawing when player is not in a vehicle | ||
allowDrawing = false; | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
SimpleSpeedometer/SimpleSpeedometer/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("SimpleSpeedometer")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("ItsClonkAndre")] | ||
[assembly: AssemblyProduct("SimpleSpeedometer")] | ||
[assembly: AssemblyCopyright("Copyright © ItsClonkAndre 2023")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(true)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("bf76e509-3de2-494b-a5a4-f55046d00121")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
47 changes: 47 additions & 0 deletions
47
SimpleSpeedometer/SimpleSpeedometer/SimpleSpeedometer.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{BF76E509-3DE2-494B-A5A4-F55046D00121}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>SimpleSpeedometer</RootNamespace> | ||
<AssemblyName>SimpleSpeedometer.ivsdk</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="IVSDKDotNetWrapper"> | ||
<HintPath>..\..\..\IVSDKDotNet\Release\IVSDKDotNetWrapper.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Numerics" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Main.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |