Example #1
1
 protected AbstractSprite( IList<byte> bytes, params IList<byte>[] extraBytes )
     : this()
 {
     OriginalSize = bytes.Count;
     Palettes = BuildPalettes( bytes.Sub( 0, 16 * 32 - 1 ) );
     Pixels = BuildPixels( bytes.Sub( 16 * 32 ), extraBytes );
 }
Example #2
1
 public DirectoryEntry( IList<byte> bytes )
 {
     System.Diagnostics.Debug.Assert( bytes[0] == bytes.Count );
     Sector = bytes.Sub( 2, 2 + 4 - 1 ).ToUInt32();
     Size = bytes.Sub( 10, 10 + 4 - 1 ).ToUInt32();
     Timestamp = new DateTime( bytes[18] + 1900, bytes[19], bytes[20], bytes[21], bytes[22], bytes[23] );
     GMTOffset = bytes[24];
     MiddleBytes = bytes.Sub( 25, 25 + 7 - 1 ).ToArray();
     byte nameLength = bytes[32];
     Filename = System.Text.Encoding.ASCII.GetString( bytes.Sub( 33, 33 + nameLength - 1 ).ToArray() );
     byte padding = (byte)(((nameLength % 2) == 0) ? 1 : 0);
     ExtendedBytes = bytes.Sub( 33 + nameLength + padding, bytes[0] - 1 ).ToArray();
 }
        protected override IList<byte> BuildPixels( IList<byte> bytes, IList<byte>[] extraBytes )
        {
            List<byte> result = new List<byte>( 36864 * 2 );
            foreach( byte b in bytes.Sub( 0, 36864 - 1 ) )
            {
                result.Add( b.GetLowerNibble() );
                result.Add( b.GetUpperNibble() );
            }

            result.AddRange( Decompress( bytes.Sub( 36864 ) ) );

            result.AddRange( new byte[Math.Max( 0, 488 * 256 - result.Count )] );
            return result.ToArray();
        }
Example #4
1
        private Shape( IList<byte> bytes, string name, Rectangle relevantRectangle )
        {
            RelevantRectangle = relevantRectangle;
            this.name = name;
            int jump = (int)bytes.Sub( 0, 3 ).ToUInt32();
            int secondHalf = bytes[4] + bytes[5] * 256;

            List<uint> offsets = new List<uint>();
            offsets.Add( 0 );
            uint addy = 0;
            int i =0 ;
            do
            {
                addy = bytes.Sub( 0x0C + 4 * i, 0x0C + 4 * i + 3 ).ToUInt32();
                i++;
                if( addy != 0 )
                {
                    offsets.Add( addy );
                }
            } while( addy != 0 );

            frames = new List<Frame>( offsets.Count );
            for( i = 0; i < offsets.Count; i++ )
            {
                frames.Add( new Frame( bytes.Sub( (int)(offsets[i] + 0x40A) ), i >= secondHalf ? 256 : 0 ) );
            }

            if( jump > 8 )
            {
                offsets = new List<uint>();
                offsets.Add( 0 );
                addy = 0;
                i = 0;
                do
                {
                    addy = bytes.Sub( jump + 4 * i + 4, jump + 4 * i + 3 + 4 ).ToUInt32();
                    i++;
                    if( addy != 0 )
                    {
                        offsets.Add( addy );
                    }
                } while( addy != 0 );
            }
            for( i = 0; i < offsets.Count; i++ )
            {
                frames.Add( new Frame( bytes.Sub( (int)(offsets[i] + jump + 0x402) ), i >= secondHalf ? 256 : 0 ) );
            }
        }
Example #5
1
        public PartitionedFile( GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList<byte> bytes )
            : base( map, layout, false )
        {
            PartitionSize = layout.Size / NumberOfSections;
            List<IList<string>> sections = new List<IList<string>>( NumberOfSections );
            for ( int i = 0; i < NumberOfSections; i++ )
            {
                sections.Add(TextUtilities.ProcessList(bytes.Sub(i * PartitionSize, (i + 1) * PartitionSize - 1), map));
                if ( sections[i].Count < SectionLengths[i] )
                {
                    string[] newSection = new string[SectionLengths[i]];
                    sections[i].CopyTo( newSection, 0 );
                    new string[SectionLengths[i] - sections[i].Count].CopyTo( newSection, sections[i].Count );
                    sections[i] = newSection;
                }
                else if (sections[i].Count > SectionLengths[i])
                {
                    sections[i] = sections[i].Sub(0, SectionLengths[i] - 1);
                }

                System.Diagnostics.Debug.Assert(sections[i].Count == SectionLengths[i]);
            }
            Sections = sections.AsReadOnly();
            PopulateDisallowedSections();
        }
