Esempio n. 1
0
        public StringBlock(FormatBase input, int readLimit = -1)
        {
            data        = new Dictionary <int, string>();
            blockOffset = input.getSeek();

            int i = 0; // Relative offset.

            while ((readLimit == -1 || i < readLimit) && !input.isEndOfStream())
            {
                i += input.seekNonZero();

                if (input.isOutOfBounds(i) || i >= readLimit)
                {
                    break;
                }

                string line = input.readString();
                data.Add(i, line);

                i += line.Length + 1;
            }

            #if DEBUG
            foreach (KeyValuePair <int, string> node in data)
            {
                Log.Write("StringBlock [{0}] -> {1}", node.Key, node.Value);
            }
            #endif
        }
Esempio n. 2
0
        public static Doodad Read(FormatBase input)
        {
            Doodad temp = new Doodad();

            // 24-bit offset?
            byte[] b = input.readBytes(3);
            temp.offset = BitConverter.ToUInt32(new byte[4] { b[0], b[1], b[2], 0 }, 0);
            Stuffer.Stuff(temp, input, "Doodad", true);

            return temp;
        }
Esempio n. 3
0
        public static Material Read(FormatBase input, int index)
        {
            Material temp = new Material();
            temp.index = index;
            temp.flags = input.readUInt32();
            temp.shader = input.readUInt32();
            temp.blendMode = input.readUInt32();

            temp.texture1 = MaterialTexture.Read(input);
            temp.texture2 = new MaterialTexture(input.readUInt32(), Colour4.Read(input), 0);
            temp.terrainType = input.readUInt32();
            temp.texture3 = MaterialTexture.Read(input);

            Stuffer.DescribeStuffing(temp);

            input.skip(4 * 4); // runtime floats
            return temp;
        }
Esempio n. 4
0
        public StringBlock(FormatBase input, int readLimit = -1)
        {
            data = new Dictionary<int, string>();
            blockOffset = input.getSeek();

            int i = 0; // Relative offset.
            while ((readLimit == -1 || i < readLimit) && !input.isEndOfStream())
            {
                i += input.seekNonZero();

                if (input.isOutOfBounds(i) || i >= readLimit)
                    break;

                string line = input.readString();
                data.Add(i, line);

                i += line.Length + 1;
            }

            #if DEBUG
            foreach (KeyValuePair<int, string> node in data)
                Log.Write("StringBlock [{0}] -> {1}", node.Key, node.Value);
            #endif
        }
Esempio n. 5
0
        public static void Stuff(object target, FormatBase feed, string logPrefix = null, bool muteLogging = false)
        {
            foreach (PropertyInfo prop in target.GetType().GetProperties())
            {
                if (prop.CanWrite)
                {
                    MethodInfo setter = prop.GetSetMethod();
                    if (setter == null || !setter.IsPublic)
                    {
                        continue;
                    }

                    Type type = prop.PropertyType;

                    object set = null;
                    if (type.Equals(typeof(Int16)))
                    {
                        set = feed.readInt16();
                    }
                    else if (type.Equals(typeof(Int32)))
                    {
                        set = feed.readInt32();
                    }
                    else if (type.Equals(typeof(Int64)))
                    {
                        set = feed.readInt64();
                    }
                    else if (type.Equals(typeof(UInt16)))
                    {
                        set = feed.readUInt16();
                    }
                    else if (type.Equals(typeof(byte)))
                    {
                        set = feed.readUInt8();
                    }
                    else if (type.Equals(typeof(UInt32)))
                    {
                        set = feed.readUInt32();
                    }
                    else if (type.Equals(typeof(UInt64)))
                    {
                        set = feed.readUInt64();
                    }
                    else if (type.Equals(typeof(float)))
                    {
                        set = feed.readFloat();
                    }
                    else if (type.Equals(typeof(double)))
                    {
                        set = feed.readDouble();
                    }
                    else if (type.Equals(typeof(string)))
                    {
                        set = feed.readString();
                    }
                    else if (type.Equals(typeof(Position)))
                    {
                        set = Position.Read(feed);
                    }
                    else if (type.Equals(typeof(C4Plane)))
                    {
                        set = C4Plane.Read(feed);
                    }
                    else if (type.Equals(typeof(Colour4)))
                    {
                        set = Colour4.Read(feed);
                    }
                    else if (type.Equals(typeof(Rotation)))
                    {
                        set = Rotation.Read(feed);
                    }
                    else if (type.Equals(typeof(MaterialTexture)))
                    {
                        set = MaterialTexture.Read(feed);
                    }

                    // This is some hacky-ass code, but it allows MCNK chunk to use
                    // the stuffer without code bloat. Probably could be done better.
                    if (set == null)
                    {
                        if (type.Equals(typeof(UInt32[])))
                        {
                            int      size = ((UInt32[])prop.GetValue(target, null)).Length;
                            UInt32[] arr  = new UInt32[size];

                            for (int i = 0; i < size; i++)
                            {
                                arr[i] = feed.readUInt32();
                            }

                            set = arr;
                        }
                    }

                    if (set != null)
                    {
                        prop.SetValue(target, set, null);

                        #if !DEBUG
                        if (!muteLogging)
                        #endif
                        Log.Write("{0}{1} -> {2}", logPrefix == null ? string.Empty : logPrefix, prop.Name, set);
                    }
                    else
                    {
                        Log.Write("WARNING: Stuffer was not prepared to handle {0}!", type.Name);
                    }
                }
            }
        }
