From 29a095639f15337645c66d573855e03d5e34a861 Mon Sep 17 00:00:00 2001 From: Faumaray Date: Tue, 21 Oct 2025 00:09:24 +0300 Subject: [PATCH] fixing mingw errors Signed-off-by: Faumaray --- include/Agent.hpp | 26 +++++++++++++------------- src/Agent.cpp | 33 ++++++++++++++++----------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/include/Agent.hpp b/include/Agent.hpp index 550a8d7..25b9a1e 100644 --- a/include/Agent.hpp +++ b/include/Agent.hpp @@ -13,12 +13,13 @@ #include #include -extern "C" JNIEXPORT jint JNICALL Java_nativeAgentInit(JNIEnv* env, jclass clazz, jobjectArray args, jobject instrumentation); -extern "C" JNIEXPORT jint JNICALL Java_nativeAgentStart(JNIEnv* env, jclass clazz); -extern "C" JNIEXPORT jint JNICALL Java_ru_faumaray_VoidLoaderAgent_nativeAgentStart(JNIEnv* env, jclass clazz); -extern "C" JNIEXPORT jint JNICALL Java_ru_faumaray_VoidLoaderAgent_nativeAgentInit(JNIEnv* env, jclass jclass, jobject instrumentation, jobjectArray args); - -extern "C" JNIEXPORT void JNICALL Java_ru_faumaray_VoidLoaderAgent_nativeCleanup(JNIEnv* env, jclass clazz); +extern "C" { + JNIEXPORT jint JNICALL Java_nativeAgentInit(JNIEnv*, jclass, jobjectArray, jobject); + JNIEXPORT jint JNICALL Java_nativeAgentStart(JNIEnv*, jclass); + JNIEXPORT jint JNICALL Java_ru_faumaray_VoidLoaderAgent_nativeAgentStart(JNIEnv*, jclass); + JNIEXPORT jint JNICALL Java_ru_faumaray_VoidLoaderAgent_nativeAgentInit(JNIEnv*, jclass, jobject, jobjectArray); + JNIEXPORT void JNICALL Java_ru_faumaray_VoidLoaderAgent_nativeCleanup(JNIEnv*, jclass); +} namespace vl::Agent { class Agent { @@ -56,12 +57,11 @@ public: private: std::unordered_map findMods(const std::string& dir); - friend int JNICALL ::Java_nativeAgentInit(JNIEnv* env, jclass clazz, jobjectArray args, jobject instrumentation); - friend int JNICALL ::Java_nativeAgentInit(JNIEnv* env, jclass clazz, jobjectArray args, jobject instrumentation); - friend int JNICALL ::Java_nativeAgentStart(JNIEnv* env, jclass clazz); - friend int JNICALL ::Java_ru_faumaray_VoidLoaderAgent_nativeAgentStart(JNIEnv* env, jclass clazz); - friend int JNICALL ::Java_ru_faumaray_VoidLoaderAgent_nativeAgentInit(JNIEnv* env, jclass jclass, jobject instrumentation, jobjectArray args); - friend void JNICALL ::Java_ru_faumaray_VoidLoaderAgent_nativeCleanup(JNIEnv* env, jclass clazz); + friend jint ::Java_nativeAgentInit(JNIEnv*, jclass, jobjectArray, jobject); + friend jint ::Java_nativeAgentStart(JNIEnv*, jclass); + friend jint ::Java_ru_faumaray_VoidLoaderAgent_nativeAgentStart(JNIEnv*, jclass); + friend jint ::Java_ru_faumaray_VoidLoaderAgent_nativeAgentInit(JNIEnv*, jclass, jobject, jobjectArray); + friend void ::Java_ru_faumaray_VoidLoaderAgent_nativeCleanup(JNIEnv*, jclass); friend class ClassTransformer; friend class vl::mod::ModLoader; private: @@ -72,7 +72,7 @@ private: std::unique_ptr m_modloader; std::unique_ptr m_transformer; vl::mod::Context m_context; - std::atomic m_isValid; + std::atomic m_isValid{false}; std::shared_ptr m_logger; static std::unique_ptr instance_; static std::once_flag initFlag_; diff --git a/src/Agent.cpp b/src/Agent.cpp index a256259..157d29c 100644 --- a/src/Agent.cpp +++ b/src/Agent.cpp @@ -17,18 +17,17 @@ namespace vl::Agent { auto currentPath = std::filesystem::current_path(); if (!args.contains("gameDir")) { - args["gameDir"] = currentPath; + args["gameDir"] = currentPath.string(); } - auto gameDir = args["gameDir"]; - auto dataDir = args["gameDir"] + std::filesystem::path::preferred_separator + "data"; - auto logDir = args["gameDir"] + std::filesystem::path::preferred_separator + "logs"; - auto modsDir = args["gameDir"] + std::filesystem::path::preferred_separator + "mods"; - m_context = { - .gameDir = std::move(gameDir), - .dataDir = std::move(dataDir), - .logDir = std::move(logDir), - .apiVersion = {1,0,0}, - }; + std::filesystem::path gameDir = args["gameDir"]; + std::filesystem::path dataDir = gameDir / "data"; + std::filesystem::path logDir = gameDir / "logs"; + std::filesystem::path modsDir = gameDir / "mods"; + m_context = {}; // if defaultable + m_context.gameDir = std::move(gameDir); + m_context.dataDir = std::move(dataDir); + m_context.logDir = std::move(logDir); + m_context.apiVersion = {1,0,0}; auto mods = findMods(modsDir); if (!mods.contains("VoidLoaderApi.vlmod")) { @@ -58,7 +57,7 @@ namespace vl::Agent { std::unordered_map result; for (auto& entry : std::filesystem::directory_iterator(dir)) { if (entry.path().extension() == ".vlmod") { - result.emplace(entry.path().filename(), std::filesystem::absolute(entry.path())); + result.emplace(entry.path().filename().string(), std::filesystem::absolute(entry.path())); } } return result; @@ -81,7 +80,7 @@ extern "C" JNIEXPORT jint JNICALL Java_nativeAgentInit(JNIEnv* env, jclass clazz auto& instance = vl::Agent::Agent::getInstance(argsMap); try { - auto coreLogDir = std::string(instance.m_context.logDir) + std::filesystem::path::preferred_separator + "VoidLoader"; + auto coreLogDir = (instance.m_context.logDir / "VoidLoader").string(); vl::logging::init_voidloader_logger(); instance.m_logger = vl::logging::LoggerManager::instance().createCombined("VoidLoader", coreLogDir.c_str(), 512'000, vl::logging::Level::Trace); vl::logging::LoggerManager::instance().createConsole("VoidLoader")->setLevel(vl::logging::Level::Info); @@ -104,9 +103,9 @@ extern "C" JNIEXPORT jint JNICALL Java_nativeAgentInit(JNIEnv* env, jclass clazz instance.m_jni = env; jvmtiEventCallbacks callbacks = {0}; - callbacks.ClassFileLoadHook = &instance.m_transformer->classFileLoadHook; - callbacks.VMInit = &instance.vmInit; - callbacks.VMDeath = &instance.vmDeath; + callbacks.ClassFileLoadHook = &ClassTransformer::classFileLoadHook; // provide a static thunk + callbacks.VMInit = &vl::Agent::Agent::vmInit; // static + callbacks.VMDeath = &vl::Agent::Agent::vmDeath; // static auto cerror = instance.m_jmti->SetEventCallbacks(&callbacks, sizeof(callbacks)); if (cerror != JVMTI_ERROR_NONE) { @@ -134,7 +133,7 @@ extern "C" JNIEXPORT jint JNICALL Java_nativeAgentStart(JNIEnv* env, jclass claz for (auto& [name, path] : instance.m_mods) { instance.m_logger->trace("Loading mod: {}", name); - loaded += instance.m_modloader->loadModule(path, instance.m_context, false); + loaded += instance.m_modloader->loadModule(path.string(), instance.m_context, false); } instance.m_logger->info("Mods loaded: {}, Starting", loaded);