public patchdb_PatchClass readPatchFromStream(StreamReader sr, string name, string hash, string creator) { patchdb_PatchClass newPatch = new patchdb_PatchClass(); try { string str; newPatch.name = name; newPatch.creator = this.formatPatchCreator(creator); newPatch.hash = hash; newPatch.patchlines = 0; while ((str = sr.ReadLine()) != null) { if (str.Length <= 8) { break; } newPatch.patchline[newPatch.patchlines] = this.patchStringToPatch(str); newPatch.patchlines++; } newPatch = this.sortPatchByOffset(newPatch); } catch { return(null); } return(newPatch); }
public patchdb_PatchClass sortPatchByOffset(patchdb_PatchClass newPatch) { ArrayList list = new ArrayList(); int index = 0; for (index = 0; index < newPatch.patchlines; index++) { if ((newPatch.patchline[index] != null) && (newPatch.patchline[index].offset != "")) { list.Add(newPatch.patchline[index].offset); } } list.Sort(); patchdb_PatchClass class2 = new patchdb_PatchClass { creator = newPatch.creator, hash = newPatch.hash, name = newPatch.name, patchlines = newPatch.patchlines, patchline = new patchLineInfo[100] }; index = 0; bool flag = false; foreach (object obj2 in list) { if (obj2 == null) { continue; } flag = false; for (int i = 0; i < 100; i++) { try { if ((newPatch.patchline[i] != null) && (newPatch.patchline[i].offset == obj2.ToString())) { class2.patchline[index] = new patchLineInfo(); class2.patchline[index] = newPatch.patchline[i]; flag = true; index++; break; } } catch { MessageBox.Show("Trying to sort something that is incorrect"); } } if (!flag) { MessageBox.Show("Failed sorting the patch"); } } return(class2); }
public void addPatchToDb(StreamReader sr, string name, string hash, string creator) { if (this.db_filled >= 0x1388) { MessageBox.Show("Fatal Error! Database is too large for the allocated memory!"); } patchdb_PatchClass class2 = this.readPatchFromStream(sr, name, hash, creator); if (class2 != null) { this.patch_db.patch[this.db_filled] = class2; this.db_filled++; } else if (!this.shownCorruptDb) { MessageBox.Show("The database appears to need updating\r\nPlease update from the database menu\r\n\r\nInvalid format for one of the integers at row " + this.db_filled, "Corrupt Database", MessageBoxButtons.OK, MessageBoxIcon.Hand); this.shownCorruptDb = true; } }