private void DumpAllCollisions(IWin32Window window, BundleArchive archive)
        {
            if (archive == null)
            {
                return;
            }

            FolderBrowserDialog fbd    = new FolderBrowserDialog();
            DialogResult        result = fbd.ShowDialog(window);

            if (result == DialogResult.OK)
            {
                string path = fbd.SelectedPath;

                for (int i = 0; ; i++)
                {
                    string idListName = "trk_clil" + i;
                    string polyName   = "trk_col_" + i;

                    ulong idListID = Crc32.HashCrc32B(idListName);
                    ulong polyID   = Crc32.HashCrc32B(polyName);

                    BundleEntry entry = archive.GetEntryByID(idListID);
                    if (entry == null)
                    {
                        break;
                    }
                    Stream       outFile = File.Open(path + "/" + idListName + ".bin", FileMode.Create, FileAccess.Write);
                    BinaryWriter bw      = new BinaryWriter(outFile);
                    bw.Write(entry.EntryBlocks[0].Data);
                    bw.Flush();
                    bw.Close();
                    outFile.Close();

                    BundleEntry polyEntry = archive.GetEntryByID(polyID);
                    if (polyEntry == null)
                    {
                        break;
                    }
                    Stream       outFilePoly = File.Open(path + "/" + polyName + ".bin", FileMode.Create, FileAccess.Write);
                    BinaryWriter bwPoly      = new BinaryWriter(outFilePoly);
                    bwPoly.Write(polyEntry.EntryBlocks[0].Data);
                    bwPoly.Flush();
                    bwPoly.Close();
                    outFilePoly.Close();

                    PolygonSoupList poly = new PolygonSoupList();
                    poly.Read(polyEntry);
                    Scene scene = poly.MakeScene();
                    scene.ExportWavefrontObj(path + "/" + polyName + ".obj");
                }

                MessageBox.Show(window, "Done!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        public Scene MakeScene(ILoader loader)
        {
            Scene scene = new Scene();

            foreach (uint instance in Instances)
            {
                BundleEntry modelEntry = Entry.Archive.GetEntryByID(instance);
                if (modelEntry == null)
                {
                    string file = BundleCache.GetFileByEntryID(instance);
                    if (!string.IsNullOrEmpty(file))
                    {
                        BundleArchive archive = BundleArchive.Read(file);
                        modelEntry = archive.GetEntryByID(instance);
                    }
                }

                if (modelEntry != null)
                {
                    BundleEntry renderableEntry = modelEntry.GetDependencies()[0].Entry;
                    Renderable  renderable      = new Renderable();
                    renderable.Read(renderableEntry, null);                     // TODO: Null Loader
                    SceneObject sceneObject = new SceneObject(instance.ToString("X8"), renderable.Model);
                    //sceneObject.Transform = instance.Transform;

                    scene.AddObject(sceneObject);
                }
            }

            return(scene);
        }
        public static MaterialEntry Read(BundleEntry entry)
        {
            MaterialEntry result = new MaterialEntry();

            List <BundleDependency> dependencies = entry.GetDependencies();

            foreach (BundleDependency dependency in dependencies)
            {
                ulong id = dependency.EntryID;

                //DebugTimer t = DebugTimer.Start("LoadDep");
                BundleEntry descEntry1 = entry.Archive.GetEntryByID(id);
                if (descEntry1 == null)
                {
                    string file = BundleCache.GetFileByEntryID(id);
                    if (!string.IsNullOrEmpty(file))
                    {
                        BundleArchive archive = BundleArchive.Read(file);
                        descEntry1 = archive.GetEntryByID(id);
                    }
                }
                //t.StopLog();

                //DebugTimer t2 = DebugTimer.Start("LoadTextureState");
                if (descEntry1 != null && descEntry1.Type == EntryType.TextureState)
                {
                    TextureState state = TextureState.Read(descEntry1);

                    result.TextureStates.Add(state);
                }
                //t2.StopLog();
            }

            MemoryStream  ms = entry.MakeStream();
            BinaryReader2 br = new BinaryReader2(ms);

            br.BigEndian = entry.Console;

            // TODO: Read Material

            br.Close();
            ms.Close();

            result.Color = Color.White;

            if (result.TextureStates.Count > 0)
            {
                result.DiffuseMap = result.TextureStates[0].Texture;
            }
            if (result.TextureStates.Count > 1)
            {
                result.NormalMap = result.TextureStates[1].Texture;
            }
            if (result.TextureStates.Count > 2)
            {
                result.SpecularMap = result.TextureStates[2].Texture;
            }

            return(result);
        }
Exemple #4
0
        private Image GetGameMap(BundleArchive archive)
        {
            ulong       id         = 0x9F55039D;
            BundleEntry descEntry1 = archive.GetEntryByID(id);

            if (descEntry1 == null)
            {
                string file = BundleCache.GetFileByEntryID(id);
                if (!string.IsNullOrEmpty(file))
                {
                    BundleArchive archive2 = BundleArchive.Read(file);
                    if (archive2 != null)
                    {
                        descEntry1 = archive2.GetEntryByID(id);
                    }
                }
            }

            if (descEntry1 == null)
            {
                string        path     = Path.GetDirectoryName(archive.Path) + Path.DirectorySeparatorChar + "GUITEXTURES.BIN";
                BundleArchive archive2 = BundleArchive.Read(path);
                if (archive2 != null)
                {
                    descEntry1 = archive2.GetEntryByID(id);
                }
            }

            Image image = null;

            if (descEntry1 != null && descEntry1.Type == EntryType.Texture)
            {
                if (archive.Console)
                {
                    image = GameImage.GetImagePS3(descEntry1.EntryBlocks[0].Data, descEntry1.EntryBlocks[1].Data);
                }
                else
                {
                    image = GameImage.GetImage(descEntry1.EntryBlocks[0].Data, descEntry1.EntryBlocks[1].Data);
                }

                if (image != null)
                {
                    TextureCache.AddToCache(id, image);
                }
            }
            return(image);
        }
        public static TextureState Read(BundleEntry entry)
        {
            TextureState result = new TextureState();

            List <BundleDependency> dependencies = entry.GetDependencies();

            foreach (BundleDependency dependency in dependencies)
            {
                ulong id = dependency.EntryID;

                if (TextureCache.Contains(id))
                {
                    result.Texture = TextureCache.GetTexture(id);
                }
                else
                {
                    BundleEntry descEntry1 = entry.Archive.GetEntryByID(id);
                    if (descEntry1 == null)
                    {
                        string file = BundleCache.GetFileByEntryID(id);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            if (archive != null)
                            {
                                descEntry1 = archive.GetEntryByID(id);
                            }
                        }
                    }

                    if (descEntry1 != null && descEntry1.Type == EntryType.Texture)
                    {
                        if (entry.Console)
                        {
                            result.Texture = GameImage.GetImagePS3(descEntry1.EntryBlocks[0].Data, descEntry1.EntryBlocks[1].Data);
                        }
                        else
                        {
                            result.Texture = GameImage.GetImage(descEntry1.EntryBlocks[0].Data, descEntry1.EntryBlocks[1].Data);
                        }

                        if (result.Texture != null)
                        {
                            TextureCache.AddToCache(id, result.Texture);
                        }

                        break;
                    }
                }
            }

            MemoryStream  ms = entry.MakeStream();
            BinaryReader2 br = new BinaryReader2(ms);

            br.BigEndian = entry.Console;

            // TODO: Read Texture State

            br.Close();
            ms.Close();

            return(result);
        }
        public Scene MakeScene(ILoader loader = null)
        {
            //TextureState.ResetCache();

            Scene scene = new Scene();

            Dictionary <ulong, Renderable> models = new Dictionary <ulong, Renderable>();

            int i     = 0;
            int index = 1;

            foreach (ModelInstance instance in Instances)
            {
                int progress = (index - 1) * 100 / Instances.Count;
                loader?.SetProgress(progress);

                loader?.SetStatus("Loading(" + progress.ToString("D2") + "%): ModelInstance: " + index + "/" + Instances.Count);
                //DebugTimer t = DebugTimer.Start("ModelInstance[" + index + "/" + Instances.Count + "]");
                index++;

                if (!InRange(instance))
                {
                    continue;
                }

                if (models.ContainsKey(instance.ModelEntryID))
                {
                    Renderable  renderable  = models[instance.ModelEntryID];
                    SceneObject sceneObject = new SceneObject(instance.ModelEntryID.ToString("X8"), renderable.Model);
                    sceneObject.ID        = i.ToString();
                    sceneObject.Transform = instance.Transform;

                    scene.AddObject(sceneObject);
                }
                else
                {
                    BundleEntry modelEntry = Entry.Archive.GetEntryByID(instance.ModelEntryID);
                    if (modelEntry == null)
                    {
                        string file = BundleCache.GetFileByEntryID(instance.ModelEntryID);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            modelEntry = archive.GetEntryByID(instance.ModelEntryID);
                        }
                    }

                    if (modelEntry != null)
                    {
                        BundleEntry renderableEntry = modelEntry.GetDependencies()[0].Entry;
                        Renderable  renderable      = new Renderable();
                        renderable.Read(renderableEntry, null);                         // TODO: Null Loader
                        models.Add(instance.ModelEntryID, renderable);
                        SceneObject sceneObject =
                            new SceneObject(instance.ModelEntryID.ToString("X8"), renderable.Model);
                        sceneObject.ID        = i.ToString();
                        sceneObject.Transform = instance.Transform;

                        scene.AddObject(sceneObject);
                    }
                }
                i++;
                //t.StopLog();
            }
            loader?.SetProgress(100);

            //TextureState.ResetCache();

            return(scene);
        }
Exemple #7
0
        public bool Read(BundleEntry entry, ILoader loader)
        {
            Clear();

            List <BundleDependency> dependencies = entry.GetDependencies();

            ID = entry.ID;

            MemoryStream  ms = entry.MakeStream();
            BinaryReader2 br = new BinaryReader2(ms);

            br.BigEndian = entry.Console;

            Unknown1      = br.ReadSingle();
            Unknown2      = br.ReadSingle();
            Unknown3      = br.ReadSingle();
            Unknown4      = br.ReadSingle();
            Unknown5      = br.ReadInt16();
            MeshCount     = br.ReadInt16();
            StartOffset   = br.ReadInt32();
            Unknown8      = br.ReadInt32();
            Unknown9      = br.ReadInt32();
            Unknown10     = br.ReadInt16();
            Unknown10_1   = br.ReadInt16();
            UnknownOffset = br.ReadInt32();
            Unknown12     = br.ReadInt32();
            Unknown13     = br.ReadInt32();

            br.BaseStream.Position = StartOffset;

            for (int i = 0; i < MeshCount; i++)
            {
                int offset = br.ReadInt32();
                MeshVertexOffsets.Add(offset);
            }

            /*if (entry.Platform == BundlePlatform.PS3)
             * {
             *  br.BaseStream.Position += 16 - (br.BaseStream.Position % 16);
             *  result.NumIndices = br.ReadInt16();
             *  result.Unknown = br.ReadInt16();
             * }
             * else
             * {*/
            NumIndices = br.ReadInt32();
            //}

            Unknown15 = br.ReadInt32();
            Unknown16 = br.ReadInt32();
            Unknown17 = br.ReadInt32();
            // some extra data here in BPR

            br.BaseStream.Position = UnknownOffset;
            if (NumIndices == 0) // BPR
            {
                // ???
                br.BaseStream.Position += 12;
            }
            VertexBlockAddress = br.ReadInt32();
            Unknown18          = (NumIndices == 0) ? 0 : br.ReadInt32();
            VertexBlockSize    = br.ReadInt32();


            for (int i = 0; i < MeshCount; i++)
            {
                br.BaseStream.Position = MeshVertexOffsets[i];

                RenderableMesh mesh = new RenderableMesh();

                mesh.RotationMatrix   = br.ReadMatrix4();
                mesh.Unknown19        = br.ReadInt32();
                mesh.Unknown20        = br.ReadInt32();
                mesh.IndexOffsetCount = br.ReadInt32();
                if (NumIndices == 0) // BPR
                {
                    mesh.NumFaces = br.ReadInt32() / 3;
                }
                else
                {
                    mesh.NumVertices       = br.ReadInt32();
                    mesh.VertexOffsetCount = br.ReadInt32();
                    mesh.VertexOffsetCount = 0;
                    mesh.NumFaces          = br.ReadInt32();
                }
                int cPos = (int)br.BaseStream.Position;
                mesh.MaterialIDInternal = br.ReadInt32();
                foreach (BundleDependency dependency in dependencies)
                {
                    if (dependency.EntryPointerOffset == cPos)
                    {
                        mesh.MaterialID = dependency.EntryID;
                        break;
                    }
                }
                mesh.Unknown21         = br.ReadInt16();
                mesh.Unknown22         = br.ReadInt16();
                mesh.NumIndicesOffset  = br.ReadInt32();
                mesh.VerticesOffsetPtr = br.ReadInt32();

                mesh.VertexDescriptionsInternal = new int[6];
                mesh.VertexDescriptionIDs       = new ulong[6];
                for (int j = 0; j < mesh.VertexDescriptionsInternal.Length; j++)
                {
                    int pos = (int)br.BaseStream.Position;
                    foreach (BundleDependency dependency in dependencies)
                    {
                        if (dependency.EntryPointerOffset == pos)
                        {
                            mesh.VertexDescriptionIDs[j] = dependency.EntryID;
                            break;
                        }
                    }

                    mesh.VertexDescriptionsInternal[j] = br.ReadInt32();
                }

                Meshes.Add(mesh);
            }

            br.Close();
            ms.Close();

            loader?.SetStatus("Loading Meshes");
            for (int i = 0; i < Meshes.Count; i++)
            {
                RenderableMesh mesh = Meshes[i];

                int progress = (i + 1) * 100 / Meshes.Count;

                loader?.SetStatus("Loading Meshes: " + (i + 1) + "/" + Meshes.Count);
                loader?.SetProgress(progress);

                if (LoadMaterials)
                {
                    BundleEntry descEntry1 = entry.Archive.GetEntryByID(mesh.MaterialID);
                    if (descEntry1 == null)
                    {
                        string file = BundleCache.GetFileByEntryID(mesh.MaterialID);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            descEntry1 = archive.GetEntryByID(mesh.MaterialID);
                        }
                    }

                    if (descEntry1 != null)
                    {
                        mesh.Material = MaterialEntry.Read(descEntry1);
                    }
                }

                mesh.VertexDescriptions = new VertexDesc[6];
                for (int j = 0; j < mesh.VertexDescriptions.Length; j++)
                {
                    ulong       vertexDescID = mesh.VertexDescriptionIDs[j];
                    BundleEntry descEntry    = entry.Archive.GetEntryByID(vertexDescID);
                    if (descEntry == null)
                    {
                        string file = BundleCache.GetFileByEntryID(vertexDescID);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            descEntry = archive.GetEntryByID(vertexDescID);
                        }
                    }

                    if (descEntry != null)
                    {
                        mesh.VertexDescriptions[j] = VertexDesc.Read(descEntry);
                    }
                }
            }

            ms           = entry.MakeStream(true);
            br           = new BinaryReader2(ms);
            br.BigEndian = entry.Console;
            ReadBody(br);
            br.Close();
            ms.Close();

            BuildModel();

            _scene = MakeScene(loader);

            return(true);
        }