public PartiallyVisiblePalettedImage4bpp(
            string name,
            int width, int height,
            int numPalettes,
            Rectangle visiblePortion,
            FFTPatcher.SpriteEditor.Palette.ColorDepth depth,
            PatcherLib.Iso.KnownPosition imagePosition,
            PatcherLib.Iso.KnownPosition palettePosition )
            : base(name, visiblePortion.Width, visiblePortion.Height)
        {
            VisiblePortion = visiblePortion;
            FullSize = new Size( width, height );
            this.position = imagePosition;
            this.palettePosition = palettePosition;
            this.depth = depth;

            System.Diagnostics.Debug.Assert( palettePosition.Length == 8 * (int)depth * 2 );
            if ( position is PatcherLib.Iso.PsxIso.KnownPosition )
            {
                var pos = position as PatcherLib.Iso.PsxIso.KnownPosition;
                saveFileName = string.Format( "{0}_{1}.png", pos.Sector, pos.StartLocation );
            }
            else if ( position is PatcherLib.Iso.PspIso.KnownPosition )
            {
                var pos = position as PatcherLib.Iso.PspIso.KnownPosition;
                saveFileName = string.Format( "{0}_{1}.png", pos.SectorEnum, pos.StartLocation );
            }
        }
        public PalettedImage8bpp( 
            string name, 
            int width, int height, 
            int numPalettes, Palette.ColorDepth depth,
            PatcherLib.Iso.KnownPosition imagePosition, 
            PatcherLib.Iso.KnownPosition palettePosition,
            bool ignoreAssert = false)
            : base(name, width, height)
        {
            this.position = imagePosition;
            this.palettePosition = palettePosition;
            this.depth = depth;

            if (!ignoreAssert)
            {
                System.Diagnostics.Debug.Assert(palettePosition.Length == 256 * (int)depth * numPalettes);
            }

            if ( position is PatcherLib.Iso.PsxIso.KnownPosition )
            {
                var pos = position as PatcherLib.Iso.PsxIso.KnownPosition;
                saveFileName = string.Format( "{0}_{1}_{2}.bmp", pos.Sector, pos.StartLocation, pos.Length );
            }
            else if ( position is PatcherLib.Iso.PspIso.KnownPosition )
            {
                var pos = position as PatcherLib.Iso.PspIso.KnownPosition;
                saveFileName = string.Format( "{0}_{1}_{2}.bmp", pos.SectorEnum, pos.StartLocation, pos.Length );
            }
        }
Exemple #3
0
 internal Sprite(PatcherLib.Datatypes.Context context, string name, PatcherLib.Iso.KnownPosition pos )
 {
     this.Context = context;
     this.name = name;
     Position = pos;
     Size = (uint)pos.Length;
 }
 public StupidTM2Image4bpp( string name, int width, int height,
     PatcherLib.Iso.KnownPosition palettePosition,
     PatcherLib.Iso.KnownPosition firstPixelsPosition,
     params PatcherLib.Iso.KnownPosition[] otherPixelsPositions )
     : base(name, width, height, palettePosition, firstPixelsPosition, otherPixelsPositions)
 {
 }
Exemple #5
0
 internal CharacterSprite(PatcherLib.Datatypes.Context context, string name, SpriteAttributes attributes, SpriteLocation location)
     : base(context, name,
         context == PatcherLib.Datatypes.Context.US_PSP ? (PatcherLib.Iso.KnownPosition)new PatcherLib.Iso.PspIso.KnownPosition((PatcherLib.Iso.FFTPack.Files)location.Sector, 0, (int)location.Size) :
                                                          (PatcherLib.Iso.KnownPosition)new PatcherLib.Iso.PsxIso.KnownPosition((PatcherLib.Iso.PsxIso.Sectors)location.Sector, 0, (int)location.Size))
 {
     this.location = location;
     this.attributes = attributes;
 }
 public PalettedImage4bpp( 
     string name, 
     int width, int height, 
     int numPalettes,
     PatcherLib.Iso.KnownPosition imagePosition, 
     PatcherLib.Iso.KnownPosition palettePosition )
     : this(name, width, height, numPalettes, Palette.ColorDepth._16bit, imagePosition, palettePosition)
 {
 }
Exemple #7
0
        public StupidTM2Image(string name, int width, int height, PatcherLib.Iso.KnownPosition palettePosition, PatcherLib.Iso.KnownPosition[] pixelPositions)
            : base(name, width, height)
        {
            List<PatcherLib.Iso.KnownPosition> otherKnownPositionList = new List<PatcherLib.Iso.KnownPosition>();
            for (int index = 1; index < pixelPositions.Length; index++)
            {
                otherKnownPositionList.Add(pixelPositions[index]);
            }

            Build(name, width, height, palettePosition, pixelPositions[0], otherKnownPositionList.ToArray());
        }
