Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b4aa6ef
feat: GetContainer() proof of concept
RobbeBryssinck Dec 23, 2021
f96ae17
feat: TESObjectREFR::AddItem()
RobbeBryssinck Dec 23, 2021
c5412d2
fix: deadlock issue with AddItem
RobbeBryssinck Dec 23, 2021
e1f7c94
tweak: null and vtables and pointers and stuff
RobbeBryssinck Dec 24, 2021
1110e42
feat: Actor::SetFullContainer()
RobbeBryssinck Dec 27, 2021
979cce9
Merge branch 'master' into feature-inventories
RobbeBryssinck Jan 22, 2022
efde771
tweak: updated TiltedReverse
RobbeBryssinck Jan 26, 2022
8935919
fix: build errors
RobbeBryssinck Jan 28, 2022
9094c8a
Merge branch 'master' into feature-inventories
RobbeBryssinck Jan 28, 2022
5fe6533
tweak: (de)serialize entries in Container struct
RobbeBryssinck Jan 28, 2022
395713a
tweak: added Container.cpp to the right folder
RobbeBryssinck Jan 28, 2022
b9751bf
tweak: further cleanup of TestService
RobbeBryssinck Jan 28, 2022
2695ed0
feat: successfully transfer inventory to dummy
RobbeBryssinck Jan 29, 2022
bdedb97
tweak: minor cleanup
RobbeBryssinck Feb 6, 2022
53c96cb
Merge branch 'master' into feature-inventories
RobbeBryssinck Feb 7, 2022
94d1dd6
Merge branch 'stability' into feature-inventories
RobbeBryssinck Feb 11, 2022
e52d8bf
fix: build error
RobbeBryssinck Feb 11, 2022
6b9264f
tweak: more hacks to make it not crash
RobbeBryssinck Feb 11, 2022
1ade122
tweak: properly handle no parsed ExtraData
RobbeBryssinck Feb 11, 2022
1c9be42
feat: sync enchantments
RobbeBryssinck Feb 11, 2022
57ed4f1
tweak: decoded EnchantmentItem struct
RobbeBryssinck Feb 11, 2022
0bc2e1b
feat: serializing custom enchantments
RobbeBryssinck Feb 12, 2022
bfdc267
fix: object, not a ptr
RobbeBryssinck Feb 12, 2022
ff9adeb
fix: forgot TESCondition
RobbeBryssinck Feb 12, 2022
001f176
tweak: properly send extra text stuff
RobbeBryssinck Feb 13, 2022
8a37d7b
tweak: improved enchantment sync
RobbeBryssinck Feb 14, 2022
ea8a9d5
tweak: dramatically cleaned up TESObjectREFR::AddItem()
RobbeBryssinck Feb 14, 2022
6bd8c51
fix: memory leak
RobbeBryssinck Feb 14, 2022
8f0cd0a
fix: build errors
RobbeBryssinck Feb 14, 2022
5af2c5a
tweak: moved container stuff to TESObjectREFR
RobbeBryssinck Feb 14, 2022
3bb8cae
tweak: network serialization for containers
RobbeBryssinck Feb 14, 2022
a0cb1f4
tweak: replaced old inventory infrastructure
RobbeBryssinck Feb 15, 2022
86319bc
fix: build fixes
RobbeBryssinck Feb 15, 2022
d2f4077
fix: serialization bugs
RobbeBryssinck Feb 17, 2022
5687a6e
tweak: restored lock
RobbeBryssinck Feb 17, 2022
de83841
tweak: EquipManager function calls
RobbeBryssinck Feb 17, 2022
7c9870b
tweak: enumerate calls to SetActorInventory()
RobbeBryssinck Feb 17, 2022
9c0b123
Merge branch 'stability' into feature-inventories
RobbeBryssinck Feb 22, 2022
bc7c73f
tweak: address lib for inventory stuff
RobbeBryssinck Feb 22, 2022
07f57c1
tweak: guard inventory change event hooks
RobbeBryssinck Feb 22, 2022
326e6bc
tweak: equip is done in Actor class
RobbeBryssinck Mar 6, 2022
c19b0f0
tweak: improved efficiency of inventory system
RobbeBryssinck Mar 9, 2022
d13b074
tweak: inventory system clean up
RobbeBryssinck Mar 9, 2022
53dcc69
tweak: further cleanup
RobbeBryssinck Mar 9, 2022
3800de2
Merge branch 'master' into feature-inventories
RobbeBryssinck Mar 9, 2022
28494fe
Merge branch 'master' into feature-inventories
RobbeBryssinck Mar 9, 2022
89b3099
Merge branch 'master' into feature-inventories
RobbeBryssinck Mar 10, 2022
3687b61
fix: SpellItem struct
RobbeBryssinck Mar 12, 2022
b614ba9
fix: temp fix for waiting spawn
RobbeBryssinck Mar 12, 2022
b63ce95
fix: health on remote actors going back up
RobbeBryssinck Mar 12, 2022
9c4e697
tweak: logging to debug new inventory system
RobbeBryssinck Mar 12, 2022
1f1b605
fix: permanent fix for waiting spawn
RobbeBryssinck Mar 12, 2022
b4fab96
fix: death bug
RobbeBryssinck Mar 12, 2022
6539d27
WIP: RemoveItem()
RobbeBryssinck Mar 14, 2022
f3c74ae
tweak: GetItemExtraData()
RobbeBryssinck Mar 14, 2022
b9a850b
tweak: refactored ugly c style casts
RobbeBryssinck Mar 14, 2022
c07cdb7
Merge branch 'master' into feature-inventories
RobbeBryssinck Mar 20, 2022
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
Prev Previous commit
Next Next commit
tweak: replaced old inventory infrastructure
  • Loading branch information
