public void FullScanWindow() { using (var integerMap = new IntegerMap(windowBitmap)) { var gridIcons = gridScanner.FullScan(integerMap).ToArray(); var gridLeft = gridIcons.Min(t => t.Item1.X); var gridRight = gridIcons.Max(t => t.Item1.X + t.Item2.IntegerMap.Size.Width - 1); var gridTop = gridIcons.Min(t => t.Item1.Y); var gridBottom = gridIcons.Max(t => t.Item1.Y + t.Item2.IntegerMap.Size.Height - 1); var gridRectangle = new Rectangle(gridLeft, gridTop, gridRight - gridLeft + 1, gridBottom - gridTop + 1); GridRectangle = gridRectangle.Add(WindowRectangle.Location); var gridCountX = GridRectangle.Width / Icons.Icon.RawGrid.IntegerMap.Size.Width; var gridCountY = GridRectangle.Height / Icons.Icon.RawGrid.IntegerMap.Size.Height; Grids = new Grid[gridCountX, gridCountY]; QuickScanGrids(); var faceIcons = faceScanner.FullScan(integerMap).ToArray(); var faceIcon = faceIcons.Single(); var faceRectangle = new Rectangle(faceIcon.Item1, faceIcon.Item2.IntegerMap.Size); FaceRectangle = faceRectangle.Add(WindowRectangle.Location); QuickScanFace(); var scoreIcons = bombCountScanner.FullScan(integerMap).ToArray(); var bombCountIcons = scoreIcons.Where(t => t.Item1.X < integerMap.Size.Width / 2).OrderBy(t => t.Item1.X); var bombCountRectangles = bombCountIcons.Select(t => new Rectangle(t.Item1, t.Item2.IntegerMap.Size)); BombCountRectangles = bombCountRectangles.Select(t => t.Add(WindowRectangle.Location)).ToArray(); QuickScanBombCount(); } }
public void QuickScanFace() { if (FaceRectangle == Rectangle.Empty) { throw new InvalidOperationException(); } var captureLog = TimeLog.Stopwatch("Capture Face"); var bitmap = GetCapture(FaceRectangle); captureLog.Dispose(); var readLog = TimeLog.Stopwatch("Read Face"); using (var integerMap = new IntegerMap(bitmap)) { var faceIcon = faceScanner.QuickRead(integerMap, Point.Empty); if (faceIcon == null) { throw new GameScanException("Scan face failed"); } Face = MapFace(faceIcon); } readLog.Dispose(); }
public void QuickScanBombCount() { if (BombCountRectangles == null) { throw new InvalidOperationException(); } var captureLog = TimeLog.Stopwatch("Capture Bomb Count"); var bitmaps = BombCountRectangles.Select(GetCapture).ToArray(); captureLog.Dispose(); var readLog = TimeLog.Stopwatch("Read Face"); var bombCountDigits = bitmaps.Select(bitmap => { using (var integerMap = new IntegerMap(bitmap)) { var bombCountIcon = bombCountScanner.QuickRead(integerMap, Point.Empty); if (bombCountIcon == null) { throw new GameScanException("Scan bomb count failed"); } return(MapBombCount(bombCountIcon)); } }); BombCount = bombCountDigits.Aggregate((total, curr) => total * 10 + curr); readLog.Dispose(); }
public Icon QuickRead(IntegerMap targetMap, Point offset) { var validIcons = icons.Where(icon => targetMap.Size.Contains(offset, icon.IntegerMap.Size)).ToArray(); var validPoints = scannerPoints.Where(point => targetMap.Size.Contains(point.Point.Add(offset))); foreach (var scannerPoint in validPoints) { var point = scannerPoint.Point.Add(offset); var pixel = targetMap[point.X, point.Y]; var scannerValue = scannerPoint.Values.FirstOrDefault(t => t.Pixel == pixel); if (scannerValue.EqualsDefault()) { return(null); } validIcons = validIcons.Intersect(scannerValue.Icons).ToArray(); if (validIcons.Length <= 0) { return(null); } if (validIcons.Length == 1) { return(validIcons.Single()); } } return(FullRead(targetMap, offset, validIcons)); }
public ZRoutineTable(Story story, InstructionCache cache = null) { this.story = story; this.cache = cache ?? new InstructionCache(8192); this.routines = new IntegerMap <ZRoutine>(8192); this.sortedAddresses = new List <int>(); Add(story.MainRoutineAddress, "Main"); }
public IEnumerable <Tuple <Point, Icon> > FullScan(IntegerMap targetMap) { var quickScan = QuickScan(targetMap); return(quickScan.Where(t => { var fullRead = FullRead(targetMap, t.Item1, new[] { t.Item2 }); return fullRead == t.Item2; })); }
public IEnumerable <Tuple <Point, Icon> > QuickScan(IntegerMap targetMap) { var points = EnumerableUtil.Rectangle(targetMap.Size); var reads = points.Select(point => { var icon = QuickRead(targetMap, point); return(Tuple.Create(point, icon)); }); return(reads.Where(t => t.Item2 != null)); }
public Icon(string fileName) { FileName = fileName; var assembly = Assembly.GetExecutingAssembly(); var resourceName = GetType().Namespace + "." + fileName; using (var stream = assembly.GetManifestResourceStream(resourceName)) { var bitmap = new Bitmap(stream); IntegerMap = new IntegerMap(bitmap); } }
public InstructionLinkedList(ZRoutine routine) : base(routine.Instructions) { this.addressToNodeMap = new IntegerMap <LinkedListNode <Instruction> >(); var node = this.First; while (node != null) { addressToNodeMap.Add(node.Value.Address, node); node = node.Next; } }
public Icon FullRead(IntegerMap targetMap, Point offset, IEnumerable <Icon> candidateIcons) { var validIcons = candidateIcons.Where(icon => targetMap.Size.Contains(offset, icon.IntegerMap.Size)); return(validIcons.FirstOrDefault(icon => { var iconPoints = EnumerableUtil.Rectangle(icon.IntegerMap.Size); return iconPoints.All(iconPoint => { var targetPoint = iconPoint.Add(offset); return targetMap[targetPoint.X, targetPoint.Y] == icon.IntegerMap[iconPoint.X, iconPoint.Y]; }); })); }
// public static IntegerMap GenerateWorld(int w, int h) // { // IntegerMap n_map = new IntegerMap(w, h); // for (var x = 0; x < n_map.width; x++) // for (var y = 0; y < n_map.width; y++) // { // if (x < n_map.width / 100f * waterWidth) // { // n_map.SetValue(x, y, -1); // continue; // } // if (x < n_map.width / 100f * beachWidth) // { // n_map.SetValue(x, y, 0); // continue; // } // if (x < n_map.width / 100f * noJungleWidth) // { // n_map.SetValue(x, y, 1); // continue; // } // n_map.SetValue(x, y, 3); // } // return n_map; // } public static IntegerMap GenerateBananas(int w, int h) { IntegerMap n_map = new IntegerMap(w, h); for (var x = 0; x < n_map.width; x++) { for (var y = 0; y < n_map.width; y++) { n_map.SetValue((x, y), 1); } } return(n_map); }
public DisassemblyViewModel( StoryService storyService, DebuggerService debuggerService, BreakpointService breakpointService, // TODO: I haven't found a better way of enforcing this to be filled in time yet LabelService labelService, RoutineService routineService, NavigationService navigationService, EditRoutineNameDialogViewModel editRoutineNameDialogViewModel) : base("DisassemblyView") { this.storyService = storyService; this.debuggerService = debuggerService; this.debuggerService.MachineCreated += DebuggerService_MachineCreated; this.debuggerService.MachineDestroyed += DebuggerService_MachineDestroyed; this.debuggerService.StateChanged += DebuggerService_StateChanged; this.debuggerService.Stepped += DebuggerService_Stepped; this.breakpointService = breakpointService; this.breakpointService.Added += BreakpointService_Added; this.breakpointService.Removed += BreakpointService_Removed; this.routineService = routineService; this.routineService.RoutineNameChanged += RoutineService_RoutineNameChanged; this.navigationService = navigationService; this.navigationService.NavigationRequested += NavigationService_NavigationRequested; this.editRoutineNameDialogViewModel = editRoutineNameDialogViewModel; lines = new BulkObservableCollection <DisassemblyLineViewModel>(); addressToLineMap = new IntegerMap <DisassemblyLineViewModel>(); routineAddressAndIndexList = new List <AddressAndIndex>(); stackLines = new List <DisassemblyLineViewModel>(); this.EditNameCommand = RegisterCommand <int>( text: "EditName", name: "Edit Name", executed: EditNameExecuted, canExecute: CanEditNameExecute); }
public CompiledZMachine(Story story, bool precompile = false, bool debugging = false, IZMachineProfiler profiler = null) : base(story) { this.profiler = profiler; this.precompile = precompile; this.debugging = debugging; this.objectTableAddress = this.Memory.ReadWord(0x0a); this.propertyDefaultsTableSize = (byte)(this.Version < 4 ? 31 : 63); this.objectEntriesAddress = (ushort)(this.objectTableAddress + (this.propertyDefaultsTableSize * 2)); this.objectEntrySize = (byte)(this.Version < 4 ? 9 : 14); this.objectParentOffset = (byte)(this.Version < 4 ? 4 : 6); this.objectSiblingOffset = (byte)(this.Version < 4 ? 5 : 8); this.objectChildOffset = (byte)(this.Version < 4 ? 6 : 10); this.objectPropertyTableAddressOffset = (byte)(this.Version < 4 ? 7 : 12); this.objectAttributeByteCount = (byte)(this.Version < 4 ? 4 : 6); this.objectAttributeCount = (byte)(this.Version < 4 ? 32 : 48); this.dictionaryAddress = this.Memory.ReadWord(0x08); this.packResolution = this.Version < 4 ? 2 : this.Version < 8 ? 4 : 8; this.routinesOffset = (this.Version >= 6 && this.Version <= 7) ? Memory.ReadWord(0x28) : 0; this.stringsOffset = (this.Version >= 6 && this.Version <= 7) ? Memory.ReadWord(0x2a) : 0; this.routineTable = new ZRoutineTable(story); this.addressToRoutineCallMap = new IntegerMap <ZRoutineCall>(8192); this.compilationResults = new IntegerMap <ZCompilerResult>(8192); this.localArrayPool = new Stack <ushort[]>(); if (this.precompile) { foreach (var routine in routineTable) { GetRoutineCall(routine.Address); } this.precompile = false; } }
public void QuickScanGrids() { if (GridRectangle == Rectangle.Empty) { throw new InvalidOperationException(); } if (Grids == null) { throw new InvalidOperationException(); } var captureLog = TimeLog.Stopwatch("Capture Grid"); var bitmap = GetCapture(GridRectangle); captureLog.Dispose(); var readLog = TimeLog.Stopwatch("Read Grid"); using (var integerMap = new IntegerMap(bitmap)) { var gridCountX = Grids.GetLength(0); var gridCountY = Grids.GetLength(1); var gridIndexes = EnumerableUtil.Rectangle(gridCountX, gridCountY); foreach (var gridIndex in gridIndexes) { var gridLocation = gridIndex.Multiply(Icons.Icon.RawGrid.IntegerMap.Size); var gridIcon = gridScanner.QuickRead(integerMap, gridLocation); if (gridIcon == null) { throw new GameScanException("Scan grid failed"); } var gridValue = MapGrid(gridIcon); Grids[gridIndex.X, gridIndex.Y] = gridValue; } } readLog.Dispose(); }
internal ZObjectTable(byte[] memory, ZText ztext) { this.memory = memory; this.ztext = ztext; this.version = Header.ReadVersion(memory); this.address = Header.ReadObjectTableAddress(memory); this.maxObjects = (ushort)(version <= 3 ? 255 : 65535); this.maxProperties = (byte)(version <= 3 ? 31 : 63); this.propertyDefaultsTableSize = (byte)(maxProperties * 2); this.objectEntriesAddress = (ushort)(address + propertyDefaultsTableSize); this.entrySize = (byte)(version <= 3 ? 9 : 14); this.attributeBytesSize = (byte)(version <= 3 ? 4 : 6); this.attributeCount = (byte)(version <= 3 ? 32 : 48); this.numberSize = (byte)(version <= 3 ? 1 : 2); this.parentOffset = (byte)(version <= 3 ? 4 : 6); this.siblingOffset = (byte)(version <= 3 ? 5 : 8); this.childOffset = (byte)(version <= 3 ? 6 : 10); this.propertyTableAddressOffset = (byte)(version <= 3 ? 7 : 12); this.objects = ReadAllObjects(); this.propertyTables = new IntegerMap <ZPropertyTable>(objects.Length); }
public InstructionCache(int capacity = 0) { map = new IntegerMap <Instruction>(capacity); }
public static bool FindPath(IntegerMap localMap, int localWidth, int localHeight, (int, int) start, (int x, int y) goal, out Queue <Vector3> result)