Beispiel #1
0
        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            uint n = 0;

            if (!r.Get(ref n))
            {
                return(false);
            }
            if (!r.Get(ref BBoxMin))
            {
                return(false);
            }
            if (!r.Get(ref BBoxMax))
            {
                return(false);
            }

            Tris.Capacity    = (int)n;
            Normals.Capacity = (int)n;
            if (!r.GetRaw(ref Tris, (uint)Marshal.SizeOf(typeof(STri)) * n))
            {
                return(false);
            }
            if (!r.GetRaw(ref Normals, (uint)Marshal.SizeOf(typeof(CVec3f)) * n))
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
                public bool Load(ref CDynMemoryReader r, ref CUberData data)
                {
                    if (!r.Get(ref A))
                    {
                        return(false);
                    }
                    if (!r.Get(ref BBMin))
                    {
                        return(false);
                    }
                    if (!r.Get(ref BBMax))
                    {
                        return(false);
                    }
                    if (!Loaders.LoadArray(ref Planes, ref r, ref data))
                    {
                        return(false);
                    }
                    if (!Loaders.LoadPrimitiveArray(ref Verts, ref r))
                    {
                        return(false);
                    }

                    return(true);
                }
Beispiel #3
0
            public bool Load(ref CDynMemoryReader r, ref CUberData data)
            {
                uint n = 0;

                AABVs.Clear();
                RootAABV.LeafIDs.Clear();
                RootAABV.pLeftNode  = null;
                RootAABV.pRightNode = null;

                if (!r.Get(ref n))
                {
                    return(false);
                }

                if (n != 0)
                {
                    AABVs.Capacity = (int)n;
                    for (int i = 0; i < n; i++)
                    {
                        AABVs.Add(new CMeshItemAABV());
                    }

                    uint index = 0;
                    return(RootAABV.Load(ref r, ref data, ref AABVs, ref index));
                }

                return(true);
            }
Beispiel #4
0
        public float E; //TODO

        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            float temp = 0;

            if (!r.Get(ref temp))
            {
                return(false);
            }
            Normal.X = temp;

            if (!r.Get(ref temp))
            {
                return(false);
            }
            Normal.Y = temp;

            if (!r.Get(ref temp))
            {
                return(false);
            }
            Normal.Z = temp;

            if (!r.Get(ref Distance))
            {
                return(false);
            }
            if (!r.Get(ref E))
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            string s;
            uint   n = 0;

            s = r.ReadPascalStr();
            if (s == "")
            {
                return(false);
            }
            Name = s;

            if (!Loaders.LoadArray(ref Bones, ref r, ref data))
            {
                return(false);
            }
            if (!r.Get(ref n))
            {
                return(false);
            }
            if (n != 0)
            {
                if (!Loaders.LoadArray(ref ExternalInstances, ref r, ref data))
                {
                    return(false);
                }
            }

            return(true);
        }
        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            uint   n = 0;
            string s;

            if (!r.Get(ref n))
            {
                return(false);
            }
            if (n == 0)
            {
                return(true);
            }

            s = r.ReadPascalStr();
            if (s == "")
            {
                return(false);
            }
            Name = s;

            if (!Loaders.LoadArray(ref Parts, ref r, ref data))
            {
                return(false);
            }

            return(true);
        }
Beispiel #7
0
        public static bool LoadPrimitiveArray <T>(ref List <T> array, ref CDynMemoryReader r) where T : struct
        {
            uint i = 0, count = 0;

            if (!r.Get(ref count))
            {
                return(false);
            }
            array.Capacity = (int)count;
            for (i = 0; i < count; i++)
            {
                if (array.Count <= i)
                {
                    array.Add(new T());
                }
                var element = array[(int)i];
                if (!r.Get(ref element))
                {
                    return(false);
                }
                array[(int)i] = element;
            }

            return(true);
        }
