Beispiel #1
0
            public override void SetData(byte[] data)
            {
                int validSize = N64Texture.GetTexSize(Width * Height, Format);

                if (data.Length != validSize)
                {
                    throw new Z64ObjectException($"Invalid data size (0x{data.Length:X} instead of 0x{validSize:X})");
                }

                Texture = data;
            }
Beispiel #2
0
        private void UpdateTexture(object sender = null, EventArgs e = null)
        {
            N64TexFormat fmt     = (N64TexFormat)comboBoxTexFmt.SelectedIndex;
            int          w       = (int)valueW.Value;
            int          h       = (int)valueH.Value;
            int          texSize = N64Texture.GetTexSize(w * h, fmt);

            if (!uint.TryParse(textBoxTexAddr.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint texAddr))
            {
                return;
            }


            byte[] tlut = null;
            if ((fmt == N64TexFormat.CI4 || fmt == N64TexFormat.CI8) && uint.TryParse(textBoxTlutAddr.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint tlutAddr))
            {
                try
                {
                    if (fmt == N64TexFormat.CI4)
                    {
                        tlut = ReadBytes(tlutAddr, 64);
                    }
                    else if (fmt == N64TexFormat.CI8)
                    {
                        tlut = ReadBytes(tlutAddr, 256);
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }

            try
            {
                byte[] tex = ReadBytes(texAddr, texSize);
                textureBox1.Image = N64Texture.DecodeBitmap(w, h, fmt, tex, tlut);
            }
            catch (Exception)
            {
                return;
            }
        }
Beispiel #3
0
        private static Tuple <List <int>, List <ReservedRegion> > FindRegions(byte[] data, int segmentId, Config cfg)
        {
            List <ReservedRegion> regions = new List <ReservedRegion>();
            List <int>            dlists  = new List <int>();

            var codeEnds = Utils.FindData(data, new byte[] { (byte)CmdID.G_ENDDL, 0, 0, 0, 0, 0, 0, 0, }, 8);

            codeEnds.Insert(0, 0);
            for (int i = 1; i < codeEnds.Count; i++)
            {
                int  end    = codeEnds[i];
                int  texels = -1;
                uint half1  = 0xFFFFFFFF;

                for (int off = end; off >= codeEnds[i - 1] + 8; off -= 8)
                {
                    CmdID op = (CmdID)data[off];

                    if (IsOverlap(off, regions) || !IsOpCodeCorrect(data, off, cfg))
                    {
                        break;
                    }

                    switch (op)
                    {
                    case CmdID.G_RDPHALF_1:
                    {
                        half1 = CmdInfo.DecodeCommand <GRdpHalf>(data, off).word;
                        break;
                    }

                    case CmdID.G_BRANCH_Z:
                    {
                        AddDlist(dlists, segmentId, half1, data.Length);
                        break;
                    }

                    case CmdID.G_DL:
                    {
                        var gdl = CmdInfo.DecodeCommand <GDl>(data, off);
                        AddDlist(dlists, segmentId, gdl.dl, data.Length);
                        break;
                    }

                    case CmdID.G_VTX:
                    {
                        var gmtx = CmdInfo.DecodeCommand <GVtx>(data, off);
                        AddRegion(regions, segmentId, gmtx.vaddr, gmtx.numv * 0x10, data.Length);
                        break;
                    }

                    case CmdID.G_SETTIMG:
                    {
                        var settimg = CmdInfo.DecodeCommand <GSetTImg>(data, off);
                        if (texels == -1)
                        {
                            break;
                        }
                        AddRegion(regions, segmentId, settimg.imgaddr, N64Texture.GetTexSize(texels, settimg.siz), data.Length);
                        texels = -1;
                        break;
                    }

                    case CmdID.G_LOADBLOCK:
                    {
                        var loadblock = CmdInfo.DecodeCommand <GLoadBlock>(data, off);
                        texels = loadblock.texels + 1;
                        break;
                    }

                    case CmdID.G_LOADTLUT:
                    {
                        var loadtlut = CmdInfo.DecodeCommand <GLoadTlut>(data, off);
                        texels = loadtlut.count + 1;
                        break;
                    }

                    default:
                        break;
                    }
                }
            }
            return(new Tuple <List <int>, List <ReservedRegion> >(dlists, regions));
        }