Skip to content

Commit

Permalink
Merge pull request #90 from psiberx/feature/patch-2.0
Browse files Browse the repository at this point in the history
Patch 2.0
  • Loading branch information
wopss authored Sep 27, 2023
2 parents 0365b61 + 9a4eaa0 commit c75d32b
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 40 deletions.
11 changes: 6 additions & 5 deletions include/RED4ext/Addresses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,17 @@ constexpr uintptr_t ISerializable_sub_A0 = 0x1409F3728 - ImageBase; // 48 83 EC
constexpr uintptr_t ISerializable_sub_C0 = 0x140390FBC - ImageBase; // 40 53 48 83 EC ? 48 8B DA E8 ? ? ? ? 48 85 C0, expected: 17, index: 0
#pragma endregion

#pragma region JobDispatcher
constexpr uintptr_t JobDispatcher = 0x1432FE3F0 - ImageBase; // 48 89 05 ? ? ? ? 48 83 C4 ? 5F C3, expected: 6, index: 3, offset: 3
constexpr uintptr_t JobDispatcher_DispatchJob = 0x140157368 - ImageBase; // 48 8B C4 48 89 58 ? 48 89 68 ? 48 89 70 ? 44 88 40 ? 57 41 54 41 55, expected: 2, index: 0
#pragma endregion

#pragma region JobHandle
constexpr uintptr_t JobHandle_ctor = 0x140158DEC - ImageBase; // 48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 41 54 48 83 EC ?, expected: 1, index: 0
constexpr uintptr_t JobHandle_dtor = 0x1401587D4 - ImageBase; // 40 53 48 83 EC ? 48 8B 11 48 8B D9 48 85 D2, expected: 6, index: 0
constexpr uintptr_t JobHandle_Join = 0x140156B4C - ImageBase; // 48 83 EC ? 48 8B 02 4C 8B C2 8B 40 ?, expected: 1, index: 0
#pragma endregion

#pragma region JobInternals
constexpr uintptr_t JobInternals_DispatchJob = 0x140157368 - ImageBase; // 48 8B C4 48 89 58 ? 48 89 68 ? 48 89 70 ? 44 88 40 ? 57 41 54, expected: 2, index: 0
#pragma endregion

#pragma region JobQueue
constexpr uintptr_t JobQueue_ctor_FromGroup = 0x140158CEC - ImageBase; // 48 89 5C 24 ? 57 48 83 EC ? 48 8B 42 ? 48 8B DA, expected: 23, index: 0
constexpr uintptr_t JobQueue_ctor_FromParams = 0x140158D2C - ImageBase; // 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC ? 49 8B D9, expected: 65, index: 0
Expand All @@ -165,7 +166,7 @@ constexpr uintptr_t OpcodeHandlers = 0x14326CCB0 - ImageBase; // 4C 8D 05 ? ? ?
#pragma endregion

#pragma region ResourceDepot
constexpr uintptr_t ResourceDepot = 0x1446DE478 - ImageBase; // 48 89 05 ? ? ? ? 49 8B 5B ? 49 8B 73 ?, expected: 1, index: 0, offset: 3
constexpr uintptr_t ResourceDepot = 0x1446DE478 - ImageBase; // 48 89 05 ? ? ? ? 49 8B 5B ? 49 8B 73, expected: 1, index: 0, offset: 3
#pragma endregion

#pragma region ResourceLoader
Expand Down
2 changes: 2 additions & 0 deletions include/RED4ext/Dump/Reflection-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ RED4EXT_INLINE void BitfieldFileDescriptor::EmitFile(std::filesystem::path aOutP
o << "struct " << nameQualified;
}

// TODO: Struct alignment: __declspec(align(X))

o << std::endl;
o << "{" << std::endl;

Expand Down
11 changes: 6 additions & 5 deletions include/RED4ext/JobQueue-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ RED4EXT_INLINE RED4ext::JobQueue::JobQueue(const JobGroup& aGroup)

RED4EXT_INLINE RED4ext::JobQueue::JobQueue(JobParamSet aParams, uintptr_t aUnk)
{
using func_t = JobQueue* (*)(JobQueue*, JobParamSet&, uint64_t);
using func_t = JobQueue* (*)(JobQueue*, uint8_t, uint8_t, uint64_t);
RelocFunc<func_t> func(Addresses::JobQueue_ctor_FromParams);

func(this, aParams, aUnk);
func(this, aParams.unk00, aParams.unk01, aUnk);
}

RED4EXT_INLINE RED4ext::JobQueue::~JobQueue()
Expand Down Expand Up @@ -106,10 +106,11 @@ RED4EXT_INLINE [[nodiscard]] RED4ext::JobHandle RED4ext::JobQueue::Capture()

