Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
kagikn committed Dec 22, 2017
2 parents 884569b + 4dca9d9 commit fd3a237
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
21 changes: 7 additions & 14 deletions StuntBonusV/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,11 @@ internal static class VehicleExtensions

static VehicleExtensions()
{
_WheelPtrCollectionOffset = GetWheelPtrCollectionOffset();
_WheelCountOffset = _WheelPtrCollectionOffset + 0x8;

int GetWheelPtrCollectionOffset()
unsafe
{
var offset = (Game.Version >= GameVersion.VER_1_0_372_2_STEAM ? 0xAA0 : 0xA80);
offset = (Game.Version >= GameVersion.VER_1_0_505_2_STEAM ? 0xA90 : offset);
offset = (Game.Version >= GameVersion.VER_1_0_791_2_STEAM ? 0xAB0 : offset);
offset = (Game.Version >= GameVersion.VER_1_0_877_1_STEAM ? 0xAE0 : offset);
offset = (Game.Version >= GameVersion.VER_1_0_944_2_STEAM ? 0xB10 : offset);
offset = (Game.Version >= GameVersion.VER_1_0_1103_2_STEAM ? 0xB20 : offset);
offset = (Game.Version >= GameVersion.VER_1_0_1180_2_STEAM ? 0xB40 : offset);

return offset;
var addr = MemoryAccess.FindPattern("\x3B\xB7\x48\x0B\x00\x00\x7D\x0D", "xx????xx");
_WheelPtrCollectionOffset = *(int*)(addr + 2) - 8;
_WheelCountOffset = *(int*)(addr + 2);
}
}

Expand Down Expand Up @@ -274,7 +265,9 @@ internal static bool IsWheelTouching(IntPtr wheelAddress)

unsafe
{
return (*((byte*)wheelAddress.ToPointer() + 0x1EC) & 0x1) != 0;
var offset = Game.Version >= GameVersion.VER_1_0_372_2_STEAM ? 0x1EC : 0x1DC;
offset = Game.Version >= GameVersion.VER_1_0_1290_1_STEAM ? 0x1E4 : offset;
return (*((byte*)wheelAddress.ToPointer() + offset) & 0x1) != 0;
}
}

Expand Down
37 changes: 37 additions & 0 deletions StuntBonusV/MemoryAccess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StuntBonusV
{
static internal class MemoryAccess
{
public unsafe static byte* FindPattern(string pattern, string mask)
{
ProcessModule module = Process.GetCurrentProcess().MainModule;

ulong address = (ulong)module.BaseAddress.ToInt64();
ulong endAddress = address + (ulong)module.ModuleMemorySize;

for (; address < endAddress; address++)
{
for (int i = 0; i < pattern.Length; i++)
{
if (mask[i] != '?' && ((byte*)address)[i] != pattern[i])
{
break;
}
else if (i + 1 == pattern.Length)
{
return (byte*)address;
}
}
}

return null;
}
}
}
1 change: 1 addition & 0 deletions StuntBonusV/StuntBonusV.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions.cs" />
<Compile Include="MemoryAccess.cs" />
<Compile Include="Setting\Setting.cs" />
<Compile Include="Setting\SettingLoader.cs" />
<Compile Include="StuntBonusMonitor\InsaneStuntBonus.cs" />
Expand Down

0 comments on commit fd3a237

Please sign in to comment.