Example #1
0
        public static Wave ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((Wave)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                DatReader datReader = DatManager.PortalDat.GetReaderForFile(fileId);
                Wave      obj       = new Wave();

                obj.Id = datReader.ReadUInt32();

                int headerSize = datReader.ReadInt32() - 2; // not sure why this is required, it just is.
                int dataSize   = datReader.ReadInt32();

                obj.Header = datReader.ReadBytes(headerSize);
                obj.Data   = datReader.ReadBytes(dataSize);

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = obj;

                return(obj);
            }
        }
Example #2
0
        public static XpTable ReadFromDat()
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(0x0E000018))
            {
                return((XpTable)DatManager.PortalDat.FileCache[0x0E000018]);
            }
            else
            {
                DatReader datReader = DatManager.PortalDat.GetReaderForFile(0x0E000018);
                XpTable   xp        = new XpTable();

                datReader.Offset += 4; // Skip the ID. We know what it is.

                // The counts for each "Table" are at the top of the file.
                int  abilityCount          = datReader.ReadInt32();
                int  vitalCount            = datReader.ReadInt32();
                int  trainedSkillCount     = datReader.ReadInt32();
                int  specializedSkillCount = datReader.ReadInt32();
                uint levelCount            = datReader.ReadUInt32();

                xp.AbilityXpChart          = ReadExperienceChart(abilityCount, ref datReader);
                xp.VitalXpChart            = ReadExperienceChart(vitalCount, ref datReader);
                xp.TrainedSkillXpChart     = ReadExperienceChart(trainedSkillCount, ref datReader);
                xp.SpecializedSkillXpChart = ReadExperienceChart(specializedSkillCount, ref datReader);

                // The level table is a little different since it has UInt64 data types.
                LevelingChart levelingXpChart = new LevelingChart();
                ulong         prevRank        = 0;
                datReader.Offset += 8; // skip level 0
                // Start from 1 because dat includes level 0.
                for (uint i = 1; i <= levelCount; i++)
                {
                    CharacterLevel characterLevel = new CharacterLevel();
                    characterLevel.Level             = i;
                    characterLevel.TotalXp           = datReader.ReadUInt64();
                    characterLevel.FromPreviousLevel = characterLevel.TotalXp - prevRank;
                    // Store this to use it in the next loop...
                    prevRank = characterLevel.TotalXp;
                    levelingXpChart.Levels.Add(characterLevel);
                }

                // The final section is skill credits... It has the same count as levels.
                int cumulativeSkillPoints = 0;
                datReader.Offset += 4; // skip level 0
                for (int i = 0; i < levelCount; i++)
                {
                    int skillPoint = datReader.ReadInt32();
                    cumulativeSkillPoints += skillPoint;
                    levelingXpChart.Levels[i].GrantsSkillPoint      = skillPoint == 1;
                    levelingXpChart.Levels[i].CumulativeSkillPoints = cumulativeSkillPoints;
                }

                xp.LevelingXpChart = levelingXpChart;

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[0x0E000018] = xp;
                return(xp);
            }
        }
Example #3
0
        public static XpTable ReadFromDat()
        {
            if (instance == null) // We'll store the XP data into the instance the first time it's loaded. No need to read it multiple times.
            {
                DatReader datReader = DatManager.PortalDat.GetReaderForFile(0x0E000018);
                XpTable   xp        = new XpTable();

                datReader.Offset += 4; // Skip the ID. We know what it is.

                // The counts for each "Table" are at the top of the file.
                int  abilityCount          = datReader.ReadInt32();
                int  vitalCount            = datReader.ReadInt32();
                int  trainedSkillCount     = datReader.ReadInt32();
                int  specializedSkillCount = datReader.ReadInt32();
                uint levelCount            = datReader.ReadUInt32();

                xp.AbilityXpChart          = ReadExperienceChart(abilityCount, ref datReader);
                xp.VitalXpChart            = ReadExperienceChart(vitalCount, ref datReader);
                xp.TrainedSkillXpChart     = ReadExperienceChart(trainedSkillCount, ref datReader);
                xp.SpecializedSkillXpChart = ReadExperienceChart(specializedSkillCount, ref datReader);

                // The level table is a little different since it has UInt64 data types.
                LevelingChart levelingXpChart = new LevelingChart();
                ulong         prevRank        = 0;
                datReader.Offset += 8; // skip level 0
                // Start from 1 because dat includes level 0.
                for (uint i = 1; i <= levelCount; i++)
                {
                    CharacterLevel characterLevel = new CharacterLevel();
                    characterLevel.Level             = i;
                    characterLevel.TotalXp           = datReader.ReadUInt64();
                    characterLevel.FromPreviousLevel = characterLevel.TotalXp - prevRank;
                    // Store this to use it in the next loop...
                    prevRank = characterLevel.TotalXp;
                    levelingXpChart.Levels.Add(characterLevel);
                }

                // The final section is skill credits... It has the same count as levels.
                int cumulativeSkillPoints = 0;
                datReader.Offset += 4; // skip level 0
                for (int i = 0; i < levelCount; i++)
                {
                    int skillPoint = datReader.ReadInt32();
                    cumulativeSkillPoints += skillPoint;
                    levelingXpChart.Levels[i].GrantsSkillPoint      = skillPoint == 1;
                    levelingXpChart.Levels[i].CumulativeSkillPoints = cumulativeSkillPoints;
                }

                xp.LevelingXpChart = levelingXpChart;
                instance           = xp;
            }
            return(instance);
        }
