Skip to content

Commit

Permalink
Fixed cohtml crash that can occur when the user joins instances faste…
Browse files Browse the repository at this point in the history
…r then expected, switched deprecated events to CVRGameEventSystem versions
  • Loading branch information
ddakebono committed Aug 2, 2024
1 parent 3808724 commit 89e045d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
16 changes: 8 additions & 8 deletions Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,30 @@ internal static void Initialize(HarmonyLib.Harmony modInstance)
if (_firstOnLoadComplete) return;

_firstOnLoadComplete = true;
CVRPlayerManager.Instance.OnPlayerEntityCreated += entity =>

CVRGameEventSystem.Player.OnJoinEntity.AddListener(entity =>
{
try
{
QuickMenuAPI.UserJoin?.Invoke(entity);
QuickMenuAPI.UserJoin?.Invoke(entity);
}
catch (Exception e)
{
BTKUILib.Log.Error(e);
}
};
CVRPlayerManager.Instance.OnPlayerEntityRecycled += entity =>
});

CVRGameEventSystem.Player.OnLeaveEntity.AddListener(entity =>
{
try
{
QuickMenuAPI.UserLeave?.Invoke(entity);
QuickMenuAPI.UserLeave?.Invoke(entity);
}
catch (Exception e)
{
BTKUILib.Log.Error(e);
}
};
});
});

BTKUILib.Log.Msg("Applied patches!");
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.4.0")]
[assembly: AssemblyFileVersion("2.1.4.0")]
[assembly: AssemblyVersion("2.1.5.0")]
[assembly: AssemblyFileVersion("2.1.5.0")]
[assembly: MelonInfo(typeof(BTKUILib.BTKUILib), BTKUILib.BuildInfo.Name, BTKUILib.BuildInfo.Version, BTKUILib.BuildInfo.Author)]
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPriority(-10)]
Expand Down
18 changes: 18 additions & 0 deletions UserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using System.Linq;
using System.Reflection;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Networking;
using ABI_RC.Core.Player;
using BTKUILib.UIObjects;
using BTKUILib.UIObjects.Components;
using BTKUILib.UIObjects.Objects;
using DarkRift;
using MelonLoader;
using MelonLoader.ICSharpCode.SharpZipLib.Zip;

Expand Down Expand Up @@ -130,6 +132,16 @@ private void OnMenuIsLoaded()
QuickMenuAPI.OnMenuGenerated?.Invoke(CVR_MenuManager.Instance);

BTKUILib.Log.Msg($"Setup {RootPages.Count} root pages and {CustomElements.Count} custom elements! BTKUILib is ready!");

if (NetworkManager.Instance.GameNetwork.ConnectionState != ConnectionState.Connected || CVRPlayerManager.Instance.NetworkPlayers.Count <= 0) return;

BTKUILib.Log.Msg("We're currently connected to an instance, populating playerlist with existing players...");

//Create the players that existed before cohtml was ready
foreach (var player in CVRPlayerManager.Instance.NetworkPlayers)
{
UserJoin(player);
}
}

internal void RegisterRootPage(Page rootPage)
Expand Down Expand Up @@ -163,16 +175,22 @@ internal bool AddModPage(string modName, Page page)

private void UserLeave(CVRPlayerEntity obj)
{
if (!UIUtils.IsQMReady()) return;

UIUtils.GetInternalView().TriggerEvent("btkRemovePlayer", obj.Uuid, CVRPlayerManager.Instance.NetworkPlayers.Count);
}

private void UserJoin(CVRPlayerEntity obj)
{
if (!UIUtils.IsQMReady()) return;

UIUtils.GetInternalView().TriggerEvent("btkAddPlayer", obj.Username, obj.Uuid, obj.ApiProfileImageUrl, CVRPlayerManager.Instance.NetworkPlayers.Count);
}

private void OnWorldLeave()
{
if (!UIUtils.IsQMReady()) return;

UIUtils.GetInternalView().TriggerEvent("btkLeaveWorld");
}

Expand Down

0 comments on commit 89e045d

Please sign in to comment.