Skip to content

Commit 4ba1ba2

Browse files
committed
Initial commit
0 parents  commit 4ba1ba2

File tree

144 files changed

+9380
-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.

144 files changed

+9380
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
/.idea
3+
/build
4+
/.gradle/
5+
/.settings/
6+
/bin/
7+
/*/build
8+
/run
9+
/run2
10+
11+
/.project
12+
/.classpath
13+
14+
/client/libs/*.jar
15+
/server/libs/*.jar

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Fox2Code
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# ReIndevFoxLoader
2+
3+
ModLoader for Minecraft ReIndev
4+
5+
## Documentation
6+
7+
For mixins usage check here: https://github.com/2xsaiko/mixin-cheatsheet
8+
9+
For spark usage check here: https://spark.lucko.me/docs/Command-Usage
10+
11+
## Project structure
12+
- `betacraft` -> BetaCraft launch method to run fox loader
13+
- `client` -> client specific code
14+
- `common` -> main component of the mod loader that are shared both on client and on server
15+
- `dev` -> Gradle plugin
16+
- `final` -> Installer a format in which the mod loader is shipped to user
17+
- `server` -> server specific code
18+
19+
## Boot process
20+
21+
- Load pre patches
22+
- Load core-mods (Aka. Legacy mods) into class loader
23+
- Load pre-patches (FoxLoader asm patches)
24+
- Load mods into class loader
25+
- Initialize mixins
26+
- Allow game to be loaded
27+
- Load mods
28+
- Launch game
29+
30+
As you see the game is allowed to be loaded very late into the boot process, even after mixins.
31+
32+
This ensures that all patches introduced by mods are applied,
33+
but also prevent code loaded in MixinPlugins to load Minecraft classes,
34+
please keep that in mind when messing with mixins.

betacraft/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
group 'com.fox2code'
2+
version project['foxloader.version']
3+
4+
dependencies {
5+
// compileOnly("com.github.Vatuu:discord-rpc:1.6.2")
6+
// compileOnly("aaaaaaaa:bbbbbbb:1.0.0") something.repo/aaaaaaaa/bbbbbbb/1.0.0/bbbbbbb-1.0.0.pom
7+
}
8+
9+
tasks.withType(Jar) {
10+
exclude('org/betacraft/*')
11+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import org.betacraft.Wrapper;
2+
3+
import java.awt.*;
4+
import java.io.*;
5+
import java.net.Proxy;
6+
import java.net.URL;
7+
import java.net.URLStreamHandler;
8+
import java.util.ArrayList;
9+
import java.util.Map;
10+
import java.util.Properties;
11+
12+
public class FoxLoader extends Wrapper {
13+
static {
14+
System.clearProperty("http.proxyHost");
15+
System.clearProperty("http.proxyPort");
16+
System.out.println("FoxLoader BetaCraft wrapper loaded!");
17+
}
18+
19+
private static boolean checkAllowDiscordRpc(String mainFolder) {
20+
// Let allow mods to disable BetaCraft RPC
21+
return !new File(mainFolder + File.separator + "config" +
22+
File.separator + "no-discord-rpc").exists();
23+
}
24+
25+
public FoxLoader(String user, String ver_prefix, String version, String sessionid, String mainFolder, Integer height, Integer width, Boolean RPC, String launchMethod, String server, String mppass, String uuid, String USR, String VER, Image img, ArrayList<?> addons) {
26+
super(user, ver_prefix, version, sessionid, mainFolder, height, width,
27+
RPC && checkAllowDiscordRpc(mainFolder),
28+
launchMethod, server, mppass, uuid, USR, VER, img, addons);
29+
}
30+
31+
public FoxLoader(String user, String ver_prefix, String version, String sessionid, String mainFolder, Integer height, Integer width, Boolean RPC, String launchMethod, String server, String mppass, String USR, String VER, Image img, ArrayList<?> addons) {
32+
super(user, ver_prefix, version, sessionid, mainFolder, height, width,
33+
RPC && checkAllowDiscordRpc(mainFolder),
34+
launchMethod, server, mppass, USR, VER, img, addons);
35+
}
36+
37+
@Override
38+
public void play() {
39+
this.loadJars();
40+
boolean hasDiscordRPC = false;
41+
try {
42+
hasDiscordRPC = this.discord;
43+
} catch (Throwable ignored) {}
44+
try {
45+
Class.forName("com.fox2code.foxloader.launcher.ClientMain", true, classLoader)
46+
.getDeclaredMethod("mainBetaCraft", Map.class, String.class, boolean.class)
47+
.invoke(null, this.params, this.mainFolder, hasDiscordRPC);
48+
} catch (ReflectiveOperationException e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
53+
@Override
54+
public void loadMainClass(URL[] url) {
55+
PrintStream outOrig = System.out;
56+
PrintStream errOrig = System.err;
57+
// Silence a normal thing to happen on launch.
58+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
59+
PrintStream printStream = new PrintStream(byteArrayOutputStream);
60+
System.setErr(printStream);
61+
System.setOut(printStream);
62+
try {
63+
super.loadMainClass(url);
64+
} catch (RuntimeException e) {
65+
try {
66+
errOrig.write(byteArrayOutputStream.toByteArray());
67+
} catch (IOException ignored) {}
68+
System.setOut(outOrig);
69+
System.setErr(errOrig);
70+
} finally {
71+
System.setOut(outOrig);
72+
System.setErr(errOrig);
73+
}
74+
}
75+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.betacraft;
2+
3+
import java.applet.Applet;
4+
import java.awt.*;
5+
import java.net.MalformedURLException;
6+
import java.net.URL;
7+
import java.net.URLClassLoader;
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
public class Wrapper extends Applet {
13+
public final Map<String, String> params = new HashMap<>();
14+
public String mainFolder;
15+
public URLClassLoader classLoader;
16+
public boolean discord = false;
17+
18+
public Wrapper(String user, String ver_prefix, String version, String sessionid,
19+
String mainFolder, Integer height, Integer width, Boolean RPC, String launchMethod, String server,
20+
String mppass, String uuid, String USR, String VER, Image img, ArrayList<?> addons) {
21+
this(user, ver_prefix, version, sessionid, mainFolder, height, width, RPC, launchMethod, server, mppass, USR, VER, img, addons);
22+
}
23+
24+
public Wrapper(String user, String ver_prefix, String version, String sessionid,
25+
String mainFolder, Integer height, Integer width, Boolean RPC, String launchMethod, String server,
26+
String mppass, String USR, String VER, Image img, ArrayList<?> addons) {
27+
params.put("username", user);
28+
params.put("sessionid", sessionid);
29+
params.put("haspaid", "true");
30+
31+
if (server != null && server.contains(":")) {
32+
params.put("server", server.split(":")[0]);
33+
params.put("port", server.split(":")[1]);
34+
}
35+
36+
this.play();
37+
}
38+
39+
public void play() {
40+
41+
}
42+
43+
public void loadMainClass(URL[] url) {}
44+
45+
public void loadJars() {}
46+
47+
@Override
48+
public URL getCodeBase() {
49+
try {
50+
return new URL("http://www.minecraft.net/game/");
51+
} catch (MalformedURLException e) {
52+
e.printStackTrace();
53+
return null;
54+
}
55+
}
56+
57+
@Override
58+
public String getParameter(final String paramName) {
59+
System.out.println("Client asked for parameter: " + paramName);
60+
if (params.containsKey(paramName)) {
61+
return params.get(paramName);
62+
}
63+
return null;
64+
}
65+
}

build.gradle

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
plugins {
2+
id 'java-base'
3+
}
4+
5+
group 'com.fox2code'
6+
version '1.0-SNAPSHOT'
7+
8+
tasks.register('publishToMavenLocal', Task)
9+
10+
subprojects {
11+
apply plugin: 'java-library'
12+
apply plugin: 'maven-publish'
13+
14+
repositories {
15+
mavenCentral()
16+
maven {
17+
name = "Modrinth"
18+
url = "https://api.modrinth.com/maven"
19+
content {
20+
includeGroup "maven.modrinth"
21+
}
22+
}
23+
maven {
24+
url 'https://repo.spongepowered.org/maven'
25+
}
26+
maven {
27+
url 'https://jitpack.io/'
28+
}
29+
}
30+
31+
dependencies {
32+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
33+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
34+
}
35+
36+
java {
37+
sourceCompatibility = JavaVersion.VERSION_1_8
38+
targetCompatibility = JavaVersion.VERSION_1_8
39+
40+
withSourcesJar()
41+
}
42+
43+
test {
44+
useJUnitPlatform()
45+
}
46+
47+
rootProject.tasks.publishToMavenLocal.dependsOn(publishToMavenLocal)
48+
49+
afterEvaluate {
50+
publishing {
51+
publications {
52+
release(MavenPublication) {
53+
from components.java
54+
groupId = "com.github.Fox2Code.FoxLoader"
55+
artifactId = project.name
56+
version = '1.0' // JitPack only work with "1.0" as version
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
64+
// We need to download client and server to be able to compile the project.
65+
// Let's do that there really quick.
66+
static void download(URL url, File file) {
67+
file.getParentFile().mkdirs()
68+
HttpURLConnection connection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY)
69+
String javaVendor = System.getProperty("java.vendor")
70+
String javaVersion = System.getProperty("java.version")
71+
String javaVendorVersion = System.getProperty("java.vm.version")
72+
String osName = System.getProperty("os.name")
73+
String osVersion = System.getProperty("os.version")
74+
String osArch = System.getProperty("os.arch")
75+
connection.setConnectTimeout(5000)
76+
connection.setRequestProperty("Connection", "keep-alive")
77+
connection.setRequestProperty("User-Agent", String.format("Gradle/7.5.1 (%s;%s;%s) (%s;%s;%s)",
78+
osName, osVersion, osArch, javaVendor, javaVersion, javaVendorVersion))
79+
file.withOutputStream { fileOut ->
80+
fileOut << connection.getInputStream()
81+
}
82+
}
83+
84+
File clientFile = new File(project.rootDir, "client" + File.separator +
85+
"libs" + File.separator + project['reindev.clientJar'])
86+
87+
if (!clientFile.exists()) {
88+
println("Downloading client...")
89+
download(new URL(project['reindev.clientUrl'] as String), clientFile)
90+
}
91+
92+
File serverFile = new File(project.rootDir, "server" + File.separator +
93+
"libs" + File.separator + project['reindev.serverJar'])
94+
95+
if (!serverFile.exists()) {
96+
println("Downloading server...")
97+
download(new URL(project['reindev.serverUrl'] as String), serverFile)
98+
}

client/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Client build.gradle
2+
group 'com.fox2code'
3+
version project['foxloader.version']
4+
5+
dependencies {
6+
api(project(":common"))
7+
8+
// Do not use API here
9+
implementation(fileTree(dir: 'libs', include: ['*.jar']))
10+
11+
//noinspection GradlePackageUpdate
12+
api("net.java.jinput:jinput:2.0.5")
13+
//noinspection GradlePackageUpdate
14+
api("org.lwjgl.lwjgl:lwjgl:2.9.1")
15+
//noinspection GradlePackageUpdate
16+
api("org.lwjgl.lwjgl:lwjgl_util:2.9.1")
17+
//noinspection GradlePackageUpdate
18+
api("org.lwjgl.lwjgl:lwjgl-platform:2.9.1")
19+
20+
// Do no expose spark APIs to mods
21+
implementation(project['spark.dependency'] as String)
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.fox2code.foxloader.client;
2+
3+
import com.fox2code.foxloader.network.NetworkPlayer;
4+
import com.fox2code.foxloader.registry.CommandCompat;
5+
import net.minecraft.mitask.command.Command;
6+
import net.minecraft.src.client.player.EntityPlayerSP;
7+
8+
public final class ClientCommandWrapper extends Command {
9+
private final CommandCompat commandCompat;
10+
11+
public ClientCommandWrapper(CommandCompat commandCompat) {
12+
super(commandCompat.getName(), commandCompat.isOpOnly(), commandCompat.isHidden(), commandCompat.getAliases());
13+
this.commandCompat = commandCompat;
14+
}
15+
16+
@Override
17+
public void onExecute(String[] args, EntityPlayerSP commandExecutor) {
18+
this.commandCompat.onExecute(args, (NetworkPlayer) commandExecutor);
19+
}
20+
}

0 commit comments

Comments
 (0)