Skip to content

Commit

Permalink
Bump 2.4: Added new module modFixes + Fixes #9
Browse files Browse the repository at this point in the history
- First mod fix: prevent `ArrayIndexOutOfBoundsException` from occurring in `BlockIEBase#getPushReaction` with special cases
  • Loading branch information
Rongmario committed May 13, 2021
1 parent 171e654 commit cb6559b
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 67 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'org.spongepowered.mixin'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.

version = "2.3.1"
version = "2.4"
group = "zone.rong.loliasm" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "loliasm"

Expand Down Expand Up @@ -55,6 +55,10 @@ repositories {
url "http://chickenbones.net/maven"
}

maven {
url "https://modmaven.k-4u.nl/"
}

// maven {
// url = "http://maven.bluexin.be/repository/snapshots/"
// }
Expand All @@ -80,6 +84,8 @@ dependencies {

compile 'codechicken:ChickenASM:1.12-1.0.2.9'

deobfCompile "blusunrize:ImmersiveEngineering:0.12-92-+"

// compile "com.teamwizardry.librarianlib:librarianlib-1.12:4.0-SNAPSHOT:deobf"

}
Expand Down
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# LoliASM Changelog

## 2.4
- Added new module `modFixes`.
- Prevent `ArrayIndexOutOfBoundsException` from occurring in `BlockIEBase#getPushReaction` with special cases.
- Fixes incompatibility with *Wings* because Wings' coremod loads some Forge classes too early for us to mixin into.

## 2.3.1
- Fixes `bakedQuadPatchClasses` not being properly targetted by mixins. This means, LoliASM now requires MixinBooter. It was going to some time down the line anyways.
- Fixes `bakedQuadPatchClasses` not being properly targeted by mixins. This means, LoliASM now requires MixinBooter. It was going to some time down the line anyways.
- Added `miscOptimizations` => aims to optimize smaller areas of the game, nothing game-breaking will be introduced under this.
- `FluidRegistryMixin` => first of `miscOptimizations`, quicker check @ `FluidRegistry::enableUniversalBucket`
- Some more logging
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package zone.rong.loliasm.common.modfixes.mixins;

