Skip to content

Instantly share code, notes, and snippets.

@m4dEngi
Last active December 7, 2022 10:43
Show Gist options
  • Save m4dEngi/48bb2f35653fc0100420cbc37f1f0f19 to your computer and use it in GitHub Desktop.
Save m4dEngi/48bb2f35653fc0100420cbc37f1f0f19 to your computer and use it in GitHub Desktop.
Bare minimum steam client bootstrapper. Can be used as drop-in replacement for steam main executable. (windows only)
#include <iostream>
#include <Windows.h>
#define export extern "C" __declspec(dllexport)
typedef void (*SteamUIMainFn) (int, char**);
typedef enum ELauncherType
{
k_ELauncherTypeDefault, // default
k_ELauncherTypePw_dota2, // pw_dota2
k_ELauncherTypeNexon_dota2, // nexon_dota2
k_ELauncherTypeSteamcmd, // steamcmd
k_ELauncherTypePw_csgo, // pw_csgo
k_ELauncherTypeClientui, // clientui
k_ELauncherTypeSteamhdl, // steamhdl
k_ELauncherTypeSteamchina, // steamchina
k_ELauncherTypeSingleapp, // singleapp
} ELauncherType;
std::string g_InstallPath;
std::string g_LogsPath;
export ELauncherType __cdecl GetClientLauncherType()
{
return k_ELauncherTypeDefault;
}
export const char* __cdecl SteamBootstrapper_GetInstallDir()
{
return g_InstallPath.c_str();
}
export const char* __cdecl SteamBootstrapper_GetBaseUserDir()
{
return g_InstallPath.c_str(); // ¯\(°_o)/¯
}
export const char* __cdecl SteamBootstrapper_GetLoggingDir()
{
return g_LogsPath.c_str();
}
std::string GetExecutablePath()
{
char szInstallDir[MAX_PATH];
int pathEnd = GetModuleFileNameA(NULL, szInstallDir, sizeof(szInstallDir));
if (pathEnd)
{
for (int i = pathEnd; i > 0; --i)
{
if (szInstallDir[i] == '\\')
{
pathEnd = i;
break;
}
}
return std::string(szInstallDir, pathEnd);
}
return std::string("./");
}
int main(int argc, char** argv)
{
std::cout << "Starting Steam...\n";
g_InstallPath = GetExecutablePath();
g_LogsPath = g_InstallPath + "/logs";
if (!SetCurrentDirectoryA(g_InstallPath.c_str()))
{
std::cout << "Could not change current work directory!" << std::endl;
}
HMODULE steamUIModule = LoadLibraryW(L"steamui.dll");
if (!steamUIModule)
{
std::cout << "Could not load SteamUI!" << std::endl;
return -1;
}
SteamUIMainFn steamUIMain = (SteamUIMainFn)GetProcAddress(steamUIModule, "SteamDllMain");
if (!steamUIMain)
{
std::cout << "SteamDllMain function not found in steamui.dll!" << std::endl;
return -1;
}
steamUIMain(argc, argv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment