This commit is contained in:
IgorEisberg 2023-07-09 22:38:08 +03:00
parent db8e7de58e
commit 302173daff
9 changed files with 172 additions and 192 deletions

View File

@ -20,7 +20,7 @@ namespace IcyClawz.CustomInteractions
} }
} }
public class ItemUiContextPatch : ModulePatch internal class ItemUiContextPatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() => protected override MethodBase GetTargetMethod() =>
typeof(ItemUiContext).GetMethod("GetItemContextInteractions", BindingFlags.Public | BindingFlags.Instance); typeof(ItemUiContext).GetMethod("GetItemContextInteractions", BindingFlags.Public | BindingFlags.Instance);
@ -42,7 +42,7 @@ namespace IcyClawz.CustomInteractions
} }
} }
public class InteractionButtonsContainerPatch : ModulePatch internal class InteractionButtonsContainerPatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() => protected override MethodBase GetTargetMethod() =>
typeof(InteractionButtonsContainer).GetMethod("method_3", BindingFlags.NonPublic | BindingFlags.Instance); typeof(InteractionButtonsContainer).GetMethod("method_3", BindingFlags.NonPublic | BindingFlags.Instance);

View File

@ -14,7 +14,7 @@ namespace IcyClawz.ItemAttributeFix
} }
} }
public class CompactCharacteristicPanelPatch : ModulePatch internal class CompactCharacteristicPanelPatch : ModulePatch
{ {
private static readonly FieldInfo ItemAttributeField = private static readonly FieldInfo ItemAttributeField =
typeof(CompactCharacteristicPanel).GetField("ItemAttribute", BindingFlags.NonPublic | BindingFlags.Instance); typeof(CompactCharacteristicPanel).GetField("ItemAttribute", BindingFlags.NonPublic | BindingFlags.Instance);

View File

@ -29,7 +29,7 @@ namespace IcyClawz.ItemContextMenuExt
((ILightTemplate)component.Item.Template).ModesCount; ((ILightTemplate)component.Item.Template).ModesCount;
} }
public sealed class CustomInteractionsProvider : IItemCustomInteractionsProvider internal sealed class CustomInteractionsProvider : IItemCustomInteractionsProvider
{ {
internal const string IconsPrefix = "Characteristics/Icons/"; internal const string IconsPrefix = "Characteristics/Icons/";
internal static StaticIcons StaticIcons => EFTHardSettings.Instance.StaticIcons; internal static StaticIcons StaticIcons => EFTHardSettings.Instance.StaticIcons;

View File

@ -12,7 +12,32 @@ using CurrencyUtil = GClass2181;
namespace IcyClawz.ItemSellPrice namespace IcyClawz.ItemSellPrice
{ {
public static class ItemSellPrice internal static class TraderClassExtensions
{
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
private static readonly FieldInfo SupplyDataField =
typeof(TraderClass).GetField("supplyData_0", BindingFlags.NonPublic | BindingFlags.Instance);
public static SupplyData GetSupplyData(this TraderClass trader) =>
SupplyDataField.GetValue(trader) as SupplyData;
public static void SetSupplyData(this TraderClass trader, SupplyData supplyData) =>
SupplyDataField.SetValue(trader, supplyData);
public static async void UpdateSupplyData(this TraderClass trader)
{
Result<SupplyData> result = await Session.GetSupplyData(trader.Id);
if (result.Failed)
{
Debug.LogError("Failed to download supply data");
return;
}
trader.SetSupplyData(result.Value);
}
}
internal static class ItemExtensions
{ {
private static readonly Dictionary<string, string[]> DisplayNames = new Dictionary<string, string[]>() private static readonly Dictionary<string, string[]> DisplayNames = new Dictionary<string, string[]>()
{ {
@ -34,42 +59,76 @@ namespace IcyClawz.ItemSellPrice
{ "tu", new[] { "Satış fiyatı ({0})", "Tüccarlara satılamaz" } } { "tu", new[] { "Satış fiyatı ({0})", "Tüccarlara satılamaz" } }
}; };
private static readonly FieldInfo SupplyDataField =
typeof(TraderClass).GetField("supplyData_0", BindingFlags.NonPublic | BindingFlags.Instance);
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession(); private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
public static async void UpdateSupplyData(this TraderClass trader)
{
Result<SupplyData> result = await Session.GetSupplyData(trader.Id);
if (result.Failed)
{
Debug.LogError("Failed to download supply data");
return;
}
trader.SetSupplyData(result.Value);
}
public static SupplyData GetSupplyData(this TraderClass trader) =>
SupplyDataField.GetValue(trader) as SupplyData;
public static void SetSupplyData(this TraderClass trader, SupplyData supplyData) =>
SupplyDataField.SetValue(trader, supplyData);
public static void AddTraderOfferAttribute(this Item item) public static void AddTraderOfferAttribute(this Item item)
{ {
List<ItemAttributeClass> attributes = new List<ItemAttributeClass> ItemAttributeClass attribute = new ItemAttributeClass(EItemAttributeId.MoneySum)
{ {
new ItemAttributeClass(EItemAttributeId.MoneySum) Name = EItemAttributeId.MoneySum.GetName(),
DisplayNameFunc = () =>
{ {
Name = EItemAttributeId.MoneySum.GetName(), string language = Singleton<SharedGameSettingsClass>.Instance?.Game?.Settings?.Language?.GetValue();
DisplayNameFunc = () => GetDisplayName(item), if (language == null || !DisplayNames.ContainsKey(language))
Base = () => GetBase(item), {
StringValue = () => GetStringValue(item), language = "en";
FullStringValue = () => GetFullStringValue(item), }
DisplayType = () => EItemAttributeDisplayType.Compact if (GetBestTraderOffer(item) is TraderOffer offer)
} {
return string.Format(DisplayNames[language][0], offer.Name);
}
else
{
return DisplayNames[language][1];
}
},
Base = () =>
{
if (GetBestTraderOffer(item) is TraderOffer offer)
{
return offer.Price;
}
else
{
return 0.01f;
}
},
StringValue = () =>
{
if (GetBestTraderOffer(item) is TraderOffer offer)
{
string value = $"{offer.Currency} {offer.Price}";
if (offer.Count > 1)
{
value += $" ({offer.Count})";
}
return value;
}
else
{
return string.Empty;
}
},
FullStringValue = () =>
{
if (GetAllTraderOffers(item) is List<TraderOffer> offers)
{
string[] lines = new string[offers.Count];
for (int i = 0; i < offers.Count; i++)
{
TraderOffer offer = offers[i];
lines[i] = $"{offer.Name}: {offer.Currency} {offer.Price}";
}
return string.Join(Environment.NewLine, lines);
}
else
{
return string.Empty;
}
},
DisplayType = () => EItemAttributeDisplayType.Compact
}; };
List<ItemAttributeClass> attributes = new List<ItemAttributeClass> { attribute };
attributes.AddRange(item.Attributes); attributes.AddRange(item.Attributes);
item.Attributes = attributes; item.Attributes = attributes;
} }
@ -149,69 +208,5 @@ namespace IcyClawz.ItemSellPrice
return null; return null;
} }
} }
public static string GetDisplayName(Item item)
{
string language = Singleton<SharedGameSettingsClass>.Instance?.Game?.Settings?.Language?.GetValue();
if (language == null || !DisplayNames.ContainsKey(language))
{
language = "en";
}
if (GetBestTraderOffer(item) is TraderOffer offer)
{
return string.Format(DisplayNames[language][0], offer.Name);
}
else
{
return DisplayNames[language][1];
}
}
public static float GetBase(Item item)
{
if (GetBestTraderOffer(item) is TraderOffer offer)
{
return offer.Price;
}
else
{
return 0.01f;
}
}
public static string GetStringValue(Item item)
{
if (GetBestTraderOffer(item) is TraderOffer offer)
{
string value = $"{offer.Currency} {offer.Price}";
if (offer.Count > 1)
{
value += $" ({offer.Count})";
}
return value;
}
else
{
return string.Empty;
}
}
public static string GetFullStringValue(Item item)
{
if (GetAllTraderOffers(item) is List<TraderOffer> offers)
{
string[] lines = new string[offers.Count];
for (int i = 0; i < offers.Count; i++)
{
TraderOffer offer = offers[i];
lines[i] = $"{offer.Name}: {offer.Currency} {offer.Price}";
}
return string.Join(Environment.NewLine, lines);
}
else
{
return string.Empty;
}
}
} }
} }

