diff --git a/M2TWEOP Code/M2TWEOP library/managerF.cpp b/M2TWEOP Code/M2TWEOP library/managerF.cpp index 4f5019af..72dd131b 100644 --- a/M2TWEOP Code/M2TWEOP library/managerF.cpp +++ b/M2TWEOP Code/M2TWEOP library/managerF.cpp @@ -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; diff --git a/autoAttachDebugger.ps1 b/autoAttachDebugger.ps1 new file mode 100644 index 00000000..35dbfd57 --- /dev/null +++ b/autoAttachDebugger.ps1 @@ -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." diff --git a/buildEOPDev_debug.ps1 b/buildEOPDev_debug.ps1 index 1a1b606f..82aad82a 100644 --- a/buildEOPDev_debug.ps1 +++ b/buildEOPDev_debug.ps1 @@ -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 diff --git a/buildEOPDev_release.ps1 b/buildEOPDev_release.ps1 index 05259107..1e5198a3 100644 --- a/buildEOPDev_release.ps1 +++ b/buildEOPDev_release.ps1 @@ -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