-
-
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
base: upcoming
Are you sure you want to change the base?
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 |
#2298, #252