Skip to content
Merged
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
1 change: 1 addition & 0 deletions codxe.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<ClCompile Include="src\game\iw3\mp\components\cj_tas.cpp" />
<ClCompile Include="src\game\iw3\mp\components\clipmap.cpp" />
<ClCompile Include="src\game\iw3\mp\components\cmds.cpp" />
<ClCompile Include="src\game\iw3\mp\components\events.cpp" />
<ClCompile Include="src\game\iw3\mp\components\g_scr_main.cpp" />
<ClCompile Include="src\game\iw3\mp\components\gsc_client_fields.cpp" />
<ClCompile Include="src\game\iw3\mp\components\gsc_functions.cpp" />
Expand Down
12 changes: 0 additions & 12 deletions src/game/iw3/mp/components/cg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ void Menus_OpenByName_Hook(UiContext *dc, const char *menuName)
Menus_OpenByName_Detour.GetOriginal<decltype(Menus_OpenByName)>()(dc, menuName);
}

Detour CG_Init_Detour;

void CG_Init_Hook(int localClientNum, int serverMessageNum, int serverCommandSequence, int clientNum)
{
CG_Init_Detour.GetOriginal<decltype(CG_Init)>()(localClientNum, serverMessageNum, serverCommandSequence, clientNum);
cj_tas::On_CG_Init();
}

cg::cg()
{
Menus_OpenByName_Detour = Detour(Menus_OpenByName, Menus_OpenByName_Hook);
Expand Down Expand Up @@ -143,9 +135,6 @@ cg::cg()
UI_SafeTranslateString_Detour = Detour(UI_SafeTranslateString, UI_SafeTranslateString_Hook);
UI_SafeTranslateString_Detour.Install();

CG_Init_Detour = Detour(CG_Init, CG_Init_Hook);
CG_Init_Detour.Install();

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

Expand All @@ -166,7 +155,6 @@ cg::~cg()
UI_SafeTranslateString_Detour.Remove();
BG_CalculateWeaponPosition_IdleAngles_Detour.Remove();
BG_CalculateView_IdleAngles_Detour.Remove();
CG_Init_Detour.Remove();
}
} // namespace mp
} // namespace iw3
32 changes: 26 additions & 6 deletions src/game/iw3/mp/components/cj_tas.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pch.h"
#include "events.h"
#include "cj_tas.h"

#define ANGLE2SHORT(x) ((int)((x) * 65536 / 360) & 65535)
Expand Down Expand Up @@ -35,12 +36,6 @@ dvar_s *cj_tas_playback_ignore_weapon = nullptr;

unsigned int rpg_mp_index = 0;

void cj_tas::On_CG_Init()
{
// Weapon indexes change every game
rpg_mp_index = BG_FindWeaponIndexForName("rpg_mp");
}

void Cmd_Startrecord_f()
{
if (is_recording)
Expand Down Expand Up @@ -372,6 +367,15 @@ void CL_CreateNewCommands_Hook(int localClientNum)
}
}

const float colorWhiteRGBA[4] = {1.0f, 1.0f, 1.0f, 1.0f};
void CG_DrawTAS()
{
static Font_s *bigDevFont = R_RegisterFont("fonts/bigDevFont");
const float x = 10.f * scrPlaceFullUnsafe.scaleVirtualToFull[0];
const float y = 30.f;
R_AddCmdDrawText("TAS", 5, bigDevFont, x, y, 1.0, 1.0, 0.0, colorWhiteRGBA, 0);
}

cj_tas::cj_tas()
{
CL_CreateNewCommands_Detour = Detour(CL_CreateNewCommands, CL_CreateNewCommands_Hook);
Expand Down Expand Up @@ -399,6 +403,22 @@ cj_tas::cj_tas()
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(
[]()
{
if (cj_tas::TAS_Enabled())
{
CG_DrawTAS();
}
});

Events::OnCG_Init(
[]()
{
// Weapon indexes change every game
rpg_mp_index = BG_FindWeaponIndexForName("rpg_mp");
});
}

cj_tas::~cj_tas()
Expand Down
3 changes: 3 additions & 0 deletions src/game/iw3/mp/components/clipmap.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "pch.h"
#include "events.h"
#include "clipmap.h"

