Skip to content

Commit f27bdca

Browse files
committed
fix: Brought back unstable hook to prevent Workshop maps from downloading
1 parent 1129d64 commit f27bdca

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

p2sm.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Authors: Orsell & Nanoman2525 & NULLderef
44
// Purpose: P2SourceMod++ Plugin
5-
//
5+
//
66
//===========================================================================//
77

88
#include "p2sm.hpp"
@@ -40,6 +40,11 @@ const char* CP2SMPlusPlusPlugin::GetPluginDescription(void)
4040
return "P2SourceModPlusPlus Plugin | Plugin Version: " P2SMPLUSPLUS_PLUGIN_VERSION;
4141
}
4242

43+
// STOP THEM WORKSHOP DOWNLOADS!
44+
class CUGCFileRequestManager;
45+
void (__fastcall* CUGCFileRequestManager__Update_orig)(CUGCFileRequestManager* thisptr);
46+
void __fastcall CUGCFileRequestManager__Update_hook(CUGCFileRequestManager* thisptr) { return; }
47+
4348
//---------------------------------------------------------------------------------
4449
// Purpose: Called when the plugin is loaded, initialization process.
4550
// Loads the interfaces we need from the engine and applies our patches.
@@ -65,14 +70,14 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfa
6570
R"(|__/ |________/ \______/ |__/ |__/ )""\n"\
6671
"(========================== VERSION: %s ==========================)", P2SMPLUSPLUS_PLUGIN_VERSION
6772
);
68-
73+
6974
Log(INFO, false, "Loading plugin...");
7075

7176
Log(INFO, true, "Grabbing game window handle...");
7277
hWnd = FindWindow("Valve001", nullptr);
7378
if (!hWnd)
7479
Log(WARNING, false, "Failed to find game window!");
75-
80+
7681
// big ol' try catch because game has a TerminateProcess handler for exceptions...
7782
// why this wasn't here is mystifying, - 10/2024 NULLderef
7883
try {
@@ -94,7 +99,7 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfa
9499
// MinHook initialization and hooking.
95100
Log(INFO, true, "Initializing MinHook and hooking functions...");
96101
MH_Initialize();
97-
102+
98103
// Hook the death think function so players can be spawned immediate when the p2sm_instantrespawn ConVar is on.
99104
Log(INFO, true, "Hooking CPortal_Player::PlayerDeathThink...");
100105
MH_CreateHook(
@@ -113,12 +118,19 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfa
113118
Memory::Scanner::Scan(SERVERDLL, "A1 ?? ?? ?? ?? 8B 50 ?? 83 7A ?? ?? 74 ?? 8B 81"),
114119
&CPortal_Player__FlashlightTurnOff_hook, reinterpret_cast<void**>(&CPortal_Player__FlashlightTurnOff_orig)
115120
);
116-
121+
122+
// Stop workshop map downloads by not returning false on the download request.
123+
// Log(INFO, true, "Hooking CWorkshopManager::CreateFileDownloadRequest...");
124+
// MH_CreateHook(
125+
// Memory::Scanner::Scan(CLIENTDLL, "55 8B EC 8B 45 ?? 8B 55 ?? 50 8B 45 ?? 52 8B 55 ?? 50 8B 45 ?? 52 8B 55 ?? 50 8B 45"),
126+
// &CWorkshopManager__CreateFileDownloadRequest_hook, reinterpret_cast<void**>(&CWorkshopManager__CreateFileDownloadRequest_orig)
127+
// );
117128
// Stop workshop map downloads by not returning false on the download request.
118-
Log(INFO, true, "Hooking CWorkshopManager::CreateFileDownloadRequest...");
129+
//!! TEMP TO FIX ORIGINAL HOOK THAT SUDDENLY BROKE
130+
Log(INFO, true, "Hooking CUGCFileRequestManager::Update...");
119131
MH_CreateHook(
120-
Memory::Scanner::Scan(CLIENTDLL, "55 8B EC 8B 45 ?? 8B 55 ?? 50 8B 45 ?? 52 8B 55 ?? 50 8B 45 ?? 52 8B 55 ?? 50 8B 45"),
121-
&CWorkshopManager__CreateFileDownloadRequest_hook, reinterpret_cast<void**>(&CWorkshopManager__CreateFileDownloadRequest_orig)
132+
Memory::Scanner::Scan<void*>(Memory::Modules::Get("client"), "55 8B EC 81 EC 48 01 00 00 57"),
133+
&CUGCFileRequestManager__Update_hook, reinterpret_cast<void**>(&CUGCFileRequestManager__Update_orig)
122134
);
123135

124136
// Stop env_projectedtexture entities from getting disabled when more than one is active.
@@ -178,7 +190,7 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfa
178190
this->m_bNoUnload = true;
179191
return false;
180192
}
181-
193+
182194
Log(INFO, true, "Loading g_pGlobals...");
183195
g_pGlobals = g_pPlayerInfoManager->GetGlobalVars();
184196
if (!g_pGlobals)
@@ -196,21 +208,21 @@ bool CP2SMPlusPlusPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfa
196208
Log(INFO, true, "cl_localnetworkbackdoor...");
197209
if (ConVar* lnbCVar = g_pCVar->FindVar("cl_localnetworkbackdoor"))
198210
lnbCVar->SetValue(0);
199-
211+
200212
// Remove the cheat flag on r_drawscreenoverlay and enable it by default to allow maps to easily display screen overlays.
201213
Log(INFO, true, "r_drawscreenoverlay...");
202214
if (ConVar* screenCVar = g_pCVar->FindVar("r_drawscreenoverlay"))
203215
{
204216
screenCVar->RemoveFlags(FCVAR_CHEAT);
205217
screenCVar->SetValue(1);
206218
}
207-
219+
208220
// Make switching between players in splitscreen when testing easier by removing
209221
// the need for cheats to change the current player under control.
210222
Log(INFO, true, "in_forceuser...");
211223
if (ConVar* ifuCVar = g_pCVar->FindVar("in_forceuser"))
212224
ifuCVar->RemoveFlags(FCVAR_CHEAT);
213-
225+
214226
Log(INFO, false, "Loaded plugin! Yay! :D");
215227
m_bPluginLoaded = true;
216228