Beispiel #8
0
        public static bool LoadStringArray(ref List <string> array, ref CDynMemoryReader r)
        {
            uint i = 0, count = 0;

            if (!r.Get(ref count))
            {
                return(false);
            }
            array.Capacity = (int)count;
            string s;

            for (i = 0; i < count; i++)
            {
                s = r.ReadPascalStr();
                if (s == "")
                {
                    return(false);
                }
                if (array.Count <= i)
                {
                    array.Add("");
                }
                array[(int)i] = s;
            }

            return(true);
        }
Beispiel #9
0
        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            byte[] d;
            if (!r.Get(ref FaceCount))
            {
                return(false);
            }
            if (FaceCount != 0)
            {
                d = data.ReadMeshData(FaceCount * (uint)Marshal.SizeOf(typeof(SAABFace)));
                if (d == null || d.Length == 0)
                {
                    return(false);
                }
                Faces.Capacity = (int)FaceCount;
                Loaders.LoadBytesIntoObjectList(ref Faces, ref d);
            }

            if (!r.Get(ref NodeCount))
            {
                return(false);
            }

            d = data.ReadMeshData(0x28); // 40 bytes
            if (d == null || d.Length == 0)
            {
                return(false);
            }
            Loaders.LoadBytesIntoObject(ref RootNode, ref d);

            if (NodeCount != 0)
            {
                d = data.ReadMeshData(NodeCount * (uint)Marshal.SizeOf(typeof(SAABBNode)));
                if (d == null || d.Length == 0)
                {
                    return(false);
                }
                Nodes.Capacity = (int)NodeCount;
                Loaders.LoadBytesIntoObjectList(ref Nodes, ref d);
            }

            if (!r.Get(ref FaceIndexMapCount))
            {
                return(false);
            }
            if (FaceIndexMapCount != 0)
            {
                d = data.ReadMeshData(FaceIndexMapCount * sizeof(uint));
                if (d == null || d.Length == 0)
                {
                    return(false);
                }
                FaceIndexMap.Capacity = (int)FaceIndexMapCount;
                Loaders.LoadBytesIntoObjectList(ref FaceIndexMap, ref d);
            }

            return(true);
        }
Beispiel #10
0
            public List <float> Transform; // This was float Transform[4 * 4]

            public bool Load(ref CDynMemoryReader r, ref CUberData data)
            {
                string s;

                if (!r.Get(ref A))
                {
                    return(false);
                }
                if (!r.Get(ref Index))
                {
                    return(false);
                }
                if (!r.Get(ref ID))
                {
                    return(false);
                }
                if (!r.Get(ref Flags))
                {
                    return(false);
                }
                if (!r.Get(ref RegionA))
                {
                    return(false);
                }
                if (!r.Get(ref RegionB))
                {
                    return(false);
                }

                s = r.ReadPascalStr();
                if (s == "")
                {
                    return(false);
                }
                InstanceName = s;

                s = r.ReadPascalStr();
                if (s == "")
                {
                    return(false);
                }
                AssetName = s;

                Materials = new List <uint>();
                if (!Loaders.LoadPrimitiveArray(ref Materials, ref r))
                {
                    return(false);
                }

                Transform = new List <float>();
                if (!r.GetRaw(ref Transform, 4 * 4))
                {
                    return(false);
                }

                return(true);
            }
Beispiel #11
0
        public static CUberData GetUbrData(string filePath)
        {
            using (var fs = new FileStream(filePath, FileMode.Open))
            {
                var r = new CDynMemoryReader(fs);

                var uberData = new CUberData();
                uberData.Load(ref r);

                return(uberData);
            }
        }
Beispiel #12
0
 public bool Load(ref CDynMemoryReader r, ref CUberData data)
 {
     if (!r.Get(ref Min))
     {
         return(false);
     }
     if (!r.Get(ref Max))
     {
         return(false);
     }
     return(true);
 }
