~ubuntu-branches/debian/sid/astromenace/sid

« back to all changes in this revision

Viewing changes to AstroMenaceSource/ScriptEngine/Setup.cpp

  • Committer: Package Import Robot
  • Author(s): Boris Pek
  • Date: 2013-04-09 02:04:25 UTC
  • Revision ID: package-import@ubuntu.com-20130409020425-a7fl9xk4diamw6di
Tags: upstream-1.3.1+repack
Import upstream version 1.3.1+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************************
 
2
 
 
3
        AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
 
4
        Copyright © 2006-2012 Michael Kurinnoy, Viewizard
 
5
 
 
6
 
 
7
        AstroMenace is free software: you can redistribute it and/or modify
 
8
        it under the terms of the GNU General Public License as published by
 
9
        the Free Software Foundation, either version 3 of the License, or
 
10
        (at your option) any later version.
 
11
 
 
12
        AstroMenace is distributed in the hope that it will be useful,
 
13
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
        GNU General Public License for more details.
 
16
 
 
17
        You should have received a copy of the GNU General Public License
 
18
        along with AstroMenace. If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
 
 
21
        Web Site: http://www.viewizard.com/
 
22
        Project: http://sourceforge.net/projects/openastromenace/
 
23
        E-mail: viewizard@viewizard.com
 
24
 
 
25
*************************************************************************************/
 
26
 
 
27
 
 
28
#include "../Game.h"
 
29
 
 
30
 
 
31
 
 
32
 
 
33
//-----------------------------------------------------------------------------
 
34
// задаем базовые настройки
 
35
//-----------------------------------------------------------------------------
 
36
void InitSetup()
 
37
{
 
38
        // базовые настройки, устанавливаем всегда - кто там знает, что в xml файле есть
 
39
        // всегда устанавливаем текущее разрешение рабочего стола
 
40
 
 
41
        // устанавливаем номер билда
 
42
        Setup.BuildVersion = GAME_BUILD;
 
43
 
 
44
        Setup.MenuLanguage = 1; // en by default
 
45
        Setup.VoiceLanguage = 1; // en by default
 
46
        Setup.FontNumber = 0;
 
47
 
 
48
        Setup.Width = 1228;
 
49
        Setup.Height = 768;
 
50
        Setup.BPP = 0;
 
51
        Setup.fAspectRatioWidth = 1228.0f;
 
52
        Setup.fAspectRatioHeight = 768.0f;
 
53
        Setup.iAspectRatioWidth = 1228;
 
54
        Setup.iAspectRatioHeight = 768;
 
55
 
 
56
        Setup.CameraModeWithStandardAspectRatio = 0;
 
57
 
 
58
        Setup.TextureFilteringMode = 2;
 
59
        Setup.TexturesQuality = 3;
 
60
        Setup.MSAA = 0;
 
61
        Setup.CSAA = 0;
 
62
        Setup.VisualEffectsQuality = 0;
 
63
        Setup.AnisotropyLevel = 1;
 
64
        Setup.TexturesCompression = 1;
 
65
        Setup.UseGLSL = false;
 
66
        Setup.ShadowMap = 0;
 
67
        Setup.MaxPointLights = 3;
 
68
        Setup.MusicSw = 8;
 
69
        Setup.Music_check = true;
 
70
        Setup.SoundSw = 10;
 
71
        Setup.VoiceSw = 10;
 
72
        Setup.Sound_check = true;
 
73
        Setup.VSync = 0;
 
74
        Setup.Brightness = 5;
 
75
        Setup.ShowFPS = false;
 
76
        Setup.GameWeaponInfoType = 1;
 
77
        Setup.GameSpeed = 1.5f;
 
78
        Setup.LoadingHint = 0;
 
79
 
 
80
 
 
81
        Setup.KeyboardDecreaseGameSpeed = SDLK_F5;
 
82
        Setup.KeyboardResetGameSpeed = SDLK_F6;
 
83
        Setup.KeyboardIncreaseGameSpeed = SDLK_F7;
 
84
        Setup.KeyboardGameWeaponInfoType = SDLK_F8;
 
85
        Setup.KeyboardPrimaryWeaponFireMode = SDLK_F9;
 
86
        Setup.KeyboardSecondaryWeaponFireMode = SDLK_F10;
 
87
 
 
88
        Setup.KeyBoardLeft = SDLK_LEFT;
 
89
        Setup.KeyBoardRight = SDLK_RIGHT;
 
90
        Setup.KeyBoardUp = SDLK_UP;
 
91
        Setup.KeyBoardDown = SDLK_DOWN;
 
92
        Setup.KeyBoardPrimary = SDLK_LCTRL;
 
93
        Setup.KeyBoardSecondary = SDLK_SPACE;
 
94
        Setup.MousePrimary = SDL_BUTTON_LEFT;
 
95
        Setup.MouseSecondary = SDL_BUTTON_RIGHT;
 
96
        Setup.JoystickPrimary = 0;
 
97
        Setup.JoystickSecondary = 1;
 
98
        Setup.JoystickNum = 0;
 
99
 
 
100
        Setup.ControlSensivity = 5;
 
101
        Setup.MouseControl = true;
 
102
        Setup.LastProfile = -1;
 
103
        Setup.MenuScript = 0;
 
104
 
 
105
 
 
106
        strcpy(Setup.TopScores[0].Name, "Viewizard");
 
107
        Setup.TopScores[0].Score = 100000;
 
108
        strcpy(Setup.TopScores[1].Name, "Alex");
 
109
        Setup.TopScores[1].Score = 90000;
 
110
        strcpy(Setup.TopScores[2].Name, "Michael");
 
111
        Setup.TopScores[2].Score = 80000;
 
112
        strcpy(Setup.TopScores[3].Name, "Jeffrey");
 
113
        Setup.TopScores[3].Score = 70000;
 
114
        strcpy(Setup.TopScores[4].Name, "Christopher Hughson");
 
115
        Setup.TopScores[4].Score = 60000;
 
116
        strcpy(Setup.TopScores[5].Name, "Becky");
 
117
        Setup.TopScores[5].Score = 40000;
 
118
        strcpy(Setup.TopScores[6].Name, "Greg");
 
119
        Setup.TopScores[6].Score = 20000;
 
120
        strcpy(Setup.TopScores[7].Name, "Jay Coleman");
 
121
        Setup.TopScores[7].Score = 10000;
 
122
        strcpy(Setup.TopScores[8].Name, "Kelvin");
 
123
        Setup.TopScores[8].Score = 5000;
 
124
        strcpy(Setup.TopScores[9].Name, "Stephan Gregory");
 
125
        Setup.TopScores[9].Score = 1000;
 
126
 
 
127
 
 
128
        for(int i=0; i<5; i++)
 
129
                Setup.Profile[i].Used = false;
 
130
 
 
131
        // сбрасываем хинты в тру, чтобы показывать
 
132
        for(int i=0; i<10; i++)
 
133
                Setup.NeedShowHint[i] = true;
 
134
 
 
135
 
 
136
        // всегда включен по умолчанию, если что железо само поймет что ему надо
 
137
        Setup.VBOCoreMode = 1;
 
138
        Setup.VAOCoreMode = 1;
 
139
        Setup.FBOCoreMode = 1;
 
140
        // по умолчанию всегда меньше 128 метров
 
141
        Setup.EqualOrMore128MBVideoRAM = false;
 
142
        // по умолчанию генерируем в видео карте (после иниц. окна поставим правильное), по крайней мере в виндовс немного быстрее
 
143
        Setup.HardwareMipMapGeneration = true;
 
144
}
 
