public override bool OnInitialize() { base.OnInitialize(); GCTCodeLine *lines = (GCTCodeLine *)Data + 1; while (true) { GCTCodeLine line = *lines++; if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2) { break; } } _header = (GCTHeader *)lines; if (((uint)_header - (uint)Data) < WorkingUncompressed.Length) { if (_header->_nameOffset > 0) { _gameName = _header->GameName; } _name = _header->GameID; } if (_name == null) { _name = Path.GetFileNameWithoutExtension(_origPath); } return(WorkingUncompressed.Length > 16 && _header->_count > 0); }
internal static GCTNode IsParsable(string path) { FileMap map = FileMap.FromFile(path, FileMapProtect.ReadWrite); GCTCodeLine *data = (GCTCodeLine *)map.Address; if (GCTCodeLine.Tag._1 != data->_1 || GCTCodeLine.Tag._2 != data->_2) { map.Dispose(); return(null); } data = (GCTCodeLine *)(map.Address + (uint)Helpers.RoundDown((uint)map.Length, 8) - GCTCodeLine.Size); bool endFound = false; int i = 0; while (!endFound) { GCTCodeLine line = *data--; if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2) { endFound = true; break; } i++; } if (endFound && i <= 0) { data = (GCTCodeLine *)map.Address + 1; string s = ""; while (true) { GCTCodeLine line = *data++; if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2) { break; } s += line.ToStringNoSpace(); } GCTNode g = new GCTNode(); List <string> _unrecognized = new List <string>(); foreach (CodeStorage c in Properties.Settings.Default.Codes) { int index = -1; if ((index = s.IndexOf(c._code)) >= 0) { g.AddChild(new GCTCodeEntryNode() { _name = c._name, _description = c._description, LinesNoSpaces = s.Substring(index, c._code.Length) }); s = s.Remove(index, c._code.Length); } } if (g.Children.Count > 0) { if (s.Length > 0) { MessageBox.Show(String.Format("{0} code{1} w{2} recognized.", g.Children.Count.ToString(), g.Children.Count > 1 ? "s" : "", g.Children.Count > 1 ? "ere" : "as")); } } else { MessageBox.Show("This GCT does not contain any recognizable codes."); } if (s.Length > 0) { g.AddChild(new GCTCodeEntryNode() { _name = "Unrecognized Code(s)", LinesNoSpaces = s }); } return(g); } else if (endFound && i > 0) { GCTNode g = new GCTNode(); g.Initialize(null, new DataSource(map)); return(g); } map.Dispose(); return(null); }
public static GCTNode FromTXT(string path) { GCTNode node = new GCTNode(); if (File.Exists(path)) { bool anyEnabled = false; using (StreamReader sr = new StreamReader(path)) { for (int i = 0; !sr.EndOfStream; i++) { string lastLine; while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) { ; } if (!String.IsNullOrEmpty(lastLine)) { node._name = lastLine; } lastLine = sr.ReadLine(); if (!String.IsNullOrEmpty(lastLine)) { node._gameName = lastLine; } while (!sr.EndOfStream) { while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) { ; } GCTCodeEntryNode e = new GCTCodeEntryNode(); List <GCTCodeLine> g = new List <GCTCodeLine>(); if (!String.IsNullOrEmpty(lastLine)) { e._name = lastLine; } else { break; } bool?codeEnabled = null; while (true) { lastLine = sr.ReadLine(); if (String.IsNullOrEmpty(lastLine)) { break; } bool lineEnabled = lastLine.StartsWith("* "); if (lineEnabled) { anyEnabled = true; lastLine = lastLine.Substring(2); } if (codeEnabled == null) { codeEnabled = lineEnabled; } else if (codeEnabled != lineEnabled) { break; } string[] lines = lastLine.Split(' '); if (lines.Length < 2) { break; } uint val1, val2; if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1)) { if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2)) { GCTCodeLine l = new GCTCodeLine(val1, val2); g.Add(l); } else { break; } } else { break; } } List <string> description = new List <string>(); while (!String.IsNullOrEmpty(lastLine)) { description.Add(lastLine); lastLine = sr.ReadLine(); } e._enabled = codeEnabled ?? false; e._lines = g.ToArray(); e._description = String.Join(Environment.NewLine, description); node.AddChild(e, false); } } } if (anyEnabled == false) { // No codes enabled in file - enable all codes foreach (GCTCodeEntryNode e in node.Children) { e._enabled = true; } } } return(node); }
public static GCTNode FromTXT(string path) { GCTNode node = new GCTNode(); if (File.Exists(path)) { using (StreamReader sr = new StreamReader(path)) for (int i = 0; !sr.EndOfStream; i++) { string lastLine; while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) { ; } if (!String.IsNullOrEmpty(lastLine)) { node._name = lastLine; } lastLine = sr.ReadLine(); if (!String.IsNullOrEmpty(lastLine)) { node._gameName = lastLine; } while (!sr.EndOfStream) { while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) { ; } GCTCodeEntryNode e = new GCTCodeEntryNode(); List <GCTCodeLine> g = new List <GCTCodeLine>(); if (!String.IsNullOrEmpty(lastLine)) { e._name = lastLine; } else { break; } while (true) { lastLine = sr.ReadLine(); if (String.IsNullOrEmpty(lastLine)) { break; } string[] lines = lastLine.Split(' '); if (lines.Length < 2) { break; } uint val1, val2; if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1)) { if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2)) { GCTCodeLine l = new GCTCodeLine(val1, val2); g.Add(l); } else { break; } } else { break; } } e._lines = g.ToArray(); e._description = lastLine; node.AddChild(e); } } } return(node); }
public static GCTNode FromTXT(string path) { GCTNode node = new GCTNode(); if (File.Exists(path)) using (StreamReader sr = new StreamReader(path)) for (int i = 0; !sr.EndOfStream; i++) { string lastLine; while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) ; if (!String.IsNullOrEmpty(lastLine)) node._name = lastLine; lastLine = sr.ReadLine(); if (!String.IsNullOrEmpty(lastLine)) node._gameName = lastLine; while (!sr.EndOfStream) { while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) ; GCTCodeEntryNode e = new GCTCodeEntryNode(); List<GCTCodeLine> g = new List<GCTCodeLine>(); if (!String.IsNullOrEmpty(lastLine)) e._name = lastLine; else break; while (true) { lastLine = sr.ReadLine(); if (String.IsNullOrEmpty(lastLine)) break; string[] lines = lastLine.Split(' '); if (lines.Length < 2) break; uint val1, val2; if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1)) if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2)) { GCTCodeLine l = new GCTCodeLine(val1, val2); g.Add(l); } else break; else break; } e._lines = g.ToArray(); e._description = lastLine; node.AddChild(e); } } return node; }