Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// h
- void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
- {
- BYTE *jmp = (BYTE*)malloc(len+5);
- DWORD dwback;
- VirtualProtect(src, len, PAGE_READWRITE, &dwback);
- memcpy(jmp, src, len); jmp += len;
- jmp[0] = 0xE9;
- *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
- src[0] = 0xE9;
- *(DWORD*)(src+1) = (DWORD)(dst-src) - 5;
- VirtualProtect(src, len, dwback, &dwback);
- return (jmp-len);
- }
- //// cpp
- typedef pub::AI::OP_RTYPE(__cdecl *pub__AI__SubmitDirective_t)(unsigned int spaceobj, pub::AI::BaseOp* op);
- pub__AI__SubmitDirective_t real_pub__AI__SubmitDirective = NULL;
- void testOp(uint spaceobj, pub::AI::BaseOp* op, bool directive)
- {
- AddLog("AI Op for ship %u (%s): %s", spaceobj, directive ? "directive" : "state", typeid(*op).name());
- pub::AI::DirectiveTrailOp* top = dynamic_cast<pub::AI::DirectiveTrailOp*>(op);
- if (top)
- {
- int x = 0;
- }
- pub::AI::DirectiveDelayOp* dop = dynamic_cast<pub::AI::DirectiveDelayOp*>(op);
- if (dop)
- {
- int x = 0;
- }
- pub::AI::DirectiveInstantTradelaneOp* itop = dynamic_cast<pub::AI::DirectiveInstantTradelaneOp*>(op);
- if (itop)
- {
- int x = 0;
- }
- pub::AI::DirectiveLaunchOp* lop = dynamic_cast<pub::AI::DirectiveLaunchOp*>(op);
- if (lop)
- {
- int x = 0;
- }
- }
- pub::AI::OP_RTYPE pub__AI__SubmitDirective(unsigned int spaceobj, pub::AI::BaseOp* op)
- {
- testOp(spaceobj, op, true);
- return real_pub__AI__SubmitDirective(spaceobj, op);
- }
- typedef pub::AI::OP_RTYPE(__cdecl *pub__AI__SubmitState_t)(unsigned int spaceobj, pub::AI::BaseOp* op);
- pub__AI__SubmitState_t real_pub__AI__SubmitState = NULL;
- pub::AI::OP_RTYPE pub__AI__SubmitState(unsigned int spaceobj, pub::AI::BaseOp* op)
- {
- testOp(spaceobj, op, false);
- return real_pub__AI__SubmitState(spaceobj, op);
- }
- void Init()
- {
- static bool loaded = false;
- if (!loaded)
- {
- loaded = true;
- DWORD baseadr = (DWORD)GetProcAddress(GetModuleHandle("server.dll"), "?SubmitDirective@AI@pub@@YA?AW4OP_RTYPE@12@IPAVBaseOp@12@@Z");
- real_pub__AI__SubmitDirective = (pub__AI__SubmitDirective_t)DetourFunc((BYTE*)baseadr, (BYTE*)pub__AI__SubmitDirective, 7);
- baseadr = (DWORD)GetProcAddress(GetModuleHandle("server.dll"), "?SubmitState@AI@pub@@YA?AW4OP_RTYPE@12@IPAVBaseOp@12@@Z");
- real_pub__AI__SubmitState = (pub__AI__SubmitState_t)DetourFunc((BYTE*)baseadr, (BYTE*)pub__AI__SubmitState, 0xA);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement