LavaGang / MelonLoader

The World's First Universal Mod Loader for Unity Games compatible with both Il2Cpp and Mono
https://discord.gg/2Wn3N2P
Apache License 2.0
2.48k stars 479 forks source link

Add method MsgPastel to MelonLogger #738

Closed HAHOOS closed 2 months ago

HAHOOS commented 2 months ago

Adds a new method to MelonLogger called MsgPastel. The name might not make it really clear, but when I was developing a plugin I've come across an issue where the ANSI colors were also written in log files, making the logs less readable. To fix this, I've created a new method for writing messages that uses Regex to remove ANSI from logs. It's the same as Msg with the exception that before writing to file, it runs the following regex: (\x1B|\e|\033)\[(.*?)m to replace all matches with nothing. I'm not quite sure if the \x1B|\e|\033 needs to be there or only one of escape characters, but to be safe I added all of them. Depending on the device running MelonLoader, Regex could slow down the process of logging (from what I have tested, it was ~0.1/0.2 ms on a browser regex tester, but while running ML with regex checking all messages, it looked like there was practically no delay. But I have a pretty good computer so I'm not sure how that would work on slower computers), that's why it's made into a separate method.

I've tested it with a plugin I'm working on that has a lot of ANSI colors and it seems to work well