Example #6
1
        public OPNBK( IList<byte> bytes )
        {
            const int start0 = 0;
            const int end0 = 320 * 240 * 2 - 1;
            const int start1 = end0 + 1;
            const int end1 = start1 + 256 * 240 * 2 - 1;
            const int start2 = end1 + 1;
            const int end2 = start2 + 210 * 180 * 2 - 1;
            const int start3 = end2 + 1;
            const int end3 = start3 + 210 * 180 * 2 - 1;
            const int start4 = end3 + 1;
            const int end4 = start4 + 210 * 180 * 2 - 1;
            const int start5 = end4 + 1;
            const int end5 = start5 + 210 * 180 * 2 - 1;
            const int start6 = end5 + 1;
            const int end6 = start6 + 512 * 240 * 2 - 1;

            images = new Image[7];
            images[0] = Utilities.ReadBytesAsRawImage( bytes.Sub( start0, end0 ), 320, 240 ).ToImage();
            images[1] = Utilities.ReadBytesAsRawImage( bytes.Sub( start1, end1 ), 256, 240 ).ToImage();
            images[2] = Utilities.ReadBytesAsRawImage( bytes.Sub( start2, end2 ), 210, 180 ).ToImage();
            images[3] = Utilities.ReadBytesAsRawImage( bytes.Sub( start3, end3 ), 210, 180 ).ToImage();
            images[4] = Utilities.ReadBytesAsRawImage( bytes.Sub( start4, end4 ), 210, 180 ).ToImage();
            images[5] = Utilities.ReadBytesAsRawImage( bytes.Sub( start5, end5 ), 210, 180 ).ToImage();
            images[6] = Utilities.ReadBytesAsRawImage( bytes.Sub( start6, end6 ), 512, 240 ).ToImage();

        }
Example #7
1
 public EVTCHR(IList<byte> bytes)
 {
     System.Diagnostics.Debug.Assert(bytes.Count == numSegments * Segment.NumBytes);
     segments = new Segment[numSegments];
     for (int i = 0; i < numSegments; i++)
     {
         segments[i] = new Segment(bytes.Sub(i * Segment.NumBytes, (i + 1) * Segment.NumBytes - 1));
     }
 }
Example #8
1
        public Frame( IList<byte> bytes, int yOffset )
        {
            int numberOfTiles = bytes[0] + bytes[1] * 256;
            tiles = new List<Tile>( numberOfTiles + 1 );
            for( int i = 0; i <= numberOfTiles; i++ )
            {
                tiles.Add( new Tile( bytes.Sub( 2 + i * 4, 2 + i * 4 + 3 ), yOffset ) );
            }

            tiles.Reverse();
        }
Example #9
0
 public ENTD( int start, IList<byte> bytes, ENTD defaults )
 {
     Default = defaults;
     Events = new Event[0x80];
     for( int i = 0; i < 0x80; i++ )
     {
         Events[i] = new Event(
             i + start,
             bytes.Sub( i * 16 * 40, (i + 1) * 16 * 40 - 1 ),
             defaults == null ? null : defaults.Events[i] );
     }
 }
Example #10
0
        protected override IList<byte> BuildPixels(IList<byte> bytes, params IList<byte>[] extraBytes)
        {
            List<byte> result = new List<byte>(36864 * 2);
            foreach (byte b in bytes.Sub(0, 36863))
            {
                result.Add(b.GetLowerNibble());
                result.Add(b.GetUpperNibble());
            }

            result.AddRange(Decompress(bytes.Sub(36864)));

            foreach (IList<byte> extra in extraBytes)
            {
                foreach (byte b in extra)
                {
                    result.Add(b.GetLowerNibble());
                    result.Add(b.GetUpperNibble());
                }
            }

            return result.ToArray();
        }
Example #11
0
        public SectionedFile( GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList<byte> bytes, string fileComments, IList<string> sectionComments, bool compressible )
            : base(map, layout, fileComments, sectionComments, compressible)
        {
            List<IList<string>> sections = new List<IList<string>>( NumberOfSections );

            for ( int i = 0; i < NumberOfSections; i++ )
            {
                uint start = PatcherLib.Utilities.Utilities.BytesToUInt32( bytes.Sub( i * 4, ( i + 1 ) * 4 - 1 ) );
                uint stop = PatcherLib.Utilities.Utilities.BytesToUInt32( bytes.Sub( ( i + 1 ) * 4, ( i + 2 ) * 4 - 1 ) ) - 1;
                if ( i == NumberOfSections - 1 )
                {
                    stop = (uint)bytes.Count - 1 - (uint)DataStart;
                }
                IList<byte> thisSection = bytes.Sub( (int)( start + DataStart ), (int)( stop + DataStart ) );
                if ( compressible )
                {
                    thisSection = TextUtilities.Decompress( bytes, thisSection, (int)( start + DataStart ) );
                }
                sections.Add( TextUtilities.ProcessList( thisSection, layout.AllowedTerminators[0], CharMap ) );
            }
            Sections = sections.AsReadOnly();
            PopulateDisallowedSections();
        }
