-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMQ2DanInterface.cpp
More file actions
208 lines (168 loc) · 5.42 KB
/
MQ2DanInterface.cpp
File metadata and controls
208 lines (168 loc) · 5.42 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
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
// MQ2DanInterface.cpp
// By Chatwiththisname
/*
Still needed.
a Listbox to show channels
a Listbox to show currently connected peers. (handled in the peers combo box?)
Reading Material:
Dannet Resource Page: https://www.redguides.com/community/resources/mq2dannet.322/
*/
#include "../MQ2Plugin.h"
#include "DanInterfaceWnd.h"
#include <functional>
PreSetup("MQ2DanInterface");
typedef void(*fFunction)();
std::map<std::string, fFunction> options;
PMQPLUGIN FindMQ2DanNetPlugin()
{
PMQPLUGIN pPlugin = pPlugins;
while (pPlugin) {
if (!_stricmp("MQ2Dannet", pPlugin->szFilename)) {
return pPlugin;
}
pPlugin = pPlugin->pNext;
}
return nullptr;
}
using fPeer_Connected = bool(*)(const std::string& name);
//From MQ2DanNet exports.
bool IsPeerConnected(const std::string& szName) {
PMQPLUGIN pDannet = FindMQ2DanNetPlugin();
if (!pDannet)
return false;
fPeer_Connected peer_connected = (fPeer_Connected)GetProcAddress(pDannet->hModule, "peer_connected");
if (peer_connected) {
if (peer_connected(szName))
return true;
}
return false;
}
inline bool InGame()
{
return(GetGameState() == GAMESTATE_INGAME && GetCharInfo() && GetCharInfo()->pSpawn && GetCharInfo2());
}
void SeeDanShow() {
MakeWindowVisible();
};
void SeeDanHide() {
MakeWindowInvisible();
};
void SeeDanToggle() {
MakeWindowToggle();
};
//szQuery used for the commented out code block, if you /seedan test, and the function call includes a query, it will add it for all connected peers.
void TestQuery(char* szQuery = "") {
//Commented out code work to dump out all known information to the MQ2Window.
//std::vector<std::string> peers = GetPeersList();
//unsigned int count = GetPeersCount();
//for (unsigned int i = 0; i < count; i++) {//For each Peer connected.
// AddObservation(peers.at(i).c_str(), szQuery);//Add the query.
//}
//for (unsigned int i = 0; i < count; i++) {//For each peer connected.
// WriteChatf("Name: %s", peers.at(i).c_str());
// std::vector<std::string> vObservations = GetObserveList(peers.at(i).c_str());
// unsigned int observecount = GetObserveCount(peers.at(i).c_str());
// for (unsigned int i = 0; i < observecount; i++) {//output each observation and it's value.
// WriteChatf("Observation: %s Value: %s", (char*)vObservations.at(i).c_str(), GetObserveValue(peers.at(i).c_str(), (char*)vObservations.at(i).c_str()));
// }
//}
//Currently this will attempt to add all the `Me.Buff[#].Name` and `Me.Song[#].Name` options for all peers in the peers list.
if (InterfaceWnd) {
InterfaceWnd->AddAllBuffs();
}
}
char* GetServer() {
if (EQADDR_SERVERNAME[0])
{
return EQADDR_SERVERNAME;
}
return "";
}
void TestCommand() {
TestQuery();
}
void SetupOptions() {//input all of these in lowercase.
options.insert(std::make_pair("on", SeeDanShow));
options.insert(std::make_pair("show", SeeDanShow));
options.insert(std::make_pair("off", SeeDanHide));
options.insert(std::make_pair("hide", SeeDanHide));
options.insert(std::make_pair("toggle", SeeDanToggle));
options.insert(std::make_pair("test", TestCommand));
}
void print_options() {//outputs all available options.
std::map<std::string, fFunction>::iterator it;
for (it = options.begin(); it != options.end(); it++) {
WriteOut("%s", it->first.c_str());
}
}
void SeeDannet(PSPAWNINFO pSpawn, char* szLine) {
if (!strlen(szLine)) {//if the user didn't pass anything after `/seedan`
WriteOut("Invalid option");
print_options();
return;
}
char temp[64] = { 0 };
strcpy_s(temp, szLine);
_strlwr_s(temp, 64);
auto result = options.find(temp);//see if it matches a valid option
if (result != options.end()) {
if (result->second) {
result->second();//If so, fire the appropriate function.
}
} else {//otherwise, let them know it was invalid, and output the available options.
WriteOut("Invalid option - %s", szLine);
print_options();
}
}
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin()
{
SetupOptions();
AddXMLFile("MQUI_DanNet.xml");
AddCommand("/seedannet",SeeDannet);
if (InGame())
CreateInterfaceWindow();
}
// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin()
{
RemoveCommand("/seedannet");
}
PLUGIN_API VOID OnCleanUI()
{
DestroyInterfaceWindow();
}
PLUGIN_API VOID OnReloadUI()
{
if (InGame()) {
CreateInterfaceWindow();
}
}
PLUGIN_API VOID SetGameState(DWORD GameState)
{
if (InGame()) {
sprintf_s(ThisINIFileName, MAX_STRING, "%s\\MQ2DanInterface_%s.ini", gszINIPath, GetCharInfo()->Name);
if (!InterfaceWnd)
CreateInterfaceWindow();
}
}
PLUGIN_API VOID OnPulse()
{
//create a timer to prevent us from pulsing too fast.
static uint64_t refreshTimer = 0;
if (refreshTimer + 500 > GetTickCount64())
return;
refreshTimer = GetTickCount64();
static int peers = GetPeersCount();
if (InGame() && !WrongUI) {
if (InterfaceWnd) {
InterfaceWnd->UpdateListBox();
{
if (peers != GetPeersCount()) {//if the peers count has changed, update the peers combo box.
InterfaceWnd->LoadSettings();
peers = GetPeersCount();
}
}
}
}
}