Removed Reflection Classes from Source entirely

This commit is contained in:
CrushedPixel
2015-05-26 16:32:11 +02:00
parent c44a1dfc14
commit 7eb24e19bc
8 changed files with 5 additions and 17193 deletions

View File

@@ -9,7 +9,6 @@ import eu.crushedpixel.replaymod.holders.KeyframeSet;
import eu.crushedpixel.replaymod.localization.LocalizedResourcePack;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import eu.crushedpixel.replaymod.registry.*;
import eu.crushedpixel.replaymod.renderer.InvisibilityRender;
import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer;
@@ -37,8 +36,6 @@ import org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Queue;
@Mod(modid = ReplayMod.MODID, version = ReplayMod.VERSION)
@@ -81,16 +78,6 @@ public class ReplayMod {
public static RatedFileHandler ratedFileHandler;
public static SpectatorRenderer spectatorRenderer;
private static Field defaultResourcePacksField;
static {
try {
defaultResourcePacksField = Minecraft.class.getDeclaredField(MCPNames.field("field_110449_ao"));
defaultResourcePacksField.setAccessible(true);
} catch(Exception e) {
e.printStackTrace();
}
}
// The instance of your mod that Forge uses.
@Instance(value = "ReplayModID")
public static ReplayMod instance;
@@ -156,9 +143,7 @@ public class ReplayMod {
removeTmcprFiles();
try {
List rps = (List) defaultResourcePacksField.get(mc);
rps.add(new LocalizedResourcePack());
defaultResourcePacksField.set(mc, rps);
mc.defaultResourcePacks.add(new LocalizedResourcePack());
mc.refreshResources();
} catch(Exception e) {
e.printStackTrace();

View File

@@ -8,10 +8,9 @@ import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import eu.crushedpixel.replaymod.registry.ResourceHelper;
import eu.crushedpixel.replaymod.utils.ImageUtils;
import eu.crushedpixel.replaymod.utils.ReplayFile;
import eu.crushedpixel.replaymod.registry.ResourceHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
@@ -98,7 +97,7 @@ public class GuiUploadFile extends GuiScreen {
//If thumb is null, set image to placeholder
if(thumb == null) {
try {
thumb = ImageIO.read(MCPNames.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
thumb = ImageIO.read(GuiUploadFile.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
} catch(Exception e) {
e.printStackTrace();
}

View File

@@ -1,140 +0,0 @@
package eu.crushedpixel.replaymod.reflection;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.io.LineProcessor;
import net.minecraft.launchwrapper.Launch;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
/**
* <p>A helper class for working with obfuscated field names.</p>
* <p>In the development environment the mappings file will automatically loaded. You can provide the location of a custom mappings file by
* providing the system property {@code sevencommons.mappingsFile}.</p>
*
* @author diesieben07
* @author CrushedPixel
*/
public final class MCPNames {
private static final Map<String, String> fields;
private static final Map<String, String> methods;
static {
if(use()) {
InputStream fieldsIs = MCPNames.class.getClassLoader().getResourceAsStream("fields.csv");
InputStream methodsIs = MCPNames.class.getClassLoader().getResourceAsStream("methods.csv");
fields = readMappings(fieldsIs);
methods = readMappings(methodsIs);
} else {
methods = fields = null;
}
}
/**
* <p>Whether the code is running in a development environment or not.</p>
*
* @return true if the code is running in development mode (use MCP instead of SRG names)
*/
public static boolean use() {
return (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
}
/**
* <p>Get the correct name for the given SRG field based on the context.</p>
*
* @param srg the SRG name for a field
* @return the input if the code is running outside of development mode or the matching MCP name otherwise
*/
public static String field(String srg) {
if(use()) {
String mcp = fields.get(srg);
if(mcp == null) {
// no mapping
return srg;
}
return mcp;
} else {
return srg;
}
}
/**
* <p>Get the correct name for the given SRG method based on the context.</p>
*
* @param srg the SRG name for a method
* @return the input if the code is running outside of development mode or the matching MCP name otherwise
*/
public static String method(String srg) {
if(use()) {
String mcp = methods.get(srg);
if(mcp == null) {
// no mapping
return srg;
}
return mcp;
} else {
return srg;
}
}
private static Map<String, String> readMappings(InputStream is) {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
MCPFileParser fileParser = new MCPFileParser();
while(br.ready()) {
fileParser.processLine(br.readLine());
}
return fileParser.getResult();
} catch(IOException e) {
throw new RuntimeException("Could not read SRG->MCP mappings", e);
}
}
private static class MCPFileParser implements LineProcessor<Map<String, String>> {
private static final Splitter splitter = Splitter.on(',').trimResults();
private final Map<String, String> map = Maps.newHashMap();
private boolean foundFirst;
@Override
public boolean processLine(String line) throws IOException {
if(!foundFirst) {
foundFirst = true;
return true;
}
Iterator<String> splitted = splitter.split(line).iterator();
try {
String srg = splitted.next();
String mcp = splitted.next();
if(!map.containsKey(srg)) {
map.put(srg, mcp);
}
} catch(NoSuchElementException e) {
throw new IOException("Invalid Mappings file!", e);
}
return true;
}
@Override
public Map<String, String> getResult() {
return ImmutableMap.copyOf(map);
}
}
}

View File

@@ -1,6 +1,5 @@
package eu.crushedpixel.replaymod.registry;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
@@ -16,7 +15,7 @@ public class ResourceHelper {
static {
try {
defaultThumb = ImageIO.read(MCPNames.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
defaultThumb = ImageIO.read(ResourceHelper.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
} catch(Exception e) {
defaultThumb = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
e.printStackTrace();

View File

@@ -8,6 +8,7 @@ public net.minecraft.client.Minecraft field_71423_H # systemTime
public net.minecraft.client.Minecraft field_71429_W # leftClickCounter
public net.minecraft.client.Minecraft field_71445_n # isGamePaused
public net.minecraft.client.Minecraft field_152351_aB # scheduledTasks
public net.minecraft.client.Minecraft field_110449_ao # defaultResourcePacks
public net.minecraft.client.Minecraft func_71386_F()L # getSystemTime
public net.minecraft.client.Minecraft func_71383_b(I)V # updateDebugProfilerName

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff