-
Notifications
You must be signed in to change notification settings - Fork 2
/
Global.cs
379 lines (297 loc) · 12.1 KB
/
Global.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Media.Imaging;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
namespace KekboomKawaii
{
[Flags]
public enum ChatClassFlag : int
{
None = 0,
World = 1,
Team = 2,
Recruit = 4,
Guild = 8,
Dojo = 16
}
public enum ChatClassEnum : int
{
None = 0,
World = 1,
Team = 3,
Recruit = 7,
Guild = 8,
Dojo = 9
}
public enum GenderEnum : int
{
None = 0,
Female = 1,
Male = 0x70
}
public enum GuildPostEnum : int
{
Member = 0,
Manager = 2,
Admin = 5,
Owner = 6
}
public enum ImageEnum : int
{
None = 0,
Avatar = 1,
AvatarFrame = 2,
Weapon = 3
}
public static class Global
{
#region INI DllImport
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32")]
private static extern int WritePrivateProfileString(string section, string key, string val, string filePath);
#endregion
public static void ShowToast(string appId, string title, string message, string image)
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(
string.IsNullOrEmpty(image) ? ToastTemplateType.ToastText02 : ToastTemplateType.ToastImageAndText02);
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode(title));
stringElements[1].AppendChild(toastXml.CreateTextNode(message));
if (string.IsNullOrEmpty(image) == false)
{
string imagePath = image;
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;
}
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier(appId).Show(toast);
}
#region Dictionary
public static Dictionary<ChatClassFlag, string> ChatClassDictionary = new Dictionary<ChatClassFlag, string>
{
{ ChatClassFlag.World,"세계" },
{ ChatClassFlag.Team,"팀" },
{ ChatClassFlag.Recruit,"모집" },
{ ChatClassFlag.Guild,"길드" },
{ ChatClassFlag.Dojo,"협력" },
};
public static Dictionary<GuildPostEnum, string> GuildPostDictionary = new Dictionary<GuildPostEnum, string> {
{GuildPostEnum.Member ,"회원"},
{GuildPostEnum.Manager ,"간부"},
{GuildPostEnum.Admin ,"부길드장"},
{GuildPostEnum.Owner ,"길드장"},
};
public static Dictionary<string, string> TitleDic = new Dictionary<string, string>();
public static Dictionary<string, string> AvatarFrameDic = new Dictionary<string, string>();
public static Dictionary<string, string> AvatarDic = new Dictionary<string, string>();
public static Dictionary<string, string> WeaponDic = new Dictionary<string, string>();
public static Dictionary<string, BitmapImage> AvatarImageDic = new Dictionary<string, BitmapImage>();
public static Dictionary<string, BitmapImage> AvatarFrameImageDic = new Dictionary<string, BitmapImage>();
public static Dictionary<string, BitmapImage> WeaponImageDic = new Dictionary<string, BitmapImage>();
#endregion
#region File Path
public static string AvatarJsonPath = @"/Resources/Database/AvatarConfigDataTable.json";
public static string AvatarFrameJsonPath = @"/Resources/Database/AvatarFrameConfigDataTable.json";
public static string StaticWeaponJsonPath = @"/Resources/Database/StaticWeaponDataTable.json";
public static string TitleJsonPath = @"/Resources/Database/DT_Title.json";
public static string LocalJsonPath = @"/Resources/Database/Game.json";
public static string AvatarImagePath = "/Resources/Avatar";
public static string AvatarFrameImagePath = "/Resources/AvatarFrame";
public static string WeaponImagePath = "/Resources/Weapon";
#endregion
#region Property
public static Regex regex = new Regex("^\\/(.+\\/)*(.+)\\.(.+)$");
public const string UserSettingsFileName = @"\Settings.ini";
private static string filterString;
public static string FilterString
{
get { return filterString; }
set
{
filterString = value;
SetiniValue("Setting", "FilterString", value);
}
}
private static int ethernetIndex;
public static int EthernetIndex
{
get { return ethernetIndex; }
set
{
ethernetIndex = value;
SetiniValue("Setting", "EthernetIndex", value.ToString());
}
}
private static ChatClassFlag chatClassFilter;
public static ChatClassFlag ChatClassFilter
{
get { return chatClassFilter; }
set
{
chatClassFilter = value;
SetiniValue("Setting", "ChatClassFilter", value.ToString());
}
}
#endregion
public static PacketSniffer Sniffer { get; set; }
#region Method
private static string GetiniValue(string section, string key)
{
var temp = new StringBuilder(255);
GetPrivateProfileString(section, key, null, temp, 255, AppDomain.CurrentDomain.BaseDirectory + UserSettingsFileName);
return temp.ToString();
}
private static void SetiniValue(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, AppDomain.CurrentDomain.BaseDirectory + UserSettingsFileName);
}
private static string GetEmbeddedResource(string fileName)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "KekboomKawaii." + fileName;
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
using (StreamReader reader = new StreamReader(stream, encoding: Encoding.UTF8))
{
string result = reader.ReadToEnd();
return result;
}
}
}
private static string GetFileResource(string fileName)
{
var filePath = AppDomain.CurrentDomain.BaseDirectory + fileName;
using (StreamReader reader = new StreamReader(filePath, encoding: Encoding.UTF8))
{
string result = reader.ReadToEnd();
return result;
}
}
// get external resources in directory
// get fileList from directory
private static string[] GetFileList(string directory)
{
// get current application path
string path = AppDomain.CurrentDomain.BaseDirectory;
return Directory.GetFiles(path + directory);
}
static Global()
{
filterString = GetiniValue("Setting", "FilterString");
if (int.TryParse(GetiniValue("Setting", "EthernetIndex"), out int index))
{
ethernetIndex = index;
}
if (Enum.TryParse<ChatClassFlag>(GetiniValue("Setting", "ChatClassFilter"), out var filter))
{
chatClassFilter = filter;
}
Sniffer = new PacketSniffer();
}
public static void ImageInit()
{
foreach (var path in GetFileList(AvatarImagePath))
{
var image = new BitmapImage(new Uri(path));
image.Freeze();
AvatarImageDic.Add(Path.GetFileNameWithoutExtension(path).ToLower(), image);
}
foreach (var path in GetFileList(AvatarFrameImagePath))
{
var image = new BitmapImage(new Uri(path));
image.Freeze();
AvatarFrameImageDic.Add(Path.GetFileNameWithoutExtension(path).ToLower(), image);
}
foreach (var path in GetFileList(WeaponImagePath))
{
var image = new BitmapImage(new Uri(path));
image.Freeze();
WeaponImageDic.Add(Path.GetFileNameWithoutExtension(path).ToLower(), image);
}
}
public static BitmapImage GetImage(string name, ImageEnum ImageType)
{
Dictionary<string, string> nameDic = null;
Dictionary<string, BitmapImage> imageDic = null;
switch (ImageType)
{
case ImageEnum.Avatar:
nameDic = AvatarDic;
imageDic = AvatarImageDic;
break;
case ImageEnum.AvatarFrame:
nameDic = AvatarFrameDic;
imageDic = AvatarFrameImageDic;
break;
case ImageEnum.Weapon:
nameDic = WeaponDic;
imageDic = WeaponImageDic;
break;
default:
return null;
}
if (nameDic.TryGetValue(name.ToLower(), out var dicName))
{
if (imageDic.TryGetValue(dicName.ToLower(), out var img))
{
return img;
}
}
if (imageDic.TryGetValue(name.ToLower(), out var image))
{
return image;
}
return null;
}
public static void Initlaize()
{
dynamic avatar = JsonConvert.DeserializeObject(GetFileResource(AvatarJsonPath));
foreach (dynamic item in avatar[0].Rows)
{
AvatarDic.Add(item.Name.ToLower(), regex.Match(item.Value.BigImage.AssetPathName.ToString()).Groups[3].Value);
}
dynamic avatarFrame = JsonConvert.DeserializeObject(GetFileResource(AvatarFrameJsonPath));
foreach (dynamic item in avatarFrame[0].Rows)
{
AvatarFrameDic.Add(item.Name.ToLower(), regex.Match(item.Value.BigImage.AssetPathName.ToString()).Groups[3].Value);
}
dynamic staticWeapon = JsonConvert.DeserializeObject(GetFileResource(StaticWeaponJsonPath));
foreach (dynamic item in staticWeapon[0].Rows)
{
WeaponDic.Add(item.Name.ToLower(), regex.Match(item.Value.WeaponIconForMatrix.AssetPathName.ToString()).Groups[3].Value);
}
dynamic title = JsonConvert.DeserializeObject(GetFileResource(TitleJsonPath));
dynamic titleLoc = JsonConvert.DeserializeObject(GetFileResource(LocalJsonPath));
foreach (dynamic item in title[0].Rows)
{
if (item.Value.Name.TableId != null)
{
if (item.Value.Name.LocalizedString != null)
{
TitleDic.Add(item.Name, item.Value.Name.LocalizedString);
continue;
}
dynamic tableId = regex.Match(item.Value.Name.TableId.ToString()).Groups[3].Value;
dynamic table = titleLoc[tableId.ToString()];
string na = table[item.Value.Name.Key.ToString()];
TitleDic.Add(item.Name, na);
}
else if (item.Value.Name.Key != null)
{
dynamic table = titleLoc[""];
string na = table[item.Value.Name.Key.ToString()];
TitleDic.Add(item.Name, na);
}
}
}
#endregion
}
}