Skip to content

Commit

Permalink
Enhanced NowLoading fallback logic
Browse files Browse the repository at this point in the history
fix #10
  • Loading branch information
Kimjio committed Feb 19, 2023
1 parent d11035b commit 44eeed3
Showing 1 changed file with 28 additions and 108 deletions.
136 changes: 28 additions & 108 deletions module/src/main/cpp/il2cpp_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2006,166 +2006,82 @@ void DeviceOrientationGuide_Show_hook(Il2CppObject *thisObj, bool isTargetOrient
g_force_landscape ? 2 : target);
}

bool onCompleteCalled_Show = false;

void *onComplete_Show_addr = nullptr;

void *onComplete_Show_orig = nullptr;

void onComplete_Show_hook(Il2CppObject *thisObj) {
reinterpret_cast<decltype(onComplete_Show_hook) *>(onComplete_Show_orig)(thisObj);
onCompleteCalled_Show = true;
DobbyDestroy(onComplete_Show_addr);
}

void *NowLoading_Show_orig = nullptr;

void NowLoading_Show_hook(Il2CppObject *thisObj, int type, Il2CppDelegate *onComplete,
float overrideDuration) {
onCompleteCalled_Show = false;
// NowLoadingOrientation
if (type == 2 && (g_force_landscape || !g_ui_loading_show_orientation_guide)) {
// NowLoadingTips
type = 0;
}
if (onComplete) {
onComplete_Show_addr = reinterpret_cast<void *>(onComplete->method_ptr);
DobbyHook(onComplete_Show_addr, reinterpret_cast<void *>(onComplete_Show_hook),
reinterpret_cast<void **>(&onComplete_Show_orig));
}
if (!g_hide_now_loading) {
reinterpret_cast<decltype(NowLoading_Show_hook) *>(NowLoading_Show_orig)(
thisObj,
type,
onComplete, overrideDuration);
}
if (onComplete) {
thread timeoutThread([onComplete]() {
sleep(1);
if (!onCompleteCalled_Show) {
auto thread = il2cpp_thread_attach(il2cpp_domain_get());
LOGI("NowLoading::Show: onCompleteCalled not changed, calling onComplete manually...");
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete_Show_addr)(
if (g_hide_now_loading) {
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete->method_ptr)(onComplete->target);
} else {
const bool isShown = reinterpret_cast<bool (*)(
Il2CppObject *)>(il2cpp_class_get_method_from_name(
thisObj->klass, "IsShown", 0)->methodPointer)(thisObj);
if (!isShown) {
LOGI("NowLoading::Show: onComplete not called, calling onComplete manually...");
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete->method_ptr)(
onComplete->target);
il2cpp_thread_detach(thread);
} else {
DobbyDestroy(onComplete_Show_addr);
}
});
timeoutThread.detach();
}
}
}

void *NowLoading_Show2_orig = nullptr;

void NowLoading_Show2_hook(Il2CppObject *thisObj, int type, Il2CppDelegate *onComplete,
Il2CppObject *overrideDuration, int easeType) {
onCompleteCalled_Show = false;
// NowLoadingOrientation
if (type == 2 && (g_force_landscape || !g_ui_loading_show_orientation_guide)) {
// NowLoadingTips
type = 0;
}
if (onComplete) {
onComplete_Show_addr = reinterpret_cast<void *>(onComplete->method_ptr);
DobbyHook(onComplete_Show_addr, reinterpret_cast<void *>(onComplete_Show_hook),
reinterpret_cast<void **>(&onComplete_Show_orig));
}
if (!g_hide_now_loading) {
reinterpret_cast<decltype(NowLoading_Show2_hook) *>(NowLoading_Show2_orig)(
thisObj,
type,
onComplete, overrideDuration, easeType);
}
if (onComplete) {
thread timeoutThread([onComplete]() {
sleep(1);
if (!onCompleteCalled_Show) {
LOGI("NowLoading::Show: onCompleteCalled not changed, calling onComplete manually...");
auto thread = il2cpp_thread_attach(il2cpp_domain_get());
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete_Show_addr)(
if (g_hide_now_loading) {
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete->method_ptr)(onComplete->target);
} else {
const bool isShown = reinterpret_cast<bool (*)(
Il2CppObject *)>(il2cpp_class_get_method_from_name(
thisObj->klass, "IsShown", 0)->methodPointer)(thisObj);
if (!isShown) {
LOGI("NowLoading::Show: onComplete not called, calling onComplete manually...");
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete->method_ptr)(
onComplete->target);
il2cpp_thread_detach(thread);
} else {
DobbyDestroy(onComplete_Show_addr);
}
});
timeoutThread.detach();
}
}
}

