#pragma warning disable IDE0051 // Remove unused private members /// <summary> /// Finds the latest patch and applies only it. /// </summary> private static void ApplyLatest() { if (instance != null) { object latest = null; Version latestVer = null; try { foreach (var pair in instance.Patches) { var patch = pair.Value; var patchVer = new Version(pair.Key); if (latestVer == null || latestVer.CompareTo(patchVer) < 0) { // First element or newer version latest = patch; latestVer = patchVer; } } } catch (ArgumentOutOfRangeException e) { // .NET 3.5 please PUtil.LogException(e); } catch (FormatException e) { PUtil.LogException(e); } catch (OverflowException e) { PUtil.LogException(e); } if (latest != null) { // Store the winning version PSharedData.PutData(KEY_VERSION, latestVer.ToString()); try { Traverse.Create(latest).CallMethod("Apply", instance.PLibInstance); } catch (ArgumentException e) { PUtil.LogException(e); } catch (Exception e) { if (e.Message?.ToLower() == "cannot get method value without method") { // Cannot get method value without method PUtil.LogError("The first PLib mod in the load order did not " + "use PUtil.InitLibrary(). PLib cannot patch correctly!"); } else { PUtil.LogException(e); } } } // Reduce memory usage by cleaning up the patch list instance.Patches.Clear(); } else { #if DEBUG LogPatchWarning("ApplyLatest invoked with no Instance!"); #endif } }