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