예제 #1
0
 public LPKBlockEntry(BinaryFileReader reader)
 {
     PtrFile = reader.ReadUInt();
     FileSize = reader.ReadUInt();
     FileSizeCompressed = reader.ReadUInt();
     Flags = reader.ReadUInt();
 }
예제 #2
0
파일: CSS.cs 프로젝트: evildude807/kaltar
        public override void Load(BinaryReader idx, BinaryReader tdb, BinaryFileReader reader)
        {
            int version = reader.ReadInt();

            m_Loaded = new Hashtable();

            switch (version)
            {
                case 0:
                    {
                        int keys = reader.ReadInt();
                        for (int i = 0; i < keys; i++)
                        {
                            School school = (School)reader.ReadInt();
                            ArrayList valuelist = new ArrayList();

                            int values = reader.ReadInt();
                            for (int j = 0; j < values; j++)
                            {
                                valuelist.Add(new CSpellInfo(reader));
                            }

                            m_Loaded.Add(school, valuelist);
                        }

                        CSSettings.FullSpellbooks = reader.ReadBool();
                        PrevVersion = reader.ReadInt();

                        Refresh();
                        Update();
                        break;
                    }
            }
        }
예제 #3
0
        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));
        }
예제 #4
0
 public RecordGroup(ProxySink proxySink, BinaryFileReader r, string filePath, GameFormat format, int recordLevel, int depth)
 {
     _proxySink  = proxySink;
     _r          = r;
     FilePath    = filePath;
     Format      = format;
     RecordLevel = recordLevel;
     Depth       = depth;
 }
예제 #5
0
 public LNAMField(BinaryFileReader r, int dataSize)
 {
     Direct = new FormId <Record>(r.ReadUInt32());
     //if (dataSize == 0)
     IndirectWorld = new FormId <WRLDRecord>(r.ReadUInt32());
     //if (dataSize == 0)
     IndirectGridX = r.ReadInt16();
     IndirectGridY = r.ReadInt16();
 }
예제 #6
0
            public int Flags; //: AutoCalc

            public DATAField(BinaryFileReader r, int dataSize, GameFormat format)
            {
                Weight = r.ReadSingle();
                if (format == GameFormat.TES3)
                {
                    Value = r.ReadInt32();
                    Flags = r.ReadInt32();
                }
            }
 public DATA3Field(BinaryFileReader r, int dataSize)
 {
     Unknown1    = r.ReadInt32();
     Disposition = r.ReadInt32();
     Rank        = r.ReadByte();
     Gender      = r.ReadByte();
     PCRank      = r.ReadByte();
     Unknown2    = r.ReadByte();
 }
예제 #8
0
 public TNAMField(BinaryFileReader r, int dataSize)
 {
     Sunrise_Begin    = r.ReadByte();
     Sunrise_End      = r.ReadByte();
     Sunset_Begin     = r.ReadByte();
     Sunset_End       = r.ReadByte();
     Volatility       = r.ReadByte();
     MoonsPhaseLength = r.ReadByte();
 }
예제 #9
0
 public AI_FField(BinaryFileReader r, int dataSize)
 {
     X        = r.ReadSingle();
     Y        = r.ReadSingle();
     Z        = r.ReadSingle();
     Duration = r.ReadInt16();
     Id       = r.ReadASCIIString(32, ASCIIFormat.ZeroPadded);
     Unknown  = r.ReadInt16();
 }
예제 #10
0
 private ushort[] GetPalette(BinaryFileReader reader)
 {
     ushort[] pal = new ushort[0x100];
     for (int i = 0; i < 0x100; ++i)
     {
         pal[i] = (ushort)(reader.ReadUShort() | 0x8000);
     }
     return(pal);
 }
예제 #11
0
        public FMIDField <SCPTRecord>?SCRI;                     // Unknown

        public override bool CreateField(BinaryFileReader r, GameFormat format, string type, int dataSize)
        {
            switch (type)
            {
            case "EDID":
            case "NAME": EDID = r.ReadSTRV(dataSize); return(true);

            case "FULL":
            case "FNAM": FULL = r.ReadSTRV(dataSize); return(true);

            case "MODL": MODL = new MODLGroup(r, dataSize); return(true);

            case "MODB": MODL.MODBField(r, dataSize); return(true);

            case "RNAM": RNAM = r.ReadSTRV(dataSize); return(true);

            case "ANAM": ANAM = r.ReadSTRV(dataSize); return(true);

            case "BNAM": BNAM = r.ReadSTRV(dataSize); return(true);

            case "CNAM": CNAM = r.ReadSTRV(dataSize); return(true);

            case "KNAM": KNAM = r.ReadSTRV(dataSize); return(true);

            case "NPDT": NPDT = new NPDTField(r, dataSize); return(true);

            case "FLAG": FLAG = r.ReadINTV(dataSize); return(true);

            case "NPCO": NPCOs.Add(new CNTOField(r, dataSize, format)); return(true);

            case "NPCS": NPCSs.Add(r.ReadSTRV(dataSize, ASCIIFormat.ZeroPadded)); return(true);

            case "AIDT": AIDT = new CREARecord.AIDTField(r, dataSize); return(true);

            case "AI_W": AI_W = new CREARecord.AI_WField(r, dataSize); return(true);

            case "AI_T": AI_T = new CREARecord.AI_TField(r, dataSize); return(true);

            case "AI_F": AI_F = new CREARecord.AI_FField(r, dataSize); return(true);

            case "AI_E": AI_E = new CREARecord.AI_FField(r, dataSize); return(true);

            case "CNDT": CNDT = r.ReadSTRV(dataSize); return(true);

            case "AI_A": AI_A = new CREARecord.AI_AField(r, dataSize); return(true);

            case "DODT": DODT = new DODTField(r, dataSize); return(true);

            case "DNAM": DNAM = r.ReadSTRV(dataSize); return(true);

            case "XSCL": XSCL = r.ReadT <FLTVField>(dataSize); return(true);

            case "SCRI": SCRI = new FMIDField <SCPTRecord>(r, dataSize); return(true);

            default: return(false);
            }
        }
