コード例 #1
0
            public static Variable DecodeVarBind(byte[] Data)
            {
                using (var stream = new MemoryStream(Data))
                    using (var read = new BigEndianReader(stream))
                    {
                        var nameType = (FieldType)read.ReadByte();
                        if (nameType != FieldType.OID)
                        {
                            throw new Exception("Invalid OID type for varbind");
                        }

                        var nameLen     = read.ReadInt16();
                        var oidIntCount = nameLen / sizeof(Int32);
                        var oidInts     = new UInt32[oidIntCount];
                        for (int i = 0; i < oidIntCount; ++i)
                        {
                            oidInts[i] = (UInt32)read.ReadInt32();
                        }

                        var oid = new ObjectIdentifier(oidInts);

                        var valueType = (FieldType)read.ReadByte();
                        var valueLen  = read.ReadUInt16();

                        switch (valueType)
                        {
                        default: break;

                        case FieldType.Null: return(new Variable(oid));

                        case FieldType.Int32: return(new Variable(oid, new Integer32(read.ReadInt32())));

                        case FieldType.String: return(new Variable(oid, new OctetString(read.ReadBytes(valueLen))));

                        case FieldType.OID:
                            oidIntCount = valueLen / sizeof(Int32);
                            oidInts     = new UInt32[oidIntCount];
                            for (int i = 0; i < oidIntCount; ++i)
                            {
                                oidInts[i] = (UInt32)read.ReadInt32();
                            }
                            return(new Variable(oid, new ObjectIdentifier(oidInts)));

                        case FieldType.IPAddress:
                            if (valueLen != 4)
                            {
                                throw new Exception("Invalid IP Address length");
                            }
                            return(new Variable(oid, new IP(read.ReadBytes(4))));

                        case FieldType.Counter32: return(new Variable(oid, new Counter32((UInt32)read.ReadInt32())));

                        case FieldType.Gauge32: return(new Variable(oid, new Gauge32((UInt32)read.ReadInt32())));

                        case FieldType.TimeTicks: return(new Variable(oid, new TimeTicks((UInt32)read.ReadInt32())));
                        }
                    }

                return(null);
            }
コード例 #2
0
        protected override void Parse(BigEndianReader reader)
        {
            reader.ReadByte();  // ID
            reader.ReadInt16(); // Size

            Serial   = reader.ReadUInt32();
            GumpID   = reader.ReadInt32();
            ButtonID = reader.ReadInt32();

            int switchCount = reader.ReadInt32();

            Switches = new List <int>(switchCount);

            for (int i = 0; i < switchCount; i++)
            {
                Switches.Add(reader.ReadInt32());
            }

            int entryCount = reader.ReadInt32();

            TextEntries = new List <GumpResponseTextEntry>(entryCount);

            for (int i = 0; i < entryCount; i++)
            {
                TextEntries.Add(new GumpResponseTextEntry(reader));
            }
        }
コード例 #3
0
        public SOLFile(string location)
        {
            var             bytes = File.ReadAllBytes(location);
            BigEndianReader br    = new BigEndianReader(bytes);

            ///HEADER///
            br.ReadInt16();                   //sol_version
            br.ReadInt32();                   //file length
            if (br.ReadInt32() != 0x5443534F) //TCSO
            {
                throw new Exception("Invalid magic number, maybe this isn't an SOL file?");
            }
            br.ReadBytes(6);                                                          //padding
            RootObject.name = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt16())); //shared object name
            if (RootObject.name != "savedLines")
            {
                throw new Exception("invalid root object");
            }
            if (br.ReadInt32() != 0)
            {
                throw new Exception("Invalid AMF version");//amf version, we only support 0o
            }
            ///items///
            Amf0 amf = new Amf0(br);

            RootObject.data = amf.ReadAmf0(true);
        }
コード例 #4
0
        public void Int32ReadWrite()
        {
            Int32 value;
            Int32 result;

            value = 20;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);


            //Multiple bytes

            value = 300000000;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);

            //Negative Values

            value = -30;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);

            //Max Values

            value = 2147483647;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);

            //Min Values

            value = -2147483648;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);
        }
