Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Initial loader 0.7.0 update. May be buggy
Browse files Browse the repository at this point in the history
modmuss50 committed Nov 23, 2019
1 parent d20e331 commit 0af7908
Showing 10 changed files with 60 additions and 30 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -32,13 +32,13 @@ repositories {

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"

modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modCompile "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"
include "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"
modCompile "com.github.modmuss50:Fabric-ASM:${project.fabric_asm_version}"
include "com.github.modmuss50:Fabric-ASM:${project.fabric_asm_version}"

//Used to handle the zip processing
compile "org.zeroturnaround:zt-zip:${project.zt_zip_version}"
9 changes: 4 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -2,15 +2,14 @@
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.14.4
yarn_mappings=1.14.4+build.14
loader_version=0.6.4+build.169
yarn_mappings=1.14.4+build.15
loader_version=0.7.0+build.171

fabric_version=0.4.1+build.245-1.14
fabric_asm_version=697a7c18da
fabric_asm_version=b97939c03a
zt_zip_version=1.13
slf4j_version=1.7.29
stitch_version=0.3.0.66

mod_version = 0.6.0
mod_version = 0.7.0
maven_group = me.modmuss50
archives_base_name = optifabric
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ private void validateIndigoVersion() {

private boolean validateLoaderVersion() {
try {
if (!isVersionValid("fabricloader", ">=0.6.4")) {
if (!isVersionValid("fabricloader", ">=0.7.0")) {
if(!OptifabricError.hasError()){
OptifineVersion.jarType = OptifineVersion.JarType.INCOMPATIBE;
OptifabricError.setError("You are using an outdated version of Fabric Loader, please update!\n\nRe-run the installer, or update via your launcher. See the link for help!", "https://fabricmc.net/wiki/install");
23 changes: 18 additions & 5 deletions src/main/java/me/modmuss50/optifabric/mod/OptifineInjector.java
Original file line number Diff line number Diff line change
@@ -6,16 +6,19 @@
import me.modmuss50.optifabric.patcher.ClassCache;
import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.FrameNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FrameNode;
import org.objectweb.asm.tree.MethodNode;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class OptifineInjector {
@@ -25,6 +28,8 @@ public class OptifineInjector {
String chunkRenderer;
String particleManager;

private static List<String> patched = new ArrayList<>();

public OptifineInjector(ClassCache classCache) {
this.classCache = classCache;
}
@@ -39,6 +44,12 @@ public void setup() throws IOException {
//I have no idea why and how this works, if you know better please let me know
public final Consumer<ClassNode> transformer = target -> {

if(patched.contains(target.name)) {
System.out.println("Already patched" + target.name);
return;
}
patched.add(target.name);

//I cannot imagine this being very good at all
ClassNode source = getSourceClassNode(target);

@@ -75,7 +86,6 @@ public void setup() throws IOException {
target.methods.forEach(methodNode -> methodNode.access = modAccess(methodNode.access));
target.fields.forEach(fieldNode -> fieldNode.access = modAccess(fieldNode.access));
}

};

private static int modAccess(int access) {
@@ -89,6 +99,9 @@ private static int modAccess(int access) {
private ClassNode getSourceClassNode(ClassNode classNode) {
String name = classNode.name.replaceAll("\\.", "/") + ".class";
byte[] bytes = classCache.getAndRemove(name);
if(bytes == null) {
throw new RuntimeException("Failed to find patched class for: " + name);
}
return ASMUtils.readClassFromBytes(bytes);
}

17 changes: 12 additions & 5 deletions src/main/java/me/modmuss50/optifabric/mod/OptifineSetup.java
Original file line number Diff line number Diff line change
@@ -21,14 +21,21 @@
import org.apache.commons.lang3.tuple.Pair;
import org.zeroturnaround.zip.ZipUtil;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class OptifineSetup {
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
import me.modmuss50.optifabric.patcher.ASMUtils;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.main.Main;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.FieldNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.zeroturnaround.zip.ZipUtil;

import java.io.*;
13 changes: 8 additions & 5 deletions src/main/java/me/modmuss50/optifabric/patcher/ASMUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package me.modmuss50.optifabric.patcher;

import org.apache.commons.io.IOUtils;
import org.spongepowered.asm.lib.ClassReader;
import org.spongepowered.asm.lib.ClassWriter;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.apache.commons.lang3.Validate;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;


import java.io.IOException;
import java.io.InputStream;
@@ -14,9 +16,10 @@
public class ASMUtils {

public static ClassNode readClassFromBytes(byte[] bytes) {
Validate.notNull(bytes, "Cannot read null bytes");
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, ClassReader.EXPAND_FRAMES);
classReader.accept(classNode, ClassReader.SKIP_FRAMES);
return classNode;
}

Original file line number Diff line number Diff line change
@@ -2,8 +2,12 @@

import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.MappingResolver;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.*;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;


public class ChunkRendererFix {

3 changes: 3 additions & 0 deletions src/main/java/me/modmuss50/optifabric/patcher/ClassCache.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.modmuss50.optifabric.patcher;

import org.apache.commons.lang3.Validate;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
@@ -24,6 +26,7 @@ public void addClass(String name, byte[] bytes){
if(classes.containsKey(name)){
throw new UnsupportedOperationException(name + " is already in ClassCache");
}
Validate.notNull(bytes, "bytes cannot be null");
classes.put(name, bytes);
}

Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@

import net.fabricmc.tinyremapper.IMappingProvider;
import net.fabricmc.tinyremapper.MemberInstance;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;


import java.io.File;
import java.io.IOException;

0 comments on commit 0af7908

Please sign in to comment.