DEADSOFTWARE

game: do not force CLI pathes to cwd
[d2df-sdl.git] / src / game / g_main.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_main;
18 interface
20 uses Utils;
22 procedure Main ();
23 procedure Init ();
24 procedure Release ();
25 procedure Update ();
26 procedure Draw ();
27 procedure KeyPress (K: Word);
28 procedure CharPress (C: AnsiChar);
30 var
31 {--- TO REMOVE ---}
32 //GameDir: string;
33 {-----------------}
35 {--- Read-only dirs ---}
36 GameWAD: string;
37 DataDirs: SSArray;
38 ModelDirs: SSArray;
39 MegawadDirs: SSArray;
40 MapDirs: SSArray;
41 WadDirs: SSArray;
42 AllMapDirs: SSArray; // Maps + Megawads
44 {--- Read-Write dirs ---}
45 LogFileName: string;
46 LogDirs: SSArray;
47 SaveDirs: SSArray;
48 CacheDirs: SSArray;
49 ConfigDirs: SSArray;
50 ScreenshotDirs: SSArray;
51 MapDownloadDirs: SSArray;
52 WadDownloadDirs: SSArray;
54 implementation
56 uses
57 {$INCLUDE ../nogl/noGLuses.inc}
58 {$IFDEF ENABLE_HOLMES}
59 g_holmes, sdlcarcass, fui_ctls, fui_wadread, fui_style, fui_gfx_gl,
60 {$ENDIF}
61 {$IFDEF LINUX}
62 BaseUnix,
63 {$ENDIF}
64 wadreader, e_log, g_window,
65 e_graphics, e_input, g_game, g_console, g_gui,
66 e_sound, g_options, g_sound, g_player, g_basic,
67 g_weapons, SysUtils, g_triggers, MAPDEF, g_map, e_res,
68 g_menu, g_language, g_net, g_touch, g_system, g_res_downloader,
69 conbuf, envvars,
70 xparser;
73 var
74 charbuff: packed array [0..15] of AnsiChar;
75 binPath: AnsiString = '';
76 forceCurrentDir: Boolean = false;
79 function GetBinaryPath (): AnsiString;
80 {$IFDEF LINUX}
81 var
82 //cd: AnsiString;
83 sl: AnsiString;
84 {$ENDIF}
85 begin
86 result := ExtractFilePath(ParamStr(0));
87 {$IFDEF LINUX}
88 // it may be a symlink; do some guesswork here
89 sl := fpReadLink(ExtractFileName(ParamStr(0)));
90 if (sl = ParamStr(0)) then
91 begin
92 // use current directory, as we don't have anything better
93 //result := '.';
94 GetDir(0, result);
95 end;
96 {$ENDIF}
97 result := fixSlashes(result);
98 if (length(result) > 0) and (result[length(result)] <> '/') then result := result+'/';
99 end;
102 procedure InitPath;
103 var i: Integer; rwdir, rodir: AnsiString;
104 //first: Boolean = true;
106 procedure xput (s: AnsiString);
108 var
109 f: TextFile;
110 begin
111 AssignFile(f, 'zzz.log');
112 if (first) then
113 begin
114 Rewrite(f);
115 first := false;
116 end
117 else
118 begin
119 Append(f);
120 end;
121 writeln(f, s);
122 CloseFile(f);
123 end;
125 begin
126 end;
128 procedure AddPath (var arr: SSArray; str: AnsiString; usecwd: Boolean=true);
129 var
130 ss: ShortString;
131 begin
132 if (length(str) = 0) then exit;
133 //writeln('NEW PATH(0): ['+str+']');
134 if (forceCurrentDir or usecwd) then
135 begin
136 str := fixSlashes(ExpandFileName(str));
137 end
138 else
139 begin
140 str := fixSlashes(str);
141 if (not isAbsolutePath(str)) then str := binPath+str;
142 while (length(str) > 0) do
143 begin
144 if (isRootPath(str)) then exit;
145 if (str[length(str)] = '/') then begin Delete(str, length(str), 1); continue; end;
146 if (length(str) >= 2) and (Copy(str, length(str)-1, 2) = '/.') then begin Delete(str, length(str)-1, 2); continue; end;
147 break;
148 end;
149 end;
150 if (length(str) = 0) then exit;
151 if (length(str) > 255) then
152 begin
153 xput('path too long: ['+str+']');
154 raise Exception.Create(Format('path "%s" too long', [str]));
155 end;
156 for ss in arr do
157 begin
158 //writeln('<<<', ss, '>>> : [', str, ']');
159 if (ss = str) then exit;
160 end;
161 SetLength(arr, Length(arr)+1);
162 //arr[High(arr)] := ExpandFileName(str);
163 arr[High(arr)] := str;
164 //writeln('NEW PATH(1): ['+str+']');
165 end;
167 procedure AddDef (var arr: SSArray; str: AnsiString);
168 begin
169 if (length(arr) = 0) then AddPath(arr, str, false)
170 end;
172 begin
173 //GetDir(0, GameDir);
174 binPath := GetBinaryPath();
175 xput('binPath=['+binPath+']');
177 for i := 1 to ParamCount do if (ParamStr(i) = '--cwd') then begin forceCurrentDir := true; break; end;
179 i := 1;
180 while i < ParamCount do
181 begin
182 case ParamStr(i) of
183 '--rw-dir':
184 begin
185 Inc(i);
186 rwdir := ParamStr(i);
187 (* RW *)
188 AddPath(LogDirs, e_CatPath(rwdir, ''));
189 AddPath(SaveDirs, e_CatPath(rwdir, 'data'));
190 AddPath(CacheDirs, e_CatPath(rwdir, 'data/cache'));
191 AddPath(ConfigDirs, e_CatPath(rwdir, ''));
192 AddPath(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads'));
193 AddPath(WadDownloadDirs, e_CatPath(rwdir, 'wads/downloads'));
194 AddPath(ScreenshotDirs, e_CatPath(rwdir, 'screenshots'));
195 (* RO *)
196 AddPath(DataDirs, e_CatPath(rwdir, 'data'));
197 AddPath(ModelDirs, e_CatPath(rwdir, 'data/models'));
198 AddPath(MegawadDirs, e_CatPath(rwdir, 'maps/megawads'));
199 AddPath(MapDirs, e_CatPath(rwdir, 'maps'));
200 AddPath(WadDirs, e_CatPath(rwdir, 'wads'));
201 end;
202 '--ro-dir':
203 begin
204 Inc(i);
205 rodir := ParamStr(i);
206 (* RO *)
207 AddPath(DataDirs, e_CatPath(rodir, 'data'));
208 AddPath(ModelDirs, e_CatPath(rodir, 'data/models'));
209 AddPath(MegawadDirs, e_CatPath(rodir, 'maps/megawads'));
210 AddPath(MapDirs, e_CatPath(rodir, 'maps'));
211 AddPath(WadDirs, e_CatPath(rodir, 'wads'));
212 end;
213 end;
214 Inc(i)
215 end;
217 (* RO *)
218 AddDef(DataDirs, 'data');
219 AddDef(ModelDirs, 'data/models');
220 AddDef(MegawadDirs, 'maps/megawads');
221 AddDef(MapDirs, 'maps');
222 AddDef(WadDirs, 'wads');
223 (* RW *)
224 AddDef(LogDirs, '.');
225 AddDef(SaveDirs, 'data');
226 AddDef(CacheDirs, 'data/cache');
227 AddDef(ConfigDirs, '.');
228 AddDef(MapDownloadDirs, 'maps/downloads');
229 AddDef(WadDownloadDirs, 'wads/downloads');
230 AddDef(ScreenshotDirs, 'screenshots');
232 for i := 0 to High(MapDirs) do
233 AddPath(AllMapDirs, MapDirs[i]);
234 for i := 0 to High(MegawadDirs) do
235 AddPath(AllMapDirs, MegawadDirs[i]);
237 if LogFileName = '' then
238 begin
239 rwdir := e_GetWriteableDir(LogDirs, false);
240 if rwdir <> '' then
241 begin
242 {$IFDEF HEADLESS}
243 LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
244 {$ELSE}
245 LogFileName := e_Catpath(rwdir, 'Doom2DF.log');
246 {$ENDIF}
247 end
248 end;
250 xput('binPath=['+binPath+']');
251 end;
253 procedure Main();
254 {$IFDEF ENABLE_HOLMES}
255 var flexloaded: Boolean;
256 {$ENDIF}
257 var s: AnsiString;
258 begin
259 InitPath;
260 if LogFileName <> '' then
261 e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
262 e_InitWritelnDriver();
264 // e_InitLog(GameDir + '/' + LogFileName, TWriteMode.WM_NEWFILE);
266 e_WriteLog(
267 'Doom 2D: Forever version ' + GAME_VERSION +
268 ' proto ' + IntToStr(NET_PROTOCOL_VER),
269 TMsgType.Notify
270 );
271 e_WriteLog(
272 'Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME,
273 TMsgType.Notify
274 );
276 e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
278 GameWAD := e_FindWad(DataDirs, 'GAME');
279 assert(GameWad <> '', 'GAME.WAD not installed?');
281 {$IFDEF HEADLESS}
282 conbufDumpToStdOut := true;
283 {$ENDIF}
284 e_WriteToStdOut := False; //{$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
286 e_InitInput;
288 sys_Init;
290 s := CONFIG_FILENAME;
291 if e_FindResource(ConfigDirs, s) = true then
292 begin
293 g_Options_Read(s)
294 end
295 else
296 begin
297 g_Options_SetDefault;
298 g_Options_SetDefaultVideo
299 end;
300 if sys_SetDisplayMode(gScreenWidth, gScreenHeight, gBPP, gFullScreen) = False then
301 raise Exception.Create('Failed to set videomode on startup.');
303 g_Console_SysInit;
304 e_WriteLog(gLanguage, TMsgType.Notify);
305 g_Language_Set(gLanguage);
307 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
308 flexloaded := true;
309 if not fuiAddWad('flexui.wad') then
310 begin
311 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
312 end;
313 try
314 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
315 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
316 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
317 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
318 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
319 except on e: Exception do
320 begin
321 writeln('ERROR loading FlexUI fonts');
322 flexloaded := false;
323 //raise;
324 end;
325 else
326 begin
327 flexloaded := false;
328 //raise;
329 end;
330 end;
331 if (flexloaded) then
332 begin
333 try
334 e_LogWriteln('FlexUI: loading stylesheet...');
335 uiLoadStyles('flexui/widgets.wgs');
336 except on e: TParserException do
337 begin
338 writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
339 //raise;
340 flexloaded := false;
341 end;
342 else
343 begin
344 //raise;
345 flexloaded := false;
346 end;
347 end;
348 end;
349 g_holmes_imfunctional := not flexloaded;
351 if (not g_holmes_imfunctional) then
352 begin
353 uiInitialize();
354 uiContext.font := 'win14';
355 end;
357 if assigned(oglInitCB) then oglInitCB;
358 {$ENDIF}
360 //g_Res_CreateDatabases(true); // it will be done before connecting to the server for the first time
362 e_WriteLog('Entering SDLMain', TMsgType.Notify);
364 {$WARNINGS OFF}
365 SDLMain();
366 {$WARNINGS ON}
368 {$IFDEF ENABLE_HOLMES}
369 if assigned(oglDeinitCB) then oglDeinitCB;
370 {$ENDIF}
372 sys_Final;
373 end;
375 procedure Init();
376 var
377 NoSound: Boolean;
378 begin
379 Randomize;
381 {$IFDEF HEADLESS}
382 {$IFDEF USE_SDLMIXER}
383 NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy
384 {$ELSE}
385 NoSound := True; // FMOD backend will sort it out
386 {$ENDIF}
387 {$ELSE}
388 NoSound := False;
389 {$ENDIF}
391 g_Touch_Init;
393 (*
394 if (e_JoysticksAvailable > 0) then
395 e_WriteLog('Input: Joysticks available.', TMsgType.Notify)
396 else
397 e_WriteLog('Input: No Joysticks.', TMsgType.Notify);
398 *)
400 if (not gNoSound) then
401 begin
402 e_WriteLog('Initializing sound system', TMsgType.Notify);
403 e_InitSoundSystem(NoSound);
404 end;
406 e_WriteLog('Init game', TMsgType.Notify);
407 g_Game_Init();
409 FillChar(charbuff, sizeof(charbuff), ' ');
410 end;
413 procedure Release();
414 begin
415 e_WriteLog('Releasing engine', TMsgType.Notify);
416 e_ReleaseEngine();
418 e_WriteLog('Releasing input', TMsgType.Notify);
419 e_ReleaseInput();
421 if not gNoSound then
422 begin
423 e_WriteLog('Releasing sound', TMsgType.Notify);
424 e_ReleaseSoundSystem();
425 end;
426 end;
429 procedure Update ();
430 begin
431 g_Game_Update();
432 end;
435 procedure Draw ();
436 begin
437 g_Game_Draw();
438 end;
441 function Translit (const S: AnsiString): AnsiString;
442 var
443 i: Integer;
444 begin
445 Result := S;
446 for i := 1 to Length(Result) do
447 begin
448 case Result[i] of
449 'É': Result[i] := 'Q';
450 'Ö': Result[i] := 'W';
451 'Ó': Result[i] := 'E';
452 'Ê': Result[i] := 'R';
453 'Å': Result[i] := 'T';
454 'Í': Result[i] := 'Y';
455 'Ã': Result[i] := 'U';
456 'Ø': Result[i] := 'I';
457 'Ù': Result[i] := 'O';
458 'Ç': Result[i] := 'P';
459 'Õ': Result[i] := '['; //Chr(219);
460 'Ú': Result[i] := ']'; //Chr(221);
461 'Ô': Result[i] := 'A';
462 'Û': Result[i] := 'S';
463 'Â': Result[i] := 'D';
464 'À': Result[i] := 'F';
465 'Ï': Result[i] := 'G';
466 'Ð': Result[i] := 'H';
467 'Î': Result[i] := 'J';
468 'Ë': Result[i] := 'K';
469 'Ä': Result[i] := 'L';
470 'Æ': Result[i] := ';'; //Chr(186);
471 'Ý': Result[i] := #39; //Chr(222);
472 'ß': Result[i] := 'Z';
473 '×': Result[i] := 'X';
474 'Ñ': Result[i] := 'C';
475 'Ì': Result[i] := 'V';
476 'È': Result[i] := 'B';
477 'Ò': Result[i] := 'N';
478 'Ü': Result[i] := 'M';
479 'Á': Result[i] := ','; //Chr(188);
480 'Þ': Result[i] := '.'; //Chr(190);
481 end;
482 end;
483 end;
486 function CheckCheat (ct: TStrings_Locale; eofs: Integer=0): Boolean;
487 var
488 ls1, ls2: string;
489 begin
490 ls1 := CheatEng[ct];
491 ls2 := Translit(CheatRus[ct]);
492 if length(ls1) = 0 then ls1 := '~';
493 if length(ls2) = 0 then ls2 := '~';
494 result :=
495 (Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)) = ls1) or
496 (Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))) = ls1) or
497 (Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)) = ls2) or
498 (Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))) = ls2);
500 if ct = I_GAME_CHEAT_JETPACK then
501 begin
502 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
503 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
504 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
505 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
506 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
507 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
508 end;
510 end;
513 procedure Cheat ();
514 const
515 CHEAT_DAMAGE = 500;
516 label
517 Cheated;
518 var
519 s, s2: string;
520 c: ShortString;
521 a: Integer;
522 begin
524 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
525 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
526 or g_Game_IsNet then Exit;
528 if not gGameOn then exit;
529 if not conIsCheatsEnabled then exit;
531 s := 'SOUND_GAME_RADIO';
533 //
534 if CheckCheat(I_GAME_CHEAT_GODMODE) then
535 begin
536 if gPlayer1 <> nil then gPlayer1.GodMode := not gPlayer1.GodMode;
537 if gPlayer2 <> nil then gPlayer2.GodMode := not gPlayer2.GodMode;
538 goto Cheated;
539 end;
540 // RAMBO
541 if CheckCheat(I_GAME_CHEAT_WEAPONS) then
542 begin
543 if gPlayer1 <> nil then gPlayer1.AllRulez(False);
544 if gPlayer2 <> nil then gPlayer2.AllRulez(False);
545 goto Cheated;
546 end;
547 // TANK
548 if CheckCheat(I_GAME_CHEAT_HEALTH) then
549 begin
550 if gPlayer1 <> nil then gPlayer1.AllRulez(True);
551 if gPlayer2 <> nil then gPlayer2.AllRulez(True);
552 goto Cheated;
553 end;
554 // IDDQD
555 if CheckCheat(I_GAME_CHEAT_DEATH) then
556 begin
557 if gPlayer1 <> nil then gPlayer1.Damage(CHEAT_DAMAGE, 0, 0, 0, HIT_TRAP);
558 if gPlayer2 <> nil then gPlayer2.Damage(CHEAT_DAMAGE, 0, 0, 0, HIT_TRAP);
559 s := 'SOUND_MONSTER_HAHA';
560 goto Cheated;
561 end;
562 //
563 if CheckCheat(I_GAME_CHEAT_DOORS) then
564 begin
565 g_Triggers_OpenAll();
566 goto Cheated;
567 end;
568 // GOODBYE
569 if CheckCheat(I_GAME_CHEAT_NEXTMAP) then
570 begin
571 if gTriggers <> nil then
572 for a := 0 to High(gTriggers) do
573 if gTriggers[a].TriggerType = TRIGGER_EXIT then
574 begin
575 gExitByTrigger := True;
576 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
577 g_Game_ExitLevel(gTriggers[a].tgcMap);
578 Break;
579 end;
580 goto Cheated;
581 end;
582 //
583 s2 := Copy(charbuff, 15, 2);
584 if CheckCheat(I_GAME_CHEAT_CHANGEMAP, 2) and (s2[1] >= '0') and (s2[1] <= '9') and (s2[2] >= '0') and (s2[2] <= '9') then
585 begin
586 if g_Map_Exist(gGameSettings.WAD + ':\MAP' + s2) then
587 begin
588 c := 'MAP' + s2;
589 g_Game_ExitLevel(c);
590 end;
591 goto Cheated;
592 end;
593 //
594 if CheckCheat(I_GAME_CHEAT_FLY) then
595 begin
596 gFly := not gFly;
597 goto Cheated;
598 end;
599 // BULLFROG
600 if CheckCheat(I_GAME_CHEAT_JUMPS) then
601 begin
602 VEL_JUMP := 30-VEL_JUMP;
603 goto Cheated;
604 end;
605 // FORMULA1
606 if CheckCheat(I_GAME_CHEAT_SPEED) then
607 begin
608 MAX_RUNVEL := 32-MAX_RUNVEL;
609 goto Cheated;
610 end;
611 // CONDOM
612 if CheckCheat(I_GAME_CHEAT_SUIT) then
613 begin
614 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_SUIT);
615 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_SUIT);
616 goto Cheated;
617 end;
618 //
619 if CheckCheat(I_GAME_CHEAT_AIR) then
620 begin
621 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_OXYGEN);
622 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_OXYGEN);
623 goto Cheated;
624 end;
625 // PURELOVE
626 if CheckCheat(I_GAME_CHEAT_BERSERK) then
627 begin
628 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_MEDKIT_BLACK);
629 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_MEDKIT_BLACK);
630 goto Cheated;
631 end;
632 //
633 if CheckCheat(I_GAME_CHEAT_JETPACK) then
634 begin
635 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_JETPACK);
636 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_JETPACK);
637 goto Cheated;
638 end;
639 // CASPER
640 if CheckCheat(I_GAME_CHEAT_NOCLIP) then
641 begin
642 if gPlayer1 <> nil then gPlayer1.SwitchNoClip;
643 if gPlayer2 <> nil then gPlayer2.SwitchNoClip;
644 goto Cheated;
645 end;
646 //
647 if CheckCheat(I_GAME_CHEAT_NOTARGET) then
648 begin
649 if gPlayer1 <> nil then gPlayer1.NoTarget := not gPlayer1.NoTarget;
650 if gPlayer2 <> nil then gPlayer2.NoTarget := not gPlayer2.NoTarget;
651 goto Cheated;
652 end;
653 // INFERNO
654 if CheckCheat(I_GAME_CHEAT_NORELOAD) then
655 begin
656 if gPlayer1 <> nil then gPlayer1.NoReload := not gPlayer1.NoReload;
657 if gPlayer2 <> nil then gPlayer2.NoReload := not gPlayer2.NoReload;
658 goto Cheated;
659 end;
660 if CheckCheat(I_GAME_CHEAT_AIMLINE) then
661 begin
662 gAimLine := not gAimLine;
663 goto Cheated;
664 end;
665 if CheckCheat(I_GAME_CHEAT_AUTOMAP) then
666 begin
667 gShowMap := not gShowMap;
668 goto Cheated;
669 end;
670 Exit;
672 Cheated:
673 g_Sound_PlayEx(s);
674 end;
677 procedure KeyPress (K: Word);
678 {$IFNDEF HEADLESS}
679 var
680 Msg: g_gui.TMessage;
681 {$ENDIF}
682 begin
683 {$IFNDEF HEADLESS}
684 case K of
685 VK_ESCAPE: // <Esc>:
686 begin
687 if (g_ActiveWindow <> nil) then
688 begin
689 Msg.Msg := WM_KEYDOWN;
690 Msg.WParam := VK_ESCAPE;
691 g_ActiveWindow.OnMessage(Msg);
692 if (not g_Game_IsNet) and (g_ActiveWindow = nil) then g_Game_Pause(false); //Fn loves to do this
693 end
694 else if (gState <> STATE_FOLD) then
695 begin
696 if gGameOn or (gState = STATE_INTERSINGLE) or (gState = STATE_INTERCUSTOM) then
697 begin
698 g_Game_InGameMenu(True);
699 end
700 else if (gExit = 0) and (gState <> STATE_SLIST) then
701 begin
702 if (gState <> STATE_MENU) then
703 begin
704 if (NetMode <> NET_NONE) then
705 begin
706 g_Game_StopAllSounds(True);
707 g_Game_Free;
708 gState := STATE_MENU;
709 Exit;
710 end;
711 end;
712 g_GUI_ShowWindow('MainMenu');
713 g_Sound_PlayEx('MENU_OPEN');
714 end;
715 end;
716 end;
718 IK_F2, IK_F3, IK_F4, IK_F5, IK_F6, IK_F7, IK_F10:
719 begin // <F2> .. <F6> � <F12>
720 if gGameOn and (not gConsoleShow) and (not gChatShow) then
721 begin
722 while (g_ActiveWindow <> nil) do g_GUI_HideWindow(False);
723 if (not g_Game_IsNet) then g_Game_Pause(True);
724 case K of
725 IK_F2: g_Menu_Show_SaveMenu();
726 IK_F3: g_Menu_Show_LoadMenu();
727 IK_F4: g_Menu_Show_GameSetGame();
728 IK_F5: g_Menu_Show_OptionsVideo();
729 IK_F6: g_Menu_Show_OptionsSound();
730 IK_F7: g_Menu_Show_EndGameMenu();
731 IK_F10: g_Menu_Show_QuitGameMenu();
732 end;
733 end;
734 end;
736 else
737 begin
738 gJustChatted := False;
739 if gConsoleShow or gChatShow then
740 begin
741 g_Console_Control(K);
742 end
743 else if (g_ActiveWindow <> nil) then
744 begin
745 Msg.Msg := WM_KEYDOWN;
746 Msg.WParam := K;
747 g_ActiveWindow.OnMessage(Msg);
748 end
749 else if (gState = STATE_MENU) then
750 begin
751 g_GUI_ShowWindow('MainMenu');
752 g_Sound_PlayEx('MENU_OPEN');
753 end;
754 end;
755 end;
756 {$ENDIF}
757 end;
760 procedure CharPress (C: AnsiChar);
761 var
762 Msg: g_gui.TMessage;
763 a: Integer;
764 begin
765 if gConsoleShow or gChatShow then
766 begin
767 g_Console_Char(C)
768 end
769 else if (g_ActiveWindow <> nil) then
770 begin
771 Msg.Msg := WM_CHAR;
772 Msg.WParam := Ord(C);
773 g_ActiveWindow.OnMessage(Msg);
774 end
775 else
776 begin
777 for a := 0 to 14 do charbuff[a] := charbuff[a+1];
778 charbuff[15] := upcase1251(C);
779 Cheat();
780 end;
781 end;
783 end.