Example #12
0
        public FFTFont( IList<byte> bytes, IList<byte> widthBytes )
        {
            GlyphWidths = new FFTFontWidths( this );
            Glyphs = new Glyph[2200];
            for( int i = 0; i < 2200; i++ )
            {
                Glyphs[i] = new Glyph( i, widthBytes[i], bytes.Sub( i * 35, (i + 1) * 35 - 1 ) );
            }

            #if DEBUG
            using ( System.Drawing.Bitmap b = new System.Drawing.Bitmap( 550, 560 ) )
            {
                for ( int i = 0; i < 2200; i++ )
                {
                    DrawGlyphOnBitmap( b, Glyphs[i], new System.Drawing.Point( 10 * ( i % 55 ), 14 * ( i / 55 ) ) );
                }
                b.Save( "font.png", System.Drawing.Imaging.ImageFormat.Png );
            }
            #endif
        }
Example #13
0
        public Frame( IList<byte> bytes, int yOffset,string name )
        {
            int rotation = 0;
            int ydisplayoffset = 0;
            int numberOfTiles = bytes[0] + bytes[1] * 256;
            if (name == "WEP1" || name == "WEP2" ||name == "EFF1" || name == "EFF2" )
            {
                numberOfTiles = 0;
                rotation = bytes[0] + bytes[1] * 256;
                ydisplayoffset = bytes[0] / 4;

            }
            tiles = new List<Tile>( numberOfTiles + 1 );
            for( int i = 0; i <= numberOfTiles; i++ )
            {
                tiles.Add( new Tile( bytes.Sub( 2 + i * 4, 2 + i * 4 + 3 ), yOffset,rotation) );

            }

            tiles.Reverse();
        }
Example #14
0
        public PartitionedFile( GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList<byte> bytes, string fileComments, IList<string> sectionComments )
            : base(map, layout, fileComments, sectionComments, false)
        {
            PartitionSize = layout.Size / NumberOfSections;
            List<IList<string>> sections = new List<IList<string>>( NumberOfSections );
            for ( int i = 0; i < NumberOfSections; i++ )
            {
                sections.Add(TextUtilities.ProcessList(bytes.Sub(i * PartitionSize, (i + 1) * PartitionSize - 1), layout.AllowedTerminators, map));

                if ( sections[i].Count < SectionLengths[i] )
                {
                    string[] newSection = new string[SectionLengths[i]];
                    sections[i].CopyTo( newSection, 0 );
                    new string[SectionLengths[i] - sections[i].Count].CopyTo( newSection, sections[i].Count );
                    sections[i] = newSection;
                }
                else if (sections[i].Count > SectionLengths[i])
                {
                    sections[i] = sections[i].Sub(0, SectionLengths[i] - 1);
                }

                if (layout.AllowedTerminators.Count > 1)
                {
                    Dictionary<byte, int> counts = new Dictionary<byte, int>();
                    layout.AllowedTerminators.ForEach(b => counts[b] = 0);

                    bytes.FindAll(b => layout.AllowedTerminators.Contains(b)).ForEach(b => counts[b]++);
                    List<KeyValuePair<byte, int>> countList = new List<KeyValuePair<byte, int>>(counts);
                    countList.Sort((a, b) => b.Value.CompareTo(a.Value));
                    this.SelectedTerminator = countList[0].Key;
                }

                System.Diagnostics.Debug.Assert(sections[i].Count == SectionLengths[i]);
            }
            Sections = sections.AsReadOnly();
            PopulateDisallowedSections();
        }
Example #15
0
        private void ProcessPage( int page, IList<byte> bytes )
        {
            int startIndex = page * portraitsPerPage;
            IList<byte> truePixels = GetTruePixels( bytes.Sub( 0, portraitsPerPage * portraitWidth * portraitHeight / 2 ) );

            for ( int i = 0; i < portraitsPerPage; i++ )
            {
                Palettes[page * portraitsPerPage + i] = new Palette(
                    bytes.Sub(
                        i * paletteSize + portraitsPerPage * portraitWidth * portraitHeight / 2,
                        ( i + 1 ) * paletteSize + portraitsPerPage * portraitWidth * portraitHeight / 2 - 1 ) );
            }

            for ( int row = 0; row < rowsPerPage; row++ )
            {
                for ( int col = 0; col < colsPerPage; col++ )
                {
                    Bitmap b = new Bitmap( portraitWidth, portraitHeight, PixelFormat.Format4bppIndexed );
                    ColorPalette p = b.Palette;
                    Palette.FixupColorPalette( p, Palettes, startIndex + row * col, 0 );
                    b.Palette = p;
                    BitmapData bmd = b.LockBits( new Rectangle( Point.Empty, b.Size ), ImageLockMode.WriteOnly, PixelFormat.Format4bppIndexed );

                    int xOffset = col * portraitWidth;
                    int yOffset = row * portraitHeight;

                    for ( int x = 0; x < portraitWidth; x++ )
                    {
                        for ( int y = 0; y < portraitHeight; y++ )
                        {
                            bmd.SetPixel4bpp( x, y, truePixels[xOffset + x + ( yOffset + y ) * portraitWidth * colsPerPage] );
                        }
                    }
                    b.UnlockBits( bmd );
                    Images[startIndex + row * colsPerPage + col] = b;
                    b.Save( string.Format( "{0}.png", startIndex + row * colsPerPage + col ), ImageFormat.Png );
                }
            }

        }
