Skip to content

Commit

Permalink
Get direct pickup address instead of its handle
Browse files Browse the repository at this point in the history
  • Loading branch information
kagikn committed Mar 29, 2018
1 parent b01e118 commit 1994927
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 22 deletions.
46 changes: 43 additions & 3 deletions GlowingPickups/GlowingPickups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,55 @@ private void OnTick(object o, EventArgs e)

var offset = (int)Game.Version >= (int)GameVersion.VER_1_0_944_2_STEAM ? 0x480 : 0x470;

var pickupProps = PickupObjectPoolTask.GetPickupObjects();

var pickupAddresses = PickupObjectPoolTask.GetPickupObjectAddresses();
foreach (var pickupAddr in pickupAddresses)
{
unsafe
{
var isVisible = (Marshal.ReadByte(pickupAddr, 0x2C) & 0x01) == 1;

if (!isVisible)
{
continue;
}

var pos = *(Vector3*)(pickupAddr + 0x90);
var dataAddress = Marshal.ReadIntPtr(pickupAddr, offset);

if (dataAddress != IntPtr.Zero)
{
var red = (int)(BitConverter.ToSingle(
BitConverter.GetBytes(Marshal.ReadInt32(dataAddress, 0x5C)), 0) * 255);
var green = (int)(BitConverter.ToSingle(
BitConverter.GetBytes(Marshal.ReadInt32(dataAddress, 0x60)), 0) * 255);
var blue = (int)(BitConverter.ToSingle(
BitConverter.GetBytes(Marshal.ReadInt32(dataAddress, 0x64)), 0) * 255);
var range = BitConverter.ToSingle(
BitConverter.GetBytes(Marshal.ReadInt32(dataAddress, 0x10)), 0) * settings.RangeMultiplier;
var intensity = BitConverter.ToSingle(
BitConverter.GetBytes(Marshal.ReadInt32(dataAddress, 0x68)), 0) * settings.LightIntensityMultiplier;
var darkIntensity = BitConverter.ToSingle(
BitConverter.GetBytes(Marshal.ReadInt32(dataAddress, 0x6C)), 0) * settings.ShadowMultiplier;
Function.Call(Hash._DRAW_LIGHT_WITH_RANGE_WITH_SHADOW, pos.X, pos.Y, pos.Z, red,
green, blue, range, intensity, darkIntensity);
}
else
{
Function.Call(Hash._DRAW_LIGHT_WITH_RANGE_WITH_SHADOW, pos.X, pos.Y, pos.Z, 255, 57, 0, 5.0f, 30.0f, 10.0f);
}
}
}

//This is unstable
/*var pickupProps = PickupObjectPoolTask.GetPickupObjects();
foreach (var pickup in pickupProps)
{
unsafe
{
var dataAddress = Marshal.ReadIntPtr(new IntPtr(pickup.MemoryAddress), offset);
if (dataAddress != IntPtr.Zero)
{
//Color glowingColor;
var pos = pickup.Position;
var red = (int)(BitConverter.ToSingle(
BitConverter.GetBytes(Marshal.ReadInt32(dataAddress, 0x5C)), 0) * 255);
Expand All @@ -69,7 +109,7 @@ private void OnTick(object o, EventArgs e)
Function.Call(Hash._DRAW_LIGHT_WITH_RANGE_WITH_SHADOW, pos.X, pos.Y, pos.Z, 255, 57, 0, 5.0f, 30.0f, 10.0f);
}
}
}
}*/
}
}
}
68 changes: 49 additions & 19 deletions GlowingPickups/MemoryAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ static internal class MemoryAccess
}

[StructLayout(LayoutKind.Explicit)]
public struct EntityPool
internal struct EntityPool
{
[FieldOffset(0x10)] UInt32 num1;
[FieldOffset(0x20)] UInt32 num2;
[FieldOffset(0x10)]
internal uint num1;
[FieldOffset(0x20)]
internal uint num2;

public bool IsFull()
internal bool IsFull()
{
return num1 - (num2 & 0x3FFFFFFF) <= 256;
}
}

