1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2024-12-22 17:47:38 +08:00

Add reverse-engineered code for SrcDS launcher.

This commit is contained in:
Scott Ehlert 2014-03-01 13:26:04 -06:00
parent ec8aa94c92
commit 86892164eb
9 changed files with 534 additions and 0 deletions

View File

@ -0,0 +1,72 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_DEDICATED ICON DISCARDABLE "srcds.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dedicated_main", "dedicated_main.vcxproj", "{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Debug|Win32.ActiveCfg = Debug|Win32
{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Debug|Win32.Build.0 = Debug|Win32
{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Release|Win32.ActiveCfg = Release|Win32
{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>dedicated_main</ProjectName>
<ProjectGuid>{E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720}</ProjectGuid>
<RootNamespace>tier1</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">srcds</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">srcds</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\public;..\public\tier0;..\public\tier1;..\public\interfaces;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_HAS_ITERATOR_DEBUGGING=0;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;_ITERATOR_DEBUG_LEVEL=0;WIN32;_WIN32;COMPILER_MSVC;COMPILER_MSVC32;_DEBUG;DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild>
<ExceptionHandling>
</ExceptionHandling>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Fast</FloatingPointModel>
<PrecompiledHeader>
</PrecompiledHeader>
<AssemblerOutput>
</AssemblerOutput>
<BrowseInformation>
</BrowseInformation>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<PreLinkEvent>
<Command>
</Command>
</PreLinkEvent>
<Lib>
<AdditionalDependencies>Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Lib>
<Xdcmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Xdcmake>
<Bscmake />
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<ClCompile>
<AdditionalIncludeDirectories>..\public;..\public\tier0;..\public\tier1;..\public\interfaces;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_HAS_ITERATOR_DEBUGGING=0;_ALLOW_RUNTIME_LIBRARY_MISMATCH;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;_ALLOW_MSC_VER_MISMATCH;WIN32;_WIN32;COMPILER_MSVC;COMPILER_MSVC32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<ExceptionHandling>
</ExceptionHandling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<AssemblerOutput>
</AssemblerOutput>
<BrowseInformation>
</BrowseInformation>
<WarningLevel>Level3</WarningLevel>
<FloatingPointModel>Fast</FloatingPointModel>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<PreLinkEvent>
<Command>
</Command>
</PreLinkEvent>
<Lib>
<AdditionalDependencies>
</AdditionalDependencies>
</Lib>
<Xdcmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Xdcmake>
<Bscmake />
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="dedicated_main.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{aba1d919-d95c-4c3f-a495-be0375bab184}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{0295d938-2af6-4393-9785-4b7b122313c9}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="dedicated_main.rc" />
</ItemGroup>
</Project>

201
dedicated_main/main.cpp Normal file
View File

@ -0,0 +1,201 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#else
#include <dlfcn.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#endif
// Reverse engineered file
// Entry point of dedicated binary
#if defined(WIN32)
typedef int (*DedicatedMain_t)(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
#else
typedef int (*DedicatedMain_t)(int argc, char **argv);
#endif
#if defined(WIN32)
#define ENGINE_BIN(x) "bin\\" #x ".dll"
#elif defined(LINUX)
#define ENGINE_BIN(x) "bin/" #x "_srv.so"
#define ENGINE_BIN_ALT(x) "bin/" #x ".so"
#define LIB_PATH "LD_LIBRARY_PATH"
#elif defined(OSX)
#define ENGINE_BIN(x) "bin/" #x ".dylib"
#define LIB_PATH "DYLD_LIBRARY_PATH"
#endif
#if defined(WANTS_DEBUGSTR_HACK) && !defined(WIN32)
#if !defined(PAGE_SIZE)
#define PAGE_SIZE 4096
#endif
#define ALIGN(ar) ((long)ar & ~(PAGE_SIZE-1))
void BlockDebugString()
{
void *tier0;
void *func;
void *addr;
int ret;
const uint8_t OP_RET = 0xC3;
tier0 = dlopen(ENGINE_BIN(libtier0), RTLD_NOW);
#if defined(ENGINE_BIN_ALT)
if (!tier0)
tier0 = dlopen(ENGINE_BIN_ALT(libtier0), RTLD_NOW);
#endif
if (!tier0)
return;
func = dlsym(tier0, "Plat_DebugString");
dlclose(tier0);
if (!func)
return;
addr = (void *)ALIGN(func);
ret = mprotect(addr, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE|PROT_EXEC);
if (ret != 0)
return;
*(uint8_t *)func = OP_RET;
mprotect(addr, sysconf(_SC_PAGESIZE), PROT_READ|PROT_EXEC);
}
#endif
#if defined(WIN32)
static const char *GetBaseDir(const char *file)
{
static char basedir[MAX_PATH];
strcpy(basedir, file);
char *rslash = strrchr(basedir, '\\');
if (rslash)
*(rslash + 1) = '\0';
return basedir;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
char exeName[MAX_PATH];
char pathBuf[4096];
char *path = getenv("PATH");
if (!GetModuleFileName(hInstance, exeName, sizeof(exeName)))
{
MessageBox(0, "Failed calling GetModuleFileName", "Launcher Error", MB_OK);
return 0;
}
const char *root = GetBaseDir(exeName);
_snprintf(pathBuf, sizeof(pathBuf) - 1, "PATH=%s\\bin\\;%s", root, path);
_putenv(pathBuf);
HMODULE dedicated = LoadLibrary(ENGINE_BIN(dedicated));
if (!dedicated)
{
char *error;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&error,
0,
NULL);
char msg[1024];
_snprintf(msg, sizeof(msg) - 1, "Failed to load the launcher DLL:\n\n%s", error);
MessageBox(0, msg, "Launcher Error", MB_OK);
LocalFree(error);
return 0;
}
DedicatedMain_t main = (DedicatedMain_t)GetProcAddress(dedicated, "DedicatedMain");
int ret = main(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
FreeLibrary(dedicated);
return ret;
}
#else
int main(int argc, char **argv)
{
char cwd[PATH_MAX];
char pathBuf[4096];
char *path = getenv(LIB_PATH);
if (!getcwd(cwd, sizeof(cwd)))
{
printf("getcwd failed (%s)\n", strerror(errno));
return -1;
}
snprintf(pathBuf, sizeof(pathBuf), LIB_PATH "=%s/bin:%s", cwd, path);
if (putenv(pathBuf) != 0)
{
printf("%s\n", strerror(errno));
return -1;
}
void *dedicated = dlopen(ENGINE_BIN(dedicated), RTLD_NOW);
#if defined(ENGINE_BIN_ALT)
if (!dedicated)
dedicated = dlopen(ENGINE_BIN_ALT(dedicated), RTLD_NOW);
#endif
if (!dedicated)
{
printf("Failed to open %s (%s)\n", ENGINE_BIN(dedicated), dlerror());
return -1;
}
#if defined(WANTS_DEBUGSTR_HACK)
BlockDebugString();
#endif
DedicatedMain_t main = (DedicatedMain_t)dlsym(dedicated, "DedicatedMain");
if (!main)
{
printf("Failed to find dedicated server entry point (%s)\n", dlerror());
return -1;
}
int ret = main(argc, argv);
dlclose(dedicated);
return ret;
}
#endif

23
dedicated_main/resource.h Normal file
View File

@ -0,0 +1,23 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by dedicated_main.rc
//
#define IDI_DEDICATED 101
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

BIN
dedicated_main/srcds.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -81,6 +81,7 @@ ARCH_CFLAGS = -mtune=i686 -march=pentium3 -mmmx -msse -msse2 -m32
ifeq "$(OS)" "Darwin"
DEFINES = -D_OSX -DOSX
ARCH_CFLAGS += -mmacosx-version-min=10.7
else
DEFINES = -D_LINUX -DLINUX
endif
@ -117,6 +118,7 @@ BASE_DEFINES = CC=$(CC) AR=$(AR) CPLUS=$(CPLUS) CPP_LIB=$(CPP_LIB) DEBUG=$(DEBUG
# Project Makefile
MAKE_SERVER = Makefile.server
MAKE_VCPM = Makefile.vcpm
MAKE_SRCDS = Makefile.srcds
MAKE_PLUGIN = Makefile.plugin
MAKE_TIER1 = Makefile.tier1
MAKE_MATH = Makefile.mathlib
@ -143,6 +145,9 @@ mod: check vcpm
./vcpm $(MOD_PROJ)
$(MAKE) -f $(MAKE_SERVER) $(BASE_DEFINES)
srcds:
$(MAKE) -f $(MAKE_SRCDS) $(BASE_DEFINES)
plugin: check
$(MAKE) -f $(MAKE_PLUGIN) $(BASE_DEFINES)
@ -167,6 +172,7 @@ installrelease:
clean:
$(MAKE) -f $(MAKE_VCPM) $(BASE_DEFINES) clean
$(MAKE) -f $(MAKE_SRCDS) $(BASE_DEFINES) clean
$(MAKE) -f $(MAKE_PLUGIN) $(BASE_DEFINES) clean
$(MAKE) -f $(MAKE_SERVER) $(BASE_DEFINES) clean
$(MAKE) -f $(MAKE_TIER1) $(BASE_DEFINES) clean

52
linux_sdk/Makefile.srcds Normal file
View File

@ -0,0 +1,52 @@
#
# Source Dedicated Server Main Executable
#
# November 2004, alfred@valvesoftware.com
#
SRCDS_SRC_DIR = $(SRC_DIR)/dedicated_main
SRCDS_OBJ_DIR = $(BUILD_OBJ_DIR)/srcds
INCLUDEDIRS =
LDFLAGS_SRCDS = -lm -ldl
DO_CC = $(CPLUS) $(INCLUDEDIRS) -DARCH=$(ARCH)
ifeq "$(DEBUG)" "true"
DO_CC += -DWANTS_DEBUGSTR_HACK $(DBG_DEFINES) $(DBG_CFLAGS)
else
DO_CC += -DWANTS_DEBUGSTR_HACK -DNDEBUG $(CFLAGS)
endif
DO_CC += -o $@ -c $<
#####################################################################
OS := $(shell uname -s)
ifeq "$(OS)" "Darwin"
SRCDS_BIN = srcds_osx
LDFLAGS_SRCDS += -mmacosx-version-min=10.7
else
SRCDS_BIN = srcds_linux
endif
SRCDS_OBJS = \
$(SRCDS_OBJ_DIR)/main.o \
all: dirs srcds
dirs:
-mkdir -p $(BUILD_OBJ_DIR)
-mkdir -p $(SRCDS_OBJ_DIR)
srcds: $(SRCDS_OBJS)
$(CLINK) -m32 -o $(BUILD_DIR)/$(SRCDS_BIN) $(SRCDS_OBJS) $(LDFLAGS_SRCDS)
$(SRCDS_OBJ_DIR)/%.o: $(SRCDS_SRC_DIR)/%.cpp
$(DO_CC)
clean:
-rm -rf $(SRCDS_OBJ_DIR)
-rm -f $(SRCDS_BIN)