Ejemplo n.º 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 );
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 3
1
        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();
        }
Ejemplo n.º 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 ) );
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();

        }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 9
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));
                }
                GenericCharMap processCharMap = DteAllowed[i] ? CharMap : GetContextCharmap(layout.Context);
                sections.Add(TextUtilities.ProcessList(thisSection, layout.AllowedTerminators[0], processCharMap));
                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);
                }
            }
            Sections = sections.AsReadOnly();
            PopulateDisallowedSections();
        }
Ejemplo n.º 10
0
 private SpriteLocation(IList <byte> bytes, params SpriteLocation[] subSpriteLocations)
 {
     System.Diagnostics.Debug.Assert(bytes.Count == 8);
     Sector             = bytes.Sub(0, 3).ToUInt32();
     Size               = bytes.Sub(4).ToUInt32();
     SubSpriteLocations = subSpriteLocations.AsReadOnly();
 }
Ejemplo n.º 11
0
        public void UpdateView(JobLevels levels)
        {
            this.levels = levels;
            foreach (Control c in Controls)
            {
                if (c is NumericUpDownWithDefault)
                {
                    NumericUpDownWithDefault spinner = c as NumericUpDownWithDefault;
                    spinner.ValueChanged -= spinner_ValueChanged;
                    spinner.SetValueAndDefault(
                        ReflectionHelpers.GetFieldOrProperty <UInt16>(levels, spinner.Tag.ToString()),
                        ReflectionHelpers.GetFieldOrProperty <UInt16>(levels.Default, spinner.Tag.ToString()));
                    spinner.ValueChanged += spinner_ValueChanged;
                }
            }

            List <Requirements> reqs = new List <Requirements>(new Requirements[] {
                levels.Chemist, levels.Knight, levels.Archer, levels.Monk,
                levels.WhiteMage, levels.BlackMage, levels.TimeMage, levels.Summoner,
                levels.Thief, levels.Orator, levels.Mystic, levels.Geomancer,
                levels.Dragoon, levels.Samurai, levels.Ninja, levels.Arithmetician,
                levels.Bard, levels.Dancer, levels.Mime
            });

            if (FFTPatch.Context == Context.US_PSP)
            {
                reqs.Add(levels.DarkKnight);
                reqs.Add(levels.OnionKnight);
                reqs.Add(levels.Unknown);
            }
            IList <string> names     = FFTPatch.Context == Context.US_PSP ? PSPResources.Lists.JobNames : PSXResources.Lists.JobNames;
            IList <string> sideNames = names.Sub(0x4B, 0x5D);
            IList <string> topNames  = names.Sub(0x4A, 0x5D);

            for (int i = 0; i < sideNames.Count; i++)
            {
                labels[i].Text         = sideNames[i];
                verticalLabels[i].Text = topNames[i];
            }
            verticalLabels[topNames.Count - 1].Text = topNames[topNames.Count - 1];

            bool psp = FFTPatch.Context == Context.US_PSP;

            if (psp)
            {
                darkKnightLabel.Text          = names[0xA0];
                darkKnightVerticalLabel.Text  = names[0xA0];
                onionKnightLabel.Text         = names[0xA4];
                onionKnightVerticalLabel.Text = names[0xA4];
            }
            darkKnightLabel.Visible          = psp;
            darkKnightVerticalLabel.Visible  = psp;
            unknown1VerticalLabel.Visible    = psp;
            unknown2VerticalLabel.Visible    = psp;
            unknownLabel.Visible             = psp;
            onionKnightLabel.Visible         = psp;
            onionKnightVerticalLabel.Visible = psp;

            requirementsEditor1.Requirements = reqs;
        }
Ejemplo n.º 12
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;
            }
        }
Ejemplo n.º 13
0
 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);
 }
Ejemplo n.º 14
0
        public AllMoveFindItems(Context context, IList <byte> bytes, AllMoveFindItems def)
        {
            Default    = def;
            ourContext = context;
            const int      numMaps = 128;
            IList <string> names   = context == Context.US_PSP ? PSPResources.Lists.MapNames : PSXResources.Lists.MapNames;

            List <MapMoveFindItems> moveFindItems = new List <MapMoveFindItems>(numMaps * 4);

            if (Default == null)
            {
                for (int i = 0; i < numMaps; i++)
                {
                    moveFindItems.Add(new MapMoveFindItems(bytes.Sub(i * 4 * 4, (i + 1) * 4 * 4 - 1), names[i], context));
                }
            }
            else
            {
                for (int i = 0; i < numMaps; i++)
                {
                    moveFindItems.Add(new MapMoveFindItems(bytes.Sub(i * 4 * 4, (i + 1) * 4 * 4 - 1), names[i], def.MoveFindItems[i], context));
                }
            }
            MoveFindItems = moveFindItems.ToArray();
        }
