// All of these readers are completely temporary while research is on-going.
        // TODO(gibbed): concrete types for all of this.

        internal static (Instruction, uint) Read(Stream input, Endian endian, ICacheTables tables)
        {
            uint size = 0;

            var op = (Opcode)input.ReadValueU8();

            size++;

            if (_Lookup.TryGetValue(op, out var reader) == false)
            {
                throw new FormatException($"no handler for {op}");
            }

            Instruction instance;

            instance.Op = op;
            if (reader == null)
            {
                instance.Argument = null;
            }
            else
            {
                (var argument, var argumentSize) = reader(input, endian, tables);
                instance.Argument = argument;
                size += argumentSize;
            }
            instance.LoadInfo = default;
            return(instance, size);
        }
        private static (object, uint) ReadJump(Stream input, Endian endian, ICacheTables tables)
        {
            var jumpOffset = input.ReadValueS16(endian);

            jumpOffset += 1 + 2; // make relative to the instruction
            return(jumpOffset, 2);
        }
示例#3
0
        internal override void Deserialize(Stream input, Endian endian, ICacheTables tables)
        {
            var visibility = (Visibility)input.ReadValueU8();

            var flags        = (ClassFlags)input.ReadValueU16();
            var unknownFlags = flags & ~KnownFlags;

            if (unknownFlags != ClassFlags.None)
            {
                throw new FormatException();
            }

            var baseClassIndex = input.ReadValueU32(endian);
            var baseClass      = tables.GetDefinition <ClassDefinition>(baseClassIndex);

            var functions = (flags & ClassFlags.HasFunctions) != 0
                ? ReadDefinitionArray <FunctionDefinition>(input, endian, tables)
                : null;

            Definition[] unknown20s;
            if ((flags & ClassFlags.Unknown5) != 0)
            {
                unknown20s = ReadDefinitionArray <PropertyDefinition>(input, endian, tables);
            }

            Definition[] unknown30s;
            if ((flags & ClassFlags.Unknown8) != 0)
            {
                unknown30s = ReadDefinitionArray <PropertyDefinition>(input, endian, tables);
            }
        }
        internal override void Deserialize(Stream input, Endian endian, ICacheTables tables)
        {
            this.Id       = input.ReadValueU32(endian);
            this.PathHash = input.ReadValueU64(endian);
            var nameLength = input.ReadValueU16(endian);

            this.Path = input.ReadString(nameLength, true, Encoding.UTF8);
        }
        internal override void Deserialize(Stream input, Endian endian, ICacheTables tables)
        {
            var typeIndex = input.ReadValueU32(endian);
            var type      = tables.GetDefinition(typeIndex);
            var unknown28 = input.ReadValueU8();

            this.Type      = type;
            this.Unknown28 = unknown28;
        }
示例#6
0
        internal static T[] ReadDefinitionArray <T>(Stream input, Endian endian, ICacheTables tables)
            where T : Definition
        {
            var count = input.ReadValueU32(endian);
            var items = new T[count];

            for (uint i = 0; i < count; i++)
            {
                var definitionIndex = input.ReadValueU32(endian);
                items[i] = tables.GetDefinition <T>(definitionIndex);
            }
            return(items);
        }
示例#7
0
        internal static Instruction[] Read(Stream input, uint count, Endian endian, ICacheTables tables)
        {
            var result = new List <Instruction>();

            for (uint i = 0; i < count;)
            {
                InstructionLoadInfo loadInfo;
                loadInfo.BasePosition       = input.Position;
                loadInfo.Offset             = i;
                (var instruction, var size) = InstructionReaders.Read(input, endian, tables);
                instruction.LoadInfo        = loadInfo;
                result.Add(instruction);
                i += size;
            }
            return(result.ToArray());
        }
        internal override void Deserialize(Stream input, Endian endian, ICacheTables tables)
        {
            // TODO(gibbed): maybe visibility?
            var unknown2A     = input.ReadValueU8();
            var size          = input.ReadValueU8();
            var enumeralCount = input.ReadValueU32(endian);
            var enumerals     = new EnumeralDefinition[enumeralCount];

            for (uint i = 0; i < enumeralCount; i++)
            {
                var enumeralIndex = input.ReadValueU32(endian);
                enumerals[i] = tables.GetDefinition <EnumeralDefinition>(enumeralIndex);
            }
            var unknown29 = input.ReadValueB8();

            this.Unknown2A = unknown2A;
            this.Size      = size;
            this.Enumerals.Clear();
            this.Enumerals.AddRange(enumerals);
            this.Unknown29 = unknown29;
        }
示例#9
0
        internal override void Deserialize(Stream input, Endian endian, ICacheTables tables)
        {
            var        unknown24 = input.ReadValueU8();
            Definition type;

            if (unknown24 >= 2 && unknown24 <= 6)
            {
                var typeIndex = input.ReadValueU32(endian);
                type = tables.GetDefinition(typeIndex);
            }
            else
            {
                type = null;
            }
            var unknown20 = unknown24 == 5
                ? input.ReadValueU32(endian)
                : 0;

            this.Unknown24 = unknown24;
            this.Type      = type;
            this.Unknown20 = unknown20;
        }
        internal override void Deserialize(Stream input, Endian endian, ICacheTables tables)
        {
            var visibility = (Visibility)input.ReadValueU8();

            var unknown88Index = input.ReadValueU32(endian);
            var unknown88      = tables.GetDefinition <NativeDefinition>(unknown88Index);
            var unknown20      = input.ReadValueU16(endian);

            if ((unknown20 & 0x20) != 0)
            {
                var somethingLength = input.ReadValueU16(endian);
                var something       = input.ReadString(somethingLength, true, Encoding.UTF8);
            }

            var unknown58Count = input.ReadValueU32(endian);
            var unknown58s     = new Tuple <string, string> [unknown58Count];

            for (uint i = 0; i < unknown58Count; i++)
            {
                var unknown58_0Length = input.ReadValueU16(endian);
                var unknown58_0       = input.ReadString(unknown58_0Length, true, Encoding.UTF8);
                var unknown58_1Length = input.ReadValueU16(endian);
                var unknown58_1       = input.ReadString(unknown58_1Length, true, Encoding.UTF8);
                unknown58s[i] = new Tuple <string, string>(unknown58_0, unknown58_1);
            }

            var unknown38Count = input.ReadValueU32(endian);
            var unknown38s     = new Tuple <string, string> [unknown38Count];

            for (uint i = 0; i < unknown38Count; i++)
            {
                var unknown38Length = input.ReadValueU16(endian);
                var unknown38       = input.ReadString(unknown38Length, true, Encoding.UTF8);
                var unknown28Length = input.ReadValueU16(endian);
                var unknown28       = input.ReadString(unknown28Length, true, Encoding.UTF8);
                unknown38s[i] = new Tuple <string, string>(unknown38, unknown28);
            }
        }
示例#11
0
 internal abstract void Serialize(Stream output, Endian endian, ICacheTables tables);
        internal override void Deserialize(Stream input, Endian endian, ICacheTables tables)
        {
            var visibility = (Visibility)input.ReadValueU8();

            var flags        = (FunctionFlags)input.ReadValueU32(endian);
            var unknownFlags = flags & ~KnownFlags;

            if (unknownFlags != FunctionFlags.None)
            {
                throw new FormatException();
            }

            SourceFileDefinition sourceFile;
            uint unknownC0;

            if ((flags & FunctionFlags.Unknown4) == 0)
            {
                var sourceFileIndex = input.ReadValueU32(endian);
                sourceFile = tables.GetDefinition <SourceFileDefinition>(sourceFileIndex);
                unknownC0  = input.ReadValueU32(endian);
            }
            else
            {
                sourceFile = null;
                unknownC0  = 0;
            }

            Definition returnType;
            bool       unknown50;

            if ((flags & FunctionFlags.HasReturnValue) == 0)
            {
                returnType = null;
                unknown50  = false;
            }
            else
            {
                var returnTypeIndex = input.ReadValueU32(endian);
                returnType = tables.GetDefinition(returnTypeIndex);
                unknown50  = input.ReadValueB8();
            }

            Definition unknown58;

            if ((flags & FunctionFlags.Unknown8) == 0)
            {
                unknown58 = null;
            }
            else
            {
                var unknown58Index = input.ReadValueU32(endian);
                unknown58 = tables.GetDefinition(unknown58Index);
            }

            ParameterDefinition[] parameters;
            if ((flags & FunctionFlags.HasParameters) == 0)
            {
                parameters = null;
            }
            else
            {
                parameters = ReadDefinitionArray <ParameterDefinition>(input, endian, tables);
            }

            LocalDefinition[] locals;
            if ((flags & FunctionFlags.HasLocals) == 0)
            {
                locals = null;
            }
            else
            {
                locals = ReadDefinitionArray <LocalDefinition>(input, endian, tables);
            }

            uint unknown98 = (flags & FunctionFlags.Unknown6) != 0
                ? input.ReadValueU32(endian)
                : default;
            byte unknownA0 = (flags & FunctionFlags.Unknown12) != 0
                ? input.ReadValueU8()
                : default;

            long bodyPosition = -1;

            Instruction[] instructions;
            if ((flags & FunctionFlags.HasBody) == 0)
            {
                instructions = null;
            }
            else
            {
                var bodySize = input.ReadValueU32(endian);
                bodyPosition = input.Position;
                instructions = Instructions.Read(input, bodySize, endian, tables);
            }

            this.Visibility       = visibility;
            this.Flags            = flags;
            this.SourceFile       = sourceFile;
            this.SourceLine       = unknownC0;
            this.ReturnType       = returnType;
            this.Unknown50        = unknown50;
            this.Unknown58        = unknown58;
            this.Parameters       = parameters;
            this.Locals           = locals;
            this.Unknown98        = unknown98;
            this.UnknownA0        = unknownA0;
            this.BodyLoadPosition = bodyPosition;
            this.Body             = instructions;
        }
        private static (object, uint) ReadType(Stream input, Endian endian, ICacheTables tables)
        {
            var definitionIndex = input.ReadValueU32(endian);

            return(new ValueTuple <Definition>(tables.GetDefinition(definitionIndex)), 8);
        }
示例#14
0
 internal override void Serialize(Stream output, Endian endian, ICacheTables tables)
 {
     throw new NotImplementedException();
 }
示例#15
0
 internal override void Deserialize(Stream input, Endian endian, ICacheTables tables)
 {
     this.Value = input.ReadValueU64(endian);
 }
 private static (object, uint) ReadValueS32(Stream input, Endian endian, ICacheTables tables)
 {
     return(input.ReadValueS32(endian), 4);
 }
 private static (object, uint) ReadValueU8(Stream input, Endian endian, ICacheTables tables)
 {
     return(input.ReadValueU8(), 1);
 }
示例#18
0
 internal abstract void Deserialize(Stream input, Endian endian, ICacheTables tables);
        private static (object, uint) ReadString(Stream input, Endian endian, ICacheTables tables)
        {
            var size = input.ReadValueU32(endian);

            return(input.ReadString((int)size, true, Encoding.UTF8), 4 + size);
        }