public ChatMessage( BinaryFileReader reader ) { int version = reader.ReadInt(); switch( version ) { case 1: case 0: { _client = reader.ReadMobile(); _message = reader.ReadString(); _recipient = reader.ReadMobile(); _timestamp = reader.ReadDateTime(); break; } } }
public LootOptions(BinaryFileReader reader) { int version = reader.ReadInt(); switch (version) { case 0: { int tblCount = reader.ReadInt(); ContainerTable = new Dictionary<LootFlag, Container>(tblCount); for (int i = 0; i < tblCount; i++) { ContainerTable.Add((LootFlag)reader.ReadInt(), (Container)reader.ReadItem()); } Flags = (LootFlag)reader.ReadInt(); Mobile = reader.ReadMobile(); break; } } }
public GrabOptions(BinaryFileReader reader) { int version = reader.ReadInt(); switch (version) { case 0: { int tblCount = reader.ReadInt(); ContainerTable = new Dictionary <GrabFlag, Container>(tblCount); for (int i = 0; i < tblCount; i++) { ContainerTable.Add((GrabFlag)reader.ReadInt(), (Container)reader.ReadItem()); } Flags = (GrabFlag)reader.ReadInt(); Mobile = reader.ReadMobile(); break; } } }
public static void LoadPlayerOptions() { if (!File.Exists(Path.Combine(General.SavePath, "PlayerOptions.bin"))) return; using (FileStream bin = new FileStream(Path.Combine(General.SavePath, "PlayerOptions.bin"), FileMode.Open, FileAccess.Read, FileShare.Read)) { GenericReader reader = new BinaryFileReader(new BinaryReader(bin)); int version = reader.ReadInt(); Mobile m = null; int count = reader.ReadInt(); for (int i = 0; i < count; ++i) { m = reader.ReadMobile(); if (m != null) GetData(m).LoadOptions(reader); else (new Data()).LoadOptions(reader); } } }
public ChatInfo( BinaryFileReader reader ) { int version = reader.ReadInt(); switch( version ) { case 0: { _buddyList = reader.ReadStrongMobileList<Mobile>(); _client = reader.ReadMobile(); _ignoreList = reader.ReadStrongMobileList<Mobile>(); _visible = reader.ReadBool(); break; } } }
public void Deserialize(BinaryFileReader reader) { int version = reader.ReadInt(); if (version >= 0) { serialString = reader.ReadString(); allianceLeader = reader.ReadMobile() as Player; int count = reader.ReadInt(); for (int n = 1; n <= count; n++) { membersOf.Add(reader.ReadMobile()); } int guildCount = reader.ReadInt(); for (int x = 1; x <= guildCount; x++) { childGuilds.Add(reader.ReadGuild() as Guild); } allianceName = reader.ReadString(); primaryHue = reader.ReadInt(); secondaryHue = reader.ReadInt(); mountBody = reader.ReadInt(); mountID = reader.ReadInt(); foreach (Mobile m in membersOf) { if (m is Player) { Player p = m as Player; p.CurrentAlliance = this; } } } }
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."); } } }
private static void OnLoad() { if ( !File.Exists( Path.Combine( SavePath, SaveFile ) ) ) { return; } using ( FileStream bin = new FileStream( Path.Combine( SavePath, SaveFile ), FileMode.Open, FileAccess.Read, FileShare.Read ) ) { GenericReader reader = new BinaryFileReader( new BinaryReader( bin ) ); m_LastResetTime = reader.ReadDateTime(); int count = reader.ReadInt(); for ( int i = 0; i < count; ++i ) { Mobile mobile = reader.ReadMobile(); MobileRateInfo info = new MobileRateInfo(); info.Deserialize( reader ); if ( mobile != null ) { MobileRateInfo.Entries.Add( mobile, info ); } } } }
private static void OnLoad() { try{ if ( !File.Exists( Path.Combine( "Saves/Chat/", "Chat.bin" ) ) ) return; using ( FileStream bin = new FileStream( Path.Combine( "Saves/Chat/", "Chat.bin" ), FileMode.Open, FileAccess.Read, FileShare.Read ) ) { GenericReader reader = new BinaryFileReader( new BinaryReader( bin ) ); int version = reader.ReadInt(); if ( version >= 12 ) s_PublicPlusIRC = reader.ReadBool(); if ( version >= 11 ) s_FilterPenalty = (FilterPenalty)reader.ReadInt(); if ( version >= 10 ) s_AllianceChat = reader.ReadBool(); if ( version >= 9 ) s_AllowFaction = reader.ReadBool(); if ( version >= 8 ) s_GuildMenuAccess = reader.ReadBool(); if ( version >= 7 ) s_MaxPmHistory = reader.ReadInt(); if ( version >= 6 ) s_IrcAutoReconnect = reader.ReadBool(); if ( version >= 5 ) s_IrcMaxAttempts = reader.ReadInt(); if ( version >= 4 ) s_IrcAutoConnect = reader.ReadBool(); if ( version >= 3 ) s_IrcStaffColor = (IrcColor)reader.ReadInt(); if ( version >= 2 ) s_IrcNick = reader.ReadString(); if ( version >= 1 ) { s_IrcEnabled = reader.ReadBool(); s_IrcServer = reader.ReadString(); s_IrcRoom = reader.ReadString(); s_IrcPort = reader.ReadInt(); } if ( version >= 0 ) { int count = reader.ReadInt(); for( int i = 0; i < count; ++i ) s_Filters.Add( reader.ReadString() ); s_SpamLimiter = reader.ReadDouble(); s_FilterBanLength = reader.ReadDouble(); if ( version < 11 ) reader.ReadBool(); // FilterBan removed s_ShowLocation = reader.ReadBool(); s_ShowStaff = reader.ReadBool(); s_PublicStyle = (PublicStyle)reader.ReadInt(); count = reader.ReadInt(); ChatInfo info; for( int i = 0; i < count; ++i ) { info = new ChatInfo( reader.ReadMobile() ); if ( !info.Load( reader ) ) return; } } reader.End(); } if ( s_IrcAutoConnect ) IrcConnection.Connection.Connect(); }catch{ Errors.Report( "ChatInfo-> OnLoad" ); } }
public static void Load(bool initonly) { if (initonly) Console.WriteLine("Initializing ResourcePool database..."); else Console.WriteLine("Resource Pool Loading..."); if (!Directory.Exists("Saves/ResourcePool")) Directory.CreateDirectory("Saves/ResourcePool"); bool newconfig = false; FileStream rpfs = new FileStream("Saves/ResourcePool/ResourcePool.dat", FileMode.OpenOrCreate, FileAccess.Read); BinaryFileReader rpreader = new BinaryFileReader(new BinaryReader(rpfs)); if (!rpreader.End()) { int rpversion = rpreader.ReadInt(); switch (rpversion) { case 0: { m_LastModified = rpreader.ReadDateTime(); FileInfo fi = new FileInfo("Data/ResourcePool/config.xml"); if (fi.LastWriteTime != m_LastModified) { m_LastModified = fi.LastWriteTime; newconfig = true; } else newconfig = false; break; } default: throw new Exception("Error loading ResourcePool: Invalid ResourcePool.dat save version"); } } else { m_LastModified = (new FileInfo("Data/ResourcePool/config.xml")).LastWriteTime; Console.WriteLine("Warning: Saves/ResourcePool/ResourcePool.dat not found."); newconfig = true; } if (newconfig) Console.WriteLine("New configuration detected! Reading from Data/..."); XmlTextReader reader; reader = new XmlTextReader((newconfig ? "Data/ResourcePool/config.xml" : "Saves/ResourcePool/config.xml")); reader.WhitespaceHandling = WhitespaceHandling.None; FileStream rcfs = new FileStream("Saves/ResourcePool/Consignments.dat", FileMode.OpenOrCreate, FileAccess.Read); FileStream dfs = new FileStream("Saves/ResourcePool/Debts.dat", FileMode.OpenOrCreate, FileAccess.Read); BinaryFileReader rcreader = new BinaryFileReader(new BinaryReader(rcfs)); BinaryFileReader dreader = new BinaryFileReader(new BinaryReader(dfs)); try { reader.MoveToContent(); } catch { Console.WriteLine("Save xml data not found or invalid, reverting to defaults"); reader = new XmlTextReader("Data/ResourcePool/config.xml"); reader.WhitespaceHandling = WhitespaceHandling.None; reader.MoveToContent(); } int version = Int32.Parse(reader.GetAttribute("version")); reader.ReadStartElement("ResourcePool"); switch (version) { case 0: { m_PaymentFactor = Double.Parse(reader.ReadElementString("PaymentFactor")); m_FailsafePriceHike = Double.Parse(reader.ReadElementString("FailsafePriceHike")); m_Resources = new Hashtable(); while (reader.LocalName == "ResourceData") { ResourceData rd = new ResourceData(reader, (initonly ? null : rcreader)); if (rd != null) m_Resources[rd.Type] = rd; } while (reader.LocalName == "RDRedirect") { RDRedirect rd = new RDRedirect(reader, (initonly ? null : rcreader)); if (rd != null) m_Resources[rd.Type] = rd; } m_Debts = new Hashtable(); if (initonly) break; while (!dreader.End()) { try { Mobile m = dreader.ReadMobile(); double debt = dreader.ReadDouble(); if (m != null) m_Debts[m] = debt; } catch (Exception ex) { Console.WriteLine("Exception occured attempting to desrialize from Debts.dat : " + ex.Message ); break; } } break; } case 1: { m_PaymentFactor = Double.Parse(reader.ReadElementString("PaymentFactor")); m_FailsafePriceHike = Double.Parse(reader.ReadElementString("FailsafePriceHike")); m_Resources = new Hashtable(); while (reader.LocalName == "ResourceData") { ResourceData rd = new ResourceData(reader, (initonly ? null : rcreader)); if (rd != null) m_Resources[rd.Type] = rd; } while (reader.LocalName == "RDRedirect") { RDRedirect rd = new RDRedirect(reader, (initonly ? null : rcreader)); if (rd != null) m_Resources[rd.Type] = rd; } m_Debts = new Hashtable(); if (initonly) break; // read count int count = dreader.ReadInt(); for (int ix = 0; ix < count; ix++) { Mobile m = dreader.ReadMobile(); double debt = dreader.ReadDouble(); if (m != null) m_Debts[m] = debt; } break; } default: { throw new Exception("Invalid ResourcePool save version."); } } reader.ReadEndElement(); reader.Close(); rcfs.Close(); rpfs.Close(); dfs.Close(); }