Skip to content

Commit

Permalink
Merge branch 'develop' into native_rumble_support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rackover authored Oct 23, 2024
2 parents fcfd277 + 42d5277 commit 2b91dcd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/Components/Modules/Download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Download.hpp"
#include "Events.hpp"
#include "MapRotation.hpp"
#include "ModList.hpp"
#include "Node.hpp"
#include "Party.hpp"
#include "ServerInfo.hpp"
Expand Down Expand Up @@ -348,7 +349,7 @@ namespace Components

Command::Execute("closemenu mod_download_popmenu", false);

if (Dvar::Var("cl_modVidRestart").get<bool>())
if (ModList::cl_modVidRestart.get<bool>())
{
Command::Execute("vid_restart", false);
}
Expand Down
52 changes: 39 additions & 13 deletions src/Components/Modules/ModList.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <STDInclude.hpp>

#include "Events.hpp"
#include "ModList.hpp"
#include "UIFeeder.hpp"

Expand All @@ -7,6 +9,8 @@ namespace Components
std::vector<std::string> ModList::Mods;
unsigned int ModList::CurrentMod;

Dvar::Var ModList::cl_modVidRestart;

bool ModList::HasMod(const std::string& modName)
{
auto list = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").get<std::string>() + "\\mods", "", true);
Expand All @@ -22,6 +26,26 @@ namespace Components
return false;
}

void ModList::ClearMods()
{
// Clear mod sequence (make sure fs_game is actually set)
if (*Game::fs_gameDirVar == nullptr || *(*Game::fs_gameDirVar)->current.string == '\0')
{
return;
}

Game::Dvar_SetString(*Game::fs_gameDirVar, "");

if (cl_modVidRestart.get<bool>())
{
Command::Execute("vid_restart", false);
}
else
{
Command::Execute("closemenu mods_menu", false);
}
}