Example #4
0
        public static Generator ReadFromDat()
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(0x0E00000D))
            {
                return((Generator)DatManager.PortalDat.FileCache[0x0E00000D]);
            }
            else
            {
                Generator gen = new Generator();

                // Create the datReader for the proper file
                DatReader datReader = DatManager.PortalDat.GetReaderForFile(0x0E00000D);

                gen.Id           = datReader.ReadInt32();
                gen.Name         = "0E00000D";
                gen.Count        = 2;
                datReader.Offset = 16;

                Generator playDay       = new Generator();
                Generator weenieObjects = new Generator();
                gen.Items.Add(playDay.GetNextGenerator(datReader));       // Parse and add PlayDay hierarchy
                gen.Items.Add(weenieObjects.GetNextGenerator(datReader)); // Parse and add WeenieObjects hierarchy

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[0x0E00000D] = gen;
                return(gen);
            }
        }
Example #5
0
        public static SetLightHook ReadHookType(DatReader datReader)
        {
            SetLightHook hook = new SetLightHook();

            hook.LightsOn = datReader.ReadInt32();
            return(hook);
        }
Example #6
0
        public static EtherealHook ReadHookType(DatReader datReader)
        {
            EtherealHook e = new EtherealHook();

            e.Ethereal = datReader.ReadInt32();
            return(e);
        }
Example #7
0
        public Generator GetNextGenerator(DatReader datReader)
        {
            Name = datReader.ReadObfuscatedString();
            datReader.AlignBoundary();
            Id    = datReader.ReadInt32();
            Count = datReader.ReadInt32();

            // Console.WriteLine($"{Id:X8} {Count:X8} {Name}");

            for (var i = 0; i < Count; i++)
            {
                var child = new Generator();
                child = child.GetNextGenerator(datReader);
                Items.Add(child);
            }
            return(this);
        }
Example #8
0
        public static BSPLeaf ReadLeaf(DatReader datReader, BSPType treeType)
        {
            BSPLeaf obj = new BSPLeaf();

            obj.Type      = 0x4C454146; // LEAF
            obj.LeafIndex = datReader.ReadInt32();

            if (treeType == BSPType.Physics)
            {
                obj.Solid = datReader.ReadInt32();
                // Note that if Solid is equal to 0, these values will basically be null. Still read them, but they don't mean anything.
                obj.Sphere = CSphere.Read(datReader);

                uint numPolys = datReader.ReadUInt32();
                for (uint i = 0; i < numPolys; i++)
                {
                    obj.InPolys.Add(datReader.ReadUInt16());
                }
            }

            return(obj);
        }
Example #9
0
        public static CVertexArray Read(DatReader datReader)
        {
            CVertexArray obj = new CVertexArray();

            obj.VertexType = datReader.ReadInt32();

            uint num_vertices = datReader.ReadUInt32();

            if (obj.VertexType == 1)
            {
                for (uint i = 0; i < num_vertices; i++)
                {
                    short vert_id = datReader.ReadInt16();
                    obj.Vertices.Add(vert_id, SWVertex.Read(datReader));
                }
            }

            return(obj);
        }