RED4EXT_INLINE void RED4ext::JobQueue::DispatchJob(const JobInstance& aJob)
{
using func_t = void (*)(const JobInstance&, JobHandle&, JobHandle&);
RelocFunc<func_t> func(Addresses::JobInternals_DispatchJob);
using func_t = uint32_t (*)(void*, const JobInstance&, uint8_t, JobHandle, JobHandle);
RelocFunc<func_t> func(Addresses::JobDispatcher_DispatchJob);
RelocPtr<void*> dispatcher(Addresses::JobDispatcher);

func(aJob, unk10, unk18);
func(dispatcher, aJob, params.unk00, unk10, unk18);
}

RED4EXT_INLINE void RED4ext::JobQueue::SyncWait()
Expand Down
2 changes: 1 addition & 1 deletion include/RED4ext/Scripting/Natives/Generated/Quaternion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace RED4ext
{
struct Quaternion
struct __declspec(align(16)) Quaternion
{
static constexpr const char* NAME = "Quaternion";
static constexpr const char* ALIAS = NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct EntityStubCreateRequest
WorldTransform transform; // 10
TweakDBID recordID; // 30
};
RED4EXT_ASSERT_SIZE(EntityStubCreateRequest, 0x38);
RED4EXT_ASSERT_SIZE(EntityStubCreateRequest, 0x40);
RED4EXT_ASSERT_OFFSET(EntityStubCreateRequest, entityID, 0x00);
RED4EXT_ASSERT_OFFSET(EntityStubCreateRequest, transform, 0x10);
RED4EXT_ASSERT_OFFSET(EntityStubCreateRequest, recordID, 0x30);
Expand Down
4 changes: 2 additions & 2 deletions include/RED4ext/Scripting/Natives/gameIGameSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct IGameSystem : IUpdatableSystem
static constexpr const char* NAME = "gameIGameSystem";
static constexpr const char* ALIAS = "IGameSystem";

virtual void OnWorldAttached(world::RuntimeScene* aScene); // 108
virtual void OnBeforeWorldDetach(world::RuntimeScene* aScene); // 110
virtual void OnWorldAttached(world::RuntimeScene* aScene); // 110
virtual void OnBeforeWorldDetach(world::RuntimeScene* aScene); // 118
virtual void OnWorldDetached(world::RuntimeScene* aScene); // 120
virtual void OnAfterWorldDetach(); // 128
virtual uint32_t OnBeforeGameSave(const JobGroup& aJobGroup, void* a2); // 130
Expand Down
9 changes: 6 additions & 3 deletions include/RED4ext/Scripting/Natives/gameIPopulationSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ struct IPopulationSystem : IGameSystem
virtual bool IsSpawning(EntityID aEntityID) = 0; // 1C8
virtual void sub_1D0() = 0; // 1D0
virtual void sub_1D8() = 0; // 1D8
virtual bool RegisterEntity(PopulationEntityRegisterRequest& aRequest) = 0; // 1E0
virtual void RemoveEntity(EntityID aEntityID, const char* aReason) = 0; // 1E8
virtual void sub_1F0() = 0; // 1F0
virtual void sub_1E0() = 0; // 1E0
virtual bool RegisterEntity(PopulationEntityRegisterRequest& aRequest) = 0; // 1E8
virtual void RemoveEntity(uint32_t aEntityID, uint64_t a2) = 0; // 1F0
virtual void sub_1F8() = 0; // 1F8
virtual void sub_200() = 0; // 200
virtual void sub_208() = 0; // 208
Expand Down Expand Up @@ -83,6 +83,9 @@ struct IPopulationSystem : IGameSystem
virtual void sub_2E8() = 0; // 2E8
virtual void sub_2F0() = 0; // 2F0
virtual void sub_2F8() = 0; // 2F8
virtual void sub_300() = 0; // 300
virtual void sub_308() = 0; // 308
virtual void sub_310() = 0; // 310
};
RED4EXT_ASSERT_SIZE(IPopulationSystem, 0x48);
} // namespace game
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ struct IWidgetLogicController : IScriptable
static constexpr const char* NAME = "inkIWidgetLogicController";
static constexpr const char* ALIAS = "inkILogicController";

virtual void OnInitialize() = 0; // 110
virtual void OnUninitialize() = 0; // 118
virtual void OnArrangeChildrenComplete() = 0; // 120
virtual void OnInitialize() = 0; // 108
virtual void OnUninitialize() = 0; // 110
virtual void OnArrangeChildrenComplete() = 0; // 118

WeakHandle<Widget> widget; // 40
WeakHandle<LayerProxy> layerProxy; // 50
Expand Down
14 changes: 7 additions & 7 deletions include/RED4ext/Scripting/Utils-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <RED4ext/Scripting/IScriptable.hpp>

