public bool LoadScript() { string scriptFileName = ScriptDirectory + @"\" + ID + ".csscript"; // Script support script.csscript if (!File.Exists(scriptFileName)) { Log.Error("InfoGrabber LoadScript() - grabber script not found: {0}", scriptFileName); return(false); } try { Environment.CurrentDirectory = Config.GetFolder(Config.Dir.Base); AsmHelper script = new AsmHelper(CSScript.Load(scriptFileName, null, false)); Grabber = (IIMDBScriptGrabber)script.CreateObject("Grabber"); } catch (Exception ex) { Log.Error("InfoGrabber LoadScript() - file: {0}, message : {1}", scriptFileName, ex.Message); return(false); } return(true); }
static void Main() { Assembly assembly = CSScript.LoadCode( @"using System; public class Claculator : IClaculator { public void Sum(int a, int b) { Console.WriteLine(a + b); } public void Multiply(int a, int b) { Console.WriteLine(a * b); } }" ); AsmHelper script = new AsmHelper(assembly); object instance = script.CreateObject("Claculator"); TypeUnsafeReflection(script, instance); TypeSafeInterface(instance); TypeSafeAlignedInterface(instance); TypeSafeDelegate(script, instance); TypeUnSafeDelegate(script, instance); }
static void Main() { Assembly assembly = CSScript.LoadCode( @"using System; public class Calculator : ICalculator { public int Add(int a, int b) { return a + b; } public string Join(string a, string b) { return a + b; } }"); AsmHelper calc = new AsmHelper(assembly); object instance = calc.CreateObject("Calculator"); //calc.CreateObject("*") can be used too if assembly has only one class defined FastInvokeDelegate methodInvoker = calc.GetMethodInvoker("Calculator.Add", 0, 0); int numOfLoops = 1000000; TestReflection(numOfLoops, calc, instance); TestFastInvoking(numOfLoops, calc, instance); TestDelegates(numOfLoops, methodInvoker, instance); TestInterface(numOfLoops, instance); TestInterfaceAlignment(numOfLoops, instance); TestDynamic(numOfLoops, instance); TestCompiledCode(numOfLoops); TestCompiledDelegate(numOfLoops); //TestMethodDelegates(); }
static void TestMethodDelegates() { Assembly assembly = CSScript.LoadCode( @"using System; public class Calculator { static public void PrintSum(int a, int b) { Console.WriteLine(a + b); } public int Multiply(int a, int b) { return (a * b); } }"); AsmHelper calc = new AsmHelper(assembly); //using static method delegate var PrintSum = calc.GetStaticMethod("Calculator.PrintSum", 0, 0); PrintSum(1, 2); //using instance method delegate var obj = calc.CreateObject("Calculator"); var Multiply = calc.GetMethod(obj, "Multiply", 0, 0); Console.WriteLine(Multiply(3, 5)); //using general method delegate; can invoke both static and instance methods var methodInvoker = calc.GetMethodInvoker("Calculator.PrintSum", 0, 0); methodInvoker(null, 5, 12); }
protected virtual IEnumerable <T> LoadScript(FileSystemInfo file, UpdateLoadResourcesDelegate updateAction, int totalCount, int currentCount) { var assemblyPath = Path.Combine(CompleteCompiledScriptPath, Path.ChangeExtension(file.Name, ".dll")); var md5Path = Path.Combine(CompleteCompiledScriptPath, Path.ChangeExtension(file.Name, ".md5")); Assembly assembly; if (ScriptNeedsCompilation(file, assemblyPath, md5Path)) { updateAction(string.Format("Compiling: {0}", file.Name), currentCount, totalCount); assembly = CSScript.Load(file.ToString(), assemblyPath, false); } else { updateAction(string.Format("Loading: {0}", Path.GetFileName(Path.ChangeExtension(file.Name, ".dll"))), currentCount, totalCount); assembly = Assembly.LoadFrom(assemblyPath); } var helper = new AsmHelper(assembly); return(assembly.ExportedTypes .Where(x => x.GetInterfaces().Contains(typeof(T))) .Select(source => (T)helper.CreateObject(source.FullName))); }
private static bool LoadScript() { string scriptFileName = InternalScriptDirectory + @"\InternalActorMoviesGrabber.csscript"; // Script support script.csscript if (!File.Exists(scriptFileName)) { Log.Error("InternalActorMoviesGrabber LoadScript() - grabber script not found: {0}", scriptFileName); return(false); } try { Environment.CurrentDirectory = Config.GetFolder(Config.Dir.Base); _asmHelper = new AsmHelper(CSScript.Load(scriptFileName, null, false)); InternalActorsGrabber = (IIMDBInternalActorsScriptGrabber)_asmHelper.CreateObject("InternalActorsGrabber"); } catch (Exception ex) { Log.Error("InternalActorMoviesGrabber LoadScript() - file: {0}, message : {1}", scriptFileName, ex.Message); return(false); } return(true); }
void test() { string assembly = CSScript.CompileFile("script.cs", null); using (var script = new AsmHelper(assembly, null, true)) { var capitalizer = (ITextCapitalizer)script.CreateObject("Script"); string te = capitalizer.ToLower("HeLLo"); MessageBox.Show(te); } }
public static void LoadStringsFromFile(string fileName) { try { var asm = new AsmHelper(CSScript.Load(fileName)); object data = asm.CreateObject("Strings"); Strings.FormMainName = callFromScript(asm, data, "*.getNesColors", ""); } catch (Exception) { } }
public static bool PreloadShowDumpField(string fileName) { try { var asm = new AsmHelper(CSScript.LoadCode(File.ReadAllText(fileName))); var data = asm.CreateObject("Data"); bool showDump = callFromScript(asm, data, "*.showDumpFileField", false); return(showDump); } catch (Exception) { return(false); } }
static void CallInstanceMethod2() { Assembly assembly = CSScript.LoadMethod( @"public void SayHello(string greeting) { Console.WriteLine(greeting); }" ); AsmHelper script = new AsmHelper(assembly); object instance = script.CreateObject("*"); //wild card * can be used as the assembly contains only one class defined script.InvokeInst(instance, "*.SayHello", "Hello World!"); }
static void CallInstanceMethod1() { //all classless scripts belong to DynamicClass type generated by the CS-Script engine Assembly assembly = CSScript.LoadMethod( @"public void SayHello(string greeting) { Console.WriteLine(greeting); }" ); AsmHelper script = new AsmHelper(assembly); object instance = script.CreateObject("Scripting.DynamicClass"); // or script.CreateObject("*") script.InvokeInst(instance, "Scripting.DynamicClass.SayHello", "Hello World!"); }
public static void LoadGlobalsFromFile(string fileName) { try { var asm = new AsmHelper(CSScript.Load(fileName)); object data = asm.CreateObject("Config"); romName = callFromScript(asm, data, "*.getFileName", ""); cfgName = callFromScript(asm, data, "*.getConfigName", ""); dumpName = callFromScript(asm, data, "*.getDumpName", ""); nesColors = callFromScript <Color[]>(asm, data, "*.getNesColors", null); } catch (Exception) { } }
static void Main() { string code = @"using System; public class Script { public static void SayHello(string greeting) { Console.WriteLine(""Static: "" + greeting); } public void Say(string greeting) { Console.WriteLine(""Instance: "" + greeting); } }" ; var script = new AsmHelper(CSScript.LoadCode(code, null, true)); //call static method script.Invoke("*.SayHello", "Hello World! (invoke)"); //call static method via emitted FastMethodInvoker var SayHello = script.GetStaticMethod("*.SayHello", ""); SayHello("Hello World! (emitted method)"); object obj = script.CreateObject("Script"); //call instance method script.InvokeInst(obj, "*.Say", "Hello World! (invoke)"); //call instance method via emitted FastMethodInvoker var Say = script.GetMethod(obj, "*.Say", ""); Say("Hello World! (emitted method)"); //call using C# 4.0 Dynamics dynamic script1 = CSScript.LoadCode(code) .CreateObject("*"); script1.Say("Hello World! (dynamic object)"); //call using CS-Scrit Interface Alignment IScript script2 = obj.AlignToInterface <IScript>(); script2.Say("Hello World! (aligned interface)"); }
private void toolStripButtonViewRunQuery_Click(object sender, EventArgs e) { var helper = new AsmHelper(CSScript.LoadCode(textBoxScript.Text, null, true)); using (helper) { gridDataEditorScript.BindEnumerable(((IQueryScript)helper.CreateObject("Script")).Query()); } if (gridDataEditorScript.BindingSource.Count > 0) { if (gridDataEditorScript.Height < 30) { splitContainerScript.SplitterDistance = Height / 2; toolStripButtonBrowse.Enabled = true; } } }
// Use this for initialization void Start() { //Wa have two script files now. ClassA.txt and ClassB.txt. ClassA has a reference to ClassB and ClassB has a reference to ClassA. This is a problem as we can only load one script at a time. //To fix this, we have to use special instruction in ClassA.txt. (See ClassA.txt for more info) //Tip: If you are lazy like me, you can tell CSScript to look for scripts in a specific folder. Now you don't have to type in the full path anymore. //Have a look at "Assembly and Script Probing scenarios" located at http://www.csscript.net/help/script_hosting_guideline_.html for more (important!) info on this CSScript.GlobalSettings.AddSearchDir(System.IO.Path.GetFullPath(Application.dataPath + "/CS-Script/02 AdvancedExample/Scripts")); CSScript.AssemblyResolvingEnabled = true; //Load ClassA script and compile. ClassB will automatically be compiled by CS-Script, as ClassA references it (See ClassA.cs for more info) System.Reflection.Assembly _assembly = CSScript.Load("ClassA.txt"); //Create instance of ClassA AsmHelper _helper = new AsmHelper(_assembly); _helper.CreateObject("ClassA"); }
// Use this for initialization void Start() { //Load script and compile. //Please not that you need to put your scripts in StreamingAssets folder or extern location. Otherwise unity will compile the .cs files. //If you want to store your script files inside your asset folder and don't want to use the StreamingAssets folder, simply give your scripts another ending than .cs (e.g. .txt) System.Reflection.Assembly _assembly = CSScript.Load(Application.dataPath + "/CS-Script/01 BasicExample/Scripts/BasicExampleScript.txt", null, true); //List all public classes inside the script Debug.Log("------ Public classes:"); foreach (System.Type t in _assembly.GetExportedTypes()) { Debug.Log(t); } Debug.Log("------ ALL classes:"); //List ALL classes inside the script foreach (System.Type t in _assembly.GetTypes()) { Debug.Log(t); } Debug.Log("----------------------"); //Add the Unity Component from our script file: MyMonoBehaviour //We know that it's the first class, but you should make sure and check. You could do a simple string check as a start this.gameObject.AddComponent(_assembly.GetExportedTypes()[0]); //Call a function in SomePublicClass in BasicExampleScript //Create an AsmHelper for easier handling. You only need one per Assembly. Multiple classes can be instantiated with it. AsmHelper helper = new AsmHelper(_assembly); //Call static function Calc(...) and print return value Debug.Log("Sum:" + (int)helper.Invoke("SomePublicClass.Sum", 1, 4)); //Create an instance of SomePublicClass using reflection IMyScript _somePublicClassInstance = (IMyScript)helper.CreateObject("SomePublicClass"); //Call function Test() on our new instance _somePublicClassInstance.Test(); }
private void btRun_Click(object sender, EventArgs e) { try { var scriptName = tbScriptFile.Text; Properties.Settings.Default["LastScript"] = scriptName; Properties.Settings.Default.Save(); tbLog.Clear(); tbLog.AppendText(String.Format("Running script: {0}\n", scriptName)); var asm = new AsmHelper(CSScript.LoadCode(File.ReadAllText(scriptName))); var script = asm.CreateObject("Script"); asm.InvokeInst(script, "Execute", this); tbLog.AppendText("Script finished\n"); } catch (Exception ex) { tbLog.AppendText("Script stopped"); MessageBox.Show(ex.Message, "Error while running script", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void loadMessageParsers() { skillParser.Items.Clear(); skillParser.Items.Add(new CBWrapper(new MiningMessageParser())); skillParser.SelectedIndex = 0; String path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); String dirname = path + "\\" + "WurmSkillRatio"; if (!Directory.Exists(dirname)) { return; } String[] files = Directory.GetFiles(dirname, "*.cs"); foreach (String file in files) { try { CSScript.GlobalSettings.AddSearchDir(dirname); AsmHelper asmHelper = new AsmHelper(CSScript.Load(file)); asmHelper.ProbingDirs = CSScript.GlobalSettings.SearchDirs.Split(';'); IMessageParser handler = asmHelper.CreateObject("*").AlignToInterface <IMessageParser>(true); int index = skillParser.Items.IndexOf(handler.getName()); if (index != -1) { skillParser.Items[index] = new CBWrapper(handler); } else { skillParser.Items.Add(new CBWrapper(handler)); } } catch (Exception e) { AddLog(e.Message + "\n"); } } }
public object LoadScript(string scriptPath) { if (!scriptPath.Contains(":")) { string folder = AppDomain.CurrentDomain.GetData("DataDirectory") + scriptsSubFolder; scriptPath = String.Format(@"{0}\{1}", folder, scriptPath); } var curTime = File.GetLastWriteTime(scriptPath).ToString(); if (loadedScripts.Any(script => script.Path.Equals(scriptPath, StringComparison.InvariantCultureIgnoreCase) && curTime == script.Id)) { return(null); } Log.WriteInfo("Loading script {0}...", scriptPath); DisposeScriptAssembly(scriptPath); var assemblyPath = Path.Combine(Path.GetDirectoryName(scriptPath), Path.GetFileNameWithoutExtension(scriptPath) + ".dll"); AsmHelper asmHelper = new AsmHelper(CSScript.LoadCodeFrom(scriptPath, null, false, null)); var obj = asmHelper.CreateObject("*"); IScriptConfig configObj = obj as IScriptConfig; if (configObj != null) { configObj.Config = GetScriptConfig(scriptPath, obj); } loadedScripts.Add(new ScriptItem( scriptPath, File.GetLastWriteTime(scriptPath).ToString(), asmHelper, obj )); return(obj); }
private bool CompileCSharpCode() { if (ScriptGenerationComplete == false) { return(false); } var progressId = this.ReportStart("Script Compilation", ScriptCode); try { CSScript.ShareHostRefAssemblies = true; CSScript.AssemblyResolvingEnabled = true; //var helper = new AsmHelper(CSScript.LoadCode(code, null, true)); var helper = new AsmHelper(CSScript.LoadCode(ScriptCode)); //the only reflection based call _gmacScriptInstance = (IGMacScript)helper.CreateObject("InteractiveScript"); _gmacScriptInstance.Ipr = Ipr; this.ReportFinish(progressId, "", ProgressEventArgsResult.Success); return(true); } catch (Exception e) { CompilationError = e; this.ReportError(e); this.ReportFinish(progressId, "", ProgressEventArgsResult.Failure); return(false); } }
public void LoadPlugins(string dir) { Plugins.Clear(); DeskApp._send = Publish; DeskApp._trace = LogPlugin; foreach (string script in Directory.GetFiles(dir, "*.cs")) { using (StreamReader sr = new StreamReader(script)) { try { string scriptCode = sr.ReadToEnd(); string name = Path.GetFileNameWithoutExtension(script); AsmHelper helper = new AsmHelper(CSScript.LoadCode(scriptCode, null, false)); IPlugin plugin = helper.CreateObject(name) as IPlugin; Plugins.Add(name, plugin); } catch (Exception ex) { //MessageBox.Show(ex.ToString(), "Load Plugin " + script, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Log(ex.ToString()); } sr.Close(); } } }
public static async void AddScripts() { //Get every c# file in our scripts folder string[] names = Directory.GetFiles(@"..\..\..\..\..\Scripts\", "*.cs"); foreach (var name in names) { string body = ""; if (File.Exists(name) == false) { Console.WriteLine("file not found: " + name); continue; } else { // I use CSSCript to load the cs files which has its own tag for adding or removing refrences // CSScript uses reflection to create a temporary type which creates refrence conflicts, so i // force only one refrence to most xna libraries and a refrence to this namespace using the css_ tags try { string header = "//css_ignore_namespace Microsoft.Xna.Framework " + "\n//css_ignore_namespace Microsoft.Xna.Framework.Graphics " + "\n//css_ignore_namespace Microsoft.Xna.Framework.Input " + "\n//css_ref MonoGame.Framework.dll " + "\nusing EmergingTech; " + "\nusing Microsoft.Xna.Framework; " + "\nusing Microsoft.Xna.Framework.Graphics; " + "\nusing Microsoft.Xna.Framework.Input; \n"; body = await ReadFileAsync(name); body = header + body; } catch (Exception e) { Console.WriteLine(e.Message); } } //Used to create dynamic assemblies AsmHelper assembly = null; try { //Load code into our assembly and put this assembly on our app domain // use of 'using' to make sure we dispose our temp files using (assembly = new AsmHelper(CSScript.LoadCode(body, null, true))) { //create our object from our assembly as a gamescript GameScript script = (GameScript)assembly.CreateObject("*"); script.name = name; gameScripts.Add(script); } } catch (Exception e) { Console.WriteLine(e.Message); } } Start(); }
public static void LoadFromFile(string fileName) { programStartDirectory = AppDomain.CurrentDomain.BaseDirectory + "/"; configDirectory = Path.GetDirectoryName(fileName) + "/"; var asm = new AsmHelper(CSScript.LoadCode(File.ReadAllText(fileName))); object data = null; bool metaDataExists = true; try { object metaData = null; try { metaData = asm.CreateObject("MetaData"); } catch (Exception) { metaDataExists = false; } if (metaDataExists) { var scriptText = callFromScript(asm, metaData, "*.makeConfig", ""); var patchDict = callFromScript(asm, metaData, "*.getPatchDictionary", new Dictionary <string, object>()); scriptText = Utils.patchConfigTemplate(scriptText, patchDict); asm = new AsmHelper(CSScript.LoadCode(scriptText)); data = asm.CreateObject("Data"); } } catch (Exception e) { MessageBox.Show(e.Message); } if (!metaDataExists) { try { data = asm.CreateObject("Data"); } catch (Exception) { return; } } levelsCount = callFromScript(asm, data, "*.getLevelsCount", 1); screensOffset = new OffsetRec[levelsCount]; palOffset = callFromScript(asm, data, "*.getPalOffset", new OffsetRec(0, 1, 0)); videoOffset = callFromScript(asm, data, "*.getVideoOffset", new OffsetRec(0, 1, 0)); videoObjOffset = callFromScript(asm, data, "*.getVideoObjOffset", new OffsetRec(0, 1, 0)); blocksOffset = callFromScript(asm, data, "*.getBlocksOffset", new OffsetRec(0, 1, 0)); screensOffset[0] = callFromScript(asm, data, "*.getScreensOffset", new OffsetRec(0, 1, 0)); screensOffset[0].width = callFromScript(asm, data, "*.getScreenWidth", 8); screensOffset[0].height = callFromScript(asm, data, "*.getScreenHeight", 8); if ((screensOffset[0].beginAddr == 0) && (screensOffset[0].recSize == 0)) { screensOffset = callFromScript(asm, data, "*.getScreensOffsetsForLevels", new OffsetRec[1]); } screensOffset2 = callFromScript(asm, data, "*.getScreensOffset2", new OffsetRec(0, 1, 0)); screenVertical = callFromScript(asm, data, "*.getScreenVertical", false); screenDataStride = callFromScript(asm, data, "*.getScreenDataStride", 1); wordLen = callFromScript(asm, data, "*.getWordLen", 1); littleEndian = callFromScript(asm, data, "*.isLittleEndian", false); useSegaGraphics = callFromScript(asm, data, "*.isUseSegaGraphics", false); blockSize4x4 = callFromScript(asm, data, "*.isBlockSize4x4", false); buildScreenFromSmallBlocks = callFromScript(asm, data, "isBuildScreenFromSmallBlocks", false); layersCount = callFromScript(asm, data, "*.getLayersCount", 1); levelRecs = callFromScript(asm, data, "*.getLevelRecs", new List <LevelRec>() { new LevelRec(0, 0, 1, 1, 0) }); //todo: remove or change to many lists interface minObjCoordX = callFromScript(asm, data, "*.getMinObjCoordX", 0); minObjCoordY = callFromScript(asm, data, "*.getMinObjCoordY", 0); minObjType = callFromScript(asm, data, "*.getMinObjType", 0); maxObjCoordX = callFromScript(asm, data, "*.getMaxObjCoordX", -1); //ConfigScript.getScreenWidth() * 32 maxObjCoordY = callFromScript(asm, data, "*.getMaxObjCoordY", -1); //ConfigScript.getScreenHeight() * 32; maxObjType = callFromScript(asm, data, "*.getMaxObjType", -1); //256 bigBlocksHierarchyCount = callFromScript <int>(asm, data, "*.getBigBlocksHierarchyCount", 1); bigBlocksCounts = new int[bigBlocksHierarchyCount]; for (int hierLevel = 0; hierLevel < bigBlocksHierarchyCount; hierLevel++) { bigBlocksCounts[hierLevel] = callFromScript(asm, data, "*.getBigBlocksCountHierarchy", 256, hierLevel); } bigBlocksCounts[0] = callFromScript(asm, data, "*.getBigBlocksCount", bigBlocksCounts[0]); bigBlocksOffsets = new OffsetRec[bigBlocksHierarchyCount]; for (int hierLevel = 0; hierLevel < bigBlocksHierarchyCount; hierLevel++) { bigBlocksOffsets[hierLevel] = callFromScript(asm, data, "*.getBigBlocksOffsetHierarchy", new OffsetRec(0, 1, 0), hierLevel); } bigBlocksOffsets[0] = callFromScript(asm, data, "*.getBigBlocksOffset", bigBlocksOffsets[0]); getVideoPageAddrFunc = callFromScript <GetVideoPageAddrFunc>(asm, data, "*.getVideoPageAddrFunc"); getVideoChunkFunc = callFromScript <GetVideoChunkFunc>(asm, data, "*.getVideoChunkFunc"); setVideoChunkFunc = callFromScript <SetVideoChunkFunc>(asm, data, "*.setVideoChunkFunc"); getBigBlocksFuncs = new GetBigBlocksFunc[bigBlocksHierarchyCount]; setBigBlocksFuncs = new SetBigBlocksFunc[bigBlocksHierarchyCount]; getBigBlocksFuncs = callFromScript <GetBigBlocksFunc[]>(asm, data, "*.getBigBlocksFuncs", new GetBigBlocksFunc[1]); setBigBlocksFuncs = callFromScript <SetBigBlocksFunc[]>(asm, data, "*.setBigBlocksFuncs", new SetBigBlocksFunc[1]); if (!buildScreenFromSmallBlocks) { getBigBlocksFuncs[0] = callFromScript <GetBigBlocksFunc>(asm, data, "*.getBigBlocksFunc", getBigBlocksFuncs[0]); setBigBlocksFuncs[0] = callFromScript <SetBigBlocksFunc>(asm, data, "*.setBigBlocksFunc", setBigBlocksFuncs[0]); } getSegaMappingFunc = callFromScript <GetSegaMappingFunc>(asm, data, "*.getSegaMappingFunc", (int index) => { return(Utils.readLinearBigBlockData(0, index)); }); setSegaMappingFunc = callFromScript <SetSegaMappingFunc>(asm, data, "*.setSegaMappingFunc", (int index, byte[] bb) => { Utils.writeLinearBigBlockData(0, index, bb); }); getBlocksFunc = callFromScript <GetBlocksFunc>(asm, data, "*.getBlocksFunc"); setBlocksFunc = callFromScript <SetBlocksFunc>(asm, data, "*.setBlocksFunc"); getPalFunc = callFromScript <GetPalFunc>(asm, data, "*.getPalFunc"); setPalFunc = callFromScript <SetPalFunc>(asm, data, "*.setPalFunc"); getObjectsFunc = callFromScript <GetObjectsFunc>(asm, data, "*.getObjectsFunc"); setObjectsFunc = callFromScript <SetObjectsFunc>(asm, data, "*.setObjectsFunc"); sortObjectsFunc = callFromScript <SortObjectsFunc>(asm, data, "*.sortObjectsFunc"); getLayoutFunc = callFromScript <GetLayoutFunc>(asm, data, "*.getLayoutFunc", Utils.getDefaultLayoutFunc()); setLayoutFunc = callFromScript <SetLayoutFunc>(asm, data, "*.setLayoutFunc", null); convertScreenTileFunc = callFromScript <ConvertScreenTileFunc>(asm, data, "*.getConvertScreenTileFunc"); backConvertScreenTileFunc = callFromScript <ConvertScreenTileFunc>(asm, data, "*.getBackConvertScreenTileFunc"); getBigTileNoFromScreenFunc = callFromScript <GetBigTileNoFromScreenFunc>(asm, data, "*.getBigTileNoFromScreenFunc", Utils.getBigTileNoFromScreen); setBigTileToScreenFunc = callFromScript <SetBigTileToScreenFunc>(asm, data, "*.setBigTileToScreenFunc", Utils.setBigTileToScreen); getObjectDictionaryFunc = callFromScript <GetObjectDictionaryFunc>(asm, data, "*.getObjectDictionaryFunc"); loadSegaBackFunc = callFromScript <LoadSegaBackFunc>(asm, data, "*.loadSegaBackFunc"); saveSegaBackFunc = callFromScript <SaveSegaBackFunc>(asm, data, "*.saveSegaBackFunc"); segaBackWidth = callFromScript(asm, data, "*.getSegaBackWidth", 64); segaBackHeight = callFromScript(asm, data, "*.getSegaBackHeight", 32); drawObjectFunc = callFromScript <DrawObjectFunc>(asm, data, "*.getDrawObjectFunc"); drawObjectBigFunc = callFromScript <DrawObjectBigFunc>(asm, data, "*.getDrawObjectBigFunc"); renderToMainScreenFunc = callFromScript <RenderToMainScreenFunc>(asm, data, "*.getRenderToMainScreenFunc"); isBigBlockEditorEnabled = callFromScript(asm, data, "*.isBigBlockEditorEnabled", true); isBlockEditorEnabled = callFromScript(asm, data, "*.isBlockEditorEnabled", true); isEnemyEditorEnabled = callFromScript(asm, data, "*.isEnemyEditorEnabled", true); objTypesPicturesDir = callFromScript(asm, data, "*.getObjTypesPicturesDir", "obj_sprites"); showScrollsInLayout = callFromScript(asm, data, "*.isShowScrollsInLayout", true); scrollsOffsetFromLayout = callFromScript(asm, data, "*.getScrollsOffsetFromLayout", 0); blocksCount = callFromScript(asm, data, "*.getBlocksCount", 256); blocksPicturesFilename = callFromScript(asm, data, "getBlocksFilename", ""); if (blocksPicturesFilename != "") { if (!File.Exists(ConfigScript.getBlocksPicturesFilename())) { throw new Exception("File does not exists: " + ConfigScript.getBlocksPicturesFilename()); } } blocksPicturesWidth = callFromScript(asm, data, "getPictureBlocksWidth", 32); usePicturesInstedBlocks = blocksPicturesFilename != ""; blockTypeNames = callFromScript(asm, data, "getBlockTypeNames", defaultBlockTypeNames); groups = callFromScript(asm, data, "getGroups", new GroupRec[0]); palBytesAddr = callFromScript(asm, data, "getPalBytesAddr", -1); loadAllPlugins(asm, data); }
public IScript ActivateScriptFromFile(string scriptPath) { if (String.IsNullOrEmpty(scriptPath)) { throw new ArgumentException("scriptPath", "A script path must be provided."); } if (!File.Exists(scriptPath)) { throw new ArgumentException("Can't find the script file: " + scriptPath); } var scriptName = Path.GetFileNameWithoutExtension(scriptPath); if (IsVerbose) { Console.WriteLine(""); Console.WriteLine("Activating script: " + scriptName); Console.WriteLine("Script path:"); Console.WriteLine(" " + scriptPath); Console.WriteLine(""); } CSScript.GlobalSettings.DefaultArguments = "/nl"; // TODO: Check if this is working //CSScript.GlobalSettings.ReportDetailedErrorInfo = IsDebug; // TODO: Check if needed var assemblyFile = FileNamer.GetScriptAssemblyPath(scriptName); DirectoryChecker.EnsureDirectoryExists(Path.GetDirectoryName(assemblyFile)); if (IsVerbose) { Console.WriteLine(""); Console.WriteLine("Assembly file..."); Console.WriteLine(" " + assemblyFile); Console.WriteLine(""); } // TODO: Check if settings are needed var scriptSettings = new Settings(); // TODO: Check if needed. // Could be causing errors with tmp dir access exception when using jenkins. // Keeping this line seems to fix errors with activation during install tests (intermittent failure) scriptSettings.InMemoryAsssembly = true; scriptSettings.HideCompilerWarnings = true; IScript script = null; // Load the script assembly try { CSScript.CacheEnabled = false; CSScript.GlobalSettings = scriptSettings; using (var helper = new AsmHelper(CSScript.Load(scriptPath))) { helper.CachingEnabled = false; script = (IScript)helper.CreateObject("*"); } // TODO: Remove if not needed // Set the assembly file last write time to the same as the script file, so it's easy to know they're matching //File.SetLastWriteTime(assemblyFile, File.GetLastWriteTime(scriptPath)); } catch (Exception ex) { throw new Exception("An error occurred when loading the '" + scriptName + "' script.", ex); } script.Construct(scriptName, ParentScript); return(script); }
public ConfigGrid(string filename) { asm = new AsmHelper(CSScript.Load(filename)); data = asm.CreateObject("Data"); }