Cube-World-Mod-Launcher/CubeModLoader/callbacks/P2PRequestHandler.h

63 lines
1.5 KiB
C
Raw Normal View History

2019-10-25 06:07:08 +08:00
extern "C" int P2PRequestHandler(long long steamID) {
2019-10-06 03:59:20 +08:00
for (DLL* dll: modDLLs) {
if (dll->HandleP2PRequest) {
if ( int result = ((int(*)(long long))dll->HandleP2PRequest)(steamID) ){
return result;
}
}
}
return 0;
}
2019-10-25 06:07:08 +08:00
GETTER_VAR(void*, ASMP2PRequestHandler_jmpback);
GETTER_VAR(void*, ASMP2PRequestHandler_block);
GETTER_VAR(void*, ASMP2PRequestHandler_allow);
void ASMP2PRequestHandler() {
asm(".intel_syntax \n"
PUSH_ALL
2019-10-06 03:59:20 +08:00
"mov rcx, [rdi] \n" //incoming steam id
PREPARE_STACK
2019-10-25 06:07:08 +08:00
"call P2PRequestHandler \n"
2019-10-06 03:59:20 +08:00
RESTORE_STACK
// Did the handler return 1? block
"cmp eax, 1 \n"
"je 1f \n"
// Did the handler return 2? allow
"cmp eax, 2 \n"
"je 2f \n"
// Otherwise? Do nothing
POP_ALL
// original code
"mov edx, 4 \n"
"mov rcx, [rax] \n"
"mov rax, [rcx] \n"
"call qword ptr [rax+0x18] \n"
2019-10-25 06:07:08 +08:00
DEREF_JMP(ASMP2PRequestHandler_jmpback)
2019-10-06 03:59:20 +08:00
"1: \n" //block
POP_ALL
2019-10-25 06:07:08 +08:00
DEREF_JMP(ASMP2PRequestHandler_block)
2019-10-06 03:59:20 +08:00
"2: \n" //allow
POP_ALL
2019-10-25 06:07:08 +08:00
DEREF_JMP(ASMP2PRequestHandler_allow)
2019-10-06 03:59:20 +08:00
);
}
void SetupP2PRequestHandler() {
2019-10-25 06:07:08 +08:00
WriteFarJMP(Offset(base, 0x9F6DF), (void*)&ASMP2PRequestHandler);
ASMP2PRequestHandler_jmpback = Offset(base, 0x9F6ED);
ASMP2PRequestHandler_block = Offset(base, 0x9F7A6);
ASMP2PRequestHandler_allow = Offset(base, 0x9F783);
2019-10-06 03:59:20 +08:00
}