From 5d075ca674c5c380b6097aded831a16303118f13 Mon Sep 17 00:00:00 2001 From: Robbe Bryssinck Date: Sun, 27 Nov 2022 16:58:58 +0100 Subject: [PATCH] fix: equipment related crash --- Code/client/Games/Skyrim/Actor.cpp | 30 +-------------------- Code/client/Games/Skyrim/EquipManager.cpp | 10 +++++++ Code/client/Games/Skyrim/EquipManager.h | 1 + Code/client/Services/Debug/DebugService.cpp | 1 + 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/Code/client/Games/Skyrim/Actor.cpp b/Code/client/Games/Skyrim/Actor.cpp index a03f69524..96a16b3a5 100644 --- a/Code/client/Games/Skyrim/Actor.cpp +++ b/Code/client/Games/Skyrim/Actor.cpp @@ -452,35 +452,7 @@ void Actor::SetPlayerTeammate(bool aSet) noexcept void Actor::UnEquipAll() noexcept { - // For each change - const auto pContainerChanges = GetContainerChanges()->entries; - for (auto pChange : *pContainerChanges) - { - if (pChange && pChange->form && pChange->dataList) - { - // Parse all extra data lists - const auto pDataLists = pChange->dataList; - for (auto* pDataList : *pDataLists) - { - if (pDataList) - { - BSScopedLock _(pDataList->lock); - - // Right slot - if (pDataList->Contains(ExtraDataType::Worn)) - { - EquipManager::Get()->UnEquip(this, pChange->form, pDataList, 1, DefaultObjectManager::Get().rightEquipSlot, false, true, false, false, nullptr); - } - - // Left slot - if (pDataList->Contains(ExtraDataType::WornLeft)) - { - EquipManager::Get()->UnEquip(this, pChange->form, pDataList, 1, DefaultObjectManager::Get().leftEquipSlot, false, true, false, false, nullptr); - } - } - } - } - } + EquipManager::Get()->UnequipAll(this); // Taken from skyrim's code shouts can be two form types apparently if (equippedShout && ((int)equippedShout->formType - 41) <= 1) diff --git a/Code/client/Games/Skyrim/EquipManager.cpp b/Code/client/Games/Skyrim/EquipManager.cpp index 70a9d6654..d09d4941b 100644 --- a/Code/client/Games/Skyrim/EquipManager.cpp +++ b/Code/client/Games/Skyrim/EquipManager.cpp @@ -131,6 +131,16 @@ void* EquipManager::UnEquipShout(Actor* apActor, TESForm* apShout) return TiltedPhoques::ThisCall(s_unequipFunc, this, apActor, apShout); } +void EquipManager::UnequipAll(Actor* apActor) +{ + TP_THIS_FUNCTION(TUnEquipAll, void, EquipManager, Actor*); + POINTER_SKYRIMSE(TUnEquipAll, s_unequipAll, 38899); + + ScopedEquipOverride equipOverride; + + TiltedPhoques::ThisCall(s_unequipAll, this, apActor); +} + void* TP_MAKE_THISCALL(EquipHook, EquipManager, Actor* apActor, TESForm* apItem, EquipData* apData) { if (!apActor) diff --git a/Code/client/Games/Skyrim/EquipManager.h b/Code/client/Games/Skyrim/EquipManager.h index 80b527b07..0e16f22a3 100644 --- a/Code/client/Games/Skyrim/EquipManager.h +++ b/Code/client/Games/Skyrim/EquipManager.h @@ -14,4 +14,5 @@ struct EquipManager void* UnEquipSpell(Actor* apActor, TESForm* apSpell, uint32_t aSlotId); void* EquipShout(Actor* apActor, TESForm* apShout); void* UnEquipShout(Actor* apActor, TESForm* apShout); + void UnequipAll(Actor* apActor); }; diff --git a/Code/client/Services/Debug/DebugService.cpp b/Code/client/Services/Debug/DebugService.cpp index 3c9666ee4..9a8863bb8 100644 --- a/Code/client/Services/Debug/DebugService.cpp +++ b/Code/client/Services/Debug/DebugService.cpp @@ -213,6 +213,7 @@ void DebugService::OnUpdate(const UpdateEvent& acUpdateEvent) noexcept //m_world.GetOverlayService().Reload(); auto* pPlayer = PlayerCharacter::Get(); spdlog::info("{}", pPlayer->formID); + pPlayer->UnEquipAll(); } } else