-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix drop boss bag hook not working properly #131
Conversation
gonna make this pull request draft as i encoutered some errors with HookResult while testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR and apologies for delays, usually don't get time to work on this project.
Have a question in relation to the new cancel code - see review comment.
Typically with OTAPI hooks, "HookResult.Cancel" would not run the event/action, so i currently feel this may need extra adjustments or we consider that changing to DropItemLocalPerClientAndSetNPCMoneyTo0
warrants a relook at how the event occurs.
Few thoughts on the direction, pending additional clarification wrt review comment:
- If we want to still use
return -1;
some additional IL could be injected to insert aif(num == -1) return;
. This will then be able to prevent new items being created, and packets being sent. - maybe less ideal - change focus from the
NewItem
call, to aroundDropItemLocalPerClientAndSetNPCMoneyTo0
instead, and if cancelled, the consumer is responsible for distributing loot (customised, or not).
e.g. patch instead of modify (not monomod runtime hook), or via the new static hooks (WIP, may be expanded to full coverage)
{ | ||
#if TerrariaServer_EntitySourcesActive || Terraria_EntitySourcesActive || tModLoader_EntitySourcesActive | ||
return Terraria.Item.NewItem(Source, args.X, args.Y, args.Width, args.Height, args.Type, args.Stack, args.NoBroadcast, args.Pfix, args.NoGrabDelay, args.ReverseLookup); | ||
#else | ||
return Terraria.Item.NewItem(args.X, args.Y, args.Width, args.Height, args.Type, args.Stack, args.NoBroadcast, args.Pfix, args.NoGrabDelay, args.ReverseLookup); | ||
#endif | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i may not be up to scratch with these hooks nowadays, but if it was cancelled, should a new item be created still? And if so, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to how "HookResult.Cancel" tend to do, we should not let the new item be created, and i completely agree with that. Sorry, it was because of my lack of knowledge that i overlooked it.
Thanks for your reply. Don't worry, the delays were not bothered me too much because i had more time to improve my IL editing skill. At the time i submitted this pr, i don't have much experience in this field but somehow the code worked and here we are lol.
Ah, this is a good improvement and easy to implement too!
A great idea to me. I personally choose this one. Some example code for the function you mentioned would help a lot! And i need some clarifications about the final code to check if i get the idea right:
|
i'm happy with it |
No problems at all and no need to be sorry, we all start somewhere!
These were just mainly ideas, but in terms of a patch/hook, just the single line would be enough as you have, however I have also come up with another idea which i think might be the best way:
foreach (var csr in new[] {
modder.GetILCursor(() => (new Terraria.NPC()).DropItemInstanced(default, default, 0, 0, false)),
modder.GetILCursor(() => Terraria.GameContent.ItemDropRules.CommonCode.DropItemLocalPerClientAndSetNPCMoneyTo0(default, default, default, default))
})
mm.Module.GetType("Terraria.GameContent.ItemDropRules.CommonCode").CreateHooks(mm); I think this solution will then allow NPC 548 / Drop medals to still function, along side the new hook and subsequently plugins that currently depend on this API. nb. have granted workflow access, and seems the current stuff doesn't compile. |
I don't understand this really well. Can you please explain this further? |
This is your existing code which creates "static hooks" for each method within |
thanks for your contribution, I am planning on including this in the release im working on now. unfortunately though there are some additional changes i would like to see, such as moving back to the original code and location (applying the foreach over the top), however this is a very simple thing to do from my end and to save you the git troubles i will utilise the co-author feature to ensure your work is attributed and appreciated! |
see fix drop boss bag hook not working properly #131 Co-Authored-By: Sors <64196796+sors89@users.noreply.github.com>
#2298, #252