Skip to content

Commit 94ce86e

Browse files
committed
Fix random grass particles due to sheathed weapons being active
1 parent 985d371 commit 94ce86e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/hooking/camera.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,13 +734,13 @@ void CemuHooks::hook_EndCameraSide(PPCInterpreter_t* hCPU) {
734734

735735
// todo: sometimes this can deadlock apparently?
736736
if (VRManager::instance().XR->GetRenderer()->IsInitialized() && side == OpenXR::EyeSide::RIGHT) {
737-
CemuHooks::m_heldWeaponsLastUpdate[0] = CemuHooks::m_heldWeaponsLastUpdate[0]++;
738-
CemuHooks::m_heldWeaponsLastUpdate[1] = CemuHooks::m_heldWeaponsLastUpdate[1]++;
739-
if (CemuHooks::m_heldWeaponsLastUpdate[0] >= 6) {
740-
CemuHooks::m_heldWeapons[0] = 0;
737+
m_heldWeaponsLastUpdate[0]++;
738+
m_heldWeaponsLastUpdate[1]++;
739+
if (m_heldWeaponsLastUpdate[0] >= 6) {
740+
m_heldWeapons[0] = 0;
741741
}
742-
if (CemuHooks::m_heldWeaponsLastUpdate[1] >= 6) {
743-
CemuHooks::m_heldWeapons[1] = 0;
742+
if (m_heldWeaponsLastUpdate[1] >= 6) {
743+
m_heldWeapons[1] = 0;
744744
}
745745
}
746746

src/hooking/weapon.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ void CemuHooks::hook_EnableWeaponAttackSensor(PPCInterpreter_t* hCPU) {
389389
return;
390390
}
391391

392+
// Weapons not currently bound to a VR hand (e.g. sheathed on back) must never
393+
// have their attack sensor activated, otherwise they cut grass / hit NPCs.
394+
bool isHandBoundWeapon = (weaponPtr == m_heldWeapons[0] || weaponPtr == m_heldWeapons[1]);
392395

393396
//AttackSensorInitArg arg = weapon.setupAttackSensor;
394397
//std::string attackSensorInitStr;
@@ -426,7 +429,7 @@ void CemuHooks::hook_EnableWeaponAttackSensor(PPCInterpreter_t* hCPU) {
426429

427430
// Use the analysed motion to determine whether the weapon is swinging or stabbing, and whether the attackSensor should be active this frame
428431
bool CHEAT_alwaysEnableWeaponCollision = false;
429-
if (isHeldByPlayer && (m_motionAnalyzers[heldIndex].IsAttacking() || CHEAT_alwaysEnableWeaponCollision)) {
432+
if (isHandBoundWeapon && isHeldByPlayer && (m_motionAnalyzers[heldIndex].IsAttacking() || CHEAT_alwaysEnableWeaponCollision)) {
430433
m_motionAnalyzers[heldIndex].SetHitboxEnabled(true);
431434
//Log::print("!! Activate sensor for {}: isHeldByPlayer={}, weaponType={}", heldIndex, isHeldByPlayer, (int)weaponType);
432435
weapon.setupAttackSensor.resetAttack = 1;
@@ -459,7 +462,7 @@ void CemuHooks::hook_EnableWeaponAttackSensor(PPCInterpreter_t* hCPU) {
459462

460463
writeMemory(weaponPtr, &weapon);
461464
}
462-
else if (m_motionAnalyzers[heldIndex].IsHitboxEnabled()) {
465+
else if (!isHandBoundWeapon || m_motionAnalyzers[heldIndex].IsHitboxEnabled()) {
463466
m_motionAnalyzers[heldIndex].SetHitboxEnabled(false);
464467
//Log::print("!! Deactivate sensor for {}: isHeldByPlayer={}, weaponType={}", heldIndex, isHeldByPlayer, (int)weaponType);
465468

0 commit comments

Comments
 (0)