public ColorRef4       VertexShading; // RGB + Shading radius (0 - 200) %

            public RDOTField(BinaryFileReader r, int dataSize)
            {
                Object    = new FormId <Record>(r.ReadUInt32());
                ParentIdx = r.ReadUInt16();
                r.Skip(2); // Unused
                Density         = r.ReadSingle();
                Clustering      = r.ReadByte();
                MinSlope        = r.ReadByte();
                MaxSlope        = r.ReadByte();
                Flags           = r.ReadByte();
                RadiusWrtParent = r.ReadUInt16();
                Radius          = r.ReadUInt16();
                MinHeight       = r.ReadSingle();
                MaxHeight       = r.ReadSingle();
                Sink            = r.ReadSingle();
                SinkVariance    = r.ReadSingle();
                SizeVariance    = r.ReadSingle();
                AngleVariance   = new Vector3Int(r.ReadUInt16(), r.ReadUInt16(), r.ReadUInt16());
                r.Skip(2); // Unused
                VertexShading = r.ReadT <ColorRef4>(dataSize);
            }
 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();
 }
Beispiel #3
0
        public UNKNField?TNAM;         // overrides (Optional)

        public override bool CreateField(BinaryFileReader r, GameFormat format, string type, int dataSize)
        {
            switch (type)
            {
            case "HEDR": HEDR = r.ReadT <HEDRField>(dataSize); return(true);

            case "OFST": r.Skip(dataSize); return(true);

            case "DELE": r.Skip(dataSize); return(true);

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

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

            case "MAST": if (MASTs == null)
                {
                    MASTs = new List <STRVField>();
                }
                MASTs.Add(r.ReadSTRV(dataSize)); return(true);

            case "DATA": if (DATAs == null)
                {
                    DATAs = new List <INTVField>();
                }
                DATAs.Add(r.ReadINTV(dataSize)); return(true);

            case "ONAM": ONAM = r.ReadUNKN(dataSize); return(true);

            case "INTV": INTV = r.ReadT <IN32Field>(dataSize); return(true);

            case "INCC": INCC = r.ReadT <IN32Field>(dataSize); return(true);

            // TES5
            case "TNAM": TNAM = r.ReadUNKN(dataSize); return(true);

            default: return(false);
            }
        }
Beispiel #4
0
        public static void ReadNonfixed(BinaryFileReader r, Header header, RecordGroup group)
        {
            var world = int.Parse(header.Label);

            // header
            r.Skip(4 * 5);
            var width  = r.ReadUInt32();
            var height = r.ReadUInt32();

            r.Skip(4);
            var indexSize = (int)(width * height);
            var indices   = r.ReadTArray <uint>(indexSize * 4, indexSize);

            r.Skip(4);
            // pages
            var page     = r.ReadT <Page>(28); r.Skip(4 * 7);
            var entities = new Entity[page.EntityCount];

            for (var i = 0; i < entities.Length; i++)
            {
                entities[i] = r.ReadT <Entity>(64);
            }
        }
