From 46a3f62406f6ce0c57fdfb57369492874f08a249 Mon Sep 17 00:00:00 2001 From: Edo Date: Wed, 4 Jan 2023 18:57:32 +0000 Subject: [PATCH] [Theatre]: Do not draw broken selector (#700) --- src/Components/Modules/Theatre.cpp | 42 ++++++++++++++++++++---------- src/Components/Modules/Theatre.hpp | 1 + src/Game/Functions.cpp | 5 ---- src/Game/Functions.hpp | 5 ---- src/Game/Structs.hpp | 6 +++++ 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/Components/Modules/Theatre.cpp b/src/Components/Modules/Theatre.cpp index 6b6bcf8d..491fd1d5 100644 --- a/src/Components/Modules/Theatre.cpp +++ b/src/Components/Modules/Theatre.cpp @@ -38,8 +38,8 @@ namespace Components void Theatre::RecordGamestateStub() { - const auto sequence = (*Game::serverMessageSequence - 1); - Game::FS_WriteToDemo(&sequence, 4, *Game::demoFile); + const auto sequence = (Game::clientConnections->serverMessageSequence - 1); + Game::FS_WriteToDemo(&sequence, 4, Game::clientConnections->demofile); } void Theatre::StoreBaseline(PBYTE snapshotMsg) @@ -72,7 +72,7 @@ namespace Components Game::msg_t buf; - Game::MSG_Init(&buf, bufData, 131072); + Game::MSG_Init(&buf, bufData, sizeof(bufData)); Game::MSG_WriteData(&buf, &BaselineSnapshot[BaselineSnapshotMsgOff], BaselineSnapshotMsgLen - BaselineSnapshotMsgOff); Game::MSG_WriteByte(&buf, 6); @@ -80,12 +80,12 @@ namespace Components const auto fileCompressedSize = compressedSize + 4; int byte8 = 8; - char byte0 = 0; + unsigned char byte0 = 0; - Game::FS_WriteToDemo(&byte0, 1, *Game::demoFile); - Game::FS_WriteToDemo(Game::serverMessageSequence, 4, *Game::demoFile); - Game::FS_WriteToDemo(&fileCompressedSize, 4, *Game::demoFile); - Game::FS_WriteToDemo(&byte8, 4, *Game::demoFile); + Game::FS_WriteToDemo(&byte0, sizeof(unsigned char), Game::clientConnections->demofile); + Game::FS_WriteToDemo(&Game::clientConnections->serverMessageSequence, sizeof(int), Game::clientConnections->demofile); + Game::FS_WriteToDemo(&fileCompressedSize, sizeof(int), Game::clientConnections->demofile); + Game::FS_WriteToDemo(&byte8, sizeof(int), Game::clientConnections->demofile); for (auto i = 0; i < compressedSize; i += 1024) { @@ -97,7 +97,7 @@ namespace Components break; } - Game::FS_WriteToDemo(&cmpData[i], size, *Game::demoFile); + Game::FS_WriteToDemo(&cmpData[i], size, Game::clientConnections->demofile); } } @@ -123,7 +123,7 @@ namespace Components { __asm { - mov eax, Game::demoPlaying + mov eax, 0xA5EA0C // clientConnections.demoplaying mov eax, [eax] test al, al jz continue @@ -141,7 +141,7 @@ namespace Components { __asm { - mov eax, Game::demoPlaying + mov eax, 0xA5EA0C // clientConnections.demoplaying mov eax, [eax] test al, al jz continue @@ -160,7 +160,7 @@ namespace Components { __asm { - mov eax, Game::demoPlaying + mov eax, 0xA5EA0C // clientConnections.demoplaying mov eax, [eax] test al, al jz continue @@ -177,6 +177,14 @@ namespace Components } } + void Theatre::CG_CompassDrawPlayerMapLocationSelector_Stub(const int localClientNum, Game::CompassType compassType, const Game::rectDef_s* parentRect, const Game::rectDef_s* rect, Game::Material* material, float* color) + { + if (!Game::clientConnections->demoplaying) + { + Utils::Hook::Call(0x45BD60)(localClientNum, compassType, parentRect, rect, material, color); + } + } + void Theatre::CL_WriteDemoClientArchive_Hk(void(*write)(const void* buffer, int len, int localClientNum), const Game::playerState_s* ps, const float* viewangles, [[maybe_unused]] const float* selectedLocation, [[maybe_unused]] const float selectedLocationAngle, int localClientNum, int index) { assert(write); @@ -334,7 +342,7 @@ namespace Components int Theatre::CL_FirstSnapshot_Stub() { - if (CLAutoRecord.get() && !*Game::demoPlaying) + if (CLAutoRecord.get() && !Game::clientConnections->demoplaying) { std::vector files; auto demos = FileSystem::GetFileList("demos/", "dm_13"); @@ -370,7 +378,7 @@ namespace Components void Theatre::StopRecording() { - if (*Game::demoRecording) + if (Game::clientConnections->demorecording) { Command::Execute("stoprecord", true); } @@ -378,6 +386,11 @@ namespace Components Theatre::Theatre() { + AssertOffset(Game::clientConnection_t, demorecording, 0x40190); + AssertOffset(Game::clientConnection_t, demoplaying, 0x40194); + AssertOffset(Game::clientConnection_t, demofile, 0x401A4); + AssertOffset(Game::clientConnection_t, serverMessageSequence, 0x2013C); + CLAutoRecord = Dvar::Register("cl_autoRecord", true, Game::DVAR_ARCHIVE, "Automatically record games"); CLDemosKeep = Dvar::Register("cl_demosKeep", 30, 1, 999, Game::DVAR_ARCHIVE, "How many demos to keep with autorecord"); @@ -391,6 +404,7 @@ namespace Components // Fix issue with locationSelectionInfo by disabling it Utils::Hook(0x5AC20F, CL_WriteDemoClientArchive_Hk, HOOK_CALL).install()->quick(); + Utils::Hook(0x4964A6, CG_CompassDrawPlayerMapLocationSelector_Stub, HOOK_CALL).install()->quick(); // Hook commands to enforce metadata generation Utils::Hook(0x5A82AE, RecordStub, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Theatre.hpp b/src/Components/Modules/Theatre.hpp index 63b45058..217240b0 100644 --- a/src/Components/Modules/Theatre.hpp +++ b/src/Components/Modules/Theatre.hpp @@ -56,6 +56,7 @@ namespace Components static int CL_FirstSnapshot_Stub(); static void SV_SpawnServer_Stub(); + static void CG_CompassDrawPlayerMapLocationSelector_Stub(int localClientNum, Game::CompassType compassType, const Game::rectDef_s* parentRect, const Game::rectDef_s* rect, Game::Material* material, float* color); static void CL_WriteDemoClientArchive_Hk(void(*write)(const void* buffer, int len, int localClientNum), const Game::playerState_s* ps, const float* viewangles, const float* selectedLocation, float selectedLocationAngle, int localClientNum, int index); static void RecordStub(int channel, char* message, char* file); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index aff6d1af..c5014e76 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -290,11 +290,6 @@ namespace Game int* numIP = reinterpret_cast(0x64A1E68); netIP_t* localIP = reinterpret_cast(0x64A1E28); - int* demoFile = reinterpret_cast(0xA5EA1C); - int* demoPlaying = reinterpret_cast(0xA5EA0C); - int* demoRecording = reinterpret_cast(0xA5EA08); - int* serverMessageSequence = reinterpret_cast(0xA3E9B4); - netadr_t* connectedHost = reinterpret_cast(0xA1E888); SOCKET* ip_socket = reinterpret_cast(0x64A3008); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 8e9a9d66..237304bd 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -633,11 +633,6 @@ namespace Game extern int* numIP; extern netIP_t* localIP; - extern int* demoFile; - extern int* demoPlaying; - extern int* demoRecording; - extern int* serverMessageSequence; - extern netadr_t* connectedHost; extern SOCKET* ip_socket; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index ca4a7f8d..d08f8236 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -7107,6 +7107,12 @@ namespace Game static_assert(sizeof(client_t) == 0xA6790); + enum CompassType + { + COMPASS_TYPE_PARTIAL = 0x0, + COMPASS_TYPE_FULL = 0x1, + }; + struct clientConnection_t { int qport;