From 7301ae16ff5f459a9ab209463a879cf17a1a16b0 Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Mon, 10 Nov 2025 21:33:58 +0100 Subject: [PATCH 01/14] Added advanced setup script, and some other tweaks: - X2PG support is now integrated into X2MBC and can be enabled by toggling a flag in build.ps1. X2PG must still be installed to do anything, though. - X2MBC can now pick the Highlander up from the X2EMPT_HIGHLANDER_FOLDER environment variable, in addition to the previously documented options. - The advanced setup script can configure X2MBC to: - Build against the Highlander from GitHub (also initializes Git), or from a local copy. The local copy may or may not be configured to use X2EMPT_HIGHLANDER_FOLDER. - Use X2PG verification. - Cook the mod. - Build against any other mod of the user's choosing. - Proofread the readme a bit, cleaning up typos and punching up the grammar. --- .scripts/build.ps1 | 24 ++++ ADVANCED_SETUP.bat | 247 +++++++++++++++++++++++++++++++++++++++++ ProjectTemplate.x2proj | 1 + README.md | 36 +++--- RUN_THIS.bat | 111 +++++++++++++++++- 5 files changed, 399 insertions(+), 20 deletions(-) create mode 100644 ADVANCED_SETUP.bat diff --git a/.scripts/build.ps1 b/.scripts/build.ps1 index fecae13..61c48cc 100644 --- a/.scripts/build.ps1 +++ b/.scripts/build.ps1 @@ -10,6 +10,22 @@ $common = Join-Path -Path $ScriptDirectory "X2ModBuildCommon\build_common.ps1" Write-Host "Sourcing $common" . ($common) +# Controls automatic project verification powered by Xymanek's X2ProjectGenerator. +# In order for this to have any effect, X2ProjectGenerator.exe must be in your PATH. +# To enable, set this flag to $true. To disable, set it back to $false. +$useX2PG = $false + +if ($useX2PG -and $null -ne (Get-Command "X2ProjectGenerator.exe" -ErrorAction SilentlyContinue)) { + Write-Host "Verifying project file..." + &"X2ProjectGenerator.exe" "$srcDirectory\YOUR_MOD_NAME_HERE" "--exclude-contents" "--verify-only" + if ($LASTEXITCODE -ne 0) { + ThrowFailure "Errors in project file." + } +} +else { + Write-Host "Skipping verification of project file." +} + $builder = [BuildProject]::new("$ModSafeName$", $srcDirectory, $sdkPath, $gamePath) # Building against Highlander option 1: @@ -23,9 +39,17 @@ $builder = [BuildProject]::new("$ModSafeName$", $srcDirectory, $sdkPath, $gamePa # and uncomment the line: # $builder.IncludeSrc("C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src") +# Building against Highlander option 3: +# Create an X2EMPT_HIGHLANDER_FOLDER environment variable (if it does not already exist) +# containing the path to your local Highlander repository or the Highlander's mod folder, +# then uncomment the line: +# $builder.IncludeSrc($env:X2EMPT_HIGHLANDER_FOLDER) + # Uncomment to use additional global Custom Src to build against. # $builder.IncludeSrc("C:\Users\Iridar\Documents\Firaxis ModBuddy\CustomSrc") +# PLACEHOLDER_CUSTOMSRC: Used by ADVANCED_SETUP.bat to configure custom source folders. + switch ($config) { "debug" { diff --git a/ADVANCED_SETUP.bat b/ADVANCED_SETUP.bat new file mode 100644 index 0000000..f5c03e7 --- /dev/null +++ b/ADVANCED_SETUP.bat @@ -0,0 +1,247 @@ +@echo off + +REM ********************** +REM *** WELCOME SCREEN *** +REM ********************** + +echo Welcome to the EMPT Advanced Setup! Let's just run through a few settings... +echo You may close this setup at any time before completion if you change your mind +echo about any of your chosen settings. +echo. +SETLOCAL EnableDelayedExpansion + +REM Set initial values so we can reliably navigate back from the commit screen. +SET highlanderMode= +SET x2PGMode= +SET cookingMode= +SET customSrc= +SET skipCustomSrc= + +REM ************************* +REM *** HIGHLANDER SCREEN *** +REM ************************* + +:highlanderSetup +echo How do you want to build against the Community Highlander? +echo 1. Get the Highlander from GitHub. +echo 2. Use a local copy of the Highlander from a project-specific path... +echo 3. Use a local copy of the Highlander from a global path... +echo 4. I don't want to build against the Highlander right now. +SET /p "highlanderMode=Please enter the number corresponding to your preferred option: " + +IF "!highlanderMode!" == "1" ( + SET highlanderMode=FromGit + GOTO highlanderFinished +) +IF "!highlanderMode!" == "2" ( + :highlanderPathSetup + SET highlanderPath= + SET /p "highlanderPath=Now, please specify the path to the Highlander's Src folder (e.g. C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src): " + IF NOT EXIST "!highlanderPath!\X2WOTCCommunityHighlander\Classes" ( + echo ERROR: Could not detect Highlander source code^^! Please double-check the path and try again^^! + GOTO highlanderPathSetup + ) + SET highlanderMode=FromPath "!highlanderPath!" + GOTO highlanderFinished +) +IF "!highlanderMode!" == "3" ( + IF NOT EXIST "!X2EMPT_HIGHLANDER_FOLDER!\X2WOTCCommunityHighlander\Classes" ( + echo WARNING: Could not detect Highlander source code^^! + echo It is highly recommended that you set the X2EMPT_HIGHLANDER_FOLDER environment variable + echo to a valid location before proceeding. This setup can set it for you, if you wish. + echo. + + :offerEnvSetup + SET setupEnv= + SET highlanderPath= + SET /p "setupEnv=Do you wish to set up X2EMPT_HIGHLANDER_FOLDER? (Y/N) " + IF "!setupEnv!" == "Y" ( + :highlanderEnvSetup + SET /p "highlanderPath=Please specify the path to the Highlander's Src folder (e.g. C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src): " + + IF NOT EXIST "!highlanderPath!\X2WOTCCommunityHighlander\Classes" ( + echo ERROR: Could not detect Highlander source code^^! Please double-check the path and try again^^! + GOTO highlanderEnvSetup + ) + SETX X2EMPT_HIGHLANDER_FOLDER "!highlanderPath!" + GOTO highlanderEnvFinished + ) + IF NOT "!setupEnv!" == "N" ( + echo Sorry, that's not a valid option^^! + echo. + GOTO offerEnvSetup + ) + ) + + :highlanderEnvFinished + SET highlanderMode=FromEnvVar + GOTO highlanderFinished +) +IF "!highlanderMode!" == "4" ( + SET highlanderMode=NoHighlander + GOTO highlanderFinished +) + +echo Sorry, that's not a valid option^^! +echo. +SET highlanderMode= +GOTO highlanderSetup + +:highlanderFinished +echo. +echo Highlander mode has been set to "!highlanderMode!"^^! (1/4) +echo Moving on... +echo. + +REM ********************************* +REM *** X2ProjectGenerator SCREEN *** +REM ********************************* + +:x2PGSetup +IF NOT "!x2PGMode!" == "" GOTO cookingSetup +echo Do you want to use Xymanek's X2ProjectGenerator +echo to automatically verify your project before compiling? +echo. +echo Note that even if enabled, X2PG will not do anything until you add +echo X2ProjectGenerator.exe to your PATH. +echo 1. Yes, please enable automatic verification. +echo 2. No, I don't want to enable automatic verification right now. +SET /p "x2PGMode=Please enter the number corresponding to your preferred option: " + +IF "!x2PGMode!" == "1" ( + SET x2PGMode=UseX2PG + GOTO x2PGFinished +) +IF "!x2PGMode!" == "2" ( + SET x2PGMode=NoX2PG + GOTO x2PGFinished +) +echo Sorry, that's not a valid option^^! +echo. +SET x2PGMode= +GOTO x2PGSetup + +:x2PGFinished +echo. +echo X2PG mode has been set to "!x2PGMode!"^^! (2/4) +echo Next up... +echo. + +REM ********************** +REM *** COOKING SCREEN *** +REM ********************** + +:cookingSetup +IF NOT "!cookingMode!" == "" GOTO customSrcSetup +echo Do you want to enable cooking? If you're not 100%% sure when you need to do this, +echo that's alright: The author of this setup isn't sure yet, either. :^( +echo 1. Yes, please enable cooking. +echo 2. No, I don't think this project benefits from cooking. +SET /p "cookingMode=Please enter the number corresponding to your preferred option: " + +IF "!cookingMode!" == "1" ( + SET cookingMode=EnableCooking + GOTO cookingFinished +) +IF "!cookingMode!" == "2" ( + SET cookingMode=NoCooking + GOTO cookingFinished +) +echo Sorry, that's not a valid option^^! +echo. +SET cookingMode= +GOTO cookingSetup + +:cookingFinished +echo. +echo Cooking mode has been set to "!cookingMode!"^^! (3/4) +echo Almost there... +echo. + +REM ************************* +REM *** CUSTOM SRC SCREEN *** +REM ************************* + +:customSrcSetup +REM Since this one keeps iteratively adding to customSrc, we need a separate flag +REM to tell us we came here from the commit screen. +IF !skipCustomSrc! == TRUE GOTO commitScreen +SET moreSrc= +SET /p "moreSrc=Are there any other mods you want to build against? (Y/N) " +IF "!moreSrc!" == "Y" ( + echo Okay^^! We can do this folder-by-folder, or as a space-delimited list of folders. + echo Remember to target the mods' Src folders^^! This setup isn't smart enough + echo to do it for you. + SET /p "moreSrc=Please specify the path(s) to the mod(s) you wish to build against: " + IF NOT "!customSrc!" == "" SET customSrc=!customSrc! !moreSrc! + IF "!customSrc!" == "" SET customSrc=!moreSrc! + echo. + echo Dependency registered^^! Current dependencies: !customSrc! + echo. + GOTO customSrcSetup +) +IF NOT "!moreSrc!" == "N" ( + echo Sorry, that's not a valid option^^! + echo. + GOTO customSrcSetup +) + +SET skipCustomSrc=TRUE +echo. +echo Finished registering dependencies^^! (4/4) +echo Setup is ready to do its thing^^! +echo. + +REM ********************* +REM *** COMMIT SCREEN *** +REM ********************* + +:commitScreen +SET commit= +echo Here's the final config, for verification: +echo 1. Highlander source: !highlanderMode! +echo 2. Automatic validation: !x2PGMode! +echo 3. Is using cooking: !cookingMode! +echo 4. Dependency paths: !customSrc! +echo. +SET /p "commit=Does that look okay? Enter a number 1-4 to return to its corresponding step, or 5 to finish setup: " + +IF "!commit!" == "1" ( + echo Okay, returning to Highlander config^^! + echo. + SET highlanderMode= + GOTO highlanderSetup +) +IF "!commit!" == "2" ( + echo Got it, returning to X2PG config^^! + echo. + SET x2PGMode= + GOTO x2PGSetup +) +IF "!commit!" == "3" ( + echo Going back to cooking config now^^! + echo. + SET cookingMode= + GOTO cookingSetup +) +IF "!commit!" == "4" ( + echo Ouch. Going back to dependency config... hopefully not for long... + echo. + SET skipCustomSrc= + SET customSrc= + GOTO customSrcSetup +) +IF "!commit!" == "5" ( + GOTO runSetup +) +echo Sorry, that's not a valid option^^! +echo. +GOTO commitScreen + +:runSetup +echo Beginning project setup^^! Do not close this window... +echo. +RUN_THIS.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! + +echo Setup complete^^! +pause \ No newline at end of file diff --git a/ProjectTemplate.x2proj b/ProjectTemplate.x2proj index 4ac8eab..cfa45ed 100644 --- a/ProjectTemplate.x2proj +++ b/ProjectTemplate.x2proj @@ -31,6 +31,7 @@ + diff --git a/README.md b/README.md index b4ce326..4e68c2e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ ![EMPT-Logo](https://github.com/Iridar/EnhancedModProjectTemplate/blob/master/ModPreview.jpg) -# Enhanced Mod Project Template +# Enhanced Mod Project Template -Enhanced Mod Project Template (EMPT) is an XCOM 2 War of the Chosen mod project template. It can be used to create new mods quickly, without spending time and effort on menial tasks, like setting up [X2ModBuildCommon](https://github.com/X2CommunityCore/X2ModBuildCommon) manually. +Enhanced Mod Project Template (EMPT) is an XCOM 2 War of the Chosen mod project template. It can be used to create new mods quickly, without spending time and effort on menial tasks, like manually setting up [X2ModBuildCommon](https://github.com/X2CommunityCore/X2ModBuildCommon). -It also contains Config Engine, and some commonly used or referenced snippets of Unreal Script, and some global macros. +It also contains Config Engine, some commonly used or referenced snippets of Unreal Script, and some global macros. ## Installation @@ -12,43 +12,43 @@ Follow these instructions if you have not used EMPT previously. 1. Download the .zip archive with the [latest release](https://github.com/Iridar/EnhancedModProjectTemplate/releases/latest). 2. Put it here: `..\steamapps\common\XCOM 2 War of the Chosen SDK\Binaries\Win32\ModBuddy\Extensions\Application\ProjectTemplates\XCOM2Mod\1033` -3. Done. The next time you create a new mod project with modbuddy, select the Enhanced Mod project template. +3. Done. The next time you create a new mod project with ModBuddy, select the Enhanced Mod project template. ## Updating -Follow these instructions if you have already installed and used EMPT. Modbuddy caches the previously used Mod Project templates, so just replacing the file is not enough for the update to take effect. +Follow these instructions if you have already installed and used EMPT. ModBuddy caches the previously used Mod Project templates, so just replacing the file is not enough for the update to take effect. 1. Download the .zip archive with the [latest release](https://github.com/Iridar/EnhancedModProjectTemplate/releases/latest). 2. Move all files out of this folder: `..\steamapps\common\XCOM 2 War of the Chosen SDK\Binaries\Win32\ModBuddy\Extensions\Application\ProjectTemplates\XCOM2Mod\1033` -3. Start Modbuddy and click to create a new mod project. You should see only the Blank Project template. -4. Cancel the dialog and close Modbuddy. +3. Start ModBuddy and click to create a new mod project. You should see only the Blank Project template. +4. Cancel the dialog and close ModBuddy. 5. Move files back into the mentioned folder. 6. Put the updated EMPT .zip archive there as well, replacing the old file. -7. Done. The next time you create a new mod project with Modbuddy, the updated Enhanced Mod project template will be available. +7. Done. The next time you create a new mod project with ModBuddy, the updated Enhanced Mod project template will be available. ## Usage -1) Use Modbuddy to create the mod project using Enhanced Mod project template. +1) Use ModBuddy to create the mod project using the Enhanced Mod project template. -**Note:** when creating mod projects using this project template, it is **extremely important** that project Name, Solution name and Title match **exactly**. Otherwise there will be issues during first time setup and the mod project will become broken. +**Note:** when creating mod projects using this project template, it is **extremely important** that Project Name, Solution name, and Title match **exactly**. Otherwise, there will be issues during first-time setup, and the mod project will be broken. -2) Perform once-per-project setup by running the "RUN_THIS.bat" batch file inside the created mod project directory. The file will automatically delete itself afterwards. +2) Perform once-per-project setup by running the "RUN_THIS.bat" batch file inside the created mod project directory. The file will automatically delete itself afterwards. If you wish to build against the Community Highlander; validate the project with Xymanek's X2ProjectGenerator; enable cooking; or build against another mod, you can use "ADVANCED_SETUP.bat", instead. It will help you configure any of these features. 3) Enjoy. If your mod project doesn't require some of the files and folders created by EMPT, feel free to delete them. -4) As with any other mod project that uses X2MobBuildCommon, you have to use [Alternative Mod Uploader](https://steamcommunity.com/sharedfiles/filedetails/?id=1134322341) to upload it to workshop. +4) As with any other mod project that uses X2ModBuildCommon, you have to use [Alternative Mod Uploader](https://steamcommunity.com/sharedfiles/filedetails/?id=1134322341) to upload it to the Steam Workshop. ## X2ModBuildCommon -EMPT includes [X2ModBuildCommon](https://github.com/X2CommunityCore/X2ModBuildCommon) of version 1.2.1. +EMPT includes version 1.2.1 of [X2ModBuildCommon](https://github.com/X2CommunityCore/X2ModBuildCommon). ### Localization -The localization files shipped with the mod project use UTF-8 encoding, so changes to them can be previewed by Git and other version control systems. Modbuddy creates UTF-16 localization files by default, so if you need more localization files, it is preferable to copy the existing ones, rather than create new ones. +The localization files shipped with the mod project use UTF-8 encoding, so changes to them can be previewed by Git and other version control systems. ModBuddy creates UTF-16 localization files by default, so if you need more localization files, it is preferable to copy the existing ones, rather than create new ones. ### Cooking -To enable cooking with X2MBC, open `.scripts\build.ps1` file and uncomment the `$builder.SetContentOptionsJsonFilename("ContentOptions.json")` line by removing the `#` at the start. +To enable cooking with X2MBC (if you have not already used `ADVANCED_SETUP.bat` to do so), open the `.scripts\build.ps1` file and uncomment the `$builder.SetContentOptionsJsonFilename("ContentOptions.json")` line by removing the `#` at the start. You can find some basic instructions for [cooking here](https://www.reddit.com/r/xcom2mods/wiki/index/cooking_for_dummies). @@ -66,12 +66,12 @@ Help.uc is an Unreal Script helper class with Unreal Script snippets of commonly ## Building against Highlander -To build your mod against Highlander, run this command in Git terminal: +To build your mod against the Highlander (if you have not already configured X2MBC to do so), run this command in a Git terminal: `git submodule add https://github.com/X2CommunityCore/X2WOTCCommunityHighlander.git` -Then open `.scripts\build.ps1` and uncomment the `$builder.IncludeSrc("$srcDirectory\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src")` line by removing the `#` at the start. +Then open `.scripts\build.ps1`, and uncomment the `$builder.IncludeSrc("$srcDirectory\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src")` line by removing the `#` at the start. # Credits -[Find And Replace Text](http://fart-it.sourceforge.net/) command line tool (replace_text.exe) by by Lionello Lunesu +[Find And Replace Text](http://fart-it.sourceforge.net/) command line tool (replace_text.exe) by Lionello Lunesu diff --git a/RUN_THIS.bat b/RUN_THIS.bat index 38c6c36..e2f6681 100644 --- a/RUN_THIS.bat +++ b/RUN_THIS.bat @@ -1,5 +1,9 @@ @echo off +REM *********************** +REM *** SOLUTION CONFIG *** +REM *********************** + REM vstemplate cannot create files near solution file, only inside the project folder. REM And X2ModBuildCommon files need to be in the solution folder. REM The only solution is to create X2MBC files inside project folder, and then use this batch file to move them to the solution folder. @@ -32,6 +36,7 @@ replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCo replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\build_common.ps1" replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\build.ps1" replace_text.exe $ModSafeName$.x2proj --remove --c-style ".gitignore" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "ADVANCED_SETUP.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "RUN_THIS.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "replace_text.exe" @@ -47,9 +52,102 @@ REM Bandaid fix for path to XCOM2.targets file we ruined by one of the commands replace_text.exe $ModSafeName$.x2proj "$(SolutionRoot)" $(SolutionRoot).scripts\\ +REM ************************ +REM *** HIGHLANDER SETUP *** +REM ************************ + +REM Option 1: From Git (also initializes the Git repo while it's at it!) +IF %1 == "FromGit" ( + REM Go outside to set up the repo and grab the Highlander. + cd .. + git init + git add **/* + git commit -m "EMPT w/ Git: Initial commit" + git submodule add + + REM Now go back here for more convenient access to FART, + REM and reconfigure X2MBC to use our Git Highlander. + cd $ModSafeName$ + replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc("\""$srcDirectory" "$builder.IncludeSrc"("\""$srcDirectory" +) + +REM Option 2: From local Highlander folder +ELSE IF %1 == "FromPath" ( + REM We'll take an extra argument for the path here, so let's shift all the indices up to keep it consistent. + SHIFT + + REM Running FART in C-style mode screws with inserting file paths, + REM and I don't want to escape an arbitrary string inside a batch script. + REM Frankly, I'm tempted to try rewriting the whole thing in PowerShell + REM to avoid all this fiddling with FART and batch scripts... + replace_text.exe ..\.scripts\build.ps1 "# $builder.IncludeSrc(\"""C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src" "$builder.IncludeSrc"(\""%1" +) + +REM Option 3: From local Highlander folder, via the X2EMPT_HIGHLANDER_FOLDER environment variable. +REM TODO: Maybe add an option to set the variable in ADVANCED_SETUP.bat for ease of access? +ELSE IF %1 == "FromEnvVar" ( + replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc($env" "$builder.IncludeSrc($env" +) + +REM Option 4 is just skipping the Highlander outright, so no scripting needed. +REM ADVANCED_SETUP.bat will pass "NoHighlander" because we're working with +REM positional arguments and need *something*, but we don't actually care what we get here. +ELSE () + +REM ******************************** +REM *** X2ProjectGenerator SETUP *** +REM ******************************** + +REM Option 1: Use X2ProjectGenerator +IF %2 == "UseX2PG" ( + replace_text.exe --c-style ..\.scripts\build.ps1 "$useX2PG = $false" "$useX2PG = $true" +) + +REM Option 2 is just skipping X2PG outright, so no scripting needed. +REM As above, ADVANCED_SETUP.bat will pass "NoX2PG", but we don't actually care what we get. +ELSE () + +REM ********************* +REM *** COOKING SETUP *** +REM ********************* + +REM Option 1: Enable cooking +IF %3 == "EnableCooking" ( + replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.SetContent" "$builder.SetContent" +) + +REM Option 2 is just keeping cooking off, so no scripting needed. +REM As above, ADVANCED_SETUP.bat will pass "NoCooking", but we don't really care. +ELSE () + +REM ************************ +REM *** CUSTOM SRC SETUP *** +REM ************************ + +IF NOT "%4" == "" ( + :insertCustomSrc + REM As mentioned above, C-style screws with inserting file paths, + REM and I don't want to escape an arbitrary string inside a batch script. + REM So we'll run in regular mode, printing \\n to represent a linebreak, + REM then do a C-style postprocessing pass to turn it into a real linebreak. + REM + REM We're using \\n instead of \n because \n could legitimately occur + REM in the filesystem, but \\n should be illegal. I think. + replace_text.exe ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC" "$builder.IncludeSrc(\""%%path\"")\\n# PLACEHOLDER_CUSTOMSRC" + replace_text.exe --c-style ..\.scripts\build.ps1 \\\\n \n + + REM We want to loop through all remaining arguments until we run out of paths. + SHIFT + IF NOT "%4" == "" GOTO insertCustomSrc +) + +REM *************** +REM *** CLEANUP *** +REM *************** + echo X2ModBuildCommon v1.2.1 successfully installed. > ReadMe.txt echo. -echo Edit .scripts\build.ps1 if you want to enable cooking or build against Highlander. >> ReadMe.txt +echo Edit .scripts\build.ps1 if you want to enable/disable cooking or building against Highlander. >> ReadMe.txt echo. >> ReadMe.txt echo Enjoy making your mod, and may the odds be ever in your favor. >> ReadMe.txt echo. >> ReadMe.txt @@ -59,8 +157,17 @@ echo. >> ReadMe.txt echo Get news and updates here: >> ReadMe.txt echo https://github.com/Iridar/EnhancedModProjectTemplate >> ReadMe.txt +REM Clean up PLACEHOLDER_CUSTOMSRC. +replace_text.exe --remove --c-style ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC: Placeholder used by EMPT setup to automatically add custom source folders.\n" + REM Delete text editor. del replace_text.exe +REM Delete advanced setup file. +del ADVANCED_SETUP.bat + REM Delete this batch file. -del %0 \ No newline at end of file +REM This used to be `del %0`, but my use of SHIFT means %0 +REM is no longer the path to the current script. Not sure why Iridar did it +REM that way, anyway... +del RUN_THIS.bat \ No newline at end of file From 56536f910bdc72d7a93fb8decbc3e211b728fb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Neven=20Pra=C5=A1nikar?= Date: Tue, 11 Nov 2025 11:19:34 +0100 Subject: [PATCH 02/14] Fixed some oversights from yesterday's commit: - Fixed my argument checks. - Removed defective ELSE-IF constructs in favor of GOTOs. *grumbles about batch scripting* - Git automation no longer picks up the setup scripts or the raw X2MBC script. --- RUN_THIS.bat | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/RUN_THIS.bat b/RUN_THIS.bat index e2f6681..bdaf723 100644 --- a/RUN_THIS.bat +++ b/RUN_THIS.bat @@ -57,22 +57,21 @@ REM *** HIGHLANDER SETUP *** REM ************************ REM Option 1: From Git (also initializes the Git repo while it's at it!) -IF %1 == "FromGit" ( +IF "%1" == "FromGit" ( REM Go outside to set up the repo and grab the Highlander. cd .. git init - git add **/* - git commit -m "EMPT w/ Git: Initial commit" - git submodule add + git submodule add https://github.com/X2CommunityCore/X2WOTCCommunityHighlander.git REM Now go back here for more convenient access to FART, REM and reconfigure X2MBC to use our Git Highlander. cd $ModSafeName$ replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc("\""$srcDirectory" "$builder.IncludeSrc"("\""$srcDirectory" + GOTO highlanderFinished ) REM Option 2: From local Highlander folder -ELSE IF %1 == "FromPath" ( +IF "%1" == "FromPath" ( REM We'll take an extra argument for the path here, so let's shift all the indices up to keep it consistent. SHIFT @@ -81,44 +80,44 @@ ELSE IF %1 == "FromPath" ( REM Frankly, I'm tempted to try rewriting the whole thing in PowerShell REM to avoid all this fiddling with FART and batch scripts... replace_text.exe ..\.scripts\build.ps1 "# $builder.IncludeSrc(\"""C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src" "$builder.IncludeSrc"(\""%1" + GOTO highlanderFinished ) REM Option 3: From local Highlander folder, via the X2EMPT_HIGHLANDER_FOLDER environment variable. REM TODO: Maybe add an option to set the variable in ADVANCED_SETUP.bat for ease of access? -ELSE IF %1 == "FromEnvVar" ( +IF "%1" == "FromEnvVar" ( replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc($env" "$builder.IncludeSrc($env" + GOTO highlanderFinished ) REM Option 4 is just skipping the Highlander outright, so no scripting needed. REM ADVANCED_SETUP.bat will pass "NoHighlander" because we're working with REM positional arguments and need *something*, but we don't actually care what we get here. -ELSE () +:highlanderFinished REM ******************************** REM *** X2ProjectGenerator SETUP *** REM ******************************** REM Option 1: Use X2ProjectGenerator -IF %2 == "UseX2PG" ( +IF "%2" == "UseX2PG" ( replace_text.exe --c-style ..\.scripts\build.ps1 "$useX2PG = $false" "$useX2PG = $true" ) REM Option 2 is just skipping X2PG outright, so no scripting needed. REM As above, ADVANCED_SETUP.bat will pass "NoX2PG", but we don't actually care what we get. -ELSE () REM ********************* REM *** COOKING SETUP *** REM ********************* REM Option 1: Enable cooking -IF %3 == "EnableCooking" ( +IF "%3" == "EnableCooking" ( replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.SetContent" "$builder.SetContent" ) REM Option 2 is just keeping cooking off, so no scripting needed. REM As above, ADVANCED_SETUP.bat will pass "NoCooking", but we don't really care. -ELSE () REM ************************ REM *** CUSTOM SRC SETUP *** @@ -170,4 +169,9 @@ REM Delete this batch file. REM This used to be `del %0`, but my use of SHIFT means %0 REM is no longer the path to the current script. Not sure why Iridar did it REM that way, anyway... -del RUN_THIS.bat \ No newline at end of file +del RUN_THIS.bat + +REM If we're using Git, now is a good time to make an initial commit! +cd .. +git add **/* +git commit -m "EMPT w/ Git: Initial commit" \ No newline at end of file From 3d041457589d0cc56960030f06a73a29366fffd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Neven=20Pra=C5=A1nikar?= Date: Tue, 11 Nov 2025 11:34:11 +0100 Subject: [PATCH 03/14] Git setup is now a separate step, and no longer requires you to fetch the Highlander from GitHub. This means you no longer need to manually set up Git if you're building against a local Highlander (e.g. from environment variables!). --- ADVANCED_SETUP.bat | 74 ++++++++++++++++++++++++++++++++++++++-------- RUN_THIS.bat | 5 ++-- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/ADVANCED_SETUP.bat b/ADVANCED_SETUP.bat index f5c03e7..a5afd28 100644 --- a/ADVANCED_SETUP.bat +++ b/ADVANCED_SETUP.bat @@ -11,25 +11,56 @@ echo. SETLOCAL EnableDelayedExpansion REM Set initial values so we can reliably navigate back from the commit screen. +SET gitMode= SET highlanderMode= SET x2PGMode= SET cookingMode= SET customSrc= SET skipCustomSrc= +REM ****************** +REM *** GIT SCREEN *** +REM ****************** + +:gitSetup +echo Do you want to use Git for version control? (You need to have installed it before, or this won't do anything...) +echo 1. Yes, I want to use Git. +echo 2. No, I don't want to use Git right now. +SET /p "gitMode=Please enter the number corresponding to your preferred option: " + +IF "!gitMode!" == "1" ( + SET gitMode=UseGit + GOTO gitFinished +) +IF "!gitMode!" == "2" ( + SET gitMode=NoGit + GOTO gitFinished +) +echo Sorry, that's not a valid option^^! +echo. +SET gitMode= +GOTO gitSetup + +:gitFinished +echo. +echo Git mode has been set to "!gitMode!"^^! (1/5) +echo Moving on to the meaty bits... +echo. + REM ************************* REM *** HIGHLANDER SCREEN *** REM ************************* :highlanderSetup echo How do you want to build against the Community Highlander? -echo 1. Get the Highlander from GitHub. +echo 1. Get the Highlander from GitHub. (This will forcibly enable Git mode^^!) echo 2. Use a local copy of the Highlander from a project-specific path... echo 3. Use a local copy of the Highlander from a global path... echo 4. I don't want to build against the Highlander right now. SET /p "highlanderMode=Please enter the number corresponding to your preferred option: " IF "!highlanderMode!" == "1" ( + SET gitMode=UseGit SET highlanderMode=FromGit GOTO highlanderFinished ) @@ -89,7 +120,7 @@ GOTO highlanderSetup :highlanderFinished echo. -echo Highlander mode has been set to "!highlanderMode!"^^! (1/4) +echo Highlander mode has been set to "!highlanderMode!"^^! (2/5) echo Moving on... echo. @@ -154,7 +185,7 @@ GOTO cookingSetup :cookingFinished echo. -echo Cooking mode has been set to "!cookingMode!"^^! (3/4) +echo Cooking mode has been set to "!cookingMode!"^^! (4/5) echo Almost there... echo. @@ -188,7 +219,7 @@ IF NOT "!moreSrc!" == "N" ( SET skipCustomSrc=TRUE echo. -echo Finished registering dependencies^^! (4/4) +echo Finished registering dependencies^^! (5/5) echo Setup is ready to do its thing^^! echo. @@ -199,39 +230,51 @@ REM ********************* :commitScreen SET commit= echo Here's the final config, for verification: -echo 1. Highlander source: !highlanderMode! -echo 2. Automatic validation: !x2PGMode! -echo 3. Is using cooking: !cookingMode! -echo 4. Dependency paths: !customSrc! +echo 1. Is using Git: !gitMode! +echo 2. Highlander source: !highlanderMode! +echo 3. Automatic validation: !x2PGMode! +echo 4. Is using cooking: !cookingMode! +echo 5. Dependency paths: !customSrc! echo. -SET /p "commit=Does that look okay? Enter a number 1-4 to return to its corresponding step, or 5 to finish setup: " +SET /p "commit=Does that look okay? Enter a number 1-5 to return to its corresponding step, or 6 to finish setup: " IF "!commit!" == "1" ( + IF "!highlanderMode!" == "FromGit" ( + echo Sorry, can't disable Git if you're using it to build against the Highlander^^! + echo. + GOTO commitScreen + ) + echo Returning to Git config now^^! + echo. + SET gitMode= + GOTO gitSetup +) +IF "!commit!" == "2" ( echo Okay, returning to Highlander config^^! echo. SET highlanderMode= GOTO highlanderSetup ) -IF "!commit!" == "2" ( +IF "!commit!" == "3" ( echo Got it, returning to X2PG config^^! echo. SET x2PGMode= GOTO x2PGSetup ) -IF "!commit!" == "3" ( +IF "!commit!" == "4" ( echo Going back to cooking config now^^! echo. SET cookingMode= GOTO cookingSetup ) -IF "!commit!" == "4" ( +IF "!commit!" == "5" ( echo Ouch. Going back to dependency config... hopefully not for long... echo. SET skipCustomSrc= SET customSrc= GOTO customSrcSetup ) -IF "!commit!" == "5" ( +IF "!commit!" == "6" ( GOTO runSetup ) echo Sorry, that's not a valid option^^! @@ -241,6 +284,11 @@ GOTO commitScreen :runSetup echo Beginning project setup^^! Do not close this window... echo. +IF "!gitMode!" == "UseGit" ( + cd .. + git init + cd $ModSafeName$ +) RUN_THIS.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! echo Setup complete^^! diff --git a/RUN_THIS.bat b/RUN_THIS.bat index bdaf723..1f6bbfb 100644 --- a/RUN_THIS.bat +++ b/RUN_THIS.bat @@ -56,11 +56,10 @@ REM ************************ REM *** HIGHLANDER SETUP *** REM ************************ -REM Option 1: From Git (also initializes the Git repo while it's at it!) +REM Option 1: From Git IF "%1" == "FromGit" ( - REM Go outside to set up the repo and grab the Highlander. + REM Go outside to grab the Highlander (we're presuming the repo already exists). cd .. - git init git submodule add https://github.com/X2CommunityCore/X2WOTCCommunityHighlander.git REM Now go back here for more convenient access to FART, From c9a2b886ca3d6bf1c361f9dae4915706062a06c0 Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Sun, 16 Nov 2025 11:44:07 +0100 Subject: [PATCH 04/14] Add the advanced setup script to the VSTemplate. --- EnhancedModProjectTemplate.vstemplate | 1 + 1 file changed, 1 insertion(+) diff --git a/EnhancedModProjectTemplate.vstemplate b/EnhancedModProjectTemplate.vstemplate index 4da7d21..d30ee66 100644 --- a/EnhancedModProjectTemplate.vstemplate +++ b/EnhancedModProjectTemplate.vstemplate @@ -27,6 +27,7 @@ .gitignore RUN_THIS.bat + ADVANCED_SETUP.bat replace_text.exe Config\Base\XComEditor.ini From ed26c404713ba08e03ed967dab5b38e42c8b3ffa Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Sun, 16 Nov 2025 12:36:47 +0100 Subject: [PATCH 05/14] Tweaked the setup scripts: - Now properly finishes the initial commit. - No longer crashes halfway through because the scripts were deleted during execution. --- ADVANCED_SETUP.bat | 8 +++++--- RUN_THIS.bat | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ADVANCED_SETUP.bat b/ADVANCED_SETUP.bat index a5afd28..f4fe061 100644 --- a/ADVANCED_SETUP.bat +++ b/ADVANCED_SETUP.bat @@ -289,7 +289,9 @@ IF "!gitMode!" == "UseGit" ( git init cd $ModSafeName$ ) -RUN_THIS.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! -echo Setup complete^^! -pause \ No newline at end of file +REM RUN_THIS expects delayed expansion to be off. +REM I chose not to bother changing that, but +REM the setting will be inherited from the previous script. +SETLOCAL DisableDelayedExpansion +RUN_THIS.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! \ No newline at end of file diff --git a/RUN_THIS.bat b/RUN_THIS.bat index 1f6bbfb..46e9b2c 100644 --- a/RUN_THIS.bat +++ b/RUN_THIS.bat @@ -164,13 +164,16 @@ del replace_text.exe REM Delete advanced setup file. del ADVANCED_SETUP.bat -REM Delete this batch file. -REM This used to be `del %0`, but my use of SHIFT means %0 -REM is no longer the path to the current script. Not sure why Iridar did it -REM that way, anyway... -del RUN_THIS.bat - REM If we're using Git, now is a good time to make an initial commit! cd .. -git add **/* -git commit -m "EMPT w/ Git: Initial commit" \ No newline at end of file +git add **/* :!$ModSafeName$\RUN_THIS.bat +git commit -m "EMPT w/ Git: Initial commit" +cd $ModSafeName$ + +REM Delete this batch file. +REM This is a bit fancier than Iridar's original, +REM because: +REM - My use of SHIFT means %0 is no longer the path to the current script. +REM - The original threw an error and I didn't like that. +REM Source/explanation: https://stackoverflow.com/a/20333152 +(GOTO) 2>NUL & del RUN_THIS.bat && echo Setup complete! && pause \ No newline at end of file From 17b942bb18e630641f188d8463d3e51c3c9354e4 Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Mon, 1 Dec 2025 11:14:49 +0100 Subject: [PATCH 06/14] Added batch scripts to build/clean the project, based on (read: shamelessly stolen from) the LWotC repo. --- EnhancedModProjectTemplate.vstemplate | 4 ++++ ProjectTemplate.x2proj | 4 ++++ RUN_THIS.bat | 4 ++++ build.bat | 14 ++++++++++++++ build_debug.bat | 3 +++ build_default.bat | 3 +++ clean.bat | 14 ++++++++++++++ 7 files changed, 46 insertions(+) create mode 100644 build.bat create mode 100644 build_debug.bat create mode 100644 build_default.bat create mode 100644 clean.bat diff --git a/EnhancedModProjectTemplate.vstemplate b/EnhancedModProjectTemplate.vstemplate index d30ee66..85ae59c 100644 --- a/EnhancedModProjectTemplate.vstemplate +++ b/EnhancedModProjectTemplate.vstemplate @@ -28,6 +28,10 @@ .gitignore RUN_THIS.bat ADVANCED_SETUP.bat + build.bat + clean.bat + build_debug.bat + build_default.bat replace_text.exe Config\Base\XComEditor.ini diff --git a/ProjectTemplate.x2proj b/ProjectTemplate.x2proj index cfa45ed..02958ac 100644 --- a/ProjectTemplate.x2proj +++ b/ProjectTemplate.x2proj @@ -33,6 +33,10 @@ + + + + diff --git a/RUN_THIS.bat b/RUN_THIS.bat index 46e9b2c..f73339b 100644 --- a/RUN_THIS.bat +++ b/RUN_THIS.bat @@ -38,6 +38,10 @@ replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\build.ps1" replace_text.exe $ModSafeName$.x2proj --remove --c-style ".gitignore" replace_text.exe $ModSafeName$.x2proj --remove --c-style "ADVANCED_SETUP.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "RUN_THIS.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "build.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_debug.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_default.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "clean.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "replace_text.exe" REM " and \ are tough to handle, so it needs to be done in two steps. diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..b3db195 --- /dev/null +++ b/build.bat @@ -0,0 +1,14 @@ +@echo off + +if "%XCOM2SDKPATH%" == "" ( + echo You need to specify the location of the XCOM 2 WOTC SDK in the XCOM2SDKPATH environment variable + exit /b 1 +) + +if "%XCOM2GAMEPATH%" == "" ( + echo You need to specify the location of the XCOM 2 War of the Chosen game directory (typically ^\steamapps\common\XCOM 2\XCom2-WarOfTheChosen^) in the XCOM2GAMEPATH environment variable + exit /b 1 +) + +rem The trailing backslash after %~dp0 is important, otherwise PowerShell thinks the " is being escaped! +powershell.exe -NonInteractive -ExecutionPolicy Unrestricted -file "%~dp0.scripts\build.ps1" -srcDirectory "%~dp0\" -sdkPath "%XCOM2SDKPATH%" -gamePath "%XCOM2GAMEPATH%" %* diff --git a/build_debug.bat b/build_debug.bat new file mode 100644 index 0000000..10c6d8e --- /dev/null +++ b/build_debug.bat @@ -0,0 +1,3 @@ +@echo off + +build.bat -config debug \ No newline at end of file diff --git a/build_default.bat b/build_default.bat new file mode 100644 index 0000000..5526008 --- /dev/null +++ b/build_default.bat @@ -0,0 +1,3 @@ +@echo off + +build.bat -config default \ No newline at end of file diff --git a/clean.bat b/clean.bat new file mode 100644 index 0000000..9ece3f3 --- /dev/null +++ b/clean.bat @@ -0,0 +1,14 @@ +@echo off + +if "%XCOM2SDKPATH%" == "" ( + echo You need to specify the location of the XCOM 2 WOTC SDK in the XCOM2SDKPATH environment variable + exit /b 1 +) + +if "%XCOM2GAMEPATH%" == "" ( + echo You need to specify the location of the XCOM 2 War of the Chosen game directory (typically ^\steamapps\common\XCOM 2\XCom2-WarOfTheChosen^) in the XCOM2GAMEPATH environment variable + exit /b 1 +) + +rem The trailing backslash after %~dp0 is important, otherwise PowerShell thinks the " is being escaped! +powershell.exe -NonInteractive -ExecutionPolicy Unrestricted -file "%~dp0.scripts\X2ModBuildCommon\clean.ps1" -srcDirectory "%~dp0\" -sdkPath "%XCOM2SDKPATH%" -gamePath "%XCOM2GAMEPATH%" -modName "$ModSafeName$" From b527bf4cf1911fb1eb205a901a6eeaa2ecbb95fd Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Mon, 1 Dec 2025 11:22:48 +0100 Subject: [PATCH 07/14] Renamed setup scripts so they get grouped together for visibility. Also added a reference to the advanced setup to ReadMe.txt. --- .scripts/build.ps1 | 2 +- EnhancedModProjectTemplate.vstemplate | 4 ++-- ProjectTemplate.x2proj | 4 ++-- README.md | 4 ++-- ReadMe.txt | 2 +- RUN_THIS.bat => SETUP.bat | 18 +++++++++--------- ADVANCED_SETUP.bat => SETUP_ADVANCED.bat | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) rename RUN_THIS.bat => SETUP.bat (93%) rename ADVANCED_SETUP.bat => SETUP_ADVANCED.bat (98%) diff --git a/.scripts/build.ps1 b/.scripts/build.ps1 index 61c48cc..24cd732 100644 --- a/.scripts/build.ps1 +++ b/.scripts/build.ps1 @@ -48,7 +48,7 @@ $builder = [BuildProject]::new("$ModSafeName$", $srcDirectory, $sdkPath, $gamePa # Uncomment to use additional global Custom Src to build against. # $builder.IncludeSrc("C:\Users\Iridar\Documents\Firaxis ModBuddy\CustomSrc") -# PLACEHOLDER_CUSTOMSRC: Used by ADVANCED_SETUP.bat to configure custom source folders. +# PLACEHOLDER_CUSTOMSRC: Used by SETUP_ADVANCED.bat to configure custom source folders. switch ($config) { diff --git a/EnhancedModProjectTemplate.vstemplate b/EnhancedModProjectTemplate.vstemplate index 85ae59c..4232716 100644 --- a/EnhancedModProjectTemplate.vstemplate +++ b/EnhancedModProjectTemplate.vstemplate @@ -26,8 +26,8 @@ .scripts\X2ModBuildCommon\XCOM2.targets .gitignore - RUN_THIS.bat - ADVANCED_SETUP.bat + SETUP.bat + SETUP_ADVANCED.bat build.bat clean.bat build_debug.bat diff --git a/ProjectTemplate.x2proj b/ProjectTemplate.x2proj index 02958ac..ca2f102 100644 --- a/ProjectTemplate.x2proj +++ b/ProjectTemplate.x2proj @@ -31,8 +31,8 @@ - - + + diff --git a/README.md b/README.md index 4e68c2e..ec4ca0b 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Follow these instructions if you have already installed and used EMPT. ModBuddy **Note:** when creating mod projects using this project template, it is **extremely important** that Project Name, Solution name, and Title match **exactly**. Otherwise, there will be issues during first-time setup, and the mod project will be broken. -2) Perform once-per-project setup by running the "RUN_THIS.bat" batch file inside the created mod project directory. The file will automatically delete itself afterwards. If you wish to build against the Community Highlander; validate the project with Xymanek's X2ProjectGenerator; enable cooking; or build against another mod, you can use "ADVANCED_SETUP.bat", instead. It will help you configure any of these features. +2) Perform once-per-project setup by running the "SETUP.bat" batch file inside the created mod project directory. The file will automatically delete itself afterwards. If you wish to build against the Community Highlander; validate the project with Xymanek's X2ProjectGenerator; enable cooking; or build against another mod, you can use "SETUP_ADVANCED.bat", instead. It will help you configure any of these features. 3) Enjoy. If your mod project doesn't require some of the files and folders created by EMPT, feel free to delete them. @@ -48,7 +48,7 @@ The localization files shipped with the mod project use UTF-8 encoding, so chang ### Cooking -To enable cooking with X2MBC (if you have not already used `ADVANCED_SETUP.bat` to do so), open the `.scripts\build.ps1` file and uncomment the `$builder.SetContentOptionsJsonFilename("ContentOptions.json")` line by removing the `#` at the start. +To enable cooking with X2MBC (if you have not already used `SETUP_ADVANCED.bat` to do so), open the `.scripts\build.ps1` file and uncomment the `$builder.SetContentOptionsJsonFilename("ContentOptions.json")` line by removing the `#` at the start. You can find some basic instructions for [cooking here](https://www.reddit.com/r/xcom2mods/wiki/index/cooking_for_dummies). diff --git a/ReadMe.txt b/ReadMe.txt index b7058b8..dfd9df9 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -2,7 +2,7 @@ You must perform once-per-mod setup before you can begin working on your mod. -To do so, run "RUN_THIS.bat" in the mod project folder. +To do so, run either "SETUP.bat" or "SETUP_ADVANCED.bat" in the mod project folder. "SETUP_ADVANCED.bat" has the added advantage of guiding you through a few common configuration steps, but these may not be relevant to your mod. If you did not close Modbuddy, you will get a popup message about files being modified outside the source editor. Click "Yes to All". diff --git a/RUN_THIS.bat b/SETUP.bat similarity index 93% rename from RUN_THIS.bat rename to SETUP.bat index f73339b..fcfd195 100644 --- a/RUN_THIS.bat +++ b/SETUP.bat @@ -36,8 +36,8 @@ replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCo replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\build_common.ps1" replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\build.ps1" replace_text.exe $ModSafeName$.x2proj --remove --c-style ".gitignore" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "ADVANCED_SETUP.bat" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "RUN_THIS.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "SETUP_ADVANCED.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "SETUP.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "build.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_debug.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_default.bat" @@ -87,14 +87,14 @@ IF "%1" == "FromPath" ( ) REM Option 3: From local Highlander folder, via the X2EMPT_HIGHLANDER_FOLDER environment variable. -REM TODO: Maybe add an option to set the variable in ADVANCED_SETUP.bat for ease of access? +REM TODO: Maybe add an option to set the variable in SETUP_ADVANCED.bat for ease of access? IF "%1" == "FromEnvVar" ( replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc($env" "$builder.IncludeSrc($env" GOTO highlanderFinished ) REM Option 4 is just skipping the Highlander outright, so no scripting needed. -REM ADVANCED_SETUP.bat will pass "NoHighlander" because we're working with +REM SETUP_ADVANCED.bat will pass "NoHighlander" because we're working with REM positional arguments and need *something*, but we don't actually care what we get here. :highlanderFinished @@ -108,7 +108,7 @@ IF "%2" == "UseX2PG" ( ) REM Option 2 is just skipping X2PG outright, so no scripting needed. -REM As above, ADVANCED_SETUP.bat will pass "NoX2PG", but we don't actually care what we get. +REM As above, SETUP_ADVANCED.bat will pass "NoX2PG", but we don't actually care what we get. REM ********************* REM *** COOKING SETUP *** @@ -120,7 +120,7 @@ IF "%3" == "EnableCooking" ( ) REM Option 2 is just keeping cooking off, so no scripting needed. -REM As above, ADVANCED_SETUP.bat will pass "NoCooking", but we don't really care. +REM As above, SETUP_ADVANCED.bat will pass "NoCooking", but we don't really care. REM ************************ REM *** CUSTOM SRC SETUP *** @@ -166,11 +166,11 @@ REM Delete text editor. del replace_text.exe REM Delete advanced setup file. -del ADVANCED_SETUP.bat +del SETUP_ADVANCED.bat REM If we're using Git, now is a good time to make an initial commit! cd .. -git add **/* :!$ModSafeName$\RUN_THIS.bat +git add **/* :!$ModSafeName$\SETUP.bat git commit -m "EMPT w/ Git: Initial commit" cd $ModSafeName$ @@ -180,4 +180,4 @@ REM because: REM - My use of SHIFT means %0 is no longer the path to the current script. REM - The original threw an error and I didn't like that. REM Source/explanation: https://stackoverflow.com/a/20333152 -(GOTO) 2>NUL & del RUN_THIS.bat && echo Setup complete! && pause \ No newline at end of file +(GOTO) 2>NUL & del SETUP.bat && echo Setup complete! && pause \ No newline at end of file diff --git a/ADVANCED_SETUP.bat b/SETUP_ADVANCED.bat similarity index 98% rename from ADVANCED_SETUP.bat rename to SETUP_ADVANCED.bat index f4fe061..a3126ca 100644 --- a/ADVANCED_SETUP.bat +++ b/SETUP_ADVANCED.bat @@ -290,8 +290,8 @@ IF "!gitMode!" == "UseGit" ( cd $ModSafeName$ ) -REM RUN_THIS expects delayed expansion to be off. +REM SETUP expects delayed expansion to be off. REM I chose not to bother changing that, but REM the setting will be inherited from the previous script. SETLOCAL DisableDelayedExpansion -RUN_THIS.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! \ No newline at end of file +SETUP.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! \ No newline at end of file From aecf5d84b31720dab1c44db964e27c6ca909ede8 Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Mon, 1 Dec 2025 11:37:54 +0100 Subject: [PATCH 08/14] Added guidance for finding the SDK path --- build.bat | 2 +- clean.bat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.bat b/build.bat index b3db195..544c1b9 100644 --- a/build.bat +++ b/build.bat @@ -1,7 +1,7 @@ @echo off if "%XCOM2SDKPATH%" == "" ( - echo You need to specify the location of the XCOM 2 WOTC SDK in the XCOM2SDKPATH environment variable + echo You need to specify the location of the XCOM 2 WOTC SDK (typically ^\steamapps\common\XCOM 2 War of the Chosen SDK^) in the XCOM2SDKPATH environment variable exit /b 1 ) diff --git a/clean.bat b/clean.bat index 9ece3f3..6375d84 100644 --- a/clean.bat +++ b/clean.bat @@ -1,7 +1,7 @@ @echo off if "%XCOM2SDKPATH%" == "" ( - echo You need to specify the location of the XCOM 2 WOTC SDK in the XCOM2SDKPATH environment variable + echo You need to specify the location of the XCOM 2 WOTC SDK (typically ^\steamapps\common\XCOM 2 War of the Chosen SDK^) in the XCOM2SDKPATH environment variable exit /b 1 ) From b592e387aa4c30d39667bf6a0eb5e5b9bb878f1b Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Mon, 1 Dec 2025 12:05:22 +0100 Subject: [PATCH 09/14] Added default VSCode workspace, and taught the setup how to set it up. --- .gitignore | 1 + EnhancedModProjectTemplate.vstemplate | 1 + ProjectTemplate.x2proj | 1 + SETUP.bat | 22 +++++++++++++++++++++- vscode.code-workspace.default | 17 +++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 vscode.code-workspace.default diff --git a/.gitignore b/.gitignore index bdcaa9d..b13ada1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.lnk +/*.code-workspace BuildCache/ \ No newline at end of file diff --git a/EnhancedModProjectTemplate.vstemplate b/EnhancedModProjectTemplate.vstemplate index 4232716..bb1dc47 100644 --- a/EnhancedModProjectTemplate.vstemplate +++ b/EnhancedModProjectTemplate.vstemplate @@ -33,6 +33,7 @@ build_debug.bat build_default.bat replace_text.exe + vscode.code-workspace.default Config\Base\XComEditor.ini Config\Base\XComEngine.ini diff --git a/ProjectTemplate.x2proj b/ProjectTemplate.x2proj index ca2f102..b71e8c6 100644 --- a/ProjectTemplate.x2proj +++ b/ProjectTemplate.x2proj @@ -37,6 +37,7 @@ + diff --git a/SETUP.bat b/SETUP.bat index fcfd195..1758e1b 100644 --- a/SETUP.bat +++ b/SETUP.bat @@ -43,6 +43,7 @@ replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_debug.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_default.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "clean.bat" replace_text.exe $ModSafeName$.x2proj --remove --c-style "replace_text.exe" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "vscode.code-workspace.default" REM " and \ are tough to handle, so it needs to be done in two steps. @@ -70,6 +71,9 @@ IF "%1" == "FromGit" ( REM and reconfigure X2MBC to use our Git Highlander. cd $ModSafeName$ replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc("\""$srcDirectory" "$builder.IncludeSrc"("\""$srcDirectory" + + REM Also configure the VSCode workspace! + replace_text.exe --c-style vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"../X2WOTCCommunityHighlander/X2WOTCCommunityHighlander/Src\"}" GOTO highlanderFinished ) @@ -83,6 +87,9 @@ IF "%1" == "FromPath" ( REM Frankly, I'm tempted to try rewriting the whole thing in PowerShell REM to avoid all this fiddling with FART and batch scripts... replace_text.exe ..\.scripts\build.ps1 "# $builder.IncludeSrc(\"""C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src" "$builder.IncludeSrc"(\""%1" + + REM Also configure the VSCode workspace! + replace_text.exe vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"%1\"}" GOTO highlanderFinished ) @@ -90,12 +97,16 @@ REM Option 3: From local Highlander folder, via the X2EMPT_HIGHLANDER_FOLDER env REM TODO: Maybe add an option to set the variable in SETUP_ADVANCED.bat for ease of access? IF "%1" == "FromEnvVar" ( replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc($env" "$builder.IncludeSrc($env" + replace_text.exe --c-style vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"${env:X2EMPT_HIGHLANDER_FOLDER}\"}" GOTO highlanderFinished ) -REM Option 4 is just skipping the Highlander outright, so no scripting needed. +REM Option 4 is just skipping the Highlander outright, so we only need to clean up the VSCode workspace. REM SETUP_ADVANCED.bat will pass "NoHighlander" because we're working with REM positional arguments and need *something*, but we don't actually care what we get here. +replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\r\n\t\t" +REM In case it's using LF line endings! +replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\n\t\t" :highlanderFinished REM ******************************** @@ -138,6 +149,9 @@ IF NOT "%4" == "" ( replace_text.exe ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC" "$builder.IncludeSrc(\""%%path\"")\\n# PLACEHOLDER_CUSTOMSRC" replace_text.exe --c-style ..\.scripts\build.ps1 \\\\n \n + replace_text.exe vscode.code-workspace.default "$DEPENDENCY" "{\""path\"": \"%1\"},\\n$DEPENDENCY" + replace_text.exe --c-style vscode.code-workspace.default \\\\n$DEPENDENCY \n\t\t$DEPENDENCY + REM We want to loop through all remaining arguments until we run out of paths. SHIFT IF NOT "%4" == "" GOTO insertCustomSrc @@ -162,6 +176,12 @@ echo https://github.com/Iridar/EnhancedModProjectTemplate >> ReadMe.txt REM Clean up PLACEHOLDER_CUSTOMSRC. replace_text.exe --remove --c-style ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC: Placeholder used by EMPT setup to automatically add custom source folders.\n" +REM Clean up and finalize VSCode workspace. +replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\r\n\t\t" +REM In case it's using LF line endings! +replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\n\t\t" +move vscode.code-workspace.default $ModSafeName$.code-workspace + REM Delete text editor. del replace_text.exe diff --git a/vscode.code-workspace.default b/vscode.code-workspace.default new file mode 100644 index 0000000..5212e78 --- /dev/null +++ b/vscode.code-workspace.default @@ -0,0 +1,17 @@ +{ + "folders": [ + { + "path": "." + }, + $HIGHLANDER, + $DEPENDENCY, + { + "path": "${env:XCOM2SDKPATH}/Development/SrcOrig" + } + ], + "settings": { + "files.associations": { + "*.int":"ini" + } + } +} \ No newline at end of file From 3b8fc61f925cc290dbce6c61306744ef6df31763 Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Mon, 1 Dec 2025 21:51:01 +0100 Subject: [PATCH 10/14] Tweaked the final location of the VSCode workspace and batch scripts. --- SETUP.bat | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SETUP.bat b/SETUP.bat index 1758e1b..d549ed5 100644 --- a/SETUP.bat +++ b/SETUP.bat @@ -176,11 +176,17 @@ echo https://github.com/Iridar/EnhancedModProjectTemplate >> ReadMe.txt REM Clean up PLACEHOLDER_CUSTOMSRC. replace_text.exe --remove --c-style ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC: Placeholder used by EMPT setup to automatically add custom source folders.\n" -REM Clean up and finalize VSCode workspace. +REM Clean up VSCode workspace. replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\r\n\t\t" REM In case it's using LF line endings! replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\n\t\t" -move vscode.code-workspace.default $ModSafeName$.code-workspace + +REM Move VSCode workspace and the helper scripts where they belong. +move vscode.code-workspace.default ../$ModSafeName$.code-workspace +move build_default.bat ../build_default.bat +move build_debug.bat ../build_debug.bat +move build.bat ../build.bat +move clean.bat ../clean.bat REM Delete text editor. del replace_text.exe From 213637c3a72ea8fd92d8bdbcf774ae4170f5719f Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Wed, 10 Dec 2025 11:13:31 +0100 Subject: [PATCH 11/14] More fixes and enhancements: - Fixed an issue where the advanced setup was no longer correctly passing parameters to regular setup. - Fixed an issue where the FART placeholders in the VSCode workspace weren't being properly cleared. - Fixed an issue where the VSCode workspace wouldn't know where the SDK source folder was, because you can't read environment variables in a workspace definition. (This also affected workspaces trying to grab the Highlander from environment. Fixed that too.) - Added optional SDK/game folder detection steps to advanced setup. --- SETUP.bat | 23 +++++++---- SETUP_ADVANCED.bat | 72 +++++++++++++++++++++++++++++++++-- build.bat | 2 +- clean.bat | 6 +-- vscode.code-workspace.default | 2 +- 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/SETUP.bat b/SETUP.bat index d549ed5..d444c18 100644 --- a/SETUP.bat +++ b/SETUP.bat @@ -1,4 +1,8 @@ @echo off +REM SETUP_ADVANCED uses delayed expansion while SETUP +REM expects it to be disabled. I chose not to bother changing that, but +REM need to clean up after the previous script. +SETLOCAL DisableDelayedExpansion REM *********************** REM *** SOLUTION CONFIG *** @@ -94,19 +98,18 @@ IF "%1" == "FromPath" ( ) REM Option 3: From local Highlander folder, via the X2EMPT_HIGHLANDER_FOLDER environment variable. -REM TODO: Maybe add an option to set the variable in SETUP_ADVANCED.bat for ease of access? IF "%1" == "FromEnvVar" ( replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc($env" "$builder.IncludeSrc($env" - replace_text.exe --c-style vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"${env:X2EMPT_HIGHLANDER_FOLDER}\"}" + replace_text.exe --c-style vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"%X2EMPT_HIGHLANDER_FOLDER%\"}" GOTO highlanderFinished ) REM Option 4 is just skipping the Highlander outright, so we only need to clean up the VSCode workspace. REM SETUP_ADVANCED.bat will pass "NoHighlander" because we're working with REM positional arguments and need *something*, but we don't actually care what we get here. -replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\r\n\t\t" +replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\r\n" REM In case it's using LF line endings! -replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\n\t\t" +replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\n" :highlanderFinished REM ******************************** @@ -176,10 +179,16 @@ echo https://github.com/Iridar/EnhancedModProjectTemplate >> ReadMe.txt REM Clean up PLACEHOLDER_CUSTOMSRC. replace_text.exe --remove --c-style ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC: Placeholder used by EMPT setup to automatically add custom source folders.\n" -REM Clean up VSCode workspace. -replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\r\n\t\t" +REM Finalize VSCode workspace. +replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\r\n" REM In case it's using LF line endings! -replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\n\t\t" +replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\n" +REM ... It's a line-by-line search, so the extra tabs need extra cleanup. +replace_text.exe vscode.code-workspace.default --c-style "\t\t\t\t" "\t\t" +REM So it turns out workspaces can't reference environment variables. +REM Good thing we're already using FART, I guess... +replace_text.exe vscode.code-workspace.default "$XCOM2SDKPATH$" "%XCOM2SDKPATH%" +replace_text.exe vscode.code-workspace.default --c-style "\\" "/" REM Move VSCode workspace and the helper scripts where they belong. move vscode.code-workspace.default ../$ModSafeName$.code-workspace diff --git a/SETUP_ADVANCED.bat b/SETUP_ADVANCED.bat index a3126ca..1216549 100644 --- a/SETUP_ADVANCED.bat +++ b/SETUP_ADVANCED.bat @@ -18,6 +18,74 @@ SET cookingMode= SET customSrc= SET skipCustomSrc= +REM ****************** +REM *** SDK SCREEN *** +REM ****************** + +REM We may need to set up the SDK and game locations +REM for the build automation to work. +IF NOT EXIST "!XCOM2SDKPATH!\Development\SrcOrig" ( + echo WARNING: Could not detect XCOM 2 WotC SDK^^! + echo A valid SDK path is required to run the build automation scripts, + echo and to correctly configure the VSCode workspace for IntelliSense. + echo It is highly recommended that you set the XCOM2SDKPATH environment variable + echo to a valid location before proceeding. This setup can set it for you, if you wish. + echo. + + :offerSdkSetup + SET setupSdk= + SET sdkPath= + SET /p "setupSdk=Do you wish to set up XCOM2SDKPATH? (Y/N) " + IF "!setupSdk!" == "Y" ( + :sdkSetup + SET /p "sdkPath=Please specify the path to the XCOM 2 WotC SDK folder (typically '^\steamapps\common\XCOM 2 War of the Chosen SDK'): " + + IF NOT EXIST "!XCOM2SDKPATH!\Development\SrcOrig" ( + echo ERROR: Could not detect XCOM 2 WotC SDK^^! Please double-check the path and try again^^! + GOTO sdkSetup + ) + SETX XCOM2SDKPATH "!sdkPath!" + GOTO findGame + ) + IF NOT "!setupSdk!" == "N" ( + echo Sorry, that's not a valid option^^! + echo. + GOTO offerSdkSetup + ) +) + +:findGame +IF NOT EXIST "!XCOM2GAMEPATH!\Binaries\Win64\XCom2.exe" ( + echo WARNING: Could not detect XCOM 2: War of the Chosen^^! + echo A valid WotC path is required to run the build automation scripts. + echo It is highly recommended that you set the XCOM2GAMEPATH environment variable + echo to a valid location before proceeding. This setup can set it for you, if you wish. + echo. + + :offerGameSetup + SET setupGame= + SET gamePath= + SET /p "setupGame=Do you wish to set up XCOM2GAMEPATH? (Y/N) " + IF "!setupGame!" == "Y" ( + :gameSetup + SET /p "gamePath=Please specify the path to the XCOM 2: War of the Chosen folder (typically '^\steamapps\common\XCOM 2\XCom2-WarOfTheChosen'): " + + IF NOT EXIST "!XCOM2GAMEPATH!\Binaries\Win64\XCom2.exe" ( + echo ERROR: Could not detect XCOM 2: War of the Chosen^^! Please double-check the path and try again^^! + GOTO gameSetup + ) + SETX XCOM2GAMEPATH "!gamePath!" + GOTO gitSetup + ) + IF NOT "!setupGame!" == "N" ( + echo Sorry, that's not a valid option^^! + echo. + GOTO offerGameSetup + ) +) + + + REM ****************** REM *** GIT SCREEN *** REM ****************** @@ -290,8 +358,4 @@ IF "!gitMode!" == "UseGit" ( cd $ModSafeName$ ) -REM SETUP expects delayed expansion to be off. -REM I chose not to bother changing that, but -REM the setting will be inherited from the previous script. -SETLOCAL DisableDelayedExpansion SETUP.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! \ No newline at end of file diff --git a/build.bat b/build.bat index 544c1b9..4a15591 100644 --- a/build.bat +++ b/build.bat @@ -1,6 +1,6 @@ @echo off -if "%XCOM2SDKPATH%" == "" ( +IF NOT EXIST "%XCOM2SDKPATH%\Development\SrcOrig" ( echo You need to specify the location of the XCOM 2 WOTC SDK (typically ^\steamapps\common\XCOM 2 War of the Chosen SDK^) in the XCOM2SDKPATH environment variable exit /b 1 ) diff --git a/clean.bat b/clean.bat index 6375d84..5977737 100644 --- a/clean.bat +++ b/clean.bat @@ -1,14 +1,14 @@ @echo off -if "%XCOM2SDKPATH%" == "" ( +IF NOT EXIST "%XCOM2SDKPATH%\Development\SrcOrig" ( echo You need to specify the location of the XCOM 2 WOTC SDK (typically ^\steamapps\common\XCOM 2 War of the Chosen SDK^) in the XCOM2SDKPATH environment variable exit /b 1 ) -if "%XCOM2GAMEPATH%" == "" ( +IF NOT EXIST "!XCOM2GAMEPATH!\Binaries\Win64\XCom2.exe" ( echo You need to specify the location of the XCOM 2 War of the Chosen game directory (typically ^\steamapps\common\XCOM 2\XCom2-WarOfTheChosen^) in the XCOM2GAMEPATH environment variable exit /b 1 ) -rem The trailing backslash after %~dp0 is important, otherwise PowerShell thinks the " is being escaped! +REM The trailing backslash after %~dp0 is important, otherwise PowerShell thinks the " is being escaped! powershell.exe -NonInteractive -ExecutionPolicy Unrestricted -file "%~dp0.scripts\X2ModBuildCommon\clean.ps1" -srcDirectory "%~dp0\" -sdkPath "%XCOM2SDKPATH%" -gamePath "%XCOM2GAMEPATH%" -modName "$ModSafeName$" diff --git a/vscode.code-workspace.default b/vscode.code-workspace.default index 5212e78..b59188d 100644 --- a/vscode.code-workspace.default +++ b/vscode.code-workspace.default @@ -6,7 +6,7 @@ $HIGHLANDER, $DEPENDENCY, { - "path": "${env:XCOM2SDKPATH}/Development/SrcOrig" + "path": "$XCOM2SDKPATH$/Development/SrcOrig" } ], "settings": { From 094ad46c26d1411907904be09f951a94a2f06d8c Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Wed, 10 Dec 2025 11:32:17 +0100 Subject: [PATCH 12/14] Advanced setup is now the default setup, as it ensures the SDK is configured for the build automation and VSCode workspace. --- .scripts/build.ps1 | 2 +- EnhancedModProjectTemplate.vstemplate | 2 +- ProjectTemplate.x2proj | 2 +- README.md | 4 +- ReadMe.txt | 23 +- SETUP.bat | 529 ++++++++++++++++---------- SETUP_ADVANCED.bat | 361 ------------------ SETUP_LEGACY.bat | 218 +++++++++++ 8 files changed, 579 insertions(+), 562 deletions(-) delete mode 100644 SETUP_ADVANCED.bat create mode 100644 SETUP_LEGACY.bat diff --git a/.scripts/build.ps1 b/.scripts/build.ps1 index 24cd732..da3e231 100644 --- a/.scripts/build.ps1 +++ b/.scripts/build.ps1 @@ -48,7 +48,7 @@ $builder = [BuildProject]::new("$ModSafeName$", $srcDirectory, $sdkPath, $gamePa # Uncomment to use additional global Custom Src to build against. # $builder.IncludeSrc("C:\Users\Iridar\Documents\Firaxis ModBuddy\CustomSrc") -# PLACEHOLDER_CUSTOMSRC: Used by SETUP_ADVANCED.bat to configure custom source folders. +# PLACEHOLDER_CUSTOMSRC: Used by SETUP.bat to configure custom source folders. switch ($config) { diff --git a/EnhancedModProjectTemplate.vstemplate b/EnhancedModProjectTemplate.vstemplate index bb1dc47..7fc5e76 100644 --- a/EnhancedModProjectTemplate.vstemplate +++ b/EnhancedModProjectTemplate.vstemplate @@ -26,8 +26,8 @@ .scripts\X2ModBuildCommon\XCOM2.targets .gitignore + SETUP_LEGACY.bat SETUP.bat - SETUP_ADVANCED.bat build.bat clean.bat build_debug.bat diff --git a/ProjectTemplate.x2proj b/ProjectTemplate.x2proj index b71e8c6..5a93f10 100644 --- a/ProjectTemplate.x2proj +++ b/ProjectTemplate.x2proj @@ -31,8 +31,8 @@ - + diff --git a/README.md b/README.md index ec4ca0b..3588cf3 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Follow these instructions if you have already installed and used EMPT. ModBuddy **Note:** when creating mod projects using this project template, it is **extremely important** that Project Name, Solution name, and Title match **exactly**. Otherwise, there will be issues during first-time setup, and the mod project will be broken. -2) Perform once-per-project setup by running the "SETUP.bat" batch file inside the created mod project directory. The file will automatically delete itself afterwards. If you wish to build against the Community Highlander; validate the project with Xymanek's X2ProjectGenerator; enable cooking; or build against another mod, you can use "SETUP_ADVANCED.bat", instead. It will help you configure any of these features. +2) Perform once-per-project setup by running the `SETUP.bat` batch file inside the created mod project directory. The file will automatically delete itself afterwards. If you wish to skip the guided setup and only use the pre-1.5 setup, you can run `SETUP_LEGACY.bat` instead. 3) Enjoy. If your mod project doesn't require some of the files and folders created by EMPT, feel free to delete them. @@ -48,7 +48,7 @@ The localization files shipped with the mod project use UTF-8 encoding, so chang ### Cooking -To enable cooking with X2MBC (if you have not already used `SETUP_ADVANCED.bat` to do so), open the `.scripts\build.ps1` file and uncomment the `$builder.SetContentOptionsJsonFilename("ContentOptions.json")` line by removing the `#` at the start. +To enable cooking with X2MBC (if you have not already used `SETUP.bat` to do so), open the `.scripts\build.ps1` file and uncomment the `$builder.SetContentOptionsJsonFilename("ContentOptions.json")` line by removing the `#` at the start. You can find some basic instructions for [cooking here](https://www.reddit.com/r/xcom2mods/wiki/index/cooking_for_dummies). diff --git a/ReadMe.txt b/ReadMe.txt index dfd9df9..db940d0 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -2,9 +2,9 @@ You must perform once-per-mod setup before you can begin working on your mod. -To do so, run either "SETUP.bat" or "SETUP_ADVANCED.bat" in the mod project folder. "SETUP_ADVANCED.bat" has the added advantage of guiding you through a few common configuration steps, but these may not be relevant to your mod. +To do so, run either "SETUP.bat" or "SETUP_LEGACY.bat" in the mod project folder. "SETUP.bat" has the advantage of guiding you through a few common configuration steps, but these may not be relevant to your mod. -If you did not close Modbuddy, you will get a popup message about files being modified outside the source editor. Click "Yes to All". +If you did not close ModBuddy, you will get a popup message about files being modified outside the source editor. Click "Yes to All". That is all. @@ -13,12 +13,29 @@ IMPORTANT!!! When you create the mod project, project Name, Solution name and Title must match *exactly*. Otherwise the first time setup will fail. -Enhanced Mod Project Template v1.4 +Enhanced Mod Project Template v1.5 Get news and updates here: https://github.com/Iridar/EnhancedModProjectTemplate +v1.5 + +Simplified X2PG setup to a Boolean flag in X2MBC. (Doesn't do anything if X2PG is unavailable, though.) +Added new guided setup script, which guides the user through: + - Finding the SDK and game folders + - Setting up a Git repository (does nothing if Git is unavailable) + - Enabling building against the Highlander, from any of the following: + - GitHub + - Project-specific path to a local copy of the Highlander + - Environment variable pointing to a local copy of the Highlander + - Toggling the X2PG flag in X2MBC + - Enabling cooking + - Enabling building against any number of extra dependencies +Deprecated old setup script. The new setup uses it under the hood, but you probably don't want to use it directly anymore. +Added VSCode workspace, which is automatically set up to include the SDK and any dependencies for IntelliSense. +Added build automation scripts, shamelessly stolen and tweaked from Long War of the Chosen. + v1.4 Filled X2DLCInfo and XComGame.int with examples. diff --git a/SETUP.bat b/SETUP.bat index d444c18..e344c12 100644 --- a/SETUP.bat +++ b/SETUP.bat @@ -1,218 +1,361 @@ @echo off -REM SETUP_ADVANCED uses delayed expansion while SETUP -REM expects it to be disabled. I chose not to bother changing that, but -REM need to clean up after the previous script. -SETLOCAL DisableDelayedExpansion - -REM *********************** -REM *** SOLUTION CONFIG *** -REM *********************** - -REM vstemplate cannot create files near solution file, only inside the project folder. -REM And X2ModBuildCommon files need to be in the solution folder. -REM The only solution is to create X2MBC files inside project folder, and then use this batch file to move them to the solution folder. - -move ".gitignore" "..\.gitignore" -move ".scripts" "..\.scripts" - -REM vstemplate cannot create empty folders, so we do it here. - -mkdir "Content" -mkdir "ContentForCook" - -REM Use the shipped text editor. -REM vstemplate requires the XCOM2.targets to be present and readable, and the XCOM2.targets is located in the X2MBC folder we have moved, -REM so we adjust the .x2proj file to point to the new location of the .targets file. - -replace_text.exe $ModSafeName$.x2proj "$(MSBuildProjectDirectory)\" "$(MSBuildProjectDirectory)\..\" - -REM All files created by vstemplate need to be referenced in .x2proj file during project creation, -REM but X2MBC and some of the others don't need to be there, so clean them out. - -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\XCOM2.targets" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\README.md" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\LICENSE" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\InvokePowershellTask.cs" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\EmptyUMap" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\clean_cooker_output.ps1" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\clean.ps1" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\CHANGELOG.md" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\build_common.ps1" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\build.ps1" -replace_text.exe $ModSafeName$.x2proj --remove --c-style ".gitignore" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "SETUP_ADVANCED.bat" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "SETUP.bat" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "build.bat" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_debug.bat" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_default.bat" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "clean.bat" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "replace_text.exe" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "vscode.code-workspace.default" - -REM " and \ are tough to handle, so it needs to be done in two steps. - -replace_text.exe $ModSafeName$.x2proj --remove --c-style .scripts\\X2ModBuildCommon\\ -replace_text.exe $ModSafeName$.x2proj --remove --c-style .scripts\\ - -replace_text.exe $ModSafeName$.x2proj --remove --c-style "" -replace_text.exe $ModSafeName$.x2proj --remove --c-style "" - -REM Bandaid fix for path to XCOM2.targets file we ruined by one of the commands above. - -replace_text.exe $ModSafeName$.x2proj "$(SolutionRoot)" $(SolutionRoot).scripts\\ - -REM ************************ -REM *** HIGHLANDER SETUP *** -REM ************************ - -REM Option 1: From Git -IF "%1" == "FromGit" ( - REM Go outside to grab the Highlander (we're presuming the repo already exists). - cd .. - git submodule add https://github.com/X2CommunityCore/X2WOTCCommunityHighlander.git - REM Now go back here for more convenient access to FART, - REM and reconfigure X2MBC to use our Git Highlander. - cd $ModSafeName$ - replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc("\""$srcDirectory" "$builder.IncludeSrc"("\""$srcDirectory" +REM ********************** +REM *** WELCOME SCREEN *** +REM ********************** - REM Also configure the VSCode workspace! - replace_text.exe --c-style vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"../X2WOTCCommunityHighlander/X2WOTCCommunityHighlander/Src\"}" - GOTO highlanderFinished +echo Welcome to the EMPT Advanced Setup! Let's just run through a few settings... +echo You may close this setup at any time before completion if you change your mind +echo about any of your chosen settings. +echo. +SETLOCAL EnableDelayedExpansion + +REM Set initial values so we can reliably navigate back from the commit screen. +SET gitMode= +SET highlanderMode= +SET x2PGMode= +SET cookingMode= +SET customSrc= +SET skipCustomSrc= + +REM ****************** +REM *** SDK SCREEN *** +REM ****************** + +REM We may need to set up the SDK and game locations +REM for the build automation to work. +IF NOT EXIST "!XCOM2SDKPATH!\Development\SrcOrig" ( + echo WARNING: Could not detect XCOM 2 WotC SDK^^! + echo A valid SDK path is required to run the build automation scripts, + echo and to correctly configure the VSCode workspace for IntelliSense. + echo It is highly recommended that you set the XCOM2SDKPATH environment variable + echo to a valid location before proceeding. This setup can set it for you, if you wish. + echo. + + :offerSdkSetup + SET setupSdk= + SET sdkPath= + SET /p "setupSdk=Do you wish to set up XCOM2SDKPATH? (Y/N) " + IF "!setupSdk!" == "Y" ( + :sdkSetup + SET /p "sdkPath=Please specify the path to the XCOM 2 WotC SDK folder (typically '^\steamapps\common\XCOM 2 War of the Chosen SDK'): " + + IF NOT EXIST "!XCOM2SDKPATH!\Development\SrcOrig" ( + echo ERROR: Could not detect XCOM 2 WotC SDK^^! Please double-check the path and try again^^! + GOTO sdkSetup + ) + SETX XCOM2SDKPATH "!sdkPath!" + GOTO findGame + ) + IF NOT "!setupSdk!" == "N" ( + echo Sorry, that's not a valid option^^! + echo. + GOTO offerSdkSetup + ) ) -REM Option 2: From local Highlander folder -IF "%1" == "FromPath" ( - REM We'll take an extra argument for the path here, so let's shift all the indices up to keep it consistent. - SHIFT +:findGame +IF NOT EXIST "!XCOM2GAMEPATH!\Binaries\Win64\XCom2.exe" ( + echo WARNING: Could not detect XCOM 2: War of the Chosen^^! + echo A valid WotC path is required to run the build automation scripts. + echo It is highly recommended that you set the XCOM2GAMEPATH environment variable + echo to a valid location before proceeding. This setup can set it for you, if you wish. + echo. + + :offerGameSetup + SET setupGame= + SET gamePath= + SET /p "setupGame=Do you wish to set up XCOM2GAMEPATH? (Y/N) " + IF "!setupGame!" == "Y" ( + :gameSetup + SET /p "gamePath=Please specify the path to the XCOM 2: War of the Chosen folder (typically '^\steamapps\common\XCOM 2\XCom2-WarOfTheChosen'): " + + IF NOT EXIST "!XCOM2GAMEPATH!\Binaries\Win64\XCom2.exe" ( + echo ERROR: Could not detect XCOM 2: War of the Chosen^^! Please double-check the path and try again^^! + GOTO gameSetup + ) + SETX XCOM2GAMEPATH "!gamePath!" + GOTO gitSetup + ) + IF NOT "!setupGame!" == "N" ( + echo Sorry, that's not a valid option^^! + echo. + GOTO offerGameSetup + ) +) - REM Running FART in C-style mode screws with inserting file paths, - REM and I don't want to escape an arbitrary string inside a batch script. - REM Frankly, I'm tempted to try rewriting the whole thing in PowerShell - REM to avoid all this fiddling with FART and batch scripts... - replace_text.exe ..\.scripts\build.ps1 "# $builder.IncludeSrc(\"""C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src" "$builder.IncludeSrc"(\""%1" - REM Also configure the VSCode workspace! - replace_text.exe vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"%1\"}" - GOTO highlanderFinished + +REM ****************** +REM *** GIT SCREEN *** +REM ****************** + +:gitSetup +echo Do you want to use Git for version control? (You need to have installed it before, or this won't do anything...) +echo 1. Yes, I want to use Git. +echo 2. No, I don't want to use Git right now. +SET /p "gitMode=Please enter the number corresponding to your preferred option: " + +IF "!gitMode!" == "1" ( + SET gitMode=UseGit + GOTO gitFinished +) +IF "!gitMode!" == "2" ( + SET gitMode=NoGit + GOTO gitFinished ) +echo Sorry, that's not a valid option^^! +echo. +SET gitMode= +GOTO gitSetup + +:gitFinished +echo. +echo Git mode has been set to "!gitMode!"^^! (1/5) +echo Moving on to the meaty bits... +echo. -REM Option 3: From local Highlander folder, via the X2EMPT_HIGHLANDER_FOLDER environment variable. -IF "%1" == "FromEnvVar" ( - replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc($env" "$builder.IncludeSrc($env" - replace_text.exe --c-style vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"%X2EMPT_HIGHLANDER_FOLDER%\"}" +REM ************************* +REM *** HIGHLANDER SCREEN *** +REM ************************* + +:highlanderSetup +echo How do you want to build against the Community Highlander? +echo 1. Get the Highlander from GitHub. (This will forcibly enable Git mode^^!) +echo 2. Use a local copy of the Highlander from a project-specific path... +echo 3. Use a local copy of the Highlander from a global path... +echo 4. I don't want to build against the Highlander right now. +SET /p "highlanderMode=Please enter the number corresponding to your preferred option: " + +IF "!highlanderMode!" == "1" ( + SET gitMode=UseGit + SET highlanderMode=FromGit + GOTO highlanderFinished +) +IF "!highlanderMode!" == "2" ( + :highlanderPathSetup + SET highlanderPath= + SET /p "highlanderPath=Now, please specify the path to the Highlander's Src folder (e.g. C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src): " + IF NOT EXIST "!highlanderPath!\X2WOTCCommunityHighlander\Classes" ( + echo ERROR: Could not detect Highlander source code^^! Please double-check the path and try again^^! + GOTO highlanderPathSetup + ) + SET highlanderMode=FromPath "!highlanderPath!" + GOTO highlanderFinished +) +IF "!highlanderMode!" == "3" ( + IF NOT EXIST "!X2EMPT_HIGHLANDER_FOLDER!\X2WOTCCommunityHighlander\Classes" ( + echo WARNING: Could not detect Highlander source code^^! + echo It is highly recommended that you set the X2EMPT_HIGHLANDER_FOLDER environment variable + echo to a valid location before proceeding. This setup can set it for you, if you wish. + echo. + + :offerEnvSetup + SET setupEnv= + SET highlanderPath= + SET /p "setupEnv=Do you wish to set up X2EMPT_HIGHLANDER_FOLDER? (Y/N) " + IF "!setupEnv!" == "Y" ( + :highlanderEnvSetup + SET /p "highlanderPath=Please specify the path to the Highlander's Src folder (e.g. C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src): " + + IF NOT EXIST "!highlanderPath!\X2WOTCCommunityHighlander\Classes" ( + echo ERROR: Could not detect Highlander source code^^! Please double-check the path and try again^^! + GOTO highlanderEnvSetup + ) + SETX X2EMPT_HIGHLANDER_FOLDER "!highlanderPath!" + GOTO highlanderEnvFinished + ) + IF NOT "!setupEnv!" == "N" ( + echo Sorry, that's not a valid option^^! + echo. + GOTO offerEnvSetup + ) + ) + + :highlanderEnvFinished + SET highlanderMode=FromEnvVar + GOTO highlanderFinished +) +IF "!highlanderMode!" == "4" ( + SET highlanderMode=NoHighlander GOTO highlanderFinished ) -REM Option 4 is just skipping the Highlander outright, so we only need to clean up the VSCode workspace. -REM SETUP_ADVANCED.bat will pass "NoHighlander" because we're working with -REM positional arguments and need *something*, but we don't actually care what we get here. -replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\r\n" -REM In case it's using LF line endings! -replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\n" +echo Sorry, that's not a valid option^^! +echo. +SET highlanderMode= +GOTO highlanderSetup + :highlanderFinished +echo. +echo Highlander mode has been set to "!highlanderMode!"^^! (2/5) +echo Moving on... +echo. -REM ******************************** -REM *** X2ProjectGenerator SETUP *** -REM ******************************** +REM ********************************* +REM *** X2ProjectGenerator SCREEN *** +REM ********************************* -REM Option 1: Use X2ProjectGenerator -IF "%2" == "UseX2PG" ( - replace_text.exe --c-style ..\.scripts\build.ps1 "$useX2PG = $false" "$useX2PG = $true" +:x2PGSetup +IF NOT "!x2PGMode!" == "" GOTO cookingSetup +echo Do you want to use Xymanek's X2ProjectGenerator +echo to automatically verify your project before compiling? +echo. +echo Note that even if enabled, X2PG will not do anything until you add +echo X2ProjectGenerator.exe to your PATH. +echo 1. Yes, please enable automatic verification. +echo 2. No, I don't want to enable automatic verification right now. +SET /p "x2PGMode=Please enter the number corresponding to your preferred option: " + +IF "!x2PGMode!" == "1" ( + SET x2PGMode=UseX2PG + GOTO x2PGFinished +) +IF "!x2PGMode!" == "2" ( + SET x2PGMode=NoX2PG + GOTO x2PGFinished ) +echo Sorry, that's not a valid option^^! +echo. +SET x2PGMode= +GOTO x2PGSetup -REM Option 2 is just skipping X2PG outright, so no scripting needed. -REM As above, SETUP_ADVANCED.bat will pass "NoX2PG", but we don't actually care what we get. +:x2PGFinished +echo. +echo X2PG mode has been set to "!x2PGMode!"^^! (2/4) +echo Next up... +echo. + +REM ********************** +REM *** COOKING SCREEN *** +REM ********************** + +:cookingSetup +IF NOT "!cookingMode!" == "" GOTO customSrcSetup +echo Do you want to enable cooking? If you're not 100%% sure when you need to do this, +echo that's alright: The author of this setup isn't sure yet, either. :^( +echo 1. Yes, please enable cooking. +echo 2. No, I don't think this project benefits from cooking. +SET /p "cookingMode=Please enter the number corresponding to your preferred option: " + +IF "!cookingMode!" == "1" ( + SET cookingMode=EnableCooking + GOTO cookingFinished +) +IF "!cookingMode!" == "2" ( + SET cookingMode=NoCooking + GOTO cookingFinished +) +echo Sorry, that's not a valid option^^! +echo. +SET cookingMode= +GOTO cookingSetup + +:cookingFinished +echo. +echo Cooking mode has been set to "!cookingMode!"^^! (4/5) +echo Almost there... +echo. + +REM ************************* +REM *** CUSTOM SRC SCREEN *** +REM ************************* + +:customSrcSetup +REM Since this one keeps iteratively adding to customSrc, we need a separate flag +REM to tell us we came here from the commit screen. +IF !skipCustomSrc! == TRUE GOTO commitScreen +SET moreSrc= +SET /p "moreSrc=Are there any other mods you want to build against? (Y/N) " +IF "!moreSrc!" == "Y" ( + echo Okay^^! We can do this folder-by-folder, or as a space-delimited list of folders. + echo Remember to target the mods' Src folders^^! This setup isn't smart enough + echo to do it for you. + SET /p "moreSrc=Please specify the path(s) to the mod(s) you wish to build against: " + IF NOT "!customSrc!" == "" SET customSrc=!customSrc! !moreSrc! + IF "!customSrc!" == "" SET customSrc=!moreSrc! + echo. + echo Dependency registered^^! Current dependencies: !customSrc! + echo. + GOTO customSrcSetup +) +IF NOT "!moreSrc!" == "N" ( + echo Sorry, that's not a valid option^^! + echo. + GOTO customSrcSetup +) + +SET skipCustomSrc=TRUE +echo. +echo Finished registering dependencies^^! (5/5) +echo Setup is ready to do its thing^^! +echo. REM ********************* -REM *** COOKING SETUP *** +REM *** COMMIT SCREEN *** REM ********************* -REM Option 1: Enable cooking -IF "%3" == "EnableCooking" ( - replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.SetContent" "$builder.SetContent" +:commitScreen +SET commit= +echo Here's the final config, for verification: +echo 1. Is using Git: !gitMode! +echo 2. Highlander source: !highlanderMode! +echo 3. Automatic validation: !x2PGMode! +echo 4. Is using cooking: !cookingMode! +echo 5. Dependency paths: !customSrc! +echo. +SET /p "commit=Does that look okay? Enter a number 1-5 to return to its corresponding step, or 6 to finish setup: " + +IF "!commit!" == "1" ( + IF "!highlanderMode!" == "FromGit" ( + echo Sorry, can't disable Git if you're using it to build against the Highlander^^! + echo. + GOTO commitScreen + ) + echo Returning to Git config now^^! + echo. + SET gitMode= + GOTO gitSetup ) +IF "!commit!" == "2" ( + echo Okay, returning to Highlander config^^! + echo. + SET highlanderMode= + GOTO highlanderSetup +) +IF "!commit!" == "3" ( + echo Got it, returning to X2PG config^^! + echo. + SET x2PGMode= + GOTO x2PGSetup +) +IF "!commit!" == "4" ( + echo Going back to cooking config now^^! + echo. + SET cookingMode= + GOTO cookingSetup +) +IF "!commit!" == "5" ( + echo Ouch. Going back to dependency config... hopefully not for long... + echo. + SET skipCustomSrc= + SET customSrc= + GOTO customSrcSetup +) +IF "!commit!" == "6" ( + GOTO runSetup +) +echo Sorry, that's not a valid option^^! +echo. +GOTO commitScreen -REM Option 2 is just keeping cooking off, so no scripting needed. -REM As above, SETUP_ADVANCED.bat will pass "NoCooking", but we don't really care. - -REM ************************ -REM *** CUSTOM SRC SETUP *** -REM ************************ - -IF NOT "%4" == "" ( - :insertCustomSrc - REM As mentioned above, C-style screws with inserting file paths, - REM and I don't want to escape an arbitrary string inside a batch script. - REM So we'll run in regular mode, printing \\n to represent a linebreak, - REM then do a C-style postprocessing pass to turn it into a real linebreak. - REM - REM We're using \\n instead of \n because \n could legitimately occur - REM in the filesystem, but \\n should be illegal. I think. - replace_text.exe ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC" "$builder.IncludeSrc(\""%%path\"")\\n# PLACEHOLDER_CUSTOMSRC" - replace_text.exe --c-style ..\.scripts\build.ps1 \\\\n \n - - replace_text.exe vscode.code-workspace.default "$DEPENDENCY" "{\""path\"": \"%1\"},\\n$DEPENDENCY" - replace_text.exe --c-style vscode.code-workspace.default \\\\n$DEPENDENCY \n\t\t$DEPENDENCY - - REM We want to loop through all remaining arguments until we run out of paths. - SHIFT - IF NOT "%4" == "" GOTO insertCustomSrc +:runSetup +echo Beginning project setup^^! Do not close this window... +echo. +IF "!gitMode!" == "UseGit" ( + cd .. + git init + cd $ModSafeName$ ) -REM *************** -REM *** CLEANUP *** -REM *************** - -echo X2ModBuildCommon v1.2.1 successfully installed. > ReadMe.txt -echo. -echo Edit .scripts\build.ps1 if you want to enable/disable cooking or building against Highlander. >> ReadMe.txt -echo. >> ReadMe.txt -echo Enjoy making your mod, and may the odds be ever in your favor. >> ReadMe.txt -echo. >> ReadMe.txt -echo. >> ReadMe.txt -echo Created with Enhanced Mod Project Template v1.4 >> ReadMe.txt -echo. >> ReadMe.txt -echo Get news and updates here: >> ReadMe.txt -echo https://github.com/Iridar/EnhancedModProjectTemplate >> ReadMe.txt - -REM Clean up PLACEHOLDER_CUSTOMSRC. -replace_text.exe --remove --c-style ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC: Placeholder used by EMPT setup to automatically add custom source folders.\n" - -REM Finalize VSCode workspace. -replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\r\n" -REM In case it's using LF line endings! -replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\n" -REM ... It's a line-by-line search, so the extra tabs need extra cleanup. -replace_text.exe vscode.code-workspace.default --c-style "\t\t\t\t" "\t\t" -REM So it turns out workspaces can't reference environment variables. -REM Good thing we're already using FART, I guess... -replace_text.exe vscode.code-workspace.default "$XCOM2SDKPATH$" "%XCOM2SDKPATH%" -replace_text.exe vscode.code-workspace.default --c-style "\\" "/" - -REM Move VSCode workspace and the helper scripts where they belong. -move vscode.code-workspace.default ../$ModSafeName$.code-workspace -move build_default.bat ../build_default.bat -move build_debug.bat ../build_debug.bat -move build.bat ../build.bat -move clean.bat ../clean.bat - -REM Delete text editor. -del replace_text.exe - -REM Delete advanced setup file. -del SETUP_ADVANCED.bat - -REM If we're using Git, now is a good time to make an initial commit! -cd .. -git add **/* :!$ModSafeName$\SETUP.bat -git commit -m "EMPT w/ Git: Initial commit" -cd $ModSafeName$ - -REM Delete this batch file. -REM This is a bit fancier than Iridar's original, -REM because: -REM - My use of SHIFT means %0 is no longer the path to the current script. -REM - The original threw an error and I didn't like that. -REM Source/explanation: https://stackoverflow.com/a/20333152 -(GOTO) 2>NUL & del SETUP.bat && echo Setup complete! && pause \ No newline at end of file +SETUP_LEGACY.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! \ No newline at end of file diff --git a/SETUP_ADVANCED.bat b/SETUP_ADVANCED.bat deleted file mode 100644 index 1216549..0000000 --- a/SETUP_ADVANCED.bat +++ /dev/null @@ -1,361 +0,0 @@ -@echo off - -REM ********************** -REM *** WELCOME SCREEN *** -REM ********************** - -echo Welcome to the EMPT Advanced Setup! Let's just run through a few settings... -echo You may close this setup at any time before completion if you change your mind -echo about any of your chosen settings. -echo. -SETLOCAL EnableDelayedExpansion - -REM Set initial values so we can reliably navigate back from the commit screen. -SET gitMode= -SET highlanderMode= -SET x2PGMode= -SET cookingMode= -SET customSrc= -SET skipCustomSrc= - -REM ****************** -REM *** SDK SCREEN *** -REM ****************** - -REM We may need to set up the SDK and game locations -REM for the build automation to work. -IF NOT EXIST "!XCOM2SDKPATH!\Development\SrcOrig" ( - echo WARNING: Could not detect XCOM 2 WotC SDK^^! - echo A valid SDK path is required to run the build automation scripts, - echo and to correctly configure the VSCode workspace for IntelliSense. - echo It is highly recommended that you set the XCOM2SDKPATH environment variable - echo to a valid location before proceeding. This setup can set it for you, if you wish. - echo. - - :offerSdkSetup - SET setupSdk= - SET sdkPath= - SET /p "setupSdk=Do you wish to set up XCOM2SDKPATH? (Y/N) " - IF "!setupSdk!" == "Y" ( - :sdkSetup - SET /p "sdkPath=Please specify the path to the XCOM 2 WotC SDK folder (typically '^\steamapps\common\XCOM 2 War of the Chosen SDK'): " - - IF NOT EXIST "!XCOM2SDKPATH!\Development\SrcOrig" ( - echo ERROR: Could not detect XCOM 2 WotC SDK^^! Please double-check the path and try again^^! - GOTO sdkSetup - ) - SETX XCOM2SDKPATH "!sdkPath!" - GOTO findGame - ) - IF NOT "!setupSdk!" == "N" ( - echo Sorry, that's not a valid option^^! - echo. - GOTO offerSdkSetup - ) -) - -:findGame -IF NOT EXIST "!XCOM2GAMEPATH!\Binaries\Win64\XCom2.exe" ( - echo WARNING: Could not detect XCOM 2: War of the Chosen^^! - echo A valid WotC path is required to run the build automation scripts. - echo It is highly recommended that you set the XCOM2GAMEPATH environment variable - echo to a valid location before proceeding. This setup can set it for you, if you wish. - echo. - - :offerGameSetup - SET setupGame= - SET gamePath= - SET /p "setupGame=Do you wish to set up XCOM2GAMEPATH? (Y/N) " - IF "!setupGame!" == "Y" ( - :gameSetup - SET /p "gamePath=Please specify the path to the XCOM 2: War of the Chosen folder (typically '^\steamapps\common\XCOM 2\XCom2-WarOfTheChosen'): " - - IF NOT EXIST "!XCOM2GAMEPATH!\Binaries\Win64\XCom2.exe" ( - echo ERROR: Could not detect XCOM 2: War of the Chosen^^! Please double-check the path and try again^^! - GOTO gameSetup - ) - SETX XCOM2GAMEPATH "!gamePath!" - GOTO gitSetup - ) - IF NOT "!setupGame!" == "N" ( - echo Sorry, that's not a valid option^^! - echo. - GOTO offerGameSetup - ) -) - - - -REM ****************** -REM *** GIT SCREEN *** -REM ****************** - -:gitSetup -echo Do you want to use Git for version control? (You need to have installed it before, or this won't do anything...) -echo 1. Yes, I want to use Git. -echo 2. No, I don't want to use Git right now. -SET /p "gitMode=Please enter the number corresponding to your preferred option: " - -IF "!gitMode!" == "1" ( - SET gitMode=UseGit - GOTO gitFinished -) -IF "!gitMode!" == "2" ( - SET gitMode=NoGit - GOTO gitFinished -) -echo Sorry, that's not a valid option^^! -echo. -SET gitMode= -GOTO gitSetup - -:gitFinished -echo. -echo Git mode has been set to "!gitMode!"^^! (1/5) -echo Moving on to the meaty bits... -echo. - -REM ************************* -REM *** HIGHLANDER SCREEN *** -REM ************************* - -:highlanderSetup -echo How do you want to build against the Community Highlander? -echo 1. Get the Highlander from GitHub. (This will forcibly enable Git mode^^!) -echo 2. Use a local copy of the Highlander from a project-specific path... -echo 3. Use a local copy of the Highlander from a global path... -echo 4. I don't want to build against the Highlander right now. -SET /p "highlanderMode=Please enter the number corresponding to your preferred option: " - -IF "!highlanderMode!" == "1" ( - SET gitMode=UseGit - SET highlanderMode=FromGit - GOTO highlanderFinished -) -IF "!highlanderMode!" == "2" ( - :highlanderPathSetup - SET highlanderPath= - SET /p "highlanderPath=Now, please specify the path to the Highlander's Src folder (e.g. C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src): " - IF NOT EXIST "!highlanderPath!\X2WOTCCommunityHighlander\Classes" ( - echo ERROR: Could not detect Highlander source code^^! Please double-check the path and try again^^! - GOTO highlanderPathSetup - ) - SET highlanderMode=FromPath "!highlanderPath!" - GOTO highlanderFinished -) -IF "!highlanderMode!" == "3" ( - IF NOT EXIST "!X2EMPT_HIGHLANDER_FOLDER!\X2WOTCCommunityHighlander\Classes" ( - echo WARNING: Could not detect Highlander source code^^! - echo It is highly recommended that you set the X2EMPT_HIGHLANDER_FOLDER environment variable - echo to a valid location before proceeding. This setup can set it for you, if you wish. - echo. - - :offerEnvSetup - SET setupEnv= - SET highlanderPath= - SET /p "setupEnv=Do you wish to set up X2EMPT_HIGHLANDER_FOLDER? (Y/N) " - IF "!setupEnv!" == "Y" ( - :highlanderEnvSetup - SET /p "highlanderPath=Please specify the path to the Highlander's Src folder (e.g. C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src): " - - IF NOT EXIST "!highlanderPath!\X2WOTCCommunityHighlander\Classes" ( - echo ERROR: Could not detect Highlander source code^^! Please double-check the path and try again^^! - GOTO highlanderEnvSetup - ) - SETX X2EMPT_HIGHLANDER_FOLDER "!highlanderPath!" - GOTO highlanderEnvFinished - ) - IF NOT "!setupEnv!" == "N" ( - echo Sorry, that's not a valid option^^! - echo. - GOTO offerEnvSetup - ) - ) - - :highlanderEnvFinished - SET highlanderMode=FromEnvVar - GOTO highlanderFinished -) -IF "!highlanderMode!" == "4" ( - SET highlanderMode=NoHighlander - GOTO highlanderFinished -) - -echo Sorry, that's not a valid option^^! -echo. -SET highlanderMode= -GOTO highlanderSetup - -:highlanderFinished -echo. -echo Highlander mode has been set to "!highlanderMode!"^^! (2/5) -echo Moving on... -echo. - -REM ********************************* -REM *** X2ProjectGenerator SCREEN *** -REM ********************************* - -:x2PGSetup -IF NOT "!x2PGMode!" == "" GOTO cookingSetup -echo Do you want to use Xymanek's X2ProjectGenerator -echo to automatically verify your project before compiling? -echo. -echo Note that even if enabled, X2PG will not do anything until you add -echo X2ProjectGenerator.exe to your PATH. -echo 1. Yes, please enable automatic verification. -echo 2. No, I don't want to enable automatic verification right now. -SET /p "x2PGMode=Please enter the number corresponding to your preferred option: " - -IF "!x2PGMode!" == "1" ( - SET x2PGMode=UseX2PG - GOTO x2PGFinished -) -IF "!x2PGMode!" == "2" ( - SET x2PGMode=NoX2PG - GOTO x2PGFinished -) -echo Sorry, that's not a valid option^^! -echo. -SET x2PGMode= -GOTO x2PGSetup - -:x2PGFinished -echo. -echo X2PG mode has been set to "!x2PGMode!"^^! (2/4) -echo Next up... -echo. - -REM ********************** -REM *** COOKING SCREEN *** -REM ********************** - -:cookingSetup -IF NOT "!cookingMode!" == "" GOTO customSrcSetup -echo Do you want to enable cooking? If you're not 100%% sure when you need to do this, -echo that's alright: The author of this setup isn't sure yet, either. :^( -echo 1. Yes, please enable cooking. -echo 2. No, I don't think this project benefits from cooking. -SET /p "cookingMode=Please enter the number corresponding to your preferred option: " - -IF "!cookingMode!" == "1" ( - SET cookingMode=EnableCooking - GOTO cookingFinished -) -IF "!cookingMode!" == "2" ( - SET cookingMode=NoCooking - GOTO cookingFinished -) -echo Sorry, that's not a valid option^^! -echo. -SET cookingMode= -GOTO cookingSetup - -:cookingFinished -echo. -echo Cooking mode has been set to "!cookingMode!"^^! (4/5) -echo Almost there... -echo. - -REM ************************* -REM *** CUSTOM SRC SCREEN *** -REM ************************* - -:customSrcSetup -REM Since this one keeps iteratively adding to customSrc, we need a separate flag -REM to tell us we came here from the commit screen. -IF !skipCustomSrc! == TRUE GOTO commitScreen -SET moreSrc= -SET /p "moreSrc=Are there any other mods you want to build against? (Y/N) " -IF "!moreSrc!" == "Y" ( - echo Okay^^! We can do this folder-by-folder, or as a space-delimited list of folders. - echo Remember to target the mods' Src folders^^! This setup isn't smart enough - echo to do it for you. - SET /p "moreSrc=Please specify the path(s) to the mod(s) you wish to build against: " - IF NOT "!customSrc!" == "" SET customSrc=!customSrc! !moreSrc! - IF "!customSrc!" == "" SET customSrc=!moreSrc! - echo. - echo Dependency registered^^! Current dependencies: !customSrc! - echo. - GOTO customSrcSetup -) -IF NOT "!moreSrc!" == "N" ( - echo Sorry, that's not a valid option^^! - echo. - GOTO customSrcSetup -) - -SET skipCustomSrc=TRUE -echo. -echo Finished registering dependencies^^! (5/5) -echo Setup is ready to do its thing^^! -echo. - -REM ********************* -REM *** COMMIT SCREEN *** -REM ********************* - -:commitScreen -SET commit= -echo Here's the final config, for verification: -echo 1. Is using Git: !gitMode! -echo 2. Highlander source: !highlanderMode! -echo 3. Automatic validation: !x2PGMode! -echo 4. Is using cooking: !cookingMode! -echo 5. Dependency paths: !customSrc! -echo. -SET /p "commit=Does that look okay? Enter a number 1-5 to return to its corresponding step, or 6 to finish setup: " - -IF "!commit!" == "1" ( - IF "!highlanderMode!" == "FromGit" ( - echo Sorry, can't disable Git if you're using it to build against the Highlander^^! - echo. - GOTO commitScreen - ) - echo Returning to Git config now^^! - echo. - SET gitMode= - GOTO gitSetup -) -IF "!commit!" == "2" ( - echo Okay, returning to Highlander config^^! - echo. - SET highlanderMode= - GOTO highlanderSetup -) -IF "!commit!" == "3" ( - echo Got it, returning to X2PG config^^! - echo. - SET x2PGMode= - GOTO x2PGSetup -) -IF "!commit!" == "4" ( - echo Going back to cooking config now^^! - echo. - SET cookingMode= - GOTO cookingSetup -) -IF "!commit!" == "5" ( - echo Ouch. Going back to dependency config... hopefully not for long... - echo. - SET skipCustomSrc= - SET customSrc= - GOTO customSrcSetup -) -IF "!commit!" == "6" ( - GOTO runSetup -) -echo Sorry, that's not a valid option^^! -echo. -GOTO commitScreen - -:runSetup -echo Beginning project setup^^! Do not close this window... -echo. -IF "!gitMode!" == "UseGit" ( - cd .. - git init - cd $ModSafeName$ -) - -SETUP.bat !highlanderMode! !x2PGMode! !cookingMode! !customSrc! \ No newline at end of file diff --git a/SETUP_LEGACY.bat b/SETUP_LEGACY.bat new file mode 100644 index 0000000..76ec133 --- /dev/null +++ b/SETUP_LEGACY.bat @@ -0,0 +1,218 @@ +@echo off +REM SETUP_ADVANCED uses delayed expansion while SETUP +REM expects it to be disabled. I chose not to bother changing that, but +REM need to clean up after the previous script. +SETLOCAL DisableDelayedExpansion + +REM *********************** +REM *** SOLUTION CONFIG *** +REM *********************** + +REM vstemplate cannot create files near solution file, only inside the project folder. +REM And X2ModBuildCommon files need to be in the solution folder. +REM The only solution is to create X2MBC files inside project folder, and then use this batch file to move them to the solution folder. + +move ".gitignore" "..\.gitignore" +move ".scripts" "..\.scripts" + +REM vstemplate cannot create empty folders, so we do it here. + +mkdir "Content" +mkdir "ContentForCook" + +REM Use the shipped text editor. +REM vstemplate requires the XCOM2.targets to be present and readable, and the XCOM2.targets is located in the X2MBC folder we have moved, +REM so we adjust the .x2proj file to point to the new location of the .targets file. + +replace_text.exe $ModSafeName$.x2proj "$(MSBuildProjectDirectory)\" "$(MSBuildProjectDirectory)\..\" + +REM All files created by vstemplate need to be referenced in .x2proj file during project creation, +REM but X2MBC and some of the others don't need to be there, so clean them out. + +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\XCOM2.targets" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\README.md" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\LICENSE" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\InvokePowershellTask.cs" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\EmptyUMap" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\clean_cooker_output.ps1" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\clean.ps1" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\CHANGELOG.md" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\X2ModBuildCommon\\build_common.ps1" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".scripts\\build.ps1" +replace_text.exe $ModSafeName$.x2proj --remove --c-style ".gitignore" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "SETUP.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "SETUP_LEGACY.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "build.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_debug.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "build_default.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "clean.bat" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "replace_text.exe" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "vscode.code-workspace.default" + +REM " and \ are tough to handle, so it needs to be done in two steps. + +replace_text.exe $ModSafeName$.x2proj --remove --c-style .scripts\\X2ModBuildCommon\\ +replace_text.exe $ModSafeName$.x2proj --remove --c-style .scripts\\ + +replace_text.exe $ModSafeName$.x2proj --remove --c-style "" +replace_text.exe $ModSafeName$.x2proj --remove --c-style "" + +REM Bandaid fix for path to XCOM2.targets file we ruined by one of the commands above. + +replace_text.exe $ModSafeName$.x2proj "$(SolutionRoot)" $(SolutionRoot).scripts\\ + +REM ************************ +REM *** HIGHLANDER SETUP *** +REM ************************ + +REM Option 1: From Git +IF "%1" == "FromGit" ( + REM Go outside to grab the Highlander (we're presuming the repo already exists). + cd .. + git submodule add https://github.com/X2CommunityCore/X2WOTCCommunityHighlander.git + + REM Now go back here for more convenient access to FART, + REM and reconfigure X2MBC to use our Git Highlander. + cd $ModSafeName$ + replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc("\""$srcDirectory" "$builder.IncludeSrc"("\""$srcDirectory" + + REM Also configure the VSCode workspace! + replace_text.exe --c-style vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"../X2WOTCCommunityHighlander/X2WOTCCommunityHighlander/Src\"}" + GOTO highlanderFinished +) + +REM Option 2: From local Highlander folder +IF "%1" == "FromPath" ( + REM We'll take an extra argument for the path here, so let's shift all the indices up to keep it consistent. + SHIFT + + REM Running FART in C-style mode screws with inserting file paths, + REM and I don't want to escape an arbitrary string inside a batch script. + REM Frankly, I'm tempted to try rewriting the whole thing in PowerShell + REM to avoid all this fiddling with FART and batch scripts... + replace_text.exe ..\.scripts\build.ps1 "# $builder.IncludeSrc(\"""C:\Users\Iridar\Documents\Firaxis ModBuddy\X2WOTCCommunityHighlander\X2WOTCCommunityHighlander\Src" "$builder.IncludeSrc"(\""%1" + + REM Also configure the VSCode workspace! + replace_text.exe vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"%1\"}" + GOTO highlanderFinished +) + +REM Option 3: From local Highlander folder, via the X2EMPT_HIGHLANDER_FOLDER environment variable. +IF "%1" == "FromEnvVar" ( + replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.IncludeSrc($env" "$builder.IncludeSrc($env" + replace_text.exe --c-style vscode.code-workspace.default "$HIGHLANDER" "{\""path\"": \"%X2EMPT_HIGHLANDER_FOLDER%\"}" + GOTO highlanderFinished +) + +REM Option 4 is just skipping the Highlander outright, so we only need to clean up the VSCode workspace. +REM SETUP.bat will pass "NoHighlander" because we're working with +REM positional arguments and need *something*, but we don't actually care what we get here. +replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\r\n" +REM In case it's using LF line endings! +replace_text.exe vscode.code-workspace.default --remove --c-style "$HIGHLANDER,\n" +:highlanderFinished + +REM ******************************** +REM *** X2ProjectGenerator SETUP *** +REM ******************************** + +REM Option 1: Use X2ProjectGenerator +IF "%2" == "UseX2PG" ( + replace_text.exe --c-style ..\.scripts\build.ps1 "$useX2PG = $false" "$useX2PG = $true" +) + +REM Option 2 is just skipping X2PG outright, so no scripting needed. +REM As above, SETUP.bat will pass "NoX2PG", but we don't actually care what we get. + +REM ********************* +REM *** COOKING SETUP *** +REM ********************* + +REM Option 1: Enable cooking +IF "%3" == "EnableCooking" ( + replace_text.exe --c-style ..\.scripts\build.ps1 "# $builder.SetContent" "$builder.SetContent" +) + +REM Option 2 is just keeping cooking off, so no scripting needed. +REM As above, SETUP.bat will pass "NoCooking", but we don't really care. + +REM ************************ +REM *** CUSTOM SRC SETUP *** +REM ************************ + +IF NOT "%4" == "" ( + :insertCustomSrc + REM As mentioned above, C-style screws with inserting file paths, + REM and I don't want to escape an arbitrary string inside a batch script. + REM So we'll run in regular mode, printing \\n to represent a linebreak, + REM then do a C-style postprocessing pass to turn it into a real linebreak. + REM + REM We're using \\n instead of \n because \n could legitimately occur + REM in the filesystem, but \\n should be illegal. I think. + replace_text.exe ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC" "$builder.IncludeSrc(\""%%path\"")\\n# PLACEHOLDER_CUSTOMSRC" + replace_text.exe --c-style ..\.scripts\build.ps1 \\\\n \n + + replace_text.exe vscode.code-workspace.default "$DEPENDENCY" "{\""path\"": \"%1\"},\\n$DEPENDENCY" + replace_text.exe --c-style vscode.code-workspace.default \\\\n$DEPENDENCY \n\t\t$DEPENDENCY + + REM We want to loop through all remaining arguments until we run out of paths. + SHIFT + IF NOT "%4" == "" GOTO insertCustomSrc +) + +REM *************** +REM *** CLEANUP *** +REM *************** + +echo X2ModBuildCommon v1.2.1 successfully installed. > ReadMe.txt +echo. +echo Edit .scripts\build.ps1 if you want to enable/disable cooking or building against Highlander. >> ReadMe.txt +echo. >> ReadMe.txt +echo Enjoy making your mod, and may the odds be ever in your favor. >> ReadMe.txt +echo. >> ReadMe.txt +echo. >> ReadMe.txt +echo Created with Enhanced Mod Project Template v1.4 >> ReadMe.txt +echo. >> ReadMe.txt +echo Get news and updates here: >> ReadMe.txt +echo https://github.com/Iridar/EnhancedModProjectTemplate >> ReadMe.txt + +REM Clean up PLACEHOLDER_CUSTOMSRC. +replace_text.exe --remove --c-style ..\.scripts\build.ps1 "# PLACEHOLDER_CUSTOMSRC: Placeholder used by EMPT setup to automatically add custom source folders.\n" + +REM Finalize VSCode workspace. +replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\r\n" +REM In case it's using LF line endings! +replace_text.exe vscode.code-workspace.default --remove --c-style "$DEPENDENCY,\n" +REM ... It's a line-by-line search, so the extra tabs need extra cleanup. +replace_text.exe vscode.code-workspace.default --c-style "\t\t\t\t" "\t\t" +REM So it turns out workspaces can't reference environment variables. +REM Good thing we're already using FART, I guess... +replace_text.exe vscode.code-workspace.default "$XCOM2SDKPATH$" "%XCOM2SDKPATH%" +replace_text.exe vscode.code-workspace.default --c-style "\\" "/" + +REM Move VSCode workspace and the helper scripts where they belong. +move vscode.code-workspace.default ../$ModSafeName$.code-workspace +move build_default.bat ../build_default.bat +move build_debug.bat ../build_debug.bat +move build.bat ../build.bat +move clean.bat ../clean.bat + +REM Delete text editor. +del replace_text.exe + +REM Delete advanced setup file. +del SETUP.bat + +REM If we're using Git, now is a good time to make an initial commit! +cd .. +git add **/* :!$ModSafeName$\SETUP_LEGACY.bat +git commit -m "EMPT w/ Git: Initial commit" +cd $ModSafeName$ + +REM Delete this batch file. +REM This is a bit fancier than Iridar's original, +REM because: +REM - My use of SHIFT means %0 is no longer the path to the current script. +REM - The original threw an error and I didn't like that. +REM Source/explanation: https://stackoverflow.com/a/20333152 +(GOTO) 2>NUL & del SETUP_LEGACY.bat && echo Setup complete! && pause \ No newline at end of file From 06746a2b43f1838b7ca4a798174f40c151ac045c Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Wed, 10 Dec 2025 11:42:30 +0100 Subject: [PATCH 13/14] Setup will no longer try to set the VSCode workspace to point to a nonexistent SDK. --- SETUP_LEGACY.bat | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SETUP_LEGACY.bat b/SETUP_LEGACY.bat index 76ec133..1581730 100644 --- a/SETUP_LEGACY.bat +++ b/SETUP_LEGACY.bat @@ -187,7 +187,13 @@ REM ... It's a line-by-line search, so the extra tabs need extra cleanup. replace_text.exe vscode.code-workspace.default --c-style "\t\t\t\t" "\t\t" REM So it turns out workspaces can't reference environment variables. REM Good thing we're already using FART, I guess... -replace_text.exe vscode.code-workspace.default "$XCOM2SDKPATH$" "%XCOM2SDKPATH%" +IF EXIST "%XCOM2SDKPATH%\Development\SrcOrig" ( + REM Leave the placeholder as-is if the user's SDK is broken. + REM It'll make it easier for them to fix later. + replace_text.exe vscode.code-workspace.default "$XCOM2SDKPATH$" "%XCOM2SDKPATH%" +) +REM The workspace is in JSON, so backslashes need to be escaped. +REM Forward slashes are a far superior path separator. replace_text.exe vscode.code-workspace.default --c-style "\\" "/" REM Move VSCode workspace and the helper scripts where they belong. From e39b5afcc7be693b02ec292f1daa3e4cdae4d69a Mon Sep 17 00:00:00 2001 From: DaloLorn Date: Wed, 10 Dec 2025 14:16:19 +0100 Subject: [PATCH 14/14] Fixed an issue that caused the setup to hang... --- SETUP_LEGACY.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SETUP_LEGACY.bat b/SETUP_LEGACY.bat index 1581730..487b7a2 100644 --- a/SETUP_LEGACY.bat +++ b/SETUP_LEGACY.bat @@ -194,7 +194,7 @@ IF EXIST "%XCOM2SDKPATH%\Development\SrcOrig" ( ) REM The workspace is in JSON, so backslashes need to be escaped. REM Forward slashes are a far superior path separator. -replace_text.exe vscode.code-workspace.default --c-style "\\" "/" +replace_text.exe vscode.code-workspace.default --c-style \\ / REM Move VSCode workspace and the helper scripts where they belong. move vscode.code-workspace.default ../$ModSafeName$.code-workspace