Skip to content

Commit

Permalink
Merge pull request #115 from psiberx/master
Browse files Browse the repository at this point in the history
Decoded DeferredDataBuffer and widget classes
  • Loading branch information
wopss authored Apr 10, 2024
2 parents 63fbda8 + 9775ff7 commit cdcf6f0
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 19 deletions.
12 changes: 6 additions & 6 deletions include/RED4ext/Callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ template<typename R, typename... Args>
struct CallbackHandler
{
template<typename T>
using InvokeFunc = R (*)(T* aTarget, Args&&... aArgs);
using InvokeFunc = R (*)(const T* aTarget, Args&&... aArgs);

template<typename T>
using CopyFunc = void (*)(T* aDst, T* aSrc);
Expand Down Expand Up @@ -141,9 +141,9 @@ class Callback<R (*)(Args...), InlineSize>
ResetHandler();
}

R operator()(Args&&... aArgs) const
auto operator()(Args&&... aArgs) const
{
return InvokeTarget(buffer, std::forward<Args>(aArgs)...);
return InvokeTarget(std::forward<Args>(aArgs)...);
}

uint8_t buffer[InlineSize];
Expand Down Expand Up @@ -176,7 +176,7 @@ class Callback<R (*)(Args...), InlineSize>
handler = nullptr;
}

R InvokeTarget(Args&&... aArgs) const
inline auto InvokeTarget(Args&&... aArgs) const
{
return handler->invoke(buffer, std::forward<Args>(aArgs)...);
}
Expand Down Expand Up @@ -304,7 +304,7 @@ class FlexCallback<R (*)(Args...), InlineSize>
ResetHandler();
}

R operator()(Args&&... aArgs) const
auto operator()(Args&&... aArgs) const
{
return InvokeTarget(std::forward<Args>(aArgs)...);
}
Expand Down Expand Up @@ -416,7 +416,7 @@ class FlexCallback<R (*)(Args...), InlineSize>
}
}

inline R InvokeTarget(Args&&... aArgs) const
inline auto InvokeTarget(Args&&... aArgs) const
{
return handler->invoke(GetBuffer(), std::forward<Args>(aArgs)...);
}
Expand Down
4 changes: 4 additions & 0 deletions include/RED4ext/Detail/AddressHashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,9 @@ constexpr std::uint32_t TweakDB_CreateRecord = 0x3201127A;
constexpr std::uint32_t UpdateRegistrar_RegisterGroupUpdate = 0xFD914605;
constexpr std::uint32_t UpdateRegistrar_RegisterBucketUpdate = 0x192F4EA2;
#pragma endregion

