Skip to content

Commit

Permalink
passing args through from FMTK
Browse files Browse the repository at this point in the history
  • Loading branch information
EphDoering committed Apr 27, 2024
1 parent ed712df commit 9e007b2
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 41 deletions.
44 changes: 44 additions & 0 deletions fa_arg_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
used.add_argument('bin',nargs='?', help="If any possitional arguments exist the whole command is assumed to be used to launch factorio")
used.add_argument('-c','--config',help='config file to use')
used.add_argument( '--mod-directory',help='Mod directory to use')
used.add_argument( '--executable-path',metavar='PATH',help='Mod directory to use')

launch_group=parser.add_argument_group(title="Launch Rrequests",description="Options that will skip the menu and just do the requested thing")
launch_reqs=launch_group.add_mutually_exclusive_group()
Expand All @@ -38,6 +39,49 @@
launch_reqs.add_argument('--benchmark-graphics', dest='launch', metavar='FILE', help='load save and run it with graphics for benchmark-ticks number of ticks as normal game would')
launch_reqs.add_argument('--join-game-by-steam-id','+connect_lobby', dest='launch', metavar='ID', help='join multiplayer game through steam network')

extra_args_group=parser.add_argument_group(title="argumented parameters",description="Options that have parameters that might otherewise be mistaken as an executable. Not actually used for anything in the launcher")
extra_args_group.add_argument('--map-gen-settings',nargs=1,metavar='FILE')
extra_args_group.add_argument('--map-gen-seed',nargs=1,metavar='SEED')
extra_args_group.add_argument('--map-gen-seed-max',nargs=1,metavar='SEED')
extra_args_group.add_argument('--map-settings',nargs=1,metavar='FILE')
extra_args_group.add_argument('--preset',nargs=1)
extra_args_group.add_argument('--generate-map-preview',nargs=1,metavar='PATH')
extra_args_group.add_argument('--generate-map-preview-random',nargs=1,metavar='COUNT')
extra_args_group.add_argument('--map-preview-size',nargs=1,metavar='SIZE')
extra_args_group.add_argument('--map-preview-scale',nargs=1,metavar='SCALE')
extra_args_group.add_argument('--map-preview-offset',nargs=1,metavar='X,Y')
extra_args_group.add_argument('--noise-outputs',nargs=1,metavar='TAG,TAG,...')
extra_args_group.add_argument('--slope-shading',nargs=1,metavar='SHADEAMOUNT')
extra_args_group.add_argument('--slope-shade-property',nargs=1,metavar='SHADEPROP')
extra_args_group.add_argument('--report-quantities',nargs=1,metavar='PROTOTYPE,...')
extra_args_group.add_argument('--threads',nargs=1,metavar='THREADCOUNT')
extra_args_group.add_argument('--instrument-mod',nargs=1,metavar='MOD')
extra_args_group.add_argument('--until-tick',nargs=1,metavar='TICK')
extra_args_group.add_argument('--benchmark-ticks',nargs=1,metavar='TICKS')
extra_args_group.add_argument('--benchmark-runs',nargs=1,metavar='RUNS')
extra_args_group.add_argument('--output-perf-stats',nargs=1,metavar='FILE')
extra_args_group.add_argument('--password',nargs=1,metavar='PASSWORD')
extra_args_group.add_argument('--fullscreen',nargs=1,metavar='BOOL')
extra_args_group.add_argument('--max-texture-size',nargs=1,metavar='N')
extra_args_group.add_argument('--graphics-quality',nargs=1)
extra_args_group.add_argument('--video-memory-usage',nargs=1)
extra_args_group.add_argument('--force-graphics-preset',nargs=1)
extra_args_group.add_argument('--window-size',nargs=1)
extra_args_group.add_argument('--cache-sprite-atlas',nargs=1,metavar='BOOL')
extra_args_group.add_argument('--port', metavar='N', help='network port to use')
extra_args_group.add_argument('--bind', metavar='ADDRESS[:PORT]', help='IP address (and optionally port) to bind to')
extra_args_group.add_argument('--rcon-port', metavar='N', help='Port to use for RCON')
extra_args_group.add_argument('--rcon-bind', metavar='ADDRESS:PORT', help='IP address and port to use for RCON')
extra_args_group.add_argument('--rcon-password', metavar='PASSWORD', help='Password for RCON')
extra_args_group.add_argument('--server-settings', metavar='FILE', help='Path to file with server settings. See data/server-settings.example.json')
extra_args_group.add_argument('--use-authserver-bans', metavar='BOOL', help='Verify that connecting players are not banned from multiplayer and inform Factorio.com about ban/unban commands.')
extra_args_group.add_argument('--use-server-whitelist', metavar='BOOL', help='If the whitelist should be used.')
extra_args_group.add_argument('--server-whitelist', metavar='FILE', help='Path to file with server whitelist.')
extra_args_group.add_argument('--server-banlist', metavar='FILE', help='Path to file with server banlist.')
extra_args_group.add_argument('--server-adminlist', metavar='FILE', help='Path to file with server adminlist.')
extra_args_group.add_argument('--console-log', metavar='FILE', help='Path to file where a copy of the server\'s log will be stored')
extra_args_group.add_argument('--server-id', metavar='FILE', help='Path where server ID will be stored or read from')

