From 991056b3623e55b6345261c06ee825b49b6ecf8a Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 30 May 2017 21:49:13 +0200 Subject: [PATCH] [Maps] Check map hash and redownload when different --- src/Components/Modules/Maps.cpp | 21 ++++++++++++++++++--- src/Components/Modules/Maps.hpp | 3 ++- src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 3 +++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index fa23aaec..3f140a01 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -442,11 +442,20 @@ namespace Components return 0; } - int Maps::TriggerReconnectForMap(const char* mapname) + void Maps::LoadNewMapCommand(char* buffer, size_t size, const char* /*format*/, const char* mapname, const char* gametype) + { + unsigned int hash = Maps::GetUsermapHash(mapname); + _snprintf_s(buffer, size, size, "loadingnewmap\n%s\n%s\n%d", mapname, gametype, hash); + } + + int Maps::TriggerReconnectForMap(Game::msg_t* msg, const char* mapname) { Theatre::StopRecording(); - if(!Maps::CheckMapInstalled(mapname, false, true)) + char hashBuf[100] = { 0 }; + unsigned int hash = atoi(Game::MSG_ReadStringLine(msg, hashBuf, sizeof hashBuf)); + + if(!Maps::CheckMapInstalled(mapname, false, true) || hash && hash != Maps::GetUsermapHash(mapname)) { // Reconnecting forces the client to download the new map Command::Execute("disconnect", false); @@ -468,8 +477,9 @@ namespace Components pushad push [esp + 28h] + push ebp call Maps::TriggerReconnectForMap - add esp, 4h + add esp, 8h mov[esp + 20h], eax @@ -1000,6 +1010,11 @@ namespace Components }, 6s); }); + if(Dedicated::IsEnabled()) + { + Utils::Hook(0x4A7251, Maps::LoadNewMapCommand, HOOK_CALL).install()->quick(); + } + // Download the map before a maprotation if necessary // Conflicts with Theater's SV map rotation check, but this one is safer! Utils::Hook(0x5AA91C, Maps::RotateCheckStub, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index c1ee8af4..1becaa63 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -112,8 +112,9 @@ namespace Components static void SpawnServerStub(); static void LoadMapLoadscreenStub(); - static int TriggerReconnectForMap(const char* mapname); + static int TriggerReconnectForMap(Game::msg_t* msg, const char* mapname); static void RotateCheckStub(); + static void LoadNewMapCommand(char* buffer, size_t size, const char* format, const char* mapname, const char* gametype); static const char* LoadArenaFileStub(const char* name, char* buffer, int size); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 3b3f0834..01fc3783 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -155,6 +155,7 @@ namespace Game MSG_ReadShort_t MSG_ReadShort = MSG_ReadShort_t(0x40BDD0); MSG_ReadInt64_t MSG_ReadInt64 = MSG_ReadInt64_t(0x4F1850); MSG_ReadString_t MSG_ReadString = MSG_ReadString_t(0x60E2B0); + MSG_ReadStringLine_t MSG_ReadStringLine = MSG_ReadStringLine_t(0x4FEF30); MSG_WriteByte_t MSG_WriteByte = MSG_WriteByte_t(0x48C520); MSG_WriteData_t MSG_WriteData = MSG_WriteData_t(0x4F4120); MSG_WriteLong_t MSG_WriteLong = MSG_WriteLong_t(0x41CA20); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 8ff2aa51..e6f7769b 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -394,6 +394,9 @@ namespace Game typedef char* (__cdecl * MSG_ReadString_t)(msg_t* msg); extern MSG_ReadString_t MSG_ReadString; + typedef char* (__cdecl * MSG_ReadStringLine_t)(msg_t *msg, char *string, unsigned int maxChars); + extern MSG_ReadStringLine_t MSG_ReadStringLine; + typedef int(__cdecl * MSG_ReadByte_t)(msg_t* msg); extern MSG_ReadByte_t MSG_ReadByte;