Beispiel #5
0
 public WEATField(BinaryFileReader r, int dataSize)
 {
     Clear    = r.ReadByte();
     Cloudy   = r.ReadByte();
     Foggy    = r.ReadByte();
     Overcast = r.ReadByte();
     Rain     = r.ReadByte();
     Thunder  = r.ReadByte();
     Ash      = r.ReadByte();
     Blight   = r.ReadByte();
     // v1.3 ESM files add 2 bytes to WEAT subrecords.
     if (dataSize == 10)
     {
         r.Skip(2);
     }
 }
        public PGRIField[] PGRIs;      // Inter-Cell Connections

        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 "DATA": DATA = new DATAField(r, dataSize, format); return(true);

            case "PGRP":
                PGRPs = new PGRPField[dataSize >> 4];
                for (var i = 0; i < PGRPs.Length; i++)
                {
                    PGRPs[i] = new PGRPField(r, 16);
                }
                return(true);

            case "PGRC": PGRC = r.ReadUNKN(dataSize); return(true);

            case "PGAG": PGAG = r.ReadUNKN(dataSize); return(true);

            case "PGRR":
                PGRRs = new PGRRField[dataSize >> 2];
                for (var i = 0; i < PGRRs.Length; i++)
                {
                    PGRRs[i] = new PGRRField(r, 4);
                }
                r.Skip(dataSize % 4); return(true);

            case "PGRL": if (PGRLs == null)
                {
                    PGRLs = new List <PGRLField>();
                }
                PGRLs.Add(new PGRLField(r, dataSize)); return(true);

            case "PGRI":
                PGRIs = new PGRIField[dataSize >> 4];
                for (var i = 0; i < PGRIs.Length; i++)
                {
                    PGRIs[i] = new PGRIField(r, 16);
                }
                return(true);

            default: return(false);
            }
        }
        public List <ENCHRecord.SCITField> SCITs = new List <ENCHRecord.SCITField>(); // Script Effect Data

        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 "MODL": MODL = new MODLGroup(r, dataSize); return(true);

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

            case "MODT": MODL.MODTField(r, dataSize); return(true);

            case "FULL": if (SCITs.Count == 0)
                {
                    FULL = r.ReadSTRV(dataSize);
                }
                else
                {
                    SCITs.Last().FULLField(r, dataSize);
                } return(true);

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

            case "DATA":
            case "ALDT": DATA = new DATAField(r, dataSize, format); return(true);

            case "ENAM": ENAM = new ENAMField(r, dataSize); return(true);

            case "ICON":
            case "TEXT": ICON = r.ReadFILE(dataSize); return(true);

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

            //
            case "ENIT": DATA.ENITField(r, dataSize); return(true);

            case "EFID": r.Skip(dataSize); return(true);

            case "EFIT": EFITs.Add(new ENCHRecord.EFITField(r, dataSize, format)); return(true);

            case "SCIT": SCITs.Add(new ENCHRecord.SCITField(r, dataSize)); return(true);

            default: return(false);
            }
        }
Beispiel #8
0
        private void ReadDisposedHeroes(BinaryFileReader reader)
        {
            if (mapObject.Header.Version >= EMapFormat.SOD)
            {
                int disp = reader.ReadUInt8();
                Console.WriteLine("ReadDisposedHeroes: Total=" + disp);
                for (int g = 0; g < disp; ++g)
                {
                    int    heroId   = reader.ReadUInt8();
                    int    portrait = reader.ReadUInt8();
                    string name     = reader.ReadString();
                    int    players  = reader.ReadUInt8();
                    Console.WriteLine(string.Format("ReadDisposedHeroes: id={0} portrait={1} name={2} players={3}", heroId, portrait, name, players));
                }
            }

            //omitting NULLS
            reader.Skip(31);
        }
Beispiel #9
0
        private void ReadObjectTemplates(BinaryFileReader reader)
        {
            uint defAmount = reader.ReadUInt32();

            Console.WriteLine("ReadObjectTemplates totally:" + defAmount);

            // Read custom defs
            for (int idd = 0; idd < defAmount; ++idd)
            {
                string animationFile = reader.ReadString();
                Console.WriteLine("Object Animation File:" + animationFile);

                int[] blockMask = new int[6];
                int[] visitMask = new int[6];

                foreach (int val in blockMask)
                {
                    int r = reader.ReadUInt8();
                    //Console.WriteLine("BlockMask: " + r);
                }

                foreach (int val in visitMask)
                {
                    int r = reader.ReadUInt8();
                    //Console.WriteLine("VisitMask: " + r);
                }

                reader.ReadUInt16();
                int terrMask = reader.ReadUInt16();

                uint objectId      = reader.ReadUInt32();
                uint objectSubId   = reader.ReadUInt32();
                int  type          = reader.ReadUInt8();
                int  printPriority = reader.ReadUInt8() * 100;

                reader.Skip(16);
            }
        }
Beispiel #10
0
        private void ReadAllowedHeroes(BinaryFileReader reader)
        {
            int byteCount = 20; //// mapHeader->version == EMapFormat::ROE ? 16 : 20;

            HashSet <int> allowedHeroSet = new HashSet <int>();

            reader.ReadBitMask(allowedHeroSet, byteCount, GameConstants.HEROES_QUANTITY, false);

            // Probably reserved for further heroes
            if (true)
            {
                uint placeholdersQty = reader.ReadUInt32();

                reader.Skip((int)placeholdersQty);

                //		std::vector<ui16> placeholdedHeroes;
                //
                //		for(int p = 0; p < placeholdersQty; ++p)
                //		{
                //			placeholdedHeroes.push_back(reader.readUInt8());
                //		}
            }
        }
