Skip to content

Commit

Permalink
Fixed colored shadow in currently typing
Browse files Browse the repository at this point in the history
  • Loading branch information
18107 committed Apr 24, 2021
1 parent e6dfcb5 commit 839c292
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 18 deletions.
47 changes: 29 additions & 18 deletions PulsarPluginLoader/Chat/Extensions/HarmonyColoredMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,42 @@
namespace PulsarPluginLoader.Chat.Extensions
{
[HarmonyPatch(typeof(PLInGameUI), "ColoredMsg")]
class HarmonyColoredMessage
public class HarmonyColoredMessage
{
static void Prefix(ref string inMsg, bool isShadow)
public static string RemoveColor(string text)
{
if (isShadow)
while (true)
{
while (true)
int index = text.IndexOf("<color=");
if (index < 0)
break;
int endIndex = index;
bool valid = false;
for (; endIndex < text.Length; endIndex++)
{
int index = inMsg.IndexOf("<color=");
if (index < 0)
break;
int endIndex = index;
for (; true; endIndex++)
if (text[endIndex] == '>')
{
if (inMsg[endIndex] == '>')
{
break;
}
}
inMsg = inMsg.Remove(index, endIndex - index + 1);
int index2 = inMsg.IndexOf("</color>");
if (index2 < 0)
valid = true;
break;
inMsg = inMsg.Remove(index2, 8);
}
}
if (valid)
{
text = text.Remove(index, endIndex - index + 1);
}
int index2 = text.IndexOf("</color>");
if (index2 < 0)
break;
text = text.Remove(index2, 8);
}
return text;
}

static void Prefix(ref string inMsg, bool isShadow)
{
if (isShadow)
{
inMsg = RemoveColor(inMsg);
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions PulsarPluginLoader/Chat/Extensions/HarmonyHandleChat.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using UnityEngine;
using static PulsarPluginLoader.Patches.HarmonyHelpers;

namespace PulsarPluginLoader.Chat.Extensions
{
Expand Down Expand Up @@ -248,5 +251,28 @@ static void Postfix(PLInGameUI __instance, ref string __state)
PLNetworkManager.Instance.CurrentChatText = __state;
}
}

//Fixes shadow in currently typing
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> targetSequence = new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Brfalse_S),
new CodeInstruction(OpCodes.Ldloc_S),
new CodeInstruction(OpCodes.Ldstr),
new CodeInstruction(OpCodes.Callvirt),
new CodeInstruction(OpCodes.Pop),
new CodeInstruction(OpCodes.Ldloc_S),
new CodeInstruction(OpCodes.Ldsfld),
new CodeInstruction(OpCodes.Ldfld)
};

List<CodeInstruction> injectedSequence = new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(HarmonyColoredMessage), "RemoveColor"))
};

return PatchBySequence(instructions, targetSequence, injectedSequence, PatchMode.AFTER, CheckMode.NEVER);
}
}
}

0 comments on commit 839c292

Please sign in to comment.