├── .gitignore ├── configure.py ├── PackageScript ├── natives.h ├── AMBuilder ├── smsdk_config.h ├── PTaH.games.txt ├── extension.cpp ├── .github └── workflows │ └── compile.yml ├── extension.h ├── smsdk_ext.cpp ├── forwards.h ├── classes.h ├── classes.cpp ├── AMBuildScript ├── LICENSE ├── PTaH.inc └── forwards.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | *.smod 19 | 20 | # Compiled Static libraries 21 | *.lai 22 | *.la 23 | *.a 24 | *.lib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | 31 | # Dir 32 | build 33 | *vs -------------------------------------------------------------------------------- /configure.py: -------------------------------------------------------------------------------- 1 | # vim: set sts=2 ts=8 sw=2 tw=99 et: 2 | import sys 3 | from ambuild2 import run 4 | 5 | # Simple extensions do not need to modify this file. 6 | 7 | builder = run.PrepareBuild(sourcePath = sys.path[0]) 8 | 9 | builder.options.add_option('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None, 10 | help='Root search folder for HL2SDKs') 11 | builder.options.add_option('--mms-path', type=str, dest='mms_path', default=None, 12 | help='Path to Metamod:Source') 13 | builder.options.add_option('--sm-path', type=str, dest='sm_path', default=None, 14 | help='Path to SourceMod') 15 | builder.options.add_option('--enable-debug', action='store_const', const='1', dest='debug', 16 | help='Enable debugging symbols') 17 | builder.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt', 18 | help='Enable optimization') 19 | builder.options.add_option('--enable-lto', action='store_const', const='1', dest='lto', 20 | help='Enable link time optimization') 21 | builder.options.add_option('--build-id', type=str, dest='build_id', default=None, 22 | help='Build ID') 23 | 24 | builder.Configure() 25 | -------------------------------------------------------------------------------- /PackageScript: -------------------------------------------------------------------------------- 1 | # vim: set ts=8 sts=2 sw=2 tw=99 et ft=python: 2 | import os 3 | 4 | # This is where the files will be output to 5 | # package is the default 6 | builder.SetBuildFolder('package') 7 | 8 | # Add any folders you need to this list 9 | folder_list = [ 10 | 'addons/sourcemod/extensions', 11 | 'addons/sourcemod/scripting/include', 12 | 'addons/sourcemod/gamedata', 13 | #'addons/sourcemod/configs', 14 | ] 15 | 16 | # Create the distribution folder hierarchy. 17 | folder_map = {} 18 | for folder in folder_list: 19 | norm_folder = os.path.normpath(folder) 20 | folder_map[folder] = builder.AddFolder(norm_folder) 21 | 22 | # Do all straight-up file copies from the source tree. 23 | def CopyFiles(src, dest, files): 24 | if not dest: 25 | dest = src 26 | dest_entry = folder_map[dest] 27 | for source_file in files: 28 | source_path = os.path.join(builder.sourcePath, src, source_file) 29 | builder.AddCopy(source_path, dest_entry) 30 | 31 | # Include files 32 | CopyFiles('', 'addons/sourcemod/scripting/include', 33 | [ 'PTaH.inc', ] 34 | ) 35 | 36 | # GameData files 37 | CopyFiles('', 'addons/sourcemod/gamedata', 38 | [ 'PTaH.games.txt' ] 39 | ) 40 | 41 | # Config Files 42 | #CopyFiles('configs', 'addons/sourcemod/configs', 43 | # [ 'configfile.cfg', 44 | # 'otherconfig.cfg, 45 | # ] 46 | #) 47 | 48 | # Copy binaries. 49 | for cxx_task in Extension.extensions: 50 | builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions']) 51 | -------------------------------------------------------------------------------- /natives.h: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 : 3 | * ============================================================================= 4 | * SourceMod P Tools and Hooks Extension 5 | * Copyright (C) 2016-2023 Phoenix (˙·٠●Феникс●٠·˙). All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | */ 20 | 21 | #ifndef _INCLUDE_SOURCEMOD_EXTENSION_NATIVES_H_ 22 | #define _INCLUDE_SOURCEMOD_EXTENSION_NATIVES_H_ 23 | 24 | enum PTaH_HookEvent 25 | { 26 | PTaH_GiveNamedItemPre = 10, 27 | PTaH_GiveNamedItemPost, 28 | PTaH_WeaponCanUsePre, 29 | PTaH_WeaponCanUsePost, 30 | PTaH_SetPlayerModelPre, 31 | PTaH_SetPlayerModelPost, 32 | PTaH_ClientVoiceToPre, 33 | PTaH_ClientVoiceToPost, 34 | PTaH_ConsolePrintPre, 35 | PTaH_ConsolePrintPost, 36 | PTaH_ExecuteStringCommandPre, 37 | PTaH_ExecuteStringCommandPost, 38 | PTaH_ClientConnectPre, 39 | PTaH_ClientConnectPost, 40 | PTaH_InventoryUpdatePost = 25, 41 | 42 | PTaH_MAXHOOKS 43 | }; 44 | 45 | enum PTaH_ModelType 46 | { 47 | ViewModel = 0, 48 | WorldModel, 49 | DroppedModel 50 | }; 51 | 52 | extern const sp_nativeinfo_t g_ExtensionNatives[]; 53 | 54 | #endif // _INCLUDE_SOURCEMOD_EXTENSION_NATIVES_H_ -------------------------------------------------------------------------------- /AMBuilder: -------------------------------------------------------------------------------- 1 | # vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: 2 | import os, sys 3 | 4 | projectName = 'PTaH' 5 | 6 | sourceFiles = [ 7 | 'extension.cpp', 8 | 'forwards.cpp', 9 | 'natives.cpp', 10 | 'classes.cpp', 11 | 'smsdk_ext.cpp' 12 | ] 13 | 14 | ############### 15 | # Make sure to edit PackageScript, which copies your files to their appropriate locations 16 | # Simple extensions do not need to modify past this point. 17 | 18 | project = Extension.HL2Project(builder, projectName + '.ext') 19 | 20 | project.sources += sourceFiles 21 | 22 | binary = Extension.HL2Config(project, projectName + '.ext.' + Extension.sdk.ext, Extension.sdk) 23 | compiler = binary.compiler 24 | 25 | binary.sources += [ 26 | # Memory management via g_pMemAlloc 27 | os.path.join(Extension.sdk.path, 'public', 'tier0', 'memoverride.cpp'), 28 | 29 | os.path.join(Extension.sm_root, 'public', 'CDetour', 'detours.cpp'), 30 | os.path.join(Extension.sm_root, 'public', 'asm', 'asm.c'), 31 | os.path.join(Extension.sm_root, 'public', 'libudis86', 'decode.c'), 32 | os.path.join(Extension.sm_root, 'public', 'libudis86', 'itab.c'), 33 | os.path.join(Extension.sm_root, 'public', 'libudis86', 'syn-att.c'), 34 | os.path.join(Extension.sm_root, 'public', 'libudis86', 'syn-intel.c'), 35 | os.path.join(Extension.sm_root, 'public', 'libudis86', 'syn.c'), 36 | os.path.join(Extension.sm_root, 'public', 'libudis86', 'udis86.c'), 37 | 38 | os.path.join(Extension.sdk.path, 'public', 'engine', 'protobuf', 'netmessages.pb.cc'), 39 | os.path.join(Extension.sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf', 'cstrike15_usermessages.pb.cc'), 40 | os.path.join(Extension.sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf', 'cstrike15_usermessage_helpers.cpp'), 41 | ] 42 | 43 | compiler.cxxincludes += [ 44 | os.path.join(Extension.sdk.path, 'common', 'protobuf-2.5.0', 'src'), 45 | os.path.join(Extension.sdk.path, 'public', 'engine', 'protobuf'), 46 | os.path.join(Extension.sdk.path, 'public', 'game', 'shared', 'csgo', 'protobuf'), 47 | os.path.join(Extension.sdk.path, 'public', 'steam'), 48 | os.path.join(Extension.sdk.path, 'game', 'server') 49 | ] 50 | 51 | if builder.target_platform == 'linux': 52 | lib_path = os.path.join(Extension.sdk.path, 'lib', 'linux32', 'release', 'libprotobuf.a') 53 | elif builder.target_platform == 'windows': 54 | lib_path = os.path.join(Extension.sdk.path, 'lib', 'win32', 'release', 'vs2017', 'libprotobuf.lib') 55 | compiler.linkflags.insert(0, binary.Dep(lib_path)) 56 | 57 | Extension.extensions = builder.Add(project) 58 | -------------------------------------------------------------------------------- /smsdk_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 : 3 | * ============================================================================= 4 | * SourceMod P Tools and Hooks Extension 5 | * Copyright (C) 2016-2023 Phoenix (˙·٠●Феникс●٠·˙). All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | */ 20 | 21 | #ifndef _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ 22 | #define _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ 23 | 24 | /** 25 | * @file smsdk_config.h 26 | * @brief Contains macros for configuring basic extension information. 27 | */ 28 | 29 | /* Basic information exposed publicly */ 30 | #define SMEXT_CONF_NAME "PTaH" 31 | #define SMEXT_CONF_DESCRIPTION "Additional CS:GO Hooks and Natives" 32 | #define SMEXT_CONF_VERSION "1.1.4" 33 | #define PTaH_VERSION 101040 34 | #define SMEXT_CONF_AUTHOR "Phoenix (˙·٠●Феникс●٠·˙)" 35 | #define SMEXT_CONF_URL "https://github.com/komashchenko/PTaH" 36 | #define SMEXT_CONF_LOGTAG "PTaH" 37 | #define SMEXT_CONF_LICENSE "GPL" 38 | #define SMEXT_CONF_DATESTRING __DATE__ 39 | 40 | /** 41 | * @brief Exposes plugin's main interface. 42 | */ 43 | #define SMEXT_LINK(name) SDKExtension *g_pExtensionIface = name; 44 | 45 | /** 46 | * @brief Sets whether or not this plugin required Metamod. 47 | * NOTE: Uncomment to enable, comment to disable. 48 | */ 49 | #define SMEXT_CONF_METAMOD 50 | 51 | /** Enable interfaces you want to use here by uncommenting lines */ 52 | #define SMEXT_ENABLE_FORWARDSYS 53 | //#define SMEXT_ENABLE_HANDLESYS 54 | #define SMEXT_ENABLE_PLAYERHELPERS 55 | //#define SMEXT_ENABLE_DBMANAGER 56 | #define SMEXT_ENABLE_GAMECONF 57 | //#define SMEXT_ENABLE_MEMUTILS 58 | #define SMEXT_ENABLE_GAMEHELPERS 59 | //#define SMEXT_ENABLE_TIMERSYS 60 | //#define SMEXT_ENABLE_THREADER 61 | //#define SMEXT_ENABLE_LIBSYS 62 | //#define SMEXT_ENABLE_MENUS 63 | //#define SMEXT_ENABLE_ADTFACTORY 64 | #define SMEXT_ENABLE_PLUGINSYS 65 | //#define SMEXT_ENABLE_ADMINSYS 66 | //#define SMEXT_ENABLE_TEXTPARSERS 67 | //#define SMEXT_ENABLE_USERMSGS 68 | //#define SMEXT_ENABLE_TRANSLATOR 69 | //#define SMEXT_ENABLE_ROOTCONSOLEMENU 70 | 71 | #endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ 72 | -------------------------------------------------------------------------------- /PTaH.games.txt: -------------------------------------------------------------------------------- 1 | "Games" 2 | { 3 | "csgo" 4 | { 5 | "Addresses" 6 | { 7 | "g_CPlayerVoiceListener" 8 | { 9 | "signature" "g_CPlayerVoiceListener" 10 | "windows" 11 | { 12 | "read" "0x3" 13 | } 14 | "linux" 15 | { 16 | "read" "0xE7" 17 | } 18 | } 19 | } 20 | "Signatures" 21 | { 22 | "CCStrike15ItemDefinition::GetLoadoutSlot" 23 | { 24 | "library" "server" 25 | "windows" "\x55\x8B\xEC\x8B\x45\x08\x8D\x50\xFF" 26 | "linux" "\x55\x89\xE5\x8B\x45\x0C\x8B\x55\x08\x8D\x48\xFF" 27 | } 28 | "CCSPlayer::FindMatchingWeaponsForTeamLoadout" 29 | { 30 | "library" "server" 31 | "windows" "\x55\x8B\xEC\x83\xEC\x08\x53\x56\x57\x89\x4D\xF8" 32 | "linux" "\x55\x89\xE5\x57\x56\x53\x83\xEC\x2C\x8B\x45\x14\x8B\x75\x10\x89\x45\xCC" 33 | } 34 | "CItemGeneration::SpawnItem" 35 | { 36 | "library" "server" 37 | "windows" "\x55\x8B\xEC\x51\x53\x56\x57\xE8\x2A\x2A\x2A\x2A\x8B\x5D\x08" 38 | "linux" "\x55\x89\xE5\x57\x56\x53\x83\xEC\x2C\x8B\x45\x08\x8B\x75\x0C\x8B\x5D\x20" 39 | } 40 | "FX_FireBullets" 41 | { 42 | "library" "server" 43 | "windows" "\x55\x8B\xEC\x83\xE4\xF8\x81\xEC\xE0\x01\x00\x00" 44 | "linux" "\x55\x89\xE5\x57\x56\x53\x81\xEC\xEC\x02\x00\x00\x8B\x45\x0C" 45 | } 46 | "g_CPlayerVoiceListener" 47 | { 48 | "library" "server" 49 | "windows" "\x6A\x00\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\x6A\x40" 50 | "linux" "\x55\x89\xE5\x53\x83\xEC\x04\x68\x00\x40\x00\x00" 51 | } 52 | } 53 | "Offsets" 54 | { 55 | "CBaseServer::ConnectClient" 56 | { 57 | "windows" "54" 58 | "linux" "55" 59 | } 60 | "CBaseServer::RejectConnection" 61 | { 62 | "windows" "52" 63 | "linux" "53" 64 | } 65 | "CEconItemSchema::m_mapItems" 66 | { 67 | "windows" "0xAC" 68 | "linux" "0xAC" 69 | } 70 | "CEconItemSchema::m_mapAttributesContainer" 71 | { 72 | "windows" "0x11C" 73 | "linux" "0x11C" 74 | } 75 | "CCStrike15ItemDefinition::m_vbClassUsability" 76 | { 77 | "windows" "0x288" 78 | "linux" "0x288" 79 | } 80 | "CEconItemDefinition::GetNumSupportedStickerSlots" 81 | { 82 | "windows" "44" 83 | "linux" "45" 84 | } 85 | "CEconItemDefinition::GetInventoryImage" 86 | { 87 | "windows" "5" 88 | "linux" "5" 89 | } 90 | "CEconItemDefinition::GetBasePlayerDisplayModel" 91 | { 92 | "windows" "6" 93 | "linux" "6" 94 | } 95 | "CEconItemDefinition::GetWorldDisplayModel" 96 | { 97 | "windows" "7" 98 | "linux" "7" 99 | } 100 | "CEconItemDefinition::GetWorldDroppedModel" 101 | { 102 | "windows" "33" 103 | "linux" "34" 104 | } 105 | "CEconItemDefinition::m_pszDefinitionName" 106 | { 107 | "windows" "0x1DC" 108 | "linux" "0x1DC" 109 | } 110 | "CGameClient::UpdateAcknowledgedFramecount" 111 | { 112 | "windows" "17" 113 | "linux" "55" 114 | } 115 | "CPlayerInventory::SendInventoryUpdateEvent" 116 | { 117 | "windows" "16" 118 | "linux" "17" 119 | } 120 | "CPlayerInventory::m_vecInventoryItems" 121 | { 122 | "windows" "0x2C" 123 | "linux" "0x2C" 124 | } 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /extension.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 : 3 | * ============================================================================= 4 | * SourceMod P Tools and Hooks Extension 5 | * Copyright (C) 2016-2023 Phoenix (˙·٠●Феникс●٠·˙). All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | */ 20 | 21 | #include "extension.h" 22 | #include "forwards.h" 23 | #include "natives.h" 24 | #include "classes.h" 25 | 26 | 27 | /** 28 | * @file extension.cpp 29 | * @brief Implement extension code here. 30 | */ 31 | 32 | PTaH g_PTaH; /**< Global singleton for extension's main interface */ 33 | 34 | SMEXT_LINK(&g_PTaH); 35 | 36 | IGameConfig* g_pGameConf[4]; 37 | 38 | ISDKTools* sdktools = nullptr; 39 | IServer* iserver = nullptr; 40 | IVoiceServer* voiceserver = nullptr; 41 | CGlobalVars* gpGlobals = nullptr; 42 | IServerGameClients* serverClients = nullptr; 43 | 44 | CEconItemSchema* g_pCEconItemSchema = nullptr; 45 | CPlayerVoiceListener* g_pCPlayerVoiceListener = nullptr; 46 | 47 | 48 | bool PTaH::SDK_OnLoad(char* error, size_t maxlength, bool late) 49 | { 50 | char conf_error[255]; 51 | 52 | if (!gameconfs->LoadGameConfigFile("sdktools.games", &g_pGameConf[GameConf_SDKT], conf_error, sizeof(conf_error))) 53 | { 54 | snprintf(error, maxlength, "Could not read sdktools.games: %s", conf_error); 55 | 56 | return false; 57 | } 58 | 59 | if (!gameconfs->LoadGameConfigFile("sdkhooks.games", &g_pGameConf[GameConf_SDKH], conf_error, sizeof(conf_error))) 60 | { 61 | snprintf(error, maxlength, "Could not read sdkhooks.games: %s", conf_error); 62 | 63 | return false; 64 | } 65 | 66 | if (!gameconfs->LoadGameConfigFile("PTaH.games", &g_pGameConf[GameConf_PTaH], conf_error, sizeof(conf_error))) 67 | { 68 | snprintf(error, maxlength, "Could not read PTaH.games: %s", conf_error); 69 | 70 | return false; 71 | } 72 | 73 | if (!gameconfs->LoadGameConfigFile("sm-cstrike.games", &g_pGameConf[GameConf_CSST], conf_error, sizeof(conf_error))) 74 | { 75 | snprintf(error, maxlength, "Could not read sm-cstrike.games: %s", conf_error); 76 | 77 | return false; 78 | } 79 | 80 | CDetourManager::Init(smutils->GetScriptingEngine(), g_pGameConf[GameConf_PTaH]); 81 | 82 | sharesys->AddDependency(myself, "sdktools.ext", true, true); 83 | 84 | sharesys->AddNatives(myself, g_ExtensionNatives); 85 | sharesys->RegisterLibrary(myself, "PTaH"); 86 | 87 | return true; 88 | } 89 | 90 | void PTaH::SDK_OnAllLoaded() 91 | { 92 | SM_GET_LATE_IFACE(SDKTOOLS, sdktools); 93 | 94 | iserver = sdktools->GetIServer(); 95 | g_pCEconItemSchema = CEconItemSchema::GetEconItemSchema(); 96 | g_pCPlayerVoiceListener = CPlayerVoiceListener::GetPlayerVoiceListener(); 97 | 98 | g_ForwardManager.Init(); 99 | } 100 | 101 | void PTaH::SDK_OnUnload() 102 | { 103 | g_ForwardManager.Shutdown(); 104 | 105 | gameconfs->CloseGameConfigFile(g_pGameConf[GameConf_SDKT]); 106 | gameconfs->CloseGameConfigFile(g_pGameConf[GameConf_SDKH]); 107 | gameconfs->CloseGameConfigFile(g_pGameConf[GameConf_PTaH]); 108 | gameconfs->CloseGameConfigFile(g_pGameConf[GameConf_CSST]); 109 | } 110 | 111 | bool PTaH::SDK_OnMetamodLoad(ISmmAPI* ismm, char* error, size_t maxlen, bool late) 112 | { 113 | GET_V_IFACE_ANY(GetEngineFactory, voiceserver, IVoiceServer, INTERFACEVERSION_VOICESERVER); 114 | GET_V_IFACE_ANY(GetServerFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS); 115 | 116 | gpGlobals = ismm->GetCGlobals(); 117 | 118 | return true; 119 | } -------------------------------------------------------------------------------- /.github/workflows/compile.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - LICENSE 7 | - README.md 8 | 9 | pull_request: 10 | paths-ignore: 11 | - LICENSE 12 | - README.md 13 | 14 | workflow_dispatch: 15 | 16 | jobs: 17 | build: 18 | name: Build on ${{ matrix.os_short }} 19 | runs-on: ${{ matrix.os }} 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | # Compile on Linux & Windows. 24 | os: 25 | - ubuntu-20.04 26 | - windows-latest 27 | 28 | include: 29 | - os: ubuntu-20.04 30 | os_short: linux 31 | - os: windows-latest 32 | os_short: win 33 | steps: 34 | - name: Short SHA 35 | shell: bash 36 | run: | 37 | echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV 38 | 39 | # Setup Python for AMBuild. 40 | - name: Setup Python 3.8 41 | uses: actions/setup-python@v4 42 | with: 43 | python-version: 3.8 44 | 45 | # Install dependencies 46 | - name: Install AMBuild 47 | run: | 48 | python -m pip install --upgrade pip setuptools wheel 49 | pip install git+https://github.com/alliedmodders/ambuild 50 | 51 | - name: Install dependencies 52 | if: runner.os == 'Linux' 53 | run: | 54 | sudo dpkg --add-architecture i386 55 | sudo apt-get update 56 | sudo apt-get install -y clang g++-multilib 57 | 58 | - name: Select clang compiler 59 | if: runner.os == 'Linux' 60 | run: | 61 | echo "CC=clang" >> $GITHUB_ENV 62 | echo "CXX=clang++" >> $GITHUB_ENV 63 | clang --version 64 | clang++ --version 65 | 66 | - name: Find Visual C++ compilers and make all environment variables global (W) 67 | if: runner.os == 'Windows' 68 | shell: cmd 69 | run: | 70 | :: See https://github.com/microsoft/vswhere/wiki/Find-VC 71 | for /f "usebackq delims=*" %%i in (`vswhere -latest -property installationPath`) do ( 72 | call "%%i"\Common7\Tools\vsdevcmd.bat -arch=x86 -host_arch=x64 73 | ) 74 | 75 | :: Loop over all environment variables and make them global. 76 | for /f "delims== tokens=1,2" %%a in ('set') do ( 77 | echo>>"%GITHUB_ENV%" %%a=%%b 78 | ) 79 | 80 | # Checkout repos 81 | - name: Checkout Metamod:Source 82 | uses: actions/checkout@v3 83 | with: 84 | repository: alliedmodders/metamod-source 85 | ref: 1.11-dev 86 | path: metamod-source 87 | 88 | - name: Checkout SourceMod 89 | uses: actions/checkout@v3 90 | with: 91 | repository: alliedmodders/sourcemod 92 | ref: 1.11-dev 93 | path: sourcemod 94 | submodules: true 95 | 96 | - name: Checkout hl2sdk-csgo 97 | uses: actions/checkout@v3 98 | with: 99 | repository: Wend4r/hl2sdk 100 | ref: csgo 101 | path: hl2sdk-csgo 102 | 103 | - name: Checkout 104 | uses: actions/checkout@v3 105 | with: 106 | path: project 107 | 108 | # Build 109 | - name: Use lto 110 | if: startsWith(github.ref, 'refs/tags/') 111 | run: echo "BUILD_LTO=--enable-lto" >> $GITHUB_ENV 112 | 113 | - name: Build 114 | shell: bash 115 | run: | 116 | cd project && mkdir build && cd build 117 | python ../configure.py --enable-optimize --build-id ${{ env.GITHUB_SHA_SHORT }} ${{ env.BUILD_LTO }} 118 | ambuild 119 | 120 | - name: Copy pdb 121 | if: runner.os == 'Windows' 122 | working-directory: project/build 123 | run: cp PTaH.ext.2.csgo/PTaH.ext.2.csgo.pdb package/addons/sourcemod/extensions 124 | 125 | - name: Upload artifact 126 | uses: actions/upload-artifact@v3 127 | with: 128 | name: ${{ runner.os }} 129 | path: project/build/package 130 | 131 | release: 132 | name: Release 133 | if: startsWith(github.ref, 'refs/tags/') 134 | needs: build 135 | runs-on: ubuntu-latest 136 | 137 | steps: 138 | - name: Download artifacts 139 | uses: actions/download-artifact@v3 140 | 141 | - name: Package 142 | run: | 143 | 7z a -mx9 linux.zip ./Linux/* 144 | 7z a -mx9 -xr!*.pdb windows.zip ./Windows/* 145 | - name: Release 146 | uses: svenstaro/upload-release-action@v2 147 | with: 148 | repo_token: ${{ secrets.GITHUB_TOKEN }} 149 | file: '*.zip' 150 | tag: ${{ github.ref }} 151 | file_glob: true 152 | -------------------------------------------------------------------------------- /extension.h: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 : 3 | * ============================================================================= 4 | * SourceMod P Tools and Hooks Extension 5 | * Copyright (C) 2016-2023 Phoenix (˙·٠●Феникс●٠·˙). All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | */ 20 | 21 | #ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ 22 | #define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ 23 | 24 | /** 25 | * @file extension.h 26 | * @brief Sample extension code header. 27 | */ 28 | 29 | 30 | // networkvar.h must be included before smsdk_ext.h !!! 31 | #include "networkvar.h" 32 | #include "smsdk_ext.h" 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | #ifdef PLATFORM_WINDOWS 43 | #define WIN_LINUX(win, linux) win 44 | #else 45 | #define WIN_LINUX(win, linux) linux 46 | #endif 47 | 48 | template 49 | constexpr T CallVFunc(size_t index, void* pThis, Args... args) noexcept 50 | { 51 | return reinterpret_cast(reinterpret_cast(pThis)[0][index])(pThis, args...); 52 | } 53 | 54 | template 55 | constexpr T CallVFMTFunc(size_t index, void* pThis, Args... args, const char* fmt, Va... va) noexcept 56 | { 57 | return reinterpret_cast(reinterpret_cast(pThis)[0][index])(pThis, args..., fmt, va...); 58 | } 59 | 60 | 61 | /** 62 | * @brief Sample implementation of the SDK Extension. 63 | * Note: Uncomment one of the pre-defined virtual functions in order to use it. 64 | */ 65 | class PTaH : public SDKExtension 66 | { 67 | public: 68 | /** 69 | * @brief This is called after the initial loading sequence has been processed. 70 | * 71 | * @param error Error message buffer. 72 | * @param maxlength Size of error message buffer. 73 | * @param late Whether or not the module was loaded after map load. 74 | * @return True to succeed loading, false to fail. 75 | */ 76 | virtual bool SDK_OnLoad(char* error, size_t maxlength, bool late); 77 | 78 | /** 79 | * @brief This is called right before the extension is unloaded. 80 | */ 81 | virtual void SDK_OnUnload(); 82 | 83 | /** 84 | * @brief This is called once all known extensions have been loaded. 85 | * Note: It is is a good idea to add natives here, if any are provided. 86 | */ 87 | virtual void SDK_OnAllLoaded(); 88 | 89 | /** 90 | * @brief Called when the pause state is changed. 91 | */ 92 | //virtual void SDK_OnPauseChange(bool paused); 93 | 94 | /** 95 | * @brief this is called when Core wants to know if your extension is working. 96 | * 97 | * @param error Error message buffer. 98 | * @param maxlength Size of error message buffer. 99 | * @return True if working, false otherwise. 100 | */ 101 | //virtual bool QueryRunning(char *error, size_t maxlength); 102 | public: 103 | #if defined SMEXT_CONF_METAMOD 104 | /** 105 | * @brief Called when Metamod is attached, before the extension version is called. 106 | * 107 | * @param error Error buffer. 108 | * @param maxlength Maximum size of error buffer. 109 | * @param late Whether or not Metamod considers this a late load. 110 | * @return True to succeed, false to fail. 111 | */ 112 | virtual bool SDK_OnMetamodLoad(ISmmAPI* ismm, char* error, size_t maxlength, bool late); 113 | 114 | /** 115 | * @brief Called when Metamod is detaching, after the extension version is called. 116 | * NOTE: By default this is blocked unless sent from SourceMod. 117 | * 118 | * @param error Error buffer. 119 | * @param maxlength Maximum size of error buffer. 120 | * @return True to succeed, false to fail. 121 | */ 122 | //virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); 123 | 124 | /** 125 | * @brief Called when Metamod's pause state is changing. 126 | * NOTE: By default this is blocked unless sent from SourceMod. 127 | * 128 | * @param paused Pause state being set. 129 | * @param error Error buffer. 130 | * @param maxlength Maximum size of error buffer. 131 | * @return True to succeed, false to fail. 132 | */ 133 | //virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); 134 | #endif 135 | }; 136 | 137 | /* Interfaces from SourceMod */ 138 | #define GameConf_SDKT 0 139 | #define GameConf_SDKH 1 140 | #define GameConf_PTaH 2 141 | #define GameConf_CSST 3 142 | 143 | extern IGameConfig* g_pGameConf[4]; 144 | extern ISDKTools* sdktools; 145 | extern IServer* iserver; 146 | extern IVoiceServer* voiceserver; 147 | extern CGlobalVars* gpGlobals; 148 | extern IServerGameClients* serverClients; 149 | 150 | #endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ -------------------------------------------------------------------------------- /smsdk_ext.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 sw=4 tw=99 noet: 3 | * ============================================================================= 4 | * SourceMod Base Extension Code 5 | * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | * 20 | * As a special exception, AlliedModders LLC gives you permission to link the 21 | * code of this program (as well as its derivative works) to "Half-Life 2," the 22 | * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software 23 | * by the Valve Corporation. You must obey the GNU General Public License in 24 | * all respects for all other code used. Additionally, AlliedModders LLC grants 25 | * this exception to all derivative works. AlliedModders LLC defines further 26 | * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), 27 | * or . 28 | * 29 | * Version: $Id$ 30 | */ 31 | 32 | #include 33 | #include 34 | #include "smsdk_ext.h" 35 | #include "am-string.h" 36 | 37 | /** 38 | * @file smsdk_ext.cpp 39 | * @brief Contains wrappers for making Extensions easier to write. 40 | */ 41 | 42 | IExtension *myself = NULL; /**< Ourself */ 43 | IShareSys *g_pShareSys = NULL; /**< Share system */ 44 | IShareSys *sharesys = NULL; /**< Share system */ 45 | ISourceMod *g_pSM = NULL; /**< SourceMod helpers */ 46 | ISourceMod *smutils = NULL; /**< SourceMod helpers */ 47 | 48 | #if defined SMEXT_ENABLE_FORWARDSYS 49 | IForwardManager *g_pForwards = NULL; /**< Forward system */ 50 | IForwardManager *forwards = NULL; /**< Forward system */ 51 | #endif 52 | #if defined SMEXT_ENABLE_HANDLESYS 53 | IHandleSys *g_pHandleSys = NULL; /**< Handle system */ 54 | IHandleSys *handlesys = NULL; /**< Handle system */ 55 | #endif 56 | #if defined SMEXT_ENABLE_PLAYERHELPERS 57 | IPlayerManager *playerhelpers = NULL; /**< Player helpers */ 58 | #endif //SMEXT_ENABLE_PLAYERHELPERS 59 | #if defined SMEXT_ENABLE_DBMANAGER 60 | IDBManager *dbi = NULL; /**< DB Manager */ 61 | #endif //SMEXT_ENABLE_DBMANAGER 62 | #if defined SMEXT_ENABLE_GAMECONF 63 | IGameConfigManager *gameconfs = NULL; /**< Game config manager */ 64 | #endif //SMEXT_ENABLE_DBMANAGER 65 | #if defined SMEXT_ENABLE_MEMUTILS 66 | IMemoryUtils *memutils = NULL; 67 | #endif //SMEXT_ENABLE_DBMANAGER 68 | #if defined SMEXT_ENABLE_GAMEHELPERS 69 | IGameHelpers *gamehelpers = NULL; 70 | #endif 71 | #if defined SMEXT_ENABLE_TIMERSYS 72 | ITimerSystem *timersys = NULL; 73 | #endif 74 | #if defined SMEXT_ENABLE_ADTFACTORY 75 | IADTFactory *adtfactory = NULL; 76 | #endif 77 | #if defined SMEXT_ENABLE_THREADER 78 | IThreader *threader = NULL; 79 | #endif 80 | #if defined SMEXT_ENABLE_LIBSYS 81 | ILibrarySys *libsys = NULL; 82 | #endif 83 | #if defined SMEXT_ENABLE_PLUGINSYS 84 | SourceMod::IPluginManager *plsys; 85 | #endif 86 | #if defined SMEXT_ENABLE_MENUS 87 | IMenuManager *menus = NULL; 88 | #endif 89 | #if defined SMEXT_ENABLE_ADMINSYS 90 | IAdminSystem *adminsys = NULL; 91 | #endif 92 | #if defined SMEXT_ENABLE_TEXTPARSERS 93 | ITextParsers *textparsers = NULL; 94 | #endif 95 | #if defined SMEXT_ENABLE_USERMSGS 96 | IUserMessages *usermsgs = NULL; 97 | #endif 98 | #if defined SMEXT_ENABLE_TRANSLATOR 99 | ITranslator *translator = NULL; 100 | #endif 101 | #if defined SMEXT_ENABLE_ROOTCONSOLEMENU 102 | IRootConsole *rootconsole = NULL; 103 | #endif 104 | 105 | /** Exports the main interface */ 106 | PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() 107 | { 108 | return g_pExtensionIface; 109 | } 110 | 111 | SDKExtension::SDKExtension() 112 | { 113 | #if defined SMEXT_CONF_METAMOD 114 | m_SourceMMLoaded = false; 115 | m_WeAreUnloaded = false; 116 | m_WeGotPauseChange = false; 117 | #endif 118 | } 119 | 120 | bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late) 121 | { 122 | g_pShareSys = sharesys = sys; 123 | myself = me; 124 | 125 | #if defined SMEXT_CONF_METAMOD 126 | m_WeAreUnloaded = true; 127 | 128 | if (!m_SourceMMLoaded) 129 | { 130 | if (error) 131 | { 132 | ke::SafeStrcpy(error, maxlength, "Metamod attach failed"); 133 | } 134 | return false; 135 | } 136 | #endif 137 | SM_GET_IFACE(SOURCEMOD, g_pSM); 138 | smutils = g_pSM; 139 | #if defined SMEXT_ENABLE_HANDLESYS 140 | SM_GET_IFACE(HANDLESYSTEM, g_pHandleSys); 141 | handlesys = g_pHandleSys; 142 | #endif 143 | #if defined SMEXT_ENABLE_FORWARDSYS 144 | SM_GET_IFACE(FORWARDMANAGER, g_pForwards); 145 | forwards = g_pForwards; 146 | #endif 147 | #if defined SMEXT_ENABLE_PLAYERHELPERS 148 | SM_GET_IFACE(PLAYERMANAGER, playerhelpers); 149 | #endif 150 | #if defined SMEXT_ENABLE_DBMANAGER 151 | SM_GET_IFACE(DBI, dbi); 152 | #endif 153 | #if defined SMEXT_ENABLE_GAMECONF 154 | SM_GET_IFACE(GAMECONFIG, gameconfs); 155 | #endif 156 | #if defined SMEXT_ENABLE_MEMUTILS 157 | SM_GET_IFACE(MEMORYUTILS, memutils); 158 | #endif 159 | #if defined SMEXT_ENABLE_GAMEHELPERS 160 | SM_GET_IFACE(GAMEHELPERS, gamehelpers); 161 | #endif 162 | #if defined SMEXT_ENABLE_TIMERSYS 163 | SM_GET_IFACE(TIMERSYS, timersys); 164 | #endif 165 | #if defined SMEXT_ENABLE_ADTFACTORY 166 | SM_GET_IFACE(ADTFACTORY, adtfactory); 167 | #endif 168 | #if defined SMEXT_ENABLE_THREADER 169 | SM_GET_IFACE(THREADER, threader); 170 | #endif 171 | #if defined SMEXT_ENABLE_LIBSYS 172 | SM_GET_IFACE(LIBRARYSYS, libsys); 173 | #endif 174 | #if defined SMEXT_ENABLE_PLUGINSYS 175 | SM_GET_IFACE(PLUGINSYSTEM, plsys); 176 | #endif 177 | #if defined SMEXT_ENABLE_MENUS 178 | SM_GET_IFACE(MENUMANAGER, menus); 179 | #endif 180 | #if defined SMEXT_ENABLE_ADMINSYS 181 | SM_GET_IFACE(ADMINSYS, adminsys); 182 | #endif 183 | #if defined SMEXT_ENABLE_TEXTPARSERS 184 | SM_GET_IFACE(TEXTPARSERS, textparsers); 185 | #endif 186 | #if defined SMEXT_ENABLE_USERMSGS 187 | SM_GET_IFACE(USERMSGS, usermsgs); 188 | #endif 189 | #if defined SMEXT_ENABLE_TRANSLATOR 190 | SM_GET_IFACE(TRANSLATOR, translator); 191 | #endif 192 | #if defined SMEXT_ENABLE_ROOTCONSOLEMENU 193 | SM_GET_IFACE(ROOTCONSOLE, rootconsole); 194 | #endif 195 | 196 | if (SDK_OnLoad(error, maxlength, late)) 197 | { 198 | #if defined SMEXT_CONF_METAMOD 199 | m_WeAreUnloaded = true; 200 | #endif 201 | return true; 202 | } 203 | 204 | return false; 205 | } 206 | 207 | bool SDKExtension::IsMetamodExtension() 208 | { 209 | #if defined SMEXT_CONF_METAMOD 210 | return true; 211 | #else 212 | return false; 213 | #endif 214 | } 215 | 216 | void SDKExtension::OnExtensionPauseChange(bool state) 217 | { 218 | #if defined SMEXT_CONF_METAMOD 219 | m_WeGotPauseChange = true; 220 | #endif 221 | SDK_OnPauseChange(state); 222 | } 223 | 224 | void SDKExtension::OnExtensionsAllLoaded() 225 | { 226 | SDK_OnAllLoaded(); 227 | } 228 | 229 | void SDKExtension::OnExtensionUnload() 230 | { 231 | #if defined SMEXT_CONF_METAMOD 232 | m_WeAreUnloaded = true; 233 | #endif 234 | SDK_OnUnload(); 235 | } 236 | 237 | void SDKExtension::OnDependenciesDropped() 238 | { 239 | SDK_OnDependenciesDropped(); 240 | } 241 | 242 | const char *SDKExtension::GetExtensionAuthor() 243 | { 244 | return SMEXT_CONF_AUTHOR; 245 | } 246 | 247 | const char *SDKExtension::GetExtensionDateString() 248 | { 249 | return SMEXT_CONF_DATESTRING; 250 | } 251 | 252 | const char *SDKExtension::GetExtensionDescription() 253 | { 254 | return SMEXT_CONF_DESCRIPTION; 255 | } 256 | 257 | const char *SDKExtension::GetExtensionVerString() 258 | { 259 | return SMEXT_CONF_VERSION BUILD_ID; 260 | } 261 | 262 | const char *SDKExtension::GetExtensionName() 263 | { 264 | return SMEXT_CONF_NAME; 265 | } 266 | 267 | const char *SDKExtension::GetExtensionTag() 268 | { 269 | return SMEXT_CONF_LOGTAG; 270 | } 271 | 272 | const char *SDKExtension::GetExtensionURL() 273 | { 274 | return SMEXT_CONF_URL; 275 | } 276 | 277 | bool SDKExtension::SDK_OnLoad(char *error, size_t maxlength, bool late) 278 | { 279 | return true; 280 | } 281 | 282 | void SDKExtension::SDK_OnUnload() 283 | { 284 | } 285 | 286 | void SDKExtension::SDK_OnPauseChange(bool paused) 287 | { 288 | } 289 | 290 | void SDKExtension::SDK_OnAllLoaded() 291 | { 292 | } 293 | 294 | void SDKExtension::SDK_OnDependenciesDropped() 295 | { 296 | } 297 | 298 | #if defined SMEXT_CONF_METAMOD 299 | 300 | PluginId g_PLID = 0; /**< Metamod plugin ID */ 301 | ISmmPlugin *g_PLAPI = NULL; /**< Metamod plugin API */ 302 | SourceHook::ISourceHook *g_SHPtr = NULL; /**< SourceHook pointer */ 303 | ISmmAPI *g_SMAPI = NULL; /**< SourceMM API pointer */ 304 | 305 | #ifndef META_NO_HL2SDK 306 | IVEngineServer *engine = NULL; /**< IVEngineServer pointer */ 307 | IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ 308 | #endif 309 | 310 | /** Exposes the extension to Metamod */ 311 | SMM_API void *PL_EXPOSURE(const char *name, int *code) 312 | { 313 | #if defined METAMOD_PLAPI_VERSION 314 | if (name && !strcmp(name, METAMOD_PLAPI_NAME)) 315 | #else 316 | if (name && !strcmp(name, PLAPI_NAME)) 317 | #endif 318 | { 319 | if (code) 320 | { 321 | *code = META_IFACE_OK; 322 | } 323 | return static_cast(g_pExtensionIface); 324 | } 325 | 326 | if (code) 327 | { 328 | *code = META_IFACE_FAILED; 329 | } 330 | 331 | return NULL; 332 | } 333 | 334 | bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) 335 | { 336 | PLUGIN_SAVEVARS(); 337 | 338 | #ifndef META_NO_HL2SDK 339 | #if !defined METAMOD_PLAPI_VERSION 340 | GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); 341 | GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); 342 | #else 343 | GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); 344 | #if SOURCE_ENGINE == SE_SDK2013 345 | // Shim to avoid hooking shims 346 | engine = (IVEngineServer *) ismm->GetEngineFactory()("VEngineServer023", nullptr); 347 | if (!engine) 348 | { 349 | engine = (IVEngineServer *) ismm->GetEngineFactory()("VEngineServer022", nullptr); 350 | if (!engine) 351 | { 352 | engine = (IVEngineServer *) ismm->GetEngineFactory()("VEngineServer021", nullptr); 353 | if (!engine) 354 | { 355 | if (error && maxlen) 356 | { 357 | ismm->Format(error, maxlen, "Could not find interface: VEngineServer023 or VEngineServer022"); 358 | } 359 | return false; 360 | } 361 | } 362 | } 363 | #else 364 | GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); 365 | #endif // TF2 / CSS / DODS / HL2DM / SDK2013 366 | #endif // !METAMOD_PLAPI_VERSION 367 | #endif //META_NO_HL2SDK 368 | 369 | m_SourceMMLoaded = true; 370 | 371 | return SDK_OnMetamodLoad(ismm, error, maxlen, late); 372 | } 373 | 374 | bool SDKExtension::Unload(char *error, size_t maxlen) 375 | { 376 | if (!m_WeAreUnloaded) 377 | { 378 | if (error) 379 | { 380 | ke::SafeStrcpy(error, maxlen, "This extension must be unloaded by SourceMod."); 381 | } 382 | return false; 383 | } 384 | 385 | return SDK_OnMetamodUnload(error, maxlen); 386 | } 387 | 388 | bool SDKExtension::Pause(char *error, size_t maxlen) 389 | { 390 | if (!m_WeGotPauseChange) 391 | { 392 | if (error) 393 | { 394 | ke::SafeStrcpy(error, maxlen, "This extension must be paused by SourceMod."); 395 | } 396 | return false; 397 | } 398 | 399 | m_WeGotPauseChange = false; 400 | 401 | return SDK_OnMetamodPauseChange(true, error, maxlen); 402 | } 403 | 404 | bool SDKExtension::Unpause(char *error, size_t maxlen) 405 | { 406 | if (!m_WeGotPauseChange) 407 | { 408 | if (error) 409 | { 410 | ke::SafeStrcpy(error, maxlen, "This extension must be unpaused by SourceMod."); 411 | } 412 | return false; 413 | } 414 | 415 | m_WeGotPauseChange = false; 416 | 417 | return SDK_OnMetamodPauseChange(false, error, maxlen); 418 | } 419 | 420 | const char *SDKExtension::GetAuthor() 421 | { 422 | return GetExtensionAuthor(); 423 | } 424 | 425 | const char *SDKExtension::GetDate() 426 | { 427 | return GetExtensionDateString(); 428 | } 429 | 430 | const char *SDKExtension::GetDescription() 431 | { 432 | return GetExtensionDescription(); 433 | } 434 | 435 | const char *SDKExtension::GetLicense() 436 | { 437 | return SMEXT_CONF_LICENSE; 438 | } 439 | 440 | const char *SDKExtension::GetLogTag() 441 | { 442 | return GetExtensionTag(); 443 | } 444 | 445 | const char *SDKExtension::GetName() 446 | { 447 | return GetExtensionName(); 448 | } 449 | 450 | const char *SDKExtension::GetURL() 451 | { 452 | return GetExtensionURL(); 453 | } 454 | 455 | const char *SDKExtension::GetVersion() 456 | { 457 | return GetExtensionVerString(); 458 | } 459 | 460 | bool SDKExtension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late) 461 | { 462 | return true; 463 | } 464 | 465 | bool SDKExtension::SDK_OnMetamodUnload(char *error, size_t maxlength) 466 | { 467 | return true; 468 | } 469 | 470 | bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength) 471 | { 472 | return true; 473 | } 474 | 475 | #endif 476 | 477 | -------------------------------------------------------------------------------- /forwards.h: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 : 3 | * ============================================================================= 4 | * SourceMod P Tools and Hooks Extension 5 | * Copyright (C) 2016-2023 Phoenix (˙·٠●Феникс●٠·˙). All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | */ 20 | 21 | #ifndef _INCLUDE_SOURCEMOD_EXTENSION_FORWARDS_H_ 22 | #define _INCLUDE_SOURCEMOD_EXTENSION_FORWARDS_H_ 23 | 24 | #include "extension.h" 25 | #include "natives.h" 26 | #include "classes.h" 27 | #include "netmessages.pb.h" 28 | #include 29 | #include 30 | 31 | class CForwardManager 32 | { 33 | friend class CCSPlayer_FindMatchingWeaponsForTeamLoadoutClass; 34 | 35 | public: 36 | void Init(); 37 | void Shutdown(); 38 | bool UpdateHook(PTaH_HookEvent htType, IPluginFunction* pFunction, bool bHook); 39 | 40 | private: 41 | class CBaseHook : public IPluginsListener 42 | { 43 | public: 44 | virtual void Init() = 0; 45 | virtual void Shutdown(); 46 | virtual bool UpdateHook(SourcePawn::IPluginFunction* pFunction, bool bHook); 47 | 48 | protected: 49 | CBaseHook(); 50 | virtual void UpdateInternalHook(); 51 | virtual void OnInternalHookActivated(); 52 | virtual void OnInternalHookDeactivated(); 53 | 54 | private: // IPluginsListener 55 | void OnPluginUnloaded(IPlugin* plugin) override; 56 | 57 | protected: 58 | IChangeableForward* m_pForward; 59 | bool m_bHooked; 60 | }; 61 | 62 | ///////////////////////////////// 63 | 64 | class CBaseManualPlayerHook : public CBaseHook, public IClientListener 65 | { 66 | typedef CBaseHook BaseClass; 67 | 68 | protected: 69 | CBaseManualPlayerHook(); 70 | 71 | private: 72 | virtual int ManualHook(int iClient) = 0; 73 | 74 | protected: // CBaseHook 75 | void OnInternalHookActivated() override; 76 | void OnInternalHookDeactivated() override; 77 | 78 | private: // IClientListener 79 | void OnClientPutInServer(int iClient) override; 80 | void OnClientDisconnected(int iClient) override; 81 | 82 | private: 83 | int m_iHookID[SM_MAXPLAYERS + 1]; 84 | }; 85 | 86 | class CBaseVPHook : public CBaseHook, public IClientListener 87 | { 88 | typedef CBaseHook BaseClass; 89 | 90 | protected: 91 | CBaseVPHook(bool bInGame); 92 | 93 | private: 94 | virtual int VPHook(int iClient) = 0; 95 | void OnClientValid(int iClient); 96 | 97 | private: // CBaseHook 98 | void OnInternalHookActivated() override; 99 | void OnInternalHookDeactivated() override; 100 | 101 | private: // IClientListener 102 | void OnClientConnected(int iClient) override; 103 | void OnClientPutInServer(int iClient) override; 104 | 105 | private: 106 | int m_iHookID; 107 | bool m_bInGame; 108 | }; 109 | 110 | class CBaseClientHook : public CBaseVPHook 111 | { 112 | typedef CBaseVPHook BaseClass; 113 | 114 | protected: 115 | CBaseClientHook(); 116 | IClient* ForceCastToIClient(IClient* pClient); 117 | 118 | #ifdef PLATFORM_LINUX 119 | private: // CBaseVPHook 120 | void OnInternalHookDeactivated() override; 121 | 122 | protected: 123 | int GetParentVFuncOffset(IClient* pClient, size_t vtbIndex); 124 | 125 | protected: 126 | int m_iGameHookId; 127 | #endif 128 | }; 129 | 130 | ///////////////////////////////// 131 | 132 | class GiveNamedItemHook : public CBaseManualPlayerHook 133 | { 134 | protected: 135 | bool Configure(); 136 | 137 | private: 138 | virtual const char* GetHookName() = 0; 139 | }; 140 | 141 | class GiveNamedItemPreHook : public GiveNamedItemHook 142 | { 143 | typedef GiveNamedItemHook BaseClass; 144 | friend class CCSPlayer_FindMatchingWeaponsForTeamLoadoutClass; 145 | 146 | public: 147 | GiveNamedItemPreHook(); 148 | 149 | private: // CBaseHook 150 | void Init() override; 151 | void Shutdown() override; 152 | 153 | private: // CBaseManualPlayerHook 154 | int ManualHook(int iClient) override; 155 | void OnInternalHookActivated() override; 156 | void OnInternalHookDeactivated() override; 157 | 158 | private: 159 | CBaseEntity* Handler(const char* pchName, int iSubType, CEconItemView* pScriptItem, bool bForce, Vector* pOrigin); 160 | 161 | const char* GetHookName() override { return "GiveNamedItemPre"; } 162 | 163 | private: 164 | CDetour* m_pFindMatchingWeaponsForTeamLoadoutHook; 165 | int m_iFrameCount; 166 | } m_GiveNamedItemPreHook; 167 | 168 | class GiveNamedItemPostHook : public GiveNamedItemHook 169 | { 170 | typedef GiveNamedItemHook BaseClass; 171 | 172 | public: 173 | GiveNamedItemPostHook(); 174 | 175 | private: // CBaseHook 176 | void Init() override; 177 | 178 | private: // CBaseManualPlayerHook 179 | int ManualHook(int iClient) override; 180 | 181 | private: 182 | CBaseEntity* Handler(const char* pchName, int iSubType, CEconItemView* pScriptItem, bool bForce, Vector* pOrigin); 183 | 184 | const char* GetHookName() override { return "GiveNamedItemPost"; } 185 | } m_GiveNamedItemPostHook; 186 | 187 | ///////////////////////////////// 188 | 189 | class WeaponCanUseHook : public CBaseManualPlayerHook 190 | { 191 | protected: 192 | bool Configure(); 193 | 194 | private: 195 | virtual const char* GetHookName() = 0; 196 | }; 197 | 198 | class WeaponCanUsePreHook : public WeaponCanUseHook 199 | { 200 | typedef WeaponCanUseHook BaseClass; 201 | 202 | public: 203 | WeaponCanUsePreHook(); 204 | 205 | private: // CBaseHook 206 | void Init() override; 207 | 208 | private: // CBaseManualPlayerHook 209 | int ManualHook(int iClient) override; 210 | 211 | private: 212 | bool Handler(CBaseCombatWeapon* pWeapon); 213 | 214 | const char* GetHookName() override { return "WeaponCanUsePre"; } 215 | } m_WeaponCanUsePreHook; 216 | 217 | class WeaponCanUsePostHook : public WeaponCanUseHook 218 | { 219 | typedef WeaponCanUseHook BaseClass; 220 | 221 | public: 222 | WeaponCanUsePostHook(); 223 | 224 | private: // CBaseHook 225 | void Init() override; 226 | 227 | private: // CBaseManualPlayerHook 228 | int ManualHook(int iClient) override; 229 | 230 | private: 231 | bool Handler(CBaseCombatWeapon* pWeapon); 232 | 233 | const char* GetHookName() override { return "WeaponCanUsePost"; } 234 | } m_WeaponCanUsePostHook; 235 | 236 | ///////////////////////////////// 237 | 238 | class SetPlayerModelHook : public CBaseManualPlayerHook 239 | { 240 | protected: 241 | bool Configure(); 242 | 243 | private: 244 | virtual const char* GetHookName() = 0; 245 | }; 246 | 247 | class SetPlayerModelPreHook : public SetPlayerModelHook 248 | { 249 | typedef SetPlayerModelHook BaseClass; 250 | 251 | public: 252 | SetPlayerModelPreHook(); 253 | 254 | private: // CBaseHook 255 | void Init() override; 256 | 257 | private: // CBaseManualPlayerHook 258 | int ManualHook(int iClient) override; 259 | 260 | private: 261 | void Handler(const char* pszModelName); 262 | 263 | const char* GetHookName() override { return "SetPlayerModelPre"; } 264 | } m_SetPlayerModelPreHook; 265 | 266 | class SetPlayerModelPostHook : public SetPlayerModelHook 267 | { 268 | typedef SetPlayerModelHook BaseClass; 269 | 270 | public: 271 | SetPlayerModelPostHook(); 272 | 273 | private: // CBaseHook 274 | void Init() override; 275 | 276 | private: // CBaseManualPlayerHook 277 | int ManualHook(int iClient) override; 278 | 279 | private: 280 | void Handler(const char* pszModelName); 281 | 282 | const char* GetHookName() override { return "SetPlayerModelPost"; } 283 | } m_SetPlayerModelPostHook; 284 | 285 | ///////////////////////////////// 286 | 287 | class ClientVoiceToPreHook : public CBaseHook 288 | { 289 | typedef CBaseHook BaseClass; 290 | 291 | public: 292 | ClientVoiceToPreHook(); 293 | 294 | private: // CBaseHook 295 | void Init() override; 296 | void OnInternalHookActivated() override; 297 | void OnInternalHookDeactivated() override; 298 | 299 | private: 300 | bool Handler(int iReceiver, int iSender, bool bListen); 301 | void ClientVoiceHandler(edict_t* pEdict); 302 | 303 | private: 304 | bool m_bStartVoice[SM_MAXPLAYERS + 1]; 305 | } m_ClientVoiceToPreHook; 306 | 307 | class ClientVoiceToPostHook : public CBaseHook 308 | { 309 | typedef CBaseHook BaseClass; 310 | 311 | public: 312 | ClientVoiceToPostHook(); 313 | 314 | private: // CBaseHook 315 | void Init() override; 316 | void OnInternalHookActivated() override; 317 | void OnInternalHookDeactivated() override; 318 | 319 | private: 320 | bool Handler(int iReceiver, int iSender, bool bListen); 321 | } m_ClientVoiceToPostHook; 322 | 323 | ///////////////////////////////// 324 | 325 | class ConsolePrintPreHook : public CBaseClientHook 326 | { 327 | public: 328 | ConsolePrintPreHook(); 329 | 330 | private: // CBaseHook 331 | void Init() override; 332 | 333 | private: // CBaseVPHook 334 | int VPHook(int iClient) override; 335 | 336 | private: 337 | void Handler(const char* szFormat); 338 | } m_ConsolePrintPreHook; 339 | 340 | class ConsolePrintPostHook : public CBaseClientHook 341 | { 342 | public: 343 | ConsolePrintPostHook(); 344 | 345 | private: // CBaseHook 346 | void Init() override; 347 | 348 | private: // CBaseVPHook 349 | int VPHook(int iClient) override; 350 | 351 | private: 352 | void Handler(const char* szFormat); 353 | } m_ConsolePrintPostHook; 354 | 355 | ///////////////////////////////// 356 | 357 | class ExecuteStringCommandPreHook : public CBaseClientHook 358 | { 359 | public: 360 | ExecuteStringCommandPreHook(); 361 | 362 | private: // CBaseHook 363 | void Init() override; 364 | 365 | private: // CBaseVPHook 366 | int VPHook(int iClient) override; 367 | 368 | private: 369 | bool Handler(const char* pCommandString); 370 | } m_ExecuteStringCommandPreHook; 371 | 372 | class ExecuteStringCommandPostHook : public CBaseClientHook 373 | { 374 | public: 375 | ExecuteStringCommandPostHook(); 376 | 377 | private: // CBaseHook 378 | void Init() override; 379 | 380 | private: // CBaseVPHook 381 | int VPHook(int iClient) override; 382 | 383 | private: 384 | bool Handler(const char* pCommandString); 385 | } m_ExecuteStringCommandPostHook; 386 | 387 | ///////////////////////////////// 388 | 389 | class ClientConnectHook : public CBaseHook 390 | { 391 | typedef CBaseHook BaseClass; 392 | 393 | protected: 394 | ClientConnectHook(); 395 | bool Configure(); 396 | const char* ExtractPlayerName(CUtlVector& splitScreenClients); 397 | 398 | private: 399 | virtual const char* GetHookName() = 0; 400 | virtual int ManualHook() = 0; 401 | 402 | private: // CBaseHook 403 | void OnInternalHookActivated() override; 404 | void OnInternalHookDeactivated() override; 405 | 406 | private: 407 | int m_iHookID; 408 | }; 409 | 410 | class ClientConnectPreHook : public ClientConnectHook 411 | { 412 | typedef ClientConnectHook BaseClass; 413 | 414 | public: 415 | ClientConnectPreHook(); 416 | 417 | private: // CBaseHook 418 | void Init() override; 419 | 420 | private: // ClientConnectHook 421 | int ManualHook() override; 422 | 423 | private: 424 | IClient* Handler(const ns_address& adr, int protocol, int challenge, int authProtocol, const char* name, const char* password, const char* hashedCDkey, int cdKeyLen, CUtlVector& splitScreenClients, bool isClientLowViolence, CrossPlayPlatform_t clientPlatform, const byte* pbEncryptionKey, int nEncryptionKeyIndex); 425 | 426 | const char* GetHookName() override { return "ClientConnectPre"; } 427 | 428 | private: 429 | int m_iRejectConnectionOffset; 430 | } m_ClientConnectPreHook; 431 | 432 | class ClientConnectPostHook : public ClientConnectHook 433 | { 434 | typedef ClientConnectHook BaseClass; 435 | 436 | public: 437 | ClientConnectPostHook(); 438 | 439 | private: // CBaseHook 440 | void Init() override; 441 | 442 | private: // ClientConnectHook 443 | int ManualHook() override; 444 | 445 | private: 446 | IClient* Handler(const ns_address& adr, int protocol, int challenge, int authProtocol, const char* name, const char* password, const char* hashedCDkey, int cdKeyLen, CUtlVector& splitScreenClients, bool isClientLowViolence, CrossPlayPlatform_t clientPlatform, const byte* pbEncryptionKey, int nEncryptionKeyIndex); 447 | 448 | const char* GetHookName() override { return "ClientConnectPost"; } 449 | } m_ClientConnectPostHook; 450 | 451 | ///////////////////////////////// 452 | 453 | class InventoryUpdatePostHook : public CBaseVPHook 454 | { 455 | typedef CBaseVPHook BaseClass; 456 | 457 | public: 458 | InventoryUpdatePostHook(); 459 | 460 | private: // CBaseHook 461 | void Init() override; 462 | 463 | private: // CBaseVPHook 464 | int VPHook(int iClient) override; 465 | 466 | private: 467 | void Handler(); 468 | } m_InventoryUpdatePostHook; 469 | 470 | ///////////////////////////////// 471 | 472 | private: 473 | static std::map m_Hooks; 474 | }; 475 | 476 | extern CForwardManager g_ForwardManager; 477 | 478 | #endif // _INCLUDE_SOURCEMOD_EXTENSION_FORWARDS_H_ 479 | -------------------------------------------------------------------------------- /classes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 : 3 | * ============================================================================= 4 | * SourceMod P Tools and Hooks Extension 5 | * Copyright (C) 2016-2023 Phoenix (˙·٠●Феникс●٠·˙). All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | */ 20 | 21 | #ifndef _INCLUDE_SOURCEMOD_EXTENSION_CLASSES_H_ 22 | #define _INCLUDE_SOURCEMOD_EXTENSION_CLASSES_H_ 23 | 24 | #include "utlhashmaplarge.h" 25 | #include "netmessages.pb.h" 26 | #include "inetchannelinfo.h" 27 | #include "igameevents.h" 28 | #include "steamtypes.h" 29 | 30 | typedef CBaseEntity CBaseCombatWeapon; 31 | class CAttribute_String; 32 | class stickerMaterialReference_t; 33 | enum eEconItemOrigin { }; 34 | enum EAssetClassAttrExportRule_t { }; 35 | enum attrib_effect_types_t { }; 36 | 37 | enum EStickerAttributeType 38 | { 39 | EStickerAttribute_ID, 40 | EStickerAttribute_Wear, 41 | EStickerAttribute_Scale, 42 | EStickerAttribute_Rotation 43 | }; 44 | 45 | enum ESchemaAttributeType 46 | { 47 | ESchemaAttribute_Unknown = -1, 48 | ESchemaAttribute_Uint32, 49 | ESchemaAttribute_Float, 50 | ESchemaAttribute_String, 51 | ESchemaAttribute_Vector 52 | }; 53 | 54 | class ISchemaAttributeType 55 | { 56 | protected: 57 | virtual ~ISchemaAttributeType() = 0; 58 | }; 59 | 60 | template class ISchemaAttributeTypeBase : public ISchemaAttributeType {}; 61 | template class CSchemaAttributeTypeBase : public ISchemaAttributeTypeBase {}; 62 | template class CSchemaAttributeTypeProtobufBase : public CSchemaAttributeTypeBase {}; 63 | 64 | class CSchemaAttributeType_Default : public CSchemaAttributeTypeBase {}; 65 | class CSchemaAttributeType_Uint32 : public CSchemaAttributeTypeBase {}; 66 | class CSchemaAttributeType_Float : public CSchemaAttributeTypeBase {}; 67 | class CSchemaAttributeType_String : public CSchemaAttributeTypeProtobufBase {}; 68 | class CSchemaAttributeType_Vector : public CSchemaAttributeTypeBase {}; 69 | 70 | class CEconItemAttributeDefinition 71 | { 72 | public: 73 | virtual uint16 GetDefinitionIndex() const = 0; 74 | virtual const char* GetDefinitionName() const = 0; 75 | virtual const char* GetDescriptionString() const = 0; 76 | virtual const char* GetAttributeClass() const = 0; 77 | virtual const KeyValues* GetRawDefinition() const = 0; 78 | 79 | uint16 GetDefinitionIndex() { return m_nDefIndex; } 80 | const char* GetDefinitionName() { return m_pszDefinitionName; } 81 | bool IsStoredAsInteger() { return m_bStoredAsInteger; } 82 | bool IsStoredAsFloat() { return !m_bStoredAsInteger; } 83 | 84 | template bool IsAttributeType() 85 | { 86 | return (dynamic_cast(this->m_pAttrType) != nullptr); 87 | } 88 | 89 | ESchemaAttributeType GetAttributeType(); 90 | 91 | KeyValues* m_pKVAttribute; //4 92 | uint16 m_nDefIndex; //8 93 | ISchemaAttributeType* m_pAttrType; //12 94 | bool m_bHidden; //16 95 | bool m_bWebSchemaOutputForced; //17 96 | bool m_bStoredAsInteger; //18 97 | bool m_bInstanceData; //19 98 | EAssetClassAttrExportRule_t m_eAssetClassAttrExportRule; //20 99 | uint32 m_unAssetClassBucket; //24 100 | attrib_effect_types_t m_iEffectType; //28 101 | int m_iDescriptionFormat; //32 102 | const char* m_pszDescriptionString; //36 103 | const char* m_pszDescriptionTag; //40 104 | const char* m_pszArmoryDesc; //44 105 | int m_iScore; //48 106 | const char* m_pszDefinitionName; //52 107 | const char* m_pszAttributeClass; //56 108 | mutable string_t m_iszAttributeClass; //60 109 | }; 110 | 111 | class CEconItemDefinition 112 | { 113 | public: 114 | uint16 GetDefinitionIndex() { return m_nDefIndex; } 115 | int GetLoadoutSlot(int iTeam); 116 | int GetUsedByTeam(); 117 | int GetNumSupportedStickerSlots(); 118 | const char* GetInventoryImage(); 119 | const char* GetBasePlayerDisplayModel(); 120 | const char* GetWorldDisplayModel(); 121 | const char* GetWorldDroppedModel(); 122 | const char* GetDefinitionName(); 123 | 124 | private: 125 | void* m_pVTable; //0 126 | public: 127 | KeyValues* m_pKVItem; //4 128 | uint16 m_nDefIndex; //8 129 | }; 130 | 131 | class CEconItemSchema 132 | { 133 | public: 134 | static CEconItemSchema* GetEconItemSchema(); 135 | 136 | CUtlHashMapLarge* GetItemDefinitionMap(); 137 | CUtlVector* GetAttributeDefinitionContainer(); 138 | 139 | CEconItemDefinition* GetItemDefinitionByName(const char* pszDefName); 140 | CEconItemDefinition* GetItemDefinitionByDefIndex(uint16_t iItemIndex); 141 | CEconItemAttributeDefinition* GetAttributeDefinitionByName(const char* pszDefName); 142 | CEconItemAttributeDefinition* GetAttributeDefinitionByDefIndex(uint16_t iDefIndex); 143 | }; 144 | 145 | class IEconItemAttributeIterator 146 | { 147 | public: 148 | virtual ~IEconItemAttributeIterator() { }; 149 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, unsigned int) = 0; 150 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, float) = 0; 151 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, CAttribute_String const&) = 0; 152 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, Vector const&) = 0; 153 | }; 154 | 155 | class CEconItemAttribute 156 | { 157 | DECLARE_CLASS_NOBASE(CEconItemAttribute); 158 | 159 | CEconItemAttribute(); 160 | 161 | public: 162 | DECLARE_EMBEDDED_NETWORKVAR(); 163 | 164 | CEconItemAttribute(const uint16 iAttributeIndex, uint32 unValue); 165 | CEconItemAttribute(const uint16 iAttributeIndex, float fValue); 166 | 167 | // This is the index of the attribute into the attributes read from the data files 168 | CNetworkVar(uint16, m_iAttributeDefinitionIndex); 169 | 170 | // This is the value of the attribute. Used to modify the item's variables. 171 | CNetworkVar(float, m_flValue); 172 | 173 | // This is the value that the attribute was first set to by an item definition 174 | CNetworkVar(float, m_flInitialValue); 175 | CNetworkVar(int, m_nRefundableCurrency); 176 | 177 | CNetworkVar(bool, m_bSetBonus); // Attribute has been generated by a set bonus. 178 | }; 179 | static_assert(sizeof(CEconItemAttribute) == 24, "CEconItemAttribute - incorrect size on this compiler"); 180 | 181 | class CAttributeList 182 | { 183 | public: 184 | void DestroyAllAttributes() { m_Attributes.Purge(); } 185 | void AddAttribute(CEconItemAttribute& pAttribute) { m_Attributes.AddToTail(pAttribute); } 186 | void RemoveAttribute(int iIndex) { m_Attributes.Remove(iIndex); } 187 | void RemoveAttributeByDefIndex(uint16_t unAttrDefIndex); 188 | void SetOrAddAttributeValue(uint16_t unAttrDefIndex, uint32_t unValue); 189 | int GetNumAttributes() { return m_Attributes.Count(); } 190 | CEconItemAttribute& GetAttribute(int iIndex) { return m_Attributes[iIndex]; } 191 | CEconItemAttribute* GetAttributeByDefIndex(uint16_t unAttrDefIndex); 192 | 193 | private: 194 | void* m_pVTable; //0 195 | CUtlVector m_Attributes; //4 (20) 196 | void* m_pAttributeManager; //24 197 | }; 198 | 199 | #pragma pack(push, 4) 200 | class CEconItemView 201 | { 202 | virtual ~CEconItemView() = 0; 203 | public: 204 | virtual int GetCustomPaintKitIndex() const = 0; 205 | virtual int GetCustomPaintKitSeed() const = 0; 206 | virtual float GetCustomPaintKitWear(float flWearDefault = 0.0f) const = 0; 207 | virtual float GetStickerAttributeBySlotIndexFloat(int nSlotIndex, EStickerAttributeType type, float flDefault) const = 0; 208 | virtual uint32 GetStickerAttributeBySlotIndexInt(int nSlotIndex, EStickerAttributeType type, uint32 uiDefault) const = 0; 209 | virtual bool IsTradable() const = 0; 210 | virtual bool IsMarketable() const = 0; 211 | virtual bool IsCommodity() const = 0; 212 | virtual bool IsUsableInCrafting() const = 0; 213 | virtual bool IsHiddenFromDropList() const = 0; 214 | virtual RTime32 GetExpirationDate() const = 0; 215 | virtual CEconItemDefinition* GetItemDefinition() const = 0; 216 | virtual uint32 GetAccountID() const = 0; 217 | virtual uint64 GetItemID() const = 0; 218 | virtual int32 GetQuality() const = 0; 219 | virtual int32 GetRarity() const = 0; 220 | virtual uint8 GetFlags() const = 0; 221 | virtual eEconItemOrigin GetOrigin() const = 0; 222 | virtual uint16 GetQuantity() const = 0; 223 | virtual uint32 GetItemLevel() const = 0; 224 | virtual bool GetInUse() const = 0; 225 | virtual const char* GetCustomName() const = 0; 226 | virtual const char* GetCustomDesc() const = 0; 227 | virtual int GetItemSetIndex() const = 0; 228 | virtual void IterateAttributes(IEconItemAttributeIterator* pIterator) const = 0; 229 | 230 | uint32 GetAccountID() { return m_iAccountID; } 231 | uint64 GetItemID() { return m_iItemID; } 232 | int GetKillEaterValue(); 233 | 234 | private: 235 | bool m_bKillEaterTypesCached; //4 236 | void* m_vCachedKillEaterTypes[7]; //8 (28) 237 | int m_nKillEaterValuesCacheFrame; //36 238 | void* m_vCachedKillEaterValues[6]; //40 (24) 239 | CUtlVector m_pStickerMaterials; //64 (20) 240 | 241 | public: 242 | uint16 m_iDefinitionIndex; //84 243 | int m_iEntityQuality; //88 244 | uint32 m_iEntityLevel; //92 245 | uint64 m_iItemID; //96 246 | uint32 m_iItemIDHigh; //104 247 | uint32 m_iItemIDLow; //108 248 | uint32 m_iAccountID; //112 249 | uint32 m_iInventoryPosition; //116 250 | void* m_pNonSOEconItem; //120 251 | bool m_bInitialized; //124 252 | 253 | CAttributeList m_AttributeList; //128 (28) 254 | CAttributeList m_NetworkedDynamicAttributesForDemos; //156 (28) 255 | 256 | char m_szCustomName[161]; //184 257 | char m_szCustomNameOverride[161]; //345 258 | void* m_autoptrInventoryImageGeneratedPath; //508 259 | }; 260 | static_assert(sizeof(CEconItemView) == 512, "CEconItemView - incorrect size on this compiler"); 261 | #pragma pack(pop) 262 | 263 | class IEconItemUntypedAttributeIterator : public IEconItemAttributeIterator 264 | { 265 | public: 266 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, unsigned int); 267 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, float); 268 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, CAttribute_String const&); 269 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, Vector const&); 270 | virtual bool OnIterateAttributeValueUntyped(CEconItemAttributeDefinition const*) = 0; 271 | }; 272 | 273 | class CAttributeIterator_HasAttribute : public IEconItemUntypedAttributeIterator 274 | { 275 | public: 276 | CAttributeIterator_HasAttribute(CEconItemAttributeDefinition const*); 277 | virtual bool OnIterateAttributeValueUntyped(CEconItemAttributeDefinition const*); 278 | 279 | CEconItemAttributeDefinition const* m_pItemAttrDef; 280 | bool m_found; 281 | }; 282 | 283 | class CAttributeIterator_GetTypedAttributeValueBase : public IEconItemAttributeIterator 284 | { 285 | public: 286 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, unsigned int) { return true; } 287 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, float) { return true; } 288 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, CAttribute_String const&) { return true; } 289 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const*, Vector const&) { return true; } 290 | }; 291 | 292 | template 293 | class CAttributeIterator_GetTypedAttributeValue : public CAttributeIterator_GetTypedAttributeValueBase 294 | { 295 | public: 296 | CAttributeIterator_GetTypedAttributeValue(CEconItemAttributeDefinition const* pItemAttrDef, B* value) 297 | : m_pItemAttrDef(pItemAttrDef), m_value(value), m_found(false) 298 | { 299 | } 300 | virtual bool OnIterateAttributeValue(CEconItemAttributeDefinition const* pItemAttrDef, A value) 301 | { 302 | if (m_pItemAttrDef == pItemAttrDef) 303 | { 304 | m_found = true; 305 | *m_value = (B)value; 306 | } 307 | 308 | return !m_found; 309 | } 310 | 311 | CEconItemAttributeDefinition const* m_pItemAttrDef; 312 | B* m_value; 313 | bool m_found; 314 | }; 315 | 316 | class CPlayerVoiceListener 317 | { 318 | public: 319 | static CPlayerVoiceListener* GetPlayerVoiceListener(); 320 | 321 | bool IsPlayerSpeaking(int iClient); 322 | 323 | private: 324 | void* m_pVTable; // 0 325 | 326 | private: // CAutoGameSystem 327 | void* m_pNext; // 4 328 | char const* m_pszName; // 8 329 | 330 | private: 331 | // Should be 65, but Valve made a mistake :( 332 | float m_flLastPlayerSpeechTime[64]; // 12 333 | float m_flPlayerSpeechDuration[64]; // 268 334 | }; 335 | 336 | class CBaseClient : public IGameEventListener2, public IClient 337 | { 338 | public: 339 | virtual ~CBaseClient() = 0; 340 | }; 341 | 342 | class CClientFrameManager 343 | { 344 | public: 345 | virtual ~CClientFrameManager() = 0; 346 | }; 347 | 348 | class CGameClient : public CBaseClient, public CClientFrameManager 349 | { 350 | }; 351 | 352 | class CCSPlayerInventory 353 | { 354 | static intptr_t GetInventoryOffset(); 355 | public: 356 | static CCSPlayerInventory* FromPlayer(CBaseEntity* pPlayer); 357 | CBaseEntity* ToPlayer(); 358 | 359 | CEconItemView* GetItemInLoadout(int iTeam, int iLoadoutSlot); 360 | CUtlVector* GetItemVector(); 361 | }; 362 | 363 | template 364 | class CNetMessagePB : public INetMessage, public NetMessage 365 | { 366 | public: 367 | ~CNetMessagePB() {} 368 | }; 369 | 370 | typedef CNetMessagePB<16, CCLCMsg_SplitPlayerConnect, 0, true> CCLCMsg_SplitPlayerConnect_t; 371 | 372 | class CNetMessagePB_PlayerAvatarData : public INetMessage, public CNETMsg_PlayerAvatarData 373 | { 374 | public: 375 | CNetMessagePB_PlayerAvatarData() { } 376 | 377 | virtual bool ReadFromBuffer(bf_read& buffer) { return false; } 378 | virtual bool WriteToBuffer(bf_write& buffer) const; 379 | virtual const char* ToString() const; 380 | virtual int GetType() const { return net_PlayerAvatarData; } 381 | virtual size_t GetSize() const { return sizeof(*this); } 382 | virtual const char* GetName() const { return "CNETMsg_PlayerAvatarData"; }; 383 | virtual int GetGroup() const { return INetChannelInfo::PAINTMAP; } 384 | virtual void SetReliable(bool state) { } 385 | virtual bool IsReliable() const { return true; } 386 | virtual INetMessage* Clone() const { return nullptr; } 387 | virtual void SetNetChannel(INetChannel* netchan) { } 388 | virtual INetChannel* GetNetChannel(void) const { return nullptr; } 389 | virtual bool Process() { return false; } 390 | 391 | protected: 392 | mutable std::string m_toString; 393 | }; 394 | 395 | extern CEconItemSchema* g_pCEconItemSchema; 396 | extern CPlayerVoiceListener* g_pCPlayerVoiceListener; 397 | 398 | #endif // _INCLUDE_SOURCEMOD_EXTENSION_CLASSES_H_ -------------------------------------------------------------------------------- /classes.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 : 3 | * ============================================================================= 4 | * SourceMod P Tools and Hooks Extension 5 | * Copyright (C) 2016-2023 Phoenix (˙·٠●Феникс●٠·˙). All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | */ 20 | 21 | #include "extension.h" 22 | #include "classes.h" 23 | 24 | 25 | CEconItemSchema* CEconItemSchema::GetEconItemSchema() 26 | { 27 | //Called once, no static needed 28 | uintptr_t (*GetItemSchema)(void); 29 | 30 | if (!g_pGameConf[GameConf_CSST]->GetMemSig("GetItemSchema", reinterpret_cast(&GetItemSchema)) || !GetItemSchema) 31 | { 32 | smutils->LogError(myself, "Failed to get GetItemSchema function."); 33 | 34 | return nullptr; 35 | } 36 | 37 | return reinterpret_cast(GetItemSchema() + WIN_LINUX(sizeof(void*), 0x0)); 38 | }; 39 | 40 | CUtlHashMapLarge* CEconItemSchema::GetItemDefinitionMap() 41 | { 42 | static int offset = -1; 43 | 44 | if (offset == -1) 45 | { 46 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CEconItemSchema::m_mapItems", &offset)) 47 | { 48 | smutils->LogError(myself, "Failed to get CEconItemSchema::m_mapItems offset."); 49 | 50 | return nullptr; 51 | } 52 | } 53 | 54 | return reinterpret_cast*>(reinterpret_cast(this) + offset); 55 | } 56 | 57 | CUtlVector* CEconItemSchema::GetAttributeDefinitionContainer() 58 | { 59 | static int offset = -1; 60 | 61 | if (offset == -1) 62 | { 63 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CEconItemSchema::m_mapAttributesContainer", &offset)) 64 | { 65 | smutils->LogError(myself, "Failed to get CEconItemSchema::m_mapAttributesContainer offset."); 66 | 67 | return nullptr; 68 | } 69 | } 70 | 71 | return reinterpret_cast*>(reinterpret_cast(this) + offset); 72 | } 73 | 74 | CEconItemDefinition* CEconItemSchema::GetItemDefinitionByName(const char* pszDefName) 75 | { 76 | auto pMapItemDef = GetItemDefinitionMap(); 77 | 78 | if (pMapItemDef) 79 | { 80 | FOR_EACH_MAP_FAST(*pMapItemDef, i) 81 | { 82 | if (!strcmp(pszDefName, pMapItemDef->Element(i)->GetDefinitionName())) 83 | { 84 | return pMapItemDef->Element(i); 85 | } 86 | } 87 | } 88 | 89 | return nullptr; 90 | } 91 | 92 | CEconItemDefinition* CEconItemSchema::GetItemDefinitionByDefIndex(uint16_t iItemIndex) 93 | { 94 | auto pMapItemDef = GetItemDefinitionMap(); 95 | 96 | if (pMapItemDef) 97 | { 98 | int iIndex = pMapItemDef->Find(iItemIndex); 99 | 100 | if (pMapItemDef->IsValidIndex(iIndex)) 101 | { 102 | return pMapItemDef->Element(iIndex); 103 | } 104 | } 105 | 106 | return nullptr; 107 | } 108 | 109 | CEconItemAttributeDefinition* CEconItemSchema::GetAttributeDefinitionByName(const char* pszDefName) 110 | { 111 | auto pAttributesContainer = GetAttributeDefinitionContainer(); 112 | 113 | if (pAttributesContainer) 114 | { 115 | FOR_EACH_VEC(*pAttributesContainer, i) 116 | { 117 | CEconItemAttributeDefinition* pItemAttributeDefinition = pAttributesContainer->Element(i); 118 | 119 | if (pItemAttributeDefinition && !strcmp(pszDefName, pItemAttributeDefinition->GetDefinitionName())) 120 | { 121 | return pItemAttributeDefinition; 122 | } 123 | } 124 | } 125 | 126 | return nullptr; 127 | } 128 | 129 | CEconItemAttributeDefinition* CEconItemSchema::GetAttributeDefinitionByDefIndex(uint16_t iDefIndex) 130 | { 131 | auto pAttributesContainer = GetAttributeDefinitionContainer(); 132 | 133 | if (pAttributesContainer) 134 | { 135 | if (pAttributesContainer->IsValidIndex(iDefIndex)) 136 | { 137 | return pAttributesContainer->Element(iDefIndex); 138 | } 139 | } 140 | 141 | return nullptr; 142 | } 143 | 144 | ESchemaAttributeType CEconItemAttributeDefinition::GetAttributeType() 145 | { 146 | if (IsAttributeType()) 147 | { 148 | if (IsStoredAsInteger()) 149 | { 150 | return ESchemaAttribute_Uint32; 151 | } 152 | 153 | return ESchemaAttribute_Float; 154 | } 155 | 156 | if (IsAttributeType()) 157 | { 158 | return ESchemaAttribute_Uint32; 159 | } 160 | 161 | if (IsAttributeType()) 162 | { 163 | return ESchemaAttribute_Float; 164 | } 165 | 166 | if (IsAttributeType()) 167 | { 168 | return ESchemaAttribute_String; 169 | } 170 | 171 | if (IsAttributeType()) 172 | { 173 | return ESchemaAttribute_Vector; 174 | } 175 | 176 | return ESchemaAttribute_Unknown; 177 | } 178 | 179 | int CEconItemDefinition::GetLoadoutSlot(int iTeam) 180 | { 181 | static int (WIN_LINUX(__thiscall, __cdecl)* GetLoadoutSlot)(void*, int) = nullptr; 182 | 183 | if (GetLoadoutSlot == nullptr) 184 | { 185 | if (!g_pGameConf[GameConf_PTaH]->GetMemSig("CCStrike15ItemDefinition::GetLoadoutSlot", reinterpret_cast(&GetLoadoutSlot)) || !GetLoadoutSlot) 186 | { 187 | smutils->LogError(myself, "Failed to get CCStrike15ItemDefinition::GetLoadoutSlot function."); 188 | 189 | return -1; 190 | } 191 | } 192 | 193 | return GetLoadoutSlot(this, iTeam); 194 | } 195 | 196 | int CEconItemDefinition::GetUsedByTeam() 197 | { 198 | static int offset = -1; 199 | 200 | if (offset == -1) 201 | { 202 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CCStrike15ItemDefinition::m_vbClassUsability", &offset)) 203 | { 204 | smutils->LogError(myself, "Failed to get CCStrike15ItemDefinition::m_vbClassUsability offset."); 205 | 206 | return -1; 207 | } 208 | } 209 | 210 | CBitVec<4>* pClassUsability = reinterpret_cast*>(reinterpret_cast(this) + offset); 211 | 212 | if (pClassUsability->IsBitSet(2) && pClassUsability->IsBitSet(3)) 213 | { 214 | return 0; 215 | } 216 | 217 | if (pClassUsability->IsBitSet(3)) 218 | { 219 | return 3; 220 | } 221 | 222 | if (pClassUsability->IsBitSet(2)) 223 | { 224 | return 2; 225 | } 226 | 227 | return 0; 228 | } 229 | 230 | int CEconItemDefinition::GetNumSupportedStickerSlots() 231 | { 232 | static int offset = -1; 233 | 234 | if (offset == -1) 235 | { 236 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CEconItemDefinition::GetNumSupportedStickerSlots", &offset)) 237 | { 238 | smutils->LogError(myself, "Failed to get CEconItemDefinition::GetNumSupportedStickerSlots offset."); 239 | 240 | return -1; 241 | } 242 | } 243 | 244 | return CallVFunc(offset, this); 245 | } 246 | 247 | const char* CEconItemDefinition::GetInventoryImage() 248 | { 249 | static int offset = -1; 250 | 251 | if (offset == -1) 252 | { 253 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CEconItemDefinition::GetInventoryImage", &offset)) 254 | { 255 | smutils->LogError(myself, "Failed to get CEconItemDefinition::GetInventoryImage offset."); 256 | 257 | return nullptr; 258 | } 259 | } 260 | 261 | return CallVFunc(offset, this); 262 | } 263 | 264 | const char* CEconItemDefinition::GetBasePlayerDisplayModel() 265 | { 266 | static int offset = -1; 267 | 268 | if (offset == -1) 269 | { 270 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CEconItemDefinition::GetBasePlayerDisplayModel", &offset)) 271 | { 272 | smutils->LogError(myself, "Failed to get CEconItemDefinition::GetBasePlayerDisplayModel offset."); 273 | 274 | return nullptr; 275 | } 276 | } 277 | 278 | return CallVFunc(offset, this); 279 | } 280 | 281 | const char* CEconItemDefinition::GetWorldDisplayModel() 282 | { 283 | static int offset = -1; 284 | 285 | if (offset == -1) 286 | { 287 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CEconItemDefinition::GetWorldDisplayModel", &offset)) 288 | { 289 | smutils->LogError(myself, "Failed to get CEconItemDefinition::GetWorldDisplayModel offset."); 290 | 291 | return nullptr; 292 | } 293 | } 294 | 295 | return CallVFunc(offset, this); 296 | } 297 | 298 | const char* CEconItemDefinition::GetWorldDroppedModel() 299 | { 300 | static int offset = -1; 301 | 302 | if (offset == -1) 303 | { 304 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CEconItemDefinition::GetWorldDroppedModel", &offset)) 305 | { 306 | smutils->LogError(myself, "Failed to get CEconItemDefinition::GetWorldDroppedModel offset."); 307 | 308 | return nullptr; 309 | } 310 | } 311 | 312 | return CallVFunc(offset, this); 313 | } 314 | 315 | const char* CEconItemDefinition::GetDefinitionName() 316 | { 317 | static int offset = -1; 318 | 319 | if (offset == -1) 320 | { 321 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CEconItemDefinition::m_pszDefinitionName", &offset)) 322 | { 323 | smutils->LogError(myself, "Failed to get CEconItemDefinition::m_pszDefinitionName offset."); 324 | 325 | return nullptr; 326 | } 327 | } 328 | 329 | return *reinterpret_cast(reinterpret_cast(this) + offset); 330 | } 331 | 332 | // Thank you Kailo 333 | int CEconItemView::GetKillEaterValue() 334 | { 335 | if (g_pCEconItemSchema) 336 | { 337 | CEconItemAttributeDefinition* pItemAttrDef = g_pCEconItemSchema->GetAttributeDefinitionByDefIndex(80); //"kill eater" 338 | unsigned int KillEaterValue; 339 | 340 | CAttributeIterator_GetTypedAttributeValue it(pItemAttrDef, &KillEaterValue); 341 | this->IterateAttributes(&it); 342 | 343 | if (it.m_found) return KillEaterValue; 344 | } 345 | else smutils->LogError(myself, "g_pCEconItemSchema == nullptr."); 346 | 347 | return -1; 348 | } 349 | 350 | CPlayerVoiceListener* CPlayerVoiceListener::GetPlayerVoiceListener() 351 | { 352 | void* addr = nullptr; 353 | 354 | if (!g_pGameConf[GameConf_PTaH]->GetAddress("g_CPlayerVoiceListener", &addr) || !addr) 355 | { 356 | smutils->LogError(myself, "Failed to get g_CPlayerVoiceListener address."); 357 | } 358 | 359 | return reinterpret_cast(addr); 360 | } 361 | 362 | bool CPlayerVoiceListener::IsPlayerSpeaking(int iClient) 363 | { 364 | return (m_flLastPlayerSpeechTime[iClient] + 0.5f) >= gpGlobals->curtime; 365 | } 366 | 367 | intptr_t CCSPlayerInventory::GetInventoryOffset() 368 | { 369 | static intptr_t iInventoryOffset = -1; 370 | 371 | if (iInventoryOffset == -1) 372 | { 373 | void* addr = nullptr; 374 | 375 | if (!g_pGameConf[GameConf_CSST]->GetOffset("CCSPlayerInventoryOffset", &iInventoryOffset)) 376 | { 377 | smutils->LogError(myself, "Failed to get CCSPlayerInventoryOffset offset."); 378 | 379 | return -1; 380 | } 381 | 382 | if (!g_pGameConf[GameConf_CSST]->GetMemSig("HandleCommand_Buy_Internal", &addr) || !addr) 383 | { 384 | smutils->LogError(myself, "Failed to get HandleCommand_Buy_Internal address."); 385 | 386 | return -1; 387 | } 388 | 389 | iInventoryOffset = *reinterpret_cast(reinterpret_cast(addr) + iInventoryOffset); 390 | } 391 | 392 | return iInventoryOffset; 393 | } 394 | 395 | CCSPlayerInventory* CCSPlayerInventory::FromPlayer(CBaseEntity* pPlayer) 396 | { 397 | int offset = GetInventoryOffset(); 398 | 399 | if (offset == -1) 400 | { 401 | return nullptr; 402 | } 403 | 404 | return reinterpret_cast(reinterpret_cast(pPlayer) + offset); 405 | } 406 | 407 | CBaseEntity* CCSPlayerInventory::ToPlayer() 408 | { 409 | int offset = GetInventoryOffset(); 410 | 411 | if (offset == -1) 412 | { 413 | return nullptr; 414 | } 415 | 416 | return reinterpret_cast(reinterpret_cast(this) - offset); 417 | } 418 | 419 | CEconItemView* CCSPlayerInventory::GetItemInLoadout(int iTeam, int iLoadoutSlot) 420 | { 421 | static int offset = -1; 422 | 423 | if (offset == -1) 424 | { 425 | if (!g_pGameConf[GameConf_CSST]->GetOffset("GetItemInLoadout", &offset)) 426 | { 427 | smutils->LogError(myself, "Failed to get GetItemInLoadout offset."); 428 | 429 | return nullptr; 430 | } 431 | } 432 | 433 | return CallVFunc(offset, this, iTeam, iLoadoutSlot); 434 | } 435 | 436 | CUtlVector* CCSPlayerInventory::GetItemVector() 437 | { 438 | static int offset = -1; 439 | 440 | if (offset == -1) 441 | { 442 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CPlayerInventory::m_vecInventoryItems", &offset)) 443 | { 444 | smutils->LogError(myself, "Failed to get CPlayerInventory::m_vecInventoryItems offset."); 445 | 446 | return nullptr; 447 | } 448 | } 449 | 450 | return reinterpret_cast*>(reinterpret_cast(this) + offset); 451 | } 452 | 453 | CEconItemAttribute::CEconItemAttribute() 454 | { 455 | m_iAttributeDefinitionIndex = 0; 456 | m_flValue = 0.f; 457 | m_flInitialValue = 0.f; 458 | m_nRefundableCurrency = 0; 459 | m_bSetBonus = false; 460 | }; 461 | 462 | CEconItemAttribute::CEconItemAttribute(const uint16 iAttributeIndex, uint32 unValue) 463 | { 464 | CEconItemAttribute(); 465 | 466 | m_iAttributeDefinitionIndex = iAttributeIndex; 467 | 468 | m_flValue = *reinterpret_cast(&unValue); 469 | m_flInitialValue = m_flValue; 470 | }; 471 | 472 | CEconItemAttribute::CEconItemAttribute(const uint16 iAttributeIndex, float fValue) 473 | { 474 | CEconItemAttribute(); 475 | 476 | m_iAttributeDefinitionIndex = iAttributeIndex; 477 | m_flValue = fValue; 478 | m_flInitialValue = m_flValue; 479 | }; 480 | 481 | void CAttributeList::RemoveAttributeByDefIndex(uint16_t unAttrDefIndex) 482 | { 483 | FOR_EACH_VEC(m_Attributes, i) 484 | { 485 | if (m_Attributes[i].m_iAttributeDefinitionIndex == unAttrDefIndex) 486 | { 487 | m_Attributes.Remove(i); 488 | 489 | return; 490 | } 491 | } 492 | } 493 | 494 | void CAttributeList::SetOrAddAttributeValue(uint16_t unAttrDefIndex, uint32_t unValue) 495 | { 496 | CEconItemAttribute* pAttribute = GetAttributeByDefIndex(unAttrDefIndex); 497 | 498 | if (pAttribute) 499 | { 500 | pAttribute->m_flValue = *reinterpret_cast(&unValue); 501 | } 502 | else 503 | { 504 | CEconItemAttribute attribute(unAttrDefIndex, unValue); 505 | 506 | AddAttribute(attribute); 507 | } 508 | } 509 | 510 | CEconItemAttribute* CAttributeList::GetAttributeByDefIndex(uint16_t unAttrDefIndex) 511 | { 512 | FOR_EACH_VEC(m_Attributes, i) 513 | { 514 | if (m_Attributes[i].m_iAttributeDefinitionIndex == unAttrDefIndex) 515 | { 516 | return &m_Attributes[i]; 517 | } 518 | } 519 | 520 | return nullptr; 521 | } 522 | 523 | bool CNetMessagePB_PlayerAvatarData::WriteToBuffer(bf_write& buffer) const 524 | { 525 | int size = ByteSize(); 526 | 527 | void* serializeBuffer = stackalloc(size); 528 | 529 | if (!SerializeWithCachedSizesToArray((google::protobuf::uint8*)serializeBuffer)) 530 | { 531 | return false; 532 | } 533 | 534 | buffer.WriteVarInt32(GetType()); 535 | buffer.WriteVarInt32(size); 536 | 537 | return buffer.WriteBytes(serializeBuffer, size); 538 | } 539 | 540 | const char* CNetMessagePB_PlayerAvatarData::ToString() const 541 | { 542 | m_toString = DebugString(); 543 | 544 | return m_toString.c_str(); 545 | } 546 | -------------------------------------------------------------------------------- /AMBuildScript: -------------------------------------------------------------------------------- 1 | # vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: 2 | import os, sys 3 | 4 | # Simple extensions do not need to modify this file. 5 | 6 | class SDK(object): 7 | def __init__(self, sdk, ext, aDef, name, platform, dir): 8 | self.folder = 'hl2sdk-' + dir 9 | self.envvar = sdk 10 | self.ext = ext 11 | self.code = aDef 12 | self.define = name 13 | self.platform = platform 14 | self.name = dir 15 | self.path = None # Actual path 16 | 17 | WinOnly = ['windows'] 18 | WinLinux = ['windows', 'linux'] 19 | 20 | PossibleSDKs = { 21 | 'episode1': SDK('HL2SDK', '1.ep1', '1', 'EPISODEONE', WinLinux, 'episode1'), 22 | 'ep2': SDK('HL2SDKOB', '2.ep2', '3', 'ORANGEBOX', WinLinux, 'orangebox'), 23 | 'css': SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinux, 'css'), 24 | 'hl2dm': SDK('HL2SDKHL2DM', '2.hl2dm', '7', 'HL2DM', WinLinux, 'hl2dm'), 25 | 'dods': SDK('HL2SDKDODS', '2.dods', '8', 'DODS', WinLinux, 'dods'), 26 | 'sdk2013': SDK('HL2SDK2013', '2.sdk2013', '9', 'SDK2013', WinLinux, 'sdk2013'), 27 | 'tf2': SDK('HL2SDKTF2', '2.tf2', '11', 'TF2', WinLinux, 'tf2'), 28 | 'l4d': SDK('HL2SDKL4D', '2.l4d', '12', 'LEFT4DEAD', WinLinux, 'l4d'), 29 | 'nucleardawn': SDK('HL2SDKND', '2.nd', '13', 'NUCLEARDAWN', WinLinux, 'nucleardawn'), 30 | 'l4d2': SDK('HL2SDKL4D2', '2.l4d2', '15', 'LEFT4DEAD2', WinLinux, 'l4d2'), 31 | 'darkm': SDK('HL2SDK-DARKM', '2.darkm', '2', 'DARKMESSIAH', WinOnly, 'darkm'), 32 | 'swarm': SDK('HL2SDK-SWARM', '2.swarm', '16', 'ALIENSWARM', WinOnly, 'swarm'), 33 | 'bgt': SDK('HL2SDK-BGT', '2.bgt', '4', 'BLOODYGOODTIME', WinOnly, 'bgt'), 34 | 'eye': SDK('HL2SDK-EYE', '2.eye', '5', 'EYE', WinOnly, 'eye'), 35 | 'csgo': SDK('HL2SDKCSGO', '2.csgo', '20', 'CSGO', WinLinux, 'csgo'), 36 | 'dota': SDK('HL2SDKDOTA', '2.dota', '21', 'DOTA', [], 'dota'), 37 | 'portal2': SDK('HL2SDKPORTAL2', '2.portal2', '17', 'PORTAL2', [], 'portal2'), 38 | 'blade': SDK('HL2SDKBLADE', '2.blade', '18', 'BLADE', WinLinux, 'blade'), 39 | 'insurgency': SDK('HL2SDKINSURGENCY', '2.insurgency', '19', 'INSURGENCY', WinLinux, 'insurgency'), 40 | 'contagion': SDK('HL2SDKCONTAGION', '2.contagion', '14', 'CONTAGION', WinOnly, 'contagion'), 41 | 'bms': SDK('HL2SDKBMS', '2.bms', '10', 'BMS', WinLinux, 'bms'), 42 | } 43 | 44 | def ResolveEnvPath(env, folder): 45 | if env in os.environ: 46 | path = os.environ[env] 47 | if os.path.isdir(path): 48 | return path 49 | return None 50 | 51 | head = os.getcwd() 52 | oldhead = None 53 | while head != None and head != oldhead: 54 | path = os.path.join(head, folder) 55 | if os.path.isdir(path): 56 | return path 57 | oldhead = head 58 | head, tail = os.path.split(head) 59 | 60 | return None 61 | 62 | def Normalize(path): 63 | return os.path.abspath(os.path.normpath(path)) 64 | 65 | class ExtensionConfig(object): 66 | def __init__(self): 67 | self.sdk = PossibleSDKs['csgo'] 68 | self.binaries = [] 69 | self.extensions = [] 70 | self.generated_headers = None 71 | self.mms_root = None 72 | self.sm_root = None 73 | 74 | @property 75 | def tag(self): 76 | if builder.options.debug == '1': 77 | return 'Debug' 78 | return 'Release' 79 | 80 | def detectSDKs(self): 81 | if builder.options.hl2sdk_root: 82 | sdk_path = os.path.join(builder.options.hl2sdk_root, self.sdk.folder) 83 | else: 84 | sdk_path = ResolveEnvPath(self.sdk.envvar, self.sdk.folder) 85 | if sdk_path is None or not os.path.isdir(sdk_path): 86 | raise Exception('Could not find a valid path for {0}'.format(self.sdk.envvar)) 87 | else: 88 | self.sdk.path = Normalize(sdk_path) 89 | 90 | if builder.options.sm_path: 91 | self.sm_root = builder.options.sm_path 92 | else: 93 | self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.8') 94 | if not self.sm_root: 95 | self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod') 96 | if not self.sm_root: 97 | self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central') 98 | 99 | if not self.sm_root or not os.path.isdir(self.sm_root): 100 | raise Exception('Could not find a source copy of SourceMod') 101 | self.sm_root = Normalize(self.sm_root) 102 | 103 | if builder.options.mms_path: 104 | self.mms_root = builder.options.mms_path 105 | else: 106 | self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10') 107 | if not self.mms_root: 108 | self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source') 109 | if not self.mms_root: 110 | self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central') 111 | 112 | if not self.mms_root or not os.path.isdir(self.mms_root): 113 | raise Exception('Could not find a source copy of Metamod:Source') 114 | self.mms_root = Normalize(self.mms_root) 115 | 116 | def configure(self): 117 | cxx = builder.DetectCompilers() 118 | 119 | if cxx.like('gcc'): 120 | self.configure_gcc(cxx) 121 | elif cxx.vendor == 'msvc': 122 | self.configure_msvc(cxx) 123 | 124 | # Optimizaiton 125 | if builder.options.opt == '1': 126 | cxx.defines += ['NDEBUG'] 127 | 128 | # Debugging 129 | if builder.options.debug == '1': 130 | cxx.defines += ['DEBUG', '_DEBUG'] 131 | 132 | # Build ID 133 | cxx.defines += ['BUILD_ID="' + ('-' + builder.options.build_id if builder.options.build_id else '') + '"'] 134 | 135 | # Platform-specifics 136 | if builder.target_platform == 'linux': 137 | self.configure_linux(cxx) 138 | elif builder.target_platform == 'windows': 139 | self.configure_windows(cxx) 140 | 141 | # Finish up. 142 | cxx.includes += [ 143 | os.path.join(self.sm_root, 'public'), 144 | ] 145 | 146 | def configure_gcc(self, cxx): 147 | cxx.defines += [ 148 | 'stricmp=strcasecmp', 149 | '_stricmp=strcasecmp', 150 | '_snprintf=snprintf', 151 | '_vsnprintf=vsnprintf', 152 | 'HAVE_STDINT_H', 153 | 'HAVE_STRING_H', 154 | 'GNUC', 155 | ] 156 | cxx.cflags += [ 157 | '-pipe', 158 | '-fno-strict-aliasing', 159 | '-Wall', 160 | '-Werror', 161 | '-Wno-unused', 162 | '-Wno-switch', 163 | '-Wno-array-bounds', 164 | '-msse', 165 | '-m32', 166 | '-fvisibility=hidden', 167 | ] 168 | cxx.cxxflags += [ 169 | '-std=c++14', 170 | '-fno-exceptions', 171 | '-fno-threadsafe-statics', 172 | '-Wno-non-virtual-dtor', 173 | '-Wno-overloaded-virtual', 174 | '-Wno-reinterpret-base-class', 175 | '-fvisibility-inlines-hidden', 176 | ] 177 | cxx.linkflags += ['-m32'] 178 | 179 | have_gcc = cxx.vendor == 'gcc' 180 | have_clang = cxx.vendor == 'clang' 181 | if cxx.version >= 'clang-3.6': 182 | cxx.cxxflags += ['-Wno-inconsistent-missing-override'] 183 | if cxx.version >= 'clang-10.0': 184 | cxx.cxxflags += ['-Wno-implicit-int-float-conversion'] 185 | if have_clang or (cxx.version >= 'gcc-4.6'): 186 | cxx.cflags += ['-Wno-narrowing'] 187 | if have_clang or (cxx.version >= 'gcc-4.7'): 188 | cxx.cxxflags += ['-Wno-delete-non-virtual-dtor'] 189 | if cxx.version >= 'gcc-4.8': 190 | cxx.cflags += ['-Wno-unused-result'] 191 | 192 | if have_clang: 193 | cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch'] 194 | if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4': 195 | cxx.cxxflags += ['-Wno-deprecated-register'] 196 | else: 197 | cxx.cxxflags += ['-Wno-deprecated'] 198 | cxx.cflags += ['-Wno-sometimes-uninitialized'] 199 | 200 | if have_gcc: 201 | cxx.cflags += ['-mfpmath=sse'] 202 | 203 | if builder.options.opt == '1': 204 | cxx.cflags += ['-O3'] 205 | 206 | if builder.options.lto == '1': 207 | cxx.cflags += ['-flto', '-fPIC'] 208 | cxx.linkflags += ['-flto', '-fuse-ld=gold'] 209 | 210 | def configure_msvc(self, cxx): 211 | if builder.options.debug == '1': 212 | cxx.cflags += ['/MTd'] 213 | cxx.linkflags += ['/NODEFAULTLIB:libcmt'] 214 | else: 215 | cxx.cflags += ['/MT'] 216 | cxx.defines += [ 217 | '_CRT_SECURE_NO_DEPRECATE', 218 | '_CRT_SECURE_NO_WARNINGS', 219 | '_CRT_NONSTDC_NO_DEPRECATE', 220 | '_ITERATOR_DEBUG_LEVEL=0', 221 | ] 222 | cxx.cflags += [ 223 | '/W3', 224 | ] 225 | cxx.cxxflags += [ 226 | '/EHsc', 227 | '/GR-', 228 | '/TP', 229 | ] 230 | cxx.linkflags += [ 231 | '/MACHINE:X86', 232 | 'kernel32.lib', 233 | 'user32.lib', 234 | 'gdi32.lib', 235 | 'winspool.lib', 236 | 'comdlg32.lib', 237 | 'advapi32.lib', 238 | 'shell32.lib', 239 | 'ole32.lib', 240 | 'oleaut32.lib', 241 | 'uuid.lib', 242 | 'odbc32.lib', 243 | 'odbccp32.lib', 244 | 'Ws2_32.lib', 245 | ] 246 | 247 | if builder.options.opt == '1': 248 | cxx.cflags += ['/Ox', '/Zo'] 249 | cxx.linkflags += ['/OPT:ICF', '/OPT:REF'] 250 | 251 | if builder.options.debug == '1': 252 | cxx.cflags += ['/Od', '/RTC1'] 253 | 254 | if builder.options.lto == '1': 255 | cxx.cflags += ['/GL'] 256 | cxx.linkflags += ['/LTCG'] 257 | 258 | # This needs to be after our optimization flags which could otherwise disable it. 259 | # Don't omit the frame pointer. 260 | cxx.cflags += ['/Oy-'] 261 | 262 | def configure_linux(self, cxx): 263 | cxx.defines += ['_LINUX', 'POSIX'] 264 | cxx.linkflags += ['-Wl,--exclude-libs,ALL', '-lm'] 265 | if cxx.vendor == 'gcc': 266 | cxx.linkflags += ['-static-libgcc'] 267 | elif cxx.vendor == 'clang': 268 | cxx.linkflags += ['-lgcc_eh'] 269 | 270 | def configure_windows(self, cxx): 271 | cxx.defines += ['WIN32', '_WINDOWS'] 272 | 273 | def ConfigureForExtension(self, context, compiler): 274 | compiler.cxxincludes += [ 275 | os.path.join(context.currentSourcePath), 276 | os.path.join(context.currentSourcePath, 'sdk'), 277 | os.path.join(self.sm_root, 'public'), 278 | os.path.join(self.sm_root, 'public', 'extensions'), 279 | os.path.join(self.sm_root, 'sourcepawn', 'include'), 280 | os.path.join(self.sm_root, 'public', 'amtl', 'amtl'), 281 | os.path.join(self.sm_root, 'public', 'amtl'), 282 | ] 283 | return compiler 284 | 285 | def ConfigureForHL2(self, binary, sdk): 286 | compiler = binary.compiler 287 | 288 | if sdk.name == 'episode1': 289 | mms_path = os.path.join(self.mms_root, 'core-legacy') 290 | else: 291 | mms_path = os.path.join(self.mms_root, 'core') 292 | 293 | compiler.cxxincludes += [ 294 | os.path.join(mms_path), 295 | os.path.join(mms_path, 'sourcehook'), 296 | ] 297 | 298 | defines = ['SE_' + PossibleSDKs[i].define + '=' + PossibleSDKs[i].code for i in PossibleSDKs] 299 | compiler.defines += defines 300 | 301 | paths = [ 302 | ['public'], 303 | ['public', 'engine'], 304 | ['public', 'mathlib'], 305 | ['public', 'vstdlib'], 306 | ['public', 'tier0'], 307 | ['public', 'tier1'] 308 | ] 309 | if sdk.name == 'episode1' or sdk.name == 'darkm': 310 | paths.append(['public', 'dlls']) 311 | paths.append(['game_shared']) 312 | else: 313 | paths.append(['public', 'game', 'server']) 314 | paths.append(['public', 'toolframework']) 315 | paths.append(['game', 'shared']) 316 | paths.append(['common']) 317 | 318 | compiler.defines += ['SOURCE_ENGINE=' + sdk.code] 319 | 320 | if sdk.name in ['sdk2013', 'bms'] and compiler.like('gcc'): 321 | # The 2013 SDK already has these in public/tier0/basetypes.h 322 | compiler.defines.remove('stricmp=strcasecmp') 323 | compiler.defines.remove('_stricmp=strcasecmp') 324 | compiler.defines.remove('_snprintf=snprintf') 325 | compiler.defines.remove('_vsnprintf=vsnprintf') 326 | 327 | if compiler.like('msvc'): 328 | compiler.defines += ['COMPILER_MSVC', 'COMPILER_MSVC32'] 329 | if compiler.version >= 1900: 330 | compiler.linkflags += ['legacy_stdio_definitions.lib'] 331 | else: 332 | compiler.defines += ['COMPILER_GCC'] 333 | 334 | # For everything after Swarm, this needs to be defined for entity networking 335 | # to work properly with sendprop value changes. 336 | if sdk.name in ['blade', 'insurgency', 'csgo', 'dota']: 337 | compiler.defines += ['NETWORK_VARS_ENABLED'] 338 | 339 | if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2', 'dota']: 340 | if builder.target_platform == 'linux': 341 | compiler.defines += ['NO_HOOK_MALLOC', 'NO_MALLOC_OVERRIDE'] 342 | 343 | if sdk.name == 'csgo' and builder.target_platform == 'linux': 344 | compiler.linkflags += ['-lstdc++'] 345 | compiler.defines += ['_GLIBCXX_USE_CXX11_ABI=0'] 346 | 347 | for path in paths: 348 | compiler.cxxincludes += [os.path.join(sdk.path, *path)] 349 | 350 | if builder.target_platform == 'linux': 351 | if sdk.name == 'episode1': 352 | lib_folder = os.path.join(sdk.path, 'linux_sdk') 353 | elif sdk.name in ['sdk2013', 'bms']: 354 | lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32') 355 | else: 356 | lib_folder = os.path.join(sdk.path, 'lib', 'linux') 357 | 358 | if builder.target_platform == 'linux': 359 | if sdk.name in ['sdk2013', 'bms']: 360 | compiler.postlink += [ 361 | compiler.Dep(os.path.join(lib_folder, 'tier1.a')), 362 | compiler.Dep(os.path.join(lib_folder, 'mathlib.a')) 363 | ] 364 | else: 365 | compiler.postlink += [ 366 | compiler.Dep(os.path.join(lib_folder, 'tier1_i486.a')), 367 | compiler.Dep(os.path.join(lib_folder, 'mathlib_i486.a')) 368 | ] 369 | 370 | if sdk.name in ['blade', 'insurgency', 'csgo', 'dota']: 371 | compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'interfaces_i486.a'))] 372 | 373 | dynamic_libs = [] 374 | if builder.target_platform == 'linux': 375 | if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'bms', 'nucleardawn', 'l4d2', 'insurgency']: 376 | dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so'] 377 | elif sdk.name in ['l4d', 'blade', 'insurgency', 'csgo', 'dota']: 378 | dynamic_libs = ['libtier0.so', 'libvstdlib.so'] 379 | else: 380 | dynamic_libs = ['tier0_i486.so', 'vstdlib_i486.so'] 381 | elif builder.target_platform == 'windows': 382 | libs = ['tier0', 'tier1', 'vstdlib', 'mathlib'] 383 | if sdk.name in ['swarm', 'blade', 'insurgency', 'csgo', 'dota']: 384 | libs.append('interfaces') 385 | for lib in libs: 386 | lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib' 387 | compiler.linkflags.append(compiler.Dep(lib_path)) 388 | 389 | for library in dynamic_libs: 390 | source_path = os.path.join(lib_folder, library) 391 | output_path = os.path.join(binary.localFolder, library) 392 | 393 | def make_linker(source_path, output_path): 394 | def link(context, binary): 395 | cmd_node, (output,) = context.AddSymlink(source_path, output_path) 396 | return output 397 | return link 398 | 399 | linker = make_linker(source_path, output_path) 400 | compiler.linkflags[0:0] = [compiler.Dep(library, linker)] 401 | 402 | return binary 403 | 404 | def HL2Library(self, context, name, sdk): 405 | binary = context.compiler.Library(name) 406 | self.ConfigureForExtension(context, binary.compiler) 407 | return self.ConfigureForHL2(binary, sdk) 408 | 409 | def HL2Project(self, context, name): 410 | project = context.compiler.LibraryProject(name) 411 | self.ConfigureForExtension(context, project.compiler) 412 | return project 413 | 414 | def HL2Config(self, project, name, sdk): 415 | binary = project.Configure(name, '{0} - {1}'.format(self.tag, sdk.name)) 416 | return self.ConfigureForHL2(binary, sdk) 417 | 418 | Extension = ExtensionConfig() 419 | Extension.detectSDKs() 420 | Extension.configure() 421 | 422 | # Add additional buildscripts here 423 | BuildScripts = [ 424 | 'AMBuilder', 425 | ] 426 | 427 | if builder.backend == 'amb2': 428 | BuildScripts += [ 429 | 'PackageScript', 430 | ] 431 | 432 | builder.RunBuildScripts(BuildScripts, { 'Extension': Extension}) 433 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /PTaH.inc: -------------------------------------------------------------------------------- 1 | #if defined _PTaH_included 2 | #endinput 3 | #endif 4 | #define _PTaH_included 5 | 6 | 7 | 8 | #define PTaH_AVATAR_SIZE 64 * 64 * 3 // Height * Width * Pixel cell 9 | 10 | enum PTaH_HookType 11 | { 12 | UnHook = 0, 13 | Hook 14 | }; 15 | 16 | enum PTaH_HookEvent 17 | { 18 | PTaH_GiveNamedItemPre = 10, 19 | PTaH_GiveNamedItemPost, 20 | PTaH_WeaponCanUsePre, 21 | PTaH_WeaponCanUsePost, 22 | PTaH_SetPlayerModelPre, 23 | PTaH_SetPlayerModelPost, 24 | PTaH_ClientVoiceToPre, 25 | PTaH_ClientVoiceToPost, 26 | PTaH_ConsolePrintPre, 27 | PTaH_ConsolePrintPost, 28 | PTaH_ExecuteStringCommandPre, 29 | PTaH_ExecuteStringCommandPost, 30 | PTaH_ClientConnectPre, 31 | PTaH_ClientConnectPost, 32 | PTaH_InventoryUpdatePost = 25 33 | }; 34 | 35 | enum PTaH_ModelType 36 | { 37 | ViewModel = 0, 38 | WorldModel, 39 | DroppedModel 40 | }; 41 | 42 | enum EStickerAttributeType 43 | { 44 | EStickerAttribute_ID = 0, // int 45 | EStickerAttribute_Wear, // float 46 | EStickerAttribute_Scale, // float 47 | EStickerAttribute_Rotation // float 48 | }; 49 | 50 | enum ESchemaAttributeType 51 | { 52 | ESchemaAttribute_Unknown = -1, 53 | ESchemaAttribute_Uint32, 54 | ESchemaAttribute_Float, 55 | ESchemaAttribute_String, 56 | ESchemaAttribute_Vector 57 | }; 58 | 59 | enum EEconItemQuality 60 | { 61 | AE_UNDEFINED = -1, 62 | 63 | AE_NORMAL = 0, 64 | AE_GENUINE = 1, 65 | AE_VINTAGE, 66 | AE_UNUSUAL, 67 | AE_UNIQUE, 68 | AE_COMMUNITY, 69 | AE_DEVELOPER, 70 | AE_SELFMADE, 71 | AE_CUSTOMIZED, 72 | AE_STRANGE, 73 | AE_COMPLETED, 74 | AE_HAUNTED, 75 | AE_TOURNAMENT, 76 | AE_FAVORED, 77 | 78 | AE_MAX_TYPES, 79 | }; 80 | 81 | enum eEconItemFlags 82 | { 83 | kEconItemFlag_CannotTrade = 1 << 0, 84 | kEconItemFlag_CannotBeUsedInCrafting = 1 << 1, 85 | kEconItemFlag_CanBeTradedByFreeAccounts = 1 << 2, 86 | kEconItemFlag_NonEconomy = 1 << 3, // Used for items that are meant to not interact in the economy -- these can't be traded, gift-wrapped, crafted, etc. 87 | 88 | // Combination of the above flags used in code. 89 | kEconItemFlags_CheckFlags_CannotTrade = kEconItemFlag_CannotTrade, 90 | kEconItemFlags_CheckFlags_NotUsableInCrafting = kEconItemFlag_CannotBeUsedInCrafting, 91 | 92 | kEconItemFlags_CheckFlags_AllGCFlags = kEconItemFlags_CheckFlags_CannotTrade | kEconItemFlags_CheckFlags_NotUsableInCrafting, 93 | }; 94 | 95 | enum eEconItemRarity 96 | { 97 | kEconItemRarity_Default = 0, 98 | kEconItemRarity_Common, 99 | kEconItemRarity_Uncommon, 100 | kEconItemRarity_Rare, 101 | kEconItemRarity_Mythical, 102 | kEconItemRarity_Legendary, 103 | kEconItemRarity_Ancient, 104 | kEconItemRarity_Immortal 105 | }; 106 | 107 | enum eEconItemOrigin 108 | { 109 | kEconItemOrigin_Invalid = -1, 110 | 111 | kEconItemOrigin_Drop = 0, 112 | kEconItemOrigin_Achievement, 113 | kEconItemOrigin_Purchased, 114 | kEconItemOrigin_Traded, 115 | kEconItemOrigin_Crafted, 116 | kEconItemOrigin_StorePromotion, 117 | kEconItemOrigin_Gifted, 118 | kEconItemOrigin_SupportGranted, 119 | kEconItemOrigin_FoundInCrate, 120 | kEconItemOrigin_Earned, 121 | kEconItemOrigin_ThirdPartyPromotion, 122 | kEconItemOrigin_GiftWrapped, 123 | kEconItemOrigin_HalloweenDrop, 124 | kEconItemOrigin_PackageItem, 125 | kEconItemOrigin_Foreign, 126 | kEconItemOrigin_CDKey, 127 | kEconItemOrigin_CollectionReward, 128 | kEconItemOrigin_PreviewItem, 129 | kEconItemOrigin_SteamWorkshopContribution, 130 | kEconItemOrigin_PeriodicScoreReward, 131 | kEconItemOrigin_Recycling, 132 | kEconItemOrigin_TournamentDrop, 133 | kEconItemOrigin_StockItem, 134 | kEconItemOrigin_QuestReward, 135 | kEconItemOrigin_LevelUpReward, 136 | 137 | kEconItemOrigin_Max, 138 | }; 139 | 140 | enum CEconItemDefinition 141 | { 142 | CEconItemDefinition_NULL = 0 143 | }; 144 | 145 | enum CEconItemAttributeDefinition 146 | { 147 | CEconItemAttributeDefinition_NULL = 0 148 | }; 149 | 150 | enum CEconItemAttribute 151 | { 152 | CEconItemAttribute_NULL = 0 153 | }; 154 | 155 | enum CAttributeList 156 | { 157 | CAttributeList_NULL = 0 158 | }; 159 | 160 | enum CEconItemView 161 | { 162 | CEconItemView_NULL = 0 163 | }; 164 | 165 | enum CCSPlayerInventory 166 | { 167 | CCSPlayerInventory_NULL = 0 168 | }; 169 | 170 | 171 | 172 | methodmap CEconItemDefinition // < Address 173 | { 174 | // CEconItemDefinition is not Handle, CloseHandle() - NOT NEEDED !!!!!!!!!!!!!!!!!!!!! 175 | // Always check, if not wounded CEconItemDefinition - NULL ( if(pItemDefinition) ) !!!!!!!!!!!!!!!!!!!!! 176 | 177 | /** 178 | * Gets the definition index. 179 | * 180 | * @return Returns definition index. 181 | * 182 | * @error CEconItemDefinition == NULL. 183 | */ 184 | public native int GetDefinitionIndex(); 185 | 186 | /** 187 | * Gets the item definition name. 188 | * 189 | * @param sBuffer Destination string buffer. 190 | * @param iLen Maximum length of output string buffer. 191 | * 192 | * @return Returns length or 0 if failed. 193 | * 194 | * @error CEconItemDefinition == NULL. 195 | */ 196 | public native int GetDefinitionName(char[] sBuffer, int iLen); 197 | 198 | /** 199 | * Gets LoadoutSlot. 200 | * 201 | * @param iTeam Team index or 0 if independently. 202 | * 203 | * @return Returns loadout slot index. 204 | * 205 | * @error CEconItemDefinition == NULL. 206 | */ 207 | public native int GetLoadoutSlot(int iTeam = 0); 208 | 209 | /** 210 | * Gets the used by team. 211 | * 212 | * @return Returns team index or 0 if both team. 213 | */ 214 | public native int GetUsedByTeam(); 215 | 216 | /** 217 | * Gets the amount slot for stickers. 218 | * @note On agents, places are counted according 219 | * to patch locations on the model. 220 | * 221 | * @return Returns sticker slot count. 222 | * 223 | * @error CEconItemDefinition == NULL. 224 | */ 225 | public native int GetNumSupportedStickerSlots(); 226 | 227 | /** 228 | * Gets the item econ image path in resource/flash/. 229 | * Example: "econ/weapons/base_weapons/weapon_knife" 230 | * 231 | * @note Add ".png" in the end of string for full formatting. 232 | * 233 | * @param sBuffer Destination string buffer. 234 | * @param iLen Maximum length of output string buffer. 235 | * 236 | * @return Returns length or 0 if failed. 237 | * 238 | * @error CEconItemDefinition == NULL. 239 | */ 240 | public native int GetEconImage(char[] sBuffer, int iLen); 241 | 242 | /** 243 | * Gets the item model path. 244 | * 245 | * @param iModelType Model type. 246 | * @param sBuffer Destination string buffer. 247 | * @param iLen Maximum length of output string buffer. 248 | * Max size PLATFORM_MAX_PATH. 249 | * 250 | * @return Returns length or 0 if failed. 251 | * 252 | * @error CEconItemDefinition == NULL or model type invalid. 253 | */ 254 | public native int GetModel(PTaH_ModelType iModelType, char[] sBuffer, int iLen); 255 | 256 | /** 257 | * @deprecated Use CEconItemDefinition::GetDefinitionName() for get the definition name. Will be removed. 258 | */ 259 | #pragma deprecated Use CEconItemDefinition::GetDefinitionName() instead 260 | public native int GetClassName(char[] sBuffer, int iLen); 261 | }; 262 | 263 | methodmap CEconItemAttributeDefinition 264 | { 265 | // CEconItemAttributeDefinition is not Handle, CloseHandle() - NOT NEEDED !!!!!!!!!!!!!!!!!!!!! 266 | // Always check, if not wounded CEconItemAttributeDefinition - NULL ( if(pItemAttributeDefinition) ) !!!!!!!!!!!!!!!!!!!!! 267 | 268 | /** 269 | * Gets the definition index. 270 | * 271 | * @return Returns definition index. 272 | * 273 | * @error CEconItemAttributeDefinition == NULL. 274 | */ 275 | public native int GetDefinitionIndex(); 276 | 277 | /** 278 | * Gets the definition attribute name. 279 | * 280 | * @param sBuffer Destination string buffer. 281 | * @param iLen Maximum length of output string buffer. 282 | * 283 | * @return Returns definition index. 284 | * 285 | * @error CEconItemAttributeDefinition == NULL. 286 | */ 287 | public native int GetDefinitionName(char[] sBuffer, int iLen); 288 | 289 | /** 290 | * Gets the attribute type. 291 | * 292 | * @return Returns attribute type index. 293 | * 294 | * @error CEconItemAttributeDefinition == NULL. 295 | */ 296 | public native ESchemaAttributeType GetAttributeType(); 297 | }; 298 | 299 | methodmap CEconItemAttribute 300 | { 301 | // CEconItemAttribute is not Handle, CloseHandle() - NOT NEEDED !!!!!!!!!!!!!!!!!!!!! 302 | // Always check, if not wounded CEconItemAttribute - NULL ( if(pItemAttribute) ) !!!!!!!!!!!!!!!!!!!!! 303 | 304 | // Returns the definition index. 305 | property int DefinitionIndex 306 | { 307 | public native get(); 308 | } 309 | 310 | // Returns or sets attribute current value. 311 | property any Value 312 | { 313 | public native set(any Value); 314 | public native get(); 315 | } 316 | 317 | // Returns the attribute initial value. 318 | property any InitialValue 319 | { 320 | public native get(); 321 | } 322 | 323 | // None. 324 | property int RefundableCurrency 325 | { 326 | public native set(int RefundableCurrency); 327 | public native get(); 328 | } 329 | 330 | // Returns or sets the setbonus flag. 331 | property bool SetBonus 332 | { 333 | public native set(bool SetBonus); 334 | public native get(); 335 | } 336 | }; 337 | 338 | methodmap CAttributeList // < Address 339 | { 340 | // CAttributeList is not Handle, CloseHandle() - NOT NEEDED !!!!!!!!!!!!!!!!!!!!! 341 | // Always check, if not wounded CAttributeList - NULL ( if(pAttributeList) ) !!!!!!!!!!!!!!!!!!!!! 342 | 343 | /** 344 | * Removes all attributes from the list. 345 | * 346 | * @noreturn 347 | * 348 | * @error CAttributeList == NULL. 349 | */ 350 | public native void DestroyAllAttributes(); 351 | 352 | /** 353 | * Gets the attributes count in the list. 354 | * 355 | * @return Returns the attributes count. 356 | * 357 | * @error CAttributeList == NULL. 358 | */ 359 | public native int GetAttributesCount(); 360 | 361 | /** 362 | * Gets the attribute by index. 363 | * 364 | * @return Returns the pointer in CEconItemAttribute. 365 | * 366 | * @error CAttributeList == NULL. 367 | */ 368 | public native CEconItemAttribute GetAttribute(int iIndex); 369 | 370 | /** 371 | * Gets the attribute by definition index. 372 | * 373 | * @param iDefIndex Attribute definition index. 374 | * 375 | * @return Returns the pointer in CEconItemAttribute. 376 | * 377 | * @error CAttributeList == NULL. 378 | */ 379 | public native CEconItemAttribute GetAttributeByDefIndex(int iDefIndex); 380 | 381 | /** 382 | * Removes the attribute by index. 383 | * 384 | * @param Attribute index in list. 385 | * 386 | * @noreturn 387 | * 388 | * @error CAttributeList == NULL. 389 | */ 390 | public native void RemoveAttribute(int iIndex); 391 | 392 | /** 393 | * Removes the attribute by definition index. 394 | * 395 | * @param iDefIndex Attribute definition index. 396 | * 397 | * @noreturn 398 | * 399 | * @error CAttributeList == NULL. 400 | */ 401 | public native void RemoveAttributeByDefIndex(int iDefIndex); 402 | 403 | /** 404 | * Sets ot adds the attribute value by definition index. 405 | * 406 | * @param iDefIndex Attribute definition index. 407 | * @param Value Attribute value. 408 | * 409 | * @noreturn 410 | * 411 | * @error CAttributeList == NULL. 412 | */ 413 | public native void SetOrAddAttributeValue(int iDefIndex, any Value); 414 | }; 415 | 416 | 417 | methodmap CEconItemView // < Address 418 | { 419 | // CEconItemView is not Handle, CloseHandle() - NOT NEEDED !!!!!!!!!!!!!!!!!!!!! 420 | // Always check, if not wounded CEconItemView - NULL ( if(pItemView) ) !!!!!!!!!!!!!!!!!!!!! 421 | // If a player will left from a server after function call to obtain CEconItemView (PTaH_GetEconItemViewFromEconEntity this applies if iEntity will be destroyed). You get crash server!!!!!!!!!!!!!!!!!!!!! 422 | 423 | /** 424 | * Gets the index of skin. 425 | * 426 | * @return Returns PaintKit index. 427 | * 428 | * @error CEconItemView == NULL. 429 | */ 430 | public native int GetCustomPaintKitIndex(); 431 | 432 | /** 433 | * Gets the displacement of skin. 434 | * 435 | * @return Returns PaintKit seed. 436 | * 437 | * @error CEconItemView == NULL. 438 | */ 439 | public native int GetCustomPaintKitSeed(); 440 | 441 | /** 442 | * Gets the quality of skins. 443 | * 444 | * @param fDef Default value if PaintKit is not found. 445 | * 446 | * @return Returns PaintKit wear. 447 | * 448 | * @error CEconItemView == NULL. 449 | */ 450 | public native float GetCustomPaintKitWear(float flDef = -1.0); 451 | 452 | /** 453 | * Gets the sticker index by slot. 454 | * 455 | * @param iSlot Sticker slot index. 456 | * @param ESAT Sticker attribute type. 457 | * @param Def Default value if sticker is not found. 458 | * 459 | * @return Returns the attribute value. 460 | * 461 | * @error CEconItemView == NULL. 462 | */ 463 | public native any GetStickerAttributeBySlotIndex(int iSlot, EStickerAttributeType ESAT, any Def = 0); 464 | 465 | /** 466 | * Gets is it possible to exchange weapons. 467 | * 468 | * @return Returns is tradable. 469 | * 470 | * @error CEconItemView == NULL. 471 | */ 472 | public native bool IsTradable(); 473 | 474 | /** 475 | * Gets is it possible to sell weapons on http://steamcommunity.com/market/. 476 | * 477 | * @return Returns Marketable. 478 | * 479 | * @error CEconItemView == NULL. 480 | */ 481 | public native bool IsMarketable(); 482 | 483 | /** 484 | * Gets CEconItemDefinition. 485 | * 486 | * @return Returns the pointer in CEconItemDefinition. 487 | * 488 | * @error CEconItemView == NULL. 489 | */ 490 | public native CEconItemDefinition GetItemDefinition(); 491 | 492 | /** 493 | * Gets AccountID owner of ItemView. 494 | * 495 | * @return Returns AccountID. 496 | * 497 | * @error CEconItemView == NULL. 498 | */ 499 | public native int GetAccountID(); 500 | 501 | /** 502 | * Gets ItemID of ItemView. 503 | * 504 | * @param iItemID Where will it be recorded ItemID. 505 | * 506 | * @noreturn 507 | * 508 | * @error CEconItemView == NULL. 509 | */ 510 | public native void GetItemID(int iItemID[2]); 511 | 512 | /** 513 | * Gets the owner of ItemView. 514 | * 515 | * @return Returns the client index or -1 is not found. 516 | * 517 | * @error CEconItemView == NULL. 518 | */ 519 | public int GetClientIndex() 520 | { 521 | int iAccountID = this.GetAccountID(); 522 | 523 | for(int i = MaxClients + 1; --i;) 524 | { 525 | if(IsClientAuthorized(i) && iAccountID == GetSteamAccountID(i)) 526 | { 527 | return i; 528 | } 529 | } 530 | 531 | return -1; 532 | } 533 | 534 | /** 535 | * Gets is custom of ItemView. 536 | * 537 | * @return Returns is custom. 538 | * 539 | * @error CEconItemView == NULL. 540 | */ 541 | public bool IsCustomItemView() 542 | { 543 | int iAccountID = this.GetAccountID(); 544 | 545 | return iAccountID != 0 && iAccountID != -1; 546 | } 547 | 548 | /** 549 | * Gets EconItem quality. 550 | * 551 | * @return Returns the quality. 552 | * 553 | * @error CEconItemView == NULL. 554 | */ 555 | public native EEconItemQuality GetQuality(); 556 | 557 | /** 558 | * Gets EconItem rarity. 559 | * 560 | * @return Returns the rarity. 561 | * 562 | * @error CEconItemView == NULL. 563 | */ 564 | public native eEconItemRarity GetRarity(); 565 | 566 | /** 567 | * Gets EconItem flags. 568 | * 569 | * @return Returns the flags. 570 | * 571 | * @error CEconItemView == NULL. 572 | */ 573 | public native eEconItemFlags GetFlags(); 574 | 575 | /** 576 | * Gets EconItem origin. 577 | * 578 | * @return Returns the origin. 579 | * 580 | * @error CEconItemView == NULL. 581 | */ 582 | public native eEconItemOrigin GetOrigin(); 583 | 584 | /** 585 | * Gets the nametag on skin. 586 | * 587 | * @param sBuffer Destination string buffer. 588 | * @param iLen Maximum length of output string buffer. 589 | * 590 | * @return Returns the nametag length. 591 | * 592 | * @error CEconItemView == NULL. 593 | */ 594 | public native int GetCustomName(char[] sBuffer, int iLen); 595 | 596 | /** 597 | * Gets the amount StatTrak. 598 | * 599 | * @return Returns the amount StatTrak. 600 | * If -1, StatTrak attribute is not found. 601 | * 602 | * @error CEconItemView == NULL. 603 | */ 604 | public native int GetStatTrakKill(); 605 | 606 | /** 607 | * Gets the attribute value by index. 608 | * 609 | * @param iAttribIndex Attribute definition index. 610 | * @param Value Variable to store value. 611 | * 612 | * @return Returns is attribute exist. 613 | * 614 | * @error CEconItemView == NULL or iAttribIndex invalid. 615 | */ 616 | public native bool GetAttributeValueByIndex(int iAttribIndex, any &Value); 617 | 618 | // Returns the attribute list with static attributes. 619 | property CAttributeList AttributeList 620 | { 621 | public native get(); 622 | } 623 | 624 | // Returns the attribute list with dynamic attributes. 625 | property CAttributeList NetworkedDynamicAttributesForDemos 626 | { 627 | public native get(); 628 | } 629 | }; 630 | 631 | methodmap CCSPlayerInventory // < Address 632 | { 633 | // CCSPlayerInventory is not Handle, CloseHandle() - NOT NEEDED !!!!!!!!!!!!!!!!!!!!! 634 | // Always check, if not wounded CCSPlayerInventory - NULL ( if(pPlayerInventory) ) !!!!!!!!!!!!!!!!!!!!! 635 | 636 | /** 637 | * Gets CEconItemView in LoadoutSlot. 638 | * 639 | * @param iTeamIndex Team index. 640 | * @param iLoadoutSlot Loadout slot index. 641 | * 642 | * @return Returns the pointer in CEconItemView. 643 | * 644 | * @error CCSPlayerInventory == NULL or team index is invalid. 645 | */ 646 | public native CEconItemView GetItemInLoadout(int iTeam, int iLoadoutSlot); 647 | 648 | /** 649 | * Gets the custom items count in inventory. 650 | * 651 | * @return Returns the items count. 652 | * 653 | * @error CCSPlayerInventory == NULL. 654 | */ 655 | public native int GetItemsCount(); 656 | 657 | /** 658 | * Gets CEconItemView in inventory by index. 659 | * 660 | * @param iPos Item position in inventory. 661 | * 662 | * @return Returns the pointer in CEconItemView. 663 | * 664 | * @error CCSPlayerInventory == NULL. 665 | */ 666 | public native CEconItemView GetItem(int iPos); 667 | }; 668 | 669 | 670 | 671 | typeset PTaHCB 672 | { 673 | /** GiveNamedItemPre 674 | * 675 | * Called before the issuance of the item. 676 | * 677 | * @param iClient Client index. 678 | * @param sClassname Weapon classname. 679 | * @param pItemView Customization item. 680 | * @param bIgnoredView Is ignores CEconItemView the item. 681 | * @param bOriginNULL Origin is unspecified. 682 | * @param vecOrigin Coordinates where the item was created. 683 | * You cannot compare vecOrigin == NULL_VECTOR, use bOriginNULL param for it. 684 | * 685 | * @return Return Plugin_Stop or Plugin_Handled for stop granting item. 686 | * Return Plugin_Continue for allow issuance item without changes. 687 | * Return Plugin_Changed for allow issuance item with changes. 688 | */ 689 | function Action (int iClient, char sClassname[64], CEconItemView &pItemView, bool &bIgnoredView, bool &bOriginNULL, float vecOrigin[3]); 690 | 691 | /** GiveNamedItemPost 692 | * 693 | * It called when a player receives a item. 694 | * 695 | * @param iClient Client index. 696 | * @param sClassname Weapon classname. 697 | * @param pItemView Customization item. 698 | * @param iEntity Entity index. -1 if invalid item. 699 | * @param bOriginNULL Origin is unspecified. 700 | * @param vecOrigin Coordinates where the item was created. 701 | * 702 | * @noreturn 703 | */ 704 | function void (int iClient, const char[] sClassname, const CEconItemView pItemView, int iEntity, bool bOriginNULL, const float vecOrigin[3]); 705 | 706 | /** WeaponCanUsePre 707 | * 708 | * Called when a player is trying to pickup the item. 709 | * 710 | * @param iClient Client index. 711 | * @param iEntity Entity index. 712 | * @param bCanUs Is can be picked up. 713 | * 714 | * @return Return Plugin_Stop or Plugin_Handled to forbid lifting. 715 | * Return Plugin_Continue to leave unchanged. 716 | * Return Plugin_Changed to apply the changes specified in bCanUse. 717 | */ 718 | function Action (int iClient, int iEntity, bool &bCanUse); 719 | 720 | /** WeaponCanUsePost 721 | * 722 | * Called when a player attempted to pick up an item. 723 | * 724 | * @param iClient Client index. 725 | * @param iEntity Entity index. 726 | * @param bCanUs Is can be picked up. 727 | * 728 | * @noreturn 729 | */ 730 | function void (int iClient, int iEntity, bool bCanUse); 731 | 732 | /** SetPlayerModelPre 733 | * 734 | * Called before changing the player model. 735 | * 736 | * @param iClient Client index. 737 | * @param sModel Path to the player model. 738 | * @param sNewModel Path to a new model for change. 739 | * 740 | * @return Return Plugin_Stop or Plugin_Handled stop changing models. 741 | * Return Plugin_Continue for allow change model without changes. 742 | * Return Plugin_Changed for allow the change to the modified model. 743 | */ 744 | function Action (int iClient, const char[] sModel, char sNewModel[256]); 745 | 746 | /** SetPlayerModelPost 747 | * 748 | * Called after the change of the player model. 749 | * 750 | * @param iClient Client index. 751 | * @param sModel Path to the player model. 752 | * 753 | * @noreturn 754 | */ 755 | function void (int iClient, const char[] sModel); 756 | 757 | /** ClientVoiceToPre 758 | * 759 | * Called when a player tries to speak. 760 | * 761 | * @param iClient Client index. 762 | * @param iTarget Player target Index. 763 | * @param bListen Can iTarget hear iClient. 764 | * 765 | * @return Return Plugin_Stop or Plugin_Handled so that iTarget does not hear iClient. 766 | * Return Plugin_Continue to leave unchanged. Return Plugin_Changed to apply the changes specified in bListen. 767 | */ 768 | function Action (int iClient, int iTarget, bool &bListen); 769 | 770 | /** ClientVoiceToPost 771 | * 772 | * Called after the player tried to speak. 773 | * 774 | * @param iClient Client index. 775 | * @param iTarget Player target Index. 776 | * @param bListen Can iTarget hear iClient. 777 | * 778 | * @noreturn 779 | */ 780 | function void (int iClient, int iTarget, bool bListen); 781 | 782 | /** ConsolePrintPre 783 | * 784 | * Called before displaying messages to the player console. 785 | * 786 | * @param iClient Client index. 787 | * @param sMessage Text message. 788 | * 789 | * @return Return Plugin_Stop or Plugin_Handled for restrict display message. 790 | * Return Plugin_Continue for allow the display message without changes. 791 | * Return Plugin_Changed for allow display changed message. 792 | * 793 | */ 794 | function Action (int iClient, char sMessage[1024]); 795 | 796 | /** ConsolePrintPost 797 | * 798 | * Called after displaying messages to the player console. 799 | * 800 | * @param iClient Client index. 801 | * @param sMessage Message text. 802 | * 803 | * @noreturn 804 | */ 805 | function void (int iClient, const char[] sMessage); 806 | 807 | /** ExecuteStringCommandPre 808 | * 809 | * Called before executing the player command of the team on the server. 810 | * 811 | * @param iClient Client index. 812 | * @param sCommand Execute command. 813 | * 814 | * @return Return Plugin_Stop or Plugin_Handled for restrict execution. 815 | * Return Plugin_Continue for allow execution without changes. 816 | * Return Plugin_Changed for allow execution with changes. 817 | */ 818 | function Action (int iClient, char sCommand[512]); 819 | 820 | /** ExecuteStringCommandPost 821 | * 822 | * Called after executing the player command of the server. 823 | * 824 | * @param iClient Client index. 825 | * @param sCommand Execute command. 826 | * 827 | * @noreturn 828 | */ 829 | function void (int iClient, const char[] sCommand); 830 | 831 | /** ClientConnectPre 832 | * 833 | * Called before the authorization of the client to the server. 834 | * 835 | * @param iAccountID Client Steam account ID. 836 | * @param sIP Client IP address. 837 | * @param sName Client nickname. 838 | * @param sPassword Password witch he introduced. 839 | * @param sRejectReason The reason is not authorized. 840 | * 841 | * @return Return Plugin_Stop or Plugin_Handled for restrict autherization client. 842 | * Return Plugin_Continue for allow autherization without changes. 843 | * Return Plugin_Changed for allow autherization with changes. 844 | */ 845 | function Action (int iAccountID, const char[] sIP, const char[] sName, char sPassword[128], char sRejectReason[255]); 846 | 847 | /** ClientConnectPost 848 | * 849 | * Called after the authorization of the client to the server. 850 | * 851 | * @param iClient Client index. 852 | * @param iAccountID Client Steam account ID. 853 | * @param sIP Client IP address. 854 | * @param sName Client nickname. 855 | * 856 | * @noreturn 857 | */ 858 | function void (int iClient, int iAccountID, const char[] sIP, const char[] sName); 859 | 860 | /** InventoryUpdatePost 861 | * 862 | * Called after action in the player inventory. 863 | * 864 | * @param iClient Client index. 865 | * @param pInventory Pointer in CCSPlayerInventory. 866 | * 867 | * @noreturn 868 | */ 869 | function void (int iClient, CCSPlayerInventory pInventory); 870 | }; 871 | 872 | 873 | 874 | /** 875 | * Gets PTaH Version. 876 | * 877 | * @param sBuffer Destination string buffer. 878 | * @param iLen Maximum length of output string buffer.. 879 | * 880 | * @return Return PTaH int Version. Example: 108 if sBuffer = "1.0.8". 881 | */ 882 | native int PTaH_Version(char[] sBuffer = NULL_STRING, int iLen = 0); 883 | 884 | /** 885 | * Enables Hook. 886 | * 887 | * @param EventType Event type. 888 | * @param HookType Hook/Unhook. 889 | * @param Callback Callback. 890 | * 891 | * @return Is hook successful. 892 | * 893 | * @error Invalid PTaH_HookEvent type. 894 | */ 895 | native bool PTaH(PTaH_HookEvent EventType, PTaH_HookType HookType, PTaHCB Callback); 896 | 897 | /** 898 | * Gets CEconItemDefinition by definition name. 899 | * 900 | * @param sDefName Item definition name. 901 | * 902 | * @return Returns pointer in CEconItemDefinition. 903 | */ 904 | native CEconItemDefinition PTaH_GetItemDefinitionByName(const char[] sDefName); 905 | 906 | /** 907 | * Gets CEconItemDefinition by definition index. 908 | * 909 | * @param iDefIndex Definition index. 910 | * 911 | * @return Returns CEconItemDefinition. 912 | */ 913 | native CEconItemDefinition PTaH_GetItemDefinitionByDefIndex(int iDefIndex); 914 | 915 | /** 916 | * Gets CEconItemAttributeDefinition by definition name. 917 | * 918 | * @param sDefName Attribute definition name. 919 | * 920 | * @return Returns CEconItemAttributeDefinition. 921 | */ 922 | native CEconItemAttributeDefinition PTaH_GetAttributeDefinitionByName(const char[] sDefName); 923 | 924 | /** 925 | * Gets CEconItemAttributeDefinition by definition index. 926 | * 927 | * @param iDefIndex Attribute definition index. 928 | * 929 | * @return Returns CEconItemAttributeDefinition. 930 | */ 931 | native CEconItemAttributeDefinition PTaH_GetAttributeDefinitionByDefIndex(int iDefIndex); 932 | 933 | /** 934 | * Gets CEconItemView from entity with type DT_EconEntity. 935 | * 936 | * @param iEntity Entity index. 937 | * 938 | * @return Returns pointer in CEconItemView. 939 | * 940 | * @error Invalid entity or entity type DT_EconEntity is not found. 941 | */ 942 | native CEconItemView PTaH_GetEconItemViewFromEconEntity(int iEntity); 943 | 944 | /** 945 | * Gets CCSPlayerInventory of Player. 946 | * 947 | * @note Use event hook "player_spawn" for get an early 948 | * stage of loading Shared Data in the inventory 949 | * 950 | * @param iClient Client index. 951 | * 952 | * @return Returns pointer in CCSPlayerInventory. 953 | * 954 | * @error Invalid client index. 955 | */ 956 | native CCSPlayerInventory PTaH_GetPlayerInventory(int iClient); 957 | 958 | /** 959 | * It gives the player item with the specified CEconItemView. 960 | * 961 | * @param iClient Client index. 962 | * @param sClassname Item classname. 963 | * @param pItemView Customization item. 964 | * @param vecOrigin Coordinates the item will be created at, or NULL_VECTOR. 965 | * 966 | * @return Return entity index. 967 | * 968 | * @error Invalid client index. 969 | */ 970 | native int PTaH_GivePlayerItem(int iClient, const char[] sClassname, CEconItemView pItemView = CEconItemView_NULL, const float vecOrigin[3] = NULL_VECTOR); 971 | 972 | /** 973 | * Sends to player a full update packet. 974 | * 975 | * @param iClient Client index. 976 | * 977 | * @noreturn 978 | * 979 | * @error Invalid client index, or client is fake. 980 | */ 981 | native void PTaH_ForceFullUpdate(int iClient); 982 | 983 | /** 984 | * Spawn item by a definition index at the coordionates. 985 | * 986 | * @param iDefIndex Definition index. 987 | * @param vecOrigin Coordinates the item will be created at. 988 | * @param flAngles Angles the item will be created at. 989 | * 990 | * @return Return index item. 991 | * 992 | * @error vecOrigin == NULL_VECTOR or invalid definition index. 993 | */ 994 | native int PTaH_SpawnItemFromDefIndex(int iDefIndex, const float vecOrigin[3], const float flAngles[3] = {0.0, 0.0, 0.0}); 995 | 996 | /** 997 | * Emulate bullet shot on the server and does the damage calculations. 998 | * 999 | * @param iClient Client index. 1000 | * @param pItemView Customization item. 1001 | * @param vecOrigin Coordinates the bullet will be created at. 1002 | * @param flAngles Angles the bullet will be created at. 1003 | * @param iMode Mode index. 1004 | * @param iSeed Randomizing seed. 1005 | * @param flInaccuracy Inaccuracy variable. 1006 | * @param flSpread Spread variable. 1007 | * @param flFishtail Accuracy Fishtail. 1008 | * @param iSoundType Sound type. (1 or 12 for silenced, 0 for none sound) 1009 | * @param flRecoilIndex Recoil variable. 1010 | * 1011 | * @noreturn 1012 | * 1013 | * @error Invalid client index or CEconItemView == NULL or vecOrigin == NULL_VECTOR. 1014 | */ 1015 | native void PTaH_FX_FireBullets(int iClient, CEconItemView pItemView, const float vecOrigin[3], const float flAngles[3], int iMode, int iSeed, float flInaccuracy, float flSpread, float flFishtail, int iSoundType, float flRecoilIndex); 1016 | 1017 | /** 1018 | * Sets the player avatar for targets. 1019 | * @note As a converter, use image with size 64x64 1020 | * cl_avatar_convert_rgb - for convert avatars/image.png files to avatars/image.rgb . 1021 | * 1022 | * @param iClient Client index. 1023 | * @param iTargets Array containing player indexes to avatar broadcast. 1024 | * Target must be connected and not fake client. 1025 | * @param iTargetCount Count of targets in the array. 1026 | * @param Avatar Contents of .rgb file. 1027 | * 1028 | * @return Is avatar sets. 1029 | * 1030 | * @error Invalid client or target (in array) index, or not connected, or is fake. 1031 | */ 1032 | native bool PTaH_SetPlayerAvatar(int iClient, const int[] iTargets, int iTargetCount, const char Avatar[PTaH_AVATAR_SIZE]); 1033 | 1034 | /** 1035 | * @deprecated Use CCSPlayerInventory::GetItemInLoadout() for get LoadoutSlot. Will be removed. 1036 | */ 1037 | #pragma deprecated Use CCSPlayerInventory::GetItemInLoadout() instead 1038 | native CEconItemView PTaH_GetItemInLoadout(int iClient, int iTeam, int iLoadoutSlot); 1039 | 1040 | /** 1041 | * @deprecated Use PTaH_GetEconItemViewFromEconEntity() for get CEconItemView from entity. Will be removed. 1042 | */ 1043 | #pragma deprecated Use PTaH_GetEconItemViewFromEconEntity() instead 1044 | native CEconItemView PTaH_GetEconItemViewFromWeapon(int iEntity); 1045 | 1046 | 1047 | 1048 | public Extension __ext_PTaH = 1049 | { 1050 | name = "PTaH", 1051 | file = "PTaH.ext", 1052 | #if defined AUTOLOAD_EXTENSIONS 1053 | autoload = 1, 1054 | #else 1055 | autoload = 0, 1056 | #endif 1057 | #if defined REQUIRE_EXTENSIONS 1058 | required = 1, 1059 | #else 1060 | required = 0, 1061 | #endif 1062 | }; 1063 | 1064 | #if !defined REQUIRE_EXTENSIONS 1065 | public __ext_PTaH_SetNTVOptional() 1066 | { 1067 | MarkNativeAsOptional("PTaH_Version"); 1068 | MarkNativeAsOptional("PTaH"); 1069 | MarkNativeAsOptional("PTaH_GetItemDefinitionByName"); 1070 | MarkNativeAsOptional("PTaH_GetItemDefinitionByDefIndex"); 1071 | MarkNativeAsOptional("PTaH_GetAttributeDefinitionByName"); 1072 | MarkNativeAsOptional("PTaH_GetAttributeDefinitionByDefIndex"); 1073 | MarkNativeAsOptional("PTaH_GetEconItemViewFromEconEntity"); 1074 | MarkNativeAsOptional("PTaH_GetPlayerInventory"); 1075 | MarkNativeAsOptional("PTaH_GivePlayerItem"); 1076 | MarkNativeAsOptional("PTaH_ForceFullUpdate"); 1077 | MarkNativeAsOptional("PTaH_SpawnItemFromDefIndex"); 1078 | MarkNativeAsOptional("PTaH_FX_FireBullets"); 1079 | MarkNativeAsOptional("PTaH_SetPlayerAvatar"); 1080 | 1081 | MarkNativeAsOptional("CEconItemDefinition.GetDefinitionIndex"); 1082 | MarkNativeAsOptional("CEconItemDefinition.GetDefinitionName"); 1083 | MarkNativeAsOptional("CEconItemDefinition.GetLoadoutSlot"); 1084 | MarkNativeAsOptional("CEconItemDefinition.GetUsedByTeam"); 1085 | MarkNativeAsOptional("CEconItemDefinition.GetNumSupportedStickerSlots"); 1086 | MarkNativeAsOptional("CEconItemDefinition.GetEconImage"); 1087 | MarkNativeAsOptional("CEconItemDefinition.GetModel"); 1088 | 1089 | MarkNativeAsOptional("CEconItemView.GetCustomPaintKitIndex"); 1090 | MarkNativeAsOptional("CEconItemView.GetCustomPaintKitSeed"); 1091 | MarkNativeAsOptional("CEconItemView.GetCustomPaintKitWear"); 1092 | MarkNativeAsOptional("CEconItemView.GetStickerAttributeBySlotIndex"); 1093 | MarkNativeAsOptional("CEconItemView.IsTradable"); 1094 | MarkNativeAsOptional("CEconItemView.IsMarketable"); 1095 | MarkNativeAsOptional("CEconItemView.GetItemDefinition"); 1096 | MarkNativeAsOptional("CEconItemView.GetAccountID"); 1097 | MarkNativeAsOptional("CEconItemView.GetItemID"); 1098 | MarkNativeAsOptional("CEconItemView.GetQuality"); 1099 | MarkNativeAsOptional("CEconItemView.GetRarity"); 1100 | MarkNativeAsOptional("CEconItemView.GetFlags"); 1101 | MarkNativeAsOptional("CEconItemView.GetOrigin"); 1102 | MarkNativeAsOptional("CEconItemView.GetCustomName"); 1103 | MarkNativeAsOptional("CEconItemView.GetStatTrakKill"); 1104 | MarkNativeAsOptional("CEconItemView.GetAttributeValueByIndex"); 1105 | MarkNativeAsOptional("CEconItemView.AttributeList.get"); 1106 | MarkNativeAsOptional("CEconItemView.NetworkedDynamicAttributesForDemos.get"); 1107 | 1108 | MarkNativeAsOptional("CCSPlayerInventory.GetItemInLoadout"); 1109 | MarkNativeAsOptional("CCSPlayerInventory.GetItemsCount"); 1110 | MarkNativeAsOptional("CCSPlayerInventory.GetItem"); 1111 | 1112 | MarkNativeAsOptional("CAttributeList.DestroyAllAttributes"); 1113 | MarkNativeAsOptional("CAttributeList.GetAttributesCount"); 1114 | MarkNativeAsOptional("CAttributeList.GetAttribute"); 1115 | MarkNativeAsOptional("CAttributeList.GetAttributeByDefIndex"); 1116 | MarkNativeAsOptional("CAttributeList.RemoveAttribute"); 1117 | MarkNativeAsOptional("CAttributeList.RemoveAttributeByDefIndex"); 1118 | MarkNativeAsOptional("CAttributeList.SetOrAddAttributeValue"); 1119 | 1120 | MarkNativeAsOptional("CEconItemAttribute.DefinitionIndex.get"); 1121 | MarkNativeAsOptional("CEconItemAttribute.Value.set"); 1122 | MarkNativeAsOptional("CEconItemAttribute.Value.get"); 1123 | MarkNativeAsOptional("CEconItemAttribute.InitialValue.get"); 1124 | MarkNativeAsOptional("CEconItemAttribute.RefundableCurrency.set"); 1125 | MarkNativeAsOptional("CEconItemAttribute.RefundableCurrency.get"); 1126 | MarkNativeAsOptional("CEconItemAttribute.SetBonus.set"); 1127 | MarkNativeAsOptional("CEconItemAttribute.SetBonus.get"); 1128 | 1129 | MarkNativeAsOptional("CEconItemAttributeDefinition.GetDefinitionIndex"); 1130 | MarkNativeAsOptional("CEconItemAttributeDefinition.GetDefinitionName"); 1131 | MarkNativeAsOptional("CEconItemAttributeDefinition.GetAttributeType"); 1132 | 1133 | // Deprecated 1134 | MarkNativeAsOptional("PTaH_GetItemInLoadout"); 1135 | MarkNativeAsOptional("PTaH_GetEconItemViewFromWeapon"); 1136 | MarkNativeAsOptional("CEconItemDefinition.GetClassName"); 1137 | } 1138 | #endif 1139 | -------------------------------------------------------------------------------- /forwards.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * vim: set ts=4 : 3 | * ============================================================================= 4 | * SourceMod P Tools and Hooks Extension 5 | * Copyright (C) 2016-2023 Phoenix (˙·٠●Феникс●٠·˙). All rights reserved. 6 | * ============================================================================= 7 | * 8 | * This program is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU General Public License, version 3.0, as published by the 10 | * Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 | * details. 16 | * 17 | * You should have received a copy of the GNU General Public License along with 18 | * this program. If not, see . 19 | */ 20 | 21 | #include "extension.h" 22 | #include "forwards.h" 23 | #include "classes.h" 24 | #include "natives.h" 25 | 26 | 27 | decltype(CForwardManager::m_Hooks) CForwardManager::m_Hooks; 28 | CForwardManager g_ForwardManager; 29 | 30 | // GiveNamedItem 31 | SH_DECL_MANUALHOOK5(GiveNamedItem, 0, 0, 0, CBaseEntity*, const char*, int, CEconItemView*, bool, Vector*); 32 | 33 | // WeaponCanUse 34 | SH_DECL_MANUALHOOK1(Weapon_CanUse, 0, 0, 0, bool, CBaseCombatWeapon*); 35 | 36 | // SetModel 37 | SH_DECL_MANUALHOOK1_void(SetEntityModel, 0, 0, 0, const char*); 38 | 39 | // ClientVoiceTo 40 | SH_DECL_HOOK3(IVoiceServer, SetClientListening, SH_NOATTRIB, 0, bool, int, int, bool); 41 | SH_DECL_HOOK1_void(IServerGameClients, ClientVoice, SH_NOATTRIB, 0, edict_t*); 42 | 43 | // ClientPrint 44 | SH_DECL_HOOK0_void_vafmt(IClient, ClientPrintf, SH_NOATTRIB, 0); 45 | #ifdef PLATFORM_LINUX 46 | SH_DECL_MANUALHOOK0_void_vafmt(CBaseClient_ClientPrintf, 0, 0, 0); 47 | #endif 48 | 49 | // ExecuteStringCommand 50 | SH_DECL_HOOK1(IClient, ExecuteStringCommand, SH_NOATTRIB, 0, bool, const char*); 51 | #ifdef PLATFORM_LINUX 52 | SH_DECL_MANUALHOOK1(CGameClient_ExecuteStringCommand, 0, 0, 0, bool, const char*); 53 | #endif 54 | 55 | // ClientConnect 56 | SH_DECL_MANUALHOOK13(ConnectClient, 0, 0, 0, IClient*, const ns_address&, int, int, int, const char*, const char*, const char*, int, CUtlVector&, bool, CrossPlayPlatform_t, const byte*, int); 57 | 58 | // InventoryUpdate 59 | SH_DECL_MANUALHOOK0_void(SendInventoryUpdateEvent, 0, 0, 0); 60 | 61 | 62 | void CForwardManager::Init() 63 | { 64 | for(auto& hook : m_Hooks) 65 | { 66 | hook.second->Init(); 67 | } 68 | } 69 | 70 | void CForwardManager::Shutdown() 71 | { 72 | for(auto& hook : m_Hooks) 73 | { 74 | hook.second->Shutdown(); 75 | } 76 | } 77 | 78 | bool CForwardManager::UpdateHook(PTaH_HookEvent htType, IPluginFunction* pFunction, bool bHook) 79 | { 80 | auto hook = m_Hooks.find(htType); 81 | if(hook != m_Hooks.end()) 82 | { 83 | return hook->second->UpdateHook(pFunction, bHook); 84 | } 85 | 86 | return false; 87 | } 88 | 89 | CForwardManager::CBaseHook::CBaseHook() 90 | { 91 | m_pForward = nullptr; 92 | m_bHooked = false; 93 | } 94 | 95 | void CForwardManager::CBaseHook::Shutdown() 96 | { 97 | if(m_pForward) 98 | { 99 | if(m_bHooked) 100 | { 101 | OnInternalHookDeactivated(); 102 | } 103 | 104 | forwards->ReleaseForward(m_pForward); 105 | } 106 | } 107 | 108 | bool CForwardManager::CBaseHook::UpdateHook(SourcePawn::IPluginFunction* pFunction, bool bHook) 109 | { 110 | if(m_pForward) 111 | { 112 | bool bRet = bHook ? m_pForward->AddFunction(pFunction) : m_pForward->RemoveFunction(pFunction); 113 | 114 | UpdateInternalHook(); 115 | 116 | return bRet; 117 | } 118 | 119 | return false; 120 | } 121 | 122 | void CForwardManager::CBaseHook::UpdateInternalHook() 123 | { 124 | if(m_pForward && (m_pForward->GetFunctionCount() > 0) != m_bHooked) 125 | { 126 | m_bHooked = !m_bHooked; 127 | 128 | if(m_bHooked) 129 | { 130 | OnInternalHookActivated(); 131 | } 132 | else 133 | { 134 | OnInternalHookDeactivated(); 135 | } 136 | } 137 | } 138 | 139 | void CForwardManager::CBaseHook::OnInternalHookActivated() 140 | { 141 | plsys->AddPluginsListener(this); 142 | } 143 | 144 | void CForwardManager::CBaseHook::OnInternalHookDeactivated() 145 | { 146 | plsys->RemovePluginsListener(this); 147 | } 148 | 149 | void CForwardManager::CBaseHook::OnPluginUnloaded(IPlugin* plugin) 150 | { 151 | UpdateInternalHook(); 152 | } 153 | 154 | CForwardManager::CBaseManualPlayerHook::CBaseManualPlayerHook() 155 | { 156 | memset(m_iHookID, 0xFF, sizeof(m_iHookID)); 157 | } 158 | 159 | void CForwardManager::CBaseManualPlayerHook::OnInternalHookActivated() 160 | { 161 | BaseClass::OnInternalHookActivated(); 162 | playerhelpers->AddClientListener(this); 163 | 164 | int iMaxClients = playerhelpers->GetMaxClients(); 165 | IGamePlayer* pPlayer; 166 | for (int i = 1; i <= iMaxClients; i++) if ((pPlayer = playerhelpers->GetGamePlayer(i)) && pPlayer->IsInGame()) 167 | { 168 | OnClientPutInServer(i); 169 | } 170 | } 171 | 172 | void CForwardManager::CBaseManualPlayerHook::OnInternalHookDeactivated() 173 | { 174 | BaseClass::OnInternalHookDeactivated(); 175 | playerhelpers->RemoveClientListener(this); 176 | 177 | int iMaxClients = playerhelpers->GetMaxClients(); 178 | for (int i = 1; i <= iMaxClients; i++) 179 | { 180 | OnClientDisconnected(i); 181 | } 182 | } 183 | 184 | void CForwardManager::CBaseManualPlayerHook::OnClientPutInServer(int iClient) 185 | { 186 | m_iHookID[iClient] = ManualHook(iClient); 187 | } 188 | 189 | void CForwardManager::CBaseManualPlayerHook::OnClientDisconnected(int iClient) 190 | { 191 | if(m_iHookID[iClient] != -1) 192 | { 193 | SH_REMOVE_HOOK_ID(m_iHookID[iClient]); 194 | m_iHookID[iClient] = -1; 195 | } 196 | } 197 | 198 | CForwardManager::CBaseVPHook::CBaseVPHook(bool bInGame) 199 | { 200 | m_iHookID = -1; 201 | m_bInGame = bInGame; 202 | } 203 | 204 | void CForwardManager::CBaseVPHook::OnClientValid(int iClient) 205 | { 206 | // Protection against multiple calls in the same frame 207 | if(m_iHookID == -1) 208 | { 209 | m_iHookID = VPHook(iClient); 210 | 211 | // Using RemoveClientListener inside the handler will cause a crash 212 | smutils->AddFrameAction([](void* pThis) 213 | { 214 | playerhelpers->RemoveClientListener(reinterpret_cast(pThis)); 215 | }, this); 216 | } 217 | } 218 | 219 | void CForwardManager::CBaseVPHook::OnInternalHookActivated() 220 | { 221 | CBaseHook::OnInternalHookActivated(); 222 | 223 | auto fPlayerValid = m_bInGame ? &IGamePlayer::IsInGame : &IGamePlayer::IsConnected; 224 | int iMaxClients = playerhelpers->GetMaxClients(); 225 | IGamePlayer* pPlayer; 226 | for (int i = 1; i <= iMaxClients; i++) if ((pPlayer = playerhelpers->GetGamePlayer(i)) && (pPlayer->*fPlayerValid)()) 227 | { 228 | m_iHookID = VPHook(i); 229 | 230 | return; 231 | } 232 | 233 | playerhelpers->AddClientListener(this); 234 | } 235 | 236 | void CForwardManager::CBaseVPHook::OnInternalHookDeactivated() 237 | { 238 | CBaseHook::OnInternalHookDeactivated(); 239 | 240 | if(m_iHookID != -1) 241 | { 242 | SH_REMOVE_HOOK_ID(m_iHookID); 243 | m_iHookID = -1; 244 | } 245 | else 246 | { 247 | playerhelpers->RemoveClientListener(this); 248 | } 249 | } 250 | 251 | void CForwardManager::CBaseVPHook::OnClientConnected(int iClient) 252 | { 253 | if(!m_bInGame) 254 | { 255 | OnClientValid(iClient); 256 | } 257 | } 258 | 259 | void CForwardManager::CBaseVPHook::OnClientPutInServer(int iClient) 260 | { 261 | if(m_bInGame) 262 | { 263 | OnClientValid(iClient); 264 | } 265 | } 266 | 267 | CForwardManager::CBaseClientHook::CBaseClientHook() : CBaseVPHook(false) 268 | { 269 | #ifdef PLATFORM_LINUX 270 | m_iGameHookId = -1; 271 | #endif 272 | } 273 | 274 | #ifdef PLATFORM_LINUX 275 | void CForwardManager::CBaseClientHook::OnInternalHookDeactivated() 276 | { 277 | CBaseHook::OnInternalHookDeactivated(); 278 | 279 | if(m_iGameHookId != -1) 280 | { 281 | SH_REMOVE_HOOK_ID(m_iGameHookId); 282 | m_iGameHookId = -1; 283 | } 284 | } 285 | 286 | int CForwardManager::CBaseClientHook::GetParentVFuncOffset(IClient* pClient, size_t vtbIndex) 287 | { 288 | CGameClient* pGameClient = dynamic_cast(pClient); 289 | 290 | // Getting the trampoline function address 291 | // If the function has been patched, get the original via GetOrigVfnPtrEntry 292 | void** vfnPtr = *reinterpret_cast(pClient) + vtbIndex; 293 | void* vfnOrigPtr = SH_GLOB_SHPTR->GetOrigVfnPtrEntry(vfnPtr); 294 | uintptr_t tmplPtr = reinterpret_cast(vfnOrigPtr ? vfnOrigPtr : *vfnPtr); 295 | 296 | // Checking that it is a trampoline function 297 | // sub dword ptr [esp+4], 4 298 | if(*reinterpret_cast(tmplPtr) != 0x4246C83) 299 | { 300 | return -1; 301 | } 302 | 303 | uint8_t jmp = *reinterpret_cast(tmplPtr + 0x5); 304 | // jmp jmp short 305 | if(jmp != 0xE9 && jmp != 0xEB) 306 | { 307 | return -1; 308 | } 309 | 310 | void* funcPtr; 311 | // Getting the function address 312 | { 313 | uintptr_t jmpPtr = tmplPtr + 0x5; 314 | if(jmp == 0xE9) 315 | { 316 | funcPtr = reinterpret_cast(jmpPtr + *reinterpret_cast(jmpPtr + 0x1) + 0x5); 317 | } 318 | else 319 | { 320 | funcPtr = reinterpret_cast(jmpPtr + *reinterpret_cast(jmpPtr + 0x1) + 0x2); 321 | } 322 | } 323 | 324 | // Finding a function in the CGameClient virtual table 325 | for(int i = 0; i < 90; i++) 326 | { 327 | void** vfnGamePtr = *reinterpret_cast(pGameClient) + i; 328 | void* vfnGameOrigPtr = SH_GLOB_SHPTR->GetOrigVfnPtrEntry(vfnGamePtr); 329 | 330 | if((vfnGameOrigPtr ? vfnGameOrigPtr : *vfnGamePtr) == funcPtr) 331 | { 332 | return i; 333 | } 334 | } 335 | 336 | return -1; 337 | } 338 | #endif 339 | inline IClient* CForwardManager::CBaseClientHook::ForceCastToIClient(IClient* pClient) 340 | { 341 | #ifdef PLATFORM_LINUX 342 | // Checking offset to this (CGameClient 0) (IClient -4) 343 | if(*reinterpret_cast(*reinterpret_cast(pClient) - 0x8) == 0) 344 | { 345 | pClient = reinterpret_cast(pClient); 346 | } 347 | #endif 348 | 349 | return pClient; 350 | } 351 | 352 | bool CForwardManager::GiveNamedItemHook::Configure() 353 | { 354 | int offset = -1; 355 | if(!g_pGameConf[GameConf_SDKT]->GetOffset("GiveNamedItem", &offset)) 356 | { 357 | smutils->LogError(myself, "Failed to get GiveNamedItem offset, hook %s will be unavailable.", GetHookName()); 358 | 359 | return false; 360 | } 361 | 362 | SH_MANUALHOOK_RECONFIGURE(GiveNamedItem, offset, 0, 0); 363 | 364 | return true; 365 | } 366 | 367 | DETOUR_DECL_MEMBER4(CCSPlayer_FindMatchingWeaponsForTeamLoadout, uint64_t, const char*, szItem, int, iTeam, bool, bMustBeTeamSpecific, CUtlVector&, matchingWeapons) 368 | { 369 | // Function can be called twice if the game mode is GunGame 370 | if(g_ForwardManager.m_GiveNamedItemPreHook.m_iFrameCount == gpGlobals->framecount) 371 | { 372 | return 0LL; 373 | } 374 | 375 | return DETOUR_MEMBER_CALL(CCSPlayer_FindMatchingWeaponsForTeamLoadout)(szItem, iTeam, bMustBeTeamSpecific, matchingWeapons); 376 | } 377 | 378 | CForwardManager::GiveNamedItemPreHook::GiveNamedItemPreHook() 379 | { 380 | m_Hooks[PTaH_GiveNamedItemPre] = this; 381 | 382 | m_pFindMatchingWeaponsForTeamLoadoutHook = nullptr; 383 | m_iFrameCount = 0; 384 | } 385 | 386 | void CForwardManager::GiveNamedItemPreHook::Init() 387 | { 388 | if(BaseClass::Configure()) 389 | { 390 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Hook, 6, nullptr, Param_Cell, Param_String, Param_CellByRef, Param_CellByRef, Param_CellByRef, Param_Array); 391 | 392 | m_pFindMatchingWeaponsForTeamLoadoutHook = DETOUR_CREATE_MEMBER(CCSPlayer_FindMatchingWeaponsForTeamLoadout, "CCSPlayer::FindMatchingWeaponsForTeamLoadout"); 393 | if(!m_pFindMatchingWeaponsForTeamLoadoutHook) 394 | { 395 | smutils->LogError(myself, "Detour failed CCSPlayer::FindMatchingWeaponsForTeamLoadout, %s hook functionality will be limited.", GetHookName()); 396 | } 397 | } 398 | } 399 | 400 | void CForwardManager::GiveNamedItemPreHook::Shutdown() 401 | { 402 | BaseClass::Shutdown(); 403 | 404 | if(m_pFindMatchingWeaponsForTeamLoadoutHook) 405 | { 406 | m_pFindMatchingWeaponsForTeamLoadoutHook->Destroy(); 407 | } 408 | } 409 | 410 | int CForwardManager::GiveNamedItemPreHook::ManualHook(int iClient) 411 | { 412 | return SH_ADD_MANUALHOOK(GiveNamedItem, gamehelpers->ReferenceToEntity(iClient), SH_MEMBER(this, &CForwardManager::GiveNamedItemPreHook::Handler), false); 413 | } 414 | 415 | void CForwardManager::GiveNamedItemPreHook::OnInternalHookActivated() 416 | { 417 | BaseClass::OnInternalHookActivated(); 418 | 419 | if(m_pFindMatchingWeaponsForTeamLoadoutHook) 420 | { 421 | m_pFindMatchingWeaponsForTeamLoadoutHook->EnableDetour(); 422 | } 423 | } 424 | 425 | void CForwardManager::GiveNamedItemPreHook::OnInternalHookDeactivated() 426 | { 427 | BaseClass::OnInternalHookDeactivated(); 428 | 429 | if(m_pFindMatchingWeaponsForTeamLoadoutHook) 430 | { 431 | m_pFindMatchingWeaponsForTeamLoadoutHook->DisableDetour(); 432 | } 433 | } 434 | 435 | CBaseEntity* CForwardManager::GiveNamedItemPreHook::Handler(const char* pchName, int iSubType, CEconItemView* pScriptItem, bool bForce, Vector* pOrigin) 436 | { 437 | m_iFrameCount = 0; 438 | 439 | if(!pchName) 440 | { 441 | RETURN_META_VALUE(MRES_IGNORED, nullptr); 442 | } 443 | 444 | cell_t res = Pl_Continue; 445 | cell_t pScriptItemNew = reinterpret_cast(pScriptItem); 446 | cell_t IgnoredCEconItemViewNew = false; 447 | cell_t OriginIsNull = pOrigin == nullptr; 448 | cell_t Origin[3] = { 0, 0, 0 }; 449 | char szNewName[64]; 450 | 451 | V_strncpy(szNewName, pchName, sizeof(szNewName)); 452 | 453 | if(pOrigin) 454 | { 455 | Origin[0] = sp_ftoc(pOrigin->x); 456 | Origin[1] = sp_ftoc(pOrigin->y); 457 | Origin[2] = sp_ftoc(pOrigin->z); 458 | } 459 | 460 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(META_IFACEPTR(CBaseEntity))); 461 | m_pForward->PushStringEx(szNewName, sizeof(szNewName), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); 462 | m_pForward->PushCellByRef(&pScriptItemNew); 463 | m_pForward->PushCellByRef(&IgnoredCEconItemViewNew); 464 | m_pForward->PushCellByRef(&OriginIsNull); 465 | m_pForward->PushArray(Origin, 3, SM_PARAM_COPYBACK); 466 | m_pForward->Execute(&res); 467 | 468 | if(res != Pl_Continue) 469 | { 470 | if(res == Pl_Changed) 471 | { 472 | if(IgnoredCEconItemViewNew) 473 | { 474 | m_iFrameCount = gpGlobals->framecount; 475 | pScriptItemNew = 0; 476 | } 477 | 478 | if(OriginIsNull == false) 479 | { 480 | Vector vecOrigin(sp_ctof(Origin[0]), sp_ctof(Origin[1]), sp_ctof(Origin[2])); 481 | 482 | RETURN_META_VALUE_MNEWPARAMS(MRES_HANDLED, nullptr, GiveNamedItem, (szNewName, iSubType, reinterpret_cast(pScriptItemNew), bForce, &vecOrigin)); 483 | } 484 | 485 | RETURN_META_VALUE_MNEWPARAMS(MRES_HANDLED, nullptr, GiveNamedItem, (szNewName, iSubType, reinterpret_cast(pScriptItemNew), bForce, nullptr)); 486 | } 487 | 488 | RETURN_META_VALUE(MRES_SUPERCEDE, nullptr); 489 | } 490 | 491 | RETURN_META_VALUE(MRES_IGNORED, nullptr); 492 | } 493 | 494 | CForwardManager::GiveNamedItemPostHook::GiveNamedItemPostHook() 495 | { 496 | m_Hooks[PTaH_GiveNamedItemPost] = this; 497 | } 498 | 499 | void CForwardManager::GiveNamedItemPostHook::Init() 500 | { 501 | if(BaseClass::Configure()) 502 | { 503 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Ignore, 6, nullptr, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell, Param_Array); 504 | } 505 | } 506 | 507 | int CForwardManager::GiveNamedItemPostHook::ManualHook(int iClient) 508 | { 509 | return SH_ADD_MANUALHOOK(GiveNamedItem, gamehelpers->ReferenceToEntity(iClient), SH_MEMBER(this, &CForwardManager::GiveNamedItemPostHook::Handler), true); 510 | } 511 | 512 | CBaseEntity* CForwardManager::GiveNamedItemPostHook::Handler(const char* pchName, int iSubType, CEconItemView* pScriptItem, bool bForce, Vector* pOrigin) 513 | { 514 | if(!pchName) 515 | { 516 | RETURN_META_VALUE(MRES_IGNORED, nullptr); 517 | } 518 | 519 | cell_t Origin[3] = { 0, 0, 0 }; 520 | 521 | if(pOrigin) 522 | { 523 | Origin[0] = sp_ftoc(pOrigin->x); 524 | Origin[1] = sp_ftoc(pOrigin->y); 525 | Origin[2] = sp_ftoc(pOrigin->z); 526 | } 527 | 528 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(META_IFACEPTR(CBaseEntity))); 529 | m_pForward->PushString(pchName); 530 | m_pForward->PushCell(reinterpret_cast(pScriptItem)); 531 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(META_RESULT_ORIG_RET(CBaseEntity*))); 532 | m_pForward->PushCell(pOrigin == nullptr); 533 | m_pForward->PushArray(Origin, 3); 534 | m_pForward->Execute(nullptr); 535 | 536 | RETURN_META_VALUE(MRES_IGNORED, nullptr); 537 | } 538 | 539 | bool CForwardManager::WeaponCanUseHook::Configure() 540 | { 541 | int offset = -1; 542 | if(!g_pGameConf[GameConf_SDKH]->GetOffset("Weapon_CanUse", &offset)) 543 | { 544 | smutils->LogError(myself, "Failed to get Weapon_CanUse offset, hook %s will be unavailable.", GetHookName()); 545 | 546 | return false; 547 | } 548 | 549 | SH_MANUALHOOK_RECONFIGURE(Weapon_CanUse, offset, 0, 0); 550 | 551 | return true; 552 | } 553 | 554 | CForwardManager::WeaponCanUsePreHook::WeaponCanUsePreHook() 555 | { 556 | m_Hooks[PTaH_WeaponCanUsePre] = this; 557 | } 558 | 559 | void CForwardManager::WeaponCanUsePreHook::Init() 560 | { 561 | if(BaseClass::Configure()) 562 | { 563 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Hook, 3, nullptr, Param_Cell, Param_Cell, Param_CellByRef); 564 | } 565 | } 566 | 567 | int CForwardManager::WeaponCanUsePreHook::ManualHook(int iClient) 568 | { 569 | return SH_ADD_MANUALHOOK(Weapon_CanUse, gamehelpers->ReferenceToEntity(iClient), SH_MEMBER(this, &CForwardManager::WeaponCanUsePreHook::Handler), false); 570 | } 571 | 572 | bool CForwardManager::WeaponCanUsePreHook::Handler(CBaseCombatWeapon* pWeapon) 573 | { 574 | cell_t res = Pl_Continue; 575 | cell_t ret = META_RESULT_ORIG_RET(bool); 576 | 577 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(META_IFACEPTR(CBaseEntity))); 578 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(pWeapon)); 579 | m_pForward->PushCellByRef(&ret); 580 | m_pForward->Execute(&res); 581 | 582 | if(res != Pl_Continue) 583 | { 584 | if(res == Pl_Changed) 585 | { 586 | RETURN_META_VALUE(MRES_SUPERCEDE, static_cast(ret)); 587 | } 588 | 589 | RETURN_META_VALUE(MRES_SUPERCEDE, false); 590 | } 591 | 592 | RETURN_META_VALUE(MRES_IGNORED, true); 593 | } 594 | 595 | CForwardManager::WeaponCanUsePostHook::WeaponCanUsePostHook() 596 | { 597 | m_Hooks[PTaH_WeaponCanUsePost] = this; 598 | } 599 | 600 | void CForwardManager::WeaponCanUsePostHook::Init() 601 | { 602 | if(BaseClass::Configure()) 603 | { 604 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Ignore, 3, nullptr, Param_Cell, Param_Cell, Param_Cell); 605 | } 606 | } 607 | 608 | int CForwardManager::WeaponCanUsePostHook::ManualHook(int iClient) 609 | { 610 | return SH_ADD_MANUALHOOK(Weapon_CanUse, gamehelpers->ReferenceToEntity(iClient), SH_MEMBER(this, &CForwardManager::WeaponCanUsePostHook::Handler), true); 611 | } 612 | 613 | bool CForwardManager::WeaponCanUsePostHook::Handler(CBaseCombatWeapon* pWeapon) 614 | { 615 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(META_IFACEPTR(CBaseEntity))); 616 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(pWeapon)); 617 | m_pForward->PushCell(META_RESULT_ORIG_RET(bool)); 618 | m_pForward->Execute(nullptr); 619 | 620 | RETURN_META_VALUE(MRES_IGNORED, true); 621 | } 622 | 623 | bool CForwardManager::SetPlayerModelHook::Configure() 624 | { 625 | int offset = -1; 626 | if(!g_pGameConf[GameConf_SDKT]->GetOffset("SetEntityModel", &offset)) 627 | { 628 | smutils->LogError(myself, "Failed to get SetEntityModel offset, hook %s will be unavailable.", GetHookName()); 629 | 630 | return false; 631 | } 632 | 633 | SH_MANUALHOOK_RECONFIGURE(SetEntityModel, offset, 0, 0); 634 | 635 | return true; 636 | } 637 | 638 | CForwardManager::SetPlayerModelPreHook::SetPlayerModelPreHook() 639 | { 640 | m_Hooks[PTaH_SetPlayerModelPre] = this; 641 | } 642 | 643 | void CForwardManager::SetPlayerModelPreHook::Init() 644 | { 645 | if(BaseClass::Configure()) 646 | { 647 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Hook, 3, nullptr, Param_Cell, Param_String, Param_String); 648 | } 649 | } 650 | 651 | int CForwardManager::SetPlayerModelPreHook::ManualHook(int iClient) 652 | { 653 | return SH_ADD_MANUALHOOK(SetEntityModel, gamehelpers->ReferenceToEntity(iClient), SH_MEMBER(this, &CForwardManager::SetPlayerModelPreHook::Handler), false); 654 | } 655 | 656 | void CForwardManager::SetPlayerModelPreHook::Handler(const char* pszModelName) 657 | { 658 | cell_t res = Pl_Continue; 659 | int iClient = gamehelpers->EntityToBCompatRef(META_IFACEPTR(CBaseEntity)); 660 | char szModelNewName[256]; 661 | 662 | V_strncpy(szModelNewName, pszModelName, sizeof(szModelNewName)); 663 | 664 | m_pForward->PushCell(iClient); 665 | m_pForward->PushString(playerhelpers->GetGamePlayer(iClient)->GetPlayerInfo()->GetModelName()); 666 | m_pForward->PushStringEx(szModelNewName, sizeof(szModelNewName), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); 667 | m_pForward->Execute(&res); 668 | 669 | if(res != Pl_Continue) 670 | { 671 | if(res == Pl_Changed) 672 | { 673 | RETURN_META_MNEWPARAMS(MRES_HANDLED, SetEntityModel, (szModelNewName)); 674 | } 675 | 676 | RETURN_META(MRES_SUPERCEDE); 677 | } 678 | 679 | RETURN_META(MRES_IGNORED); 680 | } 681 | 682 | CForwardManager::SetPlayerModelPostHook::SetPlayerModelPostHook() 683 | { 684 | m_Hooks[PTaH_SetPlayerModelPost] = this; 685 | } 686 | 687 | void CForwardManager::SetPlayerModelPostHook::Init() 688 | { 689 | if(BaseClass::Configure()) 690 | { 691 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Ignore, 2, nullptr, Param_Cell, Param_String); 692 | } 693 | } 694 | 695 | int CForwardManager::SetPlayerModelPostHook::ManualHook(int iClient) 696 | { 697 | return SH_ADD_MANUALHOOK(SetEntityModel, gamehelpers->ReferenceToEntity(iClient), SH_MEMBER(this, &CForwardManager::SetPlayerModelPostHook::Handler), true); 698 | } 699 | 700 | void CForwardManager::SetPlayerModelPostHook::Handler(const char* pszModelName) 701 | { 702 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(META_IFACEPTR(CBaseEntity))); 703 | m_pForward->PushString(pszModelName); 704 | m_pForward->Execute(nullptr); 705 | 706 | RETURN_META(MRES_IGNORED); 707 | } 708 | 709 | CForwardManager::ClientVoiceToPreHook::ClientVoiceToPreHook() 710 | { 711 | m_Hooks[PTaH_ClientVoiceToPre] = this; 712 | 713 | memset(m_bStartVoice, 0x0, sizeof(m_bStartVoice)); 714 | } 715 | 716 | void CForwardManager::ClientVoiceToPreHook::Init() 717 | { 718 | if(!g_pCPlayerVoiceListener) 719 | { 720 | smutils->LogError(myself, "g_pCPlayerVoiceListener is nullptr, hook ClientVoiceToPre will be unavailable."); 721 | 722 | return; 723 | } 724 | 725 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Hook, 3, nullptr, Param_Cell, Param_Cell, Param_CellByRef); 726 | } 727 | 728 | void CForwardManager::ClientVoiceToPreHook::OnInternalHookActivated() 729 | { 730 | CBaseHook::OnInternalHookActivated(); 731 | 732 | SH_ADD_HOOK(IVoiceServer, SetClientListening, voiceserver, SH_MEMBER(this, &CForwardManager::ClientVoiceToPreHook::Handler), false); 733 | SH_ADD_HOOK(IServerGameClients, ClientVoice, serverClients, SH_MEMBER(this, &CForwardManager::ClientVoiceToPreHook::ClientVoiceHandler), false); 734 | } 735 | 736 | void CForwardManager::ClientVoiceToPreHook::OnInternalHookDeactivated() 737 | { 738 | CBaseHook::OnInternalHookDeactivated(); 739 | 740 | SH_REMOVE_HOOK(IVoiceServer, SetClientListening, voiceserver, SH_MEMBER(this, &CForwardManager::ClientVoiceToPreHook::Handler), false); 741 | SH_REMOVE_HOOK(IServerGameClients, ClientVoice, serverClients, SH_MEMBER(this, &CForwardManager::ClientVoiceToPreHook::ClientVoiceHandler), false); 742 | 743 | memset(m_bStartVoice, 0x0, sizeof(m_bStartVoice)); 744 | } 745 | 746 | bool CForwardManager::ClientVoiceToPreHook::Handler(int iReceiver, int iSender, bool bListen) 747 | { 748 | // IsPlayerSpeaking is required to protect plugins from useless spam, but this has its disadvantage because it needs another hook. 749 | if(iReceiver != iSender && (m_bStartVoice[iSender] || g_pCPlayerVoiceListener->IsPlayerSpeaking(iSender))) 750 | { 751 | cell_t res = Pl_Continue; 752 | cell_t ret = bListen; 753 | 754 | m_pForward->PushCell(iSender); 755 | m_pForward->PushCell(iReceiver); 756 | m_pForward->PushCellByRef(&ret); 757 | m_pForward->Execute(&res); 758 | 759 | if(res != Pl_Continue) 760 | { 761 | if(res == Pl_Changed) 762 | { 763 | RETURN_META_VALUE_NEWPARAMS(MRES_HANDLED, true, &IVoiceServer::SetClientListening, (iReceiver, iSender, ret)); 764 | } 765 | 766 | RETURN_META_VALUE_NEWPARAMS(MRES_HANDLED, true, &IVoiceServer::SetClientListening, (iReceiver, iSender, false)); 767 | } 768 | } 769 | 770 | RETURN_META_VALUE(MRES_IGNORED, true); 771 | } 772 | 773 | void CForwardManager::ClientVoiceToPreHook::ClientVoiceHandler(edict_t* pEdict) 774 | { 775 | int iSender = gamehelpers->IndexOfEdict(pEdict); 776 | 777 | if(!g_pCPlayerVoiceListener->IsPlayerSpeaking(iSender)) 778 | { 779 | m_bStartVoice[iSender] = true; 780 | 781 | IGamePlayer* pPlayer; 782 | int iMaxClients = playerhelpers->GetMaxClients(); 783 | for (int iReceiver = 1; iReceiver <= iMaxClients; iReceiver++) if ((pPlayer = playerhelpers->GetGamePlayer(iReceiver)) && pPlayer->IsInGame()) 784 | { 785 | voiceserver->SetClientListening(iReceiver, iSender, voiceserver->GetClientListening(iReceiver, iSender)); 786 | } 787 | 788 | m_bStartVoice[iSender] = false; 789 | } 790 | 791 | RETURN_META(MRES_IGNORED); 792 | } 793 | 794 | CForwardManager::ClientVoiceToPostHook::ClientVoiceToPostHook() 795 | { 796 | m_Hooks[PTaH_ClientVoiceToPost] = this; 797 | } 798 | 799 | void CForwardManager::ClientVoiceToPostHook::Init() 800 | { 801 | if(!g_pCPlayerVoiceListener) 802 | { 803 | smutils->LogError(myself, "g_pCPlayerVoiceListener is nullptr, hook ClientVoiceToPost will be unavailable."); 804 | 805 | return; 806 | } 807 | 808 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Ignore, 3, nullptr, Param_Cell, Param_Cell, Param_Cell); 809 | } 810 | 811 | void CForwardManager::ClientVoiceToPostHook::OnInternalHookActivated() 812 | { 813 | CBaseHook::OnInternalHookActivated(); 814 | 815 | SH_ADD_HOOK(IVoiceServer, SetClientListening, voiceserver, SH_MEMBER(this, &CForwardManager::ClientVoiceToPostHook::Handler), true); 816 | } 817 | 818 | void CForwardManager::ClientVoiceToPostHook::OnInternalHookDeactivated() 819 | { 820 | CBaseHook::OnInternalHookDeactivated(); 821 | 822 | SH_REMOVE_HOOK(IVoiceServer, SetClientListening, voiceserver, SH_MEMBER(this, &CForwardManager::ClientVoiceToPostHook::Handler), true); 823 | } 824 | 825 | bool CForwardManager::ClientVoiceToPostHook::Handler(int iReceiver, int iSender, bool bListen) 826 | { 827 | if(iReceiver != iSender && g_pCPlayerVoiceListener->IsPlayerSpeaking(iSender)) 828 | { 829 | m_pForward->PushCell(iSender); 830 | m_pForward->PushCell(iReceiver); 831 | m_pForward->PushCell(bListen); 832 | m_pForward->Execute(nullptr); 833 | } 834 | 835 | RETURN_META_VALUE(MRES_IGNORED, true); 836 | } 837 | 838 | CForwardManager::ConsolePrintPreHook::ConsolePrintPreHook() 839 | { 840 | m_Hooks[PTaH_ConsolePrintPre] = this; 841 | } 842 | 843 | void CForwardManager::ConsolePrintPreHook::Init() 844 | { 845 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Hook, 2, nullptr, Param_Cell, Param_String); 846 | } 847 | 848 | int CForwardManager::ConsolePrintPreHook::VPHook(int iClient) 849 | { 850 | IClient* pClient = iserver->GetClient(iClient - 1); 851 | 852 | #ifdef PLATFORM_LINUX 853 | SourceHook::MemFuncInfo mfi; 854 | SourceHook::GetFuncInfo(&IClient::ClientPrintf, mfi); 855 | 856 | int offset = GetParentVFuncOffset(pClient, mfi.vtblindex); 857 | if(offset != -1) 858 | { 859 | SH_MANUALHOOK_RECONFIGURE(CBaseClient_ClientPrintf, offset, 0, 0); 860 | 861 | m_iGameHookId = SH_ADD_MANUALVPHOOK(CBaseClient_ClientPrintf, static_cast(pClient), SH_MEMBER(this, &CForwardManager::ConsolePrintPreHook::Handler), false); 862 | } 863 | else 864 | { 865 | smutils->LogError(myself, "Failed to get CBaseClient::ClientPrintf offset, ConsolePrintPre hook functionality will be limited."); 866 | } 867 | #endif 868 | 869 | return SH_ADD_VPHOOK(IClient, ClientPrintf, pClient, SH_MEMBER(this, &CForwardManager::ConsolePrintPreHook::Handler), false); 870 | } 871 | 872 | void CForwardManager::ConsolePrintPreHook::Handler(const char* szFormat) 873 | { 874 | IClient* pClient = ForceCastToIClient(META_IFACEPTR(IClient)); 875 | 876 | cell_t res = Pl_Continue; 877 | char szMsg[1024]; 878 | 879 | V_strncpy(szMsg, szFormat, sizeof(szMsg)); 880 | 881 | m_pForward->PushCell(pClient->GetPlayerSlot() + 1); 882 | m_pForward->PushStringEx(szMsg, sizeof(szMsg), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); 883 | m_pForward->Execute(&res); 884 | 885 | if(res != Pl_Continue) 886 | { 887 | if(res == Pl_Changed) 888 | { 889 | #ifdef PLATFORM_LINUX 890 | // If it's a CGameClient, the pointers will differ 891 | if(pClient != META_IFACEPTR(IClient)) 892 | { 893 | RETURN_META_MNEWPARAMS(MRES_HANDLED, CBaseClient_ClientPrintf, (szMsg)); 894 | } 895 | #endif 896 | 897 | RETURN_META_NEWPARAMS(MRES_HANDLED, &IClient::ClientPrintf, (szMsg)); 898 | } 899 | 900 | RETURN_META(MRES_SUPERCEDE); 901 | } 902 | 903 | RETURN_META(MRES_IGNORED); 904 | } 905 | 906 | CForwardManager::ConsolePrintPostHook::ConsolePrintPostHook() 907 | { 908 | m_Hooks[PTaH_ConsolePrintPost] = this; 909 | } 910 | 911 | void CForwardManager::ConsolePrintPostHook::Init() 912 | { 913 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Ignore, 2, nullptr, Param_Cell, Param_String); 914 | } 915 | 916 | int CForwardManager::ConsolePrintPostHook::VPHook(int iClient) 917 | { 918 | IClient* pClient = iserver->GetClient(iClient - 1); 919 | 920 | #ifdef PLATFORM_LINUX 921 | SourceHook::MemFuncInfo mfi; 922 | SourceHook::GetFuncInfo(&IClient::ClientPrintf, mfi); 923 | 924 | int offset = GetParentVFuncOffset(pClient, mfi.vtblindex); 925 | if (offset != -1) 926 | { 927 | SH_MANUALHOOK_RECONFIGURE(CBaseClient_ClientPrintf, offset, 0, 0); 928 | 929 | m_iGameHookId = SH_ADD_MANUALVPHOOK(CBaseClient_ClientPrintf, static_cast(pClient), SH_MEMBER(this, &CForwardManager::ConsolePrintPostHook::Handler), true); 930 | } 931 | else 932 | { 933 | smutils->LogError(myself, "Failed to get CBaseClient::ClientPrintf offset, ConsolePrintPost hook functionality will be limited."); 934 | } 935 | #endif 936 | 937 | return SH_ADD_VPHOOK(IClient, ClientPrintf, pClient, SH_MEMBER(this, &CForwardManager::ConsolePrintPostHook::Handler), true); 938 | } 939 | 940 | void CForwardManager::ConsolePrintPostHook::Handler(const char* szFormat) 941 | { 942 | IClient* pClient = ForceCastToIClient(META_IFACEPTR(IClient)); 943 | 944 | m_pForward->PushCell(pClient->GetPlayerSlot() + 1); 945 | m_pForward->PushString(szFormat); 946 | m_pForward->Execute(nullptr); 947 | 948 | RETURN_META(MRES_IGNORED); 949 | } 950 | 951 | CForwardManager::ExecuteStringCommandPreHook::ExecuteStringCommandPreHook() 952 | { 953 | m_Hooks[PTaH_ExecuteStringCommandPre] = this; 954 | } 955 | 956 | void CForwardManager::ExecuteStringCommandPreHook::Init() 957 | { 958 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Hook, 2, nullptr, Param_Cell, Param_String); 959 | } 960 | 961 | int CForwardManager::ExecuteStringCommandPreHook::VPHook(int iClient) 962 | { 963 | IClient* pClient = iserver->GetClient(iClient - 1); 964 | 965 | #ifdef PLATFORM_LINUX 966 | SourceHook::MemFuncInfo mfi; 967 | SourceHook::GetFuncInfo(&IClient::ExecuteStringCommand, mfi); 968 | 969 | int offset = GetParentVFuncOffset(pClient, mfi.vtblindex); 970 | if (offset != -1) 971 | { 972 | SH_MANUALHOOK_RECONFIGURE(CGameClient_ExecuteStringCommand, offset, 0, 0); 973 | 974 | m_iGameHookId = SH_ADD_MANUALVPHOOK(CGameClient_ExecuteStringCommand, static_cast(pClient), SH_MEMBER(this, &CForwardManager::ExecuteStringCommandPreHook::Handler), false); 975 | } 976 | else 977 | { 978 | smutils->LogError(myself, "Failed to get CGameClient::ExecuteStringCommand offset, ExecuteStringCommandPre hook functionality will be limited."); 979 | } 980 | #endif 981 | 982 | return SH_ADD_VPHOOK(IClient, ExecuteStringCommand, pClient, SH_MEMBER(this, &CForwardManager::ExecuteStringCommandPreHook::Handler), false); 983 | } 984 | 985 | bool CForwardManager::ExecuteStringCommandPreHook::Handler(const char *pCommandString) 986 | { 987 | IClient* pClient = ForceCastToIClient(META_IFACEPTR(IClient)); 988 | 989 | cell_t res = Pl_Continue; 990 | char szCommandString[512]; 991 | 992 | V_strncpy(szCommandString, pCommandString, sizeof(szCommandString)); 993 | 994 | m_pForward->PushCell(pClient->GetPlayerSlot() + 1); 995 | m_pForward->PushStringEx(szCommandString, sizeof(szCommandString), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); 996 | m_pForward->Execute(&res); 997 | 998 | if (res != Pl_Continue) 999 | { 1000 | if (res == Pl_Changed) 1001 | { 1002 | #ifdef PLATFORM_LINUX 1003 | // If it's a CGameClient, the pointers will differ 1004 | if (pClient != META_IFACEPTR(IClient)) 1005 | { 1006 | RETURN_META_VALUE_MNEWPARAMS(MRES_HANDLED, true, CGameClient_ExecuteStringCommand, (szCommandString)); 1007 | } 1008 | #endif 1009 | 1010 | RETURN_META_VALUE_NEWPARAMS(MRES_HANDLED, true, &IClient::ExecuteStringCommand, (szCommandString)); 1011 | } 1012 | 1013 | RETURN_META_VALUE(MRES_SUPERCEDE, false); 1014 | } 1015 | 1016 | RETURN_META_VALUE(MRES_IGNORED, true); 1017 | } 1018 | 1019 | CForwardManager::ExecuteStringCommandPostHook::ExecuteStringCommandPostHook() 1020 | { 1021 | m_Hooks[PTaH_ExecuteStringCommandPost] = this; 1022 | } 1023 | 1024 | void CForwardManager::ExecuteStringCommandPostHook::Init() 1025 | { 1026 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Ignore, 2, nullptr, Param_Cell, Param_String); 1027 | } 1028 | 1029 | int CForwardManager::ExecuteStringCommandPostHook::VPHook(int iClient) 1030 | { 1031 | IClient* pClient = iserver->GetClient(iClient - 1); 1032 | 1033 | #ifdef PLATFORM_LINUX 1034 | SourceHook::MemFuncInfo mfi; 1035 | SourceHook::GetFuncInfo(&IClient::ExecuteStringCommand, mfi); 1036 | 1037 | int offset = GetParentVFuncOffset(pClient, mfi.vtblindex); 1038 | if (offset != -1) 1039 | { 1040 | SH_MANUALHOOK_RECONFIGURE(CGameClient_ExecuteStringCommand, offset, 0, 0); 1041 | 1042 | m_iGameHookId = SH_ADD_MANUALVPHOOK(CGameClient_ExecuteStringCommand, static_cast(pClient), SH_MEMBER(this, &CForwardManager::ExecuteStringCommandPostHook::Handler), true); 1043 | } 1044 | else 1045 | { 1046 | smutils->LogError(myself, "Failed to get CGameClient::ExecuteStringCommand offset, ExecuteStringCommandPost hook functionality will be limited."); 1047 | } 1048 | #endif 1049 | 1050 | return SH_ADD_VPHOOK(IClient, ExecuteStringCommand, pClient, SH_MEMBER(this, &CForwardManager::ExecuteStringCommandPostHook::Handler), true); 1051 | } 1052 | 1053 | bool CForwardManager::ExecuteStringCommandPostHook::Handler(const char *pCommandString) 1054 | { 1055 | IClient* pClient = ForceCastToIClient(META_IFACEPTR(IClient)); 1056 | 1057 | m_pForward->PushCell(pClient->GetPlayerSlot() + 1); 1058 | m_pForward->PushString(pCommandString); 1059 | m_pForward->Execute(nullptr); 1060 | 1061 | RETURN_META_VALUE(MRES_IGNORED, true); 1062 | } 1063 | 1064 | CForwardManager::ClientConnectHook::ClientConnectHook() 1065 | { 1066 | m_iHookID = -1; 1067 | } 1068 | 1069 | bool CForwardManager::ClientConnectHook::Configure() 1070 | { 1071 | if(!iserver) 1072 | { 1073 | smutils->LogError(myself, "iserver is nullptr, hook %s will be unavailable.", GetHookName()); 1074 | 1075 | return false; 1076 | } 1077 | 1078 | int offset = -1; 1079 | if(!g_pGameConf[GameConf_PTaH]->GetOffset("CBaseServer::ConnectClient", &offset)) 1080 | { 1081 | smutils->LogError(myself, "Failed to get CBaseServer::ConnectClient offset, hook %s will be unavailable.", GetHookName()); 1082 | 1083 | return false; 1084 | } 1085 | 1086 | SH_MANUALHOOK_RECONFIGURE(ConnectClient, offset, 0, 0); 1087 | 1088 | return true; 1089 | } 1090 | 1091 | // Thanks Peace-Maker! 1092 | // https://github.com/peace-maker/sourcetvmanager/blob/067b238bd21c4fba4b877cb0a514011a1141e1a6/forwards.cpp#L267 1093 | const char* CForwardManager::ClientConnectHook::ExtractPlayerName(CUtlVector& splitScreenClients) 1094 | { 1095 | for (int i = 0; i < splitScreenClients.Count(); i++) 1096 | { 1097 | CCLCMsg_SplitPlayerConnect_t* split = splitScreenClients[i]; 1098 | if(!split->has_convars()) 1099 | { 1100 | continue; 1101 | } 1102 | 1103 | const CMsg_CVars& cvars = split->convars(); 1104 | for (int c = 0; c < cvars.cvars_size(); c++) 1105 | { 1106 | const CMsg_CVars_CVar& cvar = cvars.cvars(c); 1107 | if(!cvar.has_name() || !cvar.has_value()) 1108 | { 1109 | continue; 1110 | } 1111 | 1112 | if(cvar.name() == "name") 1113 | { 1114 | return cvar.value().c_str(); 1115 | } 1116 | } 1117 | } 1118 | 1119 | return ""; 1120 | } 1121 | 1122 | void CForwardManager::ClientConnectHook::OnInternalHookActivated() 1123 | { 1124 | BaseClass::OnInternalHookDeactivated(); 1125 | 1126 | m_iHookID = ManualHook(); 1127 | } 1128 | 1129 | void CForwardManager::ClientConnectHook::OnInternalHookDeactivated() 1130 | { 1131 | BaseClass::OnInternalHookDeactivated(); 1132 | 1133 | if(m_iHookID != -1) 1134 | { 1135 | SH_REMOVE_HOOK_ID(m_iHookID); 1136 | m_iHookID = -1; 1137 | } 1138 | } 1139 | 1140 | CForwardManager::ClientConnectPreHook::ClientConnectPreHook() 1141 | { 1142 | m_Hooks[PTaH_ClientConnectPre] = this; 1143 | 1144 | m_iRejectConnectionOffset = -1; 1145 | } 1146 | 1147 | void CForwardManager::ClientConnectPreHook::Init() 1148 | { 1149 | if(BaseClass::Configure()) 1150 | { 1151 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Hook, 5, nullptr, Param_Cell, Param_String, Param_String, Param_String, Param_String); 1152 | 1153 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CBaseServer::RejectConnection", &m_iRejectConnectionOffset)) 1154 | { 1155 | smutils->LogError(myself, "Failed to get CBaseServer::RejectConnection offset, %s hook functionality will be limited.", GetHookName()); 1156 | } 1157 | } 1158 | } 1159 | 1160 | int CForwardManager::ClientConnectPreHook::ManualHook() 1161 | { 1162 | return SH_ADD_MANUALHOOK(ConnectClient, iserver, SH_MEMBER(this, &CForwardManager::ClientConnectPreHook::Handler), false); 1163 | } 1164 | 1165 | IClient* CForwardManager::ClientConnectPreHook::Handler(const ns_address& adr, int protocol, int challenge, int authProtocol, const char* name, const char* password, const char* hashedCDkey, int cdKeyLen, CUtlVector& splitScreenClients, bool isClientLowViolence, CrossPlayPlatform_t clientPlatform, const byte* pbEncryptionKey, int nEncryptionKeyIndex) 1166 | { 1167 | if(authProtocol == 3 && cdKeyLen >= static_cast(sizeof(CSteamID))) 1168 | { 1169 | cell_t res = Pl_Continue; 1170 | ns_address_render sAdr(adr); 1171 | char rejectReason[255]; 1172 | char passwordNew[128]; 1173 | 1174 | V_strncpy(passwordNew, password, sizeof(passwordNew)); 1175 | 1176 | m_pForward->PushCell(reinterpret_cast(hashedCDkey)->GetAccountID()); 1177 | m_pForward->PushString(sAdr.String()); 1178 | m_pForward->PushString(ExtractPlayerName(splitScreenClients)); 1179 | m_pForward->PushStringEx(passwordNew, sizeof(passwordNew), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); 1180 | m_pForward->PushStringEx(rejectReason, sizeof(rejectReason), SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); 1181 | m_pForward->Execute(&res); 1182 | 1183 | if(res != Pl_Continue) 1184 | { 1185 | if(res == Pl_Changed) 1186 | { 1187 | RETURN_META_VALUE_MNEWPARAMS(MRES_HANDLED, nullptr, ConnectClient, (adr, protocol, challenge, authProtocol, name, passwordNew, hashedCDkey, cdKeyLen, splitScreenClients, isClientLowViolence, clientPlatform, pbEncryptionKey, nEncryptionKeyIndex)); 1188 | } 1189 | 1190 | if(m_iRejectConnectionOffset != -1) 1191 | { 1192 | CallVFMTFunc(m_iRejectConnectionOffset, iserver, adr, "%s", rejectReason); 1193 | } 1194 | 1195 | RETURN_META_VALUE(MRES_SUPERCEDE, nullptr); 1196 | } 1197 | } 1198 | 1199 | RETURN_META_VALUE(MRES_IGNORED, nullptr); 1200 | } 1201 | 1202 | CForwardManager::ClientConnectPostHook::ClientConnectPostHook() 1203 | { 1204 | m_Hooks[PTaH_ClientConnectPost] = this; 1205 | } 1206 | 1207 | void CForwardManager::ClientConnectPostHook::Init() 1208 | { 1209 | if(BaseClass::Configure()) 1210 | { 1211 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Ignore, 4, nullptr, Param_Cell, Param_Cell, Param_String, Param_String); 1212 | } 1213 | } 1214 | 1215 | int CForwardManager::ClientConnectPostHook::ManualHook() 1216 | { 1217 | return SH_ADD_MANUALHOOK(ConnectClient, iserver, SH_MEMBER(this, &CForwardManager::ClientConnectPostHook::Handler), true); 1218 | } 1219 | 1220 | IClient* CForwardManager::ClientConnectPostHook::Handler(const ns_address& adr, int protocol, int challenge, int authProtocol, const char* name, const char* password, const char* hashedCDkey, int cdKeyLen, CUtlVector& splitScreenClients, bool isClientLowViolence, CrossPlayPlatform_t clientPlatform, const byte* pbEncryptionKey, int nEncryptionKeyIndex) 1221 | { 1222 | if(authProtocol == 3 && cdKeyLen >= static_cast(sizeof(CSteamID))) 1223 | { 1224 | IClient* pClient = META_RESULT_ORIG_RET(IClient*); 1225 | if(pClient) 1226 | { 1227 | ns_address_render sAdr(adr); 1228 | 1229 | m_pForward->PushCell(pClient->GetPlayerSlot() + 1); 1230 | m_pForward->PushCell(reinterpret_cast(hashedCDkey)->GetAccountID()); 1231 | m_pForward->PushString(sAdr.String()); 1232 | m_pForward->PushString(ExtractPlayerName(splitScreenClients)); 1233 | m_pForward->Execute(nullptr); 1234 | } 1235 | } 1236 | 1237 | RETURN_META_VALUE(MRES_IGNORED, nullptr); 1238 | } 1239 | 1240 | CForwardManager::InventoryUpdatePostHook::InventoryUpdatePostHook() : CBaseVPHook(true) 1241 | { 1242 | m_Hooks[PTaH_InventoryUpdatePost] = this; 1243 | } 1244 | 1245 | void CForwardManager::InventoryUpdatePostHook::Init() 1246 | { 1247 | int offset = -1; 1248 | if (!g_pGameConf[GameConf_PTaH]->GetOffset("CPlayerInventory::SendInventoryUpdateEvent", &offset)) 1249 | { 1250 | smutils->LogError(myself, "Failed to get CPlayerInventory::SendInventoryUpdateEvent offset, hook InventoryUpdatePost will be unavailable."); 1251 | 1252 | return; 1253 | } 1254 | 1255 | SH_MANUALHOOK_RECONFIGURE(SendInventoryUpdateEvent, offset, 0, 0); 1256 | 1257 | m_pForward = forwards->CreateForwardEx(nullptr, ET_Ignore, 2, nullptr, Param_Cell, Param_Cell); 1258 | } 1259 | 1260 | int CForwardManager::InventoryUpdatePostHook::VPHook(int iClient) 1261 | { 1262 | CCSPlayerInventory* pPlayerInventory = CCSPlayerInventory::FromPlayer(gamehelpers->ReferenceToEntity(iClient)); 1263 | 1264 | return SH_ADD_MANUALVPHOOK(SendInventoryUpdateEvent, pPlayerInventory, SH_MEMBER(this, &CForwardManager::InventoryUpdatePostHook::Handler), true); 1265 | } 1266 | 1267 | void CForwardManager::InventoryUpdatePostHook::Handler() 1268 | { 1269 | CCSPlayerInventory* pPlayerInventory = META_IFACEPTR(CCSPlayerInventory); 1270 | 1271 | m_pForward->PushCell(gamehelpers->EntityToBCompatRef(pPlayerInventory->ToPlayer())); 1272 | m_pForward->PushCell(reinterpret_cast(pPlayerInventory)); 1273 | m_pForward->Execute(nullptr); 1274 | 1275 | RETURN_META(MRES_IGNORED); 1276 | } 1277 | --------------------------------------------------------------------------------