Example #16
0
            public GraphicStructureList( IList<byte> bytes
#if DEBUG
                , int startIndex
#endif
                )
            {
                Count = (UInt16)( ( bytes[1] << 8 ) + bytes[0] );
                Unknown = (UInt16)( ( bytes[3] << 8 ) + bytes[2] );
                GraphicStructure[] structs = new GraphicStructure[Count];
                int currentIndex = 4;
                for ( int i = 0; i < Count; i++ )
                {
                    int consumed = 0;
                    structs[i] = GraphicStructure.GetStructure( bytes.Sub( currentIndex ), out consumed );
                #if DEBUG
                    Console.Out.WriteLine( "{0} from {1}-{2}", structs[i].Bounds, startIndex + currentIndex+8, startIndex + currentIndex + consumed );
                #endif
                    currentIndex += consumed;
                }

                Structures = structs.AsReadOnly();
            }
Example #17
0
            public static GraphicStructure GetStructure( IList<byte> bytes, out int bytesConsumed )
            {
                int x = ( bytes[1] << 8 ) + bytes[0];
                int y = ( bytes[3] << 8 ) + bytes[2];
                int w = ( bytes[5] << 8 ) + bytes[4];
                int h = ( bytes[7] << 8 ) + bytes[6];

                int pixBytes = w * h * 2;
                byte[] pix = new byte[pixBytes];
                bytes.Sub( 8, 8 + pixBytes - 1 ).CopyTo( pix, 0 );

                bytesConsumed = pixBytes + 8;
                return new GraphicStructure { Bounds = new System.Drawing.Rectangle( x, y, w, h ), Pixels = pix.AsReadOnly() };
            }
Example #18
0
        public ItemAttributes( byte value, IList<byte> bytes, ItemAttributes defaults )
        {
            Value = value;
            PA = bytes[0];
            MA = bytes[1];
            Speed = bytes[2];
            Move = bytes[3];
            Jump = bytes[4];

            PermanentStatuses = new Statuses( bytes.Sub( 5, 9 ), defaults == null ? null : defaults.PermanentStatuses );
            StatusImmunity = new Statuses( bytes.Sub( 10, 14 ), defaults == null ? null : defaults.StatusImmunity );
            StartingStatuses = new Statuses( bytes.Sub( 15, 19 ), defaults == null ? null : defaults.StartingStatuses );

            Absorb = new Elements( bytes[20] );
            Cancel = new Elements( bytes[21] );
            Half = new Elements( bytes[22] );
            Weak = new Elements( bytes[23] );
            Strong = new Elements( bytes[24] );

            if( defaults != null )
            {
                Default = defaults;
                Absorb.Default = Default.Absorb;
                Cancel.Default = Default.Cancel;
                Half.Default = Default.Half;
                Weak.Default = Default.Weak;
                Strong.Default = Default.Strong;
            }
        }
Example #19
0
        private Ability( string name, UInt16 offset, IList<byte> first )
        {
            Name = name;
            Offset = offset;
            JPCost = PatcherLib.Utilities.Utilities.BytesToUShort( first[0], first[1] );
            LearnRate = first[2];

            bool dummy = false;
            PatcherLib.Utilities.Utilities.CopyByteToBooleans( first[3],
                ref learnWithJP, ref action, ref learnOnHit, ref blank1, ref dummy, ref dummy, ref dummy, ref dummy );
            learnWithJP = !learnWithJP;

            AbilityType = (AbilityType)(first[3] & 0x0F);

            AIFlags = new AIFlags( first.Sub( 4, 6 ) );

            PatcherLib.Utilities.Utilities.CopyByteToBooleans( first[7],
                ref unknown1, ref unknown2, ref unknown3, ref blank2, ref blank3, ref blank4, ref blank5, ref unknown4 );
        }
