Exemplo n.º 1
0
        private bool lua_LoadPlugin(string name)
        {
            Plugin oldplugin = pluginmanager[name];

            if (oldplugin != null)
            {
                return(false);
            }
            Plugin p = new Plugin(lua);

            if (!p.Load(oldplugin.Filename))
            {
                return(false);
            }
            pluginmanager.AddPlugin(p);
            return(true);
        }
Exemplo n.º 2
0
        private bool lua_LoadPlugin(string name)
        {
            Logger.Message("lua_LoadPlugin: " + name);
            Plugin oldplugin = pluginmanager[name];

            if (oldplugin != null)
            {
                return(false);
            }
            Plugin p = new Plugin(lua);

            if (!p.Load(string.Format("{0}\\{1}.lua", GetPath("plugins"), name)))
            {
                return(false);
            }
            pluginmanager.AddPlugin(p);
            p.Call("Init", null);
            p.Call("PostInit", null);
            p.Call("ServerStart", null);
            p.Call("OnDatablocksLoaded", null);
            p.Call("OnServerInitialized", null);
            return(true);
        }
Exemplo n.º 3
0
        private bool lua_ReloadPlugin(string name)
        {
            Plugin oldplugin = pluginmanager[name];

            if (oldplugin == null)
            {
                return(false);
            }
            oldplugin.Call("Unload", null);
            pluginmanager.RemovePlugin(oldplugin);
            Plugin p = new Plugin(lua);

            if (!p.Load(oldplugin.Filename))
            {
                return(false);
            }
            pluginmanager.AddPlugin(p);
            p.Call("Init", null);
            p.Call("PostInit", null);
            p.Call("ServerStart", null);
            p.Call("OnDatablocksLoaded", null);
            p.Call("OnServerInitialized", null);
            return(true);
        }
Exemplo n.º 4
0
 private bool lua_ReloadPlugin(string name)
 {
     Plugin oldplugin = pluginmanager[name];
     if (oldplugin == null) return false;
     oldplugin.Call("Unload", null);
     pluginmanager.RemovePlugin(oldplugin);
     Plugin p = new Plugin(lua);
     if (!p.Load(oldplugin.Filename)) return false;
     pluginmanager.AddPlugin(p);
     p.Call("Init", null);
     p.Call("PostInit", null);
     p.Call("ServerStart", null);
     p.Call("OnDatablocksLoaded", null);
     p.Call("OnServerInitialized", null);
     return true;
 }
