New script revision
I tried to localize all variable you need to set manually in the begining.
Threads count is now AHK work!
This is 2 in 1 script.
(May be one day I will do 3 in 1 for any map editor... but now I think it will work if you change all FAF Client staff to your Map Editor staff)
My steam shortcut simply runs script
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,9
[InternetShortcut]
IDList=
IconIndex=0
URL=file:///D:/Program%20Files/SC%20FAF%20borderleess.ahk
IconFile=D:\Steam\steam\games\540979be595a41206b56a2e427c29dce1c212ad2.ico
HotKey=0
My faf client shortcut runs SAME script with command line parameter faf
Object value is:
"D:\Program Files\SC FAF borderleess.ahk" faf
![faf shortcut Properties img]( image url)
One Script to run them all!
if I
- run it with command line parameter faf (no matter file name) or
- rename script file into FAF borderleess.ahk
it will run FAF Client - else it will run game from steam (if file name NOT starts with "faf").
Note:
If file name starts from FAF it will allways run FAF, so you can have 2 copies like "faf script.ahk" and "sc script.ahk" to run game if you don't want to use command line parameter:
- "faf script.ahk" will run only multiplayer, and
- "sc script.ahk" will run singleplayer by default and multiplayer if called with parameter faf
Problem:
"D:\Program Files\Downlord's FAF Client\downlords-faf-client.exe" is not starting client... but "downlords-faf-client.exe" works fine (if script is in faf client's dir)...
so i am calling this script from fake faf shortcut to call another faf client shortcut from it...
Interesting thing is that AHK tells me "File exists" if I'm giving it my full path... but can't run it...
About runnig game with command line args:
AHK can do it, but some trying, AHK docks reading and googlesearching may be needed. I left some tips in code as comments, maybe it will be helpfull.
File D:\Program Files\SC FAF borderleess.ahk:
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#Persistent
; all personal variables are here
; move the window to 0,0 and resize it to fit across 1 or 2 monitors
moveX := 0
moveY := 0
width := 1920
height := 1080
; single player game link from steam or normal file path
pathOrLinkGame := "steam://rungameid/9420"
; multiplayer client path
pathOrLinkClient := "D:\Program Files\downlords-faf-client.lnk"
; problem:
; "D:\Program Files\Downlord's FAF Client\downlords-faf-client.exe"
; is not starting client... but "downlords-faf-client.exe" works...
; but then this script must be in faf client dir...
; so i am calling this script from shortcut to call faf shortcut from it...
; if you run game with command line parameters add them in path string,
; for example path := "C:\Program Files\Notepad++\notepad++.exe --help"
; works fine, note: in *.lnk Object string works like
; "my.exe" myArg1
; but here it will be like path := "my.exe myArg1"
; Some tips from AHK docks:
; If path/link string contains any commas, they must be escaped
; as shown three times in the following example:
; Run rundll32.exe shell32.dll`,Control_RunDLL desk.cpl`,`, 3
; It opens Control Panel > Display Properties > Settings
; To include an actual quote character inside a quoted string,
; specify two consecutive quotes as shown twice in this example:
; "She said, ""An apple a day.""".
; usually you don't need to cheange anythig else bellow
; you can uncomment DEBUG MESSAGE STRING bellow
; to check how script have autoset some variables
; process (*.exe) names for game and faf client
procSingleplayer := "SupremeCommander.exe"
procMultiplayer := "ForgedAlliance.exe"
procClient := "downlords-faf-client.exe"
; this will automatically find your processor threads count
EnvGet, ProcessorCount, NUMBER_OF_PROCESSORS
singlePlayer := true
; true to run singleplayer game
; false to run multiplayer faf-client
; script will try to detect it automatically
; get command line first agrument
firstArg := A_Args[1]
StringLower, lowerCaseFirstArg, firstArg
; get first 3 lettest of this script file name
first3chars := SubStr(A_ScriptName, 1, 3)
StringLower, lowerCaseFirst3chars, first3chars
; it will set singlePlayer to false in 2 cases:
; case 1:
; script runs with command line argument "faf" or "FAF"
; for example Object field in *.lnk:
; "D:\Program Files\SC FAF borderleess.ahk" faf
; case 2:
; file name of this script starts with "FAF..." or "faf.."
; for example: "D:\Program Files\FAF borderleess.ahk"
if(lowerCaseFirstArg = "faf" or lowerCaseFirst3chars = "faf")
{
singlePlayer := false
}
; now "singlePlayer" variable is set
; process for game
procGame := singlePlayer ? procSingleplayer : procMultiplayer
; DEBUG MESSAGE STRING is bellow, this string is to check if it works right
; MsgBox, % ProcessorCount " threads " ( singlePlayer ? "Singleplayer: " : "Multiplayer: " ) procGame
; delete ; character to uncomment string above to see info window on script start
procName := singlePlayer ? procGame : procClient
procPath := singlePlayer ? pathOrLinkGame : pathOrLinkClient
; Start game or client and
; wait for process to start, but no more then 120 seconds
Run, %procPath%
Process, Wait, %procName%, 120
procPID := ErrorLevel
if not procPID
{
MsgBox The specified process did not appear.
ExitApp ; Stop this script
}
SetTimer, CheckProc, 2000
if(!singlePlayer)
{
; Stop then FAF Client stoped
Process, WaitClose, %procClient%
ExitApp
}
CheckProc:
if (!ProcessExist(procGame))
return
WinGet Style, Style, % "ahk_exe " procGame
if (Style & 0xC40000)
{
; remove the titlebar and borders
WinSet, Style, -0xC40000, % "ahk_exe " procGame
; move the window to 0,0 and resize it to fit across 1 or 2 monitors.
WinMove, % "ahk_exe " procGame , , moveX, moveY, width, height
WinMaximize, % "ahk_exe " procGame
WinRestore, % "ahk_exe " procGame
; set High priority and cores affinity
Process, Priority, %procGame%, H
gamePID := ErrorLevel
ProcessHandle := DllCall("OpenProcess", "UInt", 0x1F0FFF, "Int", false, "UInt", gamePID)
DllCall("SetProcessAffinityMask", "UInt", ProcessHandle, "UInt", 2**ProcessorCount - 2 )
DllCall("CloseHandle", "UInt", ProcessHandle)
; I have 4 threads, so 2**ProcessorCount - 2 will be 2^4 - 2= 16 - 2 = 14
; 1110 binary = 14 decimal.
; this means CPU 0 unchecked (right most 0 in binary number),
; CPU 1-3 checked (ones in binary number) for 4 threads optimization
if(singlePlayer)
{
ExitApp ; Stop this script
}
else
{
Process, WaitClose, %procGame%
}
}
return
ProcessExist(exeName)
{
Process, Exist, %exeName%
return !!ERRORLEVEL
}
return