diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 695841d5..5c57c5ef 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -101,6 +101,19 @@ extern sp_nativeinfo_t g_ClientNatives[]; static void InitSDKToolsAPI(); +#if SOURCE_ENGINE == SE_CSGO +CDetour *g_WriteBaselinesDetour = NULL; + +DETOUR_DECL_MEMBER3(CNetworkStringTableContainer__WriteBaselines, void, char const *, mapName, void *, buffer, int, currentTick) +{ + // Replace nAtTick with INT_MAX to work around CS:GO engine bug. + // Due to a timing issue in the engine, stringtable entries added in OnConfigsExecuted can be considered + // to have been added in the future for the first client that connects, which causes them to be ignored + // when iterating for networking, which triggers a Host_Error encoding the CreateStringTable netmsg. + return DETOUR_MEMBER_CALL(CNetworkStringTableContainer__WriteBaselines)(mapName, buffer, INT_MAX); +} +#endif + bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late) { HandleError err; @@ -186,6 +199,13 @@ bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late) m_CSGOBadList.init(); m_CSGOBadList.add("m_bIsValveDS"); m_CSGOBadList.add("m_bIsQuestEligible"); + + g_WriteBaselinesDetour = DETOUR_CREATE_MEMBER(CNetworkStringTableContainer__WriteBaselines, "WriteBaselines"); + if (g_WriteBaselinesDetour) { + g_WriteBaselinesDetour->EnableDetour(); + } else { + g_pSM->LogError(myself, "Failed to find WriteBaselines signature -- stringtable error workaround disabled."); + } #endif return true; @@ -217,6 +237,13 @@ void SDKTools::SDK_OnUnload() g_RegCalls.clear(); ShutdownHelpers(); +#if SOURCE_ENGINE == SE_CSGO + if (g_WriteBaselinesDetour) { + g_WriteBaselinesDetour->DisableDetour(); + g_WriteBaselinesDetour = NULL; + } +#endif + if (g_pAcceptInput) { g_pAcceptInput->Destroy(); diff --git a/gamedata/sdktools.games/engine.csgo.txt b/gamedata/sdktools.games/engine.csgo.txt index 56c9d755..1d0de848 100644 --- a/gamedata/sdktools.games/engine.csgo.txt +++ b/gamedata/sdktools.games/engine.csgo.txt @@ -348,5 +348,18 @@ "mac64" "279" } } + "Signatures" + { + /** + * CNetworkStringTableContainer::WriteBaselines + * "Index error writing string table baseline %s\n" + */ + "WriteBaselines" + { + "library" "engine" + "windows" "\x55\x8B\xEC\x83\xEC\x60\x53\x56\x8B\xF1\x8B\x0D\x2A\x2A\x2A\x2A\x57\x89\x75\xF8\x8B\x81\x2A\x2A\x2A\x2A\x89\x45\xF4\x85\xC0" + "linux" "\x55\x89\xE5\x57\x56\x53\x81\xEC\x8C\x00\x00\x00\x8B\x0D\x2A\x2A\x2A\x2A\x8B\x75\x08\x8B\x5D\x0C\x8B\x7D\x10\x85\xC9" + } + } } }