Ejemplo n.º 1
0
        public static MotionData Read(DatReader datReader)
        {
            MotionData md = new Entity.MotionData();

            byte numAnims = datReader.ReadByte();

            md.Bitfield  = datReader.ReadByte();
            md.Bitfield2 = datReader.ReadByte();
            datReader.AlignBoundary();

            for (byte i = 0; i < numAnims; i++)
            {
                AnimData animData = new AnimData();
                animData.AnimId    = datReader.ReadUInt32();
                animData.LowFrame  = datReader.ReadUInt32();
                animData.HighFrame = datReader.ReadUInt32();
                animData.Framerate = datReader.ReadSingle();
                md.Anims.Add(animData);
            }

            if ((md.Bitfield2 & 1) > 0)
            {
                md.Velocity = new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle());
            }

            if ((md.Bitfield2 & 2) > 0)
            {
                md.Omega = new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle());
            }

            return(md);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the structure of a CellLandblock from the client_cell.dat
        /// </summary>
        /// <param name="landblockId">Either a full int of the landblock or just the short of the cell itself</param>
        /// <returns></returns>
        public static CellLandblock ReadFromDat(uint landblockId)
        {
            CellLandblock c = new CellLandblock();

            // Check if landblockId is a full dword. We just need the hiword for the landblockId
            if ((landblockId >> 16) != 0)
            {
                landblockId = landblockId >> 16;
            }

            // The file index is CELL + 0xFFFF. e.g. a cell of 1234, the file index would be 0x1234FFFF.
            uint landblockFileIndex = (landblockId << 16) + 0xFFFF;

            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.CellDat.FileCache.ContainsKey(landblockFileIndex))
            {
                return((CellLandblock)DatManager.CellDat.FileCache[landblockFileIndex]);
            }
            else
            {
                if (DatManager.CellDat.AllFiles.ContainsKey(landblockFileIndex))
                {
                    DatReader datReader = DatManager.CellDat.GetReaderForFile(landblockFileIndex);
                    uint      cellId    = datReader.ReadUInt32();

                    uint hasObjects = datReader.ReadUInt32();
                    if (hasObjects == 1)
                    {
                        c.HasObjects = true;
                    }

                    // Read in the terrain. 9x9 so 81 records.
                    for (int i = 0; i < 81; i++)
                    {
                        uint terrain = datReader.ReadUInt16();
                        c.Terrain.Add(terrain);
                    }
                    // Read in the height. 9x9 so 81 records
                    for (int i = 0; i < 81; i++)
                    {
                        ushort height = datReader.ReadByte();
                        c.Height.Add(height);
                    }
                }

                // Store this object in the FileCache
                DatManager.CellDat.FileCache[landblockFileIndex] = c;

                return(c);
            }
        }
Ejemplo n.º 4
0
        public static ObjDesc ReadFromDat(ref DatReader datReader)
        {
            ObjDesc od = new ObjDesc();

            datReader.AlignBoundary(); // Align to the DWORD boundary before and after the ObjDesc
            datReader.ReadByte();      // ObjDesc always starts with 11.
            int numPalettes          = datReader.ReadByte();
            int numTextureMapChanges = datReader.ReadByte();
            int numAnimPartChanges   = datReader.ReadByte();

            for (int k = 0; k < numPalettes; k++)
            {
                // TODO - This isn't actually used anywhere in the CharGen system, so let's find a test care to make sure this is accurate!
                SubPalette subpalette = new SubPalette();
                subpalette.SubID     = datReader.ReadUInt16();
                subpalette.SubID     = datReader.ReadUInt16();
                subpalette.NumColors = Convert.ToUInt16(datReader.ReadByte());
                od.SubPalettes.Add(subpalette);
            }
            for (int k = 0; k < numTextureMapChanges; k++)
            {
                TextureMapChange texturechange = new TextureMapChange();
                texturechange.PartIndex  = datReader.ReadByte();
                texturechange.OldTexture = datReader.ReadUInt16();
                texturechange.NewTexture = datReader.ReadUInt16();
                od.TextureChanges.Add(texturechange);
            }
            for (int k = 0; k < numAnimPartChanges; k++)
            {
                AnimationPartChange apchange = new AnimationPartChange();
                apchange.PartIndex = datReader.ReadByte();
                apchange.PartID    = datReader.ReadUInt16();
                if (apchange.PartID == 0x8000) // To be honest, I'm not quite sure WHAT this is/means, but the math works out
                {
                    apchange.PartID = datReader.ReadUInt16();
                }
                apchange.PartID += 0x01000000u; // convert to full uint value
                od.AnimPartChanges.Add(apchange);
            }
            datReader.AlignBoundary(); // Align to the DWORD boundary before and after the ObjDesc

            return(od);
        }
