private void toolStripExtractMEMMenuItem(MeType gameType) { using (OpenFileDialog modFile = new OpenFileDialog()) { modFile.Title = "Please select Mod file"; modFile.Filter = "MEM mod file | *.mem"; modFile.Multiselect = true; if (modFile.ShowDialog() != DialogResult.OK) { return; } using (FolderBrowserDialog modDir = new FolderBrowserDialog()) { modDir.Description = "Please select destination directory for MEM extraction"; if (modDir.ShowDialog() != DialogResult.OK) { return; } enableGameDataMenu(false); GameData.gameType = gameType; string errors = ""; string log = ""; string[] files = modFile.FileNames; long diskFreeSpace = Misc.getDiskFreeSpace(modDir.SelectedPath); long diskUsage = 0; foreach (string file in files) { diskUsage += new FileInfo(file).Length; } diskUsage = (long)(diskUsage * 2.5); if (diskUsage >= diskFreeSpace) { MessageBox.Show("You have not enough disk space remaining. You need about " + Misc.getBytesFormat(diskUsage) + " free."); } else { Misc.startTimer(); foreach (string file in files) { string outDir = Path.Combine(modDir.SelectedPath, Path.GetFileNameWithoutExtension(file)); Directory.CreateDirectory(outDir); updateStatusLabel("MOD: " + file + " - extracting..."); updateStatusLabel2(""); errors += new MipMaps().extractTextureMod(file, outDir, null, null, ref log); } var time = Misc.stopTimer(); updateStatusLabel("MODs extracted. Process total time: " + Misc.getTimerFormat(time)); updateStatusLabel2(""); if (errors != "") { MessageBox.Show("WARNING: Some errors have occured!"); } } } } enableGameDataMenu(true); }
public ActionResult Edit(int id, FormCollection collection) { bool DidItWork = false; string CrudAction = "Edit"; try { MeTypeBusinessLayer bl = new MeTypeBusinessLayer(); MeType a = bl.MeTypes.Where(p => p.MeTypeID == id).Single(); #region Pull from Form Collection a.MeTypeDesc = (string)collection["MeTypeDesc"]; #endregion StoredProcedureBusinessLayer spbl = new StoredProcedureBusinessLayer(); DidItWork = spbl.ExecuteStoredProcedure(a, CrudAction, User.Identity.Name); if (DidItWork == false) { return(Content(string.Format("Error on {0} of {1}. Press back to return and try again", CrudAction, a.GetType().Name))); } else { return(RedirectToAction("Index")); } } catch { return(View()); } }
void updateMEConfig(MeType gameId) { enableGameDataMenu(false); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Assembly.GetExecutingAssembly().GetName().Name); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filename = Path.Combine(path, "me" + (int)gameId + "map.bin"); if (!File.Exists(filename)) { MessageBox.Show("Unable to update LOD settings.\nYou must scan your game using Texture Manager first always!"); enableGameDataMenu(true); return; } GameData gameData = new GameData(gameId, _configIni); path = gameData.EngineConfigIniPath; bool exist = File.Exists(path); if (!exist) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } ConfIni engineConf = new ConfIni(path); LODSettings.updateLOD(gameId, engineConf); MessageBox.Show("Game configuration file at " + path + " updated."); enableGameDataMenu(true); }
void removeTreeFile(MeType game) { enableGameDataMenu(false); DialogResult result = MessageBox.Show("WARNING: you are going to delete your current textures scan file." + "\n\nAfter that, and before scanning your game again, you need to restore game to vanilla state and reinstall vanilla DLCs and DLC mods." + "\n\nAre you sure you want to proceed?", "Remove textures map of the game.", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { GameData gameData = new GameData(game, _configIni); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Assembly.GetExecutingAssembly().GetName().Name); string filename = Path.Combine(path, "me" + (int)GameData.gameType + "map.bin"); if (File.Exists(filename)) { File.Delete(filename); MessageBox.Show("File at " + filename + " deleted."); } else { MessageBox.Show("INFO: File at " + filename + " not found."); } } enableGameDataMenu(true); }
// GET: MeType/Edit/5 public ActionResult Edit(int id) { MeTypeBusinessLayer bl = new MeTypeBusinessLayer(); MeType o = bl.MeTypes.Where(p => p.MeTypeID == id).Single(); ViewBag.ID = id; return(View(o)); }
public TexExplorer CreateTextureExplorer(MeType type) { TexExplorer explorer = new TexExplorer(this, type); explorer.Text = "Mass Effect " + (int)type; explorer.MdiParent = this; explorer.WindowState = FormWindowState.Maximized; explorer.Show(); return(explorer); }
public GameData(MeType type, ConfIni configIni, bool force = false, bool installerMode = false) { gameType = type; _configIni = configIni; string key = "ME" + (int)gameType; string path = configIni.Read(key, "GameDataPath"); if (path != null && path != "" && !force) { _path = path.TrimEnd(Path.DirectorySeparatorChar); if (File.Exists(GameExePath)) { return; } else { _path = null; } } string registryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\BioWare\Mass Effect"; string entry = "Path"; if (type == MeType.ME2_TYPE) { registryKey += " 2"; } else if (type == MeType.ME3_TYPE) { registryKey += " 3"; entry = "Install Dir"; } path = (string)Registry.GetValue(registryKey, entry, null); if (path != null && !force) { _path = path.TrimEnd(Path.DirectorySeparatorChar); if (File.Exists(GameExePath)) { configIni.Write(key, _path, "GameDataPath"); return; } else { _path = null; } } if (_path != null) { _configIni.Write(key, _path, "GameDataPath"); } }
void checkGameFiles(MeType gameType) { enableGameDataMenu(false); GameData gameData = new GameData(gameType, _configIni); if (Directory.Exists(GameData.GamePath)) { string filename = "errors.txt"; if (File.Exists(filename)) { File.Delete(filename); } string errors = ""; List <string> mods = new List <string>(); bool vanilla = Misc.checkGameFiles(gameType, ref errors, ref mods, this, null, Misc.generateModsMd5Entries); updateStatusLabel(""); using (FileStream fs = new FileStream(filename, FileMode.CreateNew)) { if (mods.Count != 0) { fs.WriteStringASCII(Environment.NewLine + "------- Detected mods --------" + Environment.NewLine); for (int l = 0; l < mods.Count; l++) { fs.WriteStringASCII(mods[l] + Environment.NewLine); } fs.WriteStringASCII("------------------------------" + Environment.NewLine + Environment.NewLine); } if (!vanilla) { fs.WriteStringASCII("===========================================================================" + Environment.NewLine); fs.WriteStringASCII("WARNING: looks like the following file(s) are not vanilla or not recognized" + Environment.NewLine); fs.WriteStringASCII("===========================================================================" + Environment.NewLine + Environment.NewLine); fs.WriteStringASCII(errors); MessageBox.Show("Finished checking game files.\n\nWARNING: Some errors have occured!"); Process.Start(filename); } else { MessageBox.Show("Finished checking game files."); } } } else { MessageBox.Show("Game path is wrong!"); } enableGameDataMenu(true); }
public void repackME12(MeType gametype) { string errors = ""; GameData gameData = new GameData(gametype, _configIni); if (!Directory.Exists(GameData.GamePath)) { MessageBox.Show("Game path is wrong!"); return; } GetPackages(gameData); for (int i = 0; i < GameData.packageFiles.Count; i++) { updateStatusLabel("Repack PCC file " + (i + 1) + " of " + GameData.packageFiles.Count); try { Package package = new Package(GameData.packageFiles[i], true, true); if (package.compressed && package.compressionType != Package.CompressionType.Zlib) { package.Dispose(); package = new Package(GameData.packageFiles[i]); package.SaveToFile(true); } } catch { errors += "The file is propably broken, skipped: " + GameData.packageFiles[i] + Environment.NewLine; } } if (errors != "") { string filename = "pcc-errors.txt"; if (File.Exists(filename)) { File.Delete(filename); } using (FileStream fs = new FileStream(filename, FileMode.CreateNew)) { fs.WriteStringASCII(errors); } MessageBox.Show("WARNING: Some errors have occured!"); Process.Start(filename); } updateStatusLabel("Done"); updateStatusLabel2(""); }
private void updateGfxME(MeType gameId, bool softShadowsMode = false) { enableGameDataMenu(false); GameData gameData = new GameData(gameId, _configIni); string path = gameData.EngineConfigIniPath; bool exist = File.Exists(path); if (!exist) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } ConfIni engineConf = new ConfIni(path); LODSettings.updateGFXSettings(gameId, engineConf, false, false); MessageBox.Show("Game configuration file at " + path + " updated."); enableGameDataMenu(true); }
private void removeLODSettings(MeType gameId) { enableGameDataMenu(false); GameData gameData = new GameData(gameId, _configIni); string path = gameData.EngineConfigIniPath; bool exist = File.Exists(path); if (exist) { ConfIni engineConf = new ConfIni(path); LODSettings.removeLOD(gameId, engineConf); MessageBox.Show("INFO: Game configuration file at " + path + " updated."); } else { MessageBox.Show("INFO: Game configuration file at " + path + " not exist, nothing done."); } enableGameDataMenu(true); }
void checkGameFiles(MeType gameType) { enableGameDataMenu(false); GameData gameData = new GameData(gameType, _configIni); if (Directory.Exists(GameData.GamePath)) { string filename = "errors.txt"; if (File.Exists(filename)) { File.Delete(filename); } string errors = Misc.checkGameFiles(gameType, this); updateStatusLabel(""); if (errors != "") { using (FileStream fs = new FileStream(filename, FileMode.CreateNew)) { fs.WriteStringASCII("=========================================================" + Environment.NewLine); fs.WriteStringASCII("WARNING: looks like the following file(s) are not vanilla" + Environment.NewLine); fs.WriteStringASCII("=========================================================" + Environment.NewLine + Environment.NewLine); fs.WriteStringASCII(errors); } MessageBox.Show("Finished checking game files.\n\nWARNING: Some errors have occured!"); Process.Start(filename); } else { MessageBox.Show("Finished checking game files."); } } else { MessageBox.Show("Game path is wrong!"); } enableGameDataMenu(true); }
public void PrepareListOfTextures(MeType gameId, bool ipc) { treeScan = null; Misc.MD5FileEntry[] md5Entries; if (gameId == MeType.ME1_TYPE) { pkgs = Program.tablePkgsME1; md5Entries = Program.entriesME1; } else if (gameId == MeType.ME2_TYPE) { pkgs = Program.tablePkgsME2; md5Entries = Program.entriesME2; } else { pkgs = Program.tablePkgsME3; md5Entries = Program.entriesME3; } List <FoundTexture> textures = new List <FoundTexture>(); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Program.MAINEXENAME); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filename = Path.Combine(path, "me" + (int)gameId + "map.bin"); if (ipc) { Console.WriteLine("[IPC]STAGE_CONTEXT STAGE_PRESCAN"); Console.Out.Flush(); } if (!GameData.FullScanME1Game) { int count = GameData.packageFiles.Count; for (int i = 0; i < count; i++) { if (GameData.packageFiles[i].Contains("_IT.") || GameData.packageFiles[i].Contains("_FR.") || GameData.packageFiles[i].Contains("_ES.") || GameData.packageFiles[i].Contains("_DE.") || GameData.packageFiles[i].Contains("_RA.") || GameData.packageFiles[i].Contains("_RU.") || GameData.packageFiles[i].Contains("_PLPC.") || GameData.packageFiles[i].Contains("_DEU.") || GameData.packageFiles[i].Contains("_FRA.") || GameData.packageFiles[i].Contains("_ITA.") || GameData.packageFiles[i].Contains("_POL.")) { GameData.packageFiles.Add(GameData.packageFiles[i]); GameData.packageFiles.RemoveAt(i--); count--; } } } if (!generateBuiltinMapFiles && !GameData.FullScanME1Game) { List <string> addedFiles = new List <string>(); List <string> modifiedFiles = new List <string>(); loadTexturesMap(gameId, textures); List <string> sortedFiles = new List <string>(); for (int i = 0; i < GameData.packageFiles.Count; i++) { sortedFiles.Add(GameData.packageFiles[i].ToLowerInvariant()); } sortedFiles.Sort(); for (int k = 0; k < textures.Count; k++) { for (int t = 0; t < textures[k].list.Count; t++) { string pkgPath = textures[k].list[t].path.ToLowerInvariant(); if (sortedFiles.BinarySearch(pkgPath) >= 0) { continue; } MatchedTexture f = textures[k].list[t]; f.path = ""; textures[k].list[t] = f; } } if (ipc) { Console.WriteLine("[IPC]STAGE_CONTEXT STAGE_SCAN"); Console.Out.Flush(); } for (int i = 0; i < GameData.packageFiles.Count; i++) { int index = -1; bool modified = true; bool foundPkg = false; string package = GameData.packageFiles[i].ToLowerInvariant(); long packageSize = new FileInfo(GameData.GamePath + GameData.packageFiles[i]).Length; for (int p = 0; p < md5Entries.Length; p++) { if (package == md5Entries[p].path.ToLowerInvariant()) { foundPkg = true; if (packageSize == md5Entries[p].size) { modified = false; break; } index = p; } } if (foundPkg && modified) { modifiedFiles.Add(md5Entries[index].path); } else if (!foundPkg) { addedFiles.Add(GameData.packageFiles[i]); } } int lastProgress = -1; int totalPackages = modifiedFiles.Count + addedFiles.Count; int currentPackage = 0; if (ipc) { Console.WriteLine("[IPC]STAGE_WEIGHT STAGE_SCAN " + string.Format("{0:0.000000}", ((float)totalPackages / GameData.packageFiles.Count))); Console.Out.Flush(); } for (int i = 0; i < modifiedFiles.Count; i++, currentPackage++) { if (ipc) { Console.WriteLine("[IPC]PROCESSING_FILE " + modifiedFiles[i]); int newProgress = currentPackage * 100 / totalPackages; if (lastProgress != newProgress) { Console.WriteLine("[IPC]TASK_PROGRESS " + newProgress); lastProgress = newProgress; } Console.Out.Flush(); } FindTextures(gameId, textures, modifiedFiles[i], true, ipc); } for (int i = 0; i < addedFiles.Count; i++, currentPackage++) { if (ipc) { Console.WriteLine("[IPC]PROCESSING_FILE " + addedFiles[i]); int newProgress = currentPackage * 100 / totalPackages; if (lastProgress != newProgress) { Console.WriteLine("[IPC]TASK_PROGRESS " + newProgress); lastProgress = newProgress; } Console.Out.Flush(); } FindTextures(gameId, textures, addedFiles[i], false, ipc); } for (int k = 0; k < textures.Count; k++) { bool found = false; for (int t = 0; t < textures[k].list.Count; t++) { if (textures[k].list[t].path != "") { found = true; break; } } if (!found) { textures[k].list.Clear(); textures.Remove(textures[k]); k--; } } } else { int lastProgress = -1; for (int i = 0; i < GameData.packageFiles.Count; i++) { if (ipc) { Console.WriteLine("[IPC]PROCESSING_FILE " + GameData.packageFiles[i]); int newProgress = i * 100 / GameData.packageFiles.Count; if (lastProgress != newProgress) { Console.WriteLine("[IPC]TASK_PROGRESS " + newProgress); lastProgress = newProgress; } Console.Out.Flush(); } FindTextures(gameId, textures, GameData.packageFiles[i], false, ipc); } } if (gameId == MeType.ME1_TYPE) { for (int k = 0; k < textures.Count; k++) { for (int t = 0; t < textures[k].list.Count; t++) { uint mipmapOffset = textures[k].list[t].mipmapOffset; if (textures[k].list[t].slave) { MatchedTexture slaveTexture = textures[k].list[t]; string basePkgName = slaveTexture.basePackageName; if (basePkgName == Path.GetFileNameWithoutExtension(slaveTexture.path).ToUpperInvariant()) { throw new Exception(); } for (int j = 0; j < textures[k].list.Count; j++) { if (!textures[k].list[j].slave && textures[k].list[j].mipmapOffset == mipmapOffset && textures[k].list[j].packageName == basePkgName) { slaveTexture.linkToMaster = j; textures[k].list[t] = slaveTexture; break; } } } } bool foundSlave = false; for (int s = 0; s < textures[k].list.Count; s++) { if (textures[k].list[s].slave) { foundSlave = true; break; } } bool foundWeakSlave = false; if (!foundSlave) { for (int w = 0; w < textures[k].list.Count; w++) { if (textures[k].list[w].weakSlave) { foundWeakSlave = true; break; } } } if (foundWeakSlave) { List <MatchedTexture> texList = new List <MatchedTexture>(); for (int t = 0; t < textures[k].list.Count; t++) { MatchedTexture tex = textures[k].list[t]; if (tex.weakSlave) { texList.Add(tex); } else { texList.Insert(0, tex); } } FoundTexture f = textures[k]; f.list = texList; textures[k] = f; if (textures[k].list[0].weakSlave) { continue; } for (int t = 0; t < textures[k].list.Count; t++) { if (textures[k].list[t].weakSlave) { MatchedTexture slaveTexture = textures[k].list[t]; string basePkgName = slaveTexture.basePackageName; if (basePkgName == Path.GetFileNameWithoutExtension(slaveTexture.path).ToUpperInvariant()) { throw new Exception(); } for (int j = 0; j < textures[k].list.Count; j++) { if (!textures[k].list[j].weakSlave && textures[k].list[j].packageName == basePkgName) { slaveTexture.linkToMaster = j; slaveTexture.slave = true; textures[k].list[t] = slaveTexture; break; } } } } } } } if (!GameData.FullScanME1Game) { GameData.packageFiles.Sort(new AsciiStringComparer()); } if (File.Exists(filename)) { File.Delete(filename); } using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write)) { MemoryStream mem = new MemoryStream(); mem.WriteUInt32(textureMapBinTag); mem.WriteUInt32(textureMapBinVersion); mem.WriteInt32(textures.Count); for (int i = 0; i < textures.Count; i++) { if (generateBuiltinMapFiles) { mem.WriteByte((byte)textures[i].name.Length); } else { mem.WriteInt32(textures[i].name.Length); } mem.WriteStringASCII(textures[i].name); mem.WriteUInt32(textures[i].crc); if (generateBuiltinMapFiles) { mem.WriteInt16((short)textures[i].width); mem.WriteInt16((short)textures[i].height); mem.WriteByte((byte)textures[i].pixfmt); mem.WriteByte((byte)textures[i].flags); mem.WriteInt16((short)textures[i].list.Count); } else { mem.WriteInt32(textures[i].list.Count); } for (int k = 0; k < textures[i].list.Count; k++) { mem.WriteInt32(textures[i].list[k].exportID); if (generateBuiltinMapFiles) { if (GameData.gameType == MeType.ME1_TYPE) { mem.WriteInt16((short)textures[i].list[k].linkToMaster); if (textures[i].list[k].linkToMaster != -1) { mem.WriteStringASCIINull(textures[i].list[k].basePackageName); } } mem.WriteByte(textures[i].list[k].removeEmptyMips ? (byte)1 : (byte)0); mem.WriteByte((byte)textures[i].list[k].numMips); mem.WriteInt16((short)pkgs.IndexOf(textures[i].list[k].path)); } else { mem.WriteInt32(textures[i].list[k].linkToMaster); mem.WriteInt32(textures[i].list[k].path.Length); mem.WriteStringASCII(textures[i].list[k].path); } } } if (!generateBuiltinMapFiles) { mem.WriteInt32(GameData.packageFiles.Count); for (int i = 0; i < GameData.packageFiles.Count; i++) { mem.WriteInt32(GameData.packageFiles[i].Length); mem.WriteStringASCII(GameData.packageFiles[i]); } } mem.SeekBegin(); if (generateBuiltinMapFiles) { fs.WriteUInt32(0x504D5443); fs.WriteUInt32((uint)mem.Length); byte[] compressed = new ZlibHelper.Zlib().Compress(mem.ToArray(), 9); fs.WriteUInt32((uint)compressed.Length); fs.WriteFromBuffer(compressed); } else { fs.WriteFromStream(mem, mem.Length); } } treeScan = textures; }
public void repackME23(MeType gameId) { string errors = ""; GameData gameData = new GameData(gameId, _configIni); if (!Directory.Exists(GameData.GamePath)) { MessageBox.Show("Game path is wrong!"); return; } GetPackages(gameData); string path = ""; if (gameId == MeType.ME2_TYPE) { path = @"\BioGame\CookedPC\BIOC_Materials.pcc".ToLowerInvariant(); } for (int i = 0; i < GameData.packageFiles.Count; i++) { if (path != "" && GameData.packageFiles[i].ToLowerInvariant().Contains(path)) { continue; } updateStatusLabel("Repack PCC file " + (i + 1) + " of " + GameData.packageFiles.Count); try { Package package = new Package(GameData.packageFiles[i], true); if (!package.compressed || package.compressed && package.compressionType != Package.CompressionType.Zlib) { package.Dispose(); package = new Package(GameData.packageFiles[i]); package.SaveToFile(true, false, false); } package.Dispose(); } catch (Exception e) { if (e.Message.Contains("Problem with PCC file header:")) { continue; } errors += "The file is propably broken, skipped: " + GameData.packageFiles[i] + Environment.NewLine; } } TOCBinFile.UpdateAllTOCBinFiles(); if (errors != "") { string filename = "pcc-errors.txt"; if (File.Exists(filename)) { File.Delete(filename); } using (FileStream fs = new FileStream(filename, FileMode.CreateNew)) { fs.WriteStringASCII(errors); } MessageBox.Show("WARNING: Some errors have occured!"); Process.Start(filename); } updateStatusLabel("Done"); updateStatusLabel2(""); }
void toolStripCreateBinaryMod(MeType gameType) { enableGameDataMenu(false); GameData gameData = new GameData(gameType, _configIni); if (!Directory.Exists(GameData.GamePath)) { MessageBox.Show("Game path is wrong!"); enableGameDataMenu(true); return; } updateStatusLabel("Finding packages in game setup..."); gameData.getPackages(); updateStatusLabel(""); using (FolderBrowserDialog modDir = new FolderBrowserDialog()) { modDir.Description = "Please select source directory of modded package files"; if (modDir.ShowDialog() != DialogResult.OK) { updateStatusLabel(""); enableGameDataMenu(true); return; } List <string> exe = Directory.GetFiles(modDir.SelectedPath, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)).ToList(); if (exe.Count != 0) { MessageBox.Show("The source directory doesn't seems right, aborting..."); updateStatusLabel(""); enableGameDataMenu(true); return; } List <string> mods = Directory.GetFiles(modDir.SelectedPath, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".upk", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".u", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".pcc", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".sfm", StringComparison.OrdinalIgnoreCase)).ToList(); for (int i = 0; i < mods.Count; i++) { try { using (FileStream fs = new FileStream(mods[i], FileMode.Open, FileAccess.Read)) { fs.SeekEnd(); fs.Seek(-Package.MEMendFileMarker.Length, SeekOrigin.Current); string marker = fs.ReadStringASCII(Package.MEMendFileMarker.Length); if (marker == Package.MEMendFileMarker) { MessageBox.Show("Mod files must be based on vanilla game data, aborting..."); updateStatusLabel(""); enableGameDataMenu(true); return; } } } catch { } } updateStatusLabel("Scanning mods..."); List <string> files = Directory.GetFiles(modDir.SelectedPath, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".upk", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".u", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".pcc", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".sfm", StringComparison.OrdinalIgnoreCase)).ToList(); List <BinaryMod> modFiles = new List <BinaryMod>(); for (int i = 0; i < mods.Count; i++) { Package vanillaPkg = null; Package modPkg = null; bool found = false; try { for (int v = 0; v < GameData.packageFiles.Count; v++) { if (Path.GetFileName(mods[i]).ToLowerInvariant() == Path.GetFileName(GameData.packageFiles[v]).ToLowerInvariant()) { modPkg = new Package(mods[i]); vanillaPkg = new Package(GameData.packageFiles[v]); if (modPkg.exportsTable.Count != vanillaPkg.exportsTable.Count || modPkg.namesTable.Count != vanillaPkg.namesTable.Count || modPkg.importsTable.Count != vanillaPkg.importsTable.Count) { found = true; vanillaPkg.Dispose(); vanillaPkg = null; continue; } found = true; break; } } if (found && vanillaPkg == null) { modPkg.Dispose(); MessageBox.Show("Package file not compatible: " + mods[i] + ", aborting..."); updateStatusLabel(""); enableGameDataMenu(true); return; } } catch { MessageBox.Show("Problem opening file: " + mods[i] + ", aborting..."); updateStatusLabel(""); enableGameDataMenu(true); return; } if (!found) { MessageBox.Show("Package not present in vanilla game data: " + mods[i] + ", aborting..."); updateStatusLabel(""); enableGameDataMenu(true); return; } for (int e = 0; e < modPkg.exportsTable.Count; e++) { byte[] vanillaExport = vanillaPkg.getExportData(e); byte[] modExport = modPkg.getExportData(e); if (vanillaExport.Length == modExport.Length) { if (StructuralComparisons.StructuralEqualityComparer.Equals(vanillaExport, modExport)) { continue; } } BinaryMod mod = new BinaryMod(); mod.packagePath = GameData.RelativeGameData(vanillaPkg.packagePath); mod.exportId = e; if (vanillaExport.Length == modExport.Length) { mod.data = new Xdelta3Helper.Xdelta3().Compress(vanillaExport, modExport); mod.binaryModType = 2; } else { mod.data = new byte[modExport.Length]; Array.Copy(modExport, mod.data, modExport.Length); mod.binaryModType = 1; } string name; if (mod.packagePath.Contains("\\DLC\\")) { string dlcName = mod.packagePath.Split('\\')[3]; name = "D" + dlcName.Length + "-" + dlcName + "-"; } else { name = "B"; } name += Path.GetFileName(mod.packagePath).Length + "-" + Path.GetFileName(mod.packagePath) + "-E" + mod.exportId; if (mod.binaryModType == 1) { name += ".bin"; } else if (mod.binaryModType == 2) { name += ".xdelta"; } mod.textureName = name; modFiles.Add(mod); } vanillaPkg.Dispose(); modPkg.Dispose(); } if (modFiles.Count == 0) { MessageBox.Show("Nothing to mod, exiting..."); updateStatusLabel(""); enableGameDataMenu(true); return; } updateStatusLabel("Creating mem..."); using (SaveFileDialog modFile = new SaveFileDialog()) { modFile.Title = "Please selecct new MEM mod file"; modFile.Filter = "MEM mod file | *.mem"; if (modFile.ShowDialog() != DialogResult.OK) { updateStatusLabel(""); enableGameDataMenu(true); return; } if (File.Exists(modFile.FileName)) { File.Delete(modFile.FileName); } using (FileStream outFs = new FileStream(modFile.FileName, FileMode.CreateNew, FileAccess.Write)) { outFs.WriteUInt32(TreeScan.TextureModTag); outFs.WriteUInt32(TreeScan.TextureModVersion); outFs.WriteInt64(0); // filled later for (int i = 0; i < modFiles.Count; i++) { Stream dst = MipMaps.compressData(modFiles[i].data); dst.SeekBegin(); BinaryMod bmod = modFiles[i]; bmod.offset = outFs.Position; bmod.size = dst.Length; modFiles[i] = bmod; outFs.WriteInt32(modFiles[i].exportId); outFs.WriteStringASCIINull(modFiles[i].packagePath); outFs.WriteFromStream(dst, dst.Length); } long pos = outFs.Position; outFs.SeekBegin(); outFs.WriteUInt32(TreeScan.TextureModTag); outFs.WriteUInt32(TreeScan.TextureModVersion); outFs.WriteInt64(pos); outFs.JumpTo(pos); outFs.WriteUInt32((uint)gameType); outFs.WriteInt32(modFiles.Count); for (int i = 0; i < modFiles.Count; i++) { if (modFiles[i].binaryModType == 1) { outFs.WriteUInt32(MipMaps.FileBinaryTag); } else if (modFiles[i].binaryModType == 2) { outFs.WriteUInt32(MipMaps.FileXdeltaTag); } outFs.WriteStringASCIINull(modFiles[i].textureName); outFs.WriteInt64(modFiles[i].offset); outFs.WriteInt64(modFiles[i].size); } } } } updateStatusLabel("Finished"); enableGameDataMenu(true); }
static void Main(string[] args) { string cmd = ""; string game; string input = ""; string output = ""; MeType gameId = 0; bool ipc = false; if (args.Length > 0) cmd = args[0]; Console.WriteLine(Environment.NewLine + Environment.NewLine + "--- MEM no GUI v" + Application.ProductVersion + " command line --- " + Environment.NewLine); for (int i = 0; i < args.Length; i++) Console.Write(args[i] + " "); Console.WriteLine(Environment.NewLine); if (cmd.Equals("-help", StringComparison.OrdinalIgnoreCase)) { DisplayHelp(); Environment.Exit(0); } if (cmd.Equals("-version", StringComparison.OrdinalIgnoreCase)) { Environment.Exit(0); } if (cmd.Equals("-convert-to-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-convert-game-image", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-convert-game-images", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-install-mods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mod", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-detect-mods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-detect-bad-mods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-apply-lods-gfx", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-remove-lods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-print-lods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-game-data-textures", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-game-data-mismatch", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-game-data-after", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-game-data-only-vanilla", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-for-markers", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-dlc-mod-for-mgamerz", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-all-dds", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-all-png", StringComparison.OrdinalIgnoreCase)) { if (args.Length < 1) { Console.WriteLine("Error: wrong game id!"); DisplayHelp(); goto fail; } game = args[1]; try { gameId = (MeType)int.Parse(game); } catch { gameId = 0; } if (gameId != MeType.ME1_TYPE && gameId != MeType.ME2_TYPE && gameId != MeType.ME3_TYPE) { Console.WriteLine("Error: wrong game id!"); DisplayHelp(); goto fail; } } if (cmd.Equals("-convert-to-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-install-mods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-convert-game-image", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-convert-game-images", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mod", StringComparison.OrdinalIgnoreCase)) { if (args.Length < 3) { Console.WriteLine("Error: missing input argument!"); DisplayHelp(); goto fail; } input = args[2]; if (!Directory.Exists(input) && !File.Exists(input)) { Console.WriteLine("Error: input file/directory doesnt exists: " + input); goto fail; } } if (cmd.Equals("-convert-to-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-convert-game-image", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-convert-game-images", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mod", StringComparison.OrdinalIgnoreCase)) { if (args.Length < 4) { Console.WriteLine("Error: missing output argument!"); DisplayHelp(); goto fail; } output = args[3]; } if (cmd.Equals("-convert-to-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-install-mods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mod", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-mem", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-detect-bad-mods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-detect-mods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-print-lods", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-game-data-textures", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-game-data-mismatch", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-game-data-after", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-game-data-only-vanilla", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-check-for-markers", StringComparison.OrdinalIgnoreCase)) { for (int l = 0; l < args.Length; l++) { if (args[l].ToLowerInvariant() == "-ipc") ipc = true; } } if (cmd.Equals("-convert-to-mem", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); loadMD5Tables(); bool markToConvert = false; for (int l = 0; l < args.Length; l++) { if (args[l].ToLowerInvariant() == "-mark-to-convert") markToConvert = true; } if (!CmdLineTools.ConvertToMEM(gameId, input, output, markToConvert, ipc)) goto fail; } else if (cmd.Equals("-install-mods", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); loadMD5Tables(); bool guiInstaller = false; bool repack = false; bool limit2k = false; for (int l = 0; l < args.Length; l++) { if (args[l].ToLowerInvariant() == "-alot-mode") guiInstaller = true; if (args[l].ToLowerInvariant() == "-repack") repack = true; if (args[l].ToLowerInvariant() == "-limit2k") limit2k = true; } if (!CmdLineTools.InstallMods(gameId, input, ipc, repack, guiInstaller, limit2k)) goto fail; } else if (cmd.Equals("-apply-me1-laa", StringComparison.OrdinalIgnoreCase)) { if (!CmdLineTools.ApplyME1LAAPatch()) goto fail; } else if (cmd.Equals("-detect-mods", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); if (!CmdLineTools.DetectMods(gameId, ipc)) goto fail; } else if (cmd.Equals("-detect-bad-mods", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); if (!CmdLineTools.DetectBadMods(gameId, ipc)) goto fail; } else if (cmd.Equals("-apply-lods-gfx", StringComparison.OrdinalIgnoreCase)) { bool softShadowsME1 = false; bool meuitmMode = false; bool limit2k = false; for (int l = 0; l < args.Length; l++) { if (args[l].ToLowerInvariant() == "-soft-shadows-mode") softShadowsME1 = true; if (args[l].ToLowerInvariant() == "-meuitm-mode") meuitmMode = true; if (args[l].ToLowerInvariant() == "-limit2k") limit2k = true; } if (!CmdLineTools.ApplyLODAndGfxSettings(gameId, softShadowsME1, meuitmMode, limit2k)) goto fail; } else if (cmd.Equals("-remove-lods", StringComparison.OrdinalIgnoreCase)) { if (!CmdLineTools.RemoveLODSettings(gameId)) goto fail; } else if (cmd.Equals("-print-lods", StringComparison.OrdinalIgnoreCase)) { if (!CmdLineTools.PrintLODSettings(gameId, ipc)) goto fail; } else if (cmd.Equals("-check-game-data-textures", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); if (!CmdLineTools.CheckTextures(gameId, ipc)) goto fail; } else if (cmd.Equals("-check-game-data-mismatch", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); if (!CmdLineTools.detectsMismatchPackagesAfter(gameId, ipc)) goto fail; } else if (cmd.Equals("-check-game-data-after", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); if (!CmdLineTools.checkGameFilesAfter(gameId, ipc)) goto fail; } else if (cmd.Equals("-check-game-data-only-vanilla", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); loadMD5Tables(); if (!CmdLineTools.CheckGameData(gameId, ipc)) goto fail; } else if (cmd.Equals("-check-for-markers", StringComparison.OrdinalIgnoreCase)) { if (!CmdLineTools.CheckForMarkers(gameId, ipc)) goto fail; } else if (cmd.Equals("-convert-game-image", StringComparison.OrdinalIgnoreCase)) { if (Path.GetExtension(output).ToLowerInvariant() != ".dds") { Console.WriteLine("Error: output file is not dds: " + output); goto fail; } loadEmbeddedDlls(); loadMD5Tables(); bool markToConvert = false; for (int l = 0; l < args.Length; l++) { if (args[l].ToLowerInvariant() == "-mark-to-convert") markToConvert = true; } if (!CmdLineTools.convertGameImage(gameId, input, output, markToConvert)) goto fail; } else if (cmd.Equals("-convert-game-images", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); loadMD5Tables(); bool markToConvert = false; for (int l = 0; l < args.Length; l++) { if (args[l].ToLowerInvariant() == "-mark-to-convert") markToConvert = true; } if (!CmdLineTools.convertGameImages(gameId, input, output, markToConvert)) goto fail; } else if (cmd.Equals("-extract-tpf", StringComparison.OrdinalIgnoreCase)) { if (args.Length != 3) { Console.WriteLine("Error: wrong arguments!"); DisplayHelp(); goto fail; } input = args[1]; output = args[2]; if (!Directory.Exists(input)) { Console.WriteLine("Error: input dir not exists: " + input); goto fail; } else { loadEmbeddedDlls(); if (!CmdLineTools.extractTPF(input, output, ipc)) goto fail; } } else if (cmd.Equals("-extract-mod", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); loadMD5Tables(); if (!CmdLineTools.extractMOD(gameId, input, output, ipc)) goto fail; } else if (cmd.Equals("-extract-mem", StringComparison.OrdinalIgnoreCase)) { loadEmbeddedDlls(); loadMD5Tables(); if (!CmdLineTools.extractMEM(gameId, input, output, ipc)) goto fail; } else if (cmd.Equals("-convert-image", StringComparison.OrdinalIgnoreCase)) { if (args.Length < 4) { Console.WriteLine("Error: wrong arguments!"); DisplayHelp(); goto fail; } string format = args[1]; string threshold = "128"; if (format == "dxt1a") { if (args.Length == 5) { threshold = args[2]; input = args[3]; output = args[4]; } else { input = args[2]; output = args[3]; } } else { input = args[2]; output = args[3]; } if (!File.Exists(input)) { Console.WriteLine("Error: input file not exists: " + input); goto fail; } else { if (Path.GetExtension(output).ToLowerInvariant() != ".dds") { Console.WriteLine("Error: output file is not dds: " + output); goto fail; } loadEmbeddedDlls(); loadMD5Tables(); if (!CmdLineTools.convertImage(input, output, format, threshold)) goto fail; } } else if (cmd.Equals("-extract-all-dds", StringComparison.OrdinalIgnoreCase) || cmd.Equals("-extract-all-png", StringComparison.OrdinalIgnoreCase)) { if (args.Length != 3 && args.Length != 4 && args.Length != 5) { Console.WriteLine("Error: wrong arguments!"); DisplayHelp(); goto fail; } output = args[2]; string tfcFilter = ""; if (args.Length > 3) tfcFilter = args[3]; bool pccOnly = tfcFilter == "-pcc-only"; bool tfcOnly = tfcFilter == "-tfc-only"; loadEmbeddedDlls(); loadMD5Tables(); if (cmd.Equals("-extract-all-dds", StringComparison.OrdinalIgnoreCase)) if (!CmdLineTools.extractAllTextures(gameId, output, false, pccOnly, tfcOnly, tfcFilter)) goto fail; if (cmd.Equals("-extract-all-png", StringComparison.OrdinalIgnoreCase)) if (!CmdLineTools.extractAllTextures(gameId, output, true, pccOnly, tfcOnly, tfcFilter)) goto fail; } else if (cmd.Equals("-dlc-mod-for-mgamerz", StringComparison.OrdinalIgnoreCase)) { if (gameId == MeType.ME1_TYPE) { Console.WriteLine("Error: wrong game id, supported only ME2 and ME3!"); DisplayHelp(); goto fail; } if (args.Length < 4) { Console.WriteLine("Error: wrong arguments!"); DisplayHelp(); goto fail; } input = args[2]; string tfcName = args[3]; bool verify = false; for (int l = 0; l < args.Length; l++) { if (args[l].ToLowerInvariant() == "-verify") verify = true; } byte[] guid; if ((args.Length == 5 && !verify) || (args.Length == 6 && verify)) { if (args[4].Length != 32) { Console.WriteLine("Error: wrong guid!"); DisplayHelp(); goto fail; } guid = new byte[16]; for (int i = 0; i < 32; i += 2) guid[i / 2] = Convert.ToByte(args[4].Substring(i, 2), 16); } else guid = Guid.NewGuid().ToByteArray(); loadEmbeddedDlls(); loadMD5Tables(); if (!CmdLineTools.applyModsSpecial(gameId, input, verify, tfcName, guid)) goto fail; } else DisplayHelp(); unloadEmbeddedDlls(); Environment.Exit(0); fail: unloadEmbeddedDlls(); Environment.Exit(1); }
public string PrepareListOfTextures(MeType gameId, TexExplorer texEplorer, MainWindow mainWindow, Installer installer, ref string log, bool ipc) { string errors = ""; treeScan = null; Misc.MD5FileEntry[] md5Entries; if (gameId == MeType.ME1_TYPE) { pkgs = Program.tablePkgsME1; md5Entries = Program.entriesME1; } else if (gameId == MeType.ME2_TYPE) { pkgs = Program.tablePkgsME2; md5Entries = Program.entriesME2; } else { pkgs = Program.tablePkgsME3; md5Entries = Program.entriesME3; } List <FoundTexture> textures = new List <FoundTexture>(); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Assembly.GetExecutingAssembly().GetName().Name); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filename = Path.Combine(path, "me" + (int)gameId + "map.bin"); if (mainWindow != null) { if (File.Exists(filename)) { using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite)) { uint tag = fs.ReadUInt32(); uint version = fs.ReadUInt32(); if (tag != textureMapBinTag || version != textureMapBinVersion) { MessageBox.Show("Detected wrong or old version of textures scan file!" + "\n\nYou need to restore the game to vanilla state then reinstall optional DLC/PCC mods." + "\n\nThen from the main menu, select 'Remove Textures Scan File' and start Texture Manager again."); mainWindow.updateStatusLabel(""); mainWindow.updateStatusLabel2(""); texEplorer.Close(); fs.Close(); log += "Detected wrong or old version of textures scan file!" + Environment.NewLine; log += "You need to restore the game to vanilla state then reinstall optional DLC/PCC mods." + Environment.NewLine; log += "Then from the main menu, select 'Remove Textures Scan File' and start Texture Manager again." + Environment.NewLine; return("Detected wrong or old version of textures scan file!" + Environment.NewLine + "You need to restore the game to vanilla state then reinstall optional DLC/PCC mods." + Environment.NewLine + "Then from the main menu, select 'Remove Textures Scan File' and start Texture Manager again." + Environment.NewLine); } uint countTexture = fs.ReadUInt32(); for (int i = 0; i < countTexture; i++) { FoundTexture texture = new FoundTexture(); int len = fs.ReadInt32(); texture.name = fs.ReadStringASCII(len); texture.crc = fs.ReadUInt32(); uint countPackages = fs.ReadUInt32(); texture.list = new List <MatchedTexture>(); for (int k = 0; k < countPackages; k++) { MatchedTexture matched = new MatchedTexture(); matched.exportID = fs.ReadInt32(); matched.linkToMaster = fs.ReadInt32(); len = fs.ReadInt32(); matched.path = fs.ReadStringASCII(len); texture.list.Add(matched); } textures.Add(texture); } List <string> packages = new List <string>(); int numPackages = fs.ReadInt32(); for (int i = 0; i < numPackages; i++) { int len = fs.ReadInt32(); string pkgPath = fs.ReadStringASCII(len); pkgPath = GameData.GamePath + pkgPath; packages.Add(pkgPath); } for (int i = 0; i < packages.Count; i++) { if (GameData.packageFiles.Find(s => s.Equals(packages[i], StringComparison.OrdinalIgnoreCase)) == null) { MessageBox.Show("Detected removal of game files since last game data scan." + "\n\nYou need to restore the game to vanilla state then reinstall optional DLC/PCC mods." + "\n\nThen from the main menu, select 'Remove Textures Scan File' and start Texture Manager again."); return(""); } } for (int i = 0; i < GameData.packageFiles.Count; i++) { if (packages.Find(s => s.Equals(GameData.packageFiles[i], StringComparison.OrdinalIgnoreCase)) == null) { MessageBox.Show("Detected additional game files not present in latest game data scan." + "\n\nYou need to restore the game to vanilla state then reinstall optional DLC/PCC mods." + "\n\nThen from the main menu, select 'Remove Textures Scan File' and start Texture Manager again."); return(""); } } treeScan = textures; mainWindow.updateStatusLabel(""); mainWindow.updateStatusLabel2(""); } if (!texEplorer.verifyGameDataEmptyMipMapsRemoval()) { MessageBox.Show("Detected empty mips in game files." + "\n\nYou need the game in vanilla state and optional DLC/PCC mods." + "\n\nThen from the main menu, select 'Remove Textures Scan File' and start Texture Manager again."); return(""); } return(errors); } if (mainWindow != null) { List <string> badMods = Misc.detectBrokenMod(GameData.gameType); if (badMods.Count != 0) { errors = ""; for (int l = 0; l < badMods.Count; l++) { errors += badMods[l] + Environment.NewLine; } MessageBox.Show("Detected not compatible mods: \n\n" + errors); return(""); } List <string> mods = Misc.detectMods(GameData.gameType); if (mods.Count != 0 && GameData.gameType == MeType.ME1_TYPE && GameData.FullScanME1Game) { errors = ""; for (int l = 0; l < mods.Count; l++) { errors += mods[l] + Environment.NewLine; } DialogResult resp = MessageBox.Show("Detected NOT compatible/supported mods with this version of game: \n\n" + errors + "\n\nPress Cancel to abort or press Ok button to continue.", "Warning !", MessageBoxButtons.OKCancel); if (resp == DialogResult.Cancel) { return(""); } } } DialogResult result = MessageBox.Show("Replacing textures and creating mods requires generating a map of the game's textures.\n" + "You only need to do it once.\n\n" + "IMPORTANT! Your game needs to be in vanilla state and have optional DLC/PCC mods installed.\n\n" + "Are you sure you want to proceed?", "Textures mapping", MessageBoxButtons.YesNo); if (result == DialogResult.No) { texEplorer.Close(); return(""); } Misc.startTimer(); } if (!GameData.FullScanME1Game) { int count = GameData.packageFiles.Count; for (int i = 0; i < count; i++) { if (GameData.packageFiles[i].Contains("_IT.") || GameData.packageFiles[i].Contains("_FR.") || GameData.packageFiles[i].Contains("_ES.") || GameData.packageFiles[i].Contains("_DE.") || GameData.packageFiles[i].Contains("_RA.") || GameData.packageFiles[i].Contains("_RU.") || GameData.packageFiles[i].Contains("_PLPC.") || GameData.packageFiles[i].Contains("_DEU.") || GameData.packageFiles[i].Contains("_FRA.") || GameData.packageFiles[i].Contains("_ITA.") || GameData.packageFiles[i].Contains("_POL.")) { GameData.packageFiles.Add(GameData.packageFiles[i]); GameData.packageFiles.RemoveAt(i--); count--; } } } if (!generateBuiltinMapFiles && !GameData.FullScanME1Game) { List <string> addedFiles = new List <string>(); List <string> modifiedFiles = new List <string>(); loadTexturesMap(gameId, textures); List <string> sortedFiles = new List <string>(); for (int i = 0; i < GameData.packageFiles.Count; i++) { sortedFiles.Add(GameData.RelativeGameData(GameData.packageFiles[i]).ToLowerInvariant()); } sortedFiles.Sort(); for (int k = 0; k < textures.Count; k++) { for (int t = 0; t < textures[k].list.Count; t++) { string pkgPath = textures[k].list[t].path.ToLowerInvariant(); if (sortedFiles.BinarySearch(pkgPath) >= 0) { continue; } MatchedTexture f = textures[k].list[t]; f.path = ""; textures[k].list[t] = f; } } if (installer != null) { installer.updateProgressStatus("Scanning packages"); } if (mainWindow != null) { mainWindow.updateStatusLabel("Scanning packages..."); } if (ipc) { Console.WriteLine("[IPC]STAGE_CONTEXT STAGE_SCAN"); Console.Out.Flush(); } for (int i = 0; i < GameData.packageFiles.Count; i++) { int index = -1; bool modified = true; bool foundPkg = false; string package = GameData.RelativeGameData(GameData.packageFiles[i].ToLowerInvariant()); long packageSize = new FileInfo(GameData.packageFiles[i]).Length; for (int p = 0; p < md5Entries.Length; p++) { if (package == md5Entries[p].path.ToLowerInvariant()) { foundPkg = true; if (packageSize == md5Entries[p].size) { modified = false; break; } index = p; } } if (foundPkg && modified) { modifiedFiles.Add(md5Entries[index].path); } else if (!foundPkg) { addedFiles.Add(GameData.RelativeGameData(GameData.packageFiles[i])); } } int lastProgress = -1; int totalPackages = modifiedFiles.Count + addedFiles.Count; int currentPackage = 0; if (ipc) { Console.WriteLine("[IPC]STAGE_WEIGHT STAGE_SCAN " + string.Format("{0:0.000000}", ((float)totalPackages / GameData.packageFiles.Count))); Console.Out.Flush(); } for (int i = 0; i < modifiedFiles.Count; i++, currentPackage++) { if (installer != null) { installer.updateProgressStatus("Scanning textures " + ((currentPackage + 1) * 100) / totalPackages + "% "); } if (mainWindow != null) { mainWindow.updateStatusLabel("Finding textures in package " + (currentPackage + 1) + " of " + totalPackages + " - " + modifiedFiles[i]); } if (ipc) { Console.WriteLine("[IPC]PROCESSING_FILE " + modifiedFiles[i]); int newProgress = currentPackage * 100 / totalPackages; if (lastProgress != newProgress) { Console.WriteLine("[IPC]TASK_PROGRESS " + newProgress); lastProgress = newProgress; } Console.Out.Flush(); } errors += FindTextures(gameId, textures, modifiedFiles[i], true, ref log); } for (int i = 0; i < addedFiles.Count; i++, currentPackage++) { if (installer != null) { installer.updateProgressStatus("Scanning textures " + ((currentPackage + 1) * 100) / totalPackages + "% "); } if (mainWindow != null) { mainWindow.updateStatusLabel("Finding textures in package " + (currentPackage + 1) + " of " + totalPackages + " - " + addedFiles[i]); } if (ipc) { Console.WriteLine("[IPC]PROCESSING_FILE " + addedFiles[i]); int newProgress = currentPackage * 100 / totalPackages; if (lastProgress != newProgress) { Console.WriteLine("[IPC]TASK_PROGRESS " + newProgress); lastProgress = newProgress; } Console.Out.Flush(); } errors += FindTextures(gameId, textures, addedFiles[i], false, ref log); } for (int k = 0; k < textures.Count; k++) { bool found = false; for (int t = 0; t < textures[k].list.Count; t++) { if (textures[k].list[t].path != "") { found = true; break; } } if (!found) { textures[k].list.Clear(); textures.Remove(textures[k]); k--; } } } else { int lastProgress = -1; for (int i = 0; i < GameData.packageFiles.Count; i++) { if (installer != null) { installer.updateProgressStatus("Scanning textures " + ((i + 1) * 100) / GameData.packageFiles.Count + "% "); } if (mainWindow != null) { mainWindow.updateStatusLabel("Finding textures in package " + (i + 1) + " of " + GameData.packageFiles.Count + " - " + GameData.packageFiles[i]); } if (ipc) { Console.WriteLine("[IPC]PROCESSING_FILE " + GameData.packageFiles[i]); int newProgress = i * 100 / GameData.packageFiles.Count; if (lastProgress != newProgress) { Console.WriteLine("[IPC]TASK_PROGRESS " + newProgress); lastProgress = newProgress; } Console.Out.Flush(); } FindTextures(gameId, textures, GameData.RelativeGameData(GameData.packageFiles[i]), false, ref log); } } if (gameId == MeType.ME1_TYPE) { for (int k = 0; k < textures.Count; k++) { for (int t = 0; t < textures[k].list.Count; t++) { uint mipmapOffset = textures[k].list[t].mipmapOffset; if (textures[k].list[t].slave) { MatchedTexture slaveTexture = textures[k].list[t]; string basePkgName = slaveTexture.basePackageName; if (basePkgName == Path.GetFileNameWithoutExtension(slaveTexture.path).ToUpperInvariant()) { throw new Exception(); } for (int j = 0; j < textures[k].list.Count; j++) { if (!textures[k].list[j].slave && textures[k].list[j].mipmapOffset == mipmapOffset && textures[k].list[j].packageName == basePkgName) { slaveTexture.linkToMaster = j; slaveTexture.slave = true; textures[k].list[t] = slaveTexture; break; } } } } if (!textures[k].list.Exists(s => s.slave) && textures[k].list.Exists(s => s.weakSlave)) { List <MatchedTexture> texList = new List <MatchedTexture>(); for (int t = 0; t < textures[k].list.Count; t++) { MatchedTexture tex = textures[k].list[t]; if (tex.weakSlave) { texList.Add(tex); } else { texList.Insert(0, tex); } } FoundTexture f = textures[k]; f.list = texList; textures[k] = f; if (textures[k].list[0].weakSlave) { continue; } for (int t = 0; t < textures[k].list.Count; t++) { if (textures[k].list[t].weakSlave) { MatchedTexture slaveTexture = textures[k].list[t]; string basePkgName = slaveTexture.basePackageName; if (basePkgName == Path.GetFileNameWithoutExtension(slaveTexture.path).ToUpperInvariant()) { throw new Exception(); } for (int j = 0; j < textures[k].list.Count; j++) { if (!textures[k].list[j].weakSlave && textures[k].list[j].packageName == basePkgName) { slaveTexture.linkToMaster = j; slaveTexture.slave = true; textures[k].list[t] = slaveTexture; break; } } } } } } } if (File.Exists(filename)) { File.Delete(filename); } using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write)) { MemoryStream mem = new MemoryStream(); mem.WriteUInt32(textureMapBinTag); mem.WriteUInt32(textureMapBinVersion); mem.WriteInt32(textures.Count); for (int i = 0; i < textures.Count; i++) { if (generateBuiltinMapFiles) { mem.WriteByte((byte)textures[i].name.Length); } else { mem.WriteInt32(textures[i].name.Length); } mem.WriteStringASCII(textures[i].name); mem.WriteUInt32(textures[i].crc); if (generateBuiltinMapFiles) { mem.WriteInt16((short)textures[i].width); mem.WriteInt16((short)textures[i].height); mem.WriteByte((byte)textures[i].pixfmt); mem.WriteByte((byte)textures[i].flags); mem.WriteInt16((short)textures[i].list.Count); } else { mem.WriteInt32(textures[i].list.Count); } for (int k = 0; k < textures[i].list.Count; k++) { mem.WriteInt32(textures[i].list[k].exportID); if (generateBuiltinMapFiles) { if (GameData.gameType == MeType.ME1_TYPE) { mem.WriteInt16((short)textures[i].list[k].linkToMaster); if (textures[i].list[k].linkToMaster != -1) { mem.WriteStringASCIINull(textures[i].list[k].basePackageName); } } mem.WriteByte(textures[i].list[k].removeEmptyMips ? (byte)1 : (byte)0); mem.WriteByte((byte)textures[i].list[k].numMips); mem.WriteInt16((short)pkgs.IndexOf(textures[i].list[k].path)); } else { mem.WriteInt32(textures[i].list[k].linkToMaster); mem.WriteInt32(textures[i].list[k].path.Length); mem.WriteStringASCII(textures[i].list[k].path); } } } if (!generateBuiltinMapFiles) { mem.WriteInt32(GameData.packageFiles.Count); for (int i = 0; i < GameData.packageFiles.Count; i++) { string s = GameData.RelativeGameData(GameData.packageFiles[i]); mem.WriteInt32(s.Length); mem.WriteStringASCII(s); } } mem.SeekBegin(); if (generateBuiltinMapFiles) { fs.WriteUInt32(0x504D5443); fs.WriteUInt32((uint)mem.Length); byte[] compressed = new ZlibHelper.Zlib().Compress(mem.ToArray(), 9); fs.WriteUInt32((uint)compressed.Length); fs.WriteFromBuffer(compressed); } else { fs.WriteFromStream(mem, mem.Length); } } if (mainWindow != null) { if (!generateBuiltinMapFiles) { MipMaps mipmaps = new MipMaps(); if (GameData.gameType == MeType.ME1_TYPE) { errors += mipmaps.removeMipMapsME1(1, textures, mainWindow, null, false); errors += mipmaps.removeMipMapsME1(2, textures, mainWindow, null, false); } else { errors += mipmaps.removeMipMapsME2ME3(textures, mainWindow, null, false, false); } if (GameData.gameType == MeType.ME3_TYPE) { TOCBinFile.UpdateAllTOCBinFiles(); } } } treeScan = textures; if (mainWindow != null) { var time = Misc.stopTimer(); mainWindow.updateStatusLabel("Done. Process total time: " + Misc.getTimerFormat(time)); mainWindow.updateStatusLabel2(""); } return(errors); }
private void FindTextures(MeType gameId, List <FoundTexture> textures, string packagePath, bool modified, bool ipc) { Package package = null; try { package = new Package(GameData.GamePath + packagePath); } catch (Exception e) { if (e.Message.Contains("Problem with PCC file header:")) { return; } if (ipc) { Console.WriteLine("[IPC]ERROR Issue opening package file: " + packagePath); Console.Out.Flush(); } else { string err = ""; err += "---- Start --------------------------------------------" + Environment.NewLine; err += "Issue opening package file: " + packagePath + Environment.NewLine; err += e.Message + Environment.NewLine + Environment.NewLine; err += e.StackTrace + Environment.NewLine + Environment.NewLine; err += "---- End ----------------------------------------------" + Environment.NewLine + Environment.NewLine; Console.WriteLine(err); } return; } for (int i = 0; i < package.exportsTable.Count; i++) { int id = package.getClassNameId(package.exportsTable[i].classId); if (id == package.nameIdTexture2D || id == package.nameIdLightMapTexture2D || id == package.nameIdShadowMapTexture2D || id == package.nameIdTextureFlipBook) { Texture texture = new Texture(package, i, package.getExportData(i)); if (!texture.hasImageData()) { continue; } Texture.MipMap mipmap = texture.getTopMipmap(); string name = package.exportsTable[i].objectName; MatchedTexture matchTexture = new MatchedTexture(); matchTexture.exportID = i; matchTexture.path = packagePath; matchTexture.packageName = texture.packageName; matchTexture.removeEmptyMips = texture.mipMapsList.Exists(s => s.storageType == Texture.StorageTypes.empty); matchTexture.numMips = texture.mipMapsList.FindAll(s => s.storageType != Texture.StorageTypes.empty).Count; if (gameId == MeType.ME1_TYPE) { matchTexture.basePackageName = texture.basePackageName; matchTexture.slave = texture.slave; matchTexture.weakSlave = texture.weakSlave; matchTexture.linkToMaster = -1; if (matchTexture.slave) { matchTexture.mipmapOffset = mipmap.dataOffset; } else { matchTexture.mipmapOffset = package.exportsTable[i].dataOffset + (uint)texture.properties.propertyEndOffset + mipmap.internalOffset; } } uint crc = 0; try { crc = texture.getCrcTopMipmap(); } catch (Exception e) { if (ipc) { Console.WriteLine("[IPC]ERROR Texture " + package.exportsTable[i].objectName + " is broken in package: " + packagePath + ", skipping..."); Console.Out.Flush(); } else { Console.WriteLine(">>>>>>>>>"); Console.WriteLine("Error: Texture " + package.exportsTable[i].objectName + " is broken in package: " + Environment.NewLine + packagePath); Console.WriteLine(e.Message); Console.WriteLine("Export Id: " + (i + 1)); Console.WriteLine("skipping..."); Console.WriteLine("<<<<<<<<<" + Environment.NewLine); } continue; } FoundTexture foundTexName = textures.Find(s => s.crc == crc); if (foundTexName.crc != 0) { if (modified && foundTexName.list.Exists(s => (s.exportID == i && s.path.ToLowerInvariant() == packagePath.ToLowerInvariant()))) { continue; } if (matchTexture.slave || gameId != MeType.ME1_TYPE) { foundTexName.list.Add(matchTexture); } else { foundTexName.list.Insert(0, matchTexture); } } else { if (modified) { for (int k = 0; k < textures.Count; k++) { bool found = false; for (int t = 0; t < textures[k].list.Count; t++) { if (textures[k].list[t].exportID == i && textures[k].list[t].path.ToLowerInvariant() == packagePath.ToLowerInvariant()) { MatchedTexture f = textures[k].list[t]; f.path = ""; textures[k].list[t] = f; found = true; break; } } if (found) { break; } } } FoundTexture foundTex = new FoundTexture(); foundTex.list = new List <MatchedTexture>(); foundTex.list.Add(matchTexture); foundTex.name = name; foundTex.crc = crc; if (generateBuiltinMapFiles) { foundTex.width = texture.getTopMipmap().width; foundTex.height = texture.getTopMipmap().height; foundTex.pixfmt = Image.getPixelFormatType(texture.properties.getProperty("Format").valueName); if (texture.properties.exists("CompressionSettings")) { string cmp = texture.properties.getProperty("CompressionSettings").valueName; if (cmp == "TC_OneBitAlpha") { foundTex.flags = TexProperty.TextureTypes.OneBitAlpha; } else if (cmp == "TC_Displacementmap") { foundTex.flags = TexProperty.TextureTypes.Displacementmap; } else if (cmp == "TC_Grayscale") { foundTex.flags = TexProperty.TextureTypes.GreyScale; } else if (cmp == "TC_Normalmap" || cmp == "TC_NormalmapHQ" || cmp == "TC_NormalmapAlpha" || cmp == "TC_NormalmapUncompressed") { foundTex.flags = TexProperty.TextureTypes.Normalmap; } else { throw new Exception(); } } else { foundTex.flags = TexProperty.TextureTypes.Normal; } } textures.Add(foundTex); } } } package.Dispose(); }
public void loadTexturesMap(MeType gameId, List <FoundTexture> textures) { Stream fs; byte[] buffer = null; if (gameId == MeType.ME1_TYPE) { pkgs = Program.tablePkgsME1; } else if (gameId == MeType.ME2_TYPE) { pkgs = Program.tablePkgsME2; } else { pkgs = Program.tablePkgsME3; } Assembly assembly = Assembly.GetExecutingAssembly(); string[] resources = assembly.GetManifestResourceNames(); for (int l = 0; l < resources.Length; l++) { if (resources[l].Contains("me" + (int)gameId + "map.bin")) { using (Stream s = Assembly.GetEntryAssembly().GetManifestResourceStream(resources[l])) { buffer = s.ReadToBuffer(s.Length); break; } } } if (buffer == null) { throw new Exception(); } MemoryStream tmp = new MemoryStream(buffer); if (tmp.ReadUInt32() != 0x504D5443) { throw new Exception(); } byte[] decompressed = new byte[tmp.ReadUInt32()]; byte[] compressed = tmp.ReadToBuffer(tmp.ReadUInt32()); if (new ZlibHelper.Zlib().Decompress(compressed, (uint)compressed.Length, decompressed) == 0) { throw new Exception(); } fs = new MemoryStream(decompressed); fs.Skip(8); uint countTexture = fs.ReadUInt32(); for (int i = 0; i < countTexture; i++) { FoundTexture texture = new FoundTexture(); int len = fs.ReadByte(); texture.name = fs.ReadStringASCII(len); texture.crc = fs.ReadUInt32(); texture.width = fs.ReadInt16(); texture.height = fs.ReadInt16(); texture.pixfmt = (PixelFormat)fs.ReadByte(); texture.flags = (TexProperty.TextureTypes)fs.ReadByte(); int countPackages = fs.ReadInt16(); texture.list = new List <MatchedTexture>(); for (int k = 0; k < countPackages; k++) { MatchedTexture matched = new MatchedTexture(); matched.exportID = fs.ReadInt32(); if (gameId == MeType.ME1_TYPE) { matched.linkToMaster = fs.ReadInt16(); if (matched.linkToMaster != -1) { matched.slave = true; matched.basePackageName = fs.ReadStringASCIINull(); } } matched.removeEmptyMips = fs.ReadByte() != 0; matched.numMips = fs.ReadByte(); matched.path = pkgs[fs.ReadInt16()]; matched.packageName = Path.GetFileNameWithoutExtension(matched.path).ToUpper(); texture.list.Add(matched); } textures.Add(texture); } }
public GameData(MeType type, ConfIni configIni, bool force = false) { gameType = type; _configIni = configIni; string key = "ME" + (int)gameType; string path = configIni.Read(key, "GameDataPath"); if (path != null && path != "" && !force) { _path = path.TrimEnd(Path.DirectorySeparatorChar); if (File.Exists(GameExePath)) { return; } else { _path = null; } } string softwareKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\"; string key64 = @"Wow6432Node\"; string gameKey = @"BioWare\Mass Effect"; string entry = "Path"; if (type == MeType.ME2_TYPE) { gameKey += @" 2"; } else if (type == MeType.ME3_TYPE) { gameKey += @" 3"; entry = "Install Dir"; } path = (string)Registry.GetValue(softwareKey + gameKey, entry, null); if (path == null) { path = (string)Registry.GetValue(softwareKey + key64 + gameKey, entry, null); } if (path != null && !force) { _path = path.TrimEnd(Path.DirectorySeparatorChar); if (File.Exists(GameExePath)) { configIni.Write(key, _path, "GameDataPath"); return; } else { _path = null; } } OpenFileDialog selectExe = new OpenFileDialog(); selectExe.Title = "Please select the Mass Effect " + (int)gameType + " executable file"; if (_path != null) { selectExe.FileName = _path; } switch (gameType) { case MeType.ME1_TYPE: selectExe.Filter = "ME1 exe file|MassEffect.exe"; selectExe.FileName = "MassEffect.exe"; break; case MeType.ME2_TYPE: selectExe.Filter = "ME2 exe file|MassEffect2.exe"; selectExe.FileName = "MassEffect2.exe"; break; case MeType.ME3_TYPE: selectExe.Filter = "ME3 exe file|MassEffect3.exe"; selectExe.FileName = "MassEffect3.exe"; break; } if (selectExe.ShowDialog() == DialogResult.OK) { if (gameType == MeType.ME3_TYPE) { _path = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(selectExe.FileName))); } else { _path = Path.GetDirectoryName(Path.GetDirectoryName(selectExe.FileName)); } } if (_path != null) { _configIni.Write(key, _path, "GameDataPath"); } }