예제 #1
0
        public void Load(byte[] raw)
        {
            RWStream str = new RWStream(raw);

            Width  = str.ReadInt32();
            Height = str.ReadInt32();
            Map    = new int[Width * Height];

            for (int i = 0; i < Width * Height; i++)
            {
                Map[i] = str.ReadInt32();//read hex value of pixle
            }
        }
예제 #2
0
        public static string ReadStringFromFile(ref RWStream file)
        {
            if (file.Length - file.Position < 4)
            {
                return("");
            }
            int strLength = file.ReadInt32();

            return(strLength == -1 || strLength == 0 ? "" : file.ReadString(StringType.Ascii, strLength).TrimEnd(new[] { '\0' }));
        }
예제 #3
0
        public void deSerialize(RWStream file)
        {
            int             size  = file.ReadInt32();
            var             bData = file.ReadBytes(size);
            RWStream        data  = new RWStream(bData);
            IDeserializable Iself = this;

            while (data.Position < data.Length)
            {
                Utilities.ReadProperty(ref data, Iself);
            }
        }
예제 #4
0
        private void DeserlizeFile()
        {
            RawFile._index = -1;
            RawFile.ReadString();//magic number
            Name       = RawFile.ReadString();
            Style      = RawFile.ReadByte();
            Size       = (short)RawFile.ReadInt32();
            CharsCount = RawFile.ReadInt32();

            for (int i = 0; i < CharsCount; i++)
            {
                Char.Add((char)RawFile.ReadByte());
                Width.Add(RawFile.ReadByte());
                Height.Add(RawFile.ReadByte());
                var l    = RawFile.ReadInt32();
                var data = new List <byte>();
                for (int dat = 0; dat < l; dat++)
                {
                    data.Add(RawFile.ReadByte());
                }
                Data.Add(data.ToArray());
            }
        }
예제 #5
0
        public void deSerialize(RWStream file)
        {
            var size  = file.ReadInt32();
            var bData = new byte[size]; file.Position += 4;

            Utilities.ReadStringFromFile(ref file); file.Position += 4;
            bData = file.ReadBytes(size);;
            var             data  = new RWStream(bData);
            IDeserializable Iself = this;

            while (data.Position < data.Length)
            {
                Utilities.ReadProperty(ref data, Iself);
            }
        }
예제 #6
0
        public void deSerialize(RWStream file)
        {
            int size = file.ReadInt32(); file.Position += 4;

            Utilities.ReadStringFromFile(ref file); file.Position += 4 + size;
        }
예제 #7
0
 public void deSerialize(RWStream file)
 {
     int size = file.ReadInt32(); file.Position += 4 + size;
 }
예제 #8
0
        public static void ReadProperty(ref RWStream file, IDeserializable obj)
        {
            string propName = ReadStringFromFile(ref file);

            file.Position += 4;
            string propType = ReadStringFromFile(ref file);

            file.Position += 4;
            FieldInfo prop = obj.GetType().GetField(propName, BindingFlags.Public | BindingFlags.Instance);

            if (prop == null)
            {
                return;
            }
            switch (propType)
            {
            case "StructProperty":

                object     instanceObj = Activator.CreateInstance(prop.GetValue(obj).GetType());
                MethodInfo parse       = instanceObj.GetType().GetMethod("deSerialize");
                parse.Invoke(instanceObj, new object[] { file });
                prop.SetValue(obj, instanceObj);
                break;

            case "ArrayProperty":
                object     instanceArray = Activator.CreateInstance(prop.GetValue(obj).GetType());
                MethodInfo arrayparse    = instanceArray.GetType().GetMethod("deSerialize");
                arrayparse.Invoke(instanceArray, new object[] { file });
                prop.SetValue(obj, instanceArray);
                break;

            case "BoolProperty":
                file.Position += 8;     //Skip two unkown int32s
                bool value = readBoolFromFile(ref file);
                prop.SetValue(obj, value);
                break;

            case "ByteProperty":
                file.Position += 8;
                ReadStringFromFile(ref file);
                file.Position += 4;
                string name      = ReadStringFromFile(ref file);
                int    eIndex    = file.ReadInt32();
                object enumValue = Enum.Parse(prop.GetValue(obj).GetType(), name);
                prop.SetValue(obj, enumValue);
                break;

            case "FloatProperty":
                int floatSize = file.ReadInt32();
                file.Position += 4;
                switch (floatSize)
                {
                case 4:
                    float single = readSingleFloatFromFile(ref file);
                    prop.SetValue(obj, single);
                    break;

                case 8:
                    double dbl = readDoubleFloatFromFile(ref file);
                    prop.SetValue(obj, dbl);
                    break;

                default:
                    throw new Exception("WTF that's not a floater");
                }

                break;

            case "IntProperty":
                file.Position += 4;
                int index    = file.ReadInt32();
                int intvalue = file.ReadInt32();
                if (prop.GetValue(obj).GetType().IsArray)
                {
                    var arrayVal = (int[])prop.GetValue(obj);
                    arrayVal[index] = intvalue;
                    prop.SetValue(obj, arrayVal);
                }
                else
                {
                    prop.SetValue(obj, intvalue);
                }
                break;

            case "StrProperty":
                file.Position += 8;
                string strValue = ReadStringFromFile(ref file);
                prop.SetValue(obj, strValue);
                break;

            case "":
                file.Position += 4;
                break;
            }
        }