This repository was archived by the owner on Jan 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarmonyPatches.cs
More file actions
54 lines (45 loc) · 1.88 KB
/
HarmonyPatches.cs
File metadata and controls
54 lines (45 loc) · 1.88 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
using Microsoft.Xna.Framework;
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace CustomEmotes
{
internal static class HarmonyPatches
{
private static readonly string EMOTE_PATTERN = @"\%emote_(?<emoteName>[A-z0-9]+)";
private static CustomEmotes Instance => CustomEmotes.Instance;
public static bool Prefix_command_emote(Event __instance, GameLocation location, GameTime time, ref string[] split)
{
if (split.Length > 2 && !int.TryParse(split[2], out var _))
{
if (Instance.EmoteIndexMap.TryGetValue(split[2], out int index))
{
split[2] = index.ToString();
return true;
}
Instance.Monitor.Log($"Unknown emote '{split[2]}' ");
__instance.CurrentCommand++;
__instance.checkForNextCommand(location, time);
return false;
}
return true;
}
public static void Prefix_getCurrentDialogue(Dialogue __instance, ref string __result)
{
if (__instance.dialogues[__instance.currentDialogueIndex].Contains("%emote_"))
{
var api = Instance.GetApi();
var m = Regex.Match(__instance.dialogues[__instance.currentDialogueIndex], EMOTE_PATTERN);
if (!m.Success) return;
string emoteName = m.Groups["emoteName"].Value;
DelayedAction.functionAfterDelay(() => api.DoEmote(__instance.speaker, emoteName), 10);
__result = __instance.dialogues[__instance.currentDialogueIndex]
= Regex.Replace(__instance.dialogues[__instance.currentDialogueIndex], EMOTE_PATTERN, "");
}
}
}
}