Skip to content

Fix modScriptPackages holding full paths instead of package names#93

Open
marlonrichert wants to merge 1 commit into
X2CommunityCore:mainfrom
marlonrichert:fix-modscriptpackages-paths
Open

Fix modScriptPackages holding full paths instead of package names#93
marlonrichert wants to merge 1 commit into
X2CommunityCore:mainfrom
marlonrichert:fix-modscriptpackages-paths

Conversation

@marlonrichert

Copy link
Copy Markdown
Contributor

$this.modScriptPackages is typed [string[]], but was assigned the raw Get-ChildItem -Directory results (DirectoryInfo objects). PowerShell coerces each to its full path via ToString(), not just the folder name, so every later "$name.u" package-copy step built a garbage path. Platform-independent bug, not Linux-specific.

@robojumper

robojumper commented Jul 11, 2026

Copy link
Copy Markdown
Member

Can you clarify whether this is specific to the cross-platform Powershell?

@marlonrichert

marlonrichert commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

It's not specific to cross-platform PowerShell. Rather, it's specific to the code in build_common.ps1 that deals with Highlander cooking.

$this.modScriptPackages is declared as [string[]] here:

[string[]] $modScriptPackages

_SetupUtils() tries to populate it here:

$this.modScriptPackages = @(Get-ChildItem "$($this.modSrcRoot)/Src" -Directory)

But @(Get-ChildItem "$($this.modSrcRoot)/Src" -Directory) does not return [string[]]; it returns [System.IO.DirectoryInfo[]].

To make the assignment work, PowerShell silently converts each DirectoryInfo to string by calling ToString() on it. However, DirectoryInfo.ToString() does not return the name of the directory; it returns the path of the directory.

This becomes a problem in _HasNativePackages() and _CopyScriptPackages(). They try to detect native packages by comparing elements from $this.modScriptPackages against the contents of $global:nativescriptpackages, but the latter does not contain paths:

$global:nativescriptpackages = @("XComGame", "Core", "Engine", "GFxUI", "AkAudio", "GameFramework", "UnrealEd", "GFxUIEditor", "IpDrv", "OnlineSubsystemPC", "OnlineSubsystemLive", "OnlineSubsystemSteamworks", "OnlineSubsystemPSN")

Thus, _HasNativePackages() always returns false, since the if in its foreach cannot succeed:

	[bool]_HasNativePackages() {
		# Check if this is a Highlander and we need to cook things
		$anynative = $false
		foreach ($name in $this.modScriptPackages) 
		{
			if ($global:nativescriptpackages.Contains($name)) {
				$anynative = $true
				break
			}
		}
		return $anynative
	}

Likewise, _CopyScriptPackages() will copy only non-native packages, because the if in its foreach cannot succeed either:

	[void]_CopyScriptPackages() {
		# copy packages to staging
		foreach ($name in $this.modScriptPackages) {
			if ($this.cookHL -and $global:nativescriptpackages.Contains($name))
			{
				# This is a native (cooked) script package -- copy important upks
				Copy-Item "$($this.cookerOutputPath)\$name.upk" "$($this.stagingPath)\CookedPCConsole" -Force -WarningAction SilentlyContinue
				Copy-Item "$($this.cookerOutputPath)\$name.upk.uncompressed_size" "$($this.stagingPath)\CookedPCConsole" -Force -WarningAction SilentlyContinue
				Write-Host "$($this.cookerOutputPath)\$name.upk"
			}
			else
			{
				# Or this is a non-native package
				Copy-Item "$($this.sdkPath)\XComGame\Script\$name.u" "$($this.stagingPath)\Script" -Force -WarningAction SilentlyContinue
				Write-Host "$($this.sdkPath)\XComGame\Script\$name.u"
			}
		}
	}

My commit fixes this by populating $this.modScriptPackages with directory names instead of paths.

@robojumper

robojumper commented Jul 12, 2026

Copy link
Copy Markdown
Member

Right, but the Highlander X2ModBuildCommon (which has an older version) already has this line:

https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/blob/1e872694b4f383d2a2232755612bc782363fec0f/.scripts/X2ModBuildCommon/build_common.ps1#L207-L209

If your explaination is right, then the current Highlander build should also be completely broken, but it isn't, at least with the classic powershell.

@marlonrichert
marlonrichert force-pushed the fix-modscriptpackages-paths branch from a276b8d to 4c43074 Compare July 12, 2026 21:18
@marlonrichert

marlonrichert commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

I need your help to be able to answer your question:

In _HasNativePackages() in build_common.ps1, can you add

Write-Host $anynative

right before

return $anynative

then build Highlander itself, and tell me whether it prints true or false?

$this.modScriptPackages is typed [string[]], but was assigned the raw
Get-ChildItem -Directory results (DirectoryInfo objects). PowerShell
coerces each to its full path via ToString(), not just the folder
name, so every later "$name.u" package-copy step built a garbage path.
Platform-independent bug, not Linux-specific.
@marlonrichert
marlonrichert force-pushed the fix-modscriptpackages-paths branch from 4c43074 to d59d645 Compare July 12, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants