Skip to content

Commit

Permalink
Update 1.2.26
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Nov 23, 2023
1 parent 902f041 commit 772b6c2
Show file tree
Hide file tree
Showing 23 changed files with 359 additions and 121 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

ModLoader for Minecraft ReIndev

[![](https://www.jitpack.io/v/com.fox2code/FoxLoader.svg)](https://www.jitpack.io/#com.fox2code/FoxLoader)

## Community

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

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

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

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

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

## Lua mods

Expand Down
85 changes: 22 additions & 63 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ subprojects {
}

withSourcesJar()
withJavadocJar()
}

test {
Expand Down Expand Up @@ -86,8 +87,18 @@ subprojects {

// We need to download client and server to be able to compile the project.
// Let's do that there really quick.
static void download(URL url, File file) {
static void downloadIfNeeded(URL url, File file, String hash) {
file.getParentFile().mkdirs()
if (file.exists()) {
byte[] localData = Files.readAllBytes(file.toPath())
byte[] localHash = MessageDigest.getInstance("SHA-256").digest(localData)
String hashString = new BigInteger(1, localHash).toString(16)
if (hashString == hash) return
if (!file.delete()) {
throw new IOException("Failed to delete corrupted file: " + file.getName())
}
}
println("Downloading " + url)
HttpURLConnection connection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY)
String javaVendor = System.getProperty("java.vendor")
String javaVersion = System.getProperty("java.version")
Expand All @@ -102,72 +113,20 @@ static void download(URL url, File file) {
file.withOutputStream { fileOut ->
fileOut << connection.getInputStream()
}
byte[] fileData = Files.readAllBytes(file.toPath())
byte[] fileHash = MessageDigest.getInstance("SHA-256").digest(fileData)
String hashString = new BigInteger(1, fileHash).toString(16)
if (hash != hashString) {
throw new IOException("Excpeted HASH: " + hash + " got " + hashString)
}
}

File clientFile = new File(project.rootDir, "client" + File.separator +
"libs" + File.separator + project['reindev.clientJar'])

if (!clientFile.exists()) {
println("Downloading client from " + project['reindev.clientUrl'])

for (int i = 0; i < 2; i++) { // Max 1 retry for downloading
if (i > 0) {
println("Retrying download in 1 second...")
Thread.sleep(1000);
}

download(new URL(project['reindev.clientUrl'] as String), clientFile)

byte[] data = Files.readAllBytes(clientFile.toPath())
byte[] hash = MessageDigest.getInstance("SHA-256").digest(data)
String hashString = new BigInteger(1, hash).toString(16)

println("SHA256 hash: " + hashString)
if (hashString == project['reindev.clientSHA256Sum'] as String) {
println("Hash matched expected")
break
} else {
println("Hash did not match! Expected: " + project['reindev.clientSHA256Sum'])
if (clientFile.delete()) {
println("Client jar file deleted")
} else {
println("Failed to delete client jar file")
break;
}
}
}
}

File serverFile = new File(project.rootDir, "server" + File.separator +
"libs" + File.separator + project['reindev.serverJar'])

if (!serverFile.exists()) {
println("\nDownloading server from " + project['reindev.serverUrl'])

for (int i = 0; i < 2; i++) { // Max 1 retry for downloading
if (i > 0) {
println("Retrying download in 1 second...")
Thread.sleep(1000);
}

download(new URL(project['reindev.serverUrl'] as String), serverFile)

byte[] data = Files.readAllBytes(serverFile.toPath())
byte[] hash = MessageDigest.getInstance("SHA-256").digest(data)
String hashString = new BigInteger(1, hash).toString(16)

println("SHA256 hash: " + hashString)
if (hashString == project['reindev.serverSHA256Sum'] as String) {
println("Hash matched expected")
break
} else {
println("Hash did not match! Expected: " + project['reindev.serverSHA256Sum'])
if (serverFile.delete()) {
println("Server file deleted")
} else {
println("Failed to delete server file")
break;
}
}
}
}
downloadIfNeeded(new URL(project['reindev.clientUrl'] as String), clientFile,
project['reindev.clientSHA256Sum'] as String)
downloadIfNeeded(new URL(project['reindev.serverUrl'] as String), serverFile,
project['reindev.serverSHA256Sum'] as String)
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ public boolean isConnected() {
return sendQueue != null && Minecraft.getInstance().isMultiplayerWorld() &&
!((NetClientHandlerExtensions) sendQueue).isDisconnected();
}

@Override
public void sendPlayerThroughPortalRegistered() {
throw new RuntimeException("No authority over player");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
import net.minecraft.src.client.player.EntityPlayerSP;
import net.minecraft.src.game.entity.Entity;
import net.minecraft.src.game.entity.player.EntityPlayer;
import net.minecraft.src.game.level.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(EntityPlayerSP.class)
public abstract class MixinEntityPlayerSP implements NetworkPlayer {
public abstract class MixinEntityPlayerSP extends EntityPlayer implements NetworkPlayer {

@Shadow public Minecraft mc;

public MixinEntityPlayerSP(World var1) {
super(var1);
}

@Override
public ConnectionType getConnectionType() {
Expand Down Expand Up @@ -69,4 +77,10 @@ public RegisteredItemStack getRegisteredHeldItem() {
EntityPlayerSP networkPlayerSP = (EntityPlayerSP) (Object) this;
return ClientMod.toRegisteredItemStack(networkPlayerSP.inventory.getCurrentItem());
}

@Override
public void sendPlayerThroughPortalRegistered() {
this.mc.usePortal();
this.inPortal = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.fox2code.foxloader.client.gui.GuiModList;
import com.fox2code.foxloader.client.gui.GuiUpdateButton;
import com.fox2code.foxloader.loader.ModLoader;
import com.fox2code.foxloader.network.NetworkPlayer;
import net.minecraft.client.Minecraft;
import net.minecraft.src.client.gui.GuiButton;
import net.minecraft.src.client.gui.GuiIngameMenu;
import net.minecraft.src.client.gui.GuiScreen;
Expand All @@ -18,8 +21,16 @@ public void onInitGui(CallbackInfo ci) {
}

@Inject(method = "actionPerformed", at = @At(value = "HEAD"), cancellable = true)
public void onActionPerformed(GuiButton var1, CallbackInfo ci) {
if (var1.id == 500) {
public void onActionPerformed(GuiButton button, CallbackInfo ci) {
if (button.id == 1) {
NetworkPlayer networkPlayer = (NetworkPlayer) Minecraft.getInstance().thePlayer;
if (networkPlayer != null && networkPlayer.getConnectionType() ==
NetworkPlayer.ConnectionType.SINGLE_PLAYER) {
ModLoader.Internal.notifyNetworkPlayerDisconnected(networkPlayer, null);
}
}

if (button.id == 500) {
this.mc.displayGuiScreen(new GuiModList(this));
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import com.fox2code.foxloader.client.gui.GuiUpdateButton;
import com.fox2code.foxloader.launcher.BuildConfig;
import com.fox2code.foxloader.loader.ModLoader;
import com.fox2code.foxloader.network.ChatColors;
import net.minecraft.src.client.Session;
import net.minecraft.src.client.gui.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GuiMainMenu.class)
Expand All @@ -25,6 +28,16 @@ public void onActionPerformed(GuiButton var1, CallbackInfo ci) {
}
}

@Redirect(method = "drawScreen", at = @At(value = "FIELD", target =
"Lnet/minecraft/src/client/Session;username:Ljava/lang/String;"))
public String onGetUsername(Session instance) {
final String username = instance.username;
if (ModLoader.Contributors.hasContributorName(username)) {
return ChatColors.RAINBOW + username;
}
return username;
}

@Inject(method = "drawScreen", at = @At(value = "INVOKE",
target = "Lnet/minecraft/src/client/gui/GuiScreen;drawScreen(IIF)V"))
public void onDrawGuiScreen(int n, int n2, float deltaTicks, CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import net.minecraft.src.game.entity.other.EntityItem;
import net.minecraft.src.game.entity.player.EntityPlayer;
import net.minecraft.src.game.level.World;
import net.minecraft.src.game.level.WorldProvider;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

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

@Shadow @Final public WorldProvider worldProvider;

@Override
public boolean hasRegisteredControl() {
return !this.multiplayerWorld;
Expand Down Expand Up @@ -80,4 +84,9 @@ public List<? extends RegisteredTileEntity> getRegisteredTileEntities() {
public List<? extends NetworkPlayer> getRegisteredNetworkPlayers() {
return (List<? extends NetworkPlayer>) (Object) this.playerEntities;
}

@Override
public int getRegisteredDimensionID() {
return this.worldProvider.worldType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fox2code.foxloader.launcher.BuildConfig;
import com.fox2code.foxloader.launcher.FoxLauncher;
import com.fox2code.foxloader.launcher.LauncherType;
import com.fox2code.foxloader.launcher.utils.IOUtils;
import com.fox2code.foxloader.launcher.utils.NetUtils;
import com.fox2code.foxloader.launcher.utils.Platform;
import com.fox2code.foxloader.launcher.utils.SourceUtil;
Expand Down Expand Up @@ -46,14 +47,14 @@ private static void computeClientHello() {
new ArrayList<>(ModLoader.modContainers.size() +
ModLoader.coreMods.size());
for (File coreMod : ModLoader.coreMods) {
byte[] sha256 = NetUtils.hashOf(coreMod);
byte[] sha256 = IOUtils.sha256Of(coreMod);
clientModData.add(new ClientHello.ClientModData(
coreMod.getName(), sha256, "", ""));
}
for (ModContainer modContainer : ModLoader.modContainers.values()) {
byte[] sha256 = nullSHA256;
if (modContainer.file != null) {
sha256 = NetUtils.hashOf(modContainer.file);
sha256 = IOUtils.sha256Of(modContainer.file);
}
clientModData.add(new ClientHello.ClientModData(
modContainer.id, sha256,
Expand Down
1 change: 1 addition & 0 deletions client/src/main/resources/foxloader.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"MixinEntityClientPlayerMP",
"MixinEntityItem",
"MixinEntityLiving",
"MixinEntityPlayer",
"MixinEntityPlayerSP",
"MixinEntityRenderer",
"MixinGameSettings",
Expand Down
4 changes: 4 additions & 0 deletions common/generate.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
final String REINDEV_VERSION = project['reindev.version']
final String CLIENT_URL = project['reindev.clientUrl']
final String SERVER_URL = project['reindev.serverUrl']
final String CLIENT_SHA256_SUM = project['reindev.clientSHA256Sum']
final String SERVER_SHA256_SUM = project['reindev.serverSHA256Sum']
FileOutputStream fileOutputStream = new FileOutputStream(buildConfigSrc)
try {
PrintStream printStream = new PrintStream(fileOutputStream)
Expand All @@ -52,6 +54,8 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
printStream.println(" public static final String REINDEV_VERSION = \"" + REINDEV_VERSION + "\";")
printStream.println(" public static final String CLIENT_URL = \"" + CLIENT_URL + "\";")
printStream.println(" public static final String SERVER_URL = \"" + SERVER_URL + "\";")
printStream.println(" public static final String CLIENT_SHA256_SUM = \"" + CLIENT_SHA256_SUM + "\";")
printStream.println(" public static final String SERVER_SHA256_SUM = \"" + SERVER_SHA256_SUM + "\";")
printStream.println("}")
} finally {
fileOutputStream.close()
Expand Down
Loading

0 comments on commit 772b6c2

Please sign in to comment.