Exemplo n.º 1
0
            public static AiInfo ReadFrom(PrimitiveReader reader)
            {
                AiInfo info = new AiInfo();

                info.Unknown = reader.ReadUInt16();
                ushort stringsCount = reader.ReadUInt16();

                System.Diagnostics.Debugger.Break();
                info.Unknown2 = reader.ReadUInt32();
                List <string> resources = new List <string>(stringsCount);

                for (int i = 0; i < stringsCount; i++)
                {
                    resources.Add(Utils.ReadUInt32LengthPrefixedString(reader));
                }
                info.Resources = resources;
                info.Unknown3  = reader.ReadBytes(6);
                AiData[] data = new AiData[8];
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = AiData.ReadFrom(reader);
                }
                info.Data = data;

                info.Unknown4 = reader.ReadBytes(104);
                AiTimer[] timers = new AiTimer[8];
                for (int i = 0; i < timers.Length; i++)
                {
                    timers[i] = AiTimer.ReadFrom(reader);
                }
                info.Timers      = timers;
                info.SharedGoals = reader.ReadUInt32Array(256);
                info.Unknown5    = reader.ReadUInt32Array(1024);
                return(info);
            }
Exemplo n.º 2
0
            public static AiRuleData ReadFrom(PrimitiveReader reader)
            {
                AiRuleData data = new AiRuleData();

                data.Type    = reader.ReadUInt32();
                data.Id      = reader.ReadUInt16();
                data.Unknown = reader.ReadUInt16();
                data.Param1  = reader.ReadUInt32();
                data.Param2  = reader.ReadUInt32();
                data.Param2  = reader.ReadUInt32();
                data.Param4  = reader.ReadUInt32();
                return(data);
            }
Exemplo n.º 3
0
        public async ValueTask Read(PrimitiveReader primitiveReader, CancellationToken cancellationToken)
        {
            BoolValue = await primitiveReader.ReadBool(cancellationToken);

            ByteValue = await primitiveReader.ReadByte(cancellationToken);

            SByteValue = await primitiveReader.ReadSByte(cancellationToken);

            ShortValue = await primitiveReader.ReadInt16(cancellationToken);

            UShortValue = await primitiveReader.ReadUInt16(cancellationToken);

            IntValue = await primitiveReader.ReadInt32(cancellationToken);

            UIntValue = await primitiveReader.ReadUInt32(cancellationToken);

            LongValue = await primitiveReader.ReadInt64(cancellationToken);

            ULongValue = await primitiveReader.ReadUInt64(cancellationToken);

            FloatValue = await primitiveReader.ReadSingle(cancellationToken);

            DoubleValue = await primitiveReader.ReadDouble(cancellationToken);

            StringValue = await primitiveReader.ReadString(cancellationToken);

            deserializationCounter++;
        }
Exemplo n.º 4
0
        public void ShouldReadAndWriteLimits()
        {
            var stream = new MemoryStream();

            using (var writer = new PrimitiveWriter(stream))
            {
                writer.Write(byte.MinValue);
                writer.Write(byte.MaxValue);
                writer.Write(sbyte.MinValue);
                writer.Write(sbyte.MaxValue);
                writer.Write(short.MinValue);
                writer.Write(short.MaxValue);
                writer.Write(ushort.MinValue);
                writer.Write(ushort.MaxValue);
                writer.Write(int.MinValue);
                writer.Write(int.MaxValue);
                writer.Write(uint.MinValue);
                writer.Write(uint.MaxValue);
                writer.Write(long.MinValue);
                writer.Write(long.MaxValue);
                writer.Write(ulong.MinValue);
                writer.Write(ulong.MaxValue);
            }
            var position = stream.Position;

            stream.Seek(0, SeekOrigin.Begin);
            using (var reader = new PrimitiveReader(stream))
            {
                Assert.AreEqual(byte.MinValue, reader.ReadByte());
                Assert.AreEqual(byte.MaxValue, reader.ReadByte());
                Assert.AreEqual(sbyte.MinValue, reader.ReadSByte());
                Assert.AreEqual(sbyte.MaxValue, reader.ReadSByte());
                Assert.AreEqual(short.MinValue, reader.ReadInt16());
                Assert.AreEqual(short.MaxValue, reader.ReadInt16());
                Assert.AreEqual(ushort.MinValue, reader.ReadUInt16());
                Assert.AreEqual(ushort.MaxValue, reader.ReadUInt16());
                Assert.AreEqual(int.MinValue, reader.ReadInt32());
                Assert.AreEqual(int.MaxValue, reader.ReadInt32());
                Assert.AreEqual(uint.MinValue, reader.ReadUInt32());
                Assert.AreEqual(uint.MaxValue, reader.ReadUInt32());
                Assert.AreEqual(long.MinValue, reader.ReadInt64());
                Assert.AreEqual(long.MaxValue, reader.ReadInt64());
                Assert.AreEqual(ulong.MinValue, reader.ReadUInt64());
                Assert.AreEqual(ulong.MaxValue, reader.ReadUInt64());
            }
            Assert.AreEqual(position, stream.Position, StreamCorruptedMessage);
        }
