예제 #1
0
 private void loadModFromFile(string modFile)
 {
     try
     {
         bool flag = Path.GetExtension(modFile) != ".dll";
         if (!flag)
         {
             string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(modFile);
             ModLoader.mainConsole.log("Loading mod: " + fileNameWithoutExtension, ModLoader.logTag);
             Assembly assembly = Assembly.LoadFrom(modFile);
             MyMod    myMod    = null;
             foreach (Type type in assembly.GetTypes())
             {
                 object[] customAttributes = type.GetCustomAttributes(typeof(MyModEntryPoint), true);
                 bool     flag2            = customAttributes.Length == 1;
                 if (flag2)
                 {
                     myMod = (Activator.CreateInstance(type) as MyMod);
                 }
             }
             bool flag3 = myMod == null;
             if (flag3)
             {
                 ModLoader.mainConsole.tryLogCustom("Mod does not contain a ModLoader entry point.", ModLoader.logTag, LogType.Generic);
                 ModLoader.mainConsole.tryLogCustom("It is possible this mod is not compatible with ModLoader.", ModLoader.logTag, LogType.Generic);
             }
             else
             {
                 List <string> list = new List <string>();
                 foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies())
                 {
                     list.Add(assemblyName.FullName);
                 }
                 ModLoader.mainConsole.tryLogCustom("Assemblies: [" + string.Join(",", list.ToArray()) + "]", ModLoader.logTag, LogType.Generic);
                 string path  = Path.Combine(Path.GetDirectoryName(modFile), Path.GetFileNameWithoutExtension(modFile));
                 bool   flag4 = myMod.LoadAssets(Path.Combine(path, "Assets"));
                 if (flag4)
                 {
                     ModLoader.mainConsole.tryLogCustom("Loaded assets.", ModLoader.logTag, LogType.Generic);
                     bool flag5 = myMod.fetchIcon();
                     if (flag5)
                     {
                         ModLoader.mainConsole.tryLogCustom("Loaded custom icon (Use UIE to display).", ModLoader.logTag, LogType.Generic);
                     }
                 }
                 bool flag6 = this.mods.ContainsKey(myMod.myName);
                 if (flag6)
                 {
                     ModLoader.mainConsole.tryLogCustom("Mod by the name " + myMod.myName + " already exists!", ModLoader.logTag, LogType.Generic);
                 }
                 else
                 {
                     string path2 = Path.Combine(this.getMyDataDirectory(), fileNameWithoutExtension);
                     myMod.assignDataPath(path2);
                     MethodInfo[] methods = myMod.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                     foreach (MethodInfo methodInfo in methods)
                     {
                         MyListenerAttribute[] array2 = (MyListenerAttribute[])methodInfo.GetCustomAttributes(typeof(MyListenerAttribute), true);
                         bool flag7 = array2.Length == 1;
                         if (flag7)
                         {
                             new MyHookListener(methodInfo, myMod);
                         }
                     }
                     FieldInfo[] fields = myMod.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                     foreach (FieldInfo fieldInfo in fields)
                     {
                         MyHookListenerContainer[] array4 = (MyHookListenerContainer[])fieldInfo.GetCustomAttributes(typeof(MyHookListenerContainer), true);
                         bool flag8 = array4.Length == 1;
                         if (flag8)
                         {
                             MethodInfo[] methods2 = fieldInfo.GetValue(myMod).GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                             foreach (MethodInfo listenMethod in methods2)
                             {
                                 new MyHookListener(listenMethod, myMod);
                             }
                         }
                     }
                     myMod.Load();
                     ModLoader.mainConsole.tryLogCustom(ModLoader.translation.autoFormat("@ModEntry", new object[]
                     {
                         myMod.myName,
                         myMod.myVersion,
                         myMod.myDescription
                     }), ModLoader.logTag, LogType.Generic);
                     this.loadedMods++;
                     this.mods[myMod.myName] = myMod;
                     MyHookSystem.executeHook <MyModLoadedHook>(new MyModLoadedHook(myMod));
                 }
             }
         }
     }
     catch (MyCoreException ex)
     {
         ex.caller = new MyCoreException.MyCaller("loadModFromFile", "ModLoader.cs");
     }
     catch (Exception e)
     {
         ModLoader.mainConsole.logError(e);
     }
 }
예제 #2
0
 private void loadModFromFile(String modFile)
 {
     try
     {
         if (Path.GetExtension(modFile) != ".dll")
         {
             return;
         }
         string modFileName = Path.GetFileNameWithoutExtension(modFile);
         mainConsole.log("Loading mod: " + modFileName, logTag);
         Assembly modAssembly = Assembly.LoadFrom(modFile);
         MyMod    entryObject = null;
         foreach (Type modType in modAssembly.GetTypes())
         {
             object[] attributeList = modType.GetCustomAttributes(typeof(MyModEntryPoint), true);
             if (attributeList.Length == 1)
             {
                 entryObject = Activator.CreateInstance(modType) as MyMod;
             }
         }
         if (entryObject == null)
         {
             mainConsole.tryLogCustom("Mod does not contain a ModLoader entry point.", logTag, LogType.Generic);
             mainConsole.tryLogCustom("It is possible this mod is not compatible with ModLoader.", logTag, LogType.Generic);
             return;
         }
         string infoPath = Path.Combine(Path.GetDirectoryName(modFile), Path.GetFileNameWithoutExtension(modFile));
         if (entryObject.LoadAssets(Path.Combine(infoPath, "Assets")))
         {
             mainConsole.tryLogCustom("Loaded assets.", logTag, LogType.Generic);
             if (entryObject.fetchIcon())
             {
                 mainConsole.tryLogCustom("Loaded custom icon (Use UIE to display).", logTag, LogType.Generic);
             }
         }
         if (mods.ContainsKey(entryObject.myName))
         {
             mainConsole.tryLogCustom("Mod by the name " + entryObject.myName + " already exists!", logTag, LogType.Generic);
             return;
         }
         string dataPath = this.getMyDataDirectory() + modFileName;
         entryObject.assignDataPath(dataPath);
         MethodInfo[] methods = modAssembly.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
         foreach (MethodInfo method in methods)
         {
             MyListenerAttribute[] att = (MyListenerAttribute[])method.GetCustomAttributes(typeof(MyListenerAttribute), true);
             if (att.Length == 1)
             {
                 new HookSystem.ReWork.MyHookListener(method, entryObject);
             }
         }
         entryObject.Load();
         mainConsole.tryLogCustom("Loaded " + entryObject.myName + ".\n" + entryObject.myDescription + "\nVersion " + entryObject.myVersion, logTag, LogType.Generic);
         this.loadedMods++;
         mods[entryObject.myName] = entryObject;
         MyHookSystem.executeHook <MyModLoadedHook>(new MyModLoadedHook(entryObject));
     }
     catch (MyCoreException e)
     {
         e.caller = new MyCoreException.MyCaller("loadModFromFile", "ModLoader.cs");
     }
     catch (Exception e)
     {
         mainConsole.logError(e);
     }
 }