-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBuildCookRunLauncher.ps1
335 lines (279 loc) · 12.2 KB
/
BuildCookRunLauncher.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<#
This script launches a winforms prompt to locally BuildCookRun a game.
Recommended use case is adding a cmd wrapper script that you can then also let artists/etc launch by double-clicking, e.g.
powershell.exe -ExecutionPolicy RemoteSigned -File .../OpenUnrealAutomationTools/BuildCookRunLauncher.ps1 -ProjectPath .../Foo.uproject
#>
param(
[String]
[Parameter(Mandatory = $true)]
$ProjectPath
)
#--------------
# POWERSHELL SCRIPT CONFIG
#--------------
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# Return all verbose output, so we don't have to specify it on individual calls
# -> all internal commands from OpenUnrealAutomationTools.psm1 can output verbose logs that actually show up in console.
$global:VerbosePreference = 'continue'
# set to a different color than Yellow so it stands out less and warnings are better recognizable
$Host.PrivateData.VerboseForegroundColor = 'Cyan'
$ScriptDirectory = Split-Path $MyInvocation.MyCommand.Path -Parent
Import-Module -Name "$ScriptDirectory/OpenUnrealAutomationTools.psm1" -Verbose -Force
#--------------
# GET CONFIG FROM UE
#--------------
$UProject = Open-UEProject $ProjectPath
$EditorIni = Get-UEConfig Editor
$UECmdPath = Get-UEProgramPath EditorCmd
$MainSectionName = "/Script/OUUDeveloper.OUUMapsToCookSettings"
$MapIniSectionNames = New-Object System.Collections.ArrayList
$MapIniSectionNames.Add("") | Out-Null
$AllMapsToCook = @{}
if (-not $EditorIni.ContainsKey($MainSectionName)) {
Write-Error "Expected a config section called [$MainSectionName] in DefaultEditor.ini to configure which map sections to use for map cook lists."
}
foreach ($MapIniSection in $EditorIni[$MainSectionName]["ConfigSections"]) {
$MapIniSectionNames.Add($MapIniSection) | Out-Null
$AllMapsToCook[$MapIniSection] = $EditorIni[$MapIniSection]["Map"]
}
$InitialMapIniSectionIdx = 0
$MapIniSection = $MapIniSectionNames[$InitialMapIniSectionIdx]
Write-Verbose "Detected ConfigSections: $MapIniSectionNames."
Write-Verbose "Detected DefaultConfigSection: $MapIniSection"
$Configuration = "Development"
$Configurations = @("DebugGame", $Configuration, "Shipping", "Test")
#--------------
# WINFORMS GUI FOR LAUNCHER
#--------------
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$WinForm = New-Object System.Windows.Forms.Form
$WinForm.Backcolor = "lightgray"
$WinForm.Text = "Build Cook Run Launcher"
# Use Unreal Engine icon for our launcher
$WinForm.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($UECmdPath)
$WinForm.Topmost = $True
$ToolTip = New-Object System.Windows.Forms.Tooltip
$ToolTip.AutoPopDelay = 10000;
$ToolTip.InitialDelay = 1;
$ToolTip.ReshowDelay = 1;
$ToolTip.ShowAlways = $true;
$Width = 400
$VerticalPadding = 5
$HorizontalPadding = 10
$AccumulatedHeight = $VerticalPadding
$Font_Regular = New-Object System.Drawing.Font("Arial",8,[System.Drawing.FontStyle]::Regular)
$Font_Bold = New-Object System.Drawing.Font("Arial",8,[System.Drawing.FontStyle]::Bold)
$Font_Header = New-Object System.Drawing.Font("Arial",10,[System.Drawing.FontStyle]::Bold)
#--------------
# Layout helpers
#--------------
function SetTooltip {
param(
$Element,
$TooltipText
)
if (-not ($TooltipText -eq "")) {
$ToolTip.SetToolTip($Element, $TooltipText)
}
}
function AddLabel {
param(
$LabelText,
$IsHeader = $False,
$TooltipText = ""
)
$Label = New-Object System.Windows.Forms.Label
$Label.Location = New-Object System.Drawing.Size($HorizontalPadding, $script:AccumulatedHeight)
$script:AccumulatedHeight += 20
$Label.Size = New-Object System.Drawing.Size($Width, 20)
#$Label.AutoSize = $true
$Label.AutoEllipsis = $true
$Label.Text = $LabelText
$Label.Font = if ($IsHeader) { $Font_Header } else { $Font_Regular }
if ($IsHeader) {
$Label.Backcolor = "#8888dd"
}
$WinForm.Controls.Add($Label) | Out-Null
SetTooltip $Label $TooltipText
return $Label
}
function AddCombobox {
param(
$LabelText,
$Items,
$Index = 0,
$TooltipText = ""
)
AddLabel -LabelText $LabelText -TooltipText $TooltipText | Out-Null
$Combobox = New-Object System.Windows.Forms.Combobox
$Combobox.Location = New-Object System.Drawing.Size($HorizontalPadding, $script:AccumulatedHeight)
$Combobox.Size = New-Object System.Drawing.Size($Width, 20)
$Combobox.Height = 70
$script:AccumulatedHeight += 20 + $VerticalPadding
$Combobox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList;
foreach ($Item in $Items) {
$Combobox.Items.Add($Item) | Out-Null
}
$WinForm.Controls.Add($Combobox)
$Combobox.SelectedIndex = $Index
SetTooltip $Combobox $TooltipText
return $Combobox
}
function AddCheckBox {
param(
$LabelText,
$DefaultCheckedState,
$TooltipText = ""
)
$Checkbox = New-Object System.Windows.Forms.Checkbox
$Checkbox.Location = New-Object System.Drawing.Size($HorizontalPadding, $script:AccumulatedHeight)
$Checkbox.Size = New-Object System.Drawing.Size($Width, 20)
$script:AccumulatedHeight += 20 + $VerticalPadding
$Checkbox.Text = $LabelText
$Checkbox.TabIndex = 4
$Checkbox.Checked = $DefaultCheckedState
$WinForm.Controls.Add($Checkbox) | Out-Null
SetTooltip $Checkbox $TooltipText
return $Checkbox
}
class ParamCheckBox {
[object] $CheckBox = $null
[string] $TrueParam
[string] $FalseParam
ParamCheckBox($LabelText, $DefaultCheckedState, $ToolTipText, $TrueParam, $FalseParam) {
$this.CheckBox = AddCheckbox -LabelText $LabelText -DefaultCheckedState $DefaultCheckedState -ToolTipText $ToolTipText
$this.TrueParam = $TrueParam
$this.FalseParam = $FalseParam
}
[string] Get() {
$Result = if ($this.CheckBox.Checked) { $this.TrueParam } else { $this.FalseParam }
return $Result
}
}
#--------------
# Primary Layout
#--------------
AddLabel -LabelText "Build" -IsHeader $true | Out-Null
$BuildCheckbox = [ParamCheckBox]::new("Build", $True, "Enable the build step. If false, skips the build", "-build", "-skipbuild")
# Build configuration combobox
$ConfigurationCombobox = AddCombobox -LabelText "Build Config (Server + Client)" -Items ($Configurations) -Index 1 -TooltipText "DebugGame is best for detailed debugging. `
Shipping does not have any logs / debug info.`
Development is a good default in-between.`
Test is closest to Shipping for performance testing."
$ConfigurationCombobox.Add_SelectedIndexChanged({
$script:Configuration = $ConfigurationCombobox.Text
})
AddLabel -LabelText "Cook" -IsHeader $true | Out-Null
$CookCheckbox = [ParamCheckBox]::new("Cook", $True, "Enable the cook step. If false, skips the cook", "-cook", "-skipcook")
function UpdateMapsToCookLabel() {
$MapsToCook = $AllMapsToCook[$script:MapIniSection] -join "`n"
$script:MapsToCookLabel.Text = "Maps: $MapsToCook"
SetTooltip $script:MapsToCookLabel $MapsToCook
}
# Maps to cook combobox
$IniSectionCombobox = AddCombobox -LabelText "MapsToCook config section" -Items ($MapIniSectionNames) -Index $InitialMapIniSectionIdx -TooltipText "Name of the map list to use for the build. Changes cooked maps and startup map."
$IniSectionCombobox.Add_SelectedIndexChanged({
$script:MapIniSection = $IniSectionCombobox.Text
UpdateMapsToCookLabel
})
$MapsToCookLabel = AddLabel -LabelText "TEMP" -IsHeader $false -TooltipText "TEMP"
UpdateMapsToCookLabel
$AdditionalCookParamsCheckboxes = @(
[ParamCheckBox]::new("waitforattach", $False, "Pause cook until a debugger is attached. Useful to debug cook code.", "-waitforattach", $null)
[ParamCheckBox]::new("pak", $False, "Combine assets into a few .pak files", "-pak", $null),
[ParamCheckBox]::new("NODEV", $True, "Exclude content from developer folders", "-NODEV", $null),
[ParamCheckBox]::new("SkipCookingEditorContent", $True, "Exclude content marked as 'editor only'", "-SkipCookingEditorContent", $null),
[ParamCheckBox]::new("DisableUnsolicitedPackages", $False, "Do not include any content through propery references. Only content explicitly requested. Debug only.'", "-DisableUnsolicitedPackages", $null)
)
AddLabel -LabelText "Stage" -IsHeader $true | Out-Null
$StageCheckbox = [ParamCheckBox]::new("Stage", $True, "Enable the stage step. If false, skips the stage", "-stage", "-skipstage")
AddLabel -LabelText "Run" -IsHeader $true | Out-Null
$RunCheckbox = [ParamCheckBox]::new("Run", $True, "Enable the run step. If false, skips the run", "-run", "-skiprun")
$WaitForAttachCheckbox = [ParamCheckBox]::new("waitforattach", $False, "Pause game until a debugger is attached. Useful to debug startup code.", "-waitforattach", $null)
# Additional padding before launch button
$AccumulatedHeight += $VerticalPadding
# Launch button
$LaunchClicked = $False
$LaunchButton = New-Object System.Windows.Forms.Button
$LaunchButton.Location = New-Object System.Drawing.Size($HorizontalPadding, $AccumulatedHeight)
$AccumulatedHeight += 20 + $VerticalPadding
$LaunchButton.Size = New-Object System.Drawing.Size(75, 20)
$LaunchButton.Text = "Launch"
$LaunchButton.Name = "Launch"
$LaunchButton.Add_Click({
$script:LaunchClicked = $True
$WinForm.Close()
})
$WinForm.Controls.Add($LaunchButton)
#--------------
# Show form + wait
#--------------
# Adjust size based on content (no scrolling / fixed size)
$TitleBarHeight = 40
$WinForm.Size = New-Object System.Drawing.Size(($Width + $HorizontalPadding*2 + 20), ($AccumulatedHeight + $TitleBarHeight))
$WinForm.FormBorderStyle = 'Fixed3D'
$WinForm.MaximizeBox = $false
# Shows the winform and pauses until closed
[void] $WinForm.ShowDialog()
if (-not $LaunchClicked) {
Write-Warning "Operation was canceled by user"
exit
}
#--------------
# GENERAL SETTINGS
#--------------
$ExecutableArg = if ($UEMajorVersion -gt 4) { "-unrealexe=$UECmdPath" } else { "-ue4exe=$UECmdPath" }
$GENERAL_ARGS = @(
"-project=\`"$ProjectPath\`"",
$ExecutableArg,
"-noP4",
"-utf8output"
)
#--------------
# COMPILE / BUILD
#--------------
$ConfigurationArgs = @("-clientconfig=$Configuration", "-serverconfig=$Configuration")
# TODO: Is this the right condition / what is the flag used for? Is this dependent on the engine version or the desired build output?
$InstalledArg = if ($UEIsInstalledBuild) { "-installed" } else { @() }
$COMPILE_ARGS = @(
$ConfigurationArgs, # see above
"-compile", # This is a convenience tool. We need to compile UAT+editor to make cooking possible without requiring explicit steps in advance.
"-compileeditor", # ^
$InstalledArg, # see above
"-platform=Win64", # current platform
"-targetplatform=Win64", # platform for game
$BuildCheckbox.Get()
)
#--------------
# COOK
#--------------
$MapIniSectionArg = if ($MapIniSection.Length -gt 0) { "-MAPINISECTION=$MapIniSection" } else { "" }
$AdditionalCookArgs = "$MapIniSectionArg -SCCProvider=None"
foreach ($checkbox in $AdditionalCookParamsCheckboxes) {
$AdditionalCookArgs += " " + $checkbox.Get()
}
$CookOptionArgs = "-additionalcookeroptions=`"$AdditionalCookArgs`""
$COOK_ARGS = @($CookCheckbox.Get(), $CookOptionArgs, "", "-compressed")
#--------------
# STAGE
#--------------
$STAGE_ARGS = @($StageCheckbox.Get())
#--------------
# DEPLOY
#--------------
# As long as we do not support platforms other than Win64, deploy is not required
$DEPLOY_ARGS = @() # @("-deploy", "-iterativedeploy")
#--------------
# RUN
#--------------
# These parameters were also present in default cmdline from ProjectLauncher
# -cmdline=" -Messaging" # -> command line to put into the stage in UE4CommandLine.txt
# -device=WindowsNoEditor@PCNAME # -> on which device to run
# -addcmdline="-SessionId=E6ACA1E245978B313340D4A46A0995FD -SessionOwner='username' -SessionName='BuildCookLaunch_GameName_Development' " # -> pass session info to run cmdline
# additional commandline args for game build during "run" step
$RunCmdline = $WaitForAttachCheckbox.Get()
$RunCmdlineArg = if ($RunCmdline.Length -gt 0) { "-addcmdline=\`"$RunCmdline\`"" } else { $null }
$RUN_ARGS = @($RunCheckbox.Get(), $RunCmdlineArg)
Start-UE UAT -ScriptsForProject="$ProjectPath" BuildCookRun $GENERAL_ARGS $COMPILE_ARGS $COOK_ARGS $DEPLOY_ARGS $STAGE_ARGS $RUN_ARGS