Example #10
0
        public static Generator ReadFromDat()
        {
            Generator gen = new Generator();

            // Create the datReader for the proper file
            DatReader datReader = DatManager.PortalDat.GetReaderForFile(0x0E00000D);

            gen.Id = datReader.ReadInt32();
            gen.Name = "0E00000D";
            gen.Count = 2;
            datReader.Offset = 16;

            Generator playDay = new Generator();
            Generator weenieObjects = new Generator();
            gen.Items.Add(playDay.GetNextGenerator(datReader)); // Parse and add PlayDay hierarchy
            gen.Items.Add(weenieObjects.GetNextGenerator(datReader)); // Parse and add WeenieObjects hierarchy

            return gen;
        }
Example #11
0
        public static Polygon Read(DatReader datReader)
        {
            Polygon obj = new Polygon();

            obj.NumPts     = datReader.ReadByte();
            obj.Stippling  = datReader.ReadByte();
            obj.SidesType  = datReader.ReadInt32();
            obj.PosSurface = datReader.ReadInt16();
            obj.NegSurface = datReader.ReadInt16();

            for (short i = 0; i < obj.NumPts; i++)
            {
                obj.VertexIds.Add(datReader.ReadInt16());
            }

            if ((obj.Stippling & 4) == 0)
            {
                for (short i = 0; i < obj.NumPts; i++)
                {
                    obj.PosUVIndices.Add(datReader.ReadByte());
                }
            }

            if (obj.SidesType == 2 && ((obj.Stippling & 8) == 0))
            {
                for (short i = 0; i < obj.NumPts; i++)
                {
                    obj.NegUVIndices.Add(datReader.ReadByte());
                }
            }

            if (obj.SidesType == 1)
            {
                obj.NegSurface   = obj.PosSurface;
                obj.NegUVIndices = obj.PosUVIndices;
            }

            return(obj);
        }
