示例#1
0
        private string ReadStringValue(int valueOffset, BdatValueType type)
        {
            switch (type)
            {
            case BdatValueType.String:
                return(Data.ReadUTF8Z(Data.ReadInt32(valueOffset)));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
示例#2
0
        private float ReadFloatValue(int valueOffset, BdatValueType type)
        {
            switch (type)
            {
            case BdatValueType.FP32:
                if (Data.Game == Game.XBX)
                {
                    uint value = Data.ReadUInt32(valueOffset);
                    return((float)(value * (1 / 4096.0)));
                }
                return(Data.ReadSingle(valueOffset));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
示例#3
0
        private static int GetTypeSize(BdatValueType type)
        {
            switch (type)
            {
            case BdatValueType.UInt8:
            case BdatValueType.Int8:
                return(1);

            case BdatValueType.UInt16:
            case BdatValueType.Int16:
                return(2);

            case BdatValueType.UInt32:
            case BdatValueType.Int32:
            case BdatValueType.String:
            case BdatValueType.FP32:
                return(4);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
示例#4
0
        private static object ParseValue(string value, BdatValueType type)
        {
            switch (type)
            {
            case BdatValueType.UInt8:
            case BdatValueType.UInt16:
            case BdatValueType.UInt32:
            case BdatValueType.Int8:
            case BdatValueType.Int16:
            case BdatValueType.Int32:
                return(long.Parse(value));

            case BdatValueType.String:
                return(value);

            case BdatValueType.FP32:
                return(float.Parse(value));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#5
0
        private int GetTypeBytes(BdatValueType type)
        {
            //also for arrays
            switch (type)
            {
            case BdatValueType.Int8:
            case BdatValueType.UInt8:
                return(1);

            case BdatValueType.UInt16:
            case BdatValueType.Int16:
                return(2);

            case BdatValueType.Int32:
            case BdatValueType.UInt32:
            case BdatValueType.String:
            case BdatValueType.FP32:
                return(4);

            default:
                return(1);
            }
        }
示例#6
0
        private static string ReadValue(DataBuffer table, int valueOffset, BdatValueType type)
        {
            switch (type)
            {
            case BdatValueType.UInt8:
                return(table[valueOffset].ToString());

            case BdatValueType.UInt16:
                return(table.ReadUInt16(valueOffset).ToString());

            case BdatValueType.UInt32:
                return(table.ReadUInt32(valueOffset).ToString());

            case BdatValueType.Int8:
                return(((sbyte)table[valueOffset]).ToString());

            case BdatValueType.Int16:
                return(table.ReadInt16(valueOffset).ToString());

            case BdatValueType.Int32:
                return(table.ReadInt32(valueOffset).ToString());

            case BdatValueType.String:
                return(table.ReadUTF8Z(table.ReadInt32(valueOffset)));

            case BdatValueType.FP32:
                if (table.Game == Game.XBX)
                {
                    uint value = table.ReadUInt32(valueOffset);
                    return(((float)(value * (1 / 4096.0))).ToString("R"));
                }
                return(table.ReadSingle(valueOffset).ToString("R"));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
示例#7
0
 public BdatMember(string name, BdatMemberType type, BdatValueType valType)
 {
     Name    = name;
     Type    = type;
     ValType = valType;
 }
        private static string ReadValue(byte[] file, int tableOffset, int valueOffset, BdatValueType type)
        {
            switch (type)
            {
            case BdatValueType.UInt8:
                return(file[valueOffset].ToString());

            case BdatValueType.UInt16:
                return(BitConverter.ToUInt16(file, valueOffset).ToString());

            case BdatValueType.UInt32:
                return(BitConverter.ToUInt32(file, valueOffset).ToString());

            case BdatValueType.Int8:
                return(((sbyte)file[valueOffset]).ToString());

            case BdatValueType.Int16:
                return(BitConverter.ToInt16(file, valueOffset).ToString());

            case BdatValueType.Int32:
                return(BitConverter.ToInt32(file, valueOffset).ToString());

            case BdatValueType.String:
                return(Stuff.GetUTF8Z(file, tableOffset + BitConverter.ToInt32(file, valueOffset)));

            case BdatValueType.FP32:
                return(BitConverter.ToSingle(file, valueOffset).ToString("R"));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }