Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New functions setWeaponRenderEnabled & isWeaponRenderEnabled #3917

Merged
merged 4 commits into from
Jan 3, 2025
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
26 changes: 26 additions & 0 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,32 @@ CWeaponStat* CGameSA::CreateWeaponStat(eWeaponType weaponType, eWeaponSkill weap
return m_pWeaponStatsManager->CreateWeaponStatUnlisted(weaponType, weaponSkill);
}

void CGameSA::SetWeaponRenderEnabled(bool enabled)
{
if (IsWeaponRenderEnabled() == enabled)
return;

if (!enabled)
{
// Disable calls to CVisibilityPlugins::RenderWeaponPedsForPC
MemSet((void*)0x53EAC4, 0x90, 5); // Idle
MemSet((void*)0x705322, 0x90, 5); // CPostEffects::Render
MemSet((void*)0x7271E3, 0x90, 5); // CMirrors::BeforeMainRender
}
else
{
// Restore original bytes
MemCpy((void*)0x53EAC4, "\xE8\x67\x44\x1F\x00", 5);
MemCpy((void*)0x705322, "\xE8\x09\xDC\x02\x00", 5);
MemCpy((void*)0x7271E3, "\xE8\x48\xBD\x00\x00", 5);
}
}

bool CGameSA::IsWeaponRenderEnabled() const
{
return *(unsigned char*)0x53EAC4 == 0xE8;
}

void CGameSA::OnPedContextChange(CPed* pPedContext)
{
m_pPedContext = pPedContext;
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ class CGameSA : public CGame
void SetupBrokenModels();
CWeapon* CreateWeapon();
CWeaponStat* CreateWeaponStat(eWeaponType weaponType, eWeaponSkill weaponSkill);
void SetWeaponRenderEnabled(bool enabled) override;
bool IsWeaponRenderEnabled() const override;
void FlushPendingRestreamIPL();
void ResetModelLodDistances();
void ResetModelFlags();
Expand Down
13 changes: 13 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3441,6 +3441,9 @@ void CClientGame::Event_OnIngame()
g_pGame->ResetAlphaTransparencies();
g_pGame->ResetModelTimes();

// Reset weapon render
g_pGame->SetWeaponRenderEnabled(true);

// Make sure we can access all areas
g_pGame->GetStats()->ModifyStat(CITIES_PASSED, 2.0);

Expand Down Expand Up @@ -6114,6 +6117,16 @@ bool CClientGame::GetBirdsEnabled()
return m_bBirdsEnabled;
}

void CClientGame::SetWeaponRenderEnabled(bool enabled)
{
g_pGame->SetWeaponRenderEnabled(enabled);
}

bool CClientGame::IsWeaponRenderEnabled() const
{
return g_pGame->IsWeaponRenderEnabled();
}

#pragma code_seg(".text")
bool CClientGame::VerifySADataFiles(int iEnableClientChecks)
{
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ class CClientGame
bool SetBirdsEnabled(bool bEnabled);
bool GetBirdsEnabled();

void SetWeaponRenderEnabled(bool enabled);
bool IsWeaponRenderEnabled() const;

void ResetWorldProperties(const ResetWorldPropsInfo& resetPropsInfo);

CTransferBox* GetTransferBox() { return m_pTransferBox; };
Expand Down
13 changes: 13 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaWeaponDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void CLuaWeaponDefs::LoadFunctions()
{"getWeaponClipAmmo", GetWeaponClipAmmo},
{"setWeaponAmmo", SetWeaponAmmo},
{"setWeaponClipAmmo", SetWeaponClipAmmo},
{"setWeaponRenderEnabled", ArgumentParser<SetWeaponRenderEnabled>},
{"isWeaponRenderEnabled", ArgumentParser<IsWeaponRenderEnabled>}
};

// Add functions
Expand Down Expand Up @@ -979,3 +981,14 @@ int CLuaWeaponDefs::GetOriginalWeaponProperty(lua_State* luaVM)
lua_pushboolean(luaVM, false);
return 1;
}

bool CLuaWeaponDefs::SetWeaponRenderEnabled(bool enabled)
{
g_pClientGame->SetWeaponRenderEnabled(enabled);
return true;
}

bool CLuaWeaponDefs::IsWeaponRenderEnabled()
{
return g_pClientGame->IsWeaponRenderEnabled();
}
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaWeaponDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#pragma once
#include "CLuaDefs.h"
#include <lua/CLuaFunctionParser.h>

class CLuaWeaponDefs : public CLuaDefs
{
Expand Down Expand Up @@ -41,4 +42,6 @@ class CLuaWeaponDefs : public CLuaDefs
LUA_DECLARE(GetWeaponClipAmmo);
LUA_DECLARE(SetWeaponAmmo);
LUA_DECLARE(SetWeaponClipAmmo);
static bool SetWeaponRenderEnabled(bool enabled);
static bool IsWeaponRenderEnabled();
};
3 changes: 3 additions & 0 deletions Client/sdk/game/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ class __declspec(novtable) CGame
virtual CWeapon* CreateWeapon() = 0;
virtual CWeaponStat* CreateWeaponStat(eWeaponType weaponType, eWeaponSkill weaponSkill) = 0;

virtual void SetWeaponRenderEnabled(bool enabled) = 0;
virtual bool IsWeaponRenderEnabled() const = 0;

virtual bool VerifySADataFileNames() = 0;
virtual bool PerformChecks() = 0;
virtual int& GetCheckStatus() = 0;
Expand Down
Loading