Example #12
0
        public static CharGen ReadFromDat()
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(0x0E000002))
            {
                return((CharGen)DatManager.PortalDat.FileCache[0x0E000002]);
            }
            else
            {
                // Create the datReader for the proper file
                DatReader datReader = DatManager.PortalDat.GetReaderForFile(0x0E000002);
                CharGen   cg        = new CharGen();

                cg.Did           = datReader.ReadInt32();
                datReader.Offset = 8;

                /// STARTER AREAS. There are 5 dungeons per starting city, and one landscape span for Olthoi.
                int numStarterAreas = datReader.ReadByte();
                for (int i = 0; i < numStarterAreas; i++)
                {
                    string starterAreaName = datReader.ReadPString();

                    int        numAreas     = datReader.ReadByte();
                    List <Loc> starterAreas = new List <Loc>();
                    for (int j = 0; j < numAreas; j++)
                    {
                        Loc starterArea = new Loc(datReader.ReadInt32(), datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle());
                        starterAreas.Add(starterArea);
                    }

                    cg.StarterAreas.Add(starterAreas);
                }

                /// HERITAGE GROUPS -- 11 standard player races and 2 Olthoi.
                datReader.Offset++; // Not sure what this byte 0x01 is indicating, but we'll skip it because we can.
                int heritageGroupCount = datReader.ReadByte();
                for (int i = 0; i < heritageGroupCount; i++)
                {
                    HeritageGroupCG heritage      = new HeritageGroupCG();
                    int             heritageIndex = datReader.ReadInt32();
                    heritage.Name               = datReader.ReadPString();
                    heritage.IconImage          = datReader.ReadUInt32();
                    heritage.SetupID            = datReader.ReadUInt32();
                    heritage.EnvironmentSetupID = datReader.ReadUInt32();
                    heritage.AttributeCredits   = datReader.ReadUInt32();
                    heritage.SkillCredits       = datReader.ReadUInt32();

                    // Start Areas correspond go the CG.StarterAreas List.
                    int numPrimaryStartAreas = datReader.ReadByte();
                    for (int j = 0; j < numPrimaryStartAreas; j++)
                    {
                        heritage.PrimaryStartAreaList.Add(datReader.ReadInt32());
                    }

                    int numSecondaryStartAreas = datReader.ReadByte();
                    for (int j = 0; j < numSecondaryStartAreas; j++)
                    {
                        heritage.SecondaryStartAreaList.Add(datReader.ReadInt32());
                    }

                    // Racial Skills
                    int skillCount = datReader.ReadByte();
                    for (int j = 0; j < skillCount; j++)
                    {
                        SkillCG skill = new SkillCG();
                        skill.SkillNum    = datReader.ReadUInt32();
                        skill.NormalCost  = datReader.ReadUInt32();
                        skill.PrimaryCost = datReader.ReadUInt32();
                        heritage.SkillList.Add(skill);
                    }

                    // Adventurer, Bow Hunter, etc.
                    int templateCount = datReader.ReadByte();
                    for (int j = 0; j < templateCount; j++)
                    {
                        TemplateCG template = new TemplateCG();
                        template.Name      = datReader.ReadPString();
                        template.IconImage = datReader.ReadUInt32();
                        template.Title     = datReader.ReadUInt32();
                        // Attributes
                        template.Strength     = datReader.ReadUInt32();
                        template.Endurance    = datReader.ReadUInt32();
                        template.Coordination = datReader.ReadUInt32();
                        template.Quickness    = datReader.ReadUInt32();
                        template.Focus        = datReader.ReadUInt32();
                        template.Self         = datReader.ReadUInt32();

                        skillCount = datReader.ReadByte();
                        for (int k = 0; k < skillCount; k++)
                        {
                            template.NormalSkillsList.Add(datReader.ReadUInt32());
                        }
                        skillCount = datReader.ReadByte();
                        for (int k = 0; k < skillCount; k++)
                        {
                            template.PrimarySkillsList.Add(datReader.ReadUInt32());
                        }

                        heritage.TemplateList.Add(template);
                    }

                    datReader.Offset++;                    // 0x01 byte here. Not sure what/why, so skip it!
                    int numGenders = datReader.ReadByte(); // this is always 2, but let's read it anyways...
                    for (int j = 0; j < numGenders; j++)
                    {
                        SexCG sex      = new SexCG();
                        int   genderID = datReader.ReadInt32();
                        sex.Name         = datReader.ReadPString();
                        sex.Scale        = datReader.ReadUInt32();
                        sex.SetupID      = datReader.ReadUInt32();
                        sex.SoundTable   = datReader.ReadUInt32();
                        sex.IconImage    = datReader.ReadUInt32();
                        sex.BasePalette  = datReader.ReadUInt32();
                        sex.SkinPalSet   = datReader.ReadUInt32();
                        sex.PhysicsTable = datReader.ReadUInt32();
                        sex.MotionTable  = datReader.ReadUInt32();
                        sex.CombatTable  = datReader.ReadUInt32();

                        sex.BaseObjDesc = ObjDesc.ReadFromDat(ref datReader);

                        int numHairColors = datReader.ReadByte();
                        for (int k = 0; k < numHairColors; k++)
                        {
                            sex.HairColorList.Add(datReader.ReadUInt32());
                        }

                        int numHairStyles = datReader.ReadByte();
                        for (int k = 0; k < numHairStyles; k++)
                        {
                            HairStyleCG hairstyle = new HairStyleCG();
                            hairstyle.IconImage      = datReader.ReadUInt32();
                            hairstyle.Bald           = Convert.ToBoolean(datReader.ReadByte());
                            hairstyle.AlternateSetup = datReader.ReadUInt32();
                            hairstyle.ObjDesc        = ObjDesc.ReadFromDat(ref datReader);
                            sex.HairStyleList.Add(hairstyle);
                        }

                        int numEyeColors = datReader.ReadByte();
                        for (int k = 0; k < numEyeColors; k++)
                        {
                            sex.EyeColorList.Add(datReader.ReadUInt32());
                        }

                        int numEyeStrips = datReader.ReadByte();
                        for (int k = 0; k < numEyeStrips; k++)
                        {
                            EyeStripCG eyestrip = new EyeStripCG();
                            eyestrip.IconImage     = datReader.ReadUInt32();
                            eyestrip.IconImageBald = datReader.ReadUInt32();
                            eyestrip.ObjDesc       = ObjDesc.ReadFromDat(ref datReader);
                            eyestrip.ObjDescBald   = ObjDesc.ReadFromDat(ref datReader);
                            sex.EyeStripList.Add(eyestrip);
                        }

                        int numNoseStrips = datReader.ReadByte(); // Breathe Right?
                        for (int k = 0; k < numNoseStrips; k++)
                        {
                            FaceStripCG nosestrip = new FaceStripCG();
                            nosestrip.IconImage = datReader.ReadUInt32();
                            nosestrip.ObjDesc   = ObjDesc.ReadFromDat(ref datReader);
                            sex.NoseStripList.Add(nosestrip);
                        }

                        int numMouthStrips = datReader.ReadByte(); // Breathe Right?
                        for (int k = 0; k < numMouthStrips; k++)
                        {
                            FaceStripCG mouthstrip = new FaceStripCG();
                            mouthstrip.IconImage = datReader.ReadUInt32();
                            mouthstrip.ObjDesc   = ObjDesc.ReadFromDat(ref datReader);
                            sex.MouthStripList.Add(mouthstrip);
                        }

                        int numHeadGear = datReader.ReadByte();
                        for (int k = 0; k < numHeadGear; k++)
                        {
                            GearCG headgear = new GearCG();
                            headgear.Name          = datReader.ReadPString();
                            headgear.ClothingTable = datReader.ReadUInt32();
                            headgear.WeenieDefault = datReader.ReadUInt32();
                            sex.HeadgearList.Add(headgear);
                        }

                        int numShirts = datReader.ReadByte();
                        for (int k = 0; k < numShirts; k++)
                        {
                            GearCG shirt = new GearCG();
                            shirt.Name          = datReader.ReadPString();
                            shirt.ClothingTable = datReader.ReadUInt32();
                            shirt.WeenieDefault = datReader.ReadUInt32();
                            sex.ShirtList.Add(shirt);
                        }

                        int numPants = datReader.ReadByte();
                        for (int k = 0; k < numPants; k++)
                        {
                            GearCG pants = new GearCG();
                            pants.Name          = datReader.ReadPString();
                            pants.ClothingTable = datReader.ReadUInt32();
                            pants.WeenieDefault = datReader.ReadUInt32();
                            sex.PantsList.Add(pants);
                        }

                        int numFootwear = datReader.ReadByte();
                        for (int k = 0; k < numFootwear; k++)
                        {
                            GearCG footwear = new GearCG();
                            footwear.Name          = datReader.ReadPString();
                            footwear.ClothingTable = datReader.ReadUInt32();
                            footwear.WeenieDefault = datReader.ReadUInt32();
                            sex.FootwearList.Add(footwear);
                        }

                        int numClothingColors = datReader.ReadByte();
                        for (int k = 0; k < numClothingColors; k++)
                        {
                            sex.ClothingColorsList.Add(datReader.ReadUInt32());
                        }

                        heritage.SexList.Add(genderID, sex);
                    }

                    cg.HeritageGroups.Add(heritageIndex, heritage);
                }
                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[0x0E000002] = cg;
                return(cg);
            }
        }
