예제 #1
0
        public static List <AbstractImage> GetPSPEffectImages(Stream iso)
        {
            List <AbstractImage> images = new List <AbstractImage>();

            const int      effectCount = 512;
            IList <string> effectNames = PatcherLib.PSPResources.Lists.AbilityEffects;

            PatcherLib.Iso.PspIso.PspIsoInfo pspIsoInfo = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso);
            //byte[] subroutineEndByteSequence = new byte[8] { 0x08, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x00, 0x00 };
            //byte[] frameDataOffsetByteSequence = new byte[4] { 0x28, 0x00, 0x00, 0x00 };

            for (int effectIndex = 0; effectIndex < effectCount; effectIndex++)
            {
                try
                {
                    AbstractImage effectImage = GetPSPEffectImage(iso, effectIndex, effectNames[effectIndex], pspIsoInfo);
                    if (effectImage != null)
                    {
                        images.Add(effectImage);
                    }
                }
                catch (Exception) { }
            }

            return(images);
        }
예제 #2
0
 public static void OpenPatchedPspIso(string filename)
 {
     using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
     {
         Context = Context.US_PSP;
         PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(stream);
         LoadDataFromBytes(
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.Abilities[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.AbilityEffects[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.OldItems[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.OldItemAttributes[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.NewItems[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.NewItemAttributes[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.Jobs[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.JobLevels[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.SkillSets[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.MonsterSkills[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.ActionEvents[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.StatusAttributes[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.InflictStatuses[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.PoachProbabilities[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.ENTD1),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.ENTD2),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.ENTD3),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.ENTD4),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.ENTD5),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.MoveFindItems[0]),
             PatcherLib.Iso.PspIso.GetBlock(stream, info, PatcherLib.Iso.PspIso.StoreInventories[0]));
         FireDataChangedEvent();
     }
 }
예제 #3
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));
                }
예제 #4
0
        public static FFTText GetPspText(Stream iso, GenericCharMap charmap, BackgroundWorker worker)
        {
            pspIsoInfo = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso);
            var result = GetText(iso, Context.US_PSP, Resources.PSP, BytesFromPspIso, charmap, worker);

            pspIsoInfo = null;
            return(result);
        }
예제 #5
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));
        }
예제 #6
0
        private static FullSpriteSet DoInitPSP(Stream iso, BackgroundWorker worker)
        {
            PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso);
            const int numberOfPspSprites          = 143;
            int       tasks         = numberOfPspSprites * 2 + 1;
            int       tasksComplete = 0;

            var         sprites = new List <AbstractSprite>();
            XmlDocument doc     = new XmlDocument();

            doc.LoadXml(Properties.Resources.PSPFiles);
            foreach (XmlNode node in doc.SelectNodes(string.Format("/PspFiles/{0}/Sprite", typeof(MonsterSprite).FullName)))
            {
                string        name      = node.SelectSingleNode("@name").InnerText;
                List <string> filenames = new List <string>();
                List <byte[]> bytes     = new List <byte[]>();
                foreach (XmlNode file in node.SelectNodes("Files/File"))
                {
                    string filename = file.SelectSingleNode("@name").InnerText;
                    worker.ReportProgress(tasksComplete++ *100 / tasks, "Reading " + filename);
                    filenames.Add(filename);
                    bytes.Add(FFTPack.GetFileFromIso(iso, info, (FFTPack.Files)Enum.Parse(typeof(FFTPack.Files), file.SelectSingleNode("@enum").InnerText)));
                }
                if (bytes.Count > 1)
                {
                    sprites.Add(new MonsterSprite(bytes[0], bytes.Sub(1).ToArray()));
                }
                else
                {
                    sprites.Add(new MonsterSprite(bytes[0]));
                }
            }

            foreach (Type t in new Type[] {
                typeof(TYPE1Sprite),
                typeof(TYPE2Sprite),
                typeof(ShortSprite),
                typeof(KANZEN),
                typeof(CYOKO),
                typeof(ARUTE)
            })
            {
                ConstructorInfo constructor = t.GetConstructor(new Type[] { typeof(string), typeof(IList <byte>) });
                foreach (XmlNode node in doc.SelectNodes(string.Format("/PspFiles/{0}/Sprite", t.FullName)))
                {
                    worker.ReportProgress(tasksComplete++ *100 / tasks, "Reading " + node.SelectSingleNode("Files/File/@name").InnerText);
                    sprites.Add((AbstractSprite)constructor.Invoke(new object[] { node.SelectSingleNode("@name").InnerText,
                                                                                  FFTPack.GetFileFromIso(iso, info, (FFTPack.Files)Enum.Parse(typeof(FFTPack.Files), node.SelectSingleNode("Files/File/@enum").InnerText)) }));
                }
            }

            worker.ReportProgress(tasksComplete++ *100 / tasks, "Sorting...");
            sprites.Sort((a, b) => a.Name.CompareTo(b.Name));

            return(new FullSpriteSet(sprites, worker, tasksComplete, tasks));
        }