namespace iw3
Expand Down Expand Up @@ -123,6 +124,8 @@ clipmap::clipmap()

CM_LoadMap_Detour = Detour(CM_LoadMap, CM_LoadMap_Hook);
CM_LoadMap_Detour.Install();

Events::OnCG_DrawActive(clipmap::HandleBrushCollisionChange);
}

clipmap::~clipmap()
Expand Down
65 changes: 65 additions & 0 deletions src/game/iw3/mp/components/events.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "pch.h"
#include "events.h"

namespace iw3
{
namespace mp
{

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

void Events::CG_DrawActive_Hook(int localClientNum)
{
// Call original function first
CG_DrawActive_Detour.GetOriginal<decltype(&CG_DrawActive_Hook)>()(localClientNum);

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

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

Detour Events::CG_DrawActive_Detour;

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

void Events::CG_Init_Hook(int localClientNum, int serverMessageNum, int serverCommandSequence, int clientNum)
{
// Call original function first
CG_Init_Detour.GetOriginal<CG_Init_t>()(localClientNum, serverMessageNum, serverCommandSequence, clientNum);

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

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

Detour Events::CG_Init_Detour;

Events::Events()
{
CG_DrawActive_Detour = Detour(CG_DrawActive, CG_DrawActive_Hook);
CG_DrawActive_Detour.Install();

CG_Init_Detour = Detour(CG_Init, CG_Init_Hook);
CG_Init_Detour.Install();
}

Events::~Events()
{
CG_DrawActive_Detour.Remove();
CG_Init_Detour.Remove();
}

} // namespace mp
} // namespace iw3
34 changes: 34 additions & 0 deletions src/game/iw3/mp/components/events.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "pch.h"

namespace iw3
{
namespace mp
{

class Events : public Module
{
public:
Events();
~Events();

const char *get_name() override
{
return "Events";
};

static void OnCG_DrawActive(const std::function<void()> &callback);
static void OnCG_Init(const std::function<void()> &callback);

private:
static std::vector<std::function<void()>> cg_drawactive_callbacks;
static Detour CG_DrawActive_Detour;
static void CG_DrawActive_Hook(int localClientNum);

static std::vector<std::function<void()>> cg_init_callbacks;
static Detour CG_Init_Detour;
static void CG_Init_Hook(int localClientNum, int serverMessageNum, int serverCommandSequence, int clientNum);
};
} // namespace mp
} // namespace iw3
63 changes: 22 additions & 41 deletions src/game/iw3/mp/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "pch.h"
#include "main.h"
#include "components/cg.h"
#include "components/cj_tas.h"
#include "components/clipmap.h"
#include "components/cmds.h"
#include "components/events.h"
#include "components/g_scr_main.h"
#include "components/gsc_client_fields.h"
#include "components/gsc_functions.h"
Expand All @@ -14,6 +14,7 @@
#include "components/scr_parser.h"
#include "components/sv_bots.h"
#include "common/config.h"
#include "main.h"

// Structure to hold data for the active keyboard request
struct KeyboardRequest
Expand Down Expand Up @@ -279,14 +280,6 @@ void DrawFixedFPS()
R_AddCmdDrawText(buff, 16, font, x, y, 1.0, 1.0, 0.0, colorWhiteRGBA, 0);
}

void CG_DrawTAS()
{
static Font_s *bigDevFont = R_RegisterFont("fonts/bigDevFont");
const float x = 10.f * scrPlaceFullUnsafe.scaleVirtualToFull[0];
const float y = 30.f;
R_AddCmdDrawText("TAS", 5, bigDevFont, x, y, 1.0, 1.0, 0.0, colorWhiteRGBA, 0);
}

dvar_s *cg_draw_player_info = nullptr;

void CG_DrawPlayerInfo()
Expand All @@ -311,34 +304,6 @@ void CG_DrawPlayerInfo()
R_AddCmdDrawText(buff, 256, consoleFont, x, y, 1.0, 1.0, 0.0, colorWhiteRGBA, 0);
}

Detour CG_DrawActive_Detour;