Beispiel #13
0
 public bool Load(ref CDynMemoryReader r, ref CUberData data)
 {
     if (!r.Get(ref Center))
     {
         return(false);
     }
     if (!r.Get(ref Radius))
     {
         return(false);
     }
     return(true);
 }
Beispiel #14
0
                public bool Load(ref CDynMemoryReader r, ref CUberData data, ref List <CMeshItemAABV> AABVs, ref uint index)
                {
                    UInt16 NumLeafs = 0;

                    if (!r.Get(ref Flags))
                    {
                        return(false);
                    }
                    if (!r.Get(ref BBMin))
                    {
                        return(false);
                    }
                    if (!r.Get(ref BBMax))
                    {
                        return(false);
                    }

                    if ((Flags & (int)CMeshItemAABVFlags.MESHITEMAABV_FLAG_LEAF) != 0)
                    {
                        if (!r.Get(ref NumLeafs))
                        {
                            return(false);
                        }
                        LeafIDs.Capacity = NumLeafs;
                        if (!r.GetRaw(ref LeafIDs, NumLeafs))
                        {
                            return(false);
                        }
                    }

                    if ((Flags & (int)CMeshItemAABVFlags.MESHITEMAABV_FLAG_LEFT) != 0)
                    {
                        index++;
                        pLeftNode = AABVs[(int)index];
                        if (!pLeftNode.Load(ref r, ref data, ref AABVs, ref index))
                        {
                            return(false);
                        }
                    }

                    if ((Flags & (int)CMeshItemAABVFlags.MESHITEMAABV_FLAG_RIGHT) != 0)
                    {
                        index++;
                        pRightNode = AABVs[(int)index];
                        if (!pRightNode.Load(ref r, ref data, ref AABVs, ref index))
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
Beispiel #15
0
            public List <CVec3f> B = new List <CVec3f>(); // Was CVec3f B[4]

            public bool Load(ref CDynMemoryReader r, ref CUberData data)
            {
                if (!r.Get(ref A))
                {
                    return(false);
                }
                if (!r.GetRaw(ref B, 4))
                {
                    return(false);
                }

                return(true);
            }
Beispiel #16
0
        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            string s0 = r.ReadPascalStr();

            if (s0 == "")
            {
                return(false);
            }
            Name = s0;

            string s1 = r.ReadPascalStr();

            if (s1 == "")
            {
                return(false);
            }
            ModelName = s1;

            if (!r.Get(ref LOD))
            {
                return(false);
            }
            if (!r.Get(ref BBMin))
            {
                return(false);
            }
            if (!r.Get(ref BBMax))
            {
                return(false);
            }
            if (!r.Get(ref MeshSectionCount2))
            {
                return(false);
            }
            //Could be quality
            if (!r.Get(ref ID))
            {
                return(false);
            }
            if (!r.Get(ref MeshSectionCount))
            {
                return(false);
            }

            return(true);
        }
Beispiel #17
0
        static void Main()
        {
            Console.WriteLine("Starting");
            var fs = new FileStream("C:\\psforever\\ubr\\expansion1.ubr", FileMode.Open); // Either change this to an absolute path, or make sure this file is in the bin folder before running.
            var r  = new CDynMemoryReader(fs);

            var uberData = new CUberData();

            uberData.Load(ref r);

            var data = uberData.FetchMeshSystem("vanu_core".ToCharArray(), new CMeshSystem());
            var a    = data.PortalSystem.MeshItems.Where(x => x.AssetName.Contains("term")).ToList();

            Debugger.Break(); // Inspect the above returned data in a debugger

            Console.WriteLine("Done");
            Console.ReadKey();
        }
Beispiel #18
0
        public bool LoadMeshSections(ref CDynMemoryReader r, ref CUberData data)
        {
            uint i;

            MeshSections.Capacity = (int)MeshSectionCount;

            for (i = 0; i < MeshSectionCount; i++)
            {
                var section = new CMeshSection();
                if (!section.Load(ref r, ref data))
                {
                    return(false);
                }
                MeshSections.Add(section);
            }

            return(true);
        }
Beispiel #19
0
            public bool Load(ref CDynMemoryReader r, ref CUberData data)
            {
                string s;

                s = r.ReadPascalStr();
                if (s == "")
                {
                    return(false);
                }
                Name = s;

                if (!r.Get(ref ID))
                {
                    return(false);
                }
                if (!r.Get(ref BBMin))
                {
                    return(false);
                }
                if (!r.Get(ref BBMax))
                {
                    return(false);
                }
                if (!Loaders.LoadArray(ref Portals, ref r, ref data))
                {
                    return(false);
                }
                if (!Loaders.LoadArray(ref ConvexHulls, ref r, ref data))
                {
                    return(false);
                }
                if (!Loaders.LoadPrimitiveArray(ref U32Array, ref r))
                {
                    return(false);
                }
                if (!Loaders.LoadArray(ref RegionSubStructs0, ref r, ref data))
                {
                    return(false);
                }

                return(true);
            }
Beispiel #20
0
        public bool FetchMeshSystem(uint index, CMeshSystem system)
        {
            if (index >= NumEntries())
            {
                return(false);
            }
            SUberEntry entry     = Entries[(int)index];
            SUberEntry nextEntry = Entries[(int)index + 1];

            var bytes = ModelData.Skip((int)entry.ModelDataOffset).Take((int)nextEntry.ModelDataOffset - (int)entry.ModelDataOffset).ToArray();

            m_ModelDataCache.m_pBuffer = bytes;
            var r = new CDynMemoryReader(ref m_ModelDataCache);

            m_pMeshDataCur = entry.MeshDataOffset;
            m_pMeshDataEnd = m_pMeshDataCur + (nextEntry.MeshDataOffset - entry.MeshDataOffset);

            m_LookupOffset = entry.LookupOffset;
            m_U32Offset    = entry.U32Offset;

            if (!system.Load(ref r, this))
            {
                return(false);
            }

            system.Name = entry.Name;
            if (entry.Name.StartsWith("map") && char.IsNumber(entry.Name[3]) && char.IsNumber(entry.Name[4]))
            {
                system.Flags |= (int)MeshFlags.MESHSYS_FLAG_MAP_GEOMETRY;
            }
            if (entry.Name.StartsWith("ugd") && char.IsNumber(entry.Name[3]) && char.IsNumber(entry.Name[4]))
            {
                system.Flags |= (int)MeshFlags.MESHSYS_FLAG_MAP_GEOMETRY;
            }
            if (entry.Name.StartsWith("lava") && char.IsNumber(entry.Name[4]) && char.IsNumber(entry.Name[5]))
            {
                system.Flags |= (int)MeshFlags.MESHSYS_FLAG_MAP_GEOMETRY;
            }

            return(true);
        }
Beispiel #21
0
            public bool Load(ref CDynMemoryReader r, ref CUberData data)
            {
                string s = r.ReadPascalStr();

                if (s == "")
                {
                    return(false);
                }
                Name = s;

                if (!r.Get(ref A))
                {
                    return(false);
                }
                if (!r.Get(ref B))
                {
                    return(false);
                }

                return(true);
            }
Beispiel #22
0
        public List <float> RotationMatrix = new List <float>(); //Scale xform? - This was float RotationMatrix[3 * 3]


        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            if (!r.Get(ref Flags))
            {
                return(false);
            }
            if (!r.Get(ref Position))
            {
                return(false);
            }
            if (!r.Get(ref RotationQuat))
            {
                return(false);
            }
            if (!r.GetRaw(ref RotationMatrix, 3 * 3))
            {
                return(false);
            }

            return(true);
        }
Beispiel #23
0
            public int MeshItemID; //ID of the attached mesh ID, e. g. a door

            public bool Load(ref CDynMemoryReader r, ref CUberData data)
            {
                if (!r.Get(ref A))
                {
                    return(false);
                }
                if (!r.Get(ref RegionA))
                {
                    return(false);
                }
                if (!r.Get(ref RegionB))
                {
                    return(false);
                }
                for (int i = 0; i < 4; i++)
                {
                    if (Points.Count <= i)
                    {
                        Points.Add(new CVec3f());
                    }
                    var element = Points[i];
                    if (!r.Get(ref element))
                    {
                        return(false);
                    }
                    Points[i] = element;
                }

                if (!Plane.Load(ref r, ref data))
                {
                    return(false);
                }

                if (!r.Get(ref MeshItemID))
                {
                    return(false);
                }

                return(true);
            }
Beispiel #24
0
        public static bool LoadArray <T>(ref List <T> array, ref CDynMemoryReader r, ref CUberData data) where T : ILoadable, new()
        {
            uint i = 0, count = 0;

            if (!r.Get(ref count))
            {
                return(false);
            }
            array.Capacity = (int)count;

            for (i = 0; i < count; i++)
            {
                if (array.Count <= i)
                {
                    array.Add(new T());
                }
                if (!array[(int)i].Load(ref r, ref data))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #25
0
        public float B; //TODO

        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            if (!r.GetRaw(ref Matrix, 4 * 4))
            {
                return(false);
            }
            if (!r.Get(ref ExtendMin))
            {
                return(false);
            }
            if (!r.Get(ref ExtendMax))
            {
                return(false);
            }
            if (!r.Get(ref A))
            {
                return(false);
            }
            if (!r.Get(ref B))
            {
                return(false);
            }
            return(true);
        }
Beispiel #26
0
        public bool Load(ref CDynMemoryReader r, CUberData data)
        {
            Console.WriteLine($"Loading {GetType().Name}");
            Clear();

            uint i, n = 0;

            if (!r.Get(ref Flags))
            {
                return(false);
            }
            if (!r.Get(ref BBMin))
            {
                return(false);
            }
            if (!r.Get(ref BBMax))
            {
                return(false);
            }
            if (!r.Get(ref A))
            {
                return(false);
            }
            if (!r.Get(ref B))
            {
                return(false);
            }

            if (!Loaders.LoadArray(ref MeshArray, ref r, ref data))
            {
                return(false);
            }
            foreach (var mesh in MeshArray)
            {
                Meshes[mesh.Name] = mesh;
            }

            if ((Flags & (uint)MeshFlags.MESHSYS_FLAG_PORTALSYSTEM) != 0)
            {
                if (!PortalSystem.Load(ref r, ref data))
                {
                    return(false);
                }
            }

            if ((Flags & (uint)MeshFlags.MESHSYS_FLAG_VEC3ARRAY) != 0)
            {
                if (!r.Get(ref n))
                {
                    return(false);
                }
                Vec3Data.Capacity = (int)n;
                for (i = 0; i < n; i++)
                {
                    if (Vec3Data.Count <= i)
                    {
                        Vec3Data.Add(new List <CVec3f>());
                    }
                    var element = Vec3Data[(int)i];
                    if (!Loaders.LoadPrimitiveArray(ref element, ref r))
                    {
                        return(false);
                    }
                    Vec3Data[(int)i] = element;
                }
            }

            if ((Flags & (uint)MeshFlags.MESHSYS_FLAG_USERDATA) != 0)
            {
                if (!r.Get(ref n))
                {
                    return(false);
                }

                UserData.Capacity = (int)n;
                if (!r.GetRaw(ref UserData, sizeof(byte) * n))
                {
                    return(false);
                }
            }

            if ((Flags & (uint)MeshFlags.MESHSYS_FLAG_SKELETONS) != 0)
            {
                if (!Loaders.LoadArray(ref Skeletons, ref r, ref data))
                {
                    return(false);
                }

                foreach (var skel in Skeletons)
                {
                    foreach (var bone in skel.Bones)
                    {
                        if (bone.Name.StartsWith("ef_"))
                        {
                            Flags |= (uint)MeshFlags.MESHSYS_FLAG_HAS_EF;
                            break;
                        }
                    }

                    if ((Flags & (uint)MeshFlags.MESHSYS_FLAG_HAS_EF) != 0)
                    {
                        break;
                    }
                }
            }

            foreach (var mesh in MeshArray)
            {
                if (!mesh.LoadMeshSections(ref r, ref data))
                {
                    return(false);
                }
            }

            if ((Flags & (uint)MeshFlags.MESHSYS_FLAG_NO_AAB) == 0)
            {
                if (!AAB.Load(ref r, ref data))
                {
                    return(false);
                }
            }

            if ((Flags & (uint)MeshFlags.MESHSYS_FLAG_COLLISION) != 0)
            {
                if (!Collision.Load(ref r, ref data))
                {
                    return(false);
                }
            }

            foreach (var mesh in MeshArray)
            {
                if (mesh.LOD == 14)
                {
                    if (LODs[0] == null)
                    {
                        LODs[0] = mesh;
                    }
                }
                else if (mesh.LOD >= 1001 && mesh.LOD <= 1008)
                {
                    n = mesh.LOD - 1000;
                    if (LODs[n] == null)
                    {
                        LODs[n] = mesh;
                    }
                }
            }

            return(true);
        }
Beispiel #27
0
        public bool Load(ref CDynMemoryReader r)
        {
            Console.WriteLine($"Loading {GetType().Name}");
            SUberHeader hdr = new SUberHeader();    // C# Possibly Unassigned Value

            if (!r.Get(ref hdr))
            {
                return(false);
            }
            if (!hdr.FourCC.SequenceEqual(SUberHeader.FourCCValue))
            {
                return(false);
            }
            if (hdr.VersionA != SUberHeader.VersionAValue)
            {
                return(false);
            }
            if (hdr.VersionB != SUberHeader.VersionBValue)
            {
                return(false);
            }

            Console.WriteLine($"Loading {hdr.EntryCount} Entries");
            Entries.Capacity = (int)hdr.EntryCount;
            if (!r.GetRaw(ref Entries, hdr.EntryCount))
            {
                return(false);
            }

            Console.WriteLine($"Loading {hdr.Vec3Count} Vec3Data");
            Vec3Data.Capacity = (int)hdr.Vec3Count;
            if (!r.GetRaw(ref Vec3Data, hdr.Vec3Count))
            {
                return(false);
            }

            Console.WriteLine($"Loading {hdr.Vec2Count} Vec2Data");
            Vec2Data.Capacity = (int)hdr.Vec2Count;
            if (!r.GetRaw(ref Vec2Data, hdr.Vec2Count))
            {
                return(false);
            }

            Console.WriteLine($"Loading {hdr.LookupCount} LookupData");
            LookupData.Capacity = (int)hdr.LookupCount;
            if (!r.GetRaw(ref LookupData, hdr.LookupCount))
            {
                return(false);
            }

            Console.WriteLine($"Loading {hdr.MeshDataSize} MeshDataSize");
            MeshData.Capacity = (int)hdr.MeshDataSize;
            if (!r.GetRaw(ref MeshData, hdr.MeshDataSize))
            {
                return(false);
            }
            MeshDataBytes = MeshData.ToArray();

            Console.WriteLine($"Loading {hdr.U32Count} U32Count");
            U32Data.Capacity = (int)hdr.U32Count;
            if (!r.GetRaw(ref U32Data, hdr.U32Count))
            {
                return(false);
            }

            Console.WriteLine($"Loading {hdr.ModelDataSize} ModelDataSize");
            ModelData.Capacity = (int)hdr.ModelDataSize;
            if (!r.GetRaw(ref ModelData, hdr.ModelDataSize))
            {
                return(false);
            }

            Entries.Add(new SUberEntry
            {
                Name            = ".",
                LookupOffset    = hdr.LookupCount,
                MeshDataOffset  = hdr.U32Count,
                ModelDataOffset = hdr.MeshDataSize,
                U32Offset       = hdr.ModelDataSize
            });

            return(true);
        }
Beispiel #28
0
        //todo: CCollisionPart operator functions
        //CCollisionPart &operator=(const CCollisionPart &b) = delete;
        //CCollisionPart(const CCollisionPart &b) = delete;
        //CCollisionPart(CCollisionPart &&b)
        //CCollisionPart &operator=(CCollisionPart &&b)

        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            Clear();
            string s;

            s = r.ReadPascalStr();
            if (s == "")
            {
                return(false);
            }

            // This is a workaround for Marshal.SizeOf not working with enums. Assign to a temporary variable of the correct byte length first.
            uint typeTemp = 0;

            if (!r.Get(ref typeTemp))
            {
                return(false);
            }
            Type = (eCollisionType)typeTemp;

            if (!r.Get(ref BBoxMin))
            {
                return(false);
            }
            if (!r.Get(ref BBoxMax))
            {
                return(false);
            }

            switch (Type)
            {
            case eCollisionType.Sphere:
                pSphere = new CCollisionPartSphere();
                if (!pSphere.Load(ref r, ref data))
                {
                    return(false);
                }
                break;

            case eCollisionType.Box:
                pBox = new CCollisionPartBox();
                if (!pBox.Load(ref r, ref data))
                {
                    return(false);
                }
                break;

            case eCollisionType.Mesh:
                pMesh = new CCollisionPartMesh();
                if (!pMesh.Load(ref r, ref data))
                {
                    return(false);
                }
                break;

            case eCollisionType.Cylinder:
                pCylinder = new CCollisionPartCylinder();
                if (!pCylinder.Load(ref r, ref data))
                {
                    return(false);
                }
                break;

            case eCollisionType.OOBB:
                pOOBB = new CCollisionPartOOBB();
                if (!pOOBB.Load(ref r, ref data))
                {
                    return(false);
                }
                break;

            case eCollisionType.Undefined:
                break;

            default:
                //Should never happen.
                break;
            }

            return(true);
        }
