Skip to content

Commit

Permalink
Update 1.2.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Sep 11, 2023
1 parent 3e14bc9 commit 18d99df
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import com.fox2code.foxloader.registry.RegisteredItemStack;
import net.minecraft.src.game.item.Item;
import net.minecraft.src.game.item.ItemStack;
import net.minecraft.src.game.nbt.NBTTagCompound;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

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

@Inject(method = "<init>(II)V", at = @At("RETURN"))
public void onNewItemStack(int id, int count, CallbackInfo ci) {
this.verifyRegisteredItemStack();
}

@Inject(method = "<init>(III)V", at = @At("RETURN"))
public void onNewItemStack(int id, int count, int damage, CallbackInfo ci) {
this.verifyRegisteredItemStack();
}

@Inject(method = "<init>(IIILnet/minecraft/src/game/nbt/NBTTagCompound;)V", at = @At("RETURN"))
public void onNewItemStack(int id, int count, int damage, NBTTagCompound tagCompound, CallbackInfo ci) {
this.verifyRegisteredItemStack();
}

@Inject(method = "readFromNBT", at = @At("RETURN"))
public void onReadFromNBT(NBTTagCompound nbtTagCompound, CallbackInfo ci) {
this.verifyRegisteredItemStack();
}

@Inject(method = "splitStack", at = @At("RETURN"))
public void onSplitStack(int stacksize, CallbackInfoReturnable<ItemStack> cir) {
((NetworkItemStack) (Object) cir.getReturnValue()).setRemoteNetworkId(this.networkId);
Expand Down Expand Up @@ -82,4 +104,12 @@ public int getRemoteItemId() {
public void setRemoteNetworkId(int networkId) {
this.networkId = networkId;
}

@Override
public void verifyRegisteredItemStack() {
if (this.itemID != 0 && this.stackSize <= 0) {
this.itemDamage = 0;
this.itemID = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class ClientMain {
private static final File currentLoaderFile = SourceUtil.getSourceFile(ClientMain.class);
public static boolean hasBetaCraftDiscordRPC = false;
public static boolean isFoxLoaderBadlyInstalled = false;

/**
* This is executed by FoxLoader BetaCraft wrapper.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.fox2code.foxloader.loader;

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 All @@ -15,6 +17,9 @@
import net.minecraft.src.client.gui.StringTranslate;

import java.io.*;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.function.Function;

Expand Down Expand Up @@ -112,8 +117,17 @@ void loaderHandleDoFoxLoaderUpdate(String version, String url) throws IOExceptio
}
dest = new File(ModLoader.updateTmp, "foxloader-" + version + ".jar");
}
try (FileOutputStream fileOutputStream = new FileOutputStream(dest)) {
NetUtils.downloadTo(url, fileOutputStream);
if (BuildConfig.FOXLOADER_VERSION.equals(version) &&
FoxLauncher.getLauncherType() != LauncherType.BIN) {
// Can happen if wrongly installed
if (!dest.equals(FoxLauncher.foxLoaderFile)) {
Files.copy(FoxLauncher.foxLoaderFile.toPath(), dest.toPath(),
StandardCopyOption.REPLACE_EXISTING);
}
} else {
try (FileOutputStream fileOutputStream = new FileOutputStream(dest)) {
NetUtils.downloadTo(url, fileOutputStream);
}
}
args[0] = Platform.getPlatform().javaBin.getPath();
args[2] = dest.getAbsolutePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GSON_DEPENDENCY, new Dependency("com.google.guava:guava:21.0", MAVEN_CENTRAL, "c

public static final Dependency[] clientDependencies = new Dependency[]{
new Dependency("net.silveros:reindev:" + BuildConfig.REINDEV_VERSION,
BuildConfig.CLIENT_URL, "net.minecraft.client.Minecraft")
BuildConfig.CLIENT_URL, "net.minecraft.src.client.MinecraftImpl")
};
public static final Dependency[] serverDependencies = new Dependency[]{
new Dependency("net.silveros:reindev-server:" + BuildConfig.REINDEV_VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,39 @@ public class FoxLauncher {
public static final File foxLoaderFile = SourceUtil.getSourceFile(FoxLauncher.class);
public static final HashMap<String, Object> mixinProperties = new HashMap<>();
static LauncherType launcherType = LauncherType.UNKNOWN;
private static boolean client;
private static boolean client, wronglyInstalled, wronglyInstalledUnrecoverable;
static FoxClassLoader foxClassLoader;
static File gameDir;
public static String initialUsername;
public static String initialSessionId;

public static void markWronglyInstalled() {
if (foxClassLoader == null) wronglyInstalled = true;
}

public static void markWronglyInstalledUnrecoverable() {
if (foxClassLoader == null) {
wronglyInstalledUnrecoverable = true;
initForClientFromArgs(new String[0]);
wronglyInstalled = true;
}
}

public static boolean isWronglyInstalled() {
return (client && wronglyInstalled) ||
wronglyInstalledUnrecoverable;
}

static void initForClientFromArgs(String[] args) {
if (foxClassLoader != null)
throw new IllegalStateException("FoxClassLoader already initialized!");
if (wronglyInstalled && wronglyInstalledUnrecoverable)
throw new IllegalStateException("FoxClassLoader cannot initialize!");
client = true;
File gameDir = null;
if (args.length < 2) {
initialUsername = // Allow username defines
args.length < 1 ? "Player" : args[0];
args.length == 0 ? "Player" : args[0];
initialSessionId = "-";
} else {
initialUsername = args[0];
Expand All @@ -68,6 +87,7 @@ static void initForClientFromArgs(String[] args) {
if (LoggerHelper.devEnvironment) {
launcherType = LauncherType.GRADLE;
}
if (wronglyInstalledUnrecoverable) return;
foxClassLoader = new FoxClassLoader();
foxClassLoader.addTransformerExclusion("org.lwjgl.");
foxClassLoader.addTransformerExclusion("org.objectweb.asm.");
Expand All @@ -82,6 +102,8 @@ static void initForClientFromArgs(String[] args) {
static void initForServerFromArgs(String[] args) {
if (foxClassLoader != null)
throw new IllegalStateException("FoxClassLoader already initialized!");
if (wronglyInstalled && wronglyInstalledUnrecoverable)
throw new IllegalStateException("FoxClassLoader cannot initialize!");
client = false;
FoxLauncher.gameDir = new File("").getAbsoluteFile();
// Special case for development environment.
Expand All @@ -91,6 +113,7 @@ static void initForServerFromArgs(String[] args) {
if (LoggerHelper.devEnvironment) {
launcherType = LauncherType.GRADLE;
}
if (wronglyInstalledUnrecoverable) return;
foxClassLoader = new FoxClassLoader();
foxClassLoader.addTransformerExclusion("org.objectweb.asm.");
foxClassLoader.addTransformerExclusion("org.spongepowered.asm.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,32 @@ public enum LauncherType {
/**
* Ex: Server ran via --server
*/
UNKNOWN,
UNKNOWN(false),
/**
* BIN is a special broken case that can happen on MultiMC
* when users lacks the mental capabilities to run a jar file
*/
BIN(false),
/**
* Ex: Dev environment.
*/
GRADLE,
GRADLE(false),
/**
* Ex: Vanilla launcher & Pojav launcher
*/
VANILLA_LIKE,
VANILLA_LIKE(false),
/**
* Ex: BetaCraft launcher.
*/
BETA_CRAFT,
BETA_CRAFT(true),
/**
* Ex: MultiMC/PolyMC/PrismLauncher
*/
MMC_LIKE
MMC_LIKE(true);

public final boolean hasAutoFix;

LauncherType(boolean hasAutoFix) {
this.hasAutoFix = hasAutoFix;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.fox2code.foxloader.launcher.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class IOUtils {
public static void copyAndClose(InputStream inputStream, OutputStream outputStream) throws IOException {
try (InputStream is = inputStream;
OutputStream out = outputStream) {
byte[] byteChunk = new byte[4096];
int n;

while ((n = is.read(byteChunk)) > 0) {
out.write(byteChunk, 0, n);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ static void initializeMixin(boolean client) {
.setOption(MixinEnvironment.Option.DEBUG_INJECTORS, true);
MixinEnvironment.getCurrentEnvironment()
.setOption(MixinEnvironment.Option.DEBUG_VERBOSE, true);
for (MixinEnvironment.Phase phase : new MixinEnvironment.Phase[]{
MixinEnvironment.Phase.PREINIT, MixinEnvironment.Phase.INIT, MixinEnvironment.Phase.DEFAULT}) {
MixinEnvironment.getEnvironment(phase).setSide(client ?
MixinEnvironment.Side.CLIENT : MixinEnvironment.Side.SERVER);
}
MixinEnvironment.getCurrentEnvironment().setSide(client ?
MixinEnvironment.Side.CLIENT : MixinEnvironment.Side.SERVER);
MixinBootstrap.getPlatform().inject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface RegisteredItemStack extends GameRegistry.Ingredient {
default String getRegisteredDisplayName() { throw new RuntimeException(); }

default void setRegisteredDisplayName(String displayName) { throw new RuntimeException(); }

default void verifyRegisteredItemStack() { throw new RuntimeException(); }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fox2code.foxloader.updater;

import com.fox2code.foxloader.launcher.FoxLauncher;
import com.fox2code.foxloader.launcher.LauncherType;
import com.fox2code.foxloader.loader.FLJitPackUpdater;
import com.fox2code.foxloader.loader.ModContainer;
import com.fox2code.foxloader.loader.ModLoader;
Expand Down Expand Up @@ -96,6 +98,20 @@ private synchronized void checkUpdates0() {
}
this.hasUpdates = hasUpdates;
this.checkingUpdates = false;
// If FoxLoader is wrongly installed, try to fix it
if (FoxLauncher.isWronglyInstalled() &&
FoxLauncher.getLauncherType().hasAutoFix) {
System.out.println("It look like you were too incompetent to install FoxLoader properly");
System.out.println("But don't worry, FoxLoader will install itself properly on the current instance");
AbstractUpdater abstractUpdater = modsToUpdater.get("foxloader");
if (abstractUpdater != null) {
try {
abstractUpdater.doUpdate();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

public synchronized void doUpdates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fox2code.foxloader.launcher.DependencyHelper;
import com.fox2code.foxloader.launcher.LauncherType;
import com.fox2code.foxloader.launcher.StackTraceStringifier;
import com.fox2code.foxloader.launcher.utils.IOUtils;
import com.fox2code.foxloader.launcher.utils.Platform;

import javax.swing.*;
Expand All @@ -13,8 +14,8 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.List;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
Expand All @@ -38,6 +39,8 @@ public class InstallerGUI implements FileDropHelper.FileDropHandler {
private static final String FULLSCREEN_LABEL =
"FoxLoader " + BuildConfig.FOXLOADER_VERSION + " for ReIndev " + BuildConfig.REINDEV_VERSION;
private static final int PROGRESS_BAR_MAX = DependencyHelper.commonDependencies.length + 1;
private static final HashSet<String> MMC_PATCHES = new HashSet<>(Arrays.asList(
"com.fox2code.foxloader.json", "net.minecraft.json", "net.minecraftforge.json"));
private final InstallerPlatform installerPlatform;
private final LauncherType launcherType;
private final JFrame jFrame;
Expand Down Expand Up @@ -251,9 +254,9 @@ public void installMineCraft() {

try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
copyAndClose(InstallerGUI.class.getResourceAsStream(
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
"/launcher-version.json"), byteArrayOutputStream);
copyAndClose(new ByteArrayInputStream(byteArrayOutputStream.toString()
IOUtils.copyAndClose(new ByteArrayInputStream(byteArrayOutputStream.toString()
.replace(installerPlatform.specialLauncher ?
"#hack_releaseTime#" : "#no-op#", "releaseTime")
.replace("#version#", this.versionName).getBytes(StandardCharsets.UTF_8)),
Expand Down Expand Up @@ -343,7 +346,7 @@ public void installBetaCraftEx(File betaCraft) {
}
printStream.println("addons:");
}
copyAndClose(InstallerGUI.class.getResourceAsStream(
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
"/betacraft-" + BuildConfig.FOXLOADER_VERSION + ".jar"),
Files.newOutputStream(foxLoaderBetaCraft.toPath()));
} catch (IOException e) {
Expand Down Expand Up @@ -374,7 +377,7 @@ public void extractMMCInstance() {
"instance.cfg", "mmc-pack.json"}) {
zipOutputStream.putNextEntry(new ZipEntry(entry));
byteArrayOutputStream.reset();
copyAndClose(InstallerGUI.class.getResourceAsStream(
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
"/mmc/" + entry), byteArrayOutputStream);
copy(new ByteArrayInputStream(byteArrayOutputStream.toString()
.replace("#version#", this.versionName)
Expand Down Expand Up @@ -423,19 +426,34 @@ public void doSilentInstall(String arg) throws IOException {
break;
}
case MMC_LIKE: {
File patches = new File(Main.currentInstallerFile.getParentFile().getParentFile(), "patches");
File root = Main.currentInstallerFile.getParentFile().getParentFile();
File patches = new File(root, "patches");
File patch = new File(patches, "com.fox2code.foxloader.json");
if (!patch.exists()) {
if (!patches.exists()) {
System.exit(-1);
return;
}
if (!patch.exists()) {
for (File file : Objects.requireNonNull(patches.listFiles())) {
if (file.getName().endsWith(".json") &&
!MMC_PATCHES.contains(file.getName())) {
if (!file.delete()) file.deleteOnExit();
}
}
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
copyAndClose(InstallerGUI.class.getResourceAsStream(
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
"/mmc/patches/com.fox2code.foxloader.json"), byteArrayOutputStream);
copyAndClose(new ByteArrayInputStream(byteArrayOutputStream.toString()
IOUtils.copyAndClose(new ByteArrayInputStream(byteArrayOutputStream.toString()
.replace("#version#", this.versionName)
.replace("#foxloader_version#", BuildConfig.FOXLOADER_VERSION)
.getBytes(StandardCharsets.UTF_8)), Files.newOutputStream(patch.toPath()));
for (String entry : new String[]{ // Fix in place replace!
"patches/net.minecraft.json", "patches/net.minecraftforge.json"}) {
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
"/mmc/patches/com.fox2code.foxloader.json"),
Files.newOutputStream(new File(entry).toPath()));
}
}
}
}
Expand Down Expand Up @@ -479,18 +497,6 @@ private static void copy(InputStream inputStream, OutputStream outputStream) thr
}
}

private static void copyAndClose(InputStream inputStream, OutputStream outputStream) throws IOException {
try (InputStream is = inputStream;
OutputStream out = outputStream) {
byte[] byteChunk = new byte[4096];
int n;

while ((n = is.read(byteChunk)) > 0) {
out.write(byteChunk, 0, n);
}
}
}

@Override
public boolean areFilesAcceptable(List<File> fileList) {
if (runningTask || fileList.size() != 1) return false;
Expand Down
Loading

0 comments on commit 18d99df

Please sign in to comment.