This repository has been archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add patch for item comparison coloring
fix record fce mod option fix delayed module loading unselected mods more directly enforce line endings for saving options
- Loading branch information
Showing
5 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Security.Cryptography; | ||
using HarmonyLib; | ||
using TaleWorlds.CampaignSystem; | ||
using TaleWorlds.CampaignSystem.ViewModelCollection; | ||
using TaleWorlds.Core; | ||
using TaleWorlds.Library; | ||
|
||
namespace CommunityPatch.Patches { | ||
|
||
public class ItemComparisonColorPatch : IPatch { | ||
|
||
private static readonly MethodInfo TargetMethodInfo = typeof(ItemMenuVM).GetMethod("GetColorFromComparison", BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly); | ||
|
||
private static readonly MethodInfo PatchMethodInfo = typeof(ItemComparisonColorPatch).GetMethod(nameof(GetColorFromComparisonPatched), BindingFlags.NonPublic|BindingFlags.Static|BindingFlags.DeclaredOnly); | ||
|
||
public bool IsApplicable(Game game) { | ||
var patchInfo = Harmony.GetPatchInfo(TargetMethodInfo); | ||
if (patchInfo.Owners.Any()) | ||
return false; | ||
|
||
var bytes = TargetMethodInfo.GetMethodBody()?.GetILAsByteArray(); | ||
if (bytes == null) return false; | ||
|
||
using var hasher = SHA256.Create(); | ||
var hash = hasher.ComputeHash(bytes); | ||
return hash.SequenceEqual(new byte[] { }); | ||
} | ||
|
||
public void Apply(Game game) | ||
=> CommunityPatchSubModule.Harmony.Patch(TargetMethodInfo, | ||
new HarmonyMethod(PatchMethodInfo)); | ||
|
||
private static bool GetColorFromComparisonPatched(int result, bool isCompared, ref Color __result) { | ||
if (MobileParty.MainParty != null && !(MobileParty.MainParty.HasPerk(DefaultPerks.Trade.WholeSeller) || MobileParty.MainParty.HasPerk(DefaultPerks.Trade.Appraiser))) { | ||
__result = Colors.Black; | ||
return false; | ||
} | ||
|
||
if (result != -1) { | ||
if (result != 1) { | ||
__result = Colors.Black; | ||
return false; | ||
} | ||
|
||
if (!isCompared) { | ||
__result = UIColors.PositiveIndicator; | ||
return false; | ||
} | ||
|
||
__result = UIColors.NegativeIndicator; | ||
return false; | ||
} | ||
|
||
if (!isCompared) { | ||
__result = UIColors.NegativeIndicator; | ||
return false; | ||
} | ||
|
||
__result = UIColors.PositiveIndicator; | ||
return false; | ||
} | ||
|
||
} | ||
|
||
} |