Exemplo n.º 5
0
            public static AiData ReadFrom(PrimitiveReader reader)
            {
                AiData data = new AiData();

                data.Unknown      = reader.ReadUInt32();
                data.Unknown2     = reader.ReadUInt32();
                data.MaximumRules = reader.ReadUInt16();
                ushort rulesCount = reader.ReadUInt16();

                data.Unknown3 = reader.ReadUInt32();
                List <AiRule> rules = new List <AiRule>(rulesCount);

                for (int i = 0; i < rulesCount; i++)
                {
                    rules.Add(AiRule.ReadFrom(reader));
                }
                data.Rules = rules;
                return(data);
            }
Exemplo n.º 6
0
            public static AiRule ReadFrom(PrimitiveReader reader)
            {
                AiRule rule = new AiRule();

                rule.Unknown          = reader.ReadBytes(8);
                rule.FactsCount       = reader.ReadUInt8();
                rule.FactsCountAction = reader.ReadUInt8();
                rule.Unknown2         = reader.ReadUInt16();
                AiRuleData[] rulesData = new AiRuleData[8];
                for (int i = 0; i < rulesData.Length; i++)
                {
                    rulesData[i] = AiRuleData.ReadFrom(reader);
                }
                return(rule);
            }
 public void ShouldReadAndWriteLimits()
 {
     var stream = new MemoryStream();
     using(var writer = new PrimitiveWriter(stream))
     {
         writer.Write(byte.MinValue);
         writer.Write(byte.MaxValue);
         writer.Write(sbyte.MinValue);
         writer.Write(sbyte.MaxValue);
         writer.Write(short.MinValue);
         writer.Write(short.MaxValue);
         writer.Write(ushort.MinValue);
         writer.Write(ushort.MaxValue);
         writer.Write(int.MinValue);
         writer.Write(int.MaxValue);
         writer.Write(uint.MinValue);
         writer.Write(uint.MaxValue);
         writer.Write(long.MinValue);
         writer.Write(long.MaxValue);
         writer.Write(ulong.MinValue);
         writer.Write(ulong.MaxValue);
     }
     var position = stream.Position;
     stream.Seek(0, SeekOrigin.Begin);
     using(var reader = new PrimitiveReader(stream))
     {
         Assert.AreEqual(byte.MinValue, reader.ReadByte());
         Assert.AreEqual(byte.MaxValue, reader.ReadByte());
         Assert.AreEqual(sbyte.MinValue, reader.ReadSByte());
         Assert.AreEqual(sbyte.MaxValue, reader.ReadSByte());
         Assert.AreEqual(short.MinValue, reader.ReadInt16());
         Assert.AreEqual(short.MaxValue, reader.ReadInt16());
         Assert.AreEqual(ushort.MinValue, reader.ReadUInt16());
         Assert.AreEqual(ushort.MaxValue, reader.ReadUInt16());
         Assert.AreEqual(int.MinValue, reader.ReadInt32());
         Assert.AreEqual(int.MaxValue, reader.ReadInt32());
         Assert.AreEqual(uint.MinValue, reader.ReadUInt32());
         Assert.AreEqual(uint.MaxValue, reader.ReadUInt32());
         Assert.AreEqual(long.MinValue, reader.ReadInt64());
         Assert.AreEqual(long.MaxValue, reader.ReadInt64());
         Assert.AreEqual(ulong.MinValue, reader.ReadUInt64());
         Assert.AreEqual(ulong.MaxValue, reader.ReadUInt64());
     }
     Assert.AreEqual(position, stream.Position, StreamCorruptedMessage);
 }
Exemplo n.º 8
0
        protected string ReadNullTerminatedEncodedString( PrimitiveReader reader, ref int bytesLeft )
        {
            byte encoding = reader.ReadByte(); bytesLeft--;
            byte[] stringData = null;
            Encoding textEncoding = null;
            int index = 0;

            if( encoding == 0 ) {
                textEncoding = Encoding.GetEncoding( 28591 );
                stringData = new byte[bytesLeft];

                while( bytesLeft > 0 ) {
                    byte part = reader.ReadByte();
                    if( part == 0x00 ) break;

                    stringData[index++] = part; bytesLeft--;
                }
            } else if( encoding == 1 ) {
                ushort bom = reader.ReadUInt16(); bytesLeft -= 2;
                stringData = new byte[bytesLeft];

                if( bom == 0xFEFF ) {
                    textEncoding = Encoding.BigEndianUnicode;
                } else if( bom == 0xFFFE ) {
                    textEncoding = Encoding.Unicode;
                } else {
                    throw new InvalidDataException( "Invalid bom: " + bom );
                }

                while( bytesLeft > 0 ) {
                    byte part1 = reader.ReadByte();
                    byte part2 = reader.ReadByte();
                    if( part1 == 0x00 && part2 == 0x00 ) break;

                    stringData[index++] = part1; bytesLeft--;
                    stringData[index++] = part2; bytesLeft--;
                }
            } else {
                throw new NotSupportedException( "Unsupported encoding " + encoding );
            }
            return textEncoding.GetString( stringData, 0, index );
        }
