I'd like to call the function "GetScreenXYFrom3DCoords" from an external C# program. I've been unable to figure that out for quite a while and decided to finally ask here. The game crashes, which is not the result I expect.
My progress:
I'm usually a shy person, so this is WAY out of my comfort zone, which I hope you understand. Thanks for helping me out in advance. <3
My progress:
C#:
public unsafe struct Vector
{
public fixed float position[3];
public Vector(float X, float Y, float Z)
{
position[0] = X;
position[1] = Y;
position[2] = Z;
}
};
public unsafe struct getScreenXYArgs
{
public unsafe Vector* InPoint;
public unsafe Vector* OutPoint;
public unsafe float* X;
public unsafe float* Y;
public unsafe char* UnUsed;
public unsafe char* UnUsed2;
}
public static void CallGetScreenXYFrom3DCoords(Util.getScreenXYArgs parameters)
{
List<byte> data = new List<byte>();
IntPtr memoryAddress = new IntPtr(Convert.ToInt32(BitConverter.ToInt32(Util.getScreenXYgetBytes(parameters), 0)));
data.Add(0x68);
data.AddRange(BitConverter.GetBytes((uint)memoryAddress));
data.Add(0xE8);
int offset = (int)0x70CE30 - ((int)memory[memory.Length - 1] + (6)*5+5 ); // Im suspecious of this line (0x70CE30 being the function address)
data.AddRange(BitConverter.GetBytes(offset));
data.Add(0xC3);
data.AddRange(new byte[] { 0x83, 0xC4 }); // Im suspecious of this line
data.Add(Convert.ToByte((6) * 4)); // Im suspecious of this line
if (!WriteMemoryBytes(memory[memory.Length - 1], data.ToArray()))
{
throw new Exception();
}
IntPtr thread = CreateRemoteThread(handle, IntPtr.Zero, 0, (uint)memory[memory.Length - 1], IntPtr.Zero, 0, IntPtr.Zero);
WaitForSingleObject(thread, 0xFFFFFFFF);
return;
}
public static bool WriteMemoryBytes(IntPtr address, byte[] bytes)
{
uint written = 0;
if (WriteProcessMemory(handle, address, bytes, (uint)bytes.Length, ref written))
{
if (written == bytes.Length)
{
return true;
}
}
return false;
}
I'm usually a shy person, so this is WAY out of my comfort zone, which I hope you understand. Thanks for helping me out in advance. <3