From 3665ae851a92c8f4abf9e591119c6f99bc2dacce Mon Sep 17 00:00:00 2001 From: chinosk <2248589280@qq.com> Date: Mon, 27 May 2024 21:03:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E9=94=81=E6=B8=B2=E6=9F=93=E5=88=86?= =?UTF-8?q?=E8=BE=A8=E7=8E=87=E4=B8=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/GakumasLocalify/Hook.cpp | 42 +++++++++++++++++++ .../main/cpp/GakumasLocalify/Il2cppUtils.hpp | 6 +++ 2 files changed, 48 insertions(+) diff --git a/app/src/main/cpp/GakumasLocalify/Hook.cpp b/app/src/main/cpp/GakumasLocalify/Hook.cpp index 068e7aa..389f03c 100644 --- a/app/src/main/cpp/GakumasLocalify/Hook.cpp +++ b/app/src/main/cpp/GakumasLocalify/Hook.cpp @@ -98,6 +98,12 @@ namespace GakumasLocal::HookMain { cameraTransformCache = mainCameraCache->GetTransform(); } + Il2cppUtils::Resolution_t GetResolution() { + static auto GetResolution = Il2cppUtils::GetMethod("UnityEngine.CoreModule.dll", "UnityEngine", + "Screen", "get_currentResolution"); + return GetResolution->Invoke(); + } + DEFINE_HOOK(void, Unity_set_fieldOfView, (UnityResolve::UnityType::Camera* _this, float value)) { if (Config::enableFreeCamera) { if (_this == mainCameraCache) { @@ -475,6 +481,29 @@ namespace GakumasLocal::HookMain { CampusQualityManager_ApplySetting_Orig(_this, qualitySettingsLevel, maxBufferPixel, renderScale, volumeIndex); } + DEFINE_HOOK(void, UIManager_UpdateRenderTarget, (UnityResolve::UnityType::Vector2 ratio, void* mtd)) { + // const auto resolution = GetResolution(); + // Log::DebugFmt("UIManager_UpdateRenderTarget: %f, %f", ratio.x, ratio.y); + return UIManager_UpdateRenderTarget_Orig(ratio, mtd); + } + + DEFINE_HOOK(void, VLSRPCameraController_UpdateRenderTarget, (void* _this, int width, int height, bool forceAlpha, void* method)) { + // const auto resolution = GetResolution(); + // Log::DebugFmt("VLSRPCameraController_UpdateRenderTarget: %d, %d", width, height); + return VLSRPCameraController_UpdateRenderTarget_Orig(_this, width, height, forceAlpha, method); + } + + DEFINE_HOOK(void*, VLUtility_GetLimitedResolution, (int32_t screenWidth, int32_t screenHeight, + UnityResolve::UnityType::Vector2 aspectRatio, int32_t maxBufferPixel, float bufferScale, bool firstCall)) { + + if (Config::useCustomeGraphicSettings && (Config::renderScale > 1.0f)) { + screenWidth *= Config::renderScale; + screenHeight *= Config::renderScale; + } + //Log::DebugFmt("VLUtility_GetLimitedResolution: %d, %d, %f, %f", screenWidth, screenHeight, aspectRatio.x, aspectRatio.y); + return VLUtility_GetLimitedResolution_Orig(screenWidth, screenHeight, aspectRatio, maxBufferPixel, bufferScale, firstCall); + } + void StartInjectFunctions() { const auto hookInstaller = Plugin::GetInstance().GetHookInstaller(); UnityResolve::Init(xdl_open(hookInstaller->m_il2cppLibraryPath.c_str(), RTLD_NOW), UnityResolve::Mode::Il2Cpp); @@ -534,6 +563,19 @@ namespace GakumasLocal::HookMain { Il2cppUtils::GetMethodPointer("campus-submodule.Runtime.dll", "Campus.Common", "CampusQualityManager", "ApplySetting")); + ADD_HOOK(UIManager_UpdateRenderTarget, + Il2cppUtils::GetMethodPointer("ADV.Runtime.dll", "Campus.ADV", + "UIManager", "UpdateRenderTarget")); + ADD_HOOK(VLSRPCameraController_UpdateRenderTarget, + Il2cppUtils::GetMethodPointer("vl-unity.Runtime.dll", "VL.Rendering", + "VLSRPCameraController", "UpdateRenderTarget", + {"*", "*", "*"})); + + ADD_HOOK(VLUtility_GetLimitedResolution, + Il2cppUtils::GetMethodPointer("vl-unity.Runtime.dll", "VL", + "VLUtility", "GetLimitedResolution", + {"*", "*", "*", "*", "*", "*"})); + ADD_HOOK(CampusQualityManager_set_TargetFrameRate, Il2cppUtils::GetMethodPointer("campus-submodule.Runtime.dll", "Campus.Common", "CampusQualityManager", "set_TargetFrameRate")); diff --git a/app/src/main/cpp/GakumasLocalify/Il2cppUtils.hpp b/app/src/main/cpp/GakumasLocalify/Il2cppUtils.hpp index 182a216..580c5f6 100644 --- a/app/src/main/cpp/GakumasLocalify/Il2cppUtils.hpp +++ b/app/src/main/cpp/GakumasLocalify/Il2cppUtils.hpp @@ -36,6 +36,12 @@ namespace Il2cppUtils { uint8_t is_marshaled_from_native : 1; }; + struct Resolution_t { + int width; + int height; + int herz; + }; + UnityResolve::Class* GetClass(const std::string& assemblyName, const std::string& nameSpaceName, const std::string& className) { const auto assembly = UnityResolve::Get(assemblyName);