Fix up MCP merger - it definitely works now - the game runs and runs well.

Fix up a couple of small network related issues.
Fix up the server launching fml properly.
This commit is contained in:
Christian committed 2012-08-10 10:03:33 -04:00
1 parent ba0cc6ec12
commit 3c1b234a61
9 files changed
+204 -117

No files matched your search

@@ -9,11 +9,12 @@ import cpw.mods.fml.common.versioning.ArtifactVersion;
public class InjectedModContainer implements ModContainer
{
private File source;
private ModContainer wrappedContainer;
public InjectedModContainer(ModContainer mc)
public InjectedModContainer(ModContainer mc, File source)
{
this.source = source;
this.wrappedContainer = mc;
}
@@ -34,7 +35,7 @@ public class InjectedModContainer implements ModContainer
public File getSource()
{
return wrappedContainer.getSource();
return source;
}
public ModMetadata getMetadata()
+2 -1
View File
@@ -254,6 +254,7 @@ public class Loader
private ModDiscoverer identifyMods()
{
FMLLog.fine("Building injected Mod Containers %s", injectedContainers);
File coremod = new File(minecraftDir,"coremods");
for (String cont : injectedContainers)
{
ModContainer mc;
@@ -266,7 +267,7 @@ public class Loader
FMLLog.log(Level.SEVERE, e, "A problem occured instantiating the injected mod container %s", cont);
throw new LoaderException(e);
}
mods.add(new InjectedModContainer(mc));
mods.add(new InjectedModContainer(mc,coremod));
}
ModDiscoverer discoverer = new ModDiscoverer();
FMLLog.fine("Attempting to load mods contained in the minecraft jar file and associated classes");
@@ -9,6 +9,12 @@ import java.util.zip.*;
import org.objectweb.asm.*;
import org.objectweb.asm.tree.*;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
@@ -19,7 +25,7 @@ public class MCPMerger
private static Hashtable<String, ClassInfo> servers = new Hashtable<String, ClassInfo>();
private static HashSet<String> copyToServer = new HashSet<String>();
private static HashSet<String> copyToClient = new HashSet<String>();
public static void main(String[] args)
{
if (args.length != 3)
@@ -27,30 +33,30 @@ public class MCPMerger
System.out.println("Usage: AccessTransformer <MapFile> <minecraft.jar> <minecraft_server.jar>");
return;
}
File map_file = new File(args[0]);
File client_jar = new File(args[1]);
File server_jar = new File(args[2]);
File client_jar_tmp = new File(args[1] + ".MergeBack");
File server_jar_tmp = new File(args[2] + ".MergeBack");
if (client_jar_tmp.exists() && !client_jar_tmp.delete())
{
System.out.println("Could not delete temp file: " + client_jar_tmp);
}
if (server_jar_tmp.exists() && !server_jar_tmp.delete())
{
System.out.println("Could not delete temp file: " + server_jar_tmp);
}
if (!client_jar.exists())
{
System.out.println("Could not find minecraft.jar: " + client_jar);
return;
}
if (!server_jar.exists())
{
System.out.println("Could not find minecraft_server.jar: " + server_jar);
@@ -68,7 +74,7 @@ public class MCPMerger
System.out.println("Could not rename file: " + server_jar + " -> " + server_jar_tmp);
return;
}
if (!readMapFile(map_file))
{
System.out.println("Could not read map file: " + map_file);
@@ -83,18 +89,18 @@ public class MCPMerger
{
e.printStackTrace();
}
if (!client_jar_tmp.delete())
{
System.out.println("Could not delete temp file: " + client_jar_tmp);
}
if (!server_jar_tmp.delete())
{
System.out.println("Could not delete temp file: " + server_jar_tmp);
}
}
private static boolean readMapFile(File mapFile)
{
try
@@ -102,7 +108,7 @@ public class MCPMerger
FileInputStream fstream = new FileInputStream(mapFile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = br.readLine()) != null)
{
@@ -111,7 +117,7 @@ public class MCPMerger
if (toClient) copyToClient.add(line);
else copyToServer.add(line);
}
in.close();
return true;
}
@@ -151,13 +157,13 @@ public class MCPMerger
}
Hashtable<String, ZipEntry> cClasses = getClassEntries(cInJar, cOutJar);
Hashtable<String, ZipEntry> sClasses = getClassEntries(sInJar, sOutJar);
for (Entry<String, ZipEntry> entry : cClasses.entrySet())
{
String name = entry.getKey();
ZipEntry cEntry = entry.getValue();
ZipEntry sEntry = sClasses.get(name);
if (sEntry == null)
{
if (!copyToServer.contains(name))
@@ -171,7 +177,7 @@ public class MCPMerger
}
continue;
}
sClasses.remove(name);
ClassInfo info = new ClassInfo(name);
shared.put(name, info);
@@ -187,7 +193,7 @@ public class MCPMerger
sOutJar.write(data);
}
for (Entry<String, ZipEntry> entry : sClasses.entrySet())
{
{
if (!copyToClient.contains(entry.getKey()))
{
copyEntry(sInJar, entry.getValue(), sOutJar);
@@ -198,7 +204,7 @@ public class MCPMerger
copyClass(sInJar, entry.getValue(), cOutJar, sOutJar, false);
}
}
for (String name : new String[]{SideOnly.class.getName(), Side.class.getName()})
{
byte[] data = getClassBytes(name);
@@ -208,7 +214,7 @@ public class MCPMerger
sOutJar.putNextEntry(newEntry);
sOutJar.write(data);
}
}
finally
{
@@ -232,7 +238,7 @@ public class MCPMerger
}
}
}
private static void copyClass(ZipFile inJar, ZipEntry entry, ZipOutputStream outJar, ZipOutputStream outJar2, boolean isClientOnly) throws IOException
{
ClassReader reader = new ClassReader(readEntry(inJar, entry));
@@ -241,7 +247,7 @@ public class MCPMerger
reader.accept(classNode, 0);
if (classNode.visibleAnnotations == null) classNode.visibleAnnotations = new ArrayList<AnnotationNode>();
classNode.visibleAnnotations.add(getSideAnn(isClientOnly));
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
byte[] data = writer.toByteArray();
@@ -252,7 +258,7 @@ public class MCPMerger
outJar2.putNextEntry(newEntry);
outJar2.write(data);
}
private static AnnotationNode getSideAnn(boolean isClientOnly)
{
AnnotationNode ann = new AnnotationNode(Type.getDescriptor(SideOnly.class));
@@ -264,10 +270,10 @@ public class MCPMerger
@SuppressWarnings("unchecked")
private static Hashtable<String, ZipEntry> getClassEntries(ZipFile inFile, ZipOutputStream outFile) throws IOException
{
{
Hashtable<String, ZipEntry> ret = new Hashtable<String, ZipEntry>();
for (ZipEntry entry : Collections.list((Enumeration<ZipEntry>)inFile.entries()))
{
{
if (entry.isDirectory())
{
outFile.putNextEntry(entry);
@@ -286,9 +292,9 @@ public class MCPMerger
return ret;
}
private static void copyEntry(ZipFile inFile, ZipEntry entry, ZipOutputStream outFile) throws IOException
{
{
ZipEntry newEntry = new ZipEntry(entry.getName());
outFile.putNextEntry(newEntry);
outFile.putNextEntry(newEntry);
outFile.write(readEntry(inFile, entry));
}
private static byte[] readEntry(ZipFile inFile, ZipEntry entry) throws IOException
@@ -308,9 +314,9 @@ public class MCPMerger
entryBuffer.write(data, 0, len);
}
} while (len != -1);
return entryBuffer.toByteArray();
}
}
private static class ClassInfo
{
public String name;
@@ -321,12 +327,12 @@ public class MCPMerger
public ClassInfo(String name){ this.name = name; }
public boolean isSame() { return (cField.size() == 0 && sField.size() == 0 && cMethods.size() == 0 && sMethods.size() == 0); }
}
public static byte[] processClass(byte[] cIn, byte[] sIn, ClassInfo info)
{
ClassNode cClassNode = getClassNode(cIn);
ClassNode sClassNode = getClassNode(sIn);
processFields(cClassNode, sClassNode, info);
processMethods(cClassNode, sClassNode, info);
@@ -334,7 +340,7 @@ public class MCPMerger
cClassNode.accept(writer);
return writer.toByteArray();
}
private static ClassNode getClassNode(byte[] data)
{
ClassReader reader = new ClassReader(data);
@@ -342,7 +348,7 @@ public class MCPMerger
reader.accept(classNode, 0);
return classNode;
}
@SuppressWarnings("unchecked")
private static void processFields(ClassNode cClass, ClassNode sClass, ClassInfo info)
{
@@ -390,18 +396,18 @@ public class MCPMerger
{
if (cF.visibleAnnotations == null) cF.visibleAnnotations = new ArrayList<AnnotationNode>();
cF.visibleAnnotations.add(getSideAnn(true));
sFields.add(sI, cF);
sFields.add(sI, cF);
info.cField.add(cF);
}
}
}
}
else
{
if (cF.visibleAnnotations == null) cF.visibleAnnotations = new ArrayList<AnnotationNode>();
cF.visibleAnnotations.add(getSideAnn(true));
sFields.add(sI, cF);
sFields.add(sI, cF);
info.cField.add(cF);
}
}
sI++;
}
if (sFields.size() != cFields.size())
@@ -414,83 +420,133 @@ public class MCPMerger
cFields.add(x++, sF);
info.sField.add(sF);
}
}
}
}
private static class MethodWrapper
{
private MethodNode node;
public boolean client;
public boolean server;
public MethodWrapper(MethodNode node)
{
this.node = node;
}
@Override
public boolean equals(Object obj)
{
if (obj == null || !(obj instanceof MethodWrapper)) return false;
MethodWrapper mw = (MethodWrapper) obj;
boolean eq = Objects.equal(node.name, mw.node.name) && Objects.equal(node.desc, mw.node.desc);
if (eq)
{
mw.client = this.client | mw.client;
mw.server = this.server | mw.server;
this.client = this.client | mw.client;
this.server = this.server | mw.server;
System.out.printf(" eq: %s %s\n", this, mw);
}
return eq;
}
@Override
public int hashCode()
{
return Objects.hashCode(node.name, node.desc);
}
@Override
public String toString()
{
return Objects.toStringHelper(this).add("name", node.name).add("desc",node.desc).add("server",server).add("client",client).toString();
}
}
@SuppressWarnings("unchecked")
private static void processMethods(ClassNode cClass, ClassNode sClass, ClassInfo info)
{
List<MethodNode> cMethods = (List<MethodNode>)cClass.methods;
List<MethodNode> sMethods = (List<MethodNode>)sClass.methods;
int sI = 0;
for (int x = 0; x < cMethods.size(); x++)
LinkedHashSet<MethodWrapper> allMethods = Sets.newLinkedHashSet();
int cPos = 0;
int sPos = 0;
int cLen = cMethods.size();
int sLen = sMethods.size();
String clientName = "";
String lastName = clientName;
String serverName = "";
while (cPos < cLen || sPos < sLen)
{
MethodNode cM = cMethods.get(x);
if (sI < sMethods.size())
do
{
if (!cM.name.equals(sMethods.get(sI).name) || (cM.name.equals("<init>") && !cM.desc.equals(sMethods.get(sI).desc)))
if (sPos>=sLen)
{
boolean serverHas = false;
for (int y = sI + 1; y < sMethods.size(); y++)
{
if (cM.name.equals(sMethods.get(y).name) && cM.desc.equals(sMethods.get(y).desc))
{
serverHas = true;
break;
}
}
if (serverHas)
{
boolean clientHas = false;
MethodNode sM = sMethods.get(sI);
for (int y = x + 1; y < cMethods.size(); y++)
{
if (sM.name.equals(cMethods.get(y).name) && sM.desc.equals(cMethods.get(y).desc))
{
clientHas = true;
break;
}
}
if (!clientHas)
{
if (sM.visibleAnnotations == null) sM.visibleAnnotations = new ArrayList<AnnotationNode>();
sM.visibleAnnotations.add(getSideAnn(false));
cMethods.add(x, sM);
info.sMethods.add(sM);
}
}
else
{
if (cM.visibleAnnotations == null) cM.visibleAnnotations = new ArrayList<AnnotationNode>();
cM.visibleAnnotations.add(getSideAnn(true));
sMethods.add(sI, cM);
info.cMethods.add(cM);
}
break;
}
}
MethodNode sM = sMethods.get(sPos);
serverName = sM.name;
if (!serverName.equals(lastName) && cPos != cLen)
{
System.out.printf("Server -skip : %s %s %d (%s %d) %d [%s]\n", sClass.name, clientName, cLen - cPos, serverName, sLen - sPos, allMethods.size(), lastName);
break;
}
MethodWrapper mw = new MethodWrapper(sM);
mw.server = true;
allMethods.add(mw);
System.out.printf("Server *add* : %s %s %d (%s %d) %d [%s]\n", sClass.name, clientName, cLen - cPos, serverName, sLen - sPos, allMethods.size(), lastName);
sPos++;
}
while (sPos < sLen);
do
{
if (cPos>=cLen)
{
break;
}
MethodNode cM = cMethods.get(cPos);
lastName = clientName;
clientName = cM.name;
if (!clientName.equals(lastName) && sPos != sLen)
{
System.out.printf("Client -skip : %s %s %d (%s %d) %d [%s]\n", cClass.name, clientName, cLen - cPos, serverName, sLen - sPos, allMethods.size(), lastName);
break;
}
MethodWrapper mw = new MethodWrapper(cM);
mw.client = true;
allMethods.add(mw);
System.out.printf("Client *add* : %s %s %d (%s %d) %d [%s]\n", cClass.name, clientName, cLen - cPos, serverName, sLen - sPos, allMethods.size(), lastName);
cPos++;
}
while (cPos < cLen);
}
cMethods.clear();
sMethods.clear();
for (MethodWrapper mw : allMethods)
{
System.out.println(mw);
cMethods.add(mw.node);
sMethods.add(mw.node);
if (mw.server && mw.client)
{
// no op
}
else
{
if (cM.visibleAnnotations == null) cM.visibleAnnotations = new ArrayList<AnnotationNode>();
cM.visibleAnnotations.add(getSideAnn(true));
sMethods.add(sI, cM);
info.cMethods.add(cM);
}
sI++;
}
if (sMethods.size() != cMethods.size())
{
for (int x = cMethods.size(); x < sMethods.size(); x++)
{
MethodNode sM = sMethods.get(x);
if (sM.visibleAnnotations == null) sM.visibleAnnotations = new ArrayList<AnnotationNode>();
sM.visibleAnnotations.add(getSideAnn(false));
cMethods.add(x++, sM);
info.sMethods.add(sM);
if (mw.node.visibleAnnotations == null) mw.node.visibleAnnotations = Lists.newArrayListWithExpectedSize(1);
mw.node.visibleAnnotations.add(getSideAnn(mw.client));
if (mw.client)
{
info.sMethods.add(mw.node);
}
else
{
info.cMethods.add(mw.node);
}
}
}
}
}
public static byte[] getClassBytes(String name) throws IOException
{
InputStream classStream = null;
@@ -72,15 +72,20 @@ public class FMLNetworkHandler
private void handleFMLPacket(Packet250CustomPayload packet, NetworkManager network, NetHandler netHandler)
{
FMLPacket pkt = FMLPacket.readPacket(packet.field_73629_c);
String userName = null;
String userName = "";
if (netHandler instanceof NetLoginHandler)
{
userName = ((NetLoginHandler) netHandler).field_72543_h;
}
else
{
userName = netHandler.getPlayer().func_70005_c_();
EntityPlayer pl = netHandler.getPlayer();
if (pl != null)
{
userName = pl.func_70005_c_();
}
}
pkt.execute(network, this, netHandler, userName);
}
@@ -266,13 +271,13 @@ public class FMLNetworkHandler
{
NetworkRegistry.instance().connectionOpened(netClientHandler, server, networkManager);
}
public static void onConnectionClosed(NetworkManager manager)
{
NetworkRegistry.instance().connectionClosed(manager);
}
public static void sendPacket(Player player, Packet packet)
{
}
@@ -309,7 +314,7 @@ public class FMLNetworkHandler
pkt.field_73630_a = "FML";
pkt.field_73629_c = FMLPacket.makePacket(Type.ENTITYSPAWNADJUSTMENT, entityId, serverX, serverY, serverZ);
pkt.field_73628_b = pkt.field_73629_c.length;
player.field_71135_a.func_72567_b(pkt);
}
}
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/FML-Server/src/net/minecraft/server/MinecraftServer.java"/>
<listEntry value="/FML-Server/src-common/net/minecraft/server/MinecraftServer.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
@@ -39,7 +39,6 @@ public class MockMod
}
@SideOnly(Side.CLIENT)
@Instance
public static MockMod myInstance;
@@ -10,18 +10,15 @@
import net.minecraft.src.AnvilSaveConverter;
import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.CallableIsServerModded;
@@ -362,8 +365,10 @@
{
try
@@ -364,6 +367,7 @@
{
+ FMLCommonHandler.instance().handleServerStarting(this);
if (this.func_71197_b())
{
+ FMLCommonHandler.instance().handleServerStarted();
long var1 = System.currentTimeMillis();
for (long var50 = 0L; this.field_71317_u; this.field_71296_Q = true)
@@ -403,6 +408,7 @@
@@ -403,6 +407,7 @@
Thread.sleep(1L);
}
@@ -29,7 +26,7 @@
}
else
{
@@ -593,6 +599,12 @@
@@ -1117,6 +1122,12 @@
@SideOnly(Side.SERVER)
public static void main(String[] p_main_0_)
{
@@ -23,3 +23,12 @@
this.func_71210_a(new DedicatedPlayerList(this));
long var4 = System.nanoTime();
@@ -160,7 +163,7 @@
this.field_71339_n = new RConThreadMain(this);
this.field_71339_n.func_72602_a();
}
-
+ FMLCommonHandler.instance().handleServerStarting(this);
return true;
}
@@ -0,0 +1,19 @@
--- ../src-base/minecraft/net/minecraft/src/IntegratedServer.java
+++ ../src-work/minecraft/net/minecraft/src/IntegratedServer.java
@@ -2,6 +2,8 @@
import java.io.File;
import java.io.IOException;
+
+import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
@@ -94,6 +96,7 @@
this.func_71253_a(CryptManager.func_75891_b());
this.func_71247_a(this.func_71270_I(), this.func_71221_J(), this.field_71350_m.func_77160_d(), this.field_71350_m.func_77165_h());
this.func_71205_p(this.func_71214_G() + " - " + this.field_71305_c[0].func_72912_H().func_76065_j());
+ FMLCommonHandler.instance().handleServerStarting(this);
return true;
}