Example #1
0
        public List <RemoveMipsEntry> prepareListToRemove(List <FoundTexture> textures)
        {
            List <RemoveMipsEntry> list = new List <RemoveMipsEntry>();

            for (int k = 0; k < textures.Count; k++)
            {
                for (int t = 0; t < textures[k].list.Count; t++)
                {
                    if (textures[k].list[t].path == "")
                    {
                        continue;
                    }
                    if (textures[k].list[t].removeEmptyMips)
                    {
                        bool found = false;
                        for (int e = 0; e < list.Count; e++)
                        {
                            if (list[e].pkgPath == textures[k].list[t].path)
                            {
                                list[e].exportIDs.Add(textures[k].list[t].exportID);
                                found = true;
                                break;
                            }
                        }
                        if (found)
                        {
                            continue;
                        }
                        RemoveMipsEntry entry = new RemoveMipsEntry();
                        entry.pkgPath   = textures[k].list[t].path;
                        entry.exportIDs = new List <int>();
                        entry.exportIDs.Add(textures[k].list[t].exportID);
                        list.Add(entry);
                    }
                }
            }

            return(list);
        }
Example #2
0
        public string removeMipMapsME2ME3(List <FoundTexture> textures, Package package, RemoveMipsEntry removeEntry, MainWindow mainWindow, Installer installer, bool ipc, bool repack)
        {
            string errors = "";

            for (int l = 0; l < removeEntry.exportIDs.Count; l++)
            {
                int exportID = removeEntry.exportIDs[l];
                using (Texture texture = new Texture(package, exportID, package.getExportData(exportID), false))
                {
                    if (!texture.mipMapsList.Exists(s => s.storageType == Texture.StorageTypes.empty))
                    {
                        continue;
                    }
                    do
                    {
                        texture.mipMapsList.Remove(texture.mipMapsList.First(s => s.storageType == Texture.StorageTypes.empty));
                    } while (texture.mipMapsList.Exists(s => s.storageType == Texture.StorageTypes.empty));
                    texture.properties.setIntValue("SizeX", texture.mipMapsList.First().width);
                    texture.properties.setIntValue("SizeY", texture.mipMapsList.First().height);
                    texture.properties.setIntValue("MipTailBaseIdx", texture.mipMapsList.Count() - 1);

                    using (MemoryStream newData = new MemoryStream())
                    {
                        newData.WriteFromBuffer(texture.properties.toArray());
                        newData.WriteFromBuffer(texture.toArray(package.exportsTable[exportID].dataOffset + (uint)newData.Position));
                        package.setExportData(exportID, newData.ToArray());
                    }
                }
            }
            if (package.SaveToFile(repack, false, installer != null))
            {
                if (repack && Installer.pkgsToRepack != null)
                {
                    Installer.pkgsToRepack.Remove(package.packagePath);
                }
                if (Installer.pkgsToMarker != null)
                {
                    Installer.pkgsToMarker.Remove(package.packagePath);
                }
            }
            package.Dispose();

            return(errors);
        }
