Advertisement
FriendlyFire

Untitled

May 26th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. //// h
  2.  
  3. void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
  4. {
  5.     BYTE *jmp = (BYTE*)malloc(len+5);
  6.     DWORD dwback;
  7.  
  8.     VirtualProtect(src, len, PAGE_READWRITE, &dwback);
  9.  
  10.     memcpy(jmp, src, len);  jmp += len;
  11.    
  12.     jmp[0] = 0xE9;
  13.     *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
  14.  
  15.     src[0] = 0xE9;
  16.     *(DWORD*)(src+1) = (DWORD)(dst-src) - 5;
  17.  
  18.     VirtualProtect(src, len, dwback, &dwback);
  19.  
  20.     return (jmp-len);
  21. }
  22.  
  23. //// cpp
  24.  
  25. typedef pub::AI::OP_RTYPE(__cdecl *pub__AI__SubmitDirective_t)(unsigned int spaceobj, pub::AI::BaseOp* op);
  26. pub__AI__SubmitDirective_t real_pub__AI__SubmitDirective = NULL;
  27.  
  28. void testOp(uint spaceobj, pub::AI::BaseOp* op, bool directive)
  29. {
  30.     AddLog("AI Op for ship %u (%s): %s", spaceobj, directive ? "directive" : "state", typeid(*op).name());
  31.  
  32.     pub::AI::DirectiveTrailOp* top = dynamic_cast<pub::AI::DirectiveTrailOp*>(op);
  33.     if (top)
  34.     {
  35.         int x = 0;
  36.     }
  37.  
  38.     pub::AI::DirectiveDelayOp* dop = dynamic_cast<pub::AI::DirectiveDelayOp*>(op);
  39.     if (dop)
  40.     {
  41.         int x = 0;
  42.     }
  43.  
  44.     pub::AI::DirectiveInstantTradelaneOp* itop = dynamic_cast<pub::AI::DirectiveInstantTradelaneOp*>(op);
  45.     if (itop)
  46.     {
  47.         int x = 0;
  48.     }
  49.  
  50.     pub::AI::DirectiveLaunchOp* lop = dynamic_cast<pub::AI::DirectiveLaunchOp*>(op);
  51.     if (lop)
  52.     {
  53.         int x = 0;
  54.     }
  55. }
  56.  
  57. pub::AI::OP_RTYPE pub__AI__SubmitDirective(unsigned int spaceobj, pub::AI::BaseOp* op)
  58. {
  59.     testOp(spaceobj, op, true);
  60.     return real_pub__AI__SubmitDirective(spaceobj, op);
  61. }
  62.  
  63. typedef pub::AI::OP_RTYPE(__cdecl *pub__AI__SubmitState_t)(unsigned int spaceobj, pub::AI::BaseOp* op);
  64. pub__AI__SubmitState_t real_pub__AI__SubmitState = NULL;
  65.  
  66. pub::AI::OP_RTYPE pub__AI__SubmitState(unsigned int spaceobj, pub::AI::BaseOp* op)
  67. {
  68.     testOp(spaceobj, op, false);
  69.     return real_pub__AI__SubmitState(spaceobj, op);
  70. }
  71.  
  72. void Init()
  73. {
  74.     static bool loaded = false;
  75.     if (!loaded)
  76.     {
  77.         loaded = true;
  78.  
  79.         DWORD baseadr = (DWORD)GetProcAddress(GetModuleHandle("server.dll"), "?SubmitDirective@AI@pub@@YA?AW4OP_RTYPE@12@IPAVBaseOp@12@@Z");
  80.  
  81.  
  82.         real_pub__AI__SubmitDirective = (pub__AI__SubmitDirective_t)DetourFunc((BYTE*)baseadr, (BYTE*)pub__AI__SubmitDirective, 7);
  83.  
  84.         baseadr = (DWORD)GetProcAddress(GetModuleHandle("server.dll"), "?SubmitState@AI@pub@@YA?AW4OP_RTYPE@12@IPAVBaseOp@12@@Z");
  85.  
  86.         real_pub__AI__SubmitState = (pub__AI__SubmitState_t)DetourFunc((BYTE*)baseadr, (BYTE*)pub__AI__SubmitState, 0xA);
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement