Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit fbc350b

Browse files
committed
Fix dummy file not being created, causing some mods to not work properly
1 parent 87bf479 commit fbc350b

File tree

6 files changed

+32
-143
lines changed

6 files changed

+32
-143
lines changed

libs/anno-api/include/anno/random_game_functions.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace anno
99
{
1010

1111
enum Address {
12-
GET_CONTAINER_BLOCK_INFO,
1312
READ_FILE_FROM_CONTAINER,
1413
SOME_GLOBAL_STRUCTURE_ARCHIVE,
1514
// ToolOneDataHelper::ReloadData
@@ -30,10 +29,6 @@ bool FindAddresses();
3029
uintptr_t GetAddress(Address address);
3130
void SetAddress(Address address, uint64_t add);
3231

33-
inline bool GetContainerBlockInfo(uintptr_t* a1, const std::wstring& file_path, int a3)
34-
{
35-
return meow_hook::func_call<bool>(GetAddress(GET_CONTAINER_BLOCK_INFO), a1, file_path, a3);
36-
}
3732
inline bool __fastcall ReadFileFromContainer(__int64 archive_file_map,
3833
const std::wstring& file_path,
3934
char** output_data_pointer, size_t* output_data_size)

libs/anno-api/src/random_game_functions.cc

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -80,81 +80,6 @@ bool FindAddresses()
8080
}
8181
initialized = true;
8282

83-
ADDRESSES[GET_CONTAINER_BLOCK_INFO] = {[](std::optional<std::string_view> game_file) {
84-
try {
85-
auto match =
86-
meow_hook::pattern(
87-
"48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 48 83 79 78 00 44 89 C6",
88-
game_file)
89-
.count(1)
90-
.get(0)
91-
.as<uintptr_t>();
92-
if (game_file) {
93-
return RebaseFileOffsetToMemoryAddess(
94-
match - reinterpret_cast<intptr_t>(game_file->data()));
95-
}
96-
return match;
97-
} catch (...) {
98-
}
99-
100-
// Game Update 7.3
101-
try {
102-
auto match = meow_hook::pattern("E8 ? ? ? ? 84 C0 75 7C", game_file)
103-
.count(1)
104-
.get(0);
105-
if (game_file) {
106-
match = match.adjust(
107-
RebaseFileOffsetToMemoryAddess(
108-
match.as<uintptr_t>() - reinterpret_cast<intptr_t>(game_file->data()))
109-
- match.as<uintptr_t>());
110-
}
111-
return match.extract_call();
112-
} catch (...) { }
113-
114-
try {
115-
auto match =
116-
meow_hook::pattern("E8 ? ? ? ? 84 C0 0F 84 ? ? ? ? F7 85 ? ? ? ? ? ? ? ?", game_file).count(1).get(0);
117-
if (game_file) {
118-
match = match.adjust(
119-
RebaseFileOffsetToMemoryAddess(
120-
match.as<uintptr_t>() - reinterpret_cast<intptr_t>(game_file->data()))
121-
- match.as<uintptr_t>());
122-
}
123-
return match.extract_call();
124-
} catch (...) {
125-
}
126-
127-
128-
try {
129-
// If this fails, we dead
130-
auto match =
131-
meow_hook::pattern(
132-
"48 89 5C 24 08 48 89 74 24 10 57 48 83 EC 20 48 83 79 78 00", game_file)
133-
.count(1)
134-
.get(0)
135-
.as<uintptr_t>();
136-
if (game_file) {
137-
return RebaseFileOffsetToMemoryAddess(
138-
match - reinterpret_cast<intptr_t>(game_file->data()));
139-
}
140-
return match;
141-
} catch (...) {
142-
143-
}
144-
145-
auto match = meow_hook::pattern("E8 ? ? ? ? 84 C0 0F 84 ? ? ? ? 4D 8B C5",
146-
game_file)
147-
.count(1)
148-
.get(0);
149-
if (game_file) {
150-
match = match.adjust(
151-
RebaseFileOffsetToMemoryAddess(match.as<uintptr_t>()
152-
- reinterpret_cast<intptr_t>(game_file->data()))
153-
- match.as<uintptr_t>());
154-
}
155-
return match.extract_call();
156-
}}; //
157-
15883
ADDRESSES[READ_FILE_FROM_CONTAINER] = {[](std::optional<std::string_view> game_file) {
15984
// Game Update 8
16085
try {

libs/external-file-loader/include/mod_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class ModManager
3838

3939
static fs::path GetModsDirectory();
4040
static fs::path GetCacheDirectory();
41+
static fs::path GetDummyPath();
42+
static void EnsureDummy();
4143

4244
bool IsFileModded(const fs::path& path) const;
4345
const File& GetModdedFileInfo(const fs::path& path) const;

libs/external-file-loader/src/external-file-loader.cc

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,56 +61,6 @@ bool ReadFileFromContainer(__int64 archive_file_map, const std::wstring& f
6161
return result;
6262
}
6363

64-
bool GetContainerBlockInfo(anno::rdsdk::CFile* file, const std::wstring& file_path, int a3)
65-
{
66-
#if defined(ADVANCED_HOOK_LOGS)
67-
if (!file_path.empty()) {
68-
spdlog::debug(L"GetContainerBlockInfo {} Size {}", file_path, file->size);
69-
}
70-
#endif
71-
72-
if (file_path.find(L"checksum.db") != std::wstring::npos) {
73-
ModManager::instance().GameFilesReady();
74-
}
75-
76-
77-
if (!fs::exists(ModManager::GetModsDirectory() / "dummy")) {
78-
std::fstream fs;
79-
fs.open(ModManager::GetModsDirectory() / "dummy", std::ios::out);
80-
fs.close();
81-
}
82-
auto m = file_path;
83-
if (ModManager::instance().IsFileModded(file_path)) {
84-
#if defined(ADVANCED_HOOK_LOGS)
85-
if (!file_path.empty()) {
86-
spdlog::debug(L"GetContainerBlockInfo Modded {} Size {} Handle {} Flags {}", file_path,
87-
file->size, (uintptr_t)file->file_handle, a3);
88-
}
89-
#endif
90-
a3 = 1;
91-
}
92-
auto result = anno::GetContainerBlockInfo((uintptr_t*)file, m, a3);
93-
if (m == L"mods/dummy") {
94-
file->file_path = file_path;
95-
}
96-
if (ModManager::instance().IsFileModded(file_path)) {
97-
auto info = ModManager::instance().GetModdedFileInfo(file_path);
98-
#if defined(ADVANCED_HOOK_LOGS)
99-
if (!file_path.empty()) {
100-
spdlog::debug(L"GetContainerBlockInfo Modded {} Size {} Info Size {} Handle {}", file_path, file->size,
101-
info.size, (uintptr_t)file->file_handle);
102-
}
103-
#endif
104-
file->size = info.size;
105-
} else {
106-
m = ModManager::MapAliasedPath(file_path);
107-
if (file->size == 0) {
108-
file->size = anno::rdsdk::CFile::GetFileSize(m);
109-
}
110-
}
111-
112-
return result;
113-
}
11464
inline size_t GetFileSize(fs::path m)
11565
{
11666
#if defined(ADVANCED_HOOK_LOGS)
@@ -138,6 +88,9 @@ inline size_t GetFileSize(fs::path m)
13888
} else {
13989
size = anno::rdsdk::CFile::GetFileSize(m);
14090
}
91+
#if defined(ADVANCED_HOOK_LOGS)
92+
spdlog::debug("Custom GetFileSize Result {}", size);
93+
#endif
14194
return size;
14295
}
14396

@@ -151,9 +104,6 @@ inline bool FileGetSize(uintptr_t a1, std::wstring &file_path, size_t* output_si
151104
auto mapped_path = ModManager::MapAliasedPath(file_path);
152105
if (ModManager::instance().IsFileModded(mapped_path)) {
153106
const auto& info = ModManager::instance().GetModdedFileInfo(mapped_path);
154-
#if defined(ADVANCED_HOOK_LOGS)
155-
spdlog::debug(L"rdsdk::CFile::GetFileSize Patched({})", info.is_patched);
156-
#endif
157107
if (info.is_patched) {
158108
*output_size = info.data.size();
159109
} else {
@@ -171,6 +121,10 @@ inline bool FileGetSize(uintptr_t a1, std::wstring &file_path, size_t* output_si
171121

172122
*output_size = lFileSize.QuadPart;
173123
}
124+
#if defined(ADVANCED_HOOK_LOGS)
125+
spdlog::debug(L"rdsdk::CFile::GetFileSize Patched({}) Size({})", info.is_patched,
126+
*output_size);
127+
#endif
174128
} else {
175129
auto r = anno::rdsdk::CFile::GetFileSize(a1, mapped_path.wstring(), output_size);
176130
#if defined(ADVANCED_HOOK_LOGS)
@@ -202,8 +156,8 @@ HANDLE FindFirstFileW_S(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)
202156
ULARGE_INTEGER nsize;
203157
nsize.QuadPart = size;
204158

205-
auto p = ModManager::GetModsDirectory();
206-
n = FindFirstFileW((p / L"dummy").wstring().c_str(), lpFindFileData);
159+
const auto dummy_path = ModManager::GetDummyPath();
160+
n = FindFirstFileW(dummy_path.wstring().c_str(), lpFindFileData);
207161
lpFindFileData->nFileSizeHigh = nsize.HighPart;
208162
lpFindFileData->nFileSizeLow = nsize.LowPart;
209163
SYSTEMTIME st;
@@ -401,13 +355,6 @@ void EnableExtenalFileLoading(Events& events)
401355
ReadFileFromContainer)));
402356
}
403357

404-
spdlog::debug("Patching GetContainerBlockInfo");
405-
{
406-
SetAddress(anno::GET_CONTAINER_BLOCK_INFO,
407-
uintptr_t(MH_STATIC_DETOUR(GetAddress(anno::GET_CONTAINER_BLOCK_INFO),
408-
GetContainerBlockInfo)));
409-
}
410-
411358
spdlog::debug("Patching ReadGameFile");
412359
ReadGameFile_QIP = MH_STATIC_DETOUR(GetAddress(anno::READ_GAME_FILE), ReadGameFile);
413360

libs/external-file-loader/src/mod_manager.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,26 @@ std::string ModManager::PushCacheLayer(const fs::path& game_path,
373373
return layer.output_hash;
374374
}
375375

376+
void ModManager::EnsureDummy()
377+
{
378+
static auto dummy_path = ModManager::GetDummyPath();
379+
if (!fs::exists(dummy_path)) {
380+
fs::create_directories(ModManager::GetCacheDirectory());
381+
std::fstream fs;
382+
fs.open(dummy_path, std::ios::out);
383+
fs.open(dummy_path, std::ios::out);
384+
fs.close();
385+
}
386+
}
387+
376388
void ModManager::GameFilesReady()
377389
{
378390
sort(begin(mods_), end(mods_), [](const auto& l, const auto& r) {
379391
return stricmp(l.Name().c_str(), r.Name().c_str()) < 0;
380392
});
381393

394+
ModManager::EnsureDummy();
395+
382396
patching_file_thread_ = std::thread([this]() {
383397
spdlog::info("Start applying xml operations");
384398

@@ -572,6 +586,12 @@ fs::path ModManager::GetCacheDirectory()
572586
{
573587
return ModManager::GetModsDirectory() / ".cache";
574588
}
589+
590+
fs::path ModManager::GetDummyPath()
591+
{
592+
return ModManager::GetCacheDirectory() / ".dummy";
593+
}
594+
575595
bool ModManager::IsPythonStartScript(const fs::path& file) const
576596
{
577597
const auto filename = file.filename();

libs/python35/src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// clang-format off
44
#define VERSION_MAJOR 0
55
#define VERSION_MINOR 7
6-
#define VERSION_REVISION 9
6+
#define VERSION_REVISION 10
77

88
#define STRINGIFY_(s) #s
99
#define STRINGIFY(s) STRINGIFY_(s)

0 commit comments

Comments
 (0)