-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathConfig.cs
93 lines (80 loc) · 3.17 KB
/
Config.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
//NCShark - By AlSch092 @ Github, thanks to @Diamondo25 for MapleShark
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace NCShark
{
public sealed class Config
{
public string Protocol;
public string Interface = "";
public ushort LowPort = 33004;
public ushort HighPort = 35001;
[System.Obsolete]
public List<Definition> Definitions = new List<Definition>();
[XmlIgnore]
public bool LoadedFromFile = false;
private static Config sInstance = null;
internal static Config Instance
{
get
{
if (sInstance == null)
{
if (!File.Exists("Config.xml"))
{
sInstance = new Config();
sInstance.Save();
}
else
{
using (XmlReader xr = XmlReader.Create("Config.xml"))
{
XmlSerializer xs = new XmlSerializer(typeof(Config));
sInstance = xs.Deserialize(xr) as Config;
sInstance.LoadedFromFile = true;
}
}
}
return sInstance;
}
}
internal Definition GetDefinition(bool pOutbound, ushort pOpcode)
{
return DefinitionsContainer.Instance.GetDefinition( pOpcode, pOutbound);
// return Definitions.Find(d => d.Locale == pLocale && d.Build == pBuild && d.Outbound == pOutbound && d.Opcode == pOpcode);
}
internal static string GetPropertiesFile(bool pOutbound, byte pLocale, ushort pVersion)
{
return System.Environment.CurrentDirectory + Path.DirectorySeparatorChar + "Scripts" + Path.DirectorySeparatorChar + pLocale.ToString() + Path.DirectorySeparatorChar + pVersion.ToString() + Path.DirectorySeparatorChar + (pOutbound ? "send" : "recv") + ".properties";
}
internal void Save()
{
// Remove useless definitions
if (Definitions.Count > 0)
{
Definitions.RemoveAll(d =>
{
return d.Locale <= 0 || d.Locale >= 11;
});
Definitions.ForEach(d => DefinitionsContainer.Instance.SaveDefinition(d));
DefinitionsContainer.Instance.Save();
Definitions.Clear();
}
XmlWriterSettings xws = new XmlWriterSettings()
{
Indent = true,
IndentChars = " ",
NewLineOnAttributes = true,
OmitXmlDeclaration = true
};
using (XmlWriter xw = XmlWriter.Create("Config.xml", xws))
{
XmlSerializer xs = new XmlSerializer(typeof(Config));
xs.Serialize(xw, this);
}
if (!Directory.Exists("Scripts")) Directory.CreateDirectory("Scripts");
}
}
}