From c64cdde4b00961b523a2f0e9bc04aba80c6fb34d Mon Sep 17 00:00:00 2001 From: KoblizekXD Date: Fri, 22 Sep 2023 07:13:16 +0200 Subject: [PATCH 1/6] feat: added partial support for custom mappings(any version url) Took 25 minutes --- .../lol/koblizek/torch/plugin/MinecraftDevelopment.kt | 5 +++++ src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt | 8 ++++++++ .../koblizek/torch/plugin/tasks/DownloadMappingsTask.kt | 8 ++++++++ .../torch/plugin/tasks/evaluated/DecompileTask.kt | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/MinecraftDevelopment.kt b/src/main/kotlin/lol/koblizek/torch/plugin/MinecraftDevelopment.kt index e996bbb..efeefd9 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/MinecraftDevelopment.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/MinecraftDevelopment.kt @@ -5,4 +5,9 @@ class MinecraftDevelopment { * if project should be decompiled */ var decompile: Boolean = false + lateinit var mappings: String + + fun useCustomMappings(): Boolean { + return ::mappings.isInitialized + } } \ No newline at end of file diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt b/src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt index 985f375..ad683ee 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt @@ -16,6 +16,7 @@ class ModProject { lateinit var minecraft: String lateinit var mappings: String lateinit var minecraftDevelopment: MinecraftDevelopment + var side: String = "any" /** * Specifies the development of game api, @@ -36,5 +37,12 @@ class ModProject { * @return true if are mappings field inside `minecraft` block used */ private fun areMappingsInitialized(): Boolean = ::mappings.isInitialized + + private fun useSide(): Boolean = side != "any" + + fun getSideOrDefault(): String { + if (useSide()) return side + else return "mappings/mappings.tiny" + } fun fieldsInitialized(): Boolean = isMinecraftInitialized() && areMappingsInitialized() } \ No newline at end of file diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadMappingsTask.kt b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadMappingsTask.kt index 72b840c..322ee1d 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadMappingsTask.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadMappingsTask.kt @@ -31,6 +31,14 @@ abstract class DownloadMappingsTask : DefaultTask() { zipFile.getInputStream(zipFile.getEntry("mappings/mappings.tiny")), file ) + } else if (ModProject.modProjectInstance.minecraftDevelopment.useCustomMappings()) { + val mappingFile = Download(ModProject.modProjectInstance.minecraftDevelopment.mappings, "mappings-jar.jar").file + val zipFile = ZipFile(mappingFile) + val file = Download.getFile("mappings.tiny", true, this) + FileUtils.copyInputStreamToFile( + zipFile.getInputStream(zipFile.getEntry(ModProject.modProjectInstance.getSideOrDefault())), + file + ) } } diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/evaluated/DecompileTask.kt b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/evaluated/DecompileTask.kt index d85005c..04ff93a 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/evaluated/DecompileTask.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/evaluated/DecompileTask.kt @@ -65,7 +65,7 @@ class DecompileTask : EvaluatedTask() { val main = project.file("src/main/java/") main.listFiles()?.forEach { - if (!(it.name == "com" || it.name == "net")) + if (!(it.name == "com" || it.name == "net" || it.name.endsWith(".java"))) FileUtils.moveToDirectory(it, resources, true) } } From b03086f7df4d98bc9172b99d41e6ce895fc41e66 Mon Sep 17 00:00:00 2001 From: KoblizekXD Date: Sat, 23 Sep 2023 13:25:45 +0200 Subject: [PATCH 2/6] feat: semi-working version for custom inputs Took 9 minutes --- src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt | 4 +++- .../lol/koblizek/torch/plugin/tasks/DownloadJsonTask.kt | 4 +++- .../lol/koblizek/torch/plugin/tasks/DownloadMinecraftTask.kt | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt b/src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt index ad683ee..7137251 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt @@ -16,6 +16,7 @@ class ModProject { lateinit var minecraft: String lateinit var mappings: String lateinit var minecraftDevelopment: MinecraftDevelopment + lateinit var customManifest: String var side: String = "any" /** @@ -38,7 +39,8 @@ class ModProject { */ private fun areMappingsInitialized(): Boolean = ::mappings.isInitialized - private fun useSide(): Boolean = side != "any" + fun useSide(): Boolean = side != "any" + fun useCustomManifest(): Boolean = ::customManifest.isInitialized fun getSideOrDefault(): String { if (useSide()) return side diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadJsonTask.kt b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadJsonTask.kt index 2b5f546..faf4480 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadJsonTask.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadJsonTask.kt @@ -21,7 +21,9 @@ abstract class DownloadJsonTask : DefaultTask() { val version = manifest.findByVersion(ModProject.modProjectInstance.minecraft) ?: throw RuntimeException("Specified Minecraft version(${ModProject.modProjectInstance.minecraft}) doesn't exist") println("Downloading Minecraft source JSON") - Download(version.url, "minecraft-data.json", true, this) + if (ModProject.modProjectInstance.useCustomManifest()) + Download(ModProject.modProjectInstance.customManifest, "minecraft-data.json", true, this) + else Download(version.url, "minecraft-data.json", true, this) println("Finished source JSON download") } } \ No newline at end of file diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadMinecraftTask.kt b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadMinecraftTask.kt index f3270a3..201ce68 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadMinecraftTask.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/DownloadMinecraftTask.kt @@ -2,6 +2,7 @@ package lol.koblizek.torch.plugin.tasks import com.google.gson.Gson import com.google.gson.JsonObject +import lol.koblizek.torch.plugin.ModProject import lol.koblizek.torch.plugin.TorchLoaderPlugin import lol.koblizek.torch.plugin.util.Download import org.gradle.api.DefaultTask @@ -21,7 +22,7 @@ abstract class DownloadMinecraftTask : DefaultTask() { val file = File(TorchLoaderPlugin.downloadJsonTask.temporaryDir, "minecraft-data.json") val json = Gson().fromJson(file.readText(), JsonObject::class.java) val clientUrl = json.getAsJsonObject("downloads") - .getAsJsonObject("client") + .getAsJsonObject(if (ModProject.modProjectInstance.useSide()) ModProject.modProjectInstance.side else "client") .getAsJsonPrimitive("url").asString Download(clientUrl, "minecraft.jar", true, this) val gameArgs = FileWriter(File(temporaryDir, "args.json")) From 327ab76bddcf590f797806056a480bbe8248c4f6 Mon Sep 17 00:00:00 2001 From: KoblizekXD Date: Sat, 23 Sep 2023 14:02:11 +0200 Subject: [PATCH 3/6] feat: support for patches Took 32 minutes --- build.gradle.kts | 3 ++ .../torch/plugin/TorchLoaderPlugin.kt | 2 ++ .../torch/plugin/tasks/ApplyPatchTask.kt | 28 ++++++++++++++++++ .../torch/plugin/tasks/GenPatchTask.kt | 29 +++++++++++++++++++ .../plugin/tasks/evaluated/DecompileTask.kt | 5 ++++ 5 files changed, 67 insertions(+) create mode 100644 src/main/kotlin/lol/koblizek/torch/plugin/tasks/ApplyPatchTask.kt create mode 100644 src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt diff --git a/build.gradle.kts b/build.gradle.kts index 36215a5..a7f500f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,9 +18,12 @@ repositories { name = "neoforgedReleases" url = uri("https://maven.neoforged.net/releases") } + maven { url = uri("https://jitpack.io") } + maven { url = uri("https://nexus.velocitypowered.com/repository/maven-public/") } } dependencies { + implementation("com.github.MCPHackers:DiffPatch:cde1224") implementation("net.neoforged:AutoRenamingTool:1.0.7") implementation("org.vineflower:vineflower:1.9.2") implementation("net.fabricmc:tiny-remapper:0.8.7") diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/TorchLoaderPlugin.kt b/src/main/kotlin/lol/koblizek/torch/plugin/TorchLoaderPlugin.kt index 3d8f185..6e09340 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/TorchLoaderPlugin.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/TorchLoaderPlugin.kt @@ -34,6 +34,8 @@ class TorchLoaderPlugin : Plugin { downloadJsonTask = project.tasks.create("downloadJson", DownloadJsonTask::class.java) downloadMinecraftTask = project.tasks.create("downloadMinecraft", DownloadMinecraftTask::class.java) downloadMappingsTask = project.tasks.create("downloadMappings", DownloadMappingsTask::class.java) + project.tasks.create("genPatch", GenPatchTask::class.java) + project.tasks.create("applyPatch", ApplyPatchTask::class.java) project.tasks.withType(JavaCompile::class.java) { it.options.encoding = "UTF-8" diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/ApplyPatchTask.kt b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/ApplyPatchTask.kt new file mode 100644 index 0000000..a8d1a47 --- /dev/null +++ b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/ApplyPatchTask.kt @@ -0,0 +1,28 @@ +package lol.koblizek.torch.plugin.tasks + +import codechicken.diffpatch.PatchOperation +import codechicken.diffpatch.util.PatchMode +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.TaskAction + + +abstract class ApplyPatchTask : DefaultTask() { + init { + group = "torch" + description = "applies patches from origin/ directory to source" + } + + @TaskAction + fun apply() { + val patchDir = project.file("patches/") + val base = project.file("src/main/java/") + val patchOperation = PatchOperation.builder() + .basePath(base.toPath()) + .patchesPath(patchDir.toPath()) + .outputPath(base.toPath()) + .mode(PatchMode.OFFSET) + .build() + val status = patchOperation.doPatch() + println("Patch status: $status") + } +} \ No newline at end of file diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt new file mode 100644 index 0000000..b739234 --- /dev/null +++ b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt @@ -0,0 +1,29 @@ +package lol.koblizek.torch.plugin.tasks + +import codechicken.diffpatch.DiffOperation +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.TaskAction + +abstract class GenPatchTask : DefaultTask() { + init { + group = "torch" + description = "generates patch files from origin/ directory" + } + + @TaskAction + fun genPatches() { + val patchDir = project.file("patches/") + if (!patchDir.exists()) { + patchDir.mkdirs() + } + val diffOperation = DiffOperation.builder() + .aPath(project.file("origin/java/").toPath()) + .bPath(project.file("src/main/java/").toPath()) + .aPrefix(null) + .bPrefix(null) + .singleDiff(true).filter { it.endsWith(".java") } + .outputPath(patchDir.toPath()) + .build() + diffOperation.doDiff() + } +} \ No newline at end of file diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/evaluated/DecompileTask.kt b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/evaluated/DecompileTask.kt index 04ff93a..cabb3c6 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/evaluated/DecompileTask.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/evaluated/DecompileTask.kt @@ -38,6 +38,11 @@ class DecompileTask : EvaluatedTask() { } fernFlower.decompileContext() moveNonCodeFiles(project) + val file = project.file("origin/") + val from = project.file("src/main/java/") + if (!file.exists()) file.mkdirs() + FileUtils.copyDirectory(from, file) + } else { logger.quiet("Minecraft resource are not missing, no need to redownload") } From a17f63758d4e2947db299747d546fd163ba0c629 Mon Sep 17 00:00:00 2001 From: KoblizekXD Date: Sat, 23 Sep 2023 14:03:13 +0200 Subject: [PATCH 4/6] bump: bumped vineflower version Took 1 minute --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index a7f500f..3d70f8b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,7 +25,7 @@ repositories { dependencies { implementation("com.github.MCPHackers:DiffPatch:cde1224") implementation("net.neoforged:AutoRenamingTool:1.0.7") - implementation("org.vineflower:vineflower:1.9.2") + implementation("org.vineflower:vineflower:1.9.3") implementation("net.fabricmc:tiny-remapper:0.8.7") implementation("net.fabricmc:mapping-io:0.4.2") implementation("commons-io:commons-io:2.13.0") From b5dbcc9437078b1081d4fbb4353d65a037367088 Mon Sep 17 00:00:00 2001 From: KoblizekXD Date: Sat, 23 Sep 2023 14:06:01 +0200 Subject: [PATCH 5/6] bump: bumped project version Took 3 minutes --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3d70f8b..fc00140 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "lol.koblizek" -version = "1.0" +version = "1.1" repositories { mavenCentral() From eb0f572e8d505d9fb74662339246fd9c8c423d67 Mon Sep 17 00:00:00 2001 From: KoblizekXD Date: Sat, 23 Sep 2023 14:42:29 +0200 Subject: [PATCH 6/6] fix: fixed issues with patches Took 15 minutes --- .../kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt index b739234..5da9835 100644 --- a/src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt +++ b/src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt @@ -17,13 +17,14 @@ abstract class GenPatchTask : DefaultTask() { patchDir.mkdirs() } val diffOperation = DiffOperation.builder() - .aPath(project.file("origin/java/").toPath()) + .aPath(project.file("origin/").toPath()) .bPath(project.file("src/main/java/").toPath()) .aPrefix(null) .bPrefix(null) - .singleDiff(true).filter { it.endsWith(".java") } + .filter { it.endsWith(".java") } .outputPath(patchDir.toPath()) .build() diffOperation.doDiff() + println("Patch done.") } } \ No newline at end of file