Beispiel #1
0
 public void EnableMod(PartialityMod mod)
 {
     mod.EnableMod();
 }
Beispiel #2
0
        public void LoadAllMods()
        {
            //Get all the .dll files in the "Mods" folder and subfolders for the game
            string modsPath = Path.Combine(PartialityManager.mainPath, "Mods") + '/';

            string[] modFiles = Directory.GetFiles(modsPath, "*.dll", SearchOption.AllDirectories);

            //Check for dependencies. Load mods that have all dependencies, skip ones that don't.
            foreach (string filePath in modFiles)
            {
                try {
                    Assembly modAssembly = Assembly.Load(File.ReadAllBytes(filePath));
                    Debug.Log("Loaded Assembly :" + modAssembly.FullName);
                } catch (System.Exception e) {
                    Debug.LogError(e);
                }
            }

            Type        modType  = typeof(PartialityMod);
            List <Type> modTypes = new List <Type>();

            //Loop through all types that are loaded currently.
            foreach (Assembly currentAssembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                try {
                    foreach (Type t in currentAssembly.GetTypes())
                    {
                        try {
                            //If the base type matches the partiality mod type, then load it as a mod.
                            if (t.BaseType == modType)
                            {
                                modTypes.Add(t);
                            }
                        } catch (System.Exception e) {
                            Debug.LogError(e);
                        }
                    }
                } catch (System.Exception e) {
                    Debug.LogError(e);
                }
            }

            //Load mods from types
            foreach (Type t in modTypes)
            {
                try {
                    PartialityMod newMod = (PartialityMod)Activator.CreateInstance(t);

                    newMod.BaseInit();
                    newMod.Init();

                    if (newMod.ModID == "NULL")
                    {
                        Debug.LogError("Mod With NULL id, assigning the file as the ID");
                        newMod.ModID = t.Name;
                    }

                    loadedMods.Add(newMod);
                    loadedModsDictionary.Add(newMod.ModID, newMod);
                    loadedModsInfo.Add(newMod.ModID, newMod.Version);

                    Debug.Log("Initialized mod " + newMod.ModID + "succesfully.");
                } catch (System.Exception e) {
                    Debug.LogError("Problem loading mod from type " + t.Name + "! \n" + e);
                }
            }

            //Call mod load function
            foreach (PartialityMod pMod in loadedMods)
            {
                Debug.Log("Loaded mod " + pMod.ModID + " succesfully.");
                try {
                    pMod.BaseLoad();
                    pMod.OnLoad();
                    pMod.OnEnable();
                } catch (System.Exception e) {
                    Debug.LogError(e);
                }
            }
        }
Beispiel #3
0
 public void DisableMod(PartialityMod mod)
 {
     mod.DisableMod();
 }