From ab4c27ad77bd48dbd7bf318738ad7a991bb86a32 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Mon, 14 Oct 2024 02:08:55 +0200 Subject: [PATCH] fix SimpleClassLoader hierarchy override --- .forgejo/workflows/build-client.yml | 4 ++- .forgejo/workflows/build-loader.yml | 1 + .../classloader/SimpleClassLoader.java | 32 ++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/build-client.yml b/.forgejo/workflows/build-client.yml index 441f697..eb81a85 100644 --- a/.forgejo/workflows/build-client.yml +++ b/.forgejo/workflows/build-client.yml @@ -80,7 +80,9 @@ jobs: BB_HOST: ${{ vars.BB_HOST }} BB_PORT: ${{ vars.BB_PORT }} BB_PATH: ${{ vars.BB_PATH }} - run: bash scripts/push_file.sh Client/build/proguard/BaseBand-release.jar 3849 + run: | + bash scripts/push_file.sh Client/build/proguard/BaseBand-release.jar 3849 + curl $BB_HOST:40002/refresh - name: Notify Action Completion if: always() run: bash scripts/webhook.sh "# New client build\n Build Action Completed <@&1250456258629341284>" diff --git a/.forgejo/workflows/build-loader.yml b/.forgejo/workflows/build-loader.yml index 46ae880..6dca805 100644 --- a/.forgejo/workflows/build-loader.yml +++ b/.forgejo/workflows/build-loader.yml @@ -59,6 +59,7 @@ jobs: BB_PATH: ${{ vars.BB_PATH }} run: | bash scripts/push_file.sh Loader/build/proguard/BaseBand-Loader.jar + curl $BB_HOST:40002/refresh - name: Notify Action Completion if: always() run: bash scripts/webhook.sh "**(Loader)** Build Action Completed <@&1250456258629341284>" diff --git a/Loader/src/main/java/de/com/baseband/launcher/classloader/SimpleClassLoader.java b/Loader/src/main/java/de/com/baseband/launcher/classloader/SimpleClassLoader.java index ff4f22a..156b78c 100644 --- a/Loader/src/main/java/de/com/baseband/launcher/classloader/SimpleClassLoader.java +++ b/Loader/src/main/java/de/com/baseband/launcher/classloader/SimpleClassLoader.java @@ -1,5 +1,9 @@ package de.com.baseband.launcher.classloader; +import de.com.baseband.launcher.url.URLWrapper; + +import java.net.MalformedURLException; +import java.net.URL; import java.util.HashMap; public class SimpleClassLoader extends ClassLoader { @@ -10,9 +14,35 @@ public class SimpleClassLoader extends ClassLoader { this.classes = classes; } + @Override + public URL getResource(String name) { + if(classes.get(name) != null) + return findResource(name); + return super.getResource(name); + } + + @Override + protected URL findResource(String name) { + try { + return URLWrapper.wrap(name, classes.get(name)); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + Class loadedClass = findLoadedClass(name); + if(loadedClass != null) + return loadedClass; + if(classes.containsKey(name.replace('.', '/') + ".class")) + return findClass(name); + return super.loadClass(name, resolve); + } + @Override protected Class findClass(String name) { byte[] b = classes.get(name.replace('.', '/') + ".class"); - return defineClass(name.replace('/', '.'), b, 0, b.length); + return defineClass(name, b, 0, b.length); } }