Example #20
0
        public StatusAttribute( string name, byte value, IList<byte> bytes, StatusAttribute defaults )
        {
            Default = defaults;
            Name = name;
            Value = value;

            Blank1 = bytes[0];
            Blank2 = bytes[1];
            Order = bytes[2];
            CT = bytes[3];

            PatcherLib.Utilities.Utilities.CopyByteToBooleans( bytes[4], ref FreezeCT, ref Unknown1, ref Unknown2, ref Unknown3, ref Unknown4, ref Unknown5, ref Unknown6, ref KO );
            PatcherLib.Utilities.Utilities.CopyByteToBooleans( bytes[5], ref CanReact, ref Blank, ref IgnoreAttack, ref Unknown7, ref Unknown8, ref Unknown9, ref Unknown10, ref Unknown11 );
            CanReact = !CanReact;
            Cancels = new Statuses( bytes.Sub( 6, 10 ), defaults == null ? null : defaults.Cancels );
            CantStackOn = new Statuses( bytes.Sub( 11, 15 ), defaults == null ? null : defaults.CantStackOn );
        }
Example #21
0
        public AllStatusAttributes( IList<byte> bytes )
        {
            StatusAttributes = new StatusAttribute[40];
            byte[] defaultBytes = FFTPatch.Context == Context.US_PSP ? PSPResources.StatusAttributesBin : PSXResources.StatusAttributesBin;

            string[] names = FFTPatch.Context == Context.US_PSP ? PSPResources.Statuses : PSXResources.Statuses;
            for( int i = 0; i < 40; i++ )
            {
                StatusAttributes[i] =
                    new StatusAttribute( names[i], (byte)i, bytes.Sub( 16 * i, 16 * i + 15 ),
                        new StatusAttribute( names[i], (byte)i, defaultBytes.Sub( 16 * i, 16 * i + 15 ) ) );
            }
        }
Example #22
0
 public AllInflictStatuses( IList<byte> bytes )
 {
     byte[] defaultBytes = FFTPatch.Context == Context.US_PSP ? PSPResources.InflictStatusesBin : PSXResources.InflictStatusesBin;
     InflictStatuses = new InflictStatus[0x80];
     for( int i = 0; i < 0x80; i++ )
     {
         InflictStatuses[i] = new InflictStatus( (byte)i, bytes.Sub( i * 6, (i + 1) * 6 - 1 ),
             new InflictStatus( (byte)i, defaultBytes.Sub( i * 6, (i + 1) * 6 - 1 ) ) );
     }
 }
Example #23
0
 public InflictStatus( byte value, IList<byte> bytes, InflictStatus defaults )
 {
     Default = defaults;
     Value = value;
     PatcherLib.Utilities.Utilities.CopyByteToBooleans( bytes[0], ref AllOrNothing, ref Random, ref Separate, ref Cancel, ref Blank1, ref Blank2, ref Blank3, ref Blank4 );
     Statuses = new Statuses( bytes.Sub( 1, 5 ), defaults == null ? null : defaults.Statuses );
 }
