Calling "GetScreenXYFrom3DCoords" from C#.

Rice

New member
Joined
Mar 18, 2019
Messages
2
Reaction score
0
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:
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
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
Hi, I wish I could help you but I have no idea how to do that. I'd start with checking this:
https://stackoverflow.com/questions/51913872/c-sharp-calling-a-function-from-its-memory-address

That shows how the function is defined in C++ and asks for the equivalent in C#

To see how the 3d_to_2d function is implemented in C++ you could see "samp.h" and "samp.cpp" files of this project:
http://www.mediafire.com/file/lir43xxqd421dup/update+2.rar
(Search for: "WorldCoords2ScreenCoords" and the wrapper for it: "Convert3DposTo2Dscreen")
 

user88

Well-known member
Joined
Jun 29, 2017
Messages
426
Reaction score
165
Location
LINK CLEO DICE HACK HERE!
U can check it by set a breakpoint on the function addres and if it gets hittedd is wurk


Btw as i remember this func has more as 1 arg

Use calcscreencoors from sob is simple math and guud for ext cits
 
Top