Beispiel #1
0
        /// <summary>
        /// The display bitmap.
        /// </summary>
        /// <param name="bitmap">The bitmap.</param>
        /// <param name="chunk">The chunk.</param>
        /// <param name="mipmap">The mipmap.</param>
        /// <remarks></remarks>
        public void DisplayBitmap(int bitmap, int chunk, int mipmap)
        {
            pictureBox1.Image = pm.FindChunkAndDecode(
                bitmap, chunk, mipmap, ref map.SelectedMeta, map, chunk, 0);

            ParsedBitmap.BitmapInfo bmInfo = new ParsedBitmap.BitmapInfo(
                pm.Properties[0].formatname, pm.Properties[0].swizzle);

            ////////////// Remove this. For testing Decoding/Encoding ///////////////
            // if (!pm.Properties[0].formatname.ToString().ToUpper().Contains("DXT"))
            // pictureBox1.Image = DDS_Convert.DecodeDDS(DDS_Convert.EncodeDDS((Bitmap)pictureBox1.Image, ref bmInfo), bmInfo);
            pictureBox1.Width    = (pictureBox1.Image.Width * trackBar1.Value) / 2;
            pictureBox1.Height   = (pictureBox1.Image.Height * trackBar1.Value) / 2;
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
        }
Beispiel #2
0
        /// <summary>
        /// The tree view 1_ after select.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode.Level == 2)
            {
                currBitm   = treeView1.SelectedNode.Parent.Parent.Index;
                currChunk  = treeView1.SelectedNode.Parent.Index;
                currMipMap = treeView1.SelectedNode.Index;
            }
            else if (treeView1.SelectedNode.Level == 1)
            {
                currBitm   = treeView1.SelectedNode.Parent.Index;
                currChunk  = treeView1.SelectedNode.Index;
                currMipMap = 0;
            }
            else
            {
                currBitm   = treeView1.SelectedNode.Index;
                currChunk  = 0;
                currMipMap = 0;
            }

            DisplayBitmap(currBitm, currChunk, currMipMap);

            object o = ((Form)this.TopLevelControl).ActiveMdiChild;

            if (o is MapForm)
            {
                MapForm      mf   = (MapForm)o;
                Meta         meta = map.SelectedMeta;
                ParsedBitmap pm   = new ParsedBitmap(ref meta, map);

                Bitmap b = pm.FindChunkAndDecode(currBitm, currChunk, currMipMap, ref meta, map, 0, 0);
                mf.pictureBox    = (Bitmap)pictureBox1.Image.Clone();
                mf.statusBarText = (Math.Max(pm.Properties[currBitm].width >> currChunk >> currMipMap, 1)).ToString().PadLeft(4) + " X " +
                                   (Math.Max(pm.Properties[currBitm].height >> currChunk >> currMipMap, 1)).ToString().PadRight(4) + "X " +
                                   (Math.Max(pm.Properties[currBitm].depth >> currChunk >> currMipMap, 1)).ToString().PadRight(4) + " " +
                                   ("(" + pm.Properties[currBitm].typename.ToString().Remove(0, 10) + ") ").PadRight(10) +
                                   pm.Properties[currBitm].formatname.ToString().Remove(0, 12).PadRight(10) + " - Swizzle:" +
                                   pm.Properties[0].swizzle + "- Location: " + meta.raw.rawChunks[0].rawLocation;
            }
        }
