From 464b84f1af93619e70f500338e62313e3584fc30 Mon Sep 17 00:00:00 2001 From: FoxAhead Date: Tue, 2 Jun 2020 18:41:02 +0300 Subject: [PATCH] 48. Get rid of uplay32.dll tyranny Patching Uplay's FacCry2.exe to remove uplay32.dll injection. Hence, no Uplay overlay support. Refactored InstallSearch and added more paths for Uplay installation. --- src/FarCry2MFL_InstallSearch.pas | 73 +++++++++++++++++++------------ src/FarCry2MFL_Proc.pas | 16 ++++++- src/FarCry2MFLauncher.dof | 6 +-- src/FarCry2MFLauncher.res | Bin 15920 -> 15920 bytes 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/src/FarCry2MFL_InstallSearch.pas b/src/FarCry2MFL_InstallSearch.pas index 872cdfb..0c38d24 100644 --- a/src/FarCry2MFL_InstallSearch.pas +++ b/src/FarCry2MFL_InstallSearch.pas @@ -9,54 +9,57 @@ TInstallSearch = record Path: string; end; - TInstallSearchs = array[0..5] of TInstallSearch; + TInstallSearchs = array[0..4] of TInstallSearch; const InstallSearchs: TInstallSearchs = (( - RKey: '\SOFTWARE\Ubisoft\Far Cry 2'; + RKey: '\Ubisoft\Far Cry 2'; RValue: 'InstallDir'; Path: 'bin'; - ), ( - RKey: '\SOFTWARE\Wow6432Node\Ubisoft\Far Cry 2'; - RValue: 'InstallDir'; - Path: 'bin'; - ), ( - RKey: '\SOFTWARE\Valve\Steam'; + ), ( + RKey: '\Valve\Steam'; RValue: 'InstallPath'; Path: 'steamapps\common\far cry 2\bin'; - ), ( - RKey: '\SOFTWARE\Wow6432Node\Valve\Steam'; - RValue: 'InstallPath'; - Path: 'steamapps\common\far cry 2\bin'; - ), ( - RKey: '\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 19900'; - RValue: 'InstallDir'; + ), ( + RKey: '\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 19900'; + RValue: 'InstallLocation'; Path: 'bin'; - ), ( - RKey: '\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 19900'; + ), ( + RKey: '\Ubisoft\Launcher\Installs\85'; RValue: 'InstallDir'; Path: 'bin'; - )); - -function TryGetOneInstallLocation(InstallSearch: TInstallSearch): string; + ), ( + RKey: '\Microsoft\Windows\CurrentVersion\Uninstall\Uplay Install 85'; + RValue: 'InstallLocation'; + Path: 'bin'; + )); function GetInstallLocation(): string; +function TryGetOneInstallLocation(Prefix: string; InstallSearch: TInstallSearch): string; + +function TranslateChar(const Str: string; FromChar, ToChar: Char): string; + +function UnixPathToDosPath(const Path: string): string; + implementation uses Registry, - Windows, - SysUtils; + SysUtils, + Windows; function GetInstallLocation(): string; var i: Integer; Path: string; begin + Result := ''; for i := Low(InstallSearchs) to High(InstallSearchs) do begin - Path := TryGetOneInstallLocation(InstallSearchs[i]); + Path := TryGetOneInstallLocation('\SOFTWARE', InstallSearchs[i]); + if Path = '' then + Path := TryGetOneInstallLocation('\SOFTWARE\Wow6432Node', InstallSearchs[i]); if Path <> '' then begin Result := Path; @@ -65,7 +68,7 @@ function GetInstallLocation(): string; end; end; -function TryGetOneInstallLocation(InstallSearch: TInstallSearch): string; +function TryGetOneInstallLocation(Prefix: string; InstallSearch: TInstallSearch): string; var Registry: TRegistry; Path: string; @@ -74,12 +77,12 @@ function TryGetOneInstallLocation(InstallSearch: TInstallSearch): string; Registry := TRegistry.Create(KEY_READ); Registry.RootKey := HKEY_LOCAL_MACHINE; try - if Registry.OpenKey(InstallSearch.RKey, False) then + if Registry.OpenKey(Prefix + InstallSearch.RKey, False) then begin Path := Registry.ReadString(InstallSearch.RValue); if Path <> '' then begin - Path := Path + '\' + InstallSearch.Path; + Path := ExcludeTrailingPathDelimiter(UnixPathToDosPath(Path)) + '\' + InstallSearch.Path; if DirectoryExists(Path) then begin Result := Path; @@ -91,4 +94,20 @@ function TryGetOneInstallLocation(InstallSearch: TInstallSearch): string; end; end; -end. +function TranslateChar(const Str: string; FromChar, ToChar: Char): string; +var + I: Integer; +begin + Result := Str; + for I := 1 to Length(Result) do + if Result[I] = FromChar then + Result[I] := ToChar; +end; + +function UnixPathToDosPath(const Path: string): string; +begin + Result := TranslateChar(Path, '/', '\'); +end; + +end. + diff --git a/src/FarCry2MFL_Proc.pas b/src/FarCry2MFL_Proc.pas index 79bc35c..8c20a00 100644 --- a/src/FarCry2MFL_Proc.pas +++ b/src/FarCry2MFL_Proc.pas @@ -52,8 +52,10 @@ TGameFilesInfo = record VersionStringOffset: Integer; end; + TGameFilesInfos = array[1..3] of TGameFilesInfo; + const - GameFilesInfo: array[1..3] of TGameFilesInfo =(( + GameFilesInfo: TGameFilesInfos =(( // Steam FarCry2ExeSize: 28296; FarCry2ExeCRC32: $5F78917A; @@ -65,7 +67,7 @@ TGameFilesInfo = record FarCry2ExeCRC32: $0FC58B66; DuniaDllSize: 19412104; VersionStringOffset: $00DB1FC4 - ), ( + ),( // Uplay FarCry2ExeSize: 29864; FarCry2ExeCRC32: $8CF778F0; @@ -390,6 +392,8 @@ function LaunchGame(): TProcessInformation; BytesRead: Cardinal; BytesWritten: Cardinal; i: Integer; + UplayPatchAddress: Pointer; + UplayPatch: array[0..4] of Cardinal; begin try DllLoadingState := dlsNone; @@ -441,6 +445,14 @@ function LaunchGame(): TProcessInformation; if not WriteProcessMemory(ProcessInformation.hProcess, FC2MFOptions, @Options, SizeOf(Options), BytesWritten) then raise Exception.Create('WriteProcessMemory2: ' + IntToStr(GetLastError())); Log('BytesWritten ' + IntToStr(BytesWritten)); + if CalcFileCRC32(FarCry2ExeName) = GameFilesInfo[GAME_VERSION_UPLAY].FarCry2ExeCRC32 then + begin + UplayPatchAddress := Pointer($0040903C); //IMAGE_IMPORT_DESCRIPTOR[3] + ZeroMemory(@UplayPatch, SizeOf(UplayPatch)); + if not WriteProcessMemory(ProcessInformation.hProcess, UplayPatchAddress, @UplayPatch, SizeOf(UplayPatch), BytesWritten) then + raise Exception.Create('WriteProcessMemory3: ' + IntToStr(GetLastError())); + Log('BytesWritten ' + IntToStr(BytesWritten)); + end; DllLoadingState := dlsLoading; diff --git a/src/FarCry2MFLauncher.dof b/src/FarCry2MFLauncher.dof index fee324a..d3b836e 100644 --- a/src/FarCry2MFLauncher.dof +++ b/src/FarCry2MFLauncher.dof @@ -113,9 +113,9 @@ RootDir= IncludeVerInfo=1 AutoIncBuild=1 MajorVer=1 -MinorVer=7 +MinorVer=8 Release=0 -Build=47 +Build=48 Debug=0 PreRelease=0 Special=0 @@ -126,7 +126,7 @@ CodePage=1252 [Version Info Keys] CompanyName= FileDescription= -FileVersion=1.7.0.47 +FileVersion=1.8.0.48 InternalName= LegalCopyright= LegalTrademarks= diff --git a/src/FarCry2MFLauncher.res b/src/FarCry2MFLauncher.res index 40b97bb07e463c5560f38f2f4cdfbf6562053016..d4485eccbf476a5057e84572d82d0a95ee0cdbbc 100644 GIT binary patch delta 42 tcmdl`v!Q0g3u|5u21W)01_lN&J^8Ekd2R~^J)nplg9(Gh=JPg*i~#uT3YY)@ delta 42 tcmdl`v!Q0g3u|6>21W*b1_lN&J^8Ekd2VwCJq80HHeoQ|eBLIJ5dipR3X%W-