Ejemplo n.º 1
0
        public TSSFile(byte[] File)
        {
            this.File = File;
            // set header
            Header = new TSSHeader(File.Take(0x20).ToArray());

            if (Header.Magic != 0x54535300)
            {
                MessageBox.Show("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] == 0x02070000)
                    {
                        inGameStringId = (int)OneEntry[i + 1];
                        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);
                    }
                }

                EntryList.Add(new TSSEntry(OneEntry, GetText(JPNPointer), GetText(ENGPointer), JPNIndex, ENGIndex, inGameStringId));
                //CurrentLocation += OneEntry.Length;
                CurrentLocation++;
            }
            Entries = EntryList.ToArray();
        }