Esempio n. 6
0
 public static Position Read(FormatBase input)
 {
     return new Position(input.readFloat(), input.readFloat(), input.readFloat());
 }
Esempio n. 7
0
 public static DoodadSet Read(FormatBase input)
 {
     return new DoodadSet(input.readString(20), input.readUInt32(), input.readUInt32());
 }
Esempio n. 8
0
 public static C4Plane Read(FormatBase input)
 {
     return new C4Plane(input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat());
 }
Esempio n. 9
0
 public static Colour4 Read(FormatBase input)
 {
     return new Colour4(input.readUInt8(), input.readUInt8(), input.readUInt8(), input.readUInt8());
 }
Esempio n. 10
0
        public static void Stuff(object target, FormatBase feed, string logPrefix = null, bool muteLogging = false)
        {
            foreach (PropertyInfo prop in target.GetType().GetProperties())
            {
                if (prop.CanWrite)
                {
                    MethodInfo setter = prop.GetSetMethod();
                    if (setter == null || !setter.IsPublic)
                        continue;

                    Type type = prop.PropertyType;

                    object set = null;
                    if (type.Equals(typeof(Int16)))
                        set = feed.readInt16();
                    else if (type.Equals(typeof(Int32)))
                        set = feed.readInt32();
                    else if (type.Equals(typeof(Int64)))
                        set = feed.readInt64();
                    else if (type.Equals(typeof(UInt16)))
                        set = feed.readUInt16();
                    else if (type.Equals(typeof(byte)))
                        set = feed.readUInt8();
                    else if (type.Equals(typeof(UInt32)))
                        set = feed.readUInt32();
                    else if (type.Equals(typeof(UInt64)))
                        set = feed.readUInt64();
                    else if (type.Equals(typeof(float)))
                        set = feed.readFloat();
                    else if (type.Equals(typeof(double)))
                        set = feed.readDouble();
                    else if (type.Equals(typeof(string)))
                        set = feed.readString();
                    else if (type.Equals(typeof(Position)))
                        set = Position.Read(feed);
                    else if (type.Equals(typeof(C4Plane)))
                        set = C4Plane.Read(feed);
                    else if (type.Equals(typeof(Colour4)))
                        set = Colour4.Read(feed);
                    else if (type.Equals(typeof(Rotation)))
                        set = Rotation.Read(feed);
                    else if (type.Equals(typeof(MaterialTexture)))
                        set = MaterialTexture.Read(feed);

                    // This is some hacky-ass code, but it allows MCNK chunk to use
                    // the stuffer without code bloat. Probably could be done better.
                    if (set == null)
                    {
                        if (type.Equals(typeof(UInt32[])))
                        {
                            int size = ((UInt32[])prop.GetValue(target, null)).Length;
                            UInt32[] arr = new UInt32[size];

                            for (int i = 0; i < size; i++)
                                arr[i] = feed.readUInt32();

                            set = arr;
                        }
                    }

                    if (set != null)
                    {
                        prop.SetValue(target, set, null);

                        #if !DEBUG
                        if (!muteLogging)
                        #endif
                            Log.Write("{0}{1} -> {2}", logPrefix == null ? string.Empty : logPrefix, prop.Name, set);
                    }
                    else
                    {
                        Log.Write("WARNING: Stuffer was not prepared to handle {0}!", type.Name);
                    }
                }
            }
        }
Esempio n. 11
0
 public static MaterialTexture Read(FormatBase input)
 {
     return new MaterialTexture(input.readUInt32(), Colour4.Read(input), input.readUInt32());
 }
Esempio n. 12
0
 public static FogInfo Read(FormatBase input)
 {
     FogInfo temp = new FogInfo();
     Stuffer.Stuff(temp, input, "FogInfo", true);
     return temp;
 }
Esempio n. 13
0
 public static GroupInformation Read(FormatBase input)
 {
     GroupInformation temp = new GroupInformation();
     Stuffer.Stuff(temp, input, "GroupInformation", true);
     return temp;
 }
Esempio n. 14
0
File: UV.cs Progetto: Kruithne/W3DT
 public static UV Read(FormatBase input)
 {
     return new UV(input.readFloat(), input.readFloat());
 }