Skip to content

Commit

Permalink
Decoded Several Rendering Structs & Small Adjustments (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mozz3d authored Jan 22, 2025
1 parent f292dbb commit 1e757de
Show file tree
Hide file tree
Showing 22 changed files with 624 additions and 74 deletions.
13 changes: 3 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,7 @@ one:
static constexpr const char* NAME = "vehicleBaseObject";
```

3. Remove `__declspec()` declaration:

```diff
- struct __declspec(align(0x10)) BaseObject : game::Object
+ struct BaseObject : game::Object
```

4. Declare the new member based on its offset and type:
3. Declare the new member based on its offset and type:

```diff
{
Expand All @@ -135,7 +128,7 @@ one:
};
```

5. Assert the offset of known members:
4. Assert the offset of known members:

```diff
};
Expand All @@ -149,7 +142,7 @@ using VehicleObject = vehicle::BaseObject;
} // namespace RED4ext
```

6. Remove these comments:
5. Remove these comments:

```diff
-// clang-format off
Expand Down
15 changes: 15 additions & 0 deletions include/RED4ext/Detail/AddressHashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ constexpr std::uint32_t Handle_ctor = 0xBA0C115D;
constexpr std::uint32_t Handle_DecWeakRef = 0x333B1404;
#pragma endregion

#pragma region IRenderProxy
constexpr std::uint32_t IRenderProxy_sub_00 = 302583262UL;
constexpr std::uint32_t IRenderProxy_sub_08 = 3505328647UL;
constexpr std::uint32_t IRenderProxy_sub_18 = 2756580845UL;
constexpr std::uint32_t IRenderProxy_sub_58 = 2462126272UL;
constexpr std::uint32_t IRenderProxy_sub_60 = 3491501770UL;
constexpr std::uint32_t IRenderProxy_sub_78 = 2542474580UL;
constexpr std::uint32_t IRenderProxy_sub_80 = 510274732UL;
constexpr std::uint32_t IRenderProxy_sub_88 = 3724941976UL;
constexpr std::uint32_t IRenderProxy_sub_90 = 1894391003UL;
constexpr std::uint32_t IRenderProxy_sub_98 = 3516862860UL;
constexpr std::uint32_t IRenderProxy_sub_A8 = 4096926792UL;
constexpr std::uint32_t IRenderProxy_sub_B0 = 1468405902UL;
#pragma endregion

#pragma region IScriptable
constexpr std::uint32_t IScriptable_sub_D8 = 0xF8E41DDF;
constexpr std::uint32_t IScriptable_DestructValueHolder = 0x3521331;
Expand Down
2 changes: 2 additions & 0 deletions include/RED4ext/GpuApi/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <d3d12.h>
#include <wrl/client.h>

#include <cstdint>