Exemplo n.º 9
0
        void ProcessFormatChunk( RiffChunkHeader chunk, PrimitiveReader reader )
        {
            byte[] chunkData = reader.ReadBytes( chunk.DataSize );
            Stream source = reader.stream;
            reader.stream = new MemoryStream( chunkData );
            int audioFormat = reader.ReadUInt16();
            Metadata["WAVE audio format"] = ((AudioFormat)audioFormat).ToString();
            int channels = reader.ReadInt16();
            Metadata[MetadataKeys.Channels] = channels.ToString();
            int sampleRate = reader.ReadInt32();
            Metadata[MetadataKeys.SampleRate] = sampleRate.ToString();
            int byteRate = reader.ReadInt32();
            int blockAlign = reader.ReadInt16();
            int bitsPerSample = reader.ReadInt16();
            Metadata[MetadataKeys.BitsPerSample] = bitsPerSample.ToString();
            int extraInfoSize = 0;
            #pragma warning disable 0618
            // Usually, only very old wave files don't have this
            // field included. (WaveFormat structure, not WaveFormatEx structure)
            // Supress the warning because it's a MemoryStream.
            if( reader.Position != reader.Length ) {
                extraInfoSize = reader.ReadUInt16();
            }
            #pragma warning restore 0618

            this.freq = sampleRate;
            transformer = EmptyTransformer.Instance;
            this.channels = channels;
            this.bitsPerSample = bitsPerSample;
            codecBitsPerSample = bitsPerSample;

            switch( (AudioFormat)audioFormat ) {
                case AudioFormat.Pcm: // No compression.
                    if( bitsPerSample == 16 && reader.BigEndian ) {
                        transformer = BigEndian16BitTo16BitTransformer.Instance;
                    }
                    break;

                case AudioFormat.IeeeFloat:
                    if( bitsPerSample == 32 ) {
                        this.bitsPerSample = 16;
                    } else if( bitsPerSample == 64 ) {
                        this.bitsPerSample = 16;
                    }
                    throw new NotSupportedException();
                    break;

                case AudioFormat.ALaw:
                    transformer = ALawTransformer.Instance;
                    this.bitsPerSample = 16;
                    break;

                case AudioFormat.MuLaw:
                    transformer = MuLawTransformer.Instance;
                    this.bitsPerSample = 16;
                    break;

                    // TODO: Properly test this transformer, but I can't seem to find any wave files that use this format.
                case AudioFormat.DialogicOkiAdpcm:
                    transformer = DialogicAdpcmTransformer.Instance;
                    this.bitsPerSample = 16;
                    break;

                    // TODO: Test this transformer too.
                case AudioFormat.ImaAdpcm:
                    transformer = ImaAdpcmTransformer.Instance;
                    this.bitsPerSample = 16;
                    break;

                case AudioFormat.Extensible:
                    ushort validBitsPerSample = reader.ReadUInt16();
                    uint channelMask = reader.ReadUInt32();
                    Guid subFormat = reader.ReadGuid();
                    Metadata["extensible guid"] = subFormat.ToString();
                    if( subFormat == PcmGuid ) {
                    } else if( subFormat == IeeeFloatGuid ) {
                        throw new NotSupportedException( "Ieee float sub format not supported." );
                    } else if( subFormat == DrmGuid ) {
                        throw new NotSupportedException( "Drm sub format not supported." );
                    } else if( subFormat == AlawGuid ) {
                        transformer = ALawTransformer.Instance;
                        this.bitsPerSample = 16;
                    } else if( subFormat == MulawGuid ) {
                        transformer = MuLawTransformer.Instance;
                        this.bitsPerSample = 16;
                    } else if( subFormat == AdpcmGuid ) {
                        throw new NotSupportedException( "Adpcm sub format not supported." );
                    } else if( subFormat == MpegGuid ) {
                        throw new NotSupportedException( "Mpeg sub format not supported." );
                    } else {
                        throw new NotSupportedException( "Unsupported sub format: " + subFormat );
                    }
                    break;

                default:
                    throw new NotSupportedException( "Unsupported audio format: " + (AudioFormat)audioFormat );
            }
            reader.stream = source;
        }