예제 #7
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));
        }
예제 #8
0
        public void PatchPspISO(Stream stream, BackgroundWorker worker, IList <PatchedByteArray> patches)
        {
            int totalTasks    = patches.Count;
            int tasksComplete = 0;

            PatcherLib.Iso.PspIso.PspIsoInfo info = PspIso.PspIsoInfo.GetPspIsoInfo(stream);
            foreach (var patch in patches)
            {
                worker.ReportProgress(tasksComplete++ *100 / totalTasks, "Patching " + patch.SectorEnum.ToString());
                FFTPack.PatchFile(stream, info, (int)((FFTPack.Files)patch.SectorEnum), (int)patch.Offset, patch.GetBytes());
            }
        }
예제 #9
0
        public static FFTText GetPspText(Stream iso, BackgroundWorker worker)
        {
            GenericCharMap charmap = TextUtilities.PSPMap;

            pspIsoInfo = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso);
            if (DTE.DoesPspIsoHaveNonDefaultFont(iso, pspIsoInfo))
            {
                charmap = DTE.DTEAnalyzer.PSP.GetCharMap(iso, pspIsoInfo);
            }

            pspIsoInfo = null;
            return(GetPspText(iso, charmap, worker));
        }
예제 #10
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)),
            }
                                  ));
        }
예제 #11
0
        public static void PatchISOSimple(FFTPatch FFTPatch, Stream stream)
        {
            PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(stream);

            if (PatcherLib.Iso.PspIso.IsJP(stream, info))
            {
                throw new NotSupportedException("Unrecognized image.");
            }
            else
            {
                PatcherLib.Iso.PspIso.DecryptISO(stream, info);
            }

            List <PatchedByteArray> patches = GetPatches(FFTPatch);

            foreach (PatchedByteArray patch in patches)
            {
                PatcherLib.Iso.PspIso.ApplyPatch(stream, info, patch);
            }
        }
예제 #12
0
        public static AllSpriteAttributes FromPspIso(Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info)
        {
            IList <byte> bytes = PatcherLib.Iso.PspIso.GetBlock(iso, info, pspPos);
            //List<byte> realBytes = new List<byte>(bytes.Sub(0, numPsxSprites * 4 - 1));
            //realBytes.AddRange(bytes.Sub(numPsxSprites * 4 + (4 * 4)));
            //bytes = realBytes.AsReadOnly();
            AllSpriteAttributes      result  = new AllSpriteAttributes();
            IList <SpriteAttributes> sprites = new SpriteAttributes[numPspSprites];

            for (int i = 0; i < numPspSprites; i++)
            {
                sprites[i] = SpriteAttributes.BuildPsp(
                    new PatcherLib.Iso.PspIso.KnownPosition(pspPos.Sector.Value, pspPos.StartLocation + i * 4, 4),
                    info,
                    bytes.Sub(i * 4, (i + 1) * 4 - 1));
            }
            result.sprites = sprites;
            result.Count   = numPspSprites;
            return(result);
        }
예제 #13
0
        public void RestoreFile(System.IO.Stream iso)
        {
            IList <byte> bytes = null;

            if (Layout.Context == Context.US_PSX)
            {
                KeyValuePair <Enum, int> sect = Layout.Sectors[SectorType.Sector][0];
                bytes = PsxIso.ReadFile(iso, (PsxIso.Sectors)sect.Key, sect.Value, Layout.Size);
            }
            else if (Layout.Context == Context.US_PSP)
            {
                PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso);
                if (Layout.Sectors.ContainsKey(SectorType.BootBin))
                {
                    KeyValuePair <Enum, int> sect = Layout.Sectors[SectorType.BootBin][0];
                    bytes = PspIso.GetFile(iso, info, (PspIso.Sectors)sect.Key, sect.Value, Layout.Size);
                }
                else if (Layout.Sectors.ContainsKey(SectorType.FFTPack))
                {
                    KeyValuePair <Enum, int> sect = Layout.Sectors[SectorType.FFTPack][0];
                    bytes = PspIso.GetFile(iso, info, (FFTPack.Files)sect.Key, sect.Value, Layout.Size);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            else
            {
                throw new InvalidOperationException();
            }
            AbstractFile tempFile = ConstructFile(
                Layout.FileType,
                CharMap,
                Layout,
                bytes);

            this.Sections = tempFile.Sections;
        }
예제 #14
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;
                }
