-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatches.cs
More file actions
69 lines (63 loc) · 2.32 KB
/
Patches.cs
File metadata and controls
69 lines (63 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using HarmonyLib;
using UnityEngine;
namespace InstantEat.Patches
{
public class MuckPatch
{
[HarmonyPrefix, HarmonyPatch(typeof(UseInventory), nameof(UseInventory.Use))]
public static bool OnUse()
{
if (InstantEat.currentItem && InstantEat.configInstantEatEnabled.Value) return !(InstantEat.currentItem.tag == InventoryItem.ItemTag.Food);
return true;
}
[HarmonyPostfix, HarmonyPatch(typeof(UseInventory), nameof(UseInventory.SetWeapon))]
public static void OnSetWeapon(ref InventoryItem item)
{
InstantEat.currentItem = item;
}
[HarmonyPostfix, HarmonyPatch(typeof(ChatBox), nameof(ChatBox.Instance.ChatCommand))]
public static void OnChatCommand(ref string message)
{
if (message == "/instanteat")
{
InstantEat.configInstantEatEnabled.Value = !InstantEat.configInstantEatEnabled.Value;
SendServerMessage($"Instant Eat {(InstantEat.configInstantEatEnabled.Value ? "Enabled" : "Disabled")}");
}
}
public static void SendServerMessage(string message)
{
ChatBox instance = ChatBox.Instance;
instance.typing = false;
message = TrimMessage(message);
if (message == "")
{
return;
}
if (message.ToCharArray()[0] == '/')
{
instance.ChatCommand(message);
return;
}
foreach (string input in instance.profanityList.text.Split(new char[] { '\n' }))
{
message = message.Replace(input, "muck");
}
instance.AppendMessage(0, message, "Server");
ClientSend.SendChatMessage(message);
ClearMessage();
}
private static void ClearMessage()
{
ChatBox.Instance.inputField.text = "";
ChatBox.Instance.inputField.interactable = false;
}
public static string TrimMessage(string message)
{
if (string.IsNullOrEmpty(message))
{
return "";
}
return message.Substring(0, Mathf.Min(message.Length, 120));
}
}
}