launch_args=sys.argv[1:] # 0th arg was used to launch us

#there may be multiple levels of args
Expand Down
86 changes: 45 additions & 41 deletions fa_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
else:
MY_BIN = main_file

MY_CONFIG_DIR = os.path.dirname(MY_BIN)
MY_CONFIG_DIR = Path(MY_BIN).parent

MAC="darwin"
WIN="win32"
Expand Down Expand Up @@ -51,51 +51,55 @@
steam_write_folder = steam_write_folder.absolute()
dprint(steam_write_folder)


BIN=''
if args.bin:
check_end='factorio.exe' if sys.platform == WIN else 'factorio'
for arg in launch_args:
if arg.endswith(check_end):
if os.path.isfile(arg):
BIN=arg
_check_end='factorio'
if sys.platform == WIN:
_check_end+='.exe'

BIN=MY_CONFIG_DIR.joinpath(_check_end)
if not BIN.is_file():
if args.bin:
for arg in launch_args:
if arg.endswith(_check_end):
if os.path.isfile(arg):
BIN=arg
break
if not BIN:
print('It looks like a command line option was given to launch factorio, but we couldn\'t figure out where factorio is located. Please add the --executable-path option with the location of the facotrio binary to be launched')
input("press enter to exit...")
raise SystemExit
else:
exe_map = {
WIN:[
"./bin/x64/factorio.exe",
r"%ProgramFiles%\Factorio\bin\x64\factorio.exe",
r'%ProgramFiles(x86)%\Steam\steamapps\common\Factorio\bin\x64\factorio.exe'
],
MAC:[
"/Applications/factorio.app/Contents/MacOS/factorio",
'~/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app/Contents/MacOS/factorio'
],
LIN:[
"./bin/x64/factorio",
r'~/.steam/root/steam/steamapps/common/Factorio/bin/x64/factorio',
r'~/.steam/steam/steamapps/common/Factorio/bin/x64/factorio'
]
}
for path in exe_map[sys.platform]:
path=os.path.expanduser(os.path.expandvars(path))
if os.path.isfile(path):
BIN = os.path.abspath(path)
break
if not BIN:
print('It looks like a command line option was given to launch factorio, but we couldn\'t figure out where factorio is located. Please add the --executable-path option with the location of the facotrio binary to be launched')
input("press enter to exit...")
raise SystemExit
else:
exe_map = {
WIN:[
"./bin/x64/factorio.exe",
r"%ProgramFiles%\Factorio\bin\x64\factorio.exe",
r'%ProgramFiles(x86)%\Steam\steamapps\common\Factorio\bin\x64\factorio.exe'
],
MAC:[
"/Applications/factorio.app/Contents/MacOS/factorio",
'~/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app/Contents/MacOS/factorio'
],
LIN:[
"./bin/x64/factorio",
r'~/.steam/root/steam/steamapps/common/Factorio/bin/x64/factorio',
r'~/.steam/steam/steamapps/common/Factorio/bin/x64/factorio'
]
}
for path in exe_map[sys.platform]:
path=os.path.expanduser(os.path.expandvars(path))
if os.path.isfile(path):
BIN = os.path.abspath(path)
break
dprint(f"checked:{path}")
dprint(f"checked:{path}")
else:
input("Could not find factorio. If you've installed factorio in a standard way please contact the mod developers with your system details. If you're using the protable version please either place this launcher in the folder with the data and bin folders or launch with the factorio execuable path as an argument.")
raise SystemExit
if BIN.find('steam') >= 0 and not steam:
print("Looks like you have a steam installed version of factorio, but didn't launch this launcher through steam. Please launch through steam after updating it's command line parameters to the following:")
print('"' + os.path.abspath(MY_BIN) + '" %command%')
input("press enter to exit")
raise SystemExit
launch_args.insert(0,BIN)
if not BIN:
input("Could not find factorio. If you've installed factorio in a standard way please contact the mod developers with your system details. If you're using the protable version please either place this launcher in the folder with the data and bin folders or launch with the factorio execuable path as an argument.")
raise SystemExit
launch_args.insert(0,BIN)

_FACTORIO_VERSION_output = subprocess.check_output([BIN,'--version']).decode()
_factorio_version_match = re.search(r'Version: (\d+\.\d+.\d+)', _FACTORIO_VERSION_output)
if not _factorio_version_match:
Expand Down Expand Up @@ -130,7 +134,7 @@ def proccess(path):
else:

config_path='config/config.ini'
configs=[os.path.join(MY_CONFIG_DIR,config_path)]
configs=[MY_CONFIG_DIR.joinpath(config_path)]
#try to append another config path from config-path.cfg
try:
fp=open(proccess('__PATH__executable__/../../config-path.cfg'),encoding='utf8')
Expand Down

0 comments on commit 9e007b2

Please sign in to comment.