RobbeBryssinck committed Feb 15, 2022
commit a0cb1f43990be8f4513faffa165b1ed06092e733
112 changes: 0 additions & 112 deletions Code/client/Games/Skyrim/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,39 +190,6 @@ TESForm *Actor::GetCurrentLocation()
return FUNC_GetActorLocation(this);
}

Inventory Actor::GetInventory() const noexcept
{
auto& modSystem = World::Get().GetModSystem();

Inventory inventory;
inventory.Buffer = SerializeInventory();

auto pMainHandWeapon = GetEquippedWeapon(0);
uint32_t mainId = pMainHandWeapon ? pMainHandWeapon->formID : 0;
modSystem.GetServerModId(mainId, inventory.LeftHandWeapon);

auto pSecondaryHandWeapon = GetEquippedWeapon(1);
uint32_t secondaryId = pSecondaryHandWeapon ? pSecondaryHandWeapon->formID : 0;
modSystem.GetServerModId(secondaryId, inventory.RightHandWeapon);

mainId = magicItems[0] ? magicItems[0]->formID : 0;
modSystem.GetServerModId(mainId, inventory.LeftHandSpell);

secondaryId = magicItems[1] ? magicItems[1]->formID : 0;
modSystem.GetServerModId(secondaryId, inventory.RightHandSpell);

uint32_t shoutId = equippedShout ? equippedShout->formID : 0;
modSystem.GetServerModId(shoutId, inventory.Shout);

auto pAmmo = GetEquippedAmmo();
uint32_t ammoId = pAmmo ? pAmmo->formID : 0;
modSystem.GetServerModId(ammoId, inventory.Ammo);

inventory.IsWeaponDrawn = actorState.IsWeaponDrawn();

return inventory;
}

Factions Actor::GetFactions() const noexcept
{
Factions result;
Expand Down Expand Up @@ -288,85 +255,6 @@ float Actor::GetActorMaxValue(uint32_t aId) const noexcept
return actorValueOwner.GetMaxValue(aId);
}

