Esempio n. 1
0
        internal static TDerived Parse(
            BinaryReader reader,
            MapParseContext context,
            ushort minimumVersionThatHasInternalName,
            ushort minimumVersionThatHasEnabledFlag,
            Action <ushort, TDerived> derivedParse = null)
        {
            return(ParseAsset(reader, context, version =>
            {
                var result = new TDerived();

                // TODO: Need to make game-specific TContentType enums.
                result.ContentType = (TContentType)(object)reader.ReadUInt32();
                //result.ContentType = reader.ReadUInt32AsEnum<TContentType>();

                if (version >= minimumVersionThatHasInternalName)
                {
                    result.InternalName = AssetPropertyKey.Parse(reader, context);
                }

                var numArguments = reader.ReadUInt32();
                result.Arguments = new ScriptArgument[numArguments];

                for (var i = 0; i < numArguments; i++)
                {
                    result.Arguments[i] = ScriptArgument.Parse(reader);
                }

                result.Enabled = true;
                if (version >= minimumVersionThatHasEnabledFlag)
                {
                    result.Enabled = reader.ReadBooleanUInt32Checked();
                }

                derivedParse?.Invoke(version, result);

                return result;
            }));
        }
Esempio n. 2
0
        internal static TDerived Parse(BinaryReader reader, MapParseContext context, ushort minimumVersionThatHasInternalName)
        {
            return(ParseAsset(reader, context, version =>
            {
                var contentType = reader.ReadUInt32AsEnum <TContentType>();

                byte magicValue = 0;
                string internalName = null;
                if (version >= minimumVersionThatHasInternalName)
                {
                    magicValue = reader.ReadByte();
                    if (magicValue != 3)
                    {
                        throw new InvalidDataException();
                    }

                    var internalNameIndex = reader.ReadUInt24();
                    internalName = context.GetAssetName(internalNameIndex);
                }

                var numArguments = reader.ReadUInt32();
                var arguments = new ScriptArgument[numArguments];

                for (var i = 0; i < numArguments; i++)
                {
                    arguments[i] = ScriptArgument.Parse(reader);
                }

                return new TDerived
                {
                    ContentType = contentType,
                    MagicValue = magicValue,
                    InternalName = internalName,
                    Arguments = arguments
                };
            }));
        }