Never had an issue with this code until last nights update.
Tested it with the plain example on Docs.oxidemod.org and still does nothing. No errors or compiling issues. Just nothing.
What has changed? or is this just plain broken?
Code:private object CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount) { var player = itemCrafter.GetComponent<BasePlayer>(); var item = bp.GetComponent<ItemDefinition>(); if (permission.UserHasPermission(player.UserIDString, Perm)) return true; if (configFile.AllowedItems.ContainsKey(item.shortname)) { if(configFile.AllowedItems[item.shortname]) return true; } if (configFile.HideMessage.SendMessage) PrintToChat(player, Lang(Message.CraftingDisabled, player.UserIDString)); return false; }
Fixed CanCraft broken or changed?
Discussion in 'Rust Development' started by Mr_Jeff, Dec 8, 2017.
-
Wulf Community Admin
No, the hook is not broken, the calling of the correct hook is just broken right now, which CanCraft has two different signatures.
-
oh, so this is fixable or do we have to wait?
-
Wulf Community Admin
-
Ok, cheers
-
So, the deal is - this hook on call drops NRE, no matter what the code is.
Even this code below dropes with NRE.
Code:object CanCraft(PlayerBlueprints bps, ItemDefinition itemDef, int skinId) => true;
Code:Failed to call hook 'CanCraft' on plugin 'QuarryCraft v1.0.0' (InvalidCastException: Cannot cast from source type to destination type.) at Oxide.Plugins.QuarryCraft.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00000] in <filename unknown>:0
-
Not sure, but shouldn't you use bool instead of object?
Oxide.Docs/hooks_player.md at d42a2e692ec35565f5e65b2f0e0b45bfde2e5e41 · OxideMod/Oxide.Docs · GitHub -
Wulf Community Admin
-
k. Sorry for double-posting, didn't saw this thread =^-^=
[DOUBLEPOST=1512834470][/DOUBLEPOST]
No, really?
If you would look into the code itself you would see that the response of the hook are object, that converted to the bool =3 -
-
Wulf Community Admin
This should be fixed in the latest Oxide build now by the way.
-
Had a major issue leading to players exploiting on our server and just wanted to bring this to the table in case it is of any interest to someone. Below are my quick findings for the two CanCraft methods. I know there are several plugins using the old definition out there and servers using this may be suffering from this.
Code:/** * Assuming this definition is the wrong and outdated one (still present in API description). * Returning true allows any item to be crafted by double clicking item in inventory standing at workbench as long as player has the blueprint. No resources needed. * Since its a hook I'd say it would be a race condition for all plugins with this behaviour so assuming it is not indended to work like this. */ bool CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount) { Puts("Original craft"); return true; } /** * This (updated definition as understand it) works, kinda. Returning true allows items to be crafted ONLY if resources and blueprints are met. * There is one catch tho. It seem to be executed twice once criteria is met. * In my case I'm notifying player with a message but it is not very desired to send two messages just because the method gets executed twice. */ object CanCraft(PlayerBlueprints bps, ItemDefinition itemDef, int skinId) { Puts("Updated craft"); return true; }
-
Wulf Community Admin
-
-
Wulf Community Admin
-
-
Wulf Community Admin