Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions codxe.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@
<ClCompile Include="src\game\t4\mp\components\branding.cpp" />
<ClCompile Include="src\game\t4\mp\components\brush_collision.cpp" />
<ClCompile Include="src\game\t4\mp\components\cg.cpp" />
<ClCompile Include="src\game\t4\mp\components\events.cpp" />
<ClCompile Include="src\game\t4\mp\components\gsc_client_fields.cpp" />
<ClCompile Include="src\game\t4\mp\components\gsc_client_methods.cpp" />
<ClCompile Include="src\game\t4\mp\components\gsc_functions.cpp" />
<ClCompile Include="src\game\t4\mp\components\gsc_loader.cpp" />
<ClCompile Include="src\game\t4\mp\components\image_loader.cpp" />
<ClCompile Include="src\game\t4\mp\components\map.cpp" />
<ClCompile Include="src\game\t4\mp\components\test_module.cpp" />
<ClCompile Include="src\game\t4\mp\components\ui.cpp" />

<ClCompile Include="src\game\t4\sp\components\clipmap.cpp" />
Expand Down Expand Up @@ -228,13 +228,13 @@
<ClInclude Include="src\game\t4\mp\components\branding.h" />
<ClInclude Include="src\game\t4\mp\components\brush_collision.h" />
<ClInclude Include="src\game\t4\mp\components\cg.h" />
<ClInclude Include="src\game\t4\mp\components\events.h" />
<ClInclude Include="src\game\t4\mp\components\gsc_client_fields.h" />
<ClInclude Include="src\game\t4\mp\components\gsc_client_methods.h" />
<ClInclude Include="src\game\t4\mp\components\gsc_functions.h" />
<ClInclude Include="src\game\t4\mp\components\gsc_loader.h" />
<ClInclude Include="src\game\t4\mp\components\image_loader.h" />
<ClInclude Include="src\game\t4\mp\components\map.h" />
<ClInclude Include="src\game\t4\mp\components\test_module.h" />
<ClInclude Include="src\game\t4\mp\components\ui.h" />

<ClInclude Include="src\game\t4\sp\components\clipmap.h" />
Expand Down Expand Up @@ -275,4 +275,4 @@
<ClInclude Include="src\plugin.h" />
<ClInclude Include="src\xbox360.h" />
</ItemGroup>
</Project>
</Project>
46 changes: 42 additions & 4 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
#include "pch.h"
#include "plugin_manager.h"

PluginManager *g_plugin_manager = nullptr;
typedef void (*XexpFinishExecutableLoad_t)(PLDR_DATA_TABLE_ENTRY module, const char *commandLine);
static XexpFinishExecutableLoad_t XexpFinishExecutableLoad = reinterpret_cast<XexpFinishExecutableLoad_t>(0x8009F340);

static PluginManager *g_plugin_manager = nullptr;
static Detour XexpFinishExecutableLoad_Detour;

void XexpFinishExecutableLoad_Hook(PLDR_DATA_TABLE_ENTRY module, const char *commandLine)
{
if (g_plugin_manager != nullptr)
{
g_plugin_manager->OnExecutableLoaded(module, commandLine);
}

XexpFinishExecutableLoad_Detour.GetOriginal<XexpFinishExecutableLoad_t>()(module, commandLine);
}

