private static void BuildCharMapFromIso( Stream iso, PspIso.PspIsoInfo info, out GenericCharMap outCharmap, out IList<Glyph> customGlyphs ) { var usrDirEnt = DirectoryEntry.GetPspDirectoryEntries( iso, info, PspIso.Sectors.PSP_GAME_USRDIR, 1 ); var charMapEntry = usrDirEnt.Find( d => d.Filename == FFTText.PspCharmapFileName ); System.Diagnostics.Debug.Assert( charMapEntry.Sector == info[PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP] ); var charmapBytes = PspIso.GetBlock( iso, info, new PspIso.KnownPosition( PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP, 0, (int)charMapEntry.Size ) ).ToArray(); Dictionary<int, string> myCharMap = new Dictionary<int, string>(); using(MemoryStream memStream = new MemoryStream(charmapBytes)) using (TextReader reader = new StreamReader( memStream, Encoding.UTF8 )) { reader.ReadLine(); string currentLine = string.Empty; while ((currentLine = reader.ReadLine()) != null) { string[] cols = currentLine.Split( '\t' ); int index = int.Parse( cols[0], System.Globalization.NumberStyles.HexNumber ); myCharMap[index] = cols[1]; } } outCharmap = new NonDefaultCharMap( myCharMap ); customGlyphs = null; }
public static IList <DirectoryEntry> GetPspDirectoryEntries(Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, PspIso.Sectors sectorOfParentEntry, int numSectors) { int length = numSectors; List <DirectoryEntry> result = new List <DirectoryEntry>(); var bytes = PspIso.GetBlock(iso, info, new PspIso.KnownPosition(sectorOfParentEntry, 0, numSectors * 2048)); return(BuildDirectoryEntriesFromBytes(bytes)); }
private int FindSectorToInsertPspCharmap( PspIso.PspIsoInfo info, int spaceNeeded ) { return info.GetSectorWithFreeSpace( spaceNeeded ); }
public long this[PspIso.Sectors file] { get { return fileToSectorMap[file]; } }
public static IList<byte> GetFile( Stream stream, PspIsoInfo info, PspIso.Sectors sector, int start, int length ) { byte[] result = new byte[length]; stream.Seek( info[sector] * 2048 + start, SeekOrigin.Begin ); stream.Read( result, 0, length ); return result; }
public override void PatchIso(Stream iso, IList <byte> bytes) { PspIso.ApplyPatch(iso, PspIsoInfo.GetPspIsoInfo(iso), GetPatchedByteArray(bytes.ToArray())); }
public byte[] ReadIso(Stream iso, PspIsoInfo info) { return(PspIso.GetBlock(iso, info, this)); }
public static IList<DirectoryEntry> GetPspDirectoryEntries( Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, PspIso.Sectors sectorOfParentEntry, int numSectors ) { int length = numSectors; List<DirectoryEntry> result = new List<DirectoryEntry>(); var bytes = PspIso.GetBlock( iso, info, new PspIso.KnownPosition( sectorOfParentEntry, 0, numSectors * 2048 ) ); return BuildDirectoryEntriesFromBytes( bytes ); }
public long GetFileSize( PspIso.Sectors file ) { return fileToSizeMap[file]; }
public void AddFile( PspIso.Sectors file, int sector, int size ) { fileToSectorMap[file] = sector; fileToSizeMap[file] = size; }
public static SpriteLocation BuildPsp(PspIso.KnownPosition pos, IList<byte> bytes, params SpriteLocation[] subSpriteLocations) { return new SpriteLocation(pos, bytes, subSpriteLocations); }
private SpriteLocation(PspIso.KnownPosition pos, IList<byte> bytes, params SpriteLocation[] subSpriteLocations) : this(bytes, subSpriteLocations) { pspPos = pos; }
public static SpriteFileLocations FromPspIso(Stream iso, PspIso.PspIsoInfo info) { const int numPspSp2 = 0x130 / 8; const int numPspSprites = 0x4d0 / 8 + 0x58 / 8; IList<byte> spriteBytes = new List<byte>(); spriteBytes.AddRange(PspIso.GetBlock(iso, info, new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x324824, 0x4d0))); spriteBytes.AddRange(PspIso.GetBlock(iso, info, new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x324D14, 0x58))); spriteBytes = spriteBytes.ToArray(); // Read the sector -> fftpack map IList<byte> fftpackMap = PatcherLib.Iso.PspIso.GetBlock( iso, info, new PatcherLib.Iso.PspIso.KnownPosition(PatcherLib.Iso.PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x252f34, 0x3e00)); // Convert the fake "Sectors" into FFTPack indices Dictionary<uint, int> sectorToFftPackMap = new Dictionary<uint, int>(); Dictionary<int, uint> fftPackToSectorMap = new Dictionary<int, uint>(); for (int i = 3; i < PatcherLib.Iso.FFTPack.NumFftPackFiles - 1; i++) { UInt32 sector = fftpackMap.Sub((i - 3) * 4, (i - 3) * 4 + 4 - 1).ToUInt32(); sectorToFftPackMap.Add(sector, i); fftPackToSectorMap.Add(i, sector); } byte[] sp2Bytes = PspIso.GetBlock(iso, info, new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x3251ac, 0x130)).ToArray(); var sp2 = new Dictionary<byte, SpriteLocation>(); for (byte i = 0; i < numPspSp2; i++) { const byte offset = 0x87; SpriteLocation loc = SpriteLocation.BuildPsp( new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x3251ac + i * 8, 8), sp2Bytes.Sub(i * 8, (i + 1) * 8 - 1)); if (loc.Sector != 0 && loc.Size != 0) { loc.Sector = (uint)sectorToFftPackMap[loc.Sector]; sp2[(byte)(i + offset)] = loc; } else { } } IList<SpriteLocation> sprites = new SpriteLocation[numPspSprites]; for (byte i = 0; i < numPspSprites; i++) { if (pspSp2toSpriteMapping.ContainsKey(i)) { IList<byte> values = pspSp2toSpriteMapping[i]; SpriteLocation[] sp2s = new SpriteLocation[values.Count]; for (int j = 0; j < values.Count; j++) { sp2s[j] = sp2[values[j]]; } sprites[i] = SpriteLocation.BuildPsp( new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, i <= 0x99 ? (0x324824 + i * 8) : (0x324d14 + (i - 0x99 - 1) * 8), 8), spriteBytes.Sub(i * 8, (i + 1) * 8 - 1), sp2s); } else { sprites[i] = SpriteLocation.BuildPsp( new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, i <= 0x99 ? (0x324824 + i * 8) : (0x324d14 + (i - 0x99 - 1) * 8), 8), spriteBytes.Sub(i * 8, (i + 1) * 8 - 1)); } sprites[i].Sector = (uint)sectorToFftPackMap[sprites[i].Sector]; } SpriteFileLocations result = new SpriteFileLocations(); result.sprites = sprites; result.sp2 = sp2; return result; }
public static SpriteAttributes BuildPsp(PspIso.KnownPosition pos, PspIso.PspIsoInfo info, IList<byte> bytes) { return new SpriteAttributes(pos, info, bytes); }
public void RemoveFile( PspIso.Sectors file ) { if (fileToSectorMap.ContainsKey( file )) { fileToSectorMap.Remove( file ); } if (fileToSizeMap.ContainsKey( file )) { fileToSizeMap.Remove( file ); } }
private SpriteAttributes(PspIso.KnownPosition pos, PspIso.PspIsoInfo info, IList<byte> bytes) : this(bytes) { pspPos = pos; pspInfo = info; }
public LazyLoadedPatchedByteArray(PspIso.Sectors sector, long offset ) : this((int)sector, offset) { SectorEnum = sector; }
public PatchedByteArray( PspIso.Sectors sector, long offset, byte[] bytes ) : this( (int)sector, offset, bytes ) { SectorEnum = sector; }
private static GenericCharMap GetCharMap( IList<byte> fontBytes, IList<byte> widthBytes, PspIso.PspIsoInfo info ) { Dictionary<int, string> myCharMap = new Dictionary<int, string>( defaultMap ); List<Glyph> glyphs = new List<Glyph>( defaultFont.Glyphs ); glyphs.Sort( ( a, b ) => b.Width.CompareTo( a.Width ) ); for (int i = MinDteByte; i < (DTE.MaxDteByte - DTE.MinDteByte + 1); i++) { IList<byte> bytes = fontBytes.Sub( i * DTE.characterSize, (i + 1) * DTE.characterSize - 1 ); Glyph first = DetermineFirstCharacter( glyphs, bytes, widthBytes[i] ); if (first != null) { Glyph second = DetermineSecondCharacter( glyphs, bytes, widthBytes[i], first.Width ); if (second != null) { int firstIndex = defaultFont.Glyphs.IndexOf( first ); int secondIndex = defaultFont.Glyphs.IndexOf( second ); firstIndex = firstIndex < 0xD0 ? firstIndex : (firstIndex - 0xD0) % 0xD0 + 0xD100 + 0x100 * ((firstIndex - 0xD0) / 0xD0); secondIndex = secondIndex < 0xD0 ? secondIndex : (secondIndex - 0xD0) % 0xD0 + 0xD100 + 0x100 * ((secondIndex - 0xD0) / 0xD0); myCharMap[i] = defaultMap[firstIndex] + defaultMap[secondIndex]; } } } return new NonDefaultCharMap( myCharMap ); // For each glyph in new font: // Determine if it's different from default // Determine the two characters that make it up // Sort original font characters DECREASING by WIDTH // For each character in the original font // Compare pixels to left side of new font // look for match -> first character // After finding first character, subtract character width from current width // For each character in original font // Compare pixels to right side of new font // look for match -> second character }