public TransactionOut GetTransactionOut(WalletAggregateAddress walletAddr) { if (walletAddr == null) { throw new ArgumentNullException(nameof(walletAddr)); } if (walletAddr.Key == null) { throw new ArgumentNullException(nameof(walletAddr.Key)); } if (TransactionOut == null || !TransactionOut.Any()) { return(null); } var interpreter = new ScriptInterpreter(); var scriptBuilder = new ScriptBuilder(); var secondScript = scriptBuilder.New() .AddToStack(walletAddr.Key.GetSignature()) .AddToStack(walletAddr.Key.GetPublicKey()) .Build(); foreach (var transactionOut in TransactionOut) { if (interpreter.Check(transactionOut.Script, secondScript)) { return(transactionOut); } } return(null); }
public void Library_FunctionTypeOf() { IList <ScriptModule> modules = new List <ScriptModule>() { new ScriptModule("object", "object", ModuleTypeEnum.COMMON, false, _path + "Functions\\typeof_object.scr"), new ScriptModule("global", "global", ModuleTypeEnum.STARTUP, true, _path + "Functions\\typeof.scr") }; ScriptCompiler compiler = new ScriptCompiler(); ScriptProgramm programm = compiler.CompileProgramm(modules); ScriptInterpreter interpreter = new ScriptInterpreter(programm); foreach (InternalScriptType type in interpreter.Programm.InternalTypes) { Console.WriteLine(type.Description); } Console.WriteLine("--"); interpreter.Debugger.AddBreakpoint("global", 68, (interpreater) => { Assert.AreEqual(68, interpreter.CurrentLine); //Assert.AreEqual(interpreter.Programm.InternalTypes.Count, interpreter.Debugger.Eval("счетчик").AsInt()); }); interpreter.Debug(); }
private void LoadTaskInterpreter() { lock (LispTaskInterperterLock) try { if (_LispTaskInterperter != null) { return; } //WriteLine("Start Loading TaskInterperter ... '" + TaskInterperterType + "' \n"); _LispTaskInterperter = ClientManager.SingleInstance.TaskInterperter.newInterpreter(this); _LispTaskInterperter.LoadFile("cogbot.lisp", DebugWriteLine); Intern("clientManager", ClientManager); Intern("client", this); if (scriptEventListener == null) { scriptEventListener = new ScriptEventListener(_LispTaskInterperter, this); botPipeline.AddSubscriber(scriptEventListener); } // WriteLine("Completed Loading TaskInterperter '" + TaskInterperterType + "'\n"); // load the initialization string CatchUpInterns(); } catch (Exception e) { LogException("LoadTaskInterperter", e); } }
static void Main(string[] args) { try { CheckArgumentsHaveBeenSupplied(args); var scriptPath = args[0]; var scriptToRun = args[1]; CheckScriptPathIsValid(scriptPath); var scriptCollection = ScriptLoader.LoadScripts(CreateBinaryReaderForScriptFile(scriptPath)); CheckScriptNameIsValid(scriptCollection, scriptToRun); var fnRoutinesCaller = new FnRoutinesCaller(); var variablesManager = new VariablesManager(); var stack = new ValueStack(); var scriptInterpreter = new ScriptInterpreter(scriptToRun, scriptCollection[scriptToRun], fnRoutinesCaller, variablesManager, stack); scriptInterpreter.Run(); } catch (Exception exception) { Console.WriteLine(exception.Message); } Console.WriteLine("Done"); }
public void CheckClientSignature() { var clientKey = KeyStore.GetClientKey(); var clientWallet = BlockChainAddress.Deserialize("12K5LnVWKCu9QGyB39uGAgVSAfBs33PKS96HSL93"); var scriptBuilder = new ScriptBuilder(); var inputScript = scriptBuilder.New() .AddToStack(clientKey.GetSignature()) .AddToStack(clientKey.GetPublicKey()) .Build(); var outputScript = scriptBuilder.New() .AddOperation(OpCodes.OP_DUP) .AddOperation(OpCodes.OP_HASH160) .AddToStack(clientWallet.PublicKeyHash) .AddOperation(OpCodes.OP_EQUALVERIFY) .AddOperation(OpCodes.OP_CHECKSIG) .Build(); var serializedInputScript = inputScript.Serialize(); var serializedOutputScript = outputScript.Serialize(); var deserializedInputScript = Script.Deserialize(serializedInputScript); var deserializedOutputScript = Script.Deserialize(serializedOutputScript); var interpreter = new ScriptInterpreter(); bool isCorrect = interpreter.Check(deserializedInputScript, deserializedOutputScript); Assert.IsTrue(isCorrect); }
// Returns true if this precise check triggered an unlock public bool Check() { if (unlocked) { return(false); } ScriptInterpreter.Execute( interpreter.MakeGameEffects(script) ); // Logging if (unlocked) { string achievementName = GameManager.instance.localization.GetLineFromCategory("achievementName", "achievement" + id); Logger.Info("Achievement_" + id + " : " + achievementName + " unlocked !"); GameManager.instance.achievementManager.unlockedAchievements.Add(id); // Add the achievement ID to the player save // g_SteamAchievements->SetAchievement(entry.value.name); // Trigger steam achievement return(true); } return(false); }
public void CheckSignature() { var key = Key.Genererate(); var publicKeyHash = key.GetPublicKeyHashed(); var scriptBuilder = new ScriptBuilder(); var payload = Encoding.UTF8.GetBytes("sss"); var signature = key.Sign(payload); var inputScript = scriptBuilder.New() .AddToStack(signature) .AddToStack(key.GetPublicKey()) .Build(); var outputScript = scriptBuilder.New() .AddOperation(OpCodes.OP_DUP) .AddOperation(OpCodes.OP_HASH160) .AddToStack(publicKeyHash) .AddOperation(OpCodes.OP_EQUALVERIFY) .AddOperation(OpCodes.OP_CHECKSIG) .Build(); var serializedInputScript = inputScript.Serialize(); var serializedOutputScript = outputScript.Serialize(); var deserializedInputScript = Script.Deserialize(serializedInputScript); var deserializedOutputScript = Script.Deserialize(serializedOutputScript); var interpreter = new ScriptInterpreter(); bool isCorrect = interpreter.Check(deserializedInputScript, deserializedOutputScript); Assert.IsTrue(isCorrect); }
public void Check16EqualTo16() { var scriptBuilder = new ScriptBuilder(); var inputScript = scriptBuilder.New() .AddOperation(OpCodes.OP_1) .Build(); var outputScript = scriptBuilder.New() .AddOperation(OpCodes.OP_15) .AddOperation(OpCodes.OP_ADD) .AddOperation(OpCodes.OP_16) .AddOperation(OpCodes.OP_EQUAL) .AddOperation(OpCodes.OP_VERIFY) .Build(); var serializedInputScript = inputScript.Serialize(); var serializedOutputScript = outputScript.Serialize(); var deserializedInputScript = Script.Deserialize(serializedInputScript); var deserializedOutputScript = Script.Deserialize(serializedOutputScript); var interpreter = new ScriptInterpreter(); bool isCorrect = interpreter.Check(deserializedInputScript, deserializedOutputScript); Assert.IsTrue(isCorrect); }
public Script(string name, ScriptInterpreter interpreter = null, ScriptEngine engine = null) { this.engine = engine; Name = name; Entries = new List <Operator> (); this.interpreter = interpreter; }
//This method allows custom implementation of running a sample in Grammar Explorer // By default it evaluates a parse tree using default interpreter public virtual string RunSample(ParseTree parsedSample) { var interpreter = new ScriptInterpreter(this); interpreter.Evaluate(parsedSample); return(interpreter.GetOutput()); }
private static ScriptInterpreter GetScriptInterpreter() { if (ScriptInterpreter0 == null) { ScriptInterpreter0 = ScriptManager.LoadScriptInterpreter("lisp", null, ScriptInterpreterParent); } return(ScriptInterpreter0); }
public Achievement(int _id, string _condition, ScriptInterpreter _interpreter) { id = _id; unlocked = false; interpreter = _interpreter; script = "[" + _condition + "{UNLOCK_ACHIEVEMENT(id:" + id + ");}ELSE{}];"; }
public ScriptSystem() { GlobalVariables = new VariablesManager(); var fnRoutinesCaller = new FnRoutinesCaller(GlobalVariables); var valueStack = new ValueStack(); _interpreter = new ScriptInterpreter(fnRoutinesCaller, GlobalVariables, valueStack); }
internal RuntimeException(ScriptInterpreter interpreter, string message) : base(message) { _module = interpreter.CurrentModule.Name; _line = interpreter.CurrentLine; _message = message; base.Data["line"] = _line; base.Data["module"] = _module; base.Data["message"] = message; }
public void CreatingAScriptInterpreterWithNullVariableManagerThrowsArgumentNullExceptionException() { // ReSharper disable once NotAccessedVariable IScriptInterpreter interpreter; Action act = () => interpreter = new ScriptInterpreter(_mockFnRoutinesCaller.Object, null, _mockValueStack.Object); act.Should().Throw <ArgumentNullException>(); }
public ScriptEventListener(ScriptInterpreter interp, BotClient client) { taskInterperter = interp; taskInterperter.Intern("Client", client); taskInterperter.Intern("thisClient", client); if (client != null) WorldSystem = client.WorldSystem; thrJobQueue = new Thread(jobManager); thrJobQueue.Name = string.Format("ScriptEventListener Thread for {0}", (client ?? (Object)"ClientManager")); thrJobQueue.Start(); }
public void Dispose() { thrJobQueue.Abort(); lock (taskQueue) { taskQueue.Clear(); } //TODO decide if we should do this here // taskInterperter.Dispose(); taskInterperter = null; }
public void Library_MapCollection() { IList <ScriptModule> modules = new List <ScriptModule>() { new ScriptModule("global", "global", ModuleTypeEnum.STARTUP, true, _path + "map.scr") }; ScriptCompiler compiler = new ScriptCompiler(); ScriptProgramm programm = compiler.CompileProgramm(modules); ScriptInterpreter interpreter = new ScriptInterpreter(programm); interpreter.Debugger.AddBreakpoint("global", 7, (interpreater) => { Assert.AreEqual(7, interpreter.CurrentLine); Assert.AreEqual("Олимпиада в Москве", interpreter.Debugger.RegisterGetValue("значение").AsString()); Assert.AreEqual("Первый полет человека в космос.", interpreter.Debugger.RegisterGetValue("значение2").AsString()); }); interpreter.Debugger.AddBreakpoint("global", 10, (interpreater) => { Assert.AreEqual(10, interpreter.CurrentLine); }); interpreter.Debugger.AddBreakpoint("global", 14, (interpreater) => { Assert.AreEqual(14, interpreter.CurrentLine); Assert.AreEqual("Олимпиада в Москве", interpreter.Debugger.RegisterGetValue("значение").AsString()); Assert.AreEqual("Первый полет человека в космос.", interpreter.Debugger.RegisterGetValue("значение2").AsString()); }); interpreter.Debugger.AddBreakpoint("global", 17, (interpreater) => { Assert.AreEqual(17, interpreter.CurrentLine); Assert.AreEqual("Первый полет Гагарина в космос.", interpreter.Debugger.RegisterGetValue("значение2").AsString()); }); interpreter.Debugger.AddBreakpoint("global", 24, (interpreater) => { Assert.AreEqual(24, interpreter.CurrentLine); Assert.AreEqual(2, interpreter.Debugger.RegisterGetValue("counter").AsInt()); }); interpreter.Debugger.AddBreakpoint("global", 26, (interpreater) => { Assert.AreEqual(26, interpreter.CurrentLine); Assert.AreEqual(0, interpreter.Debugger.RegisterGetValue("значение").AsInt()); }); interpreter.Debug(); }
public static bool RemoveInterpreter(ScriptInterpreter interpreter) { lock (InterpLock) { if (!Interpreters.Contains(interpreter)) { Interpreters.Remove(interpreter); return(true); } return(false); } }
public void Library_SystemInfo() { IList <ScriptModule> modules = new List <ScriptModule>() { new ScriptModule("global", "global", ModuleTypeEnum.STARTUP, true, _path + "systeminfo.scr") }; ScriptCompiler compiler = new ScriptCompiler(); ScriptProgramm programm = compiler.CompileProgramm(modules); ScriptInterpreter interpreter = new ScriptInterpreter(programm); interpreter.Debug(); }
public ScriptEventListener(ScriptInterpreter interp, BotClient client) { taskInterperter = interp; taskInterperter.Intern("Client", client); taskInterperter.Intern("thisClient", client); if (client != null) { WorldSystem = client.WorldSystem; } thrJobQueue = new Thread(jobManager); thrJobQueue.Name = string.Format("ScriptEventListener Thread for {0}", (client ?? (Object)"ClientManager")); thrJobQueue.Start(); }
public ScriptInterpreter FindOrCreate(object key, ScriptInterpreter parent) { if (parent != null) return parent.newInterpreter(key); lock (interpsForObjects) { ScriptInterpreter mini; if (!interpsForObjects.TryGetValue(key, out mini)) { mini = newInterpreter(key); interpsForObjects[key] = mini; } return mini; } }
private static bool InstanceNewInterpTypes(object self) { Type bt = typeof(object); if (!ReferenceEquals(self, null)) { bt = self.GetType(); } bool changed = false; foreach (var list in CopyOf(ScannedInterpTypes)) { if (IsInterpType(list)) { if (LoadedInterpTypes.Contains(list)) { continue; } Type type = list; SafelyDo("load interptype " + list, () => { var mi = type.GetConstructor(new Type[] { bt }); if (mi == null) { mi = type.GetConstructor(new Type[] { typeof(object) }); } if (mi != null) { ScriptInterpreter si = (ScriptInterpreter) mi.Invoke(new object[] { self }); AddInterpreter(si); changed = true; } else { mi = type.GetConstructor(new Type[0]); ScriptInterpreter si = (ScriptInterpreter)mi.Invoke(new object[0]); si.Self = self; AddInterpreter(si); changed = true; } }); } } return(changed); }
private static bool IsCodeMatch(SimObject obj, object smatch) { ScriptInterpreter interp = GetScriptInterpreter(); lock (interp) { interp.Intern("this", obj); interp.Intern("thisClient", WorldObjects.GridMaster.client); string res = interp.Str(interp.Eval(smatch)); if (res.ToLower().StartsWith("t")) { return(true); } return(false); } }
/// <summary> /// Reads the pointer and returns some information about the script and the position of the script that is running /// </summary> /// <returns>Information of the interpreter</returns> public ScriptInterpreter GetScriptInterpreter() { ScriptInterpreter interpreter = new ScriptInterpreter(); if (ProcessHandle != IntPtr.Zero) { long scriptInterpreter_Addr = ProcessHandle.ReadInt32(ScriptInterpreter_Ptr); scriptInterpreter_Addr = ProcessHandle.ReadInt32(scriptInterpreter_Addr + 0x14); scriptInterpreter_Addr = ProcessHandle.ReadInt32(scriptInterpreter_Addr + 0x08); interpreter.Header_addr = ProcessHandle.ReadInt32(scriptInterpreter_Addr + 0); interpreter.EntryPoint_addr = ProcessHandle.ReadInt32(scriptInterpreter_Addr + 4); interpreter.InstructionPointer_addr = (int)scriptInterpreter_Addr + 8; } return(interpreter); }
internal Unifiable SystemExecute(Unifiable cmd, Unifiable langu, Request user) { if (IsNullOrEmpty(langu)) { langu = GlobalSettings.grabSetting("systemlang") ?? "bot"; } else { langu = ToLower(Trim(langu)); } Unifiable s = "The system tag should be doing '" + cmd + "' lang=" + langu; writeToLog(s.AsString()); SystemExecHandler handler; if (SettingsDictionaryReal.TryGetValue(ExecuteHandlers, langu, out handler)) { try { object o = handler(cmd, user); return(Unifiable.Create(o)); } catch (Exception e) { writeToLog(e); return(Unifiable.Empty); } } else { try { object self = user; ScriptInterpreter parent = null; ScriptInterpreter si = ScriptManager.LoadScriptInterpreter(langu, self, parent); object o = ScriptManager.EvalScriptInterpreter(cmd.ToValue(user.CurrentQuery), langu, self, parent, writeToLog); string siStr = si.Str(o); return(Unifiable.Create(siStr)); } catch (Exception e) { writeToLog(e); } } writeToLog(s); return(Unifiable.Empty); }
public ScriptInterpreter FindOrCreate(object key, ScriptInterpreter parent) { if (parent != null) { return(parent.newInterpreter(key)); } lock (interpsForObjects) { ScriptInterpreter mini; if (!interpsForObjects.TryGetValue(key, out mini)) { mini = newInterpreter(key); interpsForObjects[key] = mini; } return(mini); } }
public void SpeedTest_ArrayDebug() { IList <ScriptModule> modules = new List <ScriptModule>() { new ScriptModule("array_test", "foreach_test", ModuleTypeEnum.STARTUP, false, _path + "array.scr") }; ScriptCompiler compiler = new ScriptCompiler(); ScriptProgramm programm = compiler.CompileProgramm(modules); ScriptInterpreter interpreter = new ScriptInterpreter(programm); interpreter.Debugger.AddBreakpoint("array_test", 28, (interpreter_int) => { Assert.AreEqual(499999500000, interpreter_int.Debugger.RegisterGetValue("result").AsNumber()); }); interpreter.Debug(); }
public void SpeedTest_Precalc_Debug() { IList <ScriptModule> modules = new List <ScriptModule>() { new ScriptModule("other", "other", ModuleTypeEnum.STARTUP, false, _path + "speed_test.scr") }; ScriptCompiler compiler = new ScriptCompiler(); ScriptProgramm programm = compiler.CompileProgramm(modules); ScriptInterpreter interpreter = new ScriptInterpreter(programm); interpreter.Debugger.AddBreakpoint("other", 107, (interpreter_int) => { Assert.AreEqual(107, interpreter.CurrentLine, 10); Assert.AreEqual(1000000, interpreter.Debugger.RegisterGetValue("ф").AsInt()); }); interpreter.Debug(); }
public void SpeedTest_Structure() { IList <ScriptModule> modules = new List <ScriptModule>() { new ScriptModule("struct", "struct", ModuleTypeEnum.STARTUP, false, _path + "structure.scr") }; ScriptCompiler compiler = new ScriptCompiler(); ScriptProgramm programm = compiler.CompileProgramm(modules); ScriptInterpreter interpreter = new ScriptInterpreter(programm); System.Diagnostics.Stopwatch sw = new Stopwatch(); sw.Start(); interpreter.Run(); sw.Stop(); Assert.AreEqual(2000, sw.ElapsedMilliseconds, 200); }
public void SpeedTest_FunctionCall() { IList <ScriptModule> modules = new List <ScriptModule>() { new ScriptModule("function", "function", ModuleTypeEnum.STARTUP, false, _path + "speed_test_function_call.scr") }; ScriptCompiler compiler = new ScriptCompiler(); ScriptProgramm programm = compiler.CompileProgramm(modules); ScriptInterpreter interpreter = new ScriptInterpreter(programm); System.Diagnostics.Stopwatch sw = new Stopwatch(); sw.Start(); interpreter.Run(); sw.Stop(); Assert.AreEqual(3400, sw.ElapsedMilliseconds, 350); }
public object DynamicInvokeImpl(object[] args) { ScriptInterpreter i = Producer.Interpreter; Dictionary <string, object> dictionary = new Dictionary <string, object>(); foreach (var o in args) { if (o is EventArgs) { foreach (var info in o.GetType().GetProperties()) { dictionary.Add(info.Name, info.GetValue(info, null)); } } } CallDict(dictionary); return(true); }
public LispEventProducer(BotClient bc, ScriptInterpreter interp) : base(bc) { Interpreter = interp; // the subclass must now run this RegisterAll(); foreach (var type in bc.GetType().GetProperties()) { if (type.CanWrite) continue; if (type.GetIndexParameters().Length!=0) continue; if (type.Name.StartsWith("Is")) continue; HookEvents(type.GetValue(bc, null)); } }
private static ScriptInterpreter GetScriptInterpreter() { if (ScriptInterpreter0 == null) ScriptInterpreter0 = ScriptManager.LoadScriptInterpreter("lisp", null, ScriptInterpreterParent); return ScriptInterpreter0; }
public void initTaskInterperter() { lock (LispTaskInterperterLock) { if (_lispTaskInterperter == null) { if (!LispTaskInterperterNeedLoad) { return; throw new NullReferenceException("_lispTaskInterperter"); } LispTaskInterperterNeedLoad = false; try { DebugWriteLine(OpenMetaverse.Helpers.LogLevel.Debug, "Start Loading Main TaskInterperter ... '" + taskInterpreterType + "' \n"); _lispTaskInterperter = ScriptManager.LoadScriptInterpreter(taskInterpreterType, this, null); _lispTaskInterperter.LoadFile("cogbot.lisp",WriteLine); _lispTaskInterperter.Intern("clientManager", this); _scriptEventListener = new ScriptEventListener(_lispTaskInterperter, null); ///_lispTaskInterperter.Intern("thisClient", this); DebugWriteLine(OpenMetaverse.Helpers.LogLevel.Debug,"Completed Loading TaskInterperter '" + taskInterpreterType + "'\n"); // load the initialization string } catch (Exception e) { WriteLine("!Exception: " + e.GetBaseException().Message); WriteLine("error occured: " + e.Message); WriteLine(" Stack: " + e.StackTrace.ToString()); } } else { return;// _lispTaskInterperter; } } return;// _lispTaskInterperter; }
private void LoadTaskInterpreter() { lock (LispTaskInterperterLock) try { if (_LispTaskInterperter != null) return; //WriteLine("Start Loading TaskInterperter ... '" + TaskInterperterType + "' \n"); _LispTaskInterperter = ClientManager.SingleInstance.TaskInterperter.newInterpreter(this); _LispTaskInterperter.LoadFile("cogbot.lisp", DebugWriteLine); Intern("clientManager", ClientManager); Intern("client", this); if (scriptEventListener == null) { scriptEventListener = new ScriptEventListener(_LispTaskInterperter, this); botPipeline.AddSubscriber(scriptEventListener); } // WriteLine("Completed Loading TaskInterperter '" + TaskInterperterType + "'\n"); // load the initialization string CatchUpInterns(); } catch (Exception e) { LogException("LoadTaskInterperter", e); } }