Skip to content

Commit

Permalink
48. Get rid of uplay32.dll tyranny
Browse files Browse the repository at this point in the history
Patching Uplay's FacCry2.exe to remove uplay32.dll injection. Hence, no Uplay overlay support.
Refactored InstallSearch and added more paths for Uplay installation.
  • Loading branch information
FoxAhead committed Jun 2, 2020
1 parent 126eb0c commit 464b84f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 32 deletions.
73 changes: 46 additions & 27 deletions src/FarCry2MFL_InstallSearch.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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.

16 changes: 14 additions & 2 deletions src/FarCry2MFL_Proc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -65,7 +67,7 @@ TGameFilesInfo = record
FarCry2ExeCRC32: $0FC58B66;
DuniaDllSize: 19412104;
VersionStringOffset: $00DB1FC4
), (
),(
// Uplay
FarCry2ExeSize: 29864;
FarCry2ExeCRC32: $8CF778F0;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/FarCry2MFLauncher.dof
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -126,7 +126,7 @@ CodePage=1252
[Version Info Keys]
CompanyName=
FileDescription=
FileVersion=1.7.0.47
FileVersion=1.8.0.48
InternalName=
LegalCopyright=
LegalTrademarks=
Expand Down
Binary file modified src/FarCry2MFLauncher.res
Binary file not shown.

0 comments on commit 464b84f

Please sign in to comment.