namespace RED4ext
{
namespace GpuApi
Expand Down
26 changes: 13 additions & 13 deletions include/RED4ext/GpuApi/CommandListContext-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@

#include <RED4ext/Relocation.hpp>

RED4EXT_INLINE void RED4ext::GpuApi::CommandListContext::AddPendingBarrier(const D3D12_RESOURCE_BARRIER& aBarrier)
namespace RED4ext::GpuApi
{
RED4EXT_INLINE void CommandListContext::AddPendingBarrier(const D3D12_RESOURCE_BARRIER& aBarrier)
{
using func_t = void (*)(CommandListContext*, const D3D12_RESOURCE_BARRIER&);
static UniversalRelocFunc<func_t> func(Detail::AddressHashes::CommandListContext_AddPendingBarrier);
static const UniversalRelocFunc<func_t> func(Detail::AddressHashes::CommandListContext_AddPendingBarrier);
func(this, aBarrier);
}

RED4EXT_INLINE void RED4ext::GpuApi::CommandListContext::Close()
RED4EXT_INLINE void CommandListContext::Close()
{
using func_t = void (*)(CommandListContext*);
static UniversalRelocFunc<func_t> func(Detail::AddressHashes::CommandListContext_Close);
static const UniversalRelocFunc<func_t> func(Detail::AddressHashes::CommandListContext_Close);
func(this);
}

RED4EXT_INLINE void RED4ext::GpuApi::CommandListContext::FlushPendingBarriers()
RED4EXT_INLINE void CommandListContext::FlushPendingBarriers()
{
using func_t = void (*)(CommandListContext*);
static UniversalRelocFunc<func_t> func(Detail::AddressHashes::CommandListContext_FlushPendingBarriers);
func(this);
}

RED4EXT_INLINE RED4ext::GpuApi::CommandListContext* AcquireFreeCommandList(RED4ext::GpuApi::CommandListType aType,
RED4ext::StringView& aDebugName,
uint64_t aHash)
RED4EXT_INLINE CommandListContext* AcquireFreeCommandList(CommandListType aType, const StringView& aDebugName,
uint64_t aHash)
{
// NOTE: This function has parameters for debug name and hash which seem to be optional.
// Expects unique ptr as an out param and returns it by reference.
using func_t = RED4ext::GpuApi::CommandListContext*& (*)(RED4ext::GpuApi::CommandListContext*&,
RED4ext::GpuApi::CommandListType,
const RED4ext::StringView&, uint64_t);
static RED4ext::UniversalRelocFunc<func_t> func(RED4ext::Detail::AddressHashes::GetFreeCommandList);
using func_t = CommandListContext*& (*)(CommandListContext*&, CommandListType, const StringView&, uint64_t);
static const UniversalRelocFunc<func_t> func(Detail::AddressHashes::GetFreeCommandList);

// TODO: This should be unique_ptr which function fills in and returns.
RED4ext::GpuApi::CommandListContext* outContext = nullptr;
CommandListContext* outContext = nullptr;
return func(outContext, aType, aDebugName, aHash);
}
} // namespace RED4ext::GpuApi
2 changes: 1 addition & 1 deletion include/RED4ext/GpuApi/D3D12MemAlloc-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RED4EXT_INLINE HRESULT D3D12MA::Allocator::CreateResource(const ALLOCATION_DESC*
{
using func_t = HRESULT (*)(Allocator*, const ALLOCATION_DESC*, const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_STATES,
const D3D12_CLEAR_VALUE*, Allocation**, REFIID, void**);
static RED4ext::UniversalRelocFunc<func_t> func(RED4ext::Detail::AddressHashes::Allocator_CreateResource);
static const RED4ext::UniversalRelocFunc<func_t> func(RED4ext::Detail::AddressHashes::Allocator_CreateResource);
return func(this, pAllocDesc, pResourceDesc, InitialResourceState, pOptimizedClearValue, ppAllocation, riidResource,
ppvResource);
}
51 changes: 4 additions & 47 deletions include/RED4ext/GpuApi/DeviceData-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,11 @@
#include <RED4ext/GpuApi/DeviceData.hpp>
#endif

template<typename T, size_t MAX_SIZE>
bool RED4ext::GpuApi::ResourceContainer<T, MAX_SIZE>::Resource::IsUsed() const
namespace RED4ext::GpuApi
{
return refCount >= 0;
}

template<typename T, size_t MAX_SIZE>
bool RED4ext::GpuApi::ResourceContainer<T, MAX_SIZE>::IsUsedID(const uint32_t id) const
{
return IsValidID(id) && resources[IDToIndex(id)].IsUsed();
}

template<typename T, size_t MAX_SIZE>
bool RED4ext::GpuApi::ResourceContainer<T, MAX_SIZE>::IsUnusedID(const uint32_t id) const
{
return IsValidID(id) && !resources[IDToIndex(id)].IsUsed();
}

template<typename T, size_t MAX_SIZE>
bool RED4ext::GpuApi::ResourceContainer<T, MAX_SIZE>::IsEmpty() const
{
assert(numUnused <= MAX_SIZE);
return numUnused == MAX_SIZE;
}

template<typename T, size_t MAX_SIZE>
bool RED4ext::GpuApi::ResourceContainer<T, MAX_SIZE>::IsFull() const
{
assert(numUnused <= MAX_SIZE);
return numUnused == 0;
}

template<typename T, size_t MAX_SIZE>
T& RED4ext::GpuApi::ResourceContainer<T, MAX_SIZE>::GetData(uint32_t id)
{
assert(IsUsedID(id));
return resources[IDToIndex(id)].instance;
}

template<typename T, size_t MAX_SIZE>
const T& RED4ext::GpuApi::ResourceContainer<T, MAX_SIZE>::GetData(uint32_t id) const
{
assert(IsUsedID(id));
return resources[IDToIndex(id)].instance;
}

RED4EXT_INLINE RED4ext::GpuApi::SDeviceData* RED4ext::GpuApi::GetDeviceData()
RED4EXT_INLINE SDeviceData* GetDeviceData()
{
static UniversalRelocPtr<SDeviceData*> dd(Detail::AddressHashes::g_DeviceData);
static const UniversalRelocPtr<SDeviceData*> dd(Detail::AddressHashes::g_DeviceData);
return dd;
}
} // namespace RED4ext::GpuApi
50 changes: 48 additions & 2 deletions include/RED4ext/GpuApi/DeviceData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace GpuApi
template<typename T, size_t MAX_SIZE>
struct ResourceContainer
{
struct Resource
struct ResourceHandle
{
bool IsUsed() const;

Expand Down Expand Up @@ -56,7 +56,7 @@ struct ResourceContainer

SpinLock& spinLockRef; // 00 - Always points to SDeviceDataBase::resourcesSpinLock.
std::atomic_int32_t numUnused; // 08 - Defaults to MaxSize.
Resource resources[MAX_SIZE];
ResourceHandle resources[MAX_SIZE];
uint16_t unusedIndices[MAX_SIZE]; // These are indices, not IDs!
};

Expand Down Expand Up @@ -94,6 +94,52 @@ RED4EXT_ASSERT_OFFSET(SDeviceData, directCommandQueue, 0x13bc4d0);
RED4EXT_ASSERT_OFFSET(SDeviceData, memoryAllocator, 0x13bc540);

SDeviceData* GetDeviceData();

template<typename T, size_t MAX_SIZE>
bool ResourceContainer<T, MAX_SIZE>::ResourceHandle::IsUsed() const
{
return refCount >= 0;
}

template<typename T, size_t MAX_SIZE>
bool ResourceContainer<T, MAX_SIZE>::IsUsedID(const uint32_t id) const
{
return IsValidID(id) && resources[IDToIndex(id)].IsUsed();
}

template<typename T, size_t MAX_SIZE>
bool ResourceContainer<T, MAX_SIZE>::IsUnusedID(const uint32_t id) const
{
return IsValidID(id) && !resources[IDToIndex(id)].IsUsed();
}

template<typename T, size_t MAX_SIZE>
bool ResourceContainer<T, MAX_SIZE>::IsEmpty() const
{
assert(numUnused <= MAX_SIZE);
return numUnused == MAX_SIZE;
}

template<typename T, size_t MAX_SIZE>
bool ResourceContainer<T, MAX_SIZE>::IsFull() const
{
assert(numUnused <= MAX_SIZE);
return numUnused == 0;
}

template<typename T, size_t MAX_SIZE>
T& ResourceContainer<T, MAX_SIZE>::GetData(uint32_t id)
{
assert(IsUsedID(id));
return resources[IDToIndex(id)].instance;
}

template<typename T, size_t MAX_SIZE>
const T& ResourceContainer<T, MAX_SIZE>::GetData(uint32_t id) const
{
assert(IsUsedID(id));
return resources[IDToIndex(id)].instance;
}
} // namespace GpuApi
} // namespace RED4ext

Expand Down
Loading

0 comments on commit 1e757de

Please sign in to comment.