コード例 #5
0
        /// <summary>
        /// Creates <see cref="TtfFileInfo"/> from <see cref="System.IO.Stream"/>.
        /// </summary>
        /// <param name="stream">Stream to create the structure. Stream will be disposed after use.</param>
        /// <returns><see cref="TtfFileInfo"/> if successful, otherwise null.</returns>
        public static TtfFileInfo FromStream(Stream stream)
        {
            try
            {
                using (var reader = new BigEndianReader(stream))
                {
                    var ttfFile = new TtfFileInfo()
                    {
                        Version = reader.ReadInt32()
                    };

                    if (ttfFile.Version != 0x74727565 && ttfFile.Version != 0x00010000) return null;

                    ttfFile.TableCount = reader.ReadInt16();
                    reader.BaseStream.Seek(6, SeekOrigin.Current);

                    for (var tableIndex = 0; tableIndex < ttfFile.TableCount; tableIndex++)
                    {
                        var tag = reader.ReadInt32();
                        reader.BaseStream.Seek(4, SeekOrigin.Current);
                        var offset = reader.ReadInt32();
                        var length = reader.ReadInt32();

                        if (tag != 0x6E616D65) continue;

                        reader.BaseStream.Seek(offset, SeekOrigin.Begin);

                        var table = reader.ReadBytes(length);

                        var count = GetInt16(table, 2);
                        var stringOffset = GetInt16(table, 4);

                        for (var record = 0; record < count; record++)
                        {
                            var nameidOffset = record*12 + 6;
                            var platformId = GetInt16(table, nameidOffset);
                            var nameidValue = GetInt16(table, nameidOffset + 6);

                            if (nameidValue != 4 || platformId != 1) continue;

                            var nameLength = GetInt16(table, nameidOffset + 8);
                            var nameOffset = stringOffset + GetInt16(table, nameidOffset + 10);

                            if (nameOffset < 0 || nameOffset + nameLength >= table.Length) continue;

                            ttfFile.FontName = Encoding.UTF8.GetString(table, nameOffset, nameLength);
                            return ttfFile;
                        }
                    }
                }
            }
            catch
            {
                return null;
            }

            return null;
        }
コード例 #6
0
ファイル: NewClientVersion.cs プロジェクト: mbnunes/SpyUO
 protected override void Parse(BigEndianReader reader)
 {
     reader.ReadByte();              // ID
     _Serial   = reader.ReadUInt32();
     _Ip       = reader.ReadInt32(); // IP
     _Major    = reader.ReadInt32(); // Version Major
     _Minor    = reader.ReadInt32(); // Version Minor
     _Revision = reader.ReadInt32(); // Version Revision
     _Build    = reader.ReadInt32(); // Version Build
 }
コード例 #7
0
        private static void Method_3()
        {
            var _loc1_ = new BigEndianReader(new MemoryStream(resources[0]));
            var _loc2_ = new BigEndianReader(new MemoryStream(resources[1]));
            var _loc3_ = new BinaryReader(new MemoryStream(resources[2]));

            var_10 = _loc3_.ReadInt32();
            int _loc4_ = _loc2_.ReadByte();
            var _loc5_ = 0;

            while (_loc5_ < _loc4_)
            {
                Method_2(_loc2_);
                _loc5_++;
            }
            _loc1_.BaseStream.Position = 0;
            _loc4_ = _loc1_.ReadInt32();
            var loc6 = 0;

            while (loc6 < _loc4_)
            {
                Method_1(_loc1_, var_4[loc6 % var_4.Count]);
                loc6++;
            }
            var_5 = true;
        }
コード例 #8
0
 public BuffItem(BigEndianReader reader)
 {
     _SourceType = (BuffSourceType)reader.ReadInt16();
     reader.ReadInt16();             // unknown
     _IconID     = reader.ReadInt16();
     _QueueIndex = reader.ReadInt16();
     reader.ReadInt32();             // unknown
     _Duration = reader.ReadInt16();
     reader.ReadBytes(3);            // unknown
     _TitleCliloc        = reader.ReadInt32();
     _SecondaryCliloc    = reader.ReadInt32();
     _TernaryCliloc      = reader.ReadInt32();
     _TitleArguments     = reader.ReadUnicodeString();
     _SecondaryArguments = reader.ReadUnicodeString();
     _TernaryArguments   = reader.ReadUnicodeString();
 }
コード例 #9
0
        public List <Amf0Object> ReadAmf0(bool rootobject = false)
        {
            List <Amf0Object> retlist = new List <Amf0Object>();

            while (true)
            {
                Amf0Object ret = new Amf0Object();
                if (br.Remaining < 2 && rootobject)
                {
                    return(retlist);
                }
                ret.name = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt16())); //object name
                ret.type = (Amf0Object.Amf0Type)br.ReadByte();                     //type
                switch (ret.type)
                {
                case Amf0Object.Amf0Type.AMF0_NUMBER:                        //NUMBER
                    ret.data = br.ReadDouble();
                    break;

                case Amf0Object.Amf0Type.AMF0_BOOLEAN:                        //BOOLEAN
                    ret.data = br.ReadBoolean();
                    break;

                case Amf0Object.Amf0Type.AMF0_STRING:
                    ret.data = Encoding.UTF8.GetString(br.ReadBytes(br.ReadInt16()));
                    break;

                case Amf0Object.Amf0Type.AMF0_OBJECT:                        //OBJECT
                {
                    ret.data = ReadAmf0();
                }
                break;

                case Amf0Object.Amf0Type.AMF0_NULL:
                case Amf0Object.Amf0Type.AMF0_UNDEFINED:
                    ret.data = null;
                    break;

                case Amf0Object.Amf0Type.AMF0_ECMA_ARRAY:                        //ecma array
                {
                    br.ReadInt32();
                    var ecma = ReadAmf0();
                    ret.data = ecma;
                    //							if (ecma.Count != l)
                    //								throw new Exception("Corrupt ECMA array in SOL file");
                }
                break;

                case Amf0Object.Amf0Type.AMF0_OBJECT_END:
                    return(retlist);

                default:
                    throw new Exception("Error reading SOL file (40)");
                }
                retlist.Add(ret);
            }
        }
