Skip to content

Commit

Permalink
Merge pull request #8 from FoxAhead/dev-affinity
Browse files Browse the repository at this point in the history
72. Processor affinity mask
  • Loading branch information
FoxAhead authored Sep 22, 2022
2 parents 07bfdac + e1f21e6 commit d062a92
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/FarCry2MFL_FormOptions.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object FormOptions: TFormOptions
BorderIcons = [biSystemMenu, biMinimize]
BorderStyle = bsSingle
Caption = 'Options'
ClientHeight = 270
ClientHeight = 282
ClientWidth = 513
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Expand All @@ -18,14 +18,14 @@ object FormOptions: TFormOptions
OnCreate = FormCreate
DesignSize = (
513
270)
282)
PixelsPerInch = 96
TextHeight = 13
object CheckListBox1: TCheckListBox
Left = 4
Top = 4
Width = 161
Height = 230
Height = 242
OnClickCheck = CheckListBox1ClickCheck
Anchors = [akLeft, akTop, akBottom]
ItemHeight = 13
Expand All @@ -34,7 +34,7 @@ object FormOptions: TFormOptions
end
object ButtonOK: TButton
Left = 152
Top = 241
Top = 253
Width = 101
Height = 25
Anchors = [akLeft, akBottom]
Expand All @@ -52,7 +52,7 @@ object FormOptions: TFormOptions
end
object ButtonCancel: TButton
Left = 260
Top = 241
Top = 253
Width = 101
Height = 25
Anchors = [akLeft, akBottom]
Expand All @@ -65,7 +65,7 @@ object FormOptions: TFormOptions
Left = 168
Top = 4
Width = 341
Height = 230
Height = 242
TabStop = False
Anchors = [akLeft, akTop, akBottom]
ReadOnly = True
Expand Down
Binary file modified src/FarCry2MFL_FormOptions.res
Binary file not shown.
15 changes: 13 additions & 2 deletions src/FarCry2MFL_FormOptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ https://farcry.fandom.com/wiki/Machete" default="1"/>
<section name="Launch Options" description="Launch options added to the command line">
<boolean key="bSkipIntroMovies" name="Skip Intro Movies" description="-GameProfile_SkipIntroMovies 1
Skip Intro Movies for faster game starting." default="1"/>
<boolean key="bMaxFps" name="Max Fps" description="-RenderProfile_MaxFps ##
<boolean key="bMaxFps" name="Max FPS" description="-RenderProfile_MaxFps ##
Limit Maximum FPS to avoid game's physical engine glitches like jumping NPCs and others. If you see screen-tearing try using MaxFps = 62 instead of 60." default="1">
<integer key="iMaxFps" name="Max Fps" default="60"/>
<integer key="iMaxFps" name="Max FPS" default="60"/>
</boolean>
<boolean key="bAllWeaponsUnlock" name="All Weapons Unlock" description="-GameProfile_AllWeaponsUnlock 1
Unlock all weapons at the bazaar, depending on what part of the map you are in at the time." default="0"/>
Expand All @@ -39,5 +39,16 @@ Runs a console command 'batchfile'. This text file can contain list of console c
'C:\Users\USERNAME\Documents\My Games\Far Cry 2'" default="0">
<string key="sExec" name="Batch file name" default=""/>
</boolean>
<boolean key="bAffinity" name="Processor affinity" description="Sets a processor affinity mask
Limits the use of cores by the game process. Can help run the game on modern fast systems with lots of cores.
The integer value represents the mask. So the value is:
1 to use only CPU0
2 to use only CPU1
3 to use both CPU0 and CPU1
...
15 to use CPU0 + CPU1 + CPU2 + CPU3
and so on." default="0">
<integer key="iAffinity" name="Affinity mask" default="1"/>
</boolean>
</section>
</options>
2 changes: 1 addition & 1 deletion src/FarCry2MFL_FormProgress.pas
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ implementation

procedure TFormProgress.StartTimer(TimeOut: Integer);
begin
ProgressBar1.Max := TimeOut * 1000 div Timer1.Interval;
ProgressBar1.Max := TimeOut * 1000 div Integer(Timer1.Interval);
Timer1.Enabled := True;
end;

Expand Down
13 changes: 13 additions & 0 deletions src/FarCry2MFL_Proc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ TCommandLineOptions = record
bZombieAI: Boolean;
bExec: Boolean;
sExec: string;
bAffinity: Boolean;
iAffinity: Integer;
end;

TGameFilesInfo = record
Expand Down Expand Up @@ -426,6 +428,9 @@ function LaunchGame(): TProcessInformation;
ZeroMemory(@ProcessInformation, SizeOf(ProcessInformation));
if not CreateProcess(PAnsiChar(FileName), PAnsiChar(CommandLine), nil, nil, False, CREATE_SUSPENDED, nil, PAnsiChar(Path), StartupInfo, ProcessInformation) then
raise Exception.Create('CreateProcess: ' + IntToStr(GetLastError()));
if CommandLineOptions.bAffinity then
if not SetProcessAffinityMask(ProcessInformation.hProcess, CommandLineOptions.iAffinity) then
raise Exception.Create('SetProcessAffinityMask: ' + IntToStr(GetLastError()));
EntryPointAddress := $004014EC;
ZeroMemory(@Inject, SizeOf(Inject));
Inject.PushCommand := $68;
Expand Down Expand Up @@ -881,6 +886,10 @@ function GetOptionByKey(Key: string): Variant;
Result := CommandLineOptions.bExec;
if Key = 'sExec' then
Result := CommandLineOptions.sExec;
if Key = 'bAffinity' then
Result := CommandLineOptions.bAffinity;
if Key = 'iAffinity' then
Result := CommandLineOptions.iAffinity;
end;

procedure SetOptionByKey(Key: string; Value: Variant);
Expand Down Expand Up @@ -917,6 +926,10 @@ procedure SetOptionByKey(Key: string; Value: Variant);
CommandLineOptions.bExec := Value;
if Key = 'sExec' then
CommandLineOptions.sExec := Value;
if Key = 'bAffinity' then
CommandLineOptions.bAffinity := Value;
if Key = 'iAffinity' then
CommandLineOptions.iAffinity := Value;
end;

end.
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=9
MinorVer=10
Release=0
Build=50
Build=73
Debug=0
PreRelease=0
Special=0
Expand All @@ -126,7 +126,7 @@ CodePage=1252
[Version Info Keys]
CompanyName=
FileDescription=
FileVersion=1.9.0.50
FileVersion=1.10.0.73
InternalName=
LegalCopyright=
LegalTrademarks=
Expand Down
Binary file modified src/FarCry2MFLauncher.res
Binary file not shown.

0 comments on commit d062a92

Please sign in to comment.