Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sends a global server message
- void GlobalMessage(wchar_t* _Format, ...)
- {
- va_list ArgList;
- va_start(ArgList, _Format);
- std::wstring msg = WFormatVarArgs(_Format, ArgList);
- va_end(ArgList);
- std::vector<halo::h_player*> players = game::GetPlayerList();
- for (std::vector<halo::h_player*>::iterator itr = players.begin();
- itr != players.end(); itr++)
- {
- // Build the chat packet
- game::chatData d;
- d.type = CHAT_TEAM;
- d.player = (*itr)->memoryId; // Player we're sending it from
- d.msg = (wchar_t*)msg.c_str();
- DispatchChat(d, msg.size(), *itr);
- }
- }
- void DispatchChat(game::chatData d, int len, halo::h_player* to_player)
- {
- halo::h_player* player = game::GetPlayer(d.player);
- std::vector<halo::h_player*> players = game::GetPlayerList();
- // Gotta pass a pointer to the dataPass sturct
- DWORD d_ptr = (DWORD)&d;
- BYTE* packetBuffer = new BYTE[4096 + 2*len];
- if (!packetBuffer)
- return;
- // Build the chat packet
- DWORD retval = BuildPacket(packetBuffer, 0, 0x0F, 0, (LPBYTE)&d_ptr, 0, 1, 0);
- if (!to_player) // apply normal processing if a dest player isn't specified
- {
- // Different chat types need to be handled differently
- if (d.type == 0) // all chat
- {
- // Send the packet to the server
- AddPacketToGlobalQueue(packetBuffer, retval, 1, 1, 0, 1, 3);
- }
- else if (d.type == 1) // Team chat
- {
- for (std::vector<halo::h_player*>::iterator itr = players.begin();
- itr != players.end(); itr++)
- {
- if ((*itr)->mem->team == player->mem->team)
- AddPacketToPlayerQueue((*itr)->mem->playerNum, packetBuffer, retval, 1, 1, 0, 1, 3);
- }
- }
- else if (d.type == 2) // Vehicle chat
- {
- // Check if the sender is in a vehicle
- if (player->m_object && *(DWORD*)(player->m_object + 0x11C) != -1)
- {
- // Iterate through all players and send to those in vehicles
- for (std::vector<halo::h_player*>::iterator itr = players.begin();
- itr != players.end(); itr++)
- {
- if ((*itr)->m_object && *(DWORD*)((*itr)->m_object + 0x11C) != -1) // check the vehicle object
- AddPacketToPlayerQueue((*itr)->mem->playerNum, packetBuffer, retval, 1, 1, 0, 1, 3);
- }
- }
- }
- }
- else
- // Send the packet to the player
- AddPacketToPlayerQueue(to_player->mem->playerNum, packetBuffer, retval, 1, 1, 0, 1, 3);
- delete[] packetBuffer;
- }
- // This function builds a packet
- DWORD BuildPacket(LPBYTE output, DWORD arg1, DWORD packettype, DWORD arg3, LPBYTE dataPtr, DWORD arg4, DWORD arg5, DWORD arg6)
- {
- DWORD dwBuildPacket = FUNC_BUILDPACKET;
- DWORD retval = 0;
- __asm
- {
- pushad
- PUSH arg6
- PUSH arg5
- PUSH arg4
- PUSH dataPtr
- PUSH arg3
- PUSH packettype
- PUSH arg1
- MOV EDX,0x7FF8
- MOV EAX,output
- call dword ptr ds:[dwBuildPacket]
- mov retval, eax
- add esp, 0x1C
- popad
- }
- return retval;
- }
- // This function adds a packet to the queue
- void AddPacketToGlobalQueue(LPBYTE packet, DWORD packetCode, DWORD arg1, DWORD arg2, DWORD arg3, DWORD arg4, DWORD arg5)
- {
- DWORD dwAddToQueue = FUNC_ADDPACKETTOQUEUE;
- __asm
- {
- pushad
- MOV ECX,DWORD PTR DS:[ADDR_SOCKETREADY]
- cmp ecx, 0
- je NOT_READY_TO_SEND
- PUSH arg5
- PUSH arg4
- PUSH arg3
- PUSH arg2
- PUSH packet
- PUSH arg1
- MOV EAX,packetCode
- call dword ptr ds:[dwAddToQueue]
- add esp, 0x18
- NOT_READY_TO_SEND:
- popad
- }
- }
- // This function adds a packet to a specific player's queue
- void AddPacketToPlayerQueue(DWORD player, LPBYTE packet, DWORD packetCode, DWORD arg1, DWORD arg2, DWORD arg3, DWORD arg4, DWORD arg5)
- {
- DWORD dwAddToPlayerQueue = FUNC_ADDPACKETTOPQUEUE;
- __asm
- {
- pushad
- MOV ESI,DWORD PTR DS:[ADDR_SOCKETREADY]
- cmp esi, 0
- je NOT_READY_TO_SEND
- PUSH arg5
- PUSH arg4
- PUSH arg3
- PUSH arg2
- PUSH packetCode
- PUSH packet
- PUSH arg1
- mov eax, player
- call dword ptr ds:[dwAddToPlayerQueue]
- add esp, 0x1C
- NOT_READY_TO_SEND:
- popad
- }
- }
- #define FUNC_BUILDPACKET 0x00522E30
- #define FUNC_ADDPACKETTOQUEUE 0x00516610
- #define FUNC_ADDPACKETTOPQUEUE 0x00516460
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement