Esempio n. 1
0
        private static unsafe IntPtr VirtualMachine__RunFunctionHook(VirtualMachine *virtualMachine, string functionName, int a3, int a4, int opLimit, int a6)
        {
            IntPtr num = IntPtr.Zero;

            try
            {
                if (functionName == "config")
                {
                    PluginSystem.OnMapLoad();
                }
                //Trace.WriteLine($"[RunFunction] {functionName} Start");
                //if (Prefix.ContainsKey(functionName)) Prefix[functionName]();
                //if (functionName == "main")
                //{
                //    MainVM = virtualMachine;
                //}
                num = VirtualMachine__RunFunction(virtualMachine, functionName, a3, a4, opLimit, a6);
                //if (Postfix.ContainsKey(functionName)) Postfix[functionName]();
                //Trace.WriteLine($"[RunFunction] {functionName} End");
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Unhandled Exception in {nameof(Script)}.{nameof(VirtualMachine__RunFunctionHook)}!");
                Trace.WriteLine(ex.ToString());
            }
            return(num);
        }
Esempio n. 2
0
            public static Component CreateComponent(string componentName)
            {
                DCustomComponentDefinition definition = PluginSystem.FindComponentDefinition(componentName);

                if (definition == null)
                {
                    return(null);
                }

                Component componentInstance = (Component)Activator.CreateInstance(definition.type);

                return(componentInstance);
            }
Esempio n. 3
0
        private void addServerPlugin_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();

            fd.Title  = "Import server plugin";
            fd.Filter = "Plugin|*.js";

            DialogResult dr = fd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                string target = serverPluginsLocation + fd.SafeFileName;

                //Check if plugin already exists

                if (File.Exists(target))
                {
                    File.Delete(target);
                }

                //Copy plugin file

                File.Copy(fd.FileName, target);

                //Create settings

                PluginSystem.SavePluginSettings(
                    target.Substring(0, target.LastIndexOf('.')) + ".settings.js",
                    true,
                    PluginSystem.ReadPlugin(target).properties
                    );

                //Refresh client plugins

                ReloadServerPlugins();
            }
        }
Esempio n. 4
0
        private void ReloadServerPlugins()
        {
            try
            {
                //Read all server plugins

                string[] serverFiles =
                    Directory.GetFiles(serverPluginsLocation)
                    .Where(name => name.IndexOf(".settings.js") == -1).ToArray();

                //Clear plugin list

                serverPlugins.Items.Clear();

                //Create new server plugin array

                serverPluginsArray = new Plugin[serverFiles.Length];

                //Handle all plugins

                foreach (string file in serverFiles)
                {
                    //Read plugin

                    Plugin plugin = PluginSystem.ReadPlugin(file);
                    if (plugin == null)
                    {
                        continue;
                    }

                    //Create settings location

                    string settingsLoc = file.Substring(0, file.LastIndexOf('.')) + ".settings.js";

                    //Check if settings exist

                    if (!File.Exists(settingsLoc))
                    {
                        if (!File.Exists(settingsLoc))
                        {
                            PluginSystem.SavePluginSettings(
                                settingsLoc,
                                true,
                                plugin.properties
                                );
                        }
                    }

                    //Read if enabled or not

                    bool enabled = ReadEnabledSettings(settingsLoc);

                    //Add plugin

                    serverPlugins.Items.Add(plugin.name, enabled);
                    serverPluginsArray[serverPlugins.Items.Count - 1] = plugin;
                }
            }
            catch (Exception exc)
            {
                Logger.Error("Could not reload server plugins: ", exc);
            }
        }
Esempio n. 5
0
 protected override byte GetBlockToPlace(PluginSystem.World.Blocks.IStructBlock baseBlock, BlockFace face)
 {
     return (byte)BlockData.Blocks.Wooden_Door;
 }
Esempio n. 6
0
 protected override byte GetBlockToPlace(PluginSystem.World.Blocks.IStructBlock baseBlock, BlockFace face)
 {
     return (byte)BlockData.Blocks.Redstone_Wire;
 }
