Beispiel #1
0
        public TSSFile(byte[] File, bool isUtf8 = false)
        {
            this.File = File;
            // set header
            Header = new TSSHeader(File.Take(0x20).ToArray());

            if (Header.Magic != 0x54535300)
            {
                Console.WriteLine("File is not a TSS file!");
                return;
            }

            // convert all instructions into a List of uint
            int         CurrentLocation = 0x20;
            UInt32      EntriesEnd      = Header.TextStart;
            List <uint> EntryUIntList   = new List <uint>();

            while (CurrentLocation < EntriesEnd)
            {
                uint Instruction = BitConverter.ToUInt32(File, CurrentLocation);
                EntryUIntList.Add(Util.SwapEndian(Instruction));
                CurrentLocation += 4;
            }

            // split the full instruction list into blocks seperated by 0xFFFFFFFF ( == TSSEntry )
            // and put them into the Entry list
            // complete with text it's pointing at
            CurrentLocation = 0;
            uint[]          EntryUIntArray = EntryUIntList.ToArray();
            int             ListSize       = EntryUIntArray.Length;
            List <TSSEntry> EntryList      = new List <TSSEntry>(ListSize / 10);
            int             i = 0;

            List <uint> OneEntryList = new List <uint>();

            while (CurrentLocation < ListSize)
            {
                //uint[] OneEntry = EntryUIntArray.Skip(CurrentLocation).TakeWhile(subject => subject != 0xFFFFFFFF).ToArray();
                OneEntryList.Clear();

                while (CurrentLocation < EntryUIntArray.Length && EntryUIntArray[CurrentLocation] != 0xFFFFFFFF)
                {
                    OneEntryList.Add(EntryUIntArray[CurrentLocation]);
                    CurrentLocation++;
                }

                uint[] OneEntry = OneEntryList.ToArray();

                int JPNPointer     = -1;
                int ENGPointer     = -1;
                int JPNIndex       = -1;
                int ENGIndex       = -1;
                int inGameStringId = -1;

                // get in-game string id
                for (i = 0; i < OneEntry.Length; i++)
                {
                    if (OneEntry[i] == 0x0E000007)
                    {
                        inGameStringId = (int)OneEntry[i - 2];
                        break;
                    }
                }

                // get JPN pointer
                for (i = 0; i < OneEntry.Length; i++)
                {
                    if (OneEntry[i] == 0x02820000)
                    {
                        break;
                    }
                }

                if (i == OneEntry.Length)
                {
                    JPNPointer = -1;
                    ENGPointer = -1;
                }
                else
                {
                    JPNIndex   = ++i;
                    JPNPointer = (int)(OneEntry[JPNIndex] + Header.TextStart);

                    // get English pointer
                    for ( ; i < OneEntry.Length; i++)
                    {
                        if (OneEntry[i] == 0x02820000)
                        {
                            break;
                        }
                    }

                    if (i == OneEntry.Length)
                    {
                        ENGPointer = -1;
                    }
                    else
                    {
                        ENGIndex   = i + 1;
                        ENGPointer = (int)(OneEntry[ENGIndex] + Header.TextStart);
                    }
                }

                string jpn, eng;
                if (isUtf8)
                {
                    jpn = Util.GetTextUTF8(File, JPNPointer);
                    eng = Util.GetTextUTF8(File, ENGPointer);
                }
                else
                {
                    jpn = Util.GetTextShiftJis(File, JPNPointer);
                    eng = Util.GetTextShiftJis(File, ENGPointer);
                }
                EntryList.Add(new TSSEntry(OneEntry, jpn, eng, JPNIndex, ENGIndex, inGameStringId));
                //CurrentLocation += OneEntry.Length;
                CurrentLocation++;
            }
            Entries = EntryList.ToArray();
        }
