private void button1_Click(object sender, EventArgs e) { GC.Collect(); foreach (DataGridViewRow row in dataGridView1.Rows) { rom.segments = (SegmentDescriptor[])row.Cells[8].Value; List <ScrollObject> scrolls = (List <ScrollObject>)row.Cells[9].Value; DisplayListRegion dlRegion = (DisplayListRegion)row.Cells[0].Value; Boolean fixingCheckBox = (Boolean)row.Cells[1].Value; DisplayList.FixConfig config = new DisplayList.FixConfig(checkBoxNerfFog.Checked, checkBoxOptimizeVertex.Checked, checkBoxTrimNops.Checked, checkBoxCombiners.Checked, checkBoxOtherMode.Checked, checkBoxNoFog.Checked); if (fixingCheckBox) { if (checkBoxNoFog.Checked) { dlRegion.isFogEnabled = false; } int maxDlLength = dlRegion.length; DisplayList.PerformRegionFix(rom, dlRegion, config); if (checkBoxOptimizeVertex.Checked) { DisplayList.PerformRegionOptimize(rom, dlRegion, config); } try { if (checkBoxGroupByTexture.Checked && !checkBoxRebuildVertices.Checked) { DisplayList.PerformVisualMapRebuild(rom, dlRegion, maxDlLength); } //DisplayList.PerformRegionOptimize(rom, dlRegion, config); } catch (Exception) { } } } if (checkBoxGroupByTexture.Checked && checkBoxRebuildVertices.Checked) { Dictionary <int, List <DataGridViewRow> > levelDatas = new Dictionary <int, List <DataGridViewRow> >(); foreach (DataGridViewRow row in dataGridView1.Rows) { Boolean fixingCheckBox = (Boolean)row.Cells[1].Value; if (!fixingCheckBox) { continue; } int level = (int)row.Cells[3].Value; if (!levelDatas.Keys.Contains(level)) { levelDatas[level] = new List <DataGridViewRow>(); } levelDatas[level].Add(row); } foreach (int level in levelDatas.Keys) { ROM romCopy = (ROM)rom.Clone(); try { List <DataGridViewRow> rows = levelDatas[level]; rom.segments = (SegmentDescriptor[])rows[0].Cells[8].Value; List <ScrollObject> scrolls = (List <ScrollObject>)rows[0].Cells[9].Value; foreach (ScrollObject scr in scrolls) { scr.Disable(rom); } ScrollFactory factory = new ScrollFactory(scrolls); SortedRegionList vertexData = new SortedRegionList(); List <KeyValuePair <DataGridViewRow, TriangleMap> > rowMaps = new List <KeyValuePair <DataGridViewRow, TriangleMap> >(); foreach (DataGridViewRow row in rows) { DisplayListRegion dlRegion = (DisplayListRegion)row.Cells[0].Value; int maxDlLength = dlRegion.length; DisplayList.GetTriangleMap(rom, dlRegion, maxDlLength, scrolls, out TriangleMap map, out SortedRegionList levelVertexData); rowMaps.Add(new KeyValuePair <DataGridViewRow, TriangleMap>(row, map)); vertexData.AddRegions(levelVertexData); } foreach (KeyValuePair <DataGridViewRow, TriangleMap> kvp in rowMaps) { DataGridViewRow row = kvp.Key; TriangleMap map = kvp.Value; DisplayListRegion dlRegion = (DisplayListRegion)row.Cells[0].Value; int maxDlLength = dlRegion.length; DisplayList.RebuildTriangleMap(rom, dlRegion, maxDlLength, map, vertexData, factory); } } catch (Exception) { rom = romCopy; } } } File.WriteAllBytes(path, rom.rom); MessageBox.Show(String.Format("ROM was patched successfully"), "f3d fix", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void button2_Click(object sender, EventArgs e) { List <Region> regions = new List <Region>(); if (!Int32.TryParse(textBoxF3DPtr.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int offset)) { MessageBox.Show("Custom DL", "Invalid ptr", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Int32.TryParse(textBoxSegNum.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int segment)) { MessageBox.Show("Custom DL", "Invalid segment", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Int32.TryParse(textBoxROMAddr.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int addr)) { MessageBox.Show("Custom DL", "Invalid rom addr", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } rom.SetSegment(segment, new SegmentDescriptor(addr, 0x00400000)); DisplayList.FixConfig config = new DisplayList.FixConfig(checkBoxNerfFog.Checked, checkBoxOptimizeVertex.Checked, checkBoxTrimNops.Checked, checkBoxCombiners.Checked, checkBoxOtherMode.Checked, checkBoxNoFog.Checked); DisplayList.PerformRegionParse(rom, regions, offset, int.Parse(textBoxLayer.Text)); foreach (Region region in regions) { if (region.state != RegionState.DisplayList) { continue; } DisplayListRegion dlRegion = (DisplayListRegion)region; region.data = new byte[region.length]; rom.ReadData(region.romStart, region.length, region.data); int maxDLLength = dlRegion.length; DisplayList.PerformRegionFix(rom, dlRegion, config); if (checkBoxOptimizeVertex.Checked) { DisplayList.PerformRegionOptimize(rom, dlRegion, config); } if (checkBoxGroupByTexture.Checked) { if (checkBoxRebuildVertices.Checked) { DisplayList.PerformTriangleMapRebuild(rom, dlRegion, maxDLLength, new List <ScrollObject>()); } else { DisplayList.PerformVisualMapRebuild(rom, dlRegion, maxDLLength); } } DisplayList.PerformRegionOptimize(rom, dlRegion, config); } File.WriteAllBytes(path, rom.rom); rom.SetSegment(segment, null); MessageBox.Show(String.Format("Ptr was fixed successfully"), "f3d fix", MessageBoxButtons.OK, MessageBoxIcon.Information); }