예제 #12
0
 public DODTField(BinaryFileReader r, int dataSize)
 {
     XPos = r.ReadSingle();
     YPos = r.ReadSingle();
     ZPos = r.ReadSingle();
     XRot = r.ReadSingle();
     YRot = r.ReadSingle();
     ZRot = r.ReadSingle();
 }
예제 #13
0
            public sbyte[] HeightData;      // HeightData

            public VHGTField(BinaryFileReader r, int dataSize)
            {
                ReferenceHeight = r.ReadSingle();
                var count = dataSize - 4 - 3;

                HeightData = r.ReadTArray <sbyte>(count, count);
                //HeightData = new sbyte[count];
                //for (var i = 0; i < HeightData.Length; i++) HeightData[i] = r.ReadSByte();
                r.Skip(3); // Unused
            }
예제 #14
0
        private void ReadAllowedArtifacts(BinaryFileReader reader)
        {
            if (mapObject.Header.Version != EMapFormat.ROE)
            {
                int bytes = (mapObject.Header.Version == EMapFormat.AB ? 17 : 18);

                HashSet <int> allowedList = new HashSet <int>();
                reader.ReadBitMask(allowedList, bytes, GameConstants.ARTIFACTS_QUANTITY);
            }
        }
예제 #15
0
            public RNAMField(BinaryFileReader r, int dataSize)
            {
                GridX = r.ReadInt16();
                GridY = r.ReadInt16();
                var referenceCount = r.ReadUInt32();
                var referenceSize  = dataSize - 8;

                Assert(referenceSize >> 3 == referenceCount);
                GridReferences = r.ReadTArray <Reference>(referenceSize, referenceSize >> 3);
            }
예제 #16
0
 public PGRLField(BinaryFileReader r, int dataSize)
 {
     Reference = new FormId <REFRRecord>(r.ReadUInt32());
     PointIds  = new short[(dataSize - 4) >> 2];
     for (var i = 0; i < PointIds.Length; i++)
     {
         PointIds[i] = r.ReadInt16();
         r.Skip(2); // Unused (can merge back)
     }
 }
예제 #17
0
 public DATAField(BinaryFileReader r, int dataSize, GameFormat format)
 {
     if (format == GameFormat.TES3)
     {
         Weight = r.ReadSingle();
         return;
     }
     Flags  = r.ReadByte();
     Weight = r.ReadSingle();
 }
예제 #18
0
        ushort[] GetPalette(BinaryFileReader r)
        {
            var pal = new ushort[0x100];

            for (var i = 0; i < 0x100; ++i)
            {
                pal[i] = (ushort)(r.ReadUInt16() | 0x8000);
            }
            return(pal);
        }
예제 #19
0
 public DATAField(BinaryFileReader r, int dataSize)
 {
     if (dataSize != 102 && dataSize != 86 && dataSize != 62 && dataSize != 42 && dataSize != 2)
     {
         WindVelocity = 1;
     }
     if (dataSize == 2)
     {
         Damage = r.ReadUInt16();
         return;
     }
     WindVelocity          = r.ReadSingle();
     WindDirection         = r.ReadSingle();
     WaveAmplitude         = r.ReadSingle();
     WaveFrequency         = r.ReadSingle();
     SunPower              = r.ReadSingle();
     ReflectivityAmount    = r.ReadSingle();
     FresnelAmount         = r.ReadSingle();
     ScrollXSpeed          = r.ReadSingle();
     ScrollYSpeed          = r.ReadSingle();
     FogDistance_NearPlane = r.ReadSingle();
     if (dataSize == 42)
     {
         Damage = r.ReadUInt16();
         return;
     }
     FogDistance_FarPlane = r.ReadSingle();
     ShallowColor         = r.ReadT <ColorRef4>(dataSize);
     DeepColor            = r.ReadT <ColorRef4>(dataSize);
     ReflectionColor      = r.ReadT <ColorRef4>(dataSize);
     TextureBlend         = r.ReadByte();
     r.Skip(3); // Unused
     if (dataSize == 62)
     {
         Damage = r.ReadUInt16();
         return;
     }
     RainSimulator_Force         = r.ReadSingle();
     RainSimulator_Velocity      = r.ReadSingle();
     RainSimulator_Falloff       = r.ReadSingle();
     RainSimulator_Dampner       = r.ReadSingle();
     RainSimulator_StartingSize  = r.ReadSingle();
     DisplacementSimulator_Force = r.ReadSingle();
     if (dataSize == 86)
     {
         //DisplacementSimulator_Velocity = DisplacementSimulator_Falloff = DisplacementSimulator_Dampner = DisplacementSimulator_StartingSize = 0F;
         Damage = r.ReadUInt16();
         return;
     }
     DisplacementSimulator_Velocity     = r.ReadSingle();
     DisplacementSimulator_Falloff      = r.ReadSingle();
     DisplacementSimulator_Dampner      = r.ReadSingle();
     DisplacementSimulator_StartingSize = r.ReadSingle();
     Damage = r.ReadUInt16();
 }
예제 #20
0
 public VTEXField(BinaryFileReader r, int dataSize, GameFormat format)
 {
     if (format == GameFormat.TES3)
     {
         TextureIndicesT3 = r.ReadTArray <ushort>(dataSize, dataSize >> 1);
         TextureIndicesT4 = null;
         return;
     }
     TextureIndicesT3 = null;
     TextureIndicesT4 = r.ReadTArray <uint>(dataSize, dataSize >> 2);
 }
