Read() public method

public Read ( BinaryReader br ) : void
br System.IO.BinaryReader
return void
Beispiel #1
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;
        }
        private void lbPanes_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbPanes.Focused)
                writePaneToMemory();

            if (lbPanes.SelectedIndex == -1)
                return;

            paneData pd = (paneData)lbPanes.SelectedItem;
            br = new BinaryReader(pd.meta.MS);

            #region Bitmaps
            // Clear the list of bitmaps
            pd.bitmaps.Clear();
            // Add a default "no selection" to the top of the list
            pd.bitmaps.Add(new bitmapData(0));
            pd.bitmaps[0].title = "<None>";

            br.BaseStream.Position = pd.offset + 36;
            int bitmapCount = br.ReadInt32();
            int bitmapOffset = br.ReadInt32() - map.SecondaryMagic;

            if (bitmapCount > 0)
            {
                BinaryReader br2 = br;

                // Handle pointers to other tags
                int bitmTag = map.Functions.ForMeta.FindMetaByOffset(bitmapOffset);
                if (bitmTag != currentScreen.meta.TagIndex)
                {
                    Meta newMeta = Map.GetMetaFromTagIndex(bitmTag, map, false, true);
                    br2 = new BinaryReader(newMeta.MS);
                    bitmapOffset -= newMeta.offset;
                }
                else
                    bitmapOffset -= currentScreen.meta.offset;

                for (int bitmaps = 0; bitmaps < bitmapCount; bitmaps++)
                {
                    bitmapData bitmSD = new bitmapData(bitmaps);
                    bitmSD.offset = bitmapOffset + bitmaps * 56;
                    bitmSD.Read(br2);

                    int tagNum = bitmSD.bitmIdent != -1 ? (int)map.MetaInfo.identHT[bitmSD.bitmIdent] : -1;

                    if (tagNum != -1)
                    {
                        bitmSD.meta = Map.GetMetaFromTagIndex(tagNum, map, false, true);
                        bitmSD.title = map.FileNames.Name[tagNum].Substring(map.FileNames.Name[tagNum].LastIndexOf('\\') + 1);
                    }
                    else
                    {
                        bitmSD.meta = null;
                        bitmSD.title = string.Empty;
                    }

                    if (bitmSD.meta == null)
                    {
                        bitmSD.link = null;
                        continue;
                    }

                    ParsedBitmap pm = new ParsedBitmap(ref bitmSD.meta, map);
                    Bitmap b = pm.FindChunkAndDecode(bitmSD.bitmNumber, 0, 0, ref bitmSD.meta, map, 0, 0);

                    System.Drawing.Imaging.ImageAttributes imgAttr = new System.Drawing.Imaging.ImageAttributes();

                    // If alpha-blended = 1, invert alpha channel now (way faster to do once!)
                    if (bitmSD.blendMethod == 1)
                    {
                        Bitmap bTemp = new Bitmap(b.Width, b.Height);
                        using (Graphics g = Graphics.FromImage(bTemp))
                        {

                            System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix();
                            cm.Matrix00 = 1.0f;
                            cm.Matrix03 = -1.0f;    // Reverse red alpha
                            cm.Matrix11 = 1.0f;
                            cm.Matrix13 = -1.0f;    // Reverse green alpha
                            cm.Matrix22 = 1.0f;
                            cm.Matrix23 = -1.0f;    // REverse blue alpha
                            cm.Matrix33 = 1.0f;
                            imgAttr.SetColorMatrix(cm);

                            g.Clear(Color.Empty);

                            g.DrawImage(
                                b,
                                new Rectangle(
                                    0,
                                    0,
                                    b.Width,
                                    b.Height),
                                0,
                                0,
                                b.Width,
                                b.Height,
                                GraphicsUnit.Pixel,
                                imgAttr
                                );
                            g.Dispose();
                        }
                        b.Dispose();
                        b = bTemp;
                    }
                    bitmSD.link = b;

                    pd.bitmaps.Add(bitmSD);
                }

                drawBitmap();
            }
            tabControl1.TabPages[0].Text = "Bitmaps [" + bitmapCount.ToString() + "]";
            tabControl1.TabPages[0].Enabled = (bitmapCount > 0);
            
            #endregion

            #region List Blocks
            // Clear the list of List Blocks
            pd.listBlocks.Clear();
            // Always use the first panes Data for list blocks
            br.BaseStream.Position = ((paneData)lbPanes.Items[0]).offset + 12;
            int listBlockCount = br.ReadInt32();
            int listBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            if (listBlockCount > 0)
            {
                BinaryReader br2 = br;

                // Handle pointers to other tags
                int listBlockTag = map.Functions.ForMeta.FindMetaByOffset(listBlockOffset);
                if (listBlockTag != currentScreen.meta.TagIndex)
                {
                    Meta newMeta = Map.GetMetaFromTagIndex(listBlockTag, map, false, true);
                    br2 = new BinaryReader(newMeta.MS);
                    listBlockOffset -= newMeta.offset;
                }
                else
                    listBlockOffset -= currentScreen.meta.offset;

                for (int listBlock = 0; listBlock < listBlockCount; listBlock++)
                {
                    listBlockData ld = new listBlockData(listBlock);
                    br2.BaseStream.Position = ld.offset = listBlockOffset + listBlock * 24;
                    ld.Read(br2);

                    //bitmSD.link = b;

                    pd.listBlocks.Add(ld);
                }
            }
            tabControl1.TabPages[1].Text = "List Boxes [" + listBlockCount.ToString() + "]";
            tabControl1.TabPages[1].Enabled = (listBlockCount > 0);
            #endregion

            #region Text Blocks
            br.BaseStream.Position = pd.offset + 28;
            int textBlockCount = br.ReadInt32();
            int textBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            if (textBlockCount > 0)
            {
                BinaryReader br2 = br;

                // Handle pointers to other tags
                int textBlockTag = map.Functions.ForMeta.FindMetaByOffset(textBlockOffset);
                if (textBlockTag != currentScreen.meta.TagIndex)
                {
                    Meta newMeta = Map.GetMetaFromTagIndex(textBlockTag, map, false, true);
                    br2 = new BinaryReader(newMeta.MS);
                    textBlockOffset -= newMeta.offset;
                }
                else
                    textBlockOffset -= currentScreen.meta.offset;

                pd.textBlocks.Clear();
                for (int textBlock = 0; textBlock < textBlockCount; textBlock++)
                {
                    textBlockData tb = new textBlockData(textBlock);
                    br2.BaseStream.Position = tb.offset = textBlockOffset + textBlock * 44;
                    tb.Read(br2);
                    tb.title = textBlock.ToString("0: ") + sSwap.getStringFromID(tb.stringID.sidIndexer);

                    pd.textBlocks.Add(tb);
                }
            }

            tabControl1.TabPages[2].Text = "Text Blocks [" + textBlockCount.ToString() + "]";
            tabControl1.TabPages[2].Enabled = (textBlockCount > 0);
            #endregion

            #region Model Scenes
            br.BaseStream.Position = pd.offset + 44;
            int modelScenesCount = br.ReadInt32();
            int modelScenesOffset = br.ReadInt32() - map.SecondaryMagic;

            if (modelScenesCount > 0)
            {
            }

            tabControl1.TabPages[3].Text = "Model Scenes [" + modelScenesCount.ToString() + "]";
            tabControl1.TabPages[3].Enabled = (modelScenesCount > 0);
            #endregion

            #region Variable Buttons
            br.BaseStream.Position = pd.offset + 68;
            int variableButtonsCount = br.ReadInt32();
            int variableButtonsOffset = br.ReadInt32() - map.SecondaryMagic;

            if (variableButtonsCount > 0)
            {
            }

            tabControl1.TabPages[4].Text = "Variable Buttons [" + variableButtonsCount.ToString() + "]";
            tabControl1.TabPages[4].Enabled = (variableButtonsCount > 0);
            #endregion

            #region Buttons
            br.BaseStream.Position = pd.offset + 4;
            int buttonsCount = br.ReadInt32();
            int buttonsOffset = br.ReadInt32() - map.SecondaryMagic;

            if (buttonsCount > 0)
            {
            }

            tabControl1.TabPages[5].Text = "Buttons [" + buttonsCount.ToString() + "]";
            tabControl1.TabPages[5].Enabled = (buttonsCount > 0);
            #endregion

            screenData screenSelected = (screenData)lbScreensList.SelectedItem;
            // offset stores the last currently selected pane for that screen
            screenSelected.offset = lbPanes.SelectedIndex;

            #region Set the bitmap list box to display our data in pd.bitmaps
            lbBitmaps.DataSource = pd.bitmaps;
            #endregion
            
            #region Set the skin combo box to display the current skin
            if (pd.listBlocks.Count > 0)
            {
                cbLBSkinIdent.Enabled = true;
                // Change value to be sure skin is created
                cbLBSkinIdent.SelectedIndex = -1;
                cbLBSkinIdent.SelectedIndex = pd.listBlocks[0].skinIndex;
            }
            else
            {
                cbLBSkinIdent.Enabled = false;
                cbLBSkinIdent.SelectedIndex = -1;
            }
            #endregion

            #region Set the text block list box to display our data in pd.textBlocks
            lbTBTextBlocks.DataSource = pd.textBlocks;

            foreach (textBlockData td in pd.textBlocks)
            {
                List<bitmapData> lbd = new List<bitmapData>();

                entity.MetaFuncs.MEStringsSelector.Unicode[] ul = sSwap.getUnicodesFromID(td.stringID.sidIndexer);

                screenData sd = ((screenData)lbScreensList.SelectedItem);
                // Default to first
                string s = ul.Length > 0 ? ul[0].unicode : string.Empty;
                for (int i = 0; i < ul.Length; i++)
                {
                    foreach (entity.MetaFuncs.MEStringsSelector.Unicode uni in sd.strings)
                        if (ul[i].position == uni.position)
                        {
                            s = ul[i].unicode;
                            i = ul.Length;
                            break;
                        }
                }


                // Create bitmap from Text
                if (s != string.Empty)
                {
                    bitmapData bd = Skin.createText(map, td, s, true);
                    if (bd != null)
                        lbd.Add(bd);
                }
                
                td.link = lbd;
            }

            #endregion

            // Transfer List Box Data to text boxes, etc
            showListBoxData();

            // link holds an array of last selected bitmap #s for each pane
            if (screenSelected.link != null)
            {
                int[] paneBitmapSelections = (int[])screenSelected.link;
                lbBitmaps.SelectedIndex = paneBitmapSelections[screenSelected.offset];
            }
            else
                lbBitmaps.SelectedIndex = 0;
            
        }