Пример #1
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));
        }
Пример #2
0
        protected static ImageInfo GetImageInfo(XmlNode node)
        {
            XmlNode nameNode     = node.SelectSingleNode("Name");
            int     width        = Int32.Parse(node.SelectSingleNode("Width").InnerText);
            int     height       = Int32.Parse(node.SelectSingleNode("Height").InnerText);
            XmlNode sectorNode   = node.SelectSingleNode("Sector");
            XmlNode fftpackNode  = node.SelectSingleNode("FFTPack");
            XmlNode pspSector    = node.SelectSingleNode("PSPSector");
            string  name         = nameNode.InnerText;
            XmlNode filenameNode = node.SelectSingleNode("Filename");
            XmlNode filesizeNode = node.SelectSingleNode("Filesize");
            string  filename     = (filenameNode == null) ? "" : filenameNode.InnerText;
            int     filesize     = (filesizeNode == null) ? 0 : int.Parse(filesizeNode.InnerText);

            XmlNode nameResourceNode = nameNode.SelectSingleNode("Resource");

            if (nameResourceNode != null)
            {
                string resourceName = nameResourceNode.Attributes["file"].InnerText;
                string context      = nameResourceNode.Attributes["context"].InnerText;

                Type   resourcesClass = context == "PSP" ? typeof(PatcherLib.PSPResources.Lists) : typeof(PatcherLib.PSXResources.Lists);
                object strings        = resourcesClass.GetProperty(resourceName).GetValue(null, null);
                if (resourceName == "TownNames")
                {
                    var names = strings as IDictionary <Town, string>;
                    name = names[(Town)Enum.Parse(typeof(Town), nameResourceNode.InnerText)];
                }
                else if (resourceName == "ShopNames")
                {
                    var names = strings as IDictionary <ShopsFlags, string>;
                    name = names[(ShopsFlags)Enum.Parse(typeof(ShopsFlags), nameResourceNode.InnerText)];
                }
                else
                {
                    var names = strings as IList <string>;
                    name = names[Int32.Parse(nameResourceNode.InnerText)];
                }
            }

            XmlNode paletteCountNode   = node["PaletteCount"];
            XmlNode defaultPaletteNode = node["DefaultPalette"];

            int paletteCount   = ((paletteCountNode != null) && (paletteCountNode.InnerText != null)) ? int.Parse(paletteCountNode.InnerText) : 0;
            int defaultPalette = ((defaultPaletteNode != null) && (defaultPaletteNode.InnerText != null)) ? int.Parse(defaultPaletteNode.InnerText) : 0;

            if (sectorNode != null)
            {
                PatcherLib.Iso.PsxIso.Sectors sector = (PatcherLib.Iso.PsxIso.Sectors)Enum.Parse(typeof(PatcherLib.Iso.PsxIso.Sectors), sectorNode.InnerText);
                if (string.IsNullOrEmpty(filename))
                {
                    filename = GetFilenameFromSectorName(Enum.GetName(typeof(PatcherLib.Iso.PsxIso.Sectors), sector));
                }

                return(new ImageInfo {
                    Name = name, Width = width, Height = height,
                    Sector = sector, OriginalFilename = filename, Filesize = filesize,
                    PaletteCount = paletteCount, DefaultPalette = defaultPalette, CurrentPalette = defaultPalette
                });
            }
            else if (fftpackNode != null)
            {
                PatcherLib.Iso.FFTPack.Files sector = (PatcherLib.Iso.FFTPack.Files)Enum.Parse(typeof(PatcherLib.Iso.FFTPack.Files), fftpackNode.InnerText);
                if (string.IsNullOrEmpty(filename))
                {
                    filename = GetFilenameFromSectorName(Enum.GetName(typeof(PatcherLib.Iso.FFTPack.Files), sector));
                }

                return(new ImageInfo {
                    Name = name, Width = width, Height = height,
                    Sector = sector, OriginalFilename = filename, Filesize = filesize,
                    PaletteCount = paletteCount, DefaultPalette = defaultPalette, CurrentPalette = defaultPalette
                });
            }
            else if (pspSector != null)
            {
                PatcherLib.Iso.PspIso.Sectors sector = (PatcherLib.Iso.PspIso.Sectors)Enum.Parse(typeof(PatcherLib.Iso.PspIso.Sectors), pspSector.InnerText);
                if (string.IsNullOrEmpty(filename))
                {
                    filename = GetFilenameFromSectorName(Enum.GetName(typeof(PatcherLib.Iso.PspIso.Sectors), sector));
                }

                return(new ImageInfo {
                    Name = name, Width = width, Height = height,
                    Sector = sector, OriginalFilename = filename, Filesize = filesize,
                    PaletteCount = paletteCount, DefaultPalette = defaultPalette, CurrentPalette = defaultPalette
                });
            }
            else
            {
                throw new Exception("No valid Sector element found");
            }
        }