Example #13
0
        public static ParticleEmitterInfo ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((ParticleEmitterInfo)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                DatReader           datReader = DatManager.PortalDat.GetReaderForFile(fileId);
                ParticleEmitterInfo obj       = new ParticleEmitterInfo();

                obj.Id = datReader.ReadUInt32();

                uint unknown = datReader.ReadUInt32();

                obj.EmitterType  = (EmitterType)datReader.ReadInt32();
                obj.ParticleType = (ParticleType)datReader.ReadInt32();

                obj.GfxObjId   = datReader.ReadUInt32();
                obj.HwGfxObjId = datReader.ReadUInt32();

                obj.Birthrate = datReader.ReadDouble();

                obj.MaxParticles     = datReader.ReadInt32();
                obj.InitialParticles = datReader.ReadInt32();
                obj.TotalParticles   = datReader.ReadInt32();

                obj.TotalSeconds = datReader.ReadDouble();
                obj.LifespanRand = datReader.ReadDouble();
                obj.Lifespan     = datReader.ReadDouble();

                obj.SortingSphere = datReader.ReadUInt32();

                obj.OffsetDir = PositionExtensions.ReadPositionFrame(datReader);
                obj.MinOffset = datReader.ReadSingle();
                obj.MaxOffset = datReader.ReadSingle();

                obj.A = PositionExtensions.ReadPositionFrame(datReader);
                obj.B = PositionExtensions.ReadPositionFrame(datReader);
                obj.C = PositionExtensions.ReadPositionFrame(datReader);

                obj.MinA = datReader.ReadSingle();
                obj.MaxA = datReader.ReadSingle();
                obj.MinB = datReader.ReadSingle();
                obj.MaxB = datReader.ReadSingle();
                obj.MinC = datReader.ReadSingle();
                obj.MaxC = datReader.ReadSingle();

                obj.ScaleRand  = datReader.ReadSingle();
                obj.StartScale = datReader.ReadSingle();
                obj.FinalScale = datReader.ReadSingle();
                obj.TransRand  = datReader.ReadSingle();
                obj.StartTrans = datReader.ReadSingle();
                obj.FinalTrans = datReader.ReadSingle();

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = obj;

                return(obj);
            }
        }
