[ChatBoxExtensions] Updated for the latest API.

This commit is contained in:
kafeijao 2023-04-26 19:38:28 +01:00
parent 62eb612d73
commit 37ad5a8f9c
No known key found for this signature in database
GPG key ID: E99978723E454B4C
9 changed files with 88 additions and 40 deletions

View file

@ -1,2 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk"/>
<Project Sdk="Microsoft.NET.Sdk">
<!-- Didn't put in the Directory.Build.props because it spams funny warnings... -->
<ItemGroup>
<Reference Include="ml_prm">
<HintPath>$(MsBuildThisFileDirectory)\..\_ManagedLibs\ml_prm.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
</Project>

View file

@ -10,22 +10,22 @@ internal class ChatBoxCommands : CommandBase
DateTime pingTime = DateTime.MinValue; // store the time when "ping" command was sent
Commands.RegisterCommand("ping",
onCommandSent: (message, sound) =>
onCommandSent: (message, sound, displayMsg) =>
{
pingTime = DateTime.Now;
awaitingPing = true;
},
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForSelf(message, args =>
{
ChatBox.SendMessage("/pong " + GetPlayerUsername(sender), false);
API.SendMessage("/pong " + GetPlayerUsername(sender), false, true);
});
});
Commands.RegisterCommand("pong",
onCommandSent: null,
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForSelf(message, args =>
{
@ -33,11 +33,11 @@ internal class ChatBoxCommands : CommandBase
{
awaitingPing = false;
TimeSpan timeSincePing = DateTime.Now - pingTime; // calculate the time difference
ChatBox.SendMessage($"Time since ping: {timeSincePing.TotalMilliseconds}ms", false);
API.SendMessage($"Time since ping: {timeSincePing.TotalMilliseconds}ms", false, true);
return;
}
ChatBox.SendMessage($"You have to ping first, {GetPlayerUsername(sender)}!", false);
API.SendMessage($"You have to ping first, {GetPlayerUsername(sender)}!", false, true);
});
});
}
}
}

View file

@ -9,14 +9,14 @@ internal class ChilloutVRBaseCommands : CommandBase
public static void RegisterCommands()
{
Commands.RegisterCommand("respawn",
onCommandSent: (message, sound) =>
onCommandSent: (message, sound, displayMsg) =>
{
LocalCommandIgnoreOthers(message, args =>
{
RootLogic.Instance.Respawn();
});
},
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForAll(message, (args) =>
{
@ -25,14 +25,14 @@ internal class ChilloutVRBaseCommands : CommandBase
});
Commands.RegisterCommand("mute",
onCommandSent: (message, sound) =>
onCommandSent: (message, sound, displayMsg) =>
{
LocalCommandIgnoreOthers(message, args =>
{
Audio.SetMicrophoneActive(true);
});
},
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForAll(message, args =>
{
@ -40,4 +40,4 @@ internal class ChilloutVRBaseCommands : CommandBase
});
});
}
}
}

View file

@ -1,16 +1,11 @@
using ABI_RC.Core;
using ABI_RC.Core.Base;
using ABI_RC.Core.Savior;
using Kafe.ChatBox;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
internal class ChilloutVRInputCommands : CommandBase
{
public static void RegisterCommands()
{
Commands.RegisterCommand("emote",
onCommandSent: (message, sound) =>
onCommandSent: (message, sound, displayMsg) =>
{
LocalCommandIgnoreOthers(message, args =>
{
@ -20,7 +15,7 @@ internal class ChilloutVRInputCommands : CommandBase
}
});
},
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForAll(message, args =>
{
@ -32,7 +27,7 @@ internal class ChilloutVRInputCommands : CommandBase
});
Commands.RegisterCommand("jump",
onCommandSent: (message, sound) =>
onCommandSent: (message, sound, displayMsg) =>
{
LocalCommandIgnoreOthers(message, args =>
{
@ -44,7 +39,7 @@ internal class ChilloutVRInputCommands : CommandBase
ChatBoxExtensions.InputModule.jump = true;
});
},
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForAll(message, args =>
{
@ -55,4 +50,4 @@ internal class ChilloutVRInputCommands : CommandBase
});
});
}
}
}

View file

