Skip to content

Commit

Permalink
[OSC]
Browse files Browse the repository at this point in the history
- Changed log that was tripping lum's error detection
[Instances]
- Added DeepLink compatibility (Instances will no longer skip the deep link urls to start the game in a certain instance)
- Fixed Obsolete Game code
  • Loading branch information
kafeijao committed Sep 15, 2024
1 parent 6cffb84 commit faa1530
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Instances/Integrations/ChatBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ private static void HandleRestart(ChatBox.API.ChatBoxMessage chatBoxMessage) {

private static void HandleRejoin(ChatBox.API.ChatBoxMessage chatBoxMessage) {
if (chatBoxMessage.Message.StartsWith(RejoinCommandPrefix) && !string.IsNullOrEmpty(MetaPort.Instance.CurrentInstanceId)) {
ABI_RC.Core.Networking.IO.Instancing.Instances.SetJoinTarget(MetaPort.Instance.CurrentInstanceId,
MetaPort.Instance.CurrentWorldId);
ABI_RC.Core.Networking.IO.Instancing.Instances.SetJoinTarget(MetaPort.Instance.CurrentInstanceId);
}
}

Expand Down
42 changes: 35 additions & 7 deletions Instances/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using ABI_RC.Core.Savior;
using ABI_RC.Core.Savior.SceneManagers;
using ABI_RC.Core.UI;
using ABI_RC.Core.Util;
using ABI_RC.Systems.GameEventSystem;
using ABI_RC.Systems.Movement;
using ABI_RC.Systems.UI;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class Instances : MelonMod {
public const int TeleportToLocationTimeout = 5;

public const string InstanceRestartConfigArg = "--instances-owo-what-is-dis";
public const string InstanceSkipDeepLink = "--instances-skip-deep-link";


// Config File Saving
Expand Down Expand Up @@ -494,7 +496,7 @@ private static IEnumerator LoadIntoLastInstance(string instanceId, bool isInitia
// User clicked on an instance that is no longer valid, or the initial instance we created borked
MelonLogger.Msg($"Instance {instanceId} has not been found.");
CohtmlHud.Instance.ViewDropTextImmediate("", "Instance not Available",
"The instance you're trying to join doesn't was deleted or you don't have permission...");
"The instance you're trying to join doesn't was deleted or you don't have permission...", "", false);
}
// Let's invalidate the attempted instance
InvalidateInstance(instanceId);
Expand All @@ -505,7 +507,7 @@ private static IEnumerator LoadIntoLastInstance(string instanceId, bool isInitia

// Load into the instance
MelonLogger.Msg($"The previous instance {instanceDetails.Data.Name} is still up! Attempting to join...");
ABI_RC.Core.Networking.IO.Instancing.Instances.SetJoinTarget(instanceDetails.Data.Id, instanceDetails.Data.World.Id);
ABI_RC.Core.Networking.IO.Instancing.Instances.SetJoinTarget(instanceDetails.Data.Id);
}

_isChangingInstance = false;
Expand Down Expand Up @@ -592,7 +594,7 @@ private static IEnumerator CreateAndJoinOnlineInstance() {

// Load into the instance
MelonLogger.Msg($"The created {instanceDetails.Data.Name} is {(attemptNum > 1 ? "finally" : "")} up! Attempting to join...");
ABI_RC.Core.Networking.IO.Instancing.Instances.SetJoinTarget(instanceDetails.Data.Id, instanceDetails.Data.World.Id);
ABI_RC.Core.Networking.IO.Instancing.Instances.SetJoinTarget(instanceDetails.Data.Id);

// We succeeded so lets break the coroutine here
yield break;
Expand Down Expand Up @@ -674,16 +676,43 @@ private static void Initialize() {
Content.LoadIntoWorld(MetaPort.Instance.homeWorldGuid);
}

private static bool HasCommandLineArg(string arg)
{
foreach (string commandLineArg in Environment.GetCommandLineArgs()) {
if (commandLineArg.Contains(arg))
{
return true;
}
}
return false;
}

[HarmonyPatch]
internal class HarmonyPatches {

[HarmonyPrefix]
[HarmonyPatch(typeof(LoginRoom), nameof(LoginRoom.LoadPlayerChosenContent))]
public static bool Before_LoginRoom_LoadPlayerChosenContent() {
public static bool Before_LoginRoom_LoadPlayerChosenContent()
{
// Prevent the initial joining to the offline home world
try {
if (!_skipInitialLoad) {
_skipInitialLoad = true;

// Prevent running our stuff if the game is starting with a DeepLink Url
if (CheckVR.Instance.hasDeepLinkUrl && !DeepLinkHelper._consumedJoinInstanceLaunchArg)
{
if (HasCommandLineArg(InstanceSkipDeepLink))
{
MelonLogger.Msg("Skipping the DeepLink Url because the game is is starting from an Instances Restart");
}
else
{
MelonLogger.Msg("Skipping Instances initial join because the game is starting with a DeepLink Url");
return true;
}
}

// Still load the avatar
AssetManagement.Instance.LoadLocalAvatar(MetaPort.Instance.currentAvatarGuid);
// We're assuming we already authenticated (we wouldn't be reaching here otherwise)
Expand Down Expand Up @@ -760,10 +789,9 @@ public static void After_RichPresence_ReadPresenceUpdateFromNetwork() {
[HarmonyPatch(typeof(MetaPort), nameof(MetaPort.Start))]
public static void After_MetaPort_Start() {
// Look for arguments set by a previous restart of the game by the Instances Mod
foreach (var commandLineArg in Environment.GetCommandLineArgs()) {
if (!commandLineArg.Contains(InstanceRestartConfigArg)) continue;
if (HasCommandLineArg(InstanceRestartConfigArg))
{
MetaPort.Instance.matureContentAllowed = true;
break;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Instances/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ internal static IEnumerator RestartCVR(bool switchPlatform) {
envArguments.Add(Instances.InstanceRestartConfigArg);
}

envArguments.Add(Instances.InstanceSkipDeepLink);

// Handle platform switches
if (switchPlatform) {
if (envArguments.Contains(VREnvArg)) {
Expand Down
2 changes: 1 addition & 1 deletion Instances/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace Kafe.Instances.Properties;
internal static class AssemblyInfoParams {
public const string Version = "1.0.19";
public const string Version = "1.0.20";
public const string Author = "kafeijao";
public const string BTKUILibName = "BTKUILib";
public const string ChatBoxName = "ChatBox";
Expand Down
4 changes: 2 additions & 2 deletions Instances/Properties/CVRMG.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_id": 133,
"name": "Instances",
"modversion": "1.0.19",
"modversion": "1.0.20",
"gameversion": "2024r176",
"loaderversion": "v0.6.1",
"modtype": "Mod",
Expand All @@ -16,6 +16,6 @@
"requirements": ["[BTKUILib](https://api.cvrmg.com/v1/mods/download/113)"],
"downloadlink": "https://github.com/kafeijao/Kafe_CVR_Mods/releases/download/r72/Instances.dll",
"sourcelink": "https://github.com/kafeijao/Kafe_CVR_Mods/tree/master/Instances",
"changelog": "- Fixed for 2024r176",
"changelog": "- Added DeepLink compatibility (Instances will no longer skip the deep link urls to start the game in a certain instance)\n- Updated obsolete code",
"embedcolor": "16C60C"
}
8 changes: 7 additions & 1 deletion OSC/Events/Avatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ internal static async void OnAnimatorManagerUpdate(AvatarAnimatorManager animato
var userGuid = MetaPort.Instance.ownerId;
var avatarGuid = MetaPort.Instance.currentAvatarGuid;

if (!Guid.TryParse(avatarGuid, out Guid _))
{
MelonLogger.Msg($"Found an invalid avatar ID {avatarGuid}, ignoring the setup...");
return;
}

string avatarName = null;

// Look in cache for the avatar name
Expand All @@ -103,7 +109,7 @@ internal static async void OnAnimatorManagerUpdate(AvatarAnimatorManager animato
// If the avatar name is still null, just give up
if (avatarName == null) {
JsonConfigOsc.ClearCurrentAvatarConfig();
MelonLogger.Msg($"[Error] The config for the avatar {avatarGuid} won't be generated.");
MelonLogger.Msg($"Failed to get the avatar name. The config for the Avatar ID {avatarGuid} won't be generated.");
}
// Otherwise create the config! (if needed)
else {
Expand Down
2 changes: 1 addition & 1 deletion OSC/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace Kafe.OSC.Properties;
internal static class AssemblyInfoParams {
public const string Version = "1.1.14";
public const string Version = "1.1.15";
public const string Author = "kafeijao";
public const string ChatBoxName = "ChatBox";
public const string CVRParamLibName = "CVRParamLib";
Expand Down
4 changes: 2 additions & 2 deletions OSC/Properties/CVRMG.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_id": 79,
"name": "OSC",
"modversion": "1.1.14",
"modversion": "1.1.15",
"gameversion": "2024r176",
"loaderversion": "v0.6.1",
"modtype": "Mod",
Expand All @@ -17,6 +17,6 @@
"requirements": [],
"downloadlink": "https://github.com/kafeijao/Kafe_CVR_Mods/releases/download/r72/OSC.dll",
"sourcelink": "https://github.com/kafeijao/Kafe_CVR_Mods/tree/master/OSC",
"changelog": "- Fixed for 2024r176",
"changelog": "- Changed a log to prevent being picked up by lum as an error when it's not",
"embedcolor": "16C60C"
}

0 comments on commit faa1530

Please sign in to comment.