Example #14
0
        } = new Dictionary <uint, CloSubPalEffect>();                                                                           // uint is a non-zero index

        public static ClothingTable ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((ClothingTable)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                ClothingTable ct        = new ClothingTable();
                DatReader     datReader = DatManager.PortalDat.GetReaderForFile(fileId);

                ct.Id = datReader.ReadUInt32();

                uint numClothingEffects = datReader.ReadUInt16();
                datReader.Offset += 2;
                for (uint i = 0; i < numClothingEffects; i++)
                {
                    ClothingBaseEffect cb = new ClothingBaseEffect();
                    cb.SetupModel = datReader.ReadUInt32();
                    int numObjectEffects = datReader.ReadInt32();
                    for (int j = 0; j < numObjectEffects; j++)
                    {
                        CloObjectEffect cloObjEffect = new CloObjectEffect();
                        cloObjEffect.Index   = datReader.ReadUInt32();
                        cloObjEffect.ModelId = datReader.ReadUInt32();
                        uint numTextureEffects = datReader.ReadUInt32();

                        for (uint k = 0; k < numTextureEffects; k++)
                        {
                            CloTextureEffect cloTexEffect = new CloTextureEffect();
                            cloTexEffect.OldTexture = datReader.ReadUInt32();
                            cloTexEffect.NewTexture = datReader.ReadUInt32();
                            cloObjEffect.CloTextureEffects.Add(cloTexEffect);
                        }

                        cb.CloObjectEffects.Add(cloObjEffect);
                    }
                    ct.ClothingBaseEffects.Add(cb.SetupModel, cb);
                }

                ushort numSubPalEffects = datReader.ReadUInt16();
                for (uint i = 0; i < numSubPalEffects; i++)
                {
                    datReader.AlignBoundary();
                    CloSubPalEffect cloSubPalEffect = new CloSubPalEffect();
                    uint            subPalIdx       = datReader.ReadUInt32();
                    cloSubPalEffect.Icon = datReader.ReadUInt32();
                    uint numPalettes = datReader.ReadUInt32();
                    for (uint j = 0; j < numPalettes; j++)
                    {
                        CloSubPalette cloSubPalette = new CloSubPalette();
                        uint          length        = datReader.ReadUInt32();
                        for (uint k = 0; k < length; k++)
                        {
                            CloSubPalleteRange range = new CloSubPalleteRange();
                            range.Offset    = datReader.ReadUInt32();
                            range.NumColors = datReader.ReadUInt32();
                            cloSubPalette.Ranges.Add(range);
                        }
                        cloSubPalette.PaletteSet = datReader.ReadUInt32();
                        cloSubPalEffect.CloSubPalettes.Add(cloSubPalette);
                    }
                    ct.ClothingSubPalEffects.Add(subPalIdx, cloSubPalEffect);
                }

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = ct;
                return(ct);
            }
        }
