Skip to content

Commit

Permalink
Register stat types
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Aug 5, 2023
1 parent 07e64ac commit 73bf934
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
41 changes: 34 additions & 7 deletions src/App/Stats/StatService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,49 @@ void App::StatService::OnInitializeStats(void* aSystem)
statRecords->EmplaceBack();
}

statTypeEnum->AddOption(statRecords->size, enumName);
const auto enumValue = statRecords->size;

statTypeEnum->AddOption(enumValue, enumName);
statRecords->PushBack(recordId);

if (!s_statTypesModified)
{
s_statTypesModified = true;
Hook<Raw::StatsDataSystem::GetStatFlags>(&OnGetStatFlags);
Hook<Raw::StatsDataSystem::GetStatRange>(&OnGetStatRange);
Hook<Raw::StatsDataSystem::GetStatFlags>(&OnGetStatFlags);
Hook<Raw::StatsDataSystem::CheckStatFlag>(&OnCheckStatFlag);
}

{
const auto record = tweakManager.GetRecord(recordId);
const auto recordSize = record->GetType()->GetSize();
const auto enumPropAddr = reinterpret_cast<uintptr_t>(record.instance) + recordSize - 8;
*reinterpret_cast<uint32_t*>(enumPropAddr) = enumValue;
}
}
}
}
}

uint64_t* App::StatService::OnGetStatRange(void* aSystem, uint64_t* aRange, uint32_t aStat)
{
if (aStat != InvalidStat)
{
auto& statParams = Raw::StatsDataSystem::StatParams::Ref(aSystem);
auto& statLock = Raw::StatsDataSystem::StatLock::Ref(aSystem);

std::shared_lock _(statLock);
if (aStat < statParams.size)
{
*aRange = statParams[aStat].range;
return aRange;
}
}

*aRange = 0;
return aRange;
}

uint32_t App::StatService::OnGetStatFlags(void* aSystem, uint32_t aStat)
{
if (aStat != InvalidStat)
Expand All @@ -77,7 +106,7 @@ uint32_t App::StatService::OnGetStatFlags(void* aSystem, uint32_t aStat)
return 0;
}

uint64_t* App::StatService::OnGetStatRange(void* aSystem, uint64_t* aRange, uint32_t aStat)
bool App::StatService::OnCheckStatFlag(void* aSystem, uint32_t aStat, uint32_t aFlag)
{
if (aStat != InvalidStat)
{
Expand All @@ -87,11 +116,9 @@ uint64_t* App::StatService::OnGetStatRange(void* aSystem, uint64_t* aRange, uint
std::shared_lock _(statLock);
if (aStat < statParams.size)
{
*aRange = statParams[aStat].range;
return aRange;
return statParams[aStat].flags & aFlag;
}
}

*aRange = 0;
return aRange;
return false;
}
3 changes: 2 additions & 1 deletion src/App/Stats/StatService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class StatService
void OnBootstrap() override;

static void OnInitializeStats(void* aSystem);
static uint32_t OnGetStatFlags(void* aSystem, uint32_t aStat);
static uint64_t* OnGetStatRange(void* aSystem, uint64_t* aRange, uint32_t aStat);
static uint32_t OnGetStatFlags(void* aSystem, uint32_t aStat);
static bool OnCheckStatFlag(void* aSystem, uint32_t aStat, uint32_t aFlag);
};
}
4 changes: 2 additions & 2 deletions src/App/Version.rc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#define VER_PRODUCTVERSION 1,2,0,0
#define VER_FILEVERSION 1,2,0,2308042025
#define VER_FILEVERSION 1,2,0,2308051122

#define VER_PRODUCTNAME_STR "TweakXL\0"
#define VER_PRODUCTVERSION_STR "1.2.0\0"
#define VER_FILEVERSION_STR "1.2.0.2308042025\0"
#define VER_FILEVERSION_STR "1.2.0.2308051122\0"

1 VERSIONINFO
FILEVERSION VER_FILEVERSION
Expand Down
5 changes: 3 additions & 2 deletions src/Red/Addresses.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

// Generated by cp77ida.py on 2023-08-04 for Cyberpunk 2077 v.1.63
// Generated by cp77ida.py on 2023-08-05 for Cyberpunk 2077 v.1.63
// DO NOT MODIFY. USE tools\ida\scan.py TO GENERATE THIS FILE.

#include <cstdint>
Expand All @@ -13,8 +13,9 @@ constexpr uintptr_t Main = 0x1401A0550 - ImageBase; // 40 53 48 81 EC ? ? ? ? FF

