Skip to content

Commit

Permalink
Refactor buildscript heavily
Browse files Browse the repository at this point in the history
Now supports 1.8.9 and 1.12.2 Forge and Fabric
  • Loading branch information
Wyvest committed Jul 30, 2024
1 parent 3cc71da commit 5099cad
Show file tree
Hide file tree
Showing 70 changed files with 573 additions and 273 deletions.
40 changes: 9 additions & 31 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true
version=1.0.0

polyfrost.defaults.loom=3
22 changes: 20 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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" }

Expand All @@ -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" }
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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<String> =
node.methods.map {
getStrings(it)
getStrings(it as MethodNode)
}.flatten().toSet()

fun getStrings(node: MethodNode): Set<String> =
node.instructions
node.instructions.iterator().asSequence()
.filter { insn ->
(insn is LdcInsnNode && insn.cst is String)
|| (insn is InvokeDynamicInsnNode && insn.bsmArgs.any { it is String })
Expand Down
6 changes: 2 additions & 4 deletions core/build.gradle.kts → modules/core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -17,7 +15,7 @@ dependencies {

tasks.processResources {
from(
project(":lwjgl")
project(":modules:lwjgl")
.tasks
.shadowJar
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" }
}
Expand All @@ -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()
}
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ 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 {
override fun transform(node: ClassNode) {
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"
Expand Down
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions modules/root.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
}
34 changes: 0 additions & 34 deletions platform/build.gradle.kts

This file was deleted.

31 changes: 0 additions & 31 deletions platform/fabric-1.8/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5099cad

Please sign in to comment.