[英]Return function int64 C++ to a C# project
i write a dll that is injected on game and return my localplayer and listArrayplayer on server. 我写了一个注入游戏的dll,并在服务器上返回了我的localplayer和listArrayplayer。 Ok work fine code dll project: C++ code:
好的工作良好的代码dll项目:C ++代码:
__int64 RerturnLocalPlayer() {
__int64 player = GetLocalPlayer_EX();// __Int64 GetLocalPlayer_EX() is a function that return type __int64 value
return player;
}
in main.h: 在main.h中:
extern "C" {
__declspec(dllexport) __int64 RerturnLocalPlayer();
} }
mt function mt功能
extern "C" {
__declspec(dllexport) __int64 GetLocalPlayer_EX()
{
DWORD64 pClientGameContext = *(DWORD64*)OFFSET_CLIENTGAMECONTEXT;
if (!(pClientGameContext)) return 0;
DWORD64 pPlayerManager = *(DWORD64*)(pClientGameContext + 0x68);
if (!(pPlayerManager)) return 0;
DWORD64 pObfuscationMgr = *(DWORD64*)OFFSET_ObfuscationMgr;
if (!(pObfuscationMgr)) return 0;
DWORD64 LocalPlayerListXorValue = *(DWORD64*)((DWORD64)pPlayerManager + 0xF0);
DWORD64 LocalPlayerListKey = LocalPlayerListXorValue ^ *(DWORD64 *)(pObfuscationMgr + 0x70);
hashtable<DWORD64>* table = (hashtable<DWORD64>*)(pObfuscationMgr + 8);
hashtable_iterator<DWORD64> iterator = { 0 };
hashtable_find(table, &iterator, LocalPlayerListKey);
if (iterator.mpNode == table->mpBucketArray[table->mnBucketCount])
return 0;
DWORD64 EncryptedPlayerMgr = (DWORD64)iterator.mpNode->mValue.second;
if (!(EncryptedPlayerMgr)) return 0;
DWORD MaxPlayerCount = *(DWORD *)(EncryptedPlayerMgr + 0x18);
if (MaxPlayerCount != 1) return 0;
return EncryptedPlayerMgr__GetPlayer(EncryptedPlayerMgr, 0);
}
}
C# Code: C#代码:
[System.Runtime.InteropServices.DllImportAttribute("BFClient1.dll", EntryPoint = "RerturnLocalPlayer",
CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern Int64 RerturnLocalPlayer();
Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
Console.WriteLine("LocalPlayer " + localp.ToString("X"));
the problem is when i run my c# application my console open and after 3 seconds close and sometimes get error: **Attempt to read or write to protected memory. 问题是当我运行我的C#应用程序时,我的控制台打开,并且在3秒钟后关闭,有时会出现错误:**尝试读取或写入受保护的内存。 Usually, this is an indication that another memory is damaged.
通常,这表明另一个内存已损坏。
can some one try help me? 有人可以帮我吗?
__int64 RerturnLocalPlayer()
is a function that returns a 64-bit value through some calling convention. __int64 RerturnLocalPlayer()
是一个通过某些调用约定返回64位值的函数。 You seem to think it's stdcall
, I think you're wrong. 您似乎认为这是
stdcall
,我认为您错了。 However I don't have your source code so you can bang your head against that wall on your own. 但是,我没有您的源代码,因此您可以自己动脑子。
public static extern Int64 RerturnLocalPlayer();
is the right definition (again, calling convention aside, there's no 64-bit register on the 32-bit CPU, so it won't be stdcall
). 是正确的定义(再次,调用约定,在32位CPU上没有64位寄存器,因此不会是
stdcall
)。
However, Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
但是,
Int64 localp = NativeMemory.Read<Int64> (RerturnLocalPlayer());
is just plain bonkers. 简直就是傻瓜。 You're already getting your integer straight from the marshaller as a return value, use it as such!
您已经从marshaller中直接获取了整数作为返回值,就这样使用它! This would be the correct way of calling your function:
这将是调用函数的正确方法:
Int64 localp = RerturnLocalPlayer();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.