Switch to prefix patch

This commit is contained in:
CactusPie 2023-11-20 11:28:27 +01:00
parent 92ed9b1748
commit 087714d394

View File

@ -16,8 +16,8 @@ namespace CactusPie.ContainerQuickLoot
return method; return method;
} }
[PatchPostfix] [PatchPrefix]
public static void PatchPostfix( public static bool PatchPrefix(
ref GStruct375<GInterface275> __result, ref GStruct375<GInterface275> __result,
object __instance, object __instance,
Item item, Item item,
@ -26,13 +26,18 @@ namespace CactusPie.ContainerQuickLoot
GClass2585.EMoveItemOrder order, GClass2585.EMoveItemOrder order,
bool simulate) bool simulate)
{ {
if (order == GClass2585.EMoveItemOrder.MoveToAnotherSide) // We only execute this for ctrl+click move
if (order != GClass2585.EMoveItemOrder.MoveToAnotherSide)
{ {
return true;
}
GameWorld gameWorld = Singleton<GameWorld>.Instance; GameWorld gameWorld = Singleton<GameWorld>.Instance;
// If gameWorld is null that means the game is currently not in progress, for instance you're in your hideout
if (gameWorld == null) if (gameWorld == null)
{ {
return; return true;
} }
Player player = GetLocalPlayerFromWorld(gameWorld); Player player = GetLocalPlayerFromWorld(gameWorld);
@ -40,7 +45,7 @@ namespace CactusPie.ContainerQuickLoot
if (inventory == null) if (inventory == null)
{ {
return; return true;
} }
ContainerCollection containerCollection = null; ContainerCollection containerCollection = null;
@ -54,16 +59,14 @@ namespace CactusPie.ContainerQuickLoot
if (targetContainer == null || containerCollection == null) if (targetContainer == null || containerCollection == null)
{ {
return; return true;
} }
foreach (IContainer collectionContainer in containerCollection.Containers) foreach (IContainer collectionContainer in containerCollection.Containers)
{ {
var container = collectionContainer as GClass2318; if (!(collectionContainer is GClass2318 container))
if (container == null)
{ {
return; return true;
} }
// ReSharper disable once PossibleMultipleEnumeration // ReSharper disable once PossibleMultipleEnumeration
@ -81,7 +84,7 @@ namespace CactusPie.ContainerQuickLoot
GStruct375<GClass2597> moveResult = GClass2585.Move(item, location, controller, simulate); GStruct375<GClass2597> moveResult = GClass2585.Move(item, location, controller, simulate);
if (moveResult.Failed) if (moveResult.Failed)
{ {
return; return true;
} }
if (!moveResult.Value.ItemsDestroyRequired) if (!moveResult.Value.ItemsDestroyRequired)
@ -89,9 +92,10 @@ namespace CactusPie.ContainerQuickLoot
__result = moveResult.Cast<GClass2597, GInterface275>(); __result = moveResult.Cast<GClass2597, GInterface275>();
} }
return; return false;
}
} }
return true;
} }
private static Player GetLocalPlayerFromWorld(GameWorld gameWorld) private static Player GetLocalPlayerFromWorld(GameWorld gameWorld)