Skip to content

Commit 8451245

Browse files
committed
Experimental late join support
1 parent 7cf1d80 commit 8451245

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
**Additions**:
44
- Added a keyboard shortcut (CTRL+C) to the lobby menu for easy copying of a steam lobby link
5+
- Added support for late joining
56

67
# 1.0.2
78

Source/Entrypoint.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,44 @@ private static void SetupDefaultSceneUniversal()
148148
}
149149

150150
/// <summary>
151-
/// <see cref="GameDirector"/> is always present in the `Main` scene, so we use it as entrypoint
151+
/// <see cref="GameDirector"/> is always present in the `Main` scene, so we use it as a base entrypoint
152152
/// </summary>
153153
[HarmonyPatch(typeof(GameDirector), nameof(GameDirector.Start))]
154154
[HarmonyPostfix]
155155
private static void OnStartup(GameDirector __instance)
156156
{
157157
VRInputSystem.instance.ActivateInput();
158-
158+
159159
if (RunManager.instance.levelCurrent == RunManager.instance.levelMainMenu ||
160-
RunManager.instance.levelCurrent == RunManager.instance.levelLobbyMenu ||
161160
RunManager.instance.levelCurrent == RunManager.instance.levelSplashScreen)
162161
OnStartupMainMenu();
163-
else
164-
OnStartupInGame();
162+
163+
// We have to do some magic for the Lobby Menu level because of ✨late join✨
164+
}
165+
166+
/// <summary>
167+
/// Special custom entrypoint since we might swap levels shortly after GameDirector startup (Late join)
168+
/// </summary>
169+
[HarmonyPatch(typeof(LobbyMenuOpen), nameof(LobbyMenuOpen.Awake))]
170+
[HarmonyPostfix]
171+
private static void OnStartLobbyMenu()
172+
{
173+
if (RunManager.instance.levelCurrent == RunManager.instance.levelLobbyMenu)
174+
OnStartupMainMenu();
175+
}
176+
177+
/// <summary>
178+
/// Use the Truck Start Room module to detect if we are in the actual game
179+
/// </summary>
180+
[HarmonyPatch(typeof(StartRoom), nameof(StartRoom.Start))]
181+
[HarmonyPostfix]
182+
private static void OnStartTruck(StartRoom __instance)
183+
{
184+
// The menu levels also have the truck so we should just ignore them
185+
if (__instance.name is "Start Room - Main Menu(Clone)" or "Start Room - Lobby Menu(Clone)")
186+
return;
187+
188+
OnStartupInGame();
165189
}
166190

167191
[HarmonyPatch(typeof(SplashScreen), nameof(SplashScreen.Start))]

Source/Managers/VRSession.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,8 @@ private void InitializeVRSession()
6666

6767
// Initialize VR HUD
6868
HUD = global::HUD.instance.gameObject.AddComponent<GameHud>();
69+
70+
// Initialize Handheld Map (if it wasn't created yet)
71+
VRMapTool.Create();
6972
}
7073
}

Source/Patches/Player/MapToolPatches.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ internal static class MapToolPatches
2121
[HarmonyPostfix]
2222
private static void OnMapToolCreated(MapToolController __instance)
2323
{
24-
if (!__instance.PlayerAvatar.isLocal || VRSession.Instance is not {} session)
25-
return;
26-
27-
__instance.transform.parent.parent = session.Player.MapParent;
28-
__instance.transform.parent.localPosition = Vector3.zero;
29-
__instance.transform.parent.localRotation = Quaternion.identity;
30-
__instance.gameObject.AddComponent<VRMapTool>();
24+
VRMapTool.Create();
3125
}
3226

3327
/// <summary>

Source/Player/VRMapTool.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using RepoXR.Managers;
1+
using System.Linq;
2+
using RepoXR.Managers;
23
using UnityEngine;
34

45
namespace RepoXR.Player;
@@ -18,6 +19,18 @@ public class VRMapTool : MonoBehaviour
1819
private RectTransform statsRect;
1920

2021
public bool leftHanded;
22+
23+
public static void Create()
24+
{
25+
var tool = FindObjectsOfType<MapToolController>().FirstOrDefault(t => t.PlayerAvatar.isLocal);
26+
if (instance != null || VRSession.Instance is not { } session || tool is null || !tool.PlayerAvatar.isLocal)
27+
return;
28+
29+
tool.transform.parent.parent = session.Player.MapParent;
30+
tool.transform.parent.localPosition = Vector3.zero;
31+
tool.transform.parent.localRotation = Quaternion.identity;
32+
tool.gameObject.AddComponent<VRMapTool>();
33+
}
2134

2235
private void Awake()
2336
{

0 commit comments

Comments
 (0)