public LoadedTMemData(RomFile file, int offset, int size, byte[] data) { SourceFile = file; FileOffset = offset; Size = size; Data = data; }
//public static public static F3DEXReaderPackage ReadF3DEXAt(RomFile file, int offset) { ResetReaderVariables(); byte[] data = file.GetAsBytes(); F3DEXReaderPackage package = new F3DEXReaderPackage(); if (offset < 0 || offset >= data.Length || offset % 8 != 0) return package; //Reset/Initialize what needs to be initialized/reset byte[] command = new byte[8]; while (offset < data.Length) { //read the command Array.Copy(data, offset, command, 0, 8); F3DEXCommand f3Command = F3DEXCommandFactory.ReadCommand(offset, command); if (f3Command == null) break; if (!_foundCommands.ContainsKey(file)) _foundCommands.Add(file, new List<F3DEXCommand>()); _foundCommands[file].Add(f3Command); ParseCommand(f3Command); offset += 8; if (f3Command is F3DEX_G_EndDL) break; } //Sort what needs to be sorted foreach(RomFile rom in _foundTextures.Keys) { _foundTextures[rom].Sort((s1, s2) => s1.FileOffset.CompareTo(s2.FileOffset)); for (int i = 0; i < _foundTextures[rom].Count - 1; i++) { if (_foundTextures[rom][i].FileOffset == _foundTextures[rom][i + 1].FileOffset) { _foundTextures[rom].RemoveAt(i); i--; } } } foreach (RomFile rom in _foundPalettes.Keys) { _foundPalettes[rom].Sort((s1, s2) => s1.FileOffset.CompareTo(s2.FileOffset)); for (int i = 0; i < _foundPalettes[rom].Count - 1; i++) { if (_foundPalettes[rom][i].FileOffset == _foundPalettes[rom][i + 1].FileOffset) { _foundPalettes[rom].RemoveAt(i); i--; } } } foreach (RomFile rom in _foundVertices.Keys) { _foundVertices[rom].Sort((s1, s2) => s1.FileOffset.CompareTo(s2.FileOffset)); for (int i = 0; i < _foundVertices[rom].Count - 1; i++) { if (_foundVertices[rom][i].FileOffset == _foundVertices[rom][i + 1].FileOffset) { _foundVertices[rom].RemoveAt(i); i--; } } } foreach (RomFile rom in _foundCommands.Keys) { _foundCommands[rom].Sort((s1, s2) => s1.FileOffset.CompareTo(s2.FileOffset)); for (int i = 0; i < _foundCommands[rom].Count - 1; i++) { if (_foundCommands[rom][i].FileOffset == _foundCommands[rom][i + 1].FileOffset) { _foundCommands[rom].RemoveAt(i); i--; } } } //Combine into the collections Dictionary<RomFile, List<F3DEXCommandCollection>> commandColls = new Dictionary<RomFile, List<F3DEXCommandCollection>>(); Dictionary<RomFile, List<VertexCollection>> vertexColls = new Dictionary<RomFile, List<VertexCollection>>(); //F3DEX Commands foreach (RomFile rom in _foundCommands.Keys) { commandColls.Add(rom, new List<F3DEXCommandCollection>()); int startColl = 0; for (int endColl = 0; endColl < _foundCommands[rom].Count; endColl++) { if (endColl == _foundCommands[rom].Count - 1 || _foundCommands[rom][endColl + 1].FileOffset != _foundCommands[rom][endColl].FileOffset + _foundCommands[rom][endColl].RawDataSize) { //Cut off the collection here F3DEXCommandCollection newColl = new F3DEXCommandCollection(_foundCommands[rom][startColl].FileOffset, _foundCommands[rom].GetRange(startColl, endColl - startColl + 1)); //NOTE: Shallow copying is done here commandColls[rom].Add(newColl); startColl = endColl + 1; } } } //Vertices foreach (RomFile rom in _foundVertices.Keys) { vertexColls.Add(rom, new List<VertexCollection>()); int startColl = 0; for (int endColl = 0; endColl < _foundVertices[rom].Count; endColl++) { if (endColl == _foundVertices[rom].Count - 1 || _foundVertices[rom][endColl + 1].FileOffset != _foundVertices[rom][endColl].FileOffset + _foundVertices[rom][endColl].RawDataSize) { //Cut off the collection here VertexCollection newVert = new VertexCollection(_foundVertices[rom][startColl].FileOffset, _foundVertices[rom].GetRange(startColl, endColl - startColl + 1)); //NOTE: Shallow copying is done here vertexColls[rom].Add(newVert); startColl = endColl + 1; } } } //double check that the package has all the files foreach (RomFile rom in _foundTextures.Keys.Union(_foundPalettes.Keys.Union( commandColls.Keys.Union(vertexColls.Keys)))) { if (!package.Elements.ContainsKey(rom)) package.Elements.Add(rom, new List<N64DataElement>()); } foreach (RomFile rom in _foundTextures.Keys) package.Elements[rom].AddRange(_foundTextures[rom]); foreach (RomFile rom in _foundPalettes.Keys) package.Elements[rom].AddRange(_foundPalettes[rom]); foreach (RomFile rom in commandColls.Keys) package.Elements[rom].AddRange(commandColls[rom]); foreach (RomFile rom in vertexColls.Keys) package.Elements[rom].AddRange(vertexColls[rom]); return package; }
public void AddRomFile(RomFile file) { _files.Add(file); }
public bool FindRamOffset(DmaAddress address, out RomFile file, out int fileOffset) { file = null; fileOffset = 0; if (SelectedDmaProfile == null || !SelectedDmaProfile.RamSegments.ContainsKey(address.Segment)) return false; foreach (DmaSegment segment in SelectedDmaProfile.RamSegments[address.Segment]) { if (address.Offset >= segment.RamStartOffset && address.Offset < segment.RamEndOffset) { file = segment.File; fileOffset = address.Offset - segment.RamStartOffset; return true; } } return false; }
public void MoveRomFile(RomFile file, int newIndex) { if (!_files.Contains(file) || newIndex < 0 || newIndex >= _files.Count) return; _files.Remove(file); _files.Insert(newIndex, file); }
public void RemoveRomFile(RomFile file) { if (_files.Contains(file)) _files.Remove(file); }
public DmaSegment(RomFile file, XElement xml) { File = file; FileStartOffset = int.Parse(xml.Attribute(FILESTARTOFFSET).Value); FileEndOffset = int.Parse(xml.Attribute(FILEENDOFFSET).Value); RamStartOffset = int.Parse(xml.Attribute(RAMSTARTOFFSET).Value); RamSegment = byte.Parse(xml.Attribute(RAMSEGMENT).Value); TagInfo = xml.Attribute(TAGINFO).Value; }