Beispiel #29
0
        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            string s0 = r.ReadPascalStr();

            if (s0 == "")
            {
                return(false);
            }
            MaterialName = s0;

            uint n = 0;

            if (!r.Get(ref Flags))
            {
                return(false);
            }
            if (!r.Get(ref ID))
            {
                return(false);
            }
            if (!r.Get(ref MeshID))
            {
                return(false);
            }
            if (!r.Get(ref LOD))
            {
                return(false);
            }

            // This is a workaround for Marshal.SizeOf not working with enums. Assign to a temporary variable of the correct byte length first.
            uint vertexTypeTemp = 0;

            if (!r.Get(ref vertexTypeTemp))
            {
                return(false);
            }
            VertexType = (eVertexType)vertexTypeTemp;

            if (!r.Get(ref BBMin))
            {
                return(false);
            }
            if (!r.Get(ref BBMax))
            {
                return(false);
            }
            if (!r.Get(ref IndexCount))
            {
                return(false);
            }

            var pIndexData = data.ReadMeshData(sizeof(UInt16) * IndexCount);

            Indices.Capacity = (int)IndexCount;
            // Convert from byte to short
            UInt16[] indices = new ushort[pIndexData.Length / 2];
            Buffer.BlockCopy(pIndexData, 0, indices, 0, pIndexData.Length);
            Indices = indices.ToList();

            uint d = 0;

            switch (VertexType)
            {
            case eVertexType.Fat:
            case eVertexType.Lit:
            case eVertexType.Unlit:
            case eVertexType.Thin:
            case eVertexType.Raw:
            case eVertexType.FatDeform:
            case eVertexType.Deform:
                if (!r.Get(ref VertexCount))
                {
                    return(false);
                }
                LookupOffset = data.GetLookup(VertexCount);
                n            = U32PerVert(VertexType);
                U32Offset    = n != 0 ? data.GetU32(VertexCount * n) : 0;
                break;

            default:
                VertexCount = 0;
                break;
            }

            switch (VertexType)
            {
            case eVertexType.Fat:
                BuildVertices_Fat(ref data);
                break;

            case eVertexType.Lit:
                BuildVerticies_Lit(ref data);
                break;

            case eVertexType.Unlit:
                BuildVertices_Unlit(ref data);
                break;

            case eVertexType.Thin:
                BuildVertices_Thin(ref data);
                break;

            case eVertexType.Raw:
                BuildVertices_Raw(ref data);
                break;

            case eVertexType.Deform:
                BuildVertices_Deform(ref data);
                break;

            case eVertexType.FatDeform:
                // Do nothing?
                break;
            }

            return(true);
        }