Beispiel #11
0
        public static void ReadFixed(BinaryFileReader r, Header header, RecordGroup group)
        {
            var world     = int.Parse(header.Label);
            var head      = r.ReadT <Head>(32);
            var indexSize = (int)(head.Width * head.Height);
            // These are either 0 or a number in the form nnnn001h, where nnnn is a number that may be a page index. This may be in [x + y * width] order, but that doesn't seem to corroborate with where objects are located in the maps
            var       indices      = r.ReadTArray <uint>(indexSize * 4, indexSize);
            const int POINT_STRIDE = 32;
            var       pages        = new Page[head.PageSize / 4096];

            for (var i = 0; i < pages.Length; i++)
            {
                var page = pages[i] = new Page();
                r.Skip(4 * 0x3);
                page.BaseX = r.ReadUInt32();
                page.BaseY = r.ReadUInt32();
                r.Skip(4 * 0x13);
                page.FixedObjects = r.ReadTArray <FixedObject>(0x18 * 166, 166);
                r.Skip(0x10);
            }
            var data = new Data
            {
                Width   = head.Width,
                Height  = head.Height,
                Indices = indices,
                Pages   = pages,
            };

            group.Tag = data;

            // transform
            const int CELL_STRIDE = 64;
            var       records     = new List <Record>();

            for (var y = 0; y < data.Height; y += 2)
            {
                for (var x = 0; x < data.Width; x += 2)
                {
                    //var vhgt = new ushort[CELL_STRIDE * CELL_STRIDE];
                    //var vtex = new ushort[CELL_STRIDE * CELL_STRIDE];
                    //var vtexf = new byte[CELL_STRIDE * CELL_STRIDE];
                    //for (var sy = 0; sy < 2; sy++)
                    //    for (var sx = 0; sx < 2; sx++)
                    //    {
                    //        var index = indices[x + sx + ((y + sy) * data.Width)];
                    //        if (index >= chunks.Length)
                    //            continue;
                    //        var chunk = chunks[index];
                    //        var offset = (sx * POINT_STRIDE) + (sy * POINT_STRIDE * CELL_STRIDE);
                    //        for (var i = 0; i < POINT_STRIDE; i++)
                    //        {
                    //            Buffer.BlockCopy(chunk.VHGT, i * POINT_STRIDE * 2, vhgt, offset + (i * CELL_STRIDE * 2), POINT_STRIDE * 2);
                    //            Buffer.BlockCopy(chunk.VTEX, i * POINT_STRIDE * 2, vtex, offset + (i * CELL_STRIDE * 2), POINT_STRIDE * 2);
                    //            Buffer.BlockCopy(chunk.VTEXF, i * POINT_STRIDE, vtexf, offset + (i * CELL_STRIDE), POINT_STRIDE);
                    //        }
                    //    }
                    records.Add(new CELLRecord
                    {
                        GridId = new Vector3Int(x / 2, y / 2, world),
                    });
                }
            }

            // insert
            group.CELLsById = records.ToDictionary(x => ((CELLRecord)x).GridId, x => (CELLRecord)x);
            group.Records.AddRange(records);
        }
 public void ENITField(BinaryFileReader r, int dataSize)
 {
     Value = r.ReadInt32();
     Flags = r.ReadByte();
     r.Skip(3); // Unknown
 }
 public PGRPField(BinaryFileReader r, int dataSize)
 {
     Point       = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
     Connections = r.ReadByte();
     r.Skip(3); // Unused
 }
