|
| 1 | +/** |
| 2 | +* yrpp-spawner |
| 3 | +* |
| 4 | +* Copyright(C) 2022-present CnCNet |
| 5 | +* |
| 6 | +* This program is free software: you can redistribute it and/or modify |
| 7 | +* it under the terms of the GNU General Public License as published by |
| 8 | +* the Free Software Foundation, either version 3 of the License, or |
| 9 | +* (at your option) any later version. |
| 10 | +* |
| 11 | +* This program is distributed in the hope that it will be useful, |
| 12 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
| 14 | +* GNU General Public License for more details. |
| 15 | +* |
| 16 | +* You should have received a copy of the GNU General Public License |
| 17 | +* along with this program.If not, see <http://www.gnu.org/licenses/>. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include <Spawner/Spawner.h> |
| 21 | +#include <Utilities/Macro.h> |
| 22 | +#include <HouseClass.h> |
| 23 | + |
| 24 | +// This corrects the processing of Unicode player names |
| 25 | +// and prohibits incoming messages from players with whom chat is disabled |
| 26 | + |
| 27 | +#pragma pack(push, 1) |
| 28 | +struct GlobalPacket_NetMessage |
| 29 | +{ |
| 30 | + static constexpr reference<GlobalPacket_NetMessage, 0xA8D638u> const Instance {}; |
| 31 | + |
| 32 | + int Command; |
| 33 | + wchar_t PlayerName[21]; |
| 34 | + byte HouseIndex; |
| 35 | + byte ChatID; |
| 36 | + wchar_t Message[112]; |
| 37 | + byte Color; |
| 38 | + byte CRC; |
| 39 | +}; |
| 40 | +#pragma pack(pop) |
| 41 | + |
| 42 | +DEFINE_HOOK(0x48D92B, NetworkCallBack_NetMessage_Print, 0x5) |
| 43 | +{ |
| 44 | + if (!Spawner::Enabled) |
| 45 | + return 0; |
| 46 | + |
| 47 | + enum { SkipMessage = 0x48DAD3, PrintMessage = 0x48D937 }; |
| 48 | + |
| 49 | + const int houseIndex = GlobalPacket_NetMessage::Instance->HouseIndex; |
| 50 | + |
| 51 | + if (houseIndex < 8 && Game::ChatMask[houseIndex]) |
| 52 | + { |
| 53 | + if (HouseClass::Array->ValidIndex(houseIndex)) |
| 54 | + { |
| 55 | + HouseClass* pHouse = HouseClass::Array->GetItem(houseIndex); |
| 56 | + |
| 57 | + GlobalPacket_NetMessage::Instance->Color = (byte)pHouse->ColorSchemeIndex; |
| 58 | + R->ESI(pHouse->UIName); |
| 59 | + return PrintMessage; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return SkipMessage; |
| 64 | +} |
| 65 | + |
| 66 | +DEFINE_HOOK(0x48D95B, NetworkCallBack_NetMessage_SetColor, 0x6) |
| 67 | +{ |
| 68 | + if (!Spawner::Enabled) |
| 69 | + return 0; |
| 70 | + |
| 71 | + R->EAX(R->ECX()); |
| 72 | + return 0x48D966; |
| 73 | +} |
| 74 | + |
| 75 | +DEFINE_HOOK(0x55EDD2, MessageInput_Write, 0x5) |
| 76 | +{ |
| 77 | + if (!Spawner::Enabled) |
| 78 | + return 0; |
| 79 | + |
| 80 | + HouseClass* pHouse = HouseClass::CurrentPlayer; |
| 81 | + wcscpy_s(GlobalPacket_NetMessage::Instance->PlayerName, pHouse->UIName); |
| 82 | + GlobalPacket_NetMessage::Instance->HouseIndex = (byte)pHouse->ArrayIndex; |
| 83 | + |
| 84 | + return 0x55EE00; |
| 85 | +} |
| 86 | + |
| 87 | +DEFINE_HOOK(0x55F0A8, MessageInput_Print, 0x5) |
| 88 | +{ |
| 89 | + if (!Spawner::Enabled) |
| 90 | + return 0; |
| 91 | + |
| 92 | + R->EAX(GlobalPacket_NetMessage::Instance->PlayerName); |
| 93 | + return 0x55F0B2; |
| 94 | +} |
0 commit comments