예제 #21
0
            public float[] UseValue;       // The use types for each skill are hard-coded.

            public DATAField(BinaryFileReader r, int dataSize, GameFormat format)
            {
                Action         = format == GameFormat.TES3 ? 0 : r.ReadInt32();
                Attribute      = r.ReadInt32();
                Specialization = r.ReadUInt32();
                UseValue       = new float[format == GameFormat.TES3 ? 4 : 2];
                for (var i = 0; i < UseValue.Length; i++)
                {
                    UseValue[i] = r.ReadSingle();
                }
            }
예제 #22
0
        unsafe Texture2D ReadLandTexture(int index)
        {
            int              length, extra;
            bool             is_patched;
            BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out is_patched);

            if (reader == null)
            {
                return(null);
            }
            ushort[] pixels = new ushort[44 * 44];
            ushort[] data   = reader.ReadUShorts(23 * 44); // land tile textures store only opaque pixels
            Metrics.ReportDataRead(data.Length);
            int i = 0;

            fixed(ushort *pData = pixels)
            {
                ushort *dataRef = pData;
                // fill the top half of the tile
                int count  = 2;
                int offset = 21;

                for (int y = 0; y < 22; y++, count += 2, offset--, dataRef += 44)
                {
                    ushort *start = dataRef + offset;
                    ushort *end   = start + count;
                    while (start < end)
                    {
                        ushort color   = data[i++];
                        *      start++ = (ushort)(color | 0x8000);
                    }
                }
                // file the bottom half of the tile
                count  = 44;
                offset = 0;
                for (int y = 0; y < 22; y++, count -= 2, offset++, dataRef += 44)
                {
                    ushort *start = dataRef + offset;
                    ushort *end   = start + count;
                    while (start < end)
                    {
                        ushort color   = data[i++];
                        *      start++ = (ushort)(color | 0x8000);
                    }
                }
            }

            Texture2D texture = new Texture2D(m_Graphics, 44, 44, false, SurfaceFormat.Bgra5551);

            texture.SetData(pixels);


            return(texture);
        }
예제 #23
0
        public FormId <Record> Item;      // The ID of the item

        public CNTOField(BinaryFileReader r, int dataSize, GameFormat format)
        {
            if (format == GameFormat.TES3)
            {
                ItemCount = r.ReadUInt32();
                Item      = new FormId <Record>(r.ReadASCIIString(32, ASCIIFormat.ZeroPadded));
                return;
            }
            Item      = new FormId <Record>(r.ReadUInt32());
            ItemCount = r.ReadUInt32();
        }
예제 #24
0
 public ENAMField(BinaryFileReader r, int dataSize)
 {
     EffectId    = r.ReadInt16();
     SkillId     = r.ReadByte();
     AttributeId = r.ReadByte();
     Unknown1    = r.ReadInt32();
     Unknown2    = r.ReadInt32();
     Duration    = r.ReadInt32();
     Magnitude   = r.ReadInt32();
     Unknown4    = r.ReadInt32();
 }
예제 #25
0
        public override bool CreateField(BinaryFileReader r, GameFormat format, string type, int dataSize)
        {
            switch (type)
            {
            case "EDID": EDID = r.ReadSTRV(dataSize); return(true);

            case "DNAM": DNAM = new DNAMField(r, dataSize); return(true);

            default: return(false);
            }
        }
예제 #26
0
 public CNAMField(BinaryFileReader r, int dataSize)
 {
     LeafCurvature      = r.ReadSingle();
     MinimumLeafAngle   = r.ReadSingle();
     MaximumLeafAngle   = r.ReadSingle();
     BranchDimmingValue = r.ReadSingle();
     LeafDimmingValue   = r.ReadSingle();
     ShadowRadius       = r.ReadInt32();
     RockSpeed          = r.ReadSingle();
     RustleSpeed        = r.ReadSingle();
 }
예제 #27
0
 public SCHDField(BinaryFileReader r, int dataSize)
 {
     Name           = r.ReadASCIIString(32, ASCIIFormat.ZeroPadded);
     NumShorts      = r.ReadInt32();
     NumLongs       = r.ReadInt32();
     NumFloats      = r.ReadInt32();
     ScriptDataSize = r.ReadInt32();
     LocalVarSize   = r.ReadInt32();
     // SCVRField
     Variables = null;
 }
 public SkillBoost(BinaryFileReader r, int dataSize, GameFormat format)
 {
     if (format == GameFormat.TES3)
     {
         SkillId = (byte)r.ReadInt32();
         Bonus   = (sbyte)r.ReadInt32();
         return;
     }
     SkillId = r.ReadByte();
     Bonus   = r.ReadSByte();
 }
예제 #29
0
 public SLSDField(BinaryFileReader r, int dataSize)
 {
     Idx = r.ReadUInt32();
     r.ReadUInt32(); // Unknown
     r.ReadUInt32(); // Unknown
     r.ReadUInt32(); // Unknown
     Type = r.ReadUInt32();
     r.ReadUInt32(); // Unknown
     // SCVRField
     VariableName = null;
 }
예제 #30
0
        public override void Load(BinaryReader idx, BinaryReader tdb, BinaryFileReader reader)
        {
            int version = reader.ReadInt();

            m_CategoryList = new List <PGCategory>();

            for (int i = reader.ReadInt(); i > 0; i--)
            {
                m_CategoryList.Add(new PGCategory(reader));
            }
        }
예제 #31
0
        public CREFField CNAME; // RGB color

        public override bool CreateField(BinaryFileReader r, GameFormat format, string type, int dataSize)
        {
            switch (type)
            {
            case "EDID": EDID = r.ReadSTRV(dataSize); return(true);

            case "CNAME": CNAME = r.ReadT <CREFField>(dataSize); return(true);

            default: return(false);
            }
        }