Example #24
0
        public AllPropositions( IList<byte> bytes, AllPropositions defaults, bool brokenLevelBonuses )
        {
            Default = defaults;
            var names = FFTPatch.Context == Context.US_PSP ? PSPResources.Lists.Propositions : PSXResources.Lists.Propositions;

            List<Proposition> props = new List<Proposition>();
            if (defaults != null)
            {
                for (int i = 0; i < NumPropositions; i++)
                {
                    props.Add( new Proposition( names[i], bytes.Sub( i * propLength, (i + 1) * propLength - 1 ), defaults.Propositions[i] ) );
                }
            }
            else
            {
                for (int i = 0; i < NumPropositions; i++)
                {
                    props.Add( new Proposition( names[i], bytes.Sub( i * propLength, (i + 1) * propLength - 1 ) ) );
                }
            }

            Prices = new UInt16[8];
            for (int i = 0; i < 8; i++)
            {
                var b = bytes.Sub( propLength * NumPropositions + i * 2 + 2, propLength * NumPropositions + i * 2 + 2 + 1 );
                Prices[i] = Utilities.BytesToUShort( b[0], b[1] );
            }

            unknownBytes = bytes.Sub( 0x8b2, 0x8bf ).ToArray();

            propTypeBonuses = new TupleDictionary<PropositionType, PropositionClass, byte>();

            foreach (PropositionType type in (PropositionType[])Enum.GetValues( typeof( PropositionType ) ))
            {
                foreach (PropositionClass _class in (PropositionClass[])Enum.GetValues( typeof( PropositionClass ) ))
                {
                    propTypeBonuses[type, _class] = bytes[0x8C0 + ((int)type - 1) * 22 + (int)_class];
                }
            }
            propTypeBonuses = new TupleDictionary<PropositionType, PropositionClass, byte>( propTypeBonuses, false, true );

            bfBonuses = new TupleDictionary<BraveFaithNeutral, PropositionClass, byte>();
            foreach (BraveFaithNeutral bfn in (BraveFaithNeutral[])Enum.GetValues( typeof( BraveFaithNeutral ) ))
            {
                foreach (PropositionClass _class in (PropositionClass[])Enum.GetValues( typeof( PropositionClass ) ))
                {
                    bfBonuses[bfn, _class] = bytes[0x970 + ((int)bfn - 1) * 22 + (int)_class];
                }
            }
            bfBonuses = new TupleDictionary<BraveFaithNeutral, PropositionClass, byte>( bfBonuses, false, true );

            braveBonuses = new TupleDictionary<BraveFaithNeutral, BraveFaithRange, byte>();
            faithBonuses = new TupleDictionary<BraveFaithNeutral, BraveFaithRange, byte>();
            levelBonuses = new TupleDictionary<BraveFaithNeutral, LevelRange, byte>();

            int levelBonusesOffset = brokenLevelBonuses ? 0x9B4 : 0x9D4;
            //int levelBonusesOffset = 0x9D4;

            foreach (BraveFaithNeutral bfn in (BraveFaithNeutral[])Enum.GetValues( typeof( BraveFaithNeutral ) ))
            {
                foreach (BraveFaithRange range in (BraveFaithRange[])Enum.GetValues( typeof( BraveFaithRange ) ))
                {
                    braveBonuses[bfn, range] = bytes[0x9B4 + ((int)bfn - 1) * 5 + (int)range];
                    faithBonuses[bfn, range] = bytes[0x9C4 + ((int)bfn - 1) * 5 + (int)range];
                }

                foreach (LevelRange range in (LevelRange[])Enum.GetValues( typeof( LevelRange ) ))
                {
                    levelBonuses[bfn, range] = bytes[levelBonusesOffset + ((int)bfn - 1) * 10 + (int)range];
                }
            }

            braveBonuses = new TupleDictionary<BraveFaithNeutral, BraveFaithRange, byte>( braveBonuses, false, true );
            faithBonuses = new TupleDictionary<BraveFaithNeutral, BraveFaithRange, byte>( faithBonuses, false, true );
            levelBonuses = new TupleDictionary<BraveFaithNeutral, LevelRange, byte>( levelBonuses, false, true );

            treasureLandJpBonuses = new Dictionary<PropositionType, BonusIndex>();
            treasureLandGilBonuses = new Dictionary<PropositionType, BonusIndex>();
            bonusCashGilBonuses = new TupleDictionary<PropositionType, BonusPercent, BonusIndex>();
            bonusCashJpBonuses = new TupleDictionary<PropositionType, BonusPercent, BonusIndex>();

            foreach (PropositionType type in (PropositionType[])Enum.GetValues( typeof( PropositionType ) ))
            {
                treasureLandGilBonuses[type] = (BonusIndex)bytes[0x9F4 + 2 * ((int)type - 1)];
                treasureLandJpBonuses[type] = (BonusIndex)bytes[0x9F4 + 2 * ((int)type - 1) + 1];

                bonusCashGilBonuses[type, BonusPercent._10Percent] = (BonusIndex)bytes[0xA04 + ((int)type - 1) * 6 + 2 * 2];
                bonusCashGilBonuses[type, BonusPercent._40Percent] = (BonusIndex)bytes[0xA04 + ((int)type - 1) * 6 + 2 * 1];
                bonusCashGilBonuses[type, BonusPercent._50Percent] = (BonusIndex)bytes[0xA04 + ((int)type - 1) * 6 + 2 * 0];

                bonusCashJpBonuses[type, BonusPercent._10Percent] = (BonusIndex)bytes[0xA04 + ((int)type - 1) * 6 + 2 * 2 + 1];
                bonusCashJpBonuses[type, BonusPercent._40Percent] = (BonusIndex)bytes[0xA04 + ((int)type - 1) * 6 + 2 * 1 + 1];
                bonusCashJpBonuses[type, BonusPercent._50Percent] = (BonusIndex)bytes[0xA04 + ((int)type - 1) * 6 + 2 * 0 + 1];
            }
            bonusCashGilBonuses = new TupleDictionary<PropositionType, BonusPercent, BonusIndex>( bonusCashGilBonuses, false, true );
            bonusCashJpBonuses = new TupleDictionary<PropositionType, BonusPercent, BonusIndex>( bonusCashJpBonuses, false, true );

            SmallBonuses = new UInt16[8];
            LargeBonuses = new UInt16[8];
            for (int i = 0; i < 8; i++)
            {
                SmallBonuses[i] = Utilities.BytesToUShort( bytes[0xA34 + i * 2], bytes[0xA34 + i * 2 + 1] );
                LargeBonuses[i] = Utilities.BytesToUShort( bytes[0xA44 + i * 2], bytes[0xA44 + i * 2 + 1] );
            }

            JPMultipliers = new UInt16[10];
            GilMultipliers = new UInt16[10];

            for (int i = 0; i < 10; i++)
            {
                JPMultipliers[i] = Utilities.BytesToUShort( bytes[0xA54 + i * 2], bytes[0xA54 + i * 2 + 1] );
                GilMultipliers[i] = Utilities.BytesToUShort( bytes[0xA68 + i * 2], bytes[0xA68 + i * 2 + 1] );
            }

            Propositions = props.AsReadOnly();
        }
