/// <summary> /// Initializes a new instance of the <see cref="KinCityData"/> class. /// </summary> /// <param name="reader">The reader.</param> public KinCityData(BinaryFileReader reader) { int version = reader.ReadInt(); switch (version) { case 2: { m_Treasury = reader.ReadInt(); m_TaxRate = reader.ReadDouble(); goto case 1; } case 1: { m_UnassignedGuardSlots = reader.ReadInt(); goto case 0; } case 0: { m_City = (KinFactionCities)reader.ReadInt(); m_ControlingKin = (IOBAlignment)reader.ReadInt(); m_CaptureTime = reader.ReadDeltaTime(); m_CityLeader = (PlayerMobile)reader.ReadMobile(); m_IsVotingStage = reader.ReadBool(); m_Sigil = (KinSigil)reader.ReadItem(); m_ControlPoints = reader.ReadInt(); m_ControlPointDelta = reader.ReadInt(); m_NPCFlags = (NPCFlags)reader.ReadInt(); m_GuardOption = (GuardOptions)reader.ReadInt(); m_LastGuardChangeTime = reader.ReadDeltaTime(); int length = reader.ReadInt(); if (length > 0) { for (int i = 0; i < length; ++i) { m_BeneficiaryDataList.Add(new BeneficiaryData(reader)); } } break; } } }
public static void Load() { string filePath = Path.Combine("Saves/Attachments", "Attachments.bin"); // the attachment serializations string imaPath = Path.Combine("Saves/Attachments", "Attachments.ima"); // the item/mob attachment tables string fpiPath = Path.Combine("Saves/Attachments", "Attachments.fpi"); // the file position indices if (!File.Exists(filePath)) { return; } FileStream fs = null; BinaryFileReader reader = null; FileStream imafs = null; BinaryFileReader imareader = null; FileStream fpifs = null; BinaryFileReader fpireader = null; try { fs = new FileStream(filePath, (FileMode)3, (FileAccess)1, (FileShare)1); reader = new BinaryFileReader(new BinaryReader(fs)); imafs = new FileStream(imaPath, (FileMode)3, (FileAccess)1, (FileShare)1); imareader = new BinaryFileReader(new BinaryReader(imafs)); fpifs = new FileStream(fpiPath, (FileMode)3, (FileAccess)1, (FileShare)1); fpireader = new BinaryFileReader(new BinaryReader(fpifs)); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } if (reader != null && imareader != null && fpireader != null) { // restore the current global attachment serial state try { ASerial.GlobalDeserialize(reader); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } ASerial.serialInitialized = true; // read in the serial attachment hash table information int count = 0; try { count = reader.ReadInt(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } for (int i = 0; i < count; i++) { // read the serial ASerial serialno = null; try { serialno = new ASerial(reader.ReadInt()); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } // read the attachment type string valuetype = null; try { valuetype = reader.ReadString(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } // read the position of the beginning of the next attachment deser within the .bin file long position = 0; try { position = fpireader.ReadLong(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } bool skip = false; XmlAttachment o = null; try { o = (XmlAttachment)Activator.CreateInstance(Type.GetType(valuetype), new object[] {serialno}); } catch { skip = true; } if (skip) { if (!AlreadyReported(valuetype)) { Console.WriteLine("\nError deserializing attachments {0}.\nMissing a serial constructor?\n", valuetype); ReportDeserError(valuetype, "Missing a serial constructor?"); } // position the .ima file at the next deser point try { reader.Seek(position, SeekOrigin.Begin); } catch { ErrorReporter.GenerateErrorReport( "Error deserializing. Attachments save file corrupted. Attachment load aborted."); return; } continue; } try { o.Deserialize(reader); } catch { skip = true; } // confirm the read position if (reader.Position != position || skip) { if (!AlreadyReported(valuetype)) { Console.WriteLine("\nError deserializing attachments {0}\n", valuetype); ReportDeserError(valuetype, "save file corruption or incorrect Serialize/Deserialize methods?"); } // position the .ima file at the next deser point try { reader.Seek(position, SeekOrigin.Begin); } catch { ErrorReporter.GenerateErrorReport( "Error deserializing. Attachments save file corrupted. Attachment load aborted."); return; } continue; } // add it to the hash table try { AllAttachments.Add(serialno.Value, o); } catch { ErrorReporter.GenerateErrorReport( String.Format( "\nError deserializing {0} serialno {1}. Attachments save file corrupted. Attachment load aborted.\n", valuetype, serialno.Value)); return; } } // read in the mobile attachment hash table information try { count = imareader.ReadInt(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } for (int i = 0; i < count; i++) { Mobile key = null; try { key = imareader.ReadMobile(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } int nattach = 0; try { nattach = imareader.ReadInt(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } for (int j = 0; j < nattach; j++) { // and serial ASerial serialno = null; try { serialno = new ASerial(imareader.ReadInt()); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } // read the attachment type string valuetype = null; try { valuetype = imareader.ReadString(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } // read the position of the beginning of the next attachment deser within the .bin file long position = 0; try { position = fpireader.ReadLong(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } XmlAttachment o = FindAttachmentBySerial(serialno.Value); if (o == null || imareader.Position != position) { if (!AlreadyReported(valuetype)) { Console.WriteLine("\nError deserializing attachments of type {0}.\n", valuetype); ReportDeserError(valuetype, "save file corruption or incorrect Serialize/Deserialize methods?"); } // position the .ima file at the next deser point try { imareader.Seek(position, SeekOrigin.Begin); } catch { ErrorReporter.GenerateErrorReport( "Error deserializing. Attachments save file corrupted. Attachment load aborted."); return; } continue; } // attachment successfully deserialized so attach it AttachTo(key, o, false); } } // read in the item attachment hash table information try { count = imareader.ReadInt(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } for (int i = 0; i < count; i++) { Item key = null; try { key = imareader.ReadItem(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } int nattach = 0; try { nattach = imareader.ReadInt(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } for (int j = 0; j < nattach; j++) { // and serial ASerial serialno = null; try { serialno = new ASerial(imareader.ReadInt()); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } // read the attachment type string valuetype = null; try { valuetype = imareader.ReadString(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } // read the position of the beginning of the next attachment deser within the .bin file long position = 0; try { position = fpireader.ReadLong(); } catch (Exception e) { ErrorReporter.GenerateErrorReport(e.ToString()); return; } XmlAttachment o = FindAttachmentBySerial(serialno.Value); if (o == null || imareader.Position != position) { if (!AlreadyReported(valuetype)) { Console.WriteLine("\nError deserializing attachments of type {0}.\n", valuetype); ReportDeserError(valuetype, "save file corruption or incorrect Serialize/Deserialize methods?"); } // position the .ima file at the next deser point try { imareader.Seek(position, SeekOrigin.Begin); } catch { ErrorReporter.GenerateErrorReport( "Error deserializing. Attachments save file corrupted. Attachment load aborted."); return; } continue; } // attachment successfully deserialized so attach it AttachTo(key, o, false); } } if (fs != null) { fs.Close(); } if (imafs != null) { imafs.Close(); } if (fpifs != null) { fpifs.Close(); } if (desererror != null) { ErrorReporter.GenerateErrorReport("Error deserializing particular attachments."); } } }