예제 #15
0
        /// <summary>
        /// Patches the ISO.
        /// </summary>
        /// <param name="stream">The stream of the ISO to patch.</param>
        public static void PatchISO(FFTPatch FFTPatch, Stream stream, BackgroundWorker worker, IGeneratePatchList patchList)
        {
            PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(stream);

            if (PatcherLib.Iso.PspIso.IsJP(stream, info))
            {
                throw new NotSupportedException("Unrecognized image.");
            }

            int numberOfTasks = patchList.PatchCount * 2;
            int tasksComplete = 0;

            List <PatchedByteArray> patches = new List <PatchedByteArray>();

            Action <string> sendProgress =
                delegate(string message)
            {
                worker.ReportProgress(++tasksComplete * 100 / numberOfTasks, message);
            };

            if (patchList.RegenECC)
            {
                PatcherLib.Iso.PspIso.DecryptISO(stream, info);
                sendProgress("Decrypting EBOOT.BIN");
            }

            const Context context = Context.US_PSP;

            if (patchList.Abilities)
            {
                patches.AddRange(FFTPatch.Abilities.GetPatches(context));
                sendProgress("Getting Abilities patches");
                sendProgress("Getting Abilities patches");
            }

            if (patchList.AbilityAnimations)
            {
                patches.AddRange(FFTPatch.AbilityAnimations.GetPatches(context));
                sendProgress("Getting Ability Animations patches");
                sendProgress("Getting Ability Animations patches");
            }

            if (patchList.AbilityEffects)
            {
                patches.AddRange(FFTPatch.Abilities.AllEffects.GetPatches(context));
                sendProgress("Getting Ability Effects patches");
                sendProgress("Getting Ability Effects patches");
            }

            if (patchList.ActionMenus)
            {
                patches.AddRange(FFTPatch.ActionMenus.GetPatches(context));
                sendProgress("Getting Action Menus patches");
                sendProgress("Getting Action Menus patches");
            }

            if (patchList.ENTD.Exists(b => b == true))
            {
                IList <PatchedByteArray> entdPatches = FFTPatch.ENTDs.GetPatches(context);
                for (int i = 0; i < 5; i++)
                {
                    if (patchList.ENTD[i])
                    {
                        patches.Add(entdPatches[i]);
                        sendProgress(string.Format("Getting ENTD {0} patches", i));
                    }
                }
            }

            if (patchList.InflictStatus)
            {
                patches.AddRange(FFTPatch.InflictStatuses.GetPatches(context));
                sendProgress("Getting Inflict Status patches");
                sendProgress("Getting Inflict Status patches");
            }
            if (patchList.ItemAttributes)
            {
                patches.AddRange(FFTPatch.ItemAttributes.GetPatches(context));
                sendProgress("Getting Item Attributes patches");
                sendProgress("Getting Item Attributes patches");
                sendProgress("Getting Item Attributes patches");
                sendProgress("Getting Item Attributes patches");
            }
            if (patchList.Items)
            {
                patches.AddRange(FFTPatch.Items.GetPatches(context));
                sendProgress("Getting Item patches");
                sendProgress("Getting Item patches");
                sendProgress("Getting Item patches");
                sendProgress("Getting Item patches");
            }
            if (patchList.JobLevels)
            {
                patches.AddRange(FFTPatch.JobLevels.GetPatches(context));
                sendProgress("Getting Job Levels patches");
                sendProgress("Getting Job Levels patches");
            }
            if (patchList.Jobs)
            {
                patches.AddRange(FFTPatch.Jobs.GetPatches(context));
                sendProgress("Getting Jobs patches");
                sendProgress("Getting Jobs patches");
            }
            if (patchList.MonsterSkills)
            {
                patches.AddRange(FFTPatch.MonsterSkills.GetPatches(context));
                sendProgress("Getting Monster Skills patches");
                sendProgress("Getting Monster Skills patches");
            }
            if (patchList.MoveFindItems)
            {
                patches.AddRange(FFTPatch.MoveFind.GetPatches(context));
                sendProgress("Getting Move/Find Items patches");
                sendProgress("Getting Move/Find Items patches");
            }
            foreach (PatchedByteArray patch in patchList.OtherPatches)
            {
                patches.Add(patch);
                sendProgress("Getting other patches");
            }
            if (patchList.Poach)
            {
                patches.AddRange(FFTPatch.PoachProbabilities.GetPatches(context));
                sendProgress("Getting Poach Probabilities patches");
                sendProgress("Getting Poach Probabilities patches");
            }
            if (patchList.Skillsets)
            {
                patches.AddRange(FFTPatch.SkillSets.GetPatches(context));
                sendProgress("Getting Skillsets patches");
                sendProgress("Getting Skillsets patches");
            }
            if (patchList.StatusAttributes)
            {
                patches.AddRange(FFTPatch.StatusAttributes.GetPatches(context));
                sendProgress("Getting Status attributes patches");
                sendProgress("Getting Status attributes patches");
            }

            if (patchList.StoreInventory)
            {
                patches.AddRange(FFTPatch.StoreInventories.GetPatches(context));
                sendProgress("Getting store inventories patches");
                sendProgress("Getting store inventories patches");
            }
            if (patchList.Propositions)
            {
                patches.AddRange(FFTPatch.Propositions.GetPatches(context));
                sendProgress("Getting errands patches");
                sendProgress("Getting errands patches");
            }

            foreach (PatchedByteArray patch in patches)
            {
                PatcherLib.Iso.PspIso.ApplyPatch(stream, info, patch);
                sendProgress("Patching ISO");
            }
        }
