private static void RegionParse_cmd15(ROM rom, List <Region> regions) { int segment = rom.Read8(4); if (segment != 0x0e) { return; } int segmentedAddress = rom.Read32(4); int address = (int)rom.GetROMAddress(segmentedAddress); DisplayList.PerformRegionParse(rom, regions, address, rom.Read8(1)); }
private static void RegionParse_cmd21(ROM rom, List <Region> regions, RegionParseState state) { if (state.regionState != RegionState.ModelsLoader) { CutRegion(rom, regions, state, rom.offset, RegionState.ModelsLoader); } int segmentedAddress = rom.Read32(4); int segment = rom.Read8(4); int model = rom.Read8(3); // Only 0x19 or 0x0E commands are supported if (segment != 0x19 && segment != 0x0E) { return; } int displayListROMAddress = (int)rom.GetROMAddress(segmentedAddress); try { List <Region> modelRegions = new List <Region>(); DisplayList.PerformRegionParse(rom, modelRegions, displayListROMAddress, rom.Read8(2)); foreach (Region region in modelRegions) { region.model = model; } regions.AddRange(modelRegions); } catch (NotSupportedException e) { MessageBox.Show(String.Format("Model {0} graphics parsing is not supported! Reason : '{1}'", model, e.Message), "Level Parser", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception e) { MessageBox.Show(String.Format("Failed to parse model {0} graphics! Reason : '{1}'", model, e.Message), "Level Parser", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); }
private void ParseGraphics(string dirname, DataBuilder segment0E, DataBuilder segmentGeoLayouts, ROM rom, out RelocationUnit unit, out RelocationUnit graphicsDataUnit, int area = -1, int model = -1) { RelocationUnit retValue = null; RelocationUnit graphicsUnit = null; segmentGeoLayouts.Backup(); segment0E.Backup(); try { DynamicRegion graphicsDataRegion = new DynamicRegion(dirname, RegionState.GraphicsData, area, model); // no relocation needed for dynamic region segment0E.AddRegion(graphicsDataRegion); segment0E.RoundOffset(); // Display lists needs to be relocated with static graphics relocation table StaticRelocationTable graphicsRelocationTable = new StaticRelocationTable(); graphicsUnit = new RelocationUnit(graphicsDataRegion, rom, isFromStatic: true); graphicsRelocationTable.AddUnit(graphicsUnit); // Geolayouts needs to be relocated with queued display lists, will be filled during relocation with graphicsRelocationTable QueueRelocationTable dispRelocationTable = new QueueRelocationTable(); RelocationUnit dispRelocationUnit = null; for (int dispNumber = 0; dispNumber < 0xFF; dispNumber++) { if (!PathComposer.IsRegionFileExists(dirname, RegionState.DisplayList, area, model, dispNumber)) { break; } DisplayListRegion dispRegion = new DisplayListRegion(dirname, area, model, dispNumber); DisplayList.PerformRegionRelocation(dispRegion, graphicsRelocationTable); segment0E.AddRegion(dispRegion); segment0E.RoundOffset(); dispRelocationUnit = new RelocationUnit(dispRegion, rom, isFromStatic: true); dispRelocationTable.AddUnit(dispRelocationUnit); } // Not even one disp relocation unit, sounds like a bug if (dispRelocationUnit == null) { throw new IOException("No display lists found!"); } // Geolayout might or might not exist for model, check if it exists and if needed, relocate it if (PathComposer.IsRegionFileExists(dirname, RegionState.GeoLayout, area, model)) { // Load geolayout and relocate it with display lists GeoLayoutRegion modelGeoLayoutRegion = new GeoLayoutRegion(dirname, area, model); GeoLayout.PerformRegionRelocation(modelGeoLayoutRegion, dispRelocationTable); segmentGeoLayouts.AddRegion(modelGeoLayoutRegion); segmentGeoLayouts.RoundOffset(); // Finalize with returning geolayout for model retValue = new RelocationUnit(modelGeoLayoutRegion, rom, isFromStatic: true); } else { // Return display list only, there should be only one, if more, it is undefinied behaviour :3 retValue = dispRelocationUnit; } } catch (Exception ex) { MessageBox.Show(String.Format("Failed to load model {0}, reason : '{1}'", model, ex.Message), "Level Combiner", MessageBoxButtons.OK, MessageBoxIcon.Error); segment0E.Restore(); segmentGeoLayouts.Restore(); } unit = retValue; graphicsDataUnit = graphicsUnit; }
public override void Relocate(RelocationTable table) { DisplayList.PerformRegionRelocation(this, table); }