Exemplo n.º 10
0
        public IEnumerable<AudioChunk> StreamData( Stream source )
        {
            PrimitiveReader reader = new PrimitiveReader( source );
            reader.BigEndian = true;
            while( true ) {

                #region Frame header

                FlacBitReader bitReader = new FlacBitReader( reader );
                bitReader.BigEndian = true;
                int syncCode = bitReader.ReadBits( 14 );
                if( syncCode != 0x3FFE ) {
                    throw new InvalidDataException( "Invalid synchronisation code." );
                }
                int reserved = bitReader.ReadBit();
                bool variableBlockSize = bitReader.ReadBit() != 0;
                int blockSizeFlags = bitReader.ReadBits( 4 );
                int sampleRateFlags = bitReader.ReadBits( 4 );
                int channelAssignment = bitReader.ReadBits( 4 );
                int sampleSizeFlags = bitReader.ReadBits( 3 );
                if( bitReader.ReadBit() != 0 )
                    throw new InvalidDataException( "Reserved bit is not 0." );

                byte[] numberData = ReadRawUTF8Char( reader );
                /*int frameNumber = numberData[0];
                for( int i = 1; i < numberData.Length; i++ ) {
                    frameNumber <<= 6;
                    frameNumber |= numberData[i];
                }
                Console.WriteLine( frameNumber );*/

                int blockSize = 0;
                if( blockSizeFlags == 0x0 ) {
                    throw new InvalidDataException( "0 is reserved for block sizes." );
                } else if( blockSizeFlags == 0x1 ) {
                    blockSize = 192;
                } else if( blockSizeFlags >= 0x2 && blockSizeFlags <= 0x5 ) {
                    blockSize = 576 * ( 1 << ( blockSizeFlags - 2 ) ); // 2^x.
                } else if( blockSizeFlags == 0x6 ) {
                    blockSize = reader.ReadByte() + 1;
                } else if( blockSizeFlags == 0x7 ) {
                    blockSize = reader.ReadUInt16() + 1;
                } else {
                    blockSize = 256 * ( 1 << ( blockSizeFlags - 8 ) ); // 2^x.
                }

                int sampleRate = 0;
                if( sampleRateFlags == 0x0 ) {
                    sampleRate = metaSampleRate;
                } else if( sampleRateFlags >= 0x01 && sampleRateFlags <= 0xB ) {
                    sampleRate = sampleRates[sampleRateFlags];
                } else if( sampleRateFlags == 0xC ) {
                    sampleRate = reader.ReadByte();
                } else if( sampleRateFlags == 0xD ) {
                    sampleRate = reader.ReadUInt16();
                } else if( sampleRateFlags == 0xE ) {
                    sampleRate = reader.ReadUInt16() * 10;
                } else {
                    throw new InvalidDataException( "Invalid sample rate flag." );
                }

                int bitsPerSample;
                if( sampleSizeFlags == 0 ) {
                    bitsPerSample = metaBitsPerSample;
                } else if( sampleSizeFlags == 0x3 || sampleRateFlags == 0x7 ) {
                    throw new InvalidDataException( "Sample size is reserved." );
                } else {
                    bitsPerSample = bitSampleSizes[sampleSizeFlags];
                }

                int channelsCount;
                ChannelAssignment soundAssignment = (ChannelAssignment)channelAssignment;
                if( channelAssignment < 0x08 ) {
                    channelsCount = channelAssignment + 1;
                } else if( channelAssignment < 0x0B ) {
                    channelsCount = 2;
                } else {
                    throw new InvalidDataException( "Channel assignment values > 1010 are reserved." );
                }
                byte crc8 = reader.ReadByte();

                #endregion

                #region Subframe

                int[][] channelsData = new int[channelsCount][];
                for( int i = 0; i < channelsCount; i++ ) {
                    if( bitReader.ReadBit() != 0 ) {
                        throw new InvalidDataException( "Padding bit should be 0." );
                    }
                    int[] channelData = null;
                    int subframeType = bitReader.ReadBits( 6 );
                    bool wastedBitsPerSampleFlag = bitReader.ReadBit() != 0;

                    int adjustedBitsPerSample = bitsPerSample;
                    switch( soundAssignment ) {
                        case ChannelAssignment.LeftSide:
                            if( i == 1 ) adjustedBitsPerSample++;
                            break;

                        case ChannelAssignment.RightSide:
                            if( i == 0 ) adjustedBitsPerSample++;
                            break;

                        case ChannelAssignment.MidSide:
                            if( i == 1 ) adjustedBitsPerSample++;
                            break;
                    }

                    int wastedBitsPerSample = 0;
                    if( wastedBitsPerSampleFlag ) {
                        wastedBitsPerSample = 1 + bitReader.ReadUnary();
                    }
                    if( subframeType == 0x00 ) {
                        channelData = ProcessConstantSubframe( bitReader, adjustedBitsPerSample, blockSize );
                    } else if( subframeType == 0x01 ) {
                        channelData = ProcessVerbatimSubframe( bitReader, adjustedBitsPerSample, blockSize );
                    } else {
                        if( ( subframeType & 0x20 ) != 0 ) {
                            int order = ( subframeType & 0x1F ) + 1;
                            channelData = ProcessLpcSubframe( bitReader, adjustedBitsPerSample, order, blockSize );
                        } else if( ( subframeType & 0x08 ) != 0 ) {
                            int order = subframeType & 0x07;
                            channelData = ProcessFixedSubframe( bitReader, adjustedBitsPerSample, order, blockSize );
                        }
                    }
                    channelsData[i] = channelData;
                }
                bitReader.SkipRemainingBits();

                #endregion

                // Transform the samples into left right
                switch( soundAssignment ) {
                    case ChannelAssignment.LeftSide:
                        TransformSamplesLS( channelsData[0], channelsData[1] );
                        break;

                    case ChannelAssignment.RightSide:
                        TransformSamplesSR( channelsData[0], channelsData[1] );
                        break;

                    case ChannelAssignment.MidSide:
                        TransformSamplesMS( channelsData[0], channelsData[1] );
                        break;
                }

                int bytesPerSample = (int)Math.Ceiling( bitsPerSample / 8.0 );
                byte[] data = new byte[channelsCount * bytesPerSample * blockSize];
                bool use16Bits = bitsPerSample <= 16;
                bool use8Bits = bitsPerSample <= 8;
                int offset = 0;
                for( int i = 0; i < blockSize; i++ ) {
                    for( int ch = 0; ch < channelsCount; ch++ ) {
                        int[] channelData = channelsData[ch];
                        if( use16Bits ) {
                            ushort sample = (ushort)channelData[i];
                            data[offset++] = (byte)( sample );
                            data[offset++] = (byte)( sample >> 8 );
                        } else if( use8Bits ) {
                            data[offset++] = (byte)channelData[i];
                        }
                    }
                }

                // Read frame footer
                ushort crc16 = reader.ReadUInt16();

                AudioChunk chunk = new AudioChunk();
                chunk.Frequency = sampleRate;
                chunk.Channels = channelsCount;
                chunk.BitsPerSample = bitsPerSample;
                chunk.Data = data;
                yield return chunk;
            }
        }
