/// <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 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 9: WallHitsDecay = datreader.ReadInt(); goto case 8; case 8: AuctioneerPayoutPercentage = datreader.ReadDouble(); goto case 7; case 7: AuctioneerCharge = datreader.ReadInt(); goto case 6; case 6: FightBrokerCharge = datreader.ReadInt(); goto case 5; 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)); } //try to initialize informational fee stuff - not crucial as this is informational // and gets set when the activity calcs are done try { FeePercentageCalc = (double)BaseFee / 2500.0; FeeAcctInfoCount = (int)(FeePercentageCalc * 1000.0); } catch { } }
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(); }
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 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); } }
/// <summary> /// Reads a DMT file filtered by a provided filter. /// </summary> /// <param name="file">The mesh file.</param> /// <param name="filter">The provided filtered.</param> /// <returns>The DMTModel that obeys to the filter condition.</returns> public List <DMTModel> ReadFile(File file, IDMTModelFilter filter) { var blocksIn = new List <DMTTriangleBlock>(); var blocksOut = new List <DMTTriangleBlock>(); var binaryReader = new BinaryFileReader(file); try { if (file.Exists == false) { throw new DMTFileException(DMTFileError.FileDoesNotExist); } // Read the file header. It is terminated with a 0 (null) and or has a // maximum of 256 bytes string header = null; header = binaryReader.ReadStringUntil(0, 256); // Read the file version number. Should be 1000 as this is the only format currently supported var version = binaryReader.ReadUShort(); if (version != 1000) { //Close the reader and return fail binaryReader.Close(); throw new DMTFileException(DMTFileError.UnsupportedFileFormat); } // Read the file flags // The bits of this integer are used as flags to detail file specific features. // 1. If this bit is set then the vertex data are stored as floats, else doubles. // 2. If this bit is set then the file contains triangles which are known to have been written in units of MMs. // If the flag is unset then the units used are unknown. This change was introduced by api#25 and dicc34143 // // New files (Since TVD release 2000111) MUST be written in MM. The code in dmkdmt always sets the flag and // the write_node() API ensures that you know about the requirement. uint fileFlags = 0; fileFlags = binaryReader.ReadUInteger(); var pointsAreFloats = (fileFlags & 1) == 1; // Read the number of triangle blocks in the file. Should not be zero uint noOfBlocks = 0; noOfBlocks = binaryReader.ReadUInteger(); if (noOfBlocks == 0) { binaryReader.Close(); throw new DMTFileException(DMTFileError.NoTriangleBlocks); } // Read the number of vertices in the file. Should not be zero uint totalTriangleVertices = 0; totalTriangleVertices = binaryReader.ReadUInteger(); if (totalTriangleVertices == 0) { binaryReader.Close(); throw new DMTFileException(DMTFileError.NoVertices); } // Read the number of triangles in the file. Should not be zero uint totalTriangles = 0; totalTriangles = binaryReader.ReadUInteger(); if (totalTriangles == 0) { binaryReader.Close(); throw new DMTFileException(DMTFileError.NoTriangles); } // Read the blocks for (var blockNo = 0; blockNo <= noOfBlocks - 1; blockNo++) { var blockIn = new DMTTriangleBlock(); var blockOut = new DMTTriangleBlock(); var vertices = new List <Point>(); var vertexNormals = new List <Vector>(); var oldIndexToNewIndexMapBlockIn = new Dictionary <int, int>(); var oldIndexToNewIndexMapBlockOut = new Dictionary <int, int>(); // Read the block flags uint blockFlags = 0; blockFlags = binaryReader.ReadUInteger(); var verticesHaveNormals = false; verticesHaveNormals = (blockFlags & 1) == 1; blockIn.DoVerticesHaveNormals = verticesHaveNormals; blockOut.DoVerticesHaveNormals = verticesHaveNormals; uint noOfTriangleVertices = 0; noOfTriangleVertices = binaryReader.ReadUInteger(); uint noOfTriangles = 0; noOfTriangles = binaryReader.ReadUInteger(); // Read the vertices var x = default(MM); var y = default(MM); var z = default(MM); var nx = default(MM); var ny = default(MM); var nz = default(MM); for (var intNodeNo = 0; intNodeNo <= noOfTriangleVertices - 1; intNodeNo++) { // Read the XYZ values if (pointsAreFloats) { x = binaryReader.ReadSingle(); y = binaryReader.ReadSingle(); z = binaryReader.ReadSingle(); } else { x = binaryReader.ReadDouble(); y = binaryReader.ReadDouble(); z = binaryReader.ReadDouble(); } // Continue reading if (verticesHaveNormals) { if (pointsAreFloats) { nx = binaryReader.ReadSingle(); ny = binaryReader.ReadSingle(); nz = binaryReader.ReadSingle(); } else { nx = binaryReader.ReadDouble(); ny = binaryReader.ReadDouble(); nz = binaryReader.ReadDouble(); } } // Store the vertex vertices.Add(new Point(x, y, z)); if (verticesHaveNormals) { vertexNormals.Add(new Vector(nx, ny, nz)); } } // What size are the pointers? // They will use 32 bit Unsigned Integers if 16 bit Unsigned Integer is not enough var use32bitPointers = noOfTriangleVertices > ushort.MaxValue; // Read the triangles var vertex1Index = 0; var vertex2Index = 0; var vertex3Index = 0; for (var triangleNo = 0; triangleNo <= noOfTriangles - 1; triangleNo++) { if (use32bitPointers) { vertex1Index = binaryReader.ReadInteger(); vertex2Index = binaryReader.ReadInteger(); vertex3Index = binaryReader.ReadInteger(); } else { vertex1Index = binaryReader.ReadUShort(); vertex2Index = binaryReader.ReadUShort(); vertex3Index = binaryReader.ReadUShort(); } if (filter.CanAddTriangle(vertices[vertex1Index], vertices[vertex2Index], vertices[vertex3Index])) { AddTriangle(oldIndexToNewIndexMapBlockIn, blockIn, verticesHaveNormals, vertices, vertexNormals, vertex1Index, vertex2Index, vertex3Index); } else { AddTriangle(oldIndexToNewIndexMapBlockOut, blockOut, verticesHaveNormals, vertices, vertexNormals, vertex1Index, vertex2Index, vertex3Index); } } // Check that the version number is ok if (binaryReader.ReadUShort() != version) { throw new DMTFileException(DMTFileError.BlockVersionDoesNotMatchFileVersion); } blocksIn.Add(blockIn); blocksOut.Add(blockOut); } var modelWithinFilter = new DMTModel(); var modelOutsideFilter = new DMTModel(); modelWithinFilter.TriangleBlocks.AddRange(blocksIn); modelOutsideFilter.TriangleBlocks.AddRange(blocksOut); var result = new List <DMTModel>(); result.Add(modelWithinFilter); result.Add(modelOutsideFilter); return(result); } finally { // Close the binary reader if (binaryReader != null) { binaryReader.Close(); } } }
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)); } }