bool DllMain(HANDLE hModule, DWORD reason, LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(hModule);
UNREFERENCED_PARAMETER(lpvReserved);

if (reason == DLL_PROCESS_ATTACH)
{
if (g_plugin_manager != nullptr)
{
DbgPrint("[codxe] DLL_PROCESS_ATTACH: Already initialized, skipping.\n");
DbgPrint("[codxe] DLL_PROCESS_ATTACH: PluginManager already initialized.\n");
return TRUE;
}
DbgPrint("[codxe] DLL_PROCESS_ATTACH: Initializing PluginManager...\n");

DbgPrint("[codxe] DLL_PROCESS_ATTACH: Creating PluginManager.\n");
g_plugin_manager = new PluginManager();

if (xbox::IsXenia())
{
DbgPrint("[codxe] DLL_PROCESS_ATTACH: Xenia detected, skipping XexpFinishExecutableLoad hook.\n");
return TRUE;
}

DbgPrint("[codxe] DLL_PROCESS_ATTACH: Installing XexpFinishExecutableLoad hook.\n");
XexpFinishExecutableLoad_Detour = Detour(XexpFinishExecutableLoad, XexpFinishExecutableLoad_Hook);
if (!XexpFinishExecutableLoad_Detour.Install())
{
DbgPrint("[codxe] DLL_PROCESS_ATTACH: Failed to install XexpFinishExecutableLoad hook.\n");
}
}
else if (reason == DLL_PROCESS_DETACH)
{
DbgPrint("[codxe] DLL_PROCESS_DETACH: Cleaning up PluginManager...\n");
DbgPrint("[codxe] DLL_PROCESS_DETACH: Shutting down.\n");

if (!xbox::IsXenia())
{
XexpFinishExecutableLoad_Detour.Remove();
}

delete g_plugin_manager;
g_plugin_manager = nullptr;
}

return TRUE;
Expand Down
1 change: 0 additions & 1 deletion src/game/iw2/mp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace mp

IW2_MP_Plugin::IW2_MP_Plugin()
{
DbgPrint("IW2 MP Plugin initialized\n");
RegisterModule(new Config());
RegisterModule(new g_scr_main());
RegisterModule(new scr_parser());
Expand Down
3 changes: 1 addition & 2 deletions src/game/iw2/sp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ namespace sp

IW2_SP_Plugin::IW2_SP_Plugin()
{
DbgPrint("IW2 SP Plugin initialized\n");
RegisterModule(new Config());
this->RegisterModule(new scr_parser());
RegisterModule(new scr_parser());
}

IW2_SP_Plugin::~IW2_SP_Plugin()
Expand Down
65 changes: 35 additions & 30 deletions src/game/iw3/mp/components/cg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,46 @@ void CG_DrawPlayerInfo()

cg::cg()
{
Events::OnDvarInit(
[]
{
// Default to true for idle gun sway
// This is the default behavior in the original game.
bg_bobIdle = Dvar_RegisterBool("bg_bobIdle", true, 0, "Idle gun sway");

Dvar_RegisterBool("r_drawDynEnts", true, 0, "Draw dynamic entities");

cg_scoreboardLabel_Score = Dvar_RegisterString("cg_scoreboardLabel_Score", "", DVAR_FLAG_NONE,
"Override label for 'Score' column on scoreboard");

cg_scoreboardLabel_Kills = Dvar_RegisterString("cg_scoreboardLabel_Kills", "", DVAR_FLAG_NONE,
"Override label for 'Kills' column on scoreboard");

cg_scoreboardLabel_Assists = Dvar_RegisterString("cg_scoreboardLabel_Assists", "", DVAR_FLAG_NONE,
"Override label for 'Assists' column on scoreboard");

cg_scoreboardLabel_Deaths = Dvar_RegisterString("cg_scoreboardLabel_Deaths", "", DVAR_FLAG_NONE,
"Override label for 'Deaths' column on scoreboard");

cg_draw_player_info = Dvar_RegisterBool("cg_draw_player_info", false, 0,
"Draw player info (origin, viewangles, speed) on screen");
});

Events::OnCG_DrawActive(
[]()
{
if (cg_draw_player_info->current.enabled)
{
CG_DrawPlayerInfo();
}
});

Menus_OpenByName_Detour = Detour(Menus_OpenByName, Menus_OpenByName_Hook);
Menus_OpenByName_Detour.Install();

UI_DrawBuildNumber_Detour = Detour(UI_DrawBuildNumber, UI_DrawBuildNumber_Hook);
UI_DrawBuildNumber_Detour.Install();

// Default to true for idle gun sway
// This is the default behavior in the original game.
bg_bobIdle = Dvar_RegisterBool("bg_bobIdle", true, 0, "Idle gun sway");

BG_CalculateWeaponPosition_IdleAngles_Detour =
Detour(BG_CalculateWeaponPosition_IdleAngles, BG_CalculateWeaponPosition_IdleAngles_Hook);
BG_CalculateWeaponPosition_IdleAngles_Detour.Install();
Expand All @@ -167,34 +197,8 @@ cg::cg()
R_DrawAllDynEnt_Detour = Detour(R_DrawAllDynEnt, R_DrawAllDynEnt_Hook);
R_DrawAllDynEnt_Detour.Install();

Dvar_RegisterBool("r_drawDynEnts", true, 0, "Draw dynamic entities");

UI_SafeTranslateString_Detour = Detour(UI_SafeTranslateString, UI_SafeTranslateString_Hook);
UI_SafeTranslateString_Detour.Install();

cg_scoreboardLabel_Score = Dvar_RegisterString("cg_scoreboardLabel_Score", "", DVAR_FLAG_NONE,
"Override label for 'Score' column on scoreboard");

cg_scoreboardLabel_Kills = Dvar_RegisterString("cg_scoreboardLabel_Kills", "", DVAR_FLAG_NONE,
"Override label for 'Kills' column on scoreboard");

cg_scoreboardLabel_Assists = Dvar_RegisterString("cg_scoreboardLabel_Assists", "", DVAR_FLAG_NONE,
"Override label for 'Assists' column on scoreboard");

cg_scoreboardLabel_Deaths = Dvar_RegisterString("cg_scoreboardLabel_Deaths", "", DVAR_FLAG_NONE,
"Override label for 'Deaths' column on scoreboard");

cg_draw_player_info =
Dvar_RegisterBool("cg_draw_player_info", false, 0, "Draw player info (origin, viewangles, speed) on screen");

Events::OnCG_DrawActive(
[]()
{
if (cg_draw_player_info->current.enabled)
{
CG_DrawPlayerInfo();
}
});
}

cg::~cg()
Expand All @@ -204,6 +208,7 @@ cg::~cg()
UI_SafeTranslateString_Detour.Remove();
BG_CalculateWeaponPosition_IdleAngles_Detour.Remove();
BG_CalculateView_IdleAngles_Detour.Remove();
R_DrawAllDynEnt_Detour.Remove();
}
} // namespace mp
} // namespace iw3
41 changes: 25 additions & 16 deletions src/game/iw3/mp/components/cj_tas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,28 +378,37 @@ cj_tas::cj_tas()
CL_CreateNewCommands_Detour = Detour(CL_CreateNewCommands, CL_CreateNewCommands_Hook);
CL_CreateNewCommands_Detour.Install();

