Exemple #1
0
        public static void Initialize()
        {
            if (!Initialized)
            {
                Initialized = true;
                ModsFolder  = System.IO.Path.GetFullPath(Application.dataPath + "/../Mods") + System.IO.Path.DirectorySeparatorChar;
                try
                {
                    XDocument configuration = XDocument.Load(ModsFolder + "RuntimeConfiguration.xml");
                    foreach (XElement modConfiguration in configuration.Root.Elements("Mod"))
                    {
                        try
                        {
                            Mod newMod = new Mod(modConfiguration);
                            if (newMod.ID != "")
                            {
                                Mods.Add(newMod.ID, newMod);
                            }
                            newMod.Assembly = Assembly.Load(new AssemblyName(newMod.ID));
                            ModAPI.Mods.Add(newMod);
                        }
                        catch (Exception e)
                        {
                            XAttribute idAttribute = modConfiguration.Attribute("ID");
                            string     ID          = "Core";
                            if (idAttribute != null)
                            {
                                ID = idAttribute.Value;
                            }
                            Log.Write("Something went wrong while initializing a mod: " + e.ToString(), ID);
                        }
                    }

                    foreach (XElement ExecuteEveryFrame in configuration.Root.Elements("ExecuteEveryFrame"))
                    {
                        MethodInfo m = FindMethod(ExecuteEveryFrame.Value.ToString());
                        if (m != null)
                        {
                            string OnlyInGame = ExecuteEveryFrame.Attribute("OnlyInGame").Value;
                            if (OnlyInGame == "true")
                            {
                                BaseSystem.ExecuteEveryFrameInGame.Add(new Execution()
                                {
                                    Method = m, ModID = ExecuteEveryFrame.Attribute("ModID").Value
                                });
                            }
                            else
                            {
                                BaseSystem.ExecuteEveryFrame.Add(new Execution()
                                {
                                    Method = m, ModID = ExecuteEveryFrame.Attribute("ModID").Value
                                });
                            }
                        }
                        else
                        {
                            Log.Write("Could not find method for execute every frame: " + ExecuteEveryFrame.Value.ToString(), "Core");
                        }
                    }

                    foreach (XElement ExecuteOnApplicationStart in configuration.Root.Elements("ExecuteOnApplicationStart"))
                    {
                        MethodInfo m = FindMethod(ExecuteOnApplicationStart.Value.ToString());
                        if (m != null)
                        {
                            BaseSystem.ExecuteOnApplicationStart.Add(new Execution()
                            {
                                Method = m, ModID = ExecuteOnApplicationStart.Attribute("ModID").Value
                            });
                        }
                        else
                        {
                            Log.Write("Could not find method for execute on application start: " + ExecuteOnApplicationStart.Value.ToString(), "Core");
                        }
                    }

                    foreach (XElement ExecuteOnGameStart in configuration.Root.Elements("ExecuteOnGameStart"))
                    {
                        MethodInfo m = FindMethod(ExecuteOnGameStart.Value.ToString());
                        if (m != null)
                        {
                            BaseSystem.ExecuteOnGameStart.Add(new Execution()
                            {
                                Method = m, ModID = ExecuteOnGameStart.Attribute("ModID").Value
                            });
                        }
                        else
                        {
                            Log.Write("Could not find method for execute on game start: " + ExecuteOnGameStart.Value.ToString(), "Core");
                        }
                    }

                    WWW www = new WWW("file://" + ModsFolder + "GUI.assetbundle");
                    while (www.progress < 1)
                    {
                    }
                    Log.Write("Asset bundle ready: " + www.error, "Core");
                    Log.Write("Asset bundle: " + www.assetBundle, "Core");
                    if ((www.error == "" || www.error == null) && www.assetBundle != null)
                    {
                        Log.Write("Asset bundle loaded", "Core");
                        UnityEngine.Object[] objs = www.assetBundle.LoadAllAssets();
                        foreach (UnityEngine.Object o in objs)
                        {
                            Log.Write("Asset bundle: " + o, "Core");
                            if (o is GUISkin)
                            {
                                ModAPI.GUI.Skin = (GUISkin)o;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Write("Something went wrong while initializing: " + e.ToString(), "Core");
                }
            }
            if (SystemObject == null)
            {
                ModAPI.Log.Write(Application.loadedLevel + "", "Core");
                SystemObject = new GameObject("__ModAPISystem__");;
                Input.Initialize(SystemObject);
                Console.Initialize(SystemObject);
                if (SystemObject.GetComponent <BaseSystem>() == null)
                {
                    SystemObject.AddComponent <BaseSystem>();
                }
                if (SystemObject.GetComponent <LiveInspector>() == null)
                {
                    SystemObject.AddComponent <LiveInspector>();
                }

                if (Application.loadedLevel > 0)
                {
                    Execute(BaseSystem.ExecuteOnGameStart);
                }
                else
                {
                    Execute(BaseSystem.ExecuteOnApplicationStart);
                }
            }
        }
Exemple #2
0
        public static void Initialize()
        {
            if (!Initialized)
            {
                Initialized = true;
                _modsFolder = Path.GetFullPath(Application.dataPath + "/../Mods") + Path.DirectorySeparatorChar;
                try
                {
                    var configuration = XDocument.Load(_modsFolder + "RuntimeConfiguration.xml");
                    foreach (var modConfiguration in configuration.Root.Elements("Mod"))
                    {
                        try
                        {
                            var newMod = new Mod(modConfiguration);
                            if (newMod.Id != "")
                            {
                                Mods.Add(newMod.Id, newMod);
                            }
                            newMod.Assembly = Assembly.Load(new AssemblyName(newMod.Id));
                            ModAPI.Mods.Add(newMod);
                        }
                        catch (Exception e)
                        {
                            var idAttribute = modConfiguration.Attribute("ID");
                            var id          = "Core";
                            if (idAttribute != null)
                            {
                                id = idAttribute.Value;
                            }
                            Log.Write("Something went wrong while initializing a mod: " + e, id);
                        }
                    }

                    foreach (var executeEveryFrame in configuration.Root.Elements("ExecuteEveryFrame"))
                    {
                        var m = FindMethod(executeEveryFrame.Value);
                        if (m != null)
                        {
                            var onlyInGame = executeEveryFrame.Attribute("OnlyInGame").Value;
                            if (onlyInGame == "true")
                            {
                                ExecuteEveryFrameInGame.Add(new Execution {
                                    Method = m, ModId = executeEveryFrame.Attribute("ModID").Value
                                });
                            }
                            else
                            {
                                ExecuteEveryFrame.Add(new Execution {
                                    Method = m, ModId = executeEveryFrame.Attribute("ModID").Value
                                });
                            }
                        }
                        else
                        {
                            Log.Write("Could not find method for execute every frame: " + executeEveryFrame.Value, "Core");
                        }
                    }

                    foreach (var executeOnApplicationStart in configuration.Root.Elements("ExecuteOnApplicationStart"))
                    {
                        var m = FindMethod(executeOnApplicationStart.Value);
                        if (m != null)
                        {
                            ExecuteOnApplicationStart.Add(new Execution {
                                Method = m, ModId = executeOnApplicationStart.Attribute("ModID").Value
                            });
                        }
                        else
                        {
                            Log.Write("Could not find method for execute on application start: " + executeOnApplicationStart.Value, "Core");
                        }
                    }

                    foreach (var executeOnGameStart in configuration.Root.Elements("ExecuteOnGameStart"))
                    {
                        var m = FindMethod(executeOnGameStart.Value);
                        if (m != null)
                        {
                            ExecuteOnGameStart.Add(new Execution {
                                Method = m, ModId = executeOnGameStart.Attribute("ModID").Value
                            });
                        }
                        else
                        {
                            Log.Write("Could not find method for execute on game start: " + executeOnGameStart.Value, "Core");
                        }
                    }

                    var www = new WWW("file://" + _modsFolder + "GUI.assetbundle");
                    while (www.progress < 1)
                    {
                    }
                    Log.Write("Asset bundle ready: " + www.error, "Core");
                    Log.Write("Asset bundle: " + www.assetBundle, "Core");
                    if ((www.error == "" || www.error == null) && www.assetBundle != null)
                    {
                        Log.Write("Asset bundle loaded", "Core");
                        var objs = www.assetBundle.LoadAllAssets();
                        foreach (var o in objs)
                        {
                            Log.Write("Asset bundle: " + o, "Core");
                            if (o is GUISkin)
                            {
                                Gui.Skin = (GUISkin)o;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Write("Something went wrong while initializing: " + e, "Core");
                }
            }
            if (SystemObject == null)
            {
                Log.Write(Application.loadedLevel + "", "Core");
                SystemObject = new GameObject("__ModAPISystem__");
                ;
                Input.Initialize(SystemObject);
                Console.Initialize(SystemObject);
                if (SystemObject.GetComponent <BaseSystem>() == null)
                {
                    SystemObject.AddComponent <BaseSystem>();
                }
                if (SystemObject.GetComponent <LiveInspector>() == null)
                {
                    SystemObject.AddComponent <LiveInspector>();
                }

                if (Application.loadedLevel > 0)
                {
                    Execute(ExecuteOnGameStart);
                }
                else
                {
                    Execute(ExecuteOnApplicationStart);
                }
            }
        }