static void Main(string[] args) { List <FileCreator> files = new List <FileCreator>(); try { LoadLocalDLL(); Assembly assembly = Assembly.LoadFrom(args[0]); foreach (Type type in assembly.GetTypes()) { if (type.GetCustomAttribute <PacketCreator>() != null) { FileCreator fc = new FileCreator(type.Name); files.Add(fc); Console.WriteLine("Extracting " + type.Name + ":\n"); foreach (var method in type.GetMethods()) { PacketCreatorFunction fct = method.GetCustomAttribute <PacketCreatorFunction>(); if (fct != null) { fc.PCFcts.Add(fct); Console.WriteLine("\t" + fct.Packet); } } Console.WriteLine(); } } foreach (FileCreator file in files) { file.CreatePacketHandler(); } Console.Write("Done !"); } catch (Exception e) { Console.WriteLine("Impossible to generate the files, check the argument"); Console.WriteLine(e.StackTrace); throw e; } }
public string GenArgs(PacketCreatorFunction fct) { string str = ""; if (fct.Args == null) { return("\n\t\treturn (null);"); } str += "\n\t\tPacketArgs args = packet.GetArgs(new Type[]\n\t\t{\n"; foreach (Type arg in fct.Args) { string t = ""; if (arg == typeof(string)) { t = "string"; } if (arg == typeof(int)) { t = "int"; } if (arg == typeof(float)) { t = "float"; } if (arg == typeof(bool)) { t = "bool"; } str += "\t\t\ttypeof(" + t + "),\n"; } str += "\t\t});\n\n"; str += "\t\treturn (null);"; return(str); }
/// <summary> /// The class constructor /// </summary> /// <param name="info">The calling method info for getting the PacketCreatorFunction attribute</param> /// <param name="args">The Packet arguments</param> public Packet(MethodBase info, params object[] args) { PacketCreatorFunction p = (PacketCreatorFunction)info.GetCustomAttributes(typeof(PacketCreatorFunction), false)[0]; Content = p.Packet + ":" + GenArgs(args) + "\n"; }