RED4EXT_INLINE bool RED4ext::ExecuteFunction(ScriptInstance aInstance, CBaseFunction* aFunc, void* aOut,
StackArgs_t aArgs)
StackArgs_t& aArgs)
{
CStackType result;
if (aFunc->returnType)
Expand Down Expand Up @@ -43,7 +43,7 @@ RED4EXT_INLINE bool RED4ext::ExecuteFunction(ScriptInstance aInstance, CBaseFunc
return aFunc->Execute(&stack);
}

RED4EXT_INLINE bool RED4ext::ExecuteFunction(CClass* aContext, CBaseFunction* aFunc, void* aOut, StackArgs_t aArgs)
RED4EXT_INLINE bool RED4ext::ExecuteFunction(CClass* aContext, CBaseFunction* aFunc, void* aOut, StackArgs_t& aArgs)
{
auto engine = CGameEngine::Get();
auto gameInstance = engine->framework->gameInstance;
Expand All @@ -52,7 +52,7 @@ RED4EXT_INLINE bool RED4ext::ExecuteFunction(CClass* aContext, CBaseFunction* aF
return ExecuteFunction(instance, aFunc, aOut, aArgs);
}

RED4EXT_INLINE bool RED4ext::ExecuteFunction(CClass* aContext, CName aFunc, void* aOut, StackArgs_t aArgs)
RED4EXT_INLINE bool RED4ext::ExecuteFunction(CClass* aContext, CName aFunc, void* aOut, StackArgs_t& aArgs)
{
auto func = aContext->GetFunction(aFunc);
if (!func)
Expand All @@ -63,7 +63,7 @@ RED4EXT_INLINE bool RED4ext::ExecuteFunction(CClass* aContext, CName aFunc, void
return ExecuteFunction(aContext, func, aOut, aArgs);
}

RED4EXT_INLINE bool RED4ext::ExecuteFunction(CName aContext, CName aFunc, void* aOut, StackArgs_t aArgs)
RED4EXT_INLINE bool RED4ext::ExecuteFunction(CName aContext, CName aFunc, void* aOut, StackArgs_t& aArgs)
{
auto rtti = CRTTISystem::Get();
auto type = rtti->GetClass(aContext);
Expand All @@ -75,7 +75,7 @@ RED4EXT_INLINE bool RED4ext::ExecuteFunction(CName aContext, CName aFunc, void*
return ExecuteFunction(type, aFunc, aOut, aArgs);
}

RED4EXT_INLINE bool RED4ext::ExecuteGlobalFunction(CClass* aContext, CName aFunc, void* aOut, StackArgs_t aArgs)
RED4EXT_INLINE bool RED4ext::ExecuteGlobalFunction(CClass* aContext, CName aFunc, void* aOut, StackArgs_t& aArgs)
{
auto rtti = CRTTISystem::Get();
auto func = rtti->GetFunction(aFunc);
Expand All @@ -87,7 +87,7 @@ RED4EXT_INLINE bool RED4ext::ExecuteGlobalFunction(CClass* aContext, CName aFunc
return ExecuteFunction(aContext, func, aOut, aArgs);
}

RED4EXT_INLINE bool RED4ext::ExecuteGlobalFunction(CName aContext, CName aFunc, void* aOut, StackArgs_t aArgs)
RED4EXT_INLINE bool RED4ext::ExecuteGlobalFunction(CName aContext, CName aFunc, void* aOut, StackArgs_t& aArgs)
{
auto rtti = CRTTISystem::Get();
auto type = rtti->GetClass(aContext);
Expand All @@ -99,7 +99,7 @@ RED4EXT_INLINE bool RED4ext::ExecuteGlobalFunction(CName aContext, CName aFunc,
return ExecuteGlobalFunction(type, aFunc, aOut, aArgs);
}

RED4EXT_INLINE bool RED4ext::ExecuteGlobalFunction(CName aFunc, void* aOut, StackArgs_t aArgs)
RED4EXT_INLINE bool RED4ext::ExecuteGlobalFunction(CName aFunc, void* aOut, StackArgs_t& aArgs)
{
return ExecuteGlobalFunction("cpPlayerSystem", aFunc, aOut, aArgs);
}
14 changes: 7 additions & 7 deletions include/RED4ext/Scripting/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ namespace RED4ext
struct CBaseFunction;
struct CClass;

bool ExecuteFunction(ScriptInstance aInstance, CBaseFunction* aFunc, void* aOut, StackArgs_t aArgs);
bool ExecuteFunction(ScriptInstance aInstance, CBaseFunction* aFunc, void* aOut, StackArgs_t& aArgs);

bool ExecuteFunction(CClass* aContext, CBaseFunction* aFunc, void* aOut, StackArgs_t aArgs);
bool ExecuteFunction(CClass* aContext, CName aFunc, void* aOut, StackArgs_t aArgs);
bool ExecuteFunction(CName aContext, CName aFunc, void* aOut, StackArgs_t aArgs);
bool ExecuteFunction(CClass* aContext, CBaseFunction* aFunc, void* aOut, StackArgs_t& aArgs);
bool ExecuteFunction(CClass* aContext, CName aFunc, void* aOut, StackArgs_t& aArgs);
bool ExecuteFunction(CName aContext, CName aFunc, void* aOut, StackArgs_t& aArgs);

bool ExecuteGlobalFunction(CClass* aContext, CName aFunc, void* aOut, StackArgs_t aArgs);
bool ExecuteGlobalFunction(CName aContext, CName aFunc, void* aOut, StackArgs_t aArgs);
bool ExecuteGlobalFunction(CName aFunc, void* aOut, StackArgs_t aArgs);
bool ExecuteGlobalFunction(CClass* aContext, CName aFunc, void* aOut, StackArgs_t& aArgs);
bool ExecuteGlobalFunction(CName aContext, CName aFunc, void* aOut, StackArgs_t& aArgs);
bool ExecuteGlobalFunction(CName aFunc, void* aOut, StackArgs_t& aArgs);

template<typename... Args>
bool ExecuteFunction(CClass* aContext, CBaseFunction* aFunc, void* aOut, Args&&... aArgs)
Expand Down
11 changes: 8 additions & 3 deletions include/RED4ext/TweakDB-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,14 @@ RED4EXT_INLINE RED4ext::TweakDB::FlatValue* RED4ext::TweakDB::GetFlatValue(Tweak

RED4EXT_INLINE int32_t RED4ext::TweakDB::CreateFlatValue(const CStackType& aStackType)
{
auto typeAlignment = aStackType.type->GetAlignment() - 1;
auto flatValueSize = 8 /* vftable */ + ((typeAlignment + aStackType.type->GetSize()) & ~typeAlignment);
auto flatDataBufferEnd_Aligned = (7 + flatDataBufferEnd) & ~7; // 8 aligned
uintptr_t flatAlignment = aStackType.type->GetAlignment();
if (flatAlignment < 8)
{
flatAlignment = 8;
}

uintptr_t flatValueSize = RED4ext::AlignUp(8ull /* vftable */ + aStackType.type->GetSize(), flatAlignment);
uintptr_t flatDataBufferEnd_Aligned = RED4ext::AlignUp(flatDataBufferEnd, flatAlignment);

{
std::lock_guard<SharedMutex> _(mutex00);
Expand Down
3 changes: 3 additions & 0 deletions include/RED4ext/TweakDB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ struct TweakDB

T data;
};
using QuaternionFlatValue = FlatValueImpl<Quaternion, CName("Quaternion")>;
RED4EXT_ASSERT_OFFSET(QuaternionFlatValue, data, 0x10);
RED4EXT_ASSERT_SIZE(QuaternionFlatValue, 0x20);

uintptr_t staticFlatDataBuffer; // 00 - same as flatDataBuffer, used for direct access
uint64_t unk08; // 08
Expand Down
9 changes: 6 additions & 3 deletions scripts/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ def get_groups() -> List[Group]:
Item(name='Join', pattern='48 83 EC ? 48 8B 02 4C 8B C2 8B 40 ?', expected=1, index=0)
]),

Group(name='JobInternals', functions=[
Item(name='DispatchJob', pattern='48 8B C4 48 89 58 ? 48 89 68 ? 48 89 70 ? 44 88 40 ? 57 41 54', expected=2, index=0)
Group(name='JobDispatcher', pointers=[
Item(pattern='48 89 05 ? ? ? ? 48 83 C4 ? 5F C3', offset=3, expected=6, index=3)
],
functions=[
Item(name='DispatchJob', pattern='48 8B C4 48 89 58 ? 48 89 68 ? 48 89 70 ? 44 88 40 ? 57 41 54 41 55', expected=2, index=0)
]),

Group(name='JobQueue', functions=[
Expand Down Expand Up @@ -190,7 +193,7 @@ def get_groups() -> List[Group]:
]),

Group(name='ResourceDepot', pointers=[
Item(pattern="48 89 05 ? ? ? ? 49 8B 5B ? 49 8B 73 ?", offset=3, expected=1, index=0)
Item(pattern="48 89 05 ? ? ? ? 49 8B 5B ? 49 8B 73", offset=3, expected=1, index=0)
]),

Group(name='ResourceLoader', pointers=[
Expand Down

0 comments on commit c75d32b

Please sign in to comment.