tanukinomori / DSPMod

3 stars 5 forks source link

AutoReplenish Exception and Possible Fix #16

Closed dpthorngren closed 2 years ago

dpthorngren commented 2 years ago

Thanks for making these mods, I use both AutoReplenishItem and CruiseAssist and find them very helpful!

The Error

When playing the game, opening a storage building results in an exception and does not withdraw items as usual. The error is:

System.MissingMethodException int StorageComponent.TakeItem(int,int)
  at UIStorageWindow.OnOpen() [...]
  at ManualBehavior._Open() [...]

It seems that the arguments required for StorageComponent.TakeItem() have changed. I think this occurred as a result of the "Icarus Evolution" major update (v0.9.24.11182), but it might have been earlier. The new signature is StorageComponent.TakeItem(int itemId, int count, out int inc). I think inc may indicate the proliferator level of the items that were removed, but I'm not certain. At any rate, a similar change to StorageComponent.AddItem() is also present. The new signature for that is StorageComponent.AddItem(int itemId, int count, int inc, out int remainInc).

Proposed Solution

Recording the output inc and passing it to AddItem fixes the error and appears to work fine in my tests. This can be done by replacing lines 27-28 in Patch_UIStorageWindow_OnOpen.cs with the following:

var takeItemCount = storageComponent.TakeItem(itemId, requireItemCount, out int inc);
GameMain.mainPlayer.package.AddItem(itemId, takeItemCount, inc, out int remainInc);

This solution ignores the output remainInc, but I haven't noticed any issues with that.

dpthorngren commented 2 years ago

The bug is now fixed in version 0.0.2. Thank you!