protected AsmCommandOld(JsmCommand command, int offset, AsmEvent script) { if (offset < 0 || offset >= script.Count) { throw new ArgumentOutOfRangeException("offset"); } Script = Exceptions.CheckArgumentNull(script, "script"); Offset = offset; Operation = Script.GetOperation(command, offset); }
private void CreateExternalBindings() { foreach (AsmEvent evt in _scripts.GetOrderedModules().SelectMany(module => module.GetOrderedEvents())) { for (int i = 0; i < evt.Count; i++) { JsmOperation operation = evt[i]; switch (operation.Command) { case JsmCommand.REQ: case JsmCommand.REQEW: case JsmCommand.REQSW: { AsmSegment source = evt.Segments.GetSegmentByOffset(i); AsmValueSource labelTargetEvent = AsmValueSource.Create(evt, i - 1); AsmAbsoluteRequestBinding binding = new AsmAbsoluteRequestBinding(source, i - source.Offset, operation.Argument, labelTargetEvent); source.OutputBindings.Add(binding); AsmSegment[] targets = binding.ResolveTargets(); if (targets != null) { foreach (AsmSegment target in targets) { target.InputBindings.Add(binding); } } break; } case JsmCommand.PREQ: case JsmCommand.PREQEW: case JsmCommand.PREQSW: { AsmSegment source = evt.Segments.GetSegmentByOffset(i); AsmValueSource labelTargetEvent = AsmValueSource.Create(evt, i - 1); AsmRelativeRequestBinding binding = new AsmRelativeRequestBinding(source, i - source.Offset, operation.Argument, labelTargetEvent); source.OutputBindings.Add(binding); AsmSegment[] targets = binding.ResolveTargets(); if (targets != null) { foreach (AsmSegment target in targets) { target.InputBindings.Add(binding); } } break; } } } } }
private void GetJumps(AsmEvent evt, out List <int> jumpFrom, out List <int> jumpTo) { jumpFrom = new List <int>(); jumpTo = new List <int>(); for (int i = 0; i < evt.Count; i++) { JsmOperation opetation = evt[i]; switch (opetation.Command) { case JsmCommand.JMP: case JsmCommand.JPF: jumpFrom.Add(i); jumpTo.Add(Math.Max(0, i + opetation.Argument)); // JMP -5479 break; } } }
private void CreateInternalBindings(AsmSegments segments, List <int> jumpFrom, List <int> jumpTo) { for (int s = 0; s < segments.Count - 1; s++) { AsmSegment source = segments[s]; AsmSegment target = segments[s + 1]; JsmOperation last = source[source.Length - 1]; if (last.Command == JsmCommand.JPF) { AsmConditionBinding binding = new AsmConditionBinding(source, target, AsmValueSource.Create(source, source.Length - 2), true); source.OutputBindings.Add(binding); target.InputBindings.Add(binding); } else if (last.Command != JsmCommand.JMP) { AsmHardlinkBinding binding = new AsmHardlinkBinding(source, target); source.OutputBindings.Add(binding); target.InputBindings.Add(binding); } } for (int i = 0; i < jumpFrom.Count; i++) { int fromIndex = jumpFrom[i]; int toIndex = jumpTo[i]; AsmSegment source = segments.GetSegmentByOffset(fromIndex); AsmSegment target = segments.GetSegmentByOffset(toIndex); JsmOperation last = source[source.Length - 1]; if (last.Command == JsmCommand.JMP) { AsmHardlinkBinding binding = new AsmHardlinkBinding(source, target); source.OutputBindings.Add(binding); target.InputBindings.Add(binding); } else if (last.Command == JsmCommand.JPF) { AsmConditionBinding binding = new AsmConditionBinding(source, target, AsmValueSource.Create(source, source.Length - 2), false); source.OutputBindings.Add(binding); target.InputBindings.Add(binding); } } }
public static AsmValueSource Create(AsmEvent evt, int offset) { JsmOperation operation = evt[offset]; switch (operation.Command) { case JsmCommand.PSHN_L: return(new AsmStaticValueSource(operation)); case JsmCommand.PSHI_L: case JsmCommand.PSHM_B: case JsmCommand.PSHM_W: case JsmCommand.PSHM_L: case JsmCommand.PSHSM_B: case JsmCommand.PSHSM_W: case JsmCommand.PSHSM_L: case JsmCommand.PSHAC: case JsmCommand.CAL: return(new AsmUnknownValueSource(evt, offset)); default: return(new AsmUnknownValueSource(evt, offset)); } }
public bool ReadScripts(Location location) { if (_root == null) { return(false); } XmlElement node = _root["Scripts"]; if (node == null) { return(false); } if (!node.GetBoolean("IsExists")) { return(true); } string scriptsFile = Path.ChangeExtension(_xmlPath, ".sct"); if (!File.Exists(scriptsFile)) { return(false); } using (Stream input = new FileStream(scriptsFile, FileMode.Open, FileAccess.Read, FileShare.Read)) using (BinaryReader br = new BinaryReader(input, Encoding.UTF8)) { string magicNumber = br.ReadString(); if (magicNumber != "FF8S") { throw Exceptions.CreateException("Неверное магическое число: '{0}'", magicNumber); } int groupsCount = br.ReadInt32(); AsmModule previousModule = null; AsmCollection groups = new AsmCollection(groupsCount); for (ushort g = 0; g < groupsCount; g++) { ushort executionOrder = br.ReadUInt16(); ushort label = br.ReadUInt16(); string title = br.ReadString(); JsmModuleType type = (JsmModuleType)br.ReadInt32(); int scriptsCount = br.ReadInt32(); AsmModule module = AsmModuleFactory.Create(type); module.Index = g; module.ExecutionOrder = executionOrder; module.Label = label; module.Title = title; module.PreviousModule = previousModule; if (previousModule != null) { previousModule.NextModule = module; } previousModule = module; groups.Add(label, module); for (int s = 0; s < scriptsCount; s++) { string scriptLabel = br.ReadString(); int operationsCount = br.ReadInt32(); AsmEvent script = new AsmEvent(module, operationsCount) { Label = (ushort)(label + s + 1), Title = scriptLabel }; module.SetEventByIndex(s, script); for (int o = 0; o < operationsCount; o++) { JsmOperation operation = new JsmOperation(br.ReadUInt32()); script.Add(operation); } } } location.Scripts = groups; } location.SaveRequest &= ~LocationProperty.Scripts; location.Importable |= LocationProperty.Scripts; return(true); }
public AsmStaticValueSource(JsmOperation operation) : base(AsmValueSourceType.Static) { _operation = operation; }
public bool ReadScripts(Location location) { ArchiveFileEntry jsmEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".jsm"); if (jsmEntry == null) { return(true); } AsmCollection result; using (JsmFileReader jsmReader = new JsmFileReader(jsmEntry.OpenReadableContentStream())) { AsmModule previousModule = null; result = new AsmCollection(jsmReader.Groups.Length); for (ushort g = 0, s = 0, o = 0; g < jsmReader.Groups.Length; g++) { JsmGroup jsmGroup = jsmReader.Groups[g]; AsmModule asmGroup = AsmModuleFactory.Create(jsmGroup.Type); asmGroup.Index = g; asmGroup.ExecutionOrder = jsmGroup.ExecutionOrder; asmGroup.Label = jsmGroup.Label; asmGroup.Title = jsmGroup.Label.ToString("D3"); asmGroup.PreviousModule = previousModule; if (previousModule != null) { previousModule.NextModule = asmGroup; } previousModule = asmGroup; result.Add(asmGroup.Label, asmGroup); for (int i = 0; i < jsmGroup.ScriptsCount; i++) { JsmScript jsmScript = jsmReader.Scripts[s++]; AsmEvent asmScript = new AsmEvent(asmGroup, jsmScript.OperationsCount) { Flag = jsmScript.Flag, Label = (ushort)(asmGroup.Label + i) }; asmGroup.SetEventByIndex(i, asmScript); for (int k = 0; k < jsmScript.OperationsCount; k++) { JsmOperation jsmOperation = jsmReader.Opertations[o++]; asmScript.Add(jsmOperation); } } } } ArchiveFileEntry symEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".sym"); if (symEntry == null) { location.Scripts = result; return(true); } using (SymFileReader symReader = new SymFileReader(symEntry.OpenReadableContentStream())) { foreach (AsmModule module in result.GetOrderedModules()) { module.Title = symReader.Labels[module.Label]; foreach (AsmEvent evt in module.GetOrderedEvents()) { evt.Title = symReader.Labels[evt.Label]; } } } location.Scripts = result; location.SaveRequest &= ~LocationProperty.Scripts; location.Importable &= ~LocationProperty.Scripts; return(true); }
protected AsmCommand(JsmCommand command, AsmEvent script, int offset) { Script = script; Offset = offset; NativeOperation = Script.GetOperation(command, offset); }