[StructLayout(LayoutKind.Explicit)]
public unsafe struct GenericPool
internal unsafe struct GenericPool
{
[FieldOffset(0x00)]
public ulong poolStartAddress;
Expand Down Expand Up @@ -83,8 +85,8 @@ private ulong Mask(uint index)
unsafe public static class PickupObjectPoolTask
{
//static public IntPtr _AddEntityToPoolFuncAddress;
static public IntPtr _EntityPoolAddress;
static public IntPtr _PickupObjectPoolAddress;
static public ulong* _EntityPoolAddress;
static public ulong* _PickupObjectPoolAddress;
internal delegate int AddEntityToPoolFunc(ulong address); //returns an entity handle
static internal AddEntityToPoolFunc _addEntToPoolFunc;

Expand All @@ -97,19 +99,16 @@ static public void Init()
FindAddEntityToPoolFuncAddress();
}

static public List<Prop> GetPickupObjects()
//This is unstable and can easily crash the game
/*static public List<Prop> GetPickupObjects()
{
//FindEntityPoolAddress();
//FindPickupPoolAddress();
//FindAddEntityToPoolFuncAddress();

if (**(ulong**)_EntityPoolAddress.ToPointer() == 0 || *(ulong*)_PickupObjectPoolAddress.ToPointer() == 0)
if (*_EntityPoolAddress == 0 || *_PickupObjectPoolAddress == 0)
{
return new List<Prop>();
}
GenericPool* pickupPool = (GenericPool*)(*(ulong*)_PickupObjectPoolAddress.ToPointer());
EntityPool* entitiesPool = (EntityPool*)(*(ulong*)_EntityPoolAddress.ToPointer());
GenericPool* pickupPool = (GenericPool*)(*_PickupObjectPoolAddress);
EntityPool* entitiesPool = (EntityPool*)(*_EntityPoolAddress);
List<Prop> pickupHandles = new List<Prop>();
Expand All @@ -127,24 +126,55 @@ static public List<Prop> GetPickupObjects()
if (address != 0)
{
int handle;
handle = _addEntToPoolFunc(address);
int handle = _addEntToPoolFunc(address);
pickupHandles.Add(new Prop(handle));
}
}
}
return pickupHandles;
}*/

static public List<IntPtr> GetPickupObjectAddresses()
{
if (*_EntityPoolAddress == 0 || *_PickupObjectPoolAddress == 0)
{
return new List<IntPtr>();
}

GenericPool* pickupPool = (GenericPool*)(*_PickupObjectPoolAddress);
EntityPool* entitiesPool = (EntityPool*)(*_EntityPoolAddress);

List<IntPtr> pickupsAddresses = new List<IntPtr>();

for (uint i = 0; i < pickupPool->size; i++)
{
if (entitiesPool->IsFull())
{
break;
}

if (pickupPool->IsValid(i))
{
ulong address = pickupPool->GetAddress(i);

if (address != 0)
{
pickupsAddresses.Add(new IntPtr((long)address));
}
}
}
return pickupsAddresses;
}

static public void FindEntityPoolAddress()
{
var address = MemoryAccess.FindPattern("\x4C\x8B\x0D\x00\x00\x00\x00\x44\x8B\xC1\x49\x8B\x41\x08", "xxx????xxxxxxx");
_EntityPoolAddress = new IntPtr(*(int*)(address + 3) + address + 7);
_EntityPoolAddress = (ulong*)(*(int*)(address + 3) + address + 7);
}
static public void FindPickupPoolAddress()
{
var address = MemoryAccess.FindPattern("\x4C\x8B\x05\x00\x00\x00\x00\x40\x8A\xF2\x8B\xE9", "xxx????xxxxx");
_PickupObjectPoolAddress = new IntPtr((*(int*)(address + 3) + address + 7));
_PickupObjectPoolAddress = (ulong*)(*(int*)(address + 3) + address + 7);
}
static public void FindAddEntityToPoolFuncAddress()
{
Expand Down

0 comments on commit 1994927

Please sign in to comment.