Exemplo n.º 11
0
 void ProcessMetadataSeekTable( int len, PrimitiveReader reader )
 {
     int pointCount = len / 18;
     for( int i = 0; i < pointCount; i++ ) {
         ulong firstSampleNumber = reader.ReadUInt64();
         ulong targetFrameOffset = reader.ReadUInt64();
         ushort numberSamples = reader.ReadUInt16();
         bool isPlaceholder = firstSampleNumber == ulong.MaxValue;
     }
 }
Exemplo n.º 12
0
        void ReadV3ExtendedHeader( PrimitiveReader reader, ref int len )
        {
            int extendedDataSize = reader.ReadInt32(); len -= ( 4 + extendedDataSize );
            ushort extendedFlags = reader.ReadUInt16();
            int paddingSize = reader.ReadInt32();
            extendedDataSize -= 6;

            if( ( extendedFlags & 0x8000 ) != 0 ) {
                uint crc32 = reader.ReadUInt32();
                extendedDataSize -= 4;
            }
            reader.SkipData( extendedDataSize );
        }
Exemplo n.º 13
0
        bool ReadV3Frame( PrimitiveReader reader, ref int len )
        {
            string frameId = reader.ReadASCIIString( 4 ); len -= 4;
            if( frameId == "\0\0\0\0" ) return true;

            int frameDataSize = reader.ReadInt32();
            ushort frameFlags = reader.ReadUInt16(); len -= ( frameDataSize + 4 + 2 );

            bool encryption = ( frameFlags & 0x80 ) != 0;
            bool compression = ( frameFlags & 0x40 ) != 0;
            bool groupingInfo = ( frameFlags & 0x20 ) != 0;
            if( groupingInfo ) {
                byte groupIdentifier = reader.ReadByte();
            }
            if( encryption || compression ) throw new NotImplementedException( "encryption and/or compression support is not yet implemented." );
            Console.WriteLine( "reading frame: " + frameId );
            if( v3TagConstructors == null ) {
                v3TagConstructors = ID3v2Tag.Makev3TagConstructors();
            }

            Func<ID3v2Tag> constructor;
            if( v3TagConstructors.TryGetValue( frameId, out constructor ) ) {
                ID3v2Tag tag = constructor();
                tag.Identifier = frameId;
                tag.DataSize = frameDataSize;
                tag.Read( container, reader );
            } else {
                Console.WriteLine( "   skipping frame." );
                reader.SkipData( frameDataSize );
            }
            return false;
        }
