Fix potential issue with max values
This commit is contained in:
parent
ccad3d23d0
commit
7183b28e8b
@ -68,15 +68,15 @@ internal static class IconCache
|
||||
|
||||
internal static class AmmoTemplateExtensions
|
||||
{
|
||||
private static readonly float MaxMalfMisfireChance = (float)
|
||||
typeof(AmmoTemplate).GetField("MaxMalfMisfireChance", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
|
||||
|
||||
private static readonly float MaxMalfFeedChance = (float)
|
||||
typeof(AmmoTemplate).GetField("MaxMalfFeedChance", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
|
||||
|
||||
private static readonly string[] MalfChancesKeys = (string[])
|
||||
typeof(AmmoTemplate).GetField("MalfChancesKeys", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
|
||||
|
||||
private static readonly FieldInfo MaxMalfMisfireChance =
|
||||
typeof(AmmoTemplate).GetField("MaxMalfMisfireChance", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
private static readonly FieldInfo MaxMalfFeedChance =
|
||||
typeof(AmmoTemplate).GetField("MaxMalfFeedChance", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
private static readonly FieldInfo CachedQualitiesField =
|
||||
typeof(AmmoTemplate).GetField("_cachedQualities", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
@ -138,20 +138,14 @@ internal static class AmmoTemplateExtensions
|
||||
Base = () => instance.MalfMisfireChance,
|
||||
StringValue = () =>
|
||||
{
|
||||
string value;
|
||||
if (instance.MalfMisfireChance <= 0f)
|
||||
value = MalfChancesKeys[0];
|
||||
else if (instance.MalfMisfireChance < 3f * MaxMalfMisfireChance / 7f)
|
||||
value = MalfChancesKeys[1];
|
||||
else if (instance.MalfMisfireChance < 4f * MaxMalfMisfireChance / 7f)
|
||||
value = MalfChancesKeys[2];
|
||||
else if (instance.MalfMisfireChance < 5f * MaxMalfMisfireChance / 7f)
|
||||
value = MalfChancesKeys[3];
|
||||
else if (instance.MalfMisfireChance < 6f * MaxMalfMisfireChance / 7f)
|
||||
value = MalfChancesKeys[4];
|
||||
else
|
||||
value = MalfChancesKeys[5];
|
||||
return value.Localized();
|
||||
float maxMalfMisfireChance = (float)MaxMalfMisfireChance.GetValue(null);
|
||||
int index = instance.MalfMisfireChance <= 0f ? 0
|
||||
: instance.MalfMisfireChance < 3f * maxMalfMisfireChance / 7f ? 1
|
||||
: instance.MalfMisfireChance < 4f * maxMalfMisfireChance / 7f ? 2
|
||||
: instance.MalfMisfireChance < 5f * maxMalfMisfireChance / 7f ? 3
|
||||
: instance.MalfMisfireChance < 6f * maxMalfMisfireChance / 7f ? 4
|
||||
: 5;
|
||||
return MalfChancesKeys[index].Localized();
|
||||
},
|
||||
DisplayType = () => EItemAttributeDisplayType.Compact,
|
||||
});
|
||||
@ -162,20 +156,14 @@ internal static class AmmoTemplateExtensions
|
||||
Base = () => instance.MalfFeedChance,
|
||||
StringValue = () =>
|
||||
{
|
||||
string value;
|
||||
if (instance.MalfFeedChance <= 0f)
|
||||
value = MalfChancesKeys[0];
|
||||
else if (instance.MalfFeedChance < 1f * MaxMalfFeedChance / 7f)
|
||||
value = MalfChancesKeys[1];
|
||||
else if (instance.MalfFeedChance < 3f * MaxMalfFeedChance / 7f)
|
||||
value = MalfChancesKeys[2];
|
||||
else if (instance.MalfFeedChance < 5f * MaxMalfFeedChance / 7f)
|
||||
value = MalfChancesKeys[3];
|
||||
else if (instance.MalfFeedChance < 6f * MaxMalfFeedChance / 7f)
|
||||
value = MalfChancesKeys[4];
|
||||
else
|
||||
value = MalfChancesKeys[5];
|
||||
return value.Localized();
|
||||
float maxMalfFeedChance = (float)MaxMalfFeedChance.GetValue(null);
|
||||
int index = instance.MalfFeedChance <= 0f ? 0
|
||||
: instance.MalfFeedChance < 1f * maxMalfFeedChance / 7f ? 1
|
||||
: instance.MalfFeedChance < 3f * maxMalfFeedChance / 7f ? 2
|
||||
: instance.MalfFeedChance < 5f * maxMalfFeedChance / 7f ? 3
|
||||
: instance.MalfFeedChance < 6f * maxMalfFeedChance / 7f ? 4
|
||||
: 5;
|
||||
return MalfChancesKeys[index].Localized();
|
||||
},
|
||||
DisplayType = () => EItemAttributeDisplayType.Compact,
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>IcyClawz.MunitionsExpert</AssemblyName>
|
||||
<Version>1.4.1</Version>
|
||||
<Version>1.4.2</Version>
|
||||
<RootNamespace>IcyClawz.MunitionsExpert</RootNamespace>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
@ -13,7 +13,7 @@ using UnityEngine.UI;
|
||||
|
||||
namespace IcyClawz.MunitionsExpert;
|
||||
|
||||
[BepInPlugin("com.IcyClawz.MunitionsExpert", "IcyClawz.MunitionsExpert", "1.4.1")]
|
||||
[BepInPlugin("com.IcyClawz.MunitionsExpert", "IcyClawz.MunitionsExpert", "1.4.2")]
|
||||
public class Plugin : BaseUnityPlugin
|
||||
{
|
||||
private static ConfigEntry<bool> ColorizeSwitch { get; set; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user