Skip to content

Commit 18d99df

Browse files
committed
Update 1.2.16
1 parent 3e14bc9 commit 18d99df

File tree

16 files changed

+289
-33
lines changed

16 files changed

+289
-33
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import com.fox2code.foxloader.registry.RegisteredItemStack;
77
import net.minecraft.src.game.item.Item;
88
import net.minecraft.src.game.item.ItemStack;
9+
import net.minecraft.src.game.nbt.NBTTagCompound;
910
import org.spongepowered.asm.mixin.Mixin;
1011
import org.spongepowered.asm.mixin.Shadow;
1112
import org.spongepowered.asm.mixin.Unique;
1213
import org.spongepowered.asm.mixin.injection.At;
1314
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1416
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1517

1618
@Mixin(ItemStack.class)
@@ -25,6 +27,26 @@ public abstract class MixinItemStack implements RegisteredItemStack, NetworkItem
2527
@Shadow public abstract void setItemName(String par1Str);
2628
@Shadow public abstract boolean hasDisplayName();
2729

30+
@Inject(method = "<init>(II)V", at = @At("RETURN"))
31+
public void onNewItemStack(int id, int count, CallbackInfo ci) {
32+
this.verifyRegisteredItemStack();
33+
}
34+
35+
@Inject(method = "<init>(III)V", at = @At("RETURN"))
36+
public void onNewItemStack(int id, int count, int damage, CallbackInfo ci) {
37+
this.verifyRegisteredItemStack();
38+
}
39+
40+
@Inject(method = "<init>(IIILnet/minecraft/src/game/nbt/NBTTagCompound;)V", at = @At("RETURN"))
41+
public void onNewItemStack(int id, int count, int damage, NBTTagCompound tagCompound, CallbackInfo ci) {
42+
this.verifyRegisteredItemStack();
43+
}
44+
45+
@Inject(method = "readFromNBT", at = @At("RETURN"))
46+
public void onReadFromNBT(NBTTagCompound nbtTagCompound, CallbackInfo ci) {
47+
this.verifyRegisteredItemStack();
48+
}
49+
2850
@Inject(method = "splitStack", at = @At("RETURN"))
2951
public void onSplitStack(int stacksize, CallbackInfoReturnable<ItemStack> cir) {
3052
((NetworkItemStack) (Object) cir.getReturnValue()).setRemoteNetworkId(this.networkId);
@@ -82,4 +104,12 @@ public int getRemoteItemId() {
82104
public void setRemoteNetworkId(int networkId) {
83105
this.networkId = networkId;
84106
}
107+
108+
@Override
109+
public void verifyRegisteredItemStack() {
110+
if (this.itemID != 0 && this.stackSize <= 0) {
111+
this.itemDamage = 0;
112+
this.itemID = 0;
113+
}
114+
}
85115
}

client/src/main/java/com/fox2code/foxloader/launcher/ClientMain.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
public class ClientMain {
1313
private static final File currentLoaderFile = SourceUtil.getSourceFile(ClientMain.class);
1414
public static boolean hasBetaCraftDiscordRPC = false;
15+
public static boolean isFoxLoaderBadlyInstalled = false;
1516

1617
/**
1718
* This is executed by FoxLoader BetaCraft wrapper.

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.fox2code.foxloader.loader;
22

3+
import com.fox2code.foxloader.launcher.BuildConfig;
34
import com.fox2code.foxloader.launcher.FoxLauncher;
45
import com.fox2code.foxloader.launcher.LauncherType;
6+
import com.fox2code.foxloader.launcher.utils.IOUtils;
57
import com.fox2code.foxloader.launcher.utils.NetUtils;
68
import com.fox2code.foxloader.launcher.utils.Platform;
79
import com.fox2code.foxloader.launcher.utils.SourceUtil;
@@ -15,6 +17,9 @@
1517
import net.minecraft.src.client.gui.StringTranslate;
1618

1719
import java.io.*;
20+
import java.nio.file.CopyOption;
21+
import java.nio.file.Files;
22+
import java.nio.file.StandardCopyOption;
1823
import java.util.*;
1924
import java.util.function.Function;
2025

@@ -112,8 +117,17 @@ void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOExceptio
112117
}
113118
dest = new File(ModLoader.updateTmp, "foxloader-" + version + ".jar");
114119
}
115-
try (FileOutputStream fileOutputStream = new FileOutputStream(dest)) {
116-
NetUtils.downloadTo(url, fileOutputStream);
120+
if (BuildConfig.FOXLOADER_VERSION.equals(version) &&
121+
FoxLauncher.getLauncherType() != LauncherType.BIN) {
122+
// Can happen if wrongly installed
123+
if (!dest.equals(FoxLauncher.foxLoaderFile)) {
124+
Files.copy(FoxLauncher.foxLoaderFile.toPath(), dest.toPath(),
125+
StandardCopyOption.REPLACE_EXISTING);
126+
}
127+
} else {
128+
try (FileOutputStream fileOutputStream = new FileOutputStream(dest)) {
129+
NetUtils.downloadTo(url, fileOutputStream);
130+
}
117131
}
118132
args[0] = Platform.getPlatform().javaBin.getPath();
119133
args[2] = dest.getAbsolutePath();

common/src/main/java/com/fox2code/foxloader/launcher/DependencyHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ GSON_DEPENDENCY, new Dependency("com.google.guava:guava:21.0", MAVEN_CENTRAL, "c
4242

4343
public static final Dependency[] clientDependencies = new Dependency[]{
4444
new Dependency("net.silveros:reindev:" + BuildConfig.REINDEV_VERSION,
45-
BuildConfig.CLIENT_URL, "net.minecraft.client.Minecraft")
45+
BuildConfig.CLIENT_URL, "net.minecraft.src.client.MinecraftImpl")
4646
};
4747
public static final Dependency[] serverDependencies = new Dependency[]{
4848
new Dependency("net.silveros:reindev-server:" + BuildConfig.REINDEV_VERSION,

common/src/main/java/com/fox2code/foxloader/launcher/FoxLauncher.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,39 @@ public class FoxLauncher {
3131
public static final File foxLoaderFile = SourceUtil.getSourceFile(FoxLauncher.class);
3232
public static final HashMap<String, Object> mixinProperties = new HashMap<>();
3333
static LauncherType launcherType = LauncherType.UNKNOWN;
34-
private static boolean client;
34+
private static boolean client, wronglyInstalled, wronglyInstalledUnrecoverable;
3535
static FoxClassLoader foxClassLoader;
3636
static File gameDir;
3737
public static String initialUsername;
3838
public static String initialSessionId;
3939

40+
public static void markWronglyInstalled() {
41+
if (foxClassLoader == null) wronglyInstalled = true;
42+
}
43+
44+
public static void markWronglyInstalledUnrecoverable() {
45+
if (foxClassLoader == null) {
46+
wronglyInstalledUnrecoverable = true;
47+
initForClientFromArgs(new String[0]);
48+
wronglyInstalled = true;
49+
}
50+
}
51+
52+
public static boolean isWronglyInstalled() {
53+
return (client && wronglyInstalled) ||
54+
wronglyInstalledUnrecoverable;
55+
}
56+
4057
static void initForClientFromArgs(String[] args) {
4158
if (foxClassLoader != null)
4259
throw new IllegalStateException("FoxClassLoader already initialized!");
60+
if (wronglyInstalled && wronglyInstalledUnrecoverable)
61+
throw new IllegalStateException("FoxClassLoader cannot initialize!");
4362
client = true;
4463
File gameDir = null;
4564
if (args.length < 2) {
4665
initialUsername = // Allow username defines
47-
args.length < 1 ? "Player" : args[0];
66+
args.length == 0 ? "Player" : args[0];
4867
initialSessionId = "-";
4968
} else {
5069
initialUsername = args[0];
@@ -68,6 +87,7 @@ static void initForClientFromArgs(String[] args) {
6887
if (LoggerHelper.devEnvironment) {
6988
launcherType = LauncherType.GRADLE;
7089
}
90+
if (wronglyInstalledUnrecoverable) return;
7191
foxClassLoader = new FoxClassLoader();
7292
foxClassLoader.addTransformerExclusion("org.lwjgl.");
7393
foxClassLoader.addTransformerExclusion("org.objectweb.asm.");
@@ -82,6 +102,8 @@ static void initForClientFromArgs(String[] args) {
82102
static void initForServerFromArgs(String[] args) {
83103
if (foxClassLoader != null)
84104
throw new IllegalStateException("FoxClassLoader already initialized!");
105+
if (wronglyInstalled && wronglyInstalledUnrecoverable)
106+
throw new IllegalStateException("FoxClassLoader cannot initialize!");
85107
client = false;
86108
FoxLauncher.gameDir = new File("").getAbsoluteFile();
87109
// Special case for development environment.
@@ -91,6 +113,7 @@ static void initForServerFromArgs(String[] args) {
91113
if (LoggerHelper.devEnvironment) {
92114
launcherType = LauncherType.GRADLE;
93115
}
116+
if (wronglyInstalledUnrecoverable) return;
94117
foxClassLoader = new FoxClassLoader();
95118
foxClassLoader.addTransformerExclusion("org.objectweb.asm.");
96119
foxClassLoader.addTransformerExclusion("org.spongepowered.asm.");

common/src/main/java/com/fox2code/foxloader/launcher/LauncherType.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,32 @@ public enum LauncherType {
77
/**
88
* Ex: Server ran via --server
99
*/
10-
UNKNOWN,
10+
UNKNOWN(false),
11+
/**
12+
* BIN is a special broken case that can happen on MultiMC
13+
* when users lacks the mental capabilities to run a jar file
14+
*/
15+
BIN(false),
1116
/**
1217
* Ex: Dev environment.
1318
*/
14-
GRADLE,
19+
GRADLE(false),
1520
/**
1621
* Ex: Vanilla launcher & Pojav launcher
1722
*/
18-
VANILLA_LIKE,
23+
VANILLA_LIKE(false),
1924
/**
2025
* Ex: BetaCraft launcher.
2126
*/
22-
BETA_CRAFT,
27+
BETA_CRAFT(true),
2328
/**
2429
* Ex: MultiMC/PolyMC/PrismLauncher
2530
*/
26-
MMC_LIKE
31+
MMC_LIKE(true);
32+
33+
public final boolean hasAutoFix;
34+
35+
LauncherType(boolean hasAutoFix) {
36+
this.hasAutoFix = hasAutoFix;
37+
}
2738
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fox2code.foxloader.launcher.utils;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.io.OutputStream;
6+
7+
public class IOUtils {
8+
public static void copyAndClose(InputStream inputStream, OutputStream outputStream) throws IOException {
9+
try (InputStream is = inputStream;
10+
OutputStream out = outputStream) {
11+
byte[] byteChunk = new byte[4096];
12+
int n;
13+
14+
while ((n = is.read(byteChunk)) > 0) {
15+
out.write(byteChunk, 0, n);
16+
}
17+
}
18+
}
19+
}

common/src/main/java/com/fox2code/foxloader/loader/ModLoaderMixin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ static void initializeMixin(boolean client) {
2727
.setOption(MixinEnvironment.Option.DEBUG_INJECTORS, true);
2828
MixinEnvironment.getCurrentEnvironment()
2929
.setOption(MixinEnvironment.Option.DEBUG_VERBOSE, true);
30+
for (MixinEnvironment.Phase phase : new MixinEnvironment.Phase[]{
31+
MixinEnvironment.Phase.PREINIT, MixinEnvironment.Phase.INIT, MixinEnvironment.Phase.DEFAULT}) {
32+
MixinEnvironment.getEnvironment(phase).setSide(client ?
33+
MixinEnvironment.Side.CLIENT : MixinEnvironment.Side.SERVER);
34+
}
3035
MixinEnvironment.getCurrentEnvironment().setSide(client ?
3136
MixinEnvironment.Side.CLIENT : MixinEnvironment.Side.SERVER);
3237
MixinBootstrap.getPlatform().inject();

common/src/main/java/com/fox2code/foxloader/registry/RegisteredItemStack.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ public interface RegisteredItemStack extends GameRegistry.Ingredient {
1414
default String getRegisteredDisplayName() { throw new RuntimeException(); }
1515

1616
default void setRegisteredDisplayName(String displayName) { throw new RuntimeException(); }
17+
18+
default void verifyRegisteredItemStack() { throw new RuntimeException(); }
1719
}

common/src/main/java/com/fox2code/foxloader/updater/UpdateManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fox2code.foxloader.updater;
22

3+
import com.fox2code.foxloader.launcher.FoxLauncher;
4+
import com.fox2code.foxloader.launcher.LauncherType;
35
import com.fox2code.foxloader.loader.FLJitPackUpdater;
46
import com.fox2code.foxloader.loader.ModContainer;
57
import com.fox2code.foxloader.loader.ModLoader;
@@ -96,6 +98,20 @@ private synchronized void checkUpdates0() {
9698
}
9799
this.hasUpdates = hasUpdates;
98100
this.checkingUpdates = false;
101+
// If FoxLoader is wrongly installed, try to fix it
102+
if (FoxLauncher.isWronglyInstalled() &&
103+
FoxLauncher.getLauncherType().hasAutoFix) {
104+
System.out.println("It look like you were too incompetent to install FoxLoader properly");
105+
System.out.println("But don't worry, FoxLoader will install itself properly on the current instance");
106+
AbstractUpdater abstractUpdater = modsToUpdater.get("foxloader");
107+
if (abstractUpdater != null) {
108+
try {
109+
abstractUpdater.doUpdate();
110+
} catch (IOException e) {
111+
e.printStackTrace();
112+
}
113+
}
114+
}
99115
}
100116

101117
public synchronized void doUpdates() {

0 commit comments

Comments
 (0)