mirror of
https://git.chinosk6.cn/chinosk/gkms-local.git
synced 2026-04-12 00:17:41 +07:00
增加自定义画质设置
This commit is contained in:
@@ -433,6 +433,48 @@ namespace GakumasLocal::HookMain {
|
||||
return VLDOF_IsActive_Orig(_this);
|
||||
}
|
||||
|
||||
DEFINE_HOOK(void, CampusQualityManager_set_TargetFrameRate, (void* _this, float value)) {
|
||||
// Log::InfoFmt("CampusQualityManager_set_TargetFrameRate: %f", value);
|
||||
const auto configFps = Config::targetFrameRate;
|
||||
CampusQualityManager_set_TargetFrameRate_Orig(_this, configFps == 0 ? value : (float)configFps);
|
||||
}
|
||||
|
||||
DEFINE_HOOK(void, CampusQualityManager_ApplySetting, (void* _this, int qualitySettingsLevel, int maxBufferPixel, float renderScale, int volumeIndex)) {
|
||||
if (Config::targetFrameRate != 0) {
|
||||
CampusQualityManager_set_TargetFrameRate_Orig(_this, Config::targetFrameRate);
|
||||
}
|
||||
if (Config::useCustomeGraphicSettings) {
|
||||
static auto SetReflectionQuality = Il2cppUtils::GetMethod("campus-submodule.Runtime.dll", "Campus.Common",
|
||||
"CampusQualityManager", "SetReflectionQuality");
|
||||
static auto SetLODQuality = Il2cppUtils::GetMethod("campus-submodule.Runtime.dll", "Campus.Common",
|
||||
"CampusQualityManager", "SetLODQuality");
|
||||
|
||||
static auto Enum_GetValues = Il2cppUtils::GetMethod("mscorlib.dll", "System", "Enum", "GetValues");
|
||||
|
||||
static auto QualityLevel_klass = Il2cppUtils::GetClass("campus-submodule.Runtime.dll", "", "QualityLevel");
|
||||
|
||||
static auto values = Enum_GetValues->Invoke<UnityResolve::UnityType::Array<int>*>(QualityLevel_klass->GetType())->ToVector();
|
||||
if (values.empty()) {
|
||||
values = {0x0, 0xa, 0x14, 0x1e, 0x28, 0x64};
|
||||
}
|
||||
if (Config::lodQualityLevel >= values.size()) Config::lodQualityLevel = values.size() - 1;
|
||||
if (Config::reflectionQualityLevel >= values.size()) Config::reflectionQualityLevel = values.size() - 1;
|
||||
|
||||
SetLODQuality->Invoke<void>(_this, values[Config::lodQualityLevel]);
|
||||
SetReflectionQuality->Invoke<void>(_this, values[Config::reflectionQualityLevel]);
|
||||
|
||||
qualitySettingsLevel = Config::qualitySettingsLevel;
|
||||
maxBufferPixel = Config::maxBufferPixel;
|
||||
renderScale = Config::renderScale;
|
||||
volumeIndex = Config::volumeIndex;
|
||||
|
||||
Log::ShowToastFmt("ApplySetting\nqualityLevel: %d, maxBufferPixel: %d\nenderScale: %f, volumeIndex: %d\nLODQualityLv: %d, ReflectionLv: %d",
|
||||
qualitySettingsLevel, maxBufferPixel, renderScale, volumeIndex, Config::lodQualityLevel, Config::reflectionQualityLevel);
|
||||
}
|
||||
|
||||
CampusQualityManager_ApplySetting_Orig(_this, qualitySettingsLevel, maxBufferPixel, renderScale, volumeIndex);
|
||||
}
|
||||
|
||||
void StartInjectFunctions() {
|
||||
const auto hookInstaller = Plugin::GetInstance().GetHookInstaller();
|
||||
UnityResolve::Init(xdl_open(hookInstaller->m_il2cppLibraryPath.c_str(), RTLD_NOW), UnityResolve::Mode::Il2Cpp);
|
||||
@@ -488,6 +530,14 @@ namespace GakumasLocal::HookMain {
|
||||
Il2cppUtils::GetMethodPointer("Unity.RenderPipelines.Universal.Runtime.dll", "VL.Rendering",
|
||||
"VLDOF", "IsActive"));
|
||||
|
||||
ADD_HOOK(CampusQualityManager_ApplySetting,
|
||||
Il2cppUtils::GetMethodPointer("campus-submodule.Runtime.dll", "Campus.Common",
|
||||
"CampusQualityManager", "ApplySetting"));
|
||||
|
||||
ADD_HOOK(CampusQualityManager_set_TargetFrameRate,
|
||||
Il2cppUtils::GetMethodPointer("campus-submodule.Runtime.dll", "Campus.Common",
|
||||
"CampusQualityManager", "set_TargetFrameRate"));
|
||||
|
||||
ADD_HOOK(Internal_LogException, Il2cppUtils::il2cpp_resolve_icall(
|
||||
"UnityEngine.DebugLogHandler::Internal_LogException(System.Exception,UnityEngine.Object)"));
|
||||
ADD_HOOK(Internal_Log, Il2cppUtils::il2cpp_resolve_icall(
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
#include "Log.h"
|
||||
#include <android/log.h>
|
||||
#include <Misc.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
std::string format(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
extern JavaVM* g_javaVM;
|
||||
extern jclass g_gakumasHookMainClass;
|
||||
extern jmethodID showToastMethodId;
|
||||
|
||||
// 计算格式化后的字符串长度
|
||||
int size = vsnprintf(nullptr, 0, fmt, args_copy) + 1; // 加上额外的终止符空间
|
||||
va_end(args_copy);
|
||||
|
||||
// 动态分配缓冲区
|
||||
char* buffer = new char[size];
|
||||
|
||||
// 格式化字符串
|
||||
vsnprintf(buffer, size, fmt, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
std::string result(buffer);
|
||||
delete[] buffer; // 释放缓冲区
|
||||
return result;
|
||||
}
|
||||
#define GetParamStringResult(name)\
|
||||
va_list args;\
|
||||
va_start(args, fmt);\
|
||||
va_list args_copy;\
|
||||
va_copy(args_copy, args);\
|
||||
int size = vsnprintf(nullptr, 0, fmt, args_copy) + 1;\
|
||||
va_end(args_copy);\
|
||||
char* buffer = new char[size];\
|
||||
vsnprintf(buffer, size, fmt, args);\
|
||||
va_end(args);\
|
||||
std::string name(buffer);\
|
||||
delete[] buffer
|
||||
|
||||
|
||||
namespace GakumasLocal::Log {
|
||||
@@ -33,26 +29,7 @@ namespace GakumasLocal::Log {
|
||||
}
|
||||
|
||||
void LogFmt(int prio, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
|
||||
// 计算格式化后的字符串长度
|
||||
int size = vsnprintf(nullptr, 0, fmt, args_copy) + 1; // 加上额外的终止符空间
|
||||
va_end(args_copy);
|
||||
|
||||
// 动态分配缓冲区
|
||||
char* buffer = new char[size];
|
||||
|
||||
// 格式化字符串
|
||||
vsnprintf(buffer, size, fmt, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
std::string result(buffer);
|
||||
delete[] buffer; // 释放缓冲区
|
||||
|
||||
GetParamStringResult(result);
|
||||
Log(prio, result.c_str());
|
||||
}
|
||||
|
||||
@@ -61,26 +38,7 @@ namespace GakumasLocal::Log {
|
||||
}
|
||||
|
||||
void InfoFmt(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
|
||||
// 计算格式化后的字符串长度
|
||||
int size = vsnprintf(nullptr, 0, fmt, args_copy) + 1; // 加上额外的终止符空间
|
||||
va_end(args_copy);
|
||||
|
||||
// 动态分配缓冲区
|
||||
char* buffer = new char[size];
|
||||
|
||||
// 格式化字符串
|
||||
vsnprintf(buffer, size, fmt, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
std::string result(buffer);
|
||||
delete[] buffer; // 释放缓冲区
|
||||
|
||||
GetParamStringResult(result);
|
||||
Info(result.c_str());
|
||||
}
|
||||
|
||||
@@ -89,26 +47,7 @@ namespace GakumasLocal::Log {
|
||||
}
|
||||
|
||||
void ErrorFmt(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
|
||||
// 计算格式化后的字符串长度
|
||||
int size = vsnprintf(nullptr, 0, fmt, args_copy) + 1; // 加上额外的终止符空间
|
||||
va_end(args_copy);
|
||||
|
||||
// 动态分配缓冲区
|
||||
char* buffer = new char[size];
|
||||
|
||||
// 格式化字符串
|
||||
vsnprintf(buffer, size, fmt, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
std::string result(buffer);
|
||||
delete[] buffer; // 释放缓冲区
|
||||
|
||||
GetParamStringResult(result);
|
||||
Error(result.c_str());
|
||||
}
|
||||
|
||||
@@ -117,50 +56,44 @@ namespace GakumasLocal::Log {
|
||||
}
|
||||
|
||||
void DebugFmt(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
|
||||
// 计算格式化后的字符串长度
|
||||
int size = vsnprintf(nullptr, 0, fmt, args_copy) + 1; // 加上额外的终止符空间
|
||||
va_end(args_copy);
|
||||
|
||||
// 动态分配缓冲区
|
||||
char* buffer = new char[size];
|
||||
|
||||
// 格式化字符串
|
||||
vsnprintf(buffer, size, fmt, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
std::string result(buffer);
|
||||
delete[] buffer; // 释放缓冲区
|
||||
|
||||
GetParamStringResult(result);
|
||||
Debug(result.c_str());
|
||||
}
|
||||
|
||||
void LogUnityLog(int prio, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
|
||||
// 计算格式化后的字符串长度
|
||||
int size = vsnprintf(nullptr, 0, fmt, args_copy) + 1; // 加上额外的终止符空间
|
||||
va_end(args_copy);
|
||||
|
||||
// 动态分配缓冲区
|
||||
char* buffer = new char[size];
|
||||
|
||||
// 格式化字符串
|
||||
vsnprintf(buffer, size, fmt, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
std::string result(buffer);
|
||||
delete[] buffer; // 释放缓冲区
|
||||
|
||||
GetParamStringResult(result);
|
||||
__android_log_write(prio, "GakumasLog", result.c_str());
|
||||
}
|
||||
|
||||
void ShowToast(const std::string& text) {
|
||||
DebugFmt("Toast: %s", text.c_str());
|
||||
|
||||
std::thread([text](){
|
||||
auto env = Misc::GetJNIEnv();
|
||||
if (!env) {
|
||||
return;
|
||||
}
|
||||
g_javaVM->AttachCurrentThread(&env, nullptr);
|
||||
|
||||
jclass& kotlinClass = g_gakumasHookMainClass;
|
||||
if (!kotlinClass) {
|
||||
g_javaVM->DetachCurrentThread();
|
||||
return;
|
||||
}
|
||||
jmethodID& methodId = showToastMethodId;
|
||||
if (!methodId) {
|
||||
g_javaVM->DetachCurrentThread();
|
||||
return;
|
||||
}
|
||||
jstring param = env->NewStringUTF(text.c_str());
|
||||
env->CallStaticVoidMethod(kotlinClass, methodId, param);
|
||||
|
||||
g_javaVM->DetachCurrentThread();
|
||||
}).detach();
|
||||
}
|
||||
|
||||
void ShowToastFmt(const char* fmt, ...) {
|
||||
GetParamStringResult(result);
|
||||
ShowToast(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ namespace GakumasLocal::Log {
|
||||
void ErrorFmt(const char* fmt, ...);
|
||||
void Debug(const char* msg);
|
||||
void DebugFmt(const char* fmt, ...);
|
||||
|
||||
void ShowToast(const char* text);
|
||||
void ShowToastFmt(const char* fmt, ...);
|
||||
}
|
||||
|
||||
#endif //GAKUMAS_LOCALIFY_LOG_H
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <jni.h>
|
||||
|
||||
|
||||
extern JavaVM* g_javaVM;
|
||||
|
||||
|
||||
namespace GakumasLocal::Misc {
|
||||
@@ -14,4 +18,17 @@ namespace GakumasLocal::Misc {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> utf16conv;
|
||||
return utf16conv.to_bytes(str.data(), str.data() + str.size());
|
||||
}
|
||||
|
||||
JNIEnv* GetJNIEnv() {
|
||||
if (!g_javaVM) return nullptr;
|
||||
JNIEnv* env = nullptr;
|
||||
if (g_javaVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||
int status = g_javaVM->AttachCurrentThread(&env, nullptr);
|
||||
if (status < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
} // namespace UmaPyogin::Misc
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <jni.h>
|
||||
|
||||
namespace GakumasLocal {
|
||||
using OpaqueFunctionPointer = void (*)();
|
||||
@@ -10,6 +11,7 @@ namespace GakumasLocal {
|
||||
namespace Misc {
|
||||
std::u16string ToUTF16(const std::string_view& str);
|
||||
std::string ToUTF8(const std::u16string_view& str);
|
||||
JNIEnv* GetJNIEnv();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Misc.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <jni.h>
|
||||
|
||||
namespace GakumasLocal {
|
||||
struct HookInstaller
|
||||
|
||||
@@ -14,6 +14,14 @@ namespace GakumasLocal::Config {
|
||||
std::string liveCustomeHeadId = "";
|
||||
std::string liveCustomeCostumeId = "";
|
||||
|
||||
bool useCustomeGraphicSettings = false;
|
||||
float renderScale = 0.77f;
|
||||
int qualitySettingsLevel = 3;
|
||||
int volumeIndex = 3;
|
||||
int maxBufferPixel = 3384;
|
||||
int reflectionQualityLevel = 4;
|
||||
int lodQualityLevel = 4;
|
||||
|
||||
void LoadConfig(const std::string& configStr) {
|
||||
try {
|
||||
const auto config = nlohmann::json::parse(configStr);
|
||||
@@ -27,6 +35,13 @@ namespace GakumasLocal::Config {
|
||||
GetConfigItem(enableLiveCustomeDress);
|
||||
GetConfigItem(liveCustomeHeadId);
|
||||
GetConfigItem(liveCustomeCostumeId);
|
||||
GetConfigItem(useCustomeGraphicSettings);
|
||||
GetConfigItem(renderScale);
|
||||
GetConfigItem(qualitySettingsLevel);
|
||||
GetConfigItem(volumeIndex);
|
||||
GetConfigItem(maxBufferPixel);
|
||||
GetConfigItem(reflectionQualityLevel);
|
||||
GetConfigItem(lodQualityLevel);
|
||||
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
|
||||
@@ -14,6 +14,15 @@ namespace GakumasLocal::Config {
|
||||
extern std::string liveCustomeHeadId;
|
||||
extern std::string liveCustomeCostumeId;
|
||||
|
||||
extern bool useCustomeGraphicSettings;
|
||||
extern float renderScale;
|
||||
extern int qualitySettingsLevel;
|
||||
extern int volumeIndex;
|
||||
extern int maxBufferPixel;
|
||||
|
||||
extern int reflectionQualityLevel;
|
||||
extern int lodQualityLevel;
|
||||
|
||||
void LoadConfig(const std::string& configStr);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "GakumasLocalify/camera/camera.hpp"
|
||||
#include "GakumasLocalify/config/Config.hpp"
|
||||
|
||||
JavaVM* g_javaVM = nullptr;
|
||||
jclass g_gakumasHookMainClass = nullptr;
|
||||
jmethodID showToastMethodId = nullptr;
|
||||
|
||||
namespace
|
||||
{
|
||||
class AndroidHookInstaller : public GakumasLocal::HookInstaller
|
||||
@@ -40,11 +44,20 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
g_javaVM = vm;
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_io_github_chinosk_gakumas_localify_GakumasHookMain_initHook(JNIEnv *env, jclass clazz, jstring targetLibraryPath,
|
||||
jstring localizationFilesDir) {
|
||||
g_gakumasHookMainClass = clazz;
|
||||
showToastMethodId = env->GetStaticMethodID(clazz, "showToast", "(Ljava/lang/String;)V");
|
||||
|
||||
const auto targetLibraryPathChars = env->GetStringUTFChars(targetLibraryPath, nullptr);
|
||||
const std::string targetLibraryPathStr = targetLibraryPathChars;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user