public string Compile(ScriptMetaData scriptMetaData, ref string script) { // Convert script to CS string scriptCS = m_LSL2CS.Convert(ref script); // Use CS compiler to compile it return m_Compiler_CS.Compile(scriptMetaData, ref scriptCS); }
public Result <List <ScriptMetaData> > ReadCld(string fileName) { var data = Result.Ok() .Ensure(() => File.Exists(fileName), "Checklist file " + fileName + " does not exist") .OnSuccess(() => { using (var fs = new FileStream(fileName, FileMode.Open)) using (var binRead = new BinaryReader(fs)) { var returnValue = new List <ScriptMetaData>(); while (fs.Position < fs.Length) { var cldData = new ScriptMetaData { Key = String.Empty, Name = binRead.ReadString(), IsEnabled = binRead.ReadBoolean(), Info = String.Empty }; returnValue.Add(cldData); } return(Result.Ok(returnValue)); } }); return(data); }
private Script CreateTauntScript(bool isStroking) { var lines = new List <string> { "(TauntSub)", }; if (!isStroking) { lines.Add("#StartStroking"); } lines.AddRange(new List <string> { "#EdgeTaunt", "@Goto(TauntSub)", "@End", }); var metaData = new ScriptMetaData { Info = "Endless loop where Domme taunts the sub until the sub edges", Name = "Taunt(Edge)", Key = "Generated", }; return(new Script(metaData, lines)); }
public string Compile(ScriptMetaData scriptMetaData, ref string script) { // Convert script to CS string scriptCS = m_LSL2CS.Convert(ref script); // Use CS compiler to compile it return(m_Compiler_CS.Compile(scriptMetaData, ref scriptCS)); }
public Result <Script> GetScript(ScriptMetaData metaData) { try { return(Result.Ok(new Script(metaData, File.ReadAllLines(metaData.Key).ToList()))); } catch (Exception ex) { return(Result.Fail <Script>(ex.Message)); } }
public IScriptCompiler FindCompiler(ScriptMetaData scriptMetaData) { string compiler = "Compiler_LSL"; if (scriptMetaData.ContainsKey("Compiler")) compiler = scriptMetaData["Compiler"]; lock (Compilers) { if (!Compilers.ContainsKey(compiler)) throw new Exception("Requested script compiler \"" + compiler + "\" does not exist."); return Compilers[compiler]; } }
private Result <ScriptMetaData> CreateScriptMetaData(string id) { if (!File.Exists(id)) { return(Result.Fail <ScriptMetaData>(id + " does not exist please try again.")); } var script = new ScriptMetaData { Name = Path.GetFileName(id).Replace(".txt", ""), Key = id, Info = GetScriptInfo(id) }; return(Result.Ok(script)); }
public override Result <Session> PerformCommand(Session session, string line) { return(Result.Ok(session.Clone()) .Ensure(s => !s.Domme.WasGreeted, "Risky Pick cannot be started from the Games window when there is a session in progress!") .Ensure(s => s.GameBoard == null, "A new Risky Pick game cannot be started until the current game is finished!") // .Ensure(s => s.GameBoard.EdgesOwed == 0, "You still owe edges from your previous game!") .Ensure(s => s.Sub.Purse[TokenDenomination.Bronze] >= RiskyPickCost, "It costs 100 Bronze Tokens to play Risky Pick!") .Ensure(s => File.Exists(_pathsAccessor.RiskyPickScript), _pathsAccessor.RiskyPickScript + " was not found.") .OnSuccess(s => { var smd = new ScriptMetaData { Key = _pathsAccessor.RiskyPickScript, Info = "Risky Pick Game. Similar to Deal or No Deal", IsEnabled = true, Name = "Risky Pick Game" }; var script = new Script(smd, File.ReadAllLines(_pathsAccessor.RiskyPickScript)); s.Sub.Purse[TokenDenomination.Bronze] = -RiskyPickCost; s.GameBoard = RiskyPickGameBoard.Create(GetRiskyPickCaseValues()); OnCommandProcessed(s, script); //RiskyState = True // mainWindow.ssh.RiskyDeal = True // SetupRiskyPick() // PlayRiskyPickButton.Text = "" // PlayRiskyPickButton.Enabled = False // mainWindow.ssh.StrokeTauntVal = -1 // If Directory.Exists(My.Settings.DomImageDir) AndAlso mainWindow.ssh.SlideshowLoaded Then // mainWindow.LoadDommeImageFolder() // End If // s.BeginSession(script) return s; })); }
public Result <List <ScriptMetaData> > ReadCld(string scriptHomeDir, string fileName) { var data = Result.Ok() .Ensure(() => File.Exists(fileName), "Checklist file " + fileName + " does not exist") .OnSuccess(() => { using (var fs = new FileStream(fileName, FileMode.Open)) using (var binRead = new BinaryReader(fs)) { var returnValue = ReadDirectory(scriptHomeDir); while (fs.Position + 1 < fs.Length) { var name = binRead.ReadString(); var key = scriptHomeDir + name + ".txt"; var cldData = returnValue.FirstOrDefault(smd => smd.Key == key); if (cldData == null) { cldData = new ScriptMetaData { Key = key }; returnValue.Add(cldData); } cldData.Key = key; cldData.Name = name; cldData.IsEnabled = cldData.IsEnabled && binRead.ReadBoolean() && File.Exists(key); cldData.Info = string.Empty; cldData.IsChastity = name.ToLower().Contains("_chastity"); cldData.IsBeg = name.ToLower().Contains("_beg"); cldData.IsEdge = name.ToLower().Contains("_edge"); cldData.IsRestricted = name.ToLower().Contains("_restricted"); //returnValue.Add(cldData); } return(Result.Ok(returnValue)); } }); return(data); }
//internal Dictionary<int, IScriptScheduler> ScriptMapping = new Dictionary<int, IScriptScheduler>(); // // HANDLE EVENTS FROM SCRIPTS // We will handle script add, change and remove events outside of command pipeline // #region Script Add/Change/Remove void Events_RezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine) { // ### // # New script created // ### m_log.DebugFormat( "[{0}] NEW SCRIPT: localID: {1}, itemID: {2}, startParam: {3}, postOnRez: {4}, engine: {5}", Name, localID, itemID, startParam, postOnRez, engine); // Make a script object ScriptStructure scriptObject = new ScriptStructure(); scriptObject.RegionInfo = RegionInfo; scriptObject.LocalID = localID; scriptObject.ItemID = itemID; scriptObject.Source = script; // // Get MetaData from script header // ScriptMetaData scriptMetaData = ScriptMetaData.Extract(ref script); scriptObject.ScriptMetaData = scriptMetaData; foreach (string key in scriptObject.ScriptMetaData.Keys) { m_log.DebugFormat("[{0}] Script metadata: Key: \"{1}\", Value: \"{2}\".", Name, key, scriptObject.ScriptMetaData[key]); } // // Load this assembly // // TODO: Use Executor to send a command instead? m_log.DebugFormat("[{0}] Adding script to scheduler", Name); RegionInfo.FindScheduler(scriptObject.ScriptMetaData).AddScript(scriptObject); // Add to our internal mapping //ScriptMapping.Add(itemID, Schedulers[scheduler]); }
public IScriptScheduler FindScheduler(ScriptMetaData scriptMetaData) { string scheduler = "Scheduler"; if (scriptMetaData.ContainsKey("Scheduler")) scheduler = scriptMetaData["Scheduler"]; lock (Schedulers) { if (!Schedulers.ContainsKey(scheduler)) throw new Exception("Requested script scheduler \"" + scheduler + "\" does not exist."); return Schedulers[scheduler]; } }
public string Compile(ScriptMetaData data, ref string _script) { // Add "using", "inherit", default constructor, etc around script. string script = PreProcessScript(ref _script); // Get filename based on content string md5Sum = System.Convert.ToBase64String( MD5Sum.ComputeHash( System.Text.Encoding.ASCII.GetBytes(script) )); // Unique name for this assembly ScriptAssemblyName = "SECS_Script_" + FileNameFixer.Replace(md5Sum, "_"); string OutFile = Path.Combine(ScriptEnginesPath, ScriptAssemblyName + ".dll"); // Make sure target dir exist if (!Directory.Exists(ScriptEnginesPath)) { try { Directory.CreateDirectory(ScriptEnginesPath); } catch { } } // Already exist? No point in recompiling if (File.Exists(OutFile)) { return(OutFile); } // // Dump source code // string dumpFile = OutFile + ".txt"; try { if (File.Exists(dumpFile)) { File.Delete(dumpFile); } File.WriteAllText(dumpFile, script); } catch (Exception e) { m_log.DebugFormat("[{0}] Exception trying to dump script source code to file \"{1}\": {2}", Name, dumpFile, e.ToString()); } // // COMPILE // CompilerParameters parameters = new CompilerParameters(); parameters.IncludeDebugInformation = true; //string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); foreach (string file in AppDomainAssemblies) { parameters.ReferencedAssemblies.Add(file); m_log.DebugFormat("[{0}] Adding reference for compile: \"{1}\".", Name, file); } //lock (commandProvider) //{ // foreach (string key in commandProvider.Keys) // { // IScriptCommandProvider cp = commandProvider[key]; // string // file = cp.GetType().Assembly.Location; // parameters.ReferencedAssemblies.Add(file); // m_log.DebugFormat("[{0}] Loading command provider assembly \"{1}\" into AppDomain: \"{2}\".", Name, // key, file); // } //} parameters.GenerateExecutable = false; parameters.OutputAssembly = OutFile; parameters.IncludeDebugInformation = true; //parameters.WarningLevel = 1; // Should be 4? parameters.TreatWarningsAsErrors = false; // Do compile CompilerResults results = CompileProvider.CompileAssemblyFromSource(parameters, script); // // WARNINGS AND ERRORS // //TODO int display = 5; if (results.Errors.Count > 0) { string errtext = String.Empty; foreach (CompilerError CompErr in results.Errors) { // Show 5 errors max // if (display <= 0) { break; } display--; string severity = "Error"; if (CompErr.IsWarning) { severity = "Warning"; } //TODO: Implement KeyValuePair <int, int> lslPos = new KeyValuePair <int, int>(); //lslPos = "NOT IMPLEMENTED";// FindErrorPosition(CompErr.Line, CompErr.Column); string text = CompErr.ErrorText; // The Second Life viewer's script editor begins // countingn lines and columns at 0, so we subtract 1. errtext += String.Format("Line ({0},{1}): {4} {2}: {3}\n", lslPos.Key - 1, lslPos.Value - 1, CompErr.ErrorNumber, text, severity); } if (!File.Exists(OutFile)) { throw new Exception(errtext); } } // TODO: Process errors return(OutFile); }