Beispiel #2
0
        private bool LoadFile(Stream File, Util.GameTextEncoding encoding, Util.Endianness endian)
        {
            long pos = File.Position;

            // set header
            Header = new TSSHeader(File, endian);

            if (Header.Magic != 0x54535300)
            {
                Console.WriteLine("File is not a TSS file!");
                return(false);
            }

            // convert all instructions into a List of uint
            File.Position = pos + 0x20;
            int         CurrentLocation = 0x20;
            UInt32      EntriesEnd      = Header.TextStart;
            List <uint> EntryUIntList   = new List <uint>();

            while (CurrentLocation < EntriesEnd)
            {
                uint Instruction = File.ReadUInt32().FromEndian(endian);
                EntryUIntList.Add(Instruction);
                CurrentLocation += 4;
            }

            // split the full instruction list into blocks seperated by 0xFFFFFFFF ( == TSSEntry )
            // and put them into the Entry list
            // complete with text it's pointing at
            CurrentLocation = 0;
            uint[]          EntryUIntArray = EntryUIntList.ToArray();
            int             ListSize       = EntryUIntArray.Length;
            List <TSSEntry> EntryList      = new List <TSSEntry>(ListSize / 10);
            int             i = 0;

            List <uint> OneEntryList = new List <uint>();

            while (CurrentLocation < ListSize)
            {
                //uint[] OneEntry = EntryUIntArray.Skip(CurrentLocation).TakeWhile(subject => subject != 0xFFFFFFFF).ToArray();
                OneEntryList.Clear();

                while (CurrentLocation < EntryUIntArray.Length && EntryUIntArray[CurrentLocation] != 0xFFFFFFFF)
                {
                    OneEntryList.Add(EntryUIntArray[CurrentLocation]);
                    CurrentLocation++;
                }

                uint[] OneEntry = OneEntryList.ToArray();

                int JPNPointer     = -1;
                int ENGPointer     = -1;
                int JPNIndex       = -1;
                int ENGIndex       = -1;
                int inGameStringId = -1;

                // get in-game string id
                for (i = 0; i < OneEntry.Length; i++)
                {
                    if (OneEntry[i] == 0x0E000007)
                    {
                        inGameStringId = (int)OneEntry[i - 2];
                        break;
                    }
                }

                // get JPN pointer
                for (i = 0; i < OneEntry.Length; i++)
                {
                    if (OneEntry[i] == 0x02820000)
                    {
                        break;
                    }
                }

                if (i == OneEntry.Length)
                {
                    JPNPointer = -1;
                    ENGPointer = -1;
                }
                else
                {
                    JPNIndex   = ++i;
                    JPNPointer = (int)(OneEntry[JPNIndex] + Header.TextStart);

                    // get English pointer
                    for ( ; i < OneEntry.Length; i++)
                    {
                        if (OneEntry[i] == 0x02820000)
                        {
                            break;
                        }
                    }

                    if (i == OneEntry.Length)
                    {
                        ENGPointer = -1;
                    }
                    else
                    {
                        ENGIndex   = i + 1;
                        ENGPointer = (int)(OneEntry[ENGIndex] + Header.TextStart);
                    }
                }

                string jpn = JPNPointer == -1 ? null : File.ReadNulltermStringFromLocationAndReset(pos + JPNPointer, encoding);
                string eng = ENGPointer == -1 ? null : File.ReadNulltermStringFromLocationAndReset(pos + ENGPointer, encoding);
                EntryList.Add(new TSSEntry(OneEntry, jpn, eng, JPNIndex, ENGIndex, inGameStringId));
                //CurrentLocation += OneEntry.Length;
                CurrentLocation++;
            }
            Entries = EntryList.ToArray();

            return(true);
        }
Beispiel #3
0
        public TSSFile( byte[] File, bool isUtf8 = false )
        {
            this.File = File;
            // set header
            Header = new TSSHeader( File.Take( 0x20 ).ToArray() );

            if ( Header.Magic != 0x54535300 ) {
                Console.WriteLine( "File is not a TSS file!" );
                return;
            }

            // convert all instructions into a List of uint
            int CurrentLocation = 0x20;
            UInt32 EntriesEnd = Header.TextStart;
            List<uint> EntryUIntList = new List<uint>();

            while ( CurrentLocation < EntriesEnd ) {
                uint Instruction = BitConverter.ToUInt32( File, CurrentLocation );
                EntryUIntList.Add( Util.SwapEndian( Instruction ) );
                CurrentLocation += 4;
            }

            // split the full instruction list into blocks seperated by 0xFFFFFFFF ( == TSSEntry )
            // and put them into the Entry list
            // complete with text it's pointing at
            CurrentLocation = 0;
            uint[] EntryUIntArray = EntryUIntList.ToArray();
            int ListSize = EntryUIntArray.Length;
            List<TSSEntry> EntryList = new List<TSSEntry>( ListSize / 10 );
            int i = 0;

            List<uint> OneEntryList = new List<uint>();

            while ( CurrentLocation < ListSize ) {
                //uint[] OneEntry = EntryUIntArray.Skip(CurrentLocation).TakeWhile(subject => subject != 0xFFFFFFFF).ToArray();
                OneEntryList.Clear();

                while ( CurrentLocation < EntryUIntArray.Length && EntryUIntArray[CurrentLocation] != 0xFFFFFFFF ) {
                    OneEntryList.Add( EntryUIntArray[CurrentLocation] );
                    CurrentLocation++;
                }

                uint[] OneEntry = OneEntryList.ToArray();

                int JPNPointer = -1;
                int ENGPointer = -1;
                int JPNIndex = -1;
                int ENGIndex = -1;
                int inGameStringId = -1;

                // get in-game string id
                for ( i = 0; i < OneEntry.Length; i++ ) {
                    if ( OneEntry[i] == 0x0E000007 ) {
                        inGameStringId = (int)OneEntry[i - 2];
                        break;
                    }
                }

                // get JPN pointer
                for ( i = 0; i < OneEntry.Length; i++ ) {
                    if ( OneEntry[i] == 0x02820000 ) {
                        break;
                    }
                }

                if ( i == OneEntry.Length ) {
                    JPNPointer = -1;
                    ENGPointer = -1;
                } else {
                    JPNIndex = ++i;
                    JPNPointer = (int)( OneEntry[JPNIndex] + Header.TextStart );

                    // get English pointer
                    for ( ; i < OneEntry.Length; i++ ) {
                        if ( OneEntry[i] == 0x02820000 ) {
                            break;
                        }
                    }

                    if ( i == OneEntry.Length ) {
                        ENGPointer = -1;
                    } else {
                        ENGIndex = i + 1;
                        ENGPointer = (int)( OneEntry[ENGIndex] + Header.TextStart );
                    }
                }

                string jpn, eng;
                if ( isUtf8 ) {
                    jpn = Util.GetTextUTF8( File, JPNPointer );
                    eng = Util.GetTextUTF8( File, ENGPointer );
                } else {
                    jpn = Util.GetTextShiftJis( File, JPNPointer );
                    eng = Util.GetTextShiftJis( File, ENGPointer );
                }
                EntryList.Add( new TSSEntry( OneEntry, jpn, eng, JPNIndex, ENGIndex, inGameStringId ) );
                //CurrentLocation += OneEntry.Length;
                CurrentLocation++;
            }
            Entries = EntryList.ToArray();
        }