Esempio n. 1
0
        /// <summary>
        /// The ScriptRunner is responsible for running a script inside an OMOD
        /// </summary>
        /// <param name="omod">The OMOD with the script to be executed</param>
        /// <param name="scriptRunnerFunctions">All callback functions for execution</param>
        public ScriptRunner(ref OMOD omod, IScriptRunnerFunctions scriptRunnerFunctions)
        {
            OMOD = omod;
            ScriptRunnerFunctions = scriptRunnerFunctions;
            script = omod.GetScript();
            if ((byte)script[0] >= (byte)ScriptType.Count)
            {
                type = ScriptType.obmmScript;
            }
            else
            {
                type   = (ScriptType)script[0];
                script = script.Substring(1);
            }

            DataPath    = omod.ExtractDataFiles();
            PluginsPath = omod.ExtractPlugins();
        }
Esempio n. 2
0
        public void TestCSharpScript(string fileName, long expectedFileLength, uint scriptCRC)
        {
            var file = Path.Combine("files", "csharp-scripting", fileName);

            if (!File.Exists(file))
            {
                return;
            }

            var fi = new FileInfo(file);
            var actualFileLength = fi.Length;

            Assert.Equal(expectedFileLength, actualFileLength);

            using var omod = new OMOD(file);

            var script = omod.GetScript();
            var crc    = Crc32Algorithm.Compute(Encoding.UTF8.GetBytes(script));

            Assert.Equal(scriptCRC, crc);

            //TODO: set this variable back to false once done testing locally
            const bool runScript = false;

            if (!runScript)
            {
                return;
            }
#pragma warning disable 162
            if (TestUtils.IsCI)
            {
                throw new Exception($"Someone forgot to change the runScript variable back to false before commiting!");
            }
            var scriptFunctions = new ExternalScriptFunctionsForTesting();
            var srd             = OMODScriptRunner.RunScript(omod, new OMODScriptSettings(scriptFunctions));

            Directory.Delete(srd.DataFolder);
            Directory.Delete(srd.PluginsFolder);
#pragma warning restore 162
        }
Esempio n. 3
0
 public static ScriptReturnData RunScript(OMOD omod, IScriptFunctions scriptFunctions, string data, string plugin)
 {
     return(ExecuteScript(omod.GetScript(), data, plugin, scriptFunctions));
 }
Esempio n. 4
0
 public static ScriptReturnData RunScript(OMOD omod, IScriptFunctions scriptFunctions)
 {
     return(ExecuteScript(omod.GetScript(), omod.GetDataFiles(), omod.GetPlugins(), scriptFunctions));
 }
Esempio n. 5
0
        public void TestOMODCreation()
        {
            var imageFile = Path.Combine("files", "image.png");

            Assert.True(File.Exists(imageFile));
            using var bitmap = (Bitmap)Image.FromFile(imageFile);

            var dataFile   = Path.Combine("files", "data.txt");
            var pluginFile = Path.Combine("files", "plugin.esp");

            Assert.True(File.Exists(dataFile));
            Assert.True(File.Exists(pluginFile));

            var options = new OMODCreationOptions(new Version(1, 2, 3))
            {
                Name                 = "erri120's Mod",
                Author               = "erri120",
                Email                = "*****@*****.**",
                Description          = "The best mod in existence",
                Website              = "https://github.com/erri120/OMODFramework",
                CompressionType      = CompressionType.SevenZip,
                OMODCompressionLevel = CompressionLevel.Optimal,
                Readme               = "This mod is very nice.",
                Script               = "Some script",
                Image                = bitmap,

                DataFiles = new List <OMODCreationFile>
                {
                    new OMODCreationFile(dataFile, "data.txt")
                },

                PluginFiles = new List <OMODCreationFile>
                {
                    new OMODCreationFile(pluginFile, "plugin.esp")
                }
            };

            using var ms   = OMODCreation.CreateOMOD(options);
            using var omod = new OMOD(ms);

            Assert.Equal(options.Name, omod.Config.Name);
            Assert.Equal(options.Author, omod.Config.Author);
            Assert.Equal(options.Email, omod.Config.Email);
            Assert.Equal(options.Description, omod.Config.Description);
            Assert.Equal(options.Website, omod.Config.Website);
            Assert.Equal(options.CompressionType, omod.Config.CompressionType);
            Assert.Equal(options.Version, omod.Config.Version);

            var readme = omod.GetReadme();

            Assert.Equal(options.Readme, readme);

            var script = omod.GetScript();

            Assert.Equal(options.Script, script);

            var image = omod.GetImage();

            Assert.Equal(options.Image.Size, image.Size);
            options.Image.Dispose();

            var dataFiles   = omod.GetDataFiles();
            var pluginFiles = omod.GetPluginFiles();

            Assert.Single(dataFiles);
            Assert.Single(pluginFiles);
        }