View File

@ -8,9 +8,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Aki.Common">
<HintPath>..\Shared\Aki.Common.dll</HintPath>
</Reference>
<Reference Include="Aki.Reflection"> <Reference Include="Aki.Reflection">
<HintPath>..\Shared\Aki.Reflection.dll</HintPath> <HintPath>..\Shared\Aki.Reflection.dll</HintPath>
</Reference> </Reference>

View File

@ -18,7 +18,7 @@ namespace IcyClawz.ItemSellPrice
} }
} }
public class TraderPatch : ModulePatch internal class TraderPatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() => protected override MethodBase GetTargetMethod() =>
typeof(TraderClass).GetConstructors()[0]; typeof(TraderClass).GetConstructors()[0];
@ -30,7 +30,7 @@ namespace IcyClawz.ItemSellPrice
} }
} }
public class ItemPatch : ModulePatch internal class ItemPatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() => protected override MethodBase GetTargetMethod() =>
typeof(Item).GetConstructors()[0]; typeof(Item).GetConstructors()[0];
@ -42,7 +42,7 @@ namespace IcyClawz.ItemSellPrice
} }
} }
public class AmmoPatch : ModulePatch internal class AmmoPatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() => protected override MethodBase GetTargetMethod() =>
typeof(BulletClass).GetConstructors()[0]; typeof(BulletClass).GetConstructors()[0];
@ -54,7 +54,7 @@ namespace IcyClawz.ItemSellPrice
} }
} }
public class GrenadePatch : ModulePatch internal class GrenadePatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() => protected override MethodBase GetTargetMethod() =>
typeof(GrenadeClass).GetConstructors()[0]; typeof(GrenadeClass).GetConstructors()[0];
@ -66,7 +66,7 @@ namespace IcyClawz.ItemSellPrice
} }
} }
public class SecureContainerPatch : ModulePatch internal class SecureContainerPatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() => protected override MethodBase GetTargetMethod() =>
typeof(ItemContainerClass).GetConstructors()[0]; typeof(ItemContainerClass).GetConstructors()[0];

