private void EmulatorConnectionWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { DWProcessReader reader = DWGlobals.ProcessReader; if (reader != default(DWProcessReader)) { // update emulator name in status bar EmulatorStatusLabel.Text = reader.Process.MainWindowTitle; // execute first hero update Hero.Update(true); // update all enemy skills and attack patterns int enemyOffset = 0x9E4B; for (int i = 0; i < DWGlobals.Enemies.Length; i++) { DWEnemy enemy = DWGlobals.Enemies[i]; int pattern = reader.Read((enemyOffset + (i * 0x10)) + 3, 1, 2)[0]; enemy.Skill2Chance = (pattern & 0x3) / 4f; enemy.Skill2 = enemy.GetSkill2((pattern >> 2) & 0x3); enemy.Skill1Chance = ((pattern >> 4) & 0x3) / 4f; enemy.Skill1 = enemy.GetSkill1((pattern >> 6) & 0x3); int resist = reader.Read(enemyOffset + (i * 0x10) + 4, 1, 2)[0]; enemy.StopspellResist = (resist % 0xF) / 16f; Console.WriteLine("0x{0:X}", enemyOffset + (i * 0x10) + 4); Console.WriteLine(enemy.Name + ": " + Math.Floor(enemy.StopspellResist * 100)); } // decode DWR map Overworld.DecodeMap(); } }
public void DecodeMap() { DWProcessReader reader = DWGlobals.ProcessReader; Func <int, int> read = offset => reader.Read(tilesOffset + offset, 1, 3)[0]; int count, tileIndex; // pointers to each role of tiles are after tile tile table int[] rowPointers = new int[gridSize]; for (int i = 0; i < gridSize; i++) { byte[] bytes = reader.Read(rowPointersOffset + (i * 2), 2, 3); rowPointers[i] = BitConverter.ToUInt16(bytes, 0) - 0x8000 - tilesOffset; } // process each tile by row for (int y = 0; y < gridSize; y++) { int mapByte = read(rowPointers[y]); if (mapByte == 0xFF) { break; } tileIndex = mapByte >> 4; count = mapByte & 0xF; for (int x = 0, byteCtr = 0; x < gridSize; x++) { grid[x, y] = new GridTile(x, y, tileIndex, false); if (count == 0) { mapByte = read(rowPointers[y] + ++byteCtr); if (mapByte == 0xFF) { break; } tileIndex = mapByte >> 4; count = mapByte & 0xF; } else { count--; } } } IsDecoded = true; }
private void EmulatorConnectionWorker_DoWork(object sender, DoWorkEventArgs e) { // load all configured emulators from emulators.json StreamReader r = new StreamReader("emulators.json"); string json = r.ReadToEnd(); dynamic array = JsonConvert.DeserializeObject(json); foreach (var item in array) { string name = item.name; foreach (var vItem in item.versions) { // assign json items string version = vItem.version; string dll = vItem.dll; int arch = vItem.arch; string[] offsets = vItem.offsets.ToObject <string[]>(); if (vItem.sramOffsets == null) { Console.WriteLine("[WARNING] no sram offsets for {0} {1}", name, version); continue; } string[] sramOffsets = vItem.sramOffsets.ToObject <string[]>(); if (vItem.romOffsets == null) { Console.WriteLine("[WARNING] no rom offsets for {0} {1}", name, version); continue; } string[] romOffsets = vItem.romOffsets.ToObject <string[]>(); if (vItem.mapOffsets == null) { Console.WriteLine("[WARNING] no map offsets for {0} {1}", name, version); continue; } string[] mapOffsets = vItem.mapOffsets.ToObject <string[]>(); // find emulator process Process[] processes = Process.GetProcessesByName(name); if (processes.Length < 1) { continue; } foreach (Process p in processes) { Console.Out.WriteLine(p.MainWindowTitle); DWProcessReader reader = new DWProcessReader(p); IntPtr baseOffset = reader.FindOffset(dll, offsets); if (baseOffset == (IntPtr)(-1)) { Console.WriteLine("[ERROR] Couldn't find NES pointer for {0}", p.ProcessName); continue; } reader.BaseOffset = baseOffset; IntPtr sramOffset = reader.FindOffset(dll, sramOffsets); if (sramOffset == (IntPtr)(-1)) { Console.WriteLine("[ERROR] Couldn't find NES sram pointer for {0}", p.ProcessName); continue; } reader.SramOffset = sramOffset; IntPtr romOffset = reader.FindOffset(dll, romOffsets); if (romOffset == (IntPtr)(-1)) { Console.WriteLine("[ERROR] Couldn't find NES rom pointer for {0}", p.ProcessName); continue; } reader.RomOffset = romOffset; IntPtr mapOffset = reader.FindOffset(dll, mapOffsets); if (mapOffset == (IntPtr)(-1)) { Console.WriteLine("[ERROR] Couldn't find NES map pointer for {0}", p.ProcessName); continue; } reader.MapOffset = mapOffset; // TODO: Base offset doesn't take us to this part of memory // find "DRAGON WARRIOR" at offset +0xFFE0 //string identifier = reader.ReadString(0xFFE0, 14); //if (identifier != "DRAGON WARRIOR") //{ // continue; //} // found our emulator DWGlobals.ProcessReader = reader; break; } if (DWGlobals.ProcessReader != default(DWProcessReader)) { break; } } } }