Skip to content

Commit 82b603c

Browse files
committed
Fixed game_ui patch to work with latest build + moved some patches around
1 parent 2f2d573 commit 82b603c

1 file changed

Lines changed: 31 additions & 25 deletions

File tree

p2mm.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,25 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
384384
{
385385
Log(INFO, true, "Fixing linked portal doors...");
386386
Memory::ReplacePattern("server", "0F B6 87 04 05 00 00 8B 16", "EB 14 87 04 05 00 00 8B 16");
387+
388+
// Increase runtime max from 0.03 to 0.05.
389+
// Helps add some more leeway to some things we do in VScript without the engine complaining and shutting down the rest of the script.
390+
Log(INFO, true, "Patching max runtime for VScript...");
391+
Memory::ReplacePattern("vscript", "00 00 00 E0 51 B8 9E 3F", "9a 99 99 99 99 99 a9 3f");
392+
393+
// Skip a line which adds a flag to the player that screws with client side prediction for multiplayer.
394+
// TODO: Currently can not unpatch
395+
Log(INFO, true, "Fixing game_ui...");
396+
switch (m_iCurGameIndex)
397+
{
398+
case (PORTAL_2):
399+
case (DIVINITY):
400+
Memory::ReplacePattern("server", "E8 ?? ?? ?? ?? A1 ?? ?? ?? ?? F3 0F 10 40 ?? 6A 00 51 8B CE F3 0F 11 04 24 E8 ?? ?? ?? ?? 8B 87", "E9 00 00 00 00");
401+
break;
402+
default:
403+
Memory::ReplacePattern("server", "E8 ?? ?? ?? ?? 6A 00 51 8B 0D ?? ?? ?? ?? F3 0F 10 41 0C 8B CE F3 0F 11 04 24 E8 ?? ?? ?? ?? 8B 87 2C 0B 00 00", "E9 00 00 00 00");
404+
break;
405+
}
387406
}
388407

389408
// Partner disconnects.
@@ -409,16 +428,6 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
409428
Log(INFO, true, "Fixing sv_password...");
410429
Memory::ReplacePattern("engine", "0F 95 C1 51 8D 4D E8", "03 C9 90 51 8D 4D E8");
411430

412-
// Increase runtime max form 0.03 to 0.05.
413-
// Helps add some more leeway to some things we do in VScript without the engine complaining and shutting down the rest of the script.
414-
Log(INFO, true, "Patching max runtime for VScript...");
415-
Memory::ReplacePattern("vscript", "00 00 00 E0 51 B8 9E 3F", "9a 99 99 99 99 99 a9 3f");
416-
417-
// Disabling adding a flag to the player that disables prediction when using entity game_ui.
418-
// TODO: figure out how to unpatch this
419-
Log(INFO, true, "Fixing game_ui...");
420-
Memory::ReplacePattern("server", "E8 ?? ?? ?? ?? 6A 00 51 8B 0D ?? ?? ?? ?? F3 0F 10 41 0C 8B CE F3 0F 11 04 24 E8 ?? ?? ?? ?? 8B 87 2C 0B 00 00", "E9 00 00 00 00");
421-
422431
// MinHook initialization and hooking.
423432
Log(INFO, true, "Initializing MinHook and hooking functions...");
424433
MH_Initialize();
@@ -440,23 +449,20 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, const CreateInt
440449
&CPortal_Player__PlayerDeathThink_hook, reinterpret_cast<void**>(&CPortal_Player__PlayerDeathThink_orig)
441450
);
442451
}
443-
452+
453+
// UTIL_GetLocalPlayer dedicated server hook crash fix.
454+
Log(INFO, true, "Hooking UTIL_GetLocalPlayer...");
455+
MH_CreateHook(
456+
Memory::Scanner::Scan(SERVERDLL, "8B 15 ?? ?? ?? ?? 8B 4A ?? 33 C0"),
457+
&UTIL_GetLocalPlayer, reinterpret_cast<void**>(&UTIL_GetLocalPlayer_orig)
458+
);
459+
444460
// "respawn" function hook for getting a VScript "game event" call out of it.
445461
Log(INFO, true, "Hooking respawn function call...");
446462
MH_CreateHook(
447463
Memory::Scanner::Scan(SERVERDLL, "55 8B EC A1 ?? ?? ?? ?? 80 78 ?? ?? 75 ?? 80 78"),
448464
&respawn_hook, reinterpret_cast<void**>(&respawn_orig)
449465
);
450-
451-
// UTIL_GetLocalPlayer dedicated server hook crash fix.
452-
if (!this->m_bP2SMPluginLoaded)
453-
{
454-
Log(INFO, true, "Hooking UTIL_GetLocalPlayer...");
455-
MH_CreateHook(
456-
Memory::Scanner::Scan(SERVERDLL, "8B 15 ?? ?? ?? ?? 8B 4A ?? 33 C0"),
457-
&UTIL_GetLocalPlayer, reinterpret_cast<void**>(&UTIL_GetLocalPlayer_orig)
458-
);
459-
}
460466

461467
// Game-specific hooks
462468
switch (g_P2MMServerPlugin.m_iCurGameIndex)
@@ -557,6 +563,10 @@ void CP2MMServerPlugin::Unload(void)
557563
{
558564
Log(INFO, true, "Un-patching linked portal doors...");
559565
Memory::ReplacePattern("server", "EB 14 87 04 05 00 00 8B 16", "0F B6 87 04 05 00 00 8B 16");
566+
567+
// runtime max 0.05 -> 0.03
568+
Log(INFO, true, "Un-patching max runtime for VScript...");
569+
Memory::ReplacePattern("vscript", "00 00 00 00 00 00 E0 3F", "00 00 00 E0 51 B8 9E 3F");
560570
}
561571

562572
// Partner disconnects
@@ -578,10 +588,6 @@ void CP2MMServerPlugin::Unload(void)
578588
Log(INFO, true, "Unfixing sv_password...");
579589
Memory::ReplacePattern("engine", "03 C9 90 51 8D 4D E8", "0F 95 C1 51 8D 4D E8");
580590

581-
// runtime max 0.05 -> 0.03
582-
Log(INFO, true, "Un-patching max runtime for VScript...");
583-
Memory::ReplacePattern("vscript", "00 00 00 00 00 00 E0 3F", "00 00 00 E0 51 B8 9E 3F");
584-
585591
Log(INFO, true, "Disconnecting hooked functions and initializing MinHook...");
586592
MH_DisableHook(MH_ALL_HOOKS);
587593
MH_Uninitialize();

0 commit comments

Comments
 (0)