UESaveTool icon indicating copy to clipboard operation
UESaveTool copied to clipboard

Adding Map Property

Open Anonym0usWork1221 opened this issue 1 year ago • 6 comments

Hi, there First of all good library. I am trying to add MapProperty in property section

The file I am trying to open is Active.zip

It contain MapProperty So I am trying to add that property and then getting this error

error

The sample data chart I created is


Name Bytes Value
Size of Name string 13 00 00 00 19bytes
Name string 50 69 63 6b 55 70 43 6f 75 6e 74 53 65 74 74 69 6e 67 00 PickUpCountSetting\0
Size of Type string 0c 00 00 00 12bytes
Type string 4d 61 70 50 72 6f 70 65 72 74 79 00 MapProperty\0
Size of Stored data 38 00 00 00 56bytes
Padding 00 00 00 00 4 null characters
Size of StoredType string 0c 00 00 00 12bytes
StoredType string 49 6e 74 50 72 6f 70 65 72 74 79 00 IntProperty\0
Size of StoredType string 0c 00 00 00 12bytes
StoredType string 49 6e 74 50 72 6f 70 65 72 74 79 00 IntProperty\0
padding 00 00 00 00 00 5 null characters
Stored Data 06 00 00 00 89 8a 01 00 96 00 00 00 8b 8a 01 00 dc 00 00 00 8c 8a 01 00 fa 00 00 00 8d 8a 01 00 a4 00 00 00 8e 8a 01 00 fa 00 00 00 90 8a 01 00 96 00 00 00 e.g (Map([["apples", 500],["bananas", 300],["oranges", 200]]);)

The sample code I am using from upper file is

sample And the Code I wrote I almost like StructProperty. Sorry I don't know java script that much but can understand to some extend.

import { Property } from './index.js'
import { PropertyFactory } from '../factories/index.js';
import { Serializer } from '../../utils/Serializer.js';
import { SerializationError } from '../PropertyErrors.js';

export class MapProperty extends Property {
    constructor() {
        super();
        this.StoredPropertyType = "";
        this.Properties = [];
    }
    get Size() {
        let size = this.Name.length + 4;
        size += this.Type.length + 4;
        size += 8; // 4 byte size + 4 byte padding
        size += this.StoredPropertyType.length + 4;
        size += 5; // 5 byte padding
        for (let i = 0; i < this.Properties.length; i++) {
            size += this.Properties[i].Size;
        }
        return size;
    }
    get HeaderSize() {
        let size = this.Name.length + 4;
        size += this.Type.length + 4;
        size += 8;
        size += this.StoredPropertyType.length + 4;
        size += 5;
        return size
    }
    get Count() {
        return this.Properties.length;
    }
    deserialize(serial, size) {
        console.log(`Deserializing ${this.Name} Size: ${size}`)
        serial.seek(4);
        this.StoredPropertyType = serial.readString();
        serial.seek(5);
        let end = serial.tell + size;
        let i = 0;
        while (serial.tell < end) {
            let Name = this.StoredPropertyType;
            let Type = 'Tuple';
            let prop = PropertyFactory.create({ Name, Type })
            prop.deserialize(serial)
            this.Properties.push(prop);
            i++;
        }
        // console.log(`Done Deserializing ${this.Name} Offset: ${serial.tell}`)
        return this;
    }
    serialize() {
        let serial = Serializer.alloc(this.Size);
        serial.writeString(this.Name);
        serial.writeString(this.Type);
        serial.writeInt32(this.Size - this.HeaderSize);
        serial.seek(4);
        serial.writeString(this.StoredPropertyType);
        serial.seek(5);
        for (let i = 0; i < this.Properties.length; i++) {
            serial.write(this.Properties[i].serialize());
        }
        if (serial.tell !== this.Size)
            throw new SerializationError(this);
        return serial.Data;
    }
    static from(obj) {
        let map = new MapProperty();
        map.Name = obj.Name;
        map.Type = obj.Type;
        map.StoredPropertyType = obj.StoredPropertyType;
        map.Properties = [];
        if (obj.Properties !== undefined)
            obj.Properties.forEach((prop) => map.Properties.push(PropertyFactory.create(prop)));
        return map;
    }
}

And one more change I want you to do add a feature to allow the drop of bytes in unknown maps

Anonym0usWork1221 avatar Sep 10 '22 17:09 Anonym0usWork1221