private static void event_worldLoad() { if (!File.Exists(PersistenceFile)) { return; } using (FileStream stream = new FileStream(PersistenceFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(stream)); int count = reader.ReadInt(); for (int i = 0; i < count; i++) { int serial = reader.ReadInt(); if (serial > -1) { Mobile m = World.FindMobile(serial); GrabOptions options = new GrabOptions(reader); if (m != null && !m.Deleted) { if (options != null && !OptionsTable.ContainsKey(m)) { OptionsTable.Add(m, options); } } } } reader.Close(); } }
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 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 static void OnLoad() { //don't load the file if it don't exist! if( !File.Exists( Path.Combine( SAVE_PATH, FILENAME ) ) ) { return; } using( FileStream bin = new FileStream( Path.Combine( SAVE_PATH, FILENAME ), FileMode.Open, FileAccess.Read, FileShare.Read ) ) { GenericReader reader = new BinaryFileReader( new BinaryReader( bin ) ); int version = reader.ReadInt(); int count = reader.ReadInt(); for( int i = 0; i < count; i++ ) { GameData.Add( new BoardGameData( reader ) ); } reader.End(); } }
/// <summary> /// Deserialize /// </summary> private static void OnLoad() { string CurRegion = ""; try { foreach (Region r in Region.Regions) { if (r != null) { if (!(r is ISeasons)) continue; if (r.GetType().IsAbstract || !r.GetType().IsSubclassOf(typeof(Region))) continue; CurRegion = r.Name; if (!Directory.Exists("Saves/Regions/Seasons/" + r.Map + "/")) Directory.CreateDirectory("Saves/Regions/Seasons/" + r.Map + "/"); string name = "(" + r.Name + ")"; string nameTmp = ""; #if(RUNUO_1) if (r.Coords != null) { for (int i = 0; i < r.Coords.Count; ++i) { object obj = r.Coords[i]; if (obj is Rectangle3D) { Rectangle3D r3d = (Rectangle3D)obj; nameTmp += r3d.ToString(); } else if (obj is Rectangle2D) { Rectangle2D r2d = (Rectangle2D)obj; nameTmp += r2d.ToString(); } } name += "(" + MD5Hash(nameTmp) + ")"; } if (name == null || name == "" || name.Length == 0) { name += "(" + r.UId + ")"; } #else if (r.Area != null) { for (int i = 0; i < r.Area.Length; ++i) { Rectangle3D r3d = r.Area[i]; nameTmp += r3d.ToString(); } name += "(" + MD5Hash(nameTmp) + ")"; } #endif if (!File.Exists(Path.Combine("Saves/Regions/Seasons/" + r.Map + "/", name + ".bin"))) return; using (FileStream bin = new FileStream(Path.Combine("Saves/Regions/Seasons/" + r.Map + "/", name + ".bin"), FileMode.Open, FileAccess.Read, FileShare.Read)) { try { GenericReader reader = new BinaryFileReader(new BinaryReader(bin)); Season season = (Season)reader.ReadInt(); ((ISeasons)r).Season = season; LoadedCount++; } catch (Exception ex1) { Console.WriteLine("[SeasonTracker] Deserialize: ({0})", CurRegion); Console.WriteLine(ex1.ToString()); } } } } } catch (Exception ex2) { Console.WriteLine("[SeasonTracker] OnLoad: ({0})", CurRegion); Console.WriteLine(ex2.ToString()); } Console.WriteLine("[SeasonTracker] Tracking {0} Regions' Seasons...", LoadedCount); LoadedCount = 0; }
public static void LoadGlobalOptions() { if (!File.Exists(Path.Combine(General.SavePath, "GlobalOptions.bin"))) return; using (FileStream bin = new FileStream(Path.Combine(General.SavePath, "GlobalOptions.bin"), FileMode.Open, FileAccess.Read, FileShare.Read)) { GenericReader reader = new BinaryFileReader(new BinaryReader(bin)); int version = reader.ReadInt(); if (version >= 2) s_MultiPort = reader.ReadInt(); if (version >= 2) s_MultiServer = reader.ReadString(); int count = 0; if (version >= 1) { count = reader.ReadInt(); Notification not = null; for (int i = 0; i < count; ++i) { not = new Notification(); not.Load(reader); } } count = reader.ReadInt(); string txt = ""; for (int i = 0; i < count; ++i) { txt = reader.ReadString(); if(!s_Filters.Contains(txt)) s_Filters.Add(txt); } s_FilterPenalty = (FilterPenalty)reader.ReadInt(); if(version >= 1) s_MacroPenalty = (MacroPenalty)reader.ReadInt(); s_MaxMsgs = reader.ReadInt(); s_ChatSpam = reader.ReadInt(); s_MsgSpam = reader.ReadInt(); s_RequestSpam = reader.ReadInt(); s_FilterBanLength = reader.ReadInt(); s_FilterWarnings = reader.ReadInt(); if (version >= 1) s_AntiMacroDelay = reader.ReadInt(); s_IrcPort = reader.ReadInt(); s_IrcMaxAttempts = reader.ReadInt(); s_IrcEnabled = reader.ReadBool(); s_IrcAutoConnect = reader.ReadBool(); s_IrcAutoReconnect = reader.ReadBool(); s_FilterSpeech = reader.ReadBool(); s_FilterMsg = reader.ReadBool(); s_Debug = reader.ReadBool(); s_LogChat = reader.ReadBool(); s_LogPms = reader.ReadBool(); s_IrcStaffColor = (IrcColor)reader.ReadInt(); s_IrcServer = reader.ReadString(); s_IrcRoom = reader.ReadString(); s_IrcNick = reader.ReadString(); s_TotalChats = reader.ReadULong() - 1; } }
private static void EventSink_WorldLoad() { try { Console.Write("Loading SectorNodes..."); DateTime dt = DateTime.Now; using (FileStream fs = new FileStream("Data/SectorPathData.dat", FileMode.Open)) { using (BinaryReader br = new BinaryReader(fs)) { BinaryFileReader reader = new BinaryFileReader(br); if (reader.ReadInt() != (Map.Felucca.Width >> Map.SectorShift)) throw new Exception("SectorNode data has different width than current map."); if (reader.ReadInt() != (Map.Felucca.Height >> Map.SectorShift)) throw new Exception("SectorNode data has different height than current map."); m_Nodes = new SectorNode[Map.Felucca.Width >> Map.SectorShift, Map.Felucca.Height >> Map.SectorShift]; for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++) { for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++) { m_Nodes[x, y] = new SectorNode(); } } for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++) { for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++) { m_Nodes[x, y].Deserialize(reader); } } reader.Close(); } } Console.WriteLine("done in {0}ms.", (DateTime.Now - dt).TotalMilliseconds); } catch (Exception e) { LogHelper.LogException(e); Console.WriteLine("error:"); Console.WriteLine(e.Message); Console.WriteLine("SectorNode data must be recomputed."); m_Nodes = null; } }
public static void OnLoad() { try { Console.WriteLine("TownshipSettings Loading..."); string filePath = Path.Combine("Saves/AngelIsland", "Township.bin"); if (!File.Exists(filePath)) return; BinaryFileReader datreader = new BinaryFileReader(new BinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read))); int version = datreader.ReadInt(); switch (version) { case 5: WallTeleporterDistance = datreader.ReadInt(); goto case 4; case 4: InitialFunds = datreader.ReadInt(); goto case 3; case 3: TSDeedCost = datreader.ReadInt(); GuildHousePercentage = datreader.ReadDouble(); LLModifierNone = datreader.ReadDouble(); LLModifierLow = datreader.ReadDouble(); LLModifierMed = datreader.ReadDouble(); LLModifierHigh = datreader.ReadDouble(); LLModifierBoom = datreader.ReadDouble(); NPCModifierNone = datreader.ReadDouble(); NPCModifierLow = datreader.ReadDouble(); NPCModifierMed = datreader.ReadDouble(); NPCModifierHigh = datreader.ReadDouble(); NPCModifierBoom = datreader.ReadDouble(); BaseModifierNone = datreader.ReadDouble(); BaseModifierLow = datreader.ReadDouble(); BaseModifierMed = datreader.ReadDouble(); BaseModifierHigh = datreader.ReadDouble(); BaseModifierBoom = datreader.ReadDouble(); goto case 2; case 2: BaseFee = datreader.ReadInt(); ExtendedFee = datreader.ReadInt(); NoGateOutFee = datreader.ReadInt(); NoGateInFee = datreader.ReadInt(); NoRecallOutFee = datreader.ReadInt(); NoRecallInFee = datreader.ReadInt(); LawlessFee = datreader.ReadInt(); LawAuthFee = datreader.ReadInt(); NPCType1Fee = datreader.ReadInt(); NPCType2Fee = datreader.ReadInt(); NPCType3Fee = datreader.ReadInt(); LawNormCharge = datreader.ReadInt(); LawlessCharge = datreader.ReadInt(); LawAuthCharge = datreader.ReadInt(); ChangeTravelCharge = datreader.ReadInt(); UpdateEnemyCharge = datreader.ReadInt(); EmissaryCharge = datreader.ReadInt(); EvocatorCharge = datreader.ReadInt(); AlchemistCharge = datreader.ReadInt(); AnimalTrainerCharge = datreader.ReadInt(); BankerCharge = datreader.ReadInt(); InnkeeperCharge = datreader.ReadInt(); MageCharge = datreader.ReadInt(); ProvisionerCharge = datreader.ReadInt(); ArmsTrainerCharge = datreader.ReadInt(); MageTrainerCharge = datreader.ReadInt(); RogueTrainerCharge = datreader.ReadInt(); LookoutCharge = datreader.ReadInt(); TownCrierCharge = datreader.ReadInt(); goto case 1; case 1: Hue = datreader.ReadInt(); NoneToLow = datreader.ReadInt(); LowToMedium = datreader.ReadInt(); MediumToHigh = datreader.ReadInt(); HighToBooming = datreader.ReadInt(); break; } datreader.Close(); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } }
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."); } } }
public static void Load() { try { if (!File.Exists(Path.Combine(General.SavePath, "Channels.bin"))) { PredefinedChannels(); return; } using (FileStream bin = new FileStream(Path.Combine(General.SavePath, "Channels.bin"), FileMode.Open, FileAccess.Read, FileShare.Read)) { GenericReader reader = new BinaryFileReader(new BinaryReader(bin)); int version = reader.ReadInt(); int count = reader.ReadInt(); Channel c; for (int i = 0; i < count; ++i) { c = Activator.CreateInstance(ScriptCompiler.FindTypeByFullName(reader.ReadString())) as Channel; if (c == null) { c = new Channel(); c.Load(reader); s_Channels.Remove(c); } else { c.Load(reader); } } } PredefinedChannels(); } catch(Exception e) { Errors.Report(General.Local(186)); Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } }
private static void OnLoad() { try{ if ( !File.Exists( Path.Combine( "Saves/Gumps/", "Gumps.bin" ) ) ) return; using ( FileStream bin = new FileStream( Path.Combine( "Saves/Gumps/", "Gumps.bin" ), FileMode.Open, FileAccess.Read, FileShare.Read ) ) { GenericReader reader = new BinaryFileReader( new BinaryReader( bin ) ); int version = reader.ReadInt(); if ( version >= 0 ) { int count = reader.ReadInt(); GumpInfo info; for( int i = 0; i < count; ++i ) { info = new GumpInfo(); info.Load( reader ); if ( info.Mobile == null || info.Type == null ) continue; if ( s_Infos[info.Mobile] == null ) s_Infos[info.Mobile] = new Hashtable(); ((Hashtable)s_Infos[info.Mobile])[info.Type] = info; } } reader.End(); } }catch{ Errors.Report( "GumpInfo-> OnLoad" ); } }
public static void DeserializeMessages() { if( !File.Exists( SaveFile ) ) return; using( FileStream stream = new FileStream( SaveFile, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryFileReader reader = new BinaryFileReader( new BinaryReader( stream ) ); int count = reader.ReadInt(); for( int i = 0; i < count; i++ ) { int serial = reader.ReadInt(); if( serial > -1 ) { Mobile m = World.FindMobile( serial ); int messages = reader.ReadInt(); List<ChatMessage> msgList = new List<ChatMessage>( messages ); for( int j = 0; j < messages; j++ ) msgList.Add( new ChatMessage( reader ) ); if( !_messageTable.ContainsKey( m ) ) _messageTable.Add( m, msgList ); } } } }
public static void Load() { if (m_Loaded) return; m_Loaded = true; m_LoadingType = null; Console.WriteLine("World: Loading..."); DateTime start = DateTime.Now; m_Loading = true; // Take care of some World class-specific stuff try { BinaryFileReader datreader = new BinaryFileReader(new BinaryReader(new FileStream("Saves/World.dat", FileMode.Open, FileAccess.Read))); int version = datreader.ReadInt(); switch (version) { case 1: { int count = datreader.ReadInt(); m_ReservedSerials = new Dictionary<int, bool>(count); for (int i = 0; i < count; i++) m_ReservedSerials[datreader.ReadInt()] = true; goto case 0; } case 0: { m_FreezeDryEnabled = datreader.ReadBool(); break; } default: { throw new Exception("Invalid World.dat savefile version."); } } datreader.Close(); } catch (Exception e) { Console.WriteLine("Error reading World.dat, using default values:"); Console.WriteLine(e.ToString()); m_ReservedSerials = new Dictionary<int, bool>(0); m_FreezeDryEnabled = false; } m_DeleteList = new ArrayList(); int mobileCount = 0, itemCount = 0, guildCount = 0, regionCount = 0; object[] ctorArgs = new object[1]; Type[] ctorTypes = new Type[1] { typeof(Serial) }; ArrayList items = new ArrayList(); ArrayList mobiles = new ArrayList(); ArrayList guilds = new ArrayList(); ArrayList regions = new ArrayList(); if (File.Exists(mobIdxPath) && File.Exists(mobTdbPath)) { using (FileStream idx = new FileStream(mobIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader idxReader = new BinaryReader(idx); using (FileStream tdb = new FileStream(mobTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader tdbReader = new BinaryReader(tdb); int count = tdbReader.ReadInt32(); ArrayList types = new ArrayList(count); for (int i = 0; i < count; ++i) { string typeName = tdbReader.ReadString(); Type t = ScriptCompiler.FindTypeByFullName(typeName); if (t == null) { Console.WriteLine("failed"); Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName); if (Console.ReadLine() == "y") { types.Add(null); Console.Write("World: Loading..."); continue; } Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return"); throw new Exception(String.Format("Bad type '{0}'", typeName)); } ConstructorInfo ctor = t.GetConstructor(ctorTypes); if (ctor != null) { types.Add(new object[] { ctor, null }); } else { throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t)); } } mobileCount = idxReader.ReadInt32(); m_Mobiles = new Dictionary<Serial, Mobile>(mobileCount); for (int i = 0; i < mobileCount; ++i) { int typeID = idxReader.ReadInt32(); int serial = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); object[] objs = (object[])types[typeID]; if (objs == null) continue; Mobile m = null; ConstructorInfo ctor = (ConstructorInfo)objs[0]; string typeName = (string)objs[1]; try { ctorArgs[0] = (Serial)serial; m = (Mobile)(ctor.Invoke(ctorArgs)); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } if (m != null) { mobiles.Add(new MobileEntry(m, typeID, typeName, pos, length)); AddMobile(m); } } tdbReader.Close(); } idxReader.Close(); } } else { m_Mobiles = new Dictionary<Serial, Mobile>(); } if (File.Exists(itemIdxPath) && File.Exists(itemTdbPath)) { using (FileStream idx = new FileStream(itemIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader idxReader = new BinaryReader(idx); using (FileStream tdb = new FileStream(itemTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader tdbReader = new BinaryReader(tdb); int count = tdbReader.ReadInt32(); ArrayList types = new ArrayList(count); for (int i = 0; i < count; ++i) { string typeName = tdbReader.ReadString(); Type t = ScriptCompiler.FindTypeByFullName(typeName); if (t == null) { Console.WriteLine("failed"); Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName); if (Console.ReadLine() == "y") { types.Add(null); Console.Write("World: Loading..."); continue; } Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return"); throw new Exception(String.Format("Bad type '{0}'", typeName)); } ConstructorInfo ctor = t.GetConstructor(ctorTypes); if (ctor != null) { types.Add(new object[] { ctor, typeName }); } else { throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t)); } } itemCount = idxReader.ReadInt32(); m_Items = new Dictionary<Serial, Item>(itemCount); for (int i = 0; i < itemCount; ++i) { int typeID = idxReader.ReadInt32(); int serial = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); object[] objs = (object[])types[typeID]; if (objs == null) continue; Item item = null; ConstructorInfo ctor = (ConstructorInfo)objs[0]; string typeName = (string)objs[1]; try { ctorArgs[0] = (Serial)serial; item = (Item)(ctor.Invoke(ctorArgs)); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } if (item != null) { items.Add(new ItemEntry(item, typeID, typeName, pos, length)); AddItem(item); } } tdbReader.Close(); } idxReader.Close(); } } else { m_Items = new Dictionary<Serial, Item>(); } if (File.Exists(guildIdxPath)) { using (FileStream idx = new FileStream(guildIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader idxReader = new BinaryReader(idx); guildCount = idxReader.ReadInt32(); CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1); for (int i = 0; i < guildCount; ++i) { idxReader.ReadInt32();//no typeid for guilds int id = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); createEventArgs.Id = id; BaseGuild guild = EventSink.InvokeCreateGuild(createEventArgs);//new Guild( id ); if (guild != null) guilds.Add(new GuildEntry(guild, pos, length)); } idxReader.Close(); } } if (File.Exists(regionIdxPath)) { using (FileStream idx = new FileStream(regionIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader idxReader = new BinaryReader(idx); regionCount = idxReader.ReadInt32(); for (int i = 0; i < regionCount; ++i) { int typeID = idxReader.ReadInt32(); int serial = idxReader.ReadInt32(); long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); Region r = Region.FindByUId(serial); if (r != null) { regions.Add(new RegionEntry(r, pos, length)); Region.AddRegion(r); regionCount++; } } idxReader.Close(); } } bool failedMobiles = false, failedItems = false, failedGuilds = false, failedRegions = false; Type failedType = null; Serial failedSerial = Serial.Zero; Exception failed = null; int failedTypeID = 0; if (File.Exists(mobBinPath)) { using (FileStream bin = new FileStream(mobBinPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); for (int i = 0; i < mobiles.Count; ++i) { MobileEntry entry = (MobileEntry)mobiles[i]; Mobile m = (Mobile)entry.Object; if (m != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { m_LoadingType = entry.TypeName; m.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType())); } catch (Exception e) { mobiles.RemoveAt(i); failed = e; failedMobiles = true; failedType = m.GetType(); failedTypeID = entry.TypeID; failedSerial = m.Serial; break; } } } reader.Close(); } } if (!failedMobiles && File.Exists(itemBinPath)) { using (FileStream bin = new FileStream(itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); for (int i = 0; i < items.Count; ++i) { ItemEntry entry = (ItemEntry)items[i]; Item item = (Item)entry.Object; if (item != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { m_LoadingType = entry.TypeName; item.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType())); } catch (Exception e) { items.RemoveAt(i); failed = e; failedItems = true; failedType = item.GetType(); failedTypeID = entry.TypeID; failedSerial = item.Serial; break; } } } reader.Close(); } } m_LoadingType = null; if (!failedMobiles && !failedItems && File.Exists(guildBinPath)) { using (FileStream bin = new FileStream(guildBinPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); for (int i = 0; i < guilds.Count; ++i) { GuildEntry entry = (GuildEntry)guilds[i]; BaseGuild g = (BaseGuild)entry.Object; if (g != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { g.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id)); } catch (Exception e) { guilds.RemoveAt(i); failed = e; failedGuilds = true; failedType = typeof(BaseGuild); failedTypeID = g.Id; failedSerial = g.Id; break; } } } reader.Close(); } } if (!failedMobiles && !failedItems && File.Exists(regionBinPath)) { using (FileStream bin = new FileStream(regionBinPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); for (int i = 0; i < regions.Count; ++i) { RegionEntry entry = (RegionEntry)regions[i]; Region r = (Region)entry.Object; if (r != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { r.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) throw new Exception(String.Format("***** Bad serialize on {0} *****", r.GetType())); } catch (Exception e) { regions.RemoveAt(i); failed = e; failedRegions = true; failedType = r.GetType(); failedTypeID = entry.TypeID; failedSerial = r.UId; break; } } } reader.Close(); } } if (failedItems || failedMobiles || failedGuilds || failedRegions) { Console.WriteLine("An error was encountered while loading a saved object"); Console.WriteLine(" - Type: {0}", failedType); Console.WriteLine(" - Serial: {0}", failedSerial); Console.WriteLine("Delete the object? (y/n)"); if (Console.ReadLine() == "y") { if (failedType != typeof(BaseGuild) && !failedType.IsSubclassOf(typeof(Region))) { Console.WriteLine("Delete all objects of that type? (y/n)"); if (Console.ReadLine() == "y") { if (failedMobiles) { for (int i = 0; i < mobiles.Count; ) { if (((MobileEntry)mobiles[i]).TypeID == failedTypeID) mobiles.RemoveAt(i); else ++i; } } else if (failedItems) { for (int i = 0; i < items.Count; ) { if (((ItemEntry)items[i]).TypeID == failedTypeID) items.RemoveAt(i); else ++i; } } } } SaveIndex(mobiles, mobIdxPath); SaveIndex(items, itemIdxPath); SaveIndex(guilds, guildIdxPath); SaveIndex(regions, regionIdxPath); } Console.WriteLine("After pressing return an exception will be thrown and the server will terminate"); Console.ReadLine(); throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, regions={3}, type={4}, serial={5})", failedItems, failedMobiles, failedGuilds, failedRegions, failedType, failedSerial), failed); } EventSink.InvokeWorldLoad(); m_Loading = false; for (int i = 0; i < m_DeleteList.Count; ++i) { object o = m_DeleteList[i]; if (o is Item) ((Item)o).Delete(); else if (o is Mobile) ((Mobile)o).Delete(); } m_DeleteList.Clear(); foreach (Item item in m_Items.Values) { if (item.Parent == null) item.UpdateTotals(); item.ClearProperties(); } ArrayList list = new ArrayList(m_Mobiles.Values); foreach (Mobile m in list) { m.ForceRegionReEnter(true); m.UpdateTotals(); m.ClearProperties(); } // adam: not currently used //DateTime copy = DateTime.Now; // make sure we take the snapshotted Temp and move it out into working data //if (Directory.Exists("Temp")) //Directory.Delete("Temp", true); //if (Directory.Exists("Saves/Temp")) //CopyDirectory("Saves/Temp", "Temp"); //Console.WriteLine("Copying Temp/ took {0}ms.", (DateTime.Now - copy).TotalMilliseconds); Console.WriteLine("done ({1} items, {2} mobiles) ({0:F1} seconds)", (DateTime.Now - start).TotalSeconds, m_Items.Count, m_Mobiles.Count); }
private static void event_worldLoad() { if( !File.Exists( PersistenceFile ) ) return; using( FileStream stream = new FileStream( PersistenceFile, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryFileReader reader = new BinaryFileReader( new BinaryReader( stream ) ); int count = reader.ReadInt(); for( int i = 0; i < count; i++ ) { int serial = reader.ReadInt(); if( serial > -1 ) { Mobile m = World.FindMobile( serial ); GrabOptions options = new GrabOptions( reader ); if( m != null && !m.Deleted ) { if( options != null && !OptionsTable.ContainsKey( m ) ) OptionsTable.Add( m, options ); } } } reader.Close(); } }
// Loads the MobileAndSpellList file the save method creates. public static void Load() { try { if ( !Directory.Exists( "Saves/BlueMagic/" ) ) Console.WriteLine( "Blue Magic: No save file found." ); else if ( !File.Exists( "Saves/BlueMagic/MobileAndSpellList.bin" ) ) Console.WriteLine( "Blue Magic: No save file found." ); else { Console.WriteLine( " " ); Console.Write( "Blue Magic: Save file found, loading..." ); using ( BinaryReader binReader = new BinaryReader( File.Open("Saves/BlueMagic/MobileAndSpellList.bin", FileMode.Open) ) ) { BinaryFileReader reader = new BinaryFileReader( binReader ); int keycount = reader.ReadInt(); int oldspellcount = reader.ReadInt(); for( int i = 0; i < keycount; i++ ) { Serial serial = reader.ReadInt(); if ( GetMobile( serial ) == null ) continue; bool[] bools = new bool[SPELLCOUNT]; for ( int j = 0; j < oldspellcount; j++ ) { bools[j] = reader.ReadBool(); } try { BlueMageSpells.Add( serial, bools ); } catch { Console.WriteLine( "Adding serial " + serial.ToString() + " to blue spells known has failed" ); } } reader.Close(); } Console.WriteLine( "Done." ); } } catch( Exception ex ) { Console.WriteLine( "BlueMagic Load failed" ); Console.WriteLine( "The exception was: " + ex.Message ); Console.WriteLine( "Continuing normal world load." ); } }
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 ); } } } }
public static void Deserialize(BinaryFileReader reader) { int version = reader.ReadInt(); if (version >= 0) { AllianceLimit = reader.ReadInt(); useXML = reader.ReadBool(); int count = reader.ReadInt(); for (int i = 1; i <= count; i++) { BaseAlliance alliance = new BaseAlliance(); alliance.Deserialize(reader); Alliances.Add(alliance); } } reader.Close(); }
private static void CustomLoad() { string binpath = m_FullPath + ".bin"; string idxpath = m_FullPath + ".idx"; if (File.Exists(binpath) && File.Exists(idxpath)) { using (FileStream bin = GetFileStream(binpath)) { BinaryFileReader binreader = new BinaryFileReader(new BinaryReader(bin)); using (FileStream idx = GetFileStream(idxpath)) { BinaryFileReader idxreader = new BinaryFileReader(new BinaryReader(idx)); int loadmethodscount = idxreader.ReadInt(); for (int i = 0; i < loadmethodscount; i++) { string index = idxreader.ReadString(); long binpos = idxreader.ReadLong(); SaveData sd; if (m_DataDictionary.TryGetValue(index, out sd)) { try { binreader.Seek(binpos, SeekOrigin.Begin); sd.LoadMethod(binreader); } catch (Exception error) { HandleError(error, index, new object[] { loadmethodscount, i, idxreader }); } long finpos = idxreader.ReadLong(); if (binreader.Position != finpos) HandleError(null, index, new object[] { loadmethodscount, i, idxreader, binreader.Position > finpos }); } else { idxreader.ReadLong(); Console.WriteLine("A module failed to load, the module that could not be found was indexed under the name \"{0}\". Please Review your Save/Load methods for this module.", index); } } idxreader.Close(); } binreader.Close(); } } }
public static void On_RHFile(CommandEventArgs e) { if (e.Arguments.Length != 1) { e.Mobile.SendMessage("Usage: [LoadCont <filename>"); return; } try { int loaded = 0; int count; LogHelper log = new LogHelper(e.Arguments[0] + " LoadCont.log"); log.Log(LogType.Text, String.Format("Reload process initiated by {0}, with {1} as backup data.", e.Mobile, e.Arguments[0])); using (FileStream idxfs = new FileStream(e.Arguments[0] + ".idx", FileMode.Open, FileAccess.Read)) { using (FileStream binfs = new FileStream(e.Arguments[0] + ".bin", FileMode.Open, FileAccess.Read)) { GenericReader bin = new BinaryFileReader(new BinaryReader(binfs)); GenericReader idx = new BinaryFileReader(new BinaryReader(idxfs)); count = idx.ReadInt(); if (count == -1) log.Log(LogType.Text, "No item data to reload."); // do nothing else { ArrayList items = new ArrayList(count); log.Log(LogType.Text, String.Format("Attempting to reload {0} items.", count)); Type[] ctortypes = new Type[] { typeof(Serial) }; object[] ctorargs = new object[1]; for (int i = 0; i < count; i++) { string type = idx.ReadString(); Serial serial = (Serial)idx.ReadInt(); long position = idx.ReadLong(); int length = idx.ReadInt(); Type t = ScriptCompiler.FindTypeByFullName(type); if (t == null) { Console.WriteLine("Warning: Tried to load nonexistent type {0}. Ignoring item.", type); log.Log(String.Format("Warning: Tried to load nonexistent type {0}. Ignoring item.", type)); continue; } ConstructorInfo ctor = t.GetConstructor(ctortypes); if (ctor == null) { Console.WriteLine("Warning: Tried to load type {0} which has no serialization constructor. Ignoring item.", type); log.Log(String.Format("Warning: Tried to load type {0} which has no serialization constructor. Ignoring item.", type)); continue; } Item item = null; try { if (World.FindItem(serial) != null) { log.Log(LogType.Item, World.FindItem(serial), "Serial already in use!! Loading of saved item failed."); } else if (!World.IsReserved(serial)) { log.Log(String.Format("Serial {0} is not reserved!! Loading of saved item failed.", serial)); } else { ctorargs[0] = serial; item = (Item)(ctor.Invoke(ctorargs)); } } catch (Exception ex) { LogHelper.LogException(ex); Console.WriteLine("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName); Console.WriteLine(ex.ToString()); log.Log(String.Format("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName)); log.Log(ex.ToString()); } if (item != null) { World.FreeSerial(serial); World.AddItem(item); items.Add(new object[] { item, position, length }); log.Log(String.Format("Successfully created item {0}", item)); } } for (int i = 0; i < items.Count; i++) { object[] entry = (object[])items[i]; Item item = entry[0] as Item; long position = (long)entry[1]; int length = (int)entry[2]; if (item != null) { bin.Seek(position, SeekOrigin.Begin); try { item.Deserialize(bin); // take care of parent hierarchy object p = item.Parent; if (p is Item) { ((Item)p).RemoveItem(item); item.Parent = null; ((Item)p).AddItem(item); } else if (p is Mobile) { ((Mobile)p).RemoveItem(item); item.Parent = null; ((Mobile)p).AddItem(item); } else { item.Delta(ItemDelta.Update); } item.ClearProperties(); object rp = item.RootParent; if (rp is Item) ((Item)rp).UpdateTotals(); else if (rp is Mobile) ((Mobile)rp).UpdateTotals(); else item.UpdateTotals(); if (bin.Position != (position + length)) throw new Exception(String.Format("Bad serialize on {0}", item)); log.Log(LogType.Item, item, "Successfully loaded."); loaded++; } catch (Exception ex) { LogHelper.LogException(ex); Console.WriteLine("Caught exception while deserializing {0}:", item); Console.WriteLine(ex.ToString()); Console.WriteLine("Deleting item."); log.Log(String.Format("Caught exception while deserializing {0}:", item)); log.Log(ex.ToString()); log.Log("Deleting item."); item.Delete(); } } } } idx.Close(); bin.Close(); } } Console.WriteLine("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded); log.Log(String.Format("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded)); e.Mobile.SendMessage("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded); log.Finish(); } catch (Exception ex) { LogHelper.LogException(ex); Console.WriteLine(ex.ToString()); e.Mobile.SendMessage("Exception: {0}", ex.Message); } }
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 OnLoad() { try { Console.WriteLine("KinSystemSettings Loading..."); string filePath = Path.Combine("Saves/AngelIsland", "KinSystemSettings.bin"); if (!File.Exists(filePath)) return; BinaryFileReader datreader = new BinaryFileReader(new BinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read))); int version = datreader.ReadInt(); switch (version) { case 11: A_MaxShoppers = datreader.ReadInt(); goto case 10; case 10: A_F_Visitor = datreader.ReadInt(); A_Visitor = datreader.ReadInt(); A_F_Sale = datreader.ReadInt(); A_Sale = datreader.ReadInt(); A_GPMaint = datreader.ReadInt(); A_GPHire = datreader.ReadInt(); A_GDeath = datreader.ReadInt(); A_F_Death = datreader.ReadInt(); A_Death = datreader.ReadInt(); A_GCChampLevel = datreader.ReadInt(); A_GCDeath = datreader.ReadInt(); A_MaxVisitors = datreader.ReadInt(); goto case 9; case 9: GuardChangeTimeHours = datreader.ReadInt(); goto case 8; case 8: CityGuardSlots = datreader.ReadInt(); GuardMaintMinutes = datreader.ReadInt(); GuardTypeLowSilverCost = datreader.ReadInt(); GuardTypeMediumSilverCost = datreader.ReadInt(); GuardTypeHighSilverCost = datreader.ReadInt(); GuardTypeLowSilverMaintCost = datreader.ReadInt(); GuardTypeMediumSilverMaintCost = datreader.ReadInt(); GuardTypeHighSilverMaintCost = datreader.ReadInt(); goto case 7; case 7: KinAwards = datreader.ReadBool(); goto case 6; case 6: OutputCaptureData = datreader.ReadBool(); goto case 5; case 5: CityCaptureEnabled = datreader.ReadBool(); VortexCaptureProportion = datreader.ReadDouble(); VortexMinDamagePercentage = datreader.ReadDouble(); BeneficiaryQualifyPercentage = datreader.ReadDouble(); BeneficiaryCap = datreader.ReadInt(); CaptureDefenseRange = datreader.ReadInt(); VortexExpireMinutes = datreader.ReadInt(); BaseCaptureMinutes = datreader.ReadInt(); goto case 4; case 4: KinNameHueEnabled = datreader.ReadBool(); goto case 3; case 3: ShowStatloss = datreader.ReadBool(); ShowKinSingleClick = datreader.ReadBool(); goto case 2; case 2: KinAggressionMinutes = datreader.ReadDouble(); KinBeneficialMinutes = datreader.ReadDouble(); KinHealerModifier = datreader.ReadDouble(); goto case 1; case 1: PointsEnabled = datreader.ReadBool(); StatLossEnabled = datreader.ReadBool(); StatLossPercentageSkills = datreader.ReadDouble(); StatLossPercentageStats = datreader.ReadDouble(); StatLossDurationMinutes = datreader.ReadDouble(); break; } datreader.Close(); } catch (Exception re) { System.Console.WriteLine("ERROR LOADING KinSystemSettings!"); Scripts.Commands.LogHelper.LogException(re); } }
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 static void OnLoad() { try { Console.WriteLine("KinCityManager Loading..."); string filePath = Path.Combine("Saves/AngelIsland", "KinCityManager.bin"); if (!File.Exists(filePath)) { Console.Write("Kin faction city data file not found. Generating default city data..."); foreach (int city in Enum.GetValues(typeof(KinFactionCities))) _cityData.Add((KinFactionCities)city, new KinCityData((KinFactionCities)city)); Console.WriteLine("done."); return; } BinaryFileReader datreader = new BinaryFileReader(new BinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read))); int version = datreader.ReadInt(); switch (version) { case 1: { int cityCount = datreader.ReadInt(); if (cityCount > 0) { for (int i = 0; i < cityCount; ++i) { try { KinCityData data = new KinCityData(datreader); _cityData.Add(data.City, data); } catch { } } } break; } } //if any were corrupted and failed to load, create a new set of data. foreach (int city in Enum.GetValues(typeof(KinFactionCities))) if (!_cityData.ContainsKey((KinFactionCities)city)) { Console.WriteLine("Warning: KinCityData for {0} did not load successfully, and a new blank set of data has been created.", ((KinFactionCities)city).ToString()); _cityData.Add((KinFactionCities)city, new KinCityData((KinFactionCities)city)); } datreader.Close(); } catch (Exception ex) { System.Console.WriteLine("Error loading KinCityManager!"); Scripts.Commands.LogHelper.LogException(ex); } }
public void Deserialize() { //Console.WriteLine("[Vote System]: Loading Config..."); FileInfo info = new FileInfo("Data\\VoteSystem.cfg"); if (!info.Exists) info.Create().Close(); if (info.Length == 0) return; using (BinaryReader br = new BinaryReader(info.OpenRead())) { BinaryFileReader bin = new BinaryFileReader(br); int version = bin.ReadInt(); _DefaultName = bin.ReadString(); _DefaultURL = bin.ReadString(); _DefaultCoolDown = bin.ReadTimeSpan(); bin.Close(); } //Console.WriteLine("[Vote System]: Done."); }
public static void Load() { try { if (!File.Exists(Path.Combine(General.SavePath, "Gumps.bin"))) return; using (FileStream bin = new FileStream(Path.Combine(General.SavePath, "Gumps.bin"), FileMode.Open, FileAccess.Read, FileShare.Read)) { GenericReader reader = new BinaryFileReader(new BinaryReader(bin)); int version = reader.ReadInt(); if (version >= 0) { s_ForceMenu = reader.ReadBool(); int count = reader.ReadInt(); GumpInfo info; for (int i = 0; i < count; ++i) { info = new GumpInfo(); info.Load(reader); if (info.Type == null) continue; s_ForceInfos[info.Type] = info; } count = reader.ReadInt(); for (int i = 0; i < count; ++i) { info = new GumpInfo(); info.Load(reader); if (info.Mobile == null || info.Type == null) continue; if (s_Infos[info.Mobile] == null) s_Infos[info.Mobile] = new Hashtable(); ((Hashtable)s_Infos[info.Mobile])[info.Type] = info; } } reader.End(); } } catch (Exception e) { Errors.Report(General.Local(198)); Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } }
public static void Load() { if( !Directory.Exists( "Saves/ACC" ) ) return; string filename = "acc.sav"; string path = @"Saves/ACC/"; string pathNfile = path+filename; DateTime start = DateTime.Now; Console.WriteLine(); Console.WriteLine( "----------" ); Console.WriteLine( "Loading ACC..." ); try { using( FileStream m_FileStream = new FileStream( pathNfile, FileMode.Open, FileAccess.Read ) ) { BinaryReader m_BinaryReader = new BinaryReader( m_FileStream ); BinaryFileReader reader = new BinaryFileReader( m_BinaryReader ); if( m_RegSystems == null ) m_RegSystems = new Hashtable(); int Count = reader.ReadInt(); for( int i = 0; i < Count; i++ ) { string system = reader.ReadString(); Type t = ScriptCompiler.FindTypeByFullName( system ); bool enabled = reader.ReadBool(); if( t != null ) { m_RegSystems[system] = enabled; if( (bool)m_RegSystems[system] ) { ACCSystem sys = (ACCSystem)Activator.CreateInstance( t ); if( sys != null ) sys.StartLoad( path ); } } } reader.Close(); m_FileStream.Close(); } Console.WriteLine( "Done in {0:F1} seconds.", (DateTime.Now-start).TotalSeconds ); Console.WriteLine( "----------" ); Console.WriteLine(); } catch( Exception e ) { Console.WriteLine( "Failed. Exception: "+e ); } }
private static void OnLoad() { try{ if ( !File.Exists( Path.Combine( "Saves/Commands/", "Commands.bin" ) ) ) return; using ( FileStream bin = new FileStream( Path.Combine( "Saves/Commands/", "Commands.bin" ), FileMode.Open, FileAccess.Read, FileShare.Read ) ) { GenericReader reader = new BinaryFileReader( new BinaryReader( bin ) ); int version = reader.ReadInt(); int count = reader.ReadInt(); object[] obj; for( int i = 0; i < count; ++i ) { obj = new object[3]; obj[0] = reader.ReadString(); obj[1] = reader.ReadString(); obj[2] = reader.ReadInt(); s_InitInfo.Add( obj ); } } }catch{ Errors.Report( "Commands-> OnLoad" ); } }
public static void LoadBackup( Mobile mobile, ArrayList ArgsList, string filePath ) { ArrayList HideSpawnerList = (ArrayList) ArgsList[6]; ArrayList MSGCheckBoxesList = (ArrayList) ArgsList[13]; MC.SetProcess( Process.LoadBackup ); FileStream fs; BinaryFileReader reader; mobile.SendMessage( "Loading backup file..." ); try { fs = new FileStream( filePath, (FileMode) 3, (FileAccess) 1, (FileShare) 1 ); reader = new BinaryFileReader( new BinaryReader( fs ) ); } catch(Exception ex) { MC.SetProcess( Process.None ); ArgsList[2] = "Load Backup File"; ArgsList[4] = String.Format( "Exception caught:\n{0}", ex ); mobile.SendGump( new FileBrowserGump( mobile, ArgsList ) ); return; } int amountOfSpawners = reader.ReadInt(); int cnt = 0; for ( int i = 0; i < amountOfSpawners; i++ ) { if ( Deserialize( (GenericReader) reader ) ) { HideSpawnerList.Add( (bool) false ); MSGCheckBoxesList.Add( (bool) false ); cnt++; } } if ( fs != null ) fs.Close(); MC.SetProcess( Process.None ); ArgsList[2] = "Load Backup File"; ArgsList[4] = String.Format( "Loading of backup file complete. {0} Mega Spawner{1} been installed.", cnt, cnt == 1 ? " has" : "s have" ); ArgsList[6] = HideSpawnerList; ArgsList[13] = MSGCheckBoxesList; mobile.SendGump( new FileMenuGump( mobile, ArgsList ) ); }
private static void Load() { try { string SavePath = Path.Combine( m_SavePath, "forumdata.sig" ); using( FileStream fs = new FileStream( SavePath, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { BinaryReader br = new BinaryReader( fs ); BinaryFileReader reader = new BinaryFileReader( br ); int version = reader.ReadInt(); switch( version ) { case 0: { m_PlayerStatistics = ReadPlayerStatistics( reader ); int count = reader.ReadInt(); for( int i = 0; i < count; i++ ) { ThreadEntry te = new ThreadEntry(); te.Deserialize( reader ); m_Threads.Add( te ); } m_Moderators = reader.ReadMobileList(); m_ThreadDeleteAccessLevel = (AccessLevel)reader.ReadInt(); m_ThreadLockAccesLevel = ( AccessLevel )reader.ReadInt(); m_AutoCleanup = reader.ReadBool(); m_AutoCleanupDays = reader.ReadInt(); m_MinPostCharactersCount = reader.ReadInt(); m_MaxPostCharactersCount = reader.ReadInt(); break; } } } m_Threads.Sort( new DateSort() ); Console.WriteLine( "done" ); Console.WriteLine( "---------" ); } catch(Exception err) { Console.WriteLine( "An error occured while loading the forums...{0}", err.ToString() ); Console.WriteLine( "---------" ); } }
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 bool Rehydrate() { if (!CanFreezeDry) { Console.WriteLine("Warning: Tried to rehydrate dry a non-freezable item: {0}", this); Console.WriteLine(new System.Diagnostics.StackTrace()); return false; } if (!GetFlag(ImplFlag.FreezeDried)) { Console.WriteLine("Warning: Tried to rehydrate a non-freezedried item: {0}", this); Console.WriteLine(new System.Diagnostics.StackTrace()); return false; } if (m_SerializedContentsBin == null || m_SerializedContentsIdx == null) { Console.WriteLine("Warning: Tried to rehydrate an item with no serialized data: {0}", this); Console.WriteLine(new System.Diagnostics.StackTrace()); return false; } if (World.Saving) { Console.WriteLine("Warning: Attempted to rehydrate item {0} during a world save!", this); Console.WriteLine(new System.Diagnostics.StackTrace()); return false; } GenericReader bin = new BinaryFileReader(new BinaryReader(new MemoryStream(m_SerializedContentsBin))); GenericReader idx = new BinaryFileReader(new BinaryReader(new MemoryStream(m_SerializedContentsIdx))); SetFlag(ImplFlag.FreezeDried, false); // set it here, no fatal errors from here on out and AddItem checks it TotalItems = 0; TotalWeight = 0; TotalGold = 0; bool faileditem = false; StringBuilder errlog = new StringBuilder(); int count = idx.ReadInt(); if (count == -1) m_Items = null; else { ArrayList items = new ArrayList(count); m_Items = new ArrayList(count); // set so it won't double unnecessarily Type[] ctortypes = new Type[] { typeof(Serial) }; object[] ctorargs = new object[1]; for (int i = 0; i < count; i++) { string type = idx.ReadString(); Serial serial = (Serial)idx.ReadInt(); long position = idx.ReadLong(); int length = idx.ReadInt(); Type t = ScriptCompiler.FindTypeByFullName(type); if (t == null) { Console.WriteLine("Warning: Tried to load nonexistent type {0} when rehydrating container {1}. Ignoring item.", type, this); errlog.AppendFormat("Warning: Tried to load nonexistent type {0} when rehydrating container {1}. Ignoring item.\r\n\r\n", type, this); faileditem = true; continue; } ConstructorInfo ctor = t.GetConstructor(ctortypes); if (ctor == null) { Console.WriteLine("Warning: Tried to load type {0} which has no serialization constructor when rehydrating container {1}. Ignoring item.", type, this); errlog.AppendFormat("Warning: Tried to load type {0} which has no serialization constructor when rehydrating container {1}. Ignoring item.\r\n\r\n", type, this); faileditem = true; continue; } Item item = null; try { if (World.FindItem(serial) != null) { Console.WriteLine("Warning: Serial number being rehydrated already exists in world, patching: {0}", serial); if (World.IsReserved(serial) == true) // free the old one World.FreeSerial(serial); serial = Serial.NewItem; // create a new one Console.WriteLine("Warning: Serial in use, issuing a new one: {0}", serial); World.ReserveSerial(serial); // reserve a new one // throw new Exception(String.Format("Serial number being rehydrated already exists in world: {0}", serial)); } else if (!World.IsReserved(serial)) { Console.WriteLine("Warning: Serial number being rehydrated is not reserved, patching: {0}", serial); Console.WriteLine("Warning: Serial Not being used, reusing: {0}", serial); // reserve it now World.ReserveSerial(serial); // throw new Exception(String.Format("Serial number being rehydrated is not reserved (shouldn't be FD'ed!): {0}", serial)); } ctorargs[0] = serial; item = (Item)(ctor.Invoke(ctorargs)); } catch (Exception e) { Console.WriteLine("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName); Console.WriteLine(e.ToString()); errlog.AppendFormat("An exception occurred while trying to invoke {0}'s serialization constructor.\r\n", t.FullName); errlog.Append(e.ToString()); errlog.AppendFormat("\r\n\r\n"); faileditem = true; } if (item != null) { World.FreeSerial(serial); World.AddItem(item); items.Add(new object[] { item, position, length }); } } for (int i = 0; i < items.Count; i++) { object[] entry = (object[])items[i]; Item item = entry[0] as Item; long position = (long)entry[1]; int length = (int)entry[2]; if (item != null) { bin.Seek(position, SeekOrigin.Begin); try { item.Deserialize(bin); item.Map = Map; // items will set their parent automatically, and containers will load their contents // however items in the first level will load their parent (this), but this won't add them automatically if (item.Parent == this) { item.Parent = null; AddItem(item); } item.ClearProperties(); if (bin.Position != (position + length)) throw new Exception(String.Format("Bad serialize on {0}", item.GetType().FullName)); } catch (Exception e) { Console.WriteLine("Caught exception while deserializing {0} for container {1}:", item.GetType().FullName, this); Console.WriteLine(e.ToString()); Console.WriteLine("Deleting item."); item.Delete(); errlog.AppendFormat("Caught exception while deserializing {0} for container {1}:\r\n", item.GetType().FullName, this); errlog.Append(e.ToString()); errlog.Append("\r\nDeleting item.\r\n\r\n"); faileditem = true; } } } } idx.Close(); bin.Close(); if (faileditem) { try { string failedpath = "Logs/FailedRehydrate/"; if (!Directory.Exists(failedpath)) Directory.CreateDirectory(failedpath); using (FileStream fs = new FileStream(Path.Combine(failedpath, String.Format("{0} {1}.idx", Serial, DateTime.Now.ToString("MM-dd-yyyy HH-mm-ss"))), FileMode.Create, FileAccess.Write)) { fs.Write(m_SerializedContentsIdx, 0, m_SerializedContentsIdx.Length); fs.Close(); } using (FileStream fs = new FileStream(Path.Combine(failedpath, String.Format("{0} {1}.bin", Serial, DateTime.Now.ToString("MM-dd-yyyy HH-mm-ss"))), FileMode.Create, FileAccess.Write)) { fs.Write(m_SerializedContentsBin, 0, m_SerializedContentsBin.Length); fs.Close(); } using (StreamWriter sw = new StreamWriter(Path.Combine(failedpath, String.Format("{0} {1}.log", Serial, DateTime.Now.ToString("MM-dd-yyyy HH-mm-ss"))))) { sw.WriteLine("Error log for container {0}", this); if (this.Parent is Mobile) sw.WriteLine("Parent is Mobile: {0}", Parent); else sw.WriteLine("Location: {0}", Location); sw.WriteLine(); sw.Write(errlog.ToString()); sw.Close(); } } catch (Exception e) { Console.WriteLine("Failed to dump data for failed rehydration."); Console.WriteLine("Exception: {0}", e.Message); } } m_SerializedContentsIdx = null; m_SerializedContentsBin = null; if (RootParent is Mobile) ((Mobile)RootParent).UpdateTotals(); else if (RootParent is Item) ((Item)RootParent).UpdateTotals(); else UpdateTotals(); OnRehydrate(); if (Debug) Console.WriteLine("Rehydrated {0}", this); return true; }