Skip to content

Commit ad33240

Browse files
committed
code
1 parent 2c30cf0 commit ad33240

5 files changed

Lines changed: 338 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vs
2+
x64
3+
auto-debug
4+
auto-debug.vcxproj.filters
5+
auto-debug.vcxproj.user

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A simple replacement for vsjitdebugger.exe because i don't want to manually choose my only running Visual Studio instance when debugging my 4D Miner mods bruh.
2+
Distributed on https://4d-modding.com/core-files/auto-debug.exe aswell i guess.

auto-debug.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36616.10 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "auto-debug", "auto-debug.vcxproj", "{3256D710-3C0F-4EAA-97A5-23431C7B68E2}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{3256D710-3C0F-4EAA-97A5-23431C7B68E2}.Debug|x64.ActiveCfg = Debug|x64
17+
{3256D710-3C0F-4EAA-97A5-23431C7B68E2}.Debug|x64.Build.0 = Debug|x64
18+
{3256D710-3C0F-4EAA-97A5-23431C7B68E2}.Debug|x86.ActiveCfg = Debug|Win32
19+
{3256D710-3C0F-4EAA-97A5-23431C7B68E2}.Debug|x86.Build.0 = Debug|Win32
20+
{3256D710-3C0F-4EAA-97A5-23431C7B68E2}.Release|x64.ActiveCfg = Release|x64
21+
{3256D710-3C0F-4EAA-97A5-23431C7B68E2}.Release|x64.Build.0 = Release|x64
22+
{3256D710-3C0F-4EAA-97A5-23431C7B68E2}.Release|x86.ActiveCfg = Release|Win32
23+
{3256D710-3C0F-4EAA-97A5-23431C7B68E2}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {5C49BA2E-8974-45C1-A930-3A38C36269ED}
30+
EndGlobalSection
31+
EndGlobal

auto-debug.vcxproj

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{3256d710-3c0f-4eaa-97a5-23431c7b68e2}</ProjectGuid>
25+
<RootNamespace>autodebug</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<SubSystem>Console</SubSystem>
82+
<GenerateDebugInformation>true</GenerateDebugInformation>
83+
</Link>
84+
</ItemDefinitionGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<FunctionLevelLinking>true</FunctionLevelLinking>
89+
<IntrinsicFunctions>true</IntrinsicFunctions>
90+
<SDLCheck>true</SDLCheck>
91+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
<ConformanceMode>true</ConformanceMode>
93+
</ClCompile>
94+
<Link>
95+
<SubSystem>Console</SubSystem>
96+
<GenerateDebugInformation>true</GenerateDebugInformation>
97+
</Link>
98+
</ItemDefinitionGroup>
99+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
100+
<ClCompile>
101+
<WarningLevel>Level3</WarningLevel>
102+
<SDLCheck>true</SDLCheck>
103+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
104+
<ConformanceMode>true</ConformanceMode>
105+
<LanguageStandard>stdcpp20</LanguageStandard>
106+
</ClCompile>
107+
<Link>
108+
<SubSystem>Console</SubSystem>
109+
<GenerateDebugInformation>true</GenerateDebugInformation>
110+
</Link>
111+
</ItemDefinitionGroup>
112+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
113+
<ClCompile>
114+
<WarningLevel>Level3</WarningLevel>
115+
<FunctionLevelLinking>true</FunctionLevelLinking>
116+
<IntrinsicFunctions>true</IntrinsicFunctions>
117+
<SDLCheck>true</SDLCheck>
118+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
119+
<ConformanceMode>true</ConformanceMode>
120+
<LanguageStandard>stdcpp20</LanguageStandard>
121+
<AdditionalIncludeDirectories>$(IntDir)</AdditionalIncludeDirectories>
122+
</ClCompile>
123+
<Link>
124+
<SubSystem>Console</SubSystem>
125+
<GenerateDebugInformation>true</GenerateDebugInformation>
126+
<AdditionalDependencies>ole32.lib;
127+
oleaut32.lib
128+
;%(AdditionalDependencies)</AdditionalDependencies>
129+
</Link>
130+
</ItemDefinitionGroup>
131+
<ItemGroup>
132+
<ClCompile Include="main.cpp" />
133+
</ItemGroup>
134+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
135+
<ImportGroup Label="ExtensionTargets">
136+
</ImportGroup>
137+
</Project>