constexpr uintptr_t StatsDataSystem_InitializeRecords = 0x141A26120 - ImageBase; // 48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 83 EC ? 48 8B F9 E8 ? ? ? ? 48 BA, expected: 1, index: 0
constexpr uintptr_t StatsDataSystem_InitializeParams = 0x141A262C0 - ImageBase; // 48 8B C4 41 54 41 56 48 81 EC ? ? ? ? 8B 91 ? ? ? ? 4C 8D B1 ? ? ? ? 45 33 E4 48 89 58 ? 48 89 78, expected: 1, index: 0
constexpr uintptr_t StatsDataSystem_GetStatFlags = 0x141A24810 - ImageBase; // 48 89 74 24 ? 57 48 83 EC ? 8B FA 48 8B F1 81 FA ? ? ? ? 73 ? 48 81 C1 ? ? ? ? 48 89 5C 24, expected: 1, index: 0
constexpr uintptr_t StatsDataSystem_GetStatRange = 0x141A24880 - ImageBase; // 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC ? 41 8B F0 48 8B FA 48 8B E9 41 81 F8 ? ? ? ? 73, expected: 1, index: 0
constexpr uintptr_t StatsDataSystem_GetStatFlags = 0x141A24810 - ImageBase; // 48 89 74 24 ? 57 48 83 EC ? 8B FA 48 8B F1 81 FA ? ? ? ? 73 ? 48 81 C1 ? ? ? ? 48 89 5C 24, expected: 1, index: 0
constexpr uintptr_t StatsDataSystem_CheckStatFlag = 0x141A24C10 - ImageBase; // 48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC ? 8B FA 41 8B F0 48 8B E9 81 FA ? ? ? ? 73 ? 48 81 C1, expected: 1, index: 0

constexpr uintptr_t TweakDB_Load = 0x140BE6B50 - ImageBase; // 48 89 5C 24 18 55 57 41 56 48 8B EC 48 83 EC 70 48 8B D9 45 33 F6 48 8D, expected: 1, index: 0
constexpr uintptr_t TweakDB_CreateRecord = 0x140FD4930 - ImageBase; // 48 89 5C 24 08 ? 89 ? 24 18 57 48 83 EC 30 8B C2, expected: 1, index: 0
Expand Down
10 changes: 7 additions & 3 deletions src/Red/StatsDataSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ constexpr auto InitializeParams = Core::RawFunc<
/* addr = */ Red::Addresses::StatsDataSystem_InitializeParams,
/* type = */ void (*)(void* aSystem)>();

constexpr auto GetStatRange = Core::RawFunc<
/* addr = */ Red::Addresses::StatsDataSystem_GetStatRange,
/* type = */ uint64_t* (*)(void* aSystem, uint64_t*, uint32_t aStat)>();

constexpr auto GetStatFlags = Core::RawFunc<
/* addr = */ Red::Addresses::StatsDataSystem_GetStatFlags,
/* type = */ uint32_t (*)(void* aSystem, uint32_t aStat)>();

constexpr auto GetStatRange = Core::RawFunc<
/* addr = */ Red::Addresses::StatsDataSystem_GetStatRange,
/* type = */ uint64_t* (*)(void* aSystem, uint64_t*, uint32_t aStat)>();
constexpr auto CheckStatFlag = Core::RawFunc<
/* addr = */ Red::Addresses::StatsDataSystem_CheckStatFlag,
/* type = */ bool (*)(void* aSystem, uint32_t aStat, uint32_t aFlag)>();
}
2 changes: 1 addition & 1 deletion src/Red/TweakDB/Reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Core::SharedPtr<Red::TweakDBRecordInfo> Red::TweakDBReflection::CollectRecordInf

auto propInfo = Red::MakeInstance<Red::TweakDBPropertyInfo>();
propInfo->name = Red::CName(propName.c_str());
propInfo->dataOffset = baseOffset + DataOffsetSize * recordInfo->props.size();
propInfo->dataOffset = baseOffset + (recordInfo->props.size() * DataOffsetSize);

// Case: Foreign Key Array => TweakDBID[]
if (!func->returnType)
Expand Down
6 changes: 4 additions & 2 deletions tools/ida/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ def patterns():
pattern="48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 83 EC ? 48 8B F9 E8 ? ? ? ? 48 BA"),
Item(name="InitializeParams",
pattern="48 8B C4 41 54 41 56 48 81 EC ? ? ? ? 8B 91 ? ? ? ? 4C 8D B1 ? ? ? ? 45 33 E4 48 89 58 ? 48 89 78"),
Item(name="GetStatFlags",
pattern="48 89 74 24 ? 57 48 83 EC ? 8B FA 48 8B F1 81 FA ? ? ? ? 73 ? 48 81 C1 ? ? ? ? 48 89 5C 24"),
Item(name="GetStatRange",
pattern="48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC ? 41 8B F0 48 8B FA 48 8B E9 41 81 F8 ? ? ? ? 73"),
Item(name="GetStatFlags",
pattern="48 89 74 24 ? 57 48 83 EC ? 8B FA 48 8B F1 81 FA ? ? ? ? 73 ? 48 81 C1 ? ? ? ? 48 89 5C 24"),
Item(name="CheckStatFlag",
pattern="48 89 6C 24 ? 48 89 74 24 ? 57 48 83 EC ? 8B FA 41 8B F0 48 8B E9 81 FA ? ? ? ? 73 ? 48 81 C1"),
]),
]),
]
Expand Down

0 comments on commit 73bf934

Please sign in to comment.