Skip to content

spawn fix#153

Closed
1312255201 wants to merge 6 commits intoExMod-Team:devfrom
1312255201:patch-1
Closed

spawn fix#153
1312255201 wants to merge 6 commits intoExMod-Team:devfrom
1312255201:patch-1

Conversation

@1312255201
Copy link
Copy Markdown

Description

Describe the changes
Added some null judgments before the code of merge #148

What is the current behavior? (You can also link to an open issue here)
Throwing an error message when the player enters the server

[2024-10-25 16:40:27.376 +08:00] [STDOUT] NullReferenceException: Object reference not set to an instance of an object
[2024-10-25 16:40:27.378 +08:00] [STDOUT]   at (wrapper dynamic-method) PlayerRoles.PlayerRoleManager.PlayerRoles.PlayerRoleManager.InitializeNewRole_Patch0(PlayerRoles.PlayerRoleManager,PlayerRoles.RoleTypeId,PlayerRoles.RoleChangeReason,PlayerRoles.RoleSpawnFlags,Mirror.NetworkReader)
[2024-10-25 16:40:27.378 +08:00] [STDOUT]   at PlayerRoles.PlayerRoleManager.get_CurrentRole () [0x00008] in <0594d213d02e488398c476c559e1ee8e>:0
[2024-10-25 16:40:27.378 +08:00] [STDOUT]   at PlayerRoles.RoleSyncInfoPack.WritePlayers (Mirror.NetworkWriter writer) [0x00026] in <0594d213d02e488398c476c559e1ee8e>:0
[2024-10-25 16:40:27.379 +08:00] [STDOUT]   at PlayerRoles.PlayerRolesNetUtils.WriteRoleSyncInfoPack (Mirror.NetworkWriter writer, PlayerRoles.RoleSyncInfoPack info) [0x00000] in <0594d213d02e488398c476c559e1ee8e>:0
[2024-10-25 16:40:27.379 +08:00] [STDOUT]   at (wrapper delegate-invoke) System.Action`2[Mirror.NetworkWriter,PlayerRoles.RoleSyncInfoPack].invoke_void_T1_T2(Mirror.NetworkWriter,PlayerRoles.RoleSyncInfoPack)
[2024-10-25 16:40:27.379 +08:00] [STDOUT]   at Mirror.NetworkWriter.Write[T] (T value) [0x00023] in <30fac3f6504c4ec7842b66bf8ea075a1>:0
[2024-10-25 16:40:27.379 +08:00] [STDOUT]   at Mirror.NetworkConnection.Send[T] (T message, System.Int32 channelId) [0x00006] in <30fac3f6504c4ec7842b66bf8ea075a1>:0
[2024-10-25 16:40:27.379 +08:00] [STDOUT]   at PlayerRoles.PlayerRolesNetUtils.HandleSpawnedPlayer (ReferenceHub hub) [0x0001b] in <0594d213d02e488398c476c559e1ee8e>:0
[2024-10-25 16:40:27.380 +08:00] [STDOUT]   at (wrapper delegate-invoke) System.Action`1[ReferenceHub].invoke_void_T(ReferenceHub)
[2024-10-25 16:40:27.380 +08:00] [STDOUT]   at (wrapper dynamic-method) ReferenceHub.ReferenceHub.Start_Patch1(ReferenceHub)

The server encountered a situation where players can only see a portion of the player models. For example, if there are 12 surviving players, they can only spectate two of them.
What is the new behavior? (if this is a feature change)
Players who enter the server now can view all alive players

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
No

Other information:
I cannot determine if this fix will cause other errors, so it may be necessary to continue monitoring it or adopt other methods to address this issue.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentations

Submission checklist

  • I have checked the project can be compiled
  • I have tested my changes and it worked as expected

Patches (if there are any changes related to Harmony patches)

  • I have checked no IL patching errors in the console

Other

  • Still requires more testing

@1312255201
Copy link
Copy Markdown
Author

I don't think this is a solution to the root problem,I'm ready to close it.

@1312255201 1312255201 closed this Oct 25, 2024
@VALERA771
Copy link
Copy Markdown

Iirc local hub is never null (also no need to check if it's null) and ref hub of not null player also always not null. Can you remove some null checks and see if something changes?

@1312255201
Copy link
Copy Markdown
Author

I tried to directly remove this piece of code, and it worked fine.

                    // if (player.ReferenceHub == ReferenceHub.LocalHub)
                    //     goto skip;
                    new(OpCodes.Ldloc_S, player.LocalIndex),
                    new(OpCodes.Callvirt, PropertyGetter(typeof(API.Features.Player), nameof(API.Features.Player.ReferenceHub))),
                    new(OpCodes.Callvirt, PropertyGetter(typeof(ReferenceHub), nameof(ReferenceHub.LocalHub))),
                    new(OpCodes.Call, Method(typeof(ReferenceHub), "op_Equality")),
                    new(OpCodes.Brtrue_S, skip),

@1312255201
Copy link
Copy Markdown
Author

But I don't have a local deployment of the Exiled compilation environment, so I can only compile through actions and haven't done more testing. Essentially, this pull request also directly skips this piece of code, making no substantial difference, so I closed it.

@VALERA771
Copy link
Copy Markdown

I tried to directly remove this piece of code, and it worked fine.

                    // if (player.ReferenceHub == ReferenceHub.LocalHub)
                    //     goto skip;
                    new(OpCodes.Ldloc_S, player.LocalIndex),
                    new(OpCodes.Callvirt, PropertyGetter(typeof(API.Features.Player), nameof(API.Features.Player.ReferenceHub))),
                    new(OpCodes.Callvirt, PropertyGetter(typeof(ReferenceHub), nameof(ReferenceHub.LocalHub))),
                    new(OpCodes.Call, Method(typeof(ReferenceHub), "op_Equality")),
                    new(OpCodes.Brtrue_S, skip),

Yeah, this check was added and seems to be a cause of problem. But if we remove it, Spawned event is calling for LocalHub which is not goof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants