private OOTSaveFile OpenSave(string filepath, long timeLastAccessed, ushort naviCounter) { byte[] arr; OOTSaveFile output; lock (saveFileLock) { try { using (BinaryReader br = new BinaryReader(File.Open(filepath, FileMode.Open))) { br.BaseStream.Position = Program.SAVE_FILE_HEAD; arr = br.ReadBytes(Program.SAVE_FILE_SIZE); } output = new OOTSaveFile(arr); this.naviCounter = naviCounter; this.timeLastAccessed = timeLastAccessed; this.activeFile = filepath; return(output); } catch (Exception e) { if (e is ThreadAbortException) { throw e; } return(ootSave); } } }
private static void AutoTrack() { //Trackers to remember auto track state bool printChests = true, printEvents = true; //unassign save to get it to rescan automatically save = null; while (true) { //check if save needs to be reloaded bool reload = fileMonitor.SaveFile != save; //reload logic if (reload) { save = fileMonitor.SaveFile; Console.Clear(); Console.WriteLine(save.naviCounter.ToString("X4")); if (printChests) { PrintChests(); } if (printEvents) { PrintEvents(); } Console.WriteLine("Auto Track Engaged:"); Console.WriteLine("Q: quit"); Console.WriteLine("C: toggle chests"); Console.WriteLine("E: Toggle events"); } //exits the loop of the console key is detected if (Console.KeyAvailable) { ConsoleKeyInfo key = System.Console.ReadKey(true); if (key.Key == ConsoleKey.Q) { return; } //Toggle chests if (key.Key == ConsoleKey.C) { printChests = !printChests; save = null; } //Toggle events if (key.Key == ConsoleKey.E) { printEvents = !printEvents; save = null; } } Thread.Sleep(50); } }
/// <summary> /// Begin execution of the monitor loop /// </summary> private void MonitorLoop() { while (true) { var file = GetLastFile(); if (file.Item1 > timeLastAccessed) { ushort naviCounter = GetNaviCounter(file.Item2); if (this.naviCounter != naviCounter) { ootSave = OpenSave(file.Item2, file.Item1, naviCounter); } } Thread.Sleep(50); } }
private static OOTSaveFile LoadFile(string path) { byte[] arr = File.ReadAllBytes(path); //get section of file with save bytes byte[] saveBytes = new byte[SAVE_FILE_SIZE]; Array.Copy(arr, SAVE_FILE_HEAD, saveBytes, 0, SAVE_FILE_SIZE); //print the sve file in big edian, to a debug file PrintOutput(saveBytes); //Generate a save file from the output bytes. var output = new OOTSaveFile(saveBytes); return(output); }
private static void ConsoleLoop() { //enter command line while (true) { save = fileMonitor.SaveFile; Console.Write("-$:"); string command = Console.ReadLine(); if (command == "exit" || command == "quit" || command == "q") { return; } //print scene data flag if (command.StartsWith("print ")) { PrintScene(command); } //Check if a scene is complete, and print that. if (command.StartsWith("check ")) { CheckScene(command); } //Check all items and print them. if (command == "checkAll") { CheckAll(command); } //Print the contents of the memory map for debugging if (command == "printMap") { PrintMap(command); } //Print the file path for the currently active file if (command == "printFilepath" || command == "printFile" || command == "printActive") { PrintActiveFile(command); } //Find a scene by name if (command.StartsWith("find ")) { FindScene(command); } //Execute auto tracking if (command == "autotrack") { AutoTrack(); } //Clear the command console if (command == "cls") { Console.Clear(); } //Print the event list for debugging if (command == "events") { PrintEvents(command); } if (command == "help") { PrintCommands(command); } if (command.StartsWith("setdir ")) { SetDir(command); } } }