From 5b41a095f9902cf5bf912ce8d99bc61cb65f2295 Mon Sep 17 00:00:00 2001 From: TherCN Date: Fri, 27 Oct 2023 21:19:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=80=E5=87=BA=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 + app/build.gradle | 4 +- app/src/main/jni/Source/EGL.cpp | 23 ++- app/src/main/jni/Source/EGL.cpp.bak | 288 ---------------------------- 4 files changed, 20 insertions(+), 298 deletions(-) delete mode 100644 app/src/main/jni/Source/EGL.cpp.bak diff --git a/README.md b/README.md index 8a7b83f..9b5514f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Where's My Water Decompile Project (WMWD or WMWDP) You can download the built APK from the [Actions](https://github.com/TherCN/Where-is-My-Water/actions) tab, and you can also use [AIDE](https://android-ide.com) to clone this repository and manually compile it + +----- + If you have any features you would like to add, please explain them in the [Issues](https://github.com/TherCN/Where-is-My-Water/issues) section or submit the code in the [Pull Request](https://github.com/TherCN/Where-is-My-Water/pulls) section and explain the specific purpose of the code diff --git a/app/build.gradle b/app/build.gradle index dd64a15..15c4e53 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,6 +5,7 @@ android { buildToolsVersion '30.0.2' ndkVersion '23.0.7599858' namespace "thercn.wmw" + signingConfigs { release { storeFile file('thercn.jks') @@ -13,6 +14,7 @@ android { keyPassword 'thercn' } } + defaultConfig { applicationId "thercn.wmw" minSdkVersion 24 @@ -34,7 +36,7 @@ android { buildTypes { release { - signingConfig signingConfigs.release + signingConfig signingConfigs.release minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } diff --git a/app/src/main/jni/Source/EGL.cpp b/app/src/main/jni/Source/EGL.cpp index f5d8d5e..b4e30b3 100644 --- a/app/src/main/jni/Source/EGL.cpp +++ b/app/src/main/jni/Source/EGL.cpp @@ -197,27 +197,32 @@ void EGL::EglThread() { } ImGui::Begin("Where's My Water?Mod Tool"); - input->g_window = g_window = ImGui::GetCurrentWindow(); - ImGui::SetWindowSize({500, 500}, ImGuiCond_FirstUseEver); - ImGui::SetWindowPos({0, 200}, ImGuiCond_FirstUseEver); - ImGui::Text("libwmw.so Mod Tool"); + input->g_window = g_window = ImGui::GetCurrentWindow(); + ImGui::SetWindowSize({500, 500}, ImGuiCond_FirstUseEver); + ImGui::SetWindowPos({0, 200}, ImGuiCond_FirstUseEver); + ImGui::Text("libwmw.so Mod Tool"); - ImGui::InputTextWithHint("##偏移", "请输入偏移(input offset)", offset, IM_ARRAYSIZE(offset), + ImGui::InputTextWithHint("##偏移", "请输入偏移(input offset)", offset, IM_ARRAYSIZE(offset), ImGuiInputTextFlags_CallbackAlways, ImguiAndroidInput::inputCallback); - ImGui::InputTextWithHint("##字节", "请输入hex(input hex)", str, IM_ARRAYSIZE(str), + ImGui::InputTextWithHint("##字节", "请输入hex(input hex)", str, IM_ARRAYSIZE(str), ImGuiInputTextFlags_CallbackAlways, ImguiAndroidInput::inputCallback); + if (ImGui::Button("修改(modify)")){ if (patch(offset,str)) LOGE("成功为%d打上%s",offset,str); } + if (ImGui::Button("退出游戏(exit)")){ + exit(0); + } + ImGui::End(); - imguiMainWinEnd(); - this->swapBuffers(); - input->fps = this->FPS; + imguiMainWinEnd(); + this->swapBuffers(); + input->fps = this->FPS; } } diff --git a/app/src/main/jni/Source/EGL.cpp.bak b/app/src/main/jni/Source/EGL.cpp.bak deleted file mode 100644 index 8e8b7f7..0000000 --- a/app/src/main/jni/Source/EGL.cpp.bak +++ /dev/null @@ -1,288 +0,0 @@ -// -// Created by admin on 2022/6/10. -// - -#include "EGL.h" -#include "../Platinmods/PlatinmodsMemoryPatch.h" - -#define PATCH_LIB(lib, offset, hex) patchOffset(lib, string2Offset(offset), hex, true) -EGL::EGL() { - mEglDisplay = EGL_NO_DISPLAY; - mEglSurface = EGL_NO_SURFACE; - mEglConfig = nullptr; - mEglContext = EGL_NO_CONTEXT; -} - -static bool RunInitImgui;//检测imgui是否初始化过 - - -int EGL::initEgl() { - //1、 - mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (mEglDisplay == EGL_NO_DISPLAY) { - LOGE("eglGetDisplay error=%u", glGetError()); - return -1; - } - LOGE("生成mEglDisplay"); - //2、 - EGLint *version = new EGLint[2]; - if (!eglInitialize(mEglDisplay, &version[0], &version[1])) { - LOGE("eglInitialize error=%u", glGetError()); - return -1; - } - LOGE("eglInitialize成功"); - //3、 - const EGLint attribs[] = {EGL_BUFFER_SIZE, 32, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE}; - - EGLint num_config; - if (!eglGetConfigs(mEglDisplay, NULL, 1, &num_config)) { - LOGE("eglGetConfigs error =%u", glGetError()); - return -1; - } - LOGE("num_config=%d", num_config); - // 4、 - if (!eglChooseConfig(mEglDisplay, attribs, &mEglConfig, 1, &num_config)) { - LOGE("eglChooseConfig error=%u", glGetError()); - return -1; - } - LOGE("eglChooseConfig成功"); - //5、 - int attrib_list[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; - mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attrib_list); - if (mEglContext == EGL_NO_CONTEXT) { - LOGE("eglCreateContext error = %u", glGetError()); - return -1; - } - // 6、 - mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig, SurfaceWin, NULL); - if (mEglSurface == EGL_NO_SURFACE) { - LOGE("eglCreateWindowSurface error = %u", glGetError()); - return -1; - } - LOGE("eglCreateWindowSurface成功"); - //7、 - if (!eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) { - LOGE("eglMakeCurrent error = %u", glGetError()); - return -1; - } - LOGE("eglMakeCurrent成功"); - return 1; -} - - - -int EGL::initImgui() { - - if (RunInitImgui){ - //如果初始化过,就只执行这段 - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGui_ImplAndroid_Init(this->SurfaceWin); - ImGui_ImplOpenGL3_Init("#version 300 es"); - return 1; - } - RunInitImgui= true; - - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - - LOGE("CreateContext成功"); - io = &ImGui::GetIO(); - io->IniSavingRate = 10.0f; - string SaveFile = this->SaveDir; - SaveFile += "/save.ini"; - io->IniFilename = SaveFile.c_str(); - - - - - ImGui_ImplAndroid_Init(this->SurfaceWin); - LOGE(" ImGui_ImplAndroid_Init成功"); - ImGui_ImplOpenGL3_Init("#version 300 es"); - LOGE(" ImGui_ImplOpenGL3_Init成功"); - ImFontConfig font_cfg; - font_cfg.FontDataOwnedByAtlas = false; - imFont = io->Fonts->AddFontFromMemoryTTF((void *) OPPOSans_H, OPPOSans_H_size, 32.0f, &font_cfg, io->Fonts->GetGlyphRangesChineseFull()); - io->MouseDoubleClickTime = 0.0001f; - LOGE(" Font成功"); - //UI窗体风格 - g = ImGui::GetCurrentContext(); - - style =&ImGui::GetStyle(); - style->ScaleAllSizes(1.0f);//缩放尺寸 - style->FramePadding=ImVec2(10.0f,20.0f); - - //自动读取主题 - string LoadFile = this->SaveDir; - LoadFile += "/Style.dat"; - ImGuiStyle s; - if (MyFile::ReadFile(&s,LoadFile.c_str())==1){ - *style=s; - LOGE("读取主题成功"); - } - - - return 1; -} - - -void EGL::onSurfaceCreate(JNIEnv *env, jobject surface, int SurfaceWidth, int SurfaceHigh) { - LOGE("onSurfaceCreate"); - this->SurfaceWin = ANativeWindow_fromSurface(env, surface); - this->surfaceWidth = SurfaceWidth; - this->surfaceHigh = SurfaceHigh; - this->surfaceWidthHalf = this->surfaceWidth / 2; - this->surfaceHighHalf = this->surfaceHigh / 2; - SurfaceThread = new std::thread([this] { EglThread(); }); - SurfaceThread->detach(); - LOGE("onSurfaceCreate_end"); -} - -void EGL::onSurfaceChange(int SurfaceWidth, int SurfaceHigh) { - this->surfaceWidth = SurfaceWidth; - this->surfaceHigh = SurfaceHigh; - this->surfaceWidthHalf = this->surfaceWidth / 2; - this->surfaceHighHalf = this->surfaceHigh / 2; - this->isChage = true; - LOGE("onSurfaceChange"); -} - -void EGL::onSurfaceDestroy() { - - LOGE("onSurfaceDestroy"); - this->isDestroy = true; - - std::unique_lock ulo(Threadlk); - cond.wait(ulo, [this] { return !this->ThreadIo; }); - delete SurfaceThread; - SurfaceThread = nullptr; - -} - - -char offset[18]; -char str[24]; - -void EGL::EglThread() { - - this->initEgl(); - this->initImgui(); - ThreadIo = true; - input->initImguiIo(io); - input->setImguiContext(g); - input->setwin(this->g_window); - - while (true) { - - - - if (this->isChage) { - glViewport(0, 0, this->surfaceWidth, this->surfaceHigh); - this->isChage = false; - } - if (this->isDestroy) { - this->isDestroy = false; - ThreadIo = false; - cond.notify_all(); - return; - } - - - this->clearBuffers(); - - //如果Activity不处于活动状态就停止绘制 - if (!ActivityState)continue;//感觉没屌用 - imguiMainWinStart(); - - //菜单 - ImGui::SetNextWindowBgAlpha(0.7); - style->WindowTitleAlign = ImVec2(0.5, 0.5);//标题居中 - if (input->Scrollio && !input->Activeio) { - input->funScroll(g->WheelingWindow ? g->WheelingWindow : g->HoveredWindow); - } - - ImGui::Begin("Where's My Water?Mod Tool"); - input->g_window = g_window = ImGui::GetCurrentWindow(); - ImGui::SetWindowSize({500, 500}, ImGuiCond_FirstUseEver); - ImGui::SetWindowPos({0, 200}, ImGuiCond_FirstUseEver); - ImGui::Text("libwmw.so Mod Tool"); - - ImGui::InputTextWithHint("##偏移", "请输入偏移(input offset)", offset, IM_ARRAYSIZE(offset), - ImGuiInputTextFlags_CallbackAlways, - ImguiAndroidInput::inputCallback); - - ImGui::InputTextWithHint("##字节", "请输入hex(input hex)", str, IM_ARRAYSIZE(str), - ImGuiInputTextFlags_CallbackAlways, - ImguiAndroidInput::inputCallback); - if (ImGui::Button("修改(modify)")){ - if (patch(offset,str)) LOGE("成功为%d打上%s",offset,str); - } - - ImGui::End(); - - imguiMainWinEnd(); - this->swapBuffers(); - input->fps = this->FPS; - } -} - -bool EGL::patch(char offset[],char hex[]) { -pid_t pid = Platinmods::getPid("thercn.wmw"); - - std::string offset_str(offset); - std::string hex_str(hex); - - Platinmods::MemoryPatch patch1 = Platinmods::MemoryPatch(pid, "libwmw.so", offset_str, hex_str); - - // Write Modified Hex - bool result = patch1.Modify(); - if (result) { - LOGE("Offset patches successfully!\n"); - } else { - LOGE("Patch failed\n"); - } - return result; -} - - - -int EGL::swapBuffers() { - //opengl当前buff传递至屏幕 - if (eglSwapBuffers(mEglDisplay, mEglSurface)) { - return 1; - } - LOGE("eglSwapBuffers error = %u", glGetError()); - return 0; -} -void EGL::clearBuffers() { - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -} - - -void EGL::imguiMainWinStart() { - // Start the Dear ImGui frame - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplAndroid_NewFrame(); - ImGui::NewFrame(); - -} - -void EGL::imguiMainWinEnd() { - // Render the Dear ImGui frame - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); -} - -void EGL::setSaveSettingsdir(string &dir) { - this->SaveDir = dir; - LOGE("保存路径=%s", SaveDir.c_str()); -} - -void EGL::setinput(ImguiAndroidInput *input_) { - this->input = input_; -} - - -