-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefenceController.cs
More file actions
121 lines (110 loc) · 4.3 KB
/
PrefenceController.cs
File metadata and controls
121 lines (110 loc) · 4.3 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
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
using DisForLС.GTRPCH;
using DisForLС.PayLoad;
using DisForLС.LogTools;
using System;
using System.IO;
using System.Reflection;
using System.Xml;
namespace DisForLС
{
public class PresenceController
{
public static PresenceController _instance;
private GameInfo _GI;
public static ILogger logger;
private ConThings client;
private System.Threading.Timer RPCupdater;
public static GameInfo GI
{
get
{
if (_instance is null)
throw new ObjectDisposedException("DiscordHandler", message: "Trying to call GameInfoHandler class but it was disposed.");
return _instance._GI;
}
}
//updating rpc rn
public void InstantUpdate()
{
RPCupdater.Change(0, 5000);
}
public bool presenceInit()
{
string path = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));
if (!File.Exists(path + "\\warp\\NativeNamedPipe.dll"))
{
FileLogger.ErrorBeforeInit(path, "Couldnt find the Native file. Try to reinstall mod or contact author");
return false;
}
LoadConfig(path);
_GI = new GameInfo();
_GI.previousGrade.Path = path + "\\warp";
client = new ConThings(path + "\\warp\\NativeNamedPipe.dll", logger);
RPCupdater = new System.Threading.Timer(new System.Threading.TimerCallback(Execute), null, 8000, 5000);
if (!client.Initialize()) return false;
//started = true;
client.SetPrefence(new Activity()
{
assets = new DisForLС.PayLoad.Assets()
{
LargeImage = "fish"
},
details = "starting",
timeSteps = new TimeSteps(0)
});
return true;
}
public void Execute(object bj)
{
GI.Update();
if (GI.newPrefence == null) return;
if (GI.oldPrefence.Equals(GI.newPrefence)) return;
client.SetPrefence(GI.newPrefence);
GI.oldPrefence = GI.newPrefence.Clone();
}
public void Close()
{
RPCupdater.Dispose();
client.Dispose();
_instance = null;
}
public void LoadConfig(string path)
{
try
{
if (File.Exists(path + "\\config.xml"))
{
XmlDocument doc = new XmlDocument();
doc.Load(path + "\\config.xml");
if (bool.Parse(doc.SelectSingleNode("configs/fileLogging").InnerText))
logger = new FileLogger(path + "\\Logs.txt");
else
logger = new DefaultLogger();
logger.Level = (LogLevel)int.Parse(doc.SelectSingleNode("configs/level").InnerText);
return;
}
else
{
lock (new object())
{
XmlDocument confDoc = new XmlDocument();
confDoc.AppendChild(confDoc.CreateXmlDeclaration("1.0", "UTF-8", null));
XmlElement root = confDoc.CreateElement("configs");
confDoc.AppendChild(root);
root.AppendChild(confDoc.CreateComment("level of logging. 0 - trace(all); 1 - info(main information); 2 - warnings; 3 - errors"));
XmlElement temp = confDoc.CreateElement("level");
temp.InnerText = "1";
root.AppendChild(temp);
root.AppendChild(confDoc.CreateComment("will logging to the file in mod's directory instead of default LobotomyBaseMod one"));
temp = confDoc.CreateElement("fileLogging");
temp.InnerText = "false";
root.AppendChild(temp);
confDoc.Save(path + "\\config.xml");
}
}
}
catch (Exception) {/*broken xml(((*/}
logger = new DefaultLogger(LogLevel.Info);
}
}
}