using file-scoped namespaces

This commit is contained in:
Tyfon
2024-07-12 16:17:42 -07:00
parent 29b6094b20
commit 7ea249114d
63 changed files with 8789 additions and 8855 deletions

View File

@@ -8,76 +8,75 @@ using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace UIFixes
namespace UIFixes;
public class LoadAmmoInRaidPatches
{
public class LoadAmmoInRaidPatches
public static void Enable()
{
public static void Enable()
new EnableContextMenuPatch().Enable();
new SlowLoadingPatch().Enable();
}
public class EnableContextMenuPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
new EnableContextMenuPatch().Enable();
new SlowLoadingPatch().Enable();
return AccessTools.Method(R.ContextMenuHelper.Type, "IsActive");
}
public class EnableContextMenuPatch : ModulePatch
[PatchPrefix]
public static bool Prefix(EItemInfoButton button, ref bool __result, Item ___item_0)
{
protected override MethodBase GetTargetMethod()
if (button != EItemInfoButton.LoadAmmo || !Plugin.InRaid() || !Settings.EnableLoadAmmo.Value)
{
return AccessTools.Method(R.ContextMenuHelper.Type, "IsActive");
return true;
}
[PatchPrefix]
public static bool Prefix(EItemInfoButton button, ref bool __result, Item ___item_0)
{
if (button != EItemInfoButton.LoadAmmo || !Plugin.InRaid() || !Settings.EnableLoadAmmo.Value)
{
return true;
}
__result = MagazineBuildClass.TryFindPresetSource(___item_0).Succeeded;
return false;
}
}
__result = MagazineBuildClass.TryFindPresetSource(___item_0).Succeeded;
return false;
}
public class SlowLoadingPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ItemUiContext), nameof(ItemUiContext.LoadAmmoByType));
}
public class SlowLoadingPatch : ModulePatch
// This code is a mix of ItemUiContext.LoadAmmoByType, but then switching over to GridView.AcceptItem
[PatchPrefix]
public static bool Prefix(ItemUiContext __instance, MagazineClass magazine, string ammoTemplateId, ref Task __result)
{
protected override MethodBase GetTargetMethod()
if (!Plugin.InRaid() || !Settings.EnableLoadAmmo.Value)
{
return AccessTools.Method(typeof(ItemUiContext), nameof(ItemUiContext.LoadAmmoByType));
return true;
}
// This code is a mix of ItemUiContext.LoadAmmoByType, but then switching over to GridView.AcceptItem
[PatchPrefix]
public static bool Prefix(ItemUiContext __instance, MagazineClass magazine, string ammoTemplateId, ref Task __result)
InventoryControllerClass inventoryController = __instance.R().InventoryController;
EquipmentClass equipment = inventoryController.Inventory.Equipment;
List<BulletClass> ammo = [];
equipment.GetAllAssembledItems(ammo);
// Just do the first stack
BulletClass bullets = ammo.Where(a => a.TemplateId == ammoTemplateId && a.Parent.Container is not Slot)
.OrderBy(a => a.SpawnedInSession)
.ThenBy(a => a.StackObjectsCount)
.FirstOrDefault();
if (bullets != null)
{
if (!Plugin.InRaid() || !Settings.EnableLoadAmmo.Value)
{
return true;
}
InventoryControllerClass inventoryController = __instance.R().InventoryController;
EquipmentClass equipment = inventoryController.Inventory.Equipment;
List<BulletClass> ammo = [];
equipment.GetAllAssembledItems(ammo);
// Just do the first stack
BulletClass bullets = ammo.Where(a => a.TemplateId == ammoTemplateId && a.Parent.Container is not Slot)
.OrderBy(a => a.SpawnedInSession)
.ThenBy(a => a.StackObjectsCount)
.FirstOrDefault();
if (bullets != null)
{
int count = GridView.smethod_0(magazine, bullets);
__result = inventoryController.LoadMagazine(bullets, magazine, count, false);
}
else
{
__result = Task.CompletedTask;
}
return false;
int count = GridView.smethod_0(magazine, bullets);
__result = inventoryController.LoadMagazine(bullets, magazine, count, false);
}
else
{
__result = Task.CompletedTask;
}
return false;
}
}
}