├── .gitignore ├── .gitmodules ├── AMBuildScript ├── README.md ├── build_gamedir.sh ├── configure.py ├── game └── server │ └── variant_t.h ├── gamedll ├── AMBuilder ├── gamedll.cpp ├── gamedll.h ├── tools.cpp └── tools.h ├── lib ├── linux │ ├── mathlib_i486.a │ ├── tier0_i486.so │ ├── tier1_i486.a │ └── vstdlib_i486.so └── linux64 │ ├── libtier0_client.so │ ├── libvstdlib_client.so │ ├── mathlib.a │ └── tier1.a ├── mathlib ├── AMBuilder └── mathlib.cpp ├── public ├── Color.h ├── SoundEmitterSystem │ └── isoundemittersystembase.h ├── basehandle.h ├── bitvec.h ├── cdll_int.h ├── cmodel.h ├── const.h ├── datamap.h ├── dt_send.h ├── edict.h ├── ehandle.h ├── eiface.h ├── engine │ ├── IEngineSound.h │ ├── IEngineTrace.h │ └── iserverplugin.h ├── filesystem.h ├── game │ ├── baseentity.h │ └── server │ │ └── iplayerinfo.h ├── gametrace.h ├── iclient.h ├── icollideable.h ├── igameevents.h ├── ihandleentity.h ├── imovehelper.h ├── inetchannel.h ├── inetchannelinfo.h ├── inetmsghandler.h ├── irecipientfilter.h ├── isaverestore.h ├── iserver.h ├── iserverentity.h ├── iservernetworkable.h ├── iserverunknown.h ├── ispatialpartition.h ├── ivoiceserver.h ├── mathlib │ ├── mathlib.h │ └── vector.h ├── networkstringtabledefs.h ├── server_class.h ├── shareddefs.h ├── steam │ └── steamclientpublic.h ├── string_t.h ├── takedamageinfo.h ├── tier0 │ ├── dbg.h │ ├── icommandline.h │ ├── logging.h │ ├── mem.h │ ├── platform.h │ └── vprof.h ├── tier1 │ ├── KeyValues.h │ ├── bitbuf.h │ ├── convar.h │ ├── interface.h │ ├── strtools.h │ ├── utlbuffer.h │ ├── utldict.h │ ├── utlstring.h │ ├── utlsymbol.h │ └── utlvector.h ├── toolframework │ └── itoolentity.h ├── usercmd.h ├── vstdlib │ └── random.h └── worldsize.h ├── srcds ├── AMBuilder ├── cvars.cpp ├── cvars.h ├── engine.cpp ├── engine.h ├── fs.cpp ├── fs.h ├── gameevents.cpp ├── gameevents.h ├── main.cpp ├── networkstringtable.cpp ├── networkstringtable.h ├── server.cpp ├── server.h ├── sound.cpp ├── sound.h ├── spatialpartition.cpp ├── spatialpartition.h ├── trace.cpp ├── trace.h ├── utility.h ├── voice.cpp └── voice.h ├── tier0 ├── AMBuilder ├── commandline.cpp ├── commandline.h ├── dbg.cpp ├── logmanager.cpp ├── logmanager.h ├── mem.cpp ├── platform.cpp └── vprof.cpp ├── tier1 ├── AMBuilder ├── convar.cpp ├── interface.cpp ├── keyvalues.cpp └── strtools.cpp ├── update_prebuilts.sh └── vstdlib ├── AMBuilder └── empty.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | objdir 2 | .gdb_history 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/cli"] 2 | path = third_party/cli 3 | url = https://github.com/daniele77/cli 4 | [submodule "third_party/amtl"] 5 | path = third_party/amtl 6 | url = https://github.com/alliedmodders/amtl 7 | -------------------------------------------------------------------------------- /AMBuildScript: -------------------------------------------------------------------------------- 1 | #! vim: set sts=4 sw=4 tw=99 et ft=python: 2 | import os 3 | 4 | class Root(object): 5 | def __init__(self): 6 | self.targets = [] 7 | self.tier0 = {} 8 | self.tier1 = {} 9 | self.vstdlib = {} 10 | self.mathlib = {} 11 | self.gamedll = {} 12 | self.srcds = {} 13 | self.so_files = {} 14 | self.renames = {} 15 | self.lib_folders = {} 16 | 17 | def configure(self): 18 | if builder.options.targets: 19 | targets = builder.options.targets.split(',') 20 | 21 | dupes = set() 22 | for target in targets: 23 | if target in dupes: 24 | continue 25 | dupes.add(target) 26 | 27 | cxx = builder.DetectCxx(target = target) 28 | self.configure_cxx(cxx) 29 | self.targets.append(cxx) 30 | else: 31 | cxx = builder.DetectCxx() 32 | self.configure_cxx(cxx) 33 | self.targets.append(cxx) 34 | 35 | self.add_renames() 36 | 37 | def configure_cxx(self, cxx): 38 | if cxx.like('gcc'): 39 | cxx.cflags += [ 40 | '-pipe', 41 | '-Wall', 42 | '-Werror', 43 | '-Wno-switch', 44 | ] 45 | cxx.cxxflags += [ 46 | '-std=c++17', 47 | '-Wno-unused-private-field', 48 | ] 49 | elif cxx.like('msvc'): 50 | if builder.options.debug == '1': 51 | cxx.cflags += ['/MTd'] 52 | cxx.linkflags += ['/NODEFAULTLIB:libcmt'] 53 | else: 54 | cxx.cflags += ['/MT'] 55 | cxx.defines += [ 56 | '_CRT_SECURE_NO_DEPRECATE', 57 | '_CRT_SECURE_NO_WARNINGS', 58 | '_CRT_NONSTDC_NO_DEPRECATE', 59 | '_ITERATOR_DEBUG_LEVEL=0', 60 | ] 61 | cxx.cflags += [ 62 | '/W3', 63 | '/wd4351', 64 | ] 65 | cxx.cxxflags += [ 66 | '/EHsc', 67 | '/GR-', 68 | '/TP', 69 | ] 70 | cxx.linkflags += [ 71 | 'kernel32.lib', 72 | 'user32.lib', 73 | 'gdi32.lib', 74 | 'winspool.lib', 75 | 'comdlg32.lib', 76 | 'advapi32.lib', 77 | 'shell32.lib', 78 | 'ole32.lib', 79 | 'oleaut32.lib', 80 | 'uuid.lib', 81 | 'odbc32.lib', 82 | 'odbccp32.lib', 83 | ] 84 | 85 | def build(self): 86 | for cxx in self.targets: 87 | self.tier0[cxx.target.arch] = self.BuildForArch('tier0/AMBuilder', cxx) 88 | self.tier1[cxx.target.arch] = self.BuildForArch('tier1/AMBuilder', cxx) 89 | self.BuildForArch('gamedll/AMBuilder', cxx) 90 | self.BuildForArch('vstdlib/AMBuilder', cxx) 91 | self.BuildForArch('mathlib/AMBuilder', cxx) 92 | self.BuildForArch('srcds/AMBuilder', cxx) 93 | 94 | def add_renames(self): 95 | for cxx in self.targets: 96 | self.add_renames_for_arch(cxx) 97 | 98 | def add_renames_for_arch(self, cxx): 99 | tier0 = 'tier0' 100 | tier1 = 'tier1' 101 | vstdlib = 'vstdlib' 102 | mathlib = 'mathlib' 103 | if cxx.target.platform == 'linux': 104 | if cxx.target.arch == 'x86_64': 105 | out_folder = 'lib/linux64' 106 | tier0 = 'libtier0_client' 107 | vstdlib = 'libvstdlib_client' 108 | else: 109 | out_folder = 'lib/linux' 110 | tier0 = 'tier0_i486' 111 | tier1 = 'tier1_i486' 112 | mathlib = 'mathlib_i486' 113 | vstdlib = 'vstdlib_i486' 114 | elif cxx.target.platform == 'mac': 115 | if cxx.target.arch == 'x86_64': 116 | out_folder = 'lib/osx64' 117 | else: 118 | out_folder = 'lib/mac' 119 | tier1 = 'tier1_i486' 120 | mathlib = 'mathlib_i486' 121 | tier0 = 'libtier0' 122 | vstdlib = 'libvstdlib' 123 | elif cxx.target.platform == 'windows': 124 | if cxx.target.arch == 'x86_64': 125 | out_folder = 'lib/public/win64' 126 | else: 127 | out_folder = 'lib/public' 128 | 129 | self.renames[cxx.target.arch] = { 130 | 'tier0': tier0, 131 | 'tier1': tier1, 132 | 'vstdlib': vstdlib, 133 | 'mathlib': mathlib, 134 | } 135 | self.lib_folders[cxx.target.arch] = out_folder 136 | 137 | def BuildForArch(self, scripts, cxx): 138 | kv = { 139 | 'Root': self, 140 | } 141 | builder.cxx = cxx 142 | return builder.Build(scripts, kv) 143 | 144 | def SetArchFlags(self, compiler): 145 | if compiler.like('gcc'): 146 | if compiler.target.arch == 'x86': 147 | if not compiler.like('emscripten'): 148 | compiler.cflags += ['-msse'] 149 | else: 150 | compiler.cflags += ['-fPIC'] 151 | 152 | def ProgramBuilder(self, compiler, name): 153 | binary = compiler.Program(name) 154 | if binary.compiler.like('msvc'): 155 | binary.compiler.linkflags.append('/SUBSYSTEM:CONSOLE') 156 | return binary 157 | 158 | def Program(self, context, name): 159 | compiler = context.cxx.clone() 160 | self.SetArchFlags(compiler) 161 | return self.ProgramBuilder(compiler, name) 162 | 163 | def StaticLibraryBuilder(self, compiler, name): 164 | return compiler.StaticLibrary(name) 165 | 166 | def StaticLibrary(self, context, name): 167 | compiler = context.cxx.clone() 168 | self.SetArchFlags(compiler) 169 | return self.StaticLibraryBuilder(compiler, name) 170 | 171 | def LibraryBuilder(self, compiler, name): 172 | return compiler.Library(name) 173 | 174 | def Library(self, context, name): 175 | compiler = context.cxx.clone() 176 | self.SetArchFlags(compiler) 177 | return self.LibraryBuilder(compiler, name) 178 | 179 | def dist(self): 180 | for cxx in self.targets: 181 | builder.CallBuilder(lambda builder: self.copy_prebuilts(cxx, builder)) 182 | builder.CallBuilder(lambda builder: self.copy_dist(cxx, builder)) 183 | 184 | def copy_prebuilts(self, cxx, builder): 185 | # Naming is incredibly inconsistent. We copy CSGO layout. 186 | def rename(node, newname): 187 | base = os.path.basename(node) 188 | _, ext = os.path.splitext(base) 189 | return newname + ext 190 | 191 | def copy(node, key, *args, **kwargs): 192 | newname = self.renames[cxx.target.arch][key] 193 | return builder.AddCopy(node, rename(node.path, newname)) 194 | 195 | builder.SetBuildFolder(self.lib_folders[cxx.target.arch]) 196 | self.so_files[cxx.target.arch] = [ 197 | copy(self.tier0[cxx.target.arch], 'tier0'), 198 | copy(self.tier1[cxx.target.arch], 'tier1'), 199 | copy(self.mathlib[cxx.target.arch], 'mathlib'), 200 | copy(self.vstdlib[cxx.target.arch], 'vstdlib'), 201 | ] 202 | 203 | def copy_dist(self, cxx, builder): 204 | builder.SetBuildFolder('dist/{}'.format(cxx.target.arch)) 205 | builder.AddCopy(self.gamedll[cxx.target.arch], '.') 206 | builder.AddCopy(self.srcds[cxx.target.arch], '.') 207 | for so_file in self.so_files[cxx.target.arch]: 208 | builder.AddCopy(so_file, '.') 209 | 210 | root = Root() 211 | root.configure() 212 | root.build() 213 | root.dist() 214 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Mock HL2SDK 2 | ----------- 3 | 4 | This is a highly experimental and very incomplete "mock" of the HL2SDK. It's 5 | intended for testing of Metamod:Source, SourceMod, and other server plugins. 6 | You don't need to download Steam or srcds. There is no Valve code in the 7 | implementation. 8 | 9 | Most functionality is stubbed, but console commands and cvars work. 10 | 11 | # Usage 12 | 13 | You will need AMBuild. Make sure you've updated. It relies on AMBuild changes 14 | made on 9-22-2021. 15 | 16 | You will need to build both hl2sdk-mock and Metamod:Source: 17 | 18 | cd metamod-source 19 | python3 configure.py --sdks=mock --targets=x86_64 20 | ambuild objdir 21 | 22 | cd - 23 | cd hl2sdk-mock 24 | python3 configure.py --targets=x86_64 25 | ambuild objdir 26 | 27 | Once you have it built, you will need to make a gamedir. Because many plugins 28 | use real filesystem paths, we cannot expose a virtual filesystem. For ease of 29 | development you can use `build_gamedir.sh`. It creates a filesystem structure 30 | given a template directory, and then creates symlinks for all files. This eases 31 | development as you don't have to rsync or copy new files when you rebuild a 32 | plugin. 33 | 34 | For example: 35 | 36 | mkdir ~/gamedir 37 | bash build_gamedir.sh ~/gamedir ../metamod-source/objdir/package 38 | bash build_gamedir.sh ~/gamedir ../sourcemod/objdir/package 39 | 40 | Now you can launch mock srcds: 41 | 42 | ./objdir/dist/x86_64/srcds -game_dir ~/gamedir +map de_thunder 43 | 44 | By default the console is in interactive mode. While in interactive mode the 45 | server is paused and commands may be entered. Typing a command will cause it to 46 | be immediately processed. You can find available commands with "cvarlist". 47 | 48 | To put the server into "run" mode, you can use "run" or "continue". This will 49 | process "frames" until you enter Ctrl+C to re-enter interactive mode. 50 | 51 | We don't have a fully asynchronous interactive console like true srcds. It's 52 | quite tricky to do without lots of OS-specific console hacks. 53 | 54 | # Working Commands 55 | 56 | The following commands are implemented, in that they do something: 57 | 58 | - changelevel (any string is accepted as a map name) 59 | - continue (run frames, mock srcds specific) 60 | - cvarlist 61 | - exit 62 | - plugin\_load 63 | - quit 64 | - run (run frames, mock srcds specific) 65 | - think (run one frame, mock srcds specific) 66 | 67 | Commands/cvars added by Metamod, SourceMod, and other plugins will all be 68 | present as well. 69 | 70 | # Development 71 | 72 | Contributions are very welcome. 73 | 74 | After changing tier1, tier0, vstdlib, or mathlib mock sources, you will need to 75 | run update\_prebuilds.sh, and then rebuild any C++ plugins. For security 76 | reasons, we cannot accept third-party commits with prebuilts, but we can 77 | generate new ones as part of a pull request. 78 | 79 | As of this writing we do not use any Valve code to implement any function 80 | definition. The minimalist approach here was to reduce the amount of things we 81 | had to get working. If needed we can re-evaluate this: eg, maybe it makes sense 82 | to import something like mathlib from the public SDK. 83 | -------------------------------------------------------------------------------- /build_gamedir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # vim: set ts=8 sts=4 sw=4 tw=99 et: 3 | 4 | if [ $# -ne 2 ]; then 5 | echo "Usage: " 6 | exit 1; 7 | fi 8 | 9 | for i in $(find ${2} -printf '%P\n'); do 10 | srcpath=$(realpath ${2}/${i}) 11 | dstpath=${1}/${i} 12 | if [[ -d "${srcpath}" ]]; then 13 | mkdir -p "$dstpath" 14 | elif [ ! -f $dstpath ] && [ ! -L $dstpath ]; then 15 | ln -s "${srcpath}" "$dstpath" 16 | fi 17 | done 18 | -------------------------------------------------------------------------------- /configure.py: -------------------------------------------------------------------------------- 1 | # vim: set ts=2 sw=2 tw=99 noet ft=python: 2 | # 3 | # Copyright (C) 2004-2012 David Anderson 4 | # 5 | # This file is part of SourcePawn. 6 | # 7 | # SourcePawn is free software: you can redistribute it and/or modify it under 8 | # the terms of the GNU General Public License as published by the Free 9 | # Software Foundation, either version 3 of the License, or (at your option) 10 | # any later version. 11 | # 12 | # SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License along with 17 | # SourcePawn. If not, see http://www.gnu.org/licenses/. 18 | # 19 | import sys 20 | try: 21 | from ambuild2 import run, util 22 | except: 23 | try: 24 | import ambuild 25 | sys.stderr.write('It looks like you have AMBuild 1 installed, but this project uses AMBuild 2.\n') 26 | sys.stderr.write('Upgrade to the latest version of AMBuild to continue.\n') 27 | except: 28 | sys.stderr.write('AMBuild must be installed to build this project.\n') 29 | sys.stderr.write('http://www.alliedmods.net/ambuild\n') 30 | sys.exit(1) 31 | from pkg_resources import parse_version 32 | 33 | # Hack to show a decent upgrade message, which wasn't done until 2.2. 34 | ambuild_version = parse_version(getattr(run, 'CURRENT_API', '2.1')) 35 | if ambuild_version < parse_version("2.2.1"): 36 | sys.stderr.write("AMBuild 2.2.1 or higher is required; please update\n") 37 | sys.exit(1) 38 | 39 | parser = run.BuildParser(sourcePath=sys.path[0], api='2.2') 40 | parser.options.add_argument('--enable-debug', action='store_true', default = True, dest='debug', 41 | help='Enable debugging symbols') 42 | parser.options.add_argument('--enable-optimize', action='store_true', default = False, dest='opt', 43 | help='Enable optimization') 44 | parser.options.add_argument("--targets", type=str, default=None, 45 | help='Specify target architecture (use commas to include more than one)') 46 | parser.Configure() 47 | -------------------------------------------------------------------------------- /game/server/variant_t.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "ehandle.h" 5 | #include "datamap.h" 6 | #include "string_t.h" 7 | #include "Color.h" 8 | #include "vector.h" 9 | 10 | class CBaseEntity; 11 | 12 | class variant_t 13 | { 14 | CHandle eVal; 15 | fieldtype_t fieldType; 16 | 17 | public: 18 | void SetBool( bool b ) { fieldType = FIELD_BOOLEAN; } 19 | void SetString( string_t str ) {fieldType = FIELD_STRING; } 20 | void SetInt( int val ) { fieldType = FIELD_INTEGER; } 21 | void SetFloat( float val ) { fieldType = FIELD_FLOAT; } 22 | void SetEntity( CBaseEntity *val ); 23 | void SetVector3D( const Vector &val ) { fieldType = FIELD_VECTOR; } 24 | void SetPositionVector3D( const Vector &val ) { fieldType = FIELD_POSITION_VECTOR; } 25 | void SetColor32( color32 val ) { fieldType = FIELD_COLOR32; } 26 | void SetColor32( int r, int g, int b, int a ) { fieldType = FIELD_COLOR32; } 27 | }; 28 | -------------------------------------------------------------------------------- /gamedll/AMBuilder: -------------------------------------------------------------------------------- 1 | #! vim: set sts=4 sw=4 tw=99 et ft=python: 2 | import os 3 | 4 | binary = Root.Library(builder, 'gamedll') 5 | 6 | binary.sources += [ 7 | 'gamedll.cpp', 8 | 'tools.cpp', 9 | ] 10 | binary.compiler.cxxincludes += [ 11 | os.path.join(builder.sourcePath, 'public'), 12 | os.path.join(builder.sourcePath, 'public', 'tier0'), 13 | os.path.join(builder.sourcePath, 'public', 'tier1'), 14 | os.path.join(builder.sourcePath, 'third_party', 'amtl'), 15 | ] 16 | 17 | binary.compiler.postlink += [ 18 | Root.tier1[builder.cxx.target.arch], 19 | ] 20 | 21 | entry = builder.Add(binary).binary 22 | Root.gamedll[binary.compiler.target.arch] = entry 23 | -------------------------------------------------------------------------------- /gamedll/gamedll.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "gamedll.h" 3 | 4 | #include 5 | #include "tier0/platform.h" 6 | 7 | ServerGame sGame; 8 | PlayerInfoManager sPlayerManager; 9 | ServerGameClients sGameClients; 10 | ServerGameEnts sGameEnts; 11 | CGlobalVars* gpGlobals = nullptr; 12 | 13 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(ServerGame, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL, 14 | sGame); 15 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(PlayerInfoManager, IPlayerInfoManager, 16 | INTERFACEVERSION_PLAYERINFOMANAGER, sPlayerManager); 17 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(ServerGameClients, IServerGameClients, 18 | INTERFACEVERSION_SERVERGAMECLIENTS, sGameClients); 19 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(ServerGameEnts, IServerGameEnts, 20 | INTERFACEVERSION_SERVERGAMEENTS, sGameEnts); 21 | 22 | bool ServerGame::DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, 23 | CreateInterfaceFn fileSystemFactory, CGlobalVars *pGlobals) 24 | { 25 | gpGlobals = pGlobals; 26 | return true; 27 | } 28 | 29 | void 30 | ServerGame::DLLShutdown() 31 | { 32 | } 33 | 34 | bool 35 | ServerGame::LevelInit(char const* map, char const* entities, char const* old_level, 36 | char const* landmark, bool load_game, bool background) 37 | { 38 | return true; 39 | } 40 | 41 | void 42 | ServerGame::LevelShutdown() 43 | { 44 | } 45 | 46 | void ServerGame::ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) { 47 | } 48 | 49 | void ServerGame::ServerHibernationUpdate(bool bHibernating) { 50 | } 51 | 52 | const char* 53 | ServerGame::GetGameDescription() 54 | { 55 | return "Mock Game"; 56 | } 57 | 58 | bool 59 | ServerGame::GameInit() 60 | { 61 | return true; 62 | } 63 | 64 | bool 65 | ServerGame::GetUserMessageInfo(int msg_type, char* name, int maxlength, int& size) 66 | { 67 | if (msg_type == 0) { 68 | ke::SafeStrcpy(name, maxlength, "MockMsg"); 69 | size = 0; 70 | return true; 71 | } 72 | return false; 73 | } 74 | 75 | void 76 | ServerGame::GameFrame(bool simulating) 77 | { 78 | } 79 | 80 | void 81 | ServerGame::Think(bool final_tick) 82 | { 83 | } 84 | 85 | void ServerGame::OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, 86 | EQueryCvarValueStatus eStatus, const char *pCvarName, 87 | const char *pCvarValue) 88 | { 89 | } 90 | 91 | ServerClass* 92 | ServerGame::GetAllServerClasses() 93 | { 94 | return nullptr; 95 | } 96 | 97 | IPlayerInfo *PlayerInfoManager::GetPlayerInfo(edict_t *pEdict) { 98 | Error("%s not implemented", __func__); 99 | return nullptr; 100 | } 101 | 102 | CGlobalVars* 103 | PlayerInfoManager::GetGlobalVars() 104 | { 105 | return gpGlobals; 106 | } 107 | 108 | void 109 | ServerGameClients::ClientCommand(edict_t* edict, const CCommand& args) 110 | { 111 | Error("%s not implemented", __func__); 112 | } 113 | 114 | void 115 | ServerGameClients::ClientEarPosition(edict_t *pEntity, Vector *pEarOrigin) 116 | { 117 | Error("%s not implemented", __func__); 118 | } 119 | 120 | void 121 | ServerGameClients::ClientSettingsChanged(edict_t *pEdict) 122 | { 123 | Error("%s not implemented", __func__); 124 | } 125 | 126 | int 127 | ServerGameClients::GetMaxHumanPlayers() 128 | { 129 | return 16; 130 | } 131 | 132 | void 133 | ServerGameClients::ClientCommandKeyValues(edict_t *pEntity, KeyValues *pKeyValues) 134 | { 135 | Error("%s not implemented", __func__); 136 | } 137 | 138 | bool ServerGameClients::ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, 139 | char *reject, int maxrejectlen) { 140 | Error("%s not implemented", __func__); 141 | return true; 142 | } 143 | 144 | void ServerGameClients::ClientPutInServer( edict_t *pEntity, char const *playername) { 145 | Error("%s not implemented", __func__); 146 | } 147 | 148 | void ServerGameClients::ClientDisconnect(edict_t *pEntity) { 149 | Error("%s not implemented", __func__); 150 | } 151 | 152 | void ServerGameClients::SetCommandClient(int index) { 153 | } 154 | 155 | edict_t* ServerGameEnts::BaseEntityToEdict(CBaseEntity* ent) { 156 | Error("%s not implemented", __func__); 157 | return nullptr; 158 | } -------------------------------------------------------------------------------- /gamedll/gamedll.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "eiface.h" 5 | #include "game/server/iplayerinfo.h" 6 | 7 | class PlayerInfoManager final : public IPlayerInfoManager 8 | { 9 | public: 10 | IPlayerInfo *GetPlayerInfo(edict_t *pEdict) override; 11 | CGlobalVars *GetGlobalVars() override; 12 | }; 13 | 14 | class ServerGameClients final : public IServerGameClients 15 | { 16 | public: 17 | void ClientCommand(edict_t* edict, const CCommand& args) override; 18 | void ClientEarPosition(edict_t *pEntity, Vector *pEarOrigin) override; 19 | void ClientSettingsChanged(edict_t *pEdict) override; 20 | int GetMaxHumanPlayers() override; 21 | void ClientCommandKeyValues(edict_t *pEntity, KeyValues *pKeyValues) override; 22 | bool ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) override; 23 | void ClientPutInServer( edict_t *pEntity, char const *playername) override; 24 | void ClientDisconnect(edict_t *pEntity) override; 25 | void SetCommandClient(int index) override; 26 | }; 27 | 28 | class ServerGameEnts final : public IServerGameEnts 29 | { 30 | public: 31 | edict_t* BaseEntityToEdict(CBaseEntity* ent) override; 32 | }; 33 | 34 | class ServerGame final : public IServerGameDLL 35 | { 36 | public: 37 | bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, 38 | CreateInterfaceFn fileSystemFactory, CGlobalVars *pGlobals) override; 39 | void DLLShutdown() override; 40 | void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) override; 41 | void ServerHibernationUpdate(bool bHibernating) override; 42 | bool LevelInit(char const* map, char const* entities, char const* old_level, 43 | char const* landmark, bool load_game, bool background) override; 44 | void LevelShutdown() override; 45 | const char* GetGameDescription() override; 46 | bool GameInit() override; 47 | bool GetUserMessageInfo(int msg_type, char* name, int maxlength, int& size) override; 48 | ServerClass* GetAllServerClasses() override; 49 | void GameFrame(bool simulating) override; 50 | void Think(bool final_tick) override; 51 | void OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, 52 | EQueryCvarValueStatus eStatus, const char *pCvarName, 53 | const char *pCvarValue) override; 54 | }; 55 | -------------------------------------------------------------------------------- /gamedll/tools.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "tools.h" 3 | 4 | #include "tier0/dbg.h" 5 | #include "tier1/interface.h" 6 | 7 | static ServerTools sServerTools; 8 | 9 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(ServerTools, IServerTools, VSERVERTOOLS_INTERFACE_VERSION, 10 | sServerTools); 11 | 12 | void* ServerTools::CreateEntityByName(const char *szClassName) { 13 | Error("%s not implemented", __func__); 14 | return nullptr; 15 | } 16 | 17 | void ServerTools::DispatchSpawn(void *pEntity) { 18 | Error("%s not implemented", __func__); 19 | } 20 | 21 | bool ServerTools::SetKeyValue(void *pEntity, const char *szField, const char *szValue) { 22 | Error("%s not implemented", __func__); 23 | return false; 24 | } 25 | 26 | bool ServerTools::SetKeyValue(void *pEntity, const char *szField, float flValue) { 27 | Error("%s not implemented", __func__); 28 | return false; 29 | } 30 | 31 | bool ServerTools::SetKeyValue(void *pEntity, const char *szField, const Vector &vecValue) { 32 | Error("%s not implemented", __func__); 33 | return false; 34 | } 35 | 36 | EntitySearchResult ServerTools::NextEntity(EntitySearchResult iter) { 37 | Error("%s not implemented", __func__); 38 | return nullptr; 39 | } 40 | -------------------------------------------------------------------------------- /gamedll/tools.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "toolframework/itoolentity.h" 5 | 6 | class ServerTools : public IServerTools 7 | { 8 | public: 9 | void *CreateEntityByName(const char *szClassName) override; 10 | void DispatchSpawn(void *pEntity) override; 11 | EntitySearchResult NextEntity(EntitySearchResult iter) override; 12 | bool SetKeyValue(void *pEntity, const char *szField, const char *szValue) override; 13 | bool SetKeyValue(void *pEntity, const char *szField, float flValue) override; 14 | bool SetKeyValue(void *pEntity, const char *szField, const Vector &vecValue) override; 15 | }; 16 | -------------------------------------------------------------------------------- /lib/linux/mathlib_i486.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/lib/linux/mathlib_i486.a -------------------------------------------------------------------------------- /lib/linux/tier0_i486.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/lib/linux/tier0_i486.so -------------------------------------------------------------------------------- /lib/linux/tier1_i486.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/lib/linux/tier1_i486.a -------------------------------------------------------------------------------- /lib/linux/vstdlib_i486.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/lib/linux/vstdlib_i486.so -------------------------------------------------------------------------------- /lib/linux64/libtier0_client.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/lib/linux64/libtier0_client.so -------------------------------------------------------------------------------- /lib/linux64/libvstdlib_client.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/lib/linux64/libvstdlib_client.so -------------------------------------------------------------------------------- /lib/linux64/mathlib.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/lib/linux64/mathlib.a -------------------------------------------------------------------------------- /lib/linux64/tier1.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/lib/linux64/tier1.a -------------------------------------------------------------------------------- /mathlib/AMBuilder: -------------------------------------------------------------------------------- 1 | #! vim: set sts=4 sw=4 tw=99 et ft=python: 2 | import os 3 | 4 | binary = Root.StaticLibrary(builder, 'mathlib') 5 | 6 | binary.sources += [ 7 | 'mathlib.cpp', 8 | ] 9 | binary.compiler.cxxincludes += [ 10 | os.path.join(builder.sourcePath, 'public'), 11 | os.path.join(builder.sourcePath, 'public', 'tier0'), 12 | os.path.join(builder.sourcePath, 'third_party', 'amtl'), 13 | ] 14 | 15 | Root.mathlib[binary.compiler.target.arch] = builder.Add(binary).binary 16 | -------------------------------------------------------------------------------- /mathlib/mathlib.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | 3 | #include "mathlib/mathlib.h" 4 | 5 | const Vector vec3_origin(0, 0, 0); 6 | -------------------------------------------------------------------------------- /public/Color.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "tier0/platform.h" 5 | 6 | struct color32 { 7 | byte r, g, b, a; 8 | }; 9 | 10 | class Color 11 | { 12 | public: 13 | Color() : rgba() {} 14 | Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) 15 | { 16 | rgba[0] = r; 17 | rgba[1] = g; 18 | rgba[2] = b; 19 | rgba[3] = a; 20 | } 21 | int r() const { return rgba[0]; } 22 | int g() const { return rgba[1]; } 23 | int b() const { return rgba[2]; } 24 | int a() const { return rgba[3]; } 25 | unsigned char rgba[4]; 26 | }; 27 | -------------------------------------------------------------------------------- /public/SoundEmitterSystem/isoundemittersystembase.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "IEngineSound.h" 5 | #include "utlsymbol.h" 6 | 7 | enum gender_t 8 | { 9 | GENDER_NONE = 0, 10 | GENDER_MALE, 11 | GENDER_FEMALE, 12 | }; 13 | 14 | struct SoundFile 15 | { 16 | CUtlSymbol symbol; 17 | }; 18 | 19 | struct CSoundParameters 20 | { 21 | int channel = CHAN_AUTO; 22 | int pitch = PITCH_NORM; 23 | soundlevel_t soundlevel = SNDLVL_NORM; 24 | float volume = VOL_NORM; 25 | char soundname[128] = {}; 26 | }; 27 | 28 | struct CSoundParametersInternal 29 | { 30 | int NumSoundNames() const { return 0; } 31 | SoundFile* GetSoundNames() { return nullptr; } 32 | }; 33 | 34 | static constexpr char SOUNDEMITTERSYSTEM_INTERFACE_VERSION[] = "VSoundEmitter003"; 35 | 36 | class ISoundEmitterSystemBase 37 | { 38 | public: 39 | virtual int GetSoundIndex(const char *pName) const = 0; 40 | virtual bool IsValidIndex(int index) = 0; 41 | virtual gender_t GetActorGender(char const *actormodel) = 0; 42 | virtual bool GetParametersForSoundEx(const char *soundname, HSOUNDSCRIPTHASH& handle, 43 | CSoundParameters& params, gender_t gender, 44 | bool isbeingemitted = false) = 0; 45 | virtual CSoundParametersInternal *InternalGetParametersForSound(int index) = 0; 46 | virtual const char *GetWaveName(CUtlSymbol& sym) = 0; 47 | }; 48 | -------------------------------------------------------------------------------- /public/basehandle.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "const.h" 5 | 6 | class IHandleEntity; 7 | 8 | class CBaseHandle 9 | { 10 | public: 11 | CBaseHandle() : index_(INVALID_EHANDLE_INDEX) {} 12 | CBaseHandle(unsigned long index) : index_(index) {} 13 | int ToInt() const { return 0; } 14 | void Term() {} 15 | int GetEntryIndex() const { return 0; } 16 | int GetSerialNumber() const { return 0; } 17 | const CBaseHandle& Set(const IHandleEntity *pEntity) { 18 | (void)pEntity; 19 | return *this; 20 | } 21 | bool IsValid() const { return index_ != INVALID_EHANDLE_INDEX; } 22 | 23 | bool operator ==(unsigned long index) const { 24 | return index_ == index; 25 | } 26 | bool operator !=(const CBaseHandle& other) const { 27 | return index_ != other.index_; 28 | } 29 | 30 | IHandleEntity* Get() const { 31 | return nullptr; 32 | } 33 | 34 | private: 35 | unsigned long index_; 36 | }; 37 | -------------------------------------------------------------------------------- /public/bitvec.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | template 5 | class CBitVec 6 | { 7 | public: 8 | int FindNextSetBit(int index) { return -1; } 9 | }; 10 | 11 | typedef CBitVec<255> CPlayerBitVec; 12 | -------------------------------------------------------------------------------- /public/cdll_int.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | struct player_info_t { 5 | CRC32_t customFiles[MAX_CUSTOM_FILES]; 6 | }; 7 | -------------------------------------------------------------------------------- /public/cmodel.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | struct csurface_t 5 | { 6 | const char* name; 7 | short surfaceProps; 8 | unsigned short flags; 9 | }; 10 | -------------------------------------------------------------------------------- /public/const.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | typedef unsigned long CRC32_t; 7 | 8 | static constexpr int INVALID_EHANDLE_INDEX = -1; 9 | static constexpr int MAX_LIGHTSTYLES = 64; 10 | static constexpr int MAX_CUSTOM_FILES = 4; 11 | static constexpr int MAX_EDICT_BITS = 11; 12 | static constexpr int MAX_EDICTS = (1 << MAX_EDICT_BITS); 13 | static constexpr int NUM_ENT_ENTRY_BITS = (MAX_EDICT_BITS + 2); 14 | static constexpr int NUM_ENT_ENTRIES = (1 << NUM_ENT_ENTRY_BITS); 15 | static constexpr int ABSOLUTE_PLAYER_LIMIT = 255; 16 | static constexpr int MAX_PLAYER_NAME_LENGTH = 32; 17 | static constexpr int LIFE_ALIVE = 0; 18 | 19 | #define MASK_ALL (0xffffffff) 20 | #define MAX_COORD_INTEGER (16384) 21 | #define COORD_EXTENT (2*MAX_COORD_INTEGER) 22 | #define MAX_TRACE_LENGTH (1.732050807569 * COORD_EXTENT) 23 | 24 | enum USE_TYPE 25 | { 26 | USE_OFF = 0, 27 | USE_ON = 1, 28 | USE_SET = 2, 29 | USE_TOGGLE = 3 30 | }; 31 | 32 | static constexpr int FL_ONGROUND = (1<<0); // At rest / on the ground 33 | static constexpr int FL_DUCKING = (1<<1); // Player flag -- Player is fully crouched 34 | static constexpr int FL_WATERJUMP = (1<<3); // player jumping out of water 35 | static constexpr int FL_ONTRAIN = (1<<4); // Player is _controlling_ a train, so movement commands should be ignored on client during prediction. 36 | static constexpr int FL_INRAIN = (1<<5); // Indicates the entity is standing in rain 37 | static constexpr int FL_FROZEN = (1<<6); // Player is frozen for 3rd person camera 38 | static constexpr int FL_ATCONTROLS = (1<<7); // Player can't move, but keeps key inputs for controlling another entity 39 | static constexpr int FL_CLIENT = (1<<8); // Is a player 40 | static constexpr int FL_FAKECLIENT = (1<<9); // Fake client, simulated server side; don't send network messages to them 41 | static constexpr int FL_INWATER = (1<<10); // In water 42 | static constexpr int PLAYER_FLAG_BITS = 11; 43 | static constexpr int FL_FLY = (1<<11); // Changes the SV_Movestep(); behavior to not need to be on ground 44 | static constexpr int FL_SWIM = (1<<12); // Changes the SV_Movestep(); behavior to not need to be on ground = (but stay in water); 45 | static constexpr int FL_CONVEYOR = (1<<13); 46 | static constexpr int FL_NPC = (1<<14); 47 | static constexpr int FL_GODMODE = (1<<15); 48 | static constexpr int FL_NOTARGET = (1<<16); 49 | static constexpr int FL_AIMTARGET = (1<<17); // set if the crosshair needs to aim onto the entity 50 | static constexpr int FL_PARTIALGROUND = (1<<18); // not all corners are valid 51 | static constexpr int FL_STATICPROP = (1<<19); // Eetsa static prop! 52 | static constexpr int FL_GRAPHED = (1<<20); // worldgraph has this ent listed as something that blocks a connection 53 | static constexpr int FL_GRENADE = (1<<21); 54 | static constexpr int FL_STEPMOVEMENT = (1<<22); // Changes the SV_Movestep(); behavior to not do any processing 55 | static constexpr int FL_DONTTOUCH = (1<<23); // Doesn't generate touch functions, generates Untouch(); for anything it was touching when this flag was set 56 | static constexpr int FL_BASEVELOCITY = (1<<24); // Base velocity has been applied this frame = (used to convert base velocity into momentum); 57 | static constexpr int FL_WORLDBRUSH = (1<<25); // Not moveable/removeable brush entity = (really part of the world, but represented as an entity for transparency or something); 58 | static constexpr int FL_OBJECT = (1<<26); // Terrible name. This is an object that NPCs should see. Missiles, for example. 59 | static constexpr int FL_KILLME = (1<<27); // This entity is marked for death -- will be freed by game DLL 60 | static constexpr int FL_ONFIRE = (1<<28); // You know... 61 | static constexpr int FL_DISSOLVING = (1<<29); // We're dissolving! 62 | static constexpr int FL_TRANSRAGDOLL = (1<<30); // In the process of turning into a client side ragdoll. 63 | static constexpr int FL_UNBLOCKABLE_BY_PLAYER = (1<<31); // pusher that can't be blocked by the player 64 | -------------------------------------------------------------------------------- /public/datamap.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "dt_send.h" 5 | #include "basehandle.h" 6 | 7 | class CBaseEntity; 8 | 9 | struct inputdata_t; 10 | typedef void (CBaseEntity::*inputfunc_t)(inputdata_t& data); 11 | 12 | static constexpr int FTYPEDESC_GLOBAL = 0x0001; 13 | static constexpr int FTYPEDESC_SAVE = 0x0002; 14 | static constexpr int FTYPEDESC_KEY = 0x0004; 15 | static constexpr int FTYPEDESC_INPUT = 0x0008; 16 | static constexpr int FTYPEDESC_OUTPUT = 0x0010; 17 | static constexpr int FTYPEDESC_FUNCTIONTABLE = 0x0020; 18 | static constexpr int FTYPEDESC_PTR = 0x0040; 19 | static constexpr int FTYPEDESC_OVERRIDE = 0x0080; 20 | static constexpr int FTYPEDESC_INSENDTABLE = 0x0100; 21 | static constexpr int FTYPEDESC_PRIVATE = 0x0200; 22 | static constexpr int FTYPEDESC_NOERRORCHECK = 0x0400; 23 | static constexpr int FTYPEDESC_MODELINDEX = 0x0800; 24 | static constexpr int FTYPEDESC_INDEX = 0x1000; 25 | static constexpr int FTYPEDESC_VIEW_OTHER_PLAYER = 0x2000; 26 | static constexpr int FTYPEDESC_VIEW_OWN_TEAM = 0x4000; 27 | static constexpr int FTYPEDESC_VIEW_NEVER = 0x8000; 28 | 29 | enum fieldtype_t 30 | { 31 | FIELD_VOID = 0, 32 | FIELD_FLOAT, 33 | FIELD_STRING, 34 | FIELD_VECTOR, 35 | FIELD_QUATERNION, 36 | FIELD_INTEGER, 37 | FIELD_BOOLEAN, 38 | FIELD_SHORT, 39 | FIELD_CHARACTER, 40 | FIELD_COLOR32, 41 | FIELD_EMBEDDED, 42 | FIELD_CUSTOM, 43 | FIELD_CLASSPTR, 44 | FIELD_EHANDLE, 45 | FIELD_EDICT, 46 | FIELD_POSITION_VECTOR, 47 | FIELD_TIME, 48 | FIELD_TICK, 49 | FIELD_MODELNAME, 50 | FIELD_SOUNDNAME, 51 | FIELD_INPUT, 52 | FIELD_FUNCTION, 53 | FIELD_VMATRIX, 54 | FIELD_VMATRIX_WORLDSPACE, 55 | FIELD_MATRIX3X4_WORLDSPACE, 56 | FIELD_INTERVAL, 57 | FIELD_MODELINDEX, 58 | FIELD_MATERIALINDEX, 59 | FIELD_VECTOR2D, 60 | FIELD_INTEGER64, 61 | FIELD_VECTOR4D, 62 | FIELD_TYPECOUNT, 63 | }; 64 | typedef fieldtype_t _fieldtypes; 65 | 66 | struct datamap_t; 67 | 68 | struct typedescription_t { 69 | const char* fieldName; 70 | const char* externalName; 71 | int fieldOffset; 72 | int flags; 73 | datamap_t* td; 74 | int fieldSizeInBytes; 75 | inputfunc_t inputFunc; 76 | fieldtype_t fieldType; 77 | unsigned short fieldSize; 78 | }; 79 | 80 | struct datamap_t { 81 | int dataNumFields; 82 | typedescription_t* dataDesc; 83 | datamap_t* baseMap; 84 | char const* dataClassName; 85 | }; 86 | -------------------------------------------------------------------------------- /public/dt_send.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class CSendProxyRecipients; 5 | class SendProp; 6 | 7 | class DVariant; 8 | 9 | typedef int (*ArrayLengthSendProxyFn)(const void *, int); 10 | typedef void* (*SendTableProxyFn)(const SendProp*, const void*, const void*, CSendProxyRecipients*, 11 | int); 12 | typedef void(*SendVarProxyFn)(const SendProp*, const void*, const void*, DVariant*, int, int); 13 | 14 | static constexpr int DT_MAX_STRING_BITS = 9; 15 | static constexpr int DT_MAX_STRING_BUFFERSIZE = (1 << DT_MAX_STRING_BITS); 16 | 17 | static constexpr int SPROP_UNSIGNED = (1<<0); 18 | static constexpr int SPROP_COORD = (1<<1); 19 | static constexpr int SPROP_NOSCALE = (1<<2); 20 | static constexpr int SPROP_ROUNDDOWN = (1<<3); 21 | static constexpr int SPROP_ROUNDUP = (1<<4); 22 | static constexpr int SPROP_NORMAL = (1<<5); 23 | static constexpr int SPROP_EXCLUDE = (1<<6); 24 | static constexpr int SPROP_XYZE = (1<<7); 25 | static constexpr int SPROP_INSIDEARRAY = (1<<8); 26 | static constexpr int SPROP_PROXY_ALWAYS_YES = (1<<9); 27 | static constexpr int SPROP_IS_A_VECTOR_ELEM = (1<<10); 28 | static constexpr int SPROP_COLLAPSIBLE = (1<<11); 29 | static constexpr int SPROP_COORD_MP = (1<<12); 30 | static constexpr int SPROP_COORD_MP_LOWPRECISION = (1<<13); 31 | static constexpr int SPROP_COORD_MP_INTEGRAL = (1<<14); 32 | static constexpr int SPROP_CELL_COORD = (1<<15); 33 | static constexpr int SPROP_CELL_COORD_LOWPRECISION = (1<<16); 34 | static constexpr int SPROP_CELL_COORD_INTEGRAL = (1<<17); 35 | static constexpr int SPROP_CHANGES_OFTEN = (1<<18); 36 | static constexpr int SPROP_VARINT = (1<<19); 37 | static constexpr int SPROP_NUMFLAGBITS_NETWORKED = 19; 38 | 39 | enum SendPropType 40 | { 41 | DPT_Int=0, 42 | DPT_Float, 43 | DPT_Vector, 44 | DPT_VectorXY, 45 | DPT_String, 46 | DPT_Array, 47 | DPT_DataTable, 48 | DPT_Int64, 49 | DPT_NUMSendPropTypes 50 | }; 51 | 52 | class SendProp 53 | { 54 | public: 55 | const char* GetName() const { return m_Name; } 56 | int GetOffset() const { return m_Offset; } 57 | SendPropType GetType() const { return m_Type; } 58 | ArrayLengthSendProxyFn GetArrayLengthProxy() const { return nullptr; } 59 | SendTableProxyFn GetDataTableProxyFn() const { return nullptr; } 60 | SendVarProxyFn GetProxyFn() const { return nullptr; } 61 | int GetNumElements() const { return m_nElements; } 62 | int GetElementStride() const { return m_ElementStride; } 63 | SendProp* GetArrayProp() const { return nullptr; } 64 | SendTable* GetDataTable() const { return nullptr; } 65 | int GetFlags() const { return 0; } 66 | bool IsInsideArray() const { return false; } 67 | const void* GetExtraData() const { return nullptr; } 68 | 69 | const char* m_Name; 70 | int m_nBits; 71 | SendPropType m_Type; 72 | int m_Offset; 73 | int m_nElements; 74 | int m_ElementStride; 75 | }; 76 | 77 | class SendTable 78 | { 79 | public: 80 | int GetNumProps() const { return 0; } 81 | SendProp* GetProp(int i) const { return nullptr; } 82 | const char* GetName() { return nullptr; } 83 | }; 84 | 85 | class CSendProxyRecipients 86 | { 87 | public: 88 | }; 89 | 90 | class DVariant 91 | { 92 | public: 93 | DVariant() {} 94 | explicit DVariant(const char* str) 95 | : m_pString(str) 96 | {} 97 | 98 | const char* m_pString; 99 | }; 100 | -------------------------------------------------------------------------------- /public/edict.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "gametrace.h" 5 | #include "icollideable.h" 6 | #include "iserverentity.h" 7 | #include "iservernetworkable.h" 8 | #include "iserverunknown.h" 9 | 10 | static constexpr int FL_EDICT_CHANGED = (1<<0); 11 | 12 | class IChangeInfoAccessor 13 | { 14 | public: 15 | }; 16 | 17 | class CBaseEdict 18 | { 19 | public: 20 | IServerEntity* GetIServerEntity() { return nullptr; } 21 | const IServerEntity* GetIServerEntity() const { return nullptr; } 22 | IChangeInfoAccessor *GetChangeAccessor(); 23 | const IChangeInfoAccessor *GetChangeAccessor() const; 24 | }; 25 | 26 | struct edict_t : public CBaseEdict 27 | { 28 | bool IsFree() const { return false; } 29 | IServerNetworkable* GetNetworkable() const { return nullptr; } 30 | IServerUnknown* GetUnknown() const { return nullptr; } 31 | ICollideable* GetCollideable() const { return nullptr; } 32 | void StateChanged() {} 33 | void StateChanged(unsigned short offset) {} 34 | 35 | int m_fStateFlags; 36 | }; 37 | 38 | class CGlobalVars { 39 | public: 40 | edict_t* pEdicts; 41 | int maxEntities; 42 | float curtime; 43 | int tickcount; 44 | float frametime; 45 | string_t mapname; 46 | float interval_per_tick; 47 | int maxClients; 48 | }; 49 | 50 | class CSharedEdictChangeInfo 51 | { 52 | public: 53 | }; 54 | -------------------------------------------------------------------------------- /public/ehandle.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "basehandle.h" 5 | 6 | template 7 | class CHandle : public CBaseHandle 8 | { 9 | public: 10 | CHandle(); 11 | CHandle(T *val); 12 | T* Get() const; 13 | void Set(const T* val); 14 | }; 15 | 16 | template 17 | CHandle::CHandle() 18 | { 19 | } 20 | 21 | template 22 | CHandle::CHandle(T *val) 23 | { 24 | Term(); 25 | Set(val); 26 | } 27 | 28 | template 29 | inline T* CHandle::Get() const 30 | { 31 | return (T*)CBaseHandle::Get(); 32 | } 33 | 34 | template 35 | void CHandle::Set(const T* val) 36 | { 37 | CBaseHandle::Set(reinterpret_cast(val)); 38 | } 39 | -------------------------------------------------------------------------------- /public/eiface.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "bitvec.h" 5 | #include "const.h" 6 | #include "convar.h" 7 | #include "edict.h" 8 | #include "engine/iserverplugin.h" 9 | #include "engine/IEngineSound.h" 10 | #include "game/server/iplayerinfo.h" 11 | #include "inetchannelinfo.h" 12 | #include "iserverentity.h" 13 | #include "mathlib/mathlib.h" 14 | #include "networkstringtabledefs.h" 15 | #include "string_t.h" 16 | #include "tier0/dbg.h" 17 | #include "tier0/logging.h" 18 | #include "tier0/mem.h" 19 | #include "tier1/strtools.h" 20 | 21 | static constexpr char INTERFACEVERSION_SERVERGAMEDLL[] = "ServerGameDLL005"; 22 | static constexpr char INTERFACEVERSION_VENGINESERVER[] = "VEngineServer023"; 23 | 24 | typedef int QueryCvarCookie_t; 25 | static constexpr int InvalidQueryCvarCookie = -1; 26 | 27 | class IServerGameDLL 28 | { 29 | public: 30 | virtual bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, 31 | CreateInterfaceFn fileSystemFactory, CGlobalVars *pGlobals) = 0; 32 | virtual void DLLShutdown() = 0; 33 | virtual bool LevelInit(char const* map, char const* entities, char const* old_level, 34 | char const* landmark, bool load_game, bool background) = 0; 35 | virtual void LevelShutdown() = 0; 36 | virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) = 0; 37 | virtual void ServerHibernationUpdate(bool bHibernating) = 0; 38 | virtual const char* GetGameDescription() = 0; 39 | virtual bool GameInit() = 0; 40 | virtual bool GetUserMessageInfo(int msg_type, char* name, int maxlength, int& size) = 0; 41 | virtual ServerClass* GetAllServerClasses() = 0; 42 | virtual void GameFrame(bool simulating) = 0; 43 | virtual void Think(bool final_tick) = 0; 44 | virtual void OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, 45 | EQueryCvarValueStatus eStatus, const char *pCvarName, 46 | const char *pCvarValue) = 0; 47 | }; 48 | 49 | class bf_write; 50 | class CSteamID; 51 | class IRecipientFilter; 52 | class SendTable; 53 | struct player_info_t; 54 | 55 | class IVEngineServer 56 | { 57 | public: 58 | virtual void ClientPrintf(edict_t* edict, const char* msg) = 0; 59 | virtual void ServerCommand(const char* str) = 0; 60 | virtual void LogPrint(const char* msg) = 0; 61 | virtual void GetGameDir(char* buffer, int length) = 0; 62 | virtual bool IsDedicatedServer() = 0; 63 | virtual void SetView(edict_t* client, edict_t* view_ent) = 0; 64 | virtual void LightStyle(int style, const char* val) = 0; 65 | virtual void PlaybackTempEntity(IRecipientFilter& filter, float delay, const void* sender, 66 | const SendTable* st, int classID) = 0; 67 | virtual edict_t* CreateFakeClient(const char* name) = 0; 68 | virtual bool LockNetworkStringTables(bool lock) = 0; 69 | virtual INetChannelInfo* GetPlayerNetInfo(int playerIndex) = 0; 70 | virtual void EmitAmbientSound(int entindex, const Vector &pos, const char *samp, float vol, 71 | soundlevel_t soundlevel, int fFlags, int pitch, 72 | float delay = 0.0f) = 0; 73 | virtual void FadeClientVolume(const edict_t *pEdict, float fadePercent, float fadeOutSeconds, 74 | float holdTime, float fadeInSeconds) = 0; 75 | virtual bool GetPlayerInfo(int ent_num, player_info_t *pinfo) = 0; 76 | virtual int PrecacheModel(const char *s, bool preload = false) = 0; 77 | virtual int PrecacheSentenceFile(const char *s, bool preload = false) = 0; 78 | virtual int PrecacheDecal(const char *name, bool preload = false) = 0; 79 | virtual int PrecacheGeneric(const char *s, bool preload = false) = 0; 80 | virtual void SetFakeClientConVarValue(edict_t *pEntity, const char *cvar, const char *value) = 0; 81 | virtual bool IsModelPrecached(char const *s) const = 0; 82 | virtual bool IsDecalPrecached(char const *s) const = 0; 83 | virtual bool IsGenericPrecached(char const *s) const = 0; 84 | virtual void Message_DetermineMulticastRecipients(bool usepas, const Vector& origin, CPlayerBitVec& playerbits) = 0; 85 | virtual edict_t *CreateEdict(int iForceEdictIndex = -1) = 0; 86 | virtual void RemoveEdict(edict_t *e) = 0; 87 | virtual int GetEntityCount() = 0; 88 | virtual void ServerExecute() = 0; 89 | virtual int GetPlayerUserId(const edict_t *e) = 0; 90 | virtual void InsertServerCommand(const char *str) = 0; 91 | virtual const char* GetClientConVarValue(int clientIndex, const char *name) = 0; 92 | virtual void ClientCommand(edict_t *pEdict, const char *szFmt, ...) = 0; 93 | virtual QueryCvarCookie_t StartQueryCvarValue(edict_t *pPlayerEntity, const char *pName) = 0; 94 | virtual bf_write* UserMessageBegin(IRecipientFilter *filter, int msg_type, const char* name) = 0; 95 | virtual void MessageEnd() = 0; 96 | virtual const char* GetPlayerNetworkIDString(const edict_t *e) = 0; 97 | virtual const CSteamID* GetClientSteamID(edict_t *pPlayerEdict) = 0; 98 | virtual bool IsClientFullyAuthenticated(edict_t *pEdict) = 0; 99 | virtual void ChangeLevel(const char *s1, const char *s2) = 0; 100 | virtual CSharedEdictChangeInfo* GetSharedEdictChangeInfo() = 0; 101 | virtual IChangeInfoAccessor* GetChangeAccessor(const edict_t *pEdict) = 0; 102 | virtual int IsMapValid(const char *filename) = 0; 103 | virtual const char *GetMapEntitiesString() = 0; 104 | }; 105 | 106 | static constexpr char INTERFACEVERSION_SERVERGAMECLIENTS[] = "ServerGameClients004"; 107 | 108 | class IServerGameClients 109 | { 110 | public: 111 | virtual void ClientCommand(edict_t* edict, const CCommand& args) = 0; 112 | virtual void ClientEarPosition(edict_t *pEntity, Vector *pEarOrigin) = 0; 113 | virtual void ClientSettingsChanged(edict_t *pEdict) = 0; 114 | virtual int GetMaxHumanPlayers() = 0; 115 | virtual void ClientCommandKeyValues(edict_t *pEntity, KeyValues *pKeyValues) = 0; 116 | virtual bool ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) = 0; 117 | virtual void ClientPutInServer(edict_t *pEntity, char const *playername) = 0; 118 | virtual void ClientDisconnect(edict_t *pEntity) = 0; 119 | virtual void SetCommandClient(int index) = 0; 120 | }; 121 | 122 | static constexpr char INTERFACEVERSION_SERVERGAMEENTS[] = "ServerGameEnts001"; 123 | 124 | class CBaseEntity; 125 | 126 | class IServerGameEnts 127 | { 128 | public: 129 | virtual edict_t* BaseEntityToEdict(CBaseEntity* ent) = 0; 130 | }; 131 | -------------------------------------------------------------------------------- /public/engine/IEngineSound.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "tier1/utlvector.h" 5 | 6 | class IRecipientFilter; 7 | class Vector; 8 | 9 | typedef unsigned int HSOUNDSCRIPTHASH; 10 | 11 | static constexpr int CHAN_AUTO = 0; 12 | static constexpr int PITCH_NORM = 100; 13 | static constexpr float VOL_NORM = 1.0f; 14 | static constexpr float ATTN_NORM = 0.8f; 15 | 16 | #define ATTN_TO_SNDLVL(a) (soundlevel_t)(int)((a) ? (50 + 20 / ((float)a)) : 0 ) 17 | #define SNDLVL_TO_ATTN( a ) ( (a > 50) ? (20.0f / (float)(a - 50)) : ( (a == 0) ? (0.0f) : (4.0f) ) ) 18 | 19 | enum soundlevel_t { 20 | SNDLVL_NORM = 75, 21 | SNDLVL_MAX = 255 22 | }; 23 | 24 | static constexpr char IENGINESOUND_SERVER_INTERFACE_VERSION[] = "IEngineSoundServer003"; 25 | 26 | class IEngineSound 27 | { 28 | public: 29 | virtual int EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, 30 | const char *pSoundEntry, unsigned int nSoundEntryHash, 31 | const char *pSample, float flVolume, float flAttenuation, 32 | int nSeed, int iFlags = 0, int iPitch = PITCH_NORM, 33 | const Vector *pOrigin = nullptr, const Vector *pDirection = nullptr, 34 | CUtlVector* pUtlVecOrigins = nullptr, 35 | bool bUpdatePositions = true, float soundtime = 0.0f, 36 | int speakerentity = -1) = 0; 37 | 38 | virtual int EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, 39 | const char *pSoundEntry, unsigned int nSoundEntryHash, 40 | const char *pSample, float flVolume, soundlevel_t level, 41 | int nSeed, int iFlags = 0, int iPitch = PITCH_NORM, 42 | const Vector *pOrigin = nullptr, const Vector *pDirection = nullptr, 43 | CUtlVector* pUtlVecOrigins = nullptr, 44 | bool bUpdatePositions = true, float soundtime = 0.0f, 45 | int speakerentity = -1) = 0; 46 | virtual void EmitSentenceByIndex(IRecipientFilter& filter, int iEntIndex, int iChannel, 47 | int iSentenceIndex, float flVolume, soundlevel_t iSoundlevel, 48 | int nSeed, int iFlags = 0, int iPitch = PITCH_NORM, 49 | const Vector *pOrigin = nullptr, 50 | const Vector *pDirection = nullptr, 51 | CUtlVector* pUtlVecOrigins = nullptr, 52 | bool bUpdatePositions = true, float soundtime = 0.0f, 53 | int speakerentity = -1) = 0; 54 | 55 | 56 | virtual bool PrecacheSound(const char *pSample, bool bPreload = false, bool bIsUISound = false) = 0; 57 | virtual void PrefetchSound(const char *pSample) = 0; 58 | virtual float GetSoundDuration(const char *pSample) = 0; 59 | virtual void StopSound(int iEntIndex, int iChannel, const char *pSample, unsigned int nSoundEntryHash) = 0; 60 | virtual float GetDistGainFromSoundLevel(soundlevel_t soundlevel, float dist) = 0; 61 | virtual bool IsSoundPrecached(const char *pSample) = 0; 62 | }; 63 | -------------------------------------------------------------------------------- /public/engine/IEngineTrace.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "const.h" 5 | #include "mathlib/vector.h" 6 | 7 | static constexpr char INTERFACEVERSION_ENGINETRACE_SERVER[] = "EngineTraceServer003"; 8 | 9 | static constexpr int CONTENTS_EMPTY = 0; 10 | static constexpr int CONTENTS_SOLID = 0x1; 11 | static constexpr int CONTENTS_WINDOW = 0x2; 12 | static constexpr int CONTENTS_AUX = 0x4; 13 | static constexpr int CONTENTS_GRATE = 0x8; 14 | static constexpr int CONTENTS_SLIME = 0x10; 15 | static constexpr int CONTENTS_WATER = 0x20; 16 | static constexpr int CONTENTS_BLOCKLOS = 0x40; 17 | static constexpr int CONTENTS_OPAQUE = 0x80; 18 | static constexpr int CONTENTS_TESTFOGVOLUME = 0x100; 19 | static constexpr int CONTENTS_UNUSED = 0x200; 20 | static constexpr int CONTENTS_BLOCKLIGHT = 0x400; 21 | static constexpr int CONTENTS_TEAM1 = 0x800; 22 | static constexpr int CONTENTS_TEAM2 = 0x1000; 23 | static constexpr int CONTENTS_IGNORE_NODRAW_OPAQUE = 0x2000; 24 | static constexpr int CONTENTS_MOVEABLE = 0x4000; 25 | static constexpr int CONTENTS_AREAPORTAL = 0x8000; 26 | static constexpr int CONTENTS_PLAYERCLIP = 0x10000; 27 | static constexpr int CONTENTS_MONSTERCLIP = 0x20000; 28 | static constexpr int CONTENTS_CURRENT_0 = 0x40000; 29 | static constexpr int CONTENTS_CURRENT_90 = 0x80000; 30 | static constexpr int CONTENTS_CURRENT_180 = 0x100000; 31 | static constexpr int CONTENTS_CURRENT_270 = 0x200000; 32 | static constexpr int CONTENTS_CURRENT_UP = 0x400000; 33 | static constexpr int CONTENTS_CURRENT_DOWN = 0x800000; 34 | static constexpr int CONTENTS_ORIGIN = 0x1000000; 35 | static constexpr int CONTENTS_MONSTER = 0x2000000; 36 | static constexpr int CONTENTS_DEBRIS = 0x4000000; 37 | static constexpr int CONTENTS_DETAIL = 0x8000000; 38 | static constexpr int CONTENTS_TRANSLUCENT = 0x10000000; 39 | static constexpr int CONTENTS_LADDER = 0x20000000; 40 | static constexpr int CONTENTS_HITBOX = 0x40000000; 41 | static constexpr int MASK_SOLID = (CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE); 42 | 43 | struct Ray_t 44 | { 45 | void Init(Vector const& start, Vector const& end) { 46 | (void)start; 47 | (void)end; 48 | } 49 | void Init(Vector const& start, Vector const& end, Vector const& mins, Vector const& maxs) { 50 | (void)start; 51 | (void)end; 52 | (void)mins; 53 | (void)maxs; 54 | } 55 | }; 56 | 57 | enum TraceType_t 58 | { 59 | TRACE_EVERYTHING = 0, 60 | TRACE_WORLD_ONLY, // NOTE: This does *not* test static props!!! 61 | TRACE_ENTITIES_ONLY, // NOTE: This version will *not* test static props 62 | TRACE_EVERYTHING_FILTER_PROPS, // NOTE: This version will pass the IHandleEntity for props through the filter, unlike all other filters 63 | }; 64 | 65 | class ITraceFilter 66 | { 67 | public: 68 | }; 69 | 70 | class CTraceFilter : public ITraceFilter 71 | { 72 | public: 73 | }; 74 | 75 | class CTraceFilterEntitiesOnly : public ITraceFilter 76 | { 77 | public: 78 | }; 79 | 80 | class CTraceFilterHitAll : public ITraceFilter 81 | { 82 | public: 83 | }; 84 | 85 | class ICollideable; 86 | class IHandleEntity; 87 | class CGameTrace; 88 | typedef CGameTrace trace_t; 89 | 90 | class IEngineTrace 91 | { 92 | public: 93 | virtual void TraceRay(const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace) = 0; 94 | virtual void ClipRayToEntity(const Ray_t &ray, unsigned int fMask, IHandleEntity *pEnt, trace_t *pTrace) = 0; 95 | virtual int GetPointContents(const Vector &vecAbsPosition, int contentsMask = MASK_ALL, 96 | IHandleEntity** ppEntity = nullptr) = 0; 97 | virtual int GetPointContents_Collideable(ICollideable *pCollide, const Vector &vecAbsPosition) = 0; 98 | virtual bool PointOutsideWorld(const Vector &ptTest) = 0; 99 | }; 100 | -------------------------------------------------------------------------------- /public/engine/iserverplugin.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "edict.h" 5 | #include "tier1/interface.h" 6 | #include "tier1/KeyValues.h" 7 | 8 | class CCommand; 9 | 10 | enum PLUGIN_RESULT { 11 | PLUGIN_CONTINUE = 0, 12 | PLUGIN_OVERRIDE, 13 | PLUGIN_STOP, 14 | }; 15 | 16 | enum EQueryCvarValueStatus { 17 | eQueryCvarValueStatus_ValueIntact = 0, 18 | eQueryCvarValueStatus_CvarNotFound = 1, 19 | eQueryCvarValueStatus_NotACvar = 2, 20 | eQueryCvarValueStatus_CvarProtected = 3 21 | }; 22 | 23 | typedef int QueryCvarCookie_t; 24 | 25 | static constexpr char INTERFACEVERSION_ISERVERPLUGINCALLBACKS[] = "ISERVERPLUGINCALLBACKS004"; 26 | 27 | class IServerPluginCallbacks 28 | { 29 | public: 30 | virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) = 0; 31 | virtual void Unload(void) = 0; 32 | virtual void Pause(void) = 0; 33 | virtual void UnPause(void) = 0; 34 | virtual const char *GetPluginDescription(void) = 0; 35 | virtual void LevelInit(char const *pMapName) = 0; 36 | virtual void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) = 0; 37 | virtual void GameFrame(bool simulating) = 0; 38 | virtual void LevelShutdown(void) = 0; 39 | virtual void ClientActive(edict_t *pEntity) = 0; 40 | virtual void ClientFullyConnect(edict_t *pEntity) = 0; 41 | virtual void ClientDisconnect(edict_t *pEntity) = 0; 42 | virtual void ClientPutInServer(edict_t *pEntity, char const *playername) = 0; 43 | virtual void SetCommandClient(int index) = 0; 44 | virtual void ClientSettingsChanged(edict_t *pEdict) = 0; 45 | virtual PLUGIN_RESULT ClientConnect(bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) = 0; 46 | virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity, const CCommand &args) = 0; 47 | virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID) = 0; 48 | virtual void OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue) = 0; 49 | virtual void OnEdictAllocated(edict_t *edict) = 0; 50 | virtual void OnEdictFreed(const edict_t *edict) = 0; 51 | virtual bool BNetworkCryptKeyCheckRequired(uint32_t unFromIP, uint16_t usFromPort, uint32_t unAccountIdProvidedByClient, 52 | bool bClientWantsToUseCryptKey) = 0; 53 | virtual bool BNetworkCryptKeyValidate(uint32_t unFromIP, uint16_t usFromPort, uint32_t unAccountIdProvidedByClient, 54 | int nEncryptionKeyIndexFromClient, int numEncryptedBytesFromClient, uint8_t *pbEncryptedBufferFromClient, 55 | uint8_t *pbPlainTextKeyForNetchan) = 0; 56 | }; 57 | 58 | static constexpr char INTERFACEVERSION_ISERVERPLUGINHELPERS[] = "ISERVERPLUGINHELPERS001"; 59 | 60 | enum DIALOG_TYPE 61 | { 62 | DIALOG_MSG = 0, 63 | DIALOG_MENU, 64 | DIALOG_TEXT, 65 | DIALOG_ENTRY, 66 | DIALOG_ASKCONNECT 67 | }; 68 | 69 | class IServerPluginHelpers 70 | { 71 | public: 72 | virtual void CreateMessage(edict_t *pEntity, DIALOG_TYPE type, KeyValues *data, IServerPluginCallbacks *plugin) = 0; 73 | virtual void ClientCommand(edict_t *ent, const char *cmd) = 0; 74 | virtual QueryCvarCookie_t StartQueryCvarValue(edict_t *pPlayerEntity, const char *pName) = 0; 75 | }; 76 | -------------------------------------------------------------------------------- /public/filesystem.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | static constexpr char BASEFILESYSTEM_INTERFACE_VERSION[] = "VBaseFileSystem011"; 7 | static constexpr char FILESYSTEM_INTERFACE_VERSION[] = "VFileSystem017"; 8 | 9 | typedef void* FileHandle_t; 10 | typedef int FileFindHandle_t; 11 | 12 | enum FileSystemSeek_t 13 | { 14 | FILESYSTEM_SEEK_HEAD = SEEK_SET, 15 | FILESYSTEM_SEEK_CURRENT = SEEK_CUR, 16 | FILESYSTEM_SEEK_TAIL = SEEK_END 17 | }; 18 | 19 | class IBaseFileSystem 20 | { 21 | public: 22 | virtual FileHandle_t Open(const char* name, const char* options, 23 | const char* path_id = nullptr) = 0; 24 | virtual unsigned int Size(FileHandle_t file) = 0; 25 | virtual unsigned int Size(const char* file, const char* pathID = nullptr) = 0; 26 | virtual int Read(void* output, int size, FileHandle_t file) = 0; 27 | virtual void Close(FileHandle_t file) = 0; 28 | virtual bool FileExists(const char *path, const char *path_id = nullptr) = 0; 29 | virtual int Write(void const* pInput, int size, FileHandle_t file) = 0; 30 | virtual void Seek(FileHandle_t file, int pos, FileSystemSeek_t seekType) = 0; 31 | virtual unsigned int Tell(FileHandle_t file) = 0; 32 | virtual int FPrintf(FileHandle_t file, const char *pFormat, ...) = 0; 33 | virtual void Flush(FileHandle_t file) = 0; 34 | virtual bool IsOk(FileHandle_t file) = 0; 35 | virtual void RemoveFile(char const* pRelativePath, const char *pathID = nullptr) = 0; 36 | virtual bool RenameFile(char const *pOldPath, char const *pNewPath, const char *pathID = nullptr) = 0; 37 | virtual bool IsDirectory(const char *pFileName, const char *pathID = nullptr) = 0; 38 | virtual void CreateDirHierarchy(const char *path, const char *pathID = nullptr) = 0; 39 | virtual const char *FindFirstEx(const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle) = 0; 40 | virtual const char *FindNext(FileFindHandle_t handle) = 0; 41 | virtual bool FindIsDirectory(FileFindHandle_t handle) = 0; 42 | virtual void FindClose(FileFindHandle_t handle) = 0; 43 | virtual char *ReadLine(char *pOutput, int maxChars, FileHandle_t file) = 0; 44 | virtual bool EndOfFile(FileHandle_t file) = 0; 45 | }; 46 | 47 | class CSysModule; 48 | 49 | class IFileSystem : public IBaseFileSystem 50 | { 51 | public: 52 | virtual CSysModule *LoadModule(const char *pFileName, const char *pPathID = 0, bool bValidatedDllOnly = true) = 0; 53 | virtual void UnloadModule(CSysModule *pModule) = 0; 54 | virtual int GetSearchPath(const char* pathID, bool bGetPackFiles, char* pPath, int nMaxLen) = 0; 55 | }; 56 | -------------------------------------------------------------------------------- /public/game/baseentity.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "edict.h" 5 | #include "ehandle.h" 6 | 7 | class CBaseEntity 8 | { 9 | public: 10 | edict_t* edict() const { return edict_; } 11 | 12 | private: 13 | edict_t* edict_; 14 | }; 15 | 16 | typedef CHandle EHANDLE; 17 | -------------------------------------------------------------------------------- /public/game/server/iplayerinfo.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | static constexpr char INTERFACEVERSION_PLAYERINFOMANAGER[] = "PlayerInfoManager002"; 7 | 8 | class IPlayerInfo 9 | { 10 | public: 11 | virtual int GetTeamIndex() const = 0; 12 | virtual bool IsObserver() = 0; 13 | virtual int GetFragCount() = 0; 14 | virtual int GetDeathCount() = 0; 15 | virtual int GetArmorValue() = 0; 16 | virtual const Vector GetAbsOrigin() = 0; 17 | virtual const QAngle GetAbsAngles() = 0; 18 | virtual const Vector GetPlayerMins() = 0; 19 | virtual const Vector GetPlayerMaxs() = 0; 20 | virtual const char *GetWeaponName() = 0; 21 | virtual const char *GetModelName() = 0; 22 | virtual const int GetHealth() = 0; 23 | virtual void ChangeTeam(int iTeamNum) = 0; 24 | virtual const char* GetName() = 0; 25 | virtual bool IsDead() = 0; 26 | }; 27 | 28 | class IPlayerInfoManager 29 | { 30 | public: 31 | virtual IPlayerInfo *GetPlayerInfo(edict_t *pEdict) = 0; 32 | virtual CGlobalVars* GetGlobalVars() = 0; 33 | }; 34 | -------------------------------------------------------------------------------- /public/gametrace.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "cmodel.h" 5 | #include "mathlib/mathlib.h" 6 | 7 | class CBaseEntity; 8 | 9 | class CBaseTrace 10 | { 11 | public: 12 | Vector startpos; 13 | Vector endpos; 14 | cplane_t plane; 15 | float fraction; 16 | bool allsolid; 17 | bool startsolid; 18 | unsigned short dispFlags; 19 | }; 20 | 21 | class CGameTrace : public CBaseTrace 22 | { 23 | public: 24 | bool DidHit() const; 25 | 26 | CBaseEntity* m_pEnt; 27 | float fractionleftsolid; 28 | csurface_t surface; 29 | short physicsbone; 30 | int hitbox; 31 | int hitgroup; 32 | }; 33 | 34 | typedef CGameTrace trace_t; 35 | 36 | inline bool CGameTrace::DidHit() const { 37 | return false; 38 | } 39 | -------------------------------------------------------------------------------- /public/iclient.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "imovehelper.h" 5 | #include "inetmsghandler.h" 6 | 7 | class IClient : public INetChannelHandler 8 | { 9 | public: 10 | virtual void Disconnect(const char *reason, ...) = 0; 11 | virtual void Inactivate() = 0; 12 | virtual void Reconnect() = 0; 13 | virtual int GetUserID() const = 0; 14 | virtual int GetPlayerSlot() const = 0; 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /public/icollideable.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class Vector; 5 | 6 | class ICollideable 7 | { 8 | public: 9 | virtual const Vector& GetCollisionOrigin() const = 0; 10 | }; 11 | -------------------------------------------------------------------------------- /public/igameevents.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | static constexpr char INTERFACEVERSION_GAMEEVENTSMANAGER2[] = "GAMEEVENTSMANAGER002"; 5 | 6 | static constexpr int EVENT_DEBUG_ID_INIT = 42; 7 | 8 | class IGameEvent 9 | { 10 | public: 11 | virtual ~IGameEvent() {}; 12 | virtual const char *GetName() const = 0; 13 | 14 | virtual bool IsReliable() const = 0; 15 | virtual bool IsLocal() const = 0; 16 | virtual bool IsEmpty(const char *keyName = nullptr) = 0; 17 | 18 | // Data access 19 | virtual bool GetBool(const char *keyName = nullptr, bool defaultValue = false) = 0; 20 | virtual int GetInt(const char *keyName = nullptr, int defaultValue = 0) = 0; 21 | virtual float GetFloat(const char *keyName = nullptr, float defaultValue = 0.0f) = 0; 22 | virtual const char *GetString(const char *keyName = nullptr, const char *defaultValue = "") = 0; 23 | virtual const void *GetPtr(const char *keyname = nullptr, const void *defaultValues = nullptr) = 0; 24 | 25 | virtual void SetBool(const char *keyName, bool value) = 0; 26 | virtual void SetInt(const char *keyName, int value) = 0; 27 | virtual void SetFloat(const char *keyName, float value) = 0; 28 | virtual void SetString(const char *keyName, const char *value) = 0; 29 | virtual void SetPtr(const char *keyname, const void *value) = 0; 30 | }; 31 | 32 | class IGameEventListener2 33 | { 34 | public: 35 | virtual ~IGameEventListener2() {} 36 | virtual void FireGameEvent(IGameEvent *event) = 0; 37 | }; 38 | 39 | class IGameEventManager2 40 | { 41 | public: 42 | virtual IGameEvent *CreateEvent(const char *name, bool bForce = false, int *pCookie = nullptr) = 0; 43 | virtual bool FireEvent(IGameEvent *event, bool bDontBroadcast = false) = 0; 44 | virtual void FreeEvent(IGameEvent *event) = 0; 45 | virtual IGameEvent *DuplicateEvent(IGameEvent *event) = 0; 46 | virtual bool AddListener(IGameEventListener2 *listener, const char *name, bool bServerSide) = 0; 47 | virtual void RemoveListener(IGameEventListener2 *listener) = 0; 48 | virtual bool FindListener(IGameEventListener2 *listener, const char *name) = 0; 49 | }; 50 | -------------------------------------------------------------------------------- /public/ihandleentity.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "basehandle.h" 5 | 6 | class IHandleEntity 7 | { 8 | public: 9 | virtual const CBaseHandle& GetRefEHandle() const = 0; 10 | }; 11 | -------------------------------------------------------------------------------- /public/imovehelper.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class IMoveHelper 5 | { 6 | public: 7 | }; 8 | -------------------------------------------------------------------------------- /public/inetchannel.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "inetchannelinfo.h" 5 | 6 | typedef struct netpacket_s { 7 | } netpacket_t; 8 | 9 | class bf_write; 10 | class INetChannelHandler; 11 | 12 | class INetChannel : public INetChannelInfo 13 | { 14 | public: 15 | virtual void ProcessPacket(struct netpacket_s* packet, bool reader) = 0; 16 | virtual bool SendFile(const char* file, unsigned int transfer_id, bool replay_demo) = 0; 17 | virtual void DenyFile(const char *file, unsigned int transfer_id, bool replay_demo) = 0; 18 | virtual INetChannelHandler *GetMsgHandler() const = 0; 19 | virtual bool SendData(bf_write &msg, bool bReliable = true) = 0; 20 | virtual int GetNumBitsWritten(bool bReliable) = 0; 21 | }; 22 | -------------------------------------------------------------------------------- /public/inetchannelinfo.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | static constexpr int FLOW_OUTGOING = 0; 5 | static constexpr int FLOW_INCOMING = 1; 6 | static constexpr int MAX_FLOWS = 2; 7 | 8 | class INetChannelInfo 9 | { 10 | public: 11 | virtual float GetTimeConnected() const = 0; 12 | virtual int GetDataRate() const = 0; 13 | virtual bool IsTimingOut() const = 0; 14 | virtual float GetLatency(int flow) const = 0; 15 | virtual float GetAvgLatency(int flow) const = 0; 16 | virtual float GetAvgLoss(int flow) const = 0; 17 | virtual float GetAvgPackets(int flow) const = 0; 18 | virtual float GetAvgData(int flow) const = 0; 19 | virtual float GetAvgChoke(int flow) const = 0; 20 | }; 21 | -------------------------------------------------------------------------------- /public/inetmsghandler.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class CLC_VoiceData; 5 | 6 | class INetChannelHandler 7 | { 8 | public: 9 | }; 10 | 11 | class IClientMessageHandler : public INetChannelHandler 12 | { 13 | public: 14 | virtual bool ProcessVoiceData(CLC_VoiceData* data) = 0; 15 | }; 16 | -------------------------------------------------------------------------------- /public/irecipientfilter.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class IRecipientFilter 5 | { 6 | public: 7 | virtual ~IRecipientFilter() {} 8 | virtual int GetRecipientCount() const = 0; 9 | virtual int GetRecipientIndex(int index) const = 0; 10 | virtual bool IsReliable() const = 0; 11 | virtual bool IsInitMessage() const = 0; 12 | }; 13 | -------------------------------------------------------------------------------- /public/isaverestore.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | -------------------------------------------------------------------------------- /public/iserver.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class IClient; 5 | 6 | class IServer 7 | { 8 | public: 9 | virtual IClient* GetClient(int client) = 0; 10 | virtual void GetNetStats(float &avgIn, float &avgOut) = 0; 11 | }; 12 | -------------------------------------------------------------------------------- /public/iserverentity.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "iserverunknown.h" 5 | #include "string_t.h" 6 | 7 | class IServerEntity : public IServerUnknown 8 | { 9 | public: 10 | virtual string_t GetModelName() const = 0; 11 | }; 12 | -------------------------------------------------------------------------------- /public/iservernetworkable.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "ihandleentity.h" 5 | 6 | class ServerClass; 7 | struct edict_t; 8 | 9 | class CCheckTransmitInfo 10 | { 11 | public: 12 | edict_t* m_pClientEnt; 13 | }; 14 | 15 | class IServerNetworkable 16 | { 17 | public: 18 | virtual IHandleEntity* GetEntityHandle() = 0; 19 | virtual ServerClass* GetServerClass() = 0; 20 | virtual CBaseEntity* GetBaseEntity() = 0; 21 | virtual edict_t *GetEdict() const = 0; 22 | }; 23 | -------------------------------------------------------------------------------- /public/iserverunknown.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "ihandleentity.h" 5 | 6 | class CBaseEntity; 7 | class IServerNetworkable; 8 | 9 | class IServerUnknown : public IHandleEntity 10 | { 11 | public: 12 | virtual CBaseEntity* GetBaseEntity(); 13 | virtual IServerNetworkable* GetNetworkable() = 0; 14 | }; 15 | -------------------------------------------------------------------------------- /public/ispatialpartition.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | enum 5 | { 6 | PARTITION_ENGINE_SOLID_EDICTS = (1 << 0), 7 | PARTITION_ENGINE_TRIGGER_EDICTS = (1 << 1), 8 | PARTITION_CLIENT_SOLID_EDICTS = (1 << 2), 9 | PARTITION_CLIENT_RESPONSIVE_EDICTS = (1 << 3), 10 | PARTITION_ENGINE_NON_STATIC_EDICTS = (1 << 4), 11 | PARTITION_CLIENT_STATIC_PROPS = (1 << 5), 12 | PARTITION_ENGINE_STATIC_PROPS = (1 << 6), 13 | PARTITION_CLIENT_NON_STATIC_EDICTS = (1 << 7), 14 | PARTITION_CLIENT_TRIGGER_ENTITIES = (1 << 8), 15 | PARTITION_CLIENT_IK_ATTACHMENT = (1 << 9), 16 | }; 17 | 18 | typedef int SpatialPartitionListMask_t; 19 | 20 | enum IterationRetval_t 21 | { 22 | ITERATION_CONTINUE = 0, 23 | ITERATION_STOP, 24 | }; 25 | 26 | class IHandleEntity; 27 | 28 | class IPartitionEnumerator 29 | { 30 | public: 31 | virtual IterationRetval_t EnumElement(IHandleEntity *pHandleEntity) = 0; 32 | }; 33 | 34 | static constexpr char INTERFACEVERSION_SPATIALPARTITION[] = "SpatialPartition001"; 35 | 36 | class Vector; 37 | struct Ray_t; 38 | 39 | class ISpatialPartition 40 | { 41 | public: 42 | virtual void EnumerateElementsInBox( 43 | SpatialPartitionListMask_t listMask, 44 | const Vector& mins, 45 | const Vector& maxs, 46 | bool coarseTest, 47 | IPartitionEnumerator* pIterator) = 0; 48 | virtual void EnumerateElementsInSphere( 49 | SpatialPartitionListMask_t listMask, 50 | const Vector& origin, 51 | float radius, 52 | bool coarseTest, 53 | IPartitionEnumerator* pIterator) = 0; 54 | virtual void EnumerateElementsAlongRay( 55 | SpatialPartitionListMask_t listMask, 56 | const Ray_t& ray, 57 | bool coarseTest, 58 | IPartitionEnumerator* pIterator) = 0; 59 | 60 | virtual void EnumerateElementsAtPoint( 61 | SpatialPartitionListMask_t listMask, 62 | const Vector& pt, 63 | bool coarseTest, 64 | IPartitionEnumerator* pIterator) = 0; 65 | }; 66 | -------------------------------------------------------------------------------- /public/ivoiceserver.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | static constexpr char INTERFACEVERSION_VOICESERVER[] = "VoiceServer002"; 5 | 6 | class IVoiceServer 7 | { 8 | public: 9 | virtual bool SetClientListening(int iReceiver, int iSender, bool bListen) = 0; 10 | }; 11 | -------------------------------------------------------------------------------- /public/mathlib/mathlib.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #include "vector.h" 8 | 9 | typedef Vector AngularImpulse; 10 | 11 | struct cplane_t 12 | { 13 | Vector normal; 14 | float dist; 15 | uint8_t type; 16 | uint8_t signbits; 17 | uint8_t pad[2]; 18 | }; 19 | 20 | struct matrix3x4_t 21 | { 22 | float mat[3][4]; 23 | }; 24 | 25 | static inline void MathLib_Init(float gamma = 2.2f, float texGamma = 2.2f, float brightness = 0.0f, 26 | int overbright = 2.0f, bool bAllow3DNow = true, bool bAllowSSE = true, 27 | bool bAllowSSE2 = true, bool bAllowMMX = true) 28 | { 29 | } 30 | 31 | static inline int RoundFloatToInt(float f) { 32 | return round(f); 33 | } 34 | 35 | inline void MatrixAngles( const matrix3x4_t &matrix, QAngle &angles ) 36 | { 37 | // Not implemented. 38 | (void)matrix; 39 | (void)angles; 40 | } 41 | 42 | inline void MatrixAngles( const matrix3x4_t &matrix, QAngle &angles, Vector &position ) 43 | { 44 | // Not implemented. 45 | (void)matrix; 46 | (void)angles; 47 | (void)position; 48 | } 49 | 50 | extern const Vector vec3_origin; 51 | -------------------------------------------------------------------------------- /public/mathlib/vector.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | typedef float vec_t; 7 | 8 | class Vector 9 | { 10 | public: 11 | float x, y, z; 12 | 13 | Vector() : x(0), y(0), z(0) {} 14 | Vector(float x, float y, float z) : x(x), y(y), z(z) {} 15 | 16 | void Init(float x = 0.0f, float y = 0.0f, float z = 0.0f) { 17 | this->x = x; 18 | this->y = y; 19 | this->z = z; 20 | } 21 | float Length() const { 22 | return sqrt(x * x + y * y + z * z); 23 | } 24 | float LengthSqr() const { 25 | return x * x + y * y + z * z; 26 | } 27 | float DistTo(const Vector& other) const { 28 | Vector v(x - other.x, y - other.y, z - other.z); 29 | return v.Length(); 30 | } 31 | float DistToSqr(const Vector& other) const { 32 | Vector v(x - other.x, y - other.y, z - other.z); 33 | return v.LengthSqr(); 34 | } 35 | float Dot(const Vector& b) const { 36 | return x * b.x + y * b.y + z * b.z; 37 | } 38 | float NormalizeInPlace() { 39 | float r = Length(); 40 | if (!r) 41 | return 0.0f; 42 | x *= r; 43 | y *= r; 44 | z *= r; 45 | return r; 46 | } 47 | Vector Cross(const Vector& b) const { 48 | return Vector(y * b.z - z * b.y, 49 | z * b.x - x * b.z, 50 | x * b.y - y * b.x); 51 | } 52 | 53 | Vector operator +(const Vector& v) const { 54 | return Vector(x + v.x, y + v.y, z + v.z); 55 | } 56 | Vector operator *(int v) const { 57 | return Vector(x * v, y * v, z * v); 58 | } 59 | }; 60 | 61 | class QAngle 62 | { 63 | public: 64 | float x, y, z; 65 | 66 | QAngle() : x(0), y(0), z(0) {} 67 | QAngle(float x, float y, float z) : x(x), y(y), z(z) {} 68 | 69 | void Init(float x = 0.0f, float y = 0.0f, float z = 0.0f) { 70 | this->x = x; 71 | this->y = y; 72 | this->z = z; 73 | } 74 | }; 75 | 76 | static inline void AngleVectors(const QAngle& angles, Vector* fwd) { 77 | // Not implemented. 78 | (void)angles; 79 | (void)fwd; 80 | } 81 | 82 | static inline void AngleVectors(const QAngle& angles, Vector* fwd, Vector* right, Vector* up) { 83 | // Not implemented. 84 | (void)angles; 85 | (void)fwd; 86 | (void)right; 87 | (void)up; 88 | } 89 | 90 | static inline void VectorAngles(const Vector& forward, QAngle& angles) { 91 | // Not implemented. 92 | (void)forward; 93 | (void)angles; 94 | } 95 | 96 | static inline void VectorVectors(const Vector& forward, Vector& right, Vector& up) { 97 | // Not implemented. 98 | (void)forward; 99 | (void)right; 100 | (void)up; 101 | } 102 | 103 | static inline float VectorNormalize(Vector& vec) { 104 | float r = vec.Length(); 105 | if (!r) 106 | return 0.0f; 107 | vec.x *= r; 108 | vec.y *= r; 109 | vec.z *= r; 110 | return r; 111 | } 112 | -------------------------------------------------------------------------------- /public/networkstringtabledefs.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | static constexpr int INVALID_STRING_TABLE = -1; 5 | static constexpr unsigned short INVALID_STRING_INDEX = -1; 6 | 7 | typedef int TABLEID; 8 | 9 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 10 | 11 | static constexpr char INTERFACENAME_NETWORKSTRINGTABLESERVER[] = "VEngineServerStringTable001"; 12 | 13 | class INetworkStringTable 14 | { 15 | public: 16 | virtual TABLEID GetTableId() const = 0; 17 | virtual int GetNumStrings() const = 0; 18 | virtual int GetMaxStrings() const = 0; 19 | virtual const char* GetTableName() const = 0; 20 | virtual int FindStringIndex(const char* str) const = 0; 21 | virtual const char* GetString(int i) const = 0; 22 | virtual const void* GetStringUserData(int i, int* len) const = 0; 23 | virtual void SetStringUserData(int i, int len, const void* userdata) = 0; 24 | virtual int AddString(bool server, const char* val, int length = -1, 25 | const void* userdata = nullptr) = 0; 26 | }; 27 | 28 | class INetworkStringTableContainer 29 | { 30 | public: 31 | virtual INetworkStringTable* FindTable(const char* name) const = 0; 32 | virtual INetworkStringTable* GetTable(int i) const = 0; 33 | virtual int GetNumTables() const = 0; 34 | }; 35 | -------------------------------------------------------------------------------- /public/server_class.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class SendTable; 5 | 6 | class ServerClass 7 | { 8 | public: 9 | const char* GetName() const { return "ServerClass"; } 10 | 11 | SendTable* m_pTable; 12 | ServerClass* m_pNext; 13 | int m_ClassID; 14 | }; 15 | -------------------------------------------------------------------------------- /public/shareddefs.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | -------------------------------------------------------------------------------- /public/steam/steamclientpublic.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | enum EUniverse { 7 | k_EUniverseInvalid = 0, 8 | k_EUniversePublic = 1, 9 | k_EUniverseBeta = 2, 10 | k_EUniverseInternal = 3, 11 | k_EUniverseDev = 4, 12 | k_EUniverseRC = 5, 13 | k_EUniverseMax 14 | }; 15 | 16 | enum EAccountType { 17 | k_EAccountTypeInvalid = 0, 18 | k_EAccountTypeIndividual = 1, 19 | k_EAccountTypeMultiseat = 2, 20 | k_EAccountTypeGameServer = 3, 21 | k_EAccountTypeAnonGameServer = 4, 22 | k_EAccountTypePending = 5, 23 | k_EAccountTypeContentServer = 6, 24 | k_EAccountTypeClan = 7, 25 | k_EAccountTypeChat = 8, 26 | k_EAccountTypeAnonUser = 10, 27 | k_EAccountTypeMax 28 | }; 29 | 30 | class CSteamID 31 | { 32 | public: 33 | CSteamID() {} 34 | CSteamID(uint64_t val) {} 35 | uint64_t ConvertToUint64() const { return 0; } 36 | bool IsValid() const { return false; } 37 | EUniverse GetEUniverse() const { return k_EUniverseInvalid; } 38 | uint32_t GetAccountID() const { return 0; } 39 | uint32_t GetUnAccountInstance() const { return 0; } 40 | EAccountType GetEAccountType() const { return k_EAccountTypeInvalid; } 41 | 42 | bool operator !=(const CSteamID& other) const { 43 | return false; 44 | } 45 | }; 46 | 47 | const CSteamID k_steamIDNil; 48 | -------------------------------------------------------------------------------- /public/string_t.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class string_t 5 | { 6 | public: 7 | const char* ToCStr() const { return value_; } 8 | 9 | bool operator ==(const string_t& other) const { 10 | return value_ == other.value_; 11 | } 12 | 13 | protected: 14 | const char* value_; 15 | }; 16 | 17 | class castable_string_t : public string_t 18 | { 19 | public: 20 | castable_string_t() { value_ = nullptr; } 21 | castable_string_t(const char* from) { value_ = from; } 22 | }; 23 | 24 | #define MAKE_STRING(str) castable_string_t((str)) 25 | #define STRING(str) ((str).ToCStr()) 26 | #define NULL_STRING string_t() 27 | -------------------------------------------------------------------------------- /public/takedamageinfo.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include "game/baseentity.h" 6 | #include "mathlib/vector.h" 7 | 8 | static constexpr float BASEDAMAGE_NOT_SPECIFIED = FLT_MAX; 9 | 10 | struct FireBulletsInfo_t 11 | { 12 | int m_iShots; 13 | }; 14 | 15 | class CTakeDamageInfo 16 | { 17 | public: 18 | CTakeDamageInfo(); 19 | CBaseEntity* GetInflictor() const; 20 | void SetInflictor(CBaseEntity* entity); 21 | CBaseEntity* GetWeapon() const; 22 | void SetWeapon(CBaseEntity* entity); 23 | CBaseEntity* GetAttacker() const; 24 | void SetAttacker(CBaseEntity* entity); 25 | float GetDamage() const; 26 | void SetDamage(float flDamage); 27 | float GetMaxDamage() const; 28 | float GetBaseDamage() const; 29 | Vector GetDamageForce() const; 30 | Vector GetDamagePosition() const; 31 | Vector GetReportedPosition() const; 32 | int GetDamageType() const; 33 | void SetDamageType(int bitsDamageType); 34 | int GetDamageCustom() const; 35 | int GetAmmoType() const; 36 | void SetAmmoType(int ammoType); 37 | 38 | Vector m_vecDamageForce; 39 | Vector m_vecDamagePosition; 40 | Vector m_vecReportedPosition; 41 | EHANDLE m_hInflictor; 42 | EHANDLE m_hAttacker; 43 | EHANDLE m_hWeapon; 44 | float m_flDamage; 45 | float m_flMaxDamage; 46 | float m_flBaseDamage; 47 | int m_bitsDamageType; 48 | int m_iDamageCustom; 49 | int m_iAmmoType; 50 | float m_flRadius; 51 | }; 52 | 53 | inline CBaseEntity* CTakeDamageInfo::GetInflictor() const { 54 | return m_hInflictor.Get(); 55 | } 56 | inline void CTakeDamageInfo::SetInflictor(CBaseEntity* entity) { 57 | m_hInflictor = entity; 58 | } 59 | inline CBaseEntity* CTakeDamageInfo::GetWeapon() const { 60 | return m_hWeapon.Get(); 61 | } 62 | inline void CTakeDamageInfo::SetWeapon(CBaseEntity* entity) { 63 | m_hWeapon = entity; 64 | } 65 | inline CBaseEntity* CTakeDamageInfo::GetAttacker() const { 66 | return m_hAttacker.Get(); 67 | } 68 | inline void CTakeDamageInfo::SetAttacker(CBaseEntity* entity) { 69 | m_hAttacker = entity; 70 | } 71 | inline float CTakeDamageInfo::GetDamage() const { 72 | return m_flDamage; 73 | } 74 | inline void CTakeDamageInfo::SetDamage(float flDamage) { 75 | m_flDamage = flDamage; 76 | } 77 | inline float CTakeDamageInfo::GetMaxDamage() const { 78 | return m_flMaxDamage; 79 | } 80 | inline float CTakeDamageInfo::GetBaseDamage() const { 81 | return m_flBaseDamage; 82 | } 83 | inline Vector CTakeDamageInfo::GetDamageForce() const { 84 | return m_vecDamageForce; 85 | } 86 | inline Vector CTakeDamageInfo::GetDamagePosition() const { 87 | return m_vecDamagePosition; 88 | } 89 | inline Vector CTakeDamageInfo::GetReportedPosition() const { 90 | return m_vecReportedPosition; 91 | } 92 | inline int CTakeDamageInfo::GetDamageType() const { 93 | return m_bitsDamageType; 94 | } 95 | inline void CTakeDamageInfo::SetDamageType(int bitsDamageType) { 96 | m_bitsDamageType = bitsDamageType; 97 | } 98 | inline int CTakeDamageInfo::GetDamageCustom() const { 99 | return m_iDamageCustom; 100 | } 101 | inline int CTakeDamageInfo::GetAmmoType() const { 102 | return m_iAmmoType; 103 | } 104 | inline void CTakeDamageInfo::SetAmmoType(int ammoType) { 105 | m_iAmmoType = ammoType; 106 | } 107 | -------------------------------------------------------------------------------- /public/tier0/dbg.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | #include "platform.h" 7 | 8 | #ifdef NDEBUG 9 | # define Assert(cond) 10 | #else 11 | # define Assert(cond) assert((cond)) 12 | #endif 13 | 14 | void ConMsg(const char* msg, ...); 15 | void Msg(const char* msg, ...); 16 | void Warning(const char* msg, ...); 17 | void Error(const char* msg, ...); 18 | void DevMsg(const char* msg, ...); 19 | -------------------------------------------------------------------------------- /public/tier0/icommandline.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class ICommandLine 5 | { 6 | public: 7 | virtual const char* ParmValue(const char* key, const char* defval = nullptr) const = 0; 8 | virtual int ParmValue(const char* key, int defval) const = 0; 9 | virtual const char* GetCmdLine() const = 0; 10 | virtual int FindParm(const char* key) const = 0; 11 | }; 12 | 13 | extern ICommandLine* CommandLine(); 14 | -------------------------------------------------------------------------------- /public/tier0/logging.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | enum class LogLevel { 5 | Warning, 6 | Normal, 7 | Message, 8 | Error 9 | }; 10 | 11 | struct LoggingContext_t 12 | { 13 | LogLevel severity; 14 | }; 15 | 16 | class ILoggingListener 17 | { 18 | public: 19 | virtual void Log(const LoggingContext_t *pContext, const char *pMessage) = 0; 20 | }; 21 | 22 | void LoggingSystem_PushLoggingState(bool bThreadLocal = false, bool bClearState = true); 23 | void LoggingSystem_PopLoggingState(bool bThreadLocal = false); 24 | void LoggingSystem_RegisterLoggingListener(ILoggingListener *pListener); 25 | -------------------------------------------------------------------------------- /public/tier0/mem.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | extern void* MemAllocScratch(int size); 7 | extern void MemFreeScratch(); 8 | -------------------------------------------------------------------------------- /public/tier0/platform.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef _WIN32 9 | # define WIN32_LEAN_AND_MEAN 10 | # define NOMINMAX 11 | # include 12 | #endif 13 | 14 | typedef char tchar; 15 | 16 | #ifdef _WIN32 17 | # define DLL_EXPORT extern "C" __declspec(dllexport) 18 | #else 19 | # define DLL_EXPORT extern "C" 20 | # define MAX_PATH PATH_MAX 21 | #endif 22 | 23 | typedef intptr_t intp; 24 | typedef uint8_t byte; 25 | typedef uint32_t uint32; 26 | typedef uint64_t uint64; 27 | 28 | #define ALIGN_VALUE(size, bytes) (((size) + (bytes) - 1) & ~((bytes) - 1)) 29 | 30 | #if defined(_MSC_VER) 31 | # define stackalloc(size) _alloca(ALIGN_VALUE((size), 16)) 32 | #else 33 | # define stackalloc(size) alloca(ALIGN_VALUE((size), 16)) 34 | #endif 35 | 36 | #define LittleDWord(val) val 37 | #define abstract_class class 38 | 39 | double Plat_FloatTime(); 40 | -------------------------------------------------------------------------------- /public/tier0/vprof.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #define VPROF_BUDGETGROUP_OTHER_UNACCOUNTED "Unaccounted" 5 | 6 | enum VProfReportType_t { 7 | VPRT_FULL 8 | }; 9 | 10 | class VProfiler 11 | { 12 | public: 13 | void Pause() {} 14 | void OutputReport(VProfReportType_t) {} 15 | void Resume() {} 16 | bool IsEnabled() { return false; } 17 | void EnterScope(const char*, int, const char*, bool, int) {} 18 | void ExitScope() {} 19 | }; 20 | 21 | extern VProfiler g_VProfCurrentProfile; 22 | -------------------------------------------------------------------------------- /public/tier1/KeyValues.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "tier0/platform.h" 10 | #include "Color.h" 11 | 12 | class CUtlBuffer; 13 | class IBaseFileSystem; 14 | 15 | class KeyValues 16 | { 17 | public: 18 | explicit KeyValues(const char* name); 19 | KeyValues(const char* name, const char* firstKey, const char* firstValue); 20 | 21 | virtual ~KeyValues() {} 22 | virtual void deleteThis() { delete this; } 23 | 24 | bool LoadFromFile(IBaseFileSystem* fs, const char* resname, const char* pathID = nullptr); 25 | bool LoadFromBuffer(const char* resname, const char* buffer, IBaseFileSystem* fs = nullptr); 26 | void RecursiveSaveToFile(CUtlBuffer& buf, int indentLevel) {} 27 | bool SaveToFile(IBaseFileSystem* fs, const char* resourceName, const char* pathID = nullptr) { return false; } 28 | 29 | KeyValues* FindKey(const char* key, bool create = false); 30 | KeyValues* FindKey(int keySymbol) { return nullptr; } 31 | const char *GetString(const char *keyName = nullptr, const char *defaultValue = ""); 32 | int GetInt(const char *keyName = nullptr, int defaultValue = 0) { 33 | return defaultValue; 34 | } 35 | float GetFloat(const char *keyName = nullptr, float defaultValue = 0.0f) { 36 | return defaultValue; 37 | } 38 | Color GetColor(const char *keyName = nullptr, const Color &defaultColor = Color(0, 0, 0, 0 )) { 39 | return defaultColor; 40 | } 41 | uint64 GetUint64(const char *keyName = nullptr, uint64 defaultValue = 0) { 42 | return defaultValue; 43 | } 44 | void SetString(const char *keyName, const char *value) {} 45 | void SetInt(const char *keyName, int value) {} 46 | void SetUint64(const char *keyName, uint64 value) {} 47 | void SetFloat(const char *keyName, float value) {} 48 | void SetColor(const char *keyName, Color value) {} 49 | const char *GetName() const { return name_.c_str(); } 50 | void SetName(const char *setName) { name_ = setName; } 51 | void SetStringValue(const char* value) { value_ = value; } 52 | void RemoveSubKey(KeyValues *subKey) {} 53 | 54 | void UsesEscapeSequences(bool state) {} 55 | 56 | void CopySubkeys(KeyValues *pParent) const {} 57 | int GetNameSymbol() const { return -1; } 58 | 59 | KeyValues* GetFirstTrueSubKey() { return nullptr; } 60 | KeyValues* GetNextTrueSubKey() { return nullptr; } 61 | KeyValues* GetFirstSubKey() { return nullptr; } 62 | KeyValues *GetNextKey() { return nullptr; } 63 | 64 | enum types_t 65 | { 66 | TYPE_NONE = 0, 67 | TYPE_STRING, 68 | TYPE_INT, 69 | TYPE_FLOAT, 70 | TYPE_PTR, 71 | TYPE_WSTRING, 72 | TYPE_COLOR, 73 | TYPE_UINT64, 74 | TYPE_COMPILED_INT_BYTE, 75 | TYPE_COMPILED_INT_0, 76 | TYPE_COMPILED_INT_1, 77 | TYPE_NUMTYPES, 78 | }; 79 | types_t GetDataType(const char *keyName = nullptr) { return TYPE_NONE; } 80 | 81 | private: 82 | std::string name_; 83 | std::string value_; 84 | std::unordered_map> dict_; 85 | std::vector> subkeys_; 86 | 87 | // Helper for the SubKey iterators. 88 | KeyValues* sub_next_ = nullptr; 89 | }; 90 | -------------------------------------------------------------------------------- /public/tier1/bitbuf.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | class bf_write 7 | { 8 | public: 9 | bf_write(void* data, size_t buflen) {} 10 | void WriteOneBit(int i) {} 11 | void WriteByte(uint8_t b) {} 12 | void WriteChar(char c) {} 13 | void WriteShort(int16_t s) {} 14 | void WriteWord(int32_t i) {} 15 | void WriteLong(int64_t i) {} 16 | void WriteFloat(float f) {} 17 | void WriteString(const char* f) {} 18 | void WriteBitAngle(float f, int) {} 19 | void WriteBitCoord(float f) {} 20 | void WriteBitAngles(const QAngle& v) {} 21 | void WriteBitVec3Coord(const Vector& v) {} 22 | void WriteBitVec3Normal(const Vector& v) {} 23 | void WriteUBitLong(unsigned int data, int numbits, bool bCheckRange=true) {} 24 | unsigned char* GetBasePointer() { return nullptr; } 25 | int GetNumBytesWritten() { return 0; } 26 | int GetNumBitsWritten() { return 0; } 27 | void Reset() {} 28 | void WriteBitsFromBuffer(const void*, int) {} 29 | }; 30 | 31 | class bf_read 32 | { 33 | public: 34 | bf_read() {} 35 | bf_read(const void *pData, int nBytes, int nBits = -1) {} 36 | void StartReading(const void* data, int bytes, int startBit = 0, int nbits = -1) { } 37 | int ReadOneBit() { return 0; } 38 | uint8_t ReadByte() { return 0; } 39 | char ReadChar() { return 0; } 40 | int16_t ReadShort() { return 0; } 41 | int32_t ReadWord() { return 0; } 42 | int64_t ReadLong() { return 0; } 43 | float ReadFloat() { return 0; } 44 | bool ReadString(char* buf, int buflen, bool bline = false, int* outchars = nullptr) { return false; } 45 | float ReadBitAngle(int) { return 0; } 46 | float ReadBitCoord() { return 0; } 47 | void ReadBitAngles(QAngle& v) { } 48 | void ReadBitVec3Coord(Vector& v) { } 49 | void ReadBitVec3Normal(Vector& v) { } 50 | int GetNumBitsLeft() { return 0; } 51 | bool IsOverflowed() { return false; } 52 | }; 53 | -------------------------------------------------------------------------------- /public/tier1/convar.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "utlstring.h" 9 | #include "utlvector.h" 10 | 11 | class ConCommandBase; 12 | class ConCommand; 13 | class ConVar; 14 | class ICvar; 15 | 16 | static constexpr char CVAR_INTERFACE_VERSION[] = "VEngineCvar007"; 17 | 18 | static constexpr int FCVAR_SPONLY = (1 << 6); 19 | static constexpr int FCVAR_NOTIFY = (1 << 8); 20 | static constexpr int FCVAR_DONTRECORD = (1<<17); 21 | 22 | class IConCommandBaseAccessor 23 | { 24 | public: 25 | virtual bool RegisterConCommandBase(ConCommandBase* base) = 0; 26 | }; 27 | 28 | class ConCommandBase 29 | { 30 | friend void ConVar_Register(int, IConCommandBaseAccessor*); 31 | friend void ConVar_Unregister(); 32 | 33 | protected: 34 | static ConCommandBase* sCommandList; 35 | 36 | public: 37 | explicit ConCommandBase(const char* name) 38 | : next_(sCommandList), 39 | name_(name) 40 | { 41 | sCommandList = this; 42 | } 43 | 44 | virtual const char* GetName() const { return name_; } 45 | virtual bool IsCommand() const = 0; 46 | virtual const char *GetHelpText() const { return help_; } 47 | 48 | virtual bool IsFlagSet(int flag) const { 49 | return !!(m_nFlags & flag); 50 | } 51 | 52 | ConCommandBase* next() const { return next_; } 53 | 54 | static void RegisterAll(ICvar* cvar); 55 | 56 | void Init(); 57 | void AddFlags(int flags) { 58 | m_nFlags |= flags; 59 | } 60 | 61 | void set_owner_token(void* ptr) { owner_token_ = ptr; } 62 | void* owner_token() const { return owner_token_; } 63 | 64 | private: 65 | ConCommandBase* next_; 66 | const char* name_; 67 | void* owner_token_ = nullptr; 68 | 69 | protected: 70 | const char* help_ = nullptr; 71 | 72 | public: 73 | int m_nFlags = 0; 74 | }; 75 | 76 | class ICvar 77 | { 78 | public: 79 | virtual void RegisterConCommand(ConCommandBase* base) = 0; 80 | virtual void UnregisterConCommand(ConCommandBase* base) = 0; 81 | virtual ConCommand* FindCommand(const char* name) = 0; 82 | virtual ConCommandBase* FindCommandBase(const char* name) = 0; 83 | virtual const char* GetCommandLineValue(const char* var) = 0; 84 | virtual ConVar* FindVar(const char *var_name) = 0; 85 | virtual void CallGlobalChangeCallbacks(ConVar *var, const char *pOldString, float flOldValue) = 0; 86 | virtual void RemoveOwnedCmds(void* token) = 0; 87 | 88 | protected: 89 | class IIteratorImpl 90 | { 91 | public: 92 | virtual ~IIteratorImpl() {} 93 | virtual void SetFirst() = 0; 94 | virtual void Next() = 0; 95 | virtual bool IsValid() = 0; 96 | virtual ConCommandBase* Get() = 0; 97 | virtual void DeleteThis() = 0; 98 | }; 99 | 100 | virtual IIteratorImpl* NewConCmdIterator() = 0; 101 | 102 | public: 103 | class Iterator 104 | { 105 | public: 106 | Iterator(ICvar* icvar) 107 | : impl_(icvar->NewConCmdIterator()) 108 | {} 109 | ~Iterator() { impl_->DeleteThis(); } 110 | void SetFirst() { impl_->SetFirst(); } 111 | bool IsValid() { return impl_->IsValid(); } 112 | ConCommandBase* Get() { return impl_->Get(); } 113 | void Next() { impl_->Next(); } 114 | 115 | private: 116 | IIteratorImpl* impl_; 117 | }; 118 | }; 119 | 120 | class IConVar 121 | { 122 | public: 123 | virtual void SetValue(const char* value) = 0; 124 | virtual void SetValue(float value) = 0; 125 | virtual void SetValue(int value) = 0; 126 | virtual const char* GetName() const = 0; 127 | }; 128 | 129 | typedef void (*FnChangeCallback_t)(IConVar *var, const char *pOldValue, float flOldValue); 130 | 131 | class ConVar : public ConCommandBase, public IConVar 132 | { 133 | public: 134 | ConVar(const char* name, const char* value, int flags = 0); 135 | ConVar(const char* name, const char* value, int flags, const char* help); 136 | ConVar(const char* name, const char* value, int flags, const char* help, bool bMin, 137 | float fMin, bool bMax, float fMax, FnChangeCallback_t callback = nullptr); 138 | 139 | virtual const char* GetName() const override { return ConCommandBase::GetName(); } 140 | char const* GetString() const { return str_value_.c_str(); } 141 | virtual float GetFloat() const; 142 | virtual int GetInt() const; 143 | virtual bool IsCommand() const override { return false; } 144 | virtual void SetValue(const char* value) override; 145 | virtual void SetValue(float value) override; 146 | virtual void SetValue(int value) override; 147 | bool GetMin(float& minVal) const { 148 | minVal = m_fMinVal; 149 | return m_bHasMin; 150 | } 151 | bool GetMax(float& maxVal) const { 152 | maxVal = m_fMaxVal; 153 | return m_bHasMax; 154 | } 155 | bool GetBool() const { return !!GetInt(); } 156 | 157 | void Revert() { SetValue(def_); } 158 | 159 | const char* GetDefault() const { return def_; } 160 | 161 | private: 162 | const char* def_; 163 | std::string str_value_; 164 | FnChangeCallback_t callback_ = nullptr; 165 | 166 | public: 167 | bool m_bHasMin = false; 168 | float m_fMinVal = 0.0f; 169 | bool m_bHasMax = false; 170 | float m_fMaxVal = 0.0f; 171 | }; 172 | 173 | class CCommand 174 | { 175 | public: 176 | CCommand(std::string&& cmdline, std::vector&& args) 177 | : cmdline_(std::move(cmdline)), 178 | args_(std::move(args)) 179 | {} 180 | 181 | static constexpr int COMMAND_MAX_LENGTH = 512; 182 | 183 | const char* ArgS() const { return cmdline_.c_str(); } 184 | int ArgC() const { return (int)args_.size(); } 185 | const char* Arg(int index) const { return args_[index].c_str(); } 186 | const char* operator[](int index) const { return Arg(index); } 187 | 188 | static constexpr int MaxCommandLength() { return COMMAND_MAX_LENGTH - 1; } 189 | 190 | private: 191 | std::string cmdline_; 192 | std::vector args_; 193 | }; 194 | 195 | class ConCommand : public ConCommandBase 196 | { 197 | public: 198 | ConCommand(const char* name, std::function callback, 199 | const char* help = nullptr, int flags = 0) 200 | : ConCommandBase(name), 201 | callback_(callback) 202 | { 203 | if (help) 204 | help_ = help; 205 | Init(); 206 | } 207 | 208 | virtual void Dispatch(const CCommand& cmd) { 209 | callback_(cmd); 210 | } 211 | virtual bool IsCommand() const override { return true; } 212 | virtual bool CanAutoComplete() { return false; } 213 | virtual int AutoCompleteSuggest(const char *partial, CUtlVector& commands) { 214 | return 0; 215 | } 216 | 217 | private: 218 | std::function callback_; 219 | }; 220 | 221 | #define CON_COMMAND(name, help) \ 222 | static void name(const CCommand& args); \ 223 | static ConCommand name##_command(#name, name, help); \ 224 | static void name(const CCommand& args) 225 | 226 | void ConVar_Register(int flag = 0, IConCommandBaseAccessor* accessor = nullptr); 227 | void ConVar_Unregister(); 228 | 229 | extern ICvar* g_pCVar; 230 | -------------------------------------------------------------------------------- /public/tier1/interface.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "tier0/platform.h" 5 | 6 | #define IFACE_OK 0 7 | #define IFACE_FAILED 1 8 | 9 | typedef void* (*InstantiateInterfaceFn)(); 10 | typedef void* (*CreateInterfaceFn)(const char* name, int* ret); 11 | 12 | class InterfaceReg 13 | { 14 | public: 15 | InterfaceReg(InstantiateInterfaceFn fn, const char* name); 16 | 17 | public: 18 | InstantiateInterfaceFn m_CreateFn; 19 | const char* m_pName; 20 | InterfaceReg* m_pNext; 21 | }; 22 | 23 | DLL_EXPORT void* CreateInterface(const char* name, int* ret); 24 | 25 | #define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, ifaceName, versionName, globalVar) \ 26 | static void* __Create##className##ifaceName##_interface() { \ 27 | return static_cast(&globalVar); \ 28 | } \ 29 | static InterfaceReg __g_Create##className##ifaceName##_reg(__Create##className##ifaceName##_interface, versionName); 30 | 31 | class CSysModule; 32 | 33 | CSysModule* OpenCSysModule(const char* path); 34 | void CloseCSysModule(CSysModule* mod); 35 | CreateInterfaceFn Sys_GetFactory(CSysModule *pModule); 36 | -------------------------------------------------------------------------------- /public/tier1/strtools.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | #include "tier0/platform.h" 7 | 8 | #define Q_strncpy V_strncpy 9 | #define Q_binarytohex V_binarytohex 10 | #define Q_strcmp strcmp 11 | 12 | void V_strncpy(char* dest, const char* src, int maxlen); 13 | void V_binarytohex(const byte *in, int inputbytes, char *out, int outsize); 14 | void V_strcat(char *dest, const char *src, int cchDest); 15 | -------------------------------------------------------------------------------- /public/tier1/utlbuffer.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class CUtlBuffer 5 | { 6 | public: 7 | int TellPut() const { return 0; } 8 | int TellMaxPut() const { return 0; } 9 | void Purge() {} 10 | void GetString(char* pString, int nMaxChars = 0) { 11 | if (nMaxChars) 12 | *pString = '\0'; 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /public/tier1/utldict.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | // :TODO: 8 | template 9 | class CUtlDict 10 | { 11 | public: 12 | char* GetElementName(I i); 13 | char const* GetElementName(I i) const; 14 | I First() const; 15 | I Next(I i) const; 16 | I InvalidIndex() const { return -1; } 17 | 18 | private: 19 | std::map impl_; 20 | }; 21 | 22 | template 23 | char* CUtlDict::GetElementName(I i) { 24 | I cnt = 0; 25 | for (auto it = impl_.begin(); it != impl_.end(); ++it, ++cnt) { 26 | if (cnt == i) 27 | return const_cast(it->first.c_str()); 28 | } 29 | return nullptr; 30 | } 31 | 32 | template 33 | char const* CUtlDict::GetElementName(I i) const { 34 | I cnt = 0; 35 | for (auto it = impl_.cbegin(); it != impl_.cend(); ++it, ++cnt) { 36 | if (cnt == i) 37 | return it->first.c_str(); 38 | } 39 | return nullptr; 40 | } 41 | 42 | template 43 | I CUtlDict::First() const { 44 | if (impl_.empty()) 45 | return InvalidIndex(); 46 | return 0; 47 | } 48 | 49 | template 50 | I CUtlDict::Next(I i) const { 51 | if (i < 0 || i >= impl_.size()) 52 | return InvalidIndex(); 53 | return i + 1; 54 | } 55 | -------------------------------------------------------------------------------- /public/tier1/utlstring.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class CUtlString 5 | { 6 | public: 7 | operator const char*() const { return impl_.data(); } 8 | 9 | private: 10 | std::string impl_; 11 | }; 12 | -------------------------------------------------------------------------------- /public/tier1/utlsymbol.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class CUtlSymbol 5 | { 6 | public: 7 | }; 8 | -------------------------------------------------------------------------------- /public/tier1/utlvector.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | template 8 | class CUtlVector 9 | { 10 | public: 11 | int AddToTail(const T& src) { 12 | impl_.emplace_back(src); 13 | return (int)impl_.size() - 1; 14 | } 15 | bool FindAndRemove(const T& src) { 16 | auto pos = std::find(impl_.begin(), impl_.end(), src); 17 | if (pos == impl_.end()) 18 | return false; 19 | impl_.erase(pos); 20 | return true; 21 | } 22 | 23 | T& operator [](int i) { return impl_[i]; } 24 | int Count() const { return (int)impl_.size(); } 25 | 26 | private: 27 | std::vector impl_; 28 | }; 29 | -------------------------------------------------------------------------------- /public/toolframework/itoolentity.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | class Vector; 5 | 6 | typedef void* EntitySearchResult; 7 | 8 | static constexpr char VSERVERTOOLS_INTERFACE_VERSION[] = "VSERVERTOOLS001"; 9 | 10 | class IServerTools 11 | { 12 | public: 13 | virtual void *CreateEntityByName(const char *szClassName) = 0; 14 | virtual void DispatchSpawn(void *pEntity) = 0; 15 | virtual EntitySearchResult NextEntity(EntitySearchResult iter) = 0; 16 | virtual bool SetKeyValue(void *pEntity, const char *szField, const char *szValue) = 0; 17 | virtual bool SetKeyValue(void *pEntity, const char *szField, float flValue) = 0; 18 | virtual bool SetKeyValue(void *pEntity, const char *szField, const Vector &vecValue) = 0; 19 | 20 | EntitySearchResult FirstEntity() { return NextEntity(nullptr); } 21 | }; 22 | -------------------------------------------------------------------------------- /public/usercmd.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | #include "mathlib/mathlib.h" 7 | 8 | class CUserCmd 9 | { 10 | public: 11 | uint8_t impulse = 0; 12 | float forwardmove = 0; 13 | float sidemove = 0; 14 | float upmove = 0; 15 | QAngle viewangles; 16 | short mousedx = 0; 17 | short mousedy = 0; 18 | int buttons = 0; 19 | int weaponselect = 0; 20 | int weaponsubtype = 0; 21 | int command_number = 0; 22 | int tick_count = 0; 23 | int random_seed = 0; 24 | }; 25 | -------------------------------------------------------------------------------- /public/vstdlib/random.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | 8 | static inline void RandomSeed(int seed) { 9 | srand(seed); 10 | } 11 | 12 | static inline float RandomFloat(float flMinVal = 0.0f, float flMaxVal = 1.0f) { 13 | float x = (float)rand() / float(RAND_MAX); 14 | x *= (flMaxVal - flMinVal); 15 | x += flMinVal; 16 | return x; 17 | } 18 | 19 | static inline int RandomInt(int iMinVal, int iMaxVal) { 20 | int r = rand(); 21 | return (r % (iMaxVal - iMinVal)) + iMinVal; 22 | } 23 | -------------------------------------------------------------------------------- /public/worldsize.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | -------------------------------------------------------------------------------- /srcds/AMBuilder: -------------------------------------------------------------------------------- 1 | #! vim: set sts=4 sw=4 tw=99 et ft=python: 2 | import os 3 | 4 | binary = Root.Program(builder, 'srcds') 5 | 6 | binary.sources += [ 7 | 'cvars.cpp', 8 | 'engine.cpp', 9 | 'fs.cpp', 10 | 'gameevents.cpp', 11 | 'main.cpp', 12 | 'networkstringtable.cpp', 13 | 'server.cpp', 14 | 'sound.cpp', 15 | 'spatialpartition.cpp', 16 | 'trace.cpp', 17 | 'voice.cpp', 18 | ] 19 | binary.compiler.cxxincludes += [ 20 | os.path.join(builder.sourcePath), 21 | os.path.join(builder.sourcePath, 'public'), 22 | os.path.join(builder.sourcePath, 'public', 'engine'), 23 | os.path.join(builder.sourcePath, 'public', 'tier1'), 24 | os.path.join(builder.sourcePath, 'third_party', 'amtl'), 25 | ] 26 | binary.compiler.linkflags += [ 27 | '-Wl,-z,origin', 28 | ] 29 | binary.compiler.postlink += [ 30 | Root.tier1[builder.cxx.target.arch], 31 | '-ldl', 32 | '-lpthread', 33 | ] 34 | 35 | # Transform 'tier0' => 'tier0_i486.so' or whatever funky name is needed for 36 | # this platform. The rename map is computed in AMBuildScript. 37 | def link_library(srcbin, destname_key): 38 | _, ext = os.path.splitext(srcbin.path) 39 | newname = Root.renames[binary.compiler.target.arch][destname_key] 40 | newname += ext 41 | 42 | output_path = os.path.join(binary.localFolder, newname) 43 | 44 | # Ensure the output path exists. 45 | builder.AddFolder(binary.localFolder) 46 | output = builder.AddSymlink(srcbin, output_path) 47 | 48 | binary.compiler.weaklinkdeps += [output] 49 | binary.compiler.linkflags += ['-Wl,-rpath,$ORIGIN/'] 50 | binary.compiler.linkflags += [newname] 51 | 52 | arch = binary.compiler.target.arch 53 | link_library(Root.tier0[arch], 'tier0') 54 | link_library(Root.tier0[arch], 'vstdlib') 55 | 56 | entry = builder.Add(binary).binary 57 | Root.srcds[binary.compiler.target.arch] = entry 58 | -------------------------------------------------------------------------------- /srcds/cvars.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "cvars.h" 3 | 4 | #include 5 | 6 | #include "tier0/commandline.h" 7 | #include "tier0/dbg.h" 8 | #include "tier1/interface.h" 9 | 10 | static CommandManager sCommandManager; 11 | 12 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CommandManager, ICvar, CVAR_INTERFACE_VERSION, sCommandManager); 13 | 14 | CommandManager::CommandManager() 15 | { 16 | g_pCVar = this; 17 | } 18 | 19 | CommandManager::~CommandManager() 20 | { 21 | g_pCVar = nullptr; 22 | } 23 | 24 | void 25 | CommandManager::RegisterConCommand(ConCommandBase* base) 26 | { 27 | commands_.emplace(base->GetName(), base); 28 | } 29 | 30 | void 31 | CommandManager::UnregisterConCommand(ConCommandBase* base) 32 | { 33 | if (auto iter = commands_.find(base->GetName()); iter != commands_.end()) 34 | commands_.erase(iter); 35 | } 36 | 37 | ConCommand* 38 | CommandManager::FindCommand(const char* name) 39 | { 40 | if (auto iter = commands_.find(name); iter != commands_.end()) { 41 | if (iter->second->IsCommand()) 42 | return reinterpret_cast(iter->second); 43 | } 44 | return nullptr; 45 | } 46 | 47 | ConCommandBase* 48 | CommandManager::FindCommandBase(const char* name) 49 | { 50 | if (auto iter = commands_.find(name); iter != commands_.end()) 51 | return iter->second; 52 | return nullptr; 53 | } 54 | 55 | void 56 | CommandManager::RemoveOwnedCmds(void* token) 57 | { 58 | auto iter = commands_.begin(); 59 | while (iter != commands_.end()) { 60 | if (iter->second->owner_token() == token) 61 | iter = commands_.erase(iter); 62 | else 63 | iter++; 64 | } 65 | } 66 | 67 | const char* 68 | CommandManager::GetCommandLineValue(const char* var) 69 | { 70 | return CommandLine()->ParmValue(var, nullptr); 71 | } 72 | 73 | auto 74 | CommandManager::NewConCmdIterator() -> ICvar::IIteratorImpl* 75 | { 76 | std::vector cmds; 77 | for (const auto& p : commands_) 78 | cmds.emplace_back(p.second); 79 | 80 | std::sort(cmds.begin(), cmds.end(), [](ConCommandBase* a, ConCommandBase* b) -> bool { 81 | return strcmp(a->GetName(), b->GetName()) < 0; 82 | }); 83 | 84 | return new CmdIterator(std::move(cmds)); 85 | } 86 | 87 | ConVar* CommandManager::FindVar(const char *name) { 88 | auto cmd = FindCommandBase(name); 89 | if (cmd && !cmd->IsCommand()) 90 | return static_cast(cmd); 91 | return nullptr; 92 | } 93 | 94 | void CommandManager::CallGlobalChangeCallbacks(ConVar *var, const char *pOldString, float flOldValue) { 95 | Error("%s not yet implemented\n", __func__); 96 | } 97 | 98 | CommandManager::CmdIterator::CmdIterator(std::vector&& cmds) 99 | : cmds_(std::move(cmds)), 100 | iter_(cmds.begin()) 101 | { 102 | } 103 | -------------------------------------------------------------------------------- /srcds/cvars.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "tier1/convar.h" 3 | 4 | class CommandManager : public ICvar 5 | { 6 | public: 7 | CommandManager(); 8 | ~CommandManager(); 9 | 10 | void RegisterConCommand(ConCommandBase* base) override; 11 | void UnregisterConCommand(ConCommandBase* base) override; 12 | ConCommand* FindCommand(const char* name) override; 13 | ConCommandBase* FindCommandBase(const char* name) override; 14 | const char* GetCommandLineValue(const char* var) override; 15 | IIteratorImpl* NewConCmdIterator() override; 16 | ConVar* FindVar(const char *var_name) override; 17 | void CallGlobalChangeCallbacks(ConVar *var, const char *pOldString, float flOldValue) override; 18 | void RemoveOwnedCmds(void* token) override; 19 | 20 | class CmdIterator : public ICvar::IIteratorImpl 21 | { 22 | public: 23 | CmdIterator(std::vector&& cmds); 24 | void SetFirst() override { iter_ = cmds_.begin(); } 25 | void Next() override { iter_++; } 26 | bool IsValid() override { return iter_ != cmds_.end(); } 27 | ConCommandBase* Get() override { return *iter_; } 28 | void DeleteThis() override { delete this; } 29 | 30 | private: 31 | std::vector cmds_; 32 | std::vector::iterator iter_; 33 | }; 34 | 35 | private: 36 | std::unordered_map commands_; 37 | }; 38 | -------------------------------------------------------------------------------- /srcds/engine.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "engine.h" 3 | 4 | #include 5 | #include "server.h" 6 | #include "tier0/logging.h" 7 | #include "tier1/interface.h" 8 | 9 | static Engine sInstance; 10 | 11 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(Engine, IVEngineServer, "VEngineServer023", sInstance); 12 | 13 | Engine* Engine::get() { 14 | return &sInstance; 15 | } 16 | 17 | Engine::Engine() { 18 | edicts_.resize(MAX_EDICTS); 19 | vars_.maxEntities = (int)edicts_.size(); 20 | vars_.pEdicts = &edicts_[0]; 21 | vars_.interval_per_tick = 1.0 / 60.0f; 22 | } 23 | 24 | void 25 | Engine::ClientPrintf(edict_t* edict, const char* msg) 26 | { 27 | LogManager::get()->Log(LogLevel::Message, "ClientPrintf: %s", msg); 28 | } 29 | 30 | void 31 | Engine::ServerCommand(const char* str) 32 | { 33 | Server::get()->AddCommand(str); 34 | } 35 | 36 | void 37 | Engine::LogPrint(const char* msg) 38 | { 39 | LogManager::get()->Log(LogLevel::Normal, "%s", msg); 40 | } 41 | 42 | void 43 | Engine::GetGameDir(char* buffer, int length) 44 | { 45 | ke::SafeStrcpy(buffer, length, game_dir_.c_str()); 46 | } 47 | 48 | edict_t* 49 | Engine::CreateFakeClient(const char*) 50 | { 51 | Error("%s not implemented", __func__); 52 | return nullptr; 53 | } 54 | 55 | bool 56 | Engine::LockNetworkStringTables(bool) 57 | { 58 | Error("%s not implemented", __func__); 59 | return false; 60 | } 61 | 62 | INetChannelInfo* 63 | Engine::GetPlayerNetInfo(int playerIndex) 64 | { 65 | Error("%s not implemented", __func__); 66 | return nullptr; 67 | } 68 | 69 | void 70 | Engine::EmitAmbientSound(int entindex, const Vector &pos, const char *samp, float vol, 71 | soundlevel_t soundlevel, int fFlags, int pitch, 72 | float delay) 73 | { 74 | Error("%s not implemented", __func__); 75 | } 76 | 77 | void 78 | Engine::FadeClientVolume(const edict_t *pEdict, float fadePercent, float fadeOutSeconds, 79 | float holdTime, float fadeInSeconds) 80 | { 81 | Error("%s not implemented", __func__); 82 | } 83 | 84 | bool 85 | Engine::GetPlayerInfo(int ent_num, player_info_t *pinfo) 86 | { 87 | Error("%s not implemented", __func__); 88 | return false; 89 | } 90 | 91 | int Engine::PrecacheModel(const char *s, bool preload) 92 | { 93 | Error("%s not implemented", __func__); 94 | return 0; 95 | } 96 | 97 | int Engine::PrecacheSentenceFile(const char *s, bool preload) 98 | { 99 | Error("%s not implemented", __func__); 100 | return 0; 101 | } 102 | 103 | int Engine::PrecacheDecal(const char *name, bool preload) 104 | { 105 | Error("%s not implemented", __func__); 106 | return 0; 107 | } 108 | 109 | int Engine::PrecacheGeneric(const char *s, bool preload) 110 | { 111 | Error("%s not implemented", __func__); 112 | return 0; 113 | } 114 | 115 | void Engine::SetFakeClientConVarValue(edict_t *pEntity, const char *cvar, const char *value) 116 | { 117 | Error("%s not implemented", __func__); 118 | } 119 | 120 | bool Engine::IsModelPrecached(char const *s) const 121 | { 122 | Error("%s not implemented", __func__); 123 | return false; 124 | } 125 | 126 | bool Engine::IsDecalPrecached(char const *s) const 127 | { 128 | Error("%s not implemented", __func__); 129 | return false; 130 | } 131 | 132 | bool Engine::IsGenericPrecached(char const *s) const 133 | { 134 | Error("%s not implemented", __func__); 135 | return false; 136 | } 137 | 138 | void Engine::Message_DetermineMulticastRecipients(bool usepas, const Vector& origin, 139 | CPlayerBitVec& playerbits) 140 | { 141 | Error("%s not implemented", __func__); 142 | } 143 | 144 | edict_t *Engine::CreateEdict(int iForceEdictIndex) 145 | { 146 | Error("%s not implemented", __func__); 147 | return nullptr; 148 | } 149 | 150 | void Engine::RemoveEdict(edict_t *e) 151 | { 152 | Error("%s not implemented", __func__); 153 | } 154 | 155 | int Engine::GetEntityCount() 156 | { 157 | Error("%s not implemented", __func__); 158 | return 0; 159 | } 160 | 161 | void 162 | Engine::ServerExecute() 163 | { 164 | Server::get()->ExecuteAll(); 165 | } 166 | 167 | int 168 | Engine::GetPlayerUserId(const edict_t *e) 169 | { 170 | Error("%s not implemented", __func__); 171 | return 0; 172 | } 173 | 174 | void 175 | Engine::InsertServerCommand(const char *str) 176 | { 177 | Server::get()->InsertCommand(str); 178 | } 179 | 180 | const char *Engine::GetClientConVarValue(int clientIndex, const char *name) { 181 | Error("%s not implemented", __func__); 182 | return ""; 183 | } 184 | 185 | void Engine::ClientCommand(edict_t *pEdict, const char *szFmt, ...) { 186 | Error("%s not implemented", __func__); 187 | } 188 | 189 | QueryCvarCookie_t Engine::StartQueryCvarValue(edict_t *pPlayerEntity, const char *pName) { 190 | Error("%s not implemented", __func__); 191 | return -1; 192 | } 193 | 194 | bf_write *Engine::UserMessageBegin(IRecipientFilter *filter, int msg_type, const char* name) { 195 | Error("%s not implemented", __func__); 196 | return nullptr; 197 | } 198 | 199 | void Engine::MessageEnd() { 200 | Error("%s not implemented", __func__); 201 | } 202 | 203 | const char *Engine::GetPlayerNetworkIDString(const edict_t *e) { 204 | Error("%s not implemented", __func__); 205 | return ""; 206 | } 207 | 208 | const CSteamID* Engine::GetClientSteamID(edict_t *pPlayerEdict) { 209 | Error("%s not implemented", __func__); 210 | return nullptr; 211 | } 212 | 213 | bool Engine::IsClientFullyAuthenticated(edict_t *pEdict) { 214 | Error("%s not implemented", __func__); 215 | return false; 216 | } 217 | 218 | void Engine::ChangeLevel(const char *s1, const char *s2) { 219 | map_ = s1; 220 | vars_.mapname = MAKE_STRING(map_.c_str()); 221 | } 222 | 223 | CSharedEdictChangeInfo* Engine::GetSharedEdictChangeInfo() { 224 | Error("%s not implemented", __func__); 225 | return nullptr; 226 | } 227 | 228 | IChangeInfoAccessor* Engine::GetChangeAccessor(const edict_t *pEdict) { 229 | Error("%s not implemented", __func__); 230 | return nullptr; 231 | } 232 | 233 | int Engine::IsMapValid(const char *filename) { 234 | Error("%s not implemented", __func__); 235 | return 0; 236 | } 237 | 238 | const char *Engine::GetMapEntitiesString() { 239 | Error("%s not implemented", __func__); 240 | return ""; 241 | } 242 | 243 | void Engine::Think() { 244 | // We don't do pausing yet. 245 | vars_.tickcount++; 246 | vars_.curtime = double(vars_.interval_per_tick) * vars_.tickcount; 247 | } 248 | 249 | class ServerPluginHelpers : public IServerPluginHelpers 250 | { 251 | public: 252 | void CreateMessage(edict_t *pEntity, DIALOG_TYPE type, KeyValues *data, 253 | IServerPluginCallbacks *plugin) override; 254 | void ClientCommand(edict_t *ent, const char *cmd) override; 255 | QueryCvarCookie_t StartQueryCvarValue(edict_t *pPlayerEntity, const char *pName) override; 256 | } sServerPluginHelpers; 257 | 258 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(ServerPluginHelpers, IServerPluginHelpers, 259 | INTERFACEVERSION_ISERVERPLUGINHELPERS, sServerPluginHelpers); 260 | 261 | void ServerPluginHelpers::CreateMessage(edict_t *pEntity, DIALOG_TYPE type, KeyValues *data, 262 | IServerPluginCallbacks *plugin) 263 | { 264 | Error("%s not implemented", __func__); 265 | } 266 | 267 | void ServerPluginHelpers::ClientCommand(edict_t *ent, const char *cmd) { 268 | Error("%s not implemented", __func__); 269 | } 270 | 271 | QueryCvarCookie_t ServerPluginHelpers::StartQueryCvarValue(edict_t *pPlayerEntity, 272 | const char *pName) 273 | { 274 | Error("%s not implemented", __func__); 275 | return InvalidQueryCvarCookie; 276 | } 277 | -------------------------------------------------------------------------------- /srcds/engine.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | #include "eiface.h" 7 | 8 | class Engine final : public IVEngineServer 9 | { 10 | public: 11 | Engine(); 12 | void ClientPrintf(edict_t* edict, const char* msg) override; 13 | void ServerCommand(const char* str) override; 14 | void LogPrint(const char* msg) override; 15 | void GetGameDir(char* buffer, int length) override; 16 | bool IsDedicatedServer() override { return true; } 17 | void SetView(edict_t*, edict_t*) override {} 18 | void LightStyle(int, const char*) override {} 19 | void PlaybackTempEntity(IRecipientFilter&, float, const void*, 20 | const SendTable*, int) override {} 21 | edict_t* CreateFakeClient(const char* name) override; 22 | bool LockNetworkStringTables(bool lock) override; 23 | INetChannelInfo* GetPlayerNetInfo(int playerIndex) override; 24 | void EmitAmbientSound(int entindex, const Vector &pos, const char *samp, float vol, 25 | soundlevel_t soundlevel, int fFlags, int pitch, 26 | float delay = 0.0f) override; 27 | void FadeClientVolume(const edict_t *pEdict, float fadePercent, float fadeOutSeconds, 28 | float holdTime, float fadeInSeconds) override; 29 | bool GetPlayerInfo(int ent_num, player_info_t *pinfo) override; 30 | int PrecacheModel(const char *s, bool preload = false) override; 31 | int PrecacheSentenceFile(const char *s, bool preload = false) override; 32 | int PrecacheDecal(const char *name, bool preload = false) override; 33 | int PrecacheGeneric(const char *s, bool preload = false) override; 34 | void SetFakeClientConVarValue(edict_t *pEntity, const char *cvar, const char *value) override; 35 | bool IsModelPrecached(char const *s) const override; 36 | bool IsDecalPrecached(char const *s) const override; 37 | bool IsGenericPrecached(char const *s) const override; 38 | void Message_DetermineMulticastRecipients(bool usepas, const Vector& origin, CPlayerBitVec& playerbits) override; 39 | edict_t *CreateEdict(int iForceEdictIndex = -1) override; 40 | void RemoveEdict(edict_t *e) override; 41 | int GetEntityCount() override; 42 | void ServerExecute() override; 43 | int GetPlayerUserId(const edict_t *e) override; 44 | void InsertServerCommand(const char *str) override; 45 | const char *GetClientConVarValue(int clientIndex, const char *name) override; 46 | void ClientCommand(edict_t *pEdict, const char *szFmt, ...) override; 47 | QueryCvarCookie_t StartQueryCvarValue(edict_t *pPlayerEntity, const char *pName) override; 48 | bf_write *UserMessageBegin(IRecipientFilter *filter, int msg_type, const char* name) override; 49 | void MessageEnd() override; 50 | const char *GetPlayerNetworkIDString(const edict_t *e) override; 51 | const CSteamID* GetClientSteamID(edict_t *pPlayerEdict) override; 52 | bool IsClientFullyAuthenticated(edict_t *pEdict) override; 53 | void ChangeLevel(const char *s1, const char *s2) override; 54 | CSharedEdictChangeInfo* GetSharedEdictChangeInfo() override; 55 | IChangeInfoAccessor* GetChangeAccessor(const edict_t *pEdict) override; 56 | int IsMapValid(const char *filename) override; 57 | const char *GetMapEntitiesString() override; 58 | 59 | void Think(); 60 | 61 | void set_game_dir(const std::string& dir) { game_dir_ = dir; } 62 | const std::string& game_dir() const { return game_dir_; } 63 | 64 | static Engine* get(); 65 | 66 | edict_t* edicts() { return &edicts_[0]; } 67 | int num_edicts() const { return (int)edicts_.size(); } 68 | CGlobalVars& vars() { return vars_; } 69 | const std::string& map() const { return map_; } 70 | 71 | private: 72 | std::string game_dir_; 73 | std::vector edicts_; 74 | CGlobalVars vars_; 75 | std::string map_; 76 | }; 77 | -------------------------------------------------------------------------------- /srcds/fs.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "fs.h" 3 | 4 | #include 5 | #include 6 | 7 | #include "tier0/dbg.h" 8 | #include "tier1/interface.h" 9 | 10 | FileSystem sFileSystem; 11 | 12 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(FileSystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION, 13 | sFileSystem); 14 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(FileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION, 15 | sFileSystem); 16 | 17 | FileSystem* FileSystem::get() { 18 | return &sFileSystem; 19 | } 20 | 21 | FileHandle_t 22 | FileSystem::Open(const char* name, const char* options, const char* path_id) 23 | { 24 | return fopen(name, options); 25 | } 26 | 27 | bool 28 | FileSystem::FileExists(const char *path, const char *path_id) 29 | { 30 | if (FILE* fp = fopen(path, "rb")) { 31 | fclose(fp); 32 | return true; 33 | } 34 | return false; 35 | } 36 | 37 | unsigned int 38 | FileSystem::Size(FileHandle_t hfile) 39 | { 40 | auto file = reinterpret_cast(hfile); 41 | auto pos = ftell(file); 42 | if (pos < 0) { 43 | Error("ftell failed\n"); 44 | return 0; 45 | } 46 | 47 | if (fseek(file, 0, SEEK_END)) { 48 | Error("fseek SEEK_END failed\n"); 49 | return 0; 50 | } 51 | 52 | auto size = ftell(file); 53 | if (fseek(file, pos, SEEK_SET)) { 54 | Error("fseek SEEK_SET failed\n"); 55 | return 0; 56 | } 57 | return size; 58 | } 59 | 60 | int 61 | FileSystem::Read(void* output, int size, FileHandle_t hfile) 62 | { 63 | auto file = reinterpret_cast(hfile); 64 | return (int)fread(output, 1, size, file); 65 | } 66 | 67 | void 68 | FileSystem::Close(FileHandle_t hfile) 69 | { 70 | auto file = reinterpret_cast(hfile); 71 | fclose(file); 72 | } 73 | 74 | int FileSystem::Write(void const* pInput, int size, FileHandle_t file) { 75 | auto fp = reinterpret_cast(file); 76 | return fwrite(pInput, 1, size, fp); 77 | } 78 | 79 | void FileSystem::Seek(FileHandle_t file, int pos, FileSystemSeek_t seekType) { 80 | auto fp = reinterpret_cast(file); 81 | fseek(fp, pos, (int)seekType); 82 | } 83 | 84 | unsigned int FileSystem::Tell(FileHandle_t file) { 85 | auto fp = reinterpret_cast(file); 86 | return ftell(fp); 87 | } 88 | 89 | int FileSystem::FPrintf(FileHandle_t file, const char *pFormat, ...) { 90 | auto fp = reinterpret_cast(file); 91 | 92 | va_list ap; 93 | va_start(ap, pFormat); 94 | auto n =vfprintf(fp, pFormat, ap); 95 | va_end(ap); 96 | return n; 97 | } 98 | 99 | void FileSystem::Flush(FileHandle_t file) { 100 | auto fp = reinterpret_cast(file); 101 | fflush(fp); 102 | } 103 | 104 | bool FileSystem::IsOk(FileHandle_t file) { 105 | auto fp = reinterpret_cast(file); 106 | return ferror(fp) != 0; 107 | } 108 | 109 | void FileSystem::RemoveFile(char const* pRelativePath, const char *pathID) { 110 | std::error_code ec; 111 | std::filesystem::remove(pRelativePath); 112 | } 113 | 114 | bool FileSystem::RenameFile(char const *pOldPath, char const *pNewPath, const char *pathID) { 115 | std::error_code ec; 116 | std::filesystem::rename(pOldPath, pNewPath); 117 | return !!ec; 118 | } 119 | 120 | bool FileSystem::IsDirectory(const char *pFileName, const char *pathID) { 121 | std::error_code ec; 122 | return std::filesystem::is_directory(pFileName, ec); 123 | } 124 | 125 | void FileSystem::CreateDirHierarchy(const char *path, const char *pathID) { 126 | std::error_code ec; 127 | std::filesystem::create_directories(path, ec); 128 | } 129 | 130 | const char* FileSystem::FindFirstEx(const char *pWildCard, const char *pPathID, 131 | FileFindHandle_t *pHandle) 132 | { 133 | *pHandle = -1; 134 | return nullptr; 135 | } 136 | 137 | const char* FileSystem::FindNext(FileFindHandle_t handle) { 138 | return nullptr; 139 | } 140 | 141 | bool FileSystem::FindIsDirectory(FileFindHandle_t handle) { 142 | return false; 143 | } 144 | 145 | void FileSystem::FindClose(FileFindHandle_t handle) { 146 | } 147 | 148 | char *FileSystem::ReadLine(char *pOutput, int maxChars, FileHandle_t file) { 149 | auto fp = reinterpret_cast(file); 150 | return fgets(pOutput, maxChars, fp); 151 | } 152 | 153 | bool FileSystem::EndOfFile(FileHandle_t file) { 154 | auto fp = reinterpret_cast(file); 155 | return feof(fp); 156 | } 157 | 158 | unsigned int FileSystem::Size(const char* file, const char* pathID) { 159 | auto h = Open(file, "rb", pathID); 160 | if (!h) 161 | return 0; 162 | auto s = Size(h); 163 | Close(h); 164 | return s; 165 | } 166 | 167 | CSysModule *FileSystem::LoadModule(const char *pFileName, const char *pPathID, 168 | bool bValidatedDllOnly) 169 | { 170 | return OpenCSysModule(pFileName); 171 | } 172 | 173 | void FileSystem::UnloadModule(CSysModule *pModule) { 174 | CloseCSysModule(pModule); 175 | } 176 | 177 | int FileSystem::GetSearchPath(const char* pathID, bool bGetPackFiles, char* pPath, int nMaxLen) { 178 | return 0; 179 | } 180 | -------------------------------------------------------------------------------- /srcds/fs.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "filesystem.h" 11 | 12 | class FileSystem final : public IFileSystem 13 | { 14 | public: 15 | FileHandle_t Open(const char* name, const char* options, 16 | const char* path_id = nullptr) override; 17 | unsigned int Size(FileHandle_t file) override; 18 | int Read(void* output, int size, FileHandle_t file) override; 19 | void Close(FileHandle_t file) override; 20 | bool FileExists(const char *path, const char *path_id = nullptr) override; 21 | int Write(void const* pInput, int size, FileHandle_t file) override; 22 | void Seek(FileHandle_t file, int pos, FileSystemSeek_t seekType) override; 23 | unsigned int Tell(FileHandle_t file) override; 24 | int FPrintf(FileHandle_t file, const char *pFormat, ...) override; 25 | void Flush(FileHandle_t file) override; 26 | bool IsOk(FileHandle_t file) override; 27 | void RemoveFile(char const* pRelativePath, const char *pathID = nullptr) override; 28 | bool RenameFile(char const *pOldPath, char const *pNewPath, const char *pathID = nullptr) override; 29 | bool IsDirectory(const char *pFileName, const char *pathID = nullptr) override; 30 | void CreateDirHierarchy(const char *path, const char *pathID = nullptr) override; 31 | const char *FindFirstEx(const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle) override; 32 | const char *FindNext(FileFindHandle_t handle) override; 33 | bool FindIsDirectory(FileFindHandle_t handle) override; 34 | void FindClose(FileFindHandle_t handle) override; 35 | char *ReadLine(char *pOutput, int maxChars, FileHandle_t file) override; 36 | bool EndOfFile(FileHandle_t file) override; 37 | unsigned int Size(const char* file, const char* pathID = nullptr) override; 38 | CSysModule *LoadModule(const char *pFileName, const char *pPathID = 0, bool bValidatedDllOnly = true) override; 39 | void UnloadModule(CSysModule *pModule) override; 40 | int GetSearchPath(const char* pathID, bool bGetPackFiles, char* pPath, int nMaxLen) override; 41 | 42 | static FileSystem* get(); 43 | 44 | private: 45 | std::mutex mutex_; 46 | }; 47 | -------------------------------------------------------------------------------- /srcds/gameevents.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "gameevents.h" 3 | 4 | #include 5 | 6 | #include "tier0/dbg.h" 7 | #include "tier1/interface.h" 8 | 9 | static GameEventManager sGameEventManager; 10 | 11 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(GameEventManager, IGameEventManager2, 12 | INTERFACEVERSION_GAMEEVENTSMANAGER2, sGameEventManager); 13 | 14 | IGameEvent *GameEventManager::CreateEvent(const char *name, bool bForce, int *pCookie) { 15 | Error("%s not implemented", __func__); 16 | return nullptr; 17 | } 18 | 19 | bool GameEventManager::FireEvent(IGameEvent *event, bool bDontBroadcast) { 20 | depth_++; 21 | for (const auto& p : hooks_) { 22 | for (const auto& listener : p.second) { 23 | if (to_remove_.count(listener)) 24 | continue; 25 | listener->FireGameEvent(event); 26 | } 27 | } 28 | depth_--; 29 | 30 | if (!depth_) { 31 | for (const auto& entry : to_remove_) 32 | RemoveListenerImpl(entry); 33 | to_remove_.clear(); 34 | } 35 | return true; 36 | } 37 | 38 | void GameEventManager::FreeEvent(IGameEvent *event) { 39 | delete event; 40 | } 41 | 42 | IGameEvent *GameEventManager::DuplicateEvent(IGameEvent *event) { 43 | Error("%s not implemented", __func__); 44 | return nullptr; 45 | } 46 | 47 | bool GameEventManager::AddListener(IGameEventListener2 *listener, const char *name, 48 | bool bServerSide) 49 | { 50 | hooks_[name].emplace_back(listener); 51 | return true; 52 | } 53 | 54 | void GameEventManager::RemoveListener(IGameEventListener2 *listener) { 55 | if (depth_) 56 | to_remove_.emplace(listener); 57 | else 58 | RemoveListenerImpl(listener); 59 | } 60 | 61 | void GameEventManager::RemoveListenerImpl(IGameEventListener2* listener) { 62 | assert(!depth_); 63 | for (auto& p : hooks_) 64 | p.second.remove(listener); 65 | } 66 | 67 | bool GameEventManager::FindListener(IGameEventListener2 *listener, const char *name) { 68 | auto hi = hooks_.find(name); 69 | if (hi == hooks_.end()) 70 | return false; 71 | for (const auto& entry : hi->second) { 72 | if (entry == listener) 73 | return true; 74 | } 75 | return false; 76 | } 77 | -------------------------------------------------------------------------------- /srcds/gameevents.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "igameevents.h" 10 | 11 | class GameEventManager : public IGameEventManager2 12 | { 13 | public: 14 | IGameEvent *CreateEvent(const char *name, bool bForce = false, int *pCookie = nullptr) override; 15 | bool FireEvent(IGameEvent *event, bool bDontBroadcast = false) override; 16 | void FreeEvent(IGameEvent *event) override; 17 | IGameEvent *DuplicateEvent(IGameEvent *event) override; 18 | bool AddListener(IGameEventListener2 *listener, const char *name, bool bServerSide) override; 19 | void RemoveListener(IGameEventListener2 *listener) override; 20 | bool FindListener(IGameEventListener2 *listener, const char *name) override; 21 | 22 | private: 23 | void RemoveListenerImpl(IGameEventListener2* listener); 24 | 25 | private: 26 | size_t depth_ = 0; 27 | std::unordered_map> hooks_; 28 | std::unordered_set to_remove_; 29 | }; 30 | -------------------------------------------------------------------------------- /srcds/main.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include "fs.h" 9 | #include "server.h" 10 | #include "tier0/commandline.h" 11 | 12 | #ifdef _WIN32 13 | # define NOMINMAX 14 | # define WIN32_LEAN_AND_MEAN 15 | # include 16 | #else 17 | # include 18 | # include 19 | # include 20 | #endif 21 | 22 | using namespace std::string_literals; 23 | 24 | class ServerConsole 25 | { 26 | public: 27 | bool Run(); 28 | void Interrupt(); 29 | void PostQuit() { quitting_ = true; } 30 | void EnterRunMode() { run_mode_ = true; } 31 | void RunOneFrame() { run_one_frame_ = true; } 32 | 33 | private: 34 | bool Setup(); 35 | bool InstallHandlers(); 36 | 37 | private: 38 | Server server_; 39 | bool quitting_ = false; 40 | bool run_mode_ = false; 41 | bool run_one_frame_ = false; 42 | } sServerConsole; 43 | 44 | int main(int argc, char** argv) 45 | { 46 | CommandLineImpl::get()->Init(argc, argv); 47 | 48 | return sServerConsole.Run() ? 0 : 1; 49 | } 50 | 51 | bool ServerConsole::Run() { 52 | if (!Setup()) 53 | return false; 54 | if (!InstallHandlers()) { 55 | server_.Shutdown(); 56 | return false; 57 | } 58 | 59 | fprintf(stdout, "Entering interactive mode.\n"); 60 | fprintf(stdout, "Use \"run\", \"continue\", or \"think\" to process frames.\n"); 61 | 62 | bool ran_cmdline_command = false; 63 | const char* cmdline_command = CommandLineImpl::get()->ParmValue("-command", nullptr); 64 | int max_tick_count = CommandLineImpl::get()->ParmValue("-run-ticks", -1); 65 | if (CommandLineImpl::get()->FindParm("-run") != -1) 66 | EnterRunMode(); 67 | 68 | while (!quitting_) { 69 | 70 | std::string cmdline; 71 | if (cmdline_command != nullptr && !ran_cmdline_command) { 72 | ran_cmdline_command = true; 73 | cmdline = cmdline_command; 74 | } else { 75 | fprintf(stdout, "> "); 76 | fflush(stdout); 77 | if (!std::getline(std::cin, cmdline)) { 78 | PostQuit(); 79 | break; 80 | } 81 | } 82 | 83 | server_.DispatchCommand(std::move(cmdline)); 84 | while (run_one_frame_ || server_.pending_action()) { 85 | bool diag = run_one_frame_; 86 | run_one_frame_ = false; 87 | 88 | server_.DoFrame(); 89 | 90 | if (diag && !run_one_frame_) 91 | ConMsg("Completed frame %d\n", Engine::get()->vars().tickcount); 92 | 93 | if (max_tick_count > 0 && Engine::get()->vars().tickcount >= max_tick_count) { 94 | PostQuit(); 95 | break; 96 | } 97 | } 98 | 99 | if (run_mode_) { 100 | fprintf(stdout, "Entering run mode.\n"); 101 | server_.Run(max_tick_count); 102 | run_mode_ = false; 103 | 104 | if (max_tick_count > 0 && Engine::get()->vars().tickcount >= max_tick_count) { 105 | PostQuit(); 106 | break; 107 | } 108 | 109 | fprintf(stdout, "Re-entering command mode.\n"); 110 | fflush(stdin); 111 | } 112 | } 113 | 114 | server_.Shutdown(); 115 | return true; 116 | } 117 | 118 | bool ServerConsole::Setup() { 119 | if (auto game_dir = CommandLine()->ParmValue("-game_dir")) 120 | Engine::get()->set_game_dir(game_dir); 121 | else 122 | Engine::get()->set_game_dir("."); 123 | 124 | #if defined(__linux__) 125 | char result[PATH_MAX + 1]; 126 | ssize_t rv = readlink("/proc/self/exe", result, PATH_MAX); 127 | if (rv == -1) { 128 | fprintf(stderr, "readlink /proc/self/exe failed: %s", strerror(errno)); 129 | return false; 130 | } 131 | result[rv] = '\0'; 132 | 133 | server_.set_dist_dir(dirname(result)); 134 | #endif 135 | 136 | const char* dir = Engine::get()->game_dir().c_str(); 137 | if (chdir(dir)) { 138 | fprintf(stderr, "chdir %s failed: %s\n", dir, strerror(errno)); 139 | return false; 140 | } 141 | 142 | if (!server_.Start()) 143 | return false; 144 | return true; 145 | } 146 | 147 | void ServerConsole::Interrupt() { 148 | server_.Interrupt(); 149 | } 150 | 151 | #ifdef _WIN32 152 | BOOL WINAPI ControlHandler(DWORD signal) { 153 | if (signal == CTRL_C_EVENT) 154 | sServerConsole.Interrupt(); 155 | return TRUE; 156 | } 157 | #else 158 | void ControlHandler(int) { 159 | sServerConsole.Interrupt(); 160 | } 161 | #endif 162 | 163 | bool ServerConsole::InstallHandlers() { 164 | #ifdef _WIN32 165 | if (!::SetConsoleCtrlHandler(ControlHandler, TRUE)) { 166 | fprintf(stderr, "Could not install console handler: %d\n", ::GetLastError()); 167 | return false; 168 | } 169 | #else 170 | struct sigaction handler; 171 | handler.sa_handler = ControlHandler; 172 | if (sigemptyset(&handler.sa_mask)) { 173 | fprintf(stderr, "sigemptyset failed: %s\n", strerror(errno)); 174 | return false; 175 | } 176 | handler.sa_flags = SA_RESTART; 177 | if (sigaction(SIGINT, &handler, nullptr)) { 178 | fprintf(stderr, "sigaction SIGINT failed: %s\n", strerror(errno)); 179 | return false; 180 | } 181 | #endif 182 | return true; 183 | } 184 | 185 | CON_COMMAND(think, "Run a single frame.") { 186 | sServerConsole.RunOneFrame(); 187 | } 188 | 189 | CON_COMMAND(quit, "Quit/exit srcds") { 190 | sServerConsole.PostQuit(); 191 | } 192 | static ConCommand exit_cmd("exit", quit, "Quit/exit srcds"); 193 | 194 | CON_COMMAND(run, "Enter run mode") { 195 | sServerConsole.EnterRunMode(); 196 | } 197 | static ConCommand continue_cmd("continue", run, "Enter run mode"); 198 | -------------------------------------------------------------------------------- /srcds/networkstringtable.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "networkstringtable.h" 3 | 4 | #include "tier0/dbg.h" 5 | #include "tier1/interface.h" 6 | 7 | static NetworkStringTableContainer sNetworkStringTableContainer; 8 | 9 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(NetworkStringTableContainer, INetworkStringTableContainer, INTERFACENAME_NETWORKSTRINGTABLESERVER, 10 | sNetworkStringTableContainer); 11 | 12 | INetworkStringTable* NetworkStringTableContainer::FindTable(const char* name) const 13 | { 14 | Error("%s not implemented", __func__); 15 | return nullptr; 16 | } 17 | 18 | INetworkStringTable* NetworkStringTableContainer::GetTable(int i) const 19 | { 20 | Error("%s not implemented", __func__); 21 | return nullptr; 22 | } 23 | 24 | int NetworkStringTableContainer::GetNumTables() const 25 | { 26 | Error("%s not implemented", __func__); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /srcds/networkstringtable.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "networkstringtabledefs.h" 5 | 6 | class NetworkStringTableContainer : public INetworkStringTableContainer 7 | { 8 | public: 9 | INetworkStringTable* FindTable(const char* name) const override; 10 | INetworkStringTable* GetTable(int i) const override; 11 | int GetNumTables() const override; 12 | }; 13 | -------------------------------------------------------------------------------- /srcds/server.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "server.h" 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include "engine.h" 10 | #include "fs.h" 11 | #include "tier0/commandline.h" 12 | 13 | using namespace std::chrono_literals; 14 | using namespace std::string_literals; 15 | 16 | Server* Server::sInstance = nullptr; 17 | 18 | #if defined(_WIN32) 19 | static constexpr char kLibraryExt[] = ".dll"; 20 | #elif defined(__linux__) 21 | static constexpr char kLibraryExt[] = ".so"; 22 | #else 23 | static constexpr char kLibraryExt[] = ".dylib"; 24 | #endif 25 | 26 | Server::Server() 27 | { 28 | assert(!sInstance); 29 | sInstance = this; 30 | thread_id_ = std::this_thread::get_id(); 31 | } 32 | 33 | Server::~Server() 34 | { 35 | assert(sInstance == this); 36 | sInstance = nullptr; 37 | } 38 | 39 | bool 40 | Server::Start() 41 | { 42 | LogManager::get()->AddListener(this); 43 | ConVar_Register(); 44 | 45 | auto path = "gamedll"s + kLibraryExt; 46 | 47 | if (!dist_dir_.empty()) 48 | path = dist_dir_ + "/" + path; 49 | 50 | char error[255]; 51 | game_ = ke::SharedLib::Open(path.c_str(), error, sizeof(error)); 52 | if (!game_) { 53 | Error("Could not open gamedll %s: %s\n", path.c_str(), error); 54 | return false; 55 | } 56 | game_ci_ = game_->get("CreateInterface"); 57 | if (!game_ci_) { 58 | Error("Could not load gamedll: no CreateInterface\n"); 59 | return false; 60 | } 61 | 62 | gamedll_ = 63 | reinterpret_cast(game_ci_(INTERFACEVERSION_SERVERGAMEDLL, nullptr)); 64 | if (!gamedll_) { 65 | Error("Could not load gamedll: %s not found\n", INTERFACEVERSION_SERVERGAMEDLL); 66 | return false; 67 | } 68 | 69 | game_clients_ = 70 | reinterpret_cast(game_ci_(INTERFACEVERSION_SERVERGAMECLIENTS, nullptr)); 71 | if (!game_clients_) { 72 | Error("Could not load gamedll: %s not found\n", INTERFACEVERSION_SERVERGAMECLIENTS); 73 | return false; 74 | } 75 | 76 | // Notify gamedll of load. 77 | auto engine = Engine::get(); 78 | if (!gamedll_->DLLInit(CreateInterfaceWrapper, nullptr, nullptr, &engine->vars())) { 79 | Error("Could not load gamedll: DLLInit returned false\n"); 80 | } 81 | 82 | // Game is done loading. Load metamod and plugins. 83 | LoadPlugins(); 84 | AddCommand("meta game"); 85 | AddCommand("meta list"); 86 | ProcessMessages(); 87 | 88 | // Init and activate the server. 89 | if (!gamedll_->GameInit()) { 90 | Error("Could not load gamedll: GameInit returned false\n"); 91 | return false; 92 | } 93 | if (auto val = CommandLine()->ParmValue("+maxplayers")) { 94 | if (auto ival = atoi(val); ival > 0) 95 | maxclients_ = ival; 96 | } 97 | 98 | // Load map if specified. 99 | auto map_name = CommandLine()->ParmValue("+map"); 100 | if (map_name) 101 | ChangeLevel(map_name); 102 | 103 | return true; 104 | } 105 | 106 | void Server::Shutdown() { 107 | shutting_down_ = true; 108 | 109 | while (!plugins_.empty()) { 110 | auto plugin = std::move(plugins_.back()); 111 | plugins_.pop_back(); 112 | plugin->callbacks->Unload(); 113 | } 114 | 115 | if (gamedll_) 116 | gamedll_->DLLShutdown(); 117 | 118 | LogManager::get()->RemoveListener(this); 119 | } 120 | 121 | void 122 | Server::Run(int max_tick_count) 123 | { 124 | while (!interrupt_) { 125 | DoFrame(); 126 | if (interrupt_) 127 | break; 128 | 129 | // Gross. 130 | int ms = int(Engine::get()->vars().interval_per_tick * 1000.0f); 131 | std::this_thread::sleep_for(std::chrono::milliseconds(ms)); 132 | 133 | if (max_tick_count > 0 && Engine::get()->vars().tickcount >= max_tick_count) 134 | break; 135 | } 136 | 137 | interrupt_ = false; 138 | } 139 | 140 | void 141 | Server::DoFrame() 142 | { 143 | std::function work; 144 | { 145 | std::lock_guard lock(mutex_); 146 | if (!messages_.empty()) { 147 | work = std::move(messages_.front()); 148 | messages_.pop_front(); 149 | } 150 | } 151 | 152 | // Set before calling work, in case more state changes happen. 153 | pending_action_ = false; 154 | 155 | if (work) 156 | work(); 157 | 158 | Engine::get()->Think(); 159 | } 160 | 161 | void 162 | Server::PostMessage(std::function&& msg) 163 | { 164 | std::lock_guard lock(mutex_); 165 | messages_.emplace_back(std::move(msg)); 166 | } 167 | 168 | void 169 | Server::InsertMessage(std::function&& msg) 170 | { 171 | std::lock_guard lock(mutex_); 172 | messages_.emplace_front(std::move(msg)); 173 | } 174 | 175 | void 176 | Server::ProcessMessages() 177 | { 178 | assert(std::this_thread::get_id() == thread_id_); 179 | 180 | decltype(messages_) work; 181 | { 182 | std::lock_guard lock(mutex_); 183 | work = std::move(messages_); 184 | } 185 | 186 | while (!work.empty()) { 187 | auto msg = std::move(work.front()); 188 | work.pop_front(); 189 | 190 | msg(); 191 | } 192 | } 193 | 194 | void 195 | Server::ExecuteAll() 196 | { 197 | ProcessMessages(); 198 | } 199 | 200 | void 201 | Server::Log(const LoggingContext_t* cx, const char* message) 202 | { 203 | std::lock_guard lock(mutex_); 204 | if (cx->severity == LogLevel::Warning) 205 | fprintf(stdout, "WARNING: "); 206 | else if (cx->severity == LogLevel::Error) 207 | fprintf(stdout, "ERROR: "); 208 | fprintf(stdout, "%s", message); 209 | 210 | if (!ke::EndsWith(message, "\n")) 211 | fprintf(stdout, "\n"); 212 | } 213 | 214 | void Server::PluginLoad(std::string path_in) { 215 | assert(std::this_thread::get_id() == thread_id_); 216 | 217 | if (shutting_down_) { 218 | Error("Cannot load plugin %s during shutdown\n", path_in.c_str()); 219 | return; 220 | } 221 | 222 | if (!std::filesystem::exists(path_in) && !ke::EndsWith(path_in, kLibraryExt)) 223 | path_in += kLibraryExt; 224 | 225 | const char* path = path_in.c_str(); 226 | 227 | char buffer[255]; 228 | ke::RefPtr lib = ke::SharedLib::Open(path, buffer, sizeof(buffer)); 229 | if (!lib) { 230 | Msg("Could not open %s: %s\n", path, buffer); 231 | return; 232 | } 233 | 234 | auto plugin = std::make_unique(); 235 | plugin->path = path; 236 | plugin->lib = lib; 237 | 238 | auto ci = lib->get("CreateInterface"); 239 | if (!ci) { 240 | Msg("Could not open %s: CreateInterface not found\n", path); 241 | return; 242 | } 243 | 244 | for (int i = 4; i >= 1; i--) { 245 | auto iface_name = ke::StringPrintf("ISERVERPLUGINCALLBACKS%03d", i); 246 | 247 | int ret; 248 | if (auto iface = ci(iface_name.c_str(), &ret)) { 249 | plugin->version = i; 250 | plugin->callbacks = reinterpret_cast(iface); 251 | break; 252 | } 253 | } 254 | if (!plugin->callbacks) { 255 | Msg("Could not load %s: No IServerPlugin callbacks\n", path); 256 | return; 257 | } 258 | if (!plugin->callbacks->Load(&CreateInterfaceWrapper, game_ci_)) { 259 | Msg("Could not load %s: load failed\n", path); 260 | return; 261 | } 262 | plugins_.emplace_back(std::move(plugin)); 263 | 264 | Msg("Successfully loaded %s\n", path); 265 | } 266 | 267 | void 268 | Server::AddCommand(std::string str) 269 | { 270 | auto fun = [this, str{std::move(str)}]() mutable { 271 | DispatchCommand(std::move(str)); 272 | }; 273 | PostMessage(std::move(fun)); 274 | } 275 | 276 | void 277 | Server::InsertCommand(std::string str) 278 | { 279 | auto fun = [this, str{std::move(str)}]() mutable { 280 | DispatchCommand(std::move(str)); 281 | }; 282 | InsertMessage(std::move(fun)); 283 | } 284 | 285 | void 286 | Server::DispatchCommand(std::string str) 287 | { 288 | auto args = ParseArgs(str); 289 | if (args.empty()) 290 | return; 291 | 292 | auto cmd = g_pCVar->FindCommandBase(args[0].c_str()); 293 | if (!cmd) { 294 | ConMsg("Unknown command: %s\n", args[0].c_str()); 295 | return; 296 | } 297 | 298 | for (const auto& plugin : plugins_) 299 | plugin->callbacks->SetCommandClient(-1); 300 | game_clients_->SetCommandClient(-1); 301 | 302 | if (cmd->IsCommand()) { 303 | CCommand ccargs(std::move(str), std::move(args)); 304 | static_cast(cmd)->Dispatch(ccargs); 305 | } else if (args.size() == 1) { 306 | auto cvar = static_cast(cmd); 307 | ConMsg("%s\n", cvar->GetString()); 308 | } else { 309 | auto cvar = static_cast(cmd); 310 | cvar->SetValue(args[1].c_str()); 311 | } 312 | } 313 | 314 | void* 315 | Server::CreateInterfaceWrapper(const char* name, int* ret) 316 | { 317 | return Server::get()->CreateInterface(name, ret); 318 | } 319 | 320 | void* 321 | Server::CreateInterface(const char* name, int* ret) 322 | { 323 | if (strcmp(name, "MOCK_ENGINE") == 0) { 324 | if (ret) 325 | *ret = IFACE_OK; 326 | return Engine::get(); 327 | } 328 | 329 | return ::CreateInterface(name, ret); 330 | } 331 | 332 | void Server::ChangeLevel(const char* map) { 333 | auto engine = Engine::get(); 334 | if (!engine->map().empty()) { 335 | for (const auto& plugin : plugins_) 336 | plugin->callbacks->LevelShutdown(); 337 | gamedll_->LevelShutdown(); 338 | } 339 | 340 | auto old_map = engine->map(); 341 | engine->ChangeLevel(map, ""); 342 | 343 | for (const auto& plugin : plugins_) 344 | plugin->callbacks->LevelInit(map); 345 | 346 | gamedll_->LevelInit(engine->map().c_str(), "", old_map.c_str(), "", true, false); 347 | 348 | gamedll_->ServerActivate(engine->edicts(), engine->num_edicts(), maxclients_); 349 | for (const auto& plugin : plugins_) 350 | plugin->callbacks->ServerActivate(engine->edicts(), engine->num_edicts(), maxclients_); 351 | } 352 | 353 | void Server::LoadPlugins() { 354 | std::error_code ec; 355 | const std::filesystem::path addons{"addons"}; 356 | for (const auto& entry : std::filesystem::directory_iterator{addons, ec}) { 357 | if (!ke::EndsWith(entry.path(), ".vdf")) 358 | continue; 359 | 360 | auto kv = std::make_unique("Plugins"); 361 | kv->LoadFromFile(nullptr, entry.path().c_str()); 362 | 363 | if (auto file = kv->GetString("file", nullptr)) 364 | PluginLoad(file); 365 | } 366 | if (ec) { 367 | Error("Could not open plugin directory %s: %s\n", addons.c_str(), 368 | ec.message().c_str()); 369 | } 370 | } 371 | 372 | CON_COMMAND(plugin_load, "Load a plugin") 373 | { 374 | Server* server = Server::get(); 375 | if (args.ArgC() <= 1) { 376 | Msg("Usage: plugin_load \n"); 377 | return; 378 | } 379 | 380 | server->PluginLoad(args[1]); 381 | } 382 | 383 | CON_COMMAND(cvarlist, "List cvars/concommands") 384 | { 385 | const char* prefix = nullptr; 386 | if (args.ArgC() > 2) 387 | prefix = args[1]; 388 | 389 | ICvar::Iterator iter(g_pCVar); 390 | for (iter.SetFirst(); iter.IsValid(); iter.Next()) { 391 | auto cmd = iter.Get(); 392 | if (prefix && !ke::StartsWith(cmd->GetName(), prefix)) 393 | continue; 394 | 395 | auto help = cmd->GetHelpText(); 396 | if (help && help[0]) 397 | ConMsg(" %s - %s\n", cmd->GetName(), help); 398 | else 399 | ConMsg(" %s\n", cmd->GetName()); 400 | } 401 | } 402 | 403 | CON_COMMAND(changelevel, "Change the map") 404 | { 405 | if (args.ArgC() <= 1) { 406 | Msg("Usage: changelevel \n"); 407 | return; 408 | } 409 | 410 | std::string map = args.Arg(1); 411 | 412 | Server* server = Server::get(); 413 | server->set_pending_action(); 414 | server->InsertMessage([server, map]() -> void { 415 | server->ChangeLevel(map.c_str()); 416 | }); 417 | } 418 | -------------------------------------------------------------------------------- /srcds/server.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include "engine.h" 17 | #include "iserverplugin.h" 18 | #include "tier0/logmanager.h" 19 | #include "tier1/convar.h" 20 | 21 | class Server final : public ILoggingListener 22 | { 23 | public: 24 | Server(); 25 | ~Server(); 26 | 27 | void PostMessage(std::function&& msg); 28 | void InsertMessage(std::function&& msg); 29 | 30 | template 31 | T RecvMessage(Callback&& msg) { 32 | std::promise promise; 33 | auto future = promise.get_future(); 34 | 35 | auto callback = [&promise, msg{std::move(msg)}]() -> void { 36 | promise.set_value(msg()); 37 | }; 38 | PostMessage(std::move(callback)); 39 | 40 | future.wait(); 41 | return future.get(); 42 | } 43 | 44 | // Everything beyond must be called on the server thread. 45 | bool Start(); 46 | void Shutdown(); 47 | void Run(int max_tick_count); 48 | void DoFrame(); 49 | void PluginLoad(std::string path_in); 50 | void AddCommand(std::string str); 51 | void InsertCommand(std::string str); 52 | void DispatchCommand(std::string str); 53 | void ExecuteAll(); 54 | void Interrupt() { interrupt_ = true; } 55 | void ChangeLevel(const char* map); 56 | 57 | static Server* get() { return sInstance; } 58 | 59 | // Some commands, like changelevel, must be run at the top of a frame to 60 | // avoid re-entrancy issues. This flag allows the interactive console to 61 | // make sure to keep running until the command has fully completed. 62 | bool pending_action() const { return pending_action_; } 63 | void set_pending_action() { pending_action_ = true; } 64 | 65 | const std::string& dist_dir() const { return dist_dir_; } 66 | void set_dist_dir(const std::string& dir) { dist_dir_ = dir; } 67 | 68 | private: 69 | void LoadPlugins(); 70 | void ProcessMessages(); 71 | void Log(const LoggingContext_t* cx, const char* message) override; 72 | void* CreateInterface(const char* name, int* ret); 73 | 74 | static Server* sInstance; 75 | static void* CreateInterfaceWrapper(const char* name, int* ret); 76 | 77 | struct Plugin { 78 | int version = 0; 79 | IServerPluginCallbacks* callbacks = nullptr; 80 | ke::RefPtr lib; 81 | std::string path; 82 | }; 83 | 84 | private: 85 | std::string dist_dir_; 86 | std::mutex mutex_; 87 | std::thread::id thread_id_; 88 | std::deque> messages_; 89 | std::vector> plugins_; 90 | ke::RefPtr game_; 91 | CreateInterfaceFn game_ci_ = nullptr; 92 | IServerGameDLL* gamedll_ = nullptr; 93 | IServerGameClients* game_clients_ = nullptr; 94 | bool shutting_down_ = false; 95 | bool interrupt_ = false; 96 | int maxclients_ = 8; 97 | bool pending_action_ = false; 98 | }; 99 | -------------------------------------------------------------------------------- /srcds/sound.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "sound.h" 3 | 4 | #include "tier0/dbg.h" 5 | #include "tier1/interface.h" 6 | 7 | static EngineSound sEngineSound; 8 | 9 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(EngineSound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION, 10 | sEngineSound); 11 | 12 | int EngineSound::EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, 13 | const char *pSoundEntry, unsigned int nSoundEntryHash, 14 | const char *pSample, float flVolume, float flAttenuation, 15 | int nSeed, int iFlags, int iPitch, 16 | const Vector *pOrigin, const Vector *pDirection, 17 | CUtlVector* pUtlVecOrigins, 18 | bool bUpdatePositions, float soundtime, 19 | int speakerentity) 20 | { 21 | Error("%s not implemented", __func__); 22 | return -1; 23 | } 24 | 25 | int EngineSound::EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, 26 | const char *pSoundEntry, unsigned int nSoundEntryHash, 27 | const char *pSample, float flVolume, soundlevel_t level, 28 | int nSeed, int iFlags, int iPitch, 29 | const Vector *pOrigin, const Vector *pDirection, 30 | CUtlVector* pUtlVecOrigins, 31 | bool bUpdatePositions, float soundtime, 32 | int speakerentity) 33 | { 34 | Error("%s not implemented", __func__); 35 | return -1; 36 | } 37 | 38 | void EngineSound::EmitSentenceByIndex(IRecipientFilter& filter, int iEntIndex, int iChannel, 39 | int iSentenceIndex, float flVolume, soundlevel_t iSoundlevel, 40 | int nSeed, int iFlags, int iPitch, 41 | const Vector *pOrigin, 42 | const Vector *pDirection, 43 | CUtlVector* pUtlVecOrigins, 44 | bool bUpdatePositions, float soundtime, 45 | int speakerentity) 46 | { 47 | Error("%s not implemented", __func__); 48 | } 49 | 50 | bool EngineSound::PrecacheSound(const char *pSample, bool bPreload, bool bIsUISound) { 51 | Error("%s not implemented", __func__); 52 | return false; 53 | } 54 | 55 | void EngineSound::PrefetchSound(const char *pSample) { 56 | Error("%s not implemented", __func__); 57 | } 58 | 59 | void EngineSound::StopSound(int iEntIndex, int iChannel, const char *pSample, 60 | unsigned int nSoundEntryHash) 61 | { 62 | Error("%s not implemented", __func__); 63 | } 64 | 65 | bool EngineSound::IsSoundPrecached(const char *pSample) { 66 | Error("%s not implemented", __func__); 67 | return false; 68 | } 69 | 70 | float EngineSound::GetSoundDuration(const char *pSample) { 71 | Error("%s not implemented", __func__); 72 | return 0.0f; 73 | } 74 | 75 | float EngineSound::GetDistGainFromSoundLevel(soundlevel_t soundlevel, float dist) { 76 | Error("%s not implemented", __func__); 77 | return 0.0f; 78 | } 79 | 80 | static SoundEmitterSystemBase sSoundEmitterSystemBase; 81 | 82 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(SoundEmitterSystemBase, ISoundEmitterSystemBase, SOUNDEMITTERSYSTEM_INTERFACE_VERSION, 83 | sSoundEmitterSystemBase); 84 | 85 | int SoundEmitterSystemBase::GetSoundIndex(const char *pName) const 86 | { 87 | Error("%s not implemented", __func__); 88 | return -1; 89 | } 90 | 91 | bool SoundEmitterSystemBase::IsValidIndex(int index) 92 | { 93 | Error("%s not implemented", __func__); 94 | return false; 95 | } 96 | 97 | gender_t SoundEmitterSystemBase::GetActorGender(char const *actormodel) 98 | { 99 | Error("%s not implemented", __func__); 100 | return GENDER_NONE; 101 | } 102 | bool SoundEmitterSystemBase::GetParametersForSoundEx(const char *soundname, HSOUNDSCRIPTHASH& handle, 103 | CSoundParameters& params, gender_t gender, 104 | bool isbeingemitted) 105 | { 106 | Error("%s not implemented", __func__); 107 | return false; 108 | } 109 | 110 | CSoundParametersInternal *SoundEmitterSystemBase::InternalGetParametersForSound(int index) 111 | { 112 | Error("%s not implemented", __func__); 113 | return nullptr; 114 | } 115 | 116 | const char *SoundEmitterSystemBase::GetWaveName(CUtlSymbol& sym) 117 | { 118 | Error("%s not implemented", __func__); 119 | return nullptr; 120 | } 121 | -------------------------------------------------------------------------------- /srcds/sound.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "IEngineSound.h" 5 | #include "SoundEmitterSystem/isoundemittersystembase.h" 6 | 7 | class EngineSound : public IEngineSound 8 | { 9 | public: 10 | int EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, 11 | const char *pSoundEntry, unsigned int nSoundEntryHash, 12 | const char *pSample, float flVolume, float flAttenuation, 13 | int nSeed, int iFlags = 0, int iPitch = PITCH_NORM, 14 | const Vector *pOrigin = nullptr, const Vector *pDirection = nullptr, 15 | CUtlVector* pUtlVecOrigins = nullptr, 16 | bool bUpdatePositions = true, float soundtime = 0.0f, 17 | int speakerentity = -1) override; 18 | 19 | int EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, 20 | const char *pSoundEntry, unsigned int nSoundEntryHash, 21 | const char *pSample, float flVolume, soundlevel_t level, 22 | int nSeed, int iFlags = 0, int iPitch = PITCH_NORM, 23 | const Vector *pOrigin = nullptr, const Vector *pDirection = nullptr, 24 | CUtlVector* pUtlVecOrigins = nullptr, 25 | bool bUpdatePositions = true, float soundtime = 0.0f, 26 | int speakerentity = -1) override; 27 | void EmitSentenceByIndex(IRecipientFilter& filter, int iEntIndex, int iChannel, 28 | int iSentenceIndex, float flVolume, soundlevel_t iSoundlevel, 29 | int nSeed, int iFlags = 0, int iPitch = PITCH_NORM, 30 | const Vector *pOrigin = nullptr, 31 | const Vector *pDirection = nullptr, 32 | CUtlVector* pUtlVecOrigins = nullptr, 33 | bool bUpdatePositions = true, float soundtime = 0.0f, 34 | int speakerentity = -1) override; 35 | 36 | 37 | bool PrecacheSound(const char *pSample, bool bPreload = false, bool bIsUISound = false) override; 38 | void PrefetchSound(const char *pSample) override; 39 | float GetSoundDuration(const char *pSample) override; 40 | void StopSound(int iEntIndex, int iChannel, const char *pSample, unsigned int nSoundEntryHash) override; 41 | float GetDistGainFromSoundLevel(soundlevel_t soundlevel, float dist) override; 42 | bool IsSoundPrecached(const char *pSample) override; 43 | }; 44 | 45 | class SoundEmitterSystemBase : public ISoundEmitterSystemBase 46 | { 47 | public: 48 | int GetSoundIndex(const char *pName) const override; 49 | bool IsValidIndex(int index) override; 50 | gender_t GetActorGender(char const *actormodel) override; 51 | bool GetParametersForSoundEx(const char *soundname, HSOUNDSCRIPTHASH& handle, 52 | CSoundParameters& params, gender_t gender, 53 | bool isbeingemitted = false) override; 54 | CSoundParametersInternal *InternalGetParametersForSound(int index) override; 55 | const char *GetWaveName(CUtlSymbol& sym) override; 56 | }; -------------------------------------------------------------------------------- /srcds/spatialpartition.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "spatialpartition.h" 3 | 4 | #include "tier0/dbg.h" 5 | #include "tier1/interface.h" 6 | 7 | static SpatialPartition sSpatialPartition; 8 | 9 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(SpatialPartition, ISpatialPartition, INTERFACEVERSION_SPATIALPARTITION, 10 | sSpatialPartition); 11 | 12 | void SpatialPartition::EnumerateElementsInBox( 13 | SpatialPartitionListMask_t listMask, 14 | const Vector& mins, 15 | const Vector& maxs, 16 | bool coarseTest, 17 | IPartitionEnumerator* pIterator) 18 | { 19 | Error("%s not implemented", __func__); 20 | } 21 | 22 | void SpatialPartition::EnumerateElementsInSphere( 23 | SpatialPartitionListMask_t listMask, 24 | const Vector& origin, 25 | float radius, 26 | bool coarseTest, 27 | IPartitionEnumerator* pIterator) 28 | { 29 | Error("%s not implemented", __func__); 30 | } 31 | 32 | void SpatialPartition::EnumerateElementsAlongRay( 33 | SpatialPartitionListMask_t listMask, 34 | const Ray_t& ray, 35 | bool coarseTest, 36 | IPartitionEnumerator* pIterator) 37 | { 38 | Error("%s not implemented", __func__); 39 | } 40 | 41 | void SpatialPartition::EnumerateElementsAtPoint( 42 | SpatialPartitionListMask_t listMask, 43 | const Vector& pt, 44 | bool coarseTest, 45 | IPartitionEnumerator* pIterator) 46 | { 47 | Error("%s not implemented", __func__); 48 | } 49 | -------------------------------------------------------------------------------- /srcds/spatialpartition.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "ispatialpartition.h" 5 | 6 | class SpatialPartition : public ISpatialPartition 7 | { 8 | public: 9 | void EnumerateElementsInBox( 10 | SpatialPartitionListMask_t listMask, 11 | const Vector& mins, 12 | const Vector& maxs, 13 | bool coarseTest, 14 | IPartitionEnumerator* pIterator) override; 15 | void EnumerateElementsInSphere( 16 | SpatialPartitionListMask_t listMask, 17 | const Vector& origin, 18 | float radius, 19 | bool coarseTest, 20 | IPartitionEnumerator* pIterator) override; 21 | void EnumerateElementsAlongRay( 22 | SpatialPartitionListMask_t listMask, 23 | const Ray_t& ray, 24 | bool coarseTest, 25 | IPartitionEnumerator* pIterator) override; 26 | 27 | void EnumerateElementsAtPoint( 28 | SpatialPartitionListMask_t listMask, 29 | const Vector& pt, 30 | bool coarseTest, 31 | IPartitionEnumerator* pIterator) override; 32 | }; 33 | -------------------------------------------------------------------------------- /srcds/trace.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "trace.h" 3 | 4 | #include "tier0/dbg.h" 5 | #include "tier1/interface.h" 6 | 7 | static EngineTrace sEngineTrace; 8 | 9 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(EngineTrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER, 10 | sEngineTrace); 11 | 12 | void EngineTrace::TraceRay(const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace) 13 | { 14 | Error("%s not implemented", __func__); 15 | } 16 | 17 | void EngineTrace::ClipRayToEntity(const Ray_t &ray, unsigned int fMask, IHandleEntity *pEnt, trace_t *pTrace) 18 | { 19 | Error("%s not implemented", __func__); 20 | } 21 | 22 | int EngineTrace::GetPointContents(const Vector &vecAbsPosition, int contentsMask, 23 | IHandleEntity** ppEntity) 24 | { 25 | Error("%s not implemented", __func__); 26 | return CONTENTS_EMPTY; 27 | } 28 | 29 | int EngineTrace::GetPointContents_Collideable(ICollideable *pCollide, const Vector &vecAbsPosition) 30 | { 31 | Error("%s not implemented", __func__); 32 | return CONTENTS_EMPTY; 33 | } 34 | 35 | bool EngineTrace::PointOutsideWorld(const Vector &ptTest) 36 | { 37 | Error("%s not implemented", __func__); 38 | return false; 39 | } 40 | -------------------------------------------------------------------------------- /srcds/trace.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "IEngineTrace.h" 5 | 6 | class EngineTrace : public IEngineTrace 7 | { 8 | public: 9 | void TraceRay(const Ray_t &ray, unsigned int fMask, ITraceFilter *pTraceFilter, trace_t *pTrace) override; 10 | void ClipRayToEntity(const Ray_t &ray, unsigned int fMask, IHandleEntity *pEnt, trace_t *pTrace) override; 11 | int GetPointContents(const Vector &vecAbsPosition, int contentsMask = MASK_ALL, 12 | IHandleEntity** ppEntity = nullptr) override; 13 | int GetPointContents_Collideable(ICollideable *pCollide, const Vector &vecAbsPosition) override; 14 | bool PointOutsideWorld(const Vector &ptTest) override; 15 | }; 16 | -------------------------------------------------------------------------------- /srcds/utility.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | #if 0 7 | template static inline T* 8 | InvokeCreateInterface(CreateInterfaceFn fn, const char* name, int start = 0, int direction = 0) { 9 | int iter = start; 10 | while (true) { 11 | std::string fq = name; 12 | if (start) 13 | fq = ke::StringPrintf("%s%03d", name, iter); 14 | 15 | int rv; 16 | if (auto iface = fn(fq.c_str(), &rv)) 17 | return reinterpret_cast(iface); 18 | if (!direction || iter < 1) 19 | return nullptr; 20 | } 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /srcds/voice.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "voice.h" 3 | 4 | #include "tier0/dbg.h" 5 | #include "tier1/interface.h" 6 | 7 | static VoiceServer sVoiceServer; 8 | 9 | EXPOSE_SINGLE_INTERFACE_GLOBALVAR(VoiceServer, IVoiceServer, INTERFACEVERSION_VOICESERVER, 10 | sVoiceServer); 11 | 12 | bool VoiceServer::SetClientListening(int iReceiver, int iSender, bool bListen) 13 | { 14 | Error("%s not implemented", __func__); 15 | return false; 16 | } 17 | -------------------------------------------------------------------------------- /srcds/voice.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include "ivoiceserver.h" 5 | 6 | class VoiceServer : public IVoiceServer 7 | { 8 | public: 9 | virtual bool SetClientListening(int iReceiver, int iSender, bool bListen) override; 10 | }; 11 | -------------------------------------------------------------------------------- /tier0/AMBuilder: -------------------------------------------------------------------------------- 1 | #! vim: set sts=4 sw=4 tw=99 et ft=python: 2 | import os 3 | 4 | binary = Root.Library(builder, 'tier0') 5 | 6 | binary.sources += [ 7 | 'commandline.cpp', 8 | 'dbg.cpp', 9 | 'logmanager.cpp', 10 | 'mem.cpp', 11 | 'platform.cpp', 12 | 'vprof.cpp', 13 | ] 14 | binary.compiler.cxxincludes += [ 15 | os.path.join(builder.sourcePath, 'public'), 16 | os.path.join(builder.sourcePath, 'public', 'tier0'), 17 | os.path.join(builder.sourcePath, 'third_party', 'amtl'), 18 | ] 19 | 20 | rvalue = builder.Add(binary).binary 21 | -------------------------------------------------------------------------------- /tier0/commandline.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "commandline.h" 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | using namespace std::string_literals; 12 | 13 | CommandLineImpl sCommandLine; 14 | 15 | void 16 | CommandLineImpl::Init(int argc, char** argv) 17 | { 18 | for (int i = 0; i < argc; i++) 19 | argv_.emplace_back(argv[i]); 20 | 21 | // Force cmdline_ to be set. 22 | GetCmdLine(); 23 | 24 | int game_idx = FindParm("-game"); 25 | if (game_idx == -1) { 26 | argv_.emplace_back("-game"s); 27 | argv_.emplace_back("mock"s); 28 | cmdline_ += " -game mock"s; 29 | } else if (game_idx == (int)argv_.size() - 1) { 30 | argv_.emplace_back("mock"s); 31 | } else if (argv_[game_idx + 1] != "mock") { 32 | argv_[game_idx + 1] = "mock"s; 33 | } 34 | } 35 | 36 | int 37 | CommandLineImpl::FindParm(const char* key) const 38 | { 39 | for (size_t i = 0; i < argv_.size(); i++) { 40 | if (argv_[i] == key) 41 | return (int)i; 42 | } 43 | return -1; 44 | } 45 | 46 | const char* 47 | CommandLineImpl::ParmValue(const char* key, const char* defval) const 48 | { 49 | for (size_t i = 0; i < argv_.size(); i++) { 50 | if (argv_[i] == key) { 51 | if (i == argv_.size() - 1) 52 | return defval; 53 | return argv_[i + 1].c_str(); 54 | } 55 | } 56 | return defval; 57 | } 58 | 59 | int 60 | CommandLineImpl::ParmValue(const char* key, int defval) const 61 | { 62 | const char* val = ParmValue(key, nullptr); 63 | if (!val) 64 | return defval; 65 | 66 | errno = 0; 67 | 68 | char *endptr; 69 | auto rv = strtol(val, &endptr, 10); 70 | if ((rv == LONG_MAX || rv == LONG_MIN) && errno == ERANGE) 71 | return defval; 72 | if (!rv && (endptr == val || *endptr != '\0')) 73 | return defval; 74 | return rv; 75 | } 76 | 77 | const char* 78 | CommandLineImpl::GetCmdLine() const 79 | { 80 | if (!cmdline_.empty()) 81 | return cmdline_.c_str(); 82 | #ifdef _WIN32 83 | cmdline_ = ke::Join(" ", argv_); 84 | #else 85 | std::ifstream cmdline("/proc/self/cmdline"); 86 | cmdline_ = std::string(std::istreambuf_iterator(cmdline), 87 | std::istreambuf_iterator()); 88 | #endif 89 | 90 | return cmdline_.c_str(); 91 | } 92 | 93 | ICommandLine* CommandLine() { 94 | return &sCommandLine; 95 | } 96 | 97 | CommandLineImpl* 98 | CommandLineImpl::get() 99 | { 100 | return &sCommandLine; 101 | } 102 | 103 | std::vector 104 | ParseArgs(const std::string& cmdline) 105 | { 106 | std::vector args; 107 | 108 | size_t i = 0; 109 | while (true) { 110 | while (i < cmdline.size() && isspace(cmdline[i])) 111 | i++; 112 | if (i >= cmdline.size()) 113 | break; 114 | 115 | bool quoted = false; 116 | if (cmdline[i] == '"' && i != cmdline.size() - 1) { 117 | quoted = true; 118 | i++; 119 | } 120 | 121 | std::string arg; 122 | while (i < cmdline.size()) { 123 | if (quoted) { 124 | if (cmdline[i] == '"') { 125 | i++; 126 | break; 127 | } 128 | } else if (cmdline[i] == '"') { 129 | i++; 130 | continue; 131 | } else if (isspace(cmdline[i])) { 132 | i++; 133 | break; 134 | } 135 | arg.push_back(cmdline[i]); 136 | i++; 137 | } 138 | args.emplace_back(std::move(arg)); 139 | } 140 | 141 | return args; 142 | } 143 | -------------------------------------------------------------------------------- /tier0/commandline.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | #include "tier0/icommandline.h" 4 | 5 | #include 6 | #include 7 | 8 | class CommandLineImpl final : public ICommandLine 9 | { 10 | public: 11 | void Init(int argc, char** argv); 12 | const char* ParmValue(const char* key, const char* defval = nullptr) const override; 13 | int ParmValue(const char* key, int defval) const override; 14 | const char* GetCmdLine() const override; 15 | int FindParm(const char* key) const override; 16 | 17 | static CommandLineImpl* get(); 18 | 19 | private: 20 | std::vector orig_argv_; 21 | std::vector argv_; 22 | mutable std::string cmdline_; 23 | }; 24 | 25 | std::vector ParseArgs(const std::string& cmdline); 26 | -------------------------------------------------------------------------------- /tier0/dbg.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "tier0/dbg.h" 3 | 4 | #include 5 | 6 | #include "logmanager.h" 7 | 8 | void ConMsg(const char* msg, ...) 9 | { 10 | va_list ap; 11 | va_start(ap, msg); 12 | LogManager::get()->LogVa(LogLevel::Message, msg, ap); 13 | va_end(ap); 14 | } 15 | 16 | void Msg(const char* msg, ...) 17 | { 18 | va_list ap; 19 | va_start(ap, msg); 20 | LogManager::get()->LogVa(LogLevel::Message, msg, ap); 21 | va_end(ap); 22 | } 23 | 24 | void Warning(const char* msg, ...) 25 | { 26 | va_list ap; 27 | va_start(ap, msg); 28 | LogManager::get()->LogVa(LogLevel::Warning, msg, ap); 29 | va_end(ap); 30 | } 31 | 32 | void Error(const char* msg, ...) 33 | { 34 | va_list ap; 35 | va_start(ap, msg); 36 | LogManager::get()->LogVa(LogLevel::Error, msg, ap); 37 | va_end(ap); 38 | } 39 | 40 | void DevMsg(const char* msg, ...) 41 | { 42 | va_list ap; 43 | va_start(ap, msg); 44 | LogManager::get()->LogVa(LogLevel::Message, msg, ap); 45 | va_end(ap); 46 | } 47 | -------------------------------------------------------------------------------- /tier0/logmanager.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "logmanager.h" 3 | 4 | #include 5 | 6 | #include 7 | 8 | LogManager* 9 | LogManager::get() 10 | { 11 | static LogManager sLogMan; 12 | return &sLogMan; 13 | } 14 | 15 | LogManager::LogManager() 16 | { 17 | state_.emplace_back(); 18 | } 19 | 20 | void 21 | LogManager::AddListener(ILoggingListener* listener) 22 | { 23 | std::lock_guard lock(mutex_); 24 | state_.back().listeners.emplace_back(listener); 25 | } 26 | 27 | void 28 | LogManager::RemoveListener(ILoggingListener* listener) 29 | { 30 | std::lock_guard lock(mutex_); 31 | auto iter = std::remove(state_.back().listeners.begin(), state_.back().listeners.end(), 32 | listener); 33 | state_.back().listeners.erase(iter, state_.back().listeners.end()); 34 | } 35 | 36 | void 37 | LogManager::LogVa(LogLevel level, const char* fmt, va_list ap) 38 | { 39 | auto message = ke::StringPrintfVa(fmt, ap); 40 | 41 | LoggingContext_t context; 42 | context.severity = level; 43 | 44 | std::lock_guard lock(mutex_); 45 | for (const auto& listener : state_.back().listeners) { 46 | listener->Log(&context, message.c_str()); 47 | } 48 | } 49 | 50 | void 51 | LogManager::Log(LogLevel level, const char* fmt, ...) 52 | { 53 | va_list ap; 54 | va_start(ap, fmt); 55 | LogVa(level, fmt, ap); 56 | va_end(ap); 57 | } 58 | 59 | void 60 | LogManager::PushState() 61 | { 62 | state_.emplace_back(); 63 | } 64 | 65 | void 66 | LogManager::PopState() 67 | { 68 | // Never pop the default state. 69 | if (state_.size() == 1) 70 | return; 71 | } 72 | 73 | void LoggingSystem_PushLoggingState(bool bThreadLocal, bool bClearState) { 74 | assert(!bThreadLocal); 75 | assert(!bClearState); 76 | LogManager::get()->PushState(); 77 | } 78 | 79 | void LoggingSystem_PopLoggingState(bool bThreadLocal) { 80 | assert(!bThreadLocal); 81 | LogManager::get()->PopState(); 82 | } 83 | 84 | void LoggingSystem_RegisterLoggingListener(ILoggingListener *pListener) { 85 | LogManager::get()->AddListener(pListener); 86 | } 87 | -------------------------------------------------------------------------------- /tier0/logmanager.h: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include "tier0/logging.h" 10 | 11 | class LogManager 12 | { 13 | public: 14 | LogManager(); 15 | void LogVa(LogLevel level, const char* fmt, va_list ap); 16 | void Log(LogLevel level, const char* fmt, ...); 17 | 18 | static LogManager* get(); 19 | 20 | void AddListener(ILoggingListener* listener); 21 | void RemoveListener(ILoggingListener* listener); 22 | 23 | void PushState(); 24 | void PopState(); 25 | 26 | private: 27 | std::mutex mutex_; 28 | struct State { 29 | std::vector listeners; 30 | }; 31 | std::vector state_; 32 | }; 33 | -------------------------------------------------------------------------------- /tier0/mem.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "tier0/dbg.h" 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | struct alloc_entry { 10 | void* block; 11 | alloc_entry* next; 12 | }; 13 | 14 | thread_local alloc_entry* sAllocEntries; 15 | 16 | void* 17 | MemAllocScratch(int size) 18 | { 19 | auto entry = new alloc_entry; 20 | entry->block = malloc(size); 21 | entry->next = sAllocEntries; 22 | sAllocEntries = entry; 23 | return sAllocEntries->block; 24 | } 25 | 26 | void 27 | MemFreeScratch() 28 | { 29 | free(sAllocEntries->block); 30 | auto next = sAllocEntries->next; 31 | delete sAllocEntries; 32 | sAllocEntries = next; 33 | } 34 | -------------------------------------------------------------------------------- /tier0/platform.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include 3 | 4 | #include "tier0/platform.h" 5 | 6 | using namespace std::chrono; 7 | using std::chrono::steady_clock; 8 | 9 | static time_point sLoadTime = steady_clock::now(); 10 | 11 | double 12 | Plat_FloatTime() 13 | { 14 | duration diff = steady_clock::now() - sLoadTime; 15 | return diff.count(); 16 | } 17 | -------------------------------------------------------------------------------- /tier0/vprof.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "vprof.h" 3 | 4 | VProfiler g_VProfCurrentProfile; 5 | -------------------------------------------------------------------------------- /tier1/AMBuilder: -------------------------------------------------------------------------------- 1 | #! vim: set sts=4 sw=4 tw=99 et ft=python: 2 | import os 3 | 4 | binary = Root.StaticLibrary(builder, 'tier1') 5 | 6 | binary.sources += [ 7 | 'convar.cpp', 8 | 'interface.cpp', 9 | 'keyvalues.cpp', 10 | 'strtools.cpp', 11 | ] 12 | binary.compiler.cxxincludes += [ 13 | os.path.join(builder.sourcePath, 'tier1'), 14 | os.path.join(builder.sourcePath, 'public'), 15 | os.path.join(builder.sourcePath, 'public', 'tier1'), 16 | os.path.join(builder.sourcePath, 'third_party', 'amtl'), 17 | ] 18 | 19 | rvalue = builder.Add(binary).binary 20 | -------------------------------------------------------------------------------- /tier1/convar.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "convar.h" 3 | 4 | ConCommandBase* ConCommandBase::sCommandList = nullptr; 5 | 6 | ICvar* g_pCVar = nullptr; 7 | static IConCommandBaseAccessor* sConCommandBaseAccessor = nullptr; 8 | 9 | void ConCommandBase::Init() { 10 | if (sConCommandBaseAccessor) 11 | sConCommandBaseAccessor->RegisterConCommandBase(this); 12 | } 13 | 14 | void 15 | ConCommandBase::RegisterAll(ICvar* cvar) 16 | { 17 | for (auto iter = sCommandList; iter; iter = iter->next_) 18 | cvar->RegisterConCommand(iter); 19 | } 20 | 21 | ConVar::ConVar(const char* name, const char* value, int flags) 22 | : ConCommandBase(name), 23 | def_(value), 24 | str_value_(value) 25 | { 26 | Init(); 27 | } 28 | 29 | ConVar::ConVar(const char* name, const char* value, int flags, const char* help) 30 | : ConCommandBase(name), 31 | def_(value), 32 | str_value_(value) 33 | { 34 | m_nFlags = flags; 35 | help_ = help; 36 | 37 | Init(); 38 | } 39 | 40 | ConVar::ConVar(const char* name, const char* value, int flags, const char* help, bool bMin, 41 | float fMin, bool bMax, float fMax, FnChangeCallback_t callback) 42 | : ConCommandBase(name), 43 | def_(value), 44 | str_value_(value), 45 | callback_(callback), 46 | m_bHasMin(bMin), 47 | m_fMinVal(fMin), 48 | m_bHasMax(fMax), 49 | m_fMaxVal(fMax) 50 | { 51 | help_ = help; 52 | 53 | Init(); 54 | } 55 | 56 | void 57 | ConVar::SetValue(const char* value) 58 | { 59 | if (str_value_ == value) 60 | return; 61 | 62 | if (callback_) 63 | callback_(this, str_value_.c_str(), GetFloat()); 64 | str_value_ = value; 65 | } 66 | 67 | void 68 | ConVar::SetValue(float value) 69 | { 70 | SetValue(std::to_string(value).c_str()); 71 | } 72 | 73 | void 74 | ConVar::SetValue(int value) 75 | { 76 | SetValue(std::to_string(value).c_str()); 77 | } 78 | 79 | float ConVar::GetFloat() const { 80 | return atof(str_value_.c_str()); 81 | } 82 | 83 | int ConVar::GetInt() const { 84 | return atoi(str_value_.c_str()); 85 | } 86 | 87 | static bool sConvarsRegistered = false; 88 | 89 | void ConVar_Register(int flag, IConCommandBaseAccessor* accessor) { 90 | if (sConvarsRegistered || !g_pCVar) 91 | return; 92 | sConvarsRegistered = true; 93 | 94 | for (auto iter = ConCommandBase::sCommandList; iter; iter = iter->next()) { 95 | iter->AddFlags(flag); 96 | iter->set_owner_token(&sConvarsRegistered); 97 | if (accessor) 98 | accessor->RegisterConCommandBase(iter); 99 | else 100 | g_pCVar->RegisterConCommand(iter); 101 | } 102 | 103 | sConCommandBaseAccessor = accessor; 104 | } 105 | 106 | void ConVar_Unregister() { 107 | if (!sConvarsRegistered || !g_pCVar) 108 | return; 109 | g_pCVar->RemoveOwnedCmds(&sConvarsRegistered); 110 | sConvarsRegistered = false; 111 | sConCommandBaseAccessor = nullptr; 112 | } 113 | -------------------------------------------------------------------------------- /tier1/interface.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "tier1/interface.h" 3 | 4 | #include 5 | 6 | #include "tier0/platform.h" 7 | 8 | static InterfaceReg* sInterfaceList; 9 | 10 | InterfaceReg::InterfaceReg(InstantiateInterfaceFn fn, const char* name) 11 | : m_CreateFn(fn), 12 | m_pName(name), 13 | m_pNext(sInterfaceList) 14 | { 15 | sInterfaceList = this; 16 | } 17 | 18 | class CSysModule : public ke::SharedLib 19 | { 20 | public: 21 | CSysModule(const char* path) : ke::SharedLib(path) 22 | {} 23 | }; 24 | 25 | CSysModule* OpenCSysModule(const char* path) { 26 | auto lib = new CSysModule(path); 27 | if (!lib->valid()) { 28 | delete lib; 29 | return nullptr; 30 | } 31 | return lib; 32 | } 33 | 34 | void CloseCSysModule(CSysModule* mod) { 35 | delete mod; 36 | } 37 | 38 | CreateInterfaceFn Sys_GetFactory(CSysModule *pModule) { 39 | return pModule->get("CreateInterface"); 40 | } 41 | 42 | DLL_EXPORT void* CreateInterface(const char* name, int* rc) { 43 | for (auto iter = sInterfaceList; iter; iter = iter->m_pNext) { 44 | if (strcmp(iter->m_pName, name) == 0) { 45 | if (rc) 46 | *rc = IFACE_OK; 47 | return iter->m_CreateFn(); 48 | } 49 | } 50 | if (rc) 51 | *rc = IFACE_FAILED; 52 | return nullptr; 53 | } 54 | -------------------------------------------------------------------------------- /tier1/keyvalues.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "KeyValues.h" 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "filesystem.h" 10 | #include "tier0/dbg.h" 11 | 12 | KeyValues::KeyValues(const char* name) 13 | : name_(name) 14 | { 15 | } 16 | 17 | KeyValues::KeyValues(const char* name, const char* firstKey, const char* firstValue) 18 | : name_(name) 19 | { 20 | auto kv = FindKey(firstKey); 21 | if (!firstValue) 22 | firstValue = ""; 23 | kv->SetStringValue(firstValue); 24 | } 25 | 26 | static bool ReadFromFile(const char* file, std::string* str) { 27 | std::unique_ptr fp(fopen(file, "rb"), &::fclose); 28 | if (!fp) 29 | return false; 30 | 31 | fseek(fp.get(), 0, SEEK_END); 32 | auto size = ftell(fp.get()); 33 | fseek(fp.get(), 0, SEEK_SET); 34 | 35 | str->resize(size, '\0'); 36 | fread(str->data(), 1, size, fp.get()); 37 | return true; 38 | } 39 | 40 | static bool ReadFromFile(IBaseFileSystem* fs, const char* path, std::string* str) { 41 | auto h = fs->Open(path, "rb"); 42 | if (!h) 43 | return false; 44 | 45 | auto size = fs->Size(h); 46 | str->resize(size, '\0'); 47 | fs->Read(str->data(), size, h); 48 | return true; 49 | } 50 | 51 | static inline const char* SkipSpaces(const char* ptr) { 52 | while (*ptr > 0 && isspace(*ptr)) 53 | ptr++; 54 | return ptr; 55 | } 56 | 57 | bool 58 | KeyValues::LoadFromBuffer(const char* resname, const char* buffer, IBaseFileSystem* fs) 59 | { 60 | std::vector work; 61 | KeyValues* kv = this; 62 | 63 | const char* ptr = buffer; 64 | while (*ptr) { 65 | ptr = SkipSpaces(ptr); 66 | 67 | // Skip comments. 68 | if (*ptr == '/' && (*(ptr + 1) == '/' || (*ptr + 1) == '*')) { 69 | while (*ptr && *ptr != '\n') 70 | ptr++; 71 | continue; 72 | } 73 | 74 | // EOF after skipping? 75 | if (!*ptr) 76 | break; 77 | 78 | if (*ptr == '}') { 79 | ptr++; 80 | if (work.empty()) { 81 | Error("Extra close brace in VDF: %s\n", resname); 82 | break; 83 | } 84 | kv = work.back(); 85 | work.pop_back(); 86 | continue; 87 | } 88 | 89 | const char* key_start = ptr++; 90 | while (*ptr) { 91 | char c = *ptr; 92 | if (c == '"') { 93 | ptr++; 94 | break; 95 | } 96 | if (c > 0 && isspace(c) && *key_start != '"') 97 | break; 98 | ptr++; 99 | } 100 | 101 | std::string key_name; 102 | if (*key_start == '"') 103 | key_name = std::string(key_start + 1, ptr - key_start - 2); 104 | else 105 | key_name = std::string(key_start, ptr - key_start); 106 | 107 | ptr = SkipSpaces(ptr); 108 | if (!*ptr) { 109 | // Broken file? 110 | Error("Maybe broken VDF file: %s\n", resname); 111 | break; 112 | } 113 | 114 | if (*ptr == '{') { 115 | ptr++; 116 | work.emplace_back(kv); 117 | auto sub = std::make_unique(key_name.c_str()); 118 | if (!kv->subkeys_.empty()) 119 | kv->subkeys_.back()->sub_next_ = sub.get(); 120 | kv->subkeys_.emplace_back(std::move(sub)); 121 | kv = kv->subkeys_.back().get(); 122 | continue; 123 | } 124 | 125 | ptr = SkipSpaces(ptr); 126 | 127 | const char* val_start = ptr++; 128 | while (*ptr) { 129 | char c = *ptr; 130 | if (c == '"') { 131 | ptr++; 132 | break; 133 | } 134 | if (c > 0 && isspace(c) && *key_start != '"') 135 | break; 136 | ptr++; 137 | } 138 | 139 | std::string val_str; 140 | if (*val_start == '"') 141 | val_str = std::string(val_start + 1, ptr - val_start - 2); 142 | else 143 | val_str = std::string(val_start, ptr - val_start); 144 | 145 | auto ptr = dict_.find(key_name); 146 | if (ptr == dict_.end()) { 147 | auto p = dict_.emplace(key_name, std::make_unique(key_name.c_str())); 148 | ptr = p.first; 149 | } 150 | ptr->second->SetStringValue(val_str.c_str()); 151 | } 152 | 153 | if (!work.empty()) 154 | Error("Missing close brace in VDF file: %s\n", resname); 155 | 156 | return true; 157 | } 158 | 159 | bool 160 | KeyValues::LoadFromFile(IBaseFileSystem* fs, const char* resname, const char* pathID) 161 | { 162 | std::string buffer; 163 | if (fs) { 164 | if (!ReadFromFile(fs, resname, &buffer)) 165 | return false; 166 | } else if (!ReadFromFile(resname, &buffer)) { 167 | return false; 168 | } 169 | return LoadFromBuffer(resname, buffer.c_str(), fs); 170 | } 171 | 172 | const char* 173 | KeyValues::GetString(const char* key, const char* def) 174 | { 175 | auto kv = FindKey(key, false); 176 | if (!kv) 177 | return def; 178 | return kv->value_.c_str(); 179 | } 180 | 181 | KeyValues* 182 | KeyValues::FindKey(const char* key, bool create) 183 | { 184 | if (!key || !key[0]) 185 | return this; 186 | auto iter = dict_.find(key); 187 | if (iter == dict_.end()) { 188 | if (!create) 189 | return nullptr; 190 | auto p = dict_.emplace(key, std::make_unique(key)); 191 | iter = p.first; 192 | } 193 | return iter->second.get(); 194 | } 195 | -------------------------------------------------------------------------------- /tier1/strtools.cpp: -------------------------------------------------------------------------------- 1 | // vim: set sts=4 ts=8 sw=4 tw=99 et: 2 | #include "strtools.h" 3 | 4 | #include 5 | 6 | void 7 | V_strncpy(char* dest, const char* src, int maxlen) 8 | { 9 | ke::SafeStrcpy(dest, maxlen, src); 10 | } 11 | 12 | void 13 | V_binarytohex(const byte *in, int inputbytes, char *out, int outsize) 14 | { 15 | std::string str; 16 | for (int i = 0; i < inputbytes; i++) 17 | str += ke::StringPrintf("%02x", in[i]); 18 | ke::SafeStrcpy(out, outsize, str.c_str()); 19 | } 20 | 21 | void V_strcat(char *dest, const char *src, int cchDest) { 22 | ke::SafeStrcat(dest, cchDest, src); 23 | } 24 | -------------------------------------------------------------------------------- /update_prebuilts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | if [ $# -ne 1 ]; then 6 | echo "Usage: " 7 | exit 1; 8 | fi 9 | 10 | set -x 11 | 12 | rsync -av "${1}/lib/" "lib/" 13 | -------------------------------------------------------------------------------- /vstdlib/AMBuilder: -------------------------------------------------------------------------------- 1 | #! vim: set sts=4 sw=4 tw=99 et ft=python: 2 | import os 3 | 4 | binary = Root.Library(builder, 'vstdlib') 5 | 6 | binary.sources += [ 7 | 'empty.cpp', 8 | ] 9 | binary.compiler.cxxincludes += [ 10 | os.path.join(builder.sourcePath, 'public'), 11 | os.path.join(builder.sourcePath, 'public', 'tier0'), 12 | os.path.join(builder.sourcePath, 'third_party', 'amtl'), 13 | ] 14 | 15 | Root.vstdlib[binary.compiler.target.arch] = builder.Add(binary).binary 16 | -------------------------------------------------------------------------------- /vstdlib/empty.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alliedmodders/hl2sdk-mock/58784edaea7b9477df4699cf0e5addaf7445e011/vstdlib/empty.cpp --------------------------------------------------------------------------------