LunaHook-mirror/LunaHook/engines/mono/monoil2cpp.hpp
恍兮惚兮 eed557375f mono
2024-05-09 15:06:36 +08:00

42 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include"def_mono.hpp"
#include"def_il2cpp.hpp"
inline void commonsolvemonostring(uintptr_t offset,uintptr_t *data, size_t*len){
MonoString* string = (MonoString*)offset;
if(string==0)return;
*data = (uintptr_t)string->chars;
if(wcslen((wchar_t*)string->chars)!=string->length)return;
*len = string->length * 2;
}
inline void unity_ui_string_hook_after(uintptr_t *offset,void* data, size_t len)
{
MonoString* string = (MonoString*)*offset;
if(string==0)return;
if(wcslen((wchar_t*)string->chars)!=string->length)return;
//其实也可以直接覆写到原来的String上但重新创建一个是更安全的操作。
auto newstring=(MonoString*)malloc(sizeof(MonoString)+len+2);
memcpy(newstring,string,sizeof(MonoString));
wcscpy((wchar_t*)newstring->chars,(wchar_t*)data);
newstring->length=len/2;
*offset=(uintptr_t)newstring;
}
namespace il2cpp_symbols
{
void init(HMODULE game_module);
uintptr_t get_method_pointer(const char* assemblyName, const char* namespaze,
const char* klassName, const char* name, int argsCount);
}
void load_mono_functions_from_dll(HMODULE dll);
uintptr_t getmonofunctionptr(const char *_dll, const char *_namespace, const char *_class, const char *_method, int paramCount);
inline uintptr_t tryfindmonoil2cpp(const char *_dll, const char *_namespace, const char *_class, const char *_method, int paramCoun){
auto addr=il2cpp_symbols::get_method_pointer(_dll,_namespace,_class,_method,paramCoun);
if(addr)return addr;
return getmonofunctionptr(_dll,_namespace,_class,_method,paramCoun);
}