-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenReader.cs
More file actions
72 lines (57 loc) · 1.96 KB
/
ScreenReader.cs
File metadata and controls
72 lines (57 loc) · 1.96 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
70
71
72
using System;
using System.Runtime.InteropServices;
using MelonLoader;
using MelatoninAccess;
using UnityEngine;
public static class ScreenReader
{
[DllImport("Tolk.dll", CharSet = CharSet.Unicode)]
private static extern void Tolk_Load();
[DllImport("Tolk.dll", CharSet = CharSet.Unicode)]
private static extern void Tolk_Unload();
[DllImport("Tolk.dll", CharSet = CharSet.Unicode)]
private static extern bool Tolk_IsLoaded();
[DllImport("Tolk.dll", CharSet = CharSet.Unicode)]
private static extern bool Tolk_Output([MarshalAs(UnmanagedType.LPWStr)] string str, bool interrupt);
[DllImport("Tolk.dll", CharSet = CharSet.Unicode)]
private static extern bool Tolk_Speak([MarshalAs(UnmanagedType.LPWStr)] string str, bool interrupt);
[DllImport("Tolk.dll", CharSet = CharSet.Unicode)]
private static extern bool Tolk_Silence();
private static string lastText = "";
private static float lastTime = 0f;
public static void Initialize()
{
Tolk_Load();
if (Tolk_IsLoaded())
{
MelonLogger.Msg("Tolk loaded successfully.");
Say(Loc.Get("mod_loaded"), true);
}
else
{
MelonLogger.Error("Failed to load Tolk.");
}
}
public static void Unload()
{
Tolk_Unload();
}
public static void Say(string text, bool interrupt = false)
{
if (string.IsNullOrEmpty(text)) return;
text = string.Join(" ", text.Split((char[])null, StringSplitOptions.RemoveEmptyEntries));
if (string.IsNullOrEmpty(text)) return;
// Debounce exact repetitions within 0.5s
float now = Time.unscaledTime;
if (now <= 0f) now = Time.time;
if (text == lastText && now - lastTime < 0.5f) return;
lastText = text;
lastTime = now;
DebugLogger.LogScreenReader(text);
Tolk_Output(text, interrupt);
}
public static void Stop()
{
Tolk_Silence();
}
}