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
|
#include "stdafx.h"
#include "Xfire_gamelist.h"
//liefert bestimmtes game zurück
Xfire_game* Xfire_gamelist::getGame(unsigned int dbid)
{
if (dbid < gamelist.size())
{
return gamelist.at(dbid);
}
return NULL;
}
//liefert bestimmtes game zurück
Xfire_game* Xfire_gamelist::getGamebyGameid(unsigned int gameid)
{
for (unsigned int i = 0; i < gamelist.size(); i++) {
Xfire_game* game = (Xfire_game*)gamelist.at(i);
if (game->id == gameid)
return game;
}
return NULL;
}
void Xfire_gamelist::readGamelist(int anz) {
//spiele einzeln einlesen
for (int i = 0; i < anz; i++)
{
//erzeuge gameobject
Xfire_game* game = new Xfire_game();
if (game) {
//lese das spiel ein
game->readFromDB(i);
//icons laden
Xfire_icon_cache icon = this->iconmngr.getGameIconEntry(game->id);
game->setIcon(icon.hicon, icon.handle);
//in die liste einfügen
gamelist.push_back(game);
}
}
}
//setzt den ingamestatus
void Xfire_gamelist::SetGameStatus(BOOL status)
{
ingame = status;
}
Xfire_gamelist::Xfire_gamelist()
{
nextgameid = 0;
ingame = FALSE;
}
//dekonstruktor
Xfire_gamelist::~Xfire_gamelist() {
for (unsigned int i = 0; i < gamelist.size(); i++) {
Xfire_game* game = (Xfire_game*)gamelist.at(i);
if (game) delete game;
}
gamelist.clear();
}
//hole das nächste game
BOOL Xfire_gamelist::getnextGame(Xfire_game**currentgame)
{
//kein pointer dann false zurückliefern
if (currentgame == NULL)
return FALSE;
//is die derzeitige id kleiner wie die anzahl an games, dann passendes game zurückliefern
if (nextgameid < gamelist.size())
{
*currentgame = gamelist.at(nextgameid);
nextgameid++;
//muss das spiel geskippt werden, dann nochmal funktion aufrufen um das nächste game zubekommen
if ((*currentgame)->skip || (*currentgame)->id == 32 || (*currentgame)->id == 33 || (*currentgame)->id == 34 || (*currentgame)->id == 35)
{
return getnextGame(currentgame);
}
return TRUE;
}
else
{
//liste durchgearbeitet, nextid wieder auf 0 setzen
nextgameid = 0;
return FALSE;
}
}
void Xfire_gamelist::Block(BOOL block)
{
if (block)
mir_cslock lck(gamlistMutex);
}
//fügt simple ein gameobject in den vector ein
void Xfire_gamelist::Addgame(Xfire_game* newgame)
{
//spielicon auslesen
Xfire_icon_cache icon = this->iconmngr.getGameIconEntry(newgame->id);
newgame->setIcon(icon.hicon, icon.handle);
gamelist.push_back(newgame);
}
//entfernt ein game aus der liste
BOOL Xfire_gamelist::Removegame(int id)
{
std::vector<Xfire_game *>::iterator i = gamelist.begin();
while (i != gamelist.end()) {
if ((*i)->id == id) {
(*i)->remoteMenuitem();
gamelist.erase(i);
return TRUE;
}
++i;
}
return FALSE;
}
//setzt die aktuelle id als currentgame
int Xfire_gamelist::CurrentGame()
{
this->SetGameStatus(TRUE);
return nextgameid - 1;
}
//erzeugt das menu der gameliste
void Xfire_gamelist::createStartmenu()
{
//keine games in der internen liste? abbruch
if (gamelist.size() == 0)
return;
//sortierarray
int* sorttemp = new int[gamelist.size()];
//zuordnungen setzen
for (unsigned int i = 0; i < gamelist.size(); i++)
sorttemp[i] = i;
//sortiert mit bubblesortalgo
BOOL changed = FALSE;
do
{
changed = FALSE;
for (unsigned int i = 1; i < gamelist.size(); i++)
{
Xfire_game* game = (Xfire_game*)gamelist.at(sorttemp[i - 1]);
Xfire_game* game2 = (Xfire_game*)gamelist.at(sorttemp[i]);
//sortieren
if (mir_strcmp(game->name, game2->name) > 0)
{
int tempi = sorttemp[i - 1];
sorttemp[i - 1] = sorttemp[i];
sorttemp[i] = tempi;
changed = TRUE;
}
}
} while (changed);
//menüpunkte anlegen
for (unsigned int i = 0; i < gamelist.size(); i++) {
Xfire_game* game = (Xfire_game*)gamelist.at(sorttemp[i]);
game->createMenuitem(i, sorttemp[i]);
}
//entferne sortarray
delete[] sorttemp;
//dummymenu entfernen
removeDummyMenuItem();
}
//schreibt derzeitige gameliste in die db
void Xfire_gamelist::writeDatabase()
{
for (unsigned int i = 0; i < gamelist.size(); i++) {
Xfire_game* game = (Xfire_game*)gamelist.at(i);
if (game) game->writeToDB(i);
}
//anzahl aktualisieren
db_set_w(NULL, protocolname, "foundgames", gamelist.size());
}
//prüft ob ein game schon in der liste is
BOOL Xfire_gamelist::Gameinlist(int id, int*dbid)
{
for (unsigned int i = 0; i < gamelist.size(); i++) {
Xfire_game* game = (Xfire_game*)gamelist.at(i);
if (game)
{
if (game->id == id)
{
//soll eine dbid zurückgeliefert werden? dann setzen
if (dbid)
*dbid = i;
return TRUE;
}
}
}
return FALSE;
}
//gibt die anzahl der spiele zurück
int Xfire_gamelist::countGames()
{
return gamelist.size();
}
//leert das startmenu
void Xfire_gamelist::clearStartmenu()
{
//erstelle dummyeintrag, für workaround
createDummyMenuItem();
//einzelene menüpunkte entfernen
for (unsigned int i = 0; i < gamelist.size(); i++) {
Xfire_game* game = (Xfire_game*)gamelist.at(i);
if (game) game->remoteMenuitem();
}
}
//dekonstruktor
void Xfire_gamelist::clearGamelist() {
createDummyMenuItem();
for (unsigned int i = 0; i < gamelist.size(); i++) {
Xfire_game* game = (Xfire_game*)gamelist.at(i);
if (game) delete game;
}
gamelist.clear();
}
//erstellt ein dummyeintrag
void Xfire_gamelist::createDummyMenuItem()
{
CLISTMENUITEM mi = { sizeof(mi) };
mi.position = 500090001;
mi.pszName = Translate("Please wait...");
mi.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(ID_OP));
mi.popupPosition = 500084000;
mi.pszPopupName = Translate("Start game");
mi.pszContactOwner = protocolname;
dummymenuitem = Menu_AddMainMenuItem(&mi);
}
//entfernt dummymenueintrag
void Xfire_gamelist::removeDummyMenuItem()
{
CallService(MO_REMOVEMENUITEM, (WPARAM)dummymenuitem, 0);
}
//säubert die datenbank spiel einträge udn trägt custom spiele vorher nach
void Xfire_gamelist::clearDatabase(BOOL dontaddcustom)
{
BOOL somethingfound = TRUE;
int i3 = 0;
//db durchsuchen
while (somethingfound) {
somethingfound = FALSE;
//customeintrag? dann ab in die gameliste damit
if (this->readBytefromDB("gamecustom", i3) == 1)
{
//customgame nur in die liste adden wenn es gewollt is
if (!dontaddcustom)
{
//erzeuge gameobject
Xfire_game* game = new Xfire_game();
//lese das spiel ein
game->readFromDB(i3);
//spielicon auslesen
/*Xfire_icon_cache icon=this->iconmngr.getGameIconEntry(game->id);
game->setIcon(icon.hicon,icon.handle);
//in die liste einfügen
gamelist.push_back(game);*/
this->Addgame(game);
}
}
if (this->removeDBEntry("gamecustom", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gameid", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamepath", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamepwargs", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gameuserargs", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamecmdline", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamencmdline", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamelaunch", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamenetargs", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamemulti", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamesendid", i3)) somethingfound = TRUE;
if (this->removeDBEntry("gamesetsmsg", i3)) somethingfound = TRUE;
for (int i2 = 0; i2 < 10; i2++)
if (this->removeDBEntry("gamepath", i3, i2)) somethingfound = TRUE;
i3++;
}
}
|