public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { if ((double)_stack.Pop().Value == 0) { _environment.ProgramCounter = this.Jump; } }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { switch (this.Type) { case LArgumentType.Variable: { if (this.Data == 0 && _stack.Count > 0) { LValue _valPush = _stack.Pop(); Dictionary <string, LValue> _variableList = Helper.GetVariables(_assets, _environment, (double)_stack.Pop().Value); LValue _varFind = _variableList[this.Variable.Name]; switch (_varFind.Type) { case LType.Array: { _stack.Push(_varFind.Array[(int)(double)_valPush.Value]); break; } default: { throw new Exception(String.Format("Could not handle push for type: {0}", _varFind.Type)); } } } else { _stack.Push(Helper.GetVariables(_assets, _environment, this.Data)[this.Variable.Name]); } break; } default: { _stack.Push(this.Value); break; } } }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { LValue _valRight = _stack.Pop(); LValue _valLeft = _stack.Pop(); _stack.Push(_valLeft / _valRight); }
public Call(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { this.FunctionName = _game.Functions[_game.FunctionMapping[(int)((_code.Base + _reader.BaseStream.Position))]].Name; if (Runner.Function.Mapping.ContainsKey(this.FunctionName) == true) { this.Function = Runner.Function.Mapping[this.FunctionName]; this.Type = CallType.Function; } else { if (_game.Code.ContainsKey(this.FunctionName) == true) { this.Code = _game.Code[this.FunctionName]; this.Type = CallType.Method; } else { throw new Exception(String.Format("Could not find function or script named \"{0}\"", this.FunctionName)); } } this.Count = this.Data; this.Arguments = new LValue[this.Count]; _reader.ReadInt32(); }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { switch (this.Variable) { case "room": { _stack.Push(LValue.Real((double)_assets.CurrentRoom.Index)); break; } case "room_width": { _stack.Push(LValue.Real((double)_assets.CurrentRoom.Width)); break; } case "room_height": { _stack.Push(LValue.Real((double)_assets.CurrentRoom.Height)); break; } case "undefined": { _stack.Push(LValue.Undef()); break; } case "current_time": { _stack.Push(LValue.Real(VM.Timer.ElapsedMilliseconds)); break; } default: { throw new Exception(String.Format("Could not return built-in variable named: \"{0}\"", this.Variable)); } } }
public static void CODE(Game _assets, BinaryReader _reader, Chunk _chunk) { HandleKVP(_assets, _reader, delegate(Int32 _offset) { LCode _codeGet = new LCode(_assets, _reader); _assets.Code.Add(_codeGet.Name, _codeGet); _assets.CodeMapping.Add(_codeGet); }); }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { for (int i = 0; i < this.Count; i++) { this.Arguments[i] = _stack.Pop(); } _stack.Push(this.Function(_assets, _environment, this.Arguments, this.Count, _stack)); }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { switch ((LArgumentType)this.Argument) { case LArgumentType.Variable: { _stack.Push(_assets.GlobalScope.Variables[this.Variable]); break; } default: { throw new Exception(String.Format("Could not push unimplemented global type: \"{0}\"", (LArgumentType)this.Argument)); } } }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { LValue _valRight = _stack.Pop(); LValue _valLeft = _stack.Pop(); if (_valRight.Number == 0 || _valLeft.Number == 0) { _stack.Push(_valLeft); } else { _stack.Push(LValue.Real(_valLeft.Number % _valRight.Number)); } }
public PushGlobal(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { switch ((LArgumentType)this.Argument) { case LArgumentType.Variable: { this.Variable = _game.Variables[_game.VariableMapping[(int)((_code.Base + _reader.BaseStream.Position)) - 4]].Name; _reader.ReadInt32(); break; } default: { throw new Exception(String.Format("Could not parse unimplemented global push type: \"{0}\"", (LArgumentType)this.Argument)); } } }
public Pop(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { this.ArgTo = (LArgumentType)(this.Argument & 0xF); this.ArgFrom = (LArgumentType)((this.Argument >> 4) & 0xF); switch (this.ArgTo) { case LArgumentType.Variable: { Int32 _varOffset = (int)((_code.Base + _reader.BaseStream.Position)) - 4; this.Variable = _game.Variables[_game.VariableMapping[_varOffset]]; _reader.ReadInt32(); break; } default: { throw new Exception(String.Format("Could not pop from {0} to {1}", this.ArgTo, this.ArgFrom)); } } }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { double _instScope = _stack.Pop().Number; switch (_instScope) { case -9: { _instScope = _stack.Pop().Number; break; } } /* * NOTE: * The code here isn't great, I don't really want to do code execution this way. * I think that the code should be ran in the current scope, and we'll just have a stack * that holds each instance scope in it. This does work, but doesn't really follow the * pattern set by Runner.exe and will likely lead to issues down the line. * - Nommiin */ if (_instScope >= 0 && _instScope < LInstance.IDStart) { List <LInstance> _instList = LInstance.FindList(_assets, _instScope, true); if (_instList != null) { foreach (LInstance _instGet in _instList) { _instGet.Environment.Locals = _environment.Locals; _instGet.Environment.ExecuteCode(_assets, _code, new Tuple <int, int>(_environment.ProgramCounter + 1, this.Jump)); } } } else { LInstance _instGet = _assets.InstanceMapping[_instScope]; if (_instGet != null) { _instGet.Environment.Locals = _environment.Locals; _instGet.Environment.ExecuteCode(_assets, _code, new Tuple <int, int>(_environment.ProgramCounter + 1, this.Jump)); } } _environment.ProgramCounter = this.Jump; }
public Push(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { this.IsArray = false; this.Type = (LArgumentType)this.Argument; switch (this.Type) { case LArgumentType.Error: { this.Value = new LValue(LType.Number, (double)this.Data); break; } case LArgumentType.Integer: { this.Value = new LValue(LType.Number, (double)_reader.ReadInt32()); break; } case LArgumentType.Long: { this.Value = new LValue(LType.Number, (double)_reader.ReadInt64()); break; } case LArgumentType.Double: { this.Value = new LValue(LType.Number, (double)_reader.ReadDouble()); break; } case LArgumentType.String: { this.Value = new LValue(LType.String, (string)_game.StringMapping[_reader.ReadInt32()].Value); break; } case LArgumentType.Variable: { this.Variable = _game.Variables[_game.VariableMapping[(int)((_code.Base + _reader.BaseStream.Position)) - 4]]; _reader.ReadInt32(); break; } default: { throw new Exception(String.Format("Could not parse unimplemented push type {0}", this.Type)); } } }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { LValue _compRight = _stack.Pop(); LValue _compLeft = _stack.Pop(); switch (this.Type) { case LConditionType.Equal: _stack.Push(_compLeft == _compRight); break; case LConditionType.NotEqual: _stack.Push(_compLeft != _compRight); break; case LConditionType.LessThan: _stack.Push(_compLeft < _compRight); break; case LConditionType.GreaterThan: _stack.Push(_compLeft > _compRight); break; case LConditionType.LessEqual: _stack.Push(_compLeft <= _compRight); break; case LConditionType.GreaterEqual: _stack.Push(_compLeft >= _compRight); break; } }
public void ExecuteCode(Game _assets, LCode _code, Tuple <int, int> _range = null) { this.Current = _code; if (_range == null) { _range = new Tuple <int, int>(0, this.Current.Instructions.Count); } for (this.ProgramCounter = _range.Item1; this.ProgramCounter < _range.Item2; this.ProgramCounter++) { _code.Instructions[this.ProgramCounter].Perform(_assets, this, _code, this.Stack); } #if (DEBUG) if (_assets.Headless == true) { Console.WriteLine("Instance Variables (Object: {0}, Count: {1})", (this.Instance.Object != null ? this.Instance.Object.Name : "N/A"), this.Instance.Variables.Count); foreach (KeyValuePair <string, LValue> _instVar in this.Instance.Variables) { Console.WriteLine("{0}.{1} = {2}", this.Instance.ID, _instVar.Key, _instVar.Value.Value); } } #endif }
public LEvent(LObject _object, Game _assets, BinaryReader _reader, LObject _owner, Int32 _type) { this.Owner = _owner; this.Subtype = _type; this.LibraryID = _reader.ReadInt32(); this.ID = _reader.ReadInt32(); this.Type = (ActionType)_reader.ReadInt32(); this.UseRelative = _reader.ReadLBoolean(); this.IsQuestion = _reader.ReadLBoolean(); this.ApplyTo = _reader.ReadLBoolean(); this.Execution = (ActionExecution)_reader.ReadInt32(); this.Name = _assets.GetString(_reader.ReadInt32()); this.Code = _assets.CodeMapping[_reader.ReadInt32()]; this.ArgumentCount = _reader.ReadInt32(); this.Caller = _reader.ReadInt32(); this.IsRelative = _reader.ReadLBoolean(); this.IsNot = _reader.ReadLBoolean(); switch (this.Code.Name.Replace("gml_Object_" + _object.Name + "_", "")) { case "PreCreate_0": _object.PreCreate = this.Code; break; case "Create_0": _object.Create = this.Code; break; case "Step_1": _object.BeginStep = this.Code; break; case "Step_0": _object.Step = this.Code; break; case "Step_2": _object.EndStep = this.Code; break; case "Draw_0": _object.Draw = this.Code; break; case "Destroy_0": _object.Destroy = this.Code; break; case "CleanUp_0": _object.CleanUp = this.Code; break; } }
/// <summary> /// 号码后6位。 /// </summary> /// <returns></returns> public string CodePart2() { return(LCode.Substring(6, 6)); }
public LInstance(Game _assets, LObject _object, bool _include = false, double _x = 0, double _y = 0) { this.Object = _object; this.ID = LInstance.IDCount++; this.Environment = new Domain(this); this.Variables = new Dictionary <string, LValue>() { ["x"] = new LValue(LType.Number, _x), ["y"] = new LValue(LType.Number, _y), ["xprevious"] = new LValue(LType.Number, _x), ["yprevious"] = new LValue(LType.Number, _y), ["xstart"] = LValue.Real(_x), ["ystart"] = LValue.Real(_y), ["id"] = new LValue(LType.Number, ID), ["solid"] = new LValue(LType.Number, (double)(_object.Solid ? 1 : 0)), ["visible"] = new LValue(LType.Number, (double)(_object.Visible ? 1 : 0)), ["persistent"] = new LValue(LType.Number, (double)(_object.Persistent ? 1 : 0)), ["depth"] = new LValue(LType.Number, (double)_object.Depth), ["alarm"] = LValue.Values(Enumerable.Repeat(LValue.Real(0), 8).ToArray()),//better than writing 8 LValue.Real(0) ["object_index"] = new LValue(LType.Number, (double)_object.Index), ["sprite_index"] = new LValue(LType.Number, (double)(_object.Sprite != null ? _object.Sprite.Index : -1)), ["sprite_width"] = new LValue(LType.Number, (double)(_object.Sprite != null ? _object.Sprite.Width : 0)), ["sprite_height"] = new LValue(LType.Number, (double)(_object.Sprite != null ? _object.Sprite.Height : 0)), ["sprite_xoffset"] = new LValue(LType.Number, (double)(_object.Sprite != null ? _object.Sprite.XOrigin : 0)), ["sprite_yoffset"] = new LValue(LType.Number, (double)(_object.Sprite != null ? _object.Sprite.YOrigin : 0)), ["image_alpha"] = new LValue(LType.Number, (double)1), ["image_angle"] = new LValue(LType.Number, (double)30), ["image_blend"] = new LValue(LType.Number, (double)0xFFFFFF), ["image_index"] = new LValue(LType.Number, (double)0), ["image_number"] = new LValue(LType.Number, (double)(_object.Sprite != null ? _object.Sprite.FrameCount : 0)), ["image_speed"] = new LValue(LType.Number, (double)(_object.Sprite != null ? _object.Sprite.PlaybackSpeed : 1)), ["image_xscale"] = new LValue(LType.Number, (double)1), ["image_yscale"] = new LValue(LType.Number, (double)1), ["mask_index"] = new LValue(LType.Number, (double)(_object.Mask != null ? _object.Mask.Index : -1)), ["bbox_left"] = new LValue(LType.Number, _object.Mask != null ? _x + _object.Mask.BoundsLeft : _x), ["bbox_right"] = new LValue(LType.Number, _object.Mask != null ? _x + _object.Mask.BoundsRight : _x), ["bbox_top"] = new LValue(LType.Number, _object.Mask != null ? _y + _object.Mask.BoundsTop : _y), ["bbox_bottom"] = new LValue(LType.Number, _object.Mask != null ? _y + _object.Mask.BoundsBottom : _y), }; if (_include == true) { _assets.InstanceList.Add(this); _assets.InstanceMapping[this.ID] = this; if (_assets.ObjectInstances.ContainsKey(this.Object.Index) == false) { _assets.ObjectInstances[this.Object.Index] = new List <LInstance>(); } _assets.ObjectInstances[this.Object.Index].Add(this); } this.PreCreate = _object.PreCreate; this.Create = _object.Create; this.BeginStep = _object.BeginStep; this.Step = _object.Step; this.EndStep = _object.EndStep; this.Draw = _object.Draw; this.Destroy = _object.Destroy; this.CleanUp = _object.CleanUp; }
public Exit(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { }
public PopEnvironment(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { this.Offset = (Int32)((_reader.BaseStream.Position + (this.Raw << 9 >> 7)) - 4); }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { Console.WriteLine("Stack Size: {0}", _stack.Count); throw new Exception(""); }
public PushImmediate(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { this.Value = new LValue(LType.Number, (double)this.Data); }
public virtual void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { Console.WriteLine("[WARNING] - Could not perform action for unimplemented opcode: {0} in {1}", this.Opcode, _code.Name); }
public PushLocal(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { this.Variable = _game.Variables[_game.VariableMapping[(int)((_code.Base + _reader.BaseStream.Position)) - 4]].Name; _reader.ReadInt32(); }
public override void Perform(Game _assets, Domain _environment, LCode _code, Stack <LValue> _stack) { if (_environment.ArrayNext == true) { int _arrayIndex = (int)(double)_stack.Pop().Value; Dictionary <string, LValue> _variableList = Helper.GetVariables(_assets, _environment, (double)_stack.Pop().Value); if (_variableList.ContainsKey(this.Variable.Name) == false || _variableList[this.Variable.Name].Type != LType.Array) { _variableList[this.Variable.Name] = new LValue(LType.Array, new LValue[_arrayIndex + 1]); for (int i = 0; i <= _arrayIndex; i++) { _variableList[this.Variable.Name].Array[i] = new LValue(LType.Number, (double)0); } } LValue _valGet = _variableList[this.Variable.Name]; if (_arrayIndex > _valGet.Array.Length) { LValue _valCopy = new LValue(LType.Array, new LValue[_arrayIndex + 1]); for (int i = 0; i <= _arrayIndex; i++) { if (i < _valGet.Array.Length) { _valCopy.Array[i] = _valGet.Array[i]; } else { _valCopy.Array[i] = new LValue(LType.Number, (double)0); } } _variableList[this.Variable.Name] = _valCopy; _valGet = _valCopy; } _valGet.Array[_arrayIndex] = _stack.Pop(); _environment.ArrayNext = false; } else { double _varScope = this.Data; if (this.Data == 0 && _stack.Count > 1) { switch ((double)_stack.Pop()) { case -9: { _varScope = _stack.Pop(); break; } } } if (_varScope >= 0 && _varScope < LInstance.IDStart) { LValue _valSet = _stack.Pop(); List <LInstance> _instList = LInstance.FindList(_assets, _varScope, true); if (_instList != null) { foreach (LInstance _instGet in _instList) { _instGet.Variables[this.Variable.Name] = _valSet; } } } else { Helper.GetVariables(_assets, _environment, _varScope)[this.Variable.Name] = _stack.Pop(); } } }
public BranchFalse(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction, _game, _code, _reader) { }
/// <summary> /// 号码前6位。 /// </summary> /// <returns></returns> public string CodePart1() { return(LCode.Substring(0, 6)); }
public Conditional(Int32 _instruction, Game _game, LCode _code, BinaryReader _reader) : base(_instruction) { this.Type = (LConditionType)((this.Data >> 8) & 0xFF); }