Exemplo n.º 14
0
        public void ReadData(string path)
        {
            PrimitiveReader reader = new PrimitiveReader(path);
            SaveGameFile    file   = new SaveGameFile();

            file.Version  = reader.ReadASCIIString(8);
            file.Unknown1 = reader.ReadFloat32();

            bool aiDataIncluded = reader.ReadUInt32() != 0;

            if (aiDataIncluded)
            {
                file.AiInfo2 = AiInfo.ReadFrom(reader);
            }
            file.Unknown2   = reader.ReadUInt32();
            file.GameSpeed1 = reader.ReadUInt32();
            file.Unknown3   = reader.ReadUInt32();
            file.GameSpeed2 = reader.ReadUInt32();
            file.Unknown4   = reader.ReadFloat32();
            file.Unknown5   = reader.ReadUInt32();
            file.Unknown6   = reader.ReadBytes(17);
            file.RecordedGamePlayerNumber = reader.ReadUInt16();
            //System.Diagnostics.Debugger.Break();
            file.PlayersCount = reader.ReadUInt8();
            file.Unknown7     = reader.ReadUInt32();
            file.Unknown8     = reader.ReadBytes(12);
            file.Unknown9     = reader.ReadBytes(14);
            file.Unknown10    = reader.ReadUInt32Array(8);

            //System.Diagnostics.Debugger.Break();

            reader.SeekAbsolute(126);
            int mapWidth  = reader.ReadInt32();
            int mapLength = reader.ReadInt32();

            uint unknownDataCount = reader.ReadUInt32();

            ushort unknown2 = reader.ReadUInt16();

            SaveGameMap map = SaveGameMap.ReadFrom(reader, mapWidth, mapLength);


            /*int unknownIntsArrayCount = reader.ReadInt32();
             * uint[][] unknowns = new uint[unknownIntsArrayCount][];
             * for( int i = 0; i < unknowns.Length; i++ ) {
             *      int intsCount = reader.ReadInt32() - 1;
             *      if( intsCount < 0 ) throw new Exception();
             *      unknowns[i] = reader.ReadUInt32Array( intsCount );
             * }*/
            reader.SeekAbsolute(29132);

            int mapWidth2  = reader.ReadInt32();
            int mapLength2 = reader.ReadInt32();

            uint[] unknownMap2 = reader.ReadUInt32Array(mapWidth2 * mapLength2);

            //byte unknownIntsCount1 = reader.ReadUInt8();
            //uint[] unknownInts = reader.ReadUInt32Array( unknownIntsCount1 );

            reader.SeekAbsolute(88779);
            SavePlayerInfo f = SavePlayerInfo.ReadFrom(reader, 2);

            System.Diagnostics.Debugger.Break();
        }
Exemplo n.º 15
0
            public static SavePlayerInfo ReadFrom(PrimitiveReader reader, int pCount)
            {
                SavePlayerInfo p = new SavePlayerInfo();

                byte[] diplomacyFrom = reader.ReadBytes(pCount);
                uint[] diplomacyTo   = reader.ReadUInt32Array(9);
                uint   unknown1      = reader.ReadUInt32();
                byte   unknown2      = reader.ReadUInt8();
                string name          = Utils.ReadUInt16LengthPrefixedString(reader);
                byte   unknown3      = reader.ReadUInt8();
                int    floatsCount   = reader.ReadInt32();
                byte   unknown4      = reader.ReadUInt8();

                float[]   civHeader = reader.ReadFloat32Array(floatsCount);
                FloatTest t         = new FloatTest(civHeader);

                byte unknown5 = reader.ReadUInt8();

                float[] unknown6     = reader.ReadFloat32Array(2);
                byte[]  unknown7     = reader.ReadBytes(9);
                byte    civilization = reader.ReadUInt8();

                byte[] unknown8 = reader.ReadBytes(3);

                byte colour = reader.ReadUInt8();

                byte[] unknown9  = reader.ReadBytes(4183);
                float  unknown10 = reader.ReadFloat32();

                int    researchCount = reader.ReadInt32();
                ushort unknown11     = reader.ReadUInt16();

                ResearchStat[] stats = new ResearchStat[researchCount];
                for (int i = 0; i < stats.Length; i++)
                {
                    stats[i] = ResearchStat.ReadFrom(reader);
                }

                Console.WriteLine("LAST KNOWN POS:" + reader.Position);


                reader.SeekAbsolute(128358);

                int masterObjectsCount = reader.ReadInt32();

                bool[] objectExistsFlags = new bool[masterObjectsCount];
                for (int i = 0; i < objectExistsFlags.Length; i++)
                {
                    objectExistsFlags[i] = reader.ReadUInt32() != 0;
                }
                //System.Diagnostics.Debugger.Break();
                ushort unknownObjects = reader.ReadUInt16();

                Console.WriteLine("BEGIN READ OBJECTS.." + reader.Position);

                MasterObject[] masterObjects = new MasterObject[masterObjectsCount];
                for (int i = 0; i < masterObjects.Length; i++)
                {
                    if (objectExistsFlags[i])
                    {
                        masterObjects[i] = MasterObject.ReadFrom(reader, i);
                    }
                }

                System.Diagnostics.Debugger.Break();
                return(p);
            }