Example #15
0
        public static SetupModel ReadFromDat(DatReader datReader)
        {
            SetupModel m = new SetupModel();

            m.ModelId = datReader.ReadUInt32();

            m.TypeId = datReader.ReadUInt32();

            if ((m.TypeId & 4) == 1)
            {
                m.Type4 = true;
            }
            else
            {
                m.Type4 = false;
            }

            if ((m.TypeId & 8) == 1)
            {
                m.Type8 = true;
            }
            else
            {
                m.Type8 = false;
            }

            // Get all the GraphicsObjects in this SetupModel. These are all the 01-types.
            uint numSubObjects = datReader.ReadUInt32();

            for (int i = 0; i < numSubObjects; i++)
            {
                m.SubObjectIds.Add(datReader.ReadUInt32());
            }

            if ((m.TypeId & 1) == 1)
            {
                for (int i = 0; i < numSubObjects; i++)
                {
                    m.ObjectUnks.Add(datReader.ReadUInt32());
                }
            }

            if ((m.TypeId & 2) == 1)
            {
                for (int i = 0; i < numSubObjects; i++)
                {
                    m.ObjectScales.Add(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()));
                }
            }

            m.LT94Count       = datReader.ReadInt32();
            datReader.Offset += (9 * 4 * m.LT94Count); // skip over the LT94 Objects. Some sort of location/positional data.

            m.LT98Count       = datReader.ReadInt32();
            datReader.Offset += (9 * 4 * m.LT98Count); // skip over the LT98 Objects. Some other sort of location/positional data.

            int placementsCount = datReader.ReadInt32();

            for (int i = 0; i < placementsCount; i++)
            {
                uint key = datReader.ReadUInt32();
                // there is a frame for each SubObject
                datReader.Offset += m.SubObjectIds.Count * 7 * 4; // This is frame data. Vector3 + Quaternion.

                uint hookCount = datReader.ReadUInt32();
                for (int j = 0; i < hookCount; j++)
                {
                    // TODO: Handle this! HOWEVER, no objects appear to actually use this. At least none currently parsed as of 2017-03-29.
                }
            }

            int cylinderSphereCount = datReader.ReadInt32();

            for (int i = 0; i < cylinderSphereCount; i++)
            {
                // Sphere is a Vector3 origin + float radius
                AceVector3 origin = new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle());
                m.CylSpheres.Add(new CylSphere(origin, datReader.ReadSingle(), datReader.ReadSingle()));
            }

            int sphereCount = datReader.ReadInt32();

            for (int i = 0; i < sphereCount; i++)
            {
                // Sphere is a Vector3 origin + float radius
                AceVector3 origin = new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle());
                m.Spheres.Add(new CSphere(origin, datReader.ReadSingle()));
            }

            m.Height         = datReader.ReadSingle();
            m.Radius         = datReader.ReadSingle();
            m.StepDownHeight = datReader.ReadSingle();
            m.StepUpHeight   = datReader.ReadSingle();

            m.SortingSphere   = new CSphere(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()), datReader.ReadSingle());
            m.SelectionSphere = new CSphere(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()), datReader.ReadSingle());

            int lightCount = datReader.ReadInt32();

            // Light is made up of a Int32 uknown, Frame (Vector3 + Quaternion), int32 RGBColor, float unknown, float uknown and int32 unknown
            datReader.Offset += 12 * 4 * lightCount;

            m.DefaultAnimation   = datReader.ReadUInt32();
            m.DefaultScript      = datReader.ReadUInt32();
            m.DefaultMotionTable = datReader.ReadUInt32();
            m.DefaultSoundTable  = datReader.ReadUInt32();
            m.DefaultScriptTable = datReader.ReadUInt32();

            return(m);
        }
Example #16
0
        } = new Dictionary <uint, CloSubPalEffect>();                                                                           // uint is a non-zero index

        public static ClothingTable ReadFromDat(uint fileId)
        {
            ClothingTable ct        = new ClothingTable();
            DatReader     datReader = DatManager.PortalDat.GetReaderForFile(fileId);

            ct.Id = datReader.ReadUInt32();

            uint numClothingEffects = datReader.ReadUInt16();

            datReader.Offset += 2;
            for (uint i = 0; i < numClothingEffects; i++)
            {
                ClothingBaseEffect cb = new ClothingBaseEffect();
                cb.SetupModel = datReader.ReadUInt32();
                int numObjectEffects = datReader.ReadInt32();
                for (int j = 0; j < numObjectEffects; j++)
                {
                    CloObjectEffect cloObjEffect = new CloObjectEffect();
                    cloObjEffect.Index   = datReader.ReadUInt32();
                    cloObjEffect.ModelId = datReader.ReadUInt32();
                    uint numTextureEffects = datReader.ReadUInt32();

                    for (uint k = 0; k < numTextureEffects; k++)
                    {
                        CloTextureEffect cloTexEffect = new CloTextureEffect();
                        cloTexEffect.OldTexture = datReader.ReadUInt32();
                        cloTexEffect.NewTexture = datReader.ReadUInt32();
                        cloObjEffect.CloTextureEffects.Add(cloTexEffect);
                    }

                    cb.CloObjectEffects.Add(cloObjEffect);
                }
                ct.ClothingBaseEffects.Add(cb.SetupModel, cb);
            }

            ushort numSubPalEffects = datReader.ReadUInt16();

            for (uint i = 0; i < numSubPalEffects; i++)
            {
                datReader.AlignBoundary();
                CloSubPalEffect cloSubPalEffect = new CloSubPalEffect();
                uint            subPalIdx       = datReader.ReadUInt32();
                cloSubPalEffect.Icon = datReader.ReadUInt32();
                uint numPalettes = datReader.ReadUInt32();
                for (uint j = 0; j < numPalettes; j++)
                {
                    CloSubPalette cloSubPalette = new CloSubPalette();
                    uint          length        = datReader.ReadUInt32();
                    for (uint k = 0; k < length; k++)
                    {
                        CloSubPalleteRange range = new CloSubPalleteRange();
                        range.Offset    = datReader.ReadUInt32();
                        range.NumColors = datReader.ReadUInt32();
                        cloSubPalette.Ranges.Add(range);
                    }
                    cloSubPalette.PaletteSet = datReader.ReadUInt32();
                    cloSubPalEffect.CloSubPalettes.Add(cloSubPalette);
                }
                ct.ClothingSubPalEffects.Add(subPalIdx, cloSubPalEffect);
            }
            return(ct);
        }
