mirror of
https://github.com/esuo1198/TaikoArcadeLoader.git
synced 2026-10-03 20:28:01 +03:00
Language patch | Fix boot lag | Fix axis input
This commit is contained in:
+39
-95
@@ -17,25 +17,6 @@ std::thread *hookInstall;
|
||||
std::mutex hooksMutex;
|
||||
std::condition_variable hooksCV;
|
||||
|
||||
// void
|
||||
// AddHookInLoop (std::function<void ()> installMethod) {
|
||||
// // hooks.push (installMethod);
|
||||
// hooksCV.notify_all ();
|
||||
// }
|
||||
|
||||
// void
|
||||
// HookInstallLoop () {
|
||||
// std::unique_lock<std::mutex> hooksLock(hooksMutex);
|
||||
// while (!hookInstallFinished) {
|
||||
// while (!hooks.empty ()) {
|
||||
// auto installMethod = hooks.front ();
|
||||
// hooks.pop ();
|
||||
// if (installMethod) installMethod ();
|
||||
// }
|
||||
// if (!hookInstallFinished) hooksCV.wait (hooksLock);
|
||||
// }
|
||||
// }
|
||||
|
||||
std::wstring
|
||||
mergeCondition (std::wstring original, std::wstring addition, std::wstring value) {
|
||||
size_t pos = original.find (L"/");
|
||||
@@ -56,18 +37,6 @@ addConditionValue (pugi::xml_node *node, std::wstring key, std::wstring addition
|
||||
attr.set_value (mergeCondition(attr.value (), addition, value).c_str ());
|
||||
} else node->append_attribute (key.c_str ()) = std::format(L"True/{}:{}", addition, value).c_str ();
|
||||
}
|
||||
class RegisteredHook : public Applicable {
|
||||
public:
|
||||
std::function<void ()> registerInit;
|
||||
RegisteredHook (const std::function<void ()> &initMethod) {
|
||||
this->registerInit = initMethod;
|
||||
}
|
||||
pugi::xml_node *
|
||||
Apply (pugi::xml_node *doc, pugi::xml_node *node) override {
|
||||
// AddHookInLoop (this->registerInit);
|
||||
return node;
|
||||
}
|
||||
};
|
||||
class RegisteredItem : public Applicable {
|
||||
public:
|
||||
std::wstring selectItem;
|
||||
@@ -237,26 +206,27 @@ Menu *modManager = new RegisteredMenu (L"MOD MANAGER", L"ModManagerMenu");
|
||||
// std::vector<RegisteredItem *> registeredItems = {};
|
||||
std::vector<RegisteredSingleItem *> registeredSingleItems = {};
|
||||
std::vector<RegisteredModify *> registeredModifies = {};
|
||||
std::vector<RegisteredHook *> registeredHooks = {};
|
||||
std::wstring moddedInitial = L"";
|
||||
std::wstring modded = L"";
|
||||
|
||||
std::wstring originalDeviceInitialize = L"";
|
||||
std::wstring usingDeviceInitialize = L"";
|
||||
std::wstring moddedDeviceInitialize = L"DeviceInitialize_mod.xml";
|
||||
std::wstring originalTestMode = L"";
|
||||
std::wstring usingTestMode = L"";
|
||||
std::wstring moddedTestMode = L"TestMode_mod.xml";
|
||||
|
||||
u64 appAccessor = 0;
|
||||
RefTestModeMain refTestMode = nullptr;
|
||||
|
||||
std::wstring
|
||||
ReadXMLFileSwitcher (std::wstring &fileName) {
|
||||
const std::size_t pos = fileName.rfind (L"/");
|
||||
const std::wstring file = fileName.substr (pos + 1, fileName.size ());
|
||||
std::wstring base = fileName.substr (0, pos + 1);
|
||||
FAST_HOOK_DYNAMIC (char, SceneTestModeLoading, u64 a1, u64 a2, u64 a3) {
|
||||
char result = originalSceneTestModeLoading.fastcall<char> (a1, a2, a3);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (gameVersion == GameVersion::JPN39 && chsPatch) {
|
||||
if (file.starts_with (L"DeviceInitialize")) base.append (L"DeviceInitialize_china.xml");
|
||||
if (file.starts_with (L"TestMode")) base.append (L"TestMode_china.xml");
|
||||
if (std::filesystem::exists (base)) return base;
|
||||
}
|
||||
|
||||
return fileName;
|
||||
FAST_HOOK_DYNAMIC (char, SceneTestModeFinalize, u64 a1, u64 a2, u64 a3) {
|
||||
char result = originalSceneTestModeFinalize.fastcall<char> (a1, a2, a3);
|
||||
return result;
|
||||
}
|
||||
|
||||
FAST_HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t *lFileName) {
|
||||
@@ -264,17 +234,15 @@ FAST_HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t
|
||||
const auto originalFileName = std::wstring (lFileName);
|
||||
LogMessage (LogLevel::DEBUG, L"Begin Loading {}", originalFileName);
|
||||
std::wstring fileName = originalFileName;
|
||||
if (fileName.ends_with (L"DeviceInitialize.xml") || fileName.ends_with (L"DeviceInitialize_asia.xml")
|
||||
|| fileName.ends_with (L"DeviceInitialize_china.xml")) {
|
||||
if (fileName.ends_with (originalDeviceInitialize)) {
|
||||
if (moddedInitial == L"") {
|
||||
fileName = ReadXMLFileSwitcher (fileName);
|
||||
fileName = replace (originalFileName, originalDeviceInitialize, usingDeviceInitialize);
|
||||
if (pugi::xml_document doc; !doc.load_file (fileName.c_str ())) {
|
||||
LogMessage (LogLevel::ERROR, L"Loading DeviceInitialize structure failed! path: " + fileName);
|
||||
moddedInitial = fileName;
|
||||
moddedInitial = originalFileName;
|
||||
fileName = originalFileName;
|
||||
} else {
|
||||
const std::wstring modFileName
|
||||
= replace (replace (replace (fileName, L"lize_asia.xml", L"lize_mod.xml"), L"lize_china.xml", L"lize_mod.xml"), L"lize.xml",
|
||||
L"lize_mod.xml");
|
||||
const std::wstring modFileName = replace (originalFileName, originalDeviceInitialize, moddedDeviceInitialize);
|
||||
const pugi::xpath_query dongleQuery = pugi::xpath_query (L"/root/menu[@id='TopMenu']/layout[@type='Center']/select-item[@id='DongleItem']");
|
||||
const pugi::xml_node dongleItem = doc.select_node (dongleQuery).node ();
|
||||
pugi::xml_node talItem = dongleItem.parent ().append_copy (dongleItem);
|
||||
@@ -288,17 +256,16 @@ FAST_HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t
|
||||
fileName = modFileName;
|
||||
}
|
||||
} else fileName = moddedInitial;
|
||||
} else if (fileName.ends_with (L"TestMode.xml") || fileName.ends_with (L"TestMode_asia.xml") || fileName.ends_with (L"TestMode_china.xml")) {
|
||||
} else if (fileName.ends_with (originalTestMode)) {
|
||||
if (modded == L"") {
|
||||
if (!((RegisteredMenu*)modManager)->items.empty () || registeredSingleItems.empty () || !registeredModifies.empty ()) {
|
||||
fileName = ReadXMLFileSwitcher (fileName);
|
||||
fileName = replace (originalFileName, originalTestMode, usingTestMode);
|
||||
if (pugi::xml_document doc; !doc.load_file (fileName.c_str ())) {
|
||||
LogMessage (LogLevel::ERROR, L"Loading TestMode structure failed! path: " + fileName);
|
||||
modded = fileName;
|
||||
modded = originalFileName;
|
||||
fileName = originalFileName;
|
||||
} else {
|
||||
const std::wstring modFileName
|
||||
= replace (replace (replace (fileName, L"Mode_asia.xml", L"Mode_mod.xml"), L"Mode_china.xml", L"Mode_mod.xml"), L"Mode.xml",
|
||||
L"Mode_mod.xml");
|
||||
const std::wstring modFileName = replace (originalFileName, originalTestMode, moddedTestMode);
|
||||
if (!((RegisteredMenu*)modManager)->items.empty ()) {
|
||||
LogMessage (LogLevel::DEBUG, "Begin generate Mod Manager menu");
|
||||
pugi::xpath_query menuQuery
|
||||
@@ -320,13 +287,6 @@ FAST_HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t
|
||||
LogMessage (LogLevel::DEBUG, "End Apply Modify Items");
|
||||
}
|
||||
|
||||
if (!registeredHooks.empty ()) {
|
||||
LogMessage (LogLevel::DEBUG, "Begin Apply Hooks");
|
||||
for (RegisteredHook *hook : registeredHooks) hook->Apply (&doc, &doc);
|
||||
LogMessage (LogLevel::DEBUG, "End Apply Hooks");
|
||||
}
|
||||
|
||||
// AddHookInLoop ([&](){ hookInstallFinished = true; });
|
||||
[[maybe_unused]] auto _ = doc.save_file (modFileName.c_str ());
|
||||
modded = modFileName;
|
||||
fileName = modFileName;
|
||||
@@ -340,16 +300,6 @@ FAST_HOOK_DYNAMIC (void, TestModeSetMenuHook, u64 testModeLibrary, const wchar_t
|
||||
originalTestModeSetMenuHook.fastcall<void> (testModeLibrary, fileName.c_str ());
|
||||
}
|
||||
|
||||
// HOOK_DYNAMIC (void, TestModeGetValueHook, u64 *reader, const wchar_t *lItemName, int *value) {
|
||||
// originalTestModeGetValueHook (reader, lItemName, value);
|
||||
// LogMessage (LogLevel::DEBUG, L"TestMode get Item: {} Value: {}", lItemName, *value);
|
||||
// }
|
||||
|
||||
// HOOK_DYNAMIC (void, TestModeSetValueHook, u64 *reader, const wchar_t *lItemName, int value) {
|
||||
// LogMessage (LogLevel::DEBUG, L"TestMode set Item: {} Value: {}", lItemName, value);
|
||||
// originalTestModeSetValueHook (reader, lItemName, value);
|
||||
// }
|
||||
|
||||
void
|
||||
CommonModify () {
|
||||
// Default off Close time
|
||||
@@ -482,28 +432,29 @@ void
|
||||
Init () {
|
||||
LogMessage (LogLevel::INFO, "Init TestMode patches");
|
||||
|
||||
const auto configPath = std::filesystem::current_path () / "config.toml";
|
||||
const std::unique_ptr<toml_table_t, void (*) (toml_table_t *)> config_ptr (openConfig (configPath), toml_free);
|
||||
|
||||
const u64 testModeLibrary = (u64)GetModuleHandle ("TestModeLibrary.dll");
|
||||
const u64 testModeSetMenu = testModeLibrary + 0x99D0;
|
||||
// const u64 testModeGetValue = testModeLibrary + 0x6FB18;
|
||||
// const u64 testModeSetValue = testModeLibrary + 0x6FAC8;
|
||||
|
||||
LogMessage (LogLevel::DEBUG, "TestModeLibrary: {}", testModeLibrary);
|
||||
// LogMessage (LogLevel::DEBUG, "TestModeLibrary set: {}", testModeSetValue);
|
||||
// LogMessage (LogLevel::DEBUG, "TestModeLibrary get: {}", testModeGetValue);
|
||||
switch (gameVersion) {
|
||||
case GameVersion::UNKNOWN: break;
|
||||
case GameVersion::JPN00: break;
|
||||
case GameVersion::JPN08: break;
|
||||
case GameVersion::JPN39: {
|
||||
if (config_ptr) {
|
||||
if (const auto patches = openConfigSection (config_ptr.get (), "patches")) {
|
||||
if (const auto jpn39 = openConfigSection (patches, "jpn39")) chsPatch = readConfigBool (jpn39, "chs_patch", chsPatch);
|
||||
}
|
||||
}
|
||||
if (chsPatch) LocalizationCHT ();
|
||||
INSTALL_FAST_HOOK_DYNAMIC (SceneTestModeLoading, ASLR (0x1404793D0));
|
||||
INSTALL_FAST_HOOK_DYNAMIC (SceneTestModeFinalize, ASLR (0x140479600));
|
||||
originalDeviceInitialize = L"DeviceInitialize.xml";
|
||||
if (std::filesystem::exists ("..\\..\\Data\\x64\\testmode\\DeviceInitialize_chspatch.xml")) {
|
||||
usingDeviceInitialize = L"DeviceInitialize_chspatch.xml";
|
||||
WRITE_MEMORY (ASLR (0x140CD1E40), wchar_t, L"加載中\0");
|
||||
WRITE_MEMORY (ASLR (0x140CD1E28), wchar_t, L"加載中.\0");
|
||||
WRITE_MEMORY (ASLR (0x140CD1E68), wchar_t, L"加載中..\0");
|
||||
WRITE_MEMORY (ASLR (0x140CD1E50), wchar_t, L"加載中...\0");
|
||||
} else usingDeviceInitialize = originalDeviceInitialize;
|
||||
originalTestMode = L"TestMode.xml";
|
||||
if (std::filesystem::exists ("..\\..\\Data\\x64\\testmode\\TestMode_chspatch.xml")) {
|
||||
usingTestMode = L"TestMode_chspatch.xml";
|
||||
} else usingTestMode = originalTestMode;
|
||||
|
||||
} break;
|
||||
case GameVersion::CHN00: break;
|
||||
}
|
||||
@@ -512,8 +463,6 @@ Init () {
|
||||
|
||||
INSTALL_FAST_HOOK_DYNAMIC (TestModeSetMenuHook, testModeSetMenu);
|
||||
for (auto method : hooks) method ();
|
||||
// INSTALL_HOOK_DYNAMIC (TestModeGetValueHook, testModeGetValue);
|
||||
// INSTALL_HOOK_DYNAMIC (TestModeSetValueHook, testModeSetValue);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -528,13 +477,10 @@ ReadTestModeValue (const wchar_t *itemId) {
|
||||
if (const u64 testModeMain = refTestMode (appAccessor)) {
|
||||
int value = 0;
|
||||
u64 *reader = *reinterpret_cast<u64 **> (testModeMain + 16);
|
||||
// LogMessage (LogLevel::DEBUG, "TestMode get:{} set:{}", *reader + 256, *reader + 176);
|
||||
(*reinterpret_cast<void (__fastcall **) (u64 *, const wchar_t *, int *)> (*reader + 256)) (reader, itemId, &value);
|
||||
// originalTestModeGetValueHook (reader, itemId, &value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
LogMessage (LogLevel::ERROR, (std::wstring (L"Read TestMode(") + itemId + L") failed!").c_str ());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -544,7 +490,6 @@ SetTestModeValue (const wchar_t *itemId, int value) {
|
||||
if (const u64 testModeMain = refTestMode (appAccessor)) {
|
||||
u64 *reader = *reinterpret_cast<u64 **> (testModeMain + 16);
|
||||
(*reinterpret_cast<void (__fastcall **) (u64 *, const wchar_t *, int)> (*reader + 176)) (reader, itemId, value);
|
||||
// ((TestModeSetValueHook)whereTestModeSetMenuHook) (reader, itemId, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -629,7 +574,6 @@ void
|
||||
RegisterHook (const std::function<void()> &initMethod) {
|
||||
LogMessage (LogLevel::DEBUG, L"Register Hook");
|
||||
hooks.push_back (initMethod);
|
||||
// registeredHooks.push_back (new RegisteredHook (initMethod));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user