This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStart.cs
57 lines (51 loc) · 2.22 KB
/
Start.cs
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
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using MelonLoader;
using static MelonLoader.MelonLogger;
namespace Dawn.Encoding
{
internal class Start : MelonMod
{
public override void OnApplicationLateStart()
{
MelonPreferences.CreateCategory("EncodingFix", "Encoding Fix");
MelonPreferences.CreateEntry("EncodingFix", "Enabled", true, "Enabled (Requires Restart"); // Don't wanna cache it yet.
MelonPreferences.CreateEntry("EncodingFix", "PageID", 65001, "Advanced: SetPageID (int) Default = 0");
LocalPrefsSaved(); // Don't wanna call OnPrefs for eveyone lol.
}
public override void OnPreferencesSaved()
{
LocalPrefsSaved();
}
private static void LocalPrefsSaved()
{
m_Enabled = MelonPreferences.GetEntryValue<bool>("EncodingFix", "Enabled");
if (!m_Enabled) return;
m_PageID = MelonPreferences.GetEntryValue<int>("EncodingFix", "PageID");
SetCodingPage((uint) m_PageID);
}
private static bool m_Enabled;
private static int m_PageID;
[DllImport("kernel32.dll", SetLastError = true)] // Credits to Bluescream for the DLLImport links!
private static extern bool SetConsoleOutputCP(uint wCodePageID);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleCP(uint wCodePageID);
//UTF-8 = 65001
//UTF-16 = 1200 / 1201
//UTF-32 = 12000 / 12001
static void SetCodingPage(uint i = 65001) // https://stackoverflow.com/questions/38533903/set-c-sharp-console-application-to-unicode-output/59307528#59307528
{
//Credits to Cillié Malan
SetConsoleOutputCP(i);
SetConsoleCP(i);
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.InputEncoding = System.Text.Encoding.UTF8;
if (!First) return;
Msg($"EncodingPage Set to {i} : {Console.OutputEncoding}");
First = false;
}
private static bool First = true;
}
}