Example #25
0
        public AllItemAttributes( IList<byte> first, IList<byte> second )
        {
            List<ItemAttributes> temp = new List<ItemAttributes>( 0x65 );
            byte[] defaultFirst = second == null ? PSXResources.OldItemAttributesBin : PSPResources.OldItemAttributesBin;
            byte[] defaultSecond = second == null ? null : PSPResources.NewItemAttributesBin;

            for( byte i = 0; i < 0x50; i++ )
            {
                temp.Add( new ItemAttributes( i, first.Sub( i * 25, (i + 1) * 25 - 1 ),
                    new ItemAttributes( i, defaultFirst.Sub( i * 25, (i + 1) * 25 - 1 ) ) ) );
            }
            if( second != null )
            {
                for( byte i = 0x50; i < 0x65; i++ )
                {
                    temp.Add( new ItemAttributes( i, second.Sub( (i - 0x50) * 25, ((i - 0x50) + 1) * 25 - 1 ),
                        new ItemAttributes( i, defaultSecond.Sub( (i - 0x50) * 25, ((i - 0x50) + 1) * 25 - 1 ) ) ) );
                }
            }

            ItemAttributes = temp.ToArray();
        }
Example #26
0
        public AllMonsterSkills( IList<byte> bytes )
        {
            byte[] defaultBytes = FFTPatch.Context == Context.US_PSP ? PSPResources.MonsterSkillsBin : PSXResources.MonsterSkillsBin;

            MonsterSkills = new MonsterSkill[48];
            for ( int i = 0; i < 48; i++ )
            {
                MonsterSkills[i] = new MonsterSkill( (byte)( i + 0xB0 ), Names[i], bytes.Sub( 5 * i, 5 * i + 4 ),
                    new MonsterSkill( (byte)( i + 0xB0 ), Names[i], defaultBytes.Sub( 5 * i, 5 * i + 4 ) ) );
            }
        }
Example #27
0
        private static IList<DirectoryEntry> BuildDirectoryEntriesFromBytes( IList<byte> bytes )
        {
            List<DirectoryEntry> result = new List<DirectoryEntry>();
            for (int i = 0; i < bytes.Count; i++)
            {
                if (bytes[i] == 0) continue;

                IList<byte> entry = bytes.Sub( i, i + bytes[i] - 1 );
                result.Add( new DirectoryEntry( entry ) );
                i += bytes[i];
                i--;
            }
            return result;
        }
