Skip to content

Commit

Permalink
feat: inventory RE (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 authored Oct 20, 2023
1 parent 74656ed commit 2c844e2
Show file tree
Hide file tree
Showing 5 changed files with 413 additions and 206 deletions.
70 changes: 70 additions & 0 deletions CommonLibSF/include/RE/B/BGSInventoryInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include "RE/B/BSTArray.h"
#include "RE/B/BSTEvent.h"
#include "RE/B/BSTSingleton.h"

namespace RE
{
class BGSInventoryItem;
class TESBoundObject;

namespace InventoryInterface
{
struct FavoriteChangedEvent
{
public:
~FavoriteChangedEvent() noexcept {} // intentional

// members
BGSInventoryItem* itemAffected; // 0
};
static_assert(sizeof(FavoriteChangedEvent) == 0x8);

struct Handle
{
public:
~Handle() noexcept {} // intentional

// members
std::uint32_t id; // 0
};
static_assert(sizeof(Handle) == 0x4);
}

class BGSInventoryInterface :
BSTSingletonSDM<BGSInventoryInterface>, // 00
BSTEventSource<InventoryInterface::FavoriteChangedEvent> // 08
{
public:
struct Agent
{
public:
// members
std::uint32_t handleID; // 0
std::uint32_t itemOwner; // 4 - TESPointerHandle
std::uint16_t listIndex; // 8
std::uint16_t refCount; // A
};
static_assert(sizeof(Agent) == 0xC);

[[nodiscard]] static BGSInventoryInterface* GetSingleton()
{
REL::Relocation<BGSInventoryInterface**> singleton { ID::BGSInventoryInterface::singleton };
return *singleton;
}

[[nodiscard]] TESBoundObject* GetInventoryObject(const std::uint32_t& a_handleID) const
{
using func_t = decltype(&BGSInventoryInterface::GetInventoryObject);
REL::Relocation<func_t> func{ ID::BGSInventoryInterface::GetInventoryObject };
return func(this, a_handleID);
}

virtual ~BGSInventoryInterface(); // 00

// members
BSTArray<Agent> agentArray; // 30
};
static_assert(sizeof(BGSInventoryInterface) == 0x40);
}
45 changes: 45 additions & 0 deletions CommonLibSF/include/RE/B/BGSInventoryItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include "RE/B/BSTArray.h"
#include "RE/B/BSTSmartPointer.h"

namespace RE
{
class ExtraDataList;
class TBO_InstanceData;
class TESBoundObject;

class BGSInventoryItem
{
public:
struct Stack
{
public:
// members
BSTSmartPointer<ExtraDataList> extra; // 00
std::uint32_t unk10; // 10
};
static_assert(sizeof(Stack) == 0x10);

enum class Flag
{
kSlotIndex1 = 1 << 0,
kSlotIndex2 = 1 << 1,
kSlotIndex3 = 1 << 2,
kEquipStateLocked = 1 << 3,
kInvShouldEquip = 1 << 4,
kTemporary = 1 << 5,
kSlotMask = kSlotIndex1 | kSlotIndex2 | kSlotIndex3
};

[[nodiscard]] bool IsEquipped() const noexcept { return flags.any(Flag::kSlotMask); }

// members
TESBoundObject* object; // 00
BSTSmartPointer<TBO_InstanceData> instanceData; // 08
BSTArray<Stack> stacks; // 10
stl::enumeration<Flag, std::uint32_t> flags; // 20
std::int8_t unk24; // 24
};
static_assert(sizeof(BGSInventoryItem) == 0x28);
}
7 changes: 7 additions & 0 deletions CommonLibSF/include/RE/IDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace RE::ID
inline constexpr REL::ID GetByType{ 83208 };
}

namespace BGSInventoryInterface
{
inline constexpr REL::ID singleton{ 825787 };
inline constexpr REL::ID GetInventoryObject{ 87520 };
}

namespace BGSObjectInstance
{
inline constexpr REL::ID ctor{ 101725 };
Expand Down Expand Up @@ -222,6 +228,7 @@ namespace RE::ID
inline constexpr REL::ID HasKeyword{ 80343 };
inline constexpr REL::ID IsCrimeToActivate{ 106755 };
inline constexpr REL::ID IsInSpace{ 106767 };
inline constexpr REL::ID IsObjectEquipped{ 106991 };
inline constexpr REL::ID IsSpaceshipDocked{ 174146 };
inline constexpr REL::ID IsSpaceshipLanded{ 173880 };
}
Expand Down
Loading

0 comments on commit 2c844e2

Please sign in to comment.