62 lines
2.0 KiB
C++
62 lines
2.0 KiB
C++
#include "../GakumasLocalify/GakumasLocalify/Plugin.h"
|
|
#include "../GakumasLocalify/GakumasLocalify/config/Config.hpp"
|
|
#include "../GakumasLocalify/GakumasLocalify/Log.h"
|
|
#include "../il2cpp_dump/il2cppTypes.hpp"
|
|
#include "IOSHookInstaller.h"
|
|
|
|
#include <dlfcn.h>
|
|
#include <os/log.h>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
|
|
// JavaVM* g_javaVM = nullptr;
|
|
// jclass g_gakumasHookMainClass = nullptr;
|
|
// jmethodID showToastMethodId = nullptr;
|
|
|
|
std::filesystem::path gakumasLocalPath;
|
|
|
|
namespace {
|
|
|
|
std::string ReadWholeFile(const std::filesystem::path& path) {
|
|
std::ifstream in(path);
|
|
if (!in.is_open()) {
|
|
return "";
|
|
}
|
|
std::ostringstream ss;
|
|
ss << in.rdbuf();
|
|
return ss.str();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
extern "C" void InitHook(void* unityFramework, void* unityBaseAddress,
|
|
const char* unityFrameworkPath,
|
|
const char* configJsonStr,
|
|
const char* localizationBaseDir) {
|
|
GakumasLocal::Log::InfoFmt("Init hook localizationBaseDir: %s", localizationBaseDir);
|
|
GakumasLocal::Log::InfoFmt("Init hook configJsonStr: %s", configJsonStr);
|
|
|
|
const std::string configJson =
|
|
(configJsonStr && configJsonStr[0] != '\0') ? configJsonStr : "{}";
|
|
GakumasLocal::Config::LoadConfig(configJson);
|
|
|
|
GakumasLocal::Log::Info("Config loaded");
|
|
|
|
const std::string baseDir =
|
|
(localizationBaseDir && localizationBaseDir[0] != '\0')
|
|
? localizationBaseDir
|
|
: "";
|
|
gakumasLocalPath = baseDir;
|
|
|
|
auto installer = std::make_unique<IOSHookInstaller>(unityFramework);
|
|
installer->localizationFilesDir = baseDir;
|
|
if (unityFrameworkPath && unityFrameworkPath[0] != '\0') {
|
|
installer->m_il2cppLibraryPath = unityFrameworkPath;
|
|
}
|
|
GakumasLocal::Plugin::GetInstance().SetHookInstaller(std::move(installer));
|
|
|
|
Il2cppJson::Init(reinterpret_cast<uintptr_t>(unityBaseAddress));
|
|
GakumasLocal::Plugin::GetInstance().InstallHook(/*std::move(installer)*/);
|
|
}
|