-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHotReload.ps1
107 lines (91 loc) · 3.52 KB
/
HotReload.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
param (
[string]$Config = "Debug"
)
if ($env:SKIP_POST_BUILD -eq "true") {
Write-Host "SKIP_POST_BUILD is set. Exiting post-build script."
exit 0
}
# Define the events and delay
$unloadEventName = "Global\UnloadEvent"
$reloadEventName = "Global\ReloadEvent"
$copyDelayMs = 50 # Delay between copy attempts
$maxAttempts = 20 # Maximum number of copy attempts
# Define paths for DLL and resources copy
$coreDllSource = "$PSScriptRoot\$Config\core.dll"
$coreDllDestination = "$PSScriptRoot\..\everquest_rof2\eqnexus\core.dll"
$resourcesSource = "$PSScriptRoot\resources"
$resourcesDestination = "$PSScriptRoot\..\everquest_rof2\eqnexus"
# Find the process ID of eqgame.exe
$process = Get-Process -Name "eqgame" -ErrorAction SilentlyContinue
if ($process -eq $null) {
Write-Host "Process eqgame.exe not found."
Write-Host "Attempting to copy core.dll (Attempt $($attempts + 1) of $maxAttempts)..."
Copy-Item -Path $coreDllSource -Destination $coreDllDestination -Force
Write-Host "core.dll copied successfully."
Copy-Item -Path "$resourcesSource\*" -Destination $resourcesDestination -Recurse -Force
Write-Host "Resources folder copied successfully."
exit 0
}
$processId = $process.Id
Write-Host "Found eqgame.exe with PID: $processId"
# Open the UnloadEvent
$unloadEvent = [System.Threading.EventWaitHandle]::OpenExisting($unloadEventName)
if ($unloadEvent -eq $null) {
Write-Host "Unload event $unloadEventName not found."
exit 0
}
# Open the ReloadEvent
$reloadEvent = [System.Threading.EventWaitHandle]::OpenExisting($reloadEventName)
if ($reloadEvent -eq $null) {
Write-Host "Reload event $reloadEventName not found."
exit 0
}
# Verify target paths
if (!(Test-Path -Path $coreDllSource)) {
Write-Host "Source core.dll does not exist: $coreDllSource. Exiting."
exit 0
}
if (!(Test-Path -Path $resourcesSource)) {
Write-Host "Resources folder does not exist: $resourcesSource. Exiting."
exit 0
}
if (!(Test-Path -Path (Split-Path -Parent $coreDllDestination))) {
Write-Host "Target directory for core.dll does not exist: $coreDllDestination. Exiting."
exit 0
}
if (!(Test-Path -Path $resourcesDestination)) {
Write-Host "Target directory for resources does not exist: $resourcesDestination. Exiting."
exit 0
}
# Trigger the UnloadEvent
Write-Host "Triggering UnloadEvent..."
$unloadEvent.Set()
# Attempt to copy the core.dll file and resources folder with retries
$attempts = 0
while ($attempts -lt $maxAttempts) {
try {
Write-Host "Attempting to copy core.dll (Attempt $($attempts + 1) of $maxAttempts)..."
Copy-Item -Path $coreDllSource -Destination $coreDllDestination -Force
Write-Host "core.dll copied successfully."
Write-Host "Copying resources folder..."
Copy-Item -Path "$resourcesSource\*" -Destination $resourcesDestination -Recurse -Force
Write-Host "Resources folder copied successfully."
break
}
catch {
Write-Host "Failed to copy core.dll or resources folder. Retrying in $copyDelayMs ms..."
Start-Sleep -Milliseconds $copyDelayMs
$attempts++
}
}
if ($attempts -ge $maxAttempts) {
Write-Host "Failed to copy core.dll and resources after $maxAttempts attempts."
exit 0
}
# Trigger the ReloadEvent
Write-Host "Triggering ReloadEvent..."
$reloadEvent.Set()
# Clean up
$unloadEvent.Close()
$reloadEvent.Close()
Write-Host "Events triggered and DLL and resources copied successfully."