Esempio n. 7
0
        private void Properties_DoubleClick(object sender, EventArgs e)
        {
            if (properties.SelectedIndex == -1)
            {
                return;
            }

            switch (plugin.properties[properties.SelectedIndex])
            {
            //String property

            case PluginStringProperty psp:
                TextInput ti = new TextInput(
                    "Edit '" + psp.name + "'",
                    "Change the property value",
                    psp.value
                    );
                if (ti.ShowDialog() == DialogResult.OK)
                {
                    psp.value = ti.GetResult();
                }
                break;

            //Number property

            case PluginNumberProperty pnp:
                NumberInput ni = new NumberInput(
                    "Edit '" + pnp.name + "'",
                    "Change the property value",
                    pnp.value
                    );
                if (ni.ShowDialog() == DialogResult.OK)
                {
                    pnp.value = ni.GetResult();
                }
                break;

            //Bool property

            case PluginBoolProperty pbp:
                BoolInput bi = new BoolInput(
                    "Edit '" + pbp.name + "'",
                    "Change the property value",
                    pbp.value
                    );
                if (bi.ShowDialog() == DialogResult.OK)
                {
                    pbp.value = bi.GetResult();
                }
                break;
            }

            //Save new settings

            PluginSystem.SavePluginSettings(
                settingsLocation,
                enabled,
                plugin.properties
                );

            //Reload properties

            LoadProperties();
        }
Esempio n. 8
0
 private void Init()
 {
     PluginSystem = new PluginSystem(this);
     LogDebug($"#FlowNet Start at {DateTime.Now}");
 }
Esempio n. 9
0
        public string AutoComplete(PluginSystem.Net.IClient client, string s)
        {
            var sb = new System.Text.StringBuilder(string.Empty);
            if (s.Length < 2 || !s.StartsWith("/"))
                return string.Empty;

            s = s.Substring(1);
            string plugin, commandName, commandStr;

            if (s.IndexOf(':') != -1)
            {
                var colonPos = s.IndexOf(':');
                var spacePos = s.IndexOf(' ');
                if (spacePos != -1 && spacePos < colonPos)
                    return string.Empty;

                plugin = s.Substring(0, colonPos);

                if (string.IsNullOrEmpty(plugin))
                    return string.Empty;

                commandStr = s.Substring(colonPos + 1);
            }
            else
            {
                plugin = string.Empty;
                commandStr = s;
            }

            if (commandStr.IndexOf(' ') != -1)
            {
                var spacePos = commandStr.IndexOf(' ');
                commandName = commandStr.Substring(0, spacePos);
                commandStr = commandStr.Substring(spacePos);
            }
            else
            {
                commandName = commandStr;
                commandStr = string.Empty;
            }

            var commandsByPlugin =
                commands.Where(
                    c =>
                    (!string.IsNullOrEmpty(plugin) &&
                     ((c.Iplugin == null && string.Compare(plugin, _chraftCoreNamespace, true) == 0) ||
                      (c.Iplugin != null && string.Compare(c.Iplugin.Name, plugin, true) == 0)))
                    || string.IsNullOrEmpty(plugin));

            var commandsByName = commandsByPlugin.Where(c => c.Name.StartsWith(commandName, StringComparison.OrdinalIgnoreCase)).ToList();
            var commandsByShortcut = commandsByPlugin.Where(c => c.Shortcut.StartsWith(commandName, StringComparison.OrdinalIgnoreCase)).ToList();

            if (commandsByName.Count == 0 && commandsByShortcut.Count == 0)
                return string.Empty;

            if (commandsByName.Count + commandsByShortcut.Count > 1)
            {
                if (commandStr.Length == 0)
                {
                    foreach (var c in commandsByName)
                        if (!string.IsNullOrEmpty(c.Name.Trim()))
                            sb.AppendFormat("/{0}{1}\0", (string.IsNullOrEmpty(plugin) ? "" : plugin + ":"), c.Name);
                    foreach (var c in commandsByShortcut)
                        if (!string.IsNullOrEmpty(c.Shortcut.Trim()))
                            sb.AppendFormat("/{0}{1}\0", (string.IsNullOrEmpty(plugin) ? "" : plugin + ":"), c.Shortcut);
                    return sb.ToString();
                }

                var nameExact = commandsByName.Where(c => string.Compare(c.Name, commandName, true) == 0).ToList();
                var shortcutExact = commandsByShortcut.Where(c => string.Compare(c.Shortcut, commandName, true) == 0).ToList();

                if (nameExact.Count > 0)
                    return sb.Append(nameExact[0].AutoComplete(client, commandStr)).ToString();
                if (shortcutExact.Count > 0)
                    return sb.Append(shortcutExact[0].AutoComplete(client, commandStr)).ToString();

                return string.Empty;
            }
            
            if (!string.IsNullOrEmpty(commandStr))
            {
                if (commandsByName.Count == 1)
                    return sb.Append(commandsByName[0].AutoComplete(client, commandStr)).ToString();

                return sb.Append(commandsByShortcut[0].AutoComplete(client, commandStr)).ToString();
            }

            if (commandsByName.Count == 1)
                return sb.AppendFormat("/{0}{1}\0", (string.IsNullOrEmpty(plugin) ? "" : plugin + ":"), commandsByName[0].Name).ToString();

            return sb.AppendFormat("/{0}{1}\0", (string.IsNullOrEmpty(plugin) ? "" : plugin + ":"), commandsByShortcut[0].Shortcut).ToString();
        }