Beispiel #3
0
        /// <summary>
        /// The h 2 shader info.
        /// </summary>
        /// <param name="TagIndex">The TagIndex.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void H2ShaderInfo(int TagIndex, Map map)
        {
            bool alreadyOpen = true;

            if (!(map.isOpen && map.openMapType == MapTypes.Internal))
            {
                map.OpenMap(MapTypes.Internal);
                alreadyOpen = false;
            }

            this.TagIndex = TagIndex;
            if (this.TagIndex == -1)
            {
                return;
            }

            this.shaderName            = map.FileNames.Name[this.TagIndex];
            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 4;
            int tempstem = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

            if (tempstem != -1)
            {
                if (map.FileNames.Name[tempstem].IndexOf("alphatest") != -1)
                {
                    this.Alpha = AlphaType.AlphaTest;
                }
                else if (map.FileNames.Name[tempstem].IndexOf("alpha") != -1)
                {
                    this.Alpha = AlphaType.AlphaBlend;
                }
                else if (map.FileNames.Name[tempstem].IndexOf("water") != -1)
                {
                    this.Alpha = AlphaType.AlphaBlend;
                }
                else
                {
                    this.Alpha = AlphaType.None;
                }
            }
            else
            {
                this.Alpha = AlphaType.None;
            }

            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 12;
            int tempc2 = map.BR.ReadInt32();
            int tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            if (tempc2 != 0)
            {
                map.BR.BaseStream.Position = tempr2 + 4;
                int tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                if (tempcrap != -1)
                {
                    Meta tempmeta = new Meta(map);
                    tempmeta.ReadMetaFromMap(tempcrap, false);
                    ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                    this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                    this.MainName   = map.FileNames.Name[tempcrap];
                    this.levels     = pm.Properties[0].mipMapCount;
                }
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 32;
            tempc2 = map.BR.ReadInt32();
            tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            map.BR.BaseStream.Position = tempr2 + 24;
            int fuckr = map.BR.ReadInt32();

            if (fuckr != 0)
            {
                fuckr -= map.SecondaryMagic;
                map.BR.BaseStream.Position = fuckr;
                this.primarydetailuscale   = map.BR.ReadSingle();
                this.primarydetailvscale   = map.BR.ReadSingle();
                this.primarydetailwscale   = map.BR.ReadSingle();
                map.BR.ReadSingle();
                this.secondarydetailuscale = map.BR.ReadSingle();
                this.secondarydetailvscale = map.BR.ReadSingle();
                this.secondarydetailwscale = map.BR.ReadSingle();
            }

            map.BR.BaseStream.Position = tempr2 + 4;
            tempc2 = map.BR.ReadInt32();
            tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            /*
             *
             * for (int x = 0; x < tempc2; x++)
             * {
             *  map.BR.BaseStream.Position = tempr2 + (x * 12);
             *  int tempcrap = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);
             *  if (tempcrap == -1) { continue; }
             *  Meta tempmeta = new Meta(map);
             *  tempmeta.ReadMetaFromMap(tempcrap, map, false);
             *  Raw.ParsedBitmap pm = new Raw.ParsedBitmap(ref tempmeta, map);
             *  Bitmaps.Add(pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0));
             * BitmapNames.Add(map.FileNames.Name[tempcrap]);
             * }
             *
             */
            // map.BR.BaseStream.Position = tempr + 20;
            // tempc2 = map.BR.ReadInt32();
            // tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            // tempc2 = tempc;
            // tempr2 = tempr;
            if (tempc2 != 0)
            {
                map.BR.BaseStream.Position = tempr2;
                int tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                if (tempcrap != -1)
                {
                    int test = map.FileNames.Name[tempcrap].IndexOf("reflection_maps");
                    if (map.FileNames.Name[tempcrap].IndexOf("_bump") != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                        //  this.BumpMapBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.BumpMapName = map.FileNames.Name[tempcrap];
                    }
                    else if (map.FileNames.Name[tempcrap].IndexOf("_cube_map") != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                        //  this.CubeMapBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.CubeMapName = map.FileNames.Name[tempcrap];
                    }
                    else if (map.FileNames.Name[tempcrap].IndexOf("default_") == -1 && this.MainBitmap == null &&
                             test == -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);

                        // Try to load LOD2-MIP3 if that fails, load LOD2-MIP0, otherwise LOD0-MIP0
                        this.MainBitmap = pm.FindChunkAndDecode(0, 2, 3, ref tempmeta, map, 0, 0);
                        if (this.MainBitmap == null)
                        {
                            this.MainBitmap = pm.FindChunkAndDecode(0, 2, 0, ref tempmeta, map, 0, 0);
                            if (this.MainBitmap == null)
                            {
                                this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                            }
                        }

                        this.MainName = map.FileNames.Name[tempcrap];
                        this.levels   = pm.Properties[0].mipMapCount;
                    }
                    else if (test != -1)
                    {
                        map.BR.BaseStream.Position += 8;
                        tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);

                        // this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map);
                        // this.MainName = map.FileNames.Name[tempcrap];
                    }
                }

                map.BR.BaseStream.Position = tempr2 + 24;
                tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                if (tempcrap != -1 && this.MainBitmap == null)
                {
                    Meta tempmeta = new Meta(map);
                    tempmeta.ReadMetaFromMap(tempcrap, false);
                    ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                    this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                    this.MainName   = map.FileNames.Name[tempcrap];
                    this.levels     = pm.Properties[0].mipMapCount;
                }
                else if (this.MainBitmap == null)
                {
                    map.BR.BaseStream.Position = tempr2 + 12;
                    tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    if (tempcrap != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                        this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.MainName   = map.FileNames.Name[tempcrap];
                        this.levels     = pm.Properties[0].mipMapCount;
                    }
                }
            }

            if (!alreadyOpen)
            {
                map.CloseMap();
            }
        }