import blusunrize.immersiveengineering.common.blocks.BlockIEBase;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.state.IBlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(BlockIEBase.class)
public abstract class BlockIEBaseMixin {

@Shadow public abstract int getMetaFromState(IBlockState state);
@Shadow(remap = false) protected EnumPushReaction[] metaMobilityFlags;

/**
* @author Rongmario
* @reason Fixes ArrayIndexOutOfBoundsException
*/
@Overwrite
public EnumPushReaction getPushReaction(IBlockState state) {
int meta = getMetaFromState(state);
if (metaMobilityFlags.length <= meta || metaMobilityFlags[meta] == null) {
return EnumPushReaction.NORMAL;
}
return metaMobilityFlags[meta];
}

}
12 changes: 9 additions & 3 deletions src/main/java/zone/rong/loliasm/config/LoliConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public static class Data {
@Ignore final String miscOptimizationsComment = "Other optimization tweaks. Nothing that is experimental or has breaking changes would be classed under this.";
@Since("2.3.1") public final boolean miscOptimizations;

@Ignore final String modFixesComment = "Various mod fixes and optimizations.";
@Since("2.4") public final boolean modFixes;

public Data(String version,
boolean bakedQuadsSquasher,
boolean logClassesThatNeedPatching,
Expand All @@ -66,7 +69,8 @@ public Data(String version,
boolean optimizeDataStructures,
boolean optimizeFurnaceRecipes,
boolean optimizeBitsOfRendering,
boolean miscOptimizations) {
boolean miscOptimizations,
boolean modFixes) {
this.VERSION = version;
this.bakedQuadsSquasher = bakedQuadsSquasher;
this.logClassesThatNeedPatching = logClassesThatNeedPatching;
Expand All @@ -78,6 +82,7 @@ public Data(String version,
this.optimizeFurnaceRecipes = optimizeFurnaceRecipes;
this.optimizeBitsOfRendering = optimizeBitsOfRendering;
this.miscOptimizations = miscOptimizations;
this.modFixes = modFixes;
}
}

Expand All @@ -104,7 +109,7 @@ public boolean shouldSkipClass(Class<?> clazz) {
try {
configFile.createNewFile();
try (FileWriter writer = new FileWriter(configFile)) {
config = new Data(LoliLoadingPlugin.VERSION, true, true, new String[] { "net.minecraft.client.renderer.block.model.FaceBakery" }, true, true, true, true, true, true, true);
config = new Data(LoliLoadingPlugin.VERSION, true, true, new String[] { "net.minecraft.client.renderer.block.model.FaceBakery" }, true, true, true, true, true, true, true, true);
gson.toJson(config, writer);
}
} catch (IOException e) {
Expand All @@ -125,13 +130,14 @@ public boolean shouldSkipClass(Class<?> clazz) {
config.optimizeDataStructures,
config.optimizeFurnaceRecipes,
true,
true,
true);
try (FileWriter writer = new FileWriter(configFile)) {
gson.toJson(config, writer);
}
} else if (isVersionOutdated(config.VERSION, LoliLoadingPlugin.VERSION)) {
LoliLogger.instance.info("Config outdated, updating config from version {} to {}.", config.VERSION, LoliLoadingPlugin.VERSION);
MethodHandle dataCtor = LoliReflector.resolveCtor(Data.class, String.class, boolean.class, boolean.class, String[].class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class);
MethodHandle dataCtor = LoliReflector.resolveCtor(Data.class, String.class, boolean.class, boolean.class, String[].class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class, boolean.class);
List<Object> args = new ArrayList<>();
args.add(LoliLoadingPlugin.VERSION);
for (Field field : Data.class.getFields()) {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/zone/rong/loliasm/core/LoliHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package zone.rong.loliasm.core;

import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import net.minecraftforge.fml.common.discovery.ModCandidate;
import zone.rong.loliasm.api.StringPool;

import java.util.Set;

public class LoliHooks {

public static <K> ObjectArraySet<K> createArraySet() {
return new ObjectArraySet<>();
}

public static <K> ObjectOpenHashSet<K> createHashSet() {
return new ObjectOpenHashSet<>();
}

public static void modCandidate$override$addClassEntry(ModCandidate modCandidate, String name, Set<String> foundClasses, Set<String> packages, ASMDataTable table) {
String className = name.substring(0, name.lastIndexOf('.'));
foundClasses.add(className);
className = className.replace('/','.');
int pkgIdx = className.lastIndexOf('.');
if (pkgIdx > -1) {
String pkg = StringPool.canonize(className.substring(0, pkgIdx));
packages.add(pkg);
table.registerPackage(modCandidate, pkg);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion)
public class LoliLoadingPlugin implements IFMLLoadingPlugin {

public static final String VERSION = "2.3.1";
public static final String VERSION = "2.4";

public static final boolean isDeobf = FMLLaunchHandler.isDeobfuscatedEnvironment();
public static final boolean isOptifineInstalled = LoliReflector.doesClassExist("optifine.OptiFineForgeTweaker");
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/zone/rong/loliasm/core/LoliMixinLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
public class LoliMixinLoader {

{
if (LoliConfig.getConfig().bakedQuadsSquasher) {
LoliConfig.Data data = LoliConfig.getConfig();
if (data.bakedQuadsSquasher) {
Mixins.addConfiguration("mixins.bakedquadsquasher.json");
}
if (data.modFixes) {
Mixins.addConfiguration("mixins.modfixes.json");
}
}

}
38 changes: 30 additions & 8 deletions src/main/java/zone/rong/loliasm/core/LoliTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ private byte[] removePackageField(byte[] bytes) {
ClassNode node = new ClassNode();
reader.accept(node, 0);

node.fields.removeIf(f -> f.name.equals("packages"));
node.fields.stream().filter(f -> f.name.equals("packages")).findFirst().ifPresent(f -> {
f.desc = "Ljava/util/Set;";
f.signature = "Ljava/util/Set<Ljava/lang/String;>;";
});

for (MethodNode method : node.methods) {
if (method.name.equals("<init>") && method.desc.equals("(Ljava/io/File;Ljava/io/File;Lnet/minecraftforge/fml/common/discovery/ContainerType;ZZ)V")) {
Expand All @@ -401,18 +404,37 @@ private byte[] removePackageField(byte[] bytes) {
if (instruction.getOpcode() == PUTFIELD) {
FieldInsnNode fieldNode = (FieldInsnNode) instruction;
if (fieldNode.name.equals("packages")) {
iter.remove(); // PUTFIELD
fieldNode.desc = "Ljava/util/Set;";
iter.previous();
iter.remove(); // INVOKESTATIC
iter.previous();
iter.remove(); // ALOAD
iter.previous();
iter.remove(); // LINENUMBER
iter.previous();
iter.remove(); // LABEL
iter.set(new MethodInsnNode(INVOKESTATIC, "zone/rong/loliasm/core/LoliHooks", "createHashSet", "()Lit/unimi/dsi/fastutil/objects/ObjectOpenHashSet;", false));
break;
}
}
}
} else if (method.name.equals("addClassEntry")) { // see: LoliHooks::modCandidate$override$addClassEntry
method.instructions.clear();
method.instructions.add(new VarInsnNode(ALOAD, 0));
method.instructions.add(new VarInsnNode(ALOAD, 1));
method.instructions.add(new VarInsnNode(ALOAD, 0));
method.instructions.add(new FieldInsnNode(GETFIELD, "net/minecraftforge/fml/common/discovery/ModCandidate", "foundClasses", "Ljava/util/Set;"));
method.instructions.add(new VarInsnNode(ALOAD, 0));
method.instructions.add(new FieldInsnNode(GETFIELD, "net/minecraftforge/fml/common/discovery/ModCandidate", "packages", "Ljava/util/Set;"));
method.instructions.add(new VarInsnNode(ALOAD, 0));
method.instructions.add(new FieldInsnNode(GETFIELD, "net/minecraftforge/fml/common/discovery/ModCandidate", "table", "Lnet/minecraftforge/fml/common/discovery/ASMDataTable;"));
method.instructions.add(new MethodInsnNode(INVOKESTATIC, "zone/rong/loliasm/core/LoliHooks", "modCandidate$override$addClassEntry", "(Lnet/minecraftforge/fml/common/discovery/ModCandidate;Ljava/lang/String;Ljava/util/Set;Ljava/util/Set;Lnet/minecraftforge/fml/common/discovery/ASMDataTable;)V", false));
method.instructions.add(new InsnNode(RETURN));
} else if (method.name.equals("getContainedPackages")) { // Return ArrayList with Set elements
ListIterator<AbstractInsnNode> iter = method.instructions.iterator();
while (iter.hasNext()) {
AbstractInsnNode instruction = iter.next();
if (instruction.getOpcode() == GETFIELD) {
FieldInsnNode fieldNode = (FieldInsnNode) instruction;
fieldNode.desc = "Ljava/util/Set;";
iter.add(new MethodInsnNode(INVOKESTATIC, "com/google/common/collect/Lists", "newArrayList", "(Ljava/lang/Iterable;)Ljava/util/ArrayList;", false));
break;
}
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/mixins.memory.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"LockCodeMixin",
"ModCandidateMixin"
"LockCodeMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/mixins.modfixes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"package": "zone.rong.loliasm.common.modfixes.mixins",
"refmap": "mixins.loliasm.refmap.json",
"target": "@env(DEFAULT)",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"BlockIEBaseMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit cb6559b

Please sign in to comment.