View File

@ -11,7 +11,7 @@ using InGameStatus = GClass1756;
namespace IcyClawz.MagazineInspector namespace IcyClawz.MagazineInspector
{ {
public static class MagazineInspector internal static class MagazineClassExtensions
{ {
private static readonly Dictionary<string, string> DisplayNames = new Dictionary<string, string>() private static readonly Dictionary<string, string> DisplayNames = new Dictionary<string, string>()
{ {
@ -35,7 +35,7 @@ namespace IcyClawz.MagazineInspector
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession(); private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
private static Profile ActiveProfile => InGameStatus.InRaid ? ClientPlayerOwner.MyPlayer.Profile : Session.Profile; private static Profile ActiveProfile => InGameStatus.InRaid ? GamePlayerOwner.MyPlayer.Profile : Session.Profile;
public static void AddAmmoCountAttribute(this MagazineClass magazine) public static void AddAmmoCountAttribute(this MagazineClass magazine)
{ {
@ -44,10 +44,77 @@ namespace IcyClawz.MagazineInspector
{ {
return; return;
} }
attribute.DisplayNameFunc = GetDisplayName; attribute.DisplayNameFunc = () =>
attribute.Base = () => GetBase(magazine); {
attribute.StringValue = () => GetStringValue(magazine); string language = Singleton<SharedGameSettingsClass>.Instance?.Game?.Settings?.Language?.GetValue();
attribute.FullStringValue = () => GetFullStringValue(magazine); if (language == null || !DisplayNames.ContainsKey(language))
{
language = "en";
}
return DisplayNames[language];
};
attribute.Base = () =>
{
if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount)
{
return ammoCount;
}
else
{
return 0f;
}
};
attribute.StringValue = () =>
{
string value;
if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount)
{
value = ammoCount.ToString();
}
else
{
value = "?";
}
return $"{value}/{magazine.MaxCount}";
};
attribute.FullStringValue = () =>
{
Profile profile = ActiveProfile;
int? ammoCount = GetAmmoCount(magazine, profile, out bool magChecked);
if (magChecked)
{
List<Item> cartridges = new List<Item>(magazine.Cartridges.Items);
string[] lines = new string[cartridges.Count];
int i = cartridges.Count - 1;
foreach (Item cartridge in cartridges)
{
string count;
if (ammoCount != null)
{
count = cartridge.StackObjectsCount.ToString();
}
else
{
count = "?";
}
string name;
if (profile.Examined(cartridge))
{
name = cartridge.LocalizedName();
}
else
{
name = "Unknown item".Localized();
}
lines[i--] = $"{count} × {name}";
}
return string.Join(Environment.NewLine, lines);
}
else
{
return string.Empty;
}
};
} }
private static int? GetAmmoCount(MagazineClass magazine, Profile profile, out bool magChecked) private static int? GetAmmoCount(MagazineClass magazine, Profile profile, out bool magChecked)
@ -77,81 +144,5 @@ namespace IcyClawz.MagazineInspector
} }
return null; return null;
} }
public static string GetDisplayName()
{
string language = Singleton<SharedGameSettingsClass>.Instance?.Game?.Settings?.Language?.GetValue();
if (language == null || !DisplayNames.ContainsKey(language))
{
language = "en";
}
return DisplayNames[language];
}
public static float GetBase(MagazineClass magazine)
{
if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount)
{
return ammoCount;
}
else
{
return 0f;
}
}
public static string GetStringValue(MagazineClass magazine)
{
string value;
if (GetAmmoCount(magazine, ActiveProfile, out _) is int ammoCount)
{
value = ammoCount.ToString();
}
else
{
value = "?";
}
return $"{value}/{magazine.MaxCount}";
}
public static string GetFullStringValue(MagazineClass magazine)
{
Profile profile = ActiveProfile;
int? ammoCount = GetAmmoCount(magazine, profile, out bool magChecked);
if (magChecked)
{
List<Item> cartridges = new List<Item>(magazine.Cartridges.Items);
string[] lines = new string[cartridges.Count];
int i = cartridges.Count - 1;
foreach (Item cartridge in cartridges)
{
string count;
if (ammoCount != null)
{
count = cartridge.StackObjectsCount.ToString();
}
else
{
count = "?";
}
string name;
if (profile.Examined(cartridge))
{
name = cartridge.LocalizedName();
}
else
{
name = "Unknown item".Localized();
}
lines[i--] = $"{count} × {name}";
}
return string.Join(Environment.NewLine, lines);
}
else
{
return string.Empty;
}
}
} }
} }

View File

@ -8,9 +8,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Aki.Common">
<HintPath>..\Shared\Aki.Common.dll</HintPath>
</Reference>
<Reference Include="Aki.Reflection"> <Reference Include="Aki.Reflection">
<HintPath>..\Shared\Aki.Reflection.dll</HintPath> <HintPath>..\Shared\Aki.Reflection.dll</HintPath>
</Reference> </Reference>

View File

@ -13,7 +13,7 @@ namespace IcyClawz.MagazineInspector
} }
} }
public class MagazinePatch : ModulePatch internal class MagazinePatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() => protected override MethodBase GetTargetMethod() =>
typeof(MagazineClass).GetConstructors()[0]; typeof(MagazineClass).GetConstructors()[0];