Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. bool __fastcall Handlers::WriteUsercmdDeltaToBuffer_h(IBaseClientDLL *ECX, void *EDX, int nSlot, bf_write *buf, int from, int to, bool isNewCmd)
  2. {
  3. static DWORD WriteUsercmdDeltaToBufferReturn = (DWORD)Utils::PatternScan(GetModuleHandle("engine.dll"), "84 C0 74 04 B0 01 EB 02 32 C0 8B FE 46 3B F3 7E C9 84 C0 0F 84 ? ? ? ?");
  4.  
  5. if (nTickBaseShift <= 0 || _ReturnAddress() != &WriteUsercmdDeltaToBufferReturn)
  6. return o_WriteUsercmdDeltaToBuffer(ECX, nSlot, buf, from, to, isNewCmd);
  7.  
  8. if (from != -1)
  9. return true;
  10.  
  11. // CL_SendMove function
  12. auto CL_SendMove = []()
  13. {
  14. using CL_SendMove_t = void(__fastcall*)(void);
  15. static CL_SendMove_t CL_SendMoveF = (CL_SendMove_t)Utils::PatternScan(GetModuleHandle("engine.dll"), ("55 8B EC A1 ? ? ? ? 81 EC ? ? ? ? B9 ? ? ? ? 53 8B 98"));
  16.  
  17. CL_SendMoveF();
  18. };
  19.  
  20. // WriteUsercmd function
  21. auto WriteUsercmd = [](bf_write *buf, CUserCmd *in, CUserCmd *out)
  22. {
  23. using WriteUsercmd_t = void(__fastcall*)(bf_write*, CUserCmd*, CUserCmd*);
  24. static WriteUsercmd_t WriteUsercmdF = (WriteUsercmd_t)Utils::PatternScan(GetModuleHandle("client.dll"), ("55 8B EC 83 E4 F8 51 53 56 8B D9 8B 0D"));
  25.  
  26. WriteUsercmdF(buf, in, out);
  27. };
  28.  
  29. uintptr_t *framePtr;
  30. __asm mov framePtr, ebp;
  31. auto msg = reinterpret_cast<CCLCMsg_Move_t*>(*framePtr + 0xFCC);
  32. auto net_channel = g_ClientState->m_NetChannel;
  33.  
  34. int32_t new_commands = msg->numNewCommands;
  35.  
  36. if (!bInSendMove)
  37. {
  38. if (new_commands <= 0)
  39. return false;
  40.  
  41. bInSendMove = true;
  42. bFirstSendMovePack = true;
  43. nTickBaseShift += new_commands;
  44.  
  45. while (nTickBaseShift > 0)
  46. {
  47. CL_SendMove();
  48. net_channel->Transmit(false);
  49. bFirstSendMovePack = false;
  50. }
  51.  
  52. bInSendMove = false;
  53. return false;
  54. }
  55.  
  56. if (!bFirstSendMovePack)
  57. {
  58. int32_t loss = min(nTickBaseShift, 10);
  59.  
  60. nTickBaseShift -= loss;
  61. net_channel->m_nOutSequenceNr += loss;
  62. }
  63.  
  64. int32_t next_cmdnr = g_ClientState->lastoutgoingcommand + g_ClientState->chokedcommands + 1;
  65. int32_t total_new_commands = min(nTickBaseShift, 62);
  66. nTickBaseShift -= total_new_commands;
  67.  
  68. from = -1;
  69. msg->numNewCommands = total_new_commands;
  70. msg->numBackupCommands = 0;
  71.  
  72. for (to = next_cmdnr - new_commands + 1; to <= next_cmdnr; to++)
  73. {
  74. if (!o_WriteUsercmdDeltaToBuffer(ECX, nSlot, buf, from, to, true))
  75. return false;
  76.  
  77. from = to;
  78. }
  79.  
  80. CUserCmd *last_realCmd = g_Input->GetUserCmd(nSlot, from);
  81. CUserCmd fromCmd;
  82.  
  83. if (last_realCmd)
  84. fromCmd = *last_realCmd;
  85.  
  86. CUserCmd toCmd = fromCmd;
  87. toCmd.command_number++;
  88. toCmd.tick_count += 200;
  89.  
  90. for (int i = new_commands; i <= total_new_commands; i++)
  91. {
  92. WriteUsercmd(buf, &toCmd, &fromCmd);
  93. fromCmd = toCmd;
  94. toCmd.command_number++;
  95. toCmd.tick_count++;
  96. }
  97.  
  98. return true;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement