Oxide.Rust icon indicating copy to clipboard operation
Oxide.Rust copied to clipboard

Fixing NPE issue of OnPlayerSpawn hook when caller returns non-null

Open saturna opened this issue 1 year ago • 3 comments

Fixing NPE issue of OnPlayerSpawn hook when caller returns non-null

Forum Post Link: https://umod.org/community/hooks-extended/51527-onplayerspawn-hook-bug-npe?page=1#post-1

Context: OnPlayerSpawn hook call returns null to the caller if return value is not-null. This will always cause NPE and a player will not be able to spawn onto the server.

In order to allow for SpawnNewPlayer default behavior modifications, BasePlayer needs to be returned instead.

Let me know if you need test evidence.

saturna avatar Dec 12 '23 05:12 saturna

Is there a reason why this PR isn't being picked up? It's been several weeks.

saturna avatar Jan 04 '24 21:01 saturna

Hey, what happens when you don't initialize the BasePlayer in the hook call. It'll just return a ghost player which I assume will cause issues later on in the joining process no?

If someone returns non-null, is there anything we should be calling before returning the BasePlayer object?

MrBlue avatar Jan 29 '24 04:01 MrBlue

If someone doesn't initialize the base player it won't make any difference because that would require to return a non-null value which will cause the exception.

My understanding is that it's up to the caller to initialize BasePlayer however they want - meaning there isn't necessary anything that SHOULD be called.

If this helps I can dig out my init code from a plugin I wrote using this hook with the patch in place (the proposed DLL patch) that made this hook usable for me.

Other than that this issue is very easy to reproduce and makes this hook somewhat useless without my proposed fix.

saturna avatar Feb 04 '24 03:02 saturna

Merged, thanks!

MrBlue avatar Jul 01 '24 05:07 MrBlue