コード例 #10
0
ファイル: CompressedGump.cs プロジェクト: mbnunes/SpyUO
        protected override void Parse(BigEndianReader reader)
        {
            reader.ReadByte();             // ID
            reader.ReadInt16();            // Size

            _Serial = reader.ReadUInt32();
            _GumpID = reader.ReadInt32();
            _X      = reader.ReadInt32();
            _Y      = reader.ReadInt32();

            int compressedEntriesLength   = reader.ReadInt32() - 4;
            int decompressedEntriesLength = reader.ReadInt32();

            byte[] compressedEntries   = reader.ReadBytes(compressedEntriesLength);
            byte[] decompressedEntries = new byte[decompressedEntriesLength];

            Ultima.Package.Zlib.Decompress(decompressedEntries, ref decompressedEntriesLength, compressedEntries, compressedEntriesLength);
            string entries = Encoding.ASCII.GetString(decompressedEntries);

            int lineCount = reader.ReadInt32();
            int compressedStringsLength   = reader.ReadInt32() - 4;
            int decompressedStringsLength = reader.ReadInt32();

            byte[] compressedStrings   = reader.ReadBytes(compressedStringsLength);
            byte[] decompressedStrings = new byte[decompressedStringsLength];

            Ultima.Package.Zlib.Decompress(decompressedStrings, ref decompressedStringsLength, compressedStrings, compressedStringsLength);
            string strings = Encoding.ASCII.GetString(decompressedStrings);

            _Text = new List <string>();

            int start = 0;

            for (int i = 0; i < strings.Length; i++)
            {
                if (strings[i] == 0)
                {
                    if (i - start > 0)
                    {
                        _Text.Add(strings.Substring(start, i - start));
                    }
                    else
                    {
                        _Text.Add(String.Empty);
                    }

                    start = i + 1;
                }
            }

            Parse(entries);
        }
コード例 #11
0
ファイル: GumpResponse.cs プロジェクト: greeduomacro/SpyUO
        protected override void Parse( BigEndianReader reader )
        {
            reader.ReadByte(); // ID
            reader.ReadInt16(); // Size

            _Serial = reader.ReadUInt32();
            _GumpID = reader.ReadInt32();
            _ButtonID = reader.ReadInt32();

            int switchCount = reader.ReadInt32();
            _Switches = new List<int>( switchCount );

            for ( int i = 0; i < switchCount; i++ )
                _Switches.Add( reader.ReadInt32() );

            int entryCount = reader.ReadInt32();
            _TextEntries = new List<GumpResponseTextEntry>( entryCount );

            for ( int i = 0; i < entryCount; i++ )
                _TextEntries.Add( new GumpResponseTextEntry( reader ) );
        }
コード例 #12
0
ファイル: GenericGump_B0.cs プロジェクト: Ben1028/SpyUO
        protected override void Parse( BigEndianReader reader )
        {
            reader.ReadByte(); // ID
            reader.ReadInt16(); // Size

            _Serial = reader.ReadUInt32();
            _GumpID = reader.ReadInt32();
            _X = reader.ReadInt32();
            _Y = reader.ReadInt32();

            string layout = reader.ReadAsciiString();

            int textLength = reader.ReadInt16();
            _Text = new List<string>( textLength );

            for ( int i = 0; i < textLength; i++ )
            {
                _Text.Add( reader.ReadAsciiString() );
            }

            Parse( layout );
        }
コード例 #13
0
ファイル: CompressedGump.cs プロジェクト: greeduomacro/SpyUO
        protected override void Parse( BigEndianReader reader )
        {
            reader.ReadByte(); // ID
            reader.ReadInt16(); // Size

            _Serial = reader.ReadUInt32();
            _GumpID = reader.ReadInt32();
            _X = reader.ReadInt32();
            _Y = reader.ReadInt32();

            int compressedEntriesLength = reader.ReadInt32() - 4;
            int decompressedEntriesLength = reader.ReadInt32();

            byte[] compressedEntries = reader.ReadBytes( compressedEntriesLength );
            byte[] decompressedEntries = new byte[ decompressedEntriesLength ];

            Ultima.Package.Zlib.Decompress( decompressedEntries, ref decompressedEntriesLength, compressedEntries, compressedEntriesLength );
            string entries = Encoding.ASCII.GetString( decompressedEntries );

            int lineCount = reader.ReadInt32();
            int compressedStringsLength = reader.ReadInt32() - 4;
            int decompressedStringsLength = reader.ReadInt32();

            byte[] compressedStrings = reader.ReadBytes( compressedStringsLength );
            byte[] decompressedStrings = new byte[ decompressedStringsLength ];

            Ultima.Package.Zlib.Decompress( decompressedStrings, ref decompressedStringsLength, compressedStrings, compressedStringsLength );
            string strings = Encoding.ASCII.GetString( decompressedStrings );

            _Text = new List<string>();

            int start = 0;

            for ( int i = 0; i < strings.Length; i++ )
            {
                if ( strings[ i ] == 0 )
                {
                    if ( i - start > 0 )
                        _Text.Add( strings.Substring( start, i - start ) );
                    else
                        _Text.Add( String.Empty );

                    start = i + 1;
                }
            }

            Parse( entries );
        }