예제 #32
0
        /// <summary>
        /// Loads serialized data
        /// </summary>
        private static void OnWorldLoad()
        {
            if (!File.Exists(DataFile))
            {
                return;
            }

            using (FileStream stream = new FileStream(DataFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryFileReader reader = new BinaryFileReader(new BinaryReader(stream));

                int version = reader.ReadInt();

                switch (version)
                {
                case 0:
                    int tableCount = reader.ReadInt();
                    PerkTable = new Dictionary <Player, Tuple <Perk, Perk> >(tableCount);

                    Player player;
                    Perk   p1, p2;

                    try
                    {
                        for (int i = 0; i < tableCount; i++)
                        {
                            player = reader.ReadMobile <Player>();

                            if (player == null || player.Deleted)
                            {
                                continue;
                            }

                            ConstructorInfo ctor = GetPerkCtor(reader.ReadString());
                            p1 = ctor.Invoke(new object[] { reader }) as Perk;

                            ctor = GetPerkCtor(reader.ReadString());
                            p2   = ctor.Invoke(new object[] { reader }) as Perk;

                            PerkTable[player] = Tuple.Create <Perk, Perk>(p1, p2);
                        }
                    }

                    catch (Exception e)
                    {
                        Utilities.ExceptionManager.LogException("Perk", e);
                    }

                    break;
                }

                reader.Close();
            }
        }
예제 #33
0
파일: LPK.cs 프로젝트: FreeReign/UltimaXNA
        public LPK(string path)
        {
            if (path == null || path == string.Empty)
                Logging.Fatal("Path to packed file system cannot be empty.");
            if (!System.IO.File.Exists(path))
                Logging.Fatal("Path to packed file system must exist");

            m_Reader = InterXLib.Serialize.OpenReader(path);
            m_Header = new LPKHeader(m_Reader);

            m_HashEntries = new LPKHashEntry[m_Header.Hashcount];
            if (m_Header.HashTableSizeCompressed != 0)
            {
                byte[] hash_table_compressed = m_Reader.ReadBytes((int)m_Header.HashTableSizeCompressed);
                byte[] hash_table = Compression.LZF.Decompress(hash_table_compressed, (int)m_Header.Hashcount * LPKHashEntry.SizeInBytes);
                using (MemoryStream mem_stream = new MemoryStream(hash_table))
                {
                    BinaryFileReader reader = new BinaryFileReader(mem_stream);
                    for (int i = 0; i < m_Header.Hashcount; i++)
                        m_HashEntries[i] = new LPKHashEntry(reader);
                }
            }
            else
            {
                for (int i = 0; i < m_Header.Hashcount; i++)
                    m_HashEntries[i] = new LPKHashEntry(m_Reader);
            }

            m_BlockEntries = new LPKBlockEntry[m_Header.BlockCount];
            if (m_Header.HashTableSizeCompressed != 0)
            {
                byte[] block_table_compressed = m_Reader.ReadBytes((int)m_Header.BlockTableSizeCompressed);
                byte[] block_table = Compression.LZF.Decompress(block_table_compressed, (int)m_Header.BlockCount * LPKBlockEntry.SizeInBytes);
                using (MemoryStream mem_stream = new MemoryStream(block_table))
                {
                    BinaryFileReader reader = new BinaryFileReader(mem_stream);
                    for (int i = 0; i < m_Header.BlockCount; i++)
                        m_BlockEntries[i] = new LPKBlockEntry(reader);
                }
            }
            else
            {
                for (int i = 0; i < m_Header.BlockCount; i++)
                    m_BlockEntries[i] = new LPKBlockEntry(m_Reader);
            }
        }
예제 #34
0
        public LPKHeader(BinaryFileReader reader)
        {
            uint version_expected = InterXLib.Library.FourCharsToUInt("LPK2");
            uint version = reader.ReadUInt();

            if (version != version_expected)
                Logging.Fatal("File is not a lpk file.");

            Hashcount = reader.ReadUInt();
            BlockCount = reader.ReadUInt();
            PtrHashTable = reader.ReadUInt();
            PtrBlocks = reader.ReadUInt();
            PtrFiles = reader.ReadUInt();

            HashTableSizeCompressed = reader.ReadUInt();
            BlockTableSizeCompressed = reader.ReadUInt();
        }
예제 #35
0
		public void StartLoad( string path )
		{
			path += Name()+"/";

			string idxPath = path+Name()+".idx";
			string tdbPath = path+Name()+".tdb";
			string binPath = path+Name()+".bin";

			if( !Directory.Exists( path ) )
				Directory.CreateDirectory( path );

			if( File.Exists( idxPath ) && File.Exists( tdbPath ) && File.Exists( binPath ) )
			{
				using( FileStream idx = new FileStream( idxPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
				{
					BinaryReader idxReader = new BinaryReader( idx );

					using( FileStream tdb = new FileStream( tdbPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
					{
						BinaryReader tdbReader = new BinaryReader( tdb );

						using( FileStream bin = new FileStream( binPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
						{
							BinaryFileReader binReader = new BinaryFileReader( new BinaryReader( bin ) );

							Console.Write( " - Loading {0}", Name() );
							Load( idxReader, tdbReader, binReader );

							idxReader.Close();
							tdbReader.Close();
							binReader.Close();

							bin.Close();
							tdb.Close();
							idx.Close();

							Console.WriteLine( "   - Done." );
						}
					}
				}
			}
		}
예제 #36
0
		private static void LoadSaves()
		{
			try
			{
				if (!File.Exists(PointsFile))
					return;

				BinaryFileReader read = new BinaryFileReader(new BinaryReader(new FileStream(PointsFile, FileMode.Open)));
				GenericReader reader = read;
				InternalLoad(reader);
				read.Close();
				Console.WriteLine("Onsite Dueling System: DuelPoints loaded.");
			}
			catch (Exception e)
			{
				Console.WriteLine("Onsite Dueling System: Load failed!");
				Console.WriteLine("Caught an exception: {0}", e.ToString());
				m_PointsTable.Clear();
				m_DeclineDuelList.Clear();
				Console.WriteLine("Onsite Dueling System: Cleared potentially corrupted data.");
			}
		}
예제 #37
0
        private static List<Encoder> InternalGetEncoders(GraphicsDevice device, BinaryFileReader reader)
        {
            List<Encoder> list = new List<Encoder>();
            int reader_count = reader.Read7BitEncodedInt();
            Regex regex = new Regex(@"\b([a-z0-9_]+)(,|$)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

            for (int i = 0; i < reader_count; i++)
            {
                string reader_name = reader.ReadString();
                int reader_version = reader.ReadInt();
                string typeReaderShortName = regex.Match(reader_name).Groups[1].Value;
                if (typeReaderShortName.IndexOf("Reader") != -1)
                    typeReaderShortName = typeReaderShortName.Substring(0, typeReaderShortName.IndexOf("Reader"));
                bool isList = (reader_name.IndexOf("ListReader") != -1);

                Encoder encoder = new Encoder(typeReaderShortName, isList);
                list.Add(encoder);
            }

            return list;
        }
예제 #38
0
 private static object InternalReadObject(GraphicsDevice device, BinaryFileReader reader, List<Encoder> encoders)
 {
     int encoder_index = reader.Read7BitEncodedInt();
     if (encoder_index <= 0)
         return null;
     Encoder encoder = encoders[encoder_index - 1];
     switch (encoder.Name)
     {
         case "SpriteFont":
             return InternalReadSpriteFont(device, reader, encoders);
         case "Texture2D":
             return InternalReadTexture(device, reader, encoders);
         case "Rectangle":
             if (encoder.IsList)
                 return InternalReadListRectangle(device, reader, encoders);
             else
                 return InternalReadRectangle(device, reader, encoders);
         case "Char":
             if (encoder.IsList)
                 return InternalReadListChar(device, reader, encoders);
             else
                 return InternalReadChar(device, reader, encoders);
         case "Vector3":
             if (encoder.IsList)
                 return InternalReadListVector3(device, reader, encoders);
             else
                 return InternalReadVector3(device, reader, encoders);
     }
     return null;
 }
예제 #39
0
 private static char InternalReadChar(GraphicsDevice device, BinaryFileReader reader, List<Encoder> encoders)
 {
     char c = reader.ReadCharUTF8();
     return c;
 }
예제 #40
0
		public static void LoadDuellers()
		{
			if (File.Exists(duellersBinPath))
			{
				// Declare and initialize reader objects.
				FileStream bin = new FileStream(duellersBinPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin));

				try
				{
					duellers = binReader.ReadMobileList();
				}
				catch (Exception e)
				{

				}

				binReader.Close();
			}
		}
예제 #41
0
        public static void onLoad()
        {
            //System.Console.WriteLine("Loading Jailings");
            FileStream idxFileStream;
            FileStream binFileStream;
            //BinaryReader idxReader;
            BinaryFileReader idxReader;
            BinaryFileReader binReader;
            //GenericReader idxReader;
            long tPos;
            int tID;
            int tLength;
            JailSystem tJail;
            int JailCount = 0;
            int temp = 0;

            // Scriptiz : false pour annuler le if et pour qu'on charge toujours les paramètres par défaut !
            if (false && (File.Exists(idxPath)) && (File.Exists(binPath)))
            {
                idxFileStream = new FileStream(idxPath, (FileMode)3, (FileAccess)1, (FileShare)1);
                binFileStream = new FileStream(binPath, (FileMode)3, (FileAccess)1, (FileShare)1);
                try
                {
                    idxReader = new BinaryFileReader(new BinaryReader(idxFileStream));
                    binReader = new BinaryFileReader(new BinaryReader(binFileStream));
                    JailCount = idxReader.ReadInt();

                    if (JailCount > 0)
                    {
                        for (int i = 0; i < JailCount; i++)
                        {
                            temp = idxReader.ReadInt();//catch the version number which we wont use
                            tID = idxReader.ReadInt();
                            tPos = idxReader.ReadLong();
                            tLength = idxReader.ReadInt();
                            tJail = new JailSystem(tID);
                            binReader.Seek(tPos, 0);
                            try
                            {
                                tJail.Deserialize((GenericReader)binReader);
                                if (binReader.Position != ((long)tPos + tLength))
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", tID));
                            }
                            catch
                            { }
                        }
                    }
                    loadingameeditsettings((GenericReader)binReader);

                }
                finally
                {
                    if (idxFileStream != null)
                        idxFileStream.Close();
                    if (binFileStream != null)
                        binFileStream.Close();
                }
            }
            else
            {
                JailSystem.defaultSettings();
                //System.Console.WriteLine("{0}: No prior Jailsystem save, using default settings", JailSystem.JSName);
            }
            //System.Console.WriteLine("{0} Jailings Loaded:{1}", JailCount, list.Count);
        }
예제 #42
0
		public abstract void Load( BinaryReader idx, BinaryReader tdb, BinaryFileReader reader );
예제 #43
0
 public LPKHashEntry(BinaryFileReader reader)
 {
     SecondHash = reader.ReadUInt();
     BlockIndex = reader.ReadUInt();
     NextHashInSequence = reader.ReadUInt();
 }
예제 #44
0
		public void LoadPlugin(BinaryFileReader reader)
		{
			SkillReportsHelper.EnableProfileReport = reader.ReadBool();
			SkillReportsHelper.EnableSelectionReport = reader.ReadBool();
		}
        public static bool ImportBuilding(string filename)
        {
            bool finished = false;
            string binpath = Path.Combine(BaseBuilding.SavePath, filename + ".bin");

            if (File.Exists(binpath))
            {
                using (FileStream bin = CustomSaving.GetFileStream(binpath))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));
                    try
                    {
                        int count = reader.ReadInt();
                        for (int i = 0; i < count; i++)
                        {
                            string name = reader.ReadString();
                            int type = reader.ReadInt();

                            switch (type)
                            {
                                case 0: m_BuildingTable[name] = new BuildingEntry(reader, type); break;
                                case 1: m_BuildingTable[name] = new ComponentEntry(reader); break;
                                case 2: m_BuildingTable[name] = new AddonEntry(reader); break;
                            }
                        }
                        finished = true;
                    }
                    catch (Exception error)
                    {
                        Console.WriteLine(error.ToString());
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
            }
            return finished;
        }
예제 #46
0
        /// <summary>
        /// Loads serialized data
        /// </summary>
        private static void OnWorldLoad()
        {
            if( !File.Exists(DataFile) )
                return;

            using( FileStream stream = new FileStream(DataFile, FileMode.Open, FileAccess.Read, FileShare.Read) )
            {
                BinaryFileReader reader = new BinaryFileReader(new BinaryReader(stream));

                int tableCount = reader.ReadInt();
                EoCTable = new Dictionary<Player, EoCContext>(tableCount);

                for( int i = 0; i < tableCount; i++ )
                {
                    if( !reader.ReadBool() )
                        continue;

                    Player pl = reader.ReadMobile<Player>();

                    if( pl != null && !pl.Deleted )
                        EoCTable[pl] = new EoCContext(reader);
                }

                int hitsCount = reader.ReadInt();
                HitsTable = new Dictionary<Player, HitsTimer>(hitsCount);

                for( int i = 0; i < hitsCount; i++ )
                {
                    if( !reader.ReadBool() )
                        continue;

                    Player player = reader.ReadMobile<Player>();

                    if( player == null || player.Deleted )
                        continue;

                    HitsTable[player] = new HitsTimer(player);

                    DateTime next = reader.ReadDateTime();

                    if( next < DateTime.Now )
                        next = DateTime.Now;

                    HitsTable[player].Delay = (next - DateTime.Now);
                }

                reader.Close();
            }
        }
예제 #47
0
		public static void Load()
		{
			string idxPath = Path.Combine( "Saves/FS Systems/FSBounty", "BountyTable.idx" );
			string binPath = Path.Combine( "Saves/FS Systems/FSBounty", "BountyTable.bin" );

			if ( File.Exists( idxPath ) && File.Exists( binPath ) )
			{
				FileStream idx = new FileStream( idxPath, FileMode.Open, FileAccess.Read, FileShare.Read );
				FileStream bin = new FileStream( binPath, FileMode.Open, FileAccess.Read, FileShare.Read) ;
				BinaryReader idxReader = new BinaryReader( idx );
				BinaryFileReader binReader = new BinaryFileReader( new BinaryReader( bin ) );

				int orderCount = idxReader.ReadInt32();

				for ( int i = 0; i < orderCount; ++i )
				{
					
					Bounty ps = new Bounty();
					long startPos = idxReader.ReadInt64();
					int length = idxReader.ReadInt32();
					binReader.Seek( startPos, SeekOrigin.Begin );

					try
					{
						ps.Deserialize(binReader);

						if (binReader.Position != ( startPos + length ) )
							throw new Exception( String.Format( "***** Bad serialize on Bounty[{0}] *****", i ) );
					}
					catch
					{
					}

					if ( ps != null && ps.Wanted != null )
						BountyTable.Add( ps.Wanted, ps );
				}
      
				idxReader.Close();
				binReader.Close();
			}

		}
예제 #48
0
		public static void LoadDuels()
		{
			if (File.Exists(duelIdxPath) && File.Exists(duelBinPath))
			{
				// Declare and initialize reader objects.
				FileStream idx = new FileStream(duelIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				FileStream bin = new FileStream(duelBinPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				BinaryReader idxReader = new BinaryReader(idx);
				BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin));

				// Start by reading the number of duels from an index file
				int duelCount = idxReader.ReadInt32();

				for (int i = 0; i < duelCount; ++i)
				{
					DuelObject d = new DuelObject();
					// Read start-position and length of current fight from index file
					long startPos = idxReader.ReadInt64();
					int length = idxReader.ReadInt32();
					// Point the reading stream to the proper position
					binReader.Seek(startPos, SeekOrigin.Begin);

					try
					{
						d.Deserialize(binReader);

						if (binReader.Position != (startPos + length))
							throw new Exception(String.Format("***** Bad serialize on DuelObject[{0}] *****", i));
					}
					catch (Exception e)
					{
						//handle
					}
					duels.Add(d);
				}
				// Remember to close the streams
				idxReader.Close();
				binReader.Close();
			}
		}
예제 #49
0
        private static void Deserialize()
        {
            if (File.Exists(m_FilePath))
            {
                using (FileStream fs = new FileStream(m_FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    try
                    {
                        BinaryReader br = new BinaryReader(fs);
                        BinaryFileReader reader = new BinaryFileReader(br);

                        int version = reader.ReadInt();

                        int count = reader.ReadInt();
                        for (int i = 0; i < count; i++)
                        {
                            string subject = reader.ReadString();
                            string body = reader.ReadString();

                            int linkcount = reader.ReadInt();
                            ArrayList links = new ArrayList();
                            for (int j = 0; j < linkcount; j++)
                                links.Add(reader.ReadString());

                            m_Messages.Add(new MotDStruct(subject, body, links));
                        }
                    }

                    catch (Exception error)
                    {
                        Console.WriteLine(error.ToString());
                    }
                    finally
                    {
                        fs.Close();
                    }
                }
            }
        }
예제 #50
0
		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( "Loading...done" );
			}
			catch(Exception err)
			{
				Console.WriteLine( "An error occured while loading the forums...{0}", err.ToString() );
			}
		}
예제 #51
0
 private static List<Vector3> InternalReadListVector3(GraphicsDevice device, BinaryFileReader reader, List<Encoder> encoders)
 {
     int count = reader.ReadInt();
     List<Vector3> list = new List<Vector3>(count);
     for (int i = 0; i < count; i++)
         list.Add(InternalReadVector3(device, reader, encoders));
     return list;
 }
예제 #52
0
 private static Rectangle InternalReadRectangle(GraphicsDevice device, BinaryFileReader reader, List<Encoder> encoders)
 {
     Rectangle rectangle = new Rectangle(
         reader.ReadInt(), reader.ReadInt(), reader.ReadInt(), reader.ReadInt());
     return rectangle;
 }
예제 #53
0
        public static object ReadObject(GraphicsDevice device, string path)
        {
            BinaryFileReader reader = Serialize.OpenReader(path);
            byte[] magic = reader.ReadBytes(4);
            byte xnb_format_version = reader.ReadByte(); // 5 = XNA GS 4.0
            byte flag_bits = reader.ReadByte();
            bool isCompressed = ((flag_bits & 0x80) == 0x80);

            int file_size_on_disk = reader.ReadInt(); // size of file, including the header block

            if (isCompressed)
            {
                int file_size_decompressed = reader.ReadInt(); // does not include size of header block (14 bytes)
                MemoryStream decompressedStream = null;

                // default window size for XNB encoded files is 64Kb (need 16 bits to represent it)
                LzxDecoder lzx = new LzxDecoder(16);
                decompressedStream = new MemoryStream(file_size_decompressed);
                int compressedSize = file_size_on_disk - 14;
                long startPos = reader.Position;
                long pos = startPos;

                while (pos - startPos < compressedSize)
                {
                    // the compressed stream is seperated into blocks that will decompress
                    // into 32Kb or some other size if specified.
                    // normal, 32Kb output blocks will have a short indicating the size
                    // of the block before the block starts
                    // blocks that have a defined output will be preceded by a byte of value
                    // 0xFF (255), then a short indicating the output size and another
                    // for the block size
                    // all shorts for these cases are encoded in big endian order
                    int hi = reader.ReadByte();
                    int lo = reader.ReadByte();
                    int block_size = (hi << 8) | lo;
                    int frame_size = 0x8000; // frame size is 32Kb by default
                    // does this block define a frame size?
                    if (hi == 0xFF)
                    {
                        hi = lo;
                        lo = (byte)reader.ReadByte();
                        frame_size = (hi << 8) | lo;
                        hi = (byte)reader.ReadByte();
                        lo = (byte)reader.ReadByte();
                        block_size = (hi << 8) | lo;
                        pos += 5;
                    }
                    else
                        pos += 2;

                    // either says there is nothing to decode
                    if (block_size == 0 || frame_size == 0)
                        break;

                    lzx.Decompress(reader.Stream, block_size, decompressedStream, frame_size);
                    pos += block_size;

                    // reset the position of the input just incase the bit buffer
                    // read in some unused bytes
                    reader.Seek(pos, SeekOrigin.Begin);
                }

                if (decompressedStream.Position != file_size_decompressed)
                {
                    Logging.Fatal("Decompression of " + path + " failed. ");
                }

                decompressedStream.Seek(0, SeekOrigin.Begin);
                reader = new BinaryFileReader(new BinaryReader(decompressedStream));
            }

            List<Encoder> encoders = InternalGetEncoders(device, reader);

            int shared_resource_count = reader.Read7BitEncodedInt();

            Object value = InternalReadObject(device, reader, encoders);
            reader.Close();

            return value;
        }
예제 #54
0
        private static Texture2D InternalReadTexture(GraphicsDevice device, BinaryFileReader reader, List<Encoder> encoders)
        {
            SurfaceFormat format = (SurfaceFormat)reader.ReadInt();
            int width = reader.ReadInt(), height = reader.ReadInt(), mip_levels = reader.ReadInt();

            Texture2D texture = new Texture2D(device, width, height, (mip_levels > 1), format);
            for (int i = 0; i < mip_levels; i++)
            {
                int data_count = reader.ReadInt();
                byte[] data = reader.ReadBytes(data_count);
                texture.SetData<byte>(data);
            }
            return texture;
        }
예제 #55
0
        private static YSpriteFont InternalReadSpriteFont(GraphicsDevice device, BinaryFileReader reader, List<Encoder> encoders)
        {
            Texture2D texture = (Texture2D)InternalReadObject(device, reader, encoders);
            List<Rectangle> glyphBounds = (List<Rectangle>)InternalReadObject(device, reader, encoders);
            List<Rectangle> cropping = (List<Rectangle>)InternalReadObject(device, reader, encoders);
            List<char> characters = (List<char>)InternalReadObject(device, reader, encoders);
            int lineSpacing = reader.ReadInt();
            float spacing = reader.ReadFloat();
            List<Vector3> kerning = (List<Vector3>)InternalReadObject(device, reader, encoders);
            char? defaultChar = null;
            int default_char = (int)reader.ReadCharUTF8();
            if (default_char != 0)
                defaultChar = (char)default_char;

            YSpriteFont ysf = new YSpriteFont(texture, glyphBounds, cropping, characters, lineSpacing, spacing, kerning, defaultChar);
            return ysf;
        }
예제 #56
0
		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.");
				}
			}
		}
예제 #57
0
 private static Vector3 InternalReadVector3(GraphicsDevice device, BinaryFileReader reader, List<Encoder> encoders)
 {
     Vector3 v = new Vector3(
         reader.ReadFloat(), reader.ReadFloat(), reader.ReadFloat());
     return v;
 }
예제 #58
0
		public static void LoadFights()
		{
			if (File.Exists(fightIdxPath) && File.Exists(fightBinPath))
            {
                // Declare and initialize reader objects.
                FileStream idx = new FileStream(fightIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                FileStream bin = new FileStream(fightBinPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryReader idxReader = new BinaryReader(idx);
                BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin));

                // Start by reading the number of figts from an index file
                int fightCount = idxReader.ReadInt32();
                //Console.WriteLine("Fight objects: {0}", fightCount);
				bool indexSet = false;
				for (int i = 0; i < fightCount; ++i)
                {
                    Fight fight = new Fight();
                    // Read start-position and length of current fight from index file
                    long startPos = idxReader.ReadInt64();
                    int length = idxReader.ReadInt32();
                    // Point the reading stream to the proper position
                    binReader.Seek(startPos, SeekOrigin.Begin);

                    try
                    {
                        fight.Deserialize(binReader);

                        if (binReader.Position != (startPos + length))
                            throw new Exception(String.Format("***** Bad serialize on Fight[{0}] *****", i));
                    }
                    catch (Exception e)
                    {
                        //handle
                    }
                    fights.Add(fight);
					// Read data into fast-access variables
					// This is done to optimize perfomance
					// Searching through long arrays repeatedly
					// Could slow down the server


					// Add mobile to the list of active players
					if (fight.Winner != null && !players.Contains(fight.Winner))
						players.Add(fight.Winner);
					if (fight.Loser != null && !players.Contains(fight.Loser))
						players.Add(fight.Loser);

					// Adjust Honor, win and loss variables
					if (fight.Winner != null)
					{
						((PlayerMobile)fight.Winner).Wins++;
						((PlayerMobile)fight.Winner).Honor += fight.Gain;
					}
					if (fight.Loser != null)
					{
						((PlayerMobile)fight.Loser).Losses++;
						((PlayerMobile)fight.Loser).Honor -= fight.Loss;
					}


					// Adjust HonorChange variable and set the index of the last fight in interval
					if ( fight.Start > DateTime.Now - interval)
					{
						if (fight.Winner != null)
							((PlayerMobile)fight.Winner).HonorChange += fight.Gain;
						if (fight.Loser != null)
							((PlayerMobile)fight.Loser).HonorChange -= fight.Loss;
						if(!indexSet)
						{
							indexSet = true;
							lastIntervalIndex = fights.IndexOf(fight);
						}
					}

				}
				// Only old fights were found, or there was no fights to load.... so we set the index to last fight
				if (!indexSet && fights.Count != 0)
					lastIntervalIndex = fights.Count - 1;
				players.Sort();
				// Remember to close the streams
                idxReader.Close();
                binReader.Close();
            }
		}
		public static void Load()
		{
			string idxPath = Path.Combine( "Saves/FriendLists", "FriendLists.idx" );
			string binPath = Path.Combine( "Saves/FriendLists", "FriendLists.bin" );

			if (File.Exists(idxPath) && File.Exists(binPath))
			{
				// Declare and initialize reader objects.
				FileStream idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				FileStream bin = new FileStream(binPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				BinaryReader idxReader = new BinaryReader(idx);
				BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin));

				// Start by reading the number of duels from an index file
				int orderCount = idxReader.ReadInt32();

				for (int i = 0; i < orderCount; ++i)
				{

					FriendList fl = new FriendList();
					// Read start-position and length of current order from index file
					long startPos = idxReader.ReadInt64();
					int length = idxReader.ReadInt32();
					// Point the reading stream to the proper position
					binReader.Seek(startPos, SeekOrigin.Begin);

					try
					{
						fl.Deserialize(binReader);

						if (binReader.Position != (startPos + length))
							throw new Exception(String.Format("***** Bad serialize on FriendList[{0}] *****", i));
					}
					catch
					{
						//handle
					}
					if ( fl != null && fl.m_Mobile != null )
						FriendLists.Add( fl.m_Mobile, fl );
				}
				// Remember to close the streams
				idxReader.Close();
				binReader.Close();
			}

		}
		public static void Load()
		{
			Console.Write("DonatorAccountSettings: Loading...");

			string idxPath = Path.Combine( "Saves/Donation", "DonatorAccountSettings.idx" );
			string binPath = Path.Combine( "Saves/Donation", "DonatorAccountSettings.bin" );

			if (File.Exists(idxPath) && File.Exists(binPath))
			{
				// Declare and initialize reader objects.
				FileStream idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				FileStream bin = new FileStream(binPath, FileMode.Open, FileAccess.Read, FileShare.Read);
				BinaryReader idxReader = new BinaryReader(idx);
				BinaryFileReader binReader = new BinaryFileReader(new BinaryReader(bin));

				// Start by reading the number of duels from an index file
				int orderCount = idxReader.ReadInt32();

				for (int i = 0; i < orderCount; ++i)
				{

					DonatorAccountSettings das = new DonatorAccountSettings();
					// Read start-position and length of current order from index file
					long startPos = idxReader.ReadInt64();
					int length = idxReader.ReadInt32();
					// Point the reading stream to the proper position
					binReader.Seek(startPos, SeekOrigin.Begin);

					try
					{
						das.Deserialize(binReader);

						if (binReader.Position != (startPos + length))
							throw new Exception(String.Format("***** Bad serialize on DonatorAccountSettings[{0}] *****", i));
					}
					catch
					{
						//handle
					}
					if ( das != null && das.m_Account != null )
						DonatorAccountSettingsTable.Add( das.m_Account, das );
				}
				// Remember to close the streams
				idxReader.Close();
				binReader.Close();
			}

			Console.WriteLine("done");
		}