Ejemplo n.º 15
0
        public static IList <IList <T> > Split <T>(this IList <T> members, Set <T> values) where T : IEquatable <T>
        {
            if (values.Count == 1)
            {
                return(Split(members, values[0]));
            }

            List <IList <T> > result = new List <IList <T> >();
            uint start = 0;
            uint stop  = 0;

            for (int i = 0; i < members.Count; i++)
            {
                if (values.Contains(members[i]))
                {
                    stop = (uint)i;
                    result.Add(members.Sub(start, stop).AsReadOnly());
                    start = (uint)i + 1;
                }
            }

            if (!values.Contains(members[members.Count - 1]))
            {
                result.Add(members.Sub(start, (uint)(members.Count - 1)).AsReadOnly());
            }

            return(result.AsReadOnly());
        }
Ejemplo n.º 16
0
 public void ImportSPR(IList <byte> bytes)
 {
     BitmapDirty = true;
     Palettes    = BuildPalettes(bytes.Sub(0, 16 * 32 - 1));
     ImportSPRInner(bytes.Sub(16 * 32));
     FirePixelsChanged();
 }
Ejemplo n.º 17
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));
            }
        }
Ejemplo n.º 18
0
 protected AbstractSprite(string name, IList <string> filenames, IList <byte> bytes, params IList <byte>[] extraBytes)
     : this(name, filenames)
 {
     OriginalSize = bytes.Count;
     CurrentSize  = OriginalSize;
     Palettes     = BuildPalettes(bytes.Sub(0, 16 * 32 - 1));
     Pixels       = BuildPixels(bytes.Sub(16 * 32), extraBytes);
 }
Ejemplo n.º 19
0
        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));
            }
        }
Ejemplo n.º 20
0
        public Job(Context context, byte value, string name, IList <byte> bytes, Job defaults)
        {
            Value      = value;
            Name       = name;
            ourContext = context;

            int equipEnd = context == Context.US_PSP ? 13 : 12;

            Ability[] dummyAbilities = AllAbilities.GetDummyAbilities(context);

            SkillSet        = context == Context.US_PSP ? SkillSet.PSPSkills[bytes[0]] : SkillSet.PSXSkills[bytes[0]];
            InnateA         = dummyAbilities[PatcherLib.Utilities.Utilities.BytesToUShort(bytes[1], bytes[2])];
            InnateB         = dummyAbilities[PatcherLib.Utilities.Utilities.BytesToUShort(bytes[3], bytes[4])];
            InnateC         = dummyAbilities[PatcherLib.Utilities.Utilities.BytesToUShort(bytes[5], bytes[6])];
            InnateD         = dummyAbilities[PatcherLib.Utilities.Utilities.BytesToUShort(bytes[7], bytes[8])];
            Equipment       = new Equipment(bytes.Sub(9, equipEnd), defaults == null ? null : defaults.Equipment, context);
            HPConstant      = bytes[equipEnd + 1];
            HPMultiplier    = bytes[equipEnd + 2];
            MPConstant      = bytes[equipEnd + 3];
            MPMultiplier    = bytes[equipEnd + 4];
            SpeedConstant   = bytes[equipEnd + 5];
            SpeedMultiplier = bytes[equipEnd + 6];
            PAConstant      = bytes[equipEnd + 7];
            PAMultiplier    = bytes[equipEnd + 8];
            MAConstant      = bytes[equipEnd + 9];
            MAMultiplier    = bytes[equipEnd + 10];
            Move            = bytes[equipEnd + 11];
            Jump            = bytes[equipEnd + 12];
            CEvade          = bytes[equipEnd + 13];
            PermanentStatus = new Statuses(bytes.Sub(equipEnd + 14, equipEnd + 18), defaults == null ? null : defaults.PermanentStatus);
            StatusImmunity  = new Statuses(bytes.Sub(equipEnd + 19, equipEnd + 23), defaults == null ? null : defaults.StatusImmunity);
            StartingStatus  = new Statuses(bytes.Sub(equipEnd + 24, equipEnd + 28), defaults == null ? null : defaults.StartingStatus);
            AbsorbElement   = new Elements(bytes[equipEnd + 29]);
            CancelElement   = new Elements(bytes[equipEnd + 30]);
            HalfElement     = new Elements(bytes[equipEnd + 31]);
            WeakElement     = new Elements(bytes[equipEnd + 32]);

            MPortrait = bytes[equipEnd + 33];
            MPalette  = bytes[equipEnd + 34];
            MGraphic  = bytes[equipEnd + 35];

            if (defaults != null)
            {
                Default = defaults;
                AbsorbElement.Default = defaults.AbsorbElement;
                CancelElement.Default = defaults.CancelElement;
                HalfElement.Default   = defaults.HalfElement;
                WeakElement.Default   = defaults.WeakElement;
            }
        }
Ejemplo n.º 21
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, 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());
        }
Ejemplo n.º 22
0
        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();
        }
Ejemplo n.º 23
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);

            System.Text.StringBuilder sbMessage = new System.Text.StringBuilder();
            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));
                }
                GenericCharMap processCharMap = DteAllowed[i] ? CharMap : GetContextCharmap(layout.Context);
                //sections.Add(TextUtilities.ProcessList(thisSection, layout.AllowedTerminators[0], processCharMap));
                sections.Add(TextUtilities.ProcessList(thisSection, layout.AllowedTerminators, processCharMap));
                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])
                {
                    if ((sections[i].Count - SectionLengths[i]) > 1)
                    {
                        sbMessage.AppendLine(string.Format("File {0} (section {1}): Section length decreased from {2} to {3}.", layout.DisplayName, i, sections[i].Count, SectionLengths[i]));
                    }

                    sections[i] = sections[i].Sub(0, SectionLengths[i] - 1);
                }
            }

            // <DEBUG>
            //string message = sbMessage.ToString();
            //if (!string.IsNullOrEmpty(message))
            //    PatcherLib.MyMessageBox.Show(message);

            Sections = sections.AsReadOnly();
            PopulateDisallowedSections();
        }
Ejemplo n.º 24
0
        public JobLevels(Context context, IList <byte> bytes, JobLevels defaults)
        {
            Default = defaults;
            int jobCount           = context == Context.US_PSP ? 22 : 19;
            int requirementsLength = context == Context.US_PSP ? 12 : 10;

            for (int i = 0; i < jobCount; i++)
            {
                ReflectionHelpers.SetFieldOrProperty(this, reqs[i],
                                                     new Requirements(context,
                                                                      bytes.Sub(i * requirementsLength, (i + 1) * requirementsLength - 1),
                                                                      defaults == null ? null : ReflectionHelpers.GetFieldOrProperty <Requirements>(defaults, reqs[i])));
            }

            int start = requirementsLength * jobCount;

            if (context == Context.US_PSX)
            {
                start += 2;
            }

            for (int i = 0; i < levels.Length; i++)
            {
                levels[i] = PatcherLib.Utilities.Utilities.BytesToUShort(bytes[start + i * 2], bytes[start + i * 2 + 1]);
            }
        }
Ejemplo n.º 25
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);
 }
Ejemplo n.º 26
0
        public void WriteImageToIsoInnerSpecific(System.IO.Stream iso, System.Drawing.Image image, bool isDest4bpp = false)
        {
            using (System.Drawing.Bitmap sourceBitmap = new System.Drawing.Bitmap(image))
            {
                Set <System.Drawing.Color> colors = GetColors(sourceBitmap);
                if (colors.Count > NumColors)
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(NumColors, 8);
                    using (var newBmp = q.Quantize(sourceBitmap))
                    {
                        WriteImageToIsoInner(iso, newBmp);
                    }
                }
                else
                {
                    byte[]       imageBytes = GetImageBytes(sourceBitmap, isDest4bpp);
                    IList <byte> bytes      = PixelsToBytes(imageBytes);

                    byte[] originalPaletteBytes = PalettePosition.ReadIso(iso);
                    PalettePosition.PatchIso(iso, GetPaletteBytes(image.Palette.Entries, originalPaletteBytes));

                    int currentIndex = 0;
                    foreach (var kp in PixelPositions)
                    {
                        var bb = bytes.Sub(currentIndex, currentIndex + kp.Length - 1);
                        kp.PatchIso(iso, bb);
                        currentIndex += kp.Length;
                    }
                }
            }
        }
Ejemplo n.º 27
0
        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();
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
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 Unknown12, ref Unknown1, ref Unknown2, ref Unknown3, ref Unknown4, ref Unknown5, ref Unknown6, ref Unknown13);
            PatcherLib.Utilities.Utilities.CopyByteToBooleans(bytes[5], ref Unknown14, ref Blank, ref Unknown15, ref Unknown7, ref Unknown8, ref Unknown9, ref CancelledByImmortal, ref Unknown11);
            Unknown14   = !Unknown14;
            Cancels     = new Statuses(bytes.Sub(6, 10), defaults == null ? null : defaults.Cancels);
            CantStackOn = new Statuses(bytes.Sub(11, 15), defaults == null ? null : defaults.CantStackOn);
        }
Ejemplo n.º 30
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 CountsAsKO);
            PatcherLib.Utilities.Utilities.CopyByteToBooleans(bytes[5], ref CanReact, ref Blank, ref IgnoreAttacks, ref IgnoredIfMount, ref Unknown8, ref Unknown9, ref CancelledByImmortal, ref LowerTargetPriority);
            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);
        }
Ejemplo n.º 31
0
        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();
        }
Ejemplo n.º 32
0
 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));
     }
 }
Ejemplo n.º 33
0
        public static void GenerateEccEdc(IList <byte> sector, IsoType isoType)
        {
            switch (isoType)
            {
            case IsoType.Mode2Form1:
                ComputeEdcBlock(sector.Sub(0x10), 0x808, sector.Sub(0x818));
                GenerateEcc(sector, true);
                break;

            case IsoType.Mode2Form2:
                ComputeEdcBlock(sector.Sub(0x10), 0x91C, sector.Sub(0x92C));
                break;

            case IsoType.Mode1:
            default:
                throw new ArgumentException("isotype");
            }
        }
Ejemplo n.º 34
0
        public static IList <Sequence> BuildSequences(IList <byte> bytes, IList <string> names, bool mon)
        {
            List <UInt32> offsets = new List <uint>();

            for (int i = 0; i < 0x100; i++)
            {
                if (mon && offsets.Count >= 194)
                {
                    break;
                }
                UInt32 currentOffset = bytes.Sub(i * 4 + 4, (i + 1) * 4 + 4 - 1).ToUInt32();
                if (currentOffset == 0xFFFFFFFF)
                {
                    break;
                }
                else
                {
                    offsets.Add(currentOffset);
                }
            }
            const int       animationStart = 0x0406;
            List <Sequence> result         = new List <Sequence>(offsets.Count);

            for (int i = 0; i < offsets.Count - 1; i++)
            {
                if (offsets[i] == offsets[i + 1])
                {
                    continue;
                }
                var seq = BuildSequence(bytes.Sub(animationStart + offsets[i], animationStart + offsets[i + 1] - 1), i, names[result.Count]);
                if (seq != null)
                {
                    result.Add(seq);
                }
            }

            var seq2 = BuildSequence(bytes.Sub(animationStart + offsets[offsets.Count - 1]), offsets.Count - 1, names[result.Count]);

            if (seq2 != null)
            {
                result.Add(seq2);
            }
            return(result.AsReadOnly());
        }
Ejemplo n.º 35
0
 public AllInflictStatuses(IList <byte> bytes, IList <byte> defaultBytes, Context context)
 {
     defaultBytes    = defaultBytes ?? (context == Context.US_PSP ? PSPResources.Binaries.InflictStatuses : PSXResources.Binaries.InflictStatuses);
     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)));
     }
 }
Ejemplo n.º 36
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)));
     }
 }
Ejemplo n.º 37
0
        /// <summary>
        /// Creates a colection of palettes from a PAL file.
        /// </summary>
        public static Palette[] FromPALFile(IList <byte> bytes)
        {
            Palette[] result = new Palette[16];
            for (int i = 0; i < 16; i++)
            {
                result[i] = Palette.FromPALFiledata(bytes.Sub(24 + 4 * 16 * i, 24 + 4 * 16 * (i + 1) - 1));
            }

            return(result);
        }
Ejemplo n.º 38
0
        protected static Palette[] BuildPalettes(IList <byte> paletteBytes)
        {
            Palette[] result = new Palette[16];
            for (int i = 0; i < 16; i++)
            {
                result[i] = new Palette(paletteBytes.Sub(i * 32, (i + 1) * 32 - 1));
            }

            return(result);
        }
Ejemplo n.º 39
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] );
     }
 }
Ejemplo n.º 40
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();
        }
Ejemplo n.º 41
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();
        }
Ejemplo n.º 42
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
        }
Ejemplo n.º 43
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();
        }
Ejemplo n.º 44
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();
        }
Ejemplo n.º 45
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 );
        }
Ejemplo n.º 46
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));
            }
        }
Ejemplo n.º 47
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 ) );
            }
        }
Ejemplo n.º 48
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();
        }
Ejemplo n.º 49
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;
        }
Ejemplo n.º 50
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;
        }
Ejemplo n.º 51
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 );
 }
Ejemplo n.º 52
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 ) ) );
            }
        }
Ejemplo n.º 53
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 ) ) );
     }
 }
Ejemplo n.º 54
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 ) ) );
            }
        }
Ejemplo n.º 55
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 );
        }
Ejemplo n.º 56
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();
        }
Ejemplo n.º 57
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() };
            }
Ejemplo n.º 58
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();
            }
Ejemplo n.º 59
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 );
                }
            }

        }
Ejemplo n.º 60
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;
            }
        }