-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsetup.ps1
152 lines (127 loc) · 5.54 KB
/
setup.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
Param(
[switch]$PatchMission = $false
)
function Get-SteamPath()
{
$regItem = (Get-ItemProperty -Path Registry::HKEY_CURRENT_USER\Software\Valve\Steam -Name SteamPath -EA SilentlyContinue)
if(!$regItem) {
Write-Error "No registry item found for Steam"
Exit
}
$steamPath = (Get-ItemProperty -Path Registry::HKEY_CURRENT_USER\Software\Valve\Steam -Name SteamPath).SteamPath
if(!$steamPath) {
Write-Error "No Steam installation found"
Exit
}
return $steamPath
}
function Pack-Pbo($SourcePath, $DestinationPath, $PrivateKeyPath)
{
$AddonBuilder = "$(Get-SteamPath)/steamapps/common/Arma 3 Tools/AddonBuilder/AddonBuilder.exe"
if(!(Test-Path $AddonBuilder)) {
Write-Host -ForegroundColor Red "Addon Builder from Arma 3 Tools not found"
Write-Host "You can install it through Steam - https://community.bistudio.com/wiki/Arma_3_Tools_Installation"
Exit
}
$SourcePath = [System.IO.Path]::GetFullPath($SourcePath)
$DestinationPath = [System.IO.Path]::GetFullPath($DestinationPath)
$TempPath = "$env:TEMP\$([System.IO.Path]::GetFileName($SourcePath))"
# Cleanup AddonBuilder temp path
Remove-Item $TempPath -Recurse -Force -ErrorAction SilentlyContinue
if(($PrivateKeyPath) -and (Test-Path $PrivateKeyPath)) {
$PrivateKeyPath = [System.IO.Path]::GetFullPath($PrivateKeyPath)
$ERR = & "$AddonBuilder" "$SourcePath" "$DestinationPath" -packonly -sign="$PrivateKeyPath"
} else {
$ERR = & "$AddonBuilder" "$SourcePath" "$DestinationPath" -packonly
}
Write-Output $ERR
if($ERR -match "\[FATAL\]") {
Write-Host -ForegroundColor Red "An error occured while executing the Arma 3 Tools."
Write-Host -ForegroundColor Red "Please make sure STEAM is running"
return $false
}
return $true
}
function Unpack-Pbo($SourceFile, $DestinationPath)
{
$BankRev = "$(Get-SteamPath)/steamapps/common/Arma 3 Tools/BankRev/BankRev.exe"
& "$BankRev" -f "$DestinationPath" "$SourceFile"
}
function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "PBO (*.pbo)| *.pbo"
$OpenFileDialog.ShowDialog() | Out-Null
return $OpenFileDialog.filename
}
function Get-CodeBlockLastLineNumber($content, $FuncName)
{
$openBracket = 0
$startLine = ($content | Select-String -Pattern "class $FuncName").LineNumber
if(!$startLine) { return }
for ($i = $startLine; $i -lt $content.Count; $i++) {
$c = $content[$i] -replace """.*?""", ""
$c = $c -replace "'.*?'", ""
for ($j = 0; $j -lt $c.Length; $j++) {
if($c[$j] -eq "{") {
$openBracket += 1
} elseif($c[$j] -eq "}") {
$openBracket -= 1
}
}
if($openBracket -le 0) {
break
}
}
return $i - 1
}
Write-Host ("#" * 90)
Write-Host "# PLEASE NOTE: Packing the PBO's is moved to arma-dev extension using Visual Studio Code #"
Write-Host "# https://marketplace.visualstudio.com/items?itemName=ole1986.arma-dev #"
Write-Host ("#" * 90)
if($PatchMission) {
Write-Host -ForegroundColor Green "Please select your mission file from the dialog:"
$missionFile = Get-FileName($PWD)
if(!$missionFile) {
Write-Host "Canceled by user action"
Exit
}
$extractedFolder = (Get-Item $missionFile).Basename
New-Item "$env:TEMP\build" -ItemType Directory -Force | Out-Null
$extractedPath = "$env:TEMP\build\$extractedFolder"
# Cleanup existing folder
Write-Host "Cleanup previous temp folder.."
Remove-Item -Recurse -Force "$extractedPath\*" -ErrorAction SilentlyContinue
# Unpack the mission file
Unpack-Pbo "$missionFile" "$env:TEMP\build"
$content = Get-Content "$extractedPath\description.ext"
if(!$content) {
Write-Host -ForegroundColor Red "The description.ext could not be found in the mission file $extractedFolder - Very Strange! - Canceled"
Exit
}
Write-Host "Copying mission related files into $extractedPath"
Copy-Item "$PWD\source\mission_file\*" -Destination "$extractedPath" -Recurse -Force
Write-Host -NoNewline "Trying to patch file $extractedPath\description.ext..."
if(!($content -match "class AdminToolkit_network_receiveRequest")) {
$lastLineNumber = Get-CodeBlockLastLineNumber $content -FuncName "Functions"
if(!$lastLineNumber) {
Write-Host -ForegroundColor Red "FAILED (User action required - Sorry)"
Exit
}
$content[$lastLineNumber] += "`n class AdminToolkit_network_receiveRequest { allowedTargets=2; };"
$content | Set-Content "$extractedPath\description.ext"
} else {
Write-Host -ForegroundColor Yellow "Already patched"
}
Write-Host "Building mission file '$extractedFolder'..."
if(! (Pack-Pbo "$extractedPath" "$PWD\@MissionFile")) {
Exit
}
Write-Host -ForegroundColor Green "############"
Write-Host -ForegroundColor Green "### DONE ###"
Write-Host -ForegroundColor Green "############"
Write-Host -ForegroundColor Green ""
Write-Host -ForegroundColor Green "Patched MissionFile: $PSScriptRoot\@MissionFile\$extractedFolder.pbo"
}