Skip to content

Commit

Permalink
working player model hook demo 1 ./_/.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNULLderef committed Oct 26, 2024
1 parent fff0d53 commit d7790ee
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions p2mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ const char* CP2MMServerPlugin::GetPluginDescription(void)
const char* (__cdecl* GetBallBotModel_orig)(bool bLowRes);
const char* __cdecl GetBallBotModel_hook(bool bLowRes)
{
return "models/player/chell/player.mdl";
return "models/player/eggbot/eggbot.mdl";

if (strcmp(GFunc::GetGameMainDir(), "portal_stories") == 0)
{
return "models/portal_stories/player/mel.mdl";
Expand All @@ -240,6 +243,10 @@ const char* __cdecl GetBallBotModel_hook(bool bLowRes)
const char* (__cdecl* GetEggBotModel_orig)(bool bLowRes);
const char* __cdecl GetEggBotModel_hook(bool bLowRes)
{
return "models/player/chell/player.mdl";
return "models/player/ballbot/ballbot.mdl";


if (strcmp(GFunc::GetGameMainDir(), "portal_stories") == 0)
{
return "models/player/chell/player.mdl";
Expand All @@ -248,6 +255,11 @@ const char* __cdecl GetEggBotModel_hook(bool bLowRes)
return GetEggBotModel_orig(bLowRes);
}

const char* (__fastcall* CPortal_Player__GetPlayerModelName_orig)(CPortal_Player* thisptr);
const char* __fastcall CPortal_Player__GetPlayerModelName_hook(CPortal_Player* thisptr) {
return "models/player/chell/player.mdl";
}

//---------------------------------------------------------------------------------
// Purpose: Called when the plugin is loaded, initialization process.
// Loads the interfaces we need from the engine and applies our patches.
Expand Down Expand Up @@ -388,12 +400,20 @@ bool CP2MMServerPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterface
//MH_CreateHook((LPVOID)Memory::Scanner::Scan<void*>(Memory::Modules::Get("engine"), "55 8B EC 83 EC 08 53 56 57 8B F1 E8 ?? ?? ?? ?? 8B"), &disconnect_hook, (LPVOID*)&disconnect_orig);

// Hook onto the function which defines what Atlas's and PBody's models are.
auto serverModule = Memory::Modules::Get("server");

MH_CreateHook(
Memory::Rel32(Memory::Scanner::Scan(Memory::Modules::Get("server"), "E8 ?? ?? ?? ?? 83 C4 40 50", 1)),
Memory::Rel32(Memory::Scanner::Scan(serverModule, "E8 ?? ?? ?? ?? 83 C4 40 50", 1)),
&GetBallBotModel_hook, (void**)&GetBallBotModel_orig);
MH_CreateHook(
Memory::Rel32(Memory::Scanner::Scan(Memory::Modules::Get("server"), "E8 ?? ?? ?? ?? 83 C4 04 50 8B 45 10 8B 10", 1)),
Memory::Rel32(Memory::Scanner::Scan(serverModule, "E8 ?? ?? ?? ?? 83 C4 04 50 8B 45 10 8B 10", 1)),
&GetEggBotModel_hook, (void**)&GetEggBotModel_orig);

MH_CreateHook(
Memory::Scanner::Scan(serverModule, "55 8B EC 81 EC 10 01 00 00 53 8B 1D"),
&CPortal_Player__GetPlayerModelName_hook,
(void**)&CPortal_Player__GetPlayerModelName_orig
);

MH_EnableHook(MH_ALL_HOOKS);

Expand Down

0 comments on commit d7790ee

Please sign in to comment.