@@ -231,18 +243,18 @@ void CP2SMPlusPlusPlugin::Unload(void)
231243
}
232244

233245
Log(INFO, false, "Unloading Plugin...");
234-
246+
235247
try
236248
{
237249
#if _WIN32
238250
Log(INFO, true, "Un-patching game patches...");
239-
251+
240252
Log(INFO, true, "Un-patching linked portal doors...");
241253
Memory::ReplacePattern("server", "EB 14 87 04 05 00 00 8B 16", "0F B6 87 04 05 00 00 8B 16");
242254

243255
Log(INFO, true, "Un-patching max runtime for VScript...");
244256
Memory::ReplacePattern("vscript", "00 00 00 00 00 00 E0 3F", "00 00 00 E0 51 B8 9E 3F");
245-
257+
246258
Log(INFO, true, "Disconnecting hooked functions and un-initializing MinHook...");
247259
MH_DisableHook(MH_ALL_HOOKS);
248260
MH_Uninitialize();
@@ -263,7 +275,7 @@ void CP2SMPlusPlusPlugin::Unload(void)
263275
Log(INFO, true, "cl_localnetworkbackdoor...");
264276
if (ConVar* lnbCVar = g_pCVar->FindVar("cl_localnetworkbackdoor"))
265277
lnbCVar->SetValue(1);
266-
278+
267279
// Cheats flag readded, disabled.
268280
Log(INFO, true, "r_drawscreenoverlay...");
269281
if (ConVar* screenCVar = g_pCVar->FindVar("r_drawscreenoverlay"))

0 commit comments

Comments
 (0)