Skip to content

Commit

Permalink
Add autoAttachDebugger.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
EddieEldridge committed Sep 28, 2024
1 parent 0005011 commit 5e2a6bb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions M2TWEOP Code/M2TWEOP library/managerF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,8 +1271,16 @@ void managerF::initThread()
globals::dataS.Modules.tacticalMapViewer.init(globals::dataS.gameVersion);
}

// void waitForDebugger() {
// while (!IsDebuggerPresent()) {
// std::this_thread::sleep_for(std::chrono::seconds(1)); // Sleep for 1 second
// }
// }

EOP_EXPORT void managerExport::initEOP(const char* modPath, const int gameVer)
{
// waitForDebugger();

// Initialize MinHook.
if (MH_Initialize() != MH_OK)
return;
Expand Down
43 changes: 43 additions & 0 deletions autoAttachDebugger.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Define the process name and Visual Studio paths
$processName = "medieval2"
$vsPath = "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe"
$vsSolution = 'C:\Users\stead\Documents\Coding Projects\M2TWEOP-library\M2TWEOP Code\M2TWEOP library.sln'

# Log message to confirm that script is starting
Write-Host "Monitoring for process: $processName..."

while ($true) {
$process = Get-Process | Where-Object { $_.Name -eq $processName } -ErrorAction SilentlyContinue

if ($process) {
Write-Host "Process $processName found. Process ID: $($process.Id)"

# Step 1: Open Visual Studio and load the solution
Write-Host "Opening solution in Visual Studio..."
$vsInstance = Start-Process $vsPath -ArgumentList "`"$vsSolution`"" -PassThru

# Wait to ensure Visual Studio opens the solution
Start-Sleep -Seconds 10

# Step 2: Use Visual Studio's DTE to attach the debugger to the process
Write-Host "Attaching debugger to process ID: $($process.Id)..."
$dte = [Runtime.Interopservices.Marshal]::GetActiveObject("VisualStudio.DTE")
$processToAttach = $dte.Debugger.LocalProcesses | Where-Object { $_.ProcessID -eq $process.Id }

if ($processToAttach) {
$processToAttach.Attach()
Write-Host "Debugger attached successfully to process $processName (ID: $($process.Id))"
} else {
Write-Host "Failed to find the process to attach the debugger."
}

# Exit the loop since the process was found and debugger was attached
break
}

# Log message indicating that the process is still not found
# Write-Host "Process $processName not found. Retrying in 1 second..."
# Start-Sleep -Seconds 1
}

Write-Host "Script complete."
1 change: 0 additions & 1 deletion buildEOPDev_debug.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Copy-Item -Path "M2TWEOP DataFiles\*" -Destination "./M2TWEOPGenerated" -recurs

# Remove scripts and config we don't need
Remove-Item -Path "./M2TWEOPGenerated/eopData/eopScripts/luaPluginScript.lua" -Force
Remove-Item -Path "./M2TWEOPGenerated/eopData/eopScripts/myConfigs.lua" -Force
Remove-Item -Path "./M2TWEOPGenerated/eopData/eopScripts/redist" -Force -Recurse -erroraction 'silentlycontinue'
Remove-Item -Path "./M2TWEOPGenerated/eopData/eopScripts/helpers" -Force -Recurse -erroraction 'silentlycontinue'
Remove-Item -Path "./M2TWEOPGenerated/eopData/config" -recurse -erroraction 'silentlycontinue' -Force
Expand Down
1 change: 0 additions & 1 deletion buildEOPDev_release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Copy-Item -Path "M2TWEOP DataFiles\*" -Destination "./M2TWEOPGenerated" -recurs

# Remove scripts and config we don't need
Remove-Item -Path "./M2TWEOPGenerated/eopData/eopScripts/luaPluginScript.lua" -Force
Remove-Item -Path "./M2TWEOPGenerated/eopData/eopScripts/myConfigs.lua" -Force
Remove-Item -Path "./M2TWEOPGenerated/eopData/eopScripts/redist" -Force -Recurse -erroraction 'silentlycontinue'
Remove-Item -Path "./M2TWEOPGenerated/eopData/eopScripts/helpers" -Force -Recurse -erroraction 'silentlycontinue'
Remove-Item -Path "./M2TWEOPGenerated/eopData/config" -recurse -erroraction 'silentlycontinue' -Force
Expand Down

0 comments on commit 5e2a6bb

Please sign in to comment.