예제 #16
0
 protected override AbstractSprite GetAbstractSpriteFromPspIso(System.IO.Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, bool ignoreCache)
 {
     return(GetFromIso(iso, ignoreCache));
 }
예제 #17
0
파일: Sprite.cs 프로젝트: xjamxx/FFTPatcher
 protected abstract AbstractSprite GetAbstractSpriteFromPspIso(System.IO.Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, bool ignoreCache);
예제 #18
0
        protected override AbstractSprite GetAbstractSpriteFromPspIso(System.IO.Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, bool ignoreCache)
        {
            if (CachedSprite == null || ignoreCache)
            {
                IList <byte> bytes = Position.ReadIso(iso);

                System.Diagnostics.Debug.Assert(bytes.Count == this.Size);
                switch (SHP)
                {
                case SpriteType.TYPE1:
                    CachedSprite = new TYPE1Sprite(bytes);
                    break;

                case SpriteType.TYPE2:
                    CachedSprite = new TYPE2Sprite(bytes);
                    break;

                case SpriteType.RUKA:
                    CachedSprite = new MonsterSprite(bytes);
                    break;

                case SpriteType.MON:
                    byte[][] sp2Bytes = new byte[location.SubSpriteLocations.Count][];
                    if (location.SubSpriteLocations.Count > 0)
                    {
                        for (int i = 0; i < location.SubSpriteLocations.Count; i++)
                        {
                            sp2Bytes[i] = PatcherLib.Iso.PspIso.GetFile(
                                iso,
                                info,
                                (PatcherLib.Iso.FFTPack.Files)location.SubSpriteLocations[i].Sector,
                                0,
                                (int)location.SubSpriteLocations[i].Size).ToArray();
                        }
                    }
                    CachedSprite = new MonsterSprite(bytes, sp2Bytes);
                    break;

                case SpriteType.KANZEN:
                    CachedSprite = new KANZEN(bytes);
                    break;

                case SpriteType.CYOKO:
                    CachedSprite = new CYOKO(bytes);
                    break;

                case SpriteType.ARUTE:
                    CachedSprite = new ARUTE(bytes);
                    break;

                case SpriteType.WEP1:
                case SpriteType.WEP2:
                    CachedSprite = new WEPSprite(bytes);
                    break;

                //case SpriteType.WEP3:
                //    cachedSprite = new WEP3Sprite(bytes);
                //    break;
                default:
                    CachedSprite = null;
                    break;
                }
            }

            return(CachedSprite);
        }
예제 #19
0
 public static FFTText GetPspText( Stream iso, GenericCharMap charmap, BackgroundWorker worker )
 {
     pspIsoInfo = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo( iso );
     var result = GetText( iso, Context.US_PSP, Resources.PSP, BytesFromPspIso, charmap, worker );
     pspIsoInfo = null;
     return result;
 }
예제 #20
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)
            });
        }
예제 #21
0
        public static FFTText GetPspText( Stream iso, BackgroundWorker worker )
        {
            GenericCharMap charmap = TextUtilities.PSPMap;
            pspIsoInfo = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo( iso );
            IList<Glyph> customGlyphs = null;
            if (DTE.DoesPspIsoHaveNonDefaultFont( iso, pspIsoInfo ))
            {
                DTE.DTEAnalyzer.PSP.GetCharMap( iso, pspIsoInfo, out charmap, out customGlyphs );
            }

            pspIsoInfo = null;
            return GetPspText( iso, charmap, customGlyphs, worker );
        }
