|
| 1 | +/* |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2026 Fox2Code |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | +package com.build_9.hyxin; |
| 25 | + |
| 26 | +import com.fox2code.hypertale.loader.HypertaleModGatherer; |
| 27 | +import org.objectweb.asm.ClassReader; |
| 28 | + |
| 29 | +import java.io.FileNotFoundException; |
| 30 | +import java.io.IOException; |
| 31 | +import java.io.InputStream; |
| 32 | + |
| 33 | +/** |
| 34 | + * Stub of Hyxin's {@code LaunchEnvironment} class, used to help improve compatibility with Hyxin mods! |
| 35 | + */ |
| 36 | +public final class LaunchEnvironment { |
| 37 | + private static final LaunchEnvironment INSTANCE = new LaunchEnvironment(); |
| 38 | + |
| 39 | + private LaunchEnvironment() {} |
| 40 | + |
| 41 | + public static LaunchEnvironment get() { |
| 42 | + return INSTANCE; |
| 43 | + } |
| 44 | + |
| 45 | + public static void create(ClassLoader systemLoader, ClassLoader earlyPluginLoader) { |
| 46 | + throw new IllegalStateException("Cannot call create() on Hypertale!"); |
| 47 | + } |
| 48 | + |
| 49 | + public void captureRuntimeLoader(ClassLoader loader) { |
| 50 | + throw new IllegalStateException("Cannot call captureRuntimeLoader() on Hypertale!"); |
| 51 | + } |
| 52 | + |
| 53 | + public ClassLoader getSystemLoader() { |
| 54 | + return HypertaleModGatherer.class.getClassLoader(); |
| 55 | + } |
| 56 | + |
| 57 | + public ClassLoader getEarlyPluginLoader() { |
| 58 | + return HypertaleModGatherer.class.getClassLoader(); |
| 59 | + } |
| 60 | + |
| 61 | + public ClassLoader getRuntimeLoader() { |
| 62 | + return HypertaleModGatherer.class.getClassLoader(); |
| 63 | + } |
| 64 | + |
| 65 | + public ClassLoader findLoaderForClass(String resourceName) throws ClassNotFoundException { |
| 66 | + try { |
| 67 | + return this.findLoaderFor(resourceName.replace(".", "/").concat(".class")); |
| 68 | + } catch (IOException var3) { |
| 69 | + throw new ClassNotFoundException("Could not find class '" + resourceName + "'.", var3); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + public ClassLoader findLoaderFor(String resourceName) throws IOException { |
| 74 | + ClassLoader mainClassLoader = HypertaleModGatherer.class.getClassLoader(); |
| 75 | + if (mainClassLoader != null && mainClassLoader.getResource(resourceName) != null) { |
| 76 | + return mainClassLoader; |
| 77 | + } else { |
| 78 | + throw new FileNotFoundException("Could not find resource '" + resourceName + "' on any class loader."); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + public InputStream findResourceStream(String resourceName) throws IOException { |
| 83 | + return this.findLoaderFor(resourceName).getResourceAsStream(resourceName); |
| 84 | + } |
| 85 | + |
| 86 | + public ClassReader getClassReader(String name) throws IOException, ClassNotFoundException { |
| 87 | + String fileName = name.replace(".", "/").concat(".class"); |
| 88 | + try (InputStream inputStream = this.findResourceStream(fileName)) { |
| 89 | + return new ClassReader(inputStream); |
| 90 | + } catch (RuntimeException var3) { |
| 91 | + throw new ClassNotFoundException("Could not find class '" + fileName + "'."); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments