Example #1
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 #2
0
                private static void BuildCharMapFromIso( Stream iso, PspIso.PspIsoInfo info, out GenericCharMap outCharmap, out IList<Glyph> customGlyphs )
                {
                    var usrDirEnt = DirectoryEntry.GetPspDirectoryEntries( iso, info, PspIso.Sectors.PSP_GAME_USRDIR, 1 );
                    var charMapEntry = usrDirEnt.Find( d => d.Filename == FFTText.PspCharmapFileName );
                    System.Diagnostics.Debug.Assert( charMapEntry.Sector == info[PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP] );
                    var charmapBytes = PspIso.GetBlock( iso, info, new PspIso.KnownPosition(
                         PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP, 0, (int)charMapEntry.Size ) ).ToArray();

                    Dictionary<int, string> myCharMap = new Dictionary<int, string>();
                    using(MemoryStream memStream = new MemoryStream(charmapBytes))
                    using (TextReader reader = new StreamReader( memStream, Encoding.UTF8 ))
                    {
                        reader.ReadLine();

                        string currentLine = string.Empty;
                        while ((currentLine = reader.ReadLine()) != null)
                        {
                            string[] cols = currentLine.Split( '\t' );
                            int index = int.Parse( cols[0], System.Globalization.NumberStyles.HexNumber );
                            myCharMap[index] = cols[1];
                        }
                    }

                    outCharmap = new NonDefaultCharMap( myCharMap );
                    customGlyphs = null;
                }
Example #3
0
        public static void Show( GenericCharMap charmap )
        {
            if( currentCharMap != charmap )
            {
                SetCharMap( charmap );
            }

            Instance.Show();
        }
Example #4
0
        private static void SetCharMap( GenericCharMap map )
        {
            List<string> keys = new List<string>( map.Reverse.Keys );
            keys.Sort();
            keys.RemoveAll( s => s.Contains( @"{Delay " ) || s.Contains( @"{Tab " ) || s.Contains( @"{Color " ) );

            Instance.textBox.Text = string.Join( "\r\n", keys.ToArray() );
            currentCharMap = map;
        }
Example #5
0
 public ATCHELP( 
     GenericCharMap map, 
     FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, 
     IList<byte> bytes, 
     string fileComments, 
     IList<string> sectionComments )
     : base(map, layout, bytes, fileComments, sectionComments)
 {
 }