Cmd_AddCommandInternal("startrecord", Cmd_Startrecord_f, &Cmd_Startrecord_VAR);
Cmd_AddCommandInternal("stoprecord", Cmd_Stoprecord_f, &Cmd_Stoprecord_VAR);
Cmd_AddCommandInternal("togglerecord", Cmd_Togglerecord_f, &Cmd_Togglerecord_VAR);
Cmd_AddCommandInternal("startplayback", Cmd_Startplayback_f, &Cmd_Startplayback_VAR);
Cmd_AddCommandInternal("stopplayback", Cmd_Stopplayback_f, &Cmd_Stopplayback_VAR);
Events::OnCmdInit(
[]()
{
Cmd_AddCommandInternal("startrecord", Cmd_Startrecord_f, &Cmd_Startrecord_VAR);
Cmd_AddCommandInternal("stoprecord", Cmd_Stoprecord_f, &Cmd_Stoprecord_VAR);
Cmd_AddCommandInternal("togglerecord", Cmd_Togglerecord_f, &Cmd_Togglerecord_VAR);
Cmd_AddCommandInternal("startplayback", Cmd_Startplayback_f, &Cmd_Startplayback_VAR);
Cmd_AddCommandInternal("stopplayback", Cmd_Stopplayback_f, &Cmd_Stopplayback_VAR);
});

cj_tas_playback_ignore_weapon =
Dvar_RegisterBool("cj_tas_playback_ignore_weapon", false, 0, "Ignore weapon in playback");
Events::OnDvarInit(
[]
{
cj_tas_playback_ignore_weapon =
Dvar_RegisterBool("cj_tas_playback_ignore_weapon", false, 0, "Ignore weapon in playback");

cj_tas_bhop_auto = Dvar_RegisterBool("cj_tas_bhop_auto", false, 0, "Enable automatic bunny hopping");
cj_tas_bhop_auto = Dvar_RegisterBool("cj_tas_bhop_auto", false, 0, "Enable automatic bunny hopping");

cj_tas_jump_at_edge = Dvar_RegisterBool("cj_tas_jump_at_edge", false, 0, "Enable jump at edge");
cj_tas_jump_at_edge = Dvar_RegisterBool("cj_tas_jump_at_edge", false, 0, "Enable jump at edge");

cj_tas_jump_on_rpg_fire =
Dvar_RegisterBool("cj_tas_jump_on_rpg_fire", false, 0, "Jump exactly when firing the RPG");
cj_tas_jump_on_rpg_fire =
Dvar_RegisterBool("cj_tas_jump_on_rpg_fire", false, 0, "Jump exactly when firing the RPG");

cj_tas_crouch_on_jump = Dvar_RegisterBool("cj_tas_crouch_on_jump", false, 0, "Enable crouch on jump");
cj_tas_crouch_on_jump = Dvar_RegisterBool("cj_tas_crouch_on_jump", false, 0, "Enable crouch on jump");

cj_tas_rpg_lookdown = Dvar_RegisterBool("cj_tas_rpg_lookdown", false, 0, "Enable RPG lookdown");
cj_tas_rpg_lookdown_yaw = Dvar_RegisterInt("cj_tas_rpg_lookdown_yaw", 0, -180, 180, 0, "RPG lookdown yaw angle");
cj_tas_rpg_lookdown_pitch =
Dvar_RegisterInt("cj_tas_rpg_lookdown_pitch", 70, -70, 70, 0, "RPG lookdown pitch angle");
cj_tas_rpg_lookdown = Dvar_RegisterBool("cj_tas_rpg_lookdown", false, 0, "Enable RPG lookdown");
cj_tas_rpg_lookdown_yaw =
Dvar_RegisterInt("cj_tas_rpg_lookdown_yaw", 0, -180, 180, 0, "RPG lookdown yaw angle");
cj_tas_rpg_lookdown_pitch =
Dvar_RegisterInt("cj_tas_rpg_lookdown_pitch", 70, -70, 70, 0, "RPG lookdown pitch angle");
});