145
 
 
146
 
 
147
 
 
148
 
 
149
 
 
150
 
 
151
 
 
152
 
 
153
 
 
154
 
 
155
 
 
156
 
 
157
 
 
158
 
 
159
//-----------------------------------------------------------------------------
 
160
// записываем файл с настройками
 
161
//-----------------------------------------------------------------------------
 
162
void SaveXMLSetupFile()
 
163
{
 
164
        cXMLDocument *XMLdoc = new cXMLDocument;
 
165
 
 
166
        cXMLEntry *RootXMLEntry = XMLdoc->AddEntry(0, "AstroMenaceSettings");
 
167
 
 
168
        XMLdoc->AddComment(RootXMLEntry, " AstroMenace game Settings ");
 
169
 
 
170
 
 
171
 
 
172
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "GAME_BUILD"), "value", GAME_BUILD);
 
173
        switch (Setup.MenuLanguage)
 
174
        {
 
175
                case 1: XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MenuLanguage"), "value", "en"); break;
 
176
                case 2: XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MenuLanguage"), "value", "de"); break;
 
177
                case 3: XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MenuLanguage"), "value", "ru"); break;
 
178
        }
 
179
        switch (Setup.VoiceLanguage)
 
180
        {
 
181
                case 1: XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "VoiceLanguage"), "value", "en"); break;
 
182
                case 2: XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "VoiceLanguage"), "value", "de"); break;
 
183
                case 3: XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "VoiceLanguage"), "value", "ru"); break;
 
184
        }
 
185
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "FontNumber"), "value", Setup.FontNumber);
 
186
 
 
187
 
 
188
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "Width"), "value", Setup.Width);
 
189
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "Height"), "value", Setup.Height);
 
190
        XMLdoc->AddComment(RootXMLEntry, " Windows (BPP = 0) or Full Screen (BPP = 16 or 32) ");
 
191
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "BPP"), "value", Setup.BPP);
 
192
        XMLdoc->AddComment(RootXMLEntry, " Aspect Ratio must be 4:3 or 16:10 ");
 
193
        if (Setup.iAspectRatioWidth == 1024)
 
194
                XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "AspectRatio"), "value", "4:3");
 
195
        else
 
196
                XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "AspectRatio"), "value", "16:10");
 
197
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "CameraModeWithStandardAspectRatio"), "value", Setup.CameraModeWithStandardAspectRatio);
 
198
 
 
199
        XMLdoc->AddComment(RootXMLEntry, " Don't change this setting unless you know what you are doing ");
 
200
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "VBOCoreMode"), "value", Setup.VBOCoreMode);
 
201
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "VAOCoreMode"), "value", Setup.VAOCoreMode);
 
202
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "FBOCoreMode"), "value", Setup.FBOCoreMode);
 
203
        XMLdoc->AddComment(RootXMLEntry, " If your video card have 128+ MB VRAM on board - turn it on ");
 
204
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "EqualOrMore128MBVideoRAM"), "value", Setup.EqualOrMore128MBVideoRAM);
 
205
        XMLdoc->AddComment(RootXMLEntry, " Don't change this setting unless you know what you are doing ");
 
206
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "HardwareMipMapGeneration"), "value", Setup.HardwareMipMapGeneration);
 
207
 
 
208
 
 
209
        XMLdoc->AddComment(RootXMLEntry, " Common settings ");
 
210
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "TextureFilteringMode"), "value", Setup.TextureFilteringMode);
 
211
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "TexturesQuality"), "value", Setup.TexturesQuality);
 
212
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MSAA"), "value", Setup.MSAA);
 
213
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "CSAA"), "value", Setup.CSAA);
 
214
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "VisualEffectsQuality"), "value", Setup.VisualEffectsQuality);
 
215
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "AnisotropyLevel"), "value", Setup.AnisotropyLevel);
 
216
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "TexturesCompression"), "value", Setup.TexturesCompression);
 
217
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "UseGLSL"), "value", Setup.UseGLSL);
 
218
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "ShadowMap"), "value", Setup.ShadowMap);
 
219
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MaxPointLights"), "value", Setup.MaxPointLights);
 
220
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MusicSw"), "value", Setup.MusicSw);
 
221
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "SoundSw"), "value", Setup.SoundSw);
 