Beispiel #14
0
        private void ReadPlayerInfo(BinaryFileReader reader)
        {
            for (int i = 0; i < GameConstants.PLAYER_LIMIT_T; i++)
            {
                PlayerInfo playerInfo = new PlayerInfo();

                Console.WriteLine("Reading Player [" + i.ToString() + "]");

                playerInfo.CanHumanPlay    = reader.ReadBool();
                playerInfo.CanComputerPlay = reader.ReadBool();
                Console.WriteLine("canHumanPlay: " + playerInfo.CanHumanPlay);
                Console.WriteLine("canComputerPlay: " + playerInfo.CanComputerPlay);

                if (!playerInfo.CanHumanPlay && !playerInfo.CanComputerPlay)
                {
                    switch (mapObject.Header.Version)
                    {
                    case EMapFormat.SOD:
                    case EMapFormat.WOG:
                        reader.Skip(13);
                        break;

                    case EMapFormat.AB:
                        reader.Skip(12);
                        break;

                    case EMapFormat.ROE:
                        reader.Skip(6);
                        break;
                    }
                    continue;
                }

                playerInfo.AiTactic = (EAiTactic)reader.ReadUInt8();
                Console.WriteLine("aiTactic:" + playerInfo.AiTactic);

                if (mapObject.Header.Version == EMapFormat.SOD || mapObject.Header.Version == EMapFormat.WOG)
                {
                    playerInfo.P7 = reader.ReadUInt8();
                }
                else
                {
                    playerInfo.P7 = -1;
                }

                Console.WriteLine("p7:" + playerInfo.P7);

                // Reading the Factions for Player
                playerInfo.AllowedFactions = new List <int>();
                int allowedFactionsMask = reader.ReadUInt8();
                Console.WriteLine("allowedFactionsMask:" + allowedFactionsMask);

                int totalFactionCount = GameConstants.F_NUMBER;
                if (mapObject.Header.Version != EMapFormat.ROE)
                {
                    allowedFactionsMask += reader.ReadUInt8() << 8;
                }
                else
                {
                    totalFactionCount--; //exclude conflux for ROE
                }
                for (int fact = 0; fact < totalFactionCount; ++fact)
                {
                    if ((allowedFactionsMask & (1 << fact)) > 0)
                    {
                        playerInfo.AllowedFactions.Add(fact);
                    }
                }

                playerInfo.IsFactionRandom = reader.ReadBool();
                playerInfo.HasMainTown     = reader.ReadBool();
                Console.WriteLine("isFactionRandom:" + playerInfo.IsFactionRandom);
                Console.WriteLine("hasMainTown:" + playerInfo.HasMainTown);

                if (playerInfo.HasMainTown)
                {
                    /// Added in new version, not tested yet
                    if (mapObject.Header.Version != EMapFormat.ROE)
                    {
                        playerInfo.GenerateHeroAtMainTown = reader.ReadBool();
                        playerInfo.GenerateHero           = reader.ReadBool();
                    }
                    else
                    {
                        playerInfo.GenerateHeroAtMainTown = true;
                        playerInfo.GenerateHero           = false;
                    }

                    var townPosition = reader.ReadPosition();
                    Console.WriteLine(string.Format("Main Town Position: {0}, {1}, {2}", townPosition.PosX, townPosition.PosY, townPosition.PosZ));
                    playerInfo.MainTownPosition = townPosition;
                }

                playerInfo.HasRandomHero = reader.ReadBool();
                Console.WriteLine("hasRandomHero:" + playerInfo.HasRandomHero);

                playerInfo.MainCustomHeroId = reader.ReadUInt8();
                Console.WriteLine("mainCustomHeroId:" + playerInfo.MainCustomHeroId);

                if (playerInfo.MainCustomHeroId != 0xff)
                {
                    playerInfo.MainCustomHeroPortrait = reader.ReadUInt8();
                    if (playerInfo.MainCustomHeroPortrait == 0xff)
                    {
                        playerInfo.MainCustomHeroPortrait = -1;
                    }

                    playerInfo.MainCustomHeroName = reader.ReadString();
                    Console.WriteLine("mainCustomHeroPortrait:" + playerInfo.MainCustomHeroPortrait);
                    Console.WriteLine("heroName:" + playerInfo.MainCustomHeroName);
                }
                else
                {
                    playerInfo.MainCustomHeroId = -1;
                }

                if (mapObject.Header.Version != EMapFormat.ROE)
                {
                    playerInfo.PowerPlaceHolders = reader.ReadUInt8();
                    int heroCount = reader.ReadUInt8();
                    reader.Skip(3);

                    playerInfo.HeroIds = new List <HeroIdentifier>();
                    for (int pp = 0; pp < heroCount; ++pp)
                    {
                        HeroIdentifier heroId = new HeroIdentifier();
                        heroId.Id   = reader.ReadUInt8();
                        heroId.Name = reader.ReadString();
                        playerInfo.HeroIds.Add(heroId);
                    }
                }
            }
        }
 public PKDTField(BinaryFileReader r, int dataSize)
 {
     Flags = r.ReadUInt16();
     Type  = r.ReadByte();
     r.Skip(dataSize - 3); // Unused
 }
 public DATAField(BinaryFileReader r, int dataSize)
 {
     if (dataSize != 224 && dataSize != 96)
     {
         Flags = 0;
     }
     Flags = r.ReadByte();
     r.Skip(3); // Unused
     MembraneShader_SourceBlendMode            = r.ReadUInt32();
     MembraneShader_BlendOperation             = r.ReadUInt32();
     MembraneShader_ZTestFunction              = r.ReadUInt32();
     FillTextureEffect_Color                   = r.ReadT <ColorRef4>(dataSize);
     FillTextureEffect_AlphaFadeInTime         = r.ReadSingle();
     FillTextureEffect_FullAlphaTime           = r.ReadSingle();
     FillTextureEffect_AlphaFadeOutTime        = r.ReadSingle();
     FillTextureEffect_PresistentAlphaRatio    = r.ReadSingle();
     FillTextureEffect_AlphaPulseAmplitude     = r.ReadSingle();
     FillTextureEffect_AlphaPulseFrequency     = r.ReadSingle();
     FillTextureEffect_TextureAnimationSpeed_U = r.ReadSingle();
     FillTextureEffect_TextureAnimationSpeed_V = r.ReadSingle();
     EdgeEffect_FallOff               = r.ReadSingle();
     EdgeEffect_Color                 = r.ReadT <ColorRef4>(dataSize);
     EdgeEffect_AlphaFadeInTime       = r.ReadSingle();
     EdgeEffect_FullAlphaTime         = r.ReadSingle();
     EdgeEffect_AlphaFadeOutTime      = r.ReadSingle();
     EdgeEffect_PresistentAlphaRatio  = r.ReadSingle();
     EdgeEffect_AlphaPulseAmplitude   = r.ReadSingle();
     EdgeEffect_AlphaPulseFrequency   = r.ReadSingle();
     FillTextureEffect_FullAlphaRatio = r.ReadSingle();
     EdgeEffect_FullAlphaRatio        = r.ReadSingle();
     MembraneShader_DestBlendMode     = r.ReadUInt32();
     if (dataSize == 96)
     {
         return;
     }
     ParticleShader_SourceBlendMode              = r.ReadUInt32();
     ParticleShader_BlendOperation               = r.ReadUInt32();
     ParticleShader_ZTestFunction                = r.ReadUInt32();
     ParticleShader_DestBlendMode                = r.ReadUInt32();
     ParticleShader_ParticleBirthRampUpTime      = r.ReadSingle();
     ParticleShader_FullParticleBirthTime        = r.ReadSingle();
     ParticleShader_ParticleBirthRampDownTime    = r.ReadSingle();
     ParticleShader_FullParticleBirthRatio       = r.ReadSingle();
     ParticleShader_PersistantParticleBirthRatio = r.ReadSingle();
     ParticleShader_ParticleLifetime             = r.ReadSingle();
     ParticleShader_ParticleLifetime_Delta       = r.ReadSingle();
     ParticleShader_InitialSpeedAlongNormal      = r.ReadSingle();
     ParticleShader_AccelerationAlongNormal      = r.ReadSingle();
     ParticleShader_InitialVelocity1             = r.ReadSingle();
     ParticleShader_InitialVelocity2             = r.ReadSingle();
     ParticleShader_InitialVelocity3             = r.ReadSingle();
     ParticleShader_Acceleration1                = r.ReadSingle();
     ParticleShader_Acceleration2                = r.ReadSingle();
     ParticleShader_Acceleration3                = r.ReadSingle();
     ParticleShader_ScaleKey1     = r.ReadSingle();
     ParticleShader_ScaleKey2     = r.ReadSingle();
     ParticleShader_ScaleKey1Time = r.ReadSingle();
     ParticleShader_ScaleKey2Time = r.ReadSingle();
     ColorKey1_Color        = r.ReadT <ColorRef4>(dataSize);
     ColorKey2_Color        = r.ReadT <ColorRef4>(dataSize);
     ColorKey3_Color        = r.ReadT <ColorRef4>(dataSize);
     ColorKey1_ColorAlpha   = r.ReadSingle();
     ColorKey2_ColorAlpha   = r.ReadSingle();
     ColorKey3_ColorAlpha   = r.ReadSingle();
     ColorKey1_ColorKeyTime = r.ReadSingle();
     ColorKey2_ColorKeyTime = r.ReadSingle();
     ColorKey3_ColorKeyTime = r.ReadSingle();
 }
 public XESPField(BinaryFileReader r, int dataSize)
 {
     Reference = new FormId <Record>(r.ReadUInt32());
     Flags     = r.ReadByte();
     r.Skip(3); // Unused
 }
 public PGRIField(BinaryFileReader r, int dataSize)
 {
     PointId = r.ReadInt16();
     r.Skip(2); // Unused (can merge back)
     ForeignNode = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
 }