void CG_DrawActive_Hook(int localClientNum)
{
static dvar_s *pm_fixed_fps_enable = Dvar_FindMalleableVar("pm_fixed_fps_enable");

CheckKeyboardCompletion();

if (pm_fixed_fps_enable->current.enabled)
{
DrawFixedFPS();
}

if (cj_tas::TAS_Enabled())
{
CG_DrawTAS();
}

if (cg_draw_player_info->current.enabled)
{
CG_DrawPlayerInfo();
}

clipmap::HandleBrushCollisionChange();

CG_DrawActive_Detour.GetOriginal<decltype(CG_DrawActive)>()(localClientNum);
}

Detour UI_Refresh_Detour;

void UI_Refresh_Hook(int localClientNum)
Expand Down Expand Up @@ -408,7 +373,9 @@ IW3_MP_Plugin::IW3_MP_Plugin()

DisableFastfileAuth();

// Special modules need to be registered first
RegisterModule(new Config());
RegisterModule(new Events());

RegisterModule(new cg());
RegisterModule(new cj_tas());
Expand All @@ -427,9 +394,6 @@ IW3_MP_Plugin::IW3_MP_Plugin()
UI_Refresh_Detour = Detour(UI_Refresh, UI_Refresh_Hook);
UI_Refresh_Detour.Install();

CG_DrawActive_Detour = Detour(CG_DrawActive, CG_DrawActive_Hook);
CG_DrawActive_Detour.Install();

CL_GamepadButtonEvent_Detour = Detour(CL_GamepadButtonEvent, CL_GamepadButtonEvent_Hook);
CL_GamepadButtonEvent_Detour.Install();

Expand All @@ -446,13 +410,30 @@ IW3_MP_Plugin::IW3_MP_Plugin()

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

Events::OnCG_DrawActive(
[]()
{
CheckKeyboardCompletion();

static dvar_s *pm_fixed_fps_enable = Dvar_FindMalleableVar("pm_fixed_fps_enable");

if (pm_fixed_fps_enable->current.enabled)
{
DrawFixedFPS();
}

if (cg_draw_player_info->current.enabled)
{
CG_DrawPlayerInfo();
}
});
}

IW3_MP_Plugin::~IW3_MP_Plugin()
{
DbgPrint("Shutting down MP\n");

CG_DrawActive_Detour.Remove();
CL_GamepadButtonEvent_Detour.Remove();
Load_MapEntsPtr_Detour.Remove();

Expand Down
9 changes: 5 additions & 4 deletions src/game/iw3/mp/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ static auto Cbuf_AddText = reinterpret_cast<void (*)(int localClientNum, const c
static auto Cbuf_ExecuteBuffer =
reinterpret_cast<void (*)(int localClientNum, int controllerIndex, const char *buffer)>(0x8223AAE8);

static auto CG_DrawActive = reinterpret_cast<void (*)(int localClientNum)>(0x8231E6E0);
typedef void (*CG_DrawActive_t)(int localClientNum);
static CG_DrawActive_t CG_DrawActive = reinterpret_cast<CG_DrawActive_t>(0x8231E6E0);

static auto CG_GameMessage = reinterpret_cast<void (*)(int localClientNum, const char *msg)>(0x8230AAF0);
static auto CG_GetPredictedPlayerState = reinterpret_cast<const playerState_s *(*)(int localClientNum)>(0x82309120);
static auto CG_RegisterGraphics = reinterpret_cast<void (*)(int localClientNum, const char *mapname)>(0x8230D858);
Expand Down Expand Up @@ -201,9 +203,8 @@ static auto CL_GetPredictedOriginForServerTime =
int *bobCycle, int *movementDir)>(0x822CAA38);
static auto CL_SetStance = reinterpret_cast<void (*)(int localClientNum, int stance)>(0x822D92A0);

static auto CG_Init =
reinterpret_cast<void (*)(int localClientNum, int serverMessageNum, int serverCommandSequence, int clientNum)>(
0x8230DEA0);
typedef void (*CG_Init_t)(int localClientNum, int serverMessageNum, int serverCommandSequence, int clientNum);
static CG_Init_t CG_Init = reinterpret_cast<CG_Init_t>(0x8230DEA0);

static auto Hunk_AllocateTempMemoryHighInternal = reinterpret_cast<void *(*)(int size)>(0x821D7328);
static auto Scr_AddSourceBuffer =
Expand Down