Skip to content

Instantly share code, notes, and snippets.

@IonutDanNica
Forked from MattMcFarland/readme.md
Last active August 1, 2023 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IonutDanNica/da07ed87f479626e7847c6f8a4e5be7a to your computer and use it in GitHub Desktop.
Save IonutDanNica/da07ed87f479626e7847c6f8a4e5be7a to your computer and use it in GitHub Desktop.
Run X4 Foundations in debug mode with timestamped file names so you don't lose them.

Run X4 Foundations in debug mode.

The handy script below (x4-debug.bat) can be used as a shortcut to start x4 in debug mode. You get:

  • All debug messages turned on
  • All debug logs sent to a timestamped file, so you dont lose anything

Setup

Batch file: Copy paste the code in the file below, then update the value for X4_EXE_PATH - change it to wherever X4.exe is located.

Powershell file: Copy paste the code in a file called x4-debug.ps1 and save this file NEXT to your X4.exe file. The script will automatically:

  • detect the .exe file
  • create a shortcut in the same folder as the x4.exe
  • launch the game with the logging enabled

You can then copy the shortcut (which points to the powershell ps1 file) to any folder you like.

Your debug logs will be available in the Documents\Egosoft\X4 Foundations\ folder.

Advanced Usage

Consider using a log analysis tool like glogg which can help you sort, filter, and find data in the logs.

@echo off
rem !!--- please change this to where your game is installed. do not add any spacing aroud the equals operator
rem !!--- set X4_EXE_PATH="Location of your X4.exe"
set X4_EXE_PATH="%PROGRAMFILES(X86)%\Steam\steamapps\common\X4 Foundations\X4.exe"
rem !!--- set the date and time for logfile year-month-day__hh-mm-ss
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2%__%datetime:~8,2%-%datetime:~10,2%-%datetime:~12,2%
echo "Date & Time test = %datetime% year-month-day__hh-mm-ss"
rem stores a value like `x4-game-2018-12-10__11-04-11.log` - to be passed in -logfile
set LOG_FILE_NAME=x4-game-%datetime%.log
rem stores a value like `x4-script-2018-12-10__11-04-11.log` - to be passed in -scriptlogfile
set SCRIPT_LOG_FILE_NAME=x4-script-%datetime%.log
set "exec=%X4_EXE_PATH% -logfile %LOG_FILE_NAME% -scriptlogfile %SCRIPT_LOG_FILE_NAME%"
rem execution phase, first we log out the command, if any of the variables are blank, make sure you dont have whitespace around any of the variables
echo "Executing %X4_EXE_PATH% -debug all -logfile %LOG_FILE_NAME% -scriptlogfile %SCRIPT_LOG_FILE_NAME%"
start "" %X4_EXE_PATH% -showfps -debug all -logfile %LOG_FILE_NAME% -scriptlogfile %SCRIPT_LOG_FILE_NAME%
$X4Executable = (Get-ChildItem -path "$PSScriptRoot\X4.exe").Fullname
$CurrentDir = (Get-Item -Path "$PSScriptRoot\X4.exe").DirectoryName
$timeStamp = Get-Date -Format "yyyy_MM_dd__hh_mm_ss"
$LogFileName="x4-game-$timeStamp.log"
$ScriptLogFileName="x4-script-$timeStamp.log"
$ScriptPath = "$CurrentDir\$($MyInvocation.MyCommand.Name)"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$CurrentDir\X4-WithLogging.lnk")
$Shortcut.TargetPath = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Arguments = "-ExecutionPolicy ByPass -File ""$ScriptPath"""
$Shortcut.Save()
$ArgList = @(
"showfps"
"debug all"
"logfile $LogFileName"
"scriptlogfile $ScriptLogFileName"
)
Start-Process -WorkingDirectory $CurrentDir -FilePath $X4Executable -ArgumentList $ArgList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment