예제 #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
        private IList <PatchedByteArray> RemovePspCharMapPatches(Stream iso)
        {
            PspIso.PspIsoInfo info = PspIso.PspIsoInfo.GetPspIsoInfo(iso);
            //DirectoryEntry.GetPspDirectoryEntries( iso,
            var usrDir = DirectoryEntry.GetPspDirectoryEntries(
                iso,
                info,
                PspIso.Sectors.PSP_GAME_USRDIR,
                1);
            List <PatchedByteArray> result = new List <PatchedByteArray>();

            var charmapDirEntry = usrDir.Find(de => de.Filename == FFTText.PspCharmapFileName);

            if (charmapDirEntry != null)
            {
                usrDir.Remove(charmapDirEntry);
                result.Add(new PatchedByteArray((int)PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP, 0,
                                                new byte[System.Text.Encoding.UTF8.GetBytes(CharmapHeader).Length]));
                DirectoryEntry.GetPspDirectoryEntryPatches(
                    (int)PspIso.Sectors.PSP_GAME_USRDIR, 1, usrDir);
            }

            return(result);
        }
        //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);
        }
예제 #4
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
                }
예제 #5
0
                public static void GetCharMap(Stream iso, out GenericCharMap outCharmap, out IList <Glyph> customGlyphs)
                {
                    PspIso.PspIsoInfo info = PspIso.PspIsoInfo.GetPspIsoInfo(iso);

                    GetCharMap(iso, info, out outCharmap, out customGlyphs);
                }
예제 #6
0
 public static SpriteAttributes BuildPsp(PspIso.KnownPosition pos, PspIso.PspIsoInfo info, IList <byte> bytes)
 {
     return(new SpriteAttributes(pos, info, bytes));
 }
예제 #7
0
 private SpriteAttributes(PspIso.KnownPosition pos, PspIso.PspIsoInfo info, IList <byte> bytes)
     : this(bytes)
 {
     pspPos  = pos;
     pspInfo = info;
 }
예제 #8
0
                public static GenericCharMap GetCharMap(Stream iso)
                {
                    PspIso.PspIsoInfo info = PspIso.PspIsoInfo.GetPspIsoInfo(iso);

                    return(GetCharMap(iso, info));
                }
예제 #9
0
 private int FindSectorToInsertPspCharmap(PspIso.PspIsoInfo info, int spaceNeeded)
 {
     return(info.GetSectorWithFreeSpace(spaceNeeded));
 }