-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchAI-Core.ps1
132 lines (96 loc) · 3.81 KB
/
patchAI-Core.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
#!/usr/bin/powershell -Command
# Clone the repo
&git clone "https://github.com/jamiephan/HeroesOfTheStorm_S2MA" ./_s2ma_repo
# Grab MPQEditor
Invoke-WebRequest -Uri http://www.zezula.net/download/mpqeditor_en.zip -UseBasicParsing -OutFile "./mpqeditor.zip"
Expand-Archive -LiteralPath "./mpqeditor.zip" -DestinationPath "./mpqeditor" -Force
Move-Item "./mpqeditor/x64/MPQEditor.exe" "." -Force
Remove-Item "./mpqeditor.zip" -Force
Remove-Item "./mpqeditor" -Force -Recurse
$mpqEditor = "./MPQEditor.exe"
function PatchAI ($mapPath, $savePath, $aiPlayers, $isPvE) {
if (Test-Path "./MapInfo") {
Remove-Item -Force "./MapInfo"
}
Start-Process -WindowStyle Hidden "$mpqEditor" -Wait -ArgumentList "extract `"$mapPath`" MapInfo"
if (Test-Path "./MapInfo") {
$byteString = $(Get-Content "./MapInfo" -Raw -AsByteStream).ForEach('ToString', 'X') -join ' '
# PvE Mode
if ($isPvE) {
Write-Output "Using PVE Patch Mode"
foreach ($i in (Invoke-Expression $aiPlayers)) {
$player = $i.ToString('X')
$byteString = $byteString -replace "\b$player 1 0 0\b", "$player 2 0 0"
}
}
else {
Write-Output "Using non-PVE Patch Mode"
# Invoke-Expression, yikes...
foreach ($i in (Invoke-Expression $aiPlayers)) {
$player = $i.ToString('X')
if ($i -le 5) {
$byteString = $byteString -replace "\b$player 1 0 0 0 2 0 0 0 50 72 6F 74 0 0 0 0 0\b", "$player 2 0 0 0 2 0 0 0 50 72 6F 74 0 0 0 0 0"
}
else {
$byteString = $byteString -replace "\b$player 1 0 0 0 6 0 0 0 50 72 6F 74 0 0 0 0 0\b", "$player 2 0 0 0 6 0 0 0 50 72 6F 74 0 0 0 0 0"
}
}
}
[byte[]] $newByteArray = -split $byteString -replace '^', '0x'
Set-Content "./MapInfo" -AsByteStream -Value $newByteArray
# Prevent no parent directory error
New-Item -Force "$savePath" | Out-Null
Copy-Item -Path $mapPath -Destination $savePath -Force
Start-Process -WindowStyle Normal "$mpqEditor" -Wait -ArgumentList "add `"$savePath`" `"./MapInfo`" MapInfo"
Remove-Item -Force "./MapInfo"
}
else {
Write-Error "Cannot find MapInfo file!"
}
}
Get-ChildItem "./_s2ma_repo/maps" | ForEach-Object {
# Nope.
if ($_.Name -eq "Try Me Mode.stormmap") { return }
if ($_.Name -eq "Tutorial.stormmap") { return }
if ($_.Name -eq "Tutorial Map Mechanics.stormmap") { return }
if ($_.Name -eq "Heroes of the Storm Veteran Challenges.stormmap") { return }
$isPveMap = $false
if ($_.Name -eq "Deadman's Stand (Heroic).stormmap") { $isPveMap = $true }
if ($_.Name -eq "Deadman's Stand.stormmap") { $isPveMap = $true }
if ($_.Name -eq "Escape From Braxis (Heroic).stormmap") { $isPveMap = $true }
if ($_.Name -eq "Escape From Braxis.stormmap") { $isPveMap = $true }
$mapName = $_.BaseName
$mapFile = $_.Name
$mapPath = $_.FullName
# Generate Comps
foreach ($t1 in 1..5) {
# Generate Team 1 Player Array
$t1Arr = @()
for ($t1n = 2 ; $t1n -le $t1 ; $t1n++) {
$t1Arr += $t1n
}
$t1ArrStr = $t1Arr -join ","
foreach ($t2 in 1..5) {
# Generate Team 1 Player Array
$t2Arr = @()
for ($t2n = 1 ; $t2n -le $t2 ; $t2n++) {
$t2Arr += ($t2n + 5)
}
$t2ArrStr = $t2Arr -join ","
# =======
$versesString = -join ($t1, "v", $t2)
$listString = $t2ArrStr
if ($t1ArrStr) {
$listString = ($t1ArrStr, $t2ArrStr) -join ","
}
Write-Output "Patching: $mapName ($versesString)"
PatchAI $mapPath "./maps/$versesString/$mapFile" "$listString" $isPveMap
}
}
# Spectator Mode
Write-Output "Patching: $mapName (spectator)"
PatchAI $mapPath "./maps/spectator/$mapFile" 1..10 $isPveMap
# === Add Your Configuration Here ===
# ===================================
}
Remove-Item "./_s2ma_repo" -Force -Recurse