222
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "VoiceSw"), "value", Setup.VoiceSw);
 
223
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "VSync"), "value", Setup.VSync);
 
224
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "Brightness"), "value", Setup.Brightness);
 
225
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "ShowFPS"), "value", Setup.ShowFPS);
 
226
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "GameWeaponInfoType"), "value", Setup.GameWeaponInfoType);
 
227
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "GameSpeed"), "value", Setup.GameSpeed);
 
228
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "LoadingHint"), "value", Setup.LoadingHint);
 
229
 
 
230
 
 
231
        XMLdoc->AddComment(RootXMLEntry, " Control settings ");
 
232
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyboardDecreaseGameSpeed"), "value", vw_KeyboardCodeName(Setup.KeyboardDecreaseGameSpeed));
 
233
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyboardResetGameSpeed"), "value", vw_KeyboardCodeName(Setup.KeyboardResetGameSpeed));
 
234
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyboardIncreaseGameSpeed"), "value", vw_KeyboardCodeName(Setup.KeyboardIncreaseGameSpeed));
 
235
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyboardGameWeaponInfoType"), "value", vw_KeyboardCodeName(Setup.KeyboardGameWeaponInfoType));
 
236
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyboardPrimaryWeaponFireMode"), "value", vw_KeyboardCodeName(Setup.KeyboardPrimaryWeaponFireMode));
 
237
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyboardSecondaryWeaponFireMode"), "value", vw_KeyboardCodeName(Setup.KeyboardSecondaryWeaponFireMode));
 
238
 
 
239
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyBoardLeft"), "value", vw_KeyboardCodeName(Setup.KeyBoardLeft));
 
240
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyBoardRight"), "value", vw_KeyboardCodeName(Setup.KeyBoardRight));
 
241
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyBoardUp"), "value", vw_KeyboardCodeName(Setup.KeyBoardUp));
 
242
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyBoardDown"), "value", vw_KeyboardCodeName(Setup.KeyBoardDown));
 
243
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyBoardPrimary"), "value", vw_KeyboardCodeName(Setup.KeyBoardPrimary));
 
244
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "KeyBoardSecondary"), "value", vw_KeyboardCodeName(Setup.KeyBoardSecondary));
 
245
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MousePrimary"), "value", Setup.MousePrimary);
 
246
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MouseSecondary"), "value", Setup.MouseSecondary);
 
247
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "JoystickPrimary"), "value", Setup.JoystickPrimary);
 
248
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "JoystickSecondary"), "value", Setup.JoystickSecondary);
 
249
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "JoystickNum"), "value", Setup.JoystickNum);
 
250
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "ControlSensivity"), "value", Setup.ControlSensivity);
 
251
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MouseControl"), "value", Setup.MouseControl);
 
252
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "LastProfile"), "value", Setup.LastProfile);
 
253
        XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, "MenuScript"), "value", Setup.MenuScript);
 
254
 
 
255
        for(int i=0; i<10; i++)
 
256
        {
 
257
                char Name[128];
 
258
                sprintf(Name, "HintStatus%i", i+1);
 
259
                XMLdoc->AddEntryAttribute(XMLdoc->AddEntry(RootXMLEntry, Name), "value", Setup.NeedShowHint[i]);
 
260
        }
 
261
 
 
262
 
 
263
 
 
264
        //
 
265
        // всегда последние
 
266
        //
 
267
 
 
268
 
 
269
        // упаковка таблицы рекордов
 
270
        int TopScoresDataSize = sizeof(sTopScores)*10;
 
271
        unsigned char *TopScoresData = new unsigned char[TopScoresDataSize];
 
272
        memcpy(TopScoresData, Setup.TopScores, TopScoresDataSize);
 
273
 
 
274
        // сразу архивируем Хаффманом
 
275
        BYTE *dstVFS;
 
276
        int dsizeVFS;
 
277
        vw_DATAtoHAFF(&dstVFS, (BYTE *)TopScoresData, &dsizeVFS, TopScoresDataSize);
 
278
        delete [] TopScoresData;
 
279
        TopScoresDataSize = dsizeVFS;
 
280
        TopScoresData = (unsigned char *)dstVFS;
 
281
 
 
282
        unsigned char *TopScoresDataXORCode = new unsigned char[TopScoresDataSize*3];
 
283
        char *TopScoresResultString = new char[TopScoresDataSize*4+1];
 
284
 
 
285
 
 
286
        {
 
287
                // XOR
 
288
                int k1;
 
289
                int k2;
 
290
                for (int i=0; i < TopScoresDataSize; i++)
 
291
                {
 
292
                        k1 = i;
 
293
                        k2 = TopScoresDataSize + i*2;
 
294
                        TopScoresDataXORCode[k1] = 97 + (unsigned char)vw_iRandNum(25);
 
295
                        TopScoresDataXORCode[k2] = 0;
 
296
                        TopScoresDataXORCode[k2+1] = TopScoresData[i]^TopScoresDataXORCode[k1];
 
297
                        // в первую - десятки, во вторую - еденицы
 
298
                        TopScoresDataXORCode[k2] = 97 + (unsigned char)(TopScoresDataXORCode[k2+1]/10.0f);
 
299
                        TopScoresDataXORCode[k2+1] = 97 + (TopScoresDataXORCode[k2+1] - (TopScoresDataXORCode[k2]-97)*10);
 
300
                }
 
301
 
 
302
                // чтобы разбить на блоки вставляем пробел
 
303
                // тогда красиво отображаться будет (если врапинг выставлен в редакторе)
 
304
                int k=0;
 
305
                int l=0;
 
306
                for (int i=0; i < TopScoresDataSize*3; i++)
 
307
                {
 
308
                        TopScoresResultString[k] = TopScoresDataXORCode[i];
 
309
                        k++;
 
310
                        l++;
 
311
                        if (l >= 125)
 
312
                        {
 
313
                                TopScoresResultString[k] = 0x20;
 
314
                                k++;
 
315
                                l=0;
 
316
                        }
 
317
                }
 
318
                TopScoresResultString[k] = 0;
 
319
        }
 
