Skip to content

Commit 772b6c2

Browse files
committed
Update 1.2.26
1 parent 902f041 commit 772b6c2

File tree

23 files changed

+359
-121
lines changed

23 files changed

+359
-121
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
ModLoader for Minecraft ReIndev
44

5+
[![](https://www.jitpack.io/v/com.fox2code/FoxLoader.svg)](https://www.jitpack.io/#com.fox2code/FoxLoader)
6+
57
## Community
68

79
You can [join the official ReIndev Discord here](https://discord.gg/38Vfes6NpR)
@@ -11,7 +13,7 @@ A feature missing to make your mod? [Just open an issue!](https://github.com/Fox
1113
## Installation
1214

1315
For client side installation, just run the jar file.
14-
Either by double clicking on it, or running `java -jar FoxLoader.jar`
16+
Either by double-clicking on it, or running `java -jar FoxLoader.jar`
1517

1618
To run FoxLoader as a server just run `java -jar FoxLoader.jar --server`
1719

@@ -37,6 +39,7 @@ For example mod check here: https://github.com/Fox2Code/FoxLoaderExampleMod
3739
- Load core-mods (Aka. Legacy mods) into class loader
3840
- Load pre-patches (FoxLoader asm patches)
3941
- Load mods into class loader
42+
- Do full game pre-patching
4043
- Initialize mixins
4144
- Allow game to be loaded
4245
- Load mods
@@ -46,7 +49,7 @@ As you see the game is allowed to be loaded very late into the boot process, eve
4649

4750
This ensures that all patches introduced by mods are applied,
4851
but also prevent code loaded in MixinPlugins to load Minecraft classes,
49-
please keep that in mind when messing with mixins.
52+
please keep that in mind when messing with mixins plugins.
5053

5154
## Lua mods
5255

build.gradle

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ subprojects {
4141
}
4242

4343
withSourcesJar()
44+
withJavadocJar()
4445
}
4546

4647
test {
@@ -86,8 +87,18 @@ subprojects {
8687

8788
// We need to download client and server to be able to compile the project.
8889
// Let's do that there really quick.
89-
static void download(URL url, File file) {
90+
static void downloadIfNeeded(URL url, File file, String hash) {
9091
file.getParentFile().mkdirs()
92+
if (file.exists()) {
93+
byte[] localData = Files.readAllBytes(file.toPath())
94+
byte[] localHash = MessageDigest.getInstance("SHA-256").digest(localData)
95+
String hashString = new BigInteger(1, localHash).toString(16)
96+
if (hashString == hash) return
97+
if (!file.delete()) {
98+
throw new IOException("Failed to delete corrupted file: " + file.getName())
99+
}
100+
}
101+
println("Downloading " + url)
91102
HttpURLConnection connection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY)
92103
String javaVendor = System.getProperty("java.vendor")
93104
String javaVersion = System.getProperty("java.version")
@@ -102,72 +113,20 @@ static void download(URL url, File file) {
102113
file.withOutputStream { fileOut ->
103114
fileOut << connection.getInputStream()
104115
}
116+
byte[] fileData = Files.readAllBytes(file.toPath())
117+
byte[] fileHash = MessageDigest.getInstance("SHA-256").digest(fileData)
118+
String hashString = new BigInteger(1, fileHash).toString(16)
119+
if (hash != hashString) {
120+
throw new IOException("Excpeted HASH: " + hash + " got " + hashString)
121+
}
105122
}
106123

107124
File clientFile = new File(project.rootDir, "client" + File.separator +
108125
"libs" + File.separator + project['reindev.clientJar'])
109-
110-
if (!clientFile.exists()) {
111-
println("Downloading client from " + project['reindev.clientUrl'])
112-
113-
for (int i = 0; i < 2; i++) { // Max 1 retry for downloading
114-
if (i > 0) {
115-
println("Retrying download in 1 second...")
116-
Thread.sleep(1000);
117-
}
118-
119-
download(new URL(project['reindev.clientUrl'] as String), clientFile)
120-
121-
byte[] data = Files.readAllBytes(clientFile.toPath())
122-
byte[] hash = MessageDigest.getInstance("SHA-256").digest(data)
123-
String hashString = new BigInteger(1, hash).toString(16)
124-
125-
println("SHA256 hash: " + hashString)
126-
if (hashString == project['reindev.clientSHA256Sum'] as String) {
127-
println("Hash matched expected")
128-
break
129-
} else {
130-
println("Hash did not match! Expected: " + project['reindev.clientSHA256Sum'])
131-
if (clientFile.delete()) {
132-
println("Client jar file deleted")
133-
} else {
134-
println("Failed to delete client jar file")
135-
break;
136-
}
137-
}
138-
}
139-
}
140-
141126
File serverFile = new File(project.rootDir, "server" + File.separator +
142127
"libs" + File.separator + project['reindev.serverJar'])
143128

144-
if (!serverFile.exists()) {
145-
println("\nDownloading server from " + project['reindev.serverUrl'])
146-
147-
for (int i = 0; i < 2; i++) { // Max 1 retry for downloading
148-
if (i > 0) {
149-
println("Retrying download in 1 second...")
150-
Thread.sleep(1000);
151-
}
152-
153-
download(new URL(project['reindev.serverUrl'] as String), serverFile)
154-
155-
byte[] data = Files.readAllBytes(serverFile.toPath())
156-
byte[] hash = MessageDigest.getInstance("SHA-256").digest(data)
157-
String hashString = new BigInteger(1, hash).toString(16)
158-
159-
println("SHA256 hash: " + hashString)
160-
if (hashString == project['reindev.serverSHA256Sum'] as String) {
161-
println("Hash matched expected")
162-
break
163-
} else {
164-
println("Hash did not match! Expected: " + project['reindev.serverSHA256Sum'])
165-
if (serverFile.delete()) {
166-
println("Server file deleted")
167-
} else {
168-
println("Failed to delete server file")
169-
break;
170-
}
171-
}
172-
}
173-
}
129+
downloadIfNeeded(new URL(project['reindev.clientUrl'] as String), clientFile,
130+
project['reindev.clientSHA256Sum'] as String)
131+
downloadIfNeeded(new URL(project['reindev.serverUrl'] as String), serverFile,
132+
project['reindev.serverSHA256Sum'] as String)

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinEntityClientPlayerMP.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@ public boolean isConnected() {
7272
return sendQueue != null && Minecraft.getInstance().isMultiplayerWorld() &&
7373
!((NetClientHandlerExtensions) sendQueue).isDisconnected();
7474
}
75+
76+
@Override
77+
public void sendPlayerThroughPortalRegistered() {
78+
throw new RuntimeException("No authority over player");
79+
}
7580
}

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinEntityPlayerSP.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
import net.minecraft.src.client.player.EntityPlayerSP;
99
import net.minecraft.src.game.entity.Entity;
1010
import net.minecraft.src.game.entity.player.EntityPlayer;
11+
import net.minecraft.src.game.level.World;
1112
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Shadow;
1214

1315
@Mixin(EntityPlayerSP.class)
14-
public abstract class MixinEntityPlayerSP implements NetworkPlayer {
16+
public abstract class MixinEntityPlayerSP extends EntityPlayer implements NetworkPlayer {
17+
18+
@Shadow public Minecraft mc;
19+
20+
public MixinEntityPlayerSP(World var1) {
21+
super(var1);
22+
}
1523

1624
@Override
1725
public ConnectionType getConnectionType() {
@@ -69,4 +77,10 @@ public RegisteredItemStack getRegisteredHeldItem() {
6977
EntityPlayerSP networkPlayerSP = (EntityPlayerSP) (Object) this;
7078
return ClientMod.toRegisteredItemStack(networkPlayerSP.inventory.getCurrentItem());
7179
}
80+
81+
@Override
82+
public void sendPlayerThroughPortalRegistered() {
83+
this.mc.usePortal();
84+
this.inPortal = false;
85+
}
7286
}

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinGuiIngameMenu.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.fox2code.foxloader.client.gui.GuiModList;
44
import com.fox2code.foxloader.client.gui.GuiUpdateButton;
5+
import com.fox2code.foxloader.loader.ModLoader;
6+
import com.fox2code.foxloader.network.NetworkPlayer;
7+
import net.minecraft.client.Minecraft;
58
import net.minecraft.src.client.gui.GuiButton;
69
import net.minecraft.src.client.gui.GuiIngameMenu;
710
import net.minecraft.src.client.gui.GuiScreen;
@@ -18,8 +21,16 @@ public void onInitGui(CallbackInfo ci) {
1821
}
1922

2023
@Inject(method = "actionPerformed", at = @At(value = "HEAD"), cancellable = true)
21-
public void onActionPerformed(GuiButton var1, CallbackInfo ci) {
22-
if (var1.id == 500) {
24+
public void onActionPerformed(GuiButton button, CallbackInfo ci) {
25+
if (button.id == 1) {
26+
NetworkPlayer networkPlayer = (NetworkPlayer) Minecraft.getInstance().thePlayer;
27+
if (networkPlayer != null && networkPlayer.getConnectionType() ==
28+
NetworkPlayer.ConnectionType.SINGLE_PLAYER) {
29+
ModLoader.Internal.notifyNetworkPlayerDisconnected(networkPlayer, null);
30+
}
31+
}
32+
33+
if (button.id == 500) {
2334
this.mc.displayGuiScreen(new GuiModList(this));
2435
ci.cancel();
2536
}

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinGuiMainMenu.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import com.fox2code.foxloader.client.gui.GuiUpdateButton;
55
import com.fox2code.foxloader.launcher.BuildConfig;
66
import com.fox2code.foxloader.loader.ModLoader;
7+
import com.fox2code.foxloader.network.ChatColors;
8+
import net.minecraft.src.client.Session;
79
import net.minecraft.src.client.gui.*;
810
import org.spongepowered.asm.mixin.Mixin;
911
import org.spongepowered.asm.mixin.injection.At;
1012
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.Redirect;
1114
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1215

1316
@Mixin(GuiMainMenu.class)
@@ -25,6 +28,16 @@ public void onActionPerformed(GuiButton var1, CallbackInfo ci) {
2528
}
2629
}
2730

31+
@Redirect(method = "drawScreen", at = @At(value = "FIELD", target =
32+
"Lnet/minecraft/src/client/Session;username:Ljava/lang/String;"))
33+
public String onGetUsername(Session instance) {
34+
final String username = instance.username;
35+
if (ModLoader.Contributors.hasContributorName(username)) {
36+
return ChatColors.RAINBOW + username;
37+
}
38+
return username;
39+
}
40+
2841
@Inject(method = "drawScreen", at = @At(value = "INVOKE",
2942
target = "Lnet/minecraft/src/client/gui/GuiScreen;drawScreen(IIF)V"))
3043
public void onDrawGuiScreen(int n, int n2, float deltaTicks, CallbackInfo ci) {

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinWorld.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.minecraft.src.game.entity.other.EntityItem;
99
import net.minecraft.src.game.entity.player.EntityPlayer;
1010
import net.minecraft.src.game.level.World;
11+
import net.minecraft.src.game.level.WorldProvider;
12+
import org.spongepowered.asm.mixin.Final;
1113
import org.spongepowered.asm.mixin.Mixin;
1214
import org.spongepowered.asm.mixin.Shadow;
1315

@@ -25,6 +27,8 @@ public abstract class MixinWorld implements RegisteredWorld {
2527
@Shadow public abstract boolean setBlockAndMetadataWithNotify(int xCoord, int yCoord, int zCoord, int block, int metadata);
2628
@Shadow public abstract boolean entityJoinedWorld(Entity entity);
2729

30+
@Shadow @Final public WorldProvider worldProvider;
31+
2832
@Override
2933
public boolean hasRegisteredControl() {
3034
return !this.multiplayerWorld;
@@ -80,4 +84,9 @@ public List<? extends RegisteredTileEntity> getRegisteredTileEntities() {
8084
public List<? extends NetworkPlayer> getRegisteredNetworkPlayers() {
8185
return (List<? extends NetworkPlayer>) (Object) this.playerEntities;
8286
}
87+
88+
@Override
89+
public int getRegisteredDimensionID() {
90+
return this.worldProvider.worldType;
91+
}
8392
}

client/src/main/java/com/fox2code/foxloader/loader/ClientModLoader.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fox2code.foxloader.launcher.BuildConfig;
44
import com.fox2code.foxloader.launcher.FoxLauncher;
55
import com.fox2code.foxloader.launcher.LauncherType;
6+
import com.fox2code.foxloader.launcher.utils.IOUtils;
67
import com.fox2code.foxloader.launcher.utils.NetUtils;
78
import com.fox2code.foxloader.launcher.utils.Platform;
89
import com.fox2code.foxloader.launcher.utils.SourceUtil;
@@ -46,14 +47,14 @@ private static void computeClientHello() {
4647
new ArrayList<>(ModLoader.modContainers.size() +
4748
ModLoader.coreMods.size());
4849
for (File coreMod : ModLoader.coreMods) {
49-
byte[] sha256 = NetUtils.hashOf(coreMod);
50+
byte[] sha256 = IOUtils.sha256Of(coreMod);
5051
clientModData.add(new ClientHello.ClientModData(
5152
coreMod.getName(), sha256, "", ""));
5253
}
5354
for (ModContainer modContainer : ModLoader.modContainers.values()) {
5455
byte[] sha256 = nullSHA256;
5556
if (modContainer.file != null) {
56-
sha256 = NetUtils.hashOf(modContainer.file);
57+
sha256 = IOUtils.sha256Of(modContainer.file);
5758
}
5859
clientModData.add(new ClientHello.ClientModData(
5960
modContainer.id, sha256,

client/src/main/resources/foxloader.client.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"MixinEntityClientPlayerMP",
1616
"MixinEntityItem",
1717
"MixinEntityLiving",
18+
"MixinEntityPlayer",
1819
"MixinEntityPlayerSP",
1920
"MixinEntityRenderer",
2021
"MixinGameSettings",

common/generate.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
3535
final String REINDEV_VERSION = project['reindev.version']
3636
final String CLIENT_URL = project['reindev.clientUrl']
3737
final String SERVER_URL = project['reindev.serverUrl']
38+
final String CLIENT_SHA256_SUM = project['reindev.clientSHA256Sum']
39+
final String SERVER_SHA256_SUM = project['reindev.serverSHA256Sum']
3840
FileOutputStream fileOutputStream = new FileOutputStream(buildConfigSrc)
3941
try {
4042
PrintStream printStream = new PrintStream(fileOutputStream)
@@ -52,6 +54,8 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
5254
printStream.println(" public static final String REINDEV_VERSION = \"" + REINDEV_VERSION + "\";")
5355
printStream.println(" public static final String CLIENT_URL = \"" + CLIENT_URL + "\";")
5456
printStream.println(" public static final String SERVER_URL = \"" + SERVER_URL + "\";")
57+
printStream.println(" public static final String CLIENT_SHA256_SUM = \"" + CLIENT_SHA256_SUM + "\";")
58+
printStream.println(" public static final String SERVER_SHA256_SUM = \"" + SERVER_SHA256_SUM + "\";")
5559
printStream.println("}")
5660
} finally {
5761
fileOutputStream.close()

0 commit comments

Comments
 (0)