Exemple #1
0
        public Chunk_MCVP(WMOFile file) : base(file, "MCVP", Magic)
        {
            int planeCount = (int)ChunkSize / 16;

            planes = new C4Plane[planeCount];

            for (int i = 0; i < planeCount; i++)
            {
                planes[i] = C4Plane.Read(file);
            }

            LogWrite("Loaded " + planeCount + " convex volume planes.");
        }
Exemple #2
0
    // Convex Volume Planes. Contains blocks of floating-point numbers.
    public static void ReadMCVP(Stream WMOrootstream, int MCVPsize) // optional
    {
        // These are used to define the volume of when you are inside this WMO.
        // Important for transports.
        //If a point is behind all planes (i.e. point-plane distance is negative for all planes), it is inside.
        List <C4Plane> ConvexVolumePlanes = new List <C4Plane>();

        for (int i = 0; i < MCVPsize / 16; i++)
        {
            C4Plane convexVolumePlane = new C4Plane();
            convexVolumePlane.normal   = new Vector3(ReadFloat(WMOrootstream), ReadFloat(WMOrootstream), ReadFloat(WMOrootstream));
            convexVolumePlane.distance = ReadFloat(WMOrootstream);
            ConvexVolumePlanes.Add(convexVolumePlane);
        }
    }
Exemple #3
0
    // Portal information.
    public static void ReadMOPT(Stream WMOrootstream)
    {
        List <SMOPortal> PortalInfo = new List <SMOPortal>();

        for (int i = 0; i < wmoData.Info.nPortals; ++i)
        {
            SMOPortal portal = new SMOPortal();
            portal.startVertex = ReadShort(WMOrootstream);
            portal.count       = ReadShort(WMOrootstream);
            C4Plane plane = new C4Plane();
            plane.normal   = new Vector3(ReadFloat(WMOrootstream), ReadFloat(WMOrootstream), ReadFloat(WMOrootstream));
            plane.distance = ReadFloat(WMOrootstream);
            portal.plane   = plane;
            PortalInfo.Add(portal);
        }
    }
Exemple #4
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);
                    }
                }
            }
        }
Exemple #5
0
 public static void WriteC4Plane(this BinaryWriter writer, C4Plane plane)
 {
     writer.WriteC3Vector(plane.Normal);
     writer.Write(plane.Distance);
 }