void Actor::SetInventory(const Inventory& acInventory) noexcept
{
spdlog::info("Actor[{:X}]::SetInventory() with inventory size: {}", formID, acInventory.Buffer.size());
UnEquipAll();

auto* pEquipManager = EquipManager::Get();

if (!acInventory.Buffer.empty())
DeserializeInventory(acInventory.Buffer);

auto& modSystem = World::Get().GetModSystem();

uint32_t mainHandWeaponId = modSystem.GetGameId(acInventory.LeftHandWeapon);

if (mainHandWeaponId)
pEquipManager->Equip(this, TESForm::GetById(mainHandWeaponId), nullptr, 1, DefaultObjectManager::Get().leftEquipSlot, false, true, false, false);

uint32_t secondaryHandWeaponId = modSystem.GetGameId(acInventory.RightHandWeapon);

if (secondaryHandWeaponId)
pEquipManager->Equip(this, TESForm::GetById(secondaryHandWeaponId), nullptr, 1, DefaultObjectManager::Get().rightEquipSlot, false, true, false, false);

mainHandWeaponId = modSystem.GetGameId(acInventory.LeftHandSpell);

if (mainHandWeaponId)
pEquipManager->EquipSpell(this, TESForm::GetById(mainHandWeaponId), 0);

secondaryHandWeaponId = modSystem.GetGameId(acInventory.RightHandSpell);

if (secondaryHandWeaponId)
pEquipManager->EquipSpell(this, TESForm::GetById(secondaryHandWeaponId), 1);

uint32_t shoutId = modSystem.GetGameId(acInventory.Shout);

if (shoutId)
pEquipManager->EquipShout(this, TESForm::GetById(shoutId));

uint32_t ammoId = modSystem.GetGameId(acInventory.Ammo);

if (ammoId)
{
auto* pAmmo = TESForm::GetById(ammoId);

auto count = GetItemCountInInventory(pAmmo);

const auto pContainerChanges = GetContainerChanges()->entries;
for (auto pChange : *pContainerChanges)
{
if (pChange && pChange->form && pChange->form->formID == ammoId)
{
if (pChange->form->formID != ammoId)
continue;

const auto pDataLists = pChange->dataList;
for (auto* pDataList : *pDataLists)
{
if (pDataList)
{
if (pDataList->Contains(ExtraData::Count))
{
BSExtraData* pExtraData = pDataList->GetByType(ExtraData::Count);
ExtraCount* pExtraCount = RTTI_CAST(pExtraData, BSExtraData, ExtraCount);
if (pExtraCount)
{
pExtraCount->count = 0;
}
}
}
}
}
}

pEquipManager->Equip(this, pAmmo, nullptr, count, DefaultObjectManager::Get().rightEquipSlot, false, true, false, false);
}

// TODO: check if weapon drawn state is the same
SetWeaponDrawnEx(acInventory.IsWeaponDrawn);
}