320
 
 
321
        XMLdoc->AddEntryContent(XMLdoc->AddEntry(RootXMLEntry, "TopScores"), TopScoresResultString);
 
322
 
 
323
        if (TopScoresResultString != 0) delete [] TopScoresResultString;
 
324
        if (TopScoresData != 0) delete [] TopScoresData;
 
325
        if (TopScoresDataXORCode != 0) delete [] TopScoresDataXORCode;
 
326
 
 
327
 
 
328
 
 
329
 
 
330
        // упаковка профайлов
 
331
 
 
332
        {
 
333
                int ProfileDataSize = sizeof(GameProfile)*5;
 
334
                unsigned char *ProfileData = new unsigned char[ProfileDataSize];
 
335
                memcpy(ProfileData, Setup.Profile, ProfileDataSize);
 
336
 
 
337
                // сразу архивируем Хаффманом
 
338
                BYTE *dstVFS;
 
339
                int dsizeVFS;
 
340
                vw_DATAtoHAFF(&dstVFS, (BYTE *)ProfileData, &dsizeVFS, ProfileDataSize);
 
341
                delete [] ProfileData;
 
342
                ProfileDataSize = dsizeVFS;
 
343
                ProfileData = (unsigned char *)dstVFS;
 
344
 
 
345
                unsigned char *ProfileDataXORCode = new unsigned char[ProfileDataSize*3];
 
346
                char *ResultString = new char[ProfileDataSize*4+1];
 
347
 
 
348
 
 
349
                // XOR
 
350
                int k1;
 
351
                int k2;
 
352
                for (int i=0; i < ProfileDataSize; i++)
 
353
                {
 
354
                        k1 = i;
 
355
                        k2 = ProfileDataSize + i*2;
 
356
                        ProfileDataXORCode[k1] = 97 + (unsigned char)vw_iRandNum(25);
 
357
                        ProfileDataXORCode[k2] = 0;
 
358
                        ProfileDataXORCode[k2+1] = ProfileData[i]^ProfileDataXORCode[k1];
 
359
                        // в первую - десятки, во вторую - еденицы
 
360
                        ProfileDataXORCode[k2] = 97 + (unsigned char)(ProfileDataXORCode[k2+1]/10.0f);
 
361
                        ProfileDataXORCode[k2+1] = 97 + (ProfileDataXORCode[k2+1] - (ProfileDataXORCode[k2]-97)*10);
 
362
                        //fprintf(stderr, "--%i %i %i %i\n", ProfileDataXORCode[k], ProfileDataXORCode[k+1],ProfileDataXORCode[k+2],ProfileDataXORCode[k+3]);
 
363
                }
 
364
 
 
365
 
 
366
                // чтобы разбить на блоки вставляем пробел
 
367
                // тогда красиво отображаться будет (если врапинг выставлен в редакторе)
 
368
                int k=0;
 
369
                int l=0;
 
370
                for (int i=0; i < ProfileDataSize*3; i++)
 
371
                {
 
372
                        ResultString[k] = ProfileDataXORCode[i];
 
373
                        k++;
 
374
                        l++;
 
375
                        if (l >= 125)
 
376
                        {
 
377
                                ResultString[k] = 0x20;
 
378
                                k++;
 
379
                                l=0;
 
380
                        }
 
381
                }
 
382
                ResultString[k] = 0;
 
383
 
 
384
                XMLdoc->AddEntryContent(XMLdoc->AddEntry(RootXMLEntry, "PilotsProfiles"), ResultString);
 
385
 
 
386
                if (ResultString != 0) delete [] ResultString;
 
387
                if (ProfileData != 0) delete [] ProfileData;
 
388
                if (ProfileDataXORCode != 0) delete [] ProfileDataXORCode;
 
389
        }
 
390
 
 
391
 
 
392
 
 
393
 
 
394
        XMLdoc->Save(DatFileName);
 
395
        delete XMLdoc;
 
396
}
 
397
 
 
398
 
 
399
 
 
400
 
 
401
 
 
402
 
 
403
 
 
404
 
 
405
 
 
406
 
 
407
 
 
408
 
 
409
 
 
410
//-----------------------------------------------------------------------------
 
411
// считываем файл с настройками
 
412
//-----------------------------------------------------------------------------
 
413
bool LoadXMLSetupFile(bool NeedSafeMode)
 