Exemplo n.º 5
0
 private bool lua_LoadPlugin(string name)
 {
     Plugin oldplugin = pluginmanager[name];
     if (oldplugin != null) return false;
     Plugin p = new Plugin(lua);
     if (!p.Load(oldplugin.Filename)) return false;
     pluginmanager.AddPlugin(p);
     return true;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Loads Oxide
        /// </summary>
        private void Load()
        {
            // Initialise SSL
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.ServerCertificateValidationCallback = (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain,
                                       System.Net.Security.SslPolicyErrors sslPolicyErrors) => { return true; };
            System.Net.ServicePointManager.DefaultConnectionLimit = 200;

            // Determine the absolute path of the server instance
            serverpath = Path.GetDirectoryName(Path.GetFullPath(Application.dataPath));
            string[] cmdline = Environment.GetCommandLineArgs();
            for (int i = 0; i < cmdline.Length - 1; i++)
            {
                string arg = cmdline[i].ToLower();
                if (arg == "-serverinstancedir" || arg == "-oxidedir")
                {
                    try
                    {
                        serverpath = Path.GetFullPath(cmdline[++i]);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Failed to read server instance directory from command line!", ex);
                    }
                }
            }

            // Ensure directories exist
            if (!Directory.Exists(serverpath)) Directory.CreateDirectory(serverpath);
            if (!Directory.Exists(GetPath("plugins"))) Directory.CreateDirectory(GetPath("plugins"));
            if (!Directory.Exists(GetPath("data"))) Directory.CreateDirectory(GetPath("data"));
            if (!Directory.Exists(GetPath("logs"))) Directory.CreateDirectory(GetPath("logs"));
            Logger.Message(string.Format("Loading at {0}...", serverpath));

            // Initialise the Unity component
            oxideobject = new GameObject("Oxide");
            oxidecomponent = oxideobject.AddComponent<OxideComponent>();
            oxidecomponent.Oxide = this;

            // Hook things that we can't hook using the IL injector
            var serverinit = UnityEngine.Object.FindObjectOfType(Type.GetType("ServerInit, Assembly-CSharp")) as MonoBehaviour;
            serverinit.gameObject.AddComponent<ServerInitHook>();

            // Initialise needed maps and collections
            datafiles = new Dictionary<string, Datafile>();
            timers = new HashSet<Timer>();
            webrequests = new HashSet<AsyncWebRequest>();

            // Initialise the lua state
            lua = new Lua();
            lua["os"] = null;
            lua["io"] = null;
            lua["require"] = null;
            lua["dofile"] = null;
            lua["package"] = null;
            lua["luanet"] = null;
            lua["load"] = null;

            // Register functions
            lua.NewTable("cs");
            RegisterFunction("cs.print", "lua_Print");
            RegisterFunction("cs.error", "lua_Error");
            RegisterFunction("cs.callplugins", "lua_CallPlugins");
            RegisterFunction("cs.findplugin", "lua_FindPlugin");
            RegisterFunction("cs.requeststatic", "lua_RequestStatic");
            RegisterFunction("cs.registerstaticmethod", "lua_RegisterStaticMethod");
            RegisterFunction("cs.requeststaticproperty", "lua_RequestStaticProperty");
            RegisterFunction("cs.requestproperty", "lua_RequestProperty");
            RegisterFunction("cs.requeststaticfield", "lua_RequestStaticField");
            RegisterFunction("cs.requestfield", "lua_RequestField");
            RegisterFunction("cs.requestenum", "lua_RequestEnum");
            RegisterFunction("cs.readproperty", "lua_ReadProperty");
            RegisterFunction("cs.readfield", "lua_ReadField");
            RegisterFunction("cs.castreadproperty", "lua_CastReadProperty");
            RegisterFunction("cs.castreadfield", "lua_CastReadField");
            RegisterFunction("cs.readulongpropertyasuint", "lua_ReadULongPropertyAsUInt");
            RegisterFunction("cs.readulongpropertyasstring", "lua_ReadULongPropertyAsString");
            RegisterFunction("cs.readulongfieldasuint", "lua_ReadULongFieldAsUInt");
            RegisterFunction("cs.readulongfieldasstring", "lua_ReadULongFieldAsString");
            RegisterFunction("cs.readpropertyandsetonarray", "lua_ReadPropertyAndSetOnArray");
            RegisterFunction("cs.readfieldandsetonarray", "lua_ReadFieldAndSetOnArray");
            RegisterFunction("cs.reloadplugin", "lua_ReloadPlugin");
            RegisterFunction("cs.getdatafile", "lua_GetDatafile");
            RegisterFunction("cs.getdatafilelist", "lua_GetDatafileList"); // LMP
            RegisterFunction("cs.removedatafile", "lua_RemoveDatafile"); // LMP
            RegisterFunction("cs.dump", "lua_Dump");
            RegisterFunction("cs.createarrayfromtable", "lua_CreateArrayFromTable");
            RegisterFunction("cs.createtablefromarray", "lua_CreateTableFromArray");
            RegisterFunction("cs.gettype", "lua_GetType");
            RegisterFunction("cs.makegenerictype", "lua_MakeGenericType");
            RegisterFunction("cs.new", "lua_New");
            RegisterFunction("cs.newarray", "lua_NewArray");
            RegisterFunction("cs.convertandsetonarray", "lua_ConvertAndSetOnArray");
            RegisterFunction("cs.getelementtype", "lua_GetElementType");
            RegisterFunction("cs.newtimer", "lua_NewTimer");
            RegisterFunction("cs.sendwebrequest", "lua_SendWebRequest");
            RegisterFunction("cs.postwebrequest", "lua_PostWebRequest");
            RegisterFunction("cs.throwexception", "lua_ThrowException");
            RegisterFunction("cs.gettimestamp", "lua_GetTimestamp");
            RegisterFunction("cs.loadstring", "lua_LoadString");
            RegisterFunction("cs.createperfcounter", "lua_CreatePerfCounter");

            // Register constants
            lua.NewTable("bf");
            lua["bf.public_instance"] = BindingFlags.Public | BindingFlags.Instance;
            lua["bf.private_instance"] = BindingFlags.NonPublic | BindingFlags.Instance;
            lua["bf.public_static"] = BindingFlags.Public | BindingFlags.Static;
            lua["bf.private_static"] = BindingFlags.NonPublic | BindingFlags.Static;

            // Load the standard library
            Logger.Message("Loading standard library...");
            lua.LoadString(LuaOxideSTL.csfunc, "csfunc.stl").Call();
            lua.LoadString(LuaOxideSTL.json, "json.stl").Call();
            lua.LoadString(LuaOxideSTL.util, "util.stl").Call();
            lua.LoadString(LuaOxideSTL.type, "type.stl").Call();
            lua.LoadString(LuaOxideSTL.baseplugin, "baseplugin.stl").Call();
            lua.LoadString(LuaOxideSTL.rust, "rust.stl").Call();
            lua.LoadString(LuaOxideSTL.config, "config.stl").Call();
            lua.LoadString(LuaOxideSTL.plugins, "plugins.stl").Call();
            lua.LoadString(LuaOxideSTL.timer, "timer.stl").Call();
            lua.LoadString(LuaOxideSTL.webrequest, "webrequest.stl").Call();
            lua.LoadString(LuaOxideSTL.validate, "validate.stl").Call();

            // Initialise the plugin manager
            pluginmanager = new PluginManager();

            // Iterate all physical plugins
            Logger.Message("Loading plugins...");
            string[] files = Directory.GetFiles(GetPath("plugins"), "*.lua");
            foreach (string file in files)
            {
                // Load and register the plugin
                Plugin p = new Plugin(lua);
                if (p.Load(file)) pluginmanager.AddPlugin(p);
            }

            // Call Init and PostInit on all plugins
            pluginmanager.Call("Init", null);
            pluginmanager.Call("PostInit", null);
        }
Exemplo n.º 7
0
        private bool lua_LoadPlugin(string name)
        {
			Logger.Message("lua_LoadPlugin: " + name );
            Plugin oldplugin = pluginmanager[name];
            if (oldplugin != null) return false;
            Plugin p = new Plugin(lua);
            if (!p.Load(string.Format("{0}\\{1}.lua", GetPath("plugins"),name))) return false;
            pluginmanager.AddPlugin(p);
            p.Call("Init", null);
            p.Call("PostInit", null);
            p.Call("ServerStart", null);
            p.Call("OnDatablocksLoaded", null);
            p.Call("OnServerInitialized", null);
            return true;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Loads Oxide
        /// </summary>
        private void Load()
        {
            // Initialise SSL
            System.Net.ServicePointManager.Expect100Continue = false;
            System.Net.ServicePointManager.ServerCertificateValidationCallback = (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain,
                                                                                  System.Net.Security.SslPolicyErrors sslPolicyErrors) => { return(true); };
            System.Net.ServicePointManager.DefaultConnectionLimit = 200;

            // Determine the absolute path of the server instance
            serverpath = Path.GetDirectoryName(Path.GetFullPath(Application.dataPath));
            string[] cmdline = Environment.GetCommandLineArgs();
            for (int i = 0; i < cmdline.Length - 1; i++)
            {
                string arg = cmdline[i].ToLower();
                if (arg == "-serverinstancedir" || arg == "-oxidedir")
                {
                    try
                    {
                        serverpath = Path.GetFullPath(cmdline[++i]);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Failed to read server instance directory from command line!", ex);
                    }
                }
            }

            // Ensure directories exist
            if (!Directory.Exists(serverpath))
            {
                Directory.CreateDirectory(serverpath);
            }
            if (!Directory.Exists(GetPath("plugins")))
            {
                Directory.CreateDirectory(GetPath("plugins"));
            }
            if (!Directory.Exists(GetPath("data")))
            {
                Directory.CreateDirectory(GetPath("data"));
            }
            if (!Directory.Exists(GetPath("logs")))
            {
                Directory.CreateDirectory(GetPath("logs"));
            }
            Logger.Message(string.Format("Loading at {0}...", serverpath));

            // Initialise the Unity component
            oxideobject          = new GameObject("Oxide");
            oxidecomponent       = oxideobject.AddComponent <OxideComponent>();
            oxidecomponent.Oxide = this;

            // Hook things that we can't hook using the IL injector
            var serverinit = UnityEngine.Object.FindObjectOfType(Type.GetType("ServerInit, Assembly-CSharp")) as MonoBehaviour;

            serverinit.gameObject.AddComponent <ServerInitHook>();

            // Initialise needed maps and collections
            datafiles       = new Dictionary <string, Datafile>();
            timers          = new HashSet <Timer>();
            webrequests     = new HashSet <AsyncWebRequest>();
            webrequestQueue = new Queue <AsyncWebRequest>();

            // Initialise the lua state
            lua            = new Lua();
            lua["os"]      = null;
            lua["io"]      = null;
            lua["require"] = null;
            lua["dofile"]  = null;
            lua["package"] = null;
            lua["luanet"]  = null;
            lua["load"]    = null;

            // Register functions
            lua.NewTable("cs");
            RegisterFunction("cs.print", "lua_Print");
            RegisterFunction("cs.error", "lua_Error");
            RegisterFunction("cs.callplugins", "lua_CallPlugins");
            RegisterFunction("cs.findplugin", "lua_FindPlugin");
            RegisterFunction("cs.requeststatic", "lua_RequestStatic");
            RegisterFunction("cs.registerstaticmethod", "lua_RegisterStaticMethod");
            RegisterFunction("cs.requeststaticproperty", "lua_RequestStaticProperty");
            RegisterFunction("cs.requestproperty", "lua_RequestProperty");
            RegisterFunction("cs.requeststaticfield", "lua_RequestStaticField");
            RegisterFunction("cs.requestfield", "lua_RequestField");
            RegisterFunction("cs.requestenum", "lua_RequestEnum");
            RegisterFunction("cs.readproperty", "lua_ReadProperty");
            RegisterFunction("cs.readfield", "lua_ReadField");
            RegisterFunction("cs.castreadproperty", "lua_CastReadProperty");
            RegisterFunction("cs.castreadfield", "lua_CastReadField");
            RegisterFunction("cs.readulongpropertyasuint", "lua_ReadULongPropertyAsUInt");
            RegisterFunction("cs.readulongpropertyasstring", "lua_ReadULongPropertyAsString");
            RegisterFunction("cs.readulongfieldasuint", "lua_ReadULongFieldAsUInt");
            RegisterFunction("cs.readulongfieldasstring", "lua_ReadULongFieldAsString");
            RegisterFunction("cs.readpropertyandsetonarray", "lua_ReadPropertyAndSetOnArray");
            RegisterFunction("cs.readfieldandsetonarray", "lua_ReadFieldAndSetOnArray");
            RegisterFunction("cs.reloadplugin", "lua_ReloadPlugin");
            RegisterFunction("cs.loadplugin", "lua_LoadPlugin");
            RegisterFunction("cs.getdatafile", "lua_GetDatafile");
            RegisterFunction("cs.getdatafilelist", "lua_GetDatafileList"); // LMP
            RegisterFunction("cs.removedatafile", "lua_RemoveDatafile");   // LMP
            RegisterFunction("cs.dump", "lua_Dump");
            RegisterFunction("cs.createarrayfromtable", "lua_CreateArrayFromTable");
            RegisterFunction("cs.createtablefromarray", "lua_CreateTableFromArray");
            RegisterFunction("cs.gettype", "lua_GetType");
            RegisterFunction("cs.makegenerictype", "lua_MakeGenericType");
            RegisterFunction("cs.new", "lua_New");
            RegisterFunction("cs.newarray", "lua_NewArray");
            RegisterFunction("cs.convertandsetonarray", "lua_ConvertAndSetOnArray");
            RegisterFunction("cs.getelementtype", "lua_GetElementType");
            RegisterFunction("cs.newtimer", "lua_NewTimer");
            RegisterFunction("cs.sendwebrequest", "lua_SendWebRequest");
            RegisterFunction("cs.postwebrequest", "lua_PostWebRequest");
            RegisterFunction("cs.throwexception", "lua_ThrowException");
            RegisterFunction("cs.gettimestamp", "lua_GetTimestamp");
            RegisterFunction("cs.loadstring", "lua_LoadString");
            RegisterFunction("cs.createperfcounter", "lua_CreatePerfCounter");

            // Register constants
            lua.NewTable("bf");
            lua["bf.public_instance"]  = BindingFlags.Public | BindingFlags.Instance;
            lua["bf.private_instance"] = BindingFlags.NonPublic | BindingFlags.Instance;
            lua["bf.public_static"]    = BindingFlags.Public | BindingFlags.Static;
            lua["bf.private_static"]   = BindingFlags.NonPublic | BindingFlags.Static;

            // Load the standard library
            Logger.Message("Loading standard library...");
            lua.LoadString(LuaOxideSTL.csfunc, "csfunc.stl").Call();
            lua.LoadString(LuaOxideSTL.json, "json.stl").Call();
            lua.LoadString(LuaOxideSTL.util, "util.stl").Call();
            lua.LoadString(LuaOxideSTL.type, "type.stl").Call();
            lua.LoadString(LuaOxideSTL.baseplugin, "baseplugin.stl").Call();
            lua.LoadString(LuaOxideSTL.rust, "rust.stl").Call();
            lua.LoadString(LuaOxideSTL.config, "config.stl").Call();
            lua.LoadString(LuaOxideSTL.plugins, "plugins.stl").Call();
            lua.LoadString(LuaOxideSTL.timer, "timer.stl").Call();
            lua.LoadString(LuaOxideSTL.webrequest, "webrequest.stl").Call();
            lua.LoadString(LuaOxideSTL.validate, "validate.stl").Call();

            // Initialise the plugin manager
            pluginmanager = new PluginManager();

            // Iterate all physical plugins
            Logger.Message("Loading plugins...");
            string[] files = Directory.GetFiles(GetPath("plugins"), "*.lua");
            foreach (string file in files)
            {
                // Load and register the plugin
                Plugin p = new Plugin(lua);
                if (p.Load(file))
                {
                    pluginmanager.AddPlugin(p);
                }
            }

            // Call Init and PostInit on all plugins
            pluginmanager.Call("Init", null);
            pluginmanager.Call("PostInit", null);
        }