예제 #22
0
        public static AbstractImage GetPSPEffectImage(Stream iso, int effectIndex, string effectName, PatcherLib.Iso.PspIso.PspIsoInfo pspIsoInfo)
        {
            string strEffectNumber = effectIndex.ToString("000");
            string sectorName      = string.Format("EFFECT_E{0}_BIN", strEffectNumber);

            PatcherLib.Iso.FFTPack.Files fftPack = (PatcherLib.Iso.FFTPack.Files) 3;

            try
            {
                fftPack = (PatcherLib.Iso.FFTPack.Files)Enum.Parse(typeof(PatcherLib.Iso.FFTPack.Files), sectorName);
            }
            catch (Exception) { }

            byte[] fileBytes = PatcherLib.Iso.PspIso.GetFile(iso, pspIsoInfo, fftPack);
            //byte[] fileBytes = PatcherLib.Iso.FFTPack.TryGetFileFromIso(iso, pspIsoInfo, fftPack, 0, 0x5800);
            if (fileBytes.Length == 0)
            {
                return(null);
            }

            /*
             * int headerOffset = 0;
             * int lastMatchIndex = fileBytes.LastIndexOf(subroutineEndByteSequence);
             * if (lastMatchIndex >= 0)
             * {
             *  int lastMatchIndex2 = fileBytes.Sub(lastMatchIndex + 8).IndexOf(frameDataOffsetByteSequence) + lastMatchIndex + 4;
             *  headerOffset = (lastMatchIndex2 >= 0) ? (lastMatchIndex2 + 4) : (lastMatchIndex + 8);
             * }
             */

            int headerOffset = fileBytes.IndexOf(Effect_FrameDataOffsetByteSequence);

            int frameDataOffset             = fileBytes.SubLength(headerOffset, 4).ToIntLE() + headerOffset;
            int frameDataSectionCount       = fileBytes.SubLength(frameDataOffset, 2).ToIntLE();
            int firstFrameDataPointerOffset = fileBytes.SubLength(frameDataOffset + 4 + (2 * frameDataSectionCount), 2).ToIntLE() + frameDataOffset + 4;
            int firstFrameTexturePageHeader = fileBytes.SubLength(firstFrameDataPointerOffset, 2).ToIntLE();

            int colorDepthCode = (firstFrameTexturePageHeader & 0x0180) >> 7;

            if (colorDepthCode > 1)     // Invalid code
            {
                return(null);
            }

            bool is4bpp        = (colorDepthCode == 0);
            int  paletteOffset = fileBytes.SubLength(headerOffset + 0x24, 4).ToIntLE() + headerOffset;

            int secondSetPaletteOffset = paletteOffset + 0x200;
            int imageSizeDataOffset    = paletteOffset + 0x400;
            int graphicsOffset         = paletteOffset + 0x404;

            byte[] imageSizeData = fileBytes.SubLength(imageSizeDataOffset, 4).ToArray();
            //byte[] imageSizeData = PatcherLib.Iso.FFTPack.TryGetFileFromIso(iso, pspIsoInfo, fftPack, imageSizeDataOffset, 4);
            int    imageSizeCombinedValue = imageSizeData.Sub(0, 2).ToIntLE();
            int    rowBytes  = (imageSizeData[3] != 0) ? 256 : 128;
            int    height    = imageSizeCombinedValue >> ((imageSizeData[3] != 0) ? 8 : 7);
            int    width     = is4bpp ? (rowBytes * 2) : rowBytes;
            int    imageSize = rowBytes * height;
            int    fileSize  = graphicsOffset + imageSize;
            string name      = String.Format("{0} {1}", effectIndex.ToString("X3"), effectName);
            string fileName  = String.Format("E{0}.BIN", strEffectNumber);

            PatcherLib.Iso.PspIso.KnownPosition graphicsPosition = new PatcherLib.Iso.PspIso.KnownPosition(fftPack, graphicsOffset, imageSize);
            PatcherLib.Iso.PspIso.KnownPosition palettePosition  = new PatcherLib.Iso.PspIso.KnownPosition(fftPack, (is4bpp ? secondSetPaletteOffset : paletteOffset), (is4bpp ? 32 : 512));

            return(GetPalettedImage(is4bpp, name, width, height, fileName, fileSize, fftPack, graphicsPosition, palettePosition, true, effectIndex));
        }