예제 #1
0
                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;
                }
예제 #2
0
        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));
        }
예제 #3
0
파일: FFTText.cs 프로젝트: Glain/FFTPatcher
 private int FindSectorToInsertPspCharmap( PspIso.PspIsoInfo info, int spaceNeeded )
 {
     return info.GetSectorWithFreeSpace( spaceNeeded );
 }
예제 #4
0
 public long this[PspIso.Sectors file] { get { return fileToSectorMap[file]; } }
예제 #5
0
 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;
 }
예제 #6
0
파일: PspIso.cs 프로젝트: xjamxx/FFTPatcher
 public override void PatchIso(Stream iso, IList <byte> bytes)
 {
     PspIso.ApplyPatch(iso, PspIsoInfo.GetPspIsoInfo(iso), GetPatchedByteArray(bytes.ToArray()));
 }
예제 #7
0
파일: PspIso.cs 프로젝트: xjamxx/FFTPatcher
 public byte[] ReadIso(Stream iso, PspIsoInfo info)
 {
     return(PspIso.GetBlock(iso, info, this));
 }
예제 #8
0
 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 );
 }
예제 #9
0
파일: PspIso.cs 프로젝트: Glain/FFTPatcher
 public long GetFileSize( PspIso.Sectors file )
 {
     return fileToSizeMap[file];
 }
예제 #10
0
파일: PspIso.cs 프로젝트: Glain/FFTPatcher
 public void AddFile( PspIso.Sectors file, int sector, int size )
 {
     fileToSectorMap[file] = sector;
     fileToSizeMap[file] = size;
 }
예제 #11
0
 public static SpriteLocation BuildPsp(PspIso.KnownPosition pos, IList<byte> bytes, params SpriteLocation[] subSpriteLocations)
 {
     return new SpriteLocation(pos, bytes, subSpriteLocations);
 }
예제 #12
0
 private SpriteLocation(PspIso.KnownPosition pos, IList<byte> bytes, params SpriteLocation[] subSpriteLocations)
     : this(bytes, subSpriteLocations)
 {
     pspPos = pos;
 }
예제 #13
0
        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;
        }
예제 #14
0
 public static SpriteAttributes BuildPsp(PspIso.KnownPosition pos, PspIso.PspIsoInfo info, IList<byte> bytes)
 {
     return new SpriteAttributes(pos, info, bytes);
 }
예제 #15
0
파일: PspIso.cs 프로젝트: Glain/FFTPatcher
 public void RemoveFile( PspIso.Sectors file )
 {
     if (fileToSectorMap.ContainsKey( file ))
     {
         fileToSectorMap.Remove( file );
     }
     if (fileToSizeMap.ContainsKey( file ))
     {
         fileToSizeMap.Remove( file );
     }
 }
예제 #16
0
 private SpriteAttributes(PspIso.KnownPosition pos, PspIso.PspIsoInfo info, IList<byte> bytes)
     : this(bytes)
 {
     pspPos = pos;
     pspInfo = info;
 }
예제 #17
0
 public LazyLoadedPatchedByteArray(PspIso.Sectors sector, long offset )
     : this((int)sector, offset)
 {
     SectorEnum = sector;
 }
예제 #18
0
 public PatchedByteArray( PspIso.Sectors sector, long offset, byte[] bytes )
     : this( (int)sector, offset, bytes )
 {
     SectorEnum = sector;
 }
예제 #19
0
                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
                }