From 30e5495882aa9056483502183e3b039f20fc06c0 Mon Sep 17 00:00:00 2001 From: maximegmd <672982+maximegmd@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:48:38 +0100 Subject: [PATCH] 2.12 --- src/CET.cpp | 2 + src/Image.h | 2 +- src/d3d12/D3D12_Hooks.cpp | 6 +-- src/dllmain.cpp | 55 +++++++++++++++++---- src/overlay/Overlay.cpp | 4 +- src/patches/DisableBoundaries.cpp | 2 +- src/patches/DisableIntroMovies.cpp | 2 +- src/patches/DisableVignette.cpp | 2 +- src/patches/OptionsPatch.cpp | 2 +- src/reverse/Addresses.h | 78 ++++++++++++++---------------- src/reverse/RTTIExtender.cpp | 16 +++--- src/reverse/RTTIHelper.cpp | 4 +- src/reverse/RenderContext.cpp | 2 +- src/scripting/FunctionOverride.cpp | 6 +-- src/scripting/GameHooks.cpp | 4 +- src/scripting/GameHooks.h | 10 ++-- src/scripting/LuaVM.h | 2 + src/scripting/LuaVM_Hooks.cpp | 28 ++++++----- src/stdafx.h | 1 + vendor/RED4ext.SDK | 2 +- xmake.lua | 12 ++--- 21 files changed, 139 insertions(+), 103 deletions(-) diff --git a/src/CET.cpp b/src/CET.cpp index 9ec5caf6..c118117a 100644 --- a/src/CET.cpp +++ b/src/CET.cpp @@ -11,6 +11,8 @@ static bool s_isRunning{true}; void CET::Initialize() { s_pInstance.reset(new CET); + + s_pInstance->GetVM().Prepare(); } void CET::Shutdown() diff --git a/src/Image.h b/src/Image.h index fd3818f4..f9e1b5c2 100644 --- a/src/Image.h +++ b/src/Image.h @@ -8,7 +8,7 @@ struct Image { void Initialize(); - static std::tuple GetSupportedVersion() noexcept { return std::make_tuple(2, 11); } + static std::tuple GetSupportedVersion() noexcept { return std::make_tuple(2, 12); } uintptr_t base_address; mem::region TextRegion; diff --git a/src/d3d12/D3D12_Hooks.cpp b/src/d3d12/D3D12_Hooks.cpp index 50570ed8..c05b7189 100644 --- a/src/d3d12/D3D12_Hooks.cpp +++ b/src/d3d12/D3D12_Hooks.cpp @@ -256,9 +256,9 @@ void D3D12::Hook() void D3D12::HookGame() { - const RED4ext::RelocPtr presentInternal(CyberEngineTweaks::Addresses::CRenderNode_Present_DoInternal); - const RED4ext::RelocPtr resizeInternal(CyberEngineTweaks::Addresses::CRenderGlobal_Resize); - const RED4ext::RelocPtr shutdownInternal(CyberEngineTweaks::Addresses::CRenderGlobal_Shutdown); + const RED4ext::UniversalRelocPtr presentInternal(CyberEngineTweaks::AddressHashes::CRenderNode_Present_DoInternal); + const RED4ext::UniversalRelocPtr resizeInternal(CyberEngineTweaks::AddressHashes::CRenderGlobal_Resize); + const RED4ext::UniversalRelocPtr shutdownInternal(CyberEngineTweaks::AddressHashes::CRenderGlobal_Shutdown); if (MH_CreateHook(presentInternal.GetAddr(), reinterpret_cast(&CRenderNode_Present_InternalPresent), reinterpret_cast(&m_realInternalPresent)) != MH_OK || MH_EnableHook(presentInternal.GetAddr()) != MH_OK) diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 2fef956a..4a318dad 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -3,6 +3,11 @@ #include "CET.h" #include "Options.h" +#include "RED4ext/Api/EMainReason.hpp" +#include "RED4ext/Api/PluginHandle.hpp" +#include "RED4ext/Api/Runtime.hpp" +#include "RED4ext/Api/Sdk.hpp" +#include "RED4ext/Api/Version.hpp" #include "scripting/GameHooks.h" @@ -16,7 +21,7 @@ static HANDLE s_modInstanceMutex = nullptr; using namespace std::chrono_literals; -static void Initialize() +static bool Initialize() { try { @@ -29,7 +34,7 @@ static void Initialize() // single instance check s_modInstanceMutex = CreateMutex(nullptr, TRUE, TEXT("Cyber Engine Tweaks Module Instance")); if (s_modInstanceMutex == nullptr) - return; + return false; // initialize patches @@ -52,7 +57,10 @@ static void Initialize() } catch (...) { + return false; } + + return true; } static void Shutdown() @@ -79,16 +87,45 @@ static void Shutdown() } } -BOOL APIENTRY DllMain(HMODULE mod, DWORD ul_reason_for_call, LPVOID) +RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::PluginHandle aHandle, RED4ext::EMainReason aReason, const RED4ext::Sdk* aSdk) { - DisableThreadLibraryCalls(mod); + RED4EXT_UNUSED_PARAMETER(aHandle); + RED4EXT_UNUSED_PARAMETER(aSdk); - switch (ul_reason_for_call) + switch (aReason) + { + case RED4ext::EMainReason::Load: + { + return Initialize(); + break; + } + case RED4ext::EMainReason::Unload: { - case DLL_PROCESS_ATTACH: Initialize(); break; - case DLL_PROCESS_DETACH: Shutdown(); break; - default: break; + Shutdown(); + break; } + } + + return true; +} - return TRUE; +RED4EXT_C_EXPORT void RED4EXT_CALL Query(RED4ext::PluginInfo* aInfo) +{ + aInfo->name = L"Cyber Engine Tweaks"; + aInfo->author = L"Yamashi and Friends"; + + std::istringstream oss(CET_BUILD_COMMIT); + + char buffer; + uint32_t major, minor, patch; + oss >> buffer >> major >> buffer >> minor >> buffer >> patch; + + aInfo->version = RED4EXT_SEMVER(major, minor, patch); + aInfo->runtime = RED4EXT_RUNTIME_INDEPENDENT; + aInfo->sdk = RED4EXT_SDK_LATEST; +} + +RED4EXT_C_EXPORT uint32_t RED4EXT_CALL Supports() +{ + return RED4EXT_API_VERSION_LATEST; } diff --git a/src/overlay/Overlay.cpp b/src/overlay/Overlay.cpp index a7ca6b6a..01734b65 100644 --- a/src/overlay/Overlay.cpp +++ b/src/overlay/Overlay.cpp @@ -250,7 +250,7 @@ BOOL Overlay::ClipToCenter(RED4ext::CGameEngine::UnkD0* apThis) void Overlay::Hook() { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CWinapi_ClipToCenter); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CWinapi_ClipToCenter); if (auto* pLocation = func.GetAddr()) { @@ -272,7 +272,7 @@ Overlay::Overlay(VKBindings& aBindings, Options& aOptions, PersistentState& aPer { Hook(); - GameMainThread::Get().AddBaseInitializationTask( + GameMainThread::Get().AddInitializationTask( [this] { PostInitialize(); diff --git a/src/patches/DisableBoundaries.cpp b/src/patches/DisableBoundaries.cpp index 82340d3e..efd02677 100644 --- a/src/patches/DisableBoundaries.cpp +++ b/src/patches/DisableBoundaries.cpp @@ -6,7 +6,7 @@ void DisableBoundaryTeleportPatch() // Disarm the WorldBoundarySystem/Tick function // Going out of bounds will still play the glitchy-screen effect that normally happens when game teleports you, but // the actual teleport won't happen - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CPatches_BoundaryTeleport); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CPatches_BoundaryTeleport); const auto pLocation = func.GetAddr(); if (pLocation == nullptr) diff --git a/src/patches/DisableIntroMovies.cpp b/src/patches/DisableIntroMovies.cpp index 2892bf42..a5be4126 100644 --- a/src/patches/DisableIntroMovies.cpp +++ b/src/patches/DisableIntroMovies.cpp @@ -27,7 +27,7 @@ void* HookInitScriptMemberVariable(void* a1, void* a2, uint64_t a3, uint64_t nam void DisableIntroMoviesPatch() { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CPatches_IntroMovie); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CPatches_IntroMovie); RealInitScriptMemberVariable = reinterpret_cast(func.GetAddr()); if (RealInitScriptMemberVariable == nullptr) diff --git a/src/patches/DisableVignette.cpp b/src/patches/DisableVignette.cpp index 1095eab5..a0e38617 100644 --- a/src/patches/DisableVignette.cpp +++ b/src/patches/DisableVignette.cpp @@ -3,7 +3,7 @@ void DisableVignettePatch() { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CPatches_Vignette); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CPatches_Vignette); const auto pLocation = func.GetAddr(); if (pLocation == nullptr) diff --git a/src/patches/OptionsPatch.cpp b/src/patches/OptionsPatch.cpp index 50272aa6..7d1a4b6e 100644 --- a/src/patches/OptionsPatch.cpp +++ b/src/patches/OptionsPatch.cpp @@ -40,7 +40,7 @@ void* HookGameOptionInit(GameOption* apThis) void OptionsInitHook() { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CPatches_OptionsInit); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CPatches_OptionsInit); uint8_t* pLocation = func.GetAddr(); if (pLocation) diff --git a/src/reverse/Addresses.h b/src/reverse/Addresses.h index b2d1abd2..352a3217 100644 --- a/src/reverse/Addresses.h +++ b/src/reverse/Addresses.h @@ -1,87 +1,79 @@ #pragma once -/* - * This file is generated. DO NOT modify it! - * - * Add new patterns in "patterns.py" file located in "project_root/scripts" and run "find_patterns.py". - * The new file should be located in "idb_path/Addresses.h". - */ #include -namespace CyberEngineTweaks::Addresses +namespace CyberEngineTweaks::AddressHashes { -constexpr uintptr_t ImageBase = 0x140000000; - #pragma region CBaseInitializationState -constexpr uintptr_t CBaseInitializationState_OnTick = 0x1406A4580 - ImageBase; // 40 53 48 83 EC 20 48 8B 05 ? ? ? ? 33 DB 4C 8B C2 48 85 C0 ? ? ? ?, expected: 1, index: 0 +constexpr uint32_t CBaseInitializationState_OnTick = 2529693960UL; #pragma endregion #pragma region CGame -constexpr uintptr_t CGame_Main = 0x140454F24 - ImageBase; // 48 89 5C 24 10 55 56 57 48 8B EC 48 81 EC 80 00 00 00 48 8B F9 0F 29 74 24 70 0F 29 7C 24 60 48 8D 4D C0, expected: 1, index: 0 +constexpr uint32_t CGame_Main = 1852772247UL; #pragma endregion #pragma region CInitializationState -constexpr uintptr_t CInitializationState_OnTick = 0x1406A463C - ImageBase; // 40 53 48 83 EC 30 48 8B 05 ? ? ? ? 33 DB 4C 8B C2 8B 88 08 01 00 00, expected: 1, index: 0 +constexpr uint32_t CInitializationState_OnTick = 2447710505UL; #pragma endregion #pragma region CPatches -constexpr uintptr_t CPatches_BoundaryTeleport = 0x140C51158 - ImageBase; // 48 8B C4 48 89 58 10 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 B0 48 81 EC ? 01 00 00 0F 29 ? B8 48 8D 51 48, expected: 1, index: 0 -constexpr uintptr_t CPatches_IntroMovie = 0x140186ABC - ImageBase; // 48 89 5C 24 08 57 48 83 EC 20 48 8B 44 24 50 48 8B D9 48 89 41 08, expected: 1, index: 0 -constexpr uintptr_t CPatches_Vignette = 0x14235C144 - ImageBase; // 33 C0 48 39 41 68 74 11, expected: 1, index: 0 -constexpr uintptr_t CPatches_OptionsInit = 0x140778E48 - ImageBase; // 48 89 5C 24 08 55 48 8B EC 48 83 EC 70 48 83 65 F8 00 48 8B D9 83 65 F4 00, expected: 1, index: 0 +constexpr uint32_t CPatches_BoundaryTeleport = 887623293UL; +constexpr uint32_t CPatches_IntroMovie = 4056423627UL; +constexpr uint32_t CPatches_Vignette = 1592528795UL; +constexpr uint32_t CPatches_OptionsInit = 2920158527UL; #pragma endregion #pragma region CPhotoMode -constexpr uintptr_t CPhotoMode_SetRecordID = 0x140450BF0 - ImageBase; // 48 89 5C 24 10 48 89 4C 24 08 55 48 8B EC 48 83 EC 40 48 8B DA 48 8D 4D E0 48 8D 55 10 E8, expected: 1, index: 0 +constexpr uint32_t CPhotoMode_SetRecordID = 2826047827UL; #pragma endregion #pragma region CRenderGlobal -constexpr uintptr_t CRenderGlobal_InstanceOffset = 0x143384588 - ImageBase; // 48 89 5C 24 08 48 89 6C 24 10 4C 89 4C 24 20 56 57 41 56 48 83 EC 30 8B 11 45 8B F0 48 8B 2D, expected: 1, index: 0, offset: 31 -constexpr uintptr_t CRenderGlobal__DoNotUse_RenderQueueOffset = 0x1B5F5FCB0 - ImageBase; // 39 72 24 74 5B 48 8B 4A 18 4C 8D 8C 24 88 00 00 00 8B 42 24 44 8B C7 48 8B 95 ? ? ? ?, expected: 1, index: 0, offset: 0 -constexpr uintptr_t CRenderGlobal_Resize = 0x14088EC60 - ImageBase; // 48 8B C4 44 88 48 20 44 89 40 18 89 50 10 89 48 08 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 68 ? 48 81 EC ? ? 00 00, expected: 1, index: 0 -constexpr uintptr_t CRenderGlobal_Shutdown = 0x141041AA8 - ImageBase; // 40 53 48 83 EC 20 48 8B D9 48 8D 05 ? ? ? ? 48 81 C1 98 00 00 00 48 89 01 E8, expected: 1, index: 0 +constexpr uint32_t CRenderGlobal_InstanceOffset = 1239944840UL; +//constexpr uint32_t CRenderGlobal__DoNotUse_RenderQueueOffset = 0x1B5F5FCB0; +constexpr uint32_t CRenderGlobal_Resize = 239671909UL; +constexpr uint32_t CRenderGlobal_Shutdown = 3192982283UL; #pragma endregion #pragma region CRenderNode_Present -constexpr uintptr_t CRenderNode_Present_DoInternal = 0x1403E195C - ImageBase; // 48 89 5C 24 08 48 89 6C 24 10 4C 89 4C 24 20 56 57 41 56 48 83 EC 30 8B 11 45 8B F0 48 8B 2D, expected: 1, index: 0 +constexpr uint32_t CRenderNode_Present_DoInternal = 2468877568UL; #pragma endregion #pragma region CRunningState -constexpr uintptr_t CRunningState_OnTick = 0x1406A45D8 - ImageBase; // 40 53 48 83 EC 30 83 64 24 28 00 48 8D 05 ? ? ? ? 48 8B 0D ? ? ? ? 48 8B DA, expected: 1, index: 0 +constexpr uint32_t CRunningState_OnTick = 3592689218UL; #pragma endregion #pragma region CScript -constexpr uintptr_t CScript_RunPureScript = 0x1405ACE18 - ImageBase; // 40 55 48 81 EC D0 00 00 00 48 8D 6C 24 40 8B, expected: 1, index: 0 -constexpr uintptr_t CScript_AllocateFunction = 0x141FE1FB8 - ImageBase; // 40 53 48 83 EC 30 BA B8 00 00 00 48 8D 4C 24 20 E8, expected: 2, index: 0 -constexpr uintptr_t CScript_Log = 0x140EADF74 - ImageBase; // 48 8B C4 53 48 83 EC 70 48 83 60 C0 00 48 8D 48 C8 83 60 BC 00, expected: 3, index: 0 -constexpr uintptr_t CScript_LogError = 0x1410951D0 - ImageBase; // 48 8B C4 53 48 83 EC 70 48 83 60 C0 00 48 8D 48 C8 83 60 BC 00, expected: 3, index: 1 -constexpr uintptr_t CScript_LogWarning = 0x141130E10 - ImageBase; // 48 8B C4 53 48 83 EC 70 48 83 60 C0 00 48 8D 48 C8 83 60 BC 00, expected: 3, index: 2 -constexpr uintptr_t CScript_ToStringDEBUG = 0x140DEABA4 - ImageBase; // 48 89 5C 24 08 57 48 83 EC 20 83 64 24 38 00 4C 8D 15 ? ? ? ? FE 42 62 33 C0, expected: 4, index: 1 -constexpr uintptr_t CScript_LogChannel = 0x140CC91C8 - ImageBase; // 48 89 5C 24 08 48 89 74 24 18 55 48 8B EC 48 83 EC 70 48 8B 02 48 8D 35 ? ? ? ? 48 83 65 18 00 4C 8D 45 18 48 83 62 30 00 45 33 C9 48 83 62 38 00, expected: 2, index: 0 -constexpr uintptr_t CScript_LogChannelWarning = 0x141FF029C - ImageBase; // 48 89 5C 24 08 48 89 74 24 18 55 48 8B EC 48 83 EC 70 48 8B 02 48 8D 35 ? ? ? ? 48 83 65 18 00 4C 8D 45 18 48 83 62 30 00 45 33 C9 48 83 62 38 00, expected: 2, index: 1 -constexpr uintptr_t CScript_TDBIDConstructorDerive = 0x14018EF44 - ImageBase; -constexpr uintptr_t CScript_TranslateBytecode = 0x1401555EC - ImageBase; // 48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 48 8B 1A 48 8B E9 8B 42 0C, expected: 2, index: 1 -constexpr uintptr_t CScript_TweakDBLoad = 0x140528F6C - ImageBase; // 48 89 5C 24 10 48 89 7C 24 18 55 48 8B EC 48 ? EC 80 00 00 00 48 8B F9 48 8B DA 48 8B 0D, expected: 1, index: 0 -constexpr uintptr_t CScript_RegisterMemberFunction = 0x140385900 - ImageBase; // 40 53 48 83 EC 20 49 8B C1 4D 8B D0 44 8B 4C 24 58 4C 8B DA 41 83 C9 03 4C 8B C0 49 8B D2 48 8B D9 E8, expected: 1, index: 0 +constexpr uint32_t CScript_RunPureScript = 3791200470UL; +constexpr uint32_t CScript_AllocateFunction = 160045886UL; +constexpr uint32_t CScript_Log = 3455393801UL; +constexpr uint32_t CScript_LogError = 2135235617UL; +constexpr uint32_t CScript_LogWarning = 3222609133UL; +constexpr uint32_t CScript_ToStringDEBUG = 3515162577UL; +constexpr uint32_t CScript_LogChannel = 1663049434UL; +constexpr uint32_t CScript_LogChannelWarning = 2841780134UL; +constexpr uint32_t CScript_TDBIDConstructorDerive = 326438016UL; +constexpr uint32_t CScript_TranslateBytecode = 3442875632UL; +constexpr uint32_t CScript_TweakDBLoad = 3602585178UL; +constexpr uint32_t CScript_RegisterMemberFunction = 592450491UL; #pragma endregion #pragma region CShutdownState -constexpr uintptr_t CShutdownState_OnTick = 0x1400FE288 - ImageBase; // 48 89 5C 24 08 57 48 83 EC 20 48 8B 0D ? ? ? ? 48, expected: 1, index: 0 +constexpr uint32_t CShutdownState_OnTick = 4069332669UL; #pragma endregion #pragma region CWinapi -constexpr uintptr_t CWinapi_ClipToCenter = 0x1401D78E4 - ImageBase; // 48 89 5C 24 08 55 48 8B EC 48 83 EC 30 48 8B D9 48 8B 89 ? 01 00 00, expected: 1, index: 0 +constexpr uint32_t CWinapi_ClipToCenter = 261693736UL; #pragma endregion #pragma region gameIGameSystem -constexpr uintptr_t gameIGameSystem_Initialize = 0x140A9E8A4 - ImageBase; // 48 89 5C 24 08 57 48 83 EC 30 48 8B 42 78 4C 8B CA 48 8B D9, expected: 1, index: 0 -constexpr uintptr_t gameIGameSystem_UnInitialize = 0x141FE5BBC - ImageBase; // 48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 20 48 8B F9 48 8D 51 42, expected: 2, index: 1 -constexpr uintptr_t gameIGameSystem_Spawn = 0x140451460 - ImageBase; // 48 89 5C 24 10 48 89 74 24 18 55 57 41 56 48 8D 6C 24 B0 48 81 EC 50 01 00 00 48 83 79 50 00 49 8B D9 4D 8B F0, expected: 1, index: 0 -constexpr uintptr_t gameIGameSystem_Despawn = 0x1404B6B88 - ImageBase; // 48 8B C4 48 89 58 08 48 89 68 10 48 89 70 18 48 89 78 20 41 56 48 83 EC 40 48 8B E9 0F 57 C0 48 83 C1 41 48 8B F2 F3 0F 7F 40 D8 E8, expected: 1, index: 0 -constexpr uintptr_t gameIGameSystem_SpawnCallback = 0x140251B38 - ImageBase; // 48 89 5C 24 10 48 89 6C 24 18 48 89 74 24 20 57 48 83 EC 60 48 8B F1 48 8B FA 48 83 C1 48 E8, expected: 1, index: 0 +constexpr uint32_t gameIGameSystem_Initialize = 385618721UL; +constexpr uint32_t gameIGameSystem_UnInitialize = 3313306514UL; +constexpr uint32_t gameIGameSystem_Spawn = 2509382878UL; +constexpr uint32_t gameIGameSystem_Despawn = 3168866665UL; +constexpr uint32_t gameIGameSystem_SpawnCallback = 2840271332UL; #pragma endregion #pragma region PlayerSystem -constexpr uintptr_t PlayerSystem_OnPlayerSpawned = 0x1409700EC - ImageBase; // 48 89 5C 24 18 48 89 74 24 20 55 57 41 54 41 56 41 57 48 8B EC 48 83 EC 50 48 8B DA 48 8B F9, expected: 1, index: 0 +constexpr uint32_t PlayerSystem_OnPlayerSpawned = 2050111212UL; #pragma endregion } // namespace CyberEngineTweaks::Addresses diff --git a/src/reverse/RTTIExtender.cpp b/src/reverse/RTTIExtender.cpp index 54bf892c..eeb8afa8 100644 --- a/src/reverse/RTTIExtender.cpp +++ b/src/reverse/RTTIExtender.cpp @@ -11,9 +11,9 @@ template struct GameCall { - GameCall(uintptr_t aAddress, const int32_t acOffset = 0) + GameCall(uint32_t aHash, const int32_t acOffset = 0) { - const RED4ext::RelocPtr addr(aAddress); + static RED4ext::UniversalRelocPtr addr(aHash); auto* pLocation = addr.GetAddr(); m_address = pLocation ? reinterpret_cast(pLocation + acOffset) : nullptr; } @@ -188,7 +188,7 @@ struct TEMP_SpawnSettings { // Copied from the function photomode uses to spawn 3rd person puppet using TFunc = void (*)(const RED4ext::TweakDBID, RED4ext::Handle&); - static GameCall func(CyberEngineTweaks::Addresses::CPhotoMode_SetRecordID); + static GameCall func(CyberEngineTweaks::AddressHashes::CPhotoMode_SetRecordID); DONOTUSE_recordDBID = acTweakDBID; func(acTweakDBID, unkB0); @@ -223,14 +223,14 @@ struct TEMP_Spawner void Initialize(RED4ext::GameInstance* apGameInstance) { using TFunc = void (*)(TEMP_Spawner*, RED4ext::GameInstance*); - static GameCall func(CyberEngineTweaks::Addresses::gameIGameSystem_Initialize); + static GameCall func(CyberEngineTweaks::AddressHashes::gameIGameSystem_Initialize); func(this, apGameInstance); } void UnInitialize() { using TFunc = void (*)(TEMP_Spawner*); - static GameCall func(CyberEngineTweaks::Addresses::gameIGameSystem_UnInitialize); + static GameCall func(CyberEngineTweaks::AddressHashes::gameIGameSystem_UnInitialize); func(this); } @@ -238,7 +238,7 @@ struct TEMP_Spawner { // REDSmartPtr TEMP_Spawner::func(this, TEMP_SpawnSettings&, RED4ext::CName&) using TFunc = void (*)(TEMP_Spawner*, REDSmartPtr*, TEMP_SpawnSettings&, const RED4ext::CName); - static GameCall func(CyberEngineTweaks::Addresses::gameIGameSystem_Spawn); + static GameCall func(CyberEngineTweaks::AddressHashes::gameIGameSystem_Spawn); REDSmartPtr pendingEntity; func(this, &pendingEntity, aSettings, acEntityPath); @@ -278,7 +278,7 @@ struct TEMP_Spawner void Despawn(const RED4ext::Handle& aEntity) { using TFunc = void (*)(TEMP_Spawner*, RED4ext::IScriptable*); - static GameCall func(CyberEngineTweaks::Addresses::gameIGameSystem_Despawn); + static GameCall func(CyberEngineTweaks::AddressHashes::gameIGameSystem_Despawn); func(this, aEntity.GetPtr()); } }; @@ -423,7 +423,7 @@ struct exEntitySpawnerSystem : RED4ext::gameIGameSystem static void SpawnCallback(TEMP_PendingEntity::Unk00& aUnk) { using TFunc = void (*)(IScriptable*, RED4ext::ent::Entity*); - static GameCall func(CyberEngineTweaks::Addresses::gameIGameSystem_SpawnCallback); + static GameCall func(CyberEngineTweaks::AddressHashes::gameIGameSystem_SpawnCallback); struct GameInstance_78_Unk { diff --git a/src/reverse/RTTIHelper.cpp b/src/reverse/RTTIHelper.cpp index d535fac4..e2c962fb 100644 --- a/src/reverse/RTTIHelper.cpp +++ b/src/reverse/RTTIHelper.cpp @@ -19,8 +19,6 @@ constexpr bool s_cThrowLuaErrors = true; std::unique_ptr s_pInstance{nullptr}; using TCallScriptFunction = bool (*)(RED4ext::IFunction* apFunction, RED4ext::IScriptable* apContext, RED4ext::CStackFrame* apFrame, void* apResult, void* apResultType); - -RED4ext::RelocFunc CallScriptFunction(RED4ext::Addresses::CBaseFunction_InternalExecute); } // namespace void RTTIHelper::Initialize(const LockableState& acLua, LuaSandbox& apSandbox) @@ -773,6 +771,8 @@ void LuaDummyFunction(RED4ext::IScriptable*, RED4ext::CStackFrame* apFrame, void bool RTTIHelper::ExecuteFunction( RED4ext::CBaseFunction* apFunc, RED4ext::IScriptable* apContext, TiltedPhoques::Vector& aArgs, RED4ext::CStackType& aResult) const { + static RED4ext::UniversalRelocFunc CallScriptFunction(RED4ext::Detail::AddressHashes::CBaseFunction_InternalExecute); + constexpr auto NopOp = 0; constexpr auto ParamOp = 27; constexpr auto ParamEndOp = 38; diff --git a/src/reverse/RenderContext.cpp b/src/reverse/RenderContext.cpp index fdccf01b..5412dbdc 100644 --- a/src/reverse/RenderContext.cpp +++ b/src/reverse/RenderContext.cpp @@ -5,6 +5,6 @@ RenderContext* RenderContext::GetInstance() noexcept { - static RED4ext::RelocPtr s_instance(CyberEngineTweaks::Addresses::CRenderGlobal_InstanceOffset); + static RED4ext::UniversalRelocPtr s_instance(CyberEngineTweaks::AddressHashes::CRenderGlobal_InstanceOffset); return *s_instance.GetAddr(); } diff --git a/src/scripting/FunctionOverride.cpp b/src/scripting/FunctionOverride.cpp index 8ca5464e..a7a30a7e 100644 --- a/src/scripting/FunctionOverride.cpp +++ b/src/scripting/FunctionOverride.cpp @@ -18,7 +18,7 @@ using TCallScriptFunction = bool (*)(RED4ext::IFunction* apFunction, RED4ext::IS TRunPureScriptFunction RealRunPureScriptFunction = nullptr; TCreateFunction RealCreateFunction = nullptr; -RED4ext::RelocFunc CallScriptFunction(RED4ext::Addresses::CBaseFunction_InternalExecute); +RED4ext::UniversalRelocFunc CallScriptFunction(RED4ext::Detail::AddressHashes::CBaseFunction_InternalExecute); constexpr size_t s_cMaxFunctionSize = std::max({sizeof(RED4ext::CClassFunction), sizeof(RED4ext::CClassStaticFunction), sizeof(RED4ext::CGlobalFunction)}); @@ -524,7 +524,7 @@ sol::function FunctionOverride::WrapNextOverride( void FunctionOverride::Hook() const { { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_RunPureScript); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_RunPureScript); RealRunPureScriptFunction = reinterpret_cast(func.GetAddr()); if (!RealRunPureScriptFunction) Log::Error("Could not find pure run script function!"); @@ -541,7 +541,7 @@ void FunctionOverride::Hook() const } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_AllocateFunction); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_AllocateFunction); RealCreateFunction = reinterpret_cast(func.GetAddr()); if (!RealCreateFunction) Log::Error("Could not find create function!"); diff --git a/src/scripting/GameHooks.cpp b/src/scripting/GameHooks.cpp index 26f8c6da..f08d86de 100644 --- a/src/scripting/GameHooks.cpp +++ b/src/scripting/GameHooks.cpp @@ -23,9 +23,9 @@ void GameMainThread::RepeatedTaskQueue::Drain() ++taskIt; } } -GameMainThread::StateTickOverride::StateTickOverride(const uintptr_t acOffset, const char* acpRealFunctionName) +GameMainThread::StateTickOverride::StateTickOverride(uint32_t aHash, const char* acpRealFunctionName) { - const RED4ext::RelocPtr func(acOffset); + const RED4ext::UniversalRelocPtr func(aHash); Location = func.GetAddr(); if (Location) diff --git a/src/scripting/GameHooks.h b/src/scripting/GameHooks.h index eb37eabd..b0c84364 100644 --- a/src/scripting/GameHooks.h +++ b/src/scripting/GameHooks.h @@ -30,7 +30,7 @@ struct GameMainThread struct StateTickOverride { - StateTickOverride(const uintptr_t acOffset, const char* acpRealFunctionName); + StateTickOverride(uint32_t aHash, const char* acpRealFunctionName); ~StateTickOverride(); bool OnTick(RED4ext::IGameState*, RED4ext::CGameApplication*); @@ -41,10 +41,10 @@ struct GameMainThread }; std::array m_stateTickOverrides{ - StateTickOverride(CyberEngineTweaks::Addresses::CBaseInitializationState_OnTick, "CBaseInitializationState::OnTick"), - StateTickOverride(CyberEngineTweaks::Addresses::CInitializationState_OnTick, "CInitializationState::OnTick"), - StateTickOverride(CyberEngineTweaks::Addresses::CRunningState_OnTick, "CRunningState::OnTick"), - StateTickOverride(CyberEngineTweaks::Addresses::CShutdownState_OnTick, "CShutdownState::OnTick")}; + StateTickOverride(CyberEngineTweaks::AddressHashes::CBaseInitializationState_OnTick, "CBaseInitializationState::OnTick"), + StateTickOverride(CyberEngineTweaks::AddressHashes::CInitializationState_OnTick, "CInitializationState::OnTick"), + StateTickOverride(CyberEngineTweaks::AddressHashes::CRunningState_OnTick, "CRunningState::OnTick"), + StateTickOverride(CyberEngineTweaks::AddressHashes::CShutdownState_OnTick, "CShutdownState::OnTick")}; RepeatedTaskQueue m_genericQueue; }; diff --git a/src/scripting/LuaVM.h b/src/scripting/LuaVM.h index be8d4291..8c62df34 100644 --- a/src/scripting/LuaVM.h +++ b/src/scripting/LuaVM.h @@ -32,6 +32,8 @@ struct LuaVM [[nodiscard]] const TiltedPhoques::Vector* GetBinds(const std::string& acModName) const; [[nodiscard]] const TiltedPhoques::Map>>& GetAllBinds() const; + void Prepare(); + bool ExecuteLua(const std::string& acCommand) const; void Update(float aDeltaTime); diff --git a/src/scripting/LuaVM_Hooks.cpp b/src/scripting/LuaVM_Hooks.cpp index a7bb3693..e97f2003 100644 --- a/src/scripting/LuaVM_Hooks.cpp +++ b/src/scripting/LuaVM_Hooks.cpp @@ -269,6 +269,12 @@ LuaVM::LuaVM(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings // before trying to access it or TweakDBID lookup // TweakDBID lookup is on top locked for the duration of the initialization so accessing it should not // be possible until it finishes + + aBindings.SetVM(this); +} + +void LuaVM::Prepare() +{ std::thread( [this] { @@ -280,8 +286,6 @@ LuaVM::LuaVM(const Paths& aPaths, const Options& aOptions, VKBindings& aBindings ResourcesList::Get()->Initialize(); }) .detach(); - - aBindings.SetVM(this); } TDBID* LuaVM::HookTDBIDCtorDerive(TDBID* apBase, TDBID* apThis, const char* acpName) @@ -345,7 +349,7 @@ void LuaVM::Hook() s_vm = this; { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_Log); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_Log); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -358,7 +362,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_LogError); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_LogError); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -371,7 +375,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_LogWarning); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_LogWarning); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -384,7 +388,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_LogChannel); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_LogChannel); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -397,7 +401,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_LogChannelWarning); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_LogChannelWarning); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -410,7 +414,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_TDBIDConstructorDerive); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_TDBIDConstructorDerive); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -424,7 +428,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_ToStringDEBUG); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_ToStringDEBUG); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -440,7 +444,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_TranslateBytecode); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_TranslateBytecode); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -456,7 +460,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::CScript_TweakDBLoad); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::CScript_TweakDBLoad); uint8_t* pLocation = func.GetAddr(); if (pLocation) @@ -471,7 +475,7 @@ void LuaVM::Hook() } { - const RED4ext::RelocPtr func(CyberEngineTweaks::Addresses::PlayerSystem_OnPlayerSpawned); + const RED4ext::UniversalRelocPtr func(CyberEngineTweaks::AddressHashes::PlayerSystem_OnPlayerSpawned); uint8_t* pLocation = func.GetAddr(); if (pLocation) diff --git a/src/stdafx.h b/src/stdafx.h index 82100359..641656f8 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include "RED4ext/GameApplication.hpp" diff --git a/vendor/RED4ext.SDK b/vendor/RED4ext.SDK index 014f185f..e113fd16 160000 --- a/vendor/RED4ext.SDK +++ b/vendor/RED4ext.SDK @@ -1 +1 @@ -Subproject commit 014f185f297836b8405ab5d8dae0ec58473b10b9 +Subproject commit e113fd169fbac9a0e19a13f115516370ad36ac09 diff --git a/xmake.lua b/xmake.lua index d4ff100a..da157bac 100644 --- a/xmake.lua +++ b/xmake.lua @@ -4,7 +4,7 @@ set_languages("cxx20") set_arch("x64") add_rules("mode.debug","mode.releasedbg", "mode.release") -add_rules("plugin.vsxmake.autoupdate") +--add_rules("plugin.vsxmake.autoupdate") add_rules("c.unity_build") add_cxflags("/bigobj", "/MP") @@ -66,10 +66,10 @@ target("RED4ext.SDK") on_install(function() end) target("cyber_engine_tweaks") - add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"") -- WINVER=0x0601 == Windows 7xmake + add_defines("WIN32_LEAN_AND_MEAN", "_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"") -- WINVER=0x0601 == Windows 7xmake set_pcxxheader("src/stdafx.h") set_kind("shared") - set_filename("cyber_engine_tweaks.asi") + set_filename("cyber_engine_tweaks.dll") add_files("src/**.cpp") add_headerfiles("src/**.h", "build/CETVersion.h") add_includedirs("src/", "build/") @@ -83,7 +83,7 @@ target("cyber_engine_tweaks") os.rm("package/*") - os.mkdir("package/bin/x64/plugins/cyber_engine_tweaks/tweakdb") + os.mkdir("package/red4ext/plugins/cyber_engine_tweaks/tweakdb") http.download("https://github.com/WolvenKit/WolvenKit/raw/main/WolvenKit.Common/Resources/usedhashes.kark", "package/bin/x64/plugins/cyber_engine_tweaks/tweakdb/usedhashes.kark") http.download("https://github.com/WolvenKit/WolvenKit/raw/main/WolvenKit.Common/Resources/tweakdbstr.kark", "package/bin/x64/plugins/cyber_engine_tweaks/tweakdb/tweakdbstr.kark") @@ -93,12 +93,10 @@ target("cyber_engine_tweaks") os.mkdir("package/bin/x64/plugins/cyber_engine_tweaks/fonts") os.cp("fonts/*", "package/bin/x64/plugins/cyber_engine_tweaks/fonts") - os.cp("vendor/asiloader/*", "package/bin/x64/") - os.cp("LICENSE", "package/bin/x64/") os.cp("ThirdParty_LICENSES", "package/bin/x64/plugins/cyber_engine_tweaks/ThirdParty_LICENSES") - os.cp(target:targetfile(), "package/bin/x64/plugins/") + os.cp(target:targetfile(), "package/red4ext/plugins/cyber_engine_tweaks/") end) on_install(function(target) cprint("${green bright}Installing Cyber Engine Tweaks ..")