コード例 #14
0
ファイル: GenericGump_B0.cs プロジェクト: trivialbit/SpyUO
        protected override void Parse(BigEndianReader reader)
        {
            reader.ReadByte();             // ID
            reader.ReadInt16();            // Size

            _Serial = reader.ReadUInt32();
            _GumpID = reader.ReadInt32();
            _X      = reader.ReadInt32();
            _Y      = reader.ReadInt32();

            string layout = reader.ReadAsciiString();

            int textLength = reader.ReadInt16();

            _Text = new List <string>(textLength);

            for (int i = 0; i < textLength; i++)
            {
                _Text.Add(reader.ReadAsciiString());
            }

            Parse(layout);
        }
コード例 #15
0
        private static void Method_1(BigEndianReader param1, BigEndianReader param2)
        {
            int _loc3_ = param1.ReadInt32();

            byte[] _loc4_ = new byte[_loc3_];
            param1.Read(_loc4_, 0, _loc3_);
            var _loc5_ = new Class_5(param2);

            _loc5_.Method_5(_loc4_);
            var reader = new BinaryReader(new MemoryStream(_loc4_));

            byte[] readbytes = new byte[_loc4_.Length];
            reader.Read(readbytes, 0, _loc4_.Length);
            var_6.Add(Encoding.UTF8.GetString(readbytes));
        }
コード例 #16
0
        protected override void Parse(BigEndianReader reader)
        {
            reader.ReadByte();             // ID
            reader.ReadInt16();            // Size
            reader.ReadInt16();
            _Serial = reader.ReadUInt32();
            reader.ReadInt16();
            _Hash = reader.ReadUInt32();

            _Properties = new List <QueryPropertiesProperty>();
            int cliloc;

            while ((cliloc = reader.ReadInt32()) != 0)
            {
                _Properties.Add(new QueryPropertiesProperty(cliloc, reader));
            }
        }
コード例 #17
0
ファイル: Session.cs プロジェクト: ananace/avoview
                public static BaseCommand ParseCommand(Stream stream)
                {
                    BaseCommand cmd;

                    using (var read = new BigEndianReader(stream))
                    {
                        if (read.ReadByte() != 1)
                        {
                            throw new Exception("Faulty or missing SOH");
                        }
                        if (read.ReadUInt32() != 0x41494450)
                        {
                            throw new Exception("Invalid response (wrong signature)");
                        }
                        ushort sequence       = read.ReadUInt16();
                        byte   commandID      = read.ReadByte();
                        int    responseLength = read.ReadInt32();
                        if (responseLength > 8192)
                        {
                            throw new Exception("Invalid response (too big)");
                        }

                        var commands = Assembly.GetExecutingAssembly().GetTypes()
                                       .Where(t => t.Namespace == "AvoCommLib.Protocols.AIDP" && t.GetCustomAttribute(typeof(CommandAttribute), true) != null);

                        var found = commands.FirstOrDefault(t => (t.GetCustomAttribute(typeof(CommandAttribute)) as CommandAttribute).CommandID == commandID);
                        if (found == null)
                        {
                            throw new Exception("Unknown AIDP message received.");
                        }

                        cmd = Activator.CreateInstance(found) as BaseCommand;
                        cmd.CommandSequence = sequence;
                        cmd.ReadFromReader(read);

                        if (read.ReadByte() != 13)
                        {
                            throw new Exception("Faulty or missing terminator");
                        }
                    }

                    return(cmd);
                }
コード例 #18
0
        protected override void Parse(BigEndianReader reader)
        {
            reader.ReadByte();              // ID
            reader.ReadInt16();             // Size
            reader.ReadInt16();

            _Serial = reader.ReadUInt32();
            reader.ReadInt16();
            _Hash = reader.ReadUInt32();

            _Properties = new List <QueryPropertiesProperty>();
            int cliloc;

            for (int len = 0; len < ((Data.Length - 15) / 4); len++)
            {
                cliloc = reader.ReadInt32();
                if (cliloc == 0)
                {
                    break;
                }
                _Properties.Add(new QueryPropertiesProperty(cliloc, reader));
            }
        }