Beispiel #30
0
        public bool Load(ref CDynMemoryReader r, ref CUberData data)
        {
            Console.WriteLine($"Loading {GetType().Name}");
            uint   n = 0, i = 0;
            string s;

            Clear();

            if (!r.Get(ref n))
            {
                return(false);
            }
            if (n == 0)
            {
                return(true);
            }

            if (!r.Get(ref BBMin))
            {
                return(false);
            }
            if (!r.Get(ref BBMax))
            {
                return(false);
            }

            if (!PortalMesh0.Load(ref r, ref data))
            {
                return(false);
            }
            if (!PortalMesh1.Load(ref r, ref data))
            {
                return(false);
            }
            if (!PortalMesh2.Load(ref r, ref data))
            {
                return(false);
            }
            if (!PortalMesh3.Load(ref r, ref data))
            {
                return(false);
            }
            if (!PortalMesh4.Load(ref r, ref data))
            {
                return(false);
            }

            if (!Loaders.LoadArray(ref ExteriorPortals, ref r, ref data))
            {
                return(false);
            }

            if (!Loaders.LoadArray(ref Regions, ref r, ref data))
            {
                return(false);
            }
            if (!Loaders.LoadStringArray(ref Strings, ref r))
            {
                return(false);
            }

            if (!r.Get(ref n))
            {
                return(false);
            }

            var aabv = new CAABV();

            if (n != 0)
            {
                MeshItems.Capacity = (int)n;
                for (i = 0; i < n; i++)
                {
                    if (MeshItems.Count <= i)
                    {
                        MeshItems.Add(new CMeshItem());
                    }
                    var element = MeshItems[(int)i];
                    if (!element.Load(ref r, ref data))
                    {
                        return(false);
                    }
                    MeshItems[(int)i] = element;
                }

                if (!r.Get(ref n))
                {
                    return(false);
                }
                if (n != 0)
                {
                    if (!AABV.Load(ref r, ref data))
                    {
                        return(false);
                    }
                }
                for (i = 0; i < Regions.Count; i++)
                {
                    uint PortalID = 0;
                    uint HasAABV  = 0;
                    if (!r.Get(ref PortalID))
                    {
                        return(false);
                    }
                    if (!r.Get(ref HasAABV))
                    {
                        return(false);
                    }
                    if (HasAABV != 0)
                    {
                        if (!aabv.Load(ref r, ref data))
                        {
                            return(false);
                        }
                    }
                }
            }

            if (!Loaders.LoadPrimitiveArray(ref U32s, ref r))
            {
                return(false);
            }

            if (U32s.Count != 0)
            {
                if (!r.Get(ref n))
                {
                    return(false);
                }
                if (n != 0)
                {
                    if (!aabv.Load(ref r, ref data))
                    {
                        return(false);
                    }
                }
            }

            if (!Loaders.LoadArray(ref SubStructs1, ref r, ref data))
            {
                Loaded = true;
            }

            return(true);
        }