Exemplo n.º 16
0
                public static MasterObject ReadFrom(PrimitiveReader reader, int i)
                {
                    MasterObject value = new MasterObject();

                    byte objectType = reader.ReadUInt8();

                    value.ObjectType = objectType;
                    value.UnitId     = reader.ReadUInt16();
                    value.Unknown1   = reader.ReadUInt16();
                    value.Unknown2   = reader.ReadUInt16();
                    value.UnitClass  = reader.ReadUInt16();
                    value.Unknown3   = reader.ReadBytes(6);

                    const int breakId = -1;

                    switch (objectType)
                    {
                    default:
                        throw new NotImplementedException("Unsupported object type: " + objectType);

                    case 10:                             // Basic units
                    {
                        short  hitpoints        = reader.ReadInt16();
                        float  lengthOfSight    = reader.ReadFloat32();
                        byte   garrisonCapacity = reader.ReadUInt8();
                        float  sizeRadiusX      = reader.ReadFloat32();
                        float  sizeRadiusY      = reader.ReadFloat32();
                        ushort resourceCarriage = reader.ReadUInt16();
                        float  resourceAmount   = reader.ReadFloat32();

                        // Constants?
                        ushort unknown12 = reader.ReadUInt16();
                        byte   unknown13 = reader.ReadUInt8();
                    }
                    break;

                    case 25:                             // Same as 20, only DOPL uses this.
                    case 20:                             // Extended basic units (FLAGX)
                    {
                        value.UnitData = reader.ReadBytes(28);
                        PrimitiveReader r2               = new PrimitiveReader(value.UnitData);
                        short           hitpoints        = r2.ReadInt16();
                        float           lengthOfSight    = r2.ReadFloat32();
                        byte            garrisonCapacity = r2.ReadUInt8();
                        float           sizeRadiusX      = r2.ReadFloat32();
                        float           sizeRadiusY      = r2.ReadFloat32();

                        ulong  unknown1 = r2.ReadUInt64();
                        ushort unknown2 = r2.ReadUInt16();

                        if (unknown1 != 0 || unknown2 != 0)
                        {
                            File.WriteAllBytes("unitextended.bin", value.UnitData);
                            System.Diagnostics.Debugger.Break();
                        }

                        // Constants?
                        ushort unknown12 = r2.ReadUInt16();
                        byte   unknown13 = r2.ReadUInt8();

                        if (i == breakId)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
                    } break;

                    case 30:                             // Dead units
                    {
                        value.UnitData = reader.ReadBytes(32);
                        if (i == breakId)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
                    }
                    break;

                    case 60:                             // Projectiles
                    {
                        short hitpoints        = reader.ReadInt16();
                        float lengthOfSight    = reader.ReadFloat32();
                        byte  garrisonCapacity = reader.ReadUInt8();
                        float sizeRadiusX      = reader.ReadFloat32();
                        float sizeRadiusY      = reader.ReadFloat32();
                        short resourceCarriage = reader.ReadInt16();
                        float unknownFloat     = reader.ReadFloat32();
                        byte  unknown2         = reader.ReadUInt8();
                        float movementRate     = reader.ReadFloat32();

                        float extraRotationSpeed = reader.ReadFloat32();
                        float searchRadius       = reader.ReadFloat32();
                        float workRate           = reader.ReadFloat32();
                        short unknown4           = reader.ReadInt16();

                        ushort           attackStrengthsCount = reader.ReadUInt16();
                        AttackStrength[] strengths            = new AttackStrength[attackStrengthsCount];
                        for (int j = 0; j < strengths.Length; j++)
                        {
                            strengths[j] = AttackStrength.ReadFrom(reader);
                        }

                        ushort           armourStrengthsCount = reader.ReadUInt16();
                        ArmourStrength[] astrengths           = new ArmourStrength[armourStrengthsCount];
                        for (int j = 0; j < astrengths.Length; j++)
                        {
                            astrengths[j] = ArmourStrength.ReadFrom(reader);
                        }
                        float reloadTime   = reader.ReadFloat32();
                        float maximumRange = reader.ReadFloat32();

                        short accuracyPercentage = reader.ReadInt16();
                        short projectileUnitId   = reader.ReadInt16();

                        short unknown7             = reader.ReadInt16();
                        float displayedAttackRange = reader.ReadFloat32();
                        float blastRadius          = reader.ReadFloat32();
                        float minimumRange         = reader.ReadFloat32();

                        // Constants?
                        ushort unknown12 = reader.ReadUInt16();
                        byte   unknown13 = reader.ReadUInt8();

                        if (unknown2 != 0)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
                        if (i == breakId)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
                    } break;

                    case 70:                             // Living units
                    {
                        short hitpoints        = reader.ReadInt16();
                        float lengthOfSight    = reader.ReadFloat32();
                        byte  garrisonCapacity = reader.ReadUInt8();
                        float sizeRadiusX      = reader.ReadFloat32();
                        float sizeRadiusY      = reader.ReadFloat32();
                        short resourceCarriage = reader.ReadInt16();
                        float storageAmount    = reader.ReadFloat32();                                      // e.g. iron boar = 700

                        byte  unknown2           = reader.ReadUInt8();
                        float movementRate       = reader.ReadFloat32();
                        float extraRotationSpeed = reader.ReadFloat32();                                         // Rotation speed for extra parts - sails for ships.

                        float searchRadius = reader.ReadFloat32();
                        float workRate     = reader.ReadFloat32();
                        short unknown4     = reader.ReadInt16();

                        ushort           attackStrengthsCount = reader.ReadUInt16();
                        AttackStrength[] strengths            = new AttackStrength[attackStrengthsCount];
                        for (int j = 0; j < strengths.Length; j++)
                        {
                            strengths[j] = AttackStrength.ReadFrom(reader);
                        }

                        ushort           armourStrengthsCount = reader.ReadUInt16();
                        ArmourStrength[] astrengths           = new ArmourStrength[armourStrengthsCount];
                        for (int j = 0; j < astrengths.Length; j++)
                        {
                            astrengths[j] = ArmourStrength.ReadFrom(reader);
                        }
                        float reloadTime   = reader.ReadFloat32();
                        float maximumRange = reader.ReadFloat32();

                        short accuracyPercentage = reader.ReadInt16();
                        short projectileUnitId   = reader.ReadInt16();

                        short unknown7             = reader.ReadInt16();
                        float displayedAttackRange = reader.ReadFloat32();
                        float blastRadius          = reader.ReadFloat32();
                        float minimumRange         = reader.ReadFloat32();

                        ResourceCost res1                     = ResourceCost.ReadFrom(reader);
                        ResourceCost res2                     = ResourceCost.ReadFrom(reader);
                        ResourceCost res3                     = ResourceCost.ReadFrom(reader);
                        short        trainingTime             = reader.ReadInt16();
                        float        missileDuplicationAmount = reader.ReadFloat32();

                        // Constants?
                        ushort unknown12 = reader.ReadUInt16();
                        byte   unknown13 = reader.ReadUInt8();

                        if (i == breakId)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
                    }
                    break;

                    case 80:                             // Buildings
                    {
                        short hitpoints        = reader.ReadInt16();
                        float lengthOfSight    = reader.ReadFloat32();
                        byte  garrisonCapacity = reader.ReadUInt8();
                        float sizeRadius1      = reader.ReadFloat32();
                        float sizeRadius2      = reader.ReadFloat32();
                        short resourceCarriage = reader.ReadInt16();
                        float storageAmount    = reader.ReadFloat32();

                        byte  unknown2     = reader.ReadUInt8();
                        float movementRate = reader.ReadFloat32();

                        float extraRotationSpeed = reader.ReadFloat32();                                        // Rotation speed for extra parts - something for trebuchets.
                        float searchRadius       = reader.ReadFloat32();
                        float workRate           = reader.ReadFloat32();
                        short unknown4           = reader.ReadInt16();

                        ushort           attackStrengthsCount = reader.ReadUInt16();
                        AttackStrength[] strengths            = new AttackStrength[attackStrengthsCount];
                        for (int j = 0; j < strengths.Length; j++)
                        {
                            strengths[j] = AttackStrength.ReadFrom(reader);
                        }

                        ushort           armourStrengthsCount = reader.ReadUInt16();
                        ArmourStrength[] astrengths           = new ArmourStrength[armourStrengthsCount];
                        for (int j = 0; j < astrengths.Length; j++)
                        {
                            astrengths[j] = ArmourStrength.ReadFrom(reader);
                        }
                        float reloadTime   = reader.ReadFloat32();
                        float maximumRange = reader.ReadFloat32();

                        short accuracyPercentage = reader.ReadInt16();
                        short projectileUnitId   = reader.ReadInt16();

                        short unknown7             = reader.ReadInt16();                             // Seems to have something to do with buildings
                        float displayedAttackRange = reader.ReadFloat32();
                        float blastRadius          = reader.ReadFloat32();
                        float minimumRange         = reader.ReadFloat32();

                        ResourceCost res1                     = ResourceCost.ReadFrom(reader);
                        ResourceCost res2                     = ResourceCost.ReadFrom(reader);
                        ResourceCost res3                     = ResourceCost.ReadFrom(reader);
                        short        trainingTime             = reader.ReadInt16();
                        float        missileDuplicationAmount = reader.ReadFloat32();
                        ushort       unknown14                = reader.ReadUInt16();                    // No clue at all.

                        // Constants?
                        ushort unknown12 = reader.ReadUInt16();
                        byte   unknown13 = reader.ReadUInt8();

                        if (i == breakId)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
                    }
                    break;
                    }
                    return(value);
                }