diff --git a/dedicated_main/dedicated_main.rc b/dedicated_main/dedicated_main.rc new file mode 100644 index 00000000..24c03a57 --- /dev/null +++ b/dedicated_main/dedicated_main.rc @@ -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 + diff --git a/dedicated_main/dedicated_main.sln b/dedicated_main/dedicated_main.sln new file mode 100644 index 00000000..03dcd48b --- /dev/null +++ b/dedicated_main/dedicated_main.sln @@ -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 diff --git a/dedicated_main/dedicated_main.vcxproj b/dedicated_main/dedicated_main.vcxproj new file mode 100644 index 00000000..e67fd592 --- /dev/null +++ b/dedicated_main/dedicated_main.vcxproj @@ -0,0 +1,134 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + dedicated_main + {E1DA8DB8-FB4C-4B14-91A6-98BCED6B9720} + tier1 + + + + Application + + + Application + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + AllRules.ruleset + + + AllRules.ruleset + + + srcds + srcds + + + + + + + + Disabled + ..\public;..\public\tier0;..\public\tier1;..\public\interfaces;%(AdditionalIncludeDirectories) + _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) + true + true + + + EnableFastChecks + MultiThreadedDebug + false + Fast + + + + + + + Level3 + + + + + + + Rpcrt4.lib;%(AdditionalDependencies) + + + true + + + + + + + + + + ..\public;..\public\tier0;..\public\tier1;..\public\interfaces;%(AdditionalIncludeDirectories) + _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) + true + + + MultiThreaded + false + true + + + + + + + Level3 + Fast + AnySuitable + true + Speed + + + + + + + + + + + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dedicated_main/dedicated_main.vcxproj.filters b/dedicated_main/dedicated_main.vcxproj.filters new file mode 100644 index 00000000..a7455685 --- /dev/null +++ b/dedicated_main/dedicated_main.vcxproj.filters @@ -0,0 +1,26 @@ + + + + + {aba1d919-d95c-4c3f-a495-be0375bab184} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {0295d938-2af6-4393-9785-4b7b122313c9} + h;hpp;hxx;hm;inl + + + + + Source Files + + + + + Header Files + + + + + + \ No newline at end of file diff --git a/dedicated_main/main.cpp b/dedicated_main/main.cpp new file mode 100644 index 00000000..841dcec1 --- /dev/null +++ b/dedicated_main/main.cpp @@ -0,0 +1,201 @@ +//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// +// +// Purpose: +// +//===========================================================================// + +#if defined(WIN32) +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 diff --git a/dedicated_main/resource.h b/dedicated_main/resource.h new file mode 100644 index 00000000..5409fb68 --- /dev/null +++ b/dedicated_main/resource.h @@ -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 diff --git a/dedicated_main/srcds.ico b/dedicated_main/srcds.ico new file mode 100644 index 00000000..bda52dd2 Binary files /dev/null and b/dedicated_main/srcds.ico differ diff --git a/linux_sdk/Makefile b/linux_sdk/Makefile index fcce185b..84095e08 100644 --- a/linux_sdk/Makefile +++ b/linux_sdk/Makefile @@ -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 diff --git a/linux_sdk/Makefile.srcds b/linux_sdk/Makefile.srcds new file mode 100644 index 00000000..35dcaeeb --- /dev/null +++ b/linux_sdk/Makefile.srcds @@ -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) +