Skip to content

Commit

Permalink
update to twoconfig, crash gui slightly ported
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Jul 26, 2024
1 parent 4000295 commit 0b2f13e
Show file tree
Hide file tree
Showing 16 changed files with 771 additions and 611 deletions.
12 changes: 10 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ loom {
runConfigs {
"client" {
programArgs("--tweakClass", "org.polyfrost.crashpatch.hooks.ModsCheckerPlugin")
programArgs("--tweakClass", "org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker")
programArgs("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker")
//property("fml.coreMods.load", "")
property("mixin.debug.export", "true")
}
Expand Down Expand Up @@ -83,19 +85,25 @@ sourceSets {
// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
repositories {
maven("https://repo.polyfrost.org/releases")
maven("https://repo.polyfrost.org/snapshots")
}

// Configures the libraries/dependencies for your mod.
dependencies {
// Adds the OneConfig library, so we can develop with it.
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+")
val oneconfig = "1.0.0-alpha.19"
implementation("org.polyfrost.oneconfig:config-impl:$oneconfig")
implementation("org.polyfrost.oneconfig:commands:$oneconfig")
implementation("org.polyfrost.oneconfig:events:$oneconfig")
implementation("org.polyfrost.oneconfig:ui:$oneconfig")
implementation("org.polyfrost.oneconfig:internal:$oneconfig")
modImplementation("org.polyfrost.oneconfig:$platform:$oneconfig")

modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.2.0")
shade("gs.mclo:api:3.0.1")
// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
if (platform.isLegacyForge) {
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
93 changes: 93 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os
import pathlib

def add_import(imports):
with open(dir, "w") as new_file:
if original_text != content:
package_index = original_text.find('package')
line_end_index = original_text.find('\n', package_index)

modified_text = content[:line_end_index] + '\nimport ' + imports

if name.endswith(".java"):
modified_text += ";"
modified_text += "\n" + content[line_end_index:]
new_file.write(modified_text)
else:
new_file.write(content)


input("MAKE SURE YOU HAVE MADE A BACKUP OF YOUR PROJECT BEFORE RUNNING THIS SCRIPT (press enter to continue)\n")

try:
os.chdir('src')
except FileNotFoundError:
input('Please put this script next to the src/ directory! (press enter to exit)')
exit()

for path, _, files in os.walk("."):
for name in files:
dir = str(pathlib.PurePath(path, name))
if not (name.endswith(".java") or name.endswith(".kt")):
continue

with open(dir,"r+") as f:
new_f = f.readlines()
f.seek(0)
for line in new_f:
if "import cc.polyfrost.oneconfig.config.core.OneColor" in line:
f.write(line.replace("cc.polyfrost.oneconfig.config.core.OneColor", "org.polyfrost.polyui.color.PolyColor"))
elif "import cc.polyfrost.oneconfig.config.core.OneKeyBind" in line:
f.write(line.replace("cc.polyfrost.oneconfig.config.core.OneKeyBind", "org.polyfrost.polyui.input.Keybinder.Bind"))
if "import cc.polyfrost.oneconfig.config" in line:
f.write(line.replace("cc.polyfrost.oneconfig.config", "org.polyfrost.oneconfig.api.config.v1"))
elif "import cc.polyfrost.oneconfig.utils.commands.annotations" in line:
f.write(line.replace("cc.polyfrost.oneconfig.utils.commands.annotations", "org.polyfrost.oneconfig.api.commands.v1.factories.annotated"))
elif "import cc.polyfrost.oneconfig.utils.commands" in line:
f.write(line.replace("cc.polyfrost.oneconfig.utils.commands", "org.polyfrost.oneconfig.api.commands.v1"))
elif "import cc.polyfrost.oneconfig.utils.hypixel" in line:
f.write(line.replace("cc.polyfrost.oneconfig.utils.hypixel", "org.polyfrost.oneconfig.api.hypixel.v1"))
elif "import cc.polyfrost.oneconfig.utils.Notifications" in line:
f.write(line.replace("cc.polyfrost.oneconfig.utils.Notifications", "org.polyfrost.oneconfig.api.ui.v1.notifications.Notifications"))
elif "import cc.polyfrost.oneconfig.utils" in line:
f.write(line.replace("cc.polyfrost.oneconfig.utils", "org.polyfrost.oneconfig.utils.v1"))
elif "import cc.polyfrost.oneconfig.platform" in line:
f.write(line.replace("cc.polyfrost.oneconfig.platform", "org.polyfrost.oneconfig.api.platform.v1"))
elif "import cc.polyfrost.oneconfig.events.event" in line:
f.write(line.replace("cc.polyfrost.oneconfig.events", "org.polyfrost.oneconfig.api.event.v1.events"))
elif "import cc.polyfrost.oneconfig.events" in line:
f.write(line.replace("cc.polyfrost.oneconfig.events", "org.polyfrost.oneconfig.api.event.v1"))
elif "import cc.polyfrost.oneconfig.libs.universal" in line:
f.write(line.replace("cc.polyfrost.oneconfig.libs.universal", "org.polyfrost.universal"))
elif "import cc.polyfrost" in line:
f.write(line.replace("cc.polyfrost", "org.polyfrost"))
else:
f.write(line)

f.truncate()

input("Finished removing OneConfig V0 imports.\n\nPress enter to start replacing V0 methods.\n")

for path, _, files in os.walk("."):
for name in files:
dir = str(pathlib.PurePath(path, name))
if not (name.endswith(".java") or name.endswith(".kt")):
continue

with open(dir, "r") as file:
original_text = file.read()
with open(dir, "r+") as file:
content = file.read().replace("TickDelay", "EventDelay.ticks").replace("tick(", "EventDelay.ticks(").replace("RenderTickDelay", "EventDelay.render").replace("renderTick(", "EventDelay.render(")
add_import("org.polyfrost.oneconfig.api.event.v1.EventDelay")

with open(dir, "r") as file:
original_text = file.read()
with open(dir, "r+") as file:
content = file.read().replace("OneColor", "PolyColor")

with open(dir, "r") as file:
original_text = file.read()
with open(dir, "r+") as file:
content = file.read().replace("OneKeyBind", "Keybinder.Bind")

input("Done! (press enter to exit)")
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pluginManagement {
maven("https://repo.polyfrost.org/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit
}
plugins {
val pgtVersion = "0.6.2" // Sets the default versions for Polyfrost Gradle Toolkit
val pgtVersion = "0.6.5" // Sets the default versions for Polyfrost Gradle Toolkit
id("org.polyfrost.multi-version.root") version pgtVersion
}
}
Expand Down
106 changes: 61 additions & 45 deletions src/main/java/org/polyfrost/crashpatch/hooks/ModsCheckerPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.polyfrost.crashpatch.hooks;

import cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker;
import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
Expand Down Expand Up @@ -32,10 +31,15 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ModsCheckerPlugin extends LaunchWrapperTweaker {
public class ModsCheckerPlugin implements ITweaker { //todo
private static final JsonParser PARSER = new JsonParser();
public static final HashMap<String, Triple<File, String, String>> modsMap = new HashMap<>(); //modid : file, version, name

@Override
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {

}

@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
try {
Expand Down Expand Up @@ -127,51 +131,63 @@ public void injectIntoClassLoader(LaunchClassLoader classLoader) {
e.printStackTrace();
}

CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource();
if (codeSource != null) {
URL location = codeSource.getLocation();
try {
File file = new File(location.toURI());
if (file.isFile()) {
CoreModManager.getIgnoredMods().remove(file.getName());
CoreModManager.getReparseableCoremods().add(file.getName());
try {
try {
List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses"); // tweak classes before other mod trolling
if (tweakClasses.contains("org.spongepowered.asm.launch.MixinTweaker")) { // if there's already a mixin tweaker, we'll just load it like "usual"
new MixinTweaker(); // also we might not need to make a new mixin tweawker all the time but im just making sure
} else if (!Launch.blackboard.containsKey("mixin.initialised")) { // if there isnt, we do our own trolling
List<ITweaker> tweaks = (List<ITweaker>) Launch.blackboard.get("Tweaks");
tweaks.add(new MixinTweaker());
}
} catch (Exception ignored) {
// if it fails i *think* we can just ignore it
}
try {
MixinBootstrap.getPlatform().addContainer(location.toURI());
} catch (Exception ignore) {
// fuck you essential
try {
Class<?> containerClass = Class.forName("org.spongepowered.asm.launch.platform.container.IContainerHandle");
Class<?> urlContainerClass = Class.forName("org.spongepowered.asm.launch.platform.container.ContainerHandleURI");
Object container = urlContainerClass.getConstructor(URI.class).newInstance(location.toURI());
MixinBootstrap.getPlatform().getClass().getDeclaredMethod("addContainer", containerClass).invoke(MixinBootstrap.getPlatform(), container);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("OneConfig's Mixin loading failed. Please contact https://polyfrost.cc/discord to resolve this issue!");
}
}
} catch (Exception ignored) {
//todo terrible

//CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource();
//if (codeSource != null) {
// URL location = codeSource.getLocation();
// try {
// File file = new File(location.toURI());
// if (file.isFile()) {
// CoreModManager.getIgnoredMods().remove(file.getName());
// CoreModManager.getReparseableCoremods().add(file.getName());
// try {
// try {
// List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses"); // tweak classes before other mod trolling
// if (tweakClasses.contains("org.spongepowered.asm.launch.MixinTweaker")) { // if there's already a mixin tweaker, we'll just load it like "usual"
// new MixinTweaker(); // also we might not need to make a new mixin tweawker all the time but im just making sure
// } else if (!Launch.blackboard.containsKey("mixin.initialised")) { // if there isnt, we do our own trolling
// List<ITweaker> tweaks = (List<ITweaker>) Launch.blackboard.get("Tweaks");
// tweaks.add(new MixinTweaker());
// }
// } catch (Exception ignored) {
// // if it fails i *think* we can just ignore it
// }
// try {
// MixinBootstrap.getPlatform().addContainer(location.toURI());
// } catch (Exception ignore) {
// // fuck you essential
// try {
// Class<?> containerClass = Class.forName("org.spongepowered.asm.launch.platform.container.IContainerHandle");
// Class<?> urlContainerClass = Class.forName("org.spongepowered.asm.launch.platform.container.ContainerHandleURI");
// Object container = urlContainerClass.getConstructor(URI.class).newInstance(location.toURI());
// MixinBootstrap.getPlatform().getClass().getDeclaredMethod("addContainer", containerClass).invoke(MixinBootstrap.getPlatform(), container);
// } catch (Exception e) {
// e.printStackTrace();
// throw new RuntimeException("OneConfig's Mixin loading failed. Please contact https://polyfrost.cc/discord to resolve this issue!");
// }
// }
// } catch (Exception ignored) {
//
// }
// }
// } catch (URISyntaxException ignored) {}
//} else {
// LogManager.getLogger().warn("No CodeSource, if this is not a development environment we might run into problems!");
// LogManager.getLogger().warn(this.getClass().getProtectionDomain());
//}
//
//super.injectIntoClassLoader(classLoader);
}

}
}
} catch (URISyntaxException ignored) {}
} else {
LogManager.getLogger().warn("No CodeSource, if this is not a development environment we might run into problems!");
LogManager.getLogger().warn(this.getClass().getProtectionDomain());
}
@Override
public String getLaunchTarget() {
return null;
}

super.injectIntoClassLoader(classLoader);
@Override
public String[] getLaunchArguments() {
return new String[0];
}

private static void doThatPopupThing(File modsFolder, String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.polyfrost.crashpatch.mixin;

import cc.polyfrost.oneconfig.libs.universal.ChatColor;
import cc.polyfrost.oneconfig.libs.universal.UDesktop;
import org.polyfrost.universal.ChatColor;
import org.polyfrost.universal.UDesktop;
import org.polyfrost.crashpatch.CrashPatch;
import org.polyfrost.crashpatch.hooks.MinecraftHook;
import net.minecraft.client.Minecraft;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.polyfrost.crashpatch.mixin;

import cc.polyfrost.oneconfig.libs.universal.UDesktop;
import org.polyfrost.universal.UDesktop;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiErrorScreen;
Expand Down
Loading

0 comments on commit 0b2f13e

Please sign in to comment.