Example #17
0
        public static SetupModel ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((SetupModel)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                DatReader  datReader = DatManager.PortalDat.GetReaderForFile(fileId);
                SetupModel m         = new SetupModel();
                m.ModelId = datReader.ReadUInt32();

                m.Bitfield = datReader.ReadUInt32();

                // Get all the GraphicsObjects in this SetupModel. These are all the 01-types.
                uint numParts = datReader.ReadUInt32();
                for (int i = 0; i < numParts; i++)
                {
                    m.Parts.Add(datReader.ReadUInt32());
                }

                if ((m.Bitfield & 1) > 0)
                {
                    for (int i = 0; i < numParts; i++)
                    {
                        m.ParentIndex.Add(datReader.ReadUInt32());
                    }
                }

                if ((m.Bitfield & 2) > 0)
                {
                    for (int i = 0; i < numParts; i++)
                    {
                        m.DefaultScale.Add(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()));
                    }
                }

                int numHoldingLocations = datReader.ReadInt32();
                if (numHoldingLocations > 0)
                {
                    for (int i = 0; i < numHoldingLocations; i++)
                    {
                        int key = datReader.ReadInt32();
                        m.HoldingLocations.Add(key, LocationType.Read(datReader));
                    }
                }

                int numConnectionPoints = datReader.ReadInt32();
                if (numConnectionPoints > 0)
                {
                    for (int i = 0; i < numConnectionPoints; i++)
                    {
                        int key = datReader.ReadInt32();
                        m.ConnectionPoints.Add(key, LocationType.Read(datReader));
                    }
                }

                int placementsCount = datReader.ReadInt32();
                for (int i = 0; i < placementsCount; i++)
                {
                    int key = datReader.ReadInt32();
                    // there is a frame for each Part
                    m.PlacementFrames.Add(key, PlacementType.Read(m.Parts.Count, datReader));
                }

                int cylinderSphereCount = datReader.ReadInt32();
                for (int i = 0; i < cylinderSphereCount; i++)
                {
                    // Sphere is a Vector3 origin + float radius
                    AceVector3 origin = new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle());
                    m.CylSpheres.Add(new CylSphere(origin, datReader.ReadSingle(), datReader.ReadSingle()));
                }

                int sphereCount = datReader.ReadInt32();
                for (int i = 0; i < sphereCount; i++)
                {
                    // Sphere is a Vector3 origin + float radius
                    AceVector3 origin = new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle());
                    m.Spheres.Add(new CSphere(origin, datReader.ReadSingle()));
                }

                m.Height         = datReader.ReadSingle();
                m.Radius         = datReader.ReadSingle();
                m.StepDownHeight = datReader.ReadSingle();
                m.StepUpHeight   = datReader.ReadSingle();

                m.SortingSphere   = new CSphere(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()), datReader.ReadSingle());
                m.SelectionSphere = new CSphere(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()), datReader.ReadSingle());

                int numLights = datReader.ReadInt32();
                if (numLights > 0)
                {
                    for (int i = 0; i < numLights; i++)
                    {
                        int key = datReader.ReadInt32();
                        m.Lights.Add(key, LightInfo.Read(datReader));
                    }
                }

                m.DefaultAnimation   = datReader.ReadUInt32();
                m.DefaultScript      = datReader.ReadUInt32();
                m.DefaultMotionTable = datReader.ReadUInt32();
                m.DefaultSoundTable  = datReader.ReadUInt32();
                m.DefaultScriptTable = datReader.ReadUInt32();

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = m;

                return(m);
            }
        }