Skip to content

Commit 8fc0dc7

Browse files
committed
FoxLoader 2.0 initial commit.
0 parents  commit 8fc0dc7

File tree

249 files changed

+23605
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+23605
-0
lines changed

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
*.iml
2+
/.idea
3+
/build
4+
/lib/*
5+
/.gradle/
6+
/.settings/
7+
/out/
8+
/bin/
9+
/*/build
10+
/*/out
11+
/run
12+
/run2
13+
/crash-reports
14+
/FoxLoader-*.zip
15+
hs_err_pid*.log
16+
*.jfr
17+
18+
/.vscode
19+
/.project
20+
/.classpath
21+
/.profileconfig.json
22+
/local.properties
23+
24+
/loader/libs/*.jar
25+
/loader/patched/*.jar

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ReIndevFoxLoader
2+
3+
ModLoader for Minecraft ReIndev
4+
5+
[![](https://www.jitpack.io/v/com.fox2code/FoxLoader.svg)](https://www.jitpack.io/#com.fox2code/FoxLoader)
6+
7+
## Community
8+
9+
You can [join the official ReIndev Discord here](https://discord.gg/38Vfes6NpR)
10+
11+
A feature missing to make your mod? [Just open an issue!](https://github.com/Fox2Code/FoxLoader/issues)
12+
13+
## Installation
14+
15+
For client side installation, just run the jar file.
16+
Either by double-clicking on it, or running `java -jar FoxLoader.jar`
17+
18+
You can also install FoxLoader on PrismLauncher by drag and dropping the `FoxLoader-mmc.zip` into it.
19+
20+
To run FoxLoader as a server just run `java -jar FoxLoader.jar --server`
21+
22+
Note: For PojavLauncher, click on "Install .jar" and the rest should be automatic,
23+
only the Android version of PojavLauncher is supported.
24+
25+
Note: Client is not supported on arm due to lack of it in LWJGL2, you can follow [this tutorial](https://shadowfacts.net/2022/lwjgl-arm64/) for help.
26+
27+
## Documentation
28+
29+
For mixins usage check here: https://github.com/2xsaiko/mixin-cheatsheet
30+
31+
For spark usage check here: https://spark.lucko.me/docs/Command-Usage
32+
33+
For example mod check here: https://github.com/Fox2Code/FoxLoaderExampleMod

build.gradle

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
import java.nio.file.Files
2+
import java.security.MessageDigest
3+
import java.util.zip.ZipEntry
4+
import java.util.zip.ZipInputStream
5+
import java.util.zip.ZipOutputStream
6+
7+
buildscript {
8+
ext {
9+
jvmDowngraderVersion = (project['jvm-downgrader.version'] as String)
10+
debugCompiler = false
11+
}
12+
dependencies {
13+
// classpath("xyz.wagyourtail.jvmdowngrader:jvmdowngrader-java-api:$jvmDowngraderVersion")
14+
}
15+
}
16+
17+
plugins {
18+
id 'java-base'
19+
id 'xyz.wagyourtail.jvmdowngrader' version "$jvmDowngraderVersion" apply false
20+
}
21+
22+
group 'com.fox2code'
23+
version project['foxloader.version']
24+
25+
tasks.register('publishToMavenLocal', Task)
26+
27+
subprojects {
28+
apply plugin: 'java-library'
29+
30+
version project['foxloader.version']
31+
32+
repositories {
33+
mavenCentral()
34+
maven {
35+
name = "Modrinth"
36+
url = "https://api.modrinth.com/maven"
37+
content {
38+
includeGroup "maven.modrinth"
39+
}
40+
}
41+
maven {
42+
url 'https://repo.spongepowered.org/maven'
43+
content {
44+
includeGroup "org.spongepowered"
45+
}
46+
}
47+
maven {
48+
name = 'Fabric'
49+
url 'https://maven.fabricmc.net/'
50+
content {
51+
includeGroup "net.fabricmc"
52+
}
53+
}
54+
maven {
55+
name = 'Unascribed'
56+
url "https://repo.unascribed.com"
57+
content {
58+
includeGroup "com.unascribed"
59+
}
60+
}
61+
maven {
62+
name = 'Sleeping Town'
63+
url 'https://repo.sleeping.town/'
64+
content {
65+
includeGroup 'blue.endless'
66+
}
67+
metadataSources {
68+
artifact()
69+
}
70+
}
71+
maven {
72+
name = 'Fox2Code Maven'
73+
url 'https://cdn.fox2code.com/maven'
74+
}
75+
maven {
76+
url 'https://jitpack.io/'
77+
}
78+
}
79+
80+
configurations {
81+
include
82+
compileOnly.extendsFrom(include)
83+
}
84+
85+
dependencies {
86+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
87+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
88+
}
89+
90+
java {
91+
// We need at least java 11 to diagnose obscure compile errors
92+
toolchain {
93+
languageVersion = JavaLanguageVersion.of(debugCompiler ? 21 : 8)
94+
}
95+
96+
sourceCompatibility = JavaVersion.VERSION_1_8
97+
targetCompatibility = JavaVersion.VERSION_1_8
98+
withSourcesJar()
99+
withJavadocJar()
100+
}
101+
102+
javadoc {
103+
failOnError false
104+
}
105+
106+
// Support "@reason" javadoc Mixin tag mandated by Minecraft-Dev Intellij plugin
107+
javadoc.options.tags = [ "reason" ]
108+
109+
test {
110+
useJUnitPlatform()
111+
}
112+
113+
afterEvaluate {
114+
tasks.withType(JavaCompile.class).configureEach {
115+
if (debugCompiler) {
116+
options.compilerArgs.addAll(['--release', '8'])
117+
}
118+
options.compilerArgs += '-g'
119+
options.encoding = 'UTF-8'
120+
}
121+
122+
jar {
123+
from(configurations.include.collect { it.isDirectory() ? it : zipTree(it) }) {
124+
exclude("module-info.class")
125+
}
126+
}
127+
128+
final String reindevVersion = project['reindev.version'] as String
129+
final String reindevVersionAllowFrom = project['reindev.version.allowFrom'] as String
130+
131+
if (project.pluginManager.hasPlugin("maven-publish")) {
132+
rootProject.tasks.publishToMavenLocal.dependsOn(publishToMavenLocal)
133+
134+
publishing {
135+
publications {
136+
release(MavenPublication) {
137+
from components.java
138+
groupId = "com.github.Fox2Code.FoxLoader"
139+
artifactId = project.name
140+
version = '1.0' // JitPack only work with "1.0" as version
141+
pom {
142+
url = 'https://github.com/Fox2Code/FoxLoader'
143+
if (reindevVersion == reindevVersionAllowFrom) {
144+
properties = [
145+
"foxloader.version": project['foxloader.version'] as String,
146+
"reindev.version" : reindevVersion,
147+
]
148+
} else {
149+
properties = [
150+
"foxloader.version" : project['foxloader.version'] as String,
151+
"reindev.version" : reindevVersion,
152+
"reindev.version.allowFrom": reindevVersionAllowFrom,
153+
]
154+
}
155+
}
156+
}
157+
}
158+
}
159+
}
160+
}
161+
}
162+
163+
164+
// We need to download client and server to be able to compile the project.
165+
// Let's do that there really quick.
166+
static void downloadIfNeeded(URL url, File file, String hash) {
167+
file.getParentFile().mkdirs()
168+
if (file.exists()) {
169+
byte[] localData = Files.readAllBytes(file.toPath())
170+
byte[] localHash = MessageDigest.getInstance("SHA-256").digest(localData)
171+
String hashString = new BigInteger(1, localHash).toString(16)
172+
if (hashString == hash) return
173+
if (!file.delete()) {
174+
throw new IOException("Failed to delete corrupted file: " + file.getName())
175+
}
176+
}
177+
println("Downloading " + url)
178+
HttpURLConnection connection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY)
179+
String javaVendor = System.getProperty("java.vendor")
180+
String javaVersion = System.getProperty("java.version")
181+
String javaVendorVersion = System.getProperty("java.vm.version")
182+
String osName = System.getProperty("os.name")
183+
String osVersion = System.getProperty("os.version")
184+
String osArch = System.getProperty("os.arch")
185+
connection.setConnectTimeout(5000)
186+
connection.setRequestProperty("Connection", "keep-alive")
187+
connection.setRequestProperty("User-Agent", String.format("Gradle/7.5.1 (%s;%s;%s) (%s;%s;%s)",
188+
osName, osVersion, osArch, javaVendor, javaVersion, javaVendorVersion))
189+
file.withOutputStream { fileOut ->
190+
fileOut << connection.getInputStream()
191+
}
192+
byte[] fileData = Files.readAllBytes(file.toPath())
193+
byte[] fileHash = MessageDigest.getInstance("SHA-256").digest(fileData)
194+
String hashString = new BigInteger(1, fileHash).toString(16)
195+
if (hash != hashString) {
196+
throw new IOException("Excpeted HASH: " + hash + " got " + hashString)
197+
}
198+
}
199+
200+
File clientFile = new File(project.rootDir, "loader" + File.separator +
201+
"libs" + File.separator + project['reindev.clientJar'])
202+
File serverFile = new File(project.rootDir, "loader" + File.separator +
203+
"libs" + File.separator + project['reindev.serverJar'])
204+
File slimFile = new File(project.rootDir, "loader" + File.separator +
205+
"libs" + File.separator + project['reindev.slimJar'])
206+
File patchedFile = new File(project.rootDir, "loader" + File.separator +
207+
"libs" + File.separator + project['reindev.patchedJar'])
208+
final String slimURL = project['reindev.slimUrl'] as String
209+
210+
static ZipEntry partialCopy(ZipEntry zipEntry) {
211+
ZipEntry newZipEntry = new ZipEntry(zipEntry)
212+
newZipEntry.setCompressedSize(-1)
213+
newZipEntry.setComment(null)
214+
return newZipEntry
215+
}
216+
217+
String slimHash = project['reindev.slimSHA256Sum'] as String
218+
if (slimURL == "null") {
219+
if (slimFile.exists()) {
220+
byte[] fileData = Files.readAllBytes(slimFile.toPath())
221+
byte[] fileHash = MessageDigest.getInstance("SHA-256").digest(fileData)
222+
String hashString = new BigInteger(1, fileHash).toString(16)
223+
if (slimHash != hashString) {
224+
throw new IOException("Excpeted HASH: " + slimHash + " got " + hashString)
225+
}
226+
} else if (clientFile.exists() && serverFile.exists()) {
227+
HashSet<String> common = new HashSet<>()
228+
ZipOutputStream slimOutputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(slimFile)))
229+
slimOutputStream.setLevel(9)
230+
ZipEntry zipEntry
231+
ZipInputStream clientInputStream = new ZipInputStream(new BufferedInputStream(new FileInputStream(clientFile)))
232+
while ((zipEntry = clientInputStream.nextEntry)) {
233+
String path = zipEntry.getName()
234+
// Don't save folders unless it's a panorama folder
235+
if (path.endsWith("/") && !path.startsWith("textures/gui/panorama/")) continue
236+
if (path.indexOf("/") == -1 || path.startsWith("com/jcraft/") || path.startsWith("paulscode/") ||
237+
path.startsWith("textures/") || path.startsWith("lang/") || path.startsWith("com/mojang/nbt/") ||
238+
path.startsWith("com/indigo3d/") || path.startsWith("net/minecraft/")) {
239+
if (path.startsWith("net/minecraft/common/")) common.add(path)
240+
slimOutputStream.putNextEntry(partialCopy(zipEntry))
241+
slimOutputStream << clientInputStream
242+
slimOutputStream.closeEntry()
243+
clientInputStream.closeEntry()
244+
}
245+
}
246+
clientInputStream.close()
247+
ZipInputStream serverInputStream = new ZipInputStream(new BufferedInputStream(new FileInputStream(serverFile)))
248+
while ((zipEntry = serverInputStream.nextEntry)) {
249+
String path = zipEntry.getName()
250+
if (path.endsWith("/")) continue
251+
if (path.startsWith("net/minecraft/server/") ||
252+
(path.startsWith("net/minecraft/common/") && !common.contains(path))) {
253+
slimOutputStream.putNextEntry(partialCopy(zipEntry))
254+
slimOutputStream << serverInputStream
255+
slimOutputStream.closeEntry()
256+
serverInputStream.closeEntry()
257+
}
258+
}
259+
serverInputStream.close()
260+
slimOutputStream.finish()
261+
slimOutputStream.flush()
262+
slimOutputStream.close()
263+
byte[] fileData = Files.readAllBytes(slimFile.toPath())
264+
byte[] fileHash = MessageDigest.getInstance("SHA-256").digest(fileData)
265+
String hashString = new BigInteger(1, fileHash).toString(16)
266+
if (slimHash != hashString) {
267+
throw new IOException("Excpeted HASH: " + slimHash + " got " + hashString)
268+
}
269+
} else {
270+
throw new IOException("Missing " + clientFile.getName() + " | " + serverFile.getName())
271+
}
272+
} else {
273+
downloadIfNeeded(new URI(slimURL).toURL(), slimFile,
274+
project['reindev.slimSHA256Sum'] as String)
275+
}

0 commit comments

Comments
 (0)