Skip to content

Commit

Permalink
Merge pull request #552 from tiltedphoques/fix/equipment-crash
Browse files Browse the repository at this point in the history
Fix: equipment related crash
  • Loading branch information
RobbeBryssinck committed Jan 3, 2023
2 parents c359d5c + 6861bcb commit f8a4d5a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
30 changes: 1 addition & 29 deletions Code/client/Games/Skyrim/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,35 +449,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<BSRecursiveLock> _(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)
Expand Down
10 changes: 10 additions & 0 deletions Code/client/Games/Skyrim/EquipManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Code/client/Games/Skyrim/EquipManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
1 change: 1 addition & 0 deletions Code/client/Services/Debug/DebugService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ void DebugService::OnUpdate(const UpdateEvent& acUpdateEvent) noexcept
// m_world.GetOverlayService().Reload();
auto* pPlayer = PlayerCharacter::Get();
spdlog::info("{}", pPlayer->formID);
pPlayer->UnEquipAll();
}
}
else
Expand Down

0 comments on commit f8a4d5a

Please sign in to comment.