bool onCompleteCalled_Hide = false;

void *onComplete_Hide_addr = nullptr;

void *onComplete_Hide_orig = nullptr;

void onComplete_Hide_hook(Il2CppObject *thisObj) {
reinterpret_cast<decltype(onComplete_Hide_hook) *>(onComplete_Hide_orig)(thisObj);
onCompleteCalled_Hide = true;
DobbyDestroy(onComplete_Hide_addr);
}

void *NowLoading_Hide_orig = nullptr;

void NowLoading_Hide_hook(Il2CppObject *thisObj, Il2CppDelegate *onComplete) {
onCompleteCalled_Hide = false;
if (onComplete) {
onComplete_Hide_addr = reinterpret_cast<void *>(onComplete->method_ptr);
DobbyHook(onComplete_Hide_addr, reinterpret_cast<void *>(onComplete_Hide_hook),
reinterpret_cast<void **>(&onComplete_Hide_orig));
}
if (!g_hide_now_loading) {
reinterpret_cast<decltype(NowLoading_Hide_hook) *>(NowLoading_Hide_orig)(thisObj,
onComplete);
}
if (onComplete) {
thread timeoutThread([onComplete]() {
sleep(1);
if (!onCompleteCalled_Hide) {
LOGI("NowLoading::Hide: onCompleteCalled not changed, calling onComplete manually...");
auto thread = il2cpp_thread_attach(il2cpp_domain_get());
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete_Hide_addr)(
onComplete->target);
il2cpp_thread_detach(thread);
} else {
DobbyDestroy(onComplete_Hide_addr);
}
});
timeoutThread.detach();
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete->method_ptr)(onComplete->target);
}
}

void *NowLoading_Hide2_orig = nullptr;

void NowLoading_Hide2_hook(Il2CppObject *thisObj, Il2CppDelegate *onComplete,
Il2CppObject *overrideDuration, int easeType) {
onCompleteCalled_Hide = false;
if (onComplete) {
onComplete_Hide_addr = reinterpret_cast<void *>(onComplete->method_ptr);
DobbyHook(onComplete_Hide_addr, reinterpret_cast<void *>(onComplete_Hide_hook),
reinterpret_cast<void **>(&onComplete_Hide_orig));
}
if (!g_hide_now_loading) {
reinterpret_cast<decltype(NowLoading_Hide2_hook) *>(NowLoading_Hide2_orig)(thisObj,
onComplete,
overrideDuration,
easeType);
}
if (onComplete) {
thread timeoutThread([onComplete]() {
sleep(1);
if (!onCompleteCalled_Hide) {
LOGI("NowLoading::Hide: onCompleteCalled not changed, calling onComplete manually...");
auto thread = il2cpp_thread_attach(il2cpp_domain_get());
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete_Hide_addr)(
onComplete->target);
il2cpp_thread_detach(thread);
} else {
DobbyDestroy(onComplete_Hide_addr);
}
});
timeoutThread.detach();
reinterpret_cast<void (*)(Il2CppObject *)>(onComplete->method_ptr)(onComplete->target);
}
}

Expand Down Expand Up @@ -3295,10 +3211,14 @@ void hookMethods() {

if (GetUnityVersion() == Unity2020) {
ADD_HOOK(NowLoading_Show2)
ADD_HOOK(NowLoading_Hide2)
if (g_hide_now_loading) {
ADD_HOOK(NowLoading_Hide2)
}
} else {
ADD_HOOK(NowLoading_Show)
ADD_HOOK(NowLoading_Hide)
if (g_hide_now_loading) {
ADD_HOOK(NowLoading_Hide)
}
}

ADD_HOOK(assetbundle_unload)
Expand Down

0 comments on commit 44eeed3

Please sign in to comment.