// Overrides bnd, relative to current dir, and outputs to other file public void OverrideBndRel <T>(string path, string outPath, Dictionary <string, T> diffData, Func <T, byte[]> writer, string fileExt = null) { if (Spec.Dcx == DCX.Type.Unknown) { throw new Exception("DCX encoding not provided"); } string fname = Path.GetFileName(path); IBinder bnd = ReadBnd(path); foreach (BinderFile file in bnd.Files) { if (fileExt != null && !file.Name.EndsWith(fileExt)) { continue; } string bndName = BaseName(file.Name); if (!diffData.ContainsKey(bndName) || diffData[bndName] == null) { continue; } try { file.Bytes = writer(diffData[bndName]); } catch (Exception ex) { Console.WriteLine($"Failed to load {path}: {bndName}: {ex}"); } } if (bnd is BND4 bnd4) { if (Spec.Game == FromGame.DS3 && outPath.EndsWith("Data0.bdt")) { SFUtil.EncryptDS3Regulation(outPath, bnd4); if (new FileInfo(outPath).Length > 0x10000C) { File.Delete(outPath); throw new Exception($"You must set loadLooseParams=1 in modengine.ini. Otherwise Data0.bdt is too large and will permanently corrupt your save file."); } } else { bnd4.Write(outPath, Spec.Dcx); } } if (bnd is BND3 bnd3) { bnd3.Write(outPath, Spec.Dcx); } }
public static void WriteWithBackup <T>(string gamedir, string moddir, string assetpath, T item, bool ds3reg = false) where T : SoulsFile <T>, new() { var assetgamepath = $@"{gamedir}\{assetpath}"; var assetmodpath = $@"{moddir}\{assetpath}"; if (moddir != null) { if (!Directory.Exists(Path.GetDirectoryName(assetmodpath))) { Directory.CreateDirectory(Path.GetDirectoryName(assetmodpath)); } } // Make a backup of the original file if a mod path doesn't exist if (moddir == null && !File.Exists($@"{assetgamepath}.bak") && File.Exists(assetgamepath)) { File.Copy(assetgamepath, $@"{assetgamepath}.bak", true); } var writepath = (moddir == null) ? assetgamepath : assetmodpath; try { if (File.Exists(writepath + ".temp")) { File.Delete(writepath + ".temp"); } if (ds3reg && item is BND4 bnd) { SFUtil.EncryptDS3Regulation(writepath + ".temp", bnd); } else { item.Write(writepath + ".temp"); } if (File.Exists(writepath)) { File.Copy(writepath, writepath + ".prev", true); File.Delete(writepath); } File.Move(writepath + ".temp", writepath); } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Error saving file: " + writepath + "\nOther files will be saved.", "Error Saving", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); } }
public static void WriteWithBackup <T>(string gamedir, string moddir, string assetpath, T item, bool ds3reg = false) where T : SoulsFile <T>, new() { var assetgamepath = $@"{gamedir}\{assetpath}"; var assetmodpath = $@"{moddir}\{assetpath}"; if (moddir != null) { if (!Directory.Exists(Path.GetDirectoryName(assetmodpath))) { Directory.CreateDirectory(Path.GetDirectoryName(assetmodpath)); } } // Make a backup of the original file if a mod path doesn't exist if (moddir == null && !File.Exists($@"{assetgamepath}.bak") && File.Exists(assetgamepath)) { File.Copy(assetgamepath, $@"{assetgamepath}.bak", true); } var writepath = (moddir == null) ? assetgamepath : assetmodpath; if (File.Exists(writepath + ".temp")) { File.Delete(writepath + ".temp"); } if (ds3reg && item is BND4 bnd) { SFUtil.EncryptDS3Regulation(writepath + ".temp", bnd); } else { item.Write(writepath + ".temp"); } if (File.Exists(writepath)) { File.Copy(writepath, writepath + ".prev", true); File.Delete(writepath); } File.Move(writepath + ".temp", writepath); }
public static void SaveParams() { if (GameType != DarkSoulsTools.GameType.DarkSoulsIII || DS3Param == null) { return; } BND4 paramBnd = SFUtil.DecryptDS3Regulation(DarkSoulsTools.GetOverridenPath(ParamPath)); var param = paramBnd.Files.Find(x => Path.GetFileName(x.Name) == "ItemLotParam.param"); param.Bytes = DS3Param.Write(); // Save a backup if one doesn't exist if (!File.Exists(ParamPath + ".backup")) { File.Copy(ParamPath, ParamPath + ".backup"); } string paramPath = ParamPath; if (DarkSoulsTools.GetModProjectPathForFile(ParamPath) != null) { paramPath = DarkSoulsTools.GetModProjectPathForFile(ParamPath); } // Write as a temporary file to make sure there are no errors before overwriting current file if (File.Exists(paramPath + ".temp")) { File.Delete(paramPath + ".temp"); } SFUtil.EncryptDS3Regulation(paramPath + ".temp", paramBnd); // Make a copy of the previous map File.Copy(paramPath, paramPath + ".prev", true); // Move temp file as new map file File.Delete(paramPath); File.Move(paramPath + ".temp", paramPath); }