-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinstall-plugin.ps1
More file actions
323 lines (256 loc) · 11 KB
/
install-plugin.ps1
File metadata and controls
323 lines (256 loc) · 11 KB
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
# Anyone seeing this? well don't waste time improving this script.
# It's messy and just temporary until i get the new version.
param(
[string]$DownloadLink, # Overwrites the download link (give a direct link)
[string]$PluginName, # Overwrites the plugin name
[int]$Branch # 1 for luatools, 2 for steamtools-collection (overwrites the above two options)
)
## Configure this
$Host.UI.RawUI.WindowTitle = "Luatools plugin installer | .gg/luatools"
$name = "luatools" # automatic first letter uppercase included
$link = "https://github.com/madoiscool/ltsteamplugin/releases/latest/download/ltsteamplugin.zip"
$milleniumTimer = 5 # in seconds for auto-installation
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
chcp 65001 > $null
Add-Type -AssemblyName System.IO.Compression.FileSystem
# Hidden defines
$steam = (Get-ItemProperty "HKLM:\SOFTWARE\WOW6432Node\Valve\Steam").InstallPath
$upperName = $name.Substring(0, 1).ToUpper() + $name.Substring(1).ToLower()
if ( $DownloadLink ) {
$link = $DownloadLink
}
if ( $PluginName ) {
$name = $PluginName
}
# Second option to get steamtools-collection plugin
# use $branch = 2 ; irm ... | iex
if ($br -eq 2 -or $Branch -eq 2) {
$name = "steamtools-collection"
$link = "https://github.com/clemdotla/steamtools-collection/releases/download/Latest/steamtools-collection.zip"
}
#### Logging defines ####
function Log {
param ([string]$Type, [string]$Message, [boolean]$NoNewline = $false)
$Type = $Type.ToUpper()
switch ($Type) {
"OK" { $foreground = "Green" }
"INFO" { $foreground = "Cyan" }
"ERR" { $foreground = "Red" }
"WARN" { $foreground = "Yellow" }
"LOG" { $foreground = "Magenta" }
"AUX" { $foreground = "DarkGray" }
default { $foreground = "White" }
}
$date = Get-Date -Format "HH:mm:ss"
$prefix = if ($NoNewline) { "`r[$date] " } else { "[$date] " }
Write-Host $prefix -ForegroundColor "Cyan" -NoNewline
Write-Host [$Type] $Message -ForegroundColor $foreground -NoNewline:$NoNewline
}
Log "WARN" "Hey! Just letting you know that i'm working on a new version combining various scripts of the server"
Log "AUX" "Will include language support on THIS script too, luv y'all brazilians"
Write-Host
# To hide IEX blue box thing
$ProgressPreference = 'SilentlyContinue'
Get-Process steam -ErrorAction SilentlyContinue | Stop-Process -Force
#### Requirements part ####
# Steamtools check
# TODO: Make this prettier?
function CheckSteamtools {
$files = @( "dwmapi.dll", "xinput1_4.dll" )
foreach($file in $files) {
if (!( Test-Path (Join-Path $steam $file) )) {
return $false
}
}
return $true
}
$path = Join-Path $steam "dwmapi.dll"
if ( CheckSteamtools ) {
Log "INFO" "Steamtools already installed"
}
else {
# Filtering the installation script
# $script = Invoke-RestMethod "https://steam.run"
$script = Invoke-RestMethod "https://luatools.vercel.app/st.ps1"
$keptLines = @()
foreach ($line in $script -split "`n") {
$conditions = @( # Removes lines containing one of those
($line -imatch "Start-Process" -and $line -imatch "steam"),
($line -imatch "steam\.exe"),
($line -imatch "Start-Sleep" -or $line -imatch "Write-Host"),
($line -imatch "cls" -or $line -imatch "exit"),
($line -imatch "Stop-Process" -and -not ($line -imatch "Get-Process"))
)
if (-not($conditions -contains $true)) {
$keptLines += $line
}
}
$SteamtoolsScript = $keptLines -join "`n"
Log "ERR" "Steamtools not found."
# Retrying with a max of 5
for ($i = 0; $i -lt 5; $i++) {
Log "AUX" "Install it at your own risk! Close this script if you don't want to."
Log "WARN" "Pressing any key will install steamtools (UI-less)."
[void][System.Console]::ReadKey($true)
Write-Host
Log "WARN" "Installing Steamtools"
Invoke-Expression $SteamtoolsScript *> $null
if ( CheckSteamtools ) {
Log "OK" "Steamtools installed"
break
}
else {
Log "ERR" "Steamtools installation failed, retrying..."
}
}
}
# Millenium check
$milleniumInstalling = $false
foreach ($file in @("millennium.dll", "python311.dll")) {
if (!( Test-Path (Join-Path $steam $file) )) {
# Ask confirmation to download
Log "ERR" "Millenium not found, installation process will start in 5 seconds."
Log "WARN" "Press any key to cancel the installation."
for ($i = $milleniumTimer; $i -ge 0; $i--) {
# Wheter a key was pressed
if ([Console]::KeyAvailable) {
Write-Host
Log "ERR" "Installation cancelled by user."
exit
}
Log "LOG" "Installing Millenium in $i second(s)... Press any key to cancel." $true
Start-Sleep -Seconds 1
}
Write-Host
Log "INFO" "Installing millenium"
Invoke-Expression "& { $(Invoke-RestMethod 'https://clemdotla.github.io/millennium-installer-ps1/millennium.ps1') } -NoLog -DontStart -SteamPath '$steam'"
Log "OK" "Millenium done installing"
$milleniumInstalling = $true
break
}
}
if ($milleniumInstalling -eq $false) { Log "INFO" "Millenium already installed" }
#### Plugin part ####
# Ensuring \Steam\plugins
if (!( Test-Path (Join-Path $steam "plugins") )) {
New-Item -Path (Join-Path $steam "plugins") -ItemType Directory *> $null
}
$Path = Join-Path $steam "plugins\$name" # Defaulting if no install found
# Checking for plugin named "$name"
foreach ($plugin in Get-ChildItem -Path (Join-Path $steam "plugins") -Directory) {
$testpath = Join-Path $plugin.FullName "plugin.json"
if (Test-Path $testpath) {
$json = Get-Content $testpath -Raw | ConvertFrom-Json
if ($json.name -eq $name) {
Log "INFO" "Plugin already installed, updating it"
$Path = $plugin.FullName # Replacing default path
break
}
}
}
# Installation
$subPath = Join-Path $env:TEMP "$name.zip"
Log "LOG" "Downloading $name"
if ($DownloadLink) { Log "Aux" $($link) }
Invoke-WebRequest -Uri $link -OutFile $subPath *> $null
if ( !( Test-Path $subPath ) ) {
Log "ERR" "Failed to download $name"
exit
}
Log "LOG" "Unzipping $name"
try {
$zip = [System.IO.Compression.ZipFile]::OpenRead($subPath)
foreach ($entry in $zip.Entries) {
$destinationPath = Join-Path $Path $entry.FullName
if (-not $entry.FullName.EndsWith('/') -and -not $entry.FullName.EndsWith('\')) {
$parentDir = Split-Path -Path $destinationPath -Parent
if ($parentDir -and $parentDir.Trim() -ne '') {
$pathParts = $parentDir -replace [regex]::Escape($steam), '' -split '[\\/]' | Where-Object { $_ }
$currentPath = $Path
foreach ($part in $pathParts) {
$currentPath = Join-Path $currentPath $part
if (Test-Path $currentPath) {
$item = Get-Item $currentPath
if (-not $item.PSIsContainer) {
Remove-Item $currentPath -Force
}
}
}
[System.IO.Directory]::CreateDirectory($parentDir) | Out-Null
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $destinationPath, $true)
}
}
}
$zip.Dispose()
}
catch {
write-host "Error: $($_.Exception.Message)"
if ($zip) { $zip.Dispose() }
Log "ERR" "Extraction failed, trying normal way"
Expand-Archive -Path $subPath -DestinationPath $Path -Force
}
if ( Test-Path $subPath ) {
Remove-Item $subPath -ErrorAction SilentlyContinue
}
Log "OK" "$upperName installed"
# Removing beta
$betaPath = Join-Path $steam "package\beta"
if ( Test-Path $betaPath ) {
Remove-Item $betaPath -Recurse -Force
}
# Removing potential x32 (kinda greedy but ppl got issues and was hard to fix without knowing it was the issue, ppl don't know what they run)
$cfgPath = Join-Path $steam "steam.cfg"
if ( Test-Path $cfgPath ) {
Remove-Item $cfgPath -Recurse -Force
}
Remove-ItemProperty -Path "HKCU:\Software\Valve\Steam" -Name "SteamCmdForceX86" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Valve\Steam" -Name "SteamCmdForceX86" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Valve\Steam" -Name "SteamCmdForceX86" -ErrorAction SilentlyContinue
# Toggling the plugin on (+turning off updateChecking to try fixing a bug where steam doesn't start)
$configPath = Join-Path $steam "ext/config.json"
if (-not (Test-Path $configPath)) {
$config = @{
plugins = @{
enabledPlugins = @($name)
}
general = @{
checkForMillenniumUpdates = $false
}
}
New-Item -Path (Split-Path $configPath) -ItemType Directory -Force | Out-Null
$config | ConvertTo-Json -Depth 10 | Set-Content $configPath -Encoding UTF8
}
else {
$config = (Get-Content $configPath -Raw -Encoding UTF8) | ConvertFrom-Json
function _EnsureProperty {
param($Object, $PropertyName, $DefaultValue)
if (-not $Object.$PropertyName) {
$Object | Add-Member -MemberType NoteProperty -Name $PropertyName -Value $DefaultValue -Force
}
}
_EnsureProperty $config "general" @{}
_EnsureProperty $config "general.checkForMillenniumUpdates" $false
$config.general.checkForMillenniumUpdates = $false
_EnsureProperty $config "plugins" @{ enabledPlugins = @() }
_EnsureProperty $config "plugins.enabledPlugins" @()
$pluginsList = @($config.plugins.enabledPlugins)
if ($pluginsList -notcontains $name) {
$pluginsList += $name
$config.plugins.enabledPlugins = $pluginsList
}
$config | ConvertTo-Json -Depth 10 | Set-Content $configPath -Encoding UTF8
}
Log "OK" "Plugin enabled"
# Result showing
Write-Host
if ($milleniumInstalling) { Log "WARN" "Steam startup will be longer, don't panic and don't touch anything in steam!" }
# Start with the "-clearbeta" argument
$exe = Join-Path $steam "steam.exe"
Start-Process $exe -ArgumentList "-clearbeta"
Log "INFO" "Starting steam"
Log "WARN" "Hey so there's a bug where steam may not start"
Log "WARN" "Hopefully this script fixes it"
Log "WARN" "But i had to turn updates of millennium off."
Log "WARN" "In future, they will come back but in the meantime:"
Log "OK" "Manually check for updates of millennium if you want up to date."
Log "AUX" "Millennium is working now tho (latest version)."