main.cpp

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#include <windows.h>
2+
#include <objbase.h>
3+
#include <oleauto.h>
4+
#include <iostream>
5+
#include <string>
6+
#include <atlbase.h>
7+
#include <comdef.h>
8+
9+
#include <atlcom.h>
10+
#pragma warning(disable : 4278)
11+
#pragma warning(disable : 4146)
12+
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") lcid("0") raw_interfaces_only named_guids
13+
#pragma warning(default : 4146)
14+
#pragma warning(default : 4278)
15+
16+
static bool tryAttach(IDispatch* dispatch, DWORD target)
17+
{
18+
if (!dispatch) return false;
19+
20+
EnvDTE::_DTEPtr dte;
21+
HRESULT hr = dispatch->QueryInterface(__uuidof(EnvDTE::_DTE), (void**)&dte);
22+
if (FAILED(hr) || !dte)
23+
{
24+
return false;
25+
}
26+
27+
try
28+
{
29+
EnvDTE::DebuggerPtr debugger;
30+
dte->get_Debugger(&debugger);
31+
if (!debugger)
32+
{
33+
return false;
34+
}
35+
36+
EnvDTE::ProcessesPtr procs;
37+
debugger->get_LocalProcesses(&procs);
38+
if (!procs)
39+
{
40+
return false;
41+
}
42+
43+
long count = 0;
44+
procs->get_Count(&count);
45+
46+
for (long i = 1; i <= count; ++i)
47+
{
48+
EnvDTE::ProcessPtr proc;
49+
VARIANT idx;
50+
VariantInit(&idx);
51+
idx.vt = VT_I4;
52+
idx.lVal = i;
53+
HRESULT qhr = procs->Item(idx, &proc);
54+
VariantClear(&idx);
55+
if (FAILED(qhr) || !proc) continue;
56+
57+
long procId = 0;
58+
proc->get_ProcessID(&procId);
59+
if ((DWORD)procId == target)
60+
{
61+
proc->Attach();
62+
63+
return true;
64+
}
65+
}
66+
}
67+
catch (_com_error& e)
68+
{
69+
std::cerr << "COM error: " << std::hex << e.Error() << " - " << (const char*)e.Description() << '\n';
70+
return false;
71+
}
72+
return false;
73+
}
74+
75+
int main(int argc, char* argv[])
76+
{
77+
if (argc != 2)
78+
{
79+
std::cout << "Usage: auto-debug <pid>\n";
80+
return 1;
81+
}
82+
83+
DWORD pid = 0;
84+
pid = (DWORD)std::stoi(argv[1]);
85+
if (pid == 0)
86+
{
87+
std::cerr << "Invalid PID.\n";
88+
return 1;
89+
}
90+
91+
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
92+
if (FAILED(hr))
93+
{
94+
std::cerr << "CoInitializeEx failed: " << std::hex << hr << '\n';
95+
return 1;
96+
}
97+
98+
IRunningObjectTable* ROT = nullptr;
99+
if (FAILED(GetRunningObjectTable(0, &ROT)) || !ROT)
100+
{
101+
std::cerr << "GetRunningObjectTable failed\n";
102+
CoUninitialize();
103+
return 1;
104+
}
105+
106+
IEnumMoniker* enumMoniker = nullptr;
107+
if (FAILED(ROT->EnumRunning(&enumMoniker)) || !enumMoniker)
108+
{
109+
std::cerr << "EnumRunning failed\n";
110+
ROT->Release();
111+
CoUninitialize();
112+
return 1;
113+
}
114+
115+
IMoniker* moniker = nullptr;
116+
ULONG fetched = 0;
117+
bool attached = false;
118+
119+
while (enumMoniker->Next(1, &moniker, &fetched) == S_OK)
120+
{
121+
IBindCtx* bindContext = nullptr;
122+
if (SUCCEEDED(CreateBindCtx(0, &bindContext)))
123+
{
124+
LPOLESTR displayName = nullptr;
125+
if (SUCCEEDED(moniker->GetDisplayName(bindContext, NULL, &displayName)))
126+
{
127+
std::wstring name{ displayName ? displayName : L"" };
128+
CoTaskMemFree(displayName);
129+
130+
if (name.find(L"VisualStudio.DTE") != std::wstring::npos)
131+
{
132+
IUnknown* unk = nullptr;
133+
if (SUCCEEDED(ROT->GetObject(moniker, &unk)) && unk)
134+
{
135+
if (tryAttach((IDispatch*)unk, pid))
136+
{
137+
attached = true;
138+
unk->Release();
139+
bindContext->Release();
140+
moniker->Release();
141+
break;
142+
}
143+
unk->Release();
144+
}
145+
}
146+
}
147+
bindContext->Release();
148+
}
149+
moniker->Release();
150+
}
151+
152+
enumMoniker->Release();
153+
ROT->Release();
154+
CoUninitialize();
155+
156+
if (!attached)
157+
{
158+
std::cerr << "Failed to attach.\n";
159+
return 2;
160+
}
161+
162+
return 0;
163+
}

0 commit comments

Comments
 (0)