Skip to content

Commit

Permalink
Update D2Loader.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
shupershuff authored Aug 23, 2024
1 parent d215c00 commit 5ae02cd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions D2Loader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ Function Inventory {#Info screen
Write-Host
PressTheAnyKey
}
Function LoadWindowClass { #Used to get window locations and place them in the same screen locations at launch. Code courtesy of Sir-Wilhelm and Microsoft.
Function Add-WindowType { #Used to get window locations and place them in the same screen locations at launch. Code courtesy of Sir-Wilhelm and Microsoft.
if ($Script:WindowClassLoaded -ne $True){
$Script:WindowClassLoaded = $True
Add-Type @"
Expand Down Expand Up @@ -1507,7 +1507,7 @@ Function LoadWindowClass { #Used to get window locations and place them in the s
}
}
Function SaveWindowLocations {# Get Window Location coordinates and save to Accounts.csv
LoadWindowClass
Add-WindowType
FormatFunction -indents 2 -text "Saving locations of each open account so that they the windows launch in the same place next time. Assumes you've configured the game to launch in windowed mode."
CheckActiveAccounts
#If Feature is enabled, add 'WindowXCoordinates' and 'WindowYCoordinates' columns to accounts.csv with empty values.
Expand Down Expand Up @@ -1568,7 +1568,7 @@ Function SetWindowLocations {#
[int]$Width,
[int]$Height
)
LoadWindowClass
Add-WindowType
$handle = (Get-Process -Id $Id).MainWindowHandle
[WindowAPI]::MoveWindow($handle, $x, $y, $Width, $Height, $True)
[WindowAPI]::SetForegroundWindow($handle)
Expand Down Expand Up @@ -1672,7 +1672,7 @@ Function Options {
}
}
ElseIf ($NewOptionValue -eq "r"){
LoadWindowClass
Add-WindowType
CheckActiveAccounts
if ($null -eq $Script:ActiveAccountsList){
FormatFunction -text "`nThere are no open games.`nTo reset window positions, you need to launch one or more instances first.`n" -indents 2 -IsWarning
Expand Down Expand Up @@ -3522,11 +3522,11 @@ Function Processing {
}
If ($Script:Config.RememberWindowLocations -eq $True){ #If user has enabled the feature to automatically move game Windows to preferred screen locations.
if ($Script:AccountChoice.WindowXCoordinates -ne "" -and $Script:AccountChoice.WindowYCoordinates -ne "" -and $Null -ne $Script:AccountChoice.WindowXCoordinates -and $Null -ne $Script:AccountChoice.WindowYCoordinates -and $Script:AccountChoice.WindowWidth -ne "" -and $Script:AccountChoice.WindowHeight -ne "" -and $Null -ne $Script:AccountChoice.WindowWidth -and $Null -ne $Script:AccountChoice.WindowHeight){ #Check if the account has had coordinates saved yet.
$GetLoadWindowClassFunc = $(Get-Command LoadWindowClass).Definition
$GetAdd-WindowTypeFunc = $(Get-Command Add-WindowType).Definition
$GetSetWindowLocationsFunc = $(Get-Command SetWindowLocations).Definition
$JobID = (Start-Job -ScriptBlock { # Run this in a background job so we don't have to wait for it to complete
start-sleep -milliseconds 2024 # We need to wait for about 2 seconds for game to load as if we move it too early, the game itself will reposition the window. Absolute minimum is 420 milliseconds (funnily enough). Delay may need to be a bit higher for people with wooden computers.
Invoke-Expression "function LoadWindowClass {$using:GetLoadWindowClassFunc}"
Invoke-Expression "function Add-WindowType {$using:GetAdd-WindowTypeFunc}"
Invoke-Expression "function SetWindowLocations {$using:GetSetWindowLocationsFunc}"
SetWindowLocations -x $Using:AccountChoice.WindowXCoordinates -y $Using:AccountChoice.WindowYCoordinates -Width $Using:AccountChoice.WindowWidth -height $Using:AccountChoice.WindowHeight -Id $Using:process.id
}).id
Expand Down

0 comments on commit 5ae02cd

Please sign in to comment.