public static bool RandomizeWeapons(RandomizationOption option) { var me2rbioweapon = CoalescedHandler.GetIniFile("BIOWeapon.ini"); // We must manually fetch game files cause MERFS will return the ini from the dlc mod instead. ME2Coalesced me2basegamecoalesced = new ME2Coalesced(MERFileSystem.GetSpecificFile(@"BioGame\Config\PC\Cooked\Coalesced.ini")); MERLog.Information("Randomizing basegame weapon ini"); var bioweapon = me2basegamecoalesced.Inis.FirstOrDefault(x => Path.GetFileName(x.Key) == "BIOWeapon.ini").Value; RandomizeWeaponIni(bioweapon, me2rbioweapon); var weaponInis = Directory.GetFiles(MEDirectories.GetDLCPath(MERFileSystem.Game), "BIOWeapon.ini", SearchOption.AllDirectories).ToList(); foreach (var wi in weaponInis) { if (wi.Contains($"DLC_MOD_{MERFileSystem.Game}Randomizer")) { continue; // Skip randomizer folders } MERLog.Information($@"Randomizing weapon ini {wi}"); //Log.Information("Randomizing weapons in ini: " + wi); var dlcWeapIni = DuplicatingIni.LoadIni(wi); RandomizeWeaponIni(dlcWeapIni, me2rbioweapon); //if (!MERFileSystem.UsingDLCModFS) //{ // Log.Information("Writing DLC BioWeapon: " + wi); // File.WriteAllText(wi, dlcWeapIni.ToString()); //} } return(true); }
private void LoadME2Keys(GameTarget target) { if (target.Game != Mod.MEGame.ME2) { throw new Exception(@"Cannot load ME2 keys from target that is not ME2"); } var me2c = ME2Coalesced.OpenFromTarget(target); var bioinput = me2c.Inis.FirstOrDefault(x => Path.GetFileName(x.Key).Equals(@"BioInput.ini", StringComparison.InvariantCultureIgnoreCase)); var engineConsole = bioinput.Value.Sections.FirstOrDefault(x => x.Header == @"Engine.Console"); if (engineConsole != null) { var consoleKey = engineConsole.Entries.FirstOrDefault(x => x.Key == @"ConsoleKey"); if (consoleKey == null) { ME2FullConsoleKeyText = M3L.GetString(M3L.string_fullConsoleNotBoundToAKey); } else { ME2FullConsoleKeyText = M3L.GetString(M3L.string_interp_fullConsoleBoundToX, consoleKey.Value); } var typeKey = engineConsole.Entries.FirstOrDefault(x => x.Key == @"TypeKey"); if (typeKey == null) { ME2MiniConsoleKeyText = M3L.GetString(M3L.string_miniConsoleNotBoundToAKey); } else { ME2MiniConsoleKeyText = M3L.GetString(M3L.string_interp_miniConsoleBoundToX, typeKey.Value); } } }
public static void SetME2ConsoleKeybinds(GameTarget target, string consoleKeyStr, string typeKeyStr) { if (target.Game != Mod.MEGame.ME2) { throw new Exception(@"Cannot set ME2 keybind for non-ME2 target"); } var me2c = ME2Coalesced.OpenFromTarget(target); var bioinput = me2c.Inis.FirstOrDefault(x => Path.GetFileName(x.Key).Equals(@"BioInput.ini", StringComparison.InvariantCultureIgnoreCase)); SetIniBasedKeybinds(bioinput.Value, consoleKeyStr, typeKeyStr); me2c.Serialize(); }
private void LoadME2Keys(GameTarget target) { if (target.Game != Mod.MEGame.ME2) { throw new Exception(@"Cannot load ME2 keys from target that is not ME2"); } ME2Coalesced me2c = null; try { me2c = ME2Coalesced.OpenFromTarget(target, true); } catch (Exception e) { Application.Current.Dispatcher.Invoke(delegate { M3L.ShowDialog(window, M3L.GetString(M3L.string_interp_cannotOpenMassEffect2CoalescediniMessage, e.Message), M3L.GetString(M3L.string_errorReadingCoalescedini), MessageBoxButton.OK, MessageBoxImage.Error); }); ME2MiniConsoleKeyText = M3L.GetString(M3L.string_errorReadingCoalescedini); ME2MiniConsoleKeyText = M3L.GetString(M3L.string_errorReadingCoalescedini); return; } var bioinput = me2c.Inis.FirstOrDefault(x => Path.GetFileName(x.Key).Equals(@"BioInput.ini", StringComparison.InvariantCultureIgnoreCase)); var engineConsole = bioinput.Value.Sections.FirstOrDefault(x => x.Header == @"Engine.Console"); if (engineConsole != null) { var consoleKey = engineConsole.Entries.FirstOrDefault(x => x.Key == @"ConsoleKey"); if (consoleKey == null) { ME2FullConsoleKeyText = M3L.GetString(M3L.string_fullConsoleNotBoundToAKey); } else { ME2FullConsoleKeyText = M3L.GetString(M3L.string_interp_fullConsoleBoundToX, consoleKey.Value); } var typeKey = engineConsole.Entries.FirstOrDefault(x => x.Key == @"TypeKey"); if (typeKey == null) { ME2MiniConsoleKeyText = M3L.GetString(M3L.string_miniConsoleNotBoundToAKey); } else { ME2MiniConsoleKeyText = M3L.GetString(M3L.string_interp_miniConsoleBoundToX, typeKey.Value); } } }
private ModInstallCompletedStatus InstallAttachedRCWMod() { CLog.Information(@"Installing attached RCW mod. Checking Coalesced.ini first to make sure this mod can be safely applied", Settings.LogModInstallation); ME2Coalesced me2c = new ME2Coalesced(ME2Directory.CoalescedPath(gameTarget)); RCWMod rcw = ModBeingInstalled.GetJob(ModJob.JobHeader.ME2_RCWMOD).RCW; foreach (var rcwF in rcw.Files) { var me2cF = me2c.Inis.FirstOrDefault(x => x.Key == rcwF.FileName); if (me2cF.Key == null) { Log.Error(@"RCW mod specifies a file in coalesced that does not exist in the local one: " + rcwF); return(ModInstallCompletedStatus.INSTALL_FAILED_MALFORMED_RCW_FILE); } foreach (var rcwS in rcwF.Sections) { var section = me2cF.Value.Sections.FirstOrDefault(x => x.Header == rcwS.SectionName); if (section == null) { Log.Error($@"RCW mod specifies a section in {rcwF.FileName} that does not exist in the local coalesced: {rcwS.SectionName}"); return(ModInstallCompletedStatus.INSTALL_FAILED_MALFORMED_RCW_FILE); } } //Apply mod foreach (var rcwS in rcwF.Sections) { var section = me2cF.Value.Sections.FirstOrDefault(x => x.Header == rcwS.SectionName); Dictionary <string, int> keyCount = new Dictionary <string, int>(); foreach (var key in section.Entries) { if (keyCount.TryGetValue(key.Key, out var existingCount)) { keyCount[key.Key] = existingCount + 1; } else { keyCount[key.Key] = 1; } } Dictionary <string, bool> keysSupportingMulti = keyCount.ToDictionary(x => x.Key, x => x.Value > 1); //Remove items foreach (var itemToDelete in rcwS.KeysToDelete) { for (int i = section.Entries.Count - 1; i > 0; i--) { var entry = section.Entries[i]; if (entry.Key == itemToDelete.Key && entry.Value == itemToDelete.Value) { CLog.Information($@"Removing ini entry {entry.RawText} in section {section.Header} of file {me2cF.Key}", Settings.LogModInstallation); section.Entries.RemoveAt(i); } } } foreach (var itemToAdd in rcwS.KeysToAdd) { var existingEntries = section.Entries.Where(x => x.Key == itemToAdd.Key).ToList(); if (existingEntries.Count <= 0) { //just add it CLog.Information($@"Adding ini entry {itemToAdd.RawText} in section {section.Header} of file {me2cF.Key}", Settings.LogModInstallation); section.Entries.Add(itemToAdd); } else if (existingEntries.Count > 1) { //Supports multi. Add this key - but making sure the data doesn't already exist! if (existingEntries.Any(x => x.Value == itemToAdd.Value)) { //Duplicate. CLog.Information($@"Not adding duplicate ini entry {itemToAdd.RawText} in section {section.Header} of file {me2cF.Key}", Settings.LogModInstallation); } else { //Not duplicate - installing key CLog.Information($@"Adding ini entry {itemToAdd.RawText} in section {section.Header} of file {me2cF.Key}", Settings.LogModInstallation); section.Entries.Add(itemToAdd); } } else { //Only one key exists currently. We need to check multi lookup to choose how to install if (keysSupportingMulti[itemToAdd.Key]) { //Supports multi. Add this key - but making sure the data doesn't already exist! if (existingEntries.Any(x => x.Value == itemToAdd.Value)) { //Duplicate. CLog.Information($@"Not adding duplicate ini entry {itemToAdd.RawText} in section {section.Header} of file {me2cF.Key}", Settings.LogModInstallation); } else { //Not duplicate - installing key CLog.Information($@"Adding ini entry {itemToAdd.RawText} in section {section.Header} of file {me2cF.Key}", Settings.LogModInstallation); section.Entries.Add(itemToAdd); } } else { //Replace existing key existingEntries[0].Value = itemToAdd.Value; } } } } } me2c.Serialize(); return(ModInstallCompletedStatus.INSTALL_SUCCESSFUL); }