void Actor::ForceActorValue(uint32_t aMode, uint32_t aId, float aValue) noexcept
{
const float current = GetActorValue(aId);
Expand Down
2 changes: 0 additions & 2 deletions Code/client/Games/Skyrim/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,12 @@ struct Actor : TESObjectREFR
float GetActorValue(uint32_t aId) const noexcept;
float GetActorMaxValue(uint32_t aId) const noexcept;

Inventory GetInventory() const noexcept;
Factions GetFactions() const noexcept;
ActorValues GetEssentialActorValues() const noexcept;

// Setters
void SetSpeed(float aSpeed) noexcept;
void SetLevelMod(uint32_t aLevel) noexcept;
void SetInventory(const Inventory& acInventory) noexcept;
void SetActorValue(uint32_t aId, float aValue) noexcept;
void ForceActorValue(uint32_t aMode, uint32_t aId, float aValue) noexcept;
void SetActorValues(const ActorValues& acActorValues) noexcept;
Expand Down
6 changes: 3 additions & 3 deletions Code/client/Games/Skyrim/Forms/EnchantmentItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <Magic/EffectItem.h>
#include <World.h>

EnchantmentItem* EnchantmentItem::Create(const Container::EnchantmentData& aData) noexcept
EnchantmentItem* EnchantmentItem::Create(const Inventory::EnchantmentData& aData) noexcept
{
/*
TP_THIS_FUNCTION(TCreateNewEnchantment, EnchantmentItem*, GameArray<EffectItem>, bool abIsWeapon);
Expand All @@ -22,7 +22,7 @@ EnchantmentItem* EnchantmentItem::Create(const Container::EnchantmentData& aData
effects.Resize(aData.Effects.size());
for (int i = 0; i < aData.Effects.size(); i++)
{
Container::EffectItem effect = aData.Effects[i];
Inventory::EffectItem effect = aData.Effects[i];

EffectItem effectItem{};
effectItem.data.fMagnitude = effect.Magnitude;
Expand Down Expand Up @@ -60,7 +60,7 @@ EnchantmentItem* EnchantmentItem::Create(const Container::EnchantmentData& aData
return pItem;
}

void EnchantmentItem::Init(const Container::EnchantmentData& aData)
void EnchantmentItem::Init(const Inventory::EnchantmentData& aData)
{
/*
iCostOverride = aData.CostOverride;
Expand Down
4 changes: 2 additions & 2 deletions Code/client/Games/Skyrim/Forms/EnchantmentItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

struct EnchantmentItem : MagicItem
{
static EnchantmentItem* Create(const Container::EnchantmentData& aData) noexcept;
static EnchantmentItem* Create(const Inventory::EnchantmentData& aData) noexcept;

void Init(const Container::EnchantmentData& aData);
void Init(const Inventory::EnchantmentData& aData);

int32_t iCostOverride;
int32_t iFlags;
Expand Down
62 changes: 31 additions & 31 deletions Code/client/Games/Skyrim/TESObjectREFR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ int64_t TESObjectREFR::GetItemCountInInventory(TESForm* apItem) const noexcept
return count;
}

Container TESObjectREFR::GetFullContainer() const noexcept
Inventory TESObjectREFR::GetInventory() const noexcept
{
auto& modSystem = World::Get().GetModSystem();
Container fullContainer{};
Inventory inventory{};

if (TESContainer* pBaseContainer = GetContainer())
{
Expand All @@ -167,20 +167,20 @@ Container TESObjectREFR::GetFullContainer() const noexcept
continue;
}

Container::Entry entry;
Inventory::Entry entry;
modSystem.GetServerModId(pGameEntry->form->formID, entry.BaseId);
entry.Count = pGameEntry->count;

fullContainer.Entries.push_back(std::move(entry));
inventory.Entries.push_back(std::move(entry));
}
}

Container extraContainer{};
Inventory extraInventory{};

auto pExtraContChangesEntries = GetContainerChanges()->entries;
for (auto pGameEntry : *pExtraContChangesEntries)
{
Container::Entry entry;
Inventory::Entry entry;
modSystem.GetServerModId(pGameEntry->form->formID, entry.BaseId);
entry.Count = pGameEntry->count;

Expand All @@ -189,7 +189,7 @@ Container TESObjectREFR::GetFullContainer() const noexcept
if (!pExtraDataList)
continue;

Container::Entry innerEntry;
Inventory::Entry innerEntry;
innerEntry.BaseId = entry.BaseId;
innerEntry.Count = 1;

Expand All @@ -215,7 +215,7 @@ Container TESObjectREFR::GetFullContainer() const noexcept
{
TP_ASSERT(pEffectItem, "pEffectItem is null.");

Container::EffectItem effect;
Inventory::EffectItem effect;
effect.Magnitude = pEffectItem->data.fMagnitude;
effect.Area = pEffectItem->data.iArea;
effect.Duration = pEffectItem->data.iDuration;
Expand Down Expand Up @@ -262,68 +262,68 @@ Container TESObjectREFR::GetFullContainer() const noexcept

entry.Count -= innerEntry.Count;

extraContainer.Entries.push_back(std::move(innerEntry));
extraInventory.Entries.push_back(std::move(innerEntry));
}

if (entry.Count != 0)
extraContainer.Entries.push_back(std::move(entry));
extraInventory.Entries.push_back(std::move(entry));
}

spdlog::info("ExtraContainer count: {}", extraContainer.Entries.size());
spdlog::info("ExtraInventory count: {}", extraInventory.Entries.size());

Container minimizedExtraContainer{};
Inventory minimizedExtraInventory{};

for (auto& entry : extraContainer.Entries)
for (auto& entry : extraInventory.Entries)
{
auto duplicate = std::find_if(minimizedExtraContainer.Entries.begin(), minimizedExtraContainer.Entries.end(), [entry](const Container::Entry& newEntry) {
auto duplicate = std::find_if(minimizedExtraInventory.Entries.begin(), minimizedExtraInventory.Entries.end(), [entry](const Inventory::Entry& newEntry) {
return newEntry.CanBeMerged(entry);
});

if (duplicate == std::end(minimizedExtraContainer.Entries))
if (duplicate == std::end(minimizedExtraInventory.Entries))
{
minimizedExtraContainer.Entries.push_back(entry);
minimizedExtraInventory.Entries.push_back(entry);
continue;
}

duplicate->Count += entry.Count;
}

spdlog::info("MinExtraContainer count: {}", minimizedExtraContainer.Entries.size());
spdlog::info("MinExtraInventory count: {}", minimizedExtraInventory.Entries.size());

for (auto& entry : minimizedExtraContainer.Entries)
for (auto& entry : minimizedExtraInventory.Entries)
{
if (entry.ContainsExtraData())
continue;

auto duplicate = std::find_if(fullContainer.Entries.begin(), fullContainer.Entries.end(), [entry](const Container::Entry& newEntry) {
auto duplicate = std::find_if(inventory.Entries.begin(), inventory.Entries.end(), [entry](const Inventory::Entry& newEntry) {
return newEntry.CanBeMerged(entry);
});

if (duplicate == std::end(fullContainer.Entries))
if (duplicate == std::end(inventory.Entries))
continue;

entry.Count += duplicate->Count;
duplicate->Count = 0;
}

spdlog::info("MinExtraContainer count after: {}", minimizedExtraContainer.Entries.size());
spdlog::info("MinExtraInventory count after: {}", minimizedExtraInventory.Entries.size());

fullContainer.Entries.insert(fullContainer.Entries.end(), minimizedExtraContainer.Entries.begin(),
minimizedExtraContainer.Entries.end());
inventory.Entries.insert(inventory.Entries.end(), minimizedExtraInventory.Entries.begin(),
minimizedExtraInventory.Entries.end());

spdlog::info("fullContainer count after: {}", fullContainer.Entries.size());
spdlog::info("Inventory count after: {}", inventory.Entries.size());

return fullContainer;
return inventory;
}

void TESObjectREFR::SetFullContainer(Container& acContainer) noexcept
void TESObjectREFR::SetInventory(Inventory& acContainer) noexcept
{
RemoveAllItems();

Container currentContainer = GetFullContainer();
Inventory currentContainer = GetInventory();
for (auto currentEntry : currentContainer.Entries)
{
auto duplicate = std::find_if(acContainer.Entries.begin(), acContainer.Entries.end(), [currentEntry](const Container::Entry& newEntry) {
auto duplicate = std::find_if(acContainer.Entries.begin(), acContainer.Entries.end(), [currentEntry](const Inventory::Entry& newEntry) {
return newEntry.CanBeMerged(currentEntry);
});

Expand All @@ -334,19 +334,19 @@ void TESObjectREFR::SetFullContainer(Container& acContainer) noexcept
else
{
acContainer.Entries.push_back(*duplicate);
Container::Entry& back = acContainer.Entries.back();
Inventory::Entry& back = acContainer.Entries.back();
back.Count *= -1;
}
}

for (const Container::Entry& entry : acContainer.Entries)
for (const Inventory::Entry& entry : acContainer.Entries)
{
if (entry.Count != 0)
AddItem(entry);
}
}

void TESObjectREFR::AddItem(const Container::Entry& arEntry) noexcept
void TESObjectREFR::AddItem(const Inventory::Entry& arEntry) noexcept
{
ModSystem& modSystem = World::Get().GetModSystem();

Expand Down
6 changes: 3 additions & 3 deletions Code/client/Games/Skyrim/TESObjectREFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ struct TESObjectREFR : TESForm
const float GetHeight() noexcept;
void EnableImpl() noexcept;

Container GetFullContainer() const noexcept;
void SetFullContainer(Container& acContainer) noexcept;
Inventory GetInventory() const noexcept;
void SetInventory(Inventory& acContainer) noexcept;

void AddItem(const Container::Entry& arEntry) noexcept;
void AddItem(const Inventory::Entry& arEntry) noexcept;

BSHandleRefObject handleRefObject;
uintptr_t unk1C;
Expand Down
10 changes: 5 additions & 5 deletions Code/client/Services/Debug/TestService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void __declspec(noinline) TestService::PlaceActorInWorld() noexcept

auto pActor = Actor::Create(pPlayerBaseForm);

auto container = PlayerCharacter::Get()->GetFullContainer();
spdlog::info("Container size: {}", container.Entries.size());
pActor->SetFullContainer(container);
Inventory inventory = PlayerCharacter::Get()->GetInventory();
spdlog::info("Inventory size: {}", inventory.Entries.size());
pActor->SetInventory(inventory);

m_actors.emplace_back(pActor);
}
Expand Down Expand Up @@ -104,8 +104,8 @@ void TestService::OnUpdate(const UpdateEvent& acUpdateEvent) noexcept

//PlaceActorInWorld();
Actor* pActor = RTTI_CAST(TESForm::GetById(0x1348C), TESForm, Actor);
auto container = PlayerCharacter::Get()->GetFullContainer();
pActor->SetFullContainer(container);
auto container = PlayerCharacter::Get()->GetInventory();
pActor->SetInventory(container);
}
}
else
Expand Down
Loading