Beispiel #1
0
        public void UpdateDisassembly()
        {
            F3DZEX.Disassembler disas = new F3DZEX.Disassembler(_dlist);
            var          lines        = disas.Disassemble();
            StringWriter sw           = new StringWriter();

            foreach (var line in lines)
            {
                sw.Write($"{line}\r\n");
            }

            textBox_disassembly.Text = sw.ToString();
        }
        public void UpdateDisassembly()
        {
            var dlist = GetCurrentHolder <Z64Object.DListHolder>();

            if (dlist != null)
            {
                try
                {
                    F3DZEX.Disassembler disas = new F3DZEX.Disassembler(new F3DZEX.Command.Dlist(dlist.GetData(), new SegmentedAddress(_segment, _obj.OffsetOf(dlist)).VAddr));
                    var          lines        = disas.Disassemble();
                    StringWriter sw           = new StringWriter();
                    lines.ForEach(s => sw.WriteLine(s));
                    textBox_holderInfo.Text = sw.ToString();
                }
                catch (Exception ex)
                {
                    textBox_holderInfo.Text = "ERROR";
                }
            }
        }
Beispiel #3
0
        private void DisassemblyOptionForm_OnOptionUpdate(object sender, EventArgs e)
        {
            F3DZEX.Disassembler.StaticConfig.ShowAddress        = checkBoxShowAddr.Checked;
            F3DZEX.Disassembler.StaticConfig.RelativeAddress    = checkBoxRelativeAddr.Checked;
            F3DZEX.Disassembler.StaticConfig.DisasMultiCmdMacro = checkBoxMultiCmdMacro.Checked;
            F3DZEX.Disassembler.StaticConfig.AddressLiteral     = checkBoxAddrLiteral.Checked;
            F3DZEX.Disassembler.StaticConfig.Static             = checkBoxStatic.Checked;

            Application.OpenForms.OfType <DisasmForm>().ToList().ForEach(f => f.UpdateDisassembly());
            Application.OpenForms.OfType <ObjectAnalyzerForm>().ToList().ForEach(f => f.UpdateDisassembly());

            var lines = _disas.Disassemble();

            StringWriter sw = new StringWriter();

            foreach (var line in lines)
            {
                sw.WriteLine(line);
            }

            previewTextBox.Text = sw.ToString();
        }
        private void exportCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.FileName = "";
            saveFileDialog1.Filter   = Filters.C;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                StringWriter sw = new StringWriter();
                foreach (var entry in _obj.Entries)
                {
                    int entryOff = _obj.OffsetOf(entry);
                    switch (entry.GetEntryType())
                    {
                    case Z64Object.EntryType.DList:
                    {
                        sw.WriteLine($"Gfx {entry.Name}[] = \r\n{{");
                        bool oldStatic = F3DZEX.Disassembler.StaticConfig.Static;

                        F3DZEX.Disassembler.StaticConfig.Static = true;
                        F3DZEX.Disassembler dis = new F3DZEX.Disassembler(new F3DZEX.Command.Dlist(entry.GetData(), new SegmentedAddress(_segment, _obj.OffsetOf(entry)).VAddr));
                        dis.Disassemble().ForEach(l => sw.WriteLine($"    {l}"));;

                        F3DZEX.Disassembler.StaticConfig.Static = oldStatic;
                        sw.WriteLine("};");
                        break;
                    }

                    case Z64Object.EntryType.Vertex:
                    {
                        sw.WriteLine($"Vtx_t {entry.Name}[] = \r\n{{");

                        var vtx = (Z64Object.VertexHolder)entry;
                        vtx.Vertices.ForEach(v => sw.WriteLine($"    {{ {v.X}, {v.Y}, {v.Z}, 0x{v.Flag:X4}, {v.TexX}, {v.TexY}, {v.R}, {v.G}, {v.B}, {v.A} }},"));

                        sw.WriteLine("};");
                        break;
                    }

                    case Z64Object.EntryType.Texture:
                    {
                        sw.WriteLine($"u8 {entry.Name}[] = \r\n{{");

                        var tex = entry.GetData();
                        for (int i = 0; i < tex.Length; i += 16)
                        {
                            sw.Write("    ");
                            for (int j = 0; j < 16 && i + j < tex.Length; j++)
                            {
                                sw.Write($"0x{tex[i + j]:X2}, ");
                            }
                            sw.Write("\r\n");
                        }

                        sw.WriteLine("};");
                        break;
                    }

                    case Z64Object.EntryType.Unknown:
                    {
                        sw.WriteLine($"u8 {entry.Name}[] = \r\n{{");

                        var bytes = entry.GetData();
                        for (int i = 0; i < bytes.Length; i += 16)
                        {
                            sw.Write("    ");
                            for (int j = 0; j < 16 && i + j < bytes.Length; j++)
                            {
                                sw.Write($"0x{bytes[i + j]:X2}, ");
                            }
                            sw.Write("\r\n");
                        }

                        sw.WriteLine("};");
                        break;
                    }

                    case Z64Object.EntryType.AnimationHeader:
                    {
                        var holder = (Z64Object.AnimationHolder)entry;
                        sw.WriteLine($"AnimationHeader {entry.Name} = {{ {{ {holder.FrameCount} }}, 0x{holder.FrameData.VAddr}, 0x{holder.JointIndices.VAddr}, {holder.StaticIndexMax} }};");
                        break;
                    }

                    case Z64Object.EntryType.FrameData:
                    {
                        var holder = (Z64Object.AnimationFrameDataHolder)entry;
                        sw.WriteLine($"s16 {entry.Name}[] = {{");
                        for (int i = 0; i < 8; i += 8)
                        {
                            sw.Write("    ");
                            for (int j = 0; j < 8 && i + j < holder.FrameData.Length; j++)
                            {
                                sw.Write($"0x{holder.FrameData[i + j]:X4}, ");
                            }
                        }
                        sw.WriteLine("};");
                        break;
                    }

                    case Z64Object.EntryType.JointIndices:
                    {
                        var holder = (Z64Object.AnimationJointIndicesHolder)entry;
                        sw.WriteLine($"JointIndex {entry.Name}[] = {{");
                        foreach (var joint in holder.JointIndices)
                        {
                            sw.WriteLine($"    {{ {joint.X}, {joint.Y}, {joint.Z} }}, ");
                        }
                        sw.WriteLine("};");
                        break;
                    }

                    case Z64Object.EntryType.SkeletonHeader:
                    {
                        var holder = (Z64Object.SkeletonHolder)entry;
                        sw.WriteLine($"SkeletonHeader {entry.Name} = {{ 0x{holder.LimbsSeg.VAddr}, {holder.LimbCount} }};");
                        break;
                    }

                    case Z64Object.EntryType.FlexSkeletonHeader:
                    {
                        var holder = (Z64Object.FlexSkeletonHolder)entry;
                        sw.WriteLine($"FlexSkeletonHeader {entry.Name} = {{ {{ 0x{holder.LimbsSeg.VAddr}, {holder.LimbCount} }}, {holder.DListCount} }};");
                        break;
                    }

                    case Z64Object.EntryType.SkeletonLimb:
                    {
                        var holder = (Z64Object.SkeletonLimbHolder)entry;
                        sw.WriteLine($"StandardLimb {entry.Name} = {{ {{ {holder.JointX}, {holder.JointY}, {holder.JointZ} }}, {holder.Child}, {holder.Sibling}, 0x{holder.DListSeg.VAddr:X8} }};");
                        break;
                    }

                    case Z64Object.EntryType.SkeletonLimbs:
                    {
                        var holder = (Z64Object.SkeletonLimbsHolder)entry;
                        sw.WriteLine($"void* {entry.Name}[] = {{");
                        foreach (var limb in holder.LimbSegments)
                        {
                            sw.WriteLine($"0x{limb.VAddr:X8}, ");
                        }
                        sw.WriteLine("};");
                        break;
                    }

                    default: throw new Exception("Invalid Entry Type");
                    }

                    sw.Write("\r\n");
                }

                File.WriteAllText(saveFileDialog1.FileName, sw.ToString());
            }
        }