Skip to content

Commit

Permalink
add config setting to hide arms
Browse files Browse the repository at this point in the history
  • Loading branch information
sd805 committed Sep 14, 2022
1 parent 2095e39 commit 7de977e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion L4D2VR/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ SnapTurning=false
SnapTurnAngle=45.0
LeftHanded=false
VRScale=43.2
IPDScale=1.0
IPDScale=1.0
HideArms=false
1 change: 1 addition & 0 deletions L4D2VR/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Game
bool m_CachedArmsModel = false;

bool m_IsMeleeWeaponActive = false;
bool m_SwitchedWeapons = false;

Game();

Expand Down
8 changes: 5 additions & 3 deletions L4D2VR/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,12 @@ Vector *Hooks::dEyePosition(void *ecx, void *edx, Vector *eyePos)

void Hooks::dDrawModelExecute(void *ecx, void *edx, void *state, const ModelRenderInfo_t &info, void *pCustomBoneToWorld)
{
if (!m_Game->m_IsMeleeWeaponActive)
if (m_Game->m_SwitchedWeapons)
m_Game->m_CachedArmsModel = false;

bool hideArms = m_Game->m_IsMeleeWeaponActive || m_VR->m_HideArms;

if (info.pModel && m_Game->m_IsMeleeWeaponActive && !m_Game->m_CachedArmsModel)
if (info.pModel && hideArms && !m_Game->m_CachedArmsModel)
{
std::string modelName = m_Game->m_ModelInfo->GetModelName(info.pModel);
if (modelName.find("/arms/") != std::string::npos)
Expand All @@ -523,7 +525,7 @@ void Hooks::dDrawModelExecute(void *ecx, void *edx, void *state, const ModelRend
}
}

if (info.pModel && info.pModel == m_Game->m_ArmsModel && m_Game->m_IsMeleeWeaponActive)
if (info.pModel && info.pModel == m_Game->m_ArmsModel && hideArms)
{
m_Game->m_ArmsMaterial->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
m_Game->m_ModelRender->ForcedMaterialOverride(m_Game->m_ArmsMaterial);
Expand Down
12 changes: 7 additions & 5 deletions L4D2VR/sdk/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -1862,8 +1862,12 @@ class C_WeaponCSBase : public C_BaseCombatWeapon
WeaponID id = GetWeaponID();

if (this == prevWep && id == prevWeaponID)
{
g_Game->m_SwitchedWeapons = false;
return prevViewmodelOffset;
}

g_Game->m_SwitchedWeapons = true;
prevWep = this;
prevWeaponID = id;

Expand All @@ -1883,12 +1887,10 @@ class C_WeaponCSBase : public C_BaseCombatWeapon
}

if (viewmodelOffsets.find(id) != viewmodelOffsets.end())
{
prevViewmodelOffset = viewmodelOffsets[id];
return prevViewmodelOffset;
}

prevViewmodelOffset = viewmodelOffsets[NONE];
else
prevViewmodelOffset = viewmodelOffsets[NONE];

return prevViewmodelOffset;
}
};
Expand Down
1 change: 1 addition & 0 deletions L4D2VR/vr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ void VR::ParseConfigFile()
m_LeftHanded = userConfig["LeftHanded"] == "true";
m_VRScale = std::stof(userConfig["VRScale"]);
m_IpdScale = std::stof(userConfig["IPDScale"]);
m_HideArms = userConfig["HideArms"] == "true";
}

void VR::WaitForConfigUpdate()
Expand Down
1 change: 1 addition & 0 deletions L4D2VR/vr.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class VR
bool m_LeftHanded = false;
float m_VRScale = 43.2;
float m_IpdScale = 1.0;
bool m_HideArms = false;

VR() {};
VR(Game *game);
Expand Down

0 comments on commit 7de977e

Please sign in to comment.