Skip to content

Commit

Permalink
Added uiLoadingShowOrientationGuide option, improved force landscape …
Browse files Browse the repository at this point in the history
…mode behavior
  • Loading branch information
Kimjio committed Aug 11, 2022
1 parent be494cd commit d11f87c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 78 deletions.
3 changes: 2 additions & 1 deletion README.ko-KR.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- `uiAnimationScale` UI 애니메이션 배율 변경 (0 < ~, 기본값: `1`)
- 주의: `0` 으로 설정 시 소프트락이 발생합니다.
- `uiUseSystemResolution` UI, 라이브 자막 등을 시스템 해상도로 렌더링합니다. (`true` / `false`, 기본값: `false`)
- `replaceToBuiltinFont` (`replaceFont`) 게임 내 폰트를 사용하지 않고 유니티 내장 폰트를 사용합니다. (`true` / `false`, 기본값: `true`)
- `replaceToBuiltinFont` (`replaceFont`) 게임 내 폰트를 사용하지 않고 유니티 내장 폰트를 사용합니다. (`true` / `false`, 기본값: `false`)
- `replaceToCustomFont` 게임 내 폰트를 사용하지 않고 사용자 지정 폰트를 사용합니다. (`true` / `false`, 기본값: `false`)
- `fontAssetBundlePath` 폰트 애셋 번들 경로 (예: `custom_font/GyeonggiTitle_Medium/font`)
- `fontAssetName` 폰트 애셋 이름 (예: `GyeonggiTitle_Medium.fontsettings`)
Expand All @@ -40,6 +40,7 @@
- `8`: MSAA x8
- `forceLandscape` 모든 화면을 강제로 가로로 설정합니다. (`true` / `false`, 기본값: `false`)
- `forceLandscapeUiScale` 강제 가로 모드에 사용할 UI 스케일을 설정합니다. (0 < ~, 기본값: `1.8`)
- `uiLoadingShowOrientationGuide` 화면이 회전되었을 때, 로딩 중 가이드를 표시할지 여부를 설정합니다. (`true` / `false`, 기본값: `true`)
- `replaceAssetsPath` 게임에서 다운로드한 애셋을 대체할 애셋들이 담긴 폴더의 경로를 설정합니다.
- 대체할 애셋 파일의 이름은 원본 애셋 파일의 해시명과 동일해야 합니다.
- 예: `2FOXNDZ5H52B3E4JMXVAJ4FRMDE3PX7Q` (홈 Footer 텍스처 및 스크립트가 포함된 애셋 (Android))
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Working directory is `/sdcard/Android/data/jp.co.cygames.umamusume/`
- `uiAnimationScale` Change UI animation scale (0 < ~, Default: `1`)
- Caution: Soft lock occurs when set to `0`.
- `uiUseSystemResolution` Renders UI, live subtitles, and more at system resolution. (`true` / `false`, Default: `false`)
- `replaceToBuiltinFont` (`replaceFont`) Use Unity builtin fonts instead of in-game fonts. (`true` / `false`, Default: `true`)
- `replaceToBuiltinFont` (`replaceFont`) Use Unity builtin fonts instead of in-game fonts. (`true` / `false`, Default: `false`)
- `replaceToCustomFont` Use custom fonts instead of in-game fonts. (`true` / `false`, Default: `false`)
- `fontAssetBundlePath` Font asset bundle path (ex: `custom_font/GyeonggiTitle_Medium/font`)
- `fontAssetName` Font asset name (ex: `GyeonggiTitle_Medium.fontsettings`)
Expand All @@ -40,6 +40,7 @@ Working directory is `/sdcard/Android/data/jp.co.cygames.umamusume/`
- `8`: MSAA x8
- `forceLandscape` Force all screens to landscape. (`true` / `false`, Default: `false`)
- `forceLandscapeUiScale` Sets the UI scale to use for forced landscape mode. (0 < ~, Default: `1.8`)
- `uiLoadingShowOrientationGuide` Set whether to display the loading guide when the screen is rotated (`true` / `false`, Default: `true`)
- `replaceAssetsPath` Set the path to the folder containing the assets to replace the downloaded assets in the game.
- The name of the asset file to be replaced must be the same as the hash name of the original asset file.
- ex: `2FOXNDZ5H52B3E4JMXVAJ4FRMDE3PX7Q` (Asset containing the Home footer texture and scripts (Android))
Expand Down
4 changes: 2 additions & 2 deletions module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ext {
moduleName = "UmamusumeLocalify"
moduleAuthor = "Kimjio"
moduleDescription = "umamusume-localify"
moduleVersion = "2.2.0"
moduleVersionCode = 10
moduleVersion = "2.3.0"
moduleVersionCode = 11
moduleUpdateJson = "https://raw.githubusercontent.com/Kimjio/umamusume-localify-android/main/update"

// Riru
Expand Down
8 changes: 4 additions & 4 deletions module/src/main/cpp/hook.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//
// Created by Perfare on 2020/7/4.
//

#include <sstream>
#include <thread>
#include "stdinclude.hpp"
Expand All @@ -28,6 +24,7 @@ int g_graphics_quality = -1;
int g_anti_aliasing = -1;
bool g_force_landscape = false;
float g_force_landscape_ui_scale = 1.8;
bool g_ui_loading_show_orientation_guide = true;
std::unordered_map<std::string, ReplaceAsset> g_replace_assets;

GameRegion gameRegion = GameRegion::UNKNOWN;
Expand Down Expand Up @@ -273,6 +270,9 @@ std::optional<std::vector<std::string>> read_config() {
g_force_landscape_ui_scale = 1;
}
}
if (document.HasMember("uiLoadingShowOrientationGuide")) {
g_ui_loading_show_orientation_guide = document["uiLoadingShowOrientationGuide"].GetBool();
}
if (document.HasMember("replaceAssetsPath")) {
auto replaceAssetsPath = localify::u8_u16(document["replaceAssetsPath"].GetString());
if (!replaceAssetsPath.starts_with(u"/")) {
Expand Down
128 changes: 58 additions & 70 deletions module/src/main/cpp/il2cpp_hook.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//
// Created by kimji on 2022-05-01.
//
#include "stdinclude.hpp"
#include "il2cpp_hook.h"
#include "il2cpp/il2cpp_symbols.h"
Expand All @@ -27,6 +24,8 @@ Il2CppString *(*uobject_get_name)(Il2CppObject *uObject);

Il2CppString *(*get_unityVersion)();

Il2CppObject *sceneManager = nullptr;

const Il2CppType *
GetRuntimeType(const char *assemblyName, const char *namespaze, const char *klassName) {
auto dummyObj = (Il2CppObject *) il2cpp_object_new(
Expand Down Expand Up @@ -502,9 +501,13 @@ Il2CppObject *
wait_resize_ui_hook(Il2CppObject *thisObj, bool isPortrait, bool isShowOrientationGuide) {
if (g_force_landscape) {
isPortrait = false;
isShowOrientationGuide = false;
}
if (!g_ui_loading_show_orientation_guide) {
isShowOrientationGuide = false;
}
return reinterpret_cast<decltype(wait_resize_ui_hook) *>(wait_resize_ui_orig)(
thisObj, isPortrait, false);
thisObj, isPortrait, isShowOrientationGuide);
}

void *set_anti_aliasing_orig = nullptr;
Expand All @@ -527,7 +530,6 @@ void set_resolution_hook(int width, int height, bool fullscreen) {
int systemWidth = get_system_width(display_main);
int systemHeight = get_system_height(display_main);
// Unity 2019 not invert width, height on landscape
LOGD("set_resolution: %d %d %d", systemWidth, systemHeight, fullscreen);
if ((width > height && systemWidth < systemHeight) || g_force_landscape) {
reinterpret_cast<decltype(set_resolution_hook) *>(set_resolution_orig)(
systemHeight, systemWidth,
Expand All @@ -547,7 +549,6 @@ void apply_graphics_quality_hook(Il2CppObject *thisObj, int quality, bool force)
true);
}


void *load_one_orig = nullptr;

Boolean load_one_hook(Il2CppObject *thisObj, Il2CppObject *handle, Il2CppObject *request) {
Expand Down Expand Up @@ -599,65 +600,40 @@ Il2CppObject *ChangeScreenOrientation_hook(ScreenOrientation targetOrientation,
g_force_landscape ? ScreenOrientation::Landscape : targetOrientation, isForce);
}

void *UpdateCanvasScaler_orig = nullptr;

void UpdateCanvasScaler_hook(Il2CppObject *canvasScaler) {
if (canvasScaler) {
auto setUiScaleMode = reinterpret_cast<void *(*)(Il2CppObject *thisObj,
int ScaleMode)>(il2cpp_class_get_method_from_name(
canvasScaler->klass, "set_uiScaleMode", 1)->methodPointer);
auto setReferenceResolution = reinterpret_cast<void *(*)(Il2CppObject *thisObj,
Vector2_t value)>(il2cpp_class_get_method_from_name(
canvasScaler->klass, "set_referenceResolution", 1)->methodPointer);
auto setScreenMatchMode = reinterpret_cast<void *(*)(Il2CppObject *thisObj,
int ScreenMatchMode)>(il2cpp_class_get_method_from_name(
canvasScaler->klass, "set_screenMatchMode", 1)->methodPointer);
auto setMatchWidthOrHeight = reinterpret_cast<void *(*)(Il2CppObject *thisObj,
float value)>(il2cpp_class_get_method_from_name(
canvasScaler->klass, "set_matchWidthOrHeight", 1)->methodPointer);
if (g_force_landscape) {
setUiScaleMode(canvasScaler, 1);
int systemWidth = get_system_width(display_main);
int systemHeight = get_system_height(display_main);

if (systemWidth < systemHeight) {
setReferenceResolution(canvasScaler,
Vector2_t{.x = static_cast<float>(systemHeight) * g_force_landscape_ui_scale, .y =
static_cast<float>(systemWidth) * g_force_landscape_ui_scale});
} else {
setReferenceResolution(canvasScaler,
Vector2_t{.x = static_cast<float>(systemWidth) * g_force_landscape_ui_scale, .y =
static_cast<float>(systemHeight) * g_force_landscape_ui_scale});
}
setScreenMatchMode(canvasScaler, 0);
setMatchWidthOrHeight(canvasScaler, 0.5f);
}
void *CanvasScaler_set_referenceResolution_orig = nullptr;

void CanvasScaler_set_referenceResolution_hook(Il2CppObject *thisObj, Vector2_t res) {
if (g_force_landscape) {
res.x = res.x * g_force_landscape_ui_scale;
res.y = res.y * g_force_landscape_ui_scale;
}
reinterpret_cast<decltype(UpdateCanvasScaler_hook) *>(UpdateCanvasScaler_orig)(canvasScaler);
return reinterpret_cast<decltype(CanvasScaler_set_referenceResolution_hook) *>(CanvasScaler_set_referenceResolution_orig)(
thisObj, res);
}

void *SetResolution_orig = nullptr;

void SetResolution_hook(int w, int h, bool fullScreen, bool forceUpdate) {
if (g_force_landscape) {
if (w > h && !forceUpdate) {
reinterpret_cast<decltype(SetResolution_hook) *>(SetResolution_orig)(
h, w,
fullScreen, forceUpdate);
void SetResolution_hook(int w, int h, bool fullscreen, bool forceUpdate) {
if (sceneManager) {
SceneId sceneId = reinterpret_cast<SceneId (*)(
Il2CppObject *)>(il2cpp_class_get_method_from_name(sceneManager->klass,
"GetCurrentSceneId",
0)->methodPointer)(sceneManager);
if (sceneId == SceneId::Live) {
return;
} else if (GetUnityVersion() == Unity2019) {
reinterpret_cast<decltype(SetResolution_hook) *>(SetResolution_orig)(
h, w,
fullScreen, forceUpdate);
}
if (sceneId == SceneId::Story) {
return;
}
if (sceneId == SceneId::Episode) {
return;
}
}
reinterpret_cast<decltype(SetResolution_hook) *>(SetResolution_orig)(w, h, fullScreen,

reinterpret_cast<decltype(SetResolution_hook) *>(SetResolution_orig)(w, h, fullscreen,
forceUpdate);
if (GetUnityVersion() == Unity2020 && g_force_landscape) {
reinterpret_cast<decltype(set_resolution_hook) *>(set_resolution_orig)(h, w,
fullScreen);
if (g_force_landscape) {
reinterpret_cast<decltype(set_resolution_hook) *>(set_resolution_orig)(h, w, fullscreen);
}
};

Expand Down Expand Up @@ -686,7 +662,7 @@ void *NowLoading_Show_orig = nullptr;
void NowLoading_Show_hook(Il2CppObject *thisObj, int type, Il2CppObject *onComplete,
float overrideDuration) {
// NowLoadingOrientation
if (type == 2 && g_force_landscape) {
if (type == 2 && (g_force_landscape || !g_ui_loading_show_orientation_guide)) {
// NowLoadingTips
type = 0;
}
Expand All @@ -700,13 +676,21 @@ void *WaitDeviceOrientation_orig = nullptr;

void WaitDeviceOrientation_hook(ScreenOrientation targetOrientation) {
if ((targetOrientation == ScreenOrientation::Portrait ||
targetOrientation == ScreenOrientation::PortraitUpsideDown) && g_force_landscape) {
targetOrientation == ScreenOrientation::PortraitUpsideDown) && g_force_landscape) {
targetOrientation = ScreenOrientation::Landscape;
}
reinterpret_cast<decltype(WaitDeviceOrientation_hook) *>(WaitDeviceOrientation_orig)(
targetOrientation);
}

void *SceneManager_ctor_orig = nullptr;

void SceneManager_ctor_hook(Il2CppObject *thisObj) {
sceneManager = thisObj;
reinterpret_cast<decltype(SceneManager_ctor_hook) *>(SceneManager_ctor_orig)(thisObj);
}


void dump_all_entries() {
// 0 is None
for (int i = 1;; i++) {
Expand Down Expand Up @@ -985,15 +969,16 @@ void hookMethods() {
"UnityEngine",
"Screen", "set_orientation", 1));

auto UpdateCanvasScaler_addr = reinterpret_cast<void (*)()>(il2cpp_symbols::get_method_pointer(
"umamusume.dll",
"Gallop", "UIManager", "UpdateCanvasScaler", 1));

auto SetResolution_addr = reinterpret_cast<void (*)(int, int, bool,
bool)>(il2cpp_symbols::get_method_pointer(
"umamusume.dll",
"Gallop", "Screen", "SetResolution", 4));

auto SceneManager_ctor_addr = reinterpret_cast<void (*)(
Il2CppObject *)>(il2cpp_symbols::get_method_pointer(
"umamusume.dll",
"Gallop", "SceneManager", ".ctor", 0));

auto DeviceOrientationGuide_Show_addr = reinterpret_cast<void (*)(bool,
int)>(il2cpp_symbols::get_method_pointer(
"umamusume.dll",
Expand All @@ -1004,11 +989,16 @@ void hookMethods() {
"umamusume.dll",
"Gallop", "NowLoading", "Show", 3));

auto WaitDeviceOrientation_addr = reinterpret_cast<void (*)(int, Il2CppObject *,
float)>(il2cpp_symbols::get_method_pointer(
auto WaitDeviceOrientation_addr = reinterpret_cast<void (*)(
ScreenOrientation)>(il2cpp_symbols::get_method_pointer(
"umamusume.dll",
"Gallop", "Screen", "WaitDeviceOrientation", 1));

auto CanvasScaler_set_referenceResolution_addr = reinterpret_cast<void (*)(Il2CppObject *,
float)>(il2cpp_symbols::get_method_pointer(
"UnityEngine.UI.dll",
"UnityEngine.UI", "CanvasScaler", "set_referenceResolution", 1));

load_from_file = reinterpret_cast<Il2CppObject *(*)(
Il2CppString *path)>(il2cpp_symbols::get_method_pointer(
"UnityEngine.AssetBundleModule.dll", "UnityEngine", "AssetBundle", "LoadFromFile", 1));
Expand Down Expand Up @@ -1079,21 +1069,22 @@ void hookMethods() {
LOGD("ADD_HOOK: %s", #_name_); \
DobbyHook((void *)_name_##_addr, (void *) _name_##_hook, (void **) &_name_##_orig);
#pragma endregion
ADD_HOOK(SceneManager_ctor);

ADD_HOOK(CanvasScaler_set_referenceResolution);

ADD_HOOK(Screen_set_orientation);

ADD_HOOK(SetResolution);

ADD_HOOK(WaitDeviceOrientation);

ADD_HOOK(NowLoading_Show);

ADD_HOOK(DeviceOrientationGuide_Show);

ADD_HOOK(SetResolution);

ADD_HOOK(ChangeScreenOrientation);

ADD_HOOK(UpdateCanvasScaler);

ADD_HOOK(assetbundle_unload);

ADD_HOOK(load_one);
Expand All @@ -1104,10 +1095,7 @@ void hookMethods() {

ADD_HOOK(an_text_set_material_to_textmesh)

// Crashed on KOR (SEGV_ACCERR)
if (gameRegion == GameRegion::JAP) {
ADD_HOOK(load_zekken_composite_resource)
}
ADD_HOOK(load_zekken_composite_resource)

ADD_HOOK(wait_resize_ui)

Expand Down

0 comments on commit d11f87c

Please sign in to comment.