push broken mod

This commit is contained in:
NotAKidoS 2023-04-26 11:18:40 -05:00
parent 742f816d3d
commit 344e3bb6d6
12 changed files with 500 additions and 0 deletions

View file

@ -0,0 +1,56 @@
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
public class CommandBase
{
internal static bool IsCommandForAll(string argument)
{
if (String.IsNullOrWhiteSpace(argument)) return false;
return argument == "*" || argument.StartsWith("@a") || argument.StartsWith("@e");
}
internal static bool IsCommandForLocalPlayer(string argument)
{
if (String.IsNullOrWhiteSpace(argument)) return false;
if (argument.Contains("*"))
{
string partialName = argument.Replace("*", "").Trim();
if (String.IsNullOrWhiteSpace(partialName)) return false;
return MetaPort.Instance.username.Contains(partialName);
}
return MetaPort.Instance.username == argument;
}
internal static void LocalCommandIgnoreOthers(string argument, Action<string[]> callback)
{
string[] args = argument.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray();
// will fail if arguments are specified which arent local player
if (args.Length == 0 || IsCommandForAll(args[0]) || IsCommandForLocalPlayer(args[0])) callback(args);
}
//remote must specify exact player, wont respawn to all
internal static void RemoteCommandListenForSelf(string argument, Action<string[]> callback)
{
string[] args = argument.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray();
if (args.Length == 0) return;
if (IsCommandForLocalPlayer(args[0])) callback(args);
}
// remote must specify player or all, ignore commands without arguments
internal static void RemoteCommandListenForAll(string argument, Action<string[]> callback)
{
string[] args = argument.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray();
if (args.Length == 0) return;
if (IsCommandForAll(args[0]) || IsCommandForLocalPlayer(args[0])) callback(args);
}
internal static string GetPlayerUsername(string guid)
{
return CVRPlayerManager.Instance.TryGetPlayerName(guid);
}
}

View file

@ -0,0 +1,43 @@
using Kafe.ChatBox;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
internal class ChatBoxCommands : CommandBase
{
public static void RegisterCommands()
{
bool awaitingPing = false;
DateTime pingTime = DateTime.MinValue; // store the time when "ping" command was sent
Commands.RegisterCommand("ping",
onCommandSent: (message, sound) =>
{
pingTime = DateTime.Now;
awaitingPing = true;
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForSelf(message, args =>
{
ChatBox.SendMessage("/pong " + GetPlayerUsername(sender), false);
});
});
Commands.RegisterCommand("pong",
onCommandSent: null,
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForSelf(message, args =>
{
if (awaitingPing)
{
awaitingPing = false;
TimeSpan timeSincePing = DateTime.Now - pingTime; // calculate the time difference
ChatBox.SendMessage($"Time since ping: {timeSincePing.TotalMilliseconds}ms", false);
return;
}
ChatBox.SendMessage($"You have to ping first, {GetPlayerUsername(sender)}!", false);
});
});
}
}

View file

@ -0,0 +1,43 @@
using ABI_RC.Core;
using ABI_RC.Core.Base;
using Kafe.ChatBox;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
internal class ChilloutVRBaseCommands : CommandBase
{
public static void RegisterCommands()
{
Commands.RegisterCommand("respawn",
onCommandSent: (message, sound) =>
{
LocalCommandIgnoreOthers(message, args =>
{
RootLogic.Instance.Respawn();
});
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForAll(message, (args) =>
{
RootLogic.Instance.Respawn();
});
});
Commands.RegisterCommand("mute",
onCommandSent: (message, sound) =>
{
LocalCommandIgnoreOthers(message, args =>
{
Audio.SetMicrophoneActive(true);
});
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForAll(message, args =>
{
Audio.SetMicrophoneActive(true);
});
});
}
}

View file

@ -0,0 +1,58 @@
using ABI_RC.Core;
using ABI_RC.Core.Base;
using ABI_RC.Core.Savior;
using Kafe.ChatBox;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
internal class ChilloutVRInputCommands : CommandBase
{
public static void RegisterCommands()
{
Commands.RegisterCommand("emote",
onCommandSent: (message, sound) =>
{
LocalCommandIgnoreOthers(message, args =>
{
if (args.Length > 0 && int.TryParse(args[0], out int emote))
{
ChatBoxExtensions.InputModule.emote = (float)emote;
}
});
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForAll(message, args =>
{
if (args.Length > 1 && int.TryParse(args[1], out int emote))
{
ChatBoxExtensions.InputModule.emote = (float)emote;
}
});
});
Commands.RegisterCommand("jump",
onCommandSent: (message, sound) =>
{
LocalCommandIgnoreOthers(message, args =>
{
if (args.Length > 0 && bool.TryParse(args[0], out bool jump))
{
ChatBoxExtensions.InputModule.jump = jump;
return;
}
ChatBoxExtensions.InputModule.jump = true;
});
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForAll(message, args =>
{
if (bool.TryParse(args[0], out bool jump))
{
ChatBoxExtensions.InputModule.jump = jump;
}
});
});
}
}

View file

@ -0,0 +1,90 @@
using Kafe.ChatBox;
using ml_prm;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
internal class PlayerRagdollModCommands : CommandBase
{
public static void RegisterCommands()
{
Commands.RegisterCommand("unragdoll",
onCommandSent: (message, sound) =>
{
LocalCommandIgnoreOthers(message, (args) =>
{
if (RagdollController.Instance.IsRagdolled())
{
RagdollController.Instance.SwitchRagdoll();
}
});
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForAll(message, (args) =>
{
if (RagdollController.Instance.IsRagdolled())
{
RagdollController.Instance.SwitchRagdoll();
}
});
});
Commands.RegisterCommand("ragdoll",
onCommandSent: (message, sound) =>
{
LocalCommandIgnoreOthers(message, (args) =>
{
bool switchRagdoll = true;
if (args.Length > 0 && bool.TryParse(args[0], out bool state))
{
switchRagdoll = state != RagdollController.Instance.IsRagdolled();
}
if (switchRagdoll)
{
RagdollController.Instance.SwitchRagdoll();
}
});
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForAll(message, (args) =>
{
bool switchRagdoll = true;
if (args.Length > 1 && bool.TryParse(args[1], out bool state))
{
switchRagdoll = state != RagdollController.Instance.IsRagdolled();
}
if (switchRagdoll)
{
RagdollController.Instance.SwitchRagdoll();
}
});
});
Commands.RegisterCommand("kill",
onCommandSent: (message, sound) =>
{
LocalCommandIgnoreOthers(message, (args) =>
{
if (!RagdollController.Instance.IsRagdolled())
{
RagdollController.Instance.SwitchRagdoll();
}
});
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForAll(message, (args) =>
{
if (!RagdollController.Instance.IsRagdolled())
{
RagdollController.Instance.SwitchRagdoll();
}
});
});
}
}