akarnokd / ThePlanetCrafterMods

BepInEx+Harmony mods for the Unity/Steam game The Planet Crafter
Apache License 2.0
46 stars 28 forks source link

CheatInventoryStacking #94

Closed Manka-Muakido closed 4 months ago

Manka-Muakido commented 4 months ago

save: Custom-1.json config:


## Settings file was created by plugin (Cheat) Inventory Stacking v1.0.1.14
## Plugin GUID: akarnokd.theplanetcraftermods.cheatinventorystacking

[General]

## Produce detailed logs? (chatty)
# Setting type: Boolean
# Default value: false
DebugMode = false

## The stack size of all item types in the inventory
# Setting type: Int32
# Default value: 10
StackSize = 999

## The font size for the stack amount
# Setting type: Int32
# Default value: 25
FontSize = 25

## Should the trade rockets' inventory stack?
# Setting type: Boolean
# Default value: false
StackTradeRockets = true

## Should the shredder inventory stack?
# Setting type: Boolean
# Default value: false
StackShredder = true

## Should the Optimizer's inventory stack?
# Setting type: Boolean
# Default value: false
StackOptimizer = true

## Should the player backpack stack?
# Setting type: Boolean
# Default value: true
StackBackpack = true

## Allow stacking in Ore Extractors.
# Setting type: Boolean
# Default value: true
StackOreExtractors = true

## Allow stacking in Water Collectors.
# Setting type: Boolean
# Default value: true
StackWaterCollectors = true

## Allow stacking in Gas Extractors.
# Setting type: Boolean
# Default value: true
StackGasExtractors = true

## Allow stacking in Beehives.
# Setting type: Boolean
# Default value: true
StackBeehives = true

## Allow stacking in Biodomes.
# Setting type: Boolean
# Default value: true
StackBiodomes = true

## Allow stacking in AutoCrafters.
# Setting type: Boolean
# Default value: true
StackAutoCrafter = true

## Allow stacking in Drone Stations.
# Setting type: Boolean
# Default value: true
StackDroneStation = true

## Allow stacking in Animal Feeders.
# Setting type: Boolean
# Default value: false
StackAnimalFeeder = true

## Workaround for the limited vanilla network buffers and too big stack sizes.
# Setting type: Int32
# Default value: 1024
NetworkBufferScaling = 9024

## Maximum time allowed to run the logistics calculations per frame, approximately, in microseconds.
# Setting type: Int32
# Default value: 5000
LogisticsTimeLimit = 50000

when clicking in container button to "loot all" image

error:

If you absolutely need to use negative scaling you can use the convex MeshCollider. Scene hierarchy path "World/Sectors/Sector-Waterfalls-Behind/Decoys/Spaceship/Wall_Normal_Simple_09 (40)"
BoxColliders does not support negative scale or size.
The effective box size has been forced positive and is likely to give unexpected collision geometry.
If you absolutely need to use negative scaling you can use the convex MeshCollider. Scene hierarchy path "World/Sectors/Sector-Waterfalls-Behind/Decoys/Spaceship/Wall_Normal_Simple_09 (39)"
Couldn't create a Convex Mesh from source mesh "SM_BrickLine_09_LOD3" within the maximum polygons limit (256). The partial hull will be used. Consider simplifying your mesh.
**OverflowException: Writing past the end of the buffer
  at SpaceCraft.InventoriesHandler.DirtyInventoryClientRpc (System.Int32 size, System.Int32 inventoryId, System.Int32[] content, System.Int32[] contentIds, System.Boolean containsGeneticTraits, Unity.Netcode.ClientRpcParams clientRpcParams) [0x0023b] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.DirtyInventory (System.Int32 inventoryId, System.UInt64 clientEditing, System.Boolean ignoreEditingClient) [0x00120] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.TransferAllItemsServerRpc (System.Int32 fromInventoryId, System.Int32 toInventoryId, Unity.Netcode.ServerRpcParams serverRpcParams) [0x00194] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.__rpc_handler_509846034 (Unity.Netcode.NetworkBehaviour target, Unity.Netcode.FastBufferReader reader, Unity.Netcode.__RpcParams rpcParams) [0x00052] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at (wrapper delegate-invoke) <Module>.invoke_void_NetworkBehaviour_FastBufferReader___RpcParams(Unity.Netcode.NetworkBehaviour,Unity.Netcode.FastBufferReader,Unity.Netcode.__RpcParams)
  at Unity.Netcode.RpcMessageHelpers.Handle (Unity.Netcode.NetworkContext& context, Unity.Netcode.RpcMetadata& metadata, Unity.Netcode.FastBufferReader& payload, Unity.Netcode.__RpcParams& rpcParams) [0x00059] in <b7ef9d5b63bf4f659cb8fdbdff2c8d4e>:0 
Rethrow as Exception: Unhandled RPC exception!**