コード例 #19
0
ファイル: MobileStatus.cs プロジェクト: greeduomacro/SpyUO
        protected override void Parse( BigEndianReader reader )
        {
            reader.ReadByte(); // ID
            reader.ReadInt16(); // Size

            _Serial = reader.ReadUInt32();
            _MobileName = reader.ReadAsciiString( 30 );

            _HitPoints = reader.ReadInt16();
            _MaxHitPoints = reader.ReadInt16();
            _AllowNameChange = reader.ReadByte() == 1 ? true : false;
            byte features = reader.ReadByte();
            _IsFemale = reader.ReadByte() == 1 ? true : false;
            _Strength = reader.ReadInt16();
            _Dexterity = reader.ReadInt16();
            _Intelligence = reader.ReadInt16();
            _Stamina = reader.ReadInt16();
            _MaxStamina = reader.ReadInt16();
            _Mana = reader.ReadInt16();
            _MaxMana = reader.ReadInt16();
            _Gold = reader.ReadInt32();
            _ArmorRating = reader.ReadInt16();
            _Weight = reader.ReadInt16();

            if ( ( features & 0x5 ) == 0x5 )
            {
                _MaxWeight = reader.ReadInt16();
                _Race = (MobileRace) reader.ReadByte();
            }

            if ( ( features & 0x2 ) == 0x2 )
            {
                _StatCap = reader.ReadInt16();
            }

            if ( ( features & 0x3 ) == 0x3 )
            {
                _Followers = reader.ReadByte();
                _MaxFollowers = reader.ReadByte();
            }

            if ( ( features & 0x4 ) == 0x4 )
            {
                _FireResistance = reader.ReadInt16();
                _ColdResistance = reader.ReadInt16();
                _PoisonResistance = reader.ReadInt16();
                _EnergyResistance = reader.ReadInt16();
                _Luck = reader.ReadInt16();
                _MinWeaponDamage = reader.ReadInt16();
                _MaxWeaponDamage = reader.ReadInt16();
                _TithingPoints = reader.ReadInt32();
            }

            if ( ( features & 0x6 ) == 0x6 )
            {
                _HitChanceIncrease = reader.ReadInt16();
                _SwingSpeedIncrease = reader.ReadInt16();
                _DamageChanceIncrease = reader.ReadInt16();
                _LowerReagentCost = reader.ReadInt16();
                _HitPointRegeneration = reader.ReadInt16();
                _StaminaRegeneration = reader.ReadInt16();
                _ManaRegeneration = reader.ReadInt16();
                _ReflectPhysicalDamage = reader.ReadInt16();
                _EnhancePotions = reader.ReadInt16();
                _DefenseChanceIncrease = reader.ReadInt16();
                _SpellDamageIncrease = reader.ReadInt16();
                _FasterCastRecovery = reader.ReadInt16();
                _FasterCasting = reader.ReadInt16();
                _LowerManaCost = reader.ReadInt16();
                _StrengthIncrease = reader.ReadInt16();
                _DexterityIncrease = reader.ReadInt16();
                _IntelligenceIncrease = reader.ReadInt16();
                _HitPointsIncrease = reader.ReadInt16();
                _StaminaIncrease = reader.ReadInt16();
                _ManaIncrease = reader.ReadInt16();
                _MaximumHitPointsIncrease = reader.ReadInt16();
                _MaximumStaminaIncrease = reader.ReadInt16();
                _MaximumManaIncrease = reader.ReadInt16();
            }
        }
コード例 #20
0
        protected override void Parse(BigEndianReader reader)
        {
            reader.ReadByte();  // ID
            reader.ReadInt16(); // Size

            Serial = reader.ReadUInt32();
            GumpID = reader.ReadInt32();
            X      = reader.ReadInt32();
            Y      = reader.ReadInt32();

            compressedEntriesLength   = reader.ReadInt32() - 4;
            decompressedEntriesLength = reader.ReadInt32();

            compressedEntries   = reader.ReadBytes(compressedEntriesLength);
            decompressedEntries = new byte[decompressedEntriesLength];

            if (SystemInfo.IsX64)
            {
                Ultima.Package.Zlib64.Decompress(decompressedEntries, ref decompressedEntriesLength, compressedEntries, compressedEntriesLength);
            }
            else
            {
                Ultima.Package.Zlib32.Decompress(decompressedEntries, ref decompressedEntriesLength, compressedEntries, compressedEntriesLength);
            }

            entries = Encoding.ASCII.GetString(decompressedEntries);

            lineCount = reader.ReadInt32();
            compressedStringsLength   = reader.ReadInt32() - 4;
            decompressedStringsLength = reader.ReadInt32();

            if (compressedStringsLength >= 0)
            {
                compressedStrings   = reader.ReadBytes(compressedStringsLength);
                decompressedStrings = new byte[decompressedStringsLength];

                if (SystemInfo.IsX64)
                {
                    Ultima.Package.Zlib64.Decompress(decompressedStrings, ref decompressedStringsLength, compressedStrings, compressedStringsLength);
                }
                else
                {
                    Ultima.Package.Zlib32.Decompress(decompressedStrings, ref decompressedStringsLength, compressedStrings, compressedStringsLength);
                }

                strings = Encoding.ASCII.GetString(decompressedStrings);

                Text = new List <string>();

                start = 0;

                for (int i = 0; i < strings.Length; i++)
                {
                    if (strings[i] == 0)
                    {
                        if (i - start > 0)
                        {
                            Text.Add(strings.Substring(start, i - start));
                        }
                        else
                        {
                            Text.Add(String.Empty);
                        }

                        start = i + 1;
                    }
                }
            }

            Parse(entries);
        }