Esempio n. 10
0
        /// @brief Load a plugin from file.
        /// @details Try to open the XML definition for the plugin from the file name given as
        /// parameter. Then extract information from the XML (class name, auxiliary references
        /// and source code to compile), trying to compile the C# source code (based on
        /// Gear.PluginSupport.PluginCommon class) and returning the new class instance. If the
        /// compilation fails, then it opens the plugin editor to show errors and source code.
        /// @param[in] FileName Name and path to the XML plugin file to open
        /// @returns Reference to the new plugin instance (on success) or NULL (on fail).
        /// @throws Exception
        // TODO Modify the method to receive a PluginData, and delete the validation
        public void LoadPlugin(string FileName)
        {
            object objInst = null;
            //create the structure to fill data from file
            PluginData pluginCandidate = new PluginData();

            //Determine if the XML is valid, and for which DTD version
            if (!pluginCandidate.ValidatePluginFile(FileName))
            {
                string allMessages = string.Empty;
                //case not valid file, so show the errors.
                foreach (string strText in pluginCandidate.ValidationErrors)
                {
                    allMessages += (strText.Trim() + "\r\n");
                }
                /// @todo Add a custom dialog to show every error message in a grid.
                //show messages
                MessageBox.Show(allMessages,
                                "Emulator - OpenPlugin.",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else  //...XML plugin file is valid & system version is determined
            {
                //determine time to use to build the plugin
                DateTime TimeOfBuild = AssemblyUtils.GetFileDateTime(FileName);
                for (int i = 0; i < pluginCandidate.UseExtFiles.Length; i++)
                {
                    if (pluginCandidate.UseExtFiles[i] == true)
                    {
                        TimeOfBuild = DateTime.FromBinary(Math.Max(
                                                              TimeOfBuild.ToBinary(),
                                                              AssemblyUtils.GetFileDateTime(pluginCandidate.ExtFiles[i]).ToBinary()));
                    }
                }
                //generate the full name of the assembly corresponding to the plugin candidate
                string candidateAssemblyFullName =
                    pluginCandidate.PluginAssemblyFullName(TimeOfBuild).FullName;

                //determine the version to look for the correct method to load it
                switch (pluginCandidate.PluginSystemVersion)
                {
                case "0.0":
                    if (PluginPersistence.GetDataFromXML_v0_0(FileName, ref pluginCandidate))
                    {
                        //Search and replace plugin class declarations for V0.0 plugin
                        // system compatibility.
                        pluginCandidate.Codes[0] =
                            PluginSystem.ReplacePropellerClassV0_0(
                                PluginSystem.ReplaceBaseClassV0_0(pluginCandidate.Codes[0]));
                    }
                    break;

                case "1.0":
                    PluginPersistence.GetDataFromXML_v1_0(FileName, ref pluginCandidate);
                    objInst = this.Chip;
                    break;

                default:
                    MessageBox.Show(string.Format("Plugin system version '{0}' not recognized " +
                                                  "on file \"{1}\".", pluginCandidate.PluginSystemVersion, FileName),
                                    "Emulator - Open File.",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                //add information into plugin's code to generate with assembly attributes
                pluginCandidate.Codes[0] = PluginSystem.InsertAssemblyDetails(
                    pluginCandidate.Codes[0],
                    TimeOfBuild,
                    pluginCandidate.InstanceName,
                    pluginCandidate.Description,
                    pluginCandidate.PluginVersion);
                try
                {
                    //Dynamic load and compile the plugin module as a class, giving the chip
                    // instance as a parameter, and casting to appropriate class
                    PluginCommon plugin = ModuleCompiler.LoadModule(
                        pluginCandidate.Codes,                  //string[] codeTexts
                        pluginCandidate.ExtFiles,               //string[] sourceFiles
                        pluginCandidate.InstanceName,           //string module
                        pluginCandidate.References,             //string[] references
                        objInst,                                //object objInstance
                        pluginCandidate.PluginSystemVersion);   //string pluginSystemVersion,
                    if (plugin == null)
                    {
                        throw new Exception("Emulator - OpenPlugin: plugin object not generated!" +
                                            " (null response from memory loading).");
                    }
                    else //if success compiling & instantiate the new instance...
                    {
                        //...add to the corresponding plugin list of the emulator instance
                        AttachPlugin(plugin);
                        //update location of last plugin
                        Properties.Settings.Default.LastPlugin = FileName;
                        Properties.Settings.Default.Save();
                    }
                }
                catch (Exception)
                {
                    //open plugin editor in other window
                    PluginEditor errorPlugin = new PluginEditor(false);
                    if (errorPlugin.OpenFile(FileName, true))
                    {
                        //remember plugin successfully loaded
                        errorPlugin.UpdateLastPluginOpened();
                        //show plugin editor loaded with the faultly one
                        errorPlugin.MdiParent = this.MdiParent;
                        //the compilation errors are displayed in the error grid
                        ModuleCompiler.EnumerateErrors(errorPlugin.EnumErrors);
                        //show the error list
                        errorPlugin.ShowErrorGrid(true);
                        errorPlugin.Show();
                    }
                }
            }
        }
Esempio n. 11
0
            public static DPlugin LoadPlugin(string pluginName)
            {
                DPlugin pluginInstance = PluginSystem.LoadPlugin(pluginName);

                return(pluginInstance);
            }
Esempio n. 12
0
        // Initialize/Start DAE
        internal static void Start()
        {
            rootBuffer = new CBuffer(new IVector(0, 0));
            rootCanvas = new RootCanvas(rootBuffer, RenderTarget.defaultRenderTarget);

            DWindow window = new DWindow();

            window.ProcessEvents();
            window.RenderFrameToScreen();

            // Initialize the static Graphics class
            Graphics.Initialize();

            // Clear out the screen (make sure it's not white when we start up the window) (Burns my eyes)
            GL.ClearColor(0, 0, 0, 1);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            window.Title = "LOADING ...";

            window.RenderFrameToScreen();

            window.Title = "LOADING PLUGINS ...";

            // Initialize PluginSystem
            PluginSystem.LoadPluginsFromAssembly(Assembly.GetExecutingAssembly());

            PluginSystem.LoadDllsFromPath(Util.CurrentPath + "Plugins/");

            window.Title = "LOADING START-UP SCRIPT...";

            Loader.PrepareScript();
            Loader.Run();

            Foo foo = new Foo(new IVector(30, 20));

            rootCanvas.AddComponent(foo);

            Button b1 = new Button(new IVector(15, 5));

            b1.position += 1;
            foo.AddComponent(b1);

            Button b2 = new Button(new IVector(15, 5));

            b2.position = b1.Size + 1;
            foo.AddComponent(b2);

            Time.OnSecond += OnSecond;

            window.Title = "Dae";

            IsRunning = true;

            logicTickThread = new Thread(TickLoop);
            logicTickThread.Start();

            // Enter the main loop
            Run();

            // Actually shutdown/free DAE from the system (GPU, Hooks & Memory)
            Shutdown();
        }
Esempio n. 13
0
 protected override byte GetBlockToPlace(PluginSystem.World.Blocks.IStructBlock baseBlock, BlockFace face)
 {
     return (byte)(face == BlockFace.Up ? BlockData.Blocks.Sign_Post : BlockData.Blocks.Wall_Sign); ;
 }