11 procedure LaunchFile(eFile, eStartDir, eParams: String);
12 var eStartInfo: TStartupInfo;
13 eProcInfo: TProcessInformation;
15 FillChar(eStartInfo, SizeOf(TStartupInfo), 0);
16 with eStartInfo do begin
17 cb := SizeOf(eStartInfo);
18 dwFlags := STARTF_USESHOWWINDOW;
21 if (CreateProcess(nil, PChar(eFile + #32 + eParams), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, PChar(eStartDir), eStartInfo, eProcInfo)) then begin
23 WaitForSingleObject(eProcInfo.hProcess, INFINITE);
25 CloseHandle(eProcInfo.hProcess);
26 CloseHandle(eProcInfo.hThread);
28 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
29 Write(' Done.' + #13#10);
32 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
33 Write(' Couldn''t start hl2.exe!' + #13#10);
37 function GetFileSize(eFile: String): Int64;
38 var eFindHandle: THandle;
39 eFindData: TWIN32FINDDATA;
42 if not FileExists(eFile) then exit;
43 eFindHandle := FindFirstFile(PChar(eFile), eFindData);
44 if eFindHandle = INVALID_HANDLE_VALUE then exit;
45 Result := (eFindData.nFileSizeHigh * (Int64(MAXDWORD) + 1)) + eFindData.nFileSizeLow;
46 FindClose(eFindHandle);
49 var eStream: TFileStream;
50 ePath, eParams: String;
52 eSearchRec: TSearchRec;
55 CheckSuccessful: Boolean;
57 ePath := ExtractFilePath(ParamStr(0));
58 for i := 1 to ParamCount do
59 eParams := eParams + #32 + ParamStr(i);
60 Delete(eParams, 1, 1);
61 if Pos('console', LowerCase(eParams)) = 0 then
62 eParams := eParams + ' -console';
66 SetConsoleTitle('HL2 Launcher');
67 Sleep(200); // wait a few ms until the launch program is closed
69 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
70 WriteLn(' _ _ _ ____ _ _ ');
71 WriteLn('| | | | | |___ \ | | __ _ _ _ _ __ ___| |__ ___ _ __ ');
72 WriteLn('| |_| | | __) | | | / _` | | | | ''_ \ / __| ''_ \ / _ \ ''__|');
73 WriteLn('| _ | |___ / __/ | |__| (_| | |_| | | | | (__| | | | __/ | ');
74 WriteLn('|_| |_|_____|_____| |_____\__,_|\__,_|_| |_|\___|_| |_|\___|_| ');
75 WriteLn(' for listen servers using Metamod:Source');
77 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
79 WriteLn('Checking files...');
80 if not FileExists(ePath + 'hl2.exe') then begin
81 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
82 WriteLn('Error: hl2.exe is missing! Maybe wrong directory? If not, start your HL2 Mod again via Steam and try again.');
86 { Verify GameInfo.txt ... }
87 Write('Verifying GameInfo.txt...');
88 if (FindFirst(ePath + '*.*', faDirectory, eSearchRec) = 0) then begin
90 if (FileExists(ePath + eSearchRec.Name + '\GameInfo.txt')) then begin
91 eModDir := eSearchRec.Name;
94 until (FindNext(eSearchRec) <> 0);
96 FindClose(eSearchRec.FindHandle);
97 if eModDir = '' then begin
98 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
100 WriteLn('Error: Couldn''t find GameInfo.txt!');
105 if Pos('game', LowerCase(eParams)) = 0 then // a small test which isn't worth a notice
106 eParams := '-game ' + eSearchRec.Name + #32 + eParams;
108 eStr := TStringList.Create;
109 eStr.LoadFromFile(ePath + eModDir + '\GameInfo.txt');
110 if Pos('|gameinfo_path|addons/metamod/bin', LowerCase(eStr.Text)) = 0 then begin
111 CheckSuccessful := False;
112 for i := 0 to eStr.Count -1 do begin
113 if Pos('searchpaths', LowerCase(Trim(eStr[i]))) = 1 then begin
114 if i+3 >= eStr.Count then
116 eStr.Insert(i+2, ' GameBin |gameinfo_path|addons/metamod/bin');
117 CheckSuccessful := True;
122 if CheckSuccessful then begin
123 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
124 SetFileAttributes(PChar(ePath + eModDir + '\GameInfo.txt'), 0);
125 eStr.SaveToFile(ePath + eModDir + '\GameInfo.txt');
126 SetFileAttributes(PChar(ePath + eModDir + '\GameInfo.txt'), faReadOnly);
127 Write(' Registered MM:S sucessfully' + #13#10);
130 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
131 Write(' Unexpected EOF, your GameInfo.txt seems to be corrupt' + #13#10);
135 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
136 Write(' Done' + #13#10);
140 { ... and set it to write-protected }
141 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
142 Write('Setting GameInfo.txt to write-protected...');
144 eStream := TFileStream.Create(ePath + eModDir + '\GameInfo.txt', fmShareDenyWrite);
145 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
146 Write(' Done.' + #13#10);
148 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
150 WriteLn('Warning: Couldn''t set GameInfo.txt to write-protected!');
154 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
155 Write('Starting HL2...');
156 LaunchFile(ePath + 'hl2.exe', Copy(ePath, 1, Pos('Steam', ePath)+5), eParams);
157 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
158 { Free GameInfo.txt }
159 Write('Removing read-only again from GameInfo.txt...');
160 if Assigned(eStream) then begin
162 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
163 Write(' Done' + #13#10);
166 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
167 Write(' Skipped' + #13#10);
170 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
172 WriteLn('Thanks for using Metamod:Source! Visit http://www.sourcemm.net/');