From 40fbd649773e940cc9b485d0a203b3b718d4422b Mon Sep 17 00:00:00 2001 From: Inorien Date: Tue, 23 Dec 2025 21:11:10 +0900 Subject: [PATCH 1/3] add rundebug config for launching both --- .vscode/launch.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index b74e0acda049..afc0670a2cbf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,6 +15,19 @@ "preLaunchTask": "Build All", "dmb": "${workspaceFolder}/${command:CurrentDMB}", "dreamDaemon": true + }, + { + "type": "byond", + "request": "launch", + "name": "Launch DreamSeeker (No Build)", + "dmb": "${workspaceFolder}/${command:CurrentDMB}" + } + ], + "compounds": [ + { + "name": "Launch Both", + "configurations": ["Launch DreamDaemon", "Launch DreamSeeker (No Build)"], + "stopAll": true } ] } From ad12a567c2e2bf841745cdd7e669ac8e89db97e7 Mon Sep 17 00:00:00 2001 From: Inorien Date: Tue, 23 Dec 2025 21:53:09 +0900 Subject: [PATCH 2/3] wait for dreamdaemon --- .vscode/launch.json | 1 + .vscode/tasks.json | 15 +++++---- bin/connect-to-local-wait.ps1 | 63 +++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 bin/connect-to-local-wait.ps1 diff --git a/.vscode/launch.json b/.vscode/launch.json index afc0670a2cbf..be8870359433 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,6 +20,7 @@ "type": "byond", "request": "launch", "name": "Launch DreamSeeker (No Build)", + "preLaunchTask": "Wait for DreamDaemon", "dmb": "${workspaceFolder}/${command:CurrentDMB}" } ], diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 21a5f2b1c3fe..a2afbad9c505 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -91,13 +91,14 @@ "label": "tgui: sonar" }, { - "type": "npm", - "script": "install", - "path": "tgui", - "group": "clean", - "problemMatcher": [], - "label": "npm: install - tgui", - "detail": "install dependencies from package" + "type": "shell", + "label": "Wait for DreamDaemon", + "command": "powershell", + "args": ["-ExecutionPolicy", "Bypass", "-File", ".\\bin\\connect-to-local-wait.ps1"], + "presentation": { + "reveal": "silent" + }, + "problemMatcher": [] } ] } diff --git a/bin/connect-to-local-wait.ps1 b/bin/connect-to-local-wait.ps1 new file mode 100644 index 000000000000..2105b85d3458 --- /dev/null +++ b/bin/connect-to-local-wait.ps1 @@ -0,0 +1,63 @@ +# Ping the local DreamDaemon server until it responds +# Autodetects port by finding what dreamdaemon.exe is listening on + +function Find-DreamDaemonPort { + $connections = Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue | Where-Object { + $proc = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue + $proc.ProcessName -in @('dd', 'dreamdaemon') + } + + if ($connections) { + return $connections[0].LocalPort + } + return $null +} + +function Test-Server { + param([string]$Server = "localhost", [int]$Port) + try { + $client = New-Object System.Net.Sockets.TcpClient + $client.Connect($Server, $Port) + $stream = $client.GetStream() + + $query = "?ping" + $queryBytes = [System.Text.Encoding]::ASCII.GetBytes($query) + $length = $queryBytes.Length + 6 + + # Byond topic packet construction + $packet = [byte[]]@( + 0x00, # Header byte + 0x83, # Header byte + [byte](($length -shr 8) -band 0xFF), # Message body size in big endian + [byte]($length -band 0xFF), # and lower byte, its an int16 + 0x00, 0x00, 0x00, 0x00, 0x00 # flag, port (unused here so 0) + ) + $queryBytes + [byte]0x00 # mesasge + null terminator + + $stream.Write($packet, 0, $packet.Length) + $stream.Flush() + $stream.ReadTimeout = 1000 + + $buffer = New-Object byte[] 1024 + $read = $stream.Read($buffer, 0, 1024) + + $client.Close() + return $read -gt 0 + } catch { + return $false + } +} + +while ($true) { + $port = Find-DreamDaemonPort + if ($port) { + Write-Host "Found DreamDaemon on port $port, feelsgoodman" + if (Test-Server -Port $port) { + Write-Host "DreamDaemon ready" + break + } + Write-Host "Server is still starting and not responding yet, retrying" + } else { + Write-Host "DreamDaemon has not yet launched, retrying" + } + Start-Sleep -Seconds 2 +} From 18c51c78ed2a1eecdc20fbf4e92f7524f61e8fc0 Mon Sep 17 00:00:00 2001 From: Inorien Date: Tue, 23 Dec 2025 23:14:32 +0900 Subject: [PATCH 3/3] im going to bed --- .vscode/launch.json | 12 +++--------- .vscode/tasks.json | 25 ++++++++++++++++++------ bin/connect-to-local-wait.ps1 | 36 +++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index be8870359433..a35df3d79d7c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,16 +19,10 @@ { "type": "byond", "request": "launch", - "name": "Launch DreamSeeker (No Build)", - "preLaunchTask": "Wait for DreamDaemon", - "dmb": "${workspaceFolder}/${command:CurrentDMB}" - } - ], - "compounds": [ - { "name": "Launch Both", - "configurations": ["Launch DreamDaemon", "Launch DreamSeeker (No Build)"], - "stopAll": true + "preLaunchTask": "Build and Launch Server", + "dmb": "${workspaceFolder}/${command:CurrentDMB}", + "dreamDaemon": true } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a2afbad9c505..c7724f04f93c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -90,14 +90,27 @@ "group": "build", "label": "tgui: sonar" }, + { + "type": "shell", + "label": "Background: Wait for DreamDaemon", + "command": "start", + "args": ["\"Waiting for DreamDaemon\"", "powershell", "-ExecutionPolicy", "Bypass", "-File", "${workspaceFolder}\\bin\\connect-to-local-wait.ps1"], + "options": { + "shell": { + "executable": "cmd.exe", // it needs to detach so vscode can actually launch dreamdaemon before we start waiting for it + "args": ["/c"] + } + }, + "presentation": { + "reveal": "silent" + }, + "problemMatcher": [] + }, { "type": "shell", - "label": "Wait for DreamDaemon", - "command": "powershell", - "args": ["-ExecutionPolicy", "Bypass", "-File", ".\\bin\\connect-to-local-wait.ps1"], - "presentation": { - "reveal": "silent" - }, + "label": "Build and Launch Server", + "dependsOn": ["Build All", "Background: Wait for DreamDaemon"], + "dependsOrder": "parallel", "problemMatcher": [] } ] diff --git a/bin/connect-to-local-wait.ps1 b/bin/connect-to-local-wait.ps1 index 2105b85d3458..4bfee1b09a0e 100644 --- a/bin/connect-to-local-wait.ps1 +++ b/bin/connect-to-local-wait.ps1 @@ -2,13 +2,16 @@ # Autodetects port by finding what dreamdaemon.exe is listening on function Find-DreamDaemonPort { - $connections = Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue | Where-Object { - $proc = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue - $proc.ProcessName -in @('dd', 'dreamdaemon') + # check running processes, this is slow as shit because it looks at everything so erroraction should be faster + $proc = Get-Process -Name 'dd','dreamdaemon' -ErrorAction SilentlyContinue | Select-Object -First 1 + if (-not $proc) { + return $null } - if ($connections) { - return $connections[0].LocalPort + # found the process, get the port + $conn = Get-NetTCPConnection -OwningProcess $proc.Id -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($conn) { + return $conn.LocalPort } return $null } @@ -17,7 +20,12 @@ function Test-Server { param([string]$Server = "localhost", [int]$Port) try { $client = New-Object System.Net.Sockets.TcpClient - $client.Connect($Server, $Port) + $asyncResult = $client.BeginConnect($Server, $Port, $null, $null) + if (-not $asyncResult.AsyncWaitHandle.WaitOne(1000)) { + $client.Close() + return $false + } + $client.EndConnect($asyncResult) $stream = $client.GetStream() $query = "?ping" @@ -47,12 +55,16 @@ function Test-Server { } } +$detectedPort = $null + while ($true) { + # get whatever port dreamdaemon is on $port = Find-DreamDaemonPort if ($port) { - Write-Host "Found DreamDaemon on port $port, feelsgoodman" + Write-Host "Found DreamDaemon on port $port" + # ping the server to make sure we can actually connect yet if (Test-Server -Port $port) { - Write-Host "DreamDaemon ready" + $detectedPort = $port break } Write-Host "Server is still starting and not responding yet, retrying" @@ -61,3 +73,11 @@ while ($true) { } Start-Sleep -Seconds 2 } + +if ($detectedPort) { + $dsPath = "C:\Program Files (x86)\BYOND\bin\dreamseeker.exe" + if (-not (Test-Path $dsPath)) { + $dsPath = "C:\Program Files\BYOND\bin\dreamseeker.exe" + } + Start-Process $dsPath -ArgumentList "byond://localhost:$detectedPort" +}