diff --git a/build.gradle.kts b/build.gradle.kts index cbbde0a..83ba50a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,37 +1,15 @@ plugins { - idea - java - - kotlin("jvm") version "1.9.10" + kotlin("jvm") version "1.9.10" apply false kotlin("plugin.serialization") version "1.9.10" - - id("org.polyfrost.loom") version "1.6.polyfrost.5" apply false - id("dev.architectury.architectury-pack200") version "0.1.3" apply false - id("com.github.johnrengelman.shadow") version "8.1.1" apply false + alias(libs.plugins.pgt.defaults.repo) apply false + idea } -allprojects { - plugins.apply("java") - plugins.apply("idea") +val modVer = project.properties["version"] - plugins.apply("org.jetbrains.kotlin.jvm") +version = "$modVer" +group = "wtf.zani" - repositories { - mavenCentral() - mavenLocal() - maven("https://repo.spongepowered.org/maven/") - maven("https://jitpack.io") - } - - dependencies { - if (name != "common") implementation(project(":common")) - } - - java { - toolchain.languageVersion.set(JavaLanguageVersion.of(8)) - } - - kotlin { - jvmToolchain(8) - } -} +subprojects { + version = rootProject.version +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index e3030c7..8fe3997 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true version=1.0.0 + +polyfrost.defaults.loom=3 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 16d1f70..c5ad324 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,9 +1,13 @@ [versions] +kotlin = "1.9.10" lwjgl = "3.3.3" -asm = "9.7" -mixins = "0.8.5-SNAPSHOT" +asm = "5.0.3" +mixins = "0.8.5-SNAPSHOT" # todo i dont think this is needed? mixinsForge = "0.7.11-SNAPSHOT" +pgt = "0.6.6" +annotations = "24.1.0" + [libraries] asmtree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" } @@ -16,5 +20,19 @@ lwjglOpengl = { module = "org.lwjgl:lwjgl-opengl", version.ref = "lwjgl" } mixins = { module = "org.spongepowered:mixin", version.ref = "mixins" } mixinsForge = { module = "org.spongepowered:mixin", version.ref = "mixinsForge" } +kotlin-common = { module = "org.jetbrains.kotlin:kotlin-stdlib-common", version.ref = "kotlin" } +kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } +kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" } + +annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" } + [bundles] lwjgl = ["lwjgl", "lwjglGlfw", "lwjglOpenal", "lwjglOpengl"] +kotlin = ["kotlin-reflect", "kotlin-stdlib", "kotlin-common"] + +[plugins] +pgt-main = { id = "org.polyfrost.multi-version", version.ref = "pgt" } +pgt-root = { id = "org.polyfrost.multi-version.root", version.ref = "pgt" } +pgt-defaults-repo = { id = "org.polyfrost.defaults.repo", version.ref = "pgt" } +pgt-defaults-java = { id = "org.polyfrost.defaults.java", version.ref = "pgt" } +pgt-defaults-loom = { id = "org.polyfrost.defaults.loom", version.ref = "pgt" } \ No newline at end of file diff --git a/common/build.gradle.kts b/modules/common/build.gradle.kts similarity index 100% rename from common/build.gradle.kts rename to modules/common/build.gradle.kts diff --git a/common/src/main/kotlin/net/weavemc/loader/api/util/InsnDsl.kt b/modules/common/src/main/kotlin/net/weavemc/loader/api/util/InsnDsl.kt similarity index 100% rename from common/src/main/kotlin/net/weavemc/loader/api/util/InsnDsl.kt rename to modules/common/src/main/kotlin/net/weavemc/loader/api/util/InsnDsl.kt diff --git a/common/src/main/kotlin/wtf/zani/spice/util/ClassUtil.kt b/modules/common/src/main/kotlin/wtf/zani/spice/util/ClassUtil.kt similarity index 77% rename from common/src/main/kotlin/wtf/zani/spice/util/ClassUtil.kt rename to modules/common/src/main/kotlin/wtf/zani/spice/util/ClassUtil.kt index f8f54a7..903c17d 100644 --- a/common/src/main/kotlin/wtf/zani/spice/util/ClassUtil.kt +++ b/modules/common/src/main/kotlin/wtf/zani/spice/util/ClassUtil.kt @@ -1,22 +1,17 @@ package wtf.zani.spice.util -import org.objectweb.asm.ClassWriter -import org.objectweb.asm.ClassWriter.COMPUTE_MAXS import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.InvokeDynamicInsnNode import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.MethodNode -import kotlin.io.path.Path -import kotlin.io.path.createDirectories -import kotlin.io.path.writeBytes fun getStrings(node: ClassNode): Set = node.methods.map { - getStrings(it) + getStrings(it as MethodNode) }.flatten().toSet() fun getStrings(node: MethodNode): Set = - node.instructions + node.instructions.iterator().asSequence() .filter { insn -> (insn is LdcInsnNode && insn.cst is String) || (insn is InvokeDynamicInsnNode && insn.bsmArgs.any { it is String }) diff --git a/core/build.gradle.kts b/modules/core/build.gradle.kts similarity index 82% rename from core/build.gradle.kts rename to modules/core/build.gradle.kts index 4273cf7..ae58500 100644 --- a/core/build.gradle.kts +++ b/modules/core/build.gradle.kts @@ -1,14 +1,12 @@ plugins { id("com.github.johnrengelman.shadow") - kotlin("plugin.serialization") } dependencies { compileOnly("org.apache.logging.log4j:log4j-api:2.0-beta9") - compileOnly(project(":lwjgl")) + compileOnly(project(":modules:lwjgl")) - compileOnly(rootProject.libs.mixins) compileOnly(rootProject.libs.asmtree) compileOnly(rootProject.libs.bundles.lwjgl) @@ -17,7 +15,7 @@ dependencies { tasks.processResources { from( - project(":lwjgl") + project(":modules:lwjgl") .tasks .shadowJar .get() diff --git a/core/src/main/kotlin/wtf/zani/spice/ModManifest.kt b/modules/core/src/main/kotlin/wtf/zani/spice/ModManifest.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/ModManifest.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/ModManifest.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/Options.kt b/modules/core/src/main/kotlin/wtf/zani/spice/Options.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/Options.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/Options.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/Spice.kt b/modules/core/src/main/kotlin/wtf/zani/spice/Spice.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/Spice.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/Spice.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/debug/DebugHelper.kt b/modules/core/src/main/kotlin/wtf/zani/spice/debug/DebugHelper.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/debug/DebugHelper.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/debug/DebugHelper.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/debug/DebugSection.kt b/modules/core/src/main/kotlin/wtf/zani/spice/debug/DebugSection.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/debug/DebugSection.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/debug/DebugSection.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/fixes/EarlyCrashFix.kt b/modules/core/src/main/kotlin/wtf/zani/spice/fixes/EarlyCrashFix.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/fixes/EarlyCrashFix.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/fixes/EarlyCrashFix.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/patcher/LunarTransformer.kt b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/LunarTransformer.kt similarity index 81% rename from core/src/main/kotlin/wtf/zani/spice/patcher/LunarTransformer.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/patcher/LunarTransformer.kt index b9bc6c9..eebf0bc 100644 --- a/core/src/main/kotlin/wtf/zani/spice/patcher/LunarTransformer.kt +++ b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/LunarTransformer.kt @@ -2,6 +2,7 @@ package wtf.zani.spice.patcher import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.FieldInsnNode +import org.objectweb.asm.tree.MethodNode import wtf.zani.spice.platform.api.IClassTransformer import wtf.zani.spice.util.getStrings @@ -11,10 +12,12 @@ object LunarTransformer : IClassTransformer { if (getStrings(node).contains("Can't translate key \u0001")) { val fromLwjglMethod = node.methods - .find { it.desc.startsWith("(I)") }!! + .find { (it as MethodNode).desc.startsWith("(I)") } as MethodNode val index = fromLwjglMethod .instructions + .iterator() + .asSequence() .indexOfLast { it is FieldInsnNode && it.owner == "java/lang/System" && it.name == "err" } (index..index + 3).map { fromLwjglMethod.instructions[it] } diff --git a/core/src/main/kotlin/wtf/zani/spice/patcher/LwjglProvider.kt b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/LwjglProvider.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/patcher/LwjglProvider.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/patcher/LwjglProvider.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/patcher/LwjglTransformer.kt b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/LwjglTransformer.kt similarity index 91% rename from core/src/main/kotlin/wtf/zani/spice/patcher/LwjglTransformer.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/patcher/LwjglTransformer.kt index ec868fb..5dea6fe 100644 --- a/core/src/main/kotlin/wtf/zani/spice/patcher/LwjglTransformer.kt +++ b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/LwjglTransformer.kt @@ -3,6 +3,7 @@ package wtf.zani.spice.patcher import net.weavemc.loader.api.util.asm import org.objectweb.asm.Opcodes.* import org.objectweb.asm.tree.ClassNode +import org.objectweb.asm.tree.FieldNode import org.objectweb.asm.tree.LdcInsnNode import org.objectweb.asm.tree.MethodNode import wtf.zani.spice.patcher.fixes.OpenAlFixes @@ -19,7 +20,9 @@ object LwjglTransformer : IClassTransformer { if (node.name == "org/lwjgl/opengl/PixelFormat") return if (node.name == "org/lwjgl/system/Library") { node.methods.forEach { method -> - method.instructions + (method as MethodNode).instructions + .iterator() + .asSequence() .filter { it is LdcInsnNode && it.cst is String && it.cst == "java.library.path" } .forEach { (it as LdcInsnNode).cst = "spice.library.path" } } @@ -45,7 +48,7 @@ object LwjglTransformer : IClassTransformer { node .fields .forEach { field -> - field.access = field.access and ACC_FINAL.inv() + (field as FieldNode).access = field.access and ACC_FINAL.inv() } } @@ -58,7 +61,7 @@ object LwjglTransformer : IClassTransformer { patch .fields .forEach { field -> - if (!node.fields.any { it.name == field.name && it.desc == field.desc }) + if (!node.fields.any { (it as FieldNode).name == (field as FieldNode).name && it.desc == field.desc }) node.fields.add(field) } @@ -101,8 +104,8 @@ object LwjglTransformer : IClassTransformer { val destroyMethod = node .methods .find { - it.name == "destroy" && it.desc == "()V" - } ?: run { + (it as MethodNode).name == "destroy" && it.desc == "()V" + } as? MethodNode ?: run { foundDestroy = false MethodNode() @@ -139,7 +142,7 @@ object LwjglTransformer : IClassTransformer { node .methods .forEach { method -> - renames[method.name]?.run { + renames[(method as MethodNode).name]?.run { if (second == method.desc) method.name = first } } diff --git a/core/src/main/kotlin/wtf/zani/spice/patcher/OptifineTransformer.kt b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/OptifineTransformer.kt similarity index 86% rename from core/src/main/kotlin/wtf/zani/spice/patcher/OptifineTransformer.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/patcher/OptifineTransformer.kt index 9032136..a3075ee 100644 --- a/core/src/main/kotlin/wtf/zani/spice/patcher/OptifineTransformer.kt +++ b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/OptifineTransformer.kt @@ -3,6 +3,7 @@ package wtf.zani.spice.patcher import org.objectweb.asm.Opcodes.INVOKESTATIC import org.objectweb.asm.tree.ClassNode import org.objectweb.asm.tree.MethodInsnNode +import org.objectweb.asm.tree.MethodNode import wtf.zani.spice.platform.api.IClassTransformer object OptifineTransformer : IClassTransformer { @@ -10,8 +11,10 @@ object OptifineTransformer : IClassTransformer { if (node.name != "net/optifine/shaders/Shaders") return node.methods.forEach { method -> - method + (method as MethodNode) .instructions + .iterator() + .asSequence() .filter { it is MethodInsnNode && it.owner == "org/lwjgl/opengl/EXTFramebufferObject" diff --git a/core/src/main/kotlin/wtf/zani/spice/patcher/fixes/OpenAlFixes.kt b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/fixes/OpenAlFixes.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/patcher/fixes/OpenAlFixes.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/patcher/fixes/OpenAlFixes.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/patcher/fixes/OpenGlFixes.kt b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/fixes/OpenGlFixes.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/patcher/fixes/OpenGlFixes.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/patcher/fixes/OpenGlFixes.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/patcher/util/AudioHelper.kt b/modules/core/src/main/kotlin/wtf/zani/spice/patcher/util/AudioHelper.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/patcher/util/AudioHelper.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/patcher/util/AudioHelper.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/platform/Bootstrap.kt b/modules/core/src/main/kotlin/wtf/zani/spice/platform/Bootstrap.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/platform/Bootstrap.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/platform/Bootstrap.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/platform/api/IClassTransformer.kt b/modules/core/src/main/kotlin/wtf/zani/spice/platform/api/IClassTransformer.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/platform/api/IClassTransformer.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/platform/api/IClassTransformer.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/platform/api/Platform.kt b/modules/core/src/main/kotlin/wtf/zani/spice/platform/api/Platform.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/platform/api/Platform.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/platform/api/Platform.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/util/OptifineUtil.kt b/modules/core/src/main/kotlin/wtf/zani/spice/util/OptifineUtil.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/util/OptifineUtil.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/util/OptifineUtil.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/util/SystemUtil.kt b/modules/core/src/main/kotlin/wtf/zani/spice/util/SystemUtil.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/util/SystemUtil.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/util/SystemUtil.kt diff --git a/core/src/main/kotlin/wtf/zani/spice/util/UrlConnection.kt b/modules/core/src/main/kotlin/wtf/zani/spice/util/UrlConnection.kt similarity index 100% rename from core/src/main/kotlin/wtf/zani/spice/util/UrlConnection.kt rename to modules/core/src/main/kotlin/wtf/zani/spice/util/UrlConnection.kt diff --git a/lwjgl/build.gradle.kts b/modules/lwjgl/build.gradle.kts similarity index 100% rename from lwjgl/build.gradle.kts rename to modules/lwjgl/build.gradle.kts diff --git a/lwjgl/src/main/kotlin/org/lwjgl/LWJGLException.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/LWJGLException.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/LWJGLException.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/LWJGLException.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/Sys.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/Sys.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/Sys.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/Sys.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/input/Keyboard.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/input/Keyboard.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/input/Keyboard.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/input/Keyboard.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/input/api/IKeyboard.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/input/api/IKeyboard.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/input/api/IKeyboard.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/input/api/IKeyboard.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/input/api/IMouse.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/input/api/IMouse.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/input/api/IMouse.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/input/api/IMouse.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/input/impl/KeyboardImpl.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/input/impl/KeyboardImpl.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/input/impl/KeyboardImpl.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/input/impl/KeyboardImpl.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/input/impl/MouseImpl.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/input/impl/MouseImpl.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/input/impl/MouseImpl.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/input/impl/MouseImpl.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/opengl/ContextCapabilities.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/ContextCapabilities.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/opengl/ContextCapabilities.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/ContextCapabilities.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/opengl/Display.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/Display.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/opengl/Display.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/Display.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/opengl/DisplayMode.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/DisplayMode.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/opengl/DisplayMode.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/DisplayMode.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/opengl/GLContext.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/GLContext.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/opengl/GLContext.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/GLContext.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/opengl/PixelFormat.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/PixelFormat.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/opengl/PixelFormat.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/opengl/PixelFormat.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/util/InputHelper.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/util/InputHelper.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/util/InputHelper.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/util/InputHelper.kt diff --git a/lwjgl/src/main/kotlin/org/lwjgl/util/Sync.kt b/modules/lwjgl/src/main/kotlin/org/lwjgl/util/Sync.kt similarity index 100% rename from lwjgl/src/main/kotlin/org/lwjgl/util/Sync.kt rename to modules/lwjgl/src/main/kotlin/org/lwjgl/util/Sync.kt diff --git a/modules/root.gradle.kts b/modules/root.gradle.kts new file mode 100644 index 0000000..3ea230b --- /dev/null +++ b/modules/root.gradle.kts @@ -0,0 +1,28 @@ +@file:Suppress("UnstableApiUsage", "DEPRECATION") + +// Shared build logic between all OneConfig modules to reduce boilerplate. + +plugins { + idea +} + +val rootModuleProject = project + +subprojects { + apply(plugin = "java-library") + apply(plugin = "kotlin") + + dependencies { + "implementation"(rootProject.libs.annotations) + if (name != "common") "implementation"(project(":modules:common")) + "implementation"(rootProject.libs.bundles.kotlin) + } + + //base.archiveBaseName = name + + configure { + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + } + } +} \ No newline at end of file diff --git a/platform/build.gradle.kts b/platform/build.gradle.kts deleted file mode 100644 index 81493a6..0000000 --- a/platform/build.gradle.kts +++ /dev/null @@ -1,34 +0,0 @@ -plugins { - id("com.github.johnrengelman.shadow") -} - -subprojects { - plugins.apply("com.github.johnrengelman.shadow") - - val shadowImpl by configurations.creating { - extendsFrom(configurations.implementation.get()) - } - - configurations { - compileClasspath { extendsFrom(shadowImpl) } - runtimeClasspath { extendsFrom(shadowImpl) } - } - - dependencies { - shadowImpl(project(":core")) - } - - tasks.jar { - archiveBaseName.set("spice") - archiveClassifier.set("no-deps") - - destinationDirectory.set(layout.buildDirectory.dir("badjars")) - } - - tasks.shadowJar { - destinationDirectory.set(layout.buildDirectory.dir("badjars")) - configurations = listOf(shadowImpl) - - exclude("org/objectweb/asm/**/*.class") - } -} diff --git a/platform/fabric-1.8/build.gradle.kts b/platform/fabric-1.8/build.gradle.kts deleted file mode 100644 index 467af95..0000000 --- a/platform/fabric-1.8/build.gradle.kts +++ /dev/null @@ -1,31 +0,0 @@ -plugins { - id("org.polyfrost.loom") - id("dev.architectury.architectury-pack200") -} - -loom { - runConfigs { remove(getByName("server")) } - runConfigs.getByName("client").isIdeConfigGenerated = true - - intermediaryUrl.set("https://maven.legacyfabric.net/net/legacyfabric/intermediary/1.8.9/intermediary-1.8.9-v2.jar") -} - -repositories { - maven("https://maven.legacyfabric.net/") -} - -dependencies { - minecraft("com.mojang:minecraft:1.8.9") - mappings("net.legacyfabric:yarn:1.8.9+build.535:v2") - modImplementation("net.fabricmc:fabric-loader:0.15.7") - - compileOnly(project(":lwjgl")) - compileOnly(rootProject.libs.mixins) -} - -tasks.remapJar { - dependsOn(tasks.shadowJar) - - archiveClassifier.set("fabric") - inputFile.set(tasks.shadowJar.get().archiveFile) -} diff --git a/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/common/DebugHudMixin.java b/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/common/DebugHudMixin.java deleted file mode 100644 index 8f94a5f..0000000 --- a/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/common/DebugHudMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package wtf.zani.spice.mixin.common; - -import net.minecraft.client.gui.hud.DebugHud; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import wtf.zani.spice.debug.DebugHelper; - -import java.util.List; - -@Mixin(DebugHud.class) -public abstract class DebugHudMixin { - @Inject(method = "getRightText", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/DebugHud;hasReducedDebugInfo()Z")) - private void addSpiceDebugInfo(CallbackInfoReturnable> cir, long max, long total, long free, long used, List lines) { - DebugHelper.applyExtraDebugInfo(lines); - } -} diff --git a/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/common/MinecraftClientMixin.java b/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/common/MinecraftClientMixin.java deleted file mode 100644 index 6d0431c..0000000 --- a/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/common/MinecraftClientMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -package wtf.zani.spice.mixin.common; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.util.crash.CrashReport; -import net.minecraft.util.crash.CrashReportSection; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import wtf.zani.spice.Spice; -import wtf.zani.spice.platform.impl.fabric.FabricPlatform; - -import java.util.concurrent.Callable; - -import static wtf.zani.spice.fixes.EarlyCrashFixKt.getFieldValue; -import static wtf.zani.spice.platform.BootstrapKt.bootstrap; - -@Mixin(MinecraftClient.class) -public abstract class MinecraftClientMixin { - @Inject(method = "addSystemDetailsToCrashReport", at = @At("HEAD")) - private void addSpiceInfo(CrashReport instance, CallbackInfoReturnable cir) { - instance.getSystemDetailsSection().add("Spice", Spice::getVersion); - instance.getSystemDetailsSection().add("GLFW", Spice::getGlfwVersion); - } - - // in case we cause a crash too early - @Redirect(method = "addSystemDetailsToCrashReport", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReportSection;add(Ljava/lang/String;Ljava/util/concurrent/Callable;)V")) - private void fixupCrashReport(CrashReportSection instance, String name, Callable value) { - instance.add(name, getFieldValue(name, value)); - } - - @Inject(method = "run", at = @At("HEAD")) - private void initialize(CallbackInfo ci) { - bootstrap(FabricPlatform.Companion.getInstance()); - } -} diff --git a/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/lwjgl3/ControlsOptionsScreenMixin.java b/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/lwjgl3/ControlsOptionsScreenMixin.java deleted file mode 100644 index 4e4da4f..0000000 --- a/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/lwjgl3/ControlsOptionsScreenMixin.java +++ /dev/null @@ -1,70 +0,0 @@ -package wtf.zani.spice.mixin.lwjgl3; - -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.options.ControlsOptionsScreen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.OptionButtonWidget; -import net.minecraft.client.option.GameOptions; -import org.lwjgl.input.Mouse; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import wtf.zani.spice.Options; -import wtf.zani.spice.Spice; - -@Mixin(ControlsOptionsScreen.class) -public abstract class ControlsOptionsScreenMixin extends Screen { - @Shadow - @Final - private static GameOptions.Option[] OPTIONS; - - @Unique - private final Options spice$options = Spice.getOptions(); - @Unique - private OptionButtonWidget spice$rawInputButton; - - @Inject(method = "init", at = @At("TAIL")) - private void injectButton(CallbackInfo ci) { - if (!Mouse.isRawInputSupported()) return; - - spice$rawInputButton = new OptionButtonWidget( - 300, - width / 2 - 155 + OPTIONS.length % 2 * 160, - 18 + 24 * (OPTIONS.length >> 1), - 150, - 20, - spice$formatButtonText() - ); - - buttons.add(spice$rawInputButton); - } - - @Inject(method = "buttonClicked", at = @At("HEAD"), cancellable = true) - private void handleAction(ButtonWidget button, CallbackInfo ci) { - if (!Mouse.isRawInputSupported()) return; - - if (button.id == 200) { - Spice.saveOptions(); - } - - if (button.id == spice$rawInputButton.id) { - spice$options.rawInput = !spice$options.rawInput; - spice$options.needsSave = true; - - Mouse.setRawInput(spice$options.rawInput); - - button.message = spice$formatButtonText(); - - ci.cancel(); - } - } - - @Unique - private String spice$formatButtonText() { - return "Raw Input: " + (spice$options.rawInput ? "ON" : "OFF"); - } -} diff --git a/platform/fabric-1.8/src/main/resources/spice.mixins.json b/platform/fabric-1.8/src/main/resources/spice.mixins.json deleted file mode 100644 index a6ff36d..0000000 --- a/platform/fabric-1.8/src/main/resources/spice.mixins.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "required": true, - "minVersion": "0.7", - "package": "wtf.zani.spice.mixin", - "compatibilityLevel": "JAVA_8", - "client": [ - "common.DebugHudMixin", - "common.MinecraftClientMixin", - "lwjgl3.ControlsOptionsScreenMixin", - "lwjgl3.MinecraftClientMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 42ad180..e753f63 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,18 +1,50 @@ pluginManagement { repositories { - mavenCentral() gradlePluginPortal() + mavenCentral() + maven("https://repo.polyfrost.org/releases") { + name = "Polyfrost Releases" + } + } +} + +dependencyResolutionManagement { + repositories { + mavenCentral() maven("https://repo.polyfrost.org/releases") } } rootProject.name = "Spice" -include( - ":lwjgl", - ":common", - ":core", - ":platform:fabric-1.8", - ":platform:forge-1.8", -) +include(":modules") +project(":modules").apply { + buildFileName = "root.gradle.kts" +} + +listOf( + "lwjgl", + "common", + "core" +).forEach { module -> + include(":modules:$module") +} +include(":platform") +project(":platform").apply { + projectDir = file("versions/") + buildFileName = "preprocessor.gradle.kts" +} + +listOf( + "1.8.9-forge", + "1.8.9-fabric", + "1.12.2-fabric", + "1.12.2-forge" +).forEach { version -> + include(":platform:$version") + project(":platform:$version").apply { + projectDir = file("versions/$version") + buildFileName = "../build.gradle.kts" + } +} \ No newline at end of file diff --git a/platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/FabricInitializer.kt b/versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/FabricInitializer.kt similarity index 100% rename from platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/FabricInitializer.kt rename to versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/FabricInitializer.kt diff --git a/platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/FabricPlatform.kt b/versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/FabricPlatform.kt similarity index 100% rename from platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/FabricPlatform.kt rename to versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/FabricPlatform.kt diff --git a/platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/MixinGenerator.kt b/versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/MixinGenerator.kt similarity index 100% rename from platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/MixinGenerator.kt rename to versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/MixinGenerator.kt diff --git a/platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/TransformerPlugin.kt b/versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/TransformerPlugin.kt similarity index 98% rename from platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/TransformerPlugin.kt rename to versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/TransformerPlugin.kt index 5187067..0ee81a7 100644 --- a/platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/TransformerPlugin.kt +++ b/versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/asm/TransformerPlugin.kt @@ -1,6 +1,5 @@ package wtf.zani.spice.platform.impl.fabric.asm -import org.apache.logging.log4j.LogManager import org.objectweb.asm.tree.ClassNode import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin import org.spongepowered.asm.mixin.extensibility.IMixinInfo diff --git a/platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/util/Classpath.kt b/versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/util/Classpath.kt similarity index 100% rename from platform/fabric-1.8/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/util/Classpath.kt rename to versions/1.8.9-fabric/src/main/kotlin/wtf/zani/spice/platform/impl/fabric/util/Classpath.kt diff --git a/platform/fabric-1.8/src/main/resources/fabric.mod.json b/versions/1.8.9-fabric/src/main/resources/fabric.mod.json similarity index 94% rename from platform/fabric-1.8/src/main/resources/fabric.mod.json rename to versions/1.8.9-fabric/src/main/resources/fabric.mod.json index b1fce78..9cac238 100644 --- a/platform/fabric-1.8/src/main/resources/fabric.mod.json +++ b/versions/1.8.9-fabric/src/main/resources/fabric.mod.json @@ -24,6 +24,6 @@ ], "depends": { "fabricloader": ">=0.14.19", - "minecraft": "1.8.9" + "minecraft": "${mcVersionStr}" } } diff --git a/platform/fabric-1.8/src/main/resources/transformer.mixins.json b/versions/1.8.9-fabric/src/main/resources/transformer.mixins.json similarity index 100% rename from platform/fabric-1.8/src/main/resources/transformer.mixins.json rename to versions/1.8.9-fabric/src/main/resources/transformer.mixins.json diff --git a/platform/fabric-1.8/src/main/resources/transformer.mixins.refmap.json b/versions/1.8.9-fabric/src/main/resources/transformer.mixins.refmap.json similarity index 100% rename from platform/fabric-1.8/src/main/resources/transformer.mixins.refmap.json rename to versions/1.8.9-fabric/src/main/resources/transformer.mixins.refmap.json diff --git a/versions/build.gradle.kts b/versions/build.gradle.kts new file mode 100644 index 0000000..6959317 --- /dev/null +++ b/versions/build.gradle.kts @@ -0,0 +1,171 @@ +@file:Suppress("UnstableApiUsage") +// Shared build logic for all versions of OneConfig. + +import org.polyfrost.gradle.util.noServerRunConfigs +import org.polyfrost.gradle.util.prebundle +import java.text.SimpleDateFormat +import java.util.zip.ZipFile + +plugins { + kotlin("jvm") version "1.9.10" + id(libs.plugins.pgt.main.get().pluginId) + id(libs.plugins.pgt.defaults.repo.get().pluginId) + id(libs.plugins.pgt.defaults.java.get().pluginId) + id(libs.plugins.pgt.defaults.loom.get().pluginId) + id("com.github.johnrengelman.shadow") + `java-library` +} +val tweakClass = "org.spongepowered.asm.launch.MixinTweaker" + +base.archivesName = "Spice-${platform}" + +kotlin { + jvmToolchain(8) +} + +loom { + noServerRunConfigs() + runConfigs { + "client" { + if (project.platform.isLegacyForge) { + programArgs("--tweakClass", tweakClass) + } + property("mixin.debug.export", "true") + property("debugBytecode", "true") + property("forge.logging.console.level", "debug") + if (org.gradle.internal.os.OperatingSystem.current().isMacOsX) { + property("fml.earlyprogresswindow", "false") + } + } + } + if (project.platform.isForge) { + forge { + mixinConfig("spice.mixins.json") + } + } +} + +val shadowImpl by configurations.creating { + configurations.implementation.get().extendsFrom(this) +} + +dependencies { + shadowImpl(project(":modules:core")) { + exclude("org.apache.logging.log4j") + exclude("org.ow2.asm") + } + compileOnly(project(":modules:lwjgl")) + + if (platform.isLegacyForge) { + shadowImpl(libs.mixinsForge) { + isTransitive = false + } + } else { + compileOnly(libs.mixins) + } + + if (!platform.isLegacyFabric) { + modRuntimeOnly( + "me.djtheredstoner:DevAuth-" + + (if (platform.isForge) { + if (platform.isLegacyForge) "forge-legacy" else "forge-latest" + } else "fabric") + + ":1.1.2" + ) + } +} + +tasks { + jar { + dependsOn(shadowJar) + archiveBaseName.set("spice") + archiveClassifier.set("no-deps") + + destinationDirectory.set(layout.buildDirectory.dir("badjars")) + } + + shadowJar { + destinationDirectory.set(layout.buildDirectory.dir("badjars")) + configurations = listOf(shadowImpl) + } + + withType(Jar::class) { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + exclude("META-INF/com.android.tools/**") + exclude("META-INF/proguard/**") + if (platform.isFabric) { + exclude("mcmod.info", "META-INF/mods.toml") + } else { + exclude("fabric.mod.json") + if (platform.isLegacyForge) { + exclude("**/mods.toml") + exclude("META-INF/versions/**") + exclude("**/module-info.class") + exclude("**/package-info.class") + } + } + } + + processResources { + inputs.property("id", rootProject.properties["mod_id"].toString()) + inputs.property("name", rootProject.name) + inputs.property("java", 8) + inputs.property("version", version) + inputs.property( + "mcVersionStr", + if (platform.isFabric) platform.mcVersionStr.substringBeforeLast('.') + ".x" else platform.mcVersionStr + ) + + val id = inputs.properties["id"] + val name = inputs.properties["name"] + val version = inputs.properties["version"] + val mcVersionStr = inputs.properties["mcVersionStr"].toString() + val java = inputs.properties["java"].toString().toInt() + val javaLevel = "JAVA-$java" + + filesMatching(listOf("mcmod.info", "spice.mixins.json", "**/mods.toml", "fabric.mod.json")) { + expand( + mapOf( + "id" to id, + "name" to name, + "java" to java, + "java_level" to javaLevel, + "version" to version, + "mcVersionStr" to mcVersionStr + ) + ) + } + } + + remapJar { + inputFile.set(shadowJar.get().archiveFile) + + manifest { + val attributesMap = buildMap { + if (platform.isForge) { + putAll( + mapOf( + "ModSide" to "CLIENT", + "ForceLoadAsMod" to true, + "TweakOrder" to "0", + "MixinConfigs" to "spice.mixins.json", + "TweakClass" to tweakClass + ) + ) + } + putAll( + mapOf( + "Specification-Title" to "Spice", + "Specification-Vendor" to "Polyfrost", + "Specification-Version" to "1", // We are version 1 of ourselves, whatever the hell that means + "Implementation-Title" to rootProject.name, + "Implementation-Version" to project.version, + "Implementation-Vendor" to "Polyfrost", + "Implementation-Timestamp" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(`java.util`.Date()) + ) + ) + } + attributes(attributesMap) + } + } +} \ No newline at end of file diff --git a/versions/mainProject b/versions/mainProject new file mode 100644 index 0000000..dd1433e --- /dev/null +++ b/versions/mainProject @@ -0,0 +1 @@ +1.8.9-forge \ No newline at end of file diff --git a/versions/mappings/fabric-forge-1.8.9.txt b/versions/mappings/fabric-forge-1.8.9.txt new file mode 100644 index 0000000..e69de29 diff --git a/versions/mappings/forge-1.12.2-1.8.9.txt b/versions/mappings/forge-1.12.2-1.8.9.txt new file mode 100644 index 0000000..d338309 --- /dev/null +++ b/versions/mappings/forge-1.12.2-1.8.9.txt @@ -0,0 +1 @@ +net.minecraft.crash.CrashReportCategory addDetail() net.minecraft.crash.CrashReportCategory addCrashSectionCallable() \ No newline at end of file diff --git a/versions/preprocessor.gradle.kts b/versions/preprocessor.gradle.kts new file mode 100644 index 0000000..28fd283 --- /dev/null +++ b/versions/preprocessor.gradle.kts @@ -0,0 +1,17 @@ +plugins { + kotlin("jvm") version "1.9.10" apply false + id(libs.plugins.pgt.root.get().pluginId) +} + +preprocess { + // FOR ALL NEW VERSIONS ENSURE TO UPDATE settings.gradle.kts ! + + val forge10809 = createNode("1.8.9-forge", 10809, "srg") + val fabric10809 = createNode("1.8.9-fabric", 10809, "yarn") + val forge11202 = createNode("1.12.2-forge", 11202, "srg") + val fabric11202 = createNode("1.12.2-fabric", 11202, "yarn") + + fabric11202.link(fabric10809) + fabric10809.link(forge10809, file("mappings/fabric-forge-1.8.9.txt")) + forge11202.link(forge10809, file("mappings/forge-1.12.2-1.8.9.txt")) +} \ No newline at end of file diff --git a/versions/src/main/java/wtf/zani/spice/mixin/common/GuiOverlayDebugMixin.java b/versions/src/main/java/wtf/zani/spice/mixin/common/GuiOverlayDebugMixin.java new file mode 100644 index 0000000..7fbe571 --- /dev/null +++ b/versions/src/main/java/wtf/zani/spice/mixin/common/GuiOverlayDebugMixin.java @@ -0,0 +1,33 @@ +package wtf.zani.spice.mixin.common; + +import net.minecraft.client.gui.GuiOverlayDebug; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import wtf.zani.spice.debug.DebugHelper; + +import java.util.List; + +@Mixin(GuiOverlayDebug.class) +public abstract class GuiOverlayDebugMixin { + @Unique + private static final String REDUCED_DEBUG_DESC = + //#if FABRIC + //#if MC>=11200 + //$$ "Lnet/minecraft/client/MinecraftClient;method_13408()Z"; // i love incomplete mappings. todo switch to mcp for legacy fabric as well? + //#else + //$$ "Lnet/minecraft/client/gui/hud/DebugHud;hasReducedDebugInfo()Z"; + //#endif + //#elseif MC>=11200 + //$$ "Lnet/minecraft/client/Minecraft;isReducedDebug()Z"; + //#else + "Lnet/minecraft/client/gui/GuiOverlayDebug;isReducedDebug()Z"; + //#endif + @Inject(method = "getDebugInfoRight", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = REDUCED_DEBUG_DESC)) + private void addSpiceDebugInfo(CallbackInfoReturnable> cir, long max, long total, long free, long used, List lines) { + DebugHelper.applyExtraDebugInfo(lines); + } +} diff --git a/versions/src/main/java/wtf/zani/spice/mixin/common/MinecraftMixin.java b/versions/src/main/java/wtf/zani/spice/mixin/common/MinecraftMixin.java new file mode 100644 index 0000000..64ffb15 --- /dev/null +++ b/versions/src/main/java/wtf/zani/spice/mixin/common/MinecraftMixin.java @@ -0,0 +1,68 @@ +package wtf.zani.spice.mixin.common; + +import net.minecraft.client.Minecraft; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import wtf.zani.spice.Spice; + +import java.util.concurrent.Callable; + +import static wtf.zani.spice.fixes.EarlyCrashFixKt.getFieldValue; +import static wtf.zani.spice.platform.BootstrapKt.bootstrap; + +@Mixin(Minecraft.class) +public abstract class MinecraftMixin { + @Unique + private static final String ADD_CRASH_SECTION_DESC = + //#if MC>=11200 + //#if FABRIC + //$$ "Lnet/minecraft/util/crash/CrashReportSection;add(Ljava/lang/String;Lnet/minecraft/util/crash/CrashCallable;)V"; + //#else + //$$ "Lnet/minecraft/crash/CrashReportCategory;addDetail(Ljava/lang/String;Lnet/minecraft/crash/ICrashReportDetail;)V"; + //#endif + //#elseif FABRIC + //$$ "Lnet/minecraft/util/crash/CrashReportSection;add(Ljava/lang/String;Ljava/util/concurrent/Callable;)V"; + //#else + "Lnet/minecraft/crash/CrashReportCategory;addCrashSectionCallable(Ljava/lang/String;Ljava/util/concurrent/Callable;)V"; + //#endif + @Inject(method = "addGraphicsAndWorldToCrashReport", at = @At("HEAD")) + private void addSpiceInfo(CrashReport instance, CallbackInfoReturnable cir) { + instance.getCategory().addCrashSectionCallable("Spice", Spice::getVersion); + instance.getCategory().addCrashSectionCallable("GLFW", Spice::getGlfwVersion); + } + + // in case we cause a crash too early + @Redirect(method = "addGraphicsAndWorldToCrashReport", at = @At(value = "INVOKE", target = ADD_CRASH_SECTION_DESC)) + private void fixupCrashReport(CrashReportCategory instance, String name, + //#if MC>=11200 + //#if FABRIC + //$$ net.minecraft.util.crash.CrashCallable value + //#else + //$$ net.minecraft.crash.ICrashReportDetail value + //#endif + //#else + Callable value + //#endif + + ) { + instance.addCrashSection(name, getFieldValue(name, value)); + } + + @Inject(method = "run", at = @At("HEAD")) + private void initialize(CallbackInfo ci) { + bootstrap(wtf.zani.spice.platform.impl. + //#if FABRIC + //$$ fabric.FabricPlatform + //#else + forge.ForgePlatform + //#endif + .Companion.getInstance()); + } +} diff --git a/versions/src/main/java/wtf/zani/spice/mixin/lwjgl3/GuiControlsMixin.java b/versions/src/main/java/wtf/zani/spice/mixin/lwjgl3/GuiControlsMixin.java new file mode 100644 index 0000000..0e2da00 --- /dev/null +++ b/versions/src/main/java/wtf/zani/spice/mixin/lwjgl3/GuiControlsMixin.java @@ -0,0 +1,83 @@ +package wtf.zani.spice.mixin.lwjgl3; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiControls; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.settings.GameSettings; +import org.lwjgl.input.Mouse; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import wtf.zani.spice.Options; +import wtf.zani.spice.Spice; + +@Mixin(GuiControls.class) +public abstract class GuiControlsMixin extends GuiScreen { + + @Shadow @Final private static GameSettings.Options[] optionsArr; + @Unique + private final Options spice$options = Spice.getOptions(); + @Unique + private GuiButton spice$rawInputButton; + @Unique + private static final String INIT_GUI_DESC = + //#if FABRIC + //$$ "init"; + //#else + "initGui"; + //#endif + + @Unique + private static final String BUTTON_PRESSED_DESC = + //#if FABRIC + //$$ "buttonClicked"; + //#else + "actionPerformed"; + //#endif + + @SuppressWarnings("AccessStaticViaInstance") // preprocessor requires `this` to be present + @Inject(method = INIT_GUI_DESC, at = @At("TAIL")) + private void injectButton(CallbackInfo ci) { + if (!Mouse.isRawInputSupported()) return; + + spice$rawInputButton = new GuiButton( + 300, + width / 2 - 155 + this.optionsArr.length % 2 * 160, + 18 + 24 * (this.optionsArr.length >> 1), + 150, + 20, + spice$formatButtonText() + ); + + this.buttonList.add(spice$rawInputButton); + } + + @Inject(method = BUTTON_PRESSED_DESC, at = @At("HEAD"), cancellable = true) + private void handleAction(GuiButton button, CallbackInfo ci) { + if (!Mouse.isRawInputSupported()) return; + + if (button.id == 200) { + Spice.saveOptions(); + } + + if (button.id == spice$rawInputButton.id) { + spice$options.rawInput = !spice$options.rawInput; + spice$options.needsSave = true; + + Mouse.setRawInput(spice$options.rawInput); + + button.displayString = spice$formatButtonText(); + + ci.cancel(); + } + } + + @Unique + private String spice$formatButtonText() { + return "Raw Input: " + (spice$options.rawInput ? "ON" : "OFF"); + } +} diff --git a/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/lwjgl3/MinecraftClientMixin.java b/versions/src/main/java/wtf/zani/spice/mixin/lwjgl3/MinecraftMixin.java similarity index 72% rename from platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/lwjgl3/MinecraftClientMixin.java rename to versions/src/main/java/wtf/zani/spice/mixin/lwjgl3/MinecraftMixin.java index a6a8ff0..8c37de1 100644 --- a/platform/fabric-1.8/src/main/java/wtf/zani/spice/mixin/lwjgl3/MinecraftClientMixin.java +++ b/versions/src/main/java/wtf/zani/spice/mixin/lwjgl3/MinecraftMixin.java @@ -1,6 +1,6 @@ package wtf.zani.spice.mixin.lwjgl3; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import org.lwjgl.input.Mouse; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -8,9 +8,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import wtf.zani.spice.Spice; -@Mixin(MinecraftClient.class) -public abstract class MinecraftClientMixin { - @Inject(method = "setPixelFormat", at = @At("TAIL")) +@Mixin(Minecraft.class) +public abstract class MinecraftMixin { + @Inject(method = "createDisplay", at = @At("TAIL")) private void setupRawInput(CallbackInfo ci) { if (!Mouse.isRawInputSupported()) return; diff --git a/versions/src/main/java/wtf/zani/spice/platform/impl/forge/asm/TransformerPlugin.java b/versions/src/main/java/wtf/zani/spice/platform/impl/forge/asm/TransformerPlugin.java new file mode 100644 index 0000000..33b39f0 --- /dev/null +++ b/versions/src/main/java/wtf/zani/spice/platform/impl/forge/asm/TransformerPlugin.java @@ -0,0 +1,34 @@ +package wtf.zani.spice.platform.impl.forge.asm; +//#if FORGE + +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; + +import java.util.Map; + +public class TransformerPlugin implements IFMLLoadingPlugin { + @Override + public String[] getASMTransformerClass() { + return new String[0]; + } + + @Override + public String getModContainerClass() { + return null; + } + + @Override + public String getSetupClass() { + return null; + } + + @Override + public void injectData(Map map) { + + } + + @Override + public String getAccessTransformerClass() { + return null; + } +} +//#endif \ No newline at end of file diff --git a/versions/src/main/kotlin/wtf/zani/spice/platform/impl/forge/ForgeInitializer.kt b/versions/src/main/kotlin/wtf/zani/spice/platform/impl/forge/ForgeInitializer.kt new file mode 100644 index 0000000..04b56f5 --- /dev/null +++ b/versions/src/main/kotlin/wtf/zani/spice/platform/impl/forge/ForgeInitializer.kt @@ -0,0 +1,9 @@ +package wtf.zani.spice.platform.impl.forge +//#if FORGE + +import net.minecraftforge.fml.common.Mod + +@Mod(modid = "spice", useMetadata = true) +class ForgeInitializer { +} +//#endif \ No newline at end of file diff --git a/versions/src/main/kotlin/wtf/zani/spice/platform/impl/forge/ForgePlatform.kt b/versions/src/main/kotlin/wtf/zani/spice/platform/impl/forge/ForgePlatform.kt new file mode 100644 index 0000000..310b1bd --- /dev/null +++ b/versions/src/main/kotlin/wtf/zani/spice/platform/impl/forge/ForgePlatform.kt @@ -0,0 +1,31 @@ +package wtf.zani.spice.platform.impl.forge +//#if FORGE + +import wtf.zani.spice.platform.api.IClassTransformer +import wtf.zani.spice.platform.api.Platform +import java.lang.reflect.Method +import java.net.URL + +class ForgePlatform(private val loader: ClassLoader, private val addUrl: Method) : Platform { + init { + instance = this + } + + override val id = Platform.ID.Fabric + internal val transformers = mutableListOf() + + override fun addTransformer(transformer: IClassTransformer) { + transformers += transformer + } + + override fun appendToClassPath(url: URL) { + println("appending $url to the classpath") + + addUrl(loader, url) + } + + companion object { + lateinit var instance: ForgePlatform + } +} +//#endif \ No newline at end of file