Skip to content

Commit

Permalink
Merge pull request #71 from chinosk114514/main
Browse files Browse the repository at this point in the history
增加高画质、垂直同步选项
  • Loading branch information
chinosk6 authored Aug 26, 2022
2 parents 49643ea + 444403a commit f6dd21f
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 6 deletions.
2 changes: 2 additions & 0 deletions resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"enableLogger": false,
"dumpStaticEntries": false,
"maxFps": 60,
"highQuality": true,
"enableVSync": false,
"unlockSize": false,
"unlockSizeOffset": {
"landspace": -0.07144,
Expand Down
12 changes: 10 additions & 2 deletions resources/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Umamusume Localify Config",
"title": "Trainers-Legend-G Config",
"description": "赛马娘本地化插件配置",
"type": "object",
"properties": {
Expand All @@ -16,10 +16,18 @@
"type": "boolean"
},
"maxFps": {
"description": "帧率限制 (-1 = 游戏原版/0 = 无限/>0 = 锁定到特定帧数)——注: 垂直同步已开启",
"description": "帧率限制 (-1 = 游戏原版/0 = 无限/>0 = 锁定到特定帧数)",
"type": "integer",
"minimum": -1
},
"highQuality": {
"description": "高画质模式 (抗锯齿 MSAA x8, 锁定图形质量等级到最高)",
"type": "boolean"
},
"enableVSync": {
"description": "开启垂直同步 (开启后 maxFps 设置将会失效)",
"type": "boolean"
},
"unlockSize": {
"description": "允许游戏使用`1080p`以上的分辨率",
"type": "boolean"
Expand Down
12 changes: 10 additions & 2 deletions resources/config_en.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Umamusume Localify Config",
"title": "Trainers-Legend-G Config",
"description": "Umamusume Localify Config",
"type": "object",
"properties": {
Expand All @@ -16,10 +16,18 @@
"type": "boolean"
},
"maxFps": {
"description": "Fps setting (-1 = Default fps|0 = Infinity|>0 = Limit game to specific fps)——Vertical synchronization is enabled",
"description": "Fps setting (-1 = Default fps|0 = Infinity|>0 = Limit game to specific fps)",
"type": "integer",
"minimum": -1
},
"highQuality": {
"description": "High quality mode (FullQuality, MSAA x8)",
"type": "boolean"
},
"enableVSync": {
"description": "Enable vertical synchronization",
"type": "boolean"
},
"unlockSize": {
"description": "Allow to use the resolution higher than `1080p`",
"type": "boolean"
Expand Down
Binary file modified resources/legend_g_plugin.exe
Binary file not shown.
44 changes: 42 additions & 2 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,27 @@ namespace
return reinterpret_cast<decltype(set_fps_hook)*>(set_fps_orig)(g_max_fps);
}

void* set_vsync_count_orig = nullptr;
void set_vsync_count_hook(int value) {
// printf("setVsyncCount: %d -> %d\n", value, g_vsync_count);
return reinterpret_cast<decltype(set_vsync_count_hook)*>(set_vsync_count_orig)(g_vsync_count == -1 ? value : g_vsync_count);
}

void* set_antialiasing_orig = nullptr;
void set_antialiasing_hook(int value) {
// printf("setAntialiasing: %d -> %d\n", value, g_antialiasing);
set_vsync_count_hook(1);
return reinterpret_cast<decltype(set_antialiasing_hook)*>(set_antialiasing_orig)(g_antialiasing == -1 ? value : g_antialiasing);
}

void* graphics_quality_orig = nullptr;
void graphics_quality_hook(Il2CppObject* thisObj, int quality, bool force) {
// printf("setGraphicsQuality: %d -> %d\n", quality, g_graphics_quality);
return reinterpret_cast<decltype(graphics_quality_hook)*>(graphics_quality_orig)(thisObj,
g_graphics_quality == -1 ? quality : g_graphics_quality,
true);
}

bool (*is_virt)() = nullptr;
int last_height = 0, last_width = 0;

Expand Down Expand Up @@ -917,11 +938,11 @@ namespace

if (width > height) {
_set_u_stat(false); // false-横屏
std::wprintf(L"to land: %d * %d\n", width, height);
// std::wprintf(L"to land: %d * %d\n", width, height);
}
else {
_set_u_stat(true);
std::wprintf(L"to virt: %d * %d\n", width, height);
// std::wprintf(L"to virt: %d * %d\n", width, height);
}

bool need_fullscreen = false;
Expand Down Expand Up @@ -1080,6 +1101,20 @@ namespace
"Application", "set_targetFrameRate", 1
);

auto set_antialiasing_addr = il2cpp_symbols::get_method_pointer(
"UnityEngine.CoreModule.dll", "UnityEngine",
"QualitySettings", "set_antiAliasing", 1
);

auto graphics_quality_addr = il2cpp_symbols::get_method_pointer(
"umamusume.dll", "Gallop",
"GraphicSettings", "ApplyGraphicsQuality", 2);

auto set_vsync_count_addr = il2cpp_symbols::get_method_pointer(
"UnityEngine.CoreModule.dll", "UnityEngine",
"QualitySettings", "set_vSyncCount", 1
);

auto wndproc_addr = il2cpp_symbols::get_method_pointer(
"umamusume.dll", "Gallop",
"StandaloneWindowResize", "WndProc", 4
Expand Down Expand Up @@ -1330,6 +1365,11 @@ namespace
ADD_HOOK(set_fps, "UnityEngine.Application.set_targetFrameRate at %p \n");
}

ADD_HOOK(set_antialiasing, "UnityEngine.CoreModule.QualitySettings.set_antiAliasing at %p\n");
ADD_HOOK(graphics_quality, "Gallop.GraphicSettings.ApplyGraphicsQuality at %p\n");
ADD_HOOK(set_vsync_count, "UnityEngine.CoreModule.QualitySettings.set_vSyncCount at %p\n");
set_vsync_count_hook(1);

// if (g_unlock_size)
// {
// break 1080p size limit
Expand Down
33 changes: 33 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ bool g_no_static_dict_cache;
std::string g_stories_path;
bool g_read_request_pack = true;
int http_start_port = 43215;
int g_antialiasing = -1;
int g_graphics_quality = -1;
int g_vsync_count = 0;

std::string g_text_data_dict_path;
std::string g_character_system_text_dict_path;
Expand Down Expand Up @@ -453,6 +456,36 @@ namespace
}
}

