Solst1c3 / SharedItemPickup

RoR2 - Gives a copy of each picked up item to every live player.
MIT License
21 stars 13 forks source link

3D Printers Infinite Dupe #1

Open Texnical opened 5 years ago

Texnical commented 5 years ago

It might be handy to mod the 3D printers to remove the randomly selected item from all players instead of the using player.

Solst1c3 commented 5 years ago

Thanks for bringing this to my attention, I completely forgot about 3D printers.

Texnical commented 5 years ago

Absolutely! I'd throw in a pull request for it, but binary diffs are frustrating to me and dll edits are still a bit outside of my comfort zone, haha. Wouldn't mind picking up some pointers from you on that!

Solst1c3 commented 5 years ago

Go for it! I definitely recommend playing around with modding the game, it is quite fun, and not as hard as it seems. You use DnSpy to edit the Assembly-CSharp.dll in the /managed folder. Most of the classes you need are in the RoR2 namespace. They're named like a dev would name them, but usually after a bit of searching you can find the class you need to edit. Dll edits are somewhat easier since you literally have the source code in front of you (unlike terraria's modloader API guesswork overrides) I recommend joining the modding discord as well: https://discord.gg/hMdjd9y

As for the issue at hand, I'm currently looking at the best way to implement the fix. So far I have 2 possible ideas:

  1. The item is taken from all players. This however can result in griefing, which was kind of the point of this mod
  2. Only the player using the printer pays their item, and only they get the resulting printed item. This is a lot harder to implement, but the ideal fix imo

I've implemented #1, but haven't tested as of yet.

Texnical commented 5 years ago

Huh, I hadn't considered #2. If you want to do that, bypass dropping the item and put it directly into the player inventory so you don't have to redo the on pickup. That'll save you the grief of working with that. Otherwise, you can tag the item and check for existence of that tag to know if it should duplicate to all living players or not, in case you still want people to be able to use the printer for other players (I do this occasionally in unmodded play)

Solst1c3 commented 5 years ago

That is indeed another option, but it might have implications, such as confusing the player, or breaking some code. I'll have to see how it turns out. The tag was what I had in mind for #2, I'm not sure of another way to do it. I do like the idea of individual printers, but shared items from chests/tri-shops. Thanks so much for your input!

Texnical commented 5 years ago

So a summary of my previous musings from Discord on how to go about implementing #2:

In PickupIndex, you'll need to add the boolean flag for whether the pickup is private / for just the specific player, and set the default value for the constructor, then you'll need an additional constructor that lets you specify a non-default value. Since only one player picking up the item is now the special case, you'll call the new constructor with the special case for 3D Printers. You may need to modify WritePickupIndex and ReadPickupIndex in GeneratedNetworkCode and OnSerialize and OnDeserialize in GenericPickupController to include the flag for netcode sync. If it's being silly in multiplayer, that may be why. In ShopTerminalBehavior, SetPickupIndex sets the item that the 3D printer will drop - call the PickupIndex constructor with the boolean flag here to set it as a property of the item dropped by the printer :) Finally, in GrantItem, check for the boolean flag on the PickupIndex to choose whether or not to foreach the pickup.

Solst1c3 commented 5 years ago

Looks like I will probably port to BepInEx and continue from there, so that will mean new repo time!

Texnical commented 5 years ago

Not just a new branch to eventually replace master? 😮

Solst1c3 commented 5 years ago

Could do that, but I feel like it needs a new mod entry in thunderstore rather than having v1 and 1.0.1 be assembly edits, and then 1.2 (or 2.0?) being a BepInEx-dependent mod 🤔 Think of the children end-users!

Texnical commented 5 years ago

Hm, yeah, a new thunderstore entry is fair for that. :)