Ejemplo n.º 5
0
        } = new List <Stab>();                                       // List of objects in the cell and their positions

        /// <summary>
        /// Load the EnvCell (Dungeon/Interior Block) from the client_cell.dat
        /// </summary>
        /// <param name="landblockId">The full int32/dword landblock value as reported by the @loc command (e.g. 0x12345678)</param>
        /// <returns></returns>
        public static EnvCell ReadFromDat(uint landblockId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.CellDat.FileCache.ContainsKey(landblockId))
            {
                return((EnvCell)DatManager.CellDat.FileCache[landblockId]);
            }
            else
            {
                EnvCell c = new EnvCell();

                if (DatManager.CellDat.AllFiles.ContainsKey(landblockId))
                {
                    DatReader datReader = DatManager.CellDat.GetReaderForFile(landblockId);
                    c.CellId          = datReader.ReadUInt32();
                    c.Bitfield        = datReader.ReadUInt32();
                    datReader.Offset += 4; // Skip ahead 4 bytes, because this is the CellId. Again. Twice.

                    byte numTextures = datReader.ReadByte();

                    // Note that "portal" in this context does not refer to the swirly pink/purple thing, its basically connecting cells
                    byte numPortals = datReader.ReadByte();

                    // I believe this is what cells can be seen from this one. So the engine knows what else it needs to load/draw.
                    ushort numVisibleBlocks = datReader.ReadUInt16();

                    // Read what textures are used in this cell
                    for (uint i = 0; i < numTextures; i++)
                    {
                        c.Textures.Add(0x08000000u + datReader.ReadUInt16()); // these are stored in the dat as short vals, so we'll make them a full dword
                    }

                    c.EnvironmentId = (0x0D000000u + datReader.ReadUInt16());
                    c.CellStructure = datReader.ReadUInt16();

                    c.Position             = new Position();
                    c.Position.LandblockId = new LandblockId(landblockId);
                    c.Position.PositionX   = datReader.ReadSingle();
                    c.Position.PositionY   = datReader.ReadSingle();
                    c.Position.PositionZ   = datReader.ReadSingle();
                    c.Position.RotationW   = datReader.ReadSingle();
                    c.Position.RotationX   = datReader.ReadSingle();
                    c.Position.RotationY   = datReader.ReadSingle();
                    c.Position.RotationZ   = datReader.ReadSingle();

                    for (uint i = 0; i < numPortals; i++)
                    {
                        CellPortal cp = new CellPortal();
                        cp.Flags         = datReader.ReadUInt16();
                        cp.EnvironmentId = datReader.ReadUInt16();
                        cp.OtherCellId   = datReader.ReadUInt16();
                        cp.OtherPortalId = datReader.ReadUInt16();
                        cp.ExactMatch    = (byte)(cp.Flags & 1);
                        cp.PortalSide    = (byte)((cp.Flags >> 1) & 1);
                        c.CellPortals.Add(cp);
                    }

                    for (uint i = 0; i < numVisibleBlocks; i++)
                    {
                        c.VisibleBlocks.Add(datReader.ReadUInt16());
                    }

                    uint numObjects = datReader.ReadUInt32();
                    for (uint i = 0; i < numObjects; i++)
                    {
                        Stab s = new Stab();
                        s.Model = datReader.ReadUInt32();
                        s.Position.LandblockId = new LandblockId(landblockId);
                        s.Position.PositionX   = datReader.ReadSingle();
                        s.Position.PositionY   = datReader.ReadSingle();
                        s.Position.PositionZ   = datReader.ReadSingle();
                        s.Position.RotationW   = datReader.ReadSingle();
                        s.Position.RotationX   = datReader.ReadSingle();
                        s.Position.RotationY   = datReader.ReadSingle();
                        s.Position.RotationZ   = datReader.ReadSingle();
                        c.StabList.Add(s);
                    }
                }

                // Store this object in the FileCache
                DatManager.CellDat.FileCache[landblockId] = c;
                return(c);
            }
        }
Ejemplo n.º 6
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);
            }
        }