Example #1
0
        private Dictionary <uint, CustomCP> ReadCustomCP(BinaryReader br, long offset)
        {
            if (offset != -1)
            {
                var map = new Dictionary <uint, CustomCP>();
                br.BaseStream.Position = offset;
                var len = br.ReadInt32();

                if (len > 0)
                {
                    var count = br.ReadInt32();

                    for (int i = 0; i < count; ++i)
                    {
                        var cp = new CustomCP();
                        cp.Read(br);
                        map[cp.Key] = cp;
                    }
                }

                return(map);
            }

            return(null);
        }
Example #2
0
        private CPAttribute[] ReadAttribs(BinaryReader br, BinaryReader str, int maxlen, Dictionary <uint, CustomCP> cpmap)
        {
            var size   = br.ReadInt32();
            var offset = br.BaseStream.Position;
            var result = new CPAttribute[size >> 3];             // set initial capacity

            int count = 0;

            while (count < maxlen && br.BaseStream.Position < offset + size)
            {
                var      key = br.ReadUInt32();
                CustomCP cp  = null;

                // If existing map does not have attribute key, it might be a custom key then
                if (!Map.CarPartKeys.TryGetValue(key, out var type))
                {
                    type = CarPartAttribType.Custom;
                    if (!cpmap.TryGetValue(key, out cp))
                    {
                        cp = new CustomCP(key);
                    }
                }

                result[count] = type switch
                {
                    CarPartAttribType.Boolean => new BoolAttribute(br, key),
                    CarPartAttribType.CarPartID => new PartIDAttribute(br, key),
                    CarPartAttribType.Floating => new FloatAttribute(br, key),
                    CarPartAttribType.String => new StringAttribute(br, str, key),
                    CarPartAttribType.TwoString => new TwoStringAttribute(br, str, key),
                    CarPartAttribType.Color => new ColorAttribute(br, key),
                    CarPartAttribType.Key => new KeyAttribute(br, key),
                    CarPartAttribType.ModelTable => new ModelTableAttribute(br, key),
                    CarPartAttribType.Custom => new CustomAttribute(br, str, cp),
                    _ => new IntAttribute(br, key),
                };

                ++count;
            }

            return(result);
        }