-
Notifications
You must be signed in to change notification settings - Fork 2
/
ArchiveTreePatcher.cpp
64 lines (49 loc) · 1.67 KB
/
ArchiveTreePatcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "ArchiveTreePatcher.h"
const std::vector<std::pair<const char*, const std::vector<const char*>>> NODES =
{
{ "DualShock3Common", {"SonicActionCommon", "SonicActionCommonHud", "SystemCommon", "cmn200", "Guide", "pam_cmn", "Title", "NoticeBoard", "pam000"} }
};
HOOK(bool, __stdcall, ParseArchiveTree, 0xD4C8E0, void* A1, char* pData, const size_t size, void* pDatabase)
{
std::string str;
{
std::stringstream stream;
for (auto& node : NODES)
{
stream << " <Node>\n";
stream << " <Name>" << node.first << "</Name>\n";
stream << " <Archive>" << node.first << "</Archive>\n";
stream << " <Order>" << 0 << "</Order>\n";
stream << " <DefAppend>" << node.first << "</DefAppend>\n";
for (auto& archive : node.second)
{
stream << " <Node>\n";
stream << " <Name>" << archive << "</Name>\n";
stream << " <Archive>" << archive << "</Archive>\n";
stream << " <Order>" << 0 << "</Order>\n";
stream << " </Node>\n";
}
stream << " </Node>\n";
}
str = stream.str();
}
const size_t newSize = size + str.size();
const std::unique_ptr<char[]> pBuffer = std::make_unique<char[]>(newSize);
memcpy(pBuffer.get(), pData, size);
char* pInsertionPos = strstr(pBuffer.get(), "<Include>");
memmove(pInsertionPos + str.size(), pInsertionPos, size - (size_t)(pInsertionPos - pBuffer.get()));
memcpy(pInsertionPos, str.c_str(), str.size());
bool result;
{
result = originalParseArchiveTree(A1, pBuffer.get(), newSize, pDatabase);
}
return result;
}
bool ArchiveTreePatcher::enabled = false;
void ArchiveTreePatcher::applyPatches()
{
if (enabled)
return;
enabled = true;
INSTALL_HOOK(ParseArchiveTree);
}