Exemple #8
0
 public RawNybbleImage( string name, int width, int height, PatcherLib.Iso.KnownPosition position )
     : base(name, width, height)
 {
     this.position = position;
     if ( position is PatcherLib.Iso.PsxIso.KnownPosition )
     {
         var pos = position as PatcherLib.Iso.PsxIso.KnownPosition;
         saveFileName = string.Format( "{0}_{1}_{2}.bmp", pos.Sector, pos.StartLocation, pos.Length );
     }
     else if ( position is PatcherLib.Iso.PspIso.KnownPosition )
     {
         var pos = position as PatcherLib.Iso.PspIso.KnownPosition;
         saveFileName = string.Format( "{0}_{1}_{2}.bmp", pos.SectorEnum, pos.StartLocation, pos.Length );
     }
 }
Exemple #9
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;
                }
        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;
        }
 public PalettedImage8bppSectioned(
     string name, int width, int height, int numPalettes, Palette.ColorDepth depth, PatcherLib.Iso.KnownPosition imagePosition, PatcherLib.Iso.KnownPosition palettePosition, 
     bool ignoreAssert = false)
     : base(name, width, height, numPalettes, depth, imagePosition, palettePosition, ignoreAssert)
 {
 }
Exemple #12
0
 public static void PatchPsxIso( Stream iso, PatcherLib.Datatypes.PatchedByteArray patch )
 {
     if (patch is STRPatchedByteArray)
     {
         PatchPsxIso( iso, (STRPatchedByteArray)patch );
     }
     else
     {
         IsoPatch.PatchFileAtSector( IsoPatch.IsoType.Mode2Form1, iso, true, patch.Sector,
             patch.Offset, patch.GetBytes(), true );
     }
 }
Exemple #13
0
 public static void PatchPsxIso( Stream iso, PatcherLib.Datatypes.STRPatchedByteArray patch )
 {
     ReplaceStrFile( iso, (Sectors)patch.Sector, patch.GetBytes() );
 }
Exemple #14
0
 protected abstract AbstractSprite GetAbstractSpriteFromPspIso(System.IO.Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, bool ignoreCache);
Exemple #15
0
 private void AddOrReplaceCharMapDirectoryEntry( IList<PatcherLib.Iso.DirectoryEntry> dir, PatcherLib.Iso.DirectoryEntry newDirEnt )
 {
     var currentCharmapIndex = dir.IndexOf( dir.Find( d => d.Filename == newDirEnt.Filename ) );
     if (currentCharmapIndex != -1)
     {
         dir[currentCharmapIndex] = newDirEnt;
     }
     else
     {
         dir.Add( newDirEnt );
         dir.Sort( ( a, b ) => a.Filename.CompareTo( b.Filename ) );
     }
 }
Exemple #16
0
 protected override AbstractSprite GetAbstractSpriteFromPspIso(System.IO.Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, bool ignoreCache)
 {
     return GetFromIso(iso, ignoreCache);
 }
Exemple #17
0
        public override IList<PatchedByteArray> GetPatches( PatcherLib.Datatypes.Context context )
        {
            var result = new List<PatchedByteArray>( 2 );
            var bytes = ToByteArray();
            if (context == Context.US_PSX)
            {
                result.Add( PatcherLib.Iso.PsxIso.Propositions.GetPatchedByteArray( bytes ) );
                foreach (var good in goodPsxInstructions)
                {
                    result.Add( new PatchedByteArray( PatcherLib.Iso.PsxIso.Sectors.WORLD_WLDCORE_BIN,
                        good.Item1, good.Item2.ToArray() ) );
                }
            }
            else if (context == Context.US_PSP)
            {
                PatcherLib.Iso.PspIso.Propositions.ForEach( kp => result.Add( kp.GetPatchedByteArray( bytes ) ) );
            }

            return result;
        }
Exemple #18
0
 public WepSprite(PatcherLib.Datatypes.Context context, Wep wep, string name, PatcherLib.Iso.KnownPosition pos)
     : base(context, name, pos)
 {
     this.WEP = wep;
 }
Exemple #19
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 );
 }
Exemple #20
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 );
        }
Exemple #21
0
        //public static void PatchFile( string filename, int index, byte[] bytes )
        //{
        //    FileStream stream = null;
        //    try
        //    {
        //        stream = new FileStream( filename, FileMode.Open );
        //        PatchFile( stream, index, bytes );
        //    }
        //    catch( Exception )
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        if( stream != null )
        //        {
        //            stream.Flush();
        //            stream.Close();
        //            stream = null;
        //        }
        //    }
        //}

        //public static void PatchFile( Stream stream, int index, byte[] bytes )
        //{
        //    PatchFile( stream, index, 0, bytes );
        //}

        public static void PatchFile( Stream stream, PatcherLib.Iso.PspIso.PspIsoInfo info, int index, int offset, byte[] bytes )
        {
            try
            {
                long fftpackLocation = info[PspIso.Sectors.PSP_GAME_USRDIR_fftpack_bin] * 2048;
                stream.Seek( fftpackLocation + ( index - 1 ) * 4 + 8, SeekOrigin.Begin );
                byte[] pointer = new byte[4];
                stream.Read( pointer, 0, 4 );

                stream.Seek( fftpackLocation + pointer.ToUInt32() + offset, SeekOrigin.Begin );

                stream.Write( bytes, 0, bytes.Length );
            }
            catch ( Exception )
            {
                throw;
            }
        }