unsigned int ModList::GetItemCount()
{
return ModList::Mods.size();
Expand Down Expand Up @@ -60,25 +84,15 @@ namespace Components

void ModList::UIScript_ClearMods([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
{
Game::Dvar_SetString(*Game::fs_gameDirVar, "");
const_cast<Game::dvar_t*>((*Game::fs_gameDirVar))->modified = true;

if (Dvar::Var("cl_modVidRestart").get<bool>())
{
Game::Cmd_ExecuteSingleCommand(0, 0, "vid_restart");
}
else
{
Game::Cmd_ExecuteSingleCommand(0, 0, "closemenu mods_menu");
}
ClearMods();
}

void ModList::RunMod(const std::string& mod)
{
Game::Dvar_SetString(*Game::fs_gameDirVar, Utils::String::Format("mods/{}", mod));
const_cast<Game::dvar_t*>((*Game::fs_gameDirVar))->modified = true;

if (Dvar::Var("cl_modVidRestart").get<bool>())
if (cl_modVidRestart.get<bool>())
{
Command::Execute("vid_restart", false);
}
Expand All @@ -93,12 +107,24 @@ namespace Components
if (Dedicated::IsEnabled()) return;

ModList::CurrentMod = 0;
Dvar::Register("cl_modVidRestart", true, Game::DVAR_ARCHIVE, "Perform a vid_restart when loading a mod.");
cl_modVidRestart = Dvar::Register("cl_modVidRestart", true, Game::DVAR_ARCHIVE, "Perform a vid_restart when loading a mod.");

UIScript::Add("LoadMods", ModList::UIScript_LoadMods);
UIScript::Add("RunMod", ModList::UIScript_RunMod);
UIScript::Add("ClearMods", ModList::UIScript_ClearMods);

UIFeeder::Add(9.0f, ModList::GetItemCount, ModList::GetItemText, ModList::Select);

Events::OnSteamDisconnect([]() -> void
{
if (Game::cgsArray->localServer)
{
// Do not unload when exiting a private match because GH-70
// Might be okay to do when that PR and related issues are sorted out
return;
}

ClearMods();
});
}
}
4 changes: 4 additions & 0 deletions src/Components/Modules/ModList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Components
public:
ModList();

static Dvar::Var cl_modVidRestart;

static void RunMod(const std::string& mod);

private:
Expand All @@ -15,6 +17,8 @@ namespace Components

static bool HasMod(const std::string& modName);

static void ClearMods();

static unsigned int GetItemCount();
static const char* GetItemText(unsigned int index, int column);
static void Select(unsigned int index);
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Modules/Party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Download.hpp"
#include "Friends.hpp"
#include "Gamepad.hpp"
#include "ModList.hpp"
#include "Node.hpp"
#include "Party.hpp"
#include "ServerList.hpp"
Expand Down Expand Up @@ -530,7 +531,7 @@ namespace Components
{
Game::Dvar_SetString(*Game::fs_gameDirVar, "");

if (Dvar::Var("cl_modVidRestart").get<bool>())
if (ModList::cl_modVidRestart.get<bool>())
{
Command::Execute("vid_restart", false);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Modules/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ namespace Components
// Show error
pushad

push eax
push [esp + 0x20 + 0x24]
push edx
push [esp + 0x20 + 0x24 + 0x4]
push eax
call R_TextureFromCodeError
add esp, 0xC
Expand Down
31 changes: 22 additions & 9 deletions src/Components/Modules/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ namespace Components
}
}
}

void Weapon::PatchHintStrings()
{
static Game::Material* hintMaterials[WEAPON_LIMIT + 4];

// CG_RegisterWeapon
Utils::Hook::Set(0x4EF619, &hintMaterials[4]);

Utils::Hook::Set(0x58D003, hintMaterials); // CG_DrawCursorhint (All hints related to crosshair, like pickup hints)
Utils::Hook::Set(0x58969A, &hintMaterials[3]); // hint_health in CG_RegisterGraphics
Utils::Hook::Set(0x5896AB, &hintMaterials[4]); // hint_friendly in CG_RegisterGraphics

Utils::Hook::Set<uint32_t>(0x58D01C + 1, ARRAYSIZE(hintMaterials));

// Has to do with fx, but somehow lies within the material array
// EDIT: Those are unrelated (PlayFX OnTag, with FX Id, which is also in cg_media but not related to hint materials)
//Utils::Hook::Set(0x402069, &unknownMaterialArray[32]);
//Utils::Hook::Set(0x4E05D9, &unknownMaterialArray[32]);

}

void Weapon::PatchLimit()
{
Utils::Hook::Set<DWORD>(0x403783, WEAPON_LIMIT);
Expand Down Expand Up @@ -252,15 +273,7 @@ namespace Components
Utils::Hook::Set(0x59C095, cg_weaponsStaticArray);
Utils::Hook::Set(0x59C09D, cg_weaponsStaticArray);

static int unknownMaterialArray[WEAPON_LIMIT + 4];
Utils::Hook::Set(0x58D003, unknownMaterialArray);
Utils::Hook::Set(0x58969A, &unknownMaterialArray[3]);
Utils::Hook::Set(0x4EF619, &unknownMaterialArray[4]);
Utils::Hook::Set(0x5896AB, &unknownMaterialArray[4]);

// Has to do with fx, but somehow lies within the material array
//Utils::Hook::Set(0x402069, &unknownMaterialArray[32]);
//Utils::Hook::Set(0x4E05D9, &unknownMaterialArray[32]);
PatchHintStrings();

// Patch bg_weaponDefs on the stack
Utils::Hook::Set<DWORD>(0x40C31D, sizeof(bg_weaponDefs));
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Modules/Weapon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace Components

static void SaveRegisteredWeapons();

static void PatchHintStrings();

static void CG_UpdatePrimaryForAltModeWeapon_Stub();
static void CG_SelectWeaponIndex_Stub();

Expand Down

0 comments on commit 2b91dcd

Please sign in to comment.