Advertisement
Guest User

Untitled

a guest
Sep 21st, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.15 KB | None | 0 0
  1. // Sends a global server message
  2.     void GlobalMessage(wchar_t* _Format, ...)
  3.     {
  4.         va_list ArgList;
  5.         va_start(ArgList, _Format);
  6.         std::wstring msg = WFormatVarArgs(_Format, ArgList);
  7.         va_end(ArgList);
  8.  
  9.         std::vector<halo::h_player*> players = game::GetPlayerList();
  10.         for (std::vector<halo::h_player*>::iterator itr = players.begin();
  11.             itr != players.end(); itr++)
  12.         {
  13.             // Build the chat packet
  14.             game::chatData d;
  15.             d.type = CHAT_TEAM;
  16.             d.player = (*itr)->memoryId; // Player we're sending it from
  17.             d.msg = (wchar_t*)msg.c_str();
  18.  
  19.             DispatchChat(d, msg.size(), *itr);
  20.         }
  21.     }
  22.  
  23. void DispatchChat(game::chatData d, int len, halo::h_player* to_player)
  24.     {
  25.         halo::h_player* player = game::GetPlayer(d.player);
  26.         std::vector<halo::h_player*> players = game::GetPlayerList();
  27.  
  28.         // Gotta pass a pointer to the dataPass sturct
  29.         DWORD d_ptr = (DWORD)&d;
  30.  
  31.         BYTE* packetBuffer = new BYTE[4096 + 2*len];
  32.  
  33.         if (!packetBuffer)
  34.             return;
  35.  
  36.         // Build the chat packet
  37.         DWORD retval =  BuildPacket(packetBuffer, 0, 0x0F, 0, (LPBYTE)&d_ptr, 0, 1, 0);
  38.  
  39.         if (!to_player) // apply normal processing if a dest player isn't specified
  40.         {
  41.             // Different chat types need to be handled differently
  42.             if (d.type == 0) // all chat
  43.             {
  44.                 // Send the packet to the server
  45.                 AddPacketToGlobalQueue(packetBuffer, retval, 1, 1, 0, 1, 3);
  46.             }
  47.             else if (d.type == 1) // Team chat
  48.             {
  49.                 for (std::vector<halo::h_player*>::iterator itr = players.begin();
  50.                     itr != players.end(); itr++)
  51.                 {
  52.                     if ((*itr)->mem->team == player->mem->team)
  53.                         AddPacketToPlayerQueue((*itr)->mem->playerNum, packetBuffer, retval, 1, 1, 0, 1, 3);
  54.                 }
  55.             }
  56.             else if (d.type == 2) // Vehicle chat
  57.             {
  58.                 // Check if the sender is in a vehicle
  59.                 if (player->m_object && *(DWORD*)(player->m_object + 0x11C) != -1)
  60.                 {
  61.                     // Iterate through all players and send to those in vehicles
  62.                     for (std::vector<halo::h_player*>::iterator itr = players.begin();
  63.                         itr != players.end(); itr++)
  64.                     {
  65.                         if ((*itr)->m_object && *(DWORD*)((*itr)->m_object + 0x11C) != -1) // check the vehicle object
  66.                             AddPacketToPlayerQueue((*itr)->mem->playerNum, packetBuffer, retval, 1, 1, 0, 1, 3);
  67.                     }                  
  68.                 }
  69.             }
  70.         }
  71.         else
  72.             // Send the packet to the player
  73.             AddPacketToPlayerQueue(to_player->mem->playerNum, packetBuffer, retval, 1, 1, 0, 1, 3);
  74.  
  75.         delete[] packetBuffer;
  76.     }
  77.  
  78. // This function builds a packet
  79.     DWORD BuildPacket(LPBYTE output, DWORD arg1, DWORD packettype, DWORD arg3, LPBYTE dataPtr, DWORD arg4, DWORD arg5, DWORD arg6)
  80.     {
  81.         DWORD dwBuildPacket = FUNC_BUILDPACKET;
  82.         DWORD retval = 0;
  83.  
  84.         __asm
  85.         {
  86.             pushad
  87.  
  88.             PUSH arg6
  89.             PUSH arg5
  90.             PUSH arg4
  91.             PUSH dataPtr
  92.             PUSH arg3
  93.             PUSH packettype
  94.             PUSH arg1
  95.             MOV EDX,0x7FF8
  96.             MOV EAX,output
  97.             call dword ptr ds:[dwBuildPacket]
  98.             mov retval, eax
  99.             add esp, 0x1C
  100.  
  101.             popad
  102.         }
  103.  
  104.         return retval;
  105.     }
  106.  
  107.     // This function adds a packet to the queue
  108.     void AddPacketToGlobalQueue(LPBYTE packet, DWORD packetCode, DWORD arg1, DWORD arg2, DWORD arg3, DWORD arg4, DWORD arg5)
  109.     {
  110.         DWORD dwAddToQueue = FUNC_ADDPACKETTOQUEUE;
  111.  
  112.         __asm
  113.         {
  114.             pushad
  115.  
  116.             MOV ECX,DWORD PTR DS:[ADDR_SOCKETREADY]
  117.  
  118.             cmp ecx, 0
  119.             je NOT_READY_TO_SEND
  120.  
  121.             PUSH arg5
  122.             PUSH arg4
  123.             PUSH arg3
  124.             PUSH arg2
  125.             PUSH packet
  126.             PUSH arg1
  127.             MOV EAX,packetCode
  128.             call dword ptr ds:[dwAddToQueue]
  129.             add esp, 0x18
  130.  
  131. NOT_READY_TO_SEND:
  132.  
  133.             popad
  134.         }
  135.     }
  136.  
  137.     // This function adds a packet to a specific player's queue
  138.     void AddPacketToPlayerQueue(DWORD player, LPBYTE packet, DWORD packetCode, DWORD arg1, DWORD arg2, DWORD arg3, DWORD arg4, DWORD arg5)
  139.     {
  140.         DWORD dwAddToPlayerQueue = FUNC_ADDPACKETTOPQUEUE;
  141.  
  142.         __asm
  143.         {
  144.             pushad
  145.  
  146.             MOV ESI,DWORD PTR DS:[ADDR_SOCKETREADY]
  147.  
  148.             cmp esi, 0
  149.             je NOT_READY_TO_SEND
  150.  
  151.             PUSH arg5
  152.             PUSH arg4
  153.             PUSH arg3
  154.             PUSH arg2
  155.             PUSH packetCode
  156.             PUSH packet
  157.             PUSH arg1
  158.             mov eax, player
  159.             call dword ptr ds:[dwAddToPlayerQueue]
  160.             add esp, 0x1C
  161.  
  162. NOT_READY_TO_SEND:
  163.  
  164.             popad
  165.         }
  166.     }
  167.  
  168. #define FUNC_BUILDPACKET                0x00522E30
  169. #define FUNC_ADDPACKETTOQUEUE           0x00516610
  170. #define FUNC_ADDPACKETTOPQUEUE          0x00516460
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement