internal static BuildList Parse(BinaryReader reader, MapParseContext context, ushort version, bool mapHasAssetList) { var result = new BuildList(); // BFME and C&C3 both used v1 for this chunk, but store the faction name differently :( // If the map file has an AssetList chunk, we assume it's C&C3. if (mapHasAssetList) { result.FactionName = reader.ReadUInt16PrefixedAsciiString(); } else { result.FactionNameProperty = AssetPropertyKey.Parse(reader, context); } var numBuildListItems = reader.ReadUInt32(); result.Items = new BuildListItem[numBuildListItems]; for (var i = 0; i < numBuildListItems; i++) { result.Items[i] = BuildListItem.Parse(reader, version, 1, mapHasAssetList); } return(result); }
internal static CastleTemplates Parse(BinaryReader reader, MapParseContext context) { return(ParseAsset(reader, context, version => { var propertyKey = AssetPropertyKey.Parse(reader, context); var count = reader.ReadUInt32(); var result = new CastleTemplate[count]; for (var i = 0; i < count; i++) { result[i] = CastleTemplate.Parse(reader, version); } CastlePerimeter perimeter = null; if (version >= 2) { perimeter = CastlePerimeter.Parse(reader, version); } return new CastleTemplates { PropertyKey = propertyKey, Templates = result, Perimeter = perimeter }; })); }
internal static AssetProperty Parse(BinaryReader reader, MapParseContext context) { var key = AssetPropertyKey.Parse(reader, context); object value = null; switch (key.PropertyType) { case AssetPropertyType.Boolean: value = reader.ReadBooleanChecked(); break; case AssetPropertyType.Integer: value = reader.ReadUInt32(); break; case AssetPropertyType.RealNumber: value = reader.ReadSingle(); break; case AssetPropertyType.AsciiString: value = reader.ReadUInt16PrefixedAsciiString(); break; case AssetPropertyType.Unknown: // Seems exactly the same as AsciiString? value = reader.ReadUInt16PrefixedAsciiString(); break; case AssetPropertyType.UnicodeString: value = reader.ReadUInt16PrefixedUnicodeString(); break; default: throw new InvalidDataException($"Unexpected property type: {key.PropertyType}."); } return(new AssetProperty { Key = key, Value = value }); }
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; })); }
internal static BuildList Parse(BinaryReader reader, MapParseContext context, ushort version) { var result = new BuildList(); if (version >= 1) { result.FactionName = reader.ReadUInt16PrefixedAsciiString(); } else { result.FactionNameProperty = AssetPropertyKey.Parse(reader, context); } var numBuildListItems = reader.ReadUInt32(); result.Items = new BuildListItem2[numBuildListItems]; for (var i = 0; i < numBuildListItems; i++) { result.Items[i] = BuildListItem2.Parse(reader, version); } return(result); }
internal AssetProperty(string name, AssetPropertyType propertyType, object value) { Key = new AssetPropertyKey(name, propertyType); Value = value; }