UnityEngine.DebugLogHandler:Internal_LogException_Injected(Exception, IntPtr)
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.RpcMessageHelpers:Handle(NetworkContext&, RpcMetadata&, FastBufferReader&, __RpcParams&)
Unity.Netcode.ServerRpcMessage:Handle(NetworkContext&)
Unity.Netcode.NetworkBehaviour:__endSendServerRpc(FastBufferWriter&, UInt32, ServerRpcParams, RpcDelivery)
SpaceCraft.InventoriesHandler:TransferAllItemsServerRpc(Int32, Int32, ServerRpcParams)
SpaceCraft.InventoriesHandler:TransferAllItems(Inventory, Inventory)
SpaceCraft.InventoriesHandler:AMoveAllInventoryHasBeenClicked(Inventory)
SpaceCraft.InventoryDisplayer:OnMoveAll()
UnityEngine.Events.InvokableCall:Invoke()
UnityEngine.Events.UnityEvent:Invoke()
UnityEngine.UI.Button:Press()
UnityEngine.UI.Button:OnPointerClick(PointerEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(IPointerClickHandler, BaseEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:ProcessPointerButton(ButtonState&, PointerEventData)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:ProcessPointer(PointerModel&)
UnityEngine.InputSystem.UI.InputSystemUIInputModule:Process()
UnityEngine.EventSystems.EventSystem:Update()

after this error any other transfer works anymore, need to close and open the game again

Manka-Muakido commented 4 months ago

first of all: e8df23cc-9bfe-4776-ae54-22d67d47f15a-6442-000008859e923c5f

but i "fixed" or at last i think i fixed, the error at last did not happen anymore

first the log i made:

        [HarmonyPrefix]
        [HarmonyPatch(typeof(NetworkBehaviour), "__beginSendClientRpc")]
        static bool Patch_NetworkBehaviour___beginSendClientRpc(ref FastBufferWriter __result)
        {
            logger.LogDebug("overrideBufferSizeInRpc: " + overrideBufferSizeInRpc.ToString());
            logger.LogDebug("stackSize.Value: " + stackSize?.Value.ToString());
            logger.LogDebug("stackSize.Value > 1: " + (stackSize.Value > 1).ToString());
            //overrideBufferSizeInRpc = stackSize.Value > 1;
            if (overrideBufferSizeInRpc)
            {
                var n = networkBufferScaling.Value * 1L * stackSize.Value + 65536;
                if (n > 128L * 1024 * 1024 || n < 65536L)
                {
                    n = -1L;
                }
                __result = new FastBufferWriter(1024, Unity.Collections.Allocator.Temp, (int)n);
                return false;
            }
            return true;
        }

output:

ModPlanetLoaded (2): akarnokd.theplanetcraftermods.uishowrocketcount
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: True
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: False
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: False
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: False
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: False
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
OverflowException: Writing past the end of the buffer
  at SpaceCraft.InventoriesHandler.DirtyInventoryClientRpc (System.Int32 size, System.Int32 inventoryId, System.Int32[] content, System.Int32[] contentIds, System.Boolean containsGeneticTraits, Unity.Netcode.ClientRpcParams clientRpcParams) [0x0023b] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.DirtyInventory (System.Int32 inventoryId, System.UInt64 clientEditing, System.Boolean ignoreEditingClient) [0x00120] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.TransferAllItemsServerRpc (System.Int32 fromInventoryId, System.Int32 toInventoryId, Unity.Netcode.ServerRpcParams serverRpcParams) [0x00194] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.__rpc_handler_509846034 (Unity.Netcode.NetworkBehaviour target, Unity.Netcode.FastBufferReader reader, Unity.Netcode.__RpcParams rpcParams) [0x00052] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at (wrapper delegate-invoke) <Module>.invoke_void_NetworkBehaviour_FastBufferReader___RpcParams(Unity.Netcode.NetworkBehaviour,Unity.Netcode.FastBufferReader,Unity.Netcode.__RpcParams)
  at Unity.Netcode.RpcMessageHelpers.Handle (Unity.Netcode.NetworkContext& context, Unity.Netcode.RpcMetadata& metadata, Unity.Netcode.FastBufferReader& payload, Unity.Netcode.__RpcParams& rpcParams) [0x00059] in <b7ef9d5b63bf4f659cb8fdbdff2c8d4e>:0 

for some reason in the process the stack becomes <2 in


        [HarmonyPrefix]
        [HarmonyPatch(typeof(InventoriesHandler), "RetrieveInventoryClientRpc")]
        static void Patch_InventoriesHandler_RetrieveInventoryClientRpc_Pre()
        {
            overrideBufferSizeInRpc = stackSize.Value > 1;
        }

but by the log:

[Info   :(UI) Show Rocket Counts] Counting rockets
ModPlanetLoaded (2): akarnokd.theplanetcraftermods.uishowrocketcount
[Debug  :(Cheat) Inventory Stacking] Patch_InventoriesHandler_RetrieveInventoryClientRpc_Pre: True
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: True
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
[Debug  :(Cheat) Inventory Stacking] Patch_InventoriesHandler_RetrieveInventoryClientRpc_Pre: True
[Debug  :(Cheat) Inventory Stacking] Patch_InventoriesHandler_RetrieveInventoryClientRpc_Post: False
[Debug  :(Cheat) Inventory Stacking] Patch_InventoriesHandler_RetrieveInventoryClientRpc_Post: False
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: False
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: False
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: False
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
[Debug  :(Cheat) Inventory Stacking] overrideBufferSizeInRpc: False
[Debug  :(Cheat) Inventory Stacking] stackSize.Value: 999
[Debug  :(Cheat) Inventory Stacking] stackSize.Value > 1: True
OverflowException: Writing past the end of the buffer
  at SpaceCraft.InventoriesHandler.DirtyInventoryClientRpc (System.Int32 size, System.Int32 inventoryId, System.Int32[] content, System.Int32[] contentIds, System.Boolean containsGeneticTraits, Unity.Netcode.ClientRpcParams clientRpcParams) [0x0023b] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.DirtyInventory (System.Int32 inventoryId, System.UInt64 clientEditing, System.Boolean ignoreEditingClient) [0x00120] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.TransferAllItemsServerRpc (System.Int32 fromInventoryId, System.Int32 toInventoryId, Unity.Netcode.ServerRpcParams serverRpcParams) [0x00194] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at SpaceCraft.InventoriesHandler.__rpc_handler_509846034 (Unity.Netcode.NetworkBehaviour target, Unity.Netcode.FastBufferReader reader, Unity.Netcode.__RpcParams rpcParams) [0x00052] in <87933cf5dadd4ce88b89709520a3779c>:0 
  at (wrapper delegate-invoke) <Module>.invoke_void_NetworkBehaviour_FastBufferReader___RpcParams(Unity.Netcode.NetworkBehaviour,Unity.Netcode.FastBufferReader,Unity.Netcode.__RpcParams)
  at Unity.Netcode.RpcMessageHelpers.Handle (Unity.Netcode.NetworkContext& context, Unity.Netcode.RpcMetadata& metadata, Unity.Netcode.FastBufferReader& payload, Unity.Netcode.__RpcParams& rpcParams) [0x00059] in <b7ef9d5b63bf4f659cb8fdbdff2c8d4e>:0 
Rethrow as Exception: Unhandled RPC exception!

code:

        [HarmonyPrefix]
        [HarmonyPatch(typeof(InventoriesHandler), "RetrieveInventoryClientRpc")]
        static void Patch_InventoriesHandler_RetrieveInventoryClientRpc_Pre()
        {
            overrideBufferSizeInRpc = stackSize.Value > 1;
            logger.LogDebug("Patch_InventoriesHandler_RetrieveInventoryClientRpc_Pre: " + overrideBufferSizeInRpc.ToString());
        }

        [HarmonyPostfix]
        [HarmonyPatch(typeof(InventoriesHandler), "RetrieveInventoryClientRpc")]
        static void Patch_InventoriesHandler_RetrieveInventoryClientRpc_Post()
        {
            overrideBufferSizeInRpc = false;
            logger.LogDebug("Patch_InventoriesHandler_RetrieveInventoryClientRpc_Post: " + overrideBufferSizeInRpc.ToString());
        }

this guy is the problem:

        [HarmonyPostfix]
        [HarmonyPatch(typeof(InventoriesHandler), "RetrieveInventoryClientRpc")]
        static void Patch_InventoriesHandler_RetrieveInventoryClientRpc_Post()
        {
            overrideBufferSizeInRpc = false;
        }

anyway:

so i just set by the method again(commented line)....probably not right....but hey.......it work.....i think "fixed"

        [HarmonyPrefix]
        [HarmonyPatch(typeof(NetworkBehaviour), "__beginSendClientRpc")]
        static bool Patch_NetworkBehaviour___beginSendClientRpc(ref FastBufferWriter __result)
        {
            overrideBufferSizeInRpc = stackSize.Value > 1;
            //could be stackSize.Value > 1 but...the var already here so....
            if (overrideBufferSizeInRpc)
            {
                var n = networkBufferScaling.Value * 1L * stackSize.Value + 65536;
                if (n > 128L * 1024 * 1024 || n < 65536L)
                {
                    n = -1L;
                }
                __result = new FastBufferWriter(1024, Unity.Collections.Allocator.Temp, (int)n);
                return false;
            }
            return true;
        }

well it fixed the problem but after any transfer using that button i cant interact with anything anymore, must exit and load the game again, but idk if is because of this mod.....but its better than the exception

akarnokd commented 4 months ago

Thanks for the report.

Fixed in v1.0.1.19 (v488+), but only for the dev branch.