if (document.HasMember("highQuality")) {
if (document["highQuality"].GetBool()) {
g_graphics_quality = 3;
g_antialiasing = 8;
}
else {
g_graphics_quality = -1;
g_antialiasing = -1;
}
}

if (document.HasMember("enableVSync")) {
if (document["enableVSync"].GetBool()) {
g_vsync_count = 1;
}
else {
g_vsync_count = 0;
}
}

if (document.HasMember("antiAliasing")) { // 自定义配置, 不包含到schema
g_antialiasing = document["antiAliasing"].GetInt();
}
if (document.HasMember("graphics_quality")) { // 自定义配置, 不包含到schema
g_graphics_quality = document["graphics_quality"].GetInt();
}
if (document.HasMember("vSync_count")) { // 自定义配置, 不包含到schema
g_vsync_count = document["vSync_count"].GetInt();
}

if (document.HasMember("aspect_ratio")) {
if (document["aspect_ratio"].IsArray()) {
auto asp = document["aspect_ratio"].GetArray();
Expand Down
3 changes: 3 additions & 0 deletions src/stdinclude.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ extern int start_width;
extern int start_height;
extern bool openExternalPluginOnLoad;
extern int http_start_port;
extern int g_antialiasing;
extern int g_graphics_quality;
extern int g_vsync_count;

0 comments on commit f6dd21f

Please sign in to comment.