예제 #1
0
    public static KeyValuePair <StatType, object> ReadStat(this BinaryReader reader)
    {
        var            t    = (StatType)reader.ReadByte();
        StatObjectType type = StatDataTypes.types[t];

        switch (type)
        {
        case StatObjectType.STRING:
            return(new KeyValuePair <StatType, object>(t, reader.ReadString()));

        case StatObjectType.INT16:
            return(new KeyValuePair <StatType, object>(t, reader.ReadInt16()));

        case StatObjectType.INT32:
            return(new KeyValuePair <StatType, object>(t, reader.ReadInt32()));

        case StatObjectType.FLOAT:
            return(new KeyValuePair <StatType, object>(t, reader.ReadSingle()));

        case StatObjectType.BYTE:
            return(new KeyValuePair <StatType, object>(t, reader.ReadByte()));
        }

        return(new KeyValuePair <StatType, object>(t, 0));
    }
예제 #2
0
    public static void Write(this BinaryWriter writer, StatType stat, object val)
    {
        StatObjectType type = StatDataTypes.types[stat];

        writer.Write((byte)stat);

        switch (type)
        {
        case StatObjectType.STRING:
            writer.Write((string)val);
            break;

        case StatObjectType.INT16:
            writer.Write((short)val);
            break;

        case StatObjectType.INT32:
            writer.Write((int)val);
            break;

        case StatObjectType.FLOAT:
            writer.Write((float)val);
            break;

        case StatObjectType.BYTE:
            writer.Write((byte)val);
            break;
        }
    }