414
{
 
415
        cXMLDocument *XMLdoc = new cXMLDocument;
 
416
 
 
417
        // устанавливаем базовые настройки
 
418
        InitSetup();
 
419
 
 
420
 
 
421
        // читаем данные
 
422
        if (!XMLdoc->Load(DatFileName))
 
423
        {
 
424
                delete XMLdoc;
 
425
                SaveXMLSetupFile();
 
426
                return true;
 
427
        }
 
428
 
 
429
 
 
430
 
 
431
        // берем первый элемент в скрипте
 
432
        cXMLEntry *RootXMLEntry = XMLdoc->RootXMLEntry;
 
433
 
 
434
 
 
435
 
 
436
        // дополнительная проверка на содержимое конфигурационного файла
 
437
        if (RootXMLEntry == 0)
 
438
        {
 
439
                fprintf(stderr, "Game configuration file corrupted: %s\n", DatFileName);
 
440
                // файл поврежден, надо завершить работу с ним
 
441
                delete XMLdoc;
 
442
                // сохранить дефолтные настройки, перезаписав файл
 
443
                SaveXMLSetupFile();
 
444
                // и сказать игре что это "первый запуск"
 
445
                return true;
 
446
        }
 
447
        if (strcmp("AstroMenaceSettings", RootXMLEntry->Name))
 
448
        {
 
449
                fprintf(stderr, "Game configuration file corrupted: %s\n", DatFileName);
 
450
                // файл поврежден, надо завершить работу с ним
 
451
                delete XMLdoc;
 
452
                // сохранить дефолтные настройки, перезаписав файл
 
453
                SaveXMLSetupFile();
 
454
                // и сказать игре что это "первый запуск"
 
455
                return true;
 
456
        }
 
457
 
 
458
 
 
459
 
 
460
 
 
461
        // если установлен NeedSafeMode, не грузим часть данных
 
462
        if (NeedSafeMode) goto LoadProfiles;
 
463
 
 
464
 
 
465
        if (XMLdoc->FindEntryByName(RootXMLEntry, "MenuLanguage") != 0)
 
466
        {
 
467
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MenuLanguage"), "value") != 0)
 
468
                {
 
469
                        if (!strcmp(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MenuLanguage"), "value"), "en")) Setup.MenuLanguage = 1;
 
470
                        else
 
471
                        if (!strcmp(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MenuLanguage"), "value"), "de")) Setup.MenuLanguage = 2;
 
472
                        else
 
473
                        if (!strcmp(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MenuLanguage"), "value"), "ru")) Setup.MenuLanguage = 3;
 
474
                }
 
475
        }
 
476
        if (XMLdoc->FindEntryByName(RootXMLEntry, "VoiceLanguage") != 0)
 
477
        {
 
478
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VoiceLanguage"), "value") != 0)
 
479
                {
 
480
                        if (!strcmp(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VoiceLanguage"), "value"), "en")) Setup.VoiceLanguage = 1;
 
481
                        else
 
482
                        if (!strcmp(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VoiceLanguage"), "value"), "de")) Setup.VoiceLanguage = 2;
 
483
                        else
 
484
                        if (!strcmp(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VoiceLanguage"), "value"), "ru")) Setup.VoiceLanguage = 3;
 
485
                }
 
486
        }
 
487
        if (XMLdoc->FindEntryByName(RootXMLEntry, "FontNumber") != 0)
 
488
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "FontNumber"), "value") != 0)
 
489
                        Setup.FontNumber = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "FontNumber"), "value");
 
490
 
 
491
        if (XMLdoc->FindEntryByName(RootXMLEntry, "Width") != 0)
 
492
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "Width"), "value") != 0)
 
493
                        Setup.Width = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "Width"), "value");
 
494
        if (XMLdoc->FindEntryByName(RootXMLEntry, "Height") != 0)
 
495
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "Height"), "value") != 0)
 
496
                        Setup.Height = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "Height"), "value");
 
497
        if (XMLdoc->FindEntryByName(RootXMLEntry, "BPP") != 0)
 
498
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "BPP"), "value") != 0)
 
499
                        Setup.BPP = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "BPP"), "value");
 
500
 
 
501
        if (XMLdoc->FindEntryByName(RootXMLEntry, "AspectRatio") != 0)
 
502
        {
 
503
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "AspectRatio"), "value") != 0)
 
504
                {
 
505
                        if (!strcmp(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "AspectRatio"), "value"), "16:10"))
 
506
                        {
 
507
                                Setup.fAspectRatioWidth = 1228.0f;
 
508
                                Setup.fAspectRatioHeight = 768.0f;
 
509
                                Setup.iAspectRatioWidth = 1228;
 
510
                                Setup.iAspectRatioHeight = 768;
 
511
                        }
 
512
                        else
 
513
                        {
 
514
                                Setup.fAspectRatioWidth = 1024.0f;
 
515
                                Setup.fAspectRatioHeight = 768.0f;
 
516
                                Setup.iAspectRatioWidth = 1024;
 
517
                                Setup.iAspectRatioHeight = 768;
 
518
                        }
 
519
                }
 
520
        }
 
521
        if (XMLdoc->FindEntryByName(RootXMLEntry, "CameraModeWithStandardAspectRatio") != 0)
 
522
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "CameraModeWithStandardAspectRatio"), "value") != 0)
 
523
                        Setup.CameraModeWithStandardAspectRatio = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "CameraModeWithStandardAspectRatio"), "value");
 
524
 
 
525
        if (XMLdoc->FindEntryByName(RootXMLEntry, "VBOCoreMode") != 0)
 
526
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VBOCoreMode"), "value") != 0)
 
527
                        Setup.VBOCoreMode = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VBOCoreMode"), "value");
 
528
        if (XMLdoc->FindEntryByName(RootXMLEntry, "VAOCoreMode") != 0)
 
529
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VAOCoreMode"), "value") != 0)
 
530
                        Setup.VAOCoreMode = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VAOCoreMode"), "value");
 
531
        if (XMLdoc->FindEntryByName(RootXMLEntry, "FBOCoreMode") != 0)
 
532
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "FBOCoreMode"), "value") != 0)
 
533
                        Setup.FBOCoreMode = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "FBOCoreMode"), "value");
 
534
        if (XMLdoc->FindEntryByName(RootXMLEntry, "EqualOrMore128MBVideoRAM") != 0)
 
535
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "EqualOrMore128MBVideoRAM"), "value") != 0)
 
536
                        Setup.EqualOrMore128MBVideoRAM = XMLdoc->bGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "EqualOrMore128MBVideoRAM"), "value");
 
537
        if (XMLdoc->FindEntryByName(RootXMLEntry, "HardwareMipMapGeneration") != 0)
 
538
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "HardwareMipMapGeneration"), "value") != 0)
 
539
                        Setup.HardwareMipMapGeneration = XMLdoc->bGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "HardwareMipMapGeneration"), "value");
 
540
 
 
541
        if (XMLdoc->FindEntryByName(RootXMLEntry, "TextureFilteringMode") != 0)
 
542
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "TextureFilteringMode"), "value") != 0)
 
543
                        Setup.TextureFilteringMode = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "TextureFilteringMode"), "value");
 
544
        if (XMLdoc->FindEntryByName(RootXMLEntry, "TexturesQuality") != 0)
 
545
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "TexturesQuality"), "value") != 0)
 
546
                        Setup.TexturesQuality = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "TexturesQuality"), "value");
 
