rename nonsense -> frog

This commit is contained in:
moehreag 2024-06-03 13:33:05 +02:00
parent 7f04454847
commit 1c3a8bd070
12 changed files with 56 additions and 56 deletions

View file

@ -6,13 +6,13 @@ import java.util.Optional;
import dev.frogmc.frogloader.api.env.Env; import dev.frogmc.frogloader.api.env.Env;
import dev.frogmc.frogloader.api.mod.ModProperties; import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.impl.LoaderImpl; import dev.frogmc.frogloader.impl.FrogLoaderImpl;
import dev.frogmc.frogloader.impl.plugin.NonsensePlugin; import dev.frogmc.frogloader.impl.plugin.NonsensePlugin;
public interface Loader { public interface FrogLoader {
static Loader getInstance(){ static FrogLoader getInstance(){
return LoaderImpl.getInstance(); return FrogLoaderImpl.getInstance();
} }
List<NonsensePlugin> getPlugins(); List<NonsensePlugin> getPlugins();

View file

@ -11,7 +11,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.google.gson.Gson; import com.google.gson.Gson;
import dev.frogmc.frogloader.api.Loader; import dev.frogmc.frogloader.api.FrogLoader;
import dev.frogmc.frogloader.api.env.Env; import dev.frogmc.frogloader.api.env.Env;
import dev.frogmc.frogloader.api.mod.ModProperties; import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.impl.launch.MixinClassLoader; import dev.frogmc.frogloader.impl.launch.MixinClassLoader;
@ -22,7 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment;
public class LoaderImpl implements Loader { public class FrogLoaderImpl implements FrogLoader {
// TODO decide this // TODO decide this
public static final String MOD_FILE_EXTENSION = ".frogmod"; public static final String MOD_FILE_EXTENSION = ".frogmod";
private final boolean DEV_ENV = Boolean.getBoolean("frogmc.development"); private final boolean DEV_ENV = Boolean.getBoolean("frogmc.development");
@ -33,7 +33,7 @@ public class LoaderImpl implements Loader {
private final Env env; private final Env env;
@Getter @Getter
private static LoaderImpl instance; private static FrogLoaderImpl instance;
private final Logger LOGGER = LoggerFactory.getLogger("Frogloader"); private final Logger LOGGER = LoggerFactory.getLogger("Frogloader");
@ -53,7 +53,7 @@ public class LoaderImpl implements Loader {
private final Collection<String> modIds; private final Collection<String> modIds;
private LoaderImpl(String[] args, Env env) { private FrogLoaderImpl(String[] args, Env env) {
instance = this; instance = this;
this.classloader = (MixinClassLoader) this.getClass().getClassLoader(); this.classloader = (MixinClassLoader) this.getClass().getClassLoader();
this.args = args; this.args = args;
@ -96,7 +96,7 @@ public class LoaderImpl implements Loader {
throw new IllegalStateException("Loader was started multiple times!"); throw new IllegalStateException("Loader was started multiple times!");
} }
new LoaderImpl(args, env); new FrogLoaderImpl(args, env);
} }
private void discoverPlugins() { private void discoverPlugins() {

View file

@ -7,18 +7,18 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import dev.frogmc.frogloader.api.env.Env; import dev.frogmc.frogloader.api.env.Env;
import dev.frogmc.frogloader.impl.mixin.NonsenseMixinService; import dev.frogmc.frogloader.impl.mixin.FrogMixinService;
import lombok.Getter; import lombok.Getter;
import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.service.IPropertyKey; import org.spongepowered.asm.service.IPropertyKey;
public class Launcher { public class FrogLauncher {
@Getter @Getter
private final MixinClassLoader targetClassLoader; private final MixinClassLoader targetClassLoader;
@Getter @Getter
private static Launcher instance; private static FrogLauncher instance;
@Getter @Getter
private final Map<IPropertyKey, Object> globalProperties = new HashMap<>(); private final Map<IPropertyKey, Object> globalProperties = new HashMap<>();
@ -27,10 +27,10 @@ public class Launcher {
private final Env env; private final Env env;
public static void run(String[] args, Env env) { public static void run(String[] args, Env env) {
new Launcher(args, env); new FrogLauncher(args, env);
} }
public Launcher(String[] args, Env env){ public FrogLauncher(String[] args, Env env){
if (instance != null){ if (instance != null){
throw new IllegalStateException(); throw new IllegalStateException();
} }
@ -45,11 +45,11 @@ public class Launcher {
Thread.currentThread().setContextClassLoader(targetClassLoader); Thread.currentThread().setContextClassLoader(targetClassLoader);
System.setProperty("mixin.service", NonsenseMixinService.class.getName()); System.setProperty("mixin.service", FrogMixinService.class.getName());
MixinBootstrap.init(); MixinBootstrap.init();
try { try {
Class<?> clazz = targetClassLoader.findClass("dev.frogmc.frogloader.impl.LoaderImpl"); Class<?> clazz = targetClassLoader.findClass("dev.frogmc.frogloader.impl.FrogLoaderImpl");
MethodHandle ctor = MethodHandles.publicLookup().findStatic(clazz, "run", MethodType.methodType(void.class, String[].class, Env.class)); MethodHandle ctor = MethodHandles.publicLookup().findStatic(clazz, "run", MethodType.methodType(void.class, String[].class, Env.class));
ctor.invoke(args, env); ctor.invoke(args, env);
} catch (Throwable e) { } catch (Throwable e) {

View file

@ -1,6 +1,6 @@
package dev.frogmc.frogloader.impl.launch; package dev.frogmc.frogloader.impl.launch;
import dev.frogmc.frogloader.impl.mixin.NonsenseMixinService; import dev.frogmc.frogloader.impl.mixin.FrogMixinService;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment;
@ -42,7 +42,7 @@ public class MixinClassLoader extends URLClassLoader {
if (in == null) if (in == null)
return null; return null;
return NonsenseMixinService.getTransformer().transformClass(MixinEnvironment.getCurrentEnvironment(), name, AccessWidener.processClass(in.readAllBytes(), binName)); return FrogMixinService.getTransformer().transformClass(MixinEnvironment.getCurrentEnvironment(), name, AccessWidener.processClass(in.readAllBytes(), binName));
} }
} }

View file

@ -1,11 +1,11 @@
package dev.frogmc.frogloader.impl.launch.client; package dev.frogmc.frogloader.impl.launch.client;
import dev.frogmc.frogloader.api.env.Env; import dev.frogmc.frogloader.api.env.Env;
import dev.frogmc.frogloader.impl.launch.Launcher; import dev.frogmc.frogloader.impl.launch.FrogLauncher;
public class NonsenseClient { public class FrogClient {
public static void main(String[] args){ public static void main(String[] args){
Launcher.run(args, Env.CLIENT); FrogLauncher.run(args, Env.CLIENT);
} }
} }

View file

@ -1,11 +1,11 @@
package dev.frogmc.frogloader.impl.launch.server; package dev.frogmc.frogloader.impl.launch.server;
import dev.frogmc.frogloader.impl.launch.Launcher; import dev.frogmc.frogloader.impl.launch.FrogLauncher;
import dev.frogmc.frogloader.api.env.Env; import dev.frogmc.frogloader.api.env.Env;
public class NonsenseServer { public class FrogServer {
public static void main(String[] args){ public static void main(String[] args){
Launcher.run(args, Env.SERVER); FrogLauncher.run(args, Env.SERVER);
} }
} }

View file

@ -1,10 +1,10 @@
package dev.frogmc.frogloader.impl.mixin; package dev.frogmc.frogloader.impl.mixin;
import dev.frogmc.frogloader.impl.launch.Launcher; import dev.frogmc.frogloader.impl.launch.FrogLauncher;
import org.spongepowered.asm.service.IGlobalPropertyService; import org.spongepowered.asm.service.IGlobalPropertyService;
import org.spongepowered.asm.service.IPropertyKey; import org.spongepowered.asm.service.IPropertyKey;
public class NonsenseGlobalPropertyService implements IGlobalPropertyService { public class FrogGlobalPropertyService implements IGlobalPropertyService {
@Override @Override
public IPropertyKey resolveKey(String name) { public IPropertyKey resolveKey(String name) {
return new IPropertyKey() { return new IPropertyKey() {
@ -18,22 +18,22 @@ public class NonsenseGlobalPropertyService implements IGlobalPropertyService {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <T> T getProperty(IPropertyKey key) { public <T> T getProperty(IPropertyKey key) {
return (T) Launcher.getInstance().getGlobalProperties().get(key); return (T) FrogLauncher.getInstance().getGlobalProperties().get(key);
} }
@Override @Override
public void setProperty(IPropertyKey key, Object value) { public void setProperty(IPropertyKey key, Object value) {
Launcher.getInstance().getGlobalProperties().put(key, value); FrogLauncher.getInstance().getGlobalProperties().put(key, value);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <T> T getProperty(IPropertyKey key, T defaultValue) { public <T> T getProperty(IPropertyKey key, T defaultValue) {
return (T) Launcher.getInstance().getGlobalProperties().getOrDefault(key, defaultValue); return (T) FrogLauncher.getInstance().getGlobalProperties().getOrDefault(key, defaultValue);
} }
@Override @Override
public String getPropertyString(IPropertyKey key, String defaultValue) { public String getPropertyString(IPropertyKey key, String defaultValue) {
return Launcher.getInstance().getGlobalProperties().getOrDefault(key, defaultValue).toString(); return FrogLauncher.getInstance().getGlobalProperties().getOrDefault(key, defaultValue).toString();
} }
} }

View file

@ -10,16 +10,16 @@ import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.logging.Level; import org.spongepowered.asm.logging.Level;
import org.spongepowered.asm.logging.LoggerAdapterAbstract; import org.spongepowered.asm.logging.LoggerAdapterAbstract;
public class NonsenseMixinLogger extends LoggerAdapterAbstract { public class FrogMixinLogger extends LoggerAdapterAbstract {
private static final Map<String, NonsenseMixinLogger> LOGGERS = new ConcurrentHashMap<>(); private static final Map<String, FrogMixinLogger> LOGGERS = new ConcurrentHashMap<>();
public static ILogger get(String name){ public static ILogger get(String name){
return LOGGERS.computeIfAbsent(name, NonsenseMixinLogger::new); return LOGGERS.computeIfAbsent(name, FrogMixinLogger::new);
} }
private final Logger log; private final Logger log;
public NonsenseMixinLogger(String name){ public FrogMixinLogger(String name){
super(name); super(name);
log = LoggerFactory.getLogger("Nonsense Loader/"+name.substring(0, 1).toUpperCase(Locale.ROOT)+name.substring(1)); log = LoggerFactory.getLogger("Nonsense Loader/"+name.substring(0, 1).toUpperCase(Locale.ROOT)+name.substring(1));
} }

View file

@ -7,8 +7,8 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import dev.frogmc.frogloader.impl.launch.FrogLauncher;
import lombok.Getter; import lombok.Getter;
import dev.frogmc.frogloader.impl.launch.Launcher;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.launch.platform.container.ContainerHandleVirtual; import org.spongepowered.asm.launch.platform.container.ContainerHandleVirtual;
@ -21,7 +21,7 @@ import org.spongepowered.asm.service.*;
import org.spongepowered.asm.transformers.MixinClassReader; import org.spongepowered.asm.transformers.MixinClassReader;
import org.spongepowered.asm.util.ReEntranceLock; import org.spongepowered.asm.util.ReEntranceLock;
public class NonsenseMixinService implements IMixinService, IClassProvider, IClassBytecodeProvider, ITransformerProvider, IClassTracker { public class FrogMixinService implements IMixinService, IClassProvider, IClassBytecodeProvider, ITransformerProvider, IClassTracker {
@Getter @Getter
static IMixinTransformer transformer; static IMixinTransformer transformer;
private final ReEntranceLock lock = new ReEntranceLock(1); private final ReEntranceLock lock = new ReEntranceLock(1);
@ -116,12 +116,12 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
@Override @Override
public InputStream getResourceAsStream(String name) { public InputStream getResourceAsStream(String name) {
return Launcher.getInstance().getTargetClassLoader().getResourceAsStream(name); return FrogLauncher.getInstance().getTargetClassLoader().getResourceAsStream(name);
} }
@Override @Override
public String getSideName() { public String getSideName() {
return Launcher.getInstance().getEnv().getMixinName(); return FrogLauncher.getInstance().getEnv().getMixinName();
} }
@Override @Override
@ -136,7 +136,7 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
@Override @Override
public ILogger getLogger(String name) { public ILogger getLogger(String name) {
return NonsenseMixinLogger.get(name); return FrogMixinLogger.get(name);
} }
@ -150,9 +150,9 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
byte[] bytes; byte[] bytes;
if (runTransformers && transformer != null) { if (runTransformers && transformer != null) {
bytes = transformer.transformClass(MixinEnvironment.getCurrentEnvironment(), name, bytes = transformer.transformClass(MixinEnvironment.getCurrentEnvironment(), name,
Launcher.getInstance().getTargetClassLoader().getClassBytes(name)); FrogLauncher.getInstance().getTargetClassLoader().getClassBytes(name));
} else { } else {
bytes = Launcher.getInstance().getTargetClassLoader().getClassBytes(name); bytes = FrogLauncher.getInstance().getTargetClassLoader().getClassBytes(name);
} }
ClassReader reader = new MixinClassReader(bytes, name); ClassReader reader = new MixinClassReader(bytes, name);
ClassNode node = new ClassNode(); ClassNode node = new ClassNode();
@ -168,17 +168,17 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
@Override @Override
public Class<?> findClass(String name) throws ClassNotFoundException { public Class<?> findClass(String name) throws ClassNotFoundException {
return Class.forName(name, false, Launcher.getInstance().getTargetClassLoader()); return Class.forName(name, false, FrogLauncher.getInstance().getTargetClassLoader());
} }
@Override @Override
public Class<?> findClass(String name, boolean initialize) throws ClassNotFoundException { public Class<?> findClass(String name, boolean initialize) throws ClassNotFoundException {
return Class.forName(name, initialize, Launcher.getInstance().getTargetClassLoader()); return Class.forName(name, initialize, FrogLauncher.getInstance().getTargetClassLoader());
} }
@Override @Override
public Class<?> findAgentClass(String name, boolean initialize) throws ClassNotFoundException { public Class<?> findAgentClass(String name, boolean initialize) throws ClassNotFoundException {
return Class.forName(name, initialize, Launcher.getInstance().getTargetClassLoader()); return Class.forName(name, initialize, FrogLauncher.getInstance().getTargetClassLoader());
} }
@Override @Override
@ -188,7 +188,7 @@ public class NonsenseMixinService implements IMixinService, IClassProvider, ICla
@Override @Override
public boolean isClassLoaded(String className) { public boolean isClassLoaded(String className) {
return Launcher.getInstance().getTargetClassLoader().isClassLoaded(className); return FrogLauncher.getInstance().getTargetClassLoader().isClassLoaded(className);
} }
@Override @Override

View file

@ -3,7 +3,7 @@ package dev.frogmc.frogloader.impl.plugin;
import java.util.Collection; import java.util.Collection;
import dev.frogmc.frogloader.api.mod.ModProperties; import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.impl.LoaderImpl; import dev.frogmc.frogloader.impl.FrogLoaderImpl;
public interface NonsensePlugin extends Runnable { public interface NonsensePlugin extends Runnable {
@ -18,7 +18,7 @@ public interface NonsensePlugin extends Runnable {
return false; return false;
} }
default void init(LoaderImpl loader) throws Exception { default void init(FrogLoaderImpl loader) throws Exception {
} }
Collection<ModProperties> getMods(); Collection<ModProperties> getMods();

View file

@ -16,7 +16,7 @@ import dev.frogmc.frogloader.api.mod.ModDependencies;
import dev.frogmc.frogloader.api.mod.ModExtensions; import dev.frogmc.frogloader.api.mod.ModExtensions;
import dev.frogmc.frogloader.api.mod.ModProperties; import dev.frogmc.frogloader.api.mod.ModProperties;
import dev.frogmc.frogloader.impl.Discovery; import dev.frogmc.frogloader.impl.Discovery;
import dev.frogmc.frogloader.impl.LoaderImpl; import dev.frogmc.frogloader.impl.FrogLoaderImpl;
import dev.frogmc.frogloader.impl.mixin.AWProcessor; import dev.frogmc.frogloader.impl.mixin.AWProcessor;
import dev.frogmc.frogloader.impl.mod.BuiltinExtensions; import dev.frogmc.frogloader.impl.mod.BuiltinExtensions;
import dev.frogmc.frogloader.impl.mod.ModPropertiesImpl; import dev.frogmc.frogloader.impl.mod.ModPropertiesImpl;
@ -48,7 +48,7 @@ public class Minecraft implements NonsensePlugin {
} }
@Override @Override
public void init(LoaderImpl loader) throws Exception { public void init(FrogLoaderImpl loader) throws Exception {
if (gamePath == null){ if (gamePath == null){
throw new IllegalStateException("Game not found yet!"); throw new IllegalStateException("Game not found yet!");
} }
@ -70,7 +70,7 @@ public class Minecraft implements NonsensePlugin {
Collection<Path> mods = Discovery.find(loader.getModsDir(), path -> Collection<Path> mods = Discovery.find(loader.getModsDir(), path ->
version.equals(path.getFileName().toString()), path -> version.equals(path.getFileName().toString()), path ->
path.getFileName().toString().endsWith(LoaderImpl.MOD_FILE_EXTENSION)); path.getFileName().toString().endsWith(FrogLoaderImpl.MOD_FILE_EXTENSION));
Collection<URL> classpathMods = this.getClass().getClassLoader().resources(ModPropertiesReader.PROPERTIES_FILE_NAME).distinct().toList(); Collection<URL> classpathMods = this.getClass().getClassLoader().resources(ModPropertiesReader.PROPERTIES_FILE_NAME).distinct().toList();
classpathMods.parallelStream().map(ModPropertiesReader::readFile).forEachOrdered(modProperties::add); classpathMods.parallelStream().map(ModPropertiesReader::readFile).forEachOrdered(modProperties::add);
@ -84,7 +84,7 @@ public class Minecraft implements NonsensePlugin {
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}).forEachOrdered(LoaderImpl.getInstance().getClassloader()::addURL); }).forEachOrdered(FrogLoaderImpl.getInstance().getClassloader()::addURL);
// TODO respect mod dependencies and display errors appropriately // TODO respect mod dependencies and display errors appropriately
@ -104,7 +104,7 @@ public class Minecraft implements NonsensePlugin {
AWProcessor.load(modProperties); AWProcessor.load(modProperties);
var runtimePath = loader.isDevelopment() ? gamePath : remappedGamePath; var runtimePath = loader.isDevelopment() ? gamePath : remappedGamePath;
LoaderImpl.getInstance().getClassloader().addURL(runtimePath.toUri().toURL()); FrogLoaderImpl.getInstance().getClassloader().addURL(runtimePath.toUri().toURL());
} }
protected void findJiJMods(Path mod, Collection<Path> mods) throws IOException { protected void findJiJMods(Path mod, Collection<Path> mods) throws IOException {
@ -159,10 +159,10 @@ public class Minecraft implements NonsensePlugin {
} }
try (FileSystem fs = FileSystems.newFileSystem(jar)) { try (FileSystem fs = FileSystems.newFileSystem(jar)) {
for (String n : MINECRAFT_CLASSES) { for (String n : MINECRAFT_CLASSES) {
if (Files.exists(fs.getPath(n)) && n.contains(LoaderImpl.getInstance().getEnv().getIdentifier())) { if (Files.exists(fs.getPath(n)) && n.contains(FrogLoaderImpl.getInstance().getEnv().getIdentifier())) {
LOGGER.info("Found game: {}", jar); LOGGER.info("Found game: {}", jar);
foundMainClass = n.substring(0, n.length() - 6).replace("/", "."); foundMainClass = n.substring(0, n.length() - 6).replace("/", ".");
version = LoaderImpl.getInstance().getGson().fromJson(Files.readString(fs.getPath("version.json")), JsonObject.class).get("id").getAsString(); version = FrogLoaderImpl.getInstance().getGson().fromJson(Files.readString(fs.getPath("version.json")), JsonObject.class).get("id").getAsString();
return true; return true;
} }
} }
@ -182,7 +182,7 @@ public class Minecraft implements NonsensePlugin {
LOGGER.info("Launching main class: {}", foundMainClass); LOGGER.info("Launching main class: {}", foundMainClass);
Class<?> mainClass = Class.forName(foundMainClass); Class<?> mainClass = Class.forName(foundMainClass);
MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); MethodHandle main = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class));
main.invoke((Object) LoaderImpl.getInstance().getArgs()); main.invoke((Object) FrogLoaderImpl.getInstance().getArgs());
} else { } else {
LOGGER.warn("Failed to locate main class!"); LOGGER.warn("Failed to locate main class!");
} }

View file

@ -1 +1 @@
dev.frogmc.frogloader.impl.mixin.NonsenseGlobalPropertyService dev.frogmc.frogloader.impl.mixin.FrogGlobalPropertyService