Skip to content

Commit

Permalink
Merge pull request #31 from psiberx/master
Browse files Browse the repository at this point in the history
Fix patch 2.01 + script compilation
  • Loading branch information
wopss authored Oct 7, 2023
2 parents 2d1acd2 + d4b3262 commit 808bbb0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/dll/Addresses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@
*/
#include <cstdint>

// Addresses for Cyberpunk 2077, version 2.0.
// Addresses for Cyberpunk 2077, version 2.01.
namespace Addresses
{
constexpr uintptr_t ImageBase = 0x140000000;

#pragma region CBaseEngine
constexpr uintptr_t CBaseEngine_InitScripts = 0x1406E8C54 - ImageBase; // 48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC ? 48 8B D9 41 0F B7 F1, expected: 1, index: 0
constexpr uintptr_t CBaseEngine_LoadScripts = 0x1406E9828 - ImageBase; // 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC ? 49 8D 99 ? ? ? ?, expected: 1, index: 0
constexpr uintptr_t CBaseEngine_InitScripts = 0x14070F590 - ImageBase; // 48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC ? 48 8B D9 41 0F B7 F1, expected: 1, index: 0
constexpr uintptr_t CBaseEngine_LoadScripts = 0x140710168 - ImageBase; // 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC ? 49 8D 99 ? ? ? ?, expected: 1, index: 0
#pragma endregion

#pragma region CGameApplication
constexpr uintptr_t CGameApplication_AddState = 0x14084AAFC - ImageBase; // 48 89 5C 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B 02 48 8D B9 ? ? ? ?, expected: 1, index: 0
constexpr uintptr_t CGameApplication_AddState = 0x14080E184 - ImageBase; // 48 89 5C 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B 02 48 8D B9 ? ? ? ?, expected: 1, index: 0
#pragma endregion

#pragma region CInitializationState
constexpr uintptr_t CInitializationState_Run = 0x14084A7A8 - ImageBase; // 40 53 48 83 EC ? 48 8B 05 ? ? ? ? 33 DB 4C 8B C2 8B 88 ? ? ? ?, expected: 1, index: 0
constexpr uintptr_t CInitializationState_Run = 0x14080DE30 - ImageBase; // 40 53 48 83 EC ? 48 8B 05 ? ? ? ? 33 DB 4C 8B C2 8B 88 ? ? ? ?, expected: 1, index: 0
#pragma endregion

#pragma region CRunningState
constexpr uintptr_t CRunningState_Run = 0x14084A744 - ImageBase; // 40 53 48 83 EC ? 83 64 24 ? ? 48 8D 05 ? ? ? ? 48 8B 0D ? ? ? ?, expected: 1, index: 0
constexpr uintptr_t CRunningState_Run = 0x14080DDCC - ImageBase; // 40 53 48 83 EC ? 83 64 24 ? ? 48 8D 05 ? ? ? ? 48 8B 0D ? ? ? ?, expected: 1, index: 0
#pragma endregion

#pragma region CShutdownState
constexpr uintptr_t CShutdownState_Run = 0x140380910 - ImageBase; // 40 53 48 83 EC ? 48 8B DA E8 ? ? ? ? 48 8B CB 89 83 ? ? ? ?, expected: 1, index: 0
constexpr uintptr_t CShutdownState_Run = 0x140A4DFD8 - ImageBase; // 40 53 48 83 EC ? 48 8B DA E8 ? ? ? ? 48 8B CB 89 83 ? ? ? ?, expected: 1, index: 0
#pragma endregion

#pragma region Global
constexpr uintptr_t Global_Main = 0x14084A994 - ImageBase; // 40 55 53 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? FF 15 ? ? ? ?, expected: 1, index: 0
constexpr uintptr_t Global_ExecuteProcess = 0x1406E93E4 - ImageBase; // 48 89 5C 24 ? 48 89 74 24 ? 57 48 81 EC ? ? ? ? 41 81 79 ? ? ? ? ?, expected: 1, index: 0
constexpr uintptr_t Global_Main = 0x14080E01C - ImageBase; // 40 55 53 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? FF 15 ? ? ? ?, expected: 1, index: 0
constexpr uintptr_t Global_ExecuteProcess = 0x14070FD24 - ImageBase; // 48 89 5C 24 ? 48 89 74 24 ? 57 48 81 EC ? ? ? ? 41 81 79 ? ? ? ? ?, expected: 1, index: 0
#pragma endregion
} // namespace Addresses
18 changes: 9 additions & 9 deletions src/dll/Hooks/InitScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ Hook<decltype(&_CBaseEngine_InitScripts)> CBaseEngine_InitScripts(Addresses::CBa
void* _CBaseEngine_InitScripts(RED4ext::CBaseEngine* aThis, const RED4ext::CString& aScriptsBlobPath, int8_t a3,
int16_t a4)
{
auto scriptCompilationSystem = App::Get()->GetScriptCompilationSystem();
RED4ext::CString original(aThis->scriptsBlobPath);

if (aThis->scriptsBlobPath.Length())
if (!aScriptsBlobPath.Length())
{
spdlog::info("Scripts BLOB is set to '{}'", aThis->scriptsBlobPath.c_str());
scriptCompilationSystem->SetScriptsBlob(aThis->scriptsBlobPath.c_str());
aThis->scriptsBlobPath = "";
return CBaseEngine_InitScripts(aThis, aScriptsBlobPath, a3, a4);
}

auto result = CBaseEngine_InitScripts(aThis, aScriptsBlobPath, a3, a4);
aThis->scriptsBlobPath = original;
spdlog::info("Scripts BLOB is set to '{}'", aScriptsBlobPath.c_str());

auto scriptCompilationSystem = App::Get()->GetScriptCompilationSystem();
scriptCompilationSystem->SetScriptsBlob(aScriptsBlobPath.c_str());

auto result = CBaseEngine_InitScripts(aThis, "", a3, a4);
aThis->scriptsBlobPath = aScriptsBlobPath;
return result;
}
} // namespace
Expand Down
4 changes: 4 additions & 0 deletions src/dll/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ std::wstring Utils::FileVerToPatch(const RED4ext::FileVer& aVersion)
{
return L"2.00";
}
else if (aVersion == RED4EXT_RUNTIME_2_01)
{
return L"2.01";
}

return fmt::format(L"Unknown patch ({})", std::to_wstring(aVersion));
}

0 comments on commit 808bbb0

Please sign in to comment.