Beispiel #4
0
        /// <summary>
        /// The ce shader info.
        /// </summary>
        /// <param name="TagIndex">The TagIndex.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void CEShaderInfo(int TagIndex, Map map)
        {
            this.TagIndex = TagIndex;
            if (this.TagIndex == -1)
            {
                return;
            }

            this.shaderName = map.FileNames.Name[this.TagIndex];

            map.OpenMap(MapTypes.Internal);
            int mainid          = 0;
            int primarydetail   = -1;
            int secondarydetail = -1;
            int micro           = -1;

            switch (map.MetaInfo.TagType[TagIndex])
            {
            case "schi":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 228;
                mainid = map.BR.ReadInt32();
                break;

            case "soso":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 176;
                mainid = map.BR.ReadInt32();
                break;

            case "sgla":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 356;
                mainid = map.BR.ReadInt32();
                break;

            case "scex":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 900;
                mainid = map.BR.ReadInt32();
                break;

            case "senv":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 148;
                mainid = map.BR.ReadInt32();
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 180;
                this.primarydetailuscale   = map.BR.ReadSingle();
                this.primarydetailvscale   = this.primarydetailuscale;
                this.primarydetailwscale   = 1;
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 196;
                primarydetail = map.BR.ReadInt32();

                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 200;
                this.secondarydetailuscale = map.BR.ReadSingle();
                this.secondarydetailvscale = this.secondarydetailuscale;
                this.secondarydetailwscale = 1;
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 216;
                secondarydetail            = map.BR.ReadInt32();

                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 248;
                this.microdetailuscale     = map.BR.ReadSingle();
                this.microdetailvscale     = this.secondarydetailuscale;
                this.microdetailwscale     = 1;
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 264;
                micro = map.BR.ReadInt32();

                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 40;
                byte alphatest = map.BR.ReadByte();
                int  test      = alphatest & 1;
                if (test != 0)
                {
                    this.Alpha = AlphaType.AlphaTest;
                }

                break;

            case "swat":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 88;
                mainid = map.BR.ReadInt32();
                break;

            case "smet":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 88;
                mainid = map.BR.ReadInt32();
                break;
            }

            map.CloseMap();

            mainid          = map.Functions.ForMeta.FindMetaByID(mainid);
            primarydetail   = map.Functions.ForMeta.FindMetaByID(primarydetail);
            secondarydetail = map.Functions.ForMeta.FindMetaByID(secondarydetail);
            micro           = map.Functions.ForMeta.FindMetaByID(micro);
            if (mainid == -1)
            {
                return;
            }

            if (map.MetaInfo.external[mainid])
            {
                map.OpenMap(MapTypes.Bitmaps);
            }
            else
            {
                map.OpenMap(MapTypes.Internal);
            }

            Meta tempmeta = new Meta(map);

            tempmeta.ReadMetaFromMap(mainid, false);

            map.CloseMap();
            ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);

            // Attempt to load LOD2, if that fails, load LOD0
            try
            {
                this.MainBitmap = pm.FindChunkAndDecode(0, 2, 0, ref tempmeta, map, 0, 0);
            }
            catch
            {
                this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
            }
            this.MainName = map.FileNames.Name[mainid];

            if (primarydetail != -1)
            {
                if (map.MetaInfo.external[primarydetail])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(primarydetail, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.primarydetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.primarydetailName   = map.FileNames.Name[primarydetail];
            }

            if (secondarydetail != -1)
            {
                if (map.MetaInfo.external[secondarydetail])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(secondarydetail, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.secondarydetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.secondarydetailName   = map.FileNames.Name[secondarydetail];
            }

            if (micro != -1)
            {
                if (map.MetaInfo.external[micro])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(micro, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.microdetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.microdetailName   = map.FileNames.Name[micro];
            }
        }
Beispiel #5
0
        private void loadSkin()
        {
            animation    = new List <animationData>();
            bitmapBlocks = new List <bitmapData>();
            textBlocks   = new List <textBlockData>();
            BinaryReader br  = new BinaryReader(meta.MS);
            BinaryReader br2 = br;

            #region Animation Frames reflexive
            br2 = br;
            br.BaseStream.Position = 20;
            int animationCount  = br.ReadInt32();
            int animationOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int animationTag = map.Functions.ForMeta.FindMetaByOffset(animationOffset);
            if (animationCount > 0 && animationTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(animationTag, meta.Map, false, true);
                br2              = new BinaryReader(newMeta.MS);
                animationOffset -= newMeta.offset;
            }
            else
            {
                animationOffset -= meta.offset;
            }

            for (int list = 0; list < animationCount; list++)
            {
                animationData ad = new animationData(list, meta);
                ad.offset = animationOffset + list * 16;
                ad.Read(br2);
                this.animation.Add(ad);
            }
            #endregion

            #region Text blocks reflexive
            br2 = br;
            br.BaseStream.Position = 28;
            int textBlockCount  = br.ReadInt32();
            int textBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int textBlockTag = map.Functions.ForMeta.FindMetaByOffset(textBlockOffset);
            if (textBlockCount > 0 && textBlockTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(textBlockTag, map, false, true);
                br2              = new BinaryReader(newMeta.MS);
                textBlockOffset -= newMeta.offset;
            }
            else
            {
                textBlockOffset -= meta.offset;
            }

            for (int list = 0; list < textBlockCount; list++)
            {
                textBlockData tbd = new textBlockData(list);
                tbd.offset = textBlockOffset + list * 44;
                tbd.Read(br2);
                this.textBlocks.Add(tbd);
            }
            #endregion

            #region Bitmap block reflexive
            br.BaseStream.Position = 36;
            int bitmapBlockCount  = br.ReadInt32();
            int bitmapBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int bitmBlockTag = map.Functions.ForMeta.FindMetaByOffset(bitmapBlockOffset);
            if (bitmapBlockCount > 0 && bitmBlockTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(bitmBlockTag, map, false, true);
                br2 = new BinaryReader(newMeta.MS);
                bitmapBlockOffset -= newMeta.offset;
            }
            else
            {
                bitmapBlockOffset -= meta.offset;
            }

            // Always add 3 in case of using sub bitmaps
            for (int list = 0; list < bitmapBlockCount; list++)
            {
                bitmapData bd = new bitmapData(list);
                bd.offset = bitmapBlockOffset + list * 56;
                bd.Read(br2);
                int bitmID = map.Functions.ForMeta.FindMetaByID(bd.bitmIdent);
                if (bitmID != -1)
                {
                    bd.meta = Map.GetMetaFromTagIndex(bitmID, map, false, false);
                    ParsedBitmap pm = new ParsedBitmap(ref bd.meta, map);
                    bd.link = pm.FindChunkAndDecode(0, 0, 0, ref bd.meta, map, 0, 0);
                    this.bitmapBlocks.Add(bd);

                    if (pm.Properties.Length > 1)
                    {
                        bd      = (bitmapData)bd.Clone();
                        bd.link = pm.FindChunkAndDecode(1, 0, 0, ref bd.meta, map, 0, 0);
                    }
                    this.bitmapBlocks.Add(bd);

                    if (pm.Properties.Length > 2)
                    {
                        bd      = (bitmapData)bd.Clone();
                        bd.link = pm.FindChunkAndDecode(2, 0, 0, ref bd.meta, map, 0, 0);
                    }
                    this.bitmapBlocks.Add(bd);
                }
            }
            #endregion

            isLoaded = true;
        }