Example #28
0
        public WLDFACE( IList<byte> bytes )
        {
            Images = new Image[160];
            Palettes = new Palette[64*4];

            //byte[][] pixels = new byte[160][];
            //for ( int i = 0; i < 160; i++ )
            //{
            //    pixels[i] = new byte[32 * 48];
            //}

            //for ( int i = 0; i < bytes.Count; i++ )
            //{
            //    byte left = bytes[i].GetLowerNibble();
            //    byte right = bytes[i].GetUpperNibble();
            //}

            List<byte> truePixels = new List<byte>( portraitHeight * portraitWidth * portraitsPerPage * 4 );
            truePixels.AddRange( GetTruePixels( bytes.Sub( 0, portraitsPerPage * portraitWidth * portraitHeight / 2 - 1 ) ) );
            truePixels.AddRange( GetTruePixels( bytes.Sub( 32768, 32768 + portraitsPerPage * portraitWidth * portraitHeight / 2 - 1 ) ) );
            truePixels.AddRange( GetTruePixels( bytes.Sub( 65536, 65536 + portraitsPerPage * portraitWidth * portraitHeight / 2 - 1 ) ) );
            truePixels.AddRange( GetTruePixels( bytes.Sub( 98304, 98304 + portraitsPerPage * portraitWidth * portraitHeight / 2 - 1 ) ) );
            for ( int page = 0; page < 4; page++ )
            {
                int start = page * 32768 + portraitHeight * portraitWidth * portraitsPerPage / 2;
                for ( int pal = 0; pal < 64; pal++ )
                {
                    Palettes[pal + 64 * page] = new Palette( bytes.Sub( start + pal * 32, start + ( pal + 1 ) * 32 - 1 ) );
                }
            }

            Bitmap b = new Bitmap( portraitWidth * colsPerPage, portraitHeight * rowsPerPage * 4, PixelFormat.Format4bppIndexed );
            BitmapData bmd = b.LockBits( new Rectangle( Point.Empty, b.Size ), ImageLockMode.WriteOnly, PixelFormat.Format4bppIndexed );
            for ( int i = 0; i < truePixels.Count; i++ )
            {
                bmd.SetPixel4bpp( i % ( colsPerPage * portraitWidth ), i / colsPerPage / portraitWidth, truePixels[i] );
            }
            b.UnlockBits( bmd );

            for ( int i = 0; i < Palettes.Length; i++ )
            {
                ColorPalette pal = b.Palette;
                Palette.FixupColorPalette( pal, Palettes, i, 0 );
                b.Palette = pal;
                b.Save( string.Format( "{0}.png", i ), ImageFormat.Png );
            }


            for ( int i = 0; i < 4; i++ )
            {
                ProcessPage( i, bytes.Sub( pageSize * i, pageSize * ( i + 1 ) - 1 ) );

                //for ( int row = 0; row < 5; row++ )
                //{
                //    for ( int col = 0; col < 8; col++ )
                //    {
                //        Palettes[i * row * col] = new Palette( bytes.Sub( ( i + 1 ) * 32 * 48 / 2 * 5 * 8 + ( row * 8 * col * 32 ), ( i + 1 ) * 32 * 48 / 2 * 5 * 8 + ( row * 8 * col * 32 ) + 32 - 1 ) );
                //        using ( Bitmap b = new Bitmap( 32, 48, System.Drawing.Imaging.PixelFormat.Format4bppIndexed ) )
                //        {
                //            BitmapData bmd = b.LockBits( new Rectangle( Point.Empty, b.Size ), ImageLockMode.WriteOnly, PixelFormat.Format4bppIndexed );
                //            for ( int x = 0; x < 32; x++ )
                //            {
                //                for ( int y = 0; y < 48; y++ )
                //                {
                //                }
                //            }
                //            b.UnlockBits( bmd );
                //        }
                //    }
                //}
            }

            Pixels = BuildPixels( bytes.Sub( 0x0000, 0x77FF ) );

            Palettes = new Palette[64];
            for( int i = 0; i < 64; i++ )
            {
                Palettes[i] = new Palette( bytes.Sub( 0x7800 + 32 * i, 0x7800 + 32 * (i + 1) - 1 ) );
            }
        }
Example #29
0
        /// <summary>
        /// Decompresses the specified section.
        /// </summary>
        /// <param name="allBytes">A collection containing the bytes to decompress.</param>
        /// <param name="sectionBytes">A collection consisting ONLY of the bytes to decompress</param>
        /// <param name="sectionStart">The relative position of <paramref name="sectionBytes"/> in <paramref name="allBytes"/></param>
        /// <returns></returns>
        public static IList<byte> Decompress( IList<byte> allBytes, IList<byte> sectionBytes, int sectionStart )
        {
            IList<byte> result = new List<byte>();

            for( int i = 0; i < sectionBytes.Count; i++ )
            {
                if( sectionBytes[i] >= 0xF0 && sectionBytes[i] <= 0xF3 )
                {
                    int length;
                    int jump;
                    ProcessPointer( new byte[] { sectionBytes[i], sectionBytes[i + 1], sectionBytes[i + 2] }, out length, out jump );
                    if( (i + sectionStart - jump) < 0 || (i + sectionStart - jump + length) >= allBytes.Count )
                    {
                        result.AddRange( new byte[] { sectionBytes[i], sectionBytes[i + 1], sectionBytes[i + 2] } );
                    }
                    else
                    {
                        result.AddRange( allBytes.Sub( i + sectionStart - jump, i + sectionStart - jump + length - 1 ) );
                    }
                    i += 2;
                }
                else
                {
                    result.Add( sectionBytes[i] );
                }
            }

            return result;
        }
Example #30
0
        /// <summary>
        /// Adds lines of text in groups of a specified size to the StringBuilder.
        /// </summary>
        /// <param name="groupSize">Number of strings in each group</param>
        /// <param name="groupName">What to name each group.</param>
        /// <param name="lines">Lines to add</param>
        private static void AddGroups(StringBuilder sb, int groupSize, string groupName, IList<string> lines)
        {
            if (lines.Count == 0)
            {
                return;
            }
            else if (lines.Count <= groupSize)
            {
                if (groupName != string.Empty)
                    sb.Append(groupName + "\n");
                sb.AppendLines(lines);
            }
            else
            {
                int i = 0;
                int j = 1;
                for (i = 0; (i + 1) * groupSize < lines.Count; i++)
                {
                    if (groupName != string.Empty)
                        sb.Append(string.Format("{0}\\(part {1})\n", groupName, j++));
                    sb.AppendLines(lines.Sub(i * groupSize, (i + 1) * groupSize - 1));
                }

                if (groupName != string.Empty)
                    sb.Append(string.Format("{0}\\(part {1})\n", groupName, j++));
                sb.AppendLines(lines.Sub(i * groupSize, lines.Count - 1));
            }
        }