547
        if (XMLdoc->FindEntryByName(RootXMLEntry, "MSAA") != 0)
 
548
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MSAA"), "value") != 0)
 
549
                        Setup.MSAA = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MSAA"), "value");
 
550
        if (XMLdoc->FindEntryByName(RootXMLEntry, "CSAA") != 0)
 
551
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "CSAA"), "value") != 0)
 
552
                        Setup.CSAA = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "CSAA"), "value");
 
553
        if (XMLdoc->FindEntryByName(RootXMLEntry, "VisualEffectsQuality") != 0)
 
554
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VisualEffectsQuality"), "value") != 0)
 
555
                        Setup.VisualEffectsQuality = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VisualEffectsQuality"), "value");
 
556
        if (XMLdoc->FindEntryByName(RootXMLEntry, "AnisotropyLevel") != 0)
 
557
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "AnisotropyLevel"), "value") != 0)
 
558
                        Setup.AnisotropyLevel = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "AnisotropyLevel"), "value");
 
559
        if (XMLdoc->FindEntryByName(RootXMLEntry, "TexturesCompression") != 0)
 
560
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "TexturesCompression"), "value") != 0)
 
561
                        Setup.TexturesCompression = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "TexturesCompression"), "value");
 
562
        if (XMLdoc->FindEntryByName(RootXMLEntry, "UseGLSL") != 0)
 
563
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "UseGLSL"), "value") != 0)
 
564
                        Setup.UseGLSL = XMLdoc->bGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "UseGLSL"), "value");
 
565
        if (XMLdoc->FindEntryByName(RootXMLEntry, "ShadowMap") != 0)
 
566
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "ShadowMap"), "value") != 0)
 
567
                        Setup.ShadowMap = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "ShadowMap"), "value");
 
568
        if (XMLdoc->FindEntryByName(RootXMLEntry, "MaxPointLights") != 0)
 
569
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MaxPointLights"), "value") != 0)
 
570
                        Setup.MaxPointLights = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MaxPointLights"), "value");
 
571
        if (XMLdoc->FindEntryByName(RootXMLEntry, "MusicSw") != 0)
 
572
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MusicSw"), "value") != 0)
 
573
                        Setup.MusicSw = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MusicSw"), "value");
 
574
        if (XMLdoc->FindEntryByName(RootXMLEntry, "SoundSw") != 0)
 
575
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "SoundSw"), "value") != 0)
 
576
                        Setup.SoundSw = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "SoundSw"), "value");
 
577
        if (XMLdoc->FindEntryByName(RootXMLEntry, "VoiceSw") != 0)
 
578
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VoiceSw"), "value") != 0)
 
579
                        Setup.VoiceSw = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VoiceSw"), "value");
 
580
        if (XMLdoc->FindEntryByName(RootXMLEntry, "VSync") != 0)
 
581
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VSync"), "value") != 0)
 
582
                        Setup.VSync = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "VSync"), "value");
 
583
        if (XMLdoc->FindEntryByName(RootXMLEntry, "Brightness") != 0)
 
584
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "Brightness"), "value") != 0)
 
585
                        Setup.Brightness = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "Brightness"), "value");
 
586
        if (XMLdoc->FindEntryByName(RootXMLEntry, "ShowFPS") != 0)
 
587
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "ShowFPS"), "value") != 0)
 
588
                        Setup.ShowFPS = XMLdoc->bGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "ShowFPS"), "value");
 
589
        if (XMLdoc->FindEntryByName(RootXMLEntry, "GameWeaponInfoType") != 0)
 
590
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "GameWeaponInfoType"), "value") != 0)
 
591
                        Setup.GameWeaponInfoType = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "GameWeaponInfoType"), "value");
 
592
        if (XMLdoc->FindEntryByName(RootXMLEntry, "GameSpeed") != 0)
 
593
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "GameSpeed"), "value") != 0)
 
594
                        Setup.GameSpeed = XMLdoc->fGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "GameSpeed"), "value");
 
595
        if (XMLdoc->FindEntryByName(RootXMLEntry, "LoadingHint") != 0)
 
596
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "LoadingHint"), "value") != 0)
 
597
                        Setup.LoadingHint = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "LoadingHint"), "value");
 
598
 
 
599
 
 
600
 
 
601
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardDecreaseGameSpeed") != 0)
 
602
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardDecreaseGameSpeed"), "value") != 0)
 
603
                        Setup.KeyboardDecreaseGameSpeed = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardDecreaseGameSpeed"), "value"));
 
604
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardResetGameSpeed") != 0)
 
605
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardResetGameSpeed"), "value") != 0)
 
606
                        Setup.KeyboardResetGameSpeed = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardResetGameSpeed"), "value"));
 
607
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardIncreaseGameSpeed") != 0)
 
608
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardIncreaseGameSpeed"), "value") != 0)
 
609
                        Setup.KeyboardIncreaseGameSpeed = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardIncreaseGameSpeed"), "value"));
 
610
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardGameWeaponInfoType") != 0)
 
611
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardGameWeaponInfoType"), "value") != 0)
 
612
                        Setup.KeyboardGameWeaponInfoType = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardGameWeaponInfoType"), "value"));
 
613
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardPrimaryWeaponFireMode") != 0)
 
614
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardPrimaryWeaponFireMode"), "value") != 0)
 
615
                        Setup.KeyboardPrimaryWeaponFireMode = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardPrimaryWeaponFireMode"), "value"));
 
616
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardSecondaryWeaponFireMode") != 0)
 
617
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardSecondaryWeaponFireMode"), "value") != 0)
 
618
                        Setup.KeyboardSecondaryWeaponFireMode = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyboardSecondaryWeaponFireMode"), "value"));
 
619
 
 
620
 
 
621
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardLeft") != 0)
 
622
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardLeft"), "value") != 0)
 
623
                        Setup.KeyBoardLeft = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardLeft"), "value"));
 
