Skip to content

Commit

Permalink
Fix ZH launch problem (ssleay32.dll)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcecore committed May 28, 2021
1 parent 30f10c4 commit 55167e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Mod launcher/manager for C&C: Generals: Zero Hour
You don't install this one, you just unzip the zip file in the releases
and execute the .exe file :)

## Fixing ssleay32.dll Problem
* Please install this fix: https://bibber.eu/downloads/cnc-ultimate-collection-launchers/

## Mod Installation Instructions
* Locate your mod files. Most mods will come with a couple of .big files
and no other files.
Expand Down
16 changes: 9 additions & 7 deletions src/mainform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ procedure TFormMain.ScanMods();
mod_dir : string;
begin
// scan the dirs in gamedir/Mods
mod_dir := IncludeTrailingPathDelimiter(settings.game_dir)+'Mods';
mod_dir := path_join(settings.game_dir, 'Mods');
If FindFirst( mod_dir + '\*', faAnyFile and faDirectory, info ) = 0 then
Repeat
ProcessMod( info );
Expand Down Expand Up @@ -196,7 +196,8 @@ procedure TFormMain.LaunchGame( params: string );
begin
// Just run the game. Don't wait for it.
// The user knows how and when to actiave or deactivate stuff.
ShellExecute( 0, nil, PChar(settings.game_exe), PChar(params), nil, SW_NORMAL );
ShellExecute( 0, nil, PChar(settings.game_exe), PChar(params), PChar(settings.game_dir), SW_NORMAL );
// RunAsAdmin(FormMain.Handle, settings.game_exe, params);
//RunCommand( settings.game_exe, [params], s );
//SysUtils.ExecuteProcess(settings.game_exe, params, []);
end;
Expand Down Expand Up @@ -250,9 +251,10 @@ procedure TFormMain.ActivateMod( mod_name: string );
for i := 0 to zbigs.Count-1 do
begin
fname := zbigs[ i ];
src := mod_path + fname;
dest := settings.game_dir + fname;
src := path_join(mod_path, fname);
dest := path_join(settings.game_dir, fname);
dest := StringReplace( dest, '.zbig', '.big', [rfReplaceAll] );
// Warning( src + ' --> ' + dest );
MoveFile( PChar(src), PChar(dest) );
end;
end;
Expand All @@ -265,7 +267,7 @@ procedure TFormMain.DeactivateMod();
begin
// From saved settings, determine what mod is active.
mod_name := settings.conf.GetValue( '/current_mod/name', '' );
if length( mod_name ) = 0 then
if mod_name = '' then
exit;

// Find zbigs in the game/Mods/mod_name then move it to game dir.
Expand All @@ -277,8 +279,8 @@ procedure TFormMain.DeactivateMod();
for i := 0 to cnt-1 do
begin
fname := settings.conf.GetValue( '/current_mod/files/'+IntToStr(i), '' );
dest := mod_path + fname;
src := settings.game_dir + fname;
dest := path_join(mod_path, fname);
src := path_join(settings.game_dir, fname);
src := StringReplace( src, '.zbig', '.big', [rfReplaceAll] );
// Warning( src + ' --> ' + dest );
MoveFile( PChar(src), PChar(dest) );
Expand Down
49 changes: 23 additions & 26 deletions src/settings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TSettings = class
procedure LoadConf();

//function GetMyDoc(): string;
function FindGeneralsExe( t: string ): string;
function FindGeneralsExe(): string;
function GetInstallDir: string;

// Property getter setters
Expand Down Expand Up @@ -69,9 +69,9 @@ procedure TSettings.LoadConf();
CreateDir( config_dir );
end;

json_fname := 'config.json';
json_fname := path_join( config_dir, json_fname );
conf.Filename := json_fname; // created if NE. loads if E.
json_fname := 'mod4_config.json';
json_fname := path_join(ExtractFileDir(Application.ExeName), json_fname);
conf.Filename := json_fname; // Created if not exists. Loads it otherwise.
end;

function TSettings.GetInstallDir: string;
Expand All @@ -80,7 +80,7 @@ function TSettings.GetInstallDir: string;
diag: TOpenDialog;
begin
// Number 1, try registry.
result := FindGeneralsExe( 'InstallPath' );
result := FindGeneralsExe();

