From bc23e7a6570c5dc1baf734b9b7c8aa87c0dcc675 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Mon, 14 May 2012 18:21:35 -0400 Subject: [PATCH] Fix up fubar in worldprovider. Add in obfuscation detection. Capture the exception that crashes minecraft in the log file. --- .../cpw/mods/fml/client/FMLClientHandler.java | 2 ++ .../cpw/mods/fml/common/ReflectionHelper.java | 23 +++++++++++++++---- .../modloader/ModLoaderModContainer.java | 4 ++-- .../minecraft/src/PanelCrashReport.java.patch | 15 ++++++++++-- .../minecraft/src/WorldProvider.java.patch | 2 +- .../cpw/mods/fml/server/FMLServerHandler.java | 2 ++ 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/fml/client/cpw/mods/fml/client/FMLClientHandler.java b/fml/client/cpw/mods/fml/client/FMLClientHandler.java index dedf41f497..7cc16d5557 100644 --- a/fml/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/client/cpw/mods/fml/client/FMLClientHandler.java @@ -71,6 +71,7 @@ import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.ModContainer.TickType; import cpw.mods.fml.common.ModMetadata; +import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.common.modloader.ModLoaderHelper; import cpw.mods.fml.common.modloader.ModLoaderModContainer; @@ -162,6 +163,7 @@ public class FMLClientHandler implements IFMLSidedHandler // We're safe. continue }*/ client = minecraft; + ReflectionHelper.detectObfuscation(World.class); FMLCommonHandler.instance().registerSidedDelegate(this); CommonRegistry.registerRegistry(new ClientRegistry()); Loader.instance().loadMods(); diff --git a/fml/common/cpw/mods/fml/common/ReflectionHelper.java b/fml/common/cpw/mods/fml/common/ReflectionHelper.java index 00e7a63458..30bc523448 100644 --- a/fml/common/cpw/mods/fml/common/ReflectionHelper.java +++ b/fml/common/cpw/mods/fml/common/ReflectionHelper.java @@ -13,6 +13,7 @@ package cpw.mods.fml.common; import java.lang.reflect.Field; +import java.lang.reflect.Method; /** * Some reflection helper code. * @@ -21,6 +22,8 @@ import java.lang.reflect.Field; */ public class ReflectionHelper { + public static boolean obfuscation; + @SuppressWarnings("unchecked") public static T getPrivateValue(Class classToAccess, E instance, int fieldIndex) { @@ -49,8 +52,10 @@ public class ReflectionHelper } catch (Exception e) { - FMLCommonHandler.instance().getFMLLogger().severe(String.format("There was a problem getting field %s from %s", fieldName, classToAccess.getName())); - FMLCommonHandler.instance().getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); + if ((fieldName.length() > 3 && !obfuscation) || (fieldName.length() <= 3 && obfuscation)) { + FMLCommonHandler.instance().getFMLLogger().severe(String.format("There was a problem getting field %s from %s", fieldName, classToAccess.getName())); + FMLCommonHandler.instance().getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); + } throw new RuntimeException(e); } } @@ -81,10 +86,20 @@ public class ReflectionHelper } catch (Exception e) { - FMLCommonHandler.instance().getFMLLogger().severe(String.format("There was a problem setting field %s from %s", fieldName, classToAccess.getName())); - FMLCommonHandler.instance().getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); + if ((fieldName.length() > 3 && !obfuscation) || (fieldName.length() <= 3 && obfuscation)) { + FMLCommonHandler.instance().getFMLLogger().severe(String.format("There was a problem setting field %s from %s", fieldName, classToAccess.getName())); + FMLCommonHandler.instance().getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e); + } throw new RuntimeException(e); } } + /** + * + */ + public static void detectObfuscation(Class clazz) + { + obfuscation=!clazz.getSimpleName().equals("World"); + } + } diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java index 75ee8d6dfc..cd4b27a824 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java @@ -352,7 +352,7 @@ public class ModLoaderModContainer implements ModContainer @Override public String getName() { - return mod != null ? mod.getName() : getSource().getName(); + return mod != null ? mod.getName() : modClazz.getSimpleName(); } public static ModContainer findContainerFor(BaseMod mod) @@ -555,7 +555,7 @@ public class ModLoaderModContainer implements ModContainer public String toString() { - return modSource.getName(); + return modClazz.getSimpleName(); } @Override diff --git a/fml/patches/minecraft/net/minecraft/src/PanelCrashReport.java.patch b/fml/patches/minecraft/net/minecraft/src/PanelCrashReport.java.patch index 7d557a0a89..6c94439c13 100644 --- a/fml/patches/minecraft/net/minecraft/src/PanelCrashReport.java.patch +++ b/fml/patches/minecraft/net/minecraft/src/PanelCrashReport.java.patch @@ -1,15 +1,26 @@ --- ../src-base/minecraft/net/minecraft/src/PanelCrashReport.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src-work/minecraft/net/minecraft/src/PanelCrashReport.java 0000-00-00 00:00:00.000000000 -0000 -@@ -12,6 +12,8 @@ +@@ -9,13 +9,19 @@ + import java.io.StringWriter; + import java.text.SimpleDateFormat; + import java.util.Date; ++import java.util.logging.Level; ++ import org.lwjgl.Sys; import org.lwjgl.opengl.GL11; ++import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; + public class PanelCrashReport extends Panel { public PanelCrashReport(UnexpectedThrowable p_i634_1_) -@@ -43,7 +45,7 @@ + { ++ FMLCommonHandler.instance().getFMLLogger().log(Level.SEVERE, "A critical error has occurred.", p_i634_1_.field_6514_b); + this.setBackground(new Color(3028036)); + this.setLayout(new BorderLayout()); + StringWriter var2 = new StringWriter(); +@@ -43,7 +49,7 @@ var5 = var5 + "\n"; var5 = var5 + var3; diff --git a/fml/patches/minecraft/net/minecraft/src/WorldProvider.java.patch b/fml/patches/minecraft/net/minecraft/src/WorldProvider.java.patch index 3b5ff52818..76021b56d9 100644 --- a/fml/patches/minecraft/net/minecraft/src/WorldProvider.java.patch +++ b/fml/patches/minecraft/net/minecraft/src/WorldProvider.java.patch @@ -12,7 +12,7 @@ - { - this.field_4215_b = new WorldChunkManager(this.field_4216_a); - } -+ this.field_46067_b.getChunkManager(field_4216_a); ++ this.field_4215_b=this.field_46067_b.getChunkManager(field_4216_a); } public IChunkProvider func_4094_c() diff --git a/fml/server/cpw/mods/fml/server/FMLServerHandler.java b/fml/server/cpw/mods/fml/server/FMLServerHandler.java index cfe758c3d7..bb9ddd3f06 100644 --- a/fml/server/cpw/mods/fml/server/FMLServerHandler.java +++ b/fml/server/cpw/mods/fml/server/FMLServerHandler.java @@ -48,6 +48,7 @@ import cpw.mods.fml.common.IFMLSidedHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.ModMetadata; +import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.common.modloader.ModLoaderModContainer; /** @@ -123,6 +124,7 @@ public class FMLServerHandler implements IFMLSidedHandler // We're safe. continue } server = minecraftServer; + ReflectionHelper.detectObfuscation(World.class); FMLCommonHandler.instance().registerSidedDelegate(this); CommonRegistry.registerRegistry(new ServerRegistry()); Loader.instance().loadMods();