#pragma region DeferredDataBuffer
constexpr std::uint32_t DeferredDataBuffer_LoadAsync = 4125893577;
#pragma endregion
}
// clang-format on
6 changes: 3 additions & 3 deletions include/RED4ext/Detail/Callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct CallbackHandlerImpl<UnboundFunctionTarget<R, Args...>>
{
using TargetType = UnboundFunctionTarget<R, Args...>;

static R Invoke(TargetType* aTarget, Args&&... aArgs)
static R Invoke(const TargetType* aTarget, Args&&... aArgs)
{
std::invoke(aTarget->func, std::forward<Args>(aArgs)...);
}
Expand All @@ -71,7 +71,7 @@ struct CallbackHandlerImpl<MemberFunctionTarget<C, R, Args...>>
{
using TargetType = MemberFunctionTarget<C, R, Args...>;

static R Invoke(TargetType* aTarget, Args&&... aArgs)
static R Invoke(const TargetType* aTarget, Args&&... aArgs)
{
std::invoke(aTarget->func, aTarget->context, std::forward<Args>(aArgs)...);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ struct CallbackHandlerImpl<ClosureTarget<L, R, Args...>>
{
using TargetType = typename ClosureTarget<L, R, Args...>::ClosureType;

static R Invoke(TargetType* aTarget, Args&&... aArgs)
static R Invoke(const TargetType* aTarget, Args&&... aArgs)
{
(*aTarget)(std::forward<Args>(aArgs)...);
}
Expand Down
2 changes: 1 addition & 1 deletion include/RED4ext/Detail/Function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using MemberFunctionPtr = R (C::*)(Args...);

// clang-format off
template<typename T, typename R, typename... Args>
concept IsClosure = std::is_class_v<T> && requires(T t, Args... args)
concept IsClosure = std::is_class_v<T> && requires(T& t, Args&&... args)
{
{ t(std::forward<Args>(args)...) } -> std::convertible_to<R>;
};
Expand Down
26 changes: 26 additions & 0 deletions include/RED4ext/NativeTypes-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,29 @@ RED4EXT_INLINE bool RED4ext::Variant::CanBeInlined(const RED4ext::CBaseRTTIType*
{
return aType->GetSize() <= InlineSize && aType->GetAlignment() <= InlineAlignment;
}

RED4EXT_INLINE RED4ext::SharedPtr<RED4ext::DeferredDataBufferToken> RED4ext::DeferredDataBuffer::LoadAsync()
{
using LoadBufferAsync_t = JobHandle* (*)(DeferredDataBuffer*, JobHandle*, int64_t);
static UniversalRelocFunc<LoadBufferAsync_t> func(Detail::AddressHashes::DeferredDataBuffer_LoadAsync);

JobHandle loadingJob;
func(this, &loadingJob, 0);

return MakeShared<DeferredDataBufferToken>(*this, loadingJob);
}

RED4EXT_INLINE RED4ext::DeferredDataBufferToken::DeferredDataBufferToken(DeferredDataBuffer& aBuffer,
JobHandle& aJob) noexcept
: buffer(aBuffer)
, job(aJob)
{
}

RED4EXT_INLINE void RED4ext::DeferredDataBufferToken::OnLoaded(LoadedCallback&& aCallback)
{
JobQueue jobQueue;
jobQueue.Wait(job);
jobQueue.Dispatch([self = MakeShared<DeferredDataBufferToken>(*this), callback = std::move(aCallback)]()
{ callback(self->buffer); });
}
49 changes: 41 additions & 8 deletions include/RED4ext/NativeTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ RED4EXT_ASSERT_SIZE(Variant, 0x18);

struct RawBuffer
{
using AllocatorType = Memory::EngineAllocator;

void* data; // 00
uint32_t size; // 08
uint32_t alignment; // 0C
Expand All @@ -185,18 +187,49 @@ struct SharedDataBuffer
};
RED4EXT_ASSERT_SIZE(SharedDataBuffer, 0x8);

struct DeferredDataBufferToken;

enum class DeferredDataBufferState : uint8_t
{
Unloaded = 0,
Loading = 1,
Loaded = 2,
};

struct DeferredDataBuffer
{
int64_t unk00; // 00
int64_t unk08; // 08
RawBuffer buffer; // 10
int64_t unk30; // 30
int8_t unk38; // 38
int64_t unk40; // 40
int64_t unk48; // 48
int64_t unk50; // 50
SharedPtr<DeferredDataBufferToken> LoadAsync();

RawBuffer temp; // 00
SharedPtr<RawBuffer> raw; // 20
void* unk30; // 30
uint8_t unk38; // 38
uint64_t unk40; // 40
uint64_t unk48; // 48
uint32_t unk50; // 50
DeferredDataBufferState state; // 54
SharedMutex lock; // 55
uint16_t unk56; // 56
};
RED4EXT_ASSERT_SIZE(DeferredDataBuffer, 0x58);
RED4EXT_ASSERT_OFFSET(DeferredDataBuffer, raw, 0x20);
RED4EXT_ASSERT_OFFSET(DeferredDataBuffer, state, 0x54);
RED4EXT_ASSERT_OFFSET(DeferredDataBuffer, lock, 0x55);

struct DeferredDataBufferToken
{
using AllocatorType = Memory::EngineAllocator;
using LoadedCallback = Callback<void (*)(DeferredDataBuffer&)>;

DeferredDataBufferToken(DeferredDataBuffer& aBuffer, JobHandle& aJob) noexcept;
DeferredDataBufferToken(const DeferredDataBufferToken&) = default;
DeferredDataBufferToken(DeferredDataBufferToken&&) = default;

void OnLoaded(LoadedCallback&& aCallback);

DeferredDataBuffer& buffer;
JobHandle job;
};

struct gamedataLocKeyWrapper
{
Expand Down
10 changes: 10 additions & 0 deletions include/RED4ext/Scripting/Natives/Generated/ink/HUDLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

// This file is generated from the Game's Reflection data

#include <RED4ext/Scripting/Natives/inkHUDLayer.hpp>

namespace RED4ext
{
RED4EXT_ASSERT_SIZE(ink::HUDLayer, 0x200);
using inkHUDLayer = ink::HUDLayer;
} // namespace RED4ext

/*
#include <cstdint>
#include <RED4ext/Common.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/FullScreenLayer.hpp>
Expand All @@ -23,5 +32,6 @@ RED4EXT_ASSERT_SIZE(HUDLayer, 0x200);
} // namespace ink
using inkHUDLayer = ink::HUDLayer;
} // namespace RED4ext
*/

// clang-format on
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

// This file is generated from the Game's Reflection data

#include <RED4ext/Scripting/Natives/inkHudWidgetSpawnEntry.hpp>

namespace RED4ext
{
RED4EXT_ASSERT_SIZE(ink::HudWidgetSpawnEntry, 0x130);
using inkHudWidgetSpawnEntry = ink::HudWidgetSpawnEntry;
} // namespace RED4ext

/*
#include <cstdint>
#include <RED4ext/Common.hpp>
#include <RED4ext/CName.hpp>
Expand Down Expand Up @@ -59,5 +68,6 @@ RED4EXT_ASSERT_SIZE(HudWidgetSpawnEntry, 0x130);
} // namespace ink
using inkHudWidgetSpawnEntry = ink::HudWidgetSpawnEntry;
} // namespace RED4ext
*/

// clang-format on
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

// This file is generated from the Game's Reflection data

#include <RED4ext/Scripting/Natives/inkIWidgetComponentWrapper.hpp>

namespace RED4ext
{
RED4EXT_ASSERT_SIZE(ink::IWidgetComponentWrapper, 0x8);
using inkIWidgetComponentWrapper = ink::IWidgetComponentWrapper;
} // namespace RED4ext

/*
#include <cstdint>
#include <RED4ext/Common.hpp>
Expand All @@ -22,5 +31,6 @@ RED4EXT_ASSERT_SIZE(IWidgetComponentWrapper, 0x8);
} // namespace ink
using inkIWidgetComponentWrapper = ink::IWidgetComponentWrapper;
} // namespace RED4ext
*/

// clang-format on
10 changes: 10 additions & 0 deletions include/RED4ext/Scripting/Natives/Generated/ink/WorldLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

// This file is generated from the Game's Reflection data

#include <RED4ext/Scripting/Natives/inkWorldLayer.hpp>

namespace RED4ext
{
RED4EXT_ASSERT_SIZE(ink::WorldLayer, 0x1B8);
using inkWorldLayer = ink::WorldLayer;
} // namespace RED4ext

/*
#include <cstdint>
#include <RED4ext/Common.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/Layer.hpp>
Expand All @@ -23,5 +32,6 @@ RED4EXT_ASSERT_SIZE(WorldLayer, 0x1B8);
} // namespace ink
using inkWorldLayer = ink::WorldLayer;
} // namespace RED4ext
*/

// clang-format on
31 changes: 31 additions & 0 deletions include/RED4ext/Scripting/Natives/inkHUDLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <RED4ext/Common.hpp>
#include <RED4ext/JobQueue.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/FullScreenLayer.hpp>

namespace RED4ext::ink
{
struct HudWidgetSpawnEntry;
struct HudEntriesResource;
struct HUDLayerDefinition;

struct __declspec(align(0x10)) HUDLayer : ink::FullScreenLayer
{
static constexpr const char* NAME = "inkHUDLayer";
static constexpr const char* ALIAS = NAME;

DynArray<HudWidgetSpawnEntry> entries; // 150
uint64_t sceneTier; // 160
uint32_t gameContext; // 168
Ref<HudEntriesResource> resource; // 170
HUDLayerDefinition* definition; // 188
JobHandle spawningJob; // 190
SharedMutex spawningLock; // 198
uint8_t unk199[0x200 - 0x199]; // 199
};
RED4EXT_ASSERT_SIZE(HUDLayer, 0x200);
RED4EXT_ASSERT_OFFSET(HUDLayer, entries, 0x150);
RED4EXT_ASSERT_OFFSET(HUDLayer, definition, 0x188);
RED4EXT_ASSERT_OFFSET(HUDLayer, spawnLock, 0x198);
} // namespace RED4ext::ink
70 changes: 70 additions & 0 deletions include/RED4ext/Scripting/Natives/inkHudWidgetSpawnEntry.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include <RED4ext/CName.hpp>
#include <RED4ext/Common.hpp>
#include <RED4ext/NativeTypes.hpp>
#include <RED4ext/Scripting/Natives/Generated/Vector2.hpp>
#include <RED4ext/Scripting/Natives/Generated/game/ui/Context.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/EAnchor.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/Margin.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/SpawnMode.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/WidgetSlotAttachmentParams.hpp>
#include <RED4ext/Scripting/Natives/Generated/world/ui/ContextVisibility.hpp>

namespace RED4ext
{
struct DynamicTexture;

namespace ink
{
struct ImageWidget;
struct IWidgetController;
struct Widget;
struct WidgetLibraryResource;

struct HudWidgetSpawnEntry
{
static constexpr const char* NAME = "inkHudWidgetSpawnEntry";
static constexpr const char* ALIAS = NAME;

CName hudEntryName; // 00
bool enabled; // 08
uint8_t unk09[0x10 - 0x9]; // 09
world::ui::ContextVisibility contextVisibility; // 10
game::ui::Context gameContextVisibility; // 18
uint8_t unk1C[0x20 - 0x1C]; // 1C
ink::SpawnMode spawnMode; // 20
uint8_t unk24[0x28 - 0x24]; // 24
Ref<ink::WidgetLibraryResource> widgetResource; // 28
ink::EAnchor anchorPlace; // 40
uint8_t unk41[0x44 - 0x41]; // 41
Vector2 anchorPoint; // 44
ink::Margin margins; // 4C
bool attachToSlot; // 5C
uint8_t unk5D[0x60 - 0x5D]; // 5D
ink::WidgetSlotAttachmentParams slotParams; // 60
bool useSeparateWindow; // A0
bool ignoreHudSafezones; // A1
bool ignoreHudScaleOverride; // A2
uint8_t unkA3[0xA4 - 0xA3]; // A3
float hudScalingInterpolationValue; // A4
ink::Margin hudScalingMarginCorrection; // A8
Handle<DynamicTexture> slotTexture; // B8
Handle<VirtualWindow> window; // C8
Handle<ImageWidget> slotWidget; // D8
uint8_t unkE8[0xF8 - 0xE8]; // E8
Handle<Widget> rootWidget; // F8
Handle<IWidgetController> gameController; // 108
uint8_t unk110[0x127 - 0x118]; // 118
bool affectedByGlitchEffect; // 127
bool affectedByBlackwallEffect; // 128
bool spawnBeforeSlots; // 129
uint8_t unk12A[0x130 - 0x12A]; // 12A
};
RED4EXT_ASSERT_SIZE(HudWidgetSpawnEntry, 0x130);
RED4EXT_ASSERT_OFFSET(HudWidgetSpawnEntry, window, 0xC8);
RED4EXT_ASSERT_OFFSET(HudWidgetSpawnEntry, rootWidget, 0xF8);
RED4EXT_ASSERT_OFFSET(HudWidgetSpawnEntry, gameController, 0x108);
RED4EXT_ASSERT_OFFSET(HudWidgetSpawnEntry, affectedByGlitchEffect, 0x127);
} // namespace ink
} // namespace RED4ext
Loading

0 comments on commit cdcf6f0

Please sign in to comment.