Example #6
0
 protected AbstractFile( GenericCharMap charmap, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, bool compressible )
 {
     NumberOfSections = layout.SectionLengths.Count;
     Layout = layout;
     CharMap = charmap;
     EntryNames = layout.EntryNames.AsReadOnly();
     SectionLengths = layout.SectionLengths.AsReadOnly();
     SectionNames = layout.SectionNames.AsReadOnly();
     DisplayName = layout.DisplayName;
     Compressible = compressible;
     CompressionAllowed = layout.CompressionAllowed.AsReadOnly();
     DteAllowed = layout.DteAllowed.AsReadOnly();
 }
 public CompressibleOneShotFile( GenericCharMap map, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList<byte> bytes, string fileComments, IList<string> sectionComments )
     : base(map, layout, fileComments, sectionComments, true)
 {
     List<IList<string>> sections = new List<IList<string>>( NumberOfSections );
     System.Diagnostics.Debug.Assert( NumberOfSections == 1 );
     for ( int i = 0; i < NumberOfSections; i++ )
     {
         sections.Add( TextUtilities.ProcessList( TextUtilities.Decompress( bytes, bytes, 0 ), 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;
         }
     }
     Sections = sections.AsReadOnly();
 }
Example #8
0
        protected AbstractFile( GenericCharMap charmap, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, string fileComments, IList<string> sectionComments, bool compressible )
        {
            System.Diagnostics.Debug.Assert( sectionComments.Count == layout.SectionNames.Count );
            FileComments = fileComments ?? string.Empty;
            SectionComments = new string[sectionComments.Count];
            sectionComments.CopyTo( SectionComments, 0 );

            NumberOfSections = layout.SectionLengths.Count;
            Layout = layout;
            CharMap = charmap;
            SelectedTerminator = layout.AllowedTerminators[0];
            EntryNames = layout.EntryNames.AsReadOnly();
            SectionLengths = layout.SectionLengths.AsReadOnly();
            SectionNames = layout.SectionNames.AsReadOnly();
            HiddenEntries = layout.Hidden.AsReadOnly();
            DisplayName = layout.DisplayName;
            Compressible = compressible;
            CompressionAllowed = layout.CompressionAllowed.AsReadOnly();
            DteAllowed = layout.DteAllowed.AsReadOnly();
        }
Example #9
0
                public static void GetCharMap( Stream iso, PatcherLib.Iso.PspIso.PspIsoInfo info, out GenericCharMap outCharmap, out IList<Glyph> customGlyphs )
                {
                    var matchBytes = Encoding.UTF8.GetBytes( FFTText.CharmapHeader );
                    if (info.ContainsKey( PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP ))
                    {
                        var isoBytes = PspIso.GetBlock( iso, info,
                            new PspIso.KnownPosition( PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP, 0,
                                matchBytes.Length ) );
                        if (Utilities.CompareArrays( matchBytes, isoBytes ))
                        {
                            BuildCharMapFromIso( iso, info , out outCharmap, out customGlyphs );
                            return;
                        }
                    }

                    IList<byte> fontBytes = PspIso.GetBlock( iso, info, DTE.PspFontSection[0] );
                    IList<byte> widthBytes = PspIso.GetBlock( iso, info, DTE.PspFontWidths[0] );
                    outCharmap = GetCharMap( fontBytes, widthBytes, info );
                    customGlyphs = null;
                }
Example #10
0
        protected AbstractFile( GenericCharMap charmap, FFTTextFactory.FileInfo layout, IList<IList<string>> strings, bool compressible )
            : this( charmap, layout, compressible )
        {
            List<IList<string>> sections = new List<IList<string>>( NumberOfSections );
            for ( int i = 0; i < NumberOfSections; i++ )
            {
                string[] thisSection = new string[strings[i].Count];
                strings[i].CopyTo( thisSection, 0 );
                for ( int j = 0; j < thisSection.Length; j++ )
                {
                    if ( !CharMap.ValidateString( thisSection[j] ) )
                    {
                        throw new InvalidStringException( layout.Guid.ToString(), i, j, thisSection[j] );
                    }
                }
                sections.Add( thisSection );
            }

            this.Sections = sections.AsReadOnly();

            PopulateDisallowedSections();
        }
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 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 #13
0
 public static string Decode(IList <byte> bytes, Context context, Set <byte> terminators = null, GenericCharMap charmap = null)
 {
     return(DecodeList(bytes, context, terminators, charmap)[0]);
 }
Example #14
0
        protected static IList<byte> Compress( IList<IList<string>> strings, out IList<UInt32> offsets, GenericCharMap charmap, IList<bool> allowedSections )
        {
            TextUtilities.CompressionResult r = TextUtilities.Compress( strings, charmap, allowedSections );
            offsets = new List<UInt32>( 32 );
            offsets.Add( 0 );
            int pos = 0;
            for ( int i = 0; i < r.SectionLengths.Count; i++ )
            {
                pos += r.SectionLengths[i];
                offsets.Add( (UInt32)pos );
            }

            return r.Bytes.AsReadOnly();
        }
Example #15
0
        /// <summary>
        /// Replaces bracketed hex values (e.g. {0xD2E3}) with Unicode characters, if known.
        /// </summary>
        /// <param name="s">The string to update.</param>
        /// <param name="charMap">The character map to use.</param>
        /// <returns>The updated string</returns>
        public static string UpgradeString( string s, GenericCharMap charMap )
        {
            string pattern = @"{0x[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]}";
            MatchCollection matches = Regex.Matches( s, pattern );
            if( matches.Count > 0 )
            {
                StringBuilder sb = new StringBuilder( s );
                foreach( Match m in matches )
                {
                    int val = Convert.ToInt32( m.Value.Substring( 3, 4 ), 16 );
                    if( charMap.ContainsKey( val ) )
                    {
                        sb.Replace( m.Value, charMap[val] );
                    }
                }

                return sb.ToString();
            }

            return s;
        }
Example #16
0
 public static AbstractFile ConstructFile( FileType type, GenericCharMap charmap, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList<IList<string>> strings )
 {
     switch ( type )
     {
         case FileType.CompressedFile:
             return new SectionedFile( charmap, layout, strings, true );
             break;
         case FileType.SectionedFile:
             return new SectionedFile( charmap, layout, strings, false );
             break;
         case FileType.CompressibleOneShotFile:
             return new CompressibleOneShotFile( charmap, layout, strings );
             break;
         case FileType.OneShotFile:
         case FileType.PartitionedFile:
             return new PartitionedFile( charmap, layout, strings );
             break;
     }
     return null;
 }
Example #17
0
 public static FFTText GetPsxText( Stream iso, GenericCharMap charmap, BackgroundWorker worker )
 {
     return GetText( iso, Context.US_PSX, Resources.PSX, BytesFromPsxIso, charmap, worker );
 }
Example #18
0
        /// <summary>
        /// Processes a list of FFT text bytes into a list of FFTacText strings.
        /// </summary>
        /// <param name="bytes">The bytes to process</param>
        /// <param name="charmap">The charmap to use</param>
        public static IList<string> ProcessList( IList<byte> bytes, byte terminator, GenericCharMap charmap )
        {
            IList<IList<byte>> words = bytes.Split( terminator );

            List<string> result = new List<string>( words.Count );

            foreach ( IList<byte> word in words )
            {
                StringBuilder sb = new StringBuilder();
                int pos = 0;
                while ( pos < ( word.Count - 1 ) || ( pos == ( word.Count - 1 ) && word[pos] != terminator ) )
                {
                    sb.Append( charmap.GetNextChar( word, ref pos ) );
                }

                sb.Replace(@"{Newline}", @"{Newline}" + Environment.NewLine);

                result.Add( sb.ToString() );
            }

            return result;
        }
Example #19
0
 private IList<PatchedByteArray> GetCharMapPatches( Stream iso, Context context, GenericCharMap baseCharmap, IDictionary<byte, string> dteInfo )
 {
     if (context == Context.US_PSX)
     {
         return GetPsxCharMapPatches( iso, baseCharmap, dteInfo );
     }
     else if (context == Context.US_PSP)
     {
         return GetPspCharMapPatches( iso, baseCharmap, dteInfo );
     }
     else
         return new PatchedByteArray[0];
 }
Example #20
0
 protected static IList<IList<byte>> GetSectionByteArrays( IList<IList<string>> strings, GenericCharMap charmap, IList<bool> compressibleSections )
 {
     if ( compressibleSections.Contains( true ) )
     {
         return GetCompressedSectionByteArrays( strings, charmap, compressibleSections );
     }
     else
     {
         return GetUncompressedSectionBytes( strings, charmap );
     }
 }
Example #21
0
        private IList<PatchedByteArray> GetPsxCharMapPatches( Stream iso, GenericCharMap baseCharmap, IDictionary<byte, string> dteInfo )
        {
            var dirEnt = DirectoryEntry.GetPsxDirectoryEntries( iso, PsxRootDirEntSector, 1 );

            var myDict = new Dictionary<int, string>( baseCharmap );
            dteInfo.ForEach( kvp => myDict[kvp.Key] = kvp.Value );

            System.Text.StringBuilder myString = new System.Text.StringBuilder();
            myString.AppendLine( CharmapHeader );
            myDict.ForEach( kvp => myString.AppendFormat( "{0:X4}\t{1}" + Environment.NewLine, kvp.Key, kvp.Value ) );
            var bytes = System.Text.Encoding.UTF8.GetBytes( myString.ToString() );

            var baseDirEntry = dirEnt.Find( d => d.Filename == "SCEAP.DAT;1" );
            var charmapDirEntry = new PatcherLib.Iso.DirectoryEntry(
                PsxCharmapSector, (uint)bytes.Length, DateTime.Now, baseDirEntry.GMTOffset,
                baseDirEntry.MiddleBytes, PsxCharmapFileName, baseDirEntry.ExtendedBytes );
            AddOrReplaceCharMapDirectoryEntry( dirEnt, charmapDirEntry );

            var dirEntPatches = PatcherLib.Iso.DirectoryEntry.GetPsxDirectoryEntryPatches(
                PsxRootDirEntSector, 1, dirEnt );
            dirEntPatches.Add( new PatchedByteArray( PsxCharmapSector, 0, bytes ) );
            return dirEntPatches;
        }
Example #22
0
        private IList<PatchedByteArray> GetPspCharMapPatches( Stream iso, GenericCharMap baseCharmap, IDictionary<byte, string> dteInfo )
        {
            var pspIsoInfo = PspIso.PspIsoInfo.GetPspIsoInfo( iso );
            var dirEnt = DirectoryEntry.GetPspDirectoryEntries( iso, pspIsoInfo, PspIso.Sectors.PSP_GAME_USRDIR, 1 );

            var currentEntry = dirEnt.Find( de => de.Filename == PspCharmapFileName );
            if (currentEntry != null)
            {
                dirEnt.Remove( currentEntry );
            }
            pspIsoInfo.RemoveFile( PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP );

            var myDict = new Dictionary<int, string>( baseCharmap );
            dteInfo.ForEach( kvp => myDict[kvp.Key] = kvp.Value );

            System.Text.StringBuilder myString = new System.Text.StringBuilder();
            myString.AppendLine( CharmapHeader );
            myDict.ForEach( kvp => myString.AppendFormat( "{0:X4}\t{1}" + Environment.NewLine, kvp.Key, kvp.Value ) );
            var bytes = System.Text.Encoding.UTF8.GetBytes( myString.ToString() );

            int insertSector = FindSectorToInsertPspCharmap( pspIsoInfo, bytes.Length );
            if (insertSector == -1)
            {
                throw new InvalidOperationException();
            }

            pspIsoInfo.AddFile( PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP, insertSector, bytes.Length );

            var baseDirEntry = dirEnt.Find( d => d.Filename == "fftpack.bin" );
            var charmapDirEntry = new PatcherLib.Iso.DirectoryEntry(
                (uint)insertSector, (uint)bytes.Length, DateTime.Now, baseDirEntry.GMTOffset,
                baseDirEntry.MiddleBytes, PspCharmapFileName, baseDirEntry.ExtendedBytes );

            AddOrReplaceCharMapDirectoryEntry( dirEnt, charmapDirEntry );

            var dirEntPatches = PatcherLib.Iso.DirectoryEntry.GetPspDirectoryEntryPatches(
                (int)PspIso.Sectors.PSP_GAME_USRDIR, 1, dirEnt );
            dirEntPatches.Add( new PatchedByteArray( PspIso.Sectors.PSP_GAME_USRDIR_CHARMAP, 0, bytes ) );

            return dirEntPatches;
        }
 public CompressibleOneShotFile( GenericCharMap map, FFTTextFactory.FileInfo layout, IList<IList<string>> strings, string fileComments, IList<string> sectionComments )
     : base(map, layout, strings, fileComments, sectionComments, true)
 {
 }
Example #24
0
        private static IDictionary<Guid, ISerializableFile> GetFiles( Stream iso, Context context, XmlNode layoutDoc, BytesFromIso reader, GenericCharMap charmap, BackgroundWorker worker )
        {
            Dictionary<Guid, ISerializableFile> files = new Dictionary<Guid, ISerializableFile>();
            foreach ( XmlNode node in layoutDoc.SelectNodes( "//Files/*" ) )
            {
                if ( worker.CancellationPending )
                    return null;

                FileInfo fi = GetFileInfo( context, node );

                if ( worker.CancellationPending )
                    return null;

                IList<byte> bytes = reader( iso, fi.PrimaryFile.Key, fi.PrimaryFile.Value, fi.Size );

                if ( worker.CancellationPending )
                    return null;

                switch ( fi.FileType )
                {
                    case FileType.CompressedFile:
                        files.Add( fi.Guid, new SectionedFile( charmap, fi, bytes, true ) );
                        break;
                    case FileType.SectionedFile:
                        files.Add( fi.Guid, new SectionedFile( charmap, fi, bytes ) );
                        break;
                    case FileType.CompressibleOneShotFile:
                        files.Add( fi.Guid, new CompressibleOneShotFile( charmap, fi, bytes ) );
                        break;
                    case FileType.OneShotFile:
                    case FileType.PartitionedFile:
                        files.Add( fi.Guid, new PartitionedFile( charmap, fi, bytes ) );
                        break;
                }

                if ( worker.CancellationPending )
                    return null;
            }

            return new ReadOnlyDictionary<Guid, ISerializableFile>( files );
        }
Example #25
0
        private static FFTText GetText( Stream iso, Context context, XmlNode doc, BytesFromIso reader, GenericCharMap charmap, BackgroundWorker worker )
        {
            IDictionary<Guid, ISerializableFile> files = GetFiles( iso, context, doc, reader, charmap, worker );
            if ( files == null || worker.CancellationPending )
                return null;

            var quickEdit = new QuickEdit( files, GetQuickEditLookup( doc.SelectSingleNode( "//QuickEdit" ), worker ) );
            if ( quickEdit == null || worker.CancellationPending )
                return null;

            return new FFTText( context, files, quickEdit );
        }
Example #26
0
        protected static IList<IList<byte>> GetUncompressedSectionBytes( IList<IList<string>> strings, GenericCharMap charmap )
        {
            IList<IList<byte>> result = new List<IList<byte>>( strings.Count );
            foreach ( IList<string> section in strings )
            {
                List<byte> bytes = new List<byte>();
                section.ForEach( s => bytes.AddRange( charmap.StringToByteArray( s ) ) );
                result.Add( bytes.AsReadOnly() );
            }
            return result.AsReadOnly();

        }
Example #27
0
        /// <summary>
        /// Compresses the specified file.
        /// </summary>
        /// <typeparam name="T">Must be <see cref="IStringSectioned"/> and <see cref="ICompressed"/></typeparam>
        /// <param name="file">The file to compress.</param>
        /// <param name="ignoreSections">A dictionary indicating which entries to not compress, with each key being the section that contains the ignored
        /// entries and each item in the value being an entry to ignore</param>
        /// <param name="callback">The progress callback.</param>
        public static CompressionResult Compress( IList<IList<string>> sections, byte terminator, GenericCharMap charmap, IList<bool> allowedSections )
        {
            int length = 0;
            sections.ForEach( s => length += charmap.StringsToByteArray( s, terminator ).Length );

            byte[] result = new byte[length];
            int[] lengths = new int[sections.Count];

            int pos = 0;
            for( int section = 0; section < sections.Count; section++ )
            {
                int oldPos = pos;

                if ( allowedSections == null || allowedSections[section] )
                {
                    CompressSection( charmap.StringsToByteArray( sections[section], terminator ), result, ref pos );
                }
                else
                {
                    byte[] secResult = charmap.StringsToByteArray( sections[section], terminator );
                    secResult.CopyTo( result, pos );
                    pos += secResult.Length;
                }

                lengths[section] = pos - oldPos;

            }

            return new CompressionResult( result.Sub( 0, pos - 1 ), lengths );
        }
Example #28
0
 private static IList<IList<byte>> GetCompressedSectionByteArrays( IList<IList<string>> sections, GenericCharMap charmap, IList<bool> compressibleSections )
 {
     IList<IList<byte>> result = new IList<byte>[sections.Count];
     IList<UInt32> offsets;
     IList<byte> compression = Compress( sections, out offsets, charmap, compressibleSections );
     offsets = new List<UInt32>( offsets );
     offsets.Add( (uint)compression.Count );
     for ( int i = 0; i < sections.Count; i++ )
     {
         result[i] = compression.Sub( (int)offsets[i], (int)offsets[i + 1] - 1 );
     }
     return result;
 }
Example #29
0
        public static Set<string> GetGroups( GenericCharMap charmap, IList<string> characterSet, IList<int> characterWidths )
        {
            const bool alphaNumOnly = true;
            const string allowedAlphaNum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!?:\"' ./";
            System.Diagnostics.Debug.Assert( allowedAlphaNum.Length == 10 + 26 + 26 + 8 );
            Dictionary<string,string> allowedPairs = new Dictionary<string,string> {
              { "0", "0123456789 ./" }, // 0
              { "1", "0123456789!? ./" }, // 1
              { "2", "0123456789!? ./" }, // 2
              { "3", "0123456789!? ./" },
              { "4", "0123456789!? ./" },
              { "5", "0123456789 ./" },
              { "6", "0123456789 ./" },
              { "7", "0123456789 ./" },
              { "8", "0123456789 ./" },
              { "9", "0123456789 ./" }, // 9
              { "A", "bcdfghijklmnpqrstuvwxyz!?\"' ./" }, // A
              { "B", "aeilmorsuy!?\"' ./" },
              { "C", "aehiklorstu!?\"' ./" },
              { "D", "aeghilnorstuwy!?\"' ./" }, // D
              { "E", "abcdefghijklmnopqrstuvwxyz!?\"' ./" },
              { "F", "aeiorstuy!?\"' ./" },
              { "G", "adehilnorsu!?\"' ./" },
              { "H", "aeiou!?\"' ./" },
              { "I", "cdefghjklmnopqrstuvwxyz!?\"' ./" },
              { "J", "aeious!?\"' ./" }, // J
              { "K", "aeilostuy!?\"' ./" },
              { "L", "aehiou!?\"' ./" },
              { "M", "aeiou!?\"' ./" },
              { "N", "aeiou!?\"' ./" },
              { "O", "abcdefghijklmnprstuvwxyz!?\"' ./" },
              { "P", "aehioruy!?\"' ./" }, // P
              { "Q", "u!?\"' ./" },
              { "R", "aehiouwy!?\"' ./" },
              { "S", "acdefghiklmnopqrtuwyz!?\"' ./" },
              { "T", "aehiouwy!?\"' ./" },
              { "U", "ghlmnoprst!?\"' ./" },
              { "V", "aeiouy!?\"' ./" }, // V
              { "W", "aehiouy!?\"' ./" },
              { "X", "aeiou!?\"' ./" },
              { "Y", "aeiou!?\"' ./" },
              { "Z", "aeiou!?\"' ./" }, // Z
              { "a", "bcdefghijklmnopqrstuvwxyz!?:\"' ./" }, // a
              { "b", "abeilmorsuy!?:\"' ./" },
              { "c", "acehiklorstu!?:\"' ./" },
              { "d", "adeghilnorstuwy!?:\"' ./" }, // d
              { "e", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "f", "aefiorstuy!?:\"' ./" },
              { "g", "adeghilnorsu!?:\"' ./" },
              { "h", "acdegilmnoprstuw!?:\"' ./" },
              { "i", "abcdefghjklmnopqrstuvwxyz!?:\"' ./" },
              { "j", "aeiosuy!?:\"' ./" }, // j
              { "k", "aeiklorsuwy!?:\"' ./" },
              { "l", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "m", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "n", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "o", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "p", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" }, // p
              { "q", "u!?:\"'./" },
              { "r", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "s", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "t", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "u", "abcdefghijklmnopqrstvwxyz!?:\"' ./" },
              { "v", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" }, // v
              { "w", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "x", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "y", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" },
              { "z", "abcdefghijklmnopqrstuvwxyz!?:\"' ./" }, // z

              { "!", "!?\" /" }, // !
              { "?", "!?\" /" }, // ?
              { ":", "!?\" /" }, // :
              { "\"", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!?: .,/" }, // "
              { "'", "dlrstv /" }, // '
              { " ", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz /" }, //
              { ".", "!?\"' ./" }, // .
              { "/", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!?:\"' .,/" }
            };

            List<string> allowed = new List<string>( allowedAlphaNum.Length );
            for ( int i = 0; i < allowedAlphaNum.Length; i++ )
                allowed.Add( allowedAlphaNum[i].ToString( System.Globalization.CultureInfo.InvariantCulture ) );

            Set<string> allowedChars = new Set<string>( allowed );

            const int maxWidth = 10;
            Set<string> result = new Set<string>();

            System.Diagnostics.Debug.Assert( characterSet.Count == characterWidths.Count );
            for ( int i = 0; i < characterSet.Count; i++ )
            {
                if ( !alphaNumOnly || allowedChars.Contains( characterSet[i] ) )
                {
                    for ( int j = i; j < characterSet.Count; j++ )
                    {
                        bool goodWidth = characterWidths[i] + characterWidths[j] <= maxWidth;
                        if ( goodWidth &&
                             ( !alphaNumOnly || allowedPairs[characterSet[i]].Contains( characterSet[j] ) ) )
                        {
                            result.Add( characterSet[i] + characterSet[j] );
                        }
                        if ( goodWidth &&
                             ( !alphaNumOnly ||
                               (allowedPairs.ContainsKey(characterSet[j]) &&
                                allowedPairs[characterSet[j]].Contains( characterSet[i] ) ) ))
                        {
                            result.Add( characterSet[j] + characterSet[i] );
                        }

                    }
                }
            }

            return result;
        }
Example #30
0
 public static AbstractFile ConstructFile( FileType type, GenericCharMap charmap, FFTPatcher.TextEditor.FFTTextFactory.FileInfo layout, IList<byte> bytes )
 {
     switch (type)
     {
         case FileType.CompressedFile:
             return new SectionedFile( charmap, layout, bytes, string.Empty, new string[layout.SectionNames.Count], true );
         case FileType.SectionedFile:
             return new SectionedFile( charmap, layout, bytes, string.Empty, new string[layout.SectionNames.Count], false );
         case FileType.OneShotFile:
         case FileType.PartitionedFile:
             return new PartitionedFile( charmap, layout, bytes, string.Empty, new string[layout.SectionNames.Count] );
     }
     return null;
 }
Example #31
0
 public static FFTText GetPspText( Stream iso, GenericCharMap charmap, BackgroundWorker worker )
 {
     pspIsoInfo = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo( iso );
     var result = GetText( iso, Context.US_PSP, Resources.PSP, BytesFromPspIso, charmap, worker );
     pspIsoInfo = null;
     return result;
 }