// installdir might point to Generals.exe!
// If file, FileExists returns true.
Expand Down Expand Up @@ -117,7 +117,7 @@ function TSettings.GetInstallDir: string;

procedure TSettings.SetGameDir(AValue: string);
begin
conf.SetValue( 'game_dir', Utf8Decode(AValue) );
conf.SetValue( Utf8Decode('game_dir'), Utf8Decode(AValue) );
end;

// get directories we need for the launcher.
Expand All @@ -128,7 +128,7 @@ procedure TSettings.GetDirs();
installdir: string;
begin
//mydoc := GetMyDoc();
//dataleaf := FindGeneralsExe( 'UserDataLeafName' );
//dataleaf := FindGeneralsExe();
//moddir := mydoc + dataleaf;

// Well, config load failed. Attempt to read reg or read user input...
Expand Down Expand Up @@ -157,43 +157,38 @@ function TSettings.GetGameDir(): string;
function TryReadRegKey(
reg: TRegistry;
key: string;
t: string
subkey: string;
exe_path: string
): string;
var
tmp: string;
begin
Result := '';
if reg.KeyExists(key) then
begin
reg.OpenKeyReadOnly(key);
if reg.ValueExists(t) then
tmp := reg.ReadString( t );
if reg.ValueExists(subkey) then
tmp := reg.ReadString(subkey);
reg.CloseKey();

tmp := path_join(tmp, 'Generals.exe');
tmp := path_join(tmp, exe_path);
if FileExists(tmp) then
Result := tmp;
end;
end;

function ResolveZH(
reg: TRegistry;
t: string
): string;
function ResolveZH(reg: TRegistry): string;
var
key: string;
tmp: string;
begin
Result := TryReadRegKey(reg, 'SOFTWARE\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour', t);
// Try the Ultimatate Collection launcher first, if exists.
Result := TryReadRegKey(reg, 'SOFTWARE\EA Games\Command and Conquer Generals Zero Hour', 'Install Dir', 'Command and Conquer Generals Zero Hour\Generals.exe');
if Result <> '' then Exit(Result);

Result := TryReadRegKey(reg, 'SOFTWARE\WOW6432Node\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour', t);
Result := TryReadRegKey(reg, 'SOFTWARE\WOW6432Node\EA Games\Command and Conquer Generals Zero Hour', 'Install Dir', 'Command and Conquer Generals Zero Hour\Generals.exe');
if Result <> '' then Exit(Result);

Result := TryReadRegKey(reg, 'SOFTWARE\Electronic Arts\EA Games\Generals', t);
Result := TryReadRegKey(reg, 'SOFTWARE\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour', 'InstallPath', 'Generals.exe');
if Result <> '' then Exit(Result);

Result := TryReadRegKey(reg, 'SOFTWARE\WOW6432Node\Electronic Arts\EA Games\Generals', t);
Result := TryReadRegKey(reg, 'SOFTWARE\WOW6432Node\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour', 'InstallPath', 'Generals.exe');
if Result <> '' then Exit(Result);

// Try where mod4.exe is
Expand All @@ -204,16 +199,18 @@ function ResolveZH(

// read values from
// SOFTWARE\Electronic Arts\EA Games\Command and Conquer Generals Zero Hour
function TSettings.FindGeneralsExe( t: string ): string;
// SOFTWARE\WOW6432Node\EA Games\Command and Conquer Generals Zero Hour
// ... etc.
function TSettings.FindGeneralsExe(): string;
var
reg: TRegistry;
begin
reg := TRegistry.Create(KEY_READ);
try
reg.RootKey := HKEY_LOCAL_MACHINE;
Result := ResolveZH(reg, t);
Result := ResolveZH(reg);
if Result = '' then
Warning( '제로아워 레지스트리값 ' + t + ' 읽기 실패, Generals.exe를 직접 골라주세요.' );
Warning( '레지스트리로 제로아워 찾기 실패, Generals.exe를 직접 골라주세요.' );
finally
reg.Free;
end;
Expand Down

0 comments on commit 55167e6

Please sign in to comment.