@ -0,0 +1,46 @@
namespace NAK.Melons.ChatBoxExtensions.Integrations;
public static class Commands {
private const string Character = "/";
private static readonly List<Command> CommandList = new();
internal static void InitializeCommandHandlers() {
Kafe.ChatBox.API.OnMessageSent += (source, msg, notification, displayMsg) => HandleSentCommand(msg, notification, displayMsg);
Kafe.ChatBox.API.OnMessageReceived += (source, sender, msg, notification, displayMsg) => HandleReceivedCommand(sender, msg, notification, displayMsg);
}
internal static void RegisterCommand(string prefix, Action<string, bool, bool> onCommandSent = null, Action<string, string, bool, bool> onCommandReceived = null) {
var cmd = new Command { Prefix = prefix, OnCommandSent = onCommandSent, OnCommandReceived = onCommandReceived };
CommandList.Add(cmd);
}
internal static void UnregisterCommand(string prefix) {
CommandList.RemoveAll(cmd => cmd.Prefix == prefix);
}
private class Command {
internal string Prefix;
// Command Sent (message)
internal Action<string, bool, bool> OnCommandSent;
// Command Sent (sender guid, message)
internal Action<string, string, bool, bool> OnCommandReceived;
}
private static void HandleSentCommand(string message, bool notification, bool displayMsg) {
if (!message.StartsWith(Character)) return;
foreach (var command in CommandList.Where(command => message.StartsWith(Character + command.Prefix))) {
command.OnCommandSent?.Invoke(message, notification, displayMsg);
}
}
private static void HandleReceivedCommand(string sender, string message, bool notification, bool displayMsg) {
if (!message.StartsWith(Character)) return;
foreach (var command in CommandList.Where(command => message.StartsWith(Character + command.Prefix))) {
command.OnCommandReceived?.Invoke(sender, message, notification, displayMsg);
}
}
}

View file

@ -1,5 +1,4 @@
using Kafe.ChatBox;
using ml_prm;
using ml_prm;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
@ -8,7 +7,7 @@ internal class PlayerRagdollModCommands : CommandBase
public static void RegisterCommands()
{
Commands.RegisterCommand("unragdoll",
onCommandSent: (message, sound) =>
onCommandSent: (message, sound, displayMsg) =>
{
LocalCommandIgnoreOthers(message, (args) =>
{
@ -18,7 +17,7 @@ internal class PlayerRagdollModCommands : CommandBase
}
});
},
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForAll(message, (args) =>
{
@ -30,7 +29,7 @@ internal class PlayerRagdollModCommands : CommandBase
});
Commands.RegisterCommand("ragdoll",
onCommandSent: (message, sound) =>
onCommandSent: (message, sound, displayMsg) =>
{
LocalCommandIgnoreOthers(message, (args) =>
{
@ -47,7 +46,7 @@ internal class PlayerRagdollModCommands : CommandBase
}
});
},
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForAll(message, (args) =>
{
@ -66,7 +65,7 @@ internal class PlayerRagdollModCommands : CommandBase
});
Commands.RegisterCommand("kill",
onCommandSent: (message, sound) =>
onCommandSent: (message, sound, displayMsg) =>
{
LocalCommandIgnoreOthers(message, (args) =>
{
@ -76,7 +75,7 @@ internal class PlayerRagdollModCommands : CommandBase
}
});
},
onCommandReceived: (sender, message, sound) =>
onCommandReceived: (sender, message, sound, displayMsg) =>
{
RemoteCommandListenForAll(message, (args) =>
{

View file

@ -23,6 +23,7 @@ public class ChatBoxExtensions : MelonMod
void ApplyIntegrations()
{
Integrations.Commands.InitializeCommandHandlers();
Integrations.ChatBoxCommands.RegisterCommands();
Integrations.ChilloutVRBaseCommands.RegisterCommands();
ApplyPatches(typeof(HarmonyPatches.CVRInputManagerPatches));
@ -45,4 +46,4 @@ public class ChatBoxExtensions : MelonMod
Logger.Error(e);
}
}
}
}

View file

@ -21,12 +21,13 @@ using System.Reflection;
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
[assembly: MelonOptionalDependencies("ChatBox", "PlayerRagdollMod")]
[assembly: MelonAdditionalDependencies("ChatBox")]
[assembly: MelonOptionalDependencies("PlayerRagdollMod")]
[assembly: HarmonyDontPatchAll]
namespace ChatBoxExtensions.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "1.0.0";
public const string Version = "1.0.1";
public const string Author = "NotAKidoS";
}
}

View file

@ -43,10 +43,6 @@
<HintPath>$(MsBuildThisFileDirectory)\_ManagedLibs\ChatBox.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ml_prm">
<HintPath>$(MsBuildThisFileDirectory)\_ManagedLibs\ml_prm.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<!-- CVR base game dependencies -->