624
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardRight") != 0)
 
625
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardRight"), "value") != 0)
 
626
                        Setup.KeyBoardRight = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardRight"), "value"));
 
627
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardUp") != 0)
 
628
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardUp"), "value") != 0)
 
629
                        Setup.KeyBoardUp = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardUp"), "value"));
 
630
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardDown") != 0)
 
631
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardDown"), "value") != 0)
 
632
                        Setup.KeyBoardDown = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardDown"), "value"));
 
633
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardPrimary") != 0)
 
634
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardPrimary"), "value") != 0)
 
635
                        Setup.KeyBoardPrimary = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardPrimary"), "value"));
 
636
        if (XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardSecondary") != 0)
 
637
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardSecondary"), "value") != 0)
 
638
                        Setup.KeyBoardSecondary = vw_KeyboardNameCode(XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "KeyBoardSecondary"), "value"));
 
639
 
 
640
        if (XMLdoc->FindEntryByName(RootXMLEntry, "MousePrimary") != 0)
 
641
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MousePrimary"), "value") != 0)
 
642
                        Setup.MousePrimary = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MousePrimary"), "value");
 
643
        if (XMLdoc->FindEntryByName(RootXMLEntry, "MouseSecondary") != 0)
 
644
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MouseSecondary"), "value") != 0)
 
645
                        Setup.MouseSecondary = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MouseSecondary"), "value");
 
646
        if (XMLdoc->FindEntryByName(RootXMLEntry, "JoystickPrimary") != 0)
 
647
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "JoystickPrimary"), "value") != 0)
 
648
                        Setup.JoystickPrimary = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "JoystickPrimary"), "value");
 
649
        if (XMLdoc->FindEntryByName(RootXMLEntry, "JoystickSecondary") != 0)
 
650
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "JoystickSecondary"), "value") != 0)
 
651
                        Setup.JoystickSecondary = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "JoystickSecondary"), "value");
 
652
        if (XMLdoc->FindEntryByName(RootXMLEntry, "JoystickNum") != 0)
 
653
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "JoystickNum"), "value") != 0)
 
654
                        Setup.JoystickNum = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "JoystickNum"), "value");
 
655
        if (XMLdoc->FindEntryByName(RootXMLEntry, "ControlSensivity") != 0)
 
656
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "ControlSensivity"), "value") != 0)
 
657
                        Setup.ControlSensivity = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "ControlSensivity"), "value");
 
658
        if (XMLdoc->FindEntryByName(RootXMLEntry, "MouseControl") != 0)
 
659
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MouseControl"), "value") != 0)
 
660
                        Setup.MouseControl = XMLdoc->bGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MouseControl"), "value");
 
661
        if (XMLdoc->FindEntryByName(RootXMLEntry, "LastProfile") != 0)
 
662
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "LastProfile"), "value") != 0)
 
663
                        Setup.LastProfile = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "LastProfile"), "value");
 
664
        if (XMLdoc->FindEntryByName(RootXMLEntry, "MenuScript") != 0)
 
665
                if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MenuScript"), "value") != 0)
 
666
                        Setup.MenuScript = XMLdoc->iGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, "MenuScript"), "value");
 
667
 
 
668
 
 
669
        for(int i=0; i<10; i++)
 
670
        {
 
671
                char Name[128];
 
672
                sprintf(Name, "HintStatus%i", i+1);
 
673
                if (XMLdoc->FindEntryByName(RootXMLEntry, Name) != 0)
 
674
                        if (XMLdoc->GetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, Name), "value") != 0)
 
675
                                Setup.NeedShowHint[i] = XMLdoc->bGetEntryAttribute(XMLdoc->FindEntryByName(RootXMLEntry, Name), "value");
 
676
        }
 
677
 
 
678
 
 
679
 
 
680
 
 
681
        //
 
682
        // заполняем таблицу рекордов
 
683
        //
 
684
 
 
685
        if ((XMLdoc->FindEntryByName(RootXMLEntry, "TopScores") != 0) && (XMLdoc->FindEntryByName(RootXMLEntry, "TopScores")->Content != 0))
 
686
        {
 
687
 
 
688
                int TopScoresDataSize = strlen(XMLdoc->FindEntryByName(RootXMLEntry, "TopScores")->Content);
 
689
                unsigned char *TopScoresData = new unsigned char[TopScoresDataSize+1];
 
690
                unsigned char *TopScoresDataXORCode = new unsigned char[TopScoresDataSize+1];
 
691
                char *TopScoresResultString = new char[TopScoresDataSize+1];
 
692
 
 
693
                strcpy(TopScoresResultString, XMLdoc->FindEntryByName(RootXMLEntry, "TopScores")->Content);
 
694
 
 
695
                // первый цикл, восстанавливаем правильную последовательность, убираем все лишние элементы
 
696
                int k=0;
 
697
                for (int i=0; i<TopScoresDataSize; i++)
 
698
                {
 
699
                        // берем только нужные символы
 
700
                        if (TopScoresResultString[i] >= 97 && TopScoresResultString[i] <= 97+26)
 
701
                        {
 
702
                                TopScoresDataXORCode[k] = TopScoresResultString[i];
 
703
                                k++;
 
704
                        }
 
705
                }
 
706
                // находим правильное значение, т.к. загружали использую длину строки (!!!)
 
707
                TopScoresDataSize = k/3;
 
708
 
 
709
                // второй цикл, восстанавливаем последовательность структуры
 
710
                int k1;
 
711
                int k2;
 
712
                for (int i=0; i<TopScoresDataSize; i++)
 
713
                {
 
714
                        k1 = i;
 
715
                        k2 = TopScoresDataSize + i*2;
 
716
 
 
717
                        unsigned char XORhash = TopScoresDataXORCode[k1];
 
718
                        unsigned char XORdata = ((TopScoresDataXORCode[k2]-97)*10) + (TopScoresDataXORCode[k2+1]-97);
 
719
 
 
720
                        TopScoresData[i] = XORdata^XORhash;
 
721
                }
 
722
 
 
723
                // третий цикл, распаковка Хаффмана
 
724
                BYTE *dstVFS;
 
725
                int dsizeVFS;
 
726
                vw_HAFFtoDATA(sizeof(sTopScores)*10, &dstVFS, (BYTE *)TopScoresData, &dsizeVFS, TopScoresDataSize);
 
727
                delete [] TopScoresData;
 
728
                TopScoresDataSize = dsizeVFS;
 
729
                TopScoresData = (unsigned char *)dstVFS;
 
730
 
 
731
                // переносим данные в структуру
 
732
                memcpy(Setup.TopScores, TopScoresData, TopScoresDataSize);
 
733
 
 
734
                if (TopScoresResultString != 0) delete [] TopScoresResultString;
 
735
                if (TopScoresData != 0) delete [] TopScoresData;
 
736
                if (TopScoresDataXORCode != 0) delete [] TopScoresDataXORCode;
 
737
        }
 
