Example #1
0
        public static TSR_SentenceArg Load(TSR_Reader tsrReader, ref int enc_pos)
        {
            TSR_SentenceArg arg = new TSR_SentenceArg();

            arg.valueType = (ValueType)tsrReader.ReadUInt16();

            switch (arg.valueType)
            {
            case ValueType.Int:
                arg.Value = tsrReader.ReadInt32().ToString();
                break;

            case ValueType.Float:
                arg.Value = tsrReader.ReadFloat().ToString();
                break;

            case ValueType.Tag:
            case ValueType.Variable:
            case ValueType.String:
            case ValueType.Expression:
                arg.Value = tsrReader.DecodeString(ref enc_pos);
                break;

            default:
                throw new InvalidDataException(String.Format("Unknown ValueType: {0}\nParse failed.", arg.valueType));
            }

            return(arg);
        }
Example #2
0
        public static TSR_Tag Load(TSR_Reader tsrReader, ref int enc_pos)
        {
            TSR_Tag tag = new TSR_Tag();

            tag.Index = tsrReader.ReadUInt16();
            tag.Name  = tsrReader.DecodeString(ref enc_pos);

            return(tag);
        }
Example #3
0
        public static TSR_Function Load(TSR_Reader tsrReader, int offset)
        {
            tsrReader.Position = offset;
            TSR_Function function = new TSR_Function()
            {
                Tags = new List <TSR_Tag>(), Sentences = new List <TSR_Sentence>()
            };

            int enc_pos = 4;

            function.Header = tsrReader.ReadInt32();
            function.Name   = tsrReader.DecodeString(ref enc_pos);
            function.Unk    = tsrReader.ReadUInt16();

            //Tags
            int tagCount = tsrReader.ReadUInt16();

            for (int i = 0; i < tagCount; i++)
            {
                function.Tags.Add(TSR_Tag.Load(tsrReader, ref enc_pos));
            }

            //Sentence
            int sentenceCount = tsrReader.ReadUInt16();

            for (int i = 0; i < sentenceCount; i++)
            {
                function.Sentences.Add(TSR_Sentence.Load(tsrReader, ref enc_pos));
            }

            //Lines
            function.Lines = new List <object>();

            for (int i = 0; i < function.Sentences.Count; i++)
            {
                var tag = function.GetTag(i);

                if (tag != null)
                {
                    function.Lines.Add(tag);
                }

                function.Lines.Add(function.Sentences[i]);
            }

            return(function);
        }
Example #4
0
        public static TSR_File Parse(TSR_Reader tsrReader, List <byte> bytes, byte[] rawBytes)
        {
            TSR_File tsrFile = new TSR_File()
            {
                Functions = new List <TSR_Function>()
            };

            int functionCount  = BitConverter.ToUInt16(rawBytes, 0);
            int functionOffset = 2 + (functionCount * 4);

            for (int i = 0; i < functionCount; i++)
            {
                int funcSize = BitConverter.ToInt32(rawBytes, 2 + (4 * i));
                tsrFile.Functions.Add(TSR_Function.Load(tsrReader, functionOffset));
                functionOffset += funcSize;
            }

            return(tsrFile);
        }
Example #5
0
        public static TSR_Sentence Load(TSR_Reader tsrReader, ref int enc_pos)
        {
            TSR_Sentence sentence = new TSR_Sentence()
            {
                Arguments = new List <TSR_SentenceArg>()
            };

            sentence.Value = tsrReader.DecodeString(ref enc_pos);
            sentence.Unk   = tsrReader.ReadUInt16();

            //Arguments
            int argCount = tsrReader.ReadUInt16();

            for (int i = 0; i < argCount; i++)
            {
                sentence.Arguments.Add(TSR_SentenceArg.Load(tsrReader, ref enc_pos));
            }

            return(sentence);
        }