Beispiel #19
0
 // Low-LOD heightmap (signed chars)
 public WNAMField(BinaryFileReader r, int dataSize)
 {
     r.Skip(dataSize);
     //var heightCount = dataSize;
     //for (var i = 0; i < heightCount; i++) { var height = r.ReadByte(); }
 }
Beispiel #20
0
        static void Test()
        {
            BinaryFileReader reader = new BinaryFileReader(@"D:\PlayGround\SOD_Data\h3ab_bmp.lod");

            reader.Skip(8);
            uint count = reader.ReadUInt32();

            Console.WriteLine("Total count: " + count);

            List <FileInfo> fileList = new List <FileInfo>();

            reader.Seek(92);
            for (int fileIndex = 0; fileIndex < count; fileIndex++)
            {
                byte[] buffer = new byte[16];
                for (int i = 0; i < 16; i++)
                {
                    buffer[i] = reader.ReadByte();
                }
                string filename = System.Text.Encoding.ASCII.GetString(buffer);

                filename = filename.Substring(0, filename.IndexOf('\0'));
                uint offset      = reader.ReadUInt32();
                uint size        = reader.ReadUInt32();
                uint placeholder = reader.ReadUInt32();
                uint csize       = reader.ReadUInt32();

                Console.WriteLine(string.Format("[{4}] filename:{0} offset:{1} size:{2} csize:{3}", filename, offset, size, csize, fileIndex));

                FileInfo info = new FileInfo();
                info.FileName = filename;
                info.Offset   = offset;
                info.Size     = size;
                info.CSize    = csize;

                fileList.Add(info);
            }

            Directory.CreateDirectory(@".\output\");

            Directory.CreateDirectory(@".\output\extracted\");

            for (int fileIndex = 0; fileIndex < count; fileIndex++)
            {
                FileInfo info = fileList[fileIndex];

                reader.Seek(info.Offset);
                byte[] content;
                string filename = @".\output\" + info.FileName;
                if (info.CSize > 0)
                {
                    filename = filename + ".zip";
                    content  = reader.ReadBytes((int)info.CSize);
                }
                else
                {
                    content = reader.ReadBytes((int)info.Size);
                }

                using (var fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                {
                    fs.Write(content, 0, content.Length);
                }

                //// Thread.Sleep(500);
                Console.WriteLine("Finished writing file " + filename);

                if (filename.EndsWith(".h3c"))
                {
                    /*
                     * //ZipFile.ExtractToDirectory(filename, @"D:\Temp\ab.h3c");
                     * int length = 100000;
                     * byte[] data = new byte[length];
                     * for (int i = 0; i < length; i++)
                     * {
                     *  data[i] = System.Convert.ToByte(i % 100 + i % 50);
                     * }
                     *
                     * byte[] o;
                     * //serialization into memory stream
                     * IFormatter formatter = new BinaryFormatter();
                     *
                     * using (FileStream decompressedFileStream = File.Create(filename + ".origin"))
                     * {
                     *  using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read))
                     *  {
                     *      using (GZipStream decompressionStream = new GZipStream(file, CompressionMode.Decompress, true))
                     *      {
                     *          int dstreamlength = 0;
                     *          while(decompressionStream.ReadByte() >= 0)
                     *          {
                     *              dstreamlength++;
                     *          }
                     *
                     *          Console.WriteLine("GZip Decompressed length: " + dstreamlength);
                     *
                     *          ///DecompressFile(@".\output\extracted\", decompressionStream);
                     *          // decompressionStream.CopyTo(decompressedFileStream);///
                     *
                     *          Console.WriteLine("Decompressed: {0}", filename);
                     *      }
                     *
                     *
                     *      file.Seek(0, SeekOrigin.Begin);
                     *      var oo = formatter.Deserialize(decompressedFileStream);
                     *      o = (byte[])oo;
                     *
                     *  }
                     * }
                     */
                }

                if (info.CSize > 0)
                {
                    ////ZipFile.ExtractToDirectory(filename, @"D:\Temp");
                    //// ZipFile.ExtractToDirectory(filename, filename.Substring(0, 5));



                    using (FileStream decompressedFileStream = File.Create(filename + ".origin"))
                    {
                        using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read))
                        {
                            using (DeflateStream decompressionStream = new DeflateStream(file, CompressionMode.Decompress, true))
                            {
                                decompressionStream.CopyTo(decompressedFileStream);
                                Console.WriteLine("Decompressed: {0}", filename);
                            }

                            /*
                             * using (GZipStream decompressionStream = new GZipStream(file, CompressionMode.Decompress, false))
                             * {
                             *  decompressionStream.CopyTo(decompressedFileStream);
                             *  Console.WriteLine("Decompressed: {0}", filename);
                             * }
                             */
                        }
                    }
                }
            }
        }
Beispiel #21
0
 public RDGSField(BinaryFileReader r, int dataSize)
 {
     Grass = new FormId <GRASRecord>(r.ReadUInt32());
     r.Skip(4); // Unused
 }
 public CSTDField(BinaryFileReader r, int dataSize)
 {
     //if (dataSize != 124 && dataSize != 120 && dataSize != 112 && dataSize != 104 && dataSize != 92 && dataSize != 84)
     //    DodgePercentChance = 0;
     DodgePercentChance     = r.ReadByte();
     LeftRightPercentChance = r.ReadByte();
     r.Skip(2); // Unused
     DodgeLeftRightTimer_Min = r.ReadSingle();
     DodgeLeftRightTimer_Max = r.ReadSingle();
     DodgeForwardTimer_Min   = r.ReadSingle();
     DodgeForwardTimer_Max   = r.ReadSingle();
     DodgeBackTimer_Min      = r.ReadSingle();
     DodgeBackTimer_Max      = r.ReadSingle();
     IdleTimer_Min           = r.ReadSingle();
     IdleTimer_Max           = r.ReadSingle();
     BlockPercentChance      = r.ReadByte();
     AttackPercentChance     = r.ReadByte();
     r.Skip(2); // Unused
     RecoilStaggerBonusToAttack = r.ReadSingle();
     UnconsciousBonusToAttack   = r.ReadSingle();
     HandToHandBonusToAttack    = r.ReadSingle();
     PowerAttackPercentChance   = r.ReadByte();
     r.Skip(3); // Unused
     RecoilStaggerBonusToPower     = r.ReadSingle();
     UnconsciousBonusToPowerAttack = r.ReadSingle();
     PowerAttack_Normal            = r.ReadByte();
     PowerAttack_Forward           = r.ReadByte();
     PowerAttack_Back  = r.ReadByte();
     PowerAttack_Left  = r.ReadByte();
     PowerAttack_Right = r.ReadByte();
     r.Skip(3); // Unused
     HoldTimer_Min = r.ReadSingle();
     HoldTimer_Max = r.ReadSingle();
     Flags1        = r.ReadByte();
     AcrobaticDodgePercentChance = r.ReadByte();
     r.Skip(2); // Unused
     if (dataSize == 84)
     {
         return;
     }
     RangeMult_Optimal = r.ReadSingle();
     RangeMult_Max     = r.ReadSingle();
     if (dataSize == 92)
     {
         return;
     }
     SwitchDistance_Melee  = r.ReadSingle();
     SwitchDistance_Ranged = r.ReadSingle();
     BuffStandoffDistance  = r.ReadSingle();
     if (dataSize == 104)
     {
         return;
     }
     RangedStandoffDistance = r.ReadSingle();
     GroupStandoffDistance  = r.ReadSingle();
     if (dataSize == 112)
     {
         return;
     }
     RushingAttackPercentChance = r.ReadByte();
     r.Skip(3); // Unused
     RushingAttackDistanceMult = r.ReadSingle();
     if (dataSize == 120)
     {
         return;
     }
     Flags2 = r.ReadUInt32();
 }