コード例 #21
0
        /// <summary>
        /// Creates <see cref="TtfFileInfo"/> from <see cref="System.IO.Stream"/>.
        /// </summary>
        /// <param name="stream">Stream to create the structure. Stream will be disposed after use.</param>
        /// <returns><see cref="TtfFileInfo"/> if successful, otherwise null.</returns>
        public static TtfFileInfo FromStream(Stream stream)
        {
            try
            {
                using (var reader = new BigEndianReader(stream))
                {
                    var ttfFile = new TtfFileInfo()
                    {
                        Version = reader.ReadInt32()
                    };

                    if (ttfFile.Version != 0x74727565 && ttfFile.Version != 0x00010000)
                    {
                        return(null);
                    }

                    ttfFile.TableCount = reader.ReadInt16();
                    reader.BaseStream.Seek(6, SeekOrigin.Current);

                    for (var tableIndex = 0; tableIndex < ttfFile.TableCount; tableIndex++)
                    {
                        var tag = reader.ReadInt32();
                        reader.BaseStream.Seek(4, SeekOrigin.Current);
                        var offset = reader.ReadInt32();
                        var length = reader.ReadInt32();

                        if (tag != 0x6E616D65)
                        {
                            continue;
                        }

                        reader.BaseStream.Seek(offset, SeekOrigin.Begin);

                        var table = reader.ReadBytes(length);

                        var count        = GetInt16(table, 2);
                        var stringOffset = GetInt16(table, 4);

                        for (var record = 0; record < count; record++)
                        {
                            var nameidOffset = record * 12 + 6;
                            var platformId   = GetInt16(table, nameidOffset);
                            var nameidValue  = GetInt16(table, nameidOffset + 6);

                            if (nameidValue != 4 || platformId != 1)
                            {
                                continue;
                            }

                            var nameLength = GetInt16(table, nameidOffset + 8);
                            var nameOffset = stringOffset + GetInt16(table, nameidOffset + 10);

                            if (nameOffset < 0 || nameOffset + nameLength >= table.Length)
                            {
                                continue;
                            }

                            ttfFile.FontName = Encoding.UTF8.GetString(table, nameOffset, nameLength);
                            return(ttfFile);
                        }
                    }
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
コード例 #22
0
        public IEnumerable GetContents()
        {
            var chars        = TypeTag.ToArray();
            var activeArrays = new Stack <ArrayList>();

            using (var reader = new BigEndianReader(GetContentStream()))
            {
                for (int i = 1; i < chars.Length; i++)
                {
                    object content;
                    switch (chars[i])
                    {
                    case Osc.TypeTag.Int32:
                        content = reader.ReadInt32();
                        break;

                    case Osc.TypeTag.Float:
                        content = reader.ReadSingle();
                        break;

                    case Osc.TypeTag.String:
                    case Osc.TypeTag.Alternate:
                        content = MessageParser.ReadString(reader);
                        break;

                    case Osc.TypeTag.Blob:
                        content = MessageParser.ReadBlob(reader);
                        break;

                    case Osc.TypeTag.Int64:
                        content = reader.ReadInt64();
                        break;

                    case Osc.TypeTag.TimeTag:
                        content = MessageParser.ReadTimeTag(reader);
                        break;

                    case Osc.TypeTag.Double:
                        content = reader.ReadDouble();
                        break;

                    case Osc.TypeTag.Char:
                        content = MessageParser.ReadChar(reader);
                        break;

                    case Osc.TypeTag.True:
                        content = true;
                        break;

                    case Osc.TypeTag.False:
                        content = false;
                        break;

                    case Osc.TypeTag.Infinitum:
                        content = float.PositiveInfinity;
                        break;

                    case Osc.TypeTag.ArrayBegin:
                        activeArrays.Push(new ArrayList());
                        continue;

                    case Osc.TypeTag.ArrayEnd:
                        var array = activeArrays.Pop();
                        content = array.ToArray();
                        break;

                    default:
                    case Osc.TypeTag.Nil:
                        content = null;
                        break;
                    }

                    if (activeArrays.Count > 0)
                    {
                        var array = activeArrays.Peek();
                        array.Add(content);
                    }
                    else
                    {
                        yield return(content);
                    }
                }
            }
        }
コード例 #23
0
        protected override void Parse( BigEndianReader reader )
        {
            reader.ReadByte(); // ID
            reader.ReadInt16(); // Size
            reader.ReadInt16();

            _Serial = reader.ReadUInt32();
            reader.ReadInt16();
            _Hash = reader.ReadUInt32();

            _Properties = new List<QueryPropertiesProperty>();
            int cliloc;

            while ( ( cliloc = reader.ReadInt32() ) != 0 )
                _Properties.Add( new QueryPropertiesProperty( cliloc, reader ) );
        }
コード例 #24
0
        protected override void Parse(BigEndianReader reader)
        {
            reader.ReadByte();             // ID
            reader.ReadInt16();            // Size

            _Serial     = reader.ReadUInt32();
            _MobileName = reader.ReadAsciiString(30);

            _HitPoints       = reader.ReadInt16();
            _MaxHitPoints    = reader.ReadInt16();
            _AllowNameChange = reader.ReadByte() == 1 ? true : false;
            byte features = reader.ReadByte();

            _IsFemale     = reader.ReadByte() == 1 ? true : false;
            _Strength     = reader.ReadInt16();
            _Dexterity    = reader.ReadInt16();
            _Intelligence = reader.ReadInt16();
            _Stamina      = reader.ReadInt16();
            _MaxStamina   = reader.ReadInt16();
            _Mana         = reader.ReadInt16();
            _MaxMana      = reader.ReadInt16();
            _Gold         = reader.ReadInt32();
            _ArmorRating  = reader.ReadInt16();
            _Weight       = reader.ReadInt16();

            if ((features & 0x5) == 0x5)
            {
                _MaxWeight = reader.ReadInt16();
                _Race      = (MobileRace)reader.ReadByte();
            }

            if ((features & 0x2) == 0x2)
            {
                _StatCap = reader.ReadInt16();
            }

            if ((features & 0x3) == 0x3)
            {
                _Followers    = reader.ReadByte();
                _MaxFollowers = reader.ReadByte();
            }

            if ((features & 0x4) == 0x4)
            {
                _FireResistance   = reader.ReadInt16();
                _ColdResistance   = reader.ReadInt16();
                _PoisonResistance = reader.ReadInt16();
                _EnergyResistance = reader.ReadInt16();
                _Luck             = reader.ReadInt16();
                _MinWeaponDamage  = reader.ReadInt16();
                _MaxWeaponDamage  = reader.ReadInt16();
                _TithingPoints    = reader.ReadInt32();
            }

            if ((features & 0x6) == 0x6)
            {
                _HitChanceIncrease        = reader.ReadInt16();
                _SwingSpeedIncrease       = reader.ReadInt16();
                _DamageChanceIncrease     = reader.ReadInt16();
                _LowerReagentCost         = reader.ReadInt16();
                _HitPointRegeneration     = reader.ReadInt16();
                _StaminaRegeneration      = reader.ReadInt16();
                _ManaRegeneration         = reader.ReadInt16();
                _ReflectPhysicalDamage    = reader.ReadInt16();
                _EnhancePotions           = reader.ReadInt16();
                _DefenseChanceIncrease    = reader.ReadInt16();
                _SpellDamageIncrease      = reader.ReadInt16();
                _FasterCastRecovery       = reader.ReadInt16();
                _FasterCasting            = reader.ReadInt16();
                _LowerManaCost            = reader.ReadInt16();
                _StrengthIncrease         = reader.ReadInt16();
                _DexterityIncrease        = reader.ReadInt16();
                _IntelligenceIncrease     = reader.ReadInt16();
                _HitPointsIncrease        = reader.ReadInt16();
                _StaminaIncrease          = reader.ReadInt16();
                _ManaIncrease             = reader.ReadInt16();
                _MaximumHitPointsIncrease = reader.ReadInt16();
                _MaximumStaminaIncrease   = reader.ReadInt16();
                _MaximumManaIncrease      = reader.ReadInt16();
            }
        }
コード例 #25
0
ファイル: ShopList.cs プロジェクト: mbnunes/SpyUO
 public ShopListItem(BigEndianReader reader)
 {
     _Price = reader.ReadInt32();
     _Name  = reader.ReadAsciiString();
 }
コード例 #26
0
ファイル: NbtReader.cs プロジェクト: Jorch72/CS-INVedit
        public NbtTag Read(NbtTagType type)
        {
            int length;

            switch (type)
            {
            case NbtTagType.End:
                return(null);

            case NbtTagType.Byte:
                return(NbtTag.Create(_reader.ReadByte()));

            case NbtTagType.Short:
                return(NbtTag.Create(_reader.ReadInt16()));

            case NbtTagType.Int:
                return(NbtTag.Create(_reader.ReadInt32()));

            case NbtTagType.Long:
                return(NbtTag.Create(_reader.ReadInt64()));

            case NbtTagType.Float:
                return(NbtTag.Create(_reader.ReadSingle()));

            case NbtTagType.Double:
                return(NbtTag.Create(_reader.ReadDouble()));

            case NbtTagType.ByteArray:
                length = _reader.ReadInt32();
                return(NbtTag.Create(_reader.ReadBytes(length)));

            case NbtTagType.String:
                length = _reader.ReadInt16();
                byte[] array = _reader.ReadBytes(length);
                return(NbtTag.Create(Encoding.UTF8.GetString(array)));

            case NbtTagType.List:
                NbtTagType listType = (NbtTagType)_reader.ReadByte();
                if (listType < NbtTagType.End || listType > NbtTagType.Compound)
                {
                    throw new FormatException("'" + (int)type + "' is not a valid ListType.");
                }
                int    count = _reader.ReadInt32();
                NbtTag list  = NbtTag.CreateList(listType);
                for (int i = 0; i < count; i++)
                {
                    list.Add(Read(listType));
                }
                return(list);

            case NbtTagType.Compound:
                NbtTag compound = NbtTag.CreateCompound();
                while (true)
                {
                    string name;
                    NbtTag item = Read(out name);
                    if (item == null)
                    {
                        return(compound);
                    }
                    compound.Add(name, item);
                }

            case NbtTagType.IntArray:
                length = _reader.ReadInt32();
                int[] intArray = new int[length];
                for (int i = 0; i < length; i++)
                {
                    intArray[i] = _reader.ReadInt32();
                }
                return(NbtTag.Create(intArray));

            default:
                throw new FormatException("'" + (int)type + "' is not a valid TagType.");
            }
        }
コード例 #27
0
ファイル: ArcCPK.cs プロジェクト: Casidi/GARbro
        public List<TableRow> DeserializeUTFChunk(byte[] chunk)
        {
            m_chunk = chunk;
            if (!Binary.AsciiEqual (m_chunk, 0, "@UTF"))
                throw new InvalidFormatException();
            var chunk_length = BigEndian.ToInt32 (m_chunk, 4);
            using (var mem = new MemoryStream (m_chunk, 8, chunk_length))
            using (var input = new BigEndianReader (mem))
            {
                int rows_offset     = input.ReadInt32();
                int strings_offset  = input.ReadInt32() + 8;
                int data_offset     = input.ReadInt32() + 8;
                input.Skip (4);
                int column_count    = input.ReadInt16();
                int row_length      = input.ReadInt16();
                int row_count       = input.ReadInt32();

                var columns = new List<Column> (column_count);
                for (int i = 0; i < column_count; ++i)
                {
                    byte flags = input.ReadByte();
                    if (0 == flags)
                    {
                        input.Skip (3);
                        flags = input.ReadByte();
                    }
                    int name_offset = strings_offset + input.ReadInt32();
                    var column = new Column
                    {
                        Flags = (TableFlags)flags,
                        Name  = ReadString (name_offset),
                    };
                    columns.Add (column);
                }

                var table = new List<TableRow> (row_count);
                int next_offset = rows_offset;
                for (int i = 0; i < row_count; ++i)
                {
                    input.Position = next_offset;
                    next_offset += row_length;
                    var row = new TableRow (column_count);
                    table.Add (row);
                    foreach (var column in columns)
                    {
                        var storage = column.Flags & TableFlags.StorageMask;
                        if (TableFlags.StorageNone == storage
                            || TableFlags.StorageZero == storage
                            || TableFlags.StorageConstant == storage)
                            continue;
                        switch (column.Flags & TableFlags.TypeMask)
                        {
                        case TableFlags.TypeByte:
                            row[column.Name] = (int)input.ReadByte();
                            break;

                        case TableFlags.TypeSByte:
                            row[column.Name] = (int)input.ReadSByte();
                            break;

                        case TableFlags.TypeUInt16:
                            row[column.Name] = (int)input.ReadUInt16();
                            break;

                        case TableFlags.TypeInt16:
                            row[column.Name] = (int)input.ReadInt16();
                            break;

                        case TableFlags.TypeUInt32:
                        case TableFlags.TypeInt32:
                            row[column.Name] = input.ReadInt32();
                            break;

                        case TableFlags.TypeUInt64:
                        case TableFlags.TypeInt64:
                            row[column.Name] = input.ReadInt64();
                            break;

                        case TableFlags.TypeFloat32:
                            row[column.Name] = input.ReadSingle();
                            break;

                        case TableFlags.TypeString:
                            {
                                int offset = strings_offset + input.ReadInt32();
                                row[column.Name] = ReadString (offset);
                                break;
                            }

                        case TableFlags.TypeData:
                            {
                                int offset = data_offset + input.ReadInt32();
                                int length = input.ReadInt32();
                                row[column.Name] = m_chunk.Skip (offset).Take (length).ToArray();
                                break;
                            }

                        default:
                            throw new NotSupportedException();
                        }
                    }
                }
                return table;
            }
        }
コード例 #28
0
ファイル: ShopList.cs プロジェクト: greeduomacro/SpyUO
 public ShopListItem( BigEndianReader reader )
 {
     _Price = reader.ReadInt32();
     _Name = reader.ReadAsciiString();
 }
コード例 #29
0
ファイル: Buffs.cs プロジェクト: greeduomacro/SpyUO
 public BuffItem( BigEndianReader reader )
 {
     _SourceType = (BuffSourceType) reader.ReadInt16();
     reader.ReadInt16(); // unknown
     _IconID = reader.ReadInt16();
     _QueueIndex = reader.ReadInt16();
     reader.ReadInt32(); // unknown
     _Duration = reader.ReadInt16();
     reader.ReadBytes( 3 ); // unknown
     _TitleCliloc = reader.ReadInt32();
     _SecondaryCliloc = reader.ReadInt32();
     _TernaryCliloc = reader.ReadInt32();
     _TitleArguments = reader.ReadUnicodeString();
     _SecondaryArguments = reader.ReadUnicodeString();
     _TernaryArguments = reader.ReadUnicodeString();
 }