Events::OnCG_DrawActive(
[]()
Expand Down
9 changes: 6 additions & 3 deletions src/game/iw3/mp/components/clipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ void clipmap::HandleBrushCollisionChange()

clipmap::clipmap()
{
noclip_brushes = Dvar_RegisterString("noclip_brushes", "", DVAR_CODINFO,
"Space separated list of brushes to disable collision on.");

Events::OnDvarInit(
[]
{
noclip_brushes = Dvar_RegisterString("noclip_brushes", "", DVAR_CODINFO,
"Space separated list of brushes to disable collision on.");
});
Events::OnCG_Init(SaveBrushContents);
Events::OnCG_DrawActive(clipmap::HandleBrushCollisionChange);
}
Expand Down
3 changes: 2 additions & 1 deletion src/game/iw3/mp/components/cmds.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pch.h"
#include "events.h"
#include "cmds.h"

namespace iw3
Expand Down Expand Up @@ -143,7 +144,7 @@ cmds::cmds()
Cmd_ExecFromFastFile_Detour = Detour(Cmd_ExecFromFastFile, Cmd_ExecFromFastFile_Hook);
Cmd_ExecFromFastFile_Detour.Install();

Cmd_AddCommandInternal("dumpraw", Cmd_Dumpraw_f, &Cmd_Dumpraw_f_VAR);
Events::OnCmdInit([]() { Cmd_AddCommandInternal("dumpraw", Cmd_Dumpraw_f, &Cmd_Dumpraw_f_VAR); });
}

cmds::~cmds()
Expand Down
57 changes: 54 additions & 3 deletions src/game/iw3/mp/components/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ namespace iw3
namespace mp
{

typedef void (*Scr_ShutdownSystem_t)(unsigned __int8 sys, int bComplete);
static Scr_ShutdownSystem_t Scr_ShutdownSystem = reinterpret_cast<Scr_ShutdownSystem_t>(0x82211FD0);

std::vector<std::function<void()>> Events::cg_drawactive_callbacks;

void Events::CG_DrawActive_Hook(int localClientNum)
Expand Down Expand Up @@ -69,6 +66,50 @@ void Events::OnVMShutdown(const std::function<void()> &callback)

Detour Events::Scr_ShutdownSystem_Detour;

std::vector<std::function<void()>> Events::dvarinit_callbacks;

void Events::Com_InitDvars_Hook()
{
for (auto it = dvarinit_callbacks.begin(); it != dvarinit_callbacks.end(); ++it)
{
(*it)();
}

dvarinit_callbacks.clear();

// Call original function after callbacks
Com_InitDvars_Detour.GetOriginal<Com_InitDvars_t>()();
}

void Events::OnDvarInit(const std::function<void()> &callback)
{
dvarinit_callbacks.emplace_back(callback);
}

Detour Events::Com_InitDvars_Detour;

std::vector<std::function<void()>> Events::cmdinit_callbacks;

void __fastcall Events::Cmd_Init_Hook()
{
// Call original function first so the command subsystem is ready.
Cmd_Init_Detour.GetOriginal<Cmd_Init_t>()();

for (auto it = cmdinit_callbacks.begin(); it != cmdinit_callbacks.end(); ++it)
{
(*it)();
}

cmdinit_callbacks.clear();
}

void Events::OnCmdInit(const std::function<void()> &callback)
{
cmdinit_callbacks.emplace_back(callback);
}

Detour Events::Cmd_Init_Detour;

Events::Events()
{
CG_DrawActive_Detour = Detour(CG_DrawActive, CG_DrawActive_Hook);
Expand All @@ -79,17 +120,27 @@ Events::Events()

Scr_ShutdownSystem_Detour = Detour(Scr_ShutdownSystem, Scr_ShutdownSystem_Hook);
Scr_ShutdownSystem_Detour.Install();

Com_InitDvars_Detour = Detour(Com_InitDvars, Com_InitDvars_Hook);
Com_InitDvars_Detour.Install();

Cmd_Init_Detour = Detour(Cmd_Init, Cmd_Init_Hook);
Cmd_Init_Detour.Install();
}

Events::~Events()
{
CG_DrawActive_Detour.Remove();
CG_Init_Detour.Remove();
Scr_ShutdownSystem_Detour.Remove();
Com_InitDvars_Detour.Remove();
Cmd_Init_Detour.Remove();

cg_drawactive_callbacks.clear();
cg_init_callbacks.clear();
vmshutdown_callbacks.clear();
dvarinit_callbacks.clear();
cmdinit_callbacks.clear();
}

} // namespace mp
Expand Down
Loading
Loading