Example #3
0
        public string removeMipMapsME1(int phase, List <FoundTexture> textures, Package package, RemoveMipsEntry removeEntry, MainWindow mainWindow, Installer installer, bool ipc)
        {
            string errors = "";

            for (int l = 0; l < removeEntry.exportIDs.Count; l++)
            {
                int exportID = removeEntry.exportIDs[l];
                using (Texture texture = new Texture(package, exportID, package.getExportData(exportID), false))
                {
                    if (!texture.mipMapsList.Exists(s => s.storageType == Texture.StorageTypes.empty))
                    {
                        continue;
                    }
                    do
                    {
                        texture.mipMapsList.Remove(texture.mipMapsList.First(s => s.storageType == Texture.StorageTypes.empty));
                    } while (texture.mipMapsList.Exists(s => s.storageType == Texture.StorageTypes.empty));
                    texture.properties.setIntValue("SizeX", texture.mipMapsList.First().width);
                    texture.properties.setIntValue("SizeY", texture.mipMapsList.First().height);
                    texture.properties.setIntValue("MipTailBaseIdx", texture.mipMapsList.Count() - 1);

                    FoundTexture foundTexture      = new FoundTexture();
                    int          foundListEntry    = -1;
                    int          foundTextureEntry = -1;
                    string       pkgName           = GameData.RelativeGameData(package.packagePath).ToLowerInvariant();
                    for (int k = 0; k < textures.Count; k++)
                    {
                        for (int t = 0; t < textures[k].list.Count; t++)
                        {
                            if (textures[k].list[t].exportID == exportID &&
                                textures[k].list[t].path.ToLowerInvariant() == pkgName)
                            {
                                foundTexture      = textures[k];
                                foundTextureEntry = k;
                                foundListEntry    = t;
                                break;
                            }
                        }
                    }
                    if (foundListEntry == -1)
                    {
                        if (ipc)
                        {
                            Console.WriteLine("[IPC]ERROR Texture " + package.exportsTable[exportID].objectName + " not found in tree: " + removeEntry.pkgPath + ", skipping...");
                            Console.Out.Flush();
                        }
                        else
                        {
                            errors += "Error: Texture " + package.exportsTable[exportID].objectName + " not found in tree: " + removeEntry.pkgPath + ", skipping..." + Environment.NewLine;
                        }
                        continue;
                    }

                    MatchedTexture m = foundTexture.list[foundListEntry];
                    if (m.linkToMaster != -1)
                    {
                        if (phase == 1)
                        {
                            continue;
                        }

                        MatchedTexture foundMasterTex = foundTexture.list[m.linkToMaster];
                        if (texture.mipMapsList.Count != foundMasterTex.masterDataOffset.Count)
                        {
                            if (ipc)
                            {
                                Console.WriteLine("[IPC]ERROR Texture " + package.exportsTable[exportID].objectName + " in package: " + foundMasterTex.path + " has wrong reference, skipping..." + Environment.NewLine);
                                Console.Out.Flush();
                            }
                            else
                            {
                                errors += "Error: Texture " + package.exportsTable[exportID].objectName + " in package: " + foundMasterTex.path + " has wrong reference, skipping..." + Environment.NewLine;
                            }
                            continue;
                        }
                        for (int t = 0; t < texture.mipMapsList.Count; t++)
                        {
                            Texture.MipMap mipmap = texture.mipMapsList[t];
                            if (mipmap.storageType == Texture.StorageTypes.extLZO ||
                                mipmap.storageType == Texture.StorageTypes.extZlib ||
                                mipmap.storageType == Texture.StorageTypes.extUnc)
                            {
                                mipmap.dataOffset      = foundMasterTex.masterDataOffset[t];
                                texture.mipMapsList[t] = mipmap;
                            }
                        }
                    }

                    uint packageDataOffset;
                    using (MemoryStream newData = new MemoryStream())
                    {
                        newData.WriteFromBuffer(texture.properties.toArray());
                        packageDataOffset = package.exportsTable[exportID].dataOffset + (uint)newData.Position;
                        newData.WriteFromBuffer(texture.toArray(packageDataOffset));
                        package.setExportData(exportID, newData.ToArray());
                    }

                    if (m.linkToMaster == -1)
                    {
                        if (phase == 2)
                        {
                            throw new Exception();
                        }
                        m.masterDataOffset = new List <uint>();
                        for (int t = 0; t < texture.mipMapsList.Count; t++)
                        {
                            m.masterDataOffset.Add(packageDataOffset + texture.mipMapsList[t].internalOffset);
                        }
                    }

                    m.removeEmptyMips = false;
                    textures[foundTextureEntry].list[foundListEntry] = m;
                }
            }
            if (package.SaveToFile(false, false, installer != null))
            {
                if (Installer.pkgsToMarker != null)
                {
                    Installer.pkgsToMarker.Remove(package.packagePath);
                }
            }
            package.Dispose();

            return(errors);
        }