Esempio n. 1
0
        private static void ExpandPspIso(Stream iso)
        {
            throw new InvalidOperationException("This method doesn't work.");
            return;

            string        tempPath    = Path.GetTempPath();
            string        guid        = Path.GetRandomFileName();
            string        tempDirPath = Path.Combine(tempPath, guid);
            DirectoryInfo temp        = Directory.CreateDirectory(tempDirPath);

            PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso);
            long fftpackSector = info[PatcherLib.Iso.PspIso.Sectors.PSP_GAME_USRDIR_fftpack_bin];

            iso.Seek(2048 * fftpackSector, SeekOrigin.Begin);

            // Dump the fftpack
            PatcherLib.Iso.FFTPack.DumpToDirectory(iso, tempDirPath, info.GetFileSize(PatcherLib.Iso.PspIso.Sectors.PSP_GAME_USRDIR_fftpack_bin), null);

            // Decrypt the ISO  while we have it open...
            PatcherLib.Iso.PspIso.DecryptISO(iso, info);

            string battleDirPath = Path.Combine(tempDirPath, "BATTLE");

            // 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);
            }

            const int numPspSp2     = 0x130 / 8;
            const int numPspSprites = 0x4d0 / 8 + 0x58 / 8;

            byte[][] oldSpriteBytes = new byte[numPspSprites][];

            // Save the old sprites
            var locs = SpriteFileLocations.FromPspIso(iso, PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso));

            for (int i = 0; i < numPspSprites; i++)
            {
                oldSpriteBytes[i] = new byte[65536];

                PatcherLib.Iso.FFTPack.GetFileFromIso(iso, info, (PatcherLib.Iso.FFTPack.Files)sectorToFftPackMap[locs[i].Sector]).CopyTo(oldSpriteBytes[i], 0);
            }

            byte[] emptyByteArray = new byte[0];
            // Replace old sprites
            //for (int i = 78; i <= 213; i++)
            //{
            //    string currentFile = Path.Combine(tempDirPath, PatcherLib.Iso.FFTPack.FFTPackFiles[i]);
            //    File.Delete(currentFile);
            //    File.WriteAllBytes(currentFile, emptyByteArray);
            //}

            for (int i = 0; i < numPspSprites; i++)
            {
                File.Delete(Path.Combine(tempDirPath, string.Format("unknown/fftpack.{0}.dummy", i + 1340)));
                File.WriteAllBytes(Path.Combine(tempDirPath, string.Format("unknown/fftpack.{0}", i + 1340)), oldSpriteBytes[i]);
                locs[i].Sector = fftPackToSectorMap[i + 1340];
                locs[i].Size   = 65536;
            }

            List <byte> newSpriteLocations = new List <byte>();

            for (int i = 0; i < 154; i++)
            {
                newSpriteLocations.AddRange(locs[i].Sector.ToBytes());
                newSpriteLocations.AddRange(locs[i].Size.ToBytes());
            }
            newSpriteLocations.AddRange(new byte[32]);
            for (int i = 154; i < numPspSprites; i++)
            {
                newSpriteLocations.AddRange(locs[i].Sector.ToBytes());
                newSpriteLocations.AddRange(locs[i].Size.ToBytes());
            }

            byte[] newSpriteLocationsArray = newSpriteLocations.ToArray();
            string outputPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            PatcherLib.Iso.FFTPack.MergeDumpedFiles(tempDirPath, outputPath, null);

            long oldFftPackSize = info.GetFileSize(PatcherLib.Iso.PspIso.Sectors.PSP_GAME_USRDIR_fftpack_bin);

            byte[] oldFftPackSizeBytes = oldFftPackSize.ToBytes();
            oldFftPackSizeBytes = new byte[8] {
                oldFftPackSizeBytes[0], oldFftPackSizeBytes[1], oldFftPackSizeBytes[2], oldFftPackSizeBytes[3],
                oldFftPackSizeBytes[3], oldFftPackSizeBytes[2], oldFftPackSizeBytes[1], oldFftPackSizeBytes[0]
            };

            using (Stream newFftPack = File.OpenRead(outputPath))
            {
                long   newFftPackSize      = newFftPack.Length;
                byte[] newFftPackSizeBytes = newFftPackSize.ToBytes();
                newFftPackSizeBytes = new byte[8] {
                    newFftPackSizeBytes[0], newFftPackSizeBytes[1], newFftPackSizeBytes[2], newFftPackSizeBytes[3],
                    newFftPackSizeBytes[3], newFftPackSizeBytes[2], newFftPackSizeBytes[1], newFftPackSizeBytes[0]
                };

                ReplaceBytesInStream(iso, oldFftPackSizeBytes, newFftPackSizeBytes);
                CopyStream(newFftPack, 0, iso, info[PatcherLib.Iso.PspIso.Sectors.PSP_GAME_USRDIR_fftpack_bin] * 2048, newFftPack.Length);
                long oldLength = info.GetFileSize(PatcherLib.Iso.PspIso.Sectors.PSP_GAME_USRDIR_fftpack_bin);
                if (newFftPack.Length < oldLength)
                {
                    iso.Write(new byte[oldLength - newFftPack.Length], 0, (int)(oldLength - newFftPack.Length));
                }
            }
            Directory.Delete(tempDirPath, true);
            File.Delete(outputPath);

            PatcherLib.Iso.PspIso.PatchISO(iso, new PatchedByteArray[] {
                new PatchedByteArray(PatcherLib.Iso.PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN, 0x324824, newSpriteLocationsArray),
                new PatchedByteArray(PatcherLib.Iso.PspIso.Sectors.PSP_GAME_SYSDIR_EBOOT_BIN, 0x324824, newSpriteLocationsArray)
            });
        }
Esempio n. 2
0
        public static AllSprites FromPspIso(Stream iso, bool expand)
        {
            PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso);

            return(new AllSprites(Context.US_PSP, AllSpriteAttributes.FromPspIso(iso, info), SpriteFileLocations.FromPspIso(iso, info),
                                  new Sprite[] {
                new WepSprite(Context.US_PSP, WepSprite.Wep.WEP1, "WEP1", new PatcherLib.Iso.PspIso.KnownPosition(PatcherLib.Iso.FFTPack.Files.BATTLE_WEP_SPR, 0, 256 * 256 / 2 + 0x200)),
                new WepSprite(Context.US_PSP, WepSprite.Wep.WEP2, "WEP2", new PatcherLib.Iso.PspIso.KnownPosition(PatcherLib.Iso.FFTPack.Files.BATTLE_WEP_SPR, 0, 256 * 256 / 2 + 0x200)),
                new WepSprite(Context.US_PSP, WepSprite.Wep.EFF1, "EFF1", new PatcherLib.Iso.PspIso.KnownPosition(PatcherLib.Iso.FFTPack.Files.BATTLE_WEP_SPR, 256 * 256 / 2 + 0x200, 256 * 256 / 2 + 0x200)),
                new WepSprite(Context.US_PSP, WepSprite.Wep.EFF2, "EFF2", new PatcherLib.Iso.PspIso.KnownPosition(PatcherLib.Iso.FFTPack.Files.BATTLE_WEP_SPR, 256 * 256 / 2 + 0x200, 256 * 256 / 2 + 0x200)),
                new WepSprite(Context.US_PSP, WepSprite.Wep.EFF2, "TRAP1", new PatcherLib.Iso.PspIso.KnownPosition(PatcherLib.Iso.FFTPack.Files.BATTLE_WEP_SPR, (256 * 256 / 2 + 0x200) * 2, 144 * 256 / 2 + 0x200)),
            }
                                  ));
        }