-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMessageHeightTwitchStatic.cs
81 lines (73 loc) · 2.23 KB
/
MessageHeightTwitchStatic.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
class MessageHeightTwitchStatic
{
public struct TwitchEmote
{
public string Name;
public string Url;
}
private static Dictionary<string, MessageHeightTwitch.MessageHeightTwitch> Instances = new Dictionary<string, MessageHeightTwitch.MessageHeightTwitch>();
public static int InitCharMap(string CharMapPath)
{
try {
MessageHeightTwitch.MessageHeightTwitch.FillCharMap(CharMapPath);
} catch (Exception ex) {
Console.WriteLine(ex);
return 0;
}
return 1;
}
public static int InitChannel(string Channel, string ChannelId, int TimeoutMs)
{
try {
var instance = new MessageHeightTwitch.MessageHeightTwitch(Channel, ChannelId, TimeoutMs);
if (Instances.ContainsKey(Channel))
Instances[Channel] = instance;
else
Instances.Add(Channel, instance);
} catch (Exception ex) {
Console.WriteLine(ex);
return 0;
}
return 1;
}
public static int InitChannel2(string Channel, string ChannelId, int TimeoutMs, bool Enable7TVEmotes)
{
try {
var instance = new MessageHeightTwitch.MessageHeightTwitch(Channel, ChannelId, TimeoutMs, Enable7TVEmotes);
if (Instances.ContainsKey(Channel))
Instances[Channel] = instance;
else
Instances.Add(Channel, instance);
} catch (Exception ex) {
Console.WriteLine(ex);
return 0;
}
return 1;
}
public static float CalculateMessageHeight(string Channel, string Input, string Username, string DisplayName, int NumberOfBadges, IntPtr TwitchEmotes, int TwitchEmotesLen)
{
if (!Instances.ContainsKey(Channel)) {
Console.WriteLine("Channel is not initialized, initialized:");
foreach (var chan in Instances.Keys) {
Console.WriteLine(chan);
}
return 0;
}
try {
var dict = new Dictionary<string, string>();
if (TwitchEmotes != null) {
for (int x = 0; x < TwitchEmotesLen * Marshal.SizeOf<TwitchEmote>(); x += Marshal.SizeOf<TwitchEmote>()) {
var te = Marshal.PtrToStructure<TwitchEmote>(new IntPtr(TwitchEmotes.ToInt64() + x));
dict.Add(te.Name, te.Url);
}
}
return Instances[Channel].CalculateMessageHeight(Input, Username, DisplayName, NumberOfBadges, dict);
} catch (Exception ex) {
Console.WriteLine(ex);
return 0;
}
}
}