diff --git a/build.gradle.kts b/build.gradle.kts index 43b85717..3b2a2510 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,66 +1,52 @@ @file:Suppress("UnstableApiUsage", "PropertyName") import dev.deftu.gradle.utils.GameSide +import dev.deftu.gradle.utils.includeOrShade plugins { java kotlin("jvm") - id("dev.deftu.gradle.multiversion") - id("dev.deftu.gradle.tools") - id("dev.deftu.gradle.tools.resources") - id("dev.deftu.gradle.tools.bloom") - id("dev.deftu.gradle.tools.shadow") - id("dev.deftu.gradle.tools.minecraft.loom") + id("dev.deftu.gradle.multiversion") // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders. + id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc. + id("dev.deftu.gradle.tools.resources") // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources. + id("dev.deftu.gradle.tools.bloom") // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files. + id("dev.deftu.gradle.tools.shadow") // Applies the Shadow plugin, which allows us to shade our dependencies into our mod JAR. This is NOT recommended for Fabric mods, but we have an *additional* configuration for those! + id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you. + id("dev.deftu.gradle.tools.minecraft.releases") // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth. } val accessTransformerName = "patcher1${mcData.version.minor}_at.cfg" -// Sets up the variables for when we preprocess to other Minecraft versions. -preprocess { - vars.put("MODERN", if (mcData.version.minor >= 16) 1 else 0) -} +toolkitLoomHelper { + useOneConfig { + version = "1.0.0-alpha.49" + loaderVersion = "1.1.0-alpha.35" -//if (project.platform.isLegacyForge) { -// runConfigs { -// "client" { -// property("patcher.debugBytecode", "true") -// property("mixin.debug.verbose", "true") -// property("mixin.debug.export", "true") -// property("mixin.dumpTargetOnFailure", "true") -// property("fml.coreMods.load", "club.sk1er.patcher.tweaker.PatcherTweaker") -// programArgs("--tweakClass", "org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker") -// programArgs("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker") -// property("mixin.debug.export", "true") -// programArgs("--mixin", "mixins.${mod_id}.json") -// } -// } -//} - -//if (project.platform.isForge) { -// forge { -// accessTransformer(rootProject.file("src/main/resources/$accessTransformerName")) -// mixinConfig("mixins.${mod_id}.json") -// } -//} + usePolyMixin = true + polyMixinVersion = "0.8.4+build.2" -toolkitLoomHelper { - useOneConfig("1.1.0-alpha.34", "1.0.0-alpha.43", mcData, "commands", "config-impl", "events", "hud", "internal", "ui") - useDevAuth() + applyLoaderTweaker = true + for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { + +module + } + } + useDevAuth("1.2.1") + useMixinExtras("0.4.1") + + // Turns off the server-side run configs, as we're building a client-sided mod. disableRunConfigs(GameSide.SERVER) + // Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes. if (!mcData.isNeoForge) { useMixinRefMap(modData.id) } - if (mcData.isLegacyForge) { - useTweaker("org.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker", GameSide.CLIENT) - useForgeMixin(modData.id) // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects. + if (mcData.isForge) { + // Configures the Mixin tweaker if we are building for Forge. + useForgeMixin(modData.id) useProperty("patcher.debugBytecode", "true", GameSide.CLIENT) - useProperty("mixin.debug.verbose", "true", GameSide.CLIENT) - useProperty("mixin.debug.export", "true", GameSide.CLIENT) - useProperty("mixin.dumpTargetOnFailure", "true", GameSide.CLIENT) useProperty("fml.coreMods.load", "club.sk1er.patcher.tweaker.PatcherTweaker", GameSide.CLIENT) } } @@ -68,7 +54,7 @@ toolkitLoomHelper { if (mcData.isForge) { loom { forge { - accessTransformer(rootProject.file("src/main/resources/$accessTransformerName")) + accessTransformer(rootProject.file("src/main/resources/META-INF/$accessTransformerName")) } } } @@ -85,34 +71,31 @@ sourceSets { // Configures the libraries/dependencies for your mod. dependencies { - modImplementation(shade("org.polyfrost:elementa-$mcData:562") { + modImplementation(includeOrShade("org.polyfrost:elementa-$mcData:562") { isTransitive = false }) - implementation(shade("com.github.ben-manes.caffeine:caffeine:2.9.3")!!) + implementation(includeOrShade("com.github.ben-manes.caffeine:caffeine:2.9.3")!!) - implementation(shade("com.github.videogame-hacker:Koffee:88ba1b0") { + implementation(includeOrShade("com.github.char:Koffee:88ba1b0") { isTransitive = false }) if (mcData.version.minor < 12) { - implementation(shade("it.unimi.dsi:fastutil:8.5.13")!!) + implementation(includeOrShade("it.unimi.dsi:fastutil:8.5.13")!!) } - - // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier. - if (mcData.isLegacyForge) { - compileOnly("org.polyfrost:polymixin:0.8.4+build.2") - //todo fix with V1 - //modImplementation("org.polyfrost:legacy-crafty-crashes:1.0.0") { - // isTransitive = false - //} + if (mcData.isFabric) { + runtimeOnly("include"(rootProject.project(":fake-mod"))!!) + implementation(includeOrShade("com.github.Chocohead:Fabric-ASM:2.3")!!) } } tasks { compileKotlin { - kotlinOptions { - freeCompilerArgs += listOf("-Xopt-in=kotlin.RequiresOptIn", "-Xno-param-assertions", "-Xjvm-default=all-compatibility") + compilerOptions { + optIn.add("kotlin.RequiresOptIn") + freeCompilerArgs.add("-Xno-param-assertions") + freeCompilerArgs.add("-Xjvm-default=all-compatibility") } } @@ -120,6 +103,8 @@ tasks { // Sets the jar manifest attributes. if (mcData.isLegacyForge) { manifest.attributes += mapOf( + "FMLCorePlugin" to "club.sk1er.patcher.tweaker.PatcherTweaker", + "FMLCorePluginContainsFMLMod" to "Yes, yes it does", "FMLAT" to accessTransformerName, "Main-Class" to "club.sk1er.container.ContainerMessage" ) @@ -127,7 +112,6 @@ tasks { } processResources { - exclude("patcher18_at.cfg") - exclude("patcher112_at.cfg") + exclude("**/*.at.cfg") } } \ No newline at end of file diff --git a/fake-mod/build.gradle.kts b/fake-mod/build.gradle.kts new file mode 100644 index 00000000..5c6a08ac --- /dev/null +++ b/fake-mod/build.gradle.kts @@ -0,0 +1,13 @@ +@file:Suppress("UnstableApiUsage", "PropertyName") + +import dev.deftu.gradle.utils.GameSide + +plugins { + java + id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc. + id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you. +} + +toolkitLoomHelper { + disableRunConfigs(GameSide.BOTH) +} \ No newline at end of file diff --git a/fake-mod/gradle.properties b/fake-mod/gradle.properties new file mode 100644 index 00000000..cb32c317 --- /dev/null +++ b/fake-mod/gradle.properties @@ -0,0 +1,5 @@ +# Configures the mod loader that we're developing for. +loom.platform=fabric +loom.loader.use=false +# Configures the Minecraft version that we're developing for. +minecraft.version=1.8.9 \ No newline at end of file diff --git a/fake-mod/settings.gradle.kts b/fake-mod/settings.gradle.kts new file mode 100644 index 00000000..d7452a29 --- /dev/null +++ b/fake-mod/settings.gradle.kts @@ -0,0 +1,22 @@ +@file:Suppress("PropertyName") + +pluginManagement { + repositories { + // Releases + maven("https://maven.deftu.dev/releases") + maven("https://maven.fabricmc.net") + maven("https://maven.architectury.dev/") + maven("https://maven.minecraftforge.net") + maven("https://repo.essential.gg/repository/maven-public") + maven("https://server.bbkr.space/artifactory/libs-release/") + maven("https://jitpack.io/") + + // Snapshots + maven("https://maven.deftu.dev/snapshots") + mavenLocal() + + // Default + gradlePluginPortal() + mavenCentral() + } +} \ No newline at end of file diff --git a/fake-mod/src/main/resources/fabric.mod.json b/fake-mod/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..6269784b --- /dev/null +++ b/fake-mod/src/main/resources/fabric.mod.json @@ -0,0 +1,21 @@ +{ + "schemaVersion": 1, + "id": "polypatcher", + "name": "PolyPatcher", + "version": "1", + "description": "", + "authors": [ + "Polyfrost" + ], + "contact": { + "homepage": "https://polyfrost.org", + "sources": "https://github.com/Polyfrost/OneConfig", + "issues": "https://inv.wtf/polyfrost" + }, + "environment": "client", + "custom": { + "modmenu": { + "parent": "patcher" + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index b8f15eaf..6ca46411 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,22 +1,17 @@ +# Gradle Configuration -- DO NOT TOUCH THESE VALUES. +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.configureoncommand=true +org.gradle.parallel.threads=4 +org.gradle.jvmargs=-Xmx2G + # gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT. # Sets the name of your mod. mod.name=Patcher -# Sets the id of your mod that mod loaders use to recognize it. +# Sets the ID of your mod that mod loaders use to recognize it. mod.id=patcher -# Sets the version of your mod. -# normal versions will be "1.x.x" -# betas will be "1.x.x+beta-y" / "1.x.x+branch_beta-y" -# rcs will be 1.x.x+rc-y -# extra branches will be 1.x.x+branch-y +# Sets the version of your mod. Make sure to update this when you make changes according to the SemVer specification. mod.version=1.10.1 -# Sets the name of the jar file that you put in your 'mods' folder. -mod.group=club.sk1er - -# Gradle Configuration -- DO NOT TOUCH THESE VALUES. -polyfrost.defaults.loom=3 -org.gradle.daemon=true -org.gradle.parallel=true -org.gradle.configureoncommand=true -org.gradle.parallel.threads=4 -org.gradle.jvmargs=-Xmx2G \ No newline at end of file +# Sets the Maven group ID of your mod. This is effectively unused but is good practice to set regardless. +mod.group=club.sk1er \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9355b415..a4413138 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/root.gradle.kts b/root.gradle.kts index 49b01b5a..8291246d 100644 --- a/root.gradle.kts +++ b/root.gradle.kts @@ -3,7 +3,13 @@ plugins { } preprocess { - strictExtraMappings.set(true) + // Adding new versions/loaders can be done like so: + // For each version, we add a new wrapper around the last from highest to lowest. + // Each mod loader needs to link up to the previous version's mod loader so that the mappings can be processed from the previous version. + // "1.12.2-forge"(11202, "srg") { + // "1.8.9-forge"(10809, "srg") + // } + "1.12.2-forge"(11202, "srg") { "1.12.2-fabric"(11202, "yarn") { "1.8.9-fabric"(10809, "yarn", file("versions/1.12.2-1.8.9.txt")) { @@ -11,4 +17,6 @@ preprocess { } } } + + strictExtraMappings.set(true) } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index f3d0f3f0..ce11030a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,8 +1,10 @@ +@file:Suppress("PropertyName") + import groovy.lang.MissingPropertyException pluginManagement { repositories { - // Repositories + // Releases maven("https://maven.deftu.dev/releases") maven("https://maven.fabricmc.net") maven("https://maven.architectury.dev/") @@ -15,23 +17,30 @@ pluginManagement { maven("https://maven.deftu.dev/snapshots") mavenLocal() - // Default repositories + // Default gradlePluginPortal() mavenCentral() } plugins { kotlin("jvm") version("2.0.0") - id("dev.deftu.gradle.multiversion-root") version("2.13.0") + id("dev.deftu.gradle.multiversion-root") version("2.17.0") } } val projectName: String = extra["mod.name"]?.toString() ?: throw MissingPropertyException("mod.name has not been set.") + +// Configures the root project Gradle name based on the value in `gradle.properties` rootProject.name = projectName rootProject.buildFileName = "root.gradle.kts" +include(":fake-mod") + // Adds all of our build target versions to the classpath if we need to add version-specific code. +// Update this list if you want to remove/add a version and/or mod loader. +// The format is: version-modloader (f.ex: 1.8.9-forge, 1.17.1-fabric, etc) +// **REMEMBER TO ALSO UPDATE THE `root.gradle.kts` FILE WITH THE NEW VERSION(S). listOf( "1.8.9-forge", "1.8.9-fabric", diff --git a/src/main/java/club/sk1er/patcher/Patcher.java b/src/main/java/club/sk1er/patcher/Patcher.java index eda50a1c..b098541c 100644 --- a/src/main/java/club/sk1er/patcher/Patcher.java +++ b/src/main/java/club/sk1er/patcher/Patcher.java @@ -1,5 +1,6 @@ package club.sk1er.patcher; +import club.sk1er.patcher.tweaker.TweakerHooks; import org.polyfrost.oneconfig.api.ui.v1.Notifications; import org.polyfrost.oneconfig.utils.v1.JsonUtils; import org.polyfrost.polyui.unit.Units; @@ -21,7 +22,6 @@ import club.sk1er.patcher.screen.render.overlay.ImagePreview; import club.sk1er.patcher.screen.render.overlay.metrics.MetricsRenderer; import club.sk1er.patcher.screen.render.title.TitleFix; -import club.sk1er.patcher.tweaker.PatcherTweaker; import club.sk1er.patcher.util.chat.ChatHandler; import club.sk1er.patcher.util.enhancement.EnhancementManager; import club.sk1er.patcher.util.enhancement.ReloadListener; @@ -64,17 +64,19 @@ import java.util.*; import java.util.stream.Collectors; +//#if FORGE @Mod(modid = "@MOD_ID@", name = "@MOD_NAME@", version = Patcher.VERSION, clientSideOnly = true) -public class Patcher { +//#endif +public class Patcher + //#if FABRIC + //$$ implements net.fabricmc.api.ClientModInitializer + //#endif +{ @Mod.Instance("patcher") public static Patcher instance; - // normal versions will be "1.x.x" - // betas will be "1.x.x+beta-y" / "1.x.x+branch_beta-y" - // rcs will be 1.x.x+rc-y - // extra branches will be 1.x.x+branch-y - public static final String VERSION = "@VER@"; + public static final String VERSION = "@MOD_VERSION@"; private static final Logger logger = LogManager.getLogger("Patcher"); private final File logsDirectory = new File(Minecraft.getMinecraft().mcDataDir + File.separator + "logs" + File.separator); @@ -161,7 +163,7 @@ public void onLoadComplete(FMLLoadCompleteEvent event) { this.detectIncompatibilities(activeModList); this.detectReplacements(activeModList); - long time = (System.currentTimeMillis() - PatcherTweaker.clientLoadTime); + long time = (System.currentTimeMillis() - TweakerHooks.clientLoadTime); if (PatcherConfig.startupNotification) { Notifications.enqueue(Notifications.Type.Info, "Minecraft Startup", "Minecraft started in " + (time / 1000L) + " seconds."); } diff --git a/src/main/java/club/sk1er/patcher/PolyPatcher.java b/src/main/java/club/sk1er/patcher/PolyPatcher.java index 06e1a9aa..27f974ab 100644 --- a/src/main/java/club/sk1er/patcher/PolyPatcher.java +++ b/src/main/java/club/sk1er/patcher/PolyPatcher.java @@ -1,12 +1,18 @@ package club.sk1er.patcher; +//#if FORGE import com.google.common.eventbus.EventBus; import net.minecraftforge.fml.common.DummyModContainer; import net.minecraftforge.fml.common.LoadController; import net.minecraftforge.fml.common.ModMetadata; +//#endif -public class PolyPatcher extends DummyModContainer { - +public class PolyPatcher + //#if FORGE + extends DummyModContainer + //#endif +{ + //#if FORGE public PolyPatcher() { super(new ModMetadata()); ModMetadata meta = getMetadata(); @@ -25,4 +31,5 @@ public PolyPatcher() { public boolean registerBus(EventBus bus, LoadController controller) { return true; } + //#endif } diff --git a/src/main/java/club/sk1er/patcher/asm/external/mods/optifine/EntityRendererTransformer.java b/src/main/java/club/sk1er/patcher/asm/external/mods/optifine/EntityRendererTransformer.java index 982a49de..a56f9df5 100644 --- a/src/main/java/club/sk1er/patcher/asm/external/mods/optifine/EntityRendererTransformer.java +++ b/src/main/java/club/sk1er/patcher/asm/external/mods/optifine/EntityRendererTransformer.java @@ -2,9 +2,9 @@ import club.sk1er.patcher.tweaker.ClassTransformer; import club.sk1er.patcher.tweaker.transform.PatcherTransformer; -import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; +import org.polyfrost.oneconfig.api.platform.v1.DeobfuscationRemapper; import java.util.ListIterator; @@ -59,7 +59,7 @@ public void transform(ClassNode classNode, String name) { switch (ClassTransformer.optifineVersion) { case "I7": { if (next instanceof TypeInsnNode) { - if (FMLDeobfuscatingRemapper.INSTANCE.map(((TypeInsnNode) next).desc).equals("net/minecraft/client/renderer/culling/Frustum")) { + if (DeobfuscationRemapper.INSTANCE.map(((TypeInsnNode) next).desc).equals("net/minecraft/client/renderer/culling/Frustum")) { while (true) { final AbstractInsnNode insn = iterator.next(); if (insn instanceof VarInsnNode) { diff --git a/src/main/java/club/sk1er/patcher/config/PatcherConfig.java b/src/main/java/club/sk1er/patcher/config/PatcherConfig.java index 3ccc8f04..3a9cc55c 100644 --- a/src/main/java/club/sk1er/patcher/config/PatcherConfig.java +++ b/src/main/java/club/sk1er/patcher/config/PatcherConfig.java @@ -1,6 +1,7 @@ package club.sk1er.patcher.config; //#if FORGE +import club.sk1er.patcher.util.forge.EntrypointCaching; import net.minecraftforge.common.ForgeVersion; //#endif @@ -1333,13 +1334,13 @@ public static int getInventoryScale() { public static boolean cacheEntrypoints = true; //todo this serializes for some reason? - //@Button( - // title = "Reset Cache", - // description = "Reset the cache of Forge mod entry points.", - // category = "Experimental", subcategory = "Forge", - // text = "Reset" - //) - //public static Runnable resetCache = () -> EntrypointCaching.INSTANCE.resetCache(); + @Button( + title = "Reset Cache", + description = "Reset the cache of Forge mod entry points.", + category = "Experimental", subcategory = "Forge", + text = "Reset" + ) + public static Runnable resetCache = () -> EntrypointCaching.INSTANCE.resetCache(); //@Info( // text = "Improved Skin Rendering can make some skins invisible. It requires a restart once toggled.", diff --git a/src/main/java/club/sk1er/patcher/mixins/bugfixes/RenderGlobalMixin_RenderOobEntities.java b/src/main/java/club/sk1er/patcher/mixins/bugfixes/RenderGlobalMixin_RenderOobEntities.java index 1900acd8..d2838101 100644 --- a/src/main/java/club/sk1er/patcher/mixins/bugfixes/RenderGlobalMixin_RenderOobEntities.java +++ b/src/main/java/club/sk1er/patcher/mixins/bugfixes/RenderGlobalMixin_RenderOobEntities.java @@ -6,7 +6,7 @@ import net.minecraft.entity.Entity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; -import org.spongepowered.asm.lib.Opcodes; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; diff --git a/src/main/java/club/sk1er/patcher/mixins/features/ScreenShotHelperMixin_ScreenshotManager.java b/src/main/java/club/sk1er/patcher/mixins/features/ScreenShotHelperMixin_ScreenshotManager.java index e8c2bcb1..69e03a72 100644 --- a/src/main/java/club/sk1er/patcher/mixins/features/ScreenShotHelperMixin_ScreenshotManager.java +++ b/src/main/java/club/sk1er/patcher/mixins/features/ScreenShotHelperMixin_ScreenshotManager.java @@ -47,24 +47,24 @@ public class ScreenShotHelperMixin_ScreenshotManager { int scale = width * height; - if (this.pixelBuffer == null || this.pixelBuffer.capacity() < scale) { - this.pixelBuffer = BufferUtils.createIntBuffer(scale); - this.pixelValues = new int[scale]; + if (ScreenShotHelperMixin_ScreenshotManager.pixelBuffer == null || ScreenShotHelperMixin_ScreenshotManager.pixelBuffer.capacity() < scale) { + ScreenShotHelperMixin_ScreenshotManager.pixelBuffer = BufferUtils.createIntBuffer(scale); + ScreenShotHelperMixin_ScreenshotManager.pixelValues = new int[scale]; } GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); - this.pixelBuffer.clear(); + ScreenShotHelperMixin_ScreenshotManager.pixelBuffer.clear(); if (OpenGlHelper.isFramebufferEnabled()) { GlStateManager.bindTexture(buffer.framebufferTexture); - GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, this.pixelBuffer); + GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, ScreenShotHelperMixin_ScreenshotManager.pixelBuffer); } else { - GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, this.pixelBuffer); + GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, ScreenShotHelperMixin_ScreenshotManager.pixelBuffer); } - this.pixelBuffer.get(this.pixelValues); - Multithreading.submit(new AsyncScreenshots(width, height, this.pixelValues, screenshotDirectory)); + ScreenShotHelperMixin_ScreenshotManager.pixelBuffer.get(ScreenShotHelperMixin_ScreenshotManager.pixelValues); + Multithreading.submit(new AsyncScreenshots(width, height, ScreenShotHelperMixin_ScreenshotManager.pixelValues, screenshotDirectory)); EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; if (player != null && !PatcherConfig.screenshotNoFeedback) { diff --git a/src/main/java/club/sk1er/patcher/mixins/performance/EnumFacingMixin_ReduceAllocations.java b/src/main/java/club/sk1er/patcher/mixins/performance/EnumFacingMixin_ReduceAllocations.java index 7ecd2879..697a8098 100644 --- a/src/main/java/club/sk1er/patcher/mixins/performance/EnumFacingMixin_ReduceAllocations.java +++ b/src/main/java/club/sk1er/patcher/mixins/performance/EnumFacingMixin_ReduceAllocations.java @@ -80,6 +80,6 @@ public EnumFacing getOpposite() { */ @Overwrite public static EnumFacing random(Random rand) { - return this.VALUES[rand.nextInt(this.VALUES.length)]; + return EnumFacingMixin_ReduceAllocations.VALUES[rand.nextInt(EnumFacingMixin_ReduceAllocations.VALUES.length)]; } } diff --git a/src/main/java/club/sk1er/patcher/mixins/performance/WorldMixin_TileEntityUnload.java b/src/main/java/club/sk1er/patcher/mixins/performance/WorldMixin_TileEntityUnload.java index b58c535a..e492336f 100644 --- a/src/main/java/club/sk1er/patcher/mixins/performance/WorldMixin_TileEntityUnload.java +++ b/src/main/java/club/sk1er/patcher/mixins/performance/WorldMixin_TileEntityUnload.java @@ -8,7 +8,7 @@ //#endif import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; -import org.spongepowered.asm.lib.Opcodes; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/src/main/java/club/sk1er/patcher/mixins/plugin/PatcherMixinPlugin.java b/src/main/java/club/sk1er/patcher/mixins/plugin/PatcherMixinPlugin.java index a48512ab..73a9aacf 100644 --- a/src/main/java/club/sk1er/patcher/mixins/plugin/PatcherMixinPlugin.java +++ b/src/main/java/club/sk1er/patcher/mixins/plugin/PatcherMixinPlugin.java @@ -1,7 +1,6 @@ package club.sk1er.patcher.mixins.plugin; import club.sk1er.patcher.tweaker.ClassTransformer; -import club.sk1er.patcher.tweaker.transform.PatcherTransformer; import com.google.common.collect.ArrayListMultimap; import kotlin.text.StringsKt; import org.objectweb.asm.tree.ClassNode; @@ -9,7 +8,6 @@ import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; -import java.util.Collection; import java.util.List; import java.util.Set; @@ -21,8 +19,6 @@ public class PatcherMixinPlugin implements IMixinConfigPlugin { private static final ArrayListMultimap CONFLICTING_CLASSES = ArrayListMultimap.create(); private static boolean isEarsMod = false; - private final ClassTransformer transformer; - static { MixinEnvironment.getDefaultEnvironment().addTransformerExclusion("com.unascribed.ears.asm.PlatformTransformerAdapter"); CONFLICTING_CLASSES.put("GuiContainerMixin_MouseBindFixThatLabyBreaks", LABYMOD_CLASS); @@ -30,10 +26,6 @@ public class PatcherMixinPlugin implements IMixinConfigPlugin { CONFLICTING_CLASSES.put("MathHelperMixin_CompactLUT", OF_CONFIG_CLASS); } - public PatcherMixinPlugin() { - this.transformer = new ClassTransformer(); - } - @Override public void onLoad(String mixinPackage) { try { @@ -79,12 +71,7 @@ public List getMixins() { @Override public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - Collection transformers = this.transformer.transformerMap.get(targetClassName); - if (transformers != null) { - for (PatcherTransformer patcherTransformer : transformers) { - patcherTransformer.transform(targetClass, targetClassName); - } - } + } @Override diff --git a/src/main/java/club/sk1er/patcher/tweaker/ClassTransformer.java b/src/main/java/club/sk1er/patcher/tweaker/ClassTransformer.java index 79d3fb35..9736b465 100644 --- a/src/main/java/club/sk1er/patcher/tweaker/ClassTransformer.java +++ b/src/main/java/club/sk1er/patcher/tweaker/ClassTransformer.java @@ -72,15 +72,17 @@ import java.util.Set; public class ClassTransformer + implements //#if FORGE - implements IClassTransformer + IClassTransformer, //#endif + club.sk1er.patcher.tweaker.transform.IClassTransformer { public static final boolean outputBytecode = "true".equals(System.getProperty("patcher.debugBytecode", "false")); public static String optifineVersion = "NONE"; private final Logger logger = LogManager.getLogger("Patcher - Class Transformer"); - public final Multimap transformerMap = ArrayListMultimap.create(); + private final Multimap transformerMap = ArrayListMultimap.create(); public static boolean smoothFontDetected; public static final Set supportedOptiFineVersions = new HashSet<>(); @@ -143,7 +145,7 @@ public ClassTransformer() { if (isDevelopment()) registerTransformer(new InventoryEffectRendererTransformer()); // forge classes - //#if MC == 1.8.9 + //#if MC == 1.8.9 && FORGE registerTransformer(new ForgeHooksClientTransformer()); registerTransformer(new GuiModListTransformer()); registerTransformer(new ModClassLoaderTransformer()); @@ -223,10 +225,10 @@ private void registerTransformer(PatcherTransformer transformer) { //#if FORGE @Override - //#endif public byte[] transform(String name, String transformedName, byte[] bytes) { return createTransformer(transformedName, bytes, transformerMap, logger); } + //#endif private void haltForOptiFine(String message) { try { @@ -260,13 +262,13 @@ public void mouseClicked(MouseEvent e) { close.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - PatcherTweaker.invokeExit(); + TweakerHooks.invokeExit(); } }); Object[] options = {openOptifine, close}; JOptionPane.showOptionDialog(frame, message, "Launch Aborted", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); - PatcherTweaker.invokeExit(); + TweakerHooks.invokeExit(); } private void fetchSupportedOptiFineVersions() { @@ -329,7 +331,16 @@ private void updateOptiFineGenerations() { } public static boolean isDevelopment() { + //#if FORGE Object o = Launch.blackboard.get("fml.deobfuscatedEnvironment"); return o != null && (boolean) o; + //#else + //$$ return net.fabricmc.loader.api.FabricLoader.getInstance().isDevelopmentEnvironment(); + //#endif + } + + @Override + public Multimap getTransformerMap() { + return transformerMap; } } diff --git a/src/main/java/club/sk1er/patcher/tweaker/PatcherTweaker.java b/src/main/java/club/sk1er/patcher/tweaker/PatcherTweaker.java index c0822a66..f057b321 100644 --- a/src/main/java/club/sk1er/patcher/tweaker/PatcherTweaker.java +++ b/src/main/java/club/sk1er/patcher/tweaker/PatcherTweaker.java @@ -1,5 +1,6 @@ package club.sk1er.patcher.tweaker; +//#if FORGE import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.stream.MalformedJsonException; @@ -34,11 +35,9 @@ @IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion) public class PatcherTweaker implements IFMLLoadingPlugin { - public static long clientLoadTime; - @SuppressWarnings("unchecked") public PatcherTweaker() { - clientLoadTime = System.currentTimeMillis(); + TweakerHooks.clientLoadTime = System.currentTimeMillis(); try { // Create a second internal tweaker, creating after OptiFine does its thing. FMLLaunchHandler launchHandler = ReflectionHelper.getPrivateValue(FMLLaunchHandler.class, null, "INSTANCE"); @@ -214,3 +213,4 @@ static void invokeExit() { } } } +//#endif diff --git a/src/main/java/club/sk1er/patcher/tweaker/TweakerHooks.java b/src/main/java/club/sk1er/patcher/tweaker/TweakerHooks.java new file mode 100644 index 00000000..fe321ab3 --- /dev/null +++ b/src/main/java/club/sk1er/patcher/tweaker/TweakerHooks.java @@ -0,0 +1,19 @@ +package club.sk1er.patcher.tweaker; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class TweakerHooks { + public static long clientLoadTime; + + static void invokeExit() { + try { + final Class aClass = Class.forName("java.lang.Shutdown"); + final Method exit = aClass.getDeclaredMethod("exit", int.class); + exit.setAccessible(true); + exit.invoke(null, 0); + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/club/sk1er/patcher/tweaker/other/ModClassTransformer.java b/src/main/java/club/sk1er/patcher/tweaker/other/ModClassTransformer.java index 7280be4b..71bf2d10 100644 --- a/src/main/java/club/sk1er/patcher/tweaker/other/ModClassTransformer.java +++ b/src/main/java/club/sk1er/patcher/tweaker/other/ModClassTransformer.java @@ -1,5 +1,10 @@ package club.sk1er.patcher.tweaker.other; +//#if FORGE +import net.minecraft.launchwrapper.IClassTransformer; +import net.minecraft.launchwrapper.Launch; +//#endif + import club.sk1er.patcher.asm.external.mods.essential.EssentialModelRendererTransformer; import club.sk1er.patcher.asm.external.mods.optifine.*; import club.sk1er.patcher.asm.external.mods.optifine.reflectionoptimizations.common.BakedQuadReflectionOptimizer; @@ -25,8 +30,6 @@ import club.sk1er.patcher.tweaker.transform.PatcherTransformer; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import net.minecraft.launchwrapper.IClassTransformer; -import net.minecraft.launchwrapper.Launch; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.MixinEnvironment; @@ -34,7 +37,13 @@ /** * Used for editing other mods (OptiFine, LevelHead, TNT Timer, etc.) after they've loaded. */ -public class ModClassTransformer implements IClassTransformer { +public class ModClassTransformer + implements + //#if FORGE + IClassTransformer, + //#endif + club.sk1er.patcher.tweaker.transform.IClassTransformer +{ private final Logger logger = LogManager.getLogger("Patcher - Mod Class Transformer"); private final Multimap transformerMap = ArrayListMultimap.create(); @@ -133,7 +142,16 @@ private void registerLSeriesFixesTransformers() { } public static boolean isDevelopment() { + //#if FORGE Object o = Launch.blackboard.get("fml.deobfuscatedEnvironment"); return o != null && (boolean) o; + //#else + //$$ return net.fabricmc.loader.api.FabricLoader.getInstance().isDevelopmentEnvironment(); + //#endif + } + + @Override + public Multimap getTransformerMap() { + return transformerMap; } } diff --git a/src/main/java/club/sk1er/patcher/tweaker/other/ModTweaker.java b/src/main/java/club/sk1er/patcher/tweaker/other/ModTweaker.java index 7526a3fd..78bb3238 100644 --- a/src/main/java/club/sk1er/patcher/tweaker/other/ModTweaker.java +++ b/src/main/java/club/sk1er/patcher/tweaker/other/ModTweaker.java @@ -1,5 +1,6 @@ package club.sk1er.patcher.tweaker.other; +//#if FORGE import net.minecraftforge.common.ForgeVersion; import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; @@ -34,3 +35,4 @@ public String getAccessTransformerClass() { return null; } } +//#endif diff --git a/src/main/java/club/sk1er/patcher/tweaker/transform/IClassTransformer.java b/src/main/java/club/sk1er/patcher/tweaker/transform/IClassTransformer.java new file mode 100644 index 00000000..f29b1574 --- /dev/null +++ b/src/main/java/club/sk1er/patcher/tweaker/transform/IClassTransformer.java @@ -0,0 +1,7 @@ +package club.sk1er.patcher.tweaker.transform; + +import com.google.common.collect.Multimap; + +public interface IClassTransformer { + Multimap getTransformerMap(); +} diff --git a/src/main/java/club/sk1er/patcher/tweaker/transform/PatcherTransformer.java b/src/main/java/club/sk1er/patcher/tweaker/transform/PatcherTransformer.java index 7fcc3cc5..fe2d852a 100644 --- a/src/main/java/club/sk1er/patcher/tweaker/transform/PatcherTransformer.java +++ b/src/main/java/club/sk1er/patcher/tweaker/transform/PatcherTransformer.java @@ -1,7 +1,8 @@ package club.sk1er.patcher.tweaker.transform; +//#if FORGE import net.minecraft.launchwrapper.Launch; -import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper; +//#endif import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; @@ -9,6 +10,7 @@ import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; +import org.polyfrost.oneconfig.api.platform.v1.DeobfuscationRemapper; public interface PatcherTransformer { @@ -34,7 +36,7 @@ public interface PatcherTransformer { * @return a mapped method name */ default String mapMethodName(ClassNode classNode, MethodNode methodNode) { - return FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(classNode.name, methodNode.name, methodNode.desc); + return DeobfuscationRemapper.INSTANCE.mapMethodName(classNode.name, methodNode.name, methodNode.desc); } /** @@ -45,7 +47,7 @@ default String mapMethodName(ClassNode classNode, MethodNode methodNode) { * @return a mapped field name */ default String mapFieldName(ClassNode classNode, FieldNode fieldNode) { - return FMLDeobfuscatingRemapper.INSTANCE.mapFieldName(classNode.name, fieldNode.name, fieldNode.desc); + return DeobfuscationRemapper.INSTANCE.mapFieldName(classNode.name, fieldNode.name, fieldNode.desc); } /** @@ -55,7 +57,7 @@ default String mapFieldName(ClassNode classNode, FieldNode fieldNode) { * @return a deobfuscated name of the class */ default String mapClassName(String className) { - return FMLDeobfuscatingRemapper.INSTANCE.map(className); + return DeobfuscationRemapper.INSTANCE.map(className); } /** @@ -65,7 +67,7 @@ default String mapClassName(String className) { * @return a mapped method desc */ default String mapMethodDesc(MethodNode methodNode) { - return FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(methodNode.desc); + return DeobfuscationRemapper.INSTANCE.mapMethodDesc(methodNode.desc); } /** @@ -76,7 +78,7 @@ default String mapMethodDesc(MethodNode methodNode) { */ default String mapMethodNameFromNode(AbstractInsnNode node) { MethodInsnNode methodInsnNode = (MethodInsnNode) node; - return FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(methodInsnNode.owner, methodInsnNode.name, methodInsnNode.desc); + return DeobfuscationRemapper.INSTANCE.mapMethodName(methodInsnNode.owner, methodInsnNode.name, methodInsnNode.desc); } /** @@ -87,12 +89,12 @@ default String mapMethodNameFromNode(AbstractInsnNode node) { */ default String mapFieldNameFromNode(AbstractInsnNode node) { FieldInsnNode fieldInsnNode = (FieldInsnNode) node; - return FMLDeobfuscatingRemapper.INSTANCE.mapFieldName(fieldInsnNode.owner, fieldInsnNode.name, fieldInsnNode.desc); + return DeobfuscationRemapper.INSTANCE.mapFieldName(fieldInsnNode.owner, fieldInsnNode.name, fieldInsnNode.desc); } default String mapMethodDescFromNode(AbstractInsnNode node) { MethodInsnNode methodInsnNode = (MethodInsnNode) node; - return FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(methodInsnNode.desc); + return DeobfuscationRemapper.INSTANCE.mapMethodDesc(methodInsnNode.desc); } /** @@ -115,7 +117,11 @@ default String getHookClass(String name) { } default boolean isDevelopment() { + //#if FORGE Object o = Launch.blackboard.get("fml.deobfuscatedEnvironment"); return o != null && (boolean) o; + //#else + //$$ return net.fabricmc.loader.api.FabricLoader.getInstance().isDevelopmentEnvironment(); + //#endif } } diff --git a/src/main/resources/patcher112_at.cfg b/src/main/resources/META-INF/patcher112_at.cfg similarity index 100% rename from src/main/resources/patcher112_at.cfg rename to src/main/resources/META-INF/patcher112_at.cfg diff --git a/src/main/resources/patcher18_at.cfg b/src/main/resources/META-INF/patcher18_at.cfg similarity index 100% rename from src/main/resources/patcher18_at.cfg rename to src/main/resources/META-INF/patcher18_at.cfg diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..40827969 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,31 @@ +{ + "schemaVersion": 1, + "id": "${mod_id}", + "version": "${mod_version}", + "name": "${mod_name}", + "description": "${mod_description}", + "authors": [ + "Sk1erLLC", + "Polyfrost" + ], + "environment": "client", + "entrypoints": { + "client": [ + { + "value": "club.sk1er.patcher.Patcher" + } + ], + "mm:early_risers": [ + { + "value": "club.sk1er.patcher.tweaker.EarlyRiser" + } + ] + }, + "mixins": [ + "mixins.${mod_id}.json" + ], + "depends": { + "minecraft": "~${minor_mc_version}", + "fabricloader": ">=0.15.11" + } +} \ No newline at end of file diff --git a/versions/1.8.9-fabric/src/main/java/club/sk1er/patcher/tweaker/EarlyRiser.java b/versions/1.8.9-fabric/src/main/java/club/sk1er/patcher/tweaker/EarlyRiser.java new file mode 100644 index 00000000..3a2ae84e --- /dev/null +++ b/versions/1.8.9-fabric/src/main/java/club/sk1er/patcher/tweaker/EarlyRiser.java @@ -0,0 +1,28 @@ +package club.sk1er.patcher.tweaker; +//#if FABRIC + +import club.sk1er.patcher.tweaker.other.ModClassTransformer; +import club.sk1er.patcher.tweaker.transform.IClassTransformer; +import club.sk1er.patcher.tweaker.transform.PatcherTransformer; +import com.chocohead.mm.api.ClassTinkerers; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * straight up tweaking rn + */ +public class EarlyRiser implements Runnable { + @Override + public void run() { + TweakerHooks.clientLoadTime = System.currentTimeMillis(); + List transformers = Arrays.asList(new ClassTransformer(), new ModClassTransformer()); + for (IClassTransformer transformer : transformers) { + for (Map.Entry target : transformer.getTransformerMap().entries()) { + ClassTinkerers.addTransformation(target.getKey(), (bytes) -> target.getValue().transform(bytes, target.getKey())); + } + } + } +} +//#endif