Exemple #1
0
        private void romSpritePointersListbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (romSpritePointersListbox.SelectedIndex == -1)
            {
                return;
            }

            BNSAOffsetFriendlyName selectedBNSA = (BNSAOffsetFriendlyName)romSpritePointersListbox.SelectedItem;

            Console.WriteLine("BNSA Offset changed to " + selectedBNSA.Offset.ToString("X8"));
            bool isNumeric = selectedBNSA.Offset > 0;

            if (isNumeric)
            {
                byte[] BNSAMemory;
                int    offset = 0;
                animationIndexUpDown.Value = 0;
                frameIndexUpDown.Value     = 0;
                paletteIndexUpDown.Value   = 0;
                if (selectedBNSA.Offset.ToString("X8").Substring(0, 2) == "88")
                {
                    //Archive is compressed
                    BNSAMemory = Nintenlord.GBA.Compressions.LZ77.Decompress(ROM, selectedBNSA.Offset & 0x00FFFFFF);
                    Array.Copy(BNSAMemory, 4, BNSAMemory, 0, BNSAMemory.Length - 4);
                }
                else
                {
                    //Not compressed
                    //Find the end of the BNSA.
                    offset = (selectedBNSA.Offset & 0x00FFFFFF) + 4;
                    int numAnimations = 0;
                    if (getint32(ROM, offset) / 4 != 0)
                    {
                        numAnimations = (getint32(ROM, offset) / 4) - 1;
                    }
                    else
                    {
                        numAnimations = (getint32(ROM, offset) / 4);
                    }

                    int startoffset     = offset - 4;
                    int framecount      = getmaxframes(numAnimations);
                    int animationoffset = offset + getint32(ROM, offset + (4 * numAnimations));
                    int opointer        = offset + getint32(ROM, animationoffset + (5 * 4 * framecount) + 4 + 4 + 4);
                    int num             = getint32(ROM, opointer);
                    num = getint32(ROM, opointer + num - 4);
                    while ((uint)getint32(ROM, (opointer + num)) != 0xFFFFFFFF)
                    {
                        num += 5;
                    }
                    num       += 5;
                    BNSAMemory = new byte[(opointer + num) - startoffset];
                    Array.Copy(ROM, startoffset, BNSAMemory, 0, (opointer + num) - startoffset);
                }
                LoadBNSA(BNSAMemory);
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets number of frames in the animation... will likely be removed in future version for BNSA version
        /// </summary>
        /// <param name="animation"></param>
        /// <returns></returns>
        private int getmaxframes(int animation)
        {
            int frame = 0;
            BNSAOffsetFriendlyName selectedItem = (BNSAOffsetFriendlyName)romSpritePointersListbox.SelectedItem;

            if (romSpritePointersListbox.SelectedItem.ToString().Substring(0, 2) == "88")
            {
                byte[] spritefile = Nintenlord.GBA.Compressions.LZ77.Decompress(ROM, selectedItem.Offset & 0x00FFFFFF);
                int    offset     = 8;
                while (true)
                {
                    int somedata = (getint32(spritefile, offset + getint32(spritefile, offset + (4 * (int)animation)) + (5 * 4 * frame) + 4 + 4 + 4 + 4));
                    if (((somedata & 0x00FF0000) >> 16) == 0xC0 || ((somedata & 0x00FF0000) >> 16) == 0x80 || ((somedata & 0x000000FF) == 0x01 && ((somedata & 0x00FF0000) >> 16) == 0x08))
                    {
                        break;
                    }
                    frame++;
                }
            }
            else
            {
                byte[] memory = ROM;
                int    offset = (selectedItem.Offset & 0x00FFFFFF) + 4;

                while (true)
                {
                    int somedata = (getint32(memory, offset + getint32(memory, offset + (4 * (int)animation)) + (5 * 4 * frame) + 4 + 4 + 4 + 4));
                    if (((somedata & 0x00FF0000) >> 16) == 0xC0 || ((somedata & 0x00FF0000) >> 16) == 0x80 || ((somedata & 0x000000FF) == 0x01 && ((somedata & 0x00FF0000) >> 16) == 0x08))
                    {
                        break;
                    }
                    frame++;
                }
            }
            return(frame);
        }
Exemple #3
0
        private void OpenROM(string fileName)
        {
            frameImage.Stretch = Stretch.None;
            RenderOptions.SetBitmapScalingMode(frameImage, BitmapScalingMode.NearestNeighbor);
            romSpritePointersListbox.ItemsSource = new List <String>(); //clear
            ROM = File.ReadAllBytes(fileName);
            string ROMID = GetROMID(ROM);
            List <BNSAOffsetFriendlyName> offsetList = new List <BNSAOffsetFriendlyName>();
            int startoffset = 0;
            int endoffset   = 0;

            if (BN6USROMCODES.Contains(ROMID))
            {
                startoffset = 0x031CEC;
                endoffset   = 0x0329A8;
                ROMID       = "EXE6";
            }
            else if (BN6JPROMCODES.Contains(ROMID))
            {
                startoffset = 0x32CA8;
                endoffset   = 0x33968;
            }
            else if (BN5TPUSROMCODES.Contains(ROMID))
            {
                startoffset = 0x32750;
                endoffset   = 0x331B0;
            }
            else if (BN5TCUSROMCODES.Contains(ROMID))
            {
                startoffset = 0x32754;
                endoffset   = 0x331B4;
            }
            else if (BN5TPJPROMCODES.Contains(ROMID))
            {
                startoffset = 0x326E8;
                endoffset   = 0x33148;
            }
            else if (BN5TCJPROMCODES.Contains(ROMID))
            {
                startoffset = 0x326EC;
                endoffset   = 0x3314C;
            }
            else if (BN45JPROMCODES.Contains(ROMID))
            {
                startoffset = 0x2B39C;
                endoffset   = 0x2BC7C;
            }
            else if (BN4BUSROMCODES.Contains(ROMID))
            {
                startoffset = 0x27968;
                endoffset   = 0x28308;
            }
            else if (BN4RUSROMCODES.Contains(ROMID))
            {
                startoffset = 0x27964;
                endoffset   = 0x28304;
            }
            else if (BN4BJPROMCODES.Contains(ROMID))
            {
                startoffset = 0x27880;
                endoffset   = 0x28220;
            }
            else if (BN4RJPROMCODES.Contains(ROMID))
            {
                startoffset = 0x2787C;
                endoffset   = 0x2821C;
            }
            else if (BN3WUSROMCODES.Contains(ROMID))
            {
                startoffset = 0x247A0;
                endoffset   = 0x25474;
            }
            else if (BN3BUSROMCODES.Contains(ROMID))
            {
                startoffset = 0x24788;
                endoffset   = 0x2545C;
            }
            else if (BN3WJPROMCODES.Contains(ROMID))
            {
                startoffset = 0x248F8;
                endoffset   = 0x251CC;
            }
            else if (BN3BJPROMCODES.Contains(ROMID))
            {
                startoffset = 0x248e0;
                endoffset   = 0x251bc;
            }
            else if (BN2USROMCODES.Contains(ROMID))
            {
                startoffset = 0x1E9FC;
                endoffset   = 0x1F1D0;
            }
            else if (BN2JPROMCODES.Contains(ROMID))
            {
                startoffset = 0x1E888;
                endoffset   = 0x1F05C;
            }
            else if (BN1USROMCODES.Contains(ROMID))
            {
                startoffset = 0x12690;
                endoffset   = 0x12BF0;
            }
            else if (BN1EUROMCODES.Contains(ROMID))
            {
                startoffset = 0x1269C;
                endoffset   = 0x12BFC;
            }
            else if (BN1JPROMCODES.Contains(ROMID))
            {
                startoffset = 0x12614;
                endoffset   = 0x12B74;
            }

            for (int i = startoffset; i < endoffset; i += 4)
            {
                BNSAOffsetFriendlyName fn = new BNSAOffsetFriendlyName();
                fn.Offset       = getint32(ROM, i);
                fn.FriendlyName = getFriendlyName(ROMID, fn.Offset);
                offsetList.Add(fn);
            }
            romSpritePointersListbox.ItemsSource   = offsetList.ToArray();
            romSpritePointersListbox.SelectedIndex = 0;
            StatusLabel.Content = "Viewing " + Path.GetFileName(fileName);

            ChangeAnimation();
            //filename = open;
            //this.Text = "Megaman BattleNetwork Sprite List Viewer ~ By Greiga Master (" + Path.GetFileName(filename) + ")";
        }