Exemplo n.º 1
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));
                }
Exemplo n.º 2
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;
                }
Exemplo 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));
        }
Exemplo n.º 4
0
 private void UpdateIso(Stream iso)
 {
     if (psxPos != null)
     {
         PsxIso.PatchPsxIso(iso, psxPos.GetPatchedByteArray(ToByteArray()));
     }
     else if (pspPos != null)
     {
         PspIso.ApplyPatch(iso, pspInfo, pspPos.GetPatchedByteArray(ToByteArray()));
     }
 }
Exemplo n.º 5
0
        public static PatchResult PatchISO(string filename, List <AsmPatch> asmPatches, ASMEncoding.ASMEncodingUtility asmUtility)
        {
            ConflictResolveResult conflictResolveResult = ConflictHelper.ResolveConflicts(asmPatches, asmUtility);

            asmPatches = conflictResolveResult.Patches;
            string conflictResolveMessage = conflictResolveResult.Message;

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

            foreach (AsmPatch asmPatch in asmPatches)
            {
                asmPatch.Update(asmUtility);
                foreach (PatchedByteArray innerPatch in asmPatch)
                {
                    patches.Add(innerPatch);

                    if ((asmUtility.EncodingMode == ASMEncodingMode.PSP) && (innerPatch.Sector == (int)PspIso.Sectors.PSP_GAME_SYSDIR_BOOT_BIN))
                    {
                        patches.Add(innerPatch.GetCopyForSector(PspIso.Sectors.PSP_GAME_SYSDIR_EBOOT_BIN));
                    }
                }
            }

            using (Stream file = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
            {
                if (asmUtility.EncodingMode == ASMEncoding.ASMEncodingMode.PSX)
                {
                    PsxIso.PatchPsxIso(file, patches);
                }
                else if (asmUtility.EncodingMode == ASMEncoding.ASMEncodingMode.PSP)
                {
                    PspIso.PatchISO(file, patches);
                }
            }

            StringBuilder sbResultMessage = new StringBuilder();

            sbResultMessage.AppendLine("Complete!");
            sbResultMessage.AppendLine();

            if (!string.IsNullOrEmpty(conflictResolveMessage))
            {
                sbResultMessage.AppendLine(conflictResolveMessage);
                sbResultMessage.AppendLine();
            }

            // DEBUG
            //File.WriteAllText("./output.xml", PatchXmlReader.CreatePatchXML(patches), Encoding.UTF8);

            return(new PatchResult(true, sbResultMessage.ToString()));
        }
Exemplo n.º 6
0
        public static int GetRamOffset(Enum sector, Context context)
        {
            Type type = sector.GetType();

            if (type == typeof(PsxIso.Sectors))
            {
                return(PsxIso.GetRamOffset((PsxIso.Sectors)sector));
            }
            else if (type == typeof(PspIso.Sectors))
            {
                return(PspIso.GetRamOffset((PspIso.Sectors)sector));
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 7
0
        public static uint GetRamOffsetUnsigned(Enum sector, Context context, bool useKSeg0 = true)
        {
            Type type = sector.GetType();

            if (type == typeof(PsxIso.Sectors))
            {
                return(PsxIso.GetRamOffset((PsxIso.Sectors)sector, useKSeg0));
            }
            else if (type == typeof(PspIso.Sectors))
            {
                return(PspIso.GetRamOffsetUnsigned((PspIso.Sectors)sector));
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 8
0
        public static string GetSectorName(Enum sector)
        {
            Type type = sector.GetType();

            if (type == typeof(PsxIso.Sectors))
            {
                return(PsxIso.GetSectorName((PsxIso.Sectors)sector));
            }
            else if (type == typeof(PspIso.Sectors))
            {
                return(PspIso.GetSectorName((PspIso.Sectors)sector));
            }
            else if (type == typeof(FFTPack.Files))
            {
                return(PspIso.GetFileName((FFTPack.Files)sector));
            }
            else
            {
                return(string.Empty);
            }
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
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;
                }
Exemplo n.º 11
0
        //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);
        }