Hey I am trying to convert old C++ code to C# and I got most of it working already but I am stuck on one error now.
The Code in C++ looks like this:
ReadProcessMemory
(
_In_ HANDLE hProcess,
_In_ LPCVOID lpBaseAddress,
_Out_writes_bytes_to_(nSize,*lpNumberOfBytesRead) LPVOID lpBuffer,
_In_ SIZE_T nSize,
_Out_opt_ SIZE_T* lpNumberOfBytesRead
);
void GetSpawnPosition(GameInfo gInfo, GameVector &vecInfo)
{
if (!ReadProcessMemory(gInfo.hProc, (LPVOID)(gInfo.dwUnityPlayer + Offset::m_vecSpawn), &vecInfo, sizeof(GameVector), 0))
{
wprintf(L"Couldnt read cords!\n");
break;
}
}
So I tried the following Conversion to C#:
[DllImport("kernel32.dll")]
static extern bool ReadProcessMemory
(
IntPtr hProcess,
IntPtr lpBaseAddress,
[Out] byte[] lpBuffer,
int nSize,
out IntPtr lpNumberOfBytesRead
);
private unsafe void GetSpawnPosition(GameInfo gInfo, GameVector vecInfo)
{
if (!ReadProcessMemory(gInfo.hProc, (IntPtr)(gInfo.dwUnityPlayer + m_vecSpawn), vecInfo, sizeof(GameVector), IntPtr.Zero))
{
Console.Write("Couldnt read spawn cords!\n");
break;
}
}
Everything works except the "vecInfo" in the ReadProcess Function. It always gives me the error message Conversion of "GameVector" to "byte[]" not possible. So how do I fix that or convert it to byte[]?
In case you need the struct of "GameVector" to help me out (C++):
struct GameVector
{
float x, z, y;
GameVector operator +(GameVector &vSome)
{
return { this->x + vSome.x, vSome.z, this->y + vSome.y };
}
GameVector operator -(GameVector& vSome)
{
return { this->x - vSome.x, this->z, this->y - vSome.y };
}
};
I converted it to C# like this (should be fine ig):
struct GameVector
{
float x, z, y;
public static GameVector operator +(GameVector ImpliedObject, GameVector vSome)
{
return new GameVector() { x = ImpliedObject.x + vSome.x, z = vSome.z, y = ImpliedObject.y + vSome.y };
}
public static GameVector operator -(GameVector ImpliedObject, GameVector vSome)
{
return new GameVector() { x = ImpliedObject.x - vSome.x, z = ImpliedObject.z, y = ImpliedObject.y - vSome.y };
}
}
I know it looks like a lot of code but its only the single "vecInfo" that gives me my last eror that I have to fix now. I'm sorry if thats too much to ask for here but would be awesome if someone could help me out since it is literally the last issue rn.