1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/installer/HL2Launch.dpr Wed Dec 28 00:08:15 2005 +0000
1.3 @@ -0,0 +1,174 @@
1.4 +program HL2Launch;
1.5 +
1.6 +{$APPTYPE CONSOLE}
1.7 +
1.8 +uses
1.9 + SysUtils,
1.10 + ShellApi,
1.11 + Windows,
1.12 + Classes;
1.13 +
1.14 +procedure LaunchFile(eFile, eStartDir, eParams: String);
1.15 +var eStartInfo: TStartupInfo;
1.16 + eProcInfo: TProcessInformation;
1.17 +begin
1.18 + FillChar(eStartInfo, SizeOf(TStartupInfo), 0);
1.19 + with eStartInfo do begin
1.20 + cb := SizeOf(eStartInfo);
1.21 + dwFlags := STARTF_USESHOWWINDOW;
1.22 + end;
1.23 +
1.24 + if (CreateProcess(nil, PChar(eFile + #32 + eParams), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, PChar(eStartDir), eStartInfo, eProcInfo)) then begin
1.25 + try
1.26 + WaitForSingleObject(eProcInfo.hProcess, INFINITE);
1.27 + finally
1.28 + CloseHandle(eProcInfo.hProcess);
1.29 + CloseHandle(eProcInfo.hThread);
1.30 + end;
1.31 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
1.32 + Write(' Done.' + #13#10);
1.33 + end
1.34 + else begin
1.35 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
1.36 + Write(' Couldn''t start hl2.exe!' + #13#10);
1.37 + end;
1.38 +end;
1.39 +
1.40 +function GetFileSize(eFile: String): Int64;
1.41 +var eFindHandle: THandle;
1.42 + eFindData: TWIN32FINDDATA;
1.43 +begin
1.44 + Result := 0;
1.45 + if not FileExists(eFile) then exit;
1.46 + eFindHandle := FindFirstFile(PChar(eFile), eFindData);
1.47 + if eFindHandle = INVALID_HANDLE_VALUE then exit;
1.48 + Result := (eFindData.nFileSizeHigh * (Int64(MAXDWORD) + 1)) + eFindData.nFileSizeLow;
1.49 + FindClose(eFindHandle);
1.50 +end;
1.51 +
1.52 +var eStream: TFileStream;
1.53 + ePath, eParams: String;
1.54 + eModDir: String;
1.55 + eSearchRec: TSearchRec;
1.56 + eStr: TStringList;
1.57 + i: integer;
1.58 + CheckSuccessful: Boolean;
1.59 +begin
1.60 + ePath := ExtractFilePath(ParamStr(0));
1.61 + for i := 1 to ParamCount do
1.62 + eParams := eParams + #32 + ParamStr(i);
1.63 + Delete(eParams, 1, 1);
1.64 + if Pos('console', LowerCase(eParams)) = 0 then
1.65 + eParams := eParams + ' -console';
1.66 + eStream := nil;
1.67 + eModDir := '';
1.68 +
1.69 + SetConsoleTitle('HL2 Launcher');
1.70 + Sleep(200); // wait a few ms until the launch program is closed
1.71 +
1.72 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
1.73 + WriteLn(' _ _ _ ____ _ _ ');
1.74 + WriteLn('| | | | | |___ \ | | __ _ _ _ _ __ ___| |__ ___ _ __ ');
1.75 + WriteLn('| |_| | | __) | | | / _` | | | | ''_ \ / __| ''_ \ / _ \ ''__|');
1.76 + WriteLn('| _ | |___ / __/ | |__| (_| | |_| | | | | (__| | | | __/ | ');
1.77 + WriteLn('|_| |_|_____|_____| |_____\__,_|\__,_|_| |_|\___|_| |_|\___|_| ');
1.78 + WriteLn(' for Metamod:Source listen servers');
1.79 + WriteLn('');
1.80 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
1.81 + { Check files }
1.82 + WriteLn('Checking files...');
1.83 + if not FileExists(ePath + 'hl2.exe') then begin
1.84 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
1.85 + WriteLn('Error: hl2.exe is missing! Maybe wrong directory? If not, start your Source game again via Steam and then run hl2launcher.exe one more time.');
1.86 + ReadLn;
1.87 + exit;
1.88 + end;
1.89 + { Verify GameInfo.txt ... }
1.90 + Write('Verifying GameInfo.txt...');
1.91 + if (FindFirst(ePath + '*.*', faDirectory, eSearchRec) = 0) then begin
1.92 + repeat
1.93 + if (FileExists(ePath + eSearchRec.Name + '\GameInfo.txt')) then begin
1.94 + eModDir := eSearchRec.Name;
1.95 + break;
1.96 + end;
1.97 + until (FindNext(eSearchRec) <> 0);
1.98 + end;
1.99 + FindClose(eSearchRec.FindHandle);
1.100 + if eModDir = '' then begin
1.101 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
1.102 + WriteLn('');
1.103 + WriteLn('Error: Couldn''t find GameInfo.txt!');
1.104 + ReadLn;
1.105 + exit;
1.106 + end
1.107 + else begin
1.108 + if Pos('game', LowerCase(eParams)) = 0 then // a small test which isn't worth a notice
1.109 + eParams := '-game ' + eSearchRec.Name + #32 + eParams;
1.110 +
1.111 + eStr := TStringList.Create;
1.112 + eStr.LoadFromFile(ePath + eModDir + '\GameInfo.txt');
1.113 + if Pos('|gameinfo_path|addons/metamod/bin', LowerCase(eStr.Text)) = 0 then begin
1.114 + CheckSuccessful := False;
1.115 + for i := 0 to eStr.Count -1 do begin
1.116 + if Pos('searchpaths', LowerCase(Trim(eStr[i]))) = 1 then begin
1.117 + if i+3 >= eStr.Count then
1.118 + break;
1.119 + eStr.Insert(i+2, ' GameBin |gameinfo_path|addons/metamod/bin');
1.120 + CheckSuccessful := True;
1.121 + break;
1.122 + end;
1.123 + end;
1.124 +
1.125 + if CheckSuccessful then begin
1.126 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
1.127 + SetFileAttributes(PChar(ePath + eModDir + '\GameInfo.txt'), 0);
1.128 + eStr.SaveToFile(ePath + eModDir + '\GameInfo.txt');
1.129 + SetFileAttributes(PChar(ePath + eModDir + '\GameInfo.txt'), faReadOnly);
1.130 + Write(' Registered MM:S sucessfully' + #13#10);
1.131 + end
1.132 + else begin
1.133 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
1.134 + Write(' Unexpected EOF, your GameInfo.txt seems to be corrupt' + #13#10);
1.135 + end;
1.136 + end
1.137 + else begin
1.138 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
1.139 + Write(' Done' + #13#10);
1.140 + end;
1.141 + eStr.Free;
1.142 + end;
1.143 + { ... and set it to write-protected }
1.144 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
1.145 + Write('Setting GameInfo.txt to write-protected...');
1.146 + try
1.147 + eStream := TFileStream.Create(ePath + eModDir + '\GameInfo.txt', fmShareDenyWrite);
1.148 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
1.149 + Write(' Done.' + #13#10);
1.150 + except
1.151 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
1.152 + WriteLn('');
1.153 + WriteLn('Warning: Couldn''t set GameInfo.txt to write-protected!');
1.154 + eStream := nil;
1.155 + end;
1.156 + { Launch game }
1.157 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
1.158 + Write('Starting HL2...');
1.159 + LaunchFile(ePath + 'hl2.exe', Copy(ePath, 1, Pos('Steam', ePath)+5), eParams);
1.160 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
1.161 + { Free GameInfo.txt }
1.162 + Write('Removing read-only again from GameInfo.txt...');
1.163 + if Assigned(eStream) then begin
1.164 + eStream.Free;
1.165 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
1.166 + Write(' Done' + #13#10);
1.167 + end
1.168 + else begin
1.169 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
1.170 + Write(' Skipped' + #13#10);
1.171 + end;
1.172 + { End message }
1.173 + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
1.174 + WriteLn('');
1.175 + WriteLn('Thanks for using Metamod:Source! Visit http://www.sourcemm.net/');
1.176 + Sleep(2500);
1.177 +end.