Esempio n. 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;
                }
Esempio n. 2
0
                public static GenericCharMap GetCharMap(Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info)
                {
                    IList <byte> fontBytes  = PspIso.GetBlock(iso, info, DTE.PspFontSection[0]);
                    IList <byte> widthBytes = PspIso.GetBlock(iso, info, DTE.PspFontWidths[0]);

                    return(GetCharMap(fontBytes, widthBytes, info));
                }
Esempio n. 3
0
        public static bool DoesPspIsoHaveNonDefaultFont(System.IO.Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info)
        {
            IList <byte> fontBytes         = PspIso.GetBlock(iso, info, DTE.PspFontSection[0]);
            IList <byte> widthBytes        = PspIso.GetBlock(iso, info, DTE.PspFontWidths[0]);
            IList <byte> defaultFontBytes  = TextUtilities.PSPFont.ToByteArray();
            IList <byte> defaultWidthBytes = TextUtilities.PSPFont.ToWidthsByteArray();

            return
                (!Utilities.CompareArrays(fontBytes, defaultFontBytes) ||
                 !Utilities.CompareArrays(widthBytes, defaultWidthBytes));
        }
Esempio n. 4
0
                public static void GetCharMap(Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, out GenericCharMap outCharmap, out IList <Glyph> customGlyphs)
                {
                    var matchBytes = Encoding.UTF8.GetBytes(FFTText.CharmapHeader);

                    if (info.ContainsKey(PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP))
                    {
                        var isoBytes = PspIso.GetBlock(iso, info,
                                                       new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP, 0,
                                                                                matchBytes.Length));
                        if (Utilities.CompareArrays(matchBytes, isoBytes))
                        {
                            BuildCharMapFromIso(iso, info, out outCharmap, out customGlyphs);
                            return;
                        }
                    }

                    IList <byte> fontBytes  = PspIso.GetBlock(iso, info, DTE.PspFontSection[0]);
                    IList <byte> widthBytes = PspIso.GetBlock(iso, info, DTE.PspFontWidths[0]);

                    outCharmap   = GetCharMap(fontBytes, widthBytes, info);
                    customGlyphs = null;
                }
        //public IList<byte> DefaultSpriteFileLocationsBytes { get { return defaultSpriteFileLocationsBytes; } }

        public static SpriteFileLocations FromPspIso(Stream iso, PspIso.PspIsoInfo info)
        {
            //const int numPspSp2 = 0x130 / 8;
            const int numPspSprites = 170;           //0x4d0 / 8 + 0x58 / 8;
            //const int numPspSp2 = numSprites + 4; //0x130 / 8;
            const int numPspSp2 = numPspSprites + 4; //0x130 / 8;

            IList <byte> spriteBytes = new List <byte>();

            //spriteBytes.AddRange(PspIso.GetBlock(iso, info, new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x32481C, 159 * 8)));
            //spriteBytes.AddRange(PspIso.GetBlock(iso, info, new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x324D14, 11 * 8)));
            spriteBytes.AddRange(PspIso.GetBlock(iso, info, new PspIso.KnownPosition(PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x32481C, numPspSprites * 8)));
            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, 0x324D6C, numPspSp2 * 8)).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, 0x324D6C + 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)] = loc;
                }
            }

            IList <SpriteLocation> sprites = new SpriteLocation[numPspSprites];

            for (byte i = 0; i < numPspSprites; i++)
            {
                if (pspSp2toSpriteMapping.ContainsKey(i))
                {
                    IList <byte> values = pspSp2toSpriteMapping[i];

                    List <byte> newValues = new List <byte>(values.Count);
                    foreach (byte value in values)
                    {
                        if (sp2.ContainsKey(value))
                        {
                            newValues.Add(value);
                        }
                    }
                    values = newValues.AsReadOnly();

                    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 <= 0x9A ? (0x32481C + i * 8) : (0x324D14 + (i - 0x9A - 1) * 8),
                                                 (0x32481C + i * 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 <= 0x9A ? (0x32481C + i * 8) : (0x324D14 + (i - 0x9A - 1) * 8),
                                                 (0x32481C + i * 8),
                                                 8),
                        spriteBytes.Sub(i * 8, (i + 1) * 8 - 1));
                }
                sprites[i].Sector = ((sprites[i].Sector > 0) ? (uint)sectorToFftPackMap[sprites[i].Sector] : 0);
            }

            SpriteFileLocations result = new SpriteFileLocations();

            result.sprites = sprites;
            result.sp2     = sp2;

            return(result);
        }