Exemple #22
0
 public static byte[] GetFileFromIso( Stream stream, PatcherLib.Iso.PspIso.PspIsoInfo info, Files file )
 {
     stream.Seek( info[PspIso.Sectors.PSP_GAME_USRDIR_fftpack_bin] * 2048, SeekOrigin.Begin );
     return GetFileFromFFTPack( stream, file );
 }
Exemple #23
0
 public IList<string> GenerateCodes( PatcherLib.Datatypes.Context context )
 {
     if (context == Context.US_PSP)
     {
         return Codes.GenerateCodes( Context.US_PSP, PSPResources.Binaries.Propositions, this.ToByteArray(), 0x2E9634 );
     }
     else
     {
         return Codes.GenerateCodes( Context.US_PSX, PSXResources.Binaries.Propositions, this.ToByteArray(), 0x9D380, Codes.CodeEnabledOnlyWhen.World );
     }
 }
Exemple #24
0
 public static void ApplyPatch( Stream stream, PspIsoInfo info, PatcherLib.Datatypes.PatchedByteArray patch )
 {
     if ( patch.SectorEnum != null )
     {
         if ( patch.SectorEnum.GetType() == typeof( PspIso.Sectors ) )
         {
             stream.WriteArrayToPosition( patch.Bytes, (int)( info[(PspIso.Sectors)patch.SectorEnum] * 2048 ) + patch.Offset );
         }
         else if ( patch.SectorEnum.GetType() == typeof( FFTPack.Files ) )
         {
             FFTPack.PatchFile( stream, info, (int)( (FFTPack.Files)patch.SectorEnum ), (int)patch.Offset, patch.Bytes );
         }
         else
         {
             throw new ArgumentException( "invalid type" );
         }
     }
 }
Exemple #25
0
 public string GetCodeHeader( PatcherLib.Datatypes.Context context )
 {
     return context == Context.US_PSP ? "_C0 Propositions" : "\"Propositions";
 }
 public Greyscale4bppImage( string name, int width, int height, PatcherLib.Iso.KnownPosition imagePosition )
     : base(name, width, height, 1, imagePosition, new FakeGreyscalePalettePosition())
 {
 }
 public PalettedImage4bppSectioned(string name, int width, int height, PatcherLib.Iso.KnownPosition imagePosition, PatcherLib.Iso.KnownPosition palettePosition)
     : base(name, width, height, 1, imagePosition, palettePosition)
 {
 }
Exemple #28
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;
        }
Exemple #29
0
 public override PatcherLib.Datatypes.Set<KeyValuePair<string, byte>> GetPreferredDTEPairs( PatcherLib.Datatypes.Set<string> replacements, PatcherLib.Datatypes.Set<KeyValuePair<string, byte>> currentPairs, Stack<byte> dteBytes, System.ComponentModel.BackgroundWorker worker )
 {
     return base.GetPreferredDTEPairs( replacements, currentPairs, dteBytes, worker );
 }
Exemple #30
0
        private void Build(string name, int width, int height,
            PatcherLib.Iso.KnownPosition palettePosition,
            PatcherLib.Iso.KnownPosition firstPixelsPosition,
            PatcherLib.Iso.KnownPosition[] otherPixelsPositions)
        {
            PalettePosition = palettePosition;
            var pixelPositions = new List<PatcherLib.Iso.KnownPosition>( 1 + otherPixelsPositions.Length );
            pixelPositions.Add( firstPixelsPosition );
            pixelPositions.AddRange( otherPixelsPositions );

            int sum = 0;
            pixelPositions.ForEach( kp => sum += kp.Length );

            PixelPositions = pixelPositions.AsReadOnly();

            var position = firstPixelsPosition;
            if (position is PatcherLib.Iso.PsxIso.KnownPosition)
            {
                var pos = position as PatcherLib.Iso.PsxIso.KnownPosition;
                saveFileName = string.Format( "{0}_{1}_{2}.bmp", pos.Sector, pos.StartLocation, pos.Length );
            }
            else if (position is PatcherLib.Iso.PspIso.KnownPosition)
            {
                var pos = position as PatcherLib.Iso.PspIso.KnownPosition;
                saveFileName = string.Format( "{0}_{1}_{2}.bmp", pos.SectorEnum, pos.StartLocation, pos.Length );
            }
        }