Skip to content

Commit 54a01b1

Browse files
Merge pull request #60 from tiltedphoques/feature-inventories
New inventory system
2 parents decb939 + c07cdb7 commit 54a01b1

49 files changed

Lines changed: 1646 additions & 922 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#pragma once
22

3+
#include <Forms/TESForm.h>
4+
35
struct ReferenceAddedEvent
46
{
5-
explicit ReferenceAddedEvent(const uint32_t aFormId, const uint8_t aFormType)
7+
explicit ReferenceAddedEvent(const uint32_t aFormId, const FormType aFormType)
68
: FormId(aFormId)
79
, FormType(aFormType)
810
{}
911

1012
uint32_t FormId;
11-
uint8_t FormType;
13+
FormType FormType;
1214
};

Code/client/Events/ReferenceSpawnedEvent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// Not to be confused with added event, this event represents a form that the mod created
44
struct ReferenceSpawnedEvent
55
{
6-
explicit ReferenceSpawnedEvent(const uint32_t aFormId, const uint8_t aFormType, const entt::entity aEntity)
6+
explicit ReferenceSpawnedEvent(const uint32_t aFormId, const FormType aFormType, const entt::entity aEntity)
77
: FormId(aFormId)
88
, FormType(aFormType)
99
, Entity(aEntity)
1010
{}
1111

1212
uint32_t FormId;
13-
uint8_t FormType;
13+
FormType FormType;
1414
entt::entity Entity;
1515
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "BGSCreatedObjectManager.h"
2+
3+
BGSCreatedObjectManager* BGSCreatedObjectManager::Get() noexcept
4+
{
5+
POINTER_SKYRIMSE(BGSCreatedObjectManager*, pObjManager, 400320);
6+
7+
return *pObjManager.Get();
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
struct BGSCreatedObjectManager
4+
{
5+
static BGSCreatedObjectManager* Get() noexcept;
6+
};

Code/client/Games/BSAnimationGraphManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ uint64_t BSAnimationGraphManager::GetDescriptorKey(int aForceIndex)
5959
using TiltedPhoques::FHash::Crc64;
6060

6161
String variableNames{};
62+
variableNames.reserve(8192);
6263
std::map<uint32_t, const char*> variables;
6364

6465
if (animationGraphIndex < animationGraphs.size)

Code/client/Games/ExtraData.cpp

Lines changed: 0 additions & 38 deletions
This file was deleted.

Code/client/Games/ExtraData.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct BSExtraData
1313
virtual ~BSExtraData() = 0;
1414
virtual ExtraData GetType() const noexcept = 0;
1515

16-
BSExtraData* next;
16+
BSExtraData* next{};
1717

1818
#if TP_FALLOUT4
1919
uint8_t pad10[2];
@@ -28,28 +28,3 @@ static_assert(offsetof(BSExtraData, form) == 0x18);
2828
static_assert(sizeof(BSExtraData) == 0x20);
2929
#endif
3030

31-
struct BSExtraDataList
32-
{
33-
bool Contains(ExtraData aType) const;
34-
void Set(ExtraData aType, bool aSet);
35-
36-
bool Add(ExtraData aType, BSExtraData* apOther);
37-
bool Remove(ExtraData aType, BSExtraData* apOther);
38-
39-
BSExtraData* GetByType(ExtraData type) const;
40-
#if TP_FALLOUT4
41-
void* unk0;
42-
#endif
43-
BSExtraData* data;
44-
45-
struct Bitfield
46-
{
47-
uint8_t data[0x18];
48-
};
49-
#if TP_FALLOUT4
50-
void* unk10;
51-
#endif
52-
53-
Bitfield* bitfield;
54-
mutable BSRecursiveLock lock;
55-
};
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#include "ExtraDataList.h"
2+
3+
bool ExtraDataList::Contains(ExtraData aType) const
4+
{
5+
if(bitfield)
6+
{
7+
const auto value = static_cast<uint32_t>(aType);
8+
const auto index = value >> 3;
9+
10+
const auto element = bitfield->data[index];
11+
12+
return (element >> (value % 8)) & 1;
13+
}
14+
15+
return false;
16+
}
17+
18+
BSExtraData* ExtraDataList::GetByType(ExtraData aType) const
19+
{
20+
BSScopedLock<BSRecursiveLock> _(lock);
21+
22+
if (!Contains(aType))
23+
return nullptr;
24+
25+
auto pEntry = data;
26+
#if TP_SKYRIM
27+
while (pEntry != nullptr && pEntry->GetType() != aType)
28+
#else
29+
while (pEntry != nullptr && pEntry->type != aType)
30+
#endif
31+
{
32+
pEntry = pEntry->next;
33+
}
34+
35+
return pEntry;
36+
}
37+
38+
bool ExtraDataList::Add(ExtraData aType, BSExtraData* apNewData)
39+
{
40+
if (Contains(aType))
41+
return false;
42+
43+
BSScopedLock<BSRecursiveLock> _(lock);
44+
45+
BSExtraData* pNext = data;
46+
data = apNewData;
47+
apNewData->next = pNext;
48+
SetType(aType, false);
49+
50+
return true;
51+
}
52+
53+
uint32_t ExtraDataList::GetCount() const
54+
{
55+
uint32_t count = 0;
56+
57+
BSExtraData* pNext = data;
58+
while (pNext)
59+
{
60+
count++;
61+
pNext = pNext->next;
62+
}
63+
64+
return count;
65+
}
66+
67+
void ExtraDataList::SetType(ExtraData aType, bool aClear)
68+
{
69+
uint32_t index = static_cast<uint8_t>(aType) >> 3;
70+
uint8_t bitmask = 1 << (static_cast<uint8_t>(aType) % 8);
71+
uint8_t& flag = bitfield->data[index];
72+
if (aClear)
73+
flag &= ~bitmask;
74+
else
75+
flag |= bitmask;
76+
}
77+
78+
void ExtraDataList::SetSoulData(SOUL_LEVEL aSoulLevel) noexcept
79+
{
80+
TP_THIS_FUNCTION(TSetSoulData, void, ExtraDataList, SOUL_LEVEL aSoulLevel);
81+
POINTER_SKYRIMSE(TSetSoulData, setSoulData, 11620);
82+
ThisCall(setSoulData, this, aSoulLevel);
83+
}
84+
85+
void ExtraDataList::SetChargeData(float aCharge) noexcept
86+
{
87+
TP_THIS_FUNCTION(TSetChargeData, void, ExtraDataList, float aCharge);
88+
POINTER_SKYRIMSE(TSetChargeData, setChargeData, 11619);
89+
ThisCall(setChargeData, this, aCharge);
90+
}
91+
92+
void ExtraDataList::SetWorn(bool aWornLeft) noexcept
93+
{
94+
// TODO: what's this bool? seems to be true always except for one instance
95+
TP_THIS_FUNCTION(TSetWornData, void, ExtraDataList, bool aUnk1, bool aWornLeft);
96+
POINTER_SKYRIMSE(TSetWornData, setWornData, 11612);
97+
ThisCall(setWornData, this, true, aWornLeft);
98+
}
99+
100+
void ExtraDataList::SetPoison(AlchemyItem* apItem, uint32_t aCount) noexcept
101+
{
102+
TP_THIS_FUNCTION(TSetPoison, void, ExtraDataList, AlchemyItem* apItem, uint32_t aCount);
103+
POINTER_SKYRIMSE(TSetPoison, setPoison, 11822);
104+
ThisCall(setPoison, this, apItem, aCount);
105+
}
106+
107+
void ExtraDataList::SetHealth(float aHealth) noexcept
108+
{
109+
TP_THIS_FUNCTION(TSetHealth, void, ExtraDataList, float aHealth);
110+
POINTER_SKYRIMSE(TSetHealth, setHealth, 11616);
111+
ThisCall(setHealth, this, aHealth);
112+
}
113+
114+
void ExtraDataList::SetEnchantmentData(EnchantmentItem* apItem, uint16_t aCharge, bool aRemoveOnUnequip) noexcept
115+
{
116+
TP_THIS_FUNCTION(TSetEnchantmentData, void, ExtraDataList, EnchantmentItem* apItem, uint16_t aCharge, bool aRemoveOnUnequip);
117+
POINTER_SKYRIMSE(TSetEnchantmentData, setEnchantmentData, 12060);
118+
ThisCall(setEnchantmentData, this, apItem, aCharge, aRemoveOnUnequip);
119+
}

Code/client/Games/ExtraDataList.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
3+
#include <Games/ExtraData.h>
4+
#include <ExtraData/ExtraSoul.h>
5+
#include <ExtraData/ExtraCharge.h>
6+
7+
#include <Forms/AlchemyItem.h>
8+
#include <Forms/EnchantmentItem.h>
9+
10+
struct ExtraDataList
11+
{
12+
bool Contains(ExtraData aType) const;
13+
void Set(ExtraData aType, bool aSet);
14+
15+
bool Add(ExtraData aType, BSExtraData* apNewData);
16+
bool Remove(ExtraData aType, BSExtraData* apNewData);
17+
18+
uint32_t GetCount() const;
19+
20+
void SetType(ExtraData aType, bool aClear);
21+
BSExtraData* GetByType(ExtraData type) const;
22+
23+
void SetSoulData(SOUL_LEVEL aSoulLevel) noexcept;
24+
void SetChargeData(float aCharge) noexcept;
25+
void SetWorn(bool aWornLeft) noexcept;
26+
void SetPoison(AlchemyItem* apItem, uint32_t aCount) noexcept;
27+
void SetHealth(float aHealth) noexcept;
28+
void SetEnchantmentData(EnchantmentItem* apItem, uint16_t aCharge, bool aRemoveOnUnequip) noexcept;
29+
30+
#if TP_FALLOUT4
31+
void* unk0;
32+
#endif
33+
BSExtraData* data = nullptr;
34+
35+
struct Bitfield
36+
{
37+
uint8_t data[0x18];
38+
};
39+
#if TP_FALLOUT4
40+
void* unk10;
41+
#endif
42+
43+
Bitfield* bitfield{};
44+
mutable BSRecursiveLock lock{};
45+
};

Code/client/Games/Fallout4/EquipManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
struct TESForm;
4-
struct BSExtraDataList;
4+
struct ExtraDataList;
55
struct Actor;
66
struct BGSObjectInstance;
77
struct BGSEquipSlot;

0 commit comments

Comments
 (0)