738
 
 
739
 
 
740
 
 
741
 
 
742
 
 
743
LoadProfiles:
 
744
 
 
745
        //
 
746
        // загрузка профайлов пилотов
 
747
        //
 
748
 
 
749
        if ((XMLdoc->FindEntryByName(RootXMLEntry, "PilotsProfiles") != 0) && (XMLdoc->FindEntryByName(RootXMLEntry, "PilotsProfiles")->Content != 0))
 
750
        {
 
751
                int ProfileDataSize = strlen(XMLdoc->FindEntryByName(RootXMLEntry, "PilotsProfiles")->Content);
 
752
                unsigned char *ProfileData = new unsigned char[ProfileDataSize+1];
 
753
                unsigned char *ProfileDataXORCode = new unsigned char[ProfileDataSize+1];
 
754
                char *ResultString = new char[ProfileDataSize+1];
 
755
 
 
756
                strcpy(ResultString, XMLdoc->FindEntryByName(RootXMLEntry, "PilotsProfiles")->Content);
 
757
 
 
758
                // первый цикл, восстанавливаем правильную последовательность, убираем все лишние элементы
 
759
                int k=0;
 
760
                for (unsigned int i=0; i<strlen(ResultString); i++)
 
761
                {
 
762
                        // берем только нужные символы
 
763
                        if (ResultString[i] >= 97 && ResultString[i] <= 97+26)
 
764
                        {
 
765
                                ProfileDataXORCode[k] = ResultString[i];
 
766
                                k++;
 
767
                        }
 
768
                }
 
769
                // находим правильное значение, т.к. загружали используя длину строки (!!!)
 
770
                ProfileDataSize = k/3;
 
771
 
 
772
                // второй цикл, восстанавливаем последовательность структуры
 
773
                int k1;
 
774
                int k2;
 
775
                for (int i=0; i<ProfileDataSize; i++)
 
776
                {
 
777
                        k1 = i;
 
778
                        k2 = ProfileDataSize + i*2;
 
779
 
 
780
                        unsigned char XORhash = ProfileDataXORCode[k1];
 
781
                        unsigned char XORdata = ((ProfileDataXORCode[k2]-97)*10) + (ProfileDataXORCode[k2+1]-97);
 
782
 
 
783
                        ProfileData[i] = XORdata^XORhash;
 
784
                }
 
785
 
 
786
                // третий цикл, распаковка Хаффмана
 
787
                BYTE *dstVFS;
 
788
                int dsizeVFS;
 
789
                vw_HAFFtoDATA(sizeof(GameProfile)*5, &dstVFS, (BYTE *)ProfileData, &dsizeVFS, ProfileDataSize);
 
790
                delete [] ProfileData;
 
791
                ProfileDataSize = dsizeVFS;
 
792
                ProfileData = (unsigned char *)dstVFS;
 
793
 
 
794
                // переносим данные в структуру
 
795
                memcpy(Setup.Profile, ProfileData, ProfileDataSize);
 
796
 
 
797
                if (ResultString != 0) delete [] ResultString;
 
798
                if (ProfileData != 0) delete [] ProfileData;
 
799
                if (ProfileDataXORCode != 0) delete [] ProfileDataXORCode;
 
800
        }
 
801
 
 
802
 
 
803
 
 
804
 
 
805
 
 
806
 
 
807
 
 
808
        //
 
809
        // делаем изменения, проверки и т.п.
 
810
        //
 
811
 
 
812
        if (Setup.KeyBoardUp == 0) Setup.KeyBoardUp = SDLK_UP;
 
813
        if (Setup.KeyBoardDown == 0) Setup.KeyBoardDown = SDLK_DOWN;
 
814
        if (Setup.KeyBoardLeft == 0) Setup.KeyBoardLeft = SDLK_LEFT;
 
815
        if (Setup.KeyBoardRight == 0) Setup.KeyBoardRight = SDLK_RIGHT;
 
816
        if (Setup.KeyBoardPrimary == 0) Setup.KeyBoardPrimary = SDLK_LCTRL;
 
817
        if (Setup.KeyBoardSecondary == 0) Setup.KeyBoardSecondary = SDLK_SPACE;
 
818
        if (Setup.MousePrimary == 0) Setup.MousePrimary = SDL_BUTTON_LEFT;
 
819
        if (Setup.MouseSecondary == 0) Setup.MouseSecondary = SDL_BUTTON_RIGHT;
 
820
        if (Setup.JoystickPrimary == -1) Setup.JoystickPrimary = 0;
 
821
        if (Setup.JoystickSecondary == -1) Setup.JoystickSecondary = 1;
 
822
 
 
823
        CurrentProfile = Setup.LastProfile;
 
824
        if (CurrentProfile != -1) CurrentMission = Setup.Profile[Setup.LastProfile].LastMission;
 
825
 
 
826
        delete XMLdoc;
 
827
 
 
828
        return false;
 
829
}
 
830
 
 
831
 
 
832