Example #1
0
        static SRMod AddMod(ProtoMod modInfo, Type entryType)
        {
            IModEntryPoint entryPoint = (IModEntryPoint)Activator.CreateInstance(entryType);
            var            newmod     = new SRMod(modInfo.ToModInfo(), entryPoint, modInfo.path);

            Mods.Add(modInfo.id, newmod);
            return(newmod);
        }
Example #2
0
 public SRMod(SRModInfo info, IModEntryPoint entryPoint)
 {
     this.ModInfo   = info;
     this.EntryType = entryPoint.GetType();
     if (entryPoint is ModEntryPoint)
     {
         entryPoint2 = (ModEntryPoint)entryPoint;
         useNewEntry = true;
     }
     this.entryPoint = entryPoint;
 }
        public static bool RunSource(List<ScriptEditorFile> sources, out string errorMessage, out IModEntryPoint modInstance)
        {
            modInstance = null;

            string dllPath;
            if (CompileSource(sources, out dllPath))
            {
                var assembly = Assembly.LoadFile(dllPath);

                if (assembly == null)
                {
                    errorMessage = "Failed to load assembly!";
                    return false;
                }

                Type entryPointType = null;
                foreach (Type type in assembly.GetTypes())
                {
                    if (typeof(IModEntryPoint).IsAssignableFrom(type))
                    {
                        entryPointType = type;
                        break;
                    }
                }

                if (entryPointType == null)
                {
                    errorMessage = "Failed to find any class that implements IModEntryPoint!";
                    return false;
                }

                modInstance = Activator.CreateInstance(entryPointType) as IModEntryPoint;
                if (modInstance == null)
                {
                    errorMessage = "Failed to create an instance of the IModEntryPoint class!";
                    return false;
                }
            }
            else
            {
                errorMessage = "Failed to compile the source!";
                return false;
            }

            errorMessage = "OK!";
            return true;
        }
Example #4
0
 public SRMod(SRModInfo info, IModEntryPoint entryPoint, String path) : this(info, entryPoint)
 {
     this.Path = path;
 }
Example #5
0
 public SRMod(SRModInfo info, IModEntryPoint entryPoint)
 {
     this.ModInfo    = info;
     this.EntryType  = entryPoint.GetType();
     this.entryPoint = entryPoint;
 }
        void DrawFooter()
        {
            footerArea.Begin();

            GUILayout.BeginHorizontal();

            if (currentMod != null)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Compile"))
            {
                string dllPath;
                if (ScriptCompiler.CompileSource(projectFiles, out dllPath))
                {
                    Log.Message("Source compiled to \"" + dllPath + "\"");
                }
                else
                {
                    Log.Error("Failed to compile script!");
                }
            }

            if (GUILayout.Button("Run"))
            {
                string errorMessage;
                if (ScriptCompiler.RunSource(projectFiles, out errorMessage, out currentMod))
                {
                    Log.Message("Running IModEntryPoint.OnModLoaded()");

                    try
                    {
                        currentMod.OnModLoaded();
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Exception while calling IModEntryPoint.OnModLoaded() - {ex.Message}");
                    }
                }
                else
                {
                    lastError = errorMessage;
                    Log.Error("Failed to compile or run source, reason: " + errorMessage);
                }
            }

            GUI.enabled = false;
            if (currentMod != null)
            {
                GUI.enabled = true;
            }

            if (GUILayout.Button("Stop"))
            {
                Log.Message("Running IModEntryPoint.OnModUnloaded()");
                try
                {
                    currentMod.OnModUnloaded();
                }
                catch (Exception ex)
                {
                    Log.Error($"Exception while calling IModEntryPoint.OnModUnloaded() - {ex.Message}");
                }

                currentMod = null;
            }

            GUI.enabled = true;

            GUILayout.Label("Last error: " + lastError);

            GUILayout.FlexibleSpace();

            if (currentFile == null)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Save"))
            {
                try
                {
                    SaveProjectFile(currentFile);
                }
                catch (Exception ex)
                {
                    lastError = ex.Message;
                    return;
                }
                lastError = "";
            }

            GUI.enabled = true;

            if (GUILayout.Button("Save all"))
            {
                SaveAllProjectFiles();
            }

            GUILayout.EndHorizontal();

            footerArea.End();
        }
        public static bool RunSource(List <ScriptEditorFile> sources, out string errorMessage, out IModEntryPoint modInstance)
        {
            modInstance = null;

            string dllPath;

            if (CompileSource(sources, out dllPath))
            {
                var assembly = Assembly.LoadFile(dllPath);

                if (assembly == null)
                {
                    errorMessage = "Failed to load assembly!";
                    return(false);
                }

                Type entryPointType = null;
                foreach (Type type in assembly.GetTypes())
                {
                    if (typeof(IModEntryPoint).IsAssignableFrom(type))
                    {
                        entryPointType = type;
                        break;
                    }
                }

                if (entryPointType == null)
                {
                    errorMessage = "Failed to find any class that implements IModEntryPoint!";
                    return(false);
                }

                modInstance = Activator.CreateInstance(entryPointType) as IModEntryPoint;
                if (modInstance == null)
                {
                    errorMessage = "Failed to create an instance of the IModEntryPoint class!";
                    return(false);
                }
            }
            else
            {
                errorMessage = "Failed to compile the source!";
                return(false);
            }

            errorMessage = "OK!";
            return(true);
        }
        void DrawFooter()
        {
            footerArea.Begin();

            GUILayout.BeginHorizontal();

            if (currentMod != null)
            {
                GUI.enabled = false;
            }

               /* if (GUILayout.Button("Compile"))
            {
                string dllPath;
                if (ScriptCompiler.CompileSource(projectFiles, out dllPath))
                {
                    Log.Message("Source compiled to \"" + dllPath + "\"");
                }
                else
                {
                    Log.Error("Failed to compile script!");
                }
            }

            if (GUILayout.Button("Run"))
            {
                string errorMessage;
                if (ScriptCompiler.RunSource(projectFiles, out errorMessage, out currentMod))
                {
                    Log.Message("Running IModEntryPoint.OnModLoaded()");

                    try
                    {
                        currentMod.OnModLoaded();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(String.Format("Exception while calling IModEntryPoint.OnModLoaded() - {0}", ex.Message));
                    }
                }
                else
                {
                    lastError = errorMessage;
                    Log.Error("Failed to compile or run source, reason: " + errorMessage);
                }
            }
            */
            GUI.enabled = false;
            if (currentMod != null)
            {
                GUI.enabled = true;
            }

            if (GUILayout.Button("Stop"))
            {
                Log.Message("Running IModEntryPoint.OnModUnloaded()");
                try
                {
                    currentMod.OnModUnloaded();
                }
                catch (Exception ex)
                {
                    Log.Error(String.Format("Exception while calling IModEntryPoint.OnModUnloaded() - {0}", ex.Message));
                }

                currentMod = null;
            }

            GUI.enabled = true;

            GUILayout.Label("Last error: " + lastError);

            GUILayout.FlexibleSpace();

            if (currentFile == null)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Save"))
            {
                SaveProjectFile(currentFile);
            }

            GUI.enabled = true;

            if (GUILayout.Button("Save all"))
            {
                SaveAllProjectFiles();
            }

            GUILayout.EndHorizontal();

            footerArea.End();
        }
 internal EntryPointMod(IModInfo info, IModEntryPoint point)
 {
     Info  = info;
     Entry = point;
 }