diff --git a/metamod/build.gradle b/metamod/build.gradle
index 9abcd7b..b811b20 100644
--- a/metamod/build.gradle
+++ b/metamod/build.gradle
@@ -39,7 +39,7 @@ void setupToolchain(NativeBinarySpec b)
{
ToolchainConfig cfg = rootProject.createToolchainConfig(b)
cfg.projectInclude(project, '', '/src', '/include/common', '/include/dlls', '/include/engine', '/include/game_shared', '/include/pm_shared', '/include/public')
- cfg.singleDefines '__METAMOD_BUILD__', '__BUILD_FAST_METAMOD__';
+ cfg.singleDefines 'METAMOD_CORE';
if (cfg instanceof MsvcToolchainConfig) {
cfg.compilerOptions.pchConfig = new MsvcToolchainConfig.PrecompiledHeadersConfig(
@@ -59,8 +59,12 @@ void setupToolchain(NativeBinarySpec b)
'_strnicmp': 'strncasecmp',
'_strdup': 'strdup',
'_unlink': 'unlink',
+ '_write' : 'write',
+ '_close' : 'close',
+ '_getcwd' : 'getcwd',
'_vsnprintf': 'vsnprintf',
- '_vsnwprintf' : 'vswprintf',
+ '_vsnwprintf': 'vswprintf',
+ '_snprintf': 'snprintf'
])
cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-msse2', '-fomit-frame-pointer', '-inline-forceinline', '-fvisibility=default', '-fvisibility-inlines-hidden', '-fno-rtti', '-g0', '-s'
@@ -114,12 +118,6 @@ model {
srcDir "version"
include "**/*.cpp"
- if (GradleCppUtils.windows) {
- exclude "osdep_linkent_linux.cpp"
- } else {
- exclude "osdep_linkent_win32.cpp"
- }
-
exclude "precompiled.cpp"
}
diff --git a/metamod/msvc/metamod.vcxproj b/metamod/msvc/metamod.vcxproj
index 13e8991..4f541fc 100644
--- a/metamod/msvc/metamod.vcxproj
+++ b/metamod/msvc/metamod.vcxproj
@@ -44,6 +44,12 @@
+
+ $(ProjectName)_mm
+
+
+ $(ProjectName)_mm
+
Disabled
@@ -51,9 +57,9 @@
METAMOD_CORE;WIN32;_DEBUG;_WINDOWS;_USRDLL;METAMOD_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
MultiThreadedDebug
Use
- .\debug/metamod.pch
- .\debug/asm/
- .\debug/obj/
+ $(IntDir)$(TargetName).pch
+ $(IntDir)
+ $(IntDir)
.\debug/inf/
Level3
true
@@ -63,14 +69,15 @@
precompiled.h
- .\debug/metamod.dll
+ $(OutDir)$(TargetName)$(TargetExt)
true
- .\metamod.def
+ metamod.def
true
- .\debug/inf/metamod.pdb
- .\debug/metamod.lib
+ $(OutDir)$(TargetName).pdb
+ $(OutDir)$(TargetName).lib
MachineX86
false
+ %(AdditionalDependencies)
_DEBUG;%(PreprocessorDefinitions)
@@ -85,6 +92,24 @@
_DEBUG;%(PreprocessorDefinitions)
0x0409
+
+ IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\")
+
+
+ Setup version from Git revision
+
+
+ IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)")
+
+
+ Automatic deployment script
+
+
+ echo Empty Action
+
+
+ Force build to run Pre-Build event
+
@@ -96,9 +121,9 @@
MultiThreaded
true
Use
- .\release/metamod.pch
- .\release/
- .\release/obj/
+ $(IntDir)$(TargetName).pch
+ $(IntDir)
+ $(IntDir)
.\release/inf/
Level3
true
@@ -110,10 +135,11 @@
.\release/metamod.dll
true
.\metamod.def
- .\release/inf/metamod.pdb
- .\release/metamod.lib
+ $(OutDir)$(TargetName).pdb
+ $(OutDir)$(TargetName).lib
MachineX86
false
+ %(AdditionalDependencies)
NDEBUG;%(PreprocessorDefinitions)
@@ -128,6 +154,24 @@
NDEBUG;%(PreprocessorDefinitions)
0x0409
+
+ IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\")
+
+
+ Setup version from Git revision
+
+
+ IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)")
+
+
+ Automatic deployment script
+
+
+ echo Empty Action
+
+
+ Force build to run Pre-Build event
+
@@ -157,7 +201,6 @@
-
@@ -191,8 +234,12 @@
-
-
+
+
+
+
+
+
diff --git a/metamod/msvc/metamod.vcxproj.filters b/metamod/msvc/metamod.vcxproj.filters
index 4a24278..8bb217f 100644
--- a/metamod/msvc/metamod.vcxproj.filters
+++ b/metamod/msvc/metamod.vcxproj.filters
@@ -83,9 +83,6 @@
Source Files
-
- Source Files
-
@@ -181,11 +178,15 @@
Source Files
-
- Source Files
-
-
- Source Files
-
+
+
+
+ Resource Files
+
+
+
+
+ Resource Files
+
\ No newline at end of file
diff --git a/metamod/src/api_info.cpp b/metamod/src/api_info.cpp
index 810f470..96229de 100644
--- a/metamod/src/api_info.cpp
+++ b/metamod/src/api_info.cpp
@@ -1,272 +1,234 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// api_info.cpp - info for api routines
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// trace flag, loglevel, name
dllapi_info_t dllapi_info = {
- { mFALSE, 3, "GameDLLInit" }, // pfnGameInit
- { mFALSE, 10, "DispatchSpawn" }, // pfnSpawn
- { mFALSE, 16, "DispatchThink" }, // pfnThink
- { mFALSE, 9, "DispatchUse" }, // pfnUse
- { mFALSE, 11, "DispatchTouch" }, // pfnTouch
- { mFALSE, 9, "DispatchBlocked" }, // pfnBlocked
- { mFALSE, 10, "DispatchKeyValue" }, // pfnKeyValue
- { mFALSE, 9, "DispatchSave" }, // pfnSave
- { mFALSE, 9, "DispatchRestore" }, // pfnRestore
- { mFALSE, 20, "DispatchObjectCollsionBox" }, // pfnSetAbsBox
- { mFALSE, 9, "SaveWriteFields" }, // pfnSaveWriteFields
- { mFALSE, 9, "SaveReadFields" }, // pfnSaveReadFields
- { mFALSE, 9, "SaveGlobalState" }, // pfnSaveGlobalState
- { mFALSE, 9, "RestoreGlobalState" }, // pfnRestoreGlobalState
- { mFALSE, 9, "ResetGlobalState" }, // pfnResetGlobalState
- { mFALSE, 3, "ClientConnect" }, // pfnClientConnect
- { mFALSE, 3, "ClientDisconnect" }, // pfnClientDisconnect
- { mFALSE, 3, "ClientKill" }, // pfnClientKill
- { mFALSE, 3, "ClientPutInServer" }, // pfnClientPutInServer
- { mFALSE, 9, "ClientCommand" }, // pfnClientCommand
- { mFALSE, 11, "ClientUserInfoChanged" }, // pfnClientUserInfoChanged
- { mFALSE, 3, "ServerActivate" }, // pfnServerActivate
- { mFALSE, 3, "ServerDeactivate" }, // pfnServerDeactivate
- { mFALSE, 14, "PlayerPreThink" }, // pfnPlayerPreThink
- { mFALSE, 14, "PlayerPostThink" }, // pfnPlayerPostThink
- { mFALSE, 18, "StartFrame" }, // pfnStartFrame
- { mFALSE, 9, "ParmsNewLevel" }, // pfnParmsNewLevel
- { mFALSE, 9, "ParmsChangeLevel" }, // pfnParmsChangeLevel
- { mFALSE, 9, "GetGameDescription" }, // pfnGetGameDescription
- { mFALSE, 9, "PlayerCustomization" }, // pfnPlayerCustomization
- { mFALSE, 9, "SpectatorConnect" }, // pfnSpectatorConnect
- { mFALSE, 9, "SpectatorDisconnect" }, // pfnSpectatorDisconnect
- { mFALSE, 9, "SpectatorThink" }, // pfnSpectatorThink
- { mFALSE, 3, "Sys_Error" }, // pfnSys_Error
- { mFALSE, 13, "PM_Move" }, // pfnPM_Move
- { mFALSE, 9, "PM_Init" }, // pfnPM_Init
- { mFALSE, 9, "PM_FindTextureType" }, // pfnPM_FindTextureType
- { mFALSE, 12, "SetupVisibility" }, // pfnSetupVisibility
- { mFALSE, 12, "UpdateClientData" }, // pfnUpdateClientData
- { mFALSE, 16, "AddToFullPack" }, // pfnAddToFullPack
- { mFALSE, 9, "CreateBaseline" }, // pfnCreateBaseline
- { mFALSE, 9, "RegisterEncoders" }, // pfnRegisterEncoders
- { mFALSE, 9, "GetWeaponData" }, // pfnGetWeaponData
- { mFALSE, 15, "CmdStart" }, // pfnCmdStart
- { mFALSE, 15, "CmdEnd" }, // pfnCmdEnd
- { mFALSE, 9, "ConnectionlessPacket" }, // pfnConnectionlessPacket
- { mFALSE, 9, "GetHullBounds" }, // pfnGetHullBounds
- { mFALSE, 9, "CreateInstancedBaselines" }, // pfnCreateInstancedBaselines
- { mFALSE, 3, "InconsistentFile" }, // pfnInconsistentFile
- { mFALSE, 20, "AllowLagCompensation" }, // pfnAllowLagCompensation
- { mFALSE, 0, NULL },
+ { mFALSE, 3, "GameDLLInit" }, // pfnGameInit
+ { mFALSE, 10, "DispatchSpawn" }, // pfnSpawn
+ { mFALSE, 16, "DispatchThink" }, // pfnThink
+ { mFALSE, 9, "DispatchUse" }, // pfnUse
+ { mFALSE, 11, "DispatchTouch" }, // pfnTouch
+ { mFALSE, 9, "DispatchBlocked" }, // pfnBlocked
+ { mFALSE, 10, "DispatchKeyValue" }, // pfnKeyValue
+ { mFALSE, 9, "DispatchSave" }, // pfnSave
+ { mFALSE, 9, "DispatchRestore" }, // pfnRestore
+ { mFALSE, 20, "DispatchObjectCollsionBox" }, // pfnSetAbsBox
+ { mFALSE, 9, "SaveWriteFields" }, // pfnSaveWriteFields
+ { mFALSE, 9, "SaveReadFields" }, // pfnSaveReadFields
+ { mFALSE, 9, "SaveGlobalState" }, // pfnSaveGlobalState
+ { mFALSE, 9, "RestoreGlobalState" }, // pfnRestoreGlobalState
+ { mFALSE, 9, "ResetGlobalState" }, // pfnResetGlobalState
+ { mFALSE, 3, "ClientConnect" }, // pfnClientConnect
+ { mFALSE, 3, "ClientDisconnect" }, // pfnClientDisconnect
+ { mFALSE, 3, "ClientKill" }, // pfnClientKill
+ { mFALSE, 3, "ClientPutInServer" }, // pfnClientPutInServer
+ { mFALSE, 9, "ClientCommand" }, // pfnClientCommand
+ { mFALSE, 11, "ClientUserInfoChanged" }, // pfnClientUserInfoChanged
+ { mFALSE, 3, "ServerActivate" }, // pfnServerActivate
+ { mFALSE, 3, "ServerDeactivate" }, // pfnServerDeactivate
+ { mFALSE, 14, "PlayerPreThink" }, // pfnPlayerPreThink
+ { mFALSE, 14, "PlayerPostThink" }, // pfnPlayerPostThink
+ { mFALSE, 18, "StartFrame" }, // pfnStartFrame
+ { mFALSE, 9, "ParmsNewLevel" }, // pfnParmsNewLevel
+ { mFALSE, 9, "ParmsChangeLevel" }, // pfnParmsChangeLevel
+ { mFALSE, 9, "GetGameDescription" }, // pfnGetGameDescription
+ { mFALSE, 9, "PlayerCustomization" }, // pfnPlayerCustomization
+ { mFALSE, 9, "SpectatorConnect" }, // pfnSpectatorConnect
+ { mFALSE, 9, "SpectatorDisconnect" }, // pfnSpectatorDisconnect
+ { mFALSE, 9, "SpectatorThink" }, // pfnSpectatorThink
+ { mFALSE, 3, "Sys_Error" }, // pfnSys_Error
+ { mFALSE, 13, "PM_Move" }, // pfnPM_Move
+ { mFALSE, 9, "PM_Init" }, // pfnPM_Init
+ { mFALSE, 9, "PM_FindTextureType" }, // pfnPM_FindTextureType
+ { mFALSE, 12, "SetupVisibility" }, // pfnSetupVisibility
+ { mFALSE, 12, "UpdateClientData" }, // pfnUpdateClientData
+ { mFALSE, 16, "AddToFullPack" }, // pfnAddToFullPack
+ { mFALSE, 9, "CreateBaseline" }, // pfnCreateBaseline
+ { mFALSE, 9, "RegisterEncoders" }, // pfnRegisterEncoders
+ { mFALSE, 9, "GetWeaponData" }, // pfnGetWeaponData
+ { mFALSE, 15, "CmdStart" }, // pfnCmdStart
+ { mFALSE, 15, "CmdEnd" }, // pfnCmdEnd
+ { mFALSE, 9, "ConnectionlessPacket" }, // pfnConnectionlessPacket
+ { mFALSE, 9, "GetHullBounds" }, // pfnGetHullBounds
+ { mFALSE, 9, "CreateInstancedBaselines" }, // pfnCreateInstancedBaselines
+ { mFALSE, 3, "InconsistentFile" }, // pfnInconsistentFile
+ { mFALSE, 20, "AllowLagCompensation" }, // pfnAllowLagCompensation
+
+ { mFALSE, 0, nullptr },
};
newapi_info_t newapi_info = {
- { mFALSE, 16, "OnFreeEntPrivateData" }, // pfnOnFreeEntPrivateData
- { mFALSE, 3, "GameShutdown" }, // pfnGameShutdown
- { mFALSE, 14, "ShouldCollide" }, // pfnShouldCollide
- // Added 2005-08-11 (no SDK update)
- { mFALSE, 3, "CvarValue" }, // pfnCvarValue
- // Added 2005-11-22 (no SDK update)
- { mFALSE, 3, "CvarValue2" }, // pfnCvarValue2
- { mFALSE, 0, NULL },
+ { mFALSE, 16, "OnFreeEntPrivateData" }, // pfnOnFreeEntPrivateData
+ { mFALSE, 3, "GameShutdown" }, // pfnGameShutdown
+ { mFALSE, 14, "ShouldCollide" }, // pfnShouldCollide
+ { mFALSE, 3, "CvarValue" }, // pfnCvarValue
+ { mFALSE, 3, "CvarValue2" }, // pfnCvarValue2
+
+ { mFALSE, 0, nullptr },
};
engine_info_t engine_info = {
- { mFALSE, 13, "PrecacheModel" }, // pfnPrecacheModel
- { mFALSE, 13, "PrecacheSound" }, // pfnPrecacheSound
- { mFALSE, 18, "SetModel" }, // pfnSetModel
- { mFALSE, 34, "ModelIndex" }, // pfnModelIndex
- { mFALSE, 10, "ModelFrames" }, // pfnModelFrames
- { mFALSE, 14, "SetSize" }, // pfnSetSize
- { mFALSE, 9, "ChangeLevel" }, // pfnChangeLevel
- { mFALSE, 9, "GetSpawnParms" }, // pfnGetSpawnParms
- { mFALSE, 9, "SaveSpawnParms" }, // pfnSaveSpawnParms
- { mFALSE, 9, "VecToYaw" }, // pfnVecToYaw
- { mFALSE, 14, "VecToAngles" }, // pfnVecToAngles
- { mFALSE, 9, "MoveToOrigin" }, // pfnMoveToOrigin
- { mFALSE, 9, "ChangeYaw" }, // pfnChangeYaw
- { mFALSE, 9, "ChangePitch" }, // pfnChangePitch
- { mFALSE, 32, "FindEntityByString" }, // pfnFindEntityByString
- { mFALSE, 9, "GetEntityIllum" }, // pfnGetEntityIllum
- { mFALSE, 9, "FindEntityInSphere" }, // pfnFindEntityInSphere
- { mFALSE, 19, "FindClientInPVS" }, // pfnFindClientInPVS
- { mFALSE, 9, "EntitiesInPVS" }, // pfnEntitiesInPVS
- { mFALSE, 40, "MakeVectors" }, // pfnMakeVectors
- { mFALSE, 9, "AngleVectors" }, // pfnAngleVectors
- { mFALSE, 13, "CreateEntity" }, // pfnCreateEntity
- { mFALSE, 13, "RemoveEntity" }, // pfnRemoveEntity
- { mFALSE, 13, "CreateNamedEntity" }, // pfnCreateNamedEntity
- { mFALSE, 9, "MakeStatic" }, // pfnMakeStatic
- { mFALSE, 9, "EntIsOnFloor" }, // pfnEntIsOnFloor
- { mFALSE, 9, "DropToFloor" }, // pfnDropToFloor
- { mFALSE, 9, "WalkMove" }, // pfnWalkMove
- { mFALSE, 14, "SetOrigin" }, // pfnSetOrigin
- { mFALSE, 12, "EmitSound" }, // pfnEmitSound
- { mFALSE, 12, "EmitAmbientSound" }, // pfnEmitAmbientSound
- { mFALSE, 20, "TraceLine" }, // pfnTraceLine
- { mFALSE, 9, "TraceToss" }, // pfnTraceToss
- { mFALSE, 9, "TraceMonsterHull" }, // pfnTraceMonsterHull
- { mFALSE, 9, "TraceHull" }, // pfnTraceHull
- { mFALSE, 9, "TraceModel" }, // pfnTraceModel
- { mFALSE, 15, "TraceTexture" }, // pfnTraceTexture // CS: when moving
- { mFALSE, 9, "TraceSphere" }, // pfnTraceSphere
- { mFALSE, 9, "GetAimVector" }, // pfnGetAimVector
- { mFALSE, 9, "ServerCommand" }, // pfnServerCommand
- { mFALSE, 9, "ServerExecute" }, // pfnServerExecute
- { mFALSE, 11, "engClientCommand" }, // pfnClientCommand // d'oh, ClientCommand in dllapi too
- { mFALSE, 9, "ParticleEffect" }, // pfnParticleEffect
- { mFALSE, 9, "LightStyle" }, // pfnLightStyle
- { mFALSE, 9, "DecalIndex" }, // pfnDecalIndex
- { mFALSE, 15, "PointContents" }, // pfnPointContents // CS: when moving
- { mFALSE, 22, "MessageBegin" }, // pfnMessageBegin
- { mFALSE, 22, "MessageEnd" }, // pfnMessageEnd
- { mFALSE, 30, "WriteByte" }, // pfnWriteByte
- { mFALSE, 23, "WriteChar" }, // pfnWriteChar
- { mFALSE, 24, "WriteShort" }, // pfnWriteShort
- { mFALSE, 23, "WriteLong" }, // pfnWriteLong
- { mFALSE, 23, "WriteAngle" }, // pfnWriteAngle
- { mFALSE, 23, "WriteCoord" }, // pfnWriteCoord
- { mFALSE, 25, "WriteString" }, // pfnWriteString
- { mFALSE, 23, "WriteEntity" }, // pfnWriteEntity
- { mFALSE, 9, "CVarRegister" }, // pfnCVarRegister
- { mFALSE, 21, "CVarGetFloat" }, // pfnCVarGetFloat
- { mFALSE, 9, "CVarGetString" }, // pfnCVarGetString
- { mFALSE, 10, "CVarSetFloat" }, // pfnCVarSetFloat
- { mFALSE, 9, "CVarSetString" }, // pfnCVarSetString
- { mFALSE, 15, "AlertMessage" }, // pfnAlertMessage
- { mFALSE, 17, "EngineFprintf" }, // pfnEngineFprintf
- { mFALSE, 14, "PvAllocEntPrivateData" }, // pfnPvAllocEntPrivateData
- { mFALSE, 9, "PvEntPrivateData" }, // pfnPvEntPrivateData
- { mFALSE, 9, "FreeEntPrivateData" }, // pfnFreeEntPrivateData
- { mFALSE, 9, "SzFromIndex" }, // pfnSzFromIndex
- { mFALSE, 10, "AllocString" }, // pfnAllocString
- { mFALSE, 9, "GetVarsOfEnt" }, // pfnGetVarsOfEnt
- { mFALSE, 14, "PEntityOfEntOffset" }, // pfnPEntityOfEntOffset
- { mFALSE, 19, "EntOffsetOfPEntity" }, // pfnEntOffsetOfPEntity
- { mFALSE, 14, "IndexOfEdict" }, // pfnIndexOfEdict
- { mFALSE, 17, "PEntityOfEntIndex" }, // pfnPEntityOfEntIndex
- { mFALSE, 9, "FindEntityByVars" }, // pfnFindEntityByVars
- { mFALSE, 14, "GetModelPtr" }, // pfnGetModelPtr
- { mFALSE, 9, "RegUserMsg" }, // pfnRegUserMsg
- { mFALSE, 9, "AnimationAutomove" }, // pfnAnimationAutomove
- { mFALSE, 9, "GetBonePosition" }, // pfnGetBonePosition
- { mFALSE, 9, "FunctionFromName" }, // pfnFunctionFromName
- { mFALSE, 9, "NameForFunction" }, // pfnNameForFunction
- { mFALSE, 9, "ClientPrintf" }, // pfnClientPrintf
- { mFALSE, 9, "ServerPrint" }, // pfnServerPrint
- { mFALSE, 13, "Cmd_Args" }, // pfnCmd_Args
- { mFALSE, 13, "Cmd_Argv" }, // pfnCmd_Argv
- { mFALSE, 13, "Cmd_Argc" }, // pfnCmd_Argc
- { mFALSE, 9, "GetAttachment" }, // pfnGetAttachment
- { mFALSE, 9, "CRC32_Init" }, // pfnCRC32_Init
- { mFALSE, 9, "CRC32_ProcessBuffer" }, // pfnCRC32_ProcessBuffer
- { mFALSE, 9, "CRC32_ProcessByte" }, // pfnCRC32_ProcessByte
- { mFALSE, 9, "CRC32_Final" }, // pfnCRC32_Final
- { mFALSE, 16, "RandomLong" }, // pfnRandomLong
- { mFALSE, 14, "RandomFloat" }, // pfnRandomFloat // CS: when firing
- { mFALSE, 14, "SetView" }, // pfnSetView
- { mFALSE, 9, "Time" }, // pfnTime
- { mFALSE, 9, "CrosshairAngle" }, // pfnCrosshairAngle
- { mFALSE, 10, "LoadFileForMe" }, // pfnLoadFileForMe
- { mFALSE, 10, "FreeFile" }, // pfnFreeFile
- { mFALSE, 9, "EndSection" }, // pfnEndSection
- { mFALSE, 9, "CompareFileTime" }, // pfnCompareFileTime
- { mFALSE, 9, "GetGameDir" }, // pfnGetGameDir
- { mFALSE, 9, "Cvar_RegisterVariable" }, // pfnCvar_RegisterVariable
- { mFALSE, 9, "FadeClientVolume" }, // pfnFadeClientVolume
- { mFALSE, 14, "SetClientMaxspeed" }, // pfnSetClientMaxspeed
- { mFALSE, 9, "CreateFakeClient" }, // pfnCreateFakeClient
- { mFALSE, 9, "RunPlayerMove" }, // pfnRunPlayerMove
- { mFALSE, 9, "NumberOfEntities" }, // pfnNumberOfEntities
- { mFALSE, 17, "GetInfoKeyBuffer" }, // pfnGetInfoKeyBuffer
- { mFALSE, 13, "InfoKeyValue" }, // pfnInfoKeyValue
- { mFALSE, 9, "SetKeyValue" }, // pfnSetKeyValue
- { mFALSE, 12, "SetClientKeyValue" }, // pfnSetClientKeyValue
- { mFALSE, 9, "IsMapValid" }, // pfnIsMapValid
- { mFALSE, 9, "StaticDecal" }, // pfnStaticDecal
- { mFALSE, 9, "PrecacheGeneric" }, // pfnPrecacheGeneric
- { mFALSE, 10, "GetPlayerUserId" }, // pfnGetPlayerUserId
- { mFALSE, 9, "BuildSoundMsg" }, // pfnBuildSoundMsg
- { mFALSE, 9, "IsDedicatedServer" }, // pfnIsDedicatedServer
- { mFALSE, 9, "CVarGetPointer" }, // pfnCVarGetPointer
- { mFALSE, 9, "GetPlayerWONId" }, // pfnGetPlayerWONId
- { mFALSE, 9, "Info_RemoveKey" }, // pfnInfo_RemoveKey
- { mFALSE, 15, "GetPhysicsKeyValue" }, // pfnGetPhysicsKeyValue
- { mFALSE, 14, "SetPhysicsKeyValue" }, // pfnSetPhysicsKeyValue
- { mFALSE, 15, "GetPhysicsInfoString" }, // pfnGetPhysicsInfoString
- { mFALSE, 13, "PrecacheEvent" }, // pfnPrecacheEvent
- { mFALSE, 9, "PlaybackEvent" }, // pfnPlaybackEvent
- { mFALSE, 31, "SetFatPVS" }, // pfnSetFatPVS
- { mFALSE, 31, "SetFatPAS" }, // pfnSetFatPAS
- { mFALSE, 50, "CheckVisibility" }, // pfnCheckVisibility
- { mFALSE, 37, "DeltaSetField" }, // pfnDeltaSetField
- { mFALSE, 38, "DeltaUnsetField" }, // pfnDeltaUnsetField
- { mFALSE, 9, "DeltaAddEncoder" }, // pfnDeltaAddEncoder
- { mFALSE, 45, "GetCurrentPlayer" }, // pfnGetCurrentPlayer
- { mFALSE, 14, "CanSkipPlayer" }, // pfnCanSkipPlayer
- { mFALSE, 9, "DeltaFindField" }, // pfnDeltaFindField
- { mFALSE, 37, "DeltaSetFieldByIndex" }, // pfnDeltaSetFieldByIndex
- { mFALSE, 38, "DeltaUnsetFieldByIndex" }, // pfnDeltaUnsetFieldByIndex
- { mFALSE, 9, "SetGroupMask" }, // pfnSetGroupMask
- { mFALSE, 9, "engCreateInstancedBaseline" }, // pfnCreateInstancedBaseline // d'oh, CreateInstancedBaseline in dllapi too
- { mFALSE, 9, "Cvar_DirectSet" }, // pfnCvar_DirectSet
- { mFALSE, 9, "ForceUnmodified" }, // pfnForceUnmodified
- { mFALSE, 9, "GetPlayerStats" }, // pfnGetPlayerStats
- { mFALSE, 3, "AddServerCommand" }, // pfnAddServerCommand
- // Added in SDK 2.2:
- { mFALSE, 9, "Voice_GetClientListening" }, // Voice_GetClientListening
- { mFALSE, 9, "Voice_SetClientListening" }, // Voice_SetClientListening
- // Added for HL 1109 (no SDK update):
- { mFALSE, 9, "GetPlayerAuthId" }, // pfnGetPlayerAuthId
- // Added 2003-11-10 (no SDK update):
- { mFALSE, 30, "SequenceGet" }, // pfnSequenceGet
- { mFALSE, 30, "SequencePickSentence" }, // pfnSequencePickSentence
- { mFALSE, 30, "GetFileSize" }, // pfnGetFileSize
- { mFALSE, 30, "GetApproxWavePlayLen" }, // pfnGetApproxWavePlayLen
- { mFALSE, 30, "IsCareerMatch" }, // pfnIsCareerMatch
- { mFALSE, 30, "GetLocalizedStringLength" }, // pfnGetLocalizedStringLength
- { mFALSE, 30, "RegisterTutorMessageShown" }, // pfnRegisterTutorMessageShown
- { mFALSE, 30, "GetTimesTutorMessageShown" }, // pfnGetTimesTutorMessageShown
- { mFALSE, 30, "ProcessTutorMessageDecayBuffer" }, // pfnProcessTutorMessageDecayBuffer
- { mFALSE, 30, "ConstructTutorMessageDecayBuffer" }, // pfnConstructTutorMessageDecayBuffer
- { mFALSE, 9, "ResetTutorMessageDecayData" }, // pfnResetTutorMessageDecayData
- // Added 2005-08-11 (no SDK update)
- { mFALSE, 3, "QueryClientCvarValue" }, //pfnQueryClientCvarValue
- // Added 2005-11-22 (no SDK update)
- { mFALSE, 3, "QueryClientCvarValue2" }, //pfnQueryClientCvarValue2
- // Added 2009-06-17 (no SDK update)
- { mFALSE, 8, "CheckParm" }, //pfnCheckParm
+ { mFALSE, 13, "PrecacheModel" }, // pfnPrecacheModel
+ { mFALSE, 13, "PrecacheSound" }, // pfnPrecacheSound
+ { mFALSE, 18, "SetModel" }, // pfnSetModel
+ { mFALSE, 34, "ModelIndex" }, // pfnModelIndex
+ { mFALSE, 10, "ModelFrames" }, // pfnModelFrames
+ { mFALSE, 14, "SetSize" }, // pfnSetSize
+ { mFALSE, 9, "ChangeLevel" }, // pfnChangeLevel
+ { mFALSE, 9, "GetSpawnParms" }, // pfnGetSpawnParms
+ { mFALSE, 9, "SaveSpawnParms" }, // pfnSaveSpawnParms
+ { mFALSE, 9, "VecToYaw" }, // pfnVecToYaw
+ { mFALSE, 14, "VecToAngles" }, // pfnVecToAngles
+ { mFALSE, 9, "MoveToOrigin" }, // pfnMoveToOrigin
+ { mFALSE, 9, "ChangeYaw" }, // pfnChangeYaw
+ { mFALSE, 9, "ChangePitch" }, // pfnChangePitch
+ { mFALSE, 32, "FindEntityByString" }, // pfnFindEntityByString
+ { mFALSE, 9, "GetEntityIllum" }, // pfnGetEntityIllum
+ { mFALSE, 9, "FindEntityInSphere" }, // pfnFindEntityInSphere
+ { mFALSE, 19, "FindClientInPVS" }, // pfnFindClientInPVS
+ { mFALSE, 9, "EntitiesInPVS" }, // pfnEntitiesInPVS
+ { mFALSE, 40, "MakeVectors" }, // pfnMakeVectors
+ { mFALSE, 9, "AngleVectors" }, // pfnAngleVectors
+ { mFALSE, 13, "CreateEntity" }, // pfnCreateEntity
+ { mFALSE, 13, "RemoveEntity" }, // pfnRemoveEntity
+ { mFALSE, 13, "CreateNamedEntity" }, // pfnCreateNamedEntity
+ { mFALSE, 9, "MakeStatic" }, // pfnMakeStatic
+ { mFALSE, 9, "EntIsOnFloor" }, // pfnEntIsOnFloor
+ { mFALSE, 9, "DropToFloor" }, // pfnDropToFloor
+ { mFALSE, 9, "WalkMove" }, // pfnWalkMove
+ { mFALSE, 14, "SetOrigin" }, // pfnSetOrigin
+ { mFALSE, 12, "EmitSound" }, // pfnEmitSound
+ { mFALSE, 12, "EmitAmbientSound" }, // pfnEmitAmbientSound
+ { mFALSE, 20, "TraceLine" }, // pfnTraceLine
+ { mFALSE, 9, "TraceToss" }, // pfnTraceToss
+ { mFALSE, 9, "TraceMonsterHull" }, // pfnTraceMonsterHull
+ { mFALSE, 9, "TraceHull" }, // pfnTraceHull
+ { mFALSE, 9, "TraceModel" }, // pfnTraceModel
+ { mFALSE, 15, "TraceTexture" }, // pfnTraceTexture // CS: when moving
+ { mFALSE, 9, "TraceSphere" }, // pfnTraceSphere
+ { mFALSE, 9, "GetAimVector" }, // pfnGetAimVector
+ { mFALSE, 9, "ServerCommand" }, // pfnServerCommand
+ { mFALSE, 9, "ServerExecute" }, // pfnServerExecute
+ { mFALSE, 11, "engClientCommand" }, // pfnClientCommand // d'oh, ClientCommand in dllapi too
+ { mFALSE, 9, "ParticleEffect" }, // pfnParticleEffect
+ { mFALSE, 9, "LightStyle" }, // pfnLightStyle
+ { mFALSE, 9, "DecalIndex" }, // pfnDecalIndex
+ { mFALSE, 15, "PointContents" }, // pfnPointContents // CS: when moving
+ { mFALSE, 22, "MessageBegin" }, // pfnMessageBegin
+ { mFALSE, 22, "MessageEnd" }, // pfnMessageEnd
+ { mFALSE, 30, "WriteByte" }, // pfnWriteByte
+ { mFALSE, 23, "WriteChar" }, // pfnWriteChar
+ { mFALSE, 24, "WriteShort" }, // pfnWriteShort
+ { mFALSE, 23, "WriteLong" }, // pfnWriteLong
+ { mFALSE, 23, "WriteAngle" }, // pfnWriteAngle
+ { mFALSE, 23, "WriteCoord" }, // pfnWriteCoord
+ { mFALSE, 25, "WriteString" }, // pfnWriteString
+ { mFALSE, 23, "WriteEntity" }, // pfnWriteEntity
+ { mFALSE, 9, "CVarRegister" }, // pfnCVarRegister
+ { mFALSE, 21, "CVarGetFloat" }, // pfnCVarGetFloat
+ { mFALSE, 9, "CVarGetString" }, // pfnCVarGetString
+ { mFALSE, 10, "CVarSetFloat" }, // pfnCVarSetFloat
+ { mFALSE, 9, "CVarSetString" }, // pfnCVarSetString
+ { mFALSE, 15, "AlertMessage" }, // pfnAlertMessage
+ { mFALSE, 17, "EngineFprintf" }, // pfnEngineFprintf
+ { mFALSE, 14, "PvAllocEntPrivateData" }, // pfnPvAllocEntPrivateData
+ { mFALSE, 9, "PvEntPrivateData" }, // pfnPvEntPrivateData
+ { mFALSE, 9, "FreeEntPrivateData" }, // pfnFreeEntPrivateData
+ { mFALSE, 9, "SzFromIndex" }, // pfnSzFromIndex
+ { mFALSE, 10, "AllocString" }, // pfnAllocString
+ { mFALSE, 9, "GetVarsOfEnt" }, // pfnGetVarsOfEnt
+ { mFALSE, 14, "PEntityOfEntOffset" }, // pfnPEntityOfEntOffset
+ { mFALSE, 19, "EntOffsetOfPEntity" }, // pfnEntOffsetOfPEntity
+ { mFALSE, 14, "IndexOfEdict" }, // pfnIndexOfEdict
+ { mFALSE, 17, "PEntityOfEntIndex" }, // pfnPEntityOfEntIndex
+ { mFALSE, 9, "FindEntityByVars" }, // pfnFindEntityByVars
+ { mFALSE, 14, "GetModelPtr" }, // pfnGetModelPtr
+ { mFALSE, 9, "RegUserMsg" }, // pfnRegUserMsg
+ { mFALSE, 9, "AnimationAutomove" }, // pfnAnimationAutomove
+ { mFALSE, 9, "GetBonePosition" }, // pfnGetBonePosition
+ { mFALSE, 9, "FunctionFromName" }, // pfnFunctionFromName
+ { mFALSE, 9, "NameForFunction" }, // pfnNameForFunction
+ { mFALSE, 9, "ClientPrintf" }, // pfnClientPrintf
+ { mFALSE, 9, "ServerPrint" }, // pfnServerPrint
+ { mFALSE, 13, "Cmd_Args" }, // pfnCmd_Args
+ { mFALSE, 13, "Cmd_Argv" }, // pfnCmd_Argv
+ { mFALSE, 13, "Cmd_Argc" }, // pfnCmd_Argc
+ { mFALSE, 9, "GetAttachment" }, // pfnGetAttachment
+ { mFALSE, 9, "CRC32_Init" }, // pfnCRC32_Init
+ { mFALSE, 9, "CRC32_ProcessBuffer" }, // pfnCRC32_ProcessBuffer
+ { mFALSE, 9, "CRC32_ProcessByte" }, // pfnCRC32_ProcessByte
+ { mFALSE, 9, "CRC32_Final" }, // pfnCRC32_Final
+ { mFALSE, 16, "RandomLong" }, // pfnRandomLong
+ { mFALSE, 14, "RandomFloat" }, // pfnRandomFloat // CS: when firing
+ { mFALSE, 14, "SetView" }, // pfnSetView
+ { mFALSE, 9, "Time" }, // pfnTime
+ { mFALSE, 9, "CrosshairAngle" }, // pfnCrosshairAngle
+ { mFALSE, 10, "LoadFileForMe" }, // pfnLoadFileForMe
+ { mFALSE, 10, "FreeFile" }, // pfnFreeFile
+ { mFALSE, 9, "EndSection" }, // pfnEndSection
+ { mFALSE, 9, "CompareFileTime" }, // pfnCompareFileTime
+ { mFALSE, 9, "GetGameDir" }, // pfnGetGameDir
+ { mFALSE, 9, "Cvar_RegisterVariable" }, // pfnCvar_RegisterVariable
+ { mFALSE, 9, "FadeClientVolume" }, // pfnFadeClientVolume
+ { mFALSE, 14, "SetClientMaxspeed" }, // pfnSetClientMaxspeed
+ { mFALSE, 9, "CreateFakeClient" }, // pfnCreateFakeClient
+ { mFALSE, 9, "RunPlayerMove" }, // pfnRunPlayerMove
+ { mFALSE, 9, "NumberOfEntities" }, // pfnNumberOfEntities
+ { mFALSE, 17, "GetInfoKeyBuffer" }, // pfnGetInfoKeyBuffer
+ { mFALSE, 13, "InfoKeyValue" }, // pfnInfoKeyValue
+ { mFALSE, 9, "SetKeyValue" }, // pfnSetKeyValue
+ { mFALSE, 12, "SetClientKeyValue" }, // pfnSetClientKeyValue
+ { mFALSE, 9, "IsMapValid" }, // pfnIsMapValid
+ { mFALSE, 9, "StaticDecal" }, // pfnStaticDecal
+ { mFALSE, 9, "PrecacheGeneric" }, // pfnPrecacheGeneric
+ { mFALSE, 10, "GetPlayerUserId" }, // pfnGetPlayerUserId
+ { mFALSE, 9, "BuildSoundMsg" }, // pfnBuildSoundMsg
+ { mFALSE, 9, "IsDedicatedServer" }, // pfnIsDedicatedServer
+ { mFALSE, 9, "CVarGetPointer" }, // pfnCVarGetPointer
+ { mFALSE, 9, "GetPlayerWONId" }, // pfnGetPlayerWONId
+ { mFALSE, 9, "Info_RemoveKey" }, // pfnInfo_RemoveKey
+ { mFALSE, 15, "GetPhysicsKeyValue" }, // pfnGetPhysicsKeyValue
+ { mFALSE, 14, "SetPhysicsKeyValue" }, // pfnSetPhysicsKeyValue
+ { mFALSE, 15, "GetPhysicsInfoString" }, // pfnGetPhysicsInfoString
+ { mFALSE, 13, "PrecacheEvent" }, // pfnPrecacheEvent
+ { mFALSE, 9, "PlaybackEvent" }, // pfnPlaybackEvent
+ { mFALSE, 31, "SetFatPVS" }, // pfnSetFatPVS
+ { mFALSE, 31, "SetFatPAS" }, // pfnSetFatPAS
+ { mFALSE, 50, "CheckVisibility" }, // pfnCheckVisibility
+ { mFALSE, 37, "DeltaSetField" }, // pfnDeltaSetField
+ { mFALSE, 38, "DeltaUnsetField" }, // pfnDeltaUnsetField
+ { mFALSE, 9, "DeltaAddEncoder" }, // pfnDeltaAddEncoder
+ { mFALSE, 45, "GetCurrentPlayer" }, // pfnGetCurrentPlayer
+ { mFALSE, 14, "CanSkipPlayer" }, // pfnCanSkipPlayer
+ { mFALSE, 9, "DeltaFindField" }, // pfnDeltaFindField
+ { mFALSE, 37, "DeltaSetFieldByIndex" }, // pfnDeltaSetFieldByIndex
+ { mFALSE, 38, "DeltaUnsetFieldByIndex" }, // pfnDeltaUnsetFieldByIndex
+ { mFALSE, 9, "SetGroupMask" }, // pfnSetGroupMask
+ { mFALSE, 9, "engCreateInstancedBaseline" }, // pfnCreateInstancedBaseline // d'oh, CreateInstancedBaseline in dllapi too
+ { mFALSE, 9, "Cvar_DirectSet" }, // pfnCvar_DirectSet
+ { mFALSE, 9, "ForceUnmodified" }, // pfnForceUnmodified
+ { mFALSE, 9, "GetPlayerStats" }, // pfnGetPlayerStats
+ { mFALSE, 3, "AddServerCommand" }, // pfnAddServerCommand
+
+ { mFALSE, 9, "Voice_GetClientListening" }, // Voice_GetClientListening
+ { mFALSE, 9, "Voice_SetClientListening" }, // Voice_SetClientListening
+ { mFALSE, 9, "GetPlayerAuthId" }, // pfnGetPlayerAuthId
+ { mFALSE, 30, "SequenceGet" }, // pfnSequenceGet
+
+ { mFALSE, 30, "SequencePickSentence" }, // pfnSequencePickSentence
+ { mFALSE, 30, "GetFileSize" }, // pfnGetFileSize
+ { mFALSE, 30, "GetApproxWavePlayLen" }, // pfnGetApproxWavePlayLen
+ { mFALSE, 30, "IsCareerMatch" }, // pfnIsCareerMatch
+ { mFALSE, 30, "GetLocalizedStringLength" }, // pfnGetLocalizedStringLength
+ { mFALSE, 30, "RegisterTutorMessageShown" }, // pfnRegisterTutorMessageShown
+ { mFALSE, 30, "GetTimesTutorMessageShown" }, // pfnGetTimesTutorMessageShown
+ { mFALSE, 30, "ProcessTutorMessageDecayBuffer" }, // pfnProcessTutorMessageDecayBuffer
+ { mFALSE, 30, "ConstructTutorMessageDecayBuffer" }, // pfnConstructTutorMessageDecayBuffer
+ { mFALSE, 9, "ResetTutorMessageDecayData" }, // pfnResetTutorMessageDecayData
+
+ { mFALSE, 3, "QueryClientCvarValue" }, //pfnQueryClientCvarValue
+ { mFALSE, 3, "QueryClientCvarValue2" }, //pfnQueryClientCvarValue2
+ { mFALSE, 8, "CheckParm" }, //pfnCheckParm
+
// end
- { mFALSE, 0, NULL },
+ { mFALSE, 0, NULL },
};
diff --git a/metamod/src/api_info.h b/metamod/src/api_info.h
index da6d7ea..63ae60f 100644
--- a/metamod/src/api_info.h
+++ b/metamod/src/api_info.h
@@ -1,58 +1,20 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// api_info.h - structures to store info about api routines
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef API_INFO_H
-#define API_INFO_H
-
-#include "types_meta.h" // mBOOL
+#pragma once
+#include "types_meta.h"
#define P_PRE 0 // plugin function called before gamedll
#define P_POST 1 // plugin function called after gamedll
-
-typedef struct api_info_s {
+struct api_info_t
+{
mBOOL trace; // if true, log info about this function
int loglevel; // level at which to log info about this function
const char *name; // string representation of function name
-} api_info_t;
-
+};
// DLL api functions
-typedef struct dllapi_info_s {
+struct dllapi_info_t
+{
api_info_t pfnGameInit;
api_info_t pfnSpawn;
api_info_t pfnThink;
@@ -103,25 +65,27 @@ typedef struct dllapi_info_s {
api_info_t pfnCreateInstancedBaselines;
api_info_t pfnInconsistentFile;
api_info_t pfnAllowLagCompensation;
- api_info_t END;
-} dllapi_info_t;
+ // end
+ api_info_t END;
+};
// "New" api functions
-typedef struct newapi_info_s {
+struct newapi_info_t
+{
api_info_t pfnOnFreeEntPrivateData;
api_info_t pfnGameShutdown;
api_info_t pfnShouldCollide;
- // Added 2005/08/11 (no SDK update)
api_info_t pfnCvarValue;
- // Added 2005/11/22 (no SDK update)
api_info_t pfnCvarValue2;
- api_info_t END;
-} newapi_info_t;
+ // end
+ api_info_t END;
+};
// g_engine functions
-typedef struct engine_info_s {
+struct engine_info_t
+{
api_info_t pfnPrecacheModel;
api_info_t pfnPrecacheSound;
api_info_t pfnSetModel;
@@ -263,12 +227,9 @@ typedef struct engine_info_s {
api_info_t pfnForceUnmodified;
api_info_t pfnGetPlayerStats;
api_info_t pfnAddServerCommand;
- // Added in SDK 2.2:
api_info_t pfnVoice_GetClientListening;
api_info_t pfnVoice_SetClientListening;
- // Added for HL 1109 (no SDK update):
api_info_t pfnGetPlayerAuthId;
- // Added 2003/11/10 (no SDK update):
api_info_t pfnSequenceGet;
api_info_t pfnSequencePickSentence;
api_info_t pfnGetFileSize;
@@ -280,19 +241,14 @@ typedef struct engine_info_s {
api_info_t pfnProcessTutorMessageDecayBuffer;
api_info_t pfnConstructTutorMessageDecayBuffer;
api_info_t pfnResetTutorMessageDecayData;
- // Added 2005/08/11 (no SDK update)
api_info_t pfnQueryClientCvarValue;
- // Added 2005/11/22 (no SDK update)
api_info_t pfnQueryClientCvarValue2;
- // Added 2009/06/17 (no SDK update)
api_info_t pfnEngCheckParm;
+
// end
api_info_t END;
-} engine_info_t;
-
+};
extern dllapi_info_t dllapi_info;
extern newapi_info_t newapi_info;
extern engine_info_t engine_info;
-
-#endif /* API_INFO_H */
diff --git a/metamod/src/commands_meta.cpp b/metamod/src/commands_meta.cpp
index 6e16bbc..18b6e20 100644
--- a/metamod/src/commands_meta.cpp
+++ b/metamod/src/commands_meta.cpp
@@ -1,39 +1,3 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// commands_meta.cpp - implementation of various console commands
-
-/*
-* Copyright (c) 2001-2004 Will Day
-*
-* This file is part of Metamod.
-*
-* Metamod is free software; you can redistribute it and/or modify it
-* under the terms of the GNU General Public License as published by the
-* Free Software Foundation; either version 2 of the License, or (at
-* your option) any later version.
-*
-* Metamod is distributed in the hope that it will be useful, but
-* WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with Metamod; if not, write to the Free Software Foundation,
-* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*
-* In addition, as a special exception, the author gives permission to
-* link the code of this program with the Half-Life Game g_engine ("HL
-* g_engine") and Modified Game Libraries ("MODs") developed by Valve,
-* L.L.C ("Valve"). You must obey the GNU General Public License in all
-* respects for all of the code used other than the HL g_engine and MODs
-* from Valve. If you modify this file, you may extend this exception
-* to your version of the file, but you are not obligated to do so. If
-* you do not wish to do so, delete this exception statement from your
-* version.
-*
-*/
-
#include "precompiled.h"
struct metacmd_t
@@ -44,26 +8,28 @@ struct metacmd_t
metacmd_t g_meta_cmds[] =
{
- {"version", cmd_meta_version},
- {"gpl", cmd_meta_gpl},
- {"refresh", cmd_meta_refresh},
- {"list", cmd_meta_pluginlist},
- {"cmds", cmd_meta_cmdlist},
- {"cvars", cmd_meta_cvarlist},
- {"game", cmd_meta_game},
- {"config", cmd_meta_config},
+ {"version", cmd_meta_version},
+ {"gpl", cmd_meta_gpl},
+ {"refresh", cmd_meta_refresh},
+ {"list", cmd_meta_pluginlist},
+ {"cmds", cmd_meta_cmdlist},
+ {"cvars", cmd_meta_cvarlist},
+ {"game", cmd_meta_game},
+ {"config", cmd_meta_config},
+
// arguments: existing plugin(s)
- {"pause", []() { cmd_doplug(PC_PAUSE); }},
- {"unpause", []() { cmd_doplug(PC_UNPAUSE); }},
- {"unload", []() { cmd_doplug(PC_UNLOAD); }},
- {"force_unload", []() { cmd_doplug(PC_FORCE_UNLOAD); }},
- {"reload", []() { cmd_doplug(PC_RELOAD); }},
- {"retry", []() { cmd_doplug(PC_RETRY); }},
- {"clear", []() { cmd_doplug(PC_CLEAR); }},
- {"info", []() { cmd_doplug(PC_INFO); }},
- {"require", []() { cmd_doplug(PC_REQUIRE); }},
+ {"pause", []() { cmd_doplug(PC_PAUSE); }},
+ {"unpause", []() { cmd_doplug(PC_UNPAUSE); }},
+ {"unload", []() { cmd_doplug(PC_UNLOAD); }},
+ {"force_unload", []() { cmd_doplug(PC_FORCE_UNLOAD); }},
+ {"reload", []() { cmd_doplug(PC_RELOAD); }},
+ {"retry", []() { cmd_doplug(PC_RETRY); }},
+ {"clear", []() { cmd_doplug(PC_CLEAR); }},
+ {"info", []() { cmd_doplug(PC_INFO); }},
+ {"require", []() { cmd_doplug(PC_REQUIRE); }},
+
// arguments: filename, description
- {"load", cmd_meta_load},
+ {"load", cmd_meta_load},
};
// Register commands and cvars.
@@ -75,12 +41,14 @@ void meta_register_cmdcvar()
}
// Parse "meta" console command.
-void server_meta(void)
+void server_meta()
{
- const char* cmd = CMD_ARGV(1);
+ const char *cmd = CMD_ARGV(1);
- for (auto& meta_cmd : g_meta_cmds) {
- if (!strcmp(cmd, meta_cmd.name)) {
+ for (auto& meta_cmd : g_meta_cmds)
+ {
+ if (!Q_strcmp(cmd, meta_cmd.name))
+ {
meta_cmd.handler();
return;
}
@@ -93,24 +61,25 @@ void server_meta(void)
// Parse "meta" client command.
void client_meta(edict_t* pEntity)
{
- const char* cmd = CMD_ARGV(1);
-
+ const char *cmd = CMD_ARGV(1);
META_LOG("ClientCommand 'meta %s' from player '%s'", CMD_ARGS(), STRING(pEntity->v.netname));
// arguments: none
- if (!strcmp(cmd, "version"))
+ if (!Q_strcmp(cmd, "version"))
client_meta_version(pEntity);
- else if (!strcmp(cmd, "list"))
+
+ else if (!Q_strcmp(cmd, "list"))
client_meta_pluginlist(pEntity);
- // unrecognized
- else {
+ else
+ {
META_CLIENT(pEntity, "Unrecognized meta command: %s", cmd);
client_meta_usage(pEntity);
+ return;
}
}
// Print usage for "meta" console command.
-void cmd_meta_usage(void)
+void cmd_meta_usage()
{
META_CONS("usage: meta []");
META_CONS("valid commands are:");
@@ -134,7 +103,7 @@ void cmd_meta_usage(void)
}
// Print usage for "meta" client command.
-void client_meta_usage(edict_t* pEntity)
+void client_meta_usage(edict_t *pEntity)
{
META_CLIENT(pEntity, "usage: meta []");
META_CLIENT(pEntity, "valid commands are:");
@@ -143,37 +112,38 @@ void client_meta_usage(edict_t* pEntity)
}
// "meta version" console command.
-void cmd_meta_version(void)
+void cmd_meta_version()
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CONS("usage: meta version");
return;
}
- META_CONS("%s v%s %s (%s)", VNAME, VVERSION, VDATE, META_INTERFACE_VERSION);
- META_CONS("by %s", VAUTHOR);
- META_CONS(" %s", VURL);
- META_CONS("compiled: %s %s (%s)", COMPILE_TIME, COMPILE_TZONE, OPT_TYPE);
+
+ META_CONS("Metamod v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
+ META_CONS("Metamod build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")");
+ META_CONS("Metamod from: " APP_COMMITS_URL APP_COMMIT_ID " " APP_COMMIT_AUTHOR "");
}
// "meta version" client command.
-void client_meta_version(edict_t* pEntity)
+void client_meta_version(edict_t *pEntity)
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CLIENT(pEntity, "usage: meta version");
return;
}
- META_CLIENT(pEntity, "%s v%s %s (%s)", VNAME, VVERSION, VDATE, META_INTERFACE_VERSION);
- META_CLIENT(pEntity, "by %s", VAUTHOR);
- META_CLIENT(pEntity, " %s", VURL);
- META_CLIENT(pEntity, "compiled: %s %s (%s)", COMPILE_TIME, COMPILE_TZONE, OPT_TYPE);
- META_CLIENT(pEntity, "ifvers: %s", META_INTERFACE_VERSION);
+
+ META_CONS("Metamod v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
+ META_CONS("Metamod build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")");
+ META_CONS("Metamod from: " APP_COMMITS_URL APP_COMMIT_ID " " APP_COMMIT_AUTHOR "");
}
// "meta gpl" console command.
-void cmd_meta_gpl(void)
+void cmd_meta_gpl()
{
- META_CONS("%s version %s %s", VNAME, VVERSION, VDATE);
- META_CONS("Copyright (c) 2001-%s Will Day ", COPYRIGHT_YEAR);
+ META_CONS("Metamod version " __TIME__ " " __DATE__);
+ META_CONS("Copyright (c) 2001-2016 Will Day (modification ReHLDS Team)");
META_CONS("");
META_CONS(" Metamod is free software; you can redistribute it and/or");
META_CONS(" modify it under the terms of the GNU General Public License");
@@ -193,10 +163,10 @@ void cmd_meta_gpl(void)
META_CONS(" ");
META_CONS(" In addition, as a special exception, the author gives");
META_CONS(" permission to link the code of this program with the");
- META_CONS(" Half-Life Game g_engine (\"HL g_engine\") and Modified Game");
+ META_CONS(" Half-Life Game Engine (\"HL Engine\") and Modified Game");
META_CONS(" Libraries (\"MODs\") developed by Valve, L.L.C (\"Valve\").");
META_CONS(" You must obey the GNU General Public License in all");
- META_CONS(" respects for all of the code used other than the HL g_engine");
+ META_CONS(" respects for all of the code used other than the HL Engine");
META_CONS(" and MODs from Valve. If you modify this file, you may");
META_CONS(" extend this exception to your version of the file, but you");
META_CONS(" are not obligated to do so. If you do not wish to do so,");
@@ -204,12 +174,14 @@ void cmd_meta_gpl(void)
}
// "meta game" console command.
-void cmd_meta_game(void)
+void cmd_meta_game()
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CONS("usage: meta game");
return;
}
+
META_CONS("GameDLL info:");
META_CONS(" name: %s", GameDLL.name);
META_CONS(" desc: %s", GameDLL.desc);
@@ -220,67 +192,78 @@ void cmd_meta_game(void)
}
// "meta refresh" console command.
-void cmd_meta_refresh(void)
+void cmd_meta_refresh()
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CONS("usage: meta refresh");
return;
}
META_LOG("Refreshing the plugins on demand...");
-
- if (g_plugins->refresh(PT_ANYTIME) != mTRUE) {
+ if (g_plugins->refresh(PT_ANYTIME) != mTRUE)
+ {
META_LOG("Refresh failed.");
}
}
// "meta list" console command.
-void cmd_meta_pluginlist(void)
+void cmd_meta_pluginlist()
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CONS("usage: meta list");
return;
}
+
g_plugins->show(0);
}
// "meta list" client command.
void client_meta_pluginlist(edict_t* pEntity)
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CLIENT(pEntity, "usage: meta list");
return;
}
+
g_plugins->show_client(pEntity);
}
// "meta cmds" console command.
-void cmd_meta_cmdlist(void)
+void cmd_meta_cmdlist()
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CONS("usage: meta cmds");
return;
}
+
g_regCmds->show();
}
// "meta cvars" console command.
-void cmd_meta_cvarlist(void)
+void cmd_meta_cvarlist()
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CONS("usage: meta cvars");
return;
}
+
g_regCvars->show();
}
// "meta config" console command.
-void cmd_meta_config(void)
+void cmd_meta_config()
{
- if (CMD_ARGC() != 2) {
+ if (CMD_ARGC() != 2)
+ {
META_CONS("usage: meta cvars");
return;
}
+
g_config->show();
}
@@ -297,31 +280,26 @@ void cmd_meta_config(void)
// path_i386.so, path_i486.so, etc
// "meta load" console command.
-void cmd_meta_load(void)
+void cmd_meta_load()
{
int argc = CMD_ARGC();
-
- if (argc < 3) {
+ if (argc < 3)
+ {
META_CONS("usage: meta load []");
META_CONS(" where is an identifier used to locate the plugin file.");
META_CONS(" The system will look for a number of files based on this name, including:");
META_CONS(" name");
-#ifdef linux
+#ifdef _WIN32
+ META_CONS(" name.dll");
+ META_CONS(" name_mm.dll");
+ META_CONS(" mm_name.dll");
+#else
META_CONS(" name.so");
META_CONS(" name_mm.so");
META_CONS(" name_MM.so");
META_CONS(" mm_name.so");
- META_CONS(" name_i386.so");
- META_CONS(" name_i686.so");
-#elif defined(__APPLE__)
- META_CONS(" name.dylib");
- META_CONS(" name_mm.dylib");
- META_CONS(" mm_name.dylib");
-#elif defined(_WIN32)
- META_CONS(" name.dll");
- META_CONS(" name_mm.dll");
- META_CONS(" mm_name.dll");
-#endif /* linux */
+#endif
+
META_CONS(" in a number of directories, including:");
META_CONS(" ");
META_CONS(" /dlls");
@@ -329,7 +307,7 @@ void cmd_meta_load(void)
return;
}
- const char* args = CMD_ARGS();
+ const char *args = CMD_ARGS();
// cmd_addload() handles all the feedback to the console..
g_plugins->cmd_addload(args);
}
@@ -338,24 +316,29 @@ void cmd_meta_load(void)
void cmd_doplug(PLUG_CMD pcmd)
{
int argc = CMD_ARGC();
- const char* cmd = CMD_ARGV(1);
+ const char *cmd = CMD_ARGV(1);
- if (argc < 3) {
+ if (argc < 3)
+ {
META_CONS("usage: meta %s [ ...]", cmd);
META_CONS(" where can be either the plugin index #");
META_CONS(" or a non-ambiguous prefix string matching name, desc, file, or logtag");
return;
}
- // i=2 to skip first arg, as that's the "cmd"
- for (int i = 2; i < argc; i++) {
- const char* arg = CMD_ARGV(i);
- MPlugin* findp;
- char* endptr;
+
+ // i = 2 to skip first arg, as that's the "cmd"
+ for (int i = 2; i < argc; i++)
+ {
+ const char *arg = CMD_ARGV(i);
+ MPlugin *findp;
+ char *endptr;
// try to match plugin id first
- long pindex = strtol(arg, &endptr, 10);
- if (*arg != '\0' && *endptr == '\0')
+ int pindex = strtol(arg, &endptr, 10);
+
+ if (*arg && !*endptr)
findp = g_plugins->find(pindex);
+
// else try to match some string (prefix)
else
findp = g_plugins->find_match(arg);
@@ -364,40 +347,37 @@ void cmd_doplug(PLUG_CMD pcmd)
// - specified plugin was found in the list of current plugins
// - plugin successfully loaded and began running
// Otherwise, print error and exit.
- if (pcmd == PC_REQUIRE) {
- if (findp && findp->status >= PL_RUNNING) {
+ if (pcmd == PC_REQUIRE)
+ {
+ if (findp && findp->status >= PL_RUNNING)
+ {
META_DEBUG(3, ("Required plugin '%s' found loaded and running.", arg));
return;
}
// Output to both places, because we don't want the admin
// to miss this..
- if (!findp && meta_errno == ME_NOTUNIQ) {
+ if (!findp && meta_errno == ME_NOTUNIQ)
+ {
META_ERROR("Unique match for required plugin '%s' was not found! Exiting.", arg);
META_CONS("\nERROR: Unique match for required plugin '%s' was not found! Exiting.\n", arg);
}
- else if (!findp) {
+ else if (!findp)
+ {
META_ERROR("Required plugin '%s' was not found! Exiting.", arg);
META_CONS("\nERROR: Required plugin '%s' was not found! Exiting.\n", arg);
}
- else {
+ else
+ {
META_ERROR("Required plugin '%s' did not load successfully! (status=%s) Exiting.", arg, findp->str_status(ST_SIMPLE));
META_CONS("\nERROR: Required plugin '%s' did not load successfully! (status=%s) Exiting.\n", arg, findp->str_status(ST_SIMPLE));
}
+
// Allow chance to read the message, before any window closes.
- sleep(1);
-#ifdef linux
- // Argh, "quit" appears to segfault the server under linux; I
- // was unable to determine why.
- exit(1);
-#else
- // Argh, and exit() appears to generate an "Application Error"
- // under MSVC. Interestingly, both seem to work fine with
- // mingw32.
- SERVER_COMMAND("quit\n");
-#endif /* not linux */
+ do_exit(1);
}
- if (!findp) {
+ if (!findp)
+ {
if (meta_errno == ME_NOTUNIQ)
META_CONS("Couldn't find unique plugin matching '%s'", arg);
else
@@ -405,39 +385,48 @@ void cmd_doplug(PLUG_CMD pcmd)
return;
}
- if (pcmd == PC_PAUSE) {
+ switch (pcmd)
+ {
+ case PC_PAUSE:
if (findp->pause())
META_CONS("Paused plugin '%s'", findp->desc);
else
META_CONS("Pause failed for plugin '%s'", findp->desc);
- }
- else if (pcmd == PC_UNPAUSE) {
+ break;
+ case PC_UNPAUSE:
if (findp->unpause())
META_CONS("Unpaused plugin '%s'", findp->desc);
else
META_CONS("Unpause failed for plugin '%s'", findp->desc);
- }
- else if (pcmd == PC_UNLOAD) {
+ break;
+ case PC_UNLOAD:
+ {
findp->action = PA_UNLOAD;
- if (findp->unload(PT_ANYTIME, PNL_COMMAND, PNL_COMMAND)) {
+ if (findp->unload(PT_ANYTIME, PNL_COMMAND, PNL_COMMAND))
+ {
META_CONS("Unloaded plugin '%s'", findp->desc);
- g_plugins->show(0);
+ g_plugins->show();
}
else if (meta_errno == ME_DELAYED)
META_CONS("Unload delayed for plugin '%s'", findp->desc);
else
META_CONS("Unload failed for plugin '%s'", findp->desc);
+ break;
}
- else if (pcmd == PC_FORCE_UNLOAD) {
+ case PC_FORCE_UNLOAD:
+ {
findp->action = PA_UNLOAD;
- if (findp->unload(PT_ANYTIME, PNL_CMD_FORCED, PNL_CMD_FORCED)) {
+ if (findp->unload(PT_ANYTIME, PNL_CMD_FORCED, PNL_CMD_FORCED))
+ {
META_CONS("Forced unload plugin '%s'", findp->desc);
- g_plugins->show(0);
+ g_plugins->show();
}
else
META_CONS("Forced unload failed for plugin '%s'", findp->desc);
+ break;
}
- else if (pcmd == PC_RELOAD) {
+ case PC_RELOAD:
+ {
findp->action = PA_RELOAD;
if (findp->reload(PT_ANYTIME, PNL_COMMAND))
META_CONS("Reloaded plugin '%s'", findp->desc);
@@ -447,26 +436,31 @@ void cmd_doplug(PLUG_CMD pcmd)
META_CONS("Reload not allowed for plugin '%s' now, only allowed %s", findp->desc, findp->str_loadable(SL_ALLOWED));
else
META_CONS("Reload failed for plugin '%s'", findp->desc);
+ break;
}
- else if (pcmd == PC_RETRY) {
+ case PC_RETRY:
if (findp->retry(PT_ANYTIME, PNL_COMMAND))
META_CONS("Retry succeeded for plugin '%s'", findp->desc);
else
META_CONS("Retry failed for plugin '%s'", findp->desc);
- }
- else if (pcmd == PC_CLEAR) {
- if (findp->clear()) {
- META_CONS("Cleared failed plugin '%s' from list", findp->desc);
- g_plugins->show(0);
- }
- else
+ break;
+ case PC_CLEAR:
+ if (!findp->clear())
+ {
META_CONS("Clear failed for plugin '%s'", findp->desc);
- }
- else if (pcmd == PC_INFO)
+ return;
+ }
+
+ META_CONS("Cleared failed plugin '%s' from list", findp->desc);
+ g_plugins->show();
+ break;
+ case PC_INFO:
findp->show();
- else {
- META_ERROR("Unexpected plug_cmd: %d", pcmd);
+ break;
+ default:
+ META_WARNING("Unexpected plug_cmd: %d", pcmd);
META_CONS("Command failed; see log");
+ break;
}
}
}
diff --git a/metamod/src/commands_meta.h b/metamod/src/commands_meta.h
index 53b9bac..0ea7dbc 100644
--- a/metamod/src/commands_meta.h
+++ b/metamod/src/commands_meta.h
@@ -1,47 +1,11 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// commands_meta.h - prototypes for console commands
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef COMMANDS_META_H
-#define COMMANDS_META_H
-
-#include "types_meta.h" // mBOOL
+#include "types_meta.h"
// Flags to use for meta_cmd_doplug(), to operate on existing plugins; note
// "load" operates on a non-existing plugin thus isn't included here.
-typedef enum {
+enum PLUG_CMD
+{
PC_NULL = 0,
PC_PAUSE, // pause the plugin
PC_UNPAUSE, // unpause the plugin
@@ -52,24 +16,24 @@ typedef enum {
PC_CLEAR, // remove a failed plugin from the list
PC_FORCE_UNLOAD, // forcibly unload the plugin
PC_REQUIRE, // require that this plugin is loaded/running
-} PLUG_CMD;
+};
void meta_register_cmdcvar();
-void server_meta(void);
+void server_meta();
-void cmd_meta_usage(void);
-void cmd_meta_version(void);
-void cmd_meta_gpl(void);
+void cmd_meta_usage();
+void cmd_meta_version();
+void cmd_meta_gpl();
-void cmd_meta_game(void);
-void cmd_meta_refresh(void);
-void cmd_meta_load(void);
+void cmd_meta_game();
+void cmd_meta_refresh();
+void cmd_meta_load();
-void cmd_meta_pluginlist(void);
-void cmd_meta_cmdlist(void);
-void cmd_meta_cvarlist(void);
-void cmd_meta_config(void);
+void cmd_meta_pluginlist();
+void cmd_meta_cmdlist();
+void cmd_meta_cvarlist();
+void cmd_meta_config();
void cmd_doplug(PLUG_CMD pcmd);
@@ -77,5 +41,3 @@ void client_meta(edict_t *pEntity);
void client_meta_usage(edict_t *pEntity);
void client_meta_version(edict_t *pEntity);
void client_meta_pluginlist(edict_t *pEntity);
-
-#endif /* COMMANDS_META_H */
diff --git a/metamod/src/conf_meta.cpp b/metamod/src/conf_meta.cpp
index 4ac4629..0b7b45b 100644
--- a/metamod/src/conf_meta.cpp
+++ b/metamod/src/conf_meta.cpp
@@ -1,42 +1,8 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// conf_meta.cpp - configfile reading routines
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
-MConfig::MConfig() : list(NULL), filename(NULL), debuglevel(0), gamedll(NULL), plugins_file(NULL), exec_cfg(NULL)
+MConfig::MConfig()
+ : list(nullptr), filename(nullptr), debuglevel(0),
+ plugins_file(nullptr), exec_cfg(nullptr)
{
}
@@ -49,20 +15,21 @@ void MConfig::init(option_t* global_options)
set(optp, optp->init);
}
-option_t* MConfig::find(const char* lookup) const
+option_t *MConfig::find(const char* lookup) const
{
for (auto optp = list; optp->name; optp++)
- if (!strcmp(optp->name, lookup)) {
+ {
+ if (!Q_strcmp(optp->name, lookup)) {
return optp;
}
-
+ }
+
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
mBOOL MConfig::set(const char* key, const char* value)
{
option_t* optp = find(key);
-
if (optp)
return set(optp, value);
@@ -80,23 +47,28 @@ mBOOL MConfig::set(option_t* setp, const char* setstr)
if (!setstr)
return mTRUE;
- switch (setp->type) {
+ switch (setp->type)
+ {
case CF_INT:
- if (!isdigit(setstr[0])) {
+ if (!isdigit(setstr[0]))
+ {
META_ERROR("option '%s' invalid format '%s'", setp->name, setstr);
RETURN_ERRNO(mFALSE, ME_FORMAT);
}
- *optval = atoi(setstr);
+ *optval = Q_atoi(setstr);
META_DEBUG(3, ("set config int: %s = %d", setp->name, *optval));
break;
case CF_BOOL:
- if (is_yes(setstr)) {
+ if (is_yes(setstr))
+ {
*optval = TRUE;
}
- else if (is_no(setstr)) {
+ else if (is_no(setstr))
+ {
*optval = FALSE;
}
- else {
+ else
+ {
META_ERROR("option '%s' invalid format '%s'", setp->name,
setstr);
RETURN_ERRNO(mFALSE, ME_FORMAT);
@@ -105,33 +77,23 @@ mBOOL MConfig::set(option_t* setp, const char* setstr)
break;
case CF_STR:
if (*optstr)
- free(*optstr);
- *optstr = _strdup(setstr);
+ Q_free(*optstr);
+ *optstr = Q_strdup(setstr);
META_DEBUG(3, ("set config string: %s = %s", setp->name, *optstr));
break;
case CF_PATH:
if (*optstr)
- free(*optstr);
+ Q_free(*optstr);
full_gamedir_path(setstr, pathbuf);
- *optstr = _strdup(pathbuf);
+ *optstr = Q_strdup(pathbuf);
META_DEBUG(3, ("set config path: %s = %s", setp->name, *optstr));
break;
-#if 0
- case CF_CVAR:
- CVAR_SET_STRING(optcvar->name, setstr);
- META_DEBUG(3, ("set config cvar: %s = %s", optcvar->name, setstr));
- break;
- case CF_CMD:
- optcmd(setp->name, setstr);
- META_DEBUG(3, ("set config command: %s, %s",
- optcvar->name, setstr));
- break;
-#endif
default:
META_ERROR("unrecognized config type '%d'", setp->type);
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
- return (mTRUE);
+
+ return mTRUE;
}
mBOOL MConfig::load(const char* fn)
@@ -148,58 +110,61 @@ mBOOL MConfig::load(const char* fn)
full_gamedir_path(fn, loadfile);
fp = fopen(loadfile, "r");
- if (!fp) {
- META_ERROR("unable to open config file '%s': %s", loadfile,
- strerror(errno));
+ if (!fp)
+ {
+ META_ERROR("unable to open config file '%s': %s", loadfile, strerror(errno));
RETURN_ERRNO(mFALSE, ME_NOFILE);
}
META_DEBUG(2, ("Loading from config file: %s", loadfile));
- for (ln = 1; !feof(fp) && fgets(line, sizeof(line), fp); ln++) {
- if (line[0] == '#')
+ for (ln = 1; !feof(fp) && fgets(line, sizeof(line), fp); ln++)
+ {
+ if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2))
continue;
- if (line[0] == ';')
- continue;
- if (strnmatch(line, "//", 2))
- continue;
- if (!(optname = strtok(line, " \t\r\n"))) {
- META_ERROR("'%s' line %d: bad config format: missing option",
- loadfile, ln);
+
+ if (!(optname = strtok(line, " \t\r\n")))
+ {
+ META_ERROR("'%s' line %d: bad config format: missing option", loadfile, ln);
continue;
}
- if (!(optval = strtok(NULL, "\r\n"))) {
- META_ERROR("'%s' line %d: bad config format: missing value",
- loadfile, ln);
+
+ if (!(optval = strtok(NULL, "\r\n")))
+ {
+ META_ERROR("'%s' line %d: bad config format: missing value", loadfile, ln);
continue;
}
- if (!(optp = find(optname))) {
- META_ERROR("'%s' line %d: unknown option name '%s'",
- loadfile, ln, optname);
+ if (!(optp = find(optname)))
+ {
+ META_ERROR("'%s' line %d: unknown option name '%s'", loadfile, ln, optname);
continue;
}
- if (!set(optp, optval)) {
- META_ERROR("'%s' line %d: unable to set option '%s' value '%s'",
- loadfile, ln, optname, optval);
+ if (!set(optp, optval))
+ {
+ META_ERROR("'%s' line %d: unable to set option '%s' value '%s'", loadfile, ln, optname, optval);
continue;
}
}
- filename = _strdup(loadfile);
+
+ filename = Q_strdup(loadfile);
fclose(fp);
- return (mTRUE);
+ return mTRUE;
}
-void MConfig::show(void) const
+void MConfig::show() const
{
META_CONS("Config options from localinfo and %s:", filename);
- for (auto optp = list; optp->name; optp++) {
- int* optval = (int *) optp->dest;
- char** optstr = (char **) optp->dest;
+ for (auto optp = list; optp->name; optp++)
+ {
+ int *optval = (int *)optp->dest;
+ char **optstr = (char **)optp->dest;
+
// cvar_t *optcvar = (cvar_t *) optp->dest;
// SETOPT_FN optcmd = (SETOPT_FN) optp->dest;
- switch (optp->type) {
+ switch (optp->type)
+ {
case CF_INT:
printf(" %-20s\t%d\n", optp->name, *optval);
break;
@@ -210,14 +175,6 @@ void MConfig::show(void) const
case CF_PATH:
printf(" %-20s\t%s\n", optp->name, *optstr ? *optstr : "");
break;
-#if 0
- case CF_CVAR:
- printf(" %-20s\tstores in: %s\n", optp->name, optcvar->name);
- break;
- case CF_CMD:
- printf(" %-20s\tparsed by: %d\n", optp->name, (int) optcmd);
- break;
-#endif
case CF_NONE:
break;
}
diff --git a/metamod/src/conf_meta.h b/metamod/src/conf_meta.h
index 7da3354..e5865c4 100644
--- a/metamod/src/conf_meta.h
+++ b/metamod/src/conf_meta.h
@@ -1,96 +1,49 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// conf_meta.h - configfile reading
-
-// Modeled after mutt/init.[ch].
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef CONF_META_H
-#define CONF_META_H
-
-#include "types_meta.h" // mBOOL
+#include "types_meta.h"
// Max length of line in config file.
#define MAX_CONF_LEN 1024
// Supported config value-types.
-typedef enum {
- CF_NONE=0,
+enum cf_type_t
+{
+ CF_NONE = 0,
CF_INT,
CF_BOOL,
CF_STR,
CF_PATH,
-#if 0
- CF_CVAR,
- CF_CMD,
-#endif
-} cf_type_t;
-
-typedef mBOOL (*SETOPT_FN) (char *key, char *value);
-
-typedef struct option_s {
- const char *name; // option name
- cf_type_t type; // option type
- void *dest; // addr of destination variable, or handler function
- const char *init; // initial value, as a string, just as config file would
-} option_t;
-
-class MConfig {
- private:
- // data
- option_t *list;
- char *filename;
- // functions
- option_t *find(const char *lookup) const;
- static mBOOL set(option_t *setp, const char *value);
- // Private; to satisfy -Weffc++ "has pointer data members but does
- // not override" copy/assignment constructor.
- void operator=(const MConfig &src);
- MConfig(const MConfig &src);
- public:
- // contructor
- MConfig(void);
- // data
- int debuglevel; // to use for meta_debug
- char *gamedll; // string if specified in config.ini
- char *plugins_file; // ie metamod.ini, plugins.ini
- char *exec_cfg; // ie metaexec.cfg, exec.cfg
- // functions
- void init(option_t *global_options);
- mBOOL load(const char *filename);
- mBOOL set(const char *key, const char *value);
- void show(void) const;
};
-#endif /* CONF_META_H */
+struct option_t
+{
+ char *name; // option name
+ cf_type_t type; // option type
+ void *dest; // addr of destination variable, or handler function
+ char *init; // initial value, as a string, just as config file would
+};
+
+class MConfig {
+public:
+ MConfig();
+
+ int debuglevel; // to use for meta_debug
+ char *plugins_file; // ie metamod.ini, plugins.ini
+ char *exec_cfg; // ie metaexec.cfg, exec.cfg
+
+ void init(option_t *global_options);
+ mBOOL load(const char *filename);
+ mBOOL set(const char *key, const char *value);
+ void show() const;
+
+private:
+ option_t *list;
+ char *filename;
+
+ option_t *find(const char *lookup) const;
+ static mBOOL set(option_t *setp, const char *value);
+ // Private; to satisfy -Weffc++ "has pointer data members but does
+ // not override" copy/assignment constructor.
+ void operator=(const MConfig &src);
+ MConfig(const MConfig &src);
+};
diff --git a/metamod/src/dllapi.cpp b/metamod/src/dllapi.cpp
index 2deac6e..e41dbf3 100644
--- a/metamod/src/dllapi.cpp
+++ b/metamod/src/dllapi.cpp
@@ -1,39 +1,3 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// dllapi.cpp - implementation of Half-Life DLL routines
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// Original DLL routines, functions returning "void".
@@ -65,113 +29,152 @@
CALL_GAME_API(pfnName, pfn_args, newapi_table); \
CALL_PLUGIN_API(P_POST, ret_init, pfnName, pfn_args, MRES_OVERRIDE, newapi_post_table);
-
-// From SDK dlls/game.cpp:
-void mm_GameDLLInit(void) {
+void mm_GameDLLInit(void)
+{
META_DLLAPI_HANDLE_void(FN_GAMEINIT, pfnGameInit, ());
RETURN_API_void();
}
-// From SDK dlls/cbase.cpp:
-int mm_DispatchSpawn(edict_t *pent) {
- // 0==Success, -1==Failure ?
+int mm_DispatchSpawn(edict_t *pent)
+{
+ // Success == 0, Failure == -1 ?
META_DLLAPI_HANDLE(int, 0, FN_DISPATCHSPAWN, pfnSpawn, (pent));
RETURN_API();
}
-void mm_DispatchThink(edict_t *pent) {
+
+void mm_DispatchThink(edict_t *pent)
+{
META_DLLAPI_HANDLE_void(FN_DISPATCHTHINK, pfnThink, (pent));
RETURN_API_void();
}
-void mm_DispatchUse(edict_t *pentUsed, edict_t *pentOther) {
+
+void mm_DispatchUse(edict_t *pentUsed, edict_t *pentOther)
+{
META_DLLAPI_HANDLE_void(FN_DISPATCHUSE, pfnUse, (pentUsed, pentOther));
RETURN_API_void();
}
-void mm_DispatchTouch(edict_t *pentTouched, edict_t *pentOther) {
+
+void mm_DispatchTouch(edict_t *pentTouched, edict_t *pentOther)
+{
META_DLLAPI_HANDLE_void(FN_DISPATCHTOUCH, pfnTouch, (pentTouched, pentOther));
RETURN_API_void();
}
-void mm_DispatchBlocked(edict_t *pentBlocked, edict_t *pentOther) {
+
+void mm_DispatchBlocked(edict_t *pentBlocked, edict_t *pentOther)
+{
META_DLLAPI_HANDLE_void(FN_DISPATCHBLOCKED, pfnBlocked, (pentBlocked, pentOther));
RETURN_API_void();
}
-void mm_DispatchKeyValue(edict_t *pentKeyvalue, KeyValueData *pkvd) {
+
+void mm_DispatchKeyValue(edict_t *pentKeyvalue, KeyValueData *pkvd)
+{
META_DLLAPI_HANDLE_void(FN_DISPATCHKEYVALUE, pfnKeyValue, (pentKeyvalue, pkvd));
RETURN_API_void();
}
-void mm_DispatchSave(edict_t *pent, SAVERESTOREDATA *pSaveData) {
+
+void mm_DispatchSave(edict_t *pent, SAVERESTOREDATA *pSaveData)
+{
META_DLLAPI_HANDLE_void(FN_DISPATCHSAVE, pfnSave, (pent, pSaveData));
RETURN_API_void();
}
-int mm_DispatchRestore(edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity) {
- // 0==Success, -1==Failure ?
+
+int mm_DispatchRestore(edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity)
+{
+ // Success == 0, Failure == -1 ?
META_DLLAPI_HANDLE(int, 0, FN_DISPATCHRESTORE, pfnRestore, (pent, pSaveData, globalEntity));
RETURN_API();
}
-void mm_DispatchObjectCollsionBox(edict_t *pent) {
+
+void mm_DispatchObjectCollsionBox(edict_t *pent)
+{
META_DLLAPI_HANDLE_void(FN_DISPATCHOBJECTCOLLISIONBOX, pfnSetAbsBox, (pent));
RETURN_API_void();
}
-void mm_SaveWriteFields(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount) {
+
+void mm_SaveWriteFields(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount)
+{
META_DLLAPI_HANDLE_void(FN_SAVEWRITEFIELDS, pfnSaveWriteFields, (pSaveData, pname, pBaseData, pFields, fieldCount));
RETURN_API_void();
}
-void mm_SaveReadFields(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount) {
+
+void mm_SaveReadFields(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount)
+{
META_DLLAPI_HANDLE_void(FN_SAVEREADFIELDS, pfnSaveReadFields, (pSaveData, pname, pBaseData, pFields, fieldCount));
RETURN_API_void();
}
-// From SDK dlls/world.cpp:
-void mm_SaveGlobalState(SAVERESTOREDATA *pSaveData) {
+void mm_SaveGlobalState(SAVERESTOREDATA *pSaveData)
+{
META_DLLAPI_HANDLE_void(FN_SAVEGLOBALSTATE, pfnSaveGlobalState, (pSaveData));
RETURN_API_void();
}
-void mm_RestoreGlobalState(SAVERESTOREDATA *pSaveData) {
+
+void mm_RestoreGlobalState(SAVERESTOREDATA *pSaveData)
+{
META_DLLAPI_HANDLE_void(FN_RESTOREGLOBALSTATE, pfnRestoreGlobalState, (pSaveData));
RETURN_API_void();
}
-void mm_ResetGlobalState(void) {
+
+void mm_ResetGlobalState(void)
+{
META_DLLAPI_HANDLE_void(FN_RESETGLOBALSTATE, pfnResetGlobalState, ());
RETURN_API_void();
}
-// From SDK dlls/client.cpp:
-BOOL mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] ) {
+BOOL mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] )
+{
g_Players.clear_player_cvar_query(pEntity);
META_DLLAPI_HANDLE(BOOL, TRUE, FN_CLIENTCONNECT, pfnClientConnect, (pEntity, pszName, pszAddress, szRejectReason));
RETURN_API();
}
-void mm_ClientDisconnect(edict_t *pEntity) {
+
+void mm_ClientDisconnect(edict_t *pEntity)
+{
g_Players.clear_player_cvar_query(pEntity);
META_DLLAPI_HANDLE_void(FN_CLIENTDISCONNECT, pfnClientDisconnect, (pEntity));
RETURN_API_void();
}
-void mm_ClientKill(edict_t *pEntity) {
+
+void mm_ClientKill(edict_t *pEntity)
+{
META_DLLAPI_HANDLE_void(FN_CLIENTKILL, pfnClientKill, (pEntity));
RETURN_API_void();
}
-void mm_ClientPutInServer(edict_t *pEntity) {
+
+void mm_ClientPutInServer(edict_t *pEntity)
+{
META_DLLAPI_HANDLE_void(FN_CLIENTPUTINSERVER, pfnClientPutInServer, (pEntity));
RETURN_API_void();
}
-void mm_ClientCommand(edict_t *pEntity) {
- if(!strcmp(CMD_ARGV(0), "meta")) {
+
+void mm_ClientCommand(edict_t *pEntity)
+{
+ if (!Q_strcmp(CMD_ARGV(0), "meta"))
+ {
client_meta(pEntity);
}
+
META_DLLAPI_HANDLE_void(FN_CLIENTCOMMAND, pfnClientCommand, (pEntity));
RETURN_API_void();
}
-void mm_ClientUserInfoChanged(edict_t *pEntity, char *infobuffer) {
+
+void mm_ClientUserInfoChanged(edict_t *pEntity, char *infobuffer)
+{
META_DLLAPI_HANDLE_void(FN_CLIENTUSERINFOCHANGED, pfnClientUserInfoChanged, (pEntity, infobuffer));
RETURN_API_void();
}
-void mm_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) {
+
+void mm_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
+{
META_DLLAPI_HANDLE_void(FN_SERVERACTIVATE, pfnServerActivate, (pEdictList, edictCount, clientMax));
RETURN_API_void();
}
-void mm_ServerDeactivate(void) {
+
+void mm_ServerDeactivate(void)
+{
META_DLLAPI_HANDLE_void(FN_SERVERDEACTIVATE, pfnServerDeactivate, ());
// Update loaded plugins. Look for new plugins in inifile, as well as
- // any plugins waiting for a changelevel to load.
+ // any plugins waiting for a changelevel to load.
//
// This is done in ServerDeactivate rather than Activate, as the latter
// isn't actually the first routine to be called on a new map. In
@@ -190,217 +193,269 @@ void mm_ServerDeactivate(void) {
requestid_counter = 0;
RETURN_API_void();
}
-void mm_PlayerPreThink(edict_t *pEntity) {
+
+void mm_PlayerPreThink(edict_t *pEntity)
+{
META_DLLAPI_HANDLE_void(FN_PLAYERPRETHINK, pfnPlayerPreThink, (pEntity));
RETURN_API_void();
}
-void mm_PlayerPostThink(edict_t *pEntity) {
+
+void mm_PlayerPostThink(edict_t *pEntity)
+{
META_DLLAPI_HANDLE_void(FN_PLAYERPOSTTHINK, pfnPlayerPostThink, (pEntity));
RETURN_API_void();
}
-void mm_StartFrame(void) {
+
+void mm_StartFrame(void)
+{
META_DLLAPI_HANDLE_void(FN_STARTFRAME, pfnStartFrame, ());
RETURN_API_void();
}
-void mm_ParmsNewLevel(void) {
+
+void mm_ParmsNewLevel(void)
+{
META_DLLAPI_HANDLE_void(FN_PARMSNEWLEVEL, pfnParmsNewLevel, ());
RETURN_API_void();
}
-void mm_ParmsChangeLevel(void) {
+
+void mm_ParmsChangeLevel(void)
+{
META_DLLAPI_HANDLE_void(FN_PARMSCHANGELEVEL, pfnParmsChangeLevel, ());
RETURN_API_void();
}
-const char *mm_GetGameDescription(void) {
+
+const char *mm_GetGameDescription(void)
+{
META_DLLAPI_HANDLE(const char *, NULL, FN_GETGAMEDESCRIPTION, pfnGetGameDescription, ());
RETURN_API();
}
-void mm_PlayerCustomization(edict_t *pEntity, customization_t *pCust) {
+
+void mm_PlayerCustomization(edict_t *pEntity, customization_t *pCust)
+{
META_DLLAPI_HANDLE_void(FN_PLAYERCUSTOMIZATION, pfnPlayerCustomization, (pEntity, pCust));
RETURN_API_void();
}
-void mm_SpectatorConnect(edict_t *pEntity) {
+
+void mm_SpectatorConnect(edict_t *pEntity)
+{
META_DLLAPI_HANDLE_void(FN_SPECTATORCONNECT, pfnSpectatorConnect, (pEntity));
RETURN_API_void();
}
-void mm_SpectatorDisconnect(edict_t *pEntity) {
+
+void mm_SpectatorDisconnect(edict_t *pEntity)
+{
META_DLLAPI_HANDLE_void(FN_SPECTATORDISCONNECT, pfnSpectatorDisconnect, (pEntity));
RETURN_API_void();
}
-void mm_SpectatorThink(edict_t *pEntity) {
+
+void mm_SpectatorThink(edict_t *pEntity)
+{
META_DLLAPI_HANDLE_void(FN_SPECTATORTHINK, pfnSpectatorThink, (pEntity));
RETURN_API_void();
}
-void mm_Sys_Error(const char *error_string) {
+
+void mm_Sys_Error(const char *error_string)
+{
META_DLLAPI_HANDLE_void(FN_SYS_ERROR, pfnSys_Error, (error_string));
RETURN_API_void();
}
-// From SDK pm_shared/pm_shared.c:
-void mm_PM_Move (struct playermove_s *ppmove, int server) {
+void mm_PM_Move (struct playermove_s *ppmove, int server)
+{
META_DLLAPI_HANDLE_void(FN_PM_MOVE, pfnPM_Move, (ppmove, server));
RETURN_API_void();
}
-void mm_PM_Init(struct playermove_s *ppmove) {
+
+void mm_PM_Init(struct playermove_s *ppmove)
+{
META_DLLAPI_HANDLE_void(FN_PM_INIT, pfnPM_Init, (ppmove));
RETURN_API_void();
}
-char mm_PM_FindTextureType(char *name) {
+
+char mm_PM_FindTextureType(char *name)
+{
META_DLLAPI_HANDLE(char, '\0', FN_PM_FINDTEXTURETYPE, pfnPM_FindTextureType, (name));
RETURN_API();
}
-// From SDK dlls/client.cpp:
-void mm_SetupVisibility(edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas) {
+void mm_SetupVisibility(edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas)
+{
META_DLLAPI_HANDLE_void(FN_SETUPVISIBILITY, pfnSetupVisibility, (pViewEntity, pClient, pvs, pas));
RETURN_API_void();
}
-void mm_UpdateClientData (const struct edict_s *ent, int sendweapons, struct clientdata_s *cd) {
+
+void mm_UpdateClientData (const struct edict_s *ent, int sendweapons, struct clientdata_s *cd)
+{
META_DLLAPI_HANDLE_void(FN_UPDATECLIENTDATA, pfnUpdateClientData, (ent, sendweapons, cd));
RETURN_API_void();
}
-int mm_AddToFullPack(struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet) {
+
+int mm_AddToFullPack(struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet)
+{
META_DLLAPI_HANDLE(int, 0, FN_ADDTOFULLPACK, pfnAddToFullPack, (state, e, ent, host, hostflags, player, pSet));
RETURN_API();
}
-void mm_CreateBaseline(int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs) {
+
+void mm_CreateBaseline(int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs)
+{
META_DLLAPI_HANDLE_void(FN_CREATEBASELINE, pfnCreateBaseline, (player, eindex, baseline, entity, playermodelindex, player_mins, player_maxs));
RETURN_API_void();
}
-void mm_RegisterEncoders(void) {
+
+void mm_RegisterEncoders(void)
+{
META_DLLAPI_HANDLE_void(FN_REGISTERENCODERS, pfnRegisterEncoders, ());
RETURN_API_void();
}
-int mm_GetWeaponData(struct edict_s *player, struct weapon_data_s *info) {
+
+int mm_GetWeaponData(struct edict_s *player, struct weapon_data_s *info)
+{
META_DLLAPI_HANDLE(int, 0, FN_GETWEAPONDATA, pfnGetWeaponData, (player, info));
RETURN_API();
}
-void mm_CmdStart(const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed) {
+
+void mm_CmdStart(const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed)
+{
META_DLLAPI_HANDLE_void(FN_CMDSTART, pfnCmdStart, (player, cmd, random_seed));
RETURN_API_void();
}
-void mm_CmdEnd (const edict_t *player) {
+
+void mm_CmdEnd (const edict_t *player)
+{
META_DLLAPI_HANDLE_void(FN_CMDEND, pfnCmdEnd, (player));
RETURN_API_void();
}
-int mm_ConnectionlessPacket(const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size) {
+
+int mm_ConnectionlessPacket(const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size)
+{
META_DLLAPI_HANDLE(int, 0, FN_CONNECTIONLESSPACKET, pfnConnectionlessPacket, (net_from, args, response_buffer, response_buffer_size));
RETURN_API();
}
-int mm_GetHullBounds(int hullnumber, float *mins, float *maxs) {
+
+int mm_GetHullBounds(int hullnumber, float *mins, float *maxs)
+{
META_DLLAPI_HANDLE(int, 0, FN_GETHULLBOUNDS, pfnGetHullBounds, (hullnumber, mins, maxs));
RETURN_API();
}
-void mm_CreateInstancedBaselines (void) {
+
+void mm_CreateInstancedBaselines (void)
+{
META_DLLAPI_HANDLE_void(FN_CREATEINSTANCEDBASELINES, pfnCreateInstancedBaselines, ());
RETURN_API_void();
}
-int mm_InconsistentFile(const edict_t *player, const char *filename, char *disconnect_message) {
+
+int mm_InconsistentFile(const edict_t *player, const char *filename, char *disconnect_message)
+{
META_DLLAPI_HANDLE(int, 0, FN_INCONSISTENTFILE, pfnInconsistentFile, (player, filename, disconnect_message));
RETURN_API();
}
-int mm_AllowLagCompensation(void) {
+
+int mm_AllowLagCompensation(void)
+{
META_DLLAPI_HANDLE(int, 0, FN_ALLOWLAGCOMPENSATION, pfnAllowLagCompensation, ());
RETURN_API();
}
-
-// New API functions
-// From SDK ?
-void mm_OnFreeEntPrivateData(edict_t *pEnt) {
+void mm_OnFreeEntPrivateData(edict_t *pEnt)
+{
META_NEWAPI_HANDLE_void(FN_ONFREEENTPRIVATEDATA, pfnOnFreeEntPrivateData, (pEnt));
RETURN_API_void();
}
-void mm_GameShutdown(void) {
+
+void mm_GameShutdown(void)
+{
META_NEWAPI_HANDLE_void(FN_GAMESHUTDOWN, pfnGameShutdown, ());
RETURN_API_void();
}
-int mm_ShouldCollide(edict_t *pentTouched, edict_t *pentOther) {
+
+int mm_ShouldCollide(edict_t *pentTouched, edict_t *pentOther)
+{
META_NEWAPI_HANDLE(int, 1, FN_SHOULDCOLLIDE, pfnShouldCollide, (pentTouched, pentOther));
RETURN_API();
}
-// Added 2005-08-11 (no SDK update)
-void mm_CvarValue(const edict_t *pEdict, const char *value) {
+
+void mm_CvarValue(const edict_t *pEdict, const char *value)
+{
g_Players.clear_player_cvar_query(pEdict);
META_NEWAPI_HANDLE_void(FN_CVARVALUE, pfnCvarValue, (pEdict, value));
RETURN_API_void();
}
-//Added 2005-11-22 (no SDK update)
-void mm_CvarValue2(const edict_t *pEdict, int requestID, const char *cvarName, const char *value) {
+void mm_CvarValue2(const edict_t *pEdict, int requestID, const char *cvarName, const char *value)
+{
META_NEWAPI_HANDLE_void(FN_CVARVALUE2, pfnCvarValue2, (pEdict, requestID, cvarName, value));
RETURN_API_void();
}
-// From SDK dlls/cbase.cpp:
// "(wd)" indicates my comments on the functions
-static DLL_FUNCTIONS sFunctionTable =
+DLL_FUNCTIONS sFunctionTable =
{
- mm_GameDLLInit, //! pfnGameInit() Initialize the game (one-time call after loading of game .dll)
- mm_DispatchSpawn, //! pfnSpawn()
- mm_DispatchThink, //! pfnThink()
- mm_DispatchUse, //! pfnUse()
- mm_DispatchTouch, //! pfnTouch()
- mm_DispatchBlocked, //! pfnBlocked()
- mm_DispatchKeyValue, //! pfnKeyValue()
- mm_DispatchSave, //! pfnSave()
- mm_DispatchRestore, //! pfnRestore()
- mm_DispatchObjectCollsionBox, //! pfnSetAbsBox()
+ mm_GameDLLInit, // pfnGameInit() Initialize the game (one-time call after loading of game .dll)
+ mm_DispatchSpawn, // pfnSpawn()
+ mm_DispatchThink, // pfnThink()
+ mm_DispatchUse, // pfnUse()
+ mm_DispatchTouch, // pfnTouch()
+ mm_DispatchBlocked, // pfnBlocked()
+ mm_DispatchKeyValue, // pfnKeyValue()
+ mm_DispatchSave, // pfnSave()
+ mm_DispatchRestore, // pfnRestore()
+ mm_DispatchObjectCollsionBox, // pfnSetAbsBox()
- mm_SaveWriteFields, //! pfnSaveWriteFields()
- mm_SaveReadFields, //! pfnSaveReadFields()
+ mm_SaveWriteFields, // pfnSaveWriteFields()
+ mm_SaveReadFields, // pfnSaveReadFields()
- mm_SaveGlobalState, //! pfnSaveGlobalState()
- mm_RestoreGlobalState, //! pfnRestoreGlobalState()
- mm_ResetGlobalState, //! pfnResetGlobalState()
+ mm_SaveGlobalState, // pfnSaveGlobalState()
+ mm_RestoreGlobalState, // pfnRestoreGlobalState()
+ mm_ResetGlobalState, // pfnResetGlobalState()
- mm_ClientConnect, //! pfnClientConnect() (wd) Client has connected
- mm_ClientDisconnect, //! pfnClientDisconnect() (wd) Player has left the game
- mm_ClientKill, //! pfnClientKill() (wd) Player has typed "kill"
- mm_ClientPutInServer, //! pfnClientPutInServer() (wd) Client is entering the game
- mm_ClientCommand, //! pfnClientCommand() (wd) Player has sent a command (typed, or from a bind)
- mm_ClientUserInfoChanged, //! pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure
- mm_ServerActivate, //! pfnServerActivate() (wd) Server is starting a new map
- mm_ServerDeactivate, //! pfnServerDeactivate() (wd) Server is leaving the map (shutdown, or changelevel); SDK2
+ mm_ClientConnect, // pfnClientConnect() (wd) Client has connected
+ mm_ClientDisconnect, // pfnClientDisconnect() (wd) Player has left the game
+ mm_ClientKill, // pfnClientKill() (wd) Player has typed "kill"
+ mm_ClientPutInServer, // pfnClientPutInServer() (wd) Client is entering the game
+ mm_ClientCommand, // pfnClientCommand() (wd) Player has sent a command (typed, or from a bind)
+ mm_ClientUserInfoChanged, // pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure
+ mm_ServerActivate, // pfnServerActivate() (wd) Server is starting a new map
+ mm_ServerDeactivate, // pfnServerDeactivate() (wd) Server is leaving the map (shutdown, or changelevel); SDK2
- mm_PlayerPreThink, //! pfnPlayerPreThink()
- mm_PlayerPostThink, //! pfnPlayerPostThink()
+ mm_PlayerPreThink, // pfnPlayerPreThink()
+ mm_PlayerPostThink, // pfnPlayerPostThink()
- mm_StartFrame, //! pfnStartFrame()
- mm_ParmsNewLevel, //! pfnParmsNewLevel()
- mm_ParmsChangeLevel, //! pfnParmsChangeLevel()
+ mm_StartFrame, // pfnStartFrame()
+ mm_ParmsNewLevel, // pfnParmsNewLevel()
+ mm_ParmsChangeLevel, // pfnParmsChangeLevel()
- mm_GetGameDescription, //! pfnGetGameDescription() Returns string describing current .dll. E.g. "TeamFotrress 2", "Half-Life"
- mm_PlayerCustomization, //! pfnPlayerCustomization() Notifies .dll of new customization for player.
+ mm_GetGameDescription, // pfnGetGameDescription() Returns string describing current .dll. E.g. "TeamFotrress 2", "Half-Life"
+ mm_PlayerCustomization, // pfnPlayerCustomization() Notifies .dll of new customization for player.
- mm_SpectatorConnect, //! pfnSpectatorConnect() Called when spectator joins server
- mm_SpectatorDisconnect, //! pfnSpectatorDisconnect() Called when spectator leaves the server
- mm_SpectatorThink, //! pfnSpectatorThink() Called when spectator sends a command packet (usercmd_t)
+ mm_SpectatorConnect, // pfnSpectatorConnect() Called when spectator joins server
+ mm_SpectatorDisconnect, // pfnSpectatorDisconnect() Called when spectator leaves the server
+ mm_SpectatorThink, // pfnSpectatorThink() Called when spectator sends a command packet (usercmd_t)
- mm_Sys_Error, //! pfnSys_Error() Notify game .dll that engine is going to shut down. Allows mod authors to set a breakpoint. SDK2
+ mm_Sys_Error, // pfnSys_Error() Notify game .dll that engine is going to shut down. Allows mod authors to set a breakpoint. SDK2
- mm_PM_Move, //! pfnPM_Move() (wd) SDK2
- mm_PM_Init, //! pfnPM_Init() Server version of player movement initialization; (wd) SDK2
- mm_PM_FindTextureType, //! pfnPM_FindTextureType() (wd) SDK2
+ mm_PM_Move, // pfnPM_Move() (wd) SDK2
+ mm_PM_Init, // pfnPM_Init() Server version of player movement initialization; (wd) SDK2
+ mm_PM_FindTextureType, // pfnPM_FindTextureType() (wd) SDK2
- mm_SetupVisibility, //! pfnSetupVisibility() Set up PVS and PAS for networking for this client; (wd) SDK2
- mm_UpdateClientData, //! pfnUpdateClientData() Set up data sent only to specific client; (wd) SDK2
- mm_AddToFullPack, //! pfnAddToFullPack() (wd) SDK2
- mm_CreateBaseline, //! pfnCreateBaseline() Tweak entity baseline for network encoding, allows setup of player baselines, too.; (wd) SDK2
- mm_RegisterEncoders, //! pfnRegisterEncoders() Callbacks for network encoding; (wd) SDK2
- mm_GetWeaponData, //! pfnGetWeaponData() (wd) SDK2
- mm_CmdStart, //! pfnCmdStart() (wd) SDK2
- mm_CmdEnd, //! pfnCmdEnd() (wd) SDK2
- mm_ConnectionlessPacket, //! pfnConnectionlessPacket() (wd) SDK2
- mm_GetHullBounds, //! pfnGetHullBounds() (wd) SDK2
- mm_CreateInstancedBaselines, //! pfnCreateInstancedBaselines() (wd) SDK2
- mm_InconsistentFile, //! pfnInconsistentFile() (wd) SDK2
- mm_AllowLagCompensation, //! pfnAllowLagCompensation() (wd) SDK2
+ mm_SetupVisibility, // pfnSetupVisibility() Set up PVS and PAS for networking for this client; (wd) SDK2
+ mm_UpdateClientData, // pfnUpdateClientData() Set up data sent only to specific client; (wd) SDK2
+ mm_AddToFullPack, // pfnAddToFullPack() (wd) SDK2
+ mm_CreateBaseline, // pfnCreateBaseline() Tweak entity baseline for network encoding, allows setup of player baselines, too.; (wd) SDK2
+ mm_RegisterEncoders, // pfnRegisterEncoders() Callbacks for network encoding; (wd) SDK2
+ mm_GetWeaponData, // pfnGetWeaponData() (wd) SDK2
+ mm_CmdStart, // pfnCmdStart() (wd) SDK2
+ mm_CmdEnd, // pfnCmdEnd() (wd) SDK2
+ mm_ConnectionlessPacket, // pfnConnectionlessPacket() (wd) SDK2
+ mm_GetHullBounds, // pfnGetHullBounds() (wd) SDK2
+ mm_CreateInstancedBaselines, // pfnCreateInstancedBaselines() (wd) SDK2
+ mm_InconsistentFile, // pfnInconsistentFile() (wd) SDK2
+ mm_AllowLagCompensation, // pfnAllowLagCompensation() (wd) SDK2
};
DLL_FUNCTIONS *pHookedDllFunctions = &sFunctionTable;
// It's not clear what the difference is between GetAPI and GetAPI2; they
-// both appear to return the exact same function table.
+// both appear to return the exact same function table.
//
// Only one of them appears to be ever called, though. If the DLL provides
// GetAPI2, the engine/hlds will call that, and will not call GetAPI. If
@@ -414,52 +469,48 @@ DLL_FUNCTIONS *pHookedDllFunctions = &sFunctionTable;
//
// It's unclear whether a DLL coded under SDK2 needs to provide the older
// GetAPI or not..
-
C_DLLEXPORT int GetEntityAPI(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion)
{
META_DEBUG(3, ("called: GetEntityAPI; version=%d", interfaceVersion));
- if(!pFunctionTable) {
+ if (!pFunctionTable)
+ {
META_ERROR("GetEntityAPI called with null pFunctionTable");
- return(FALSE);
+ return FALSE;
}
- else if(interfaceVersion != INTERFACE_VERSION) {
+ else if (interfaceVersion != INTERFACE_VERSION)
+ {
META_ERROR("GetEntityAPI version mismatch; requested=%d ours=%d", interfaceVersion, INTERFACE_VERSION);
- return(FALSE);
+ return FALSE;
}
-
- memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
-
-
- return(TRUE);
+ Q_memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
+ return TRUE;
}
C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
{
META_DEBUG(3, ("called: GetEntityAPI2; version=%d", *interfaceVersion));
- if(!pFunctionTable) {
+ if (!pFunctionTable)
+ {
META_ERROR("GetEntityAPI2 called with null pFunctionTable");
- return(FALSE);
+ return FALSE;
}
- else if(*interfaceVersion != INTERFACE_VERSION) {
+ else if (*interfaceVersion != INTERFACE_VERSION)
+ {
META_ERROR("GetEntityAPI2 version mismatch; requested=%d ours=%d", *interfaceVersion, INTERFACE_VERSION);
//! Tell engine what version we had, so it can figure out who is out of date.
*interfaceVersion = INTERFACE_VERSION;
- return(FALSE);
+ return FALSE;
}
-
- memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
-
-
- return(TRUE);
+ Q_memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
+ return TRUE;
}
-
// I could find _no_ documentation or examples for the intended use of
-// NEW_DLL_FUNCTIONS. I wouldn't have even _known_ about the
-// GetNewDLLFunctions() function except for the reference in Adminmod.. It
+// NEW_DLL_FUNCTIONS. I wouldn't have even _known_ about the
+// GetNewDLLFunctions() function except for the reference in Adminmod.. It
// appears to be new with SDK 2.0.
//
// Obviously, it seems to provide additional functions to the engine, but
@@ -468,46 +519,42 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi
//
// Interestingly, it appears to be called by the engine _before_ GetAPI.
-static meta_new_dll_functions_t sNewFunctionTable (
- &mm_OnFreeEntPrivateData, //! pfnOnFreeEntPrivateData() Called right before the object's memory is freed. Calls its destructor.
- &mm_GameShutdown, //! pfnGameShutdown()
- &mm_ShouldCollide, //! pfnShouldCollide()
- // Added 2005-08-11 (no SDK update)
- &mm_CvarValue, //! pfnCvarValue() (fz) Obsolete! Use mm_CvarValue2 instead
- // Added 2005-11-22 (no SDK update)
- &mm_CvarValue2 //! pfnCvarValue2() (fz) When pfnQueryClientCvarValue2() completes it will call
- //! pfnCvarValue2() with the request ID supplied earlier, the name of
- //! the cvar requested and the value of that cvar.
-);
+meta_new_dll_functions_t sNewFunctionTable (
+ &mm_OnFreeEntPrivateData, // pfnOnFreeEntPrivateData() Called right before the object's memory is freed. Calls its destructor.
+ &mm_GameShutdown, // pfnGameShutdown()
+ &mm_ShouldCollide, // pfnShouldCollide()
+ &mm_CvarValue, // pfnCvarValue() (fz) Use mm_CvarValue2 instead
+ &mm_CvarValue2 // pfnCvarValue2() (fz) When pfnQueryClientCvarValue2() completes it will call
+ // pfnCvarValue2() with the request ID supplied earlier, the name of the cvar requested and the value of that cvar.
+);
NEW_DLL_FUNCTIONS *pHookedNewDllFunctions = &sNewFunctionTable;
-C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion)
+C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion)
{
META_DEBUG(6, ("called: GetNewDLLFunctions; version=%d", *interfaceVersion));
#if 0 // ~dvander - but then you can't use cvar querying on many mods...
// Don't provide these functions to engine if gamedll doesn't provide
- // them. Otherwise, we're in the position of having to provide answers
+ // them. Otherwise, we're in the position of having to provide answers
// we can't necessarily provide (for instance, ShouldCollide())...
- if(!GameDLL.funcs.newapi_table)
- return(FALSE);
+ if (!GameDLL.funcs.newapi_table)
+ return FALSE;
#endif
- if(!pNewFunctionTable) {
+ if (!pNewFunctionTable)
+ {
META_ERROR("GetNewDLLFunctions called with null pNewFunctionTable");
- return(FALSE);
+ return FALSE;
}
- else if(*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) {
+ else if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION)
+ {
META_ERROR("GetNewDLLFunctions version mismatch; requested=%d ours=%d", *interfaceVersion, NEW_DLL_FUNCTIONS_VERSION);
//! Tell engine what version we had, so it can figure out who is out of date.
*interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;
- return(FALSE);
+ return FALSE;
}
sNewFunctionTable.copy_to(pNewFunctionTable);
-
-
- return(TRUE);
+ return TRUE;
}
-
diff --git a/metamod/src/dllapi.h b/metamod/src/dllapi.h
index f1967ef..567523f 100644
--- a/metamod/src/dllapi.h
+++ b/metamod/src/dllapi.h
@@ -1,192 +1,126 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// dllapi.h - prototypes and typedefs for Half-Life DLL API routines
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef DLLAPI_H
-#define DLLAPI_H
-
-#include "sdk_util.h" // BOOL
-#include "osdep.h" // DLLEXPORT, etc
+#include "sdk_util.h"
+#include "osdep.h"
// Typedefs for these are provided in SDK engine/eiface.h, but I didn't
// like the names (APIFUNCTION, APIFUNCTION2, NEW_DLL_FUNCTIONS_FN).
-typedef int (*GETENTITYAPI_FN) (DLL_FUNCTIONS *pFunctionTable, int interfaceVersion);
-typedef int (*GETENTITYAPI2_FN) (DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion);
-typedef int (*GETNEWDLLFUNCTIONS_FN) (NEW_DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion);
+typedef int (*GETENTITYAPI_FN)(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion);
+typedef int (*GETENTITYAPI2_FN)(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion);
+typedef int (*GETNEWDLLFUNCTIONS_FN)(NEW_DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion);
-// From SDK dlls/cbase.h:
-C_DLLEXPORT int GetEntityAPI( DLL_FUNCTIONS *pFunctionTable, int interfaceVersion );
-C_DLLEXPORT int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion );
+C_DLLEXPORT int GetEntityAPI(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion);
+C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion);
+C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion);
-// No example in SDK..
-// From Adminmod dll.cpp:
-C_DLLEXPORT int GetNewDLLFunctions( NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion );
-
-
-// From SDK dlls/game.h:
-extern void mm_GameDLLInit( void );
-
-// From SDK dlls/cbase.h:
-extern int mm_DispatchSpawn( edict_t *pent );
-extern void mm_DispatchThink( edict_t *pent );
-extern void mm_DispatchUse( edict_t *pentUsed, edict_t *pentOther );
-extern void mm_DispatchTouch( edict_t *pentTouched, edict_t *pentOther );
-extern void mm_DispatchBlocked( edict_t *pentBlocked, edict_t *pentOther );
-extern void mm_DispatchKeyValue( edict_t *pentKeyvalue, KeyValueData *pkvd );
-extern void mm_DispatchSave( edict_t *pent, SAVERESTOREDATA *pSaveData );
-extern int mm_DispatchRestore( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity );
-extern void mm_DispatchObjectCollisionBox( edict_t *pent );
-extern void mm_SaveWriteFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount );
-extern void mm_SaveReadFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount );
-extern void mm_SaveGlobalState( SAVERESTOREDATA *pSaveData );
-extern void mm_RestoreGlobalState( SAVERESTOREDATA *pSaveData );
-extern void mm_ResetGlobalState( void );
-
-// From SDK dlls/client.h:
-extern BOOL mm_ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] );
-extern void mm_ClientDisconnect( edict_t *pEntity );
-extern void mm_ClientKill( edict_t *pEntity );
-extern void mm_ClientPutInServer( edict_t *pEntity );
-extern void mm_ClientCommand( edict_t *pEntity );
-extern void mm_ClientUserInfoChanged( edict_t *pEntity, char *infobuffer );
-extern void mm_ServerActivate( edict_t *pEdictList, int edictCount, int clientMax );
-extern void mm_ServerDeactivate( void );
-extern void mm_PlayerPreThink( edict_t *pEntity );
-extern void mm_PlayerPostThink( edict_t *pEntity );
-extern void mm_StartFrame( void );
-extern void mm_ParmsNewLevel( void );
-extern void mm_ParmsChangeLevel( void );
-extern const char *mm_GetGameDescription( void );
-extern void mm_PlayerCustomization( edict_t *pEntity, customization_t *pCust );
-extern void mm_SpectatorConnect ( edict_t *pEntity );
-extern void mm_SpectatorDisconnect ( edict_t *pEntity );
-extern void mm_SpectatorThink ( edict_t *pEntity );
-extern void mm_Sys_Error( const char *error_string );
-
-// From SDK pm_shared/pm_shared.h:
-extern void mm_PM_Move ( struct playermove_s *ppmove, int server );
-extern void mm_PM_Init ( struct playermove_s *ppmove );
-extern char mm_PM_FindTextureType ( const char *name );
-
-// From SDK dlls/client.h:
-extern void mm_SetupVisibility( edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas );
-extern void mm_UpdateClientData ( const struct edict_s *ent, int sendweapons, struct clientdata_s *cd );
-extern int mm_AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet );
-extern void mm_CreateBaseline( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs );
-extern void mm_RegisterEncoders( void );
-extern int mm_GetWeaponData( struct edict_s *player, struct weapon_data_s *info );
-extern void mm_CmdStart( const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed );
-extern void mm_CmdEnd ( const edict_t *player );
-extern int mm_ConnectionlessPacket( const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size );
-extern int mm_GetHullBounds( int hullnumber, float *mins, float *maxs );
-extern void mm_CreateInstancedBaselines ( void );
-extern int mm_InconsistentFile( const edict_t *player, const char *filename, char *disconnect_message );
-extern int mm_AllowLagCompensation( void );
-
-// No example from SDK...
+extern void mm_GameDLLInit();
+extern int mm_DispatchSpawn(edict_t *pent);
+extern void mm_DispatchThink(edict_t *pent);
+extern void mm_DispatchUse(edict_t *pentUsed, edict_t *pentOther);
+extern void mm_DispatchTouch(edict_t *pentTouched, edict_t *pentOther);
+extern void mm_DispatchBlocked(edict_t *pentBlocked, edict_t *pentOther);
+extern void mm_DispatchKeyValue(edict_t *pentKeyvalue, KeyValueData *pkvd);
+extern void mm_DispatchSave(edict_t *pent, SAVERESTOREDATA *pSaveData);
+extern int mm_DispatchRestore(edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity);
+extern void mm_DispatchObjectCollisionBox(edict_t *pent);
+extern void mm_SaveWriteFields(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount);
+extern void mm_SaveReadFields(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount);
+extern void mm_SaveGlobalState(SAVERESTOREDATA *pSaveData);
+extern void mm_RestoreGlobalState(SAVERESTOREDATA *pSaveData);
+extern void mm_ResetGlobalState();
+extern BOOL mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ]);
+extern void mm_ClientDisconnect(edict_t *pEntity);
+extern void mm_ClientKill(edict_t *pEntity);
+extern void mm_ClientPutInServer(edict_t *pEntity);
+extern void mm_ClientCommand(edict_t *pEntity);
+extern void mm_ClientUserInfoChanged(edict_t *pEntity, char *infobuffer);
+extern void mm_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
+extern void mm_ServerDeactivate();
+extern void mm_PlayerPreThink(edict_t *pEntity);
+extern void mm_PlayerPostThink(edict_t *pEntity);
+extern void mm_StartFrame();
+extern void mm_ParmsNewLevel();
+extern void mm_ParmsChangeLevel();
+extern const char *mm_GetGameDescription();
+extern void mm_PlayerCustomization(edict_t *pEntity, customization_t *pCust);
+extern void mm_SpectatorConnect (edict_t *pEntity);
+extern void mm_SpectatorDisconnect (edict_t *pEntity);
+extern void mm_SpectatorThink (edict_t *pEntity);
+extern void mm_Sys_Error(const char *error_string);
+extern void mm_PM_Move(struct playermove_s *ppmove, int server);
+extern void mm_PM_Init(struct playermove_s *ppmove);
+extern char mm_PM_FindTextureType (const char *name);
+extern void mm_SetupVisibility(edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas);
+extern void mm_UpdateClientData (const struct edict_s *ent, int sendweapons, struct clientdata_s *cd);
+extern int mm_AddToFullPack(struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet);
+extern void mm_CreateBaseline(int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs);
+extern void mm_RegisterEncoders();
+extern int mm_GetWeaponData(struct edict_s *player, struct weapon_data_s *info);
+extern void mm_CmdStart(const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed);
+extern void mm_CmdEnd (const edict_t *player);
+extern int mm_ConnectionlessPacket(const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size);
+extern int mm_GetHullBounds(int hullnumber, float *mins, float *maxs);
+extern void mm_CreateInstancedBaselines ();
+extern int mm_InconsistentFile(const edict_t *player, const char *filename, char *disconnect_message);
+extern int mm_AllowLagCompensation();
extern void mm_OnFreeEntPrivateData(edict_t pEnt);
-extern void mm_GameShutdown(void);
+extern void mm_GameShutdown();
extern int mm_ShouldCollide(edict_t *pentTouched, edict_t *pentOther);
-//Added 2005-08-11 (no SDK update)
-extern void mm_CvarValue(const edict_t *pEnt, const char *value); //! Obsolete! Use mm_CvarValue2 instead
-//Added 2005-11-22 (no SDK update)
+extern void mm_CvarValue(const edict_t *pEnt, const char *value);
extern void mm_CvarValue2(const edict_t *pEnt, int requestID, const char *cvarName, const char *value);
-
-// Typedefs for the above functions:
-
-typedef void (*FN_GAMEINIT) ( void );
-typedef int (*FN_DISPATCHSPAWN) ( edict_t *pent );
-typedef void (*FN_DISPATCHTHINK) ( edict_t *pent );
-typedef void (*FN_DISPATCHUSE) ( edict_t *pentUsed, edict_t *pentOther );
-typedef void (*FN_DISPATCHTOUCH) ( edict_t *pentTouched, edict_t *pentOther );
-typedef void (*FN_DISPATCHBLOCKED) ( edict_t *pentBlocked, edict_t *pentOther );
-typedef void (*FN_DISPATCHKEYVALUE) ( edict_t *pentKeyvalue, KeyValueData *pkvd );
-typedef void (*FN_DISPATCHSAVE) ( edict_t *pent, SAVERESTOREDATA *pSaveData );
-typedef int (*FN_DISPATCHRESTORE) ( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity );
-typedef void (*FN_DISPATCHOBJECTCOLLISIONBOX) ( edict_t *pent );
-typedef void (*FN_SAVEWRITEFIELDS) ( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount );
-typedef void (*FN_SAVEREADFIELDS) ( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount );
-typedef void (*FN_SAVEGLOBALSTATE) ( SAVERESTOREDATA *pSaveData );
-typedef void (*FN_RESTOREGLOBALSTATE) ( SAVERESTOREDATA *pSaveData );
-typedef void (*FN_RESETGLOBALSTATE) ( void );
-
-typedef BOOL (*FN_CLIENTCONNECT) ( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] );
-typedef void (*FN_CLIENTDISCONNECT) ( edict_t *pEntity );
-typedef void (*FN_CLIENTKILL) ( edict_t *pEntity );
-typedef void (*FN_CLIENTPUTINSERVER) ( edict_t *pEntity );
-typedef void (*FN_CLIENTCOMMAND) ( edict_t *pEntity );
-typedef void (*FN_CLIENTUSERINFOCHANGED) ( edict_t *pEntity, char *infobuffer );
-typedef void (*FN_SERVERACTIVATE) ( edict_t *pEdictList, int edictCount, int clientMax );
-typedef void (*FN_SERVERDEACTIVATE) ( void );
-typedef void (*FN_PLAYERPRETHINK) ( edict_t *pEntity );
-typedef void (*FN_PLAYERPOSTTHINK) ( edict_t *pEntity );
-typedef void (*FN_STARTFRAME) ( void );
-typedef void (*FN_PARMSNEWLEVEL) ( void );
-typedef void (*FN_PARMSCHANGELEVEL) ( void );
-typedef const char *(*FN_GETGAMEDESCRIPTION) ( void );
-typedef void (*FN_PLAYERCUSTOMIZATION) ( edict_t *pEntity, customization_t *pCust );
-typedef void (*FN_SPECTATORCONNECT) ( edict_t *pEntity );
-typedef void (*FN_SPECTATORDISCONNECT) ( edict_t *pEntity );
-typedef void (*FN_SPECTATORTHINK) ( edict_t *pEntity );
-typedef void (*FN_SYS_ERROR) ( const char *error_string );
-
-typedef void (*FN_PM_MOVE) ( struct playermove_s *ppmove, int server );
-typedef void (*FN_PM_INIT) ( struct playermove_s *ppmove );
-typedef char (*FN_PM_FINDTEXTURETYPE) ( char *name );
-
-typedef void (*FN_SETUPVISIBILITY) ( edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas );
-typedef void (*FN_UPDATECLIENTDATA) ( const struct edict_s *ent, int sendweapons, struct clientdata_s *cd );
-typedef int (*FN_ADDTOFULLPACK) ( struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet );
-typedef void (*FN_CREATEBASELINE) ( int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs );
-typedef void (*FN_REGISTERENCODERS) ( void );
-typedef int (*FN_GETWEAPONDATA) ( struct edict_s *player, struct weapon_data_s *info );
-typedef void (*FN_CMDSTART) ( const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed );
-typedef void (*FN_CMDEND) ( const edict_t *player );
-typedef int (*FN_CONNECTIONLESSPACKET) ( const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size );
-typedef int (*FN_GETHULLBOUNDS) ( int hullnumber, float *mins, float *maxs );
-typedef void (*FN_CREATEINSTANCEDBASELINES) ( void );
-typedef int (*FN_INCONSISTENTFILE) ( const edict_t *player, const char *filename, char *disconnect_message );
-typedef int (*FN_ALLOWLAGCOMPENSATION) ( void );
-
-typedef void (*FN_ONFREEENTPRIVATEDATA) (edict_t *pEnt);
-typedef void (*FN_GAMESHUTDOWN) (void);
-typedef int (*FN_SHOULDCOLLIDE) (edict_t *pentTouched, edict_t *pentOther);
-//Added 2005-08-11 (no SDK update)
+typedef void (*FN_GAMEINIT)();
+typedef int (*FN_DISPATCHSPAWN)(edict_t *pent);
+typedef void (*FN_DISPATCHTHINK)(edict_t *pent);
+typedef void (*FN_DISPATCHUSE)(edict_t *pentUsed, edict_t *pentOther);
+typedef void (*FN_DISPATCHTOUCH)(edict_t *pentTouched, edict_t *pentOther);
+typedef void (*FN_DISPATCHBLOCKED)(edict_t *pentBlocked, edict_t *pentOther);
+typedef void (*FN_DISPATCHKEYVALUE)(edict_t *pentKeyvalue, KeyValueData *pkvd);
+typedef void (*FN_DISPATCHSAVE)(edict_t *pent, SAVERESTOREDATA *pSaveData);
+typedef int (*FN_DISPATCHRESTORE)(edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity);
+typedef void (*FN_DISPATCHOBJECTCOLLISIONBOX)(edict_t *pent);
+typedef void (*FN_SAVEWRITEFIELDS)(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount);
+typedef void (*FN_SAVEREADFIELDS)(SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount);
+typedef void (*FN_SAVEGLOBALSTATE)(SAVERESTOREDATA *pSaveData);
+typedef void (*FN_RESTOREGLOBALSTATE)(SAVERESTOREDATA *pSaveData);
+typedef void (*FN_RESETGLOBALSTATE)();
+typedef BOOL (*FN_CLIENTCONNECT)(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ]);
+typedef void (*FN_CLIENTDISCONNECT)(edict_t *pEntity);
+typedef void (*FN_CLIENTKILL)(edict_t *pEntity);
+typedef void (*FN_CLIENTPUTINSERVER)(edict_t *pEntity);
+typedef void (*FN_CLIENTCOMMAND)(edict_t *pEntity);
+typedef void (*FN_CLIENTUSERINFOCHANGED)(edict_t *pEntity, char *infobuffer);
+typedef void (*FN_SERVERACTIVATE)(edict_t *pEdictList, int edictCount, int clientMax);
+typedef void (*FN_SERVERDEACTIVATE)();
+typedef void (*FN_PLAYERPRETHINK)(edict_t *pEntity);
+typedef void (*FN_PLAYERPOSTTHINK)(edict_t *pEntity);
+typedef void (*FN_STARTFRAME)();
+typedef void (*FN_PARMSNEWLEVEL)();
+typedef void (*FN_PARMSCHANGELEVEL)();
+typedef const char *(*FN_GETGAMEDESCRIPTION)();
+typedef void (*FN_PLAYERCUSTOMIZATION)(edict_t *pEntity, customization_t *pCust);
+typedef void (*FN_SPECTATORCONNECT) (edict_t *pEntity);
+typedef void (*FN_SPECTATORDISCONNECT) (edict_t *pEntity);
+typedef void (*FN_SPECTATORTHINK) (edict_t *pEntity);
+typedef void (*FN_SYS_ERROR)(const char *error_string);
+typedef void (*FN_PM_MOVE)(struct playermove_s *ppmove, int server);
+typedef void (*FN_PM_INIT)(struct playermove_s *ppmove);
+typedef char (*FN_PM_FINDTEXTURETYPE)(char *name);
+typedef void (*FN_SETUPVISIBILITY)(edict_t *pViewEntity, edict_t *pClient, unsigned char **pvs, unsigned char **pas);
+typedef void (*FN_UPDATECLIENTDATA) (const struct edict_s *ent, int sendweapons, struct clientdata_s *cd);
+typedef int (*FN_ADDTOFULLPACK)(struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet);
+typedef void (*FN_CREATEBASELINE)(int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, vec3_t player_mins, vec3_t player_maxs);
+typedef void (*FN_REGISTERENCODERS)();
+typedef int (*FN_GETWEAPONDATA)(struct edict_s *player, struct weapon_data_s *info);
+typedef void (*FN_CMDSTART)(const edict_t *player, const struct usercmd_s *cmd, unsigned int random_seed);
+typedef void (*FN_CMDEND) (const edict_t *player);
+typedef int (*FN_CONNECTIONLESSPACKET)(const struct netadr_s *net_from, const char *args, char *response_buffer, int *response_buffer_size);
+typedef int (*FN_GETHULLBOUNDS)(int hullnumber, float *mins, float *maxs);
+typedef void (*FN_CREATEINSTANCEDBASELINES) ();
+typedef int (*FN_INCONSISTENTFILE)(const edict_t *player, const char *filename, char *disconnect_message);
+typedef int (*FN_ALLOWLAGCOMPENSATION)();
+typedef void (*FN_ONFREEENTPRIVATEDATA)(edict_t *pEnt);
+typedef void (*FN_GAMESHUTDOWN)();
+typedef int (*FN_SHOULDCOLLIDE)(edict_t *pentTouched, edict_t *pentOther);
typedef void (*FN_CVARVALUE)(const edict_t *pEnt, const char *value); //! Obsolete! Use FN_CVARVALUE2 instead
-//Added 2005-11-22 (no SDK update)
typedef void (*FN_CVARVALUE2)(const edict_t *pEnt, int requestID, const char *cvarName, const char *value);
-
-#endif /* DLLAPI_H */
diff --git a/metamod/src/engine_api.cpp b/metamod/src/engine_api.cpp
index 599f9c9..7f3bd5c 100644
--- a/metamod/src/engine_api.cpp
+++ b/metamod/src/engine_api.cpp
@@ -1,39 +1,3 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// engine_api.cpp - implementation of Half-Life engine functions
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// g_engine routines, functions returning "void".
@@ -58,7 +22,7 @@
va_list ap; \
META_DEBUG(loglevel, ("In %s: fmt=%s", pfn_string, fmt_arg)); \
va_start(ap, fmt_arg); \
- vsnprintf(buf, sizeof(buf), fmt_arg, ap); \
+ Q_vsnprintf(buf, sizeof(buf), fmt_arg, ap); \
va_end(ap); \
CALL_PLUGIN_API_void(P_PRE, pfnName, (pfn_arg, "%s", buf), engine_table); \
CALL_ENGINE_API_void(pfnName, (pfn_arg, "%s", buf)); \
@@ -71,390 +35,518 @@
va_list ap; \
META_DEBUG(loglevel, ("In %s: fmt=%s", pfn_string, fmt_arg)); \
va_start(ap, fmt_arg); \
- vsnprintf(buf, sizeof(buf), fmt_arg, ap); \
+ Q_vsnprintf(buf, sizeof(buf), fmt_arg, ap); \
va_end(ap); \
CALL_PLUGIN_API(P_PRE, ret_init, pfnName, (pfn_arg, "%s", buf), MRES_SUPERCEDE, engine_table); \
CALL_ENGINE_API(pfnName, (pfn_arg, "%s", buf)); \
CALL_PLUGIN_API(P_POST, ret_init, pfnName, (pfn_arg, "%s", buf), MRES_OVERRIDE, engine_post_table);
-
-int mm_PrecacheModel(const char *s) {
+int mm_PrecacheModel(const char *s)
+{
META_ENGINE_HANDLE(int, 0, FN_PRECACHEMODEL, pfnPrecacheModel, (s));
RETURN_API()
}
-int mm_PrecacheSound(const char *s) {
+
+int mm_PrecacheSound(const char *s)
+{
META_ENGINE_HANDLE(int, 0, FN_PRECACHESOUND, pfnPrecacheSound, (s));
RETURN_API()
}
-void mm_SetModel(edict_t *e, const char *m) {
+
+void mm_SetModel(edict_t *e, const char *m)
+{
META_ENGINE_HANDLE_void(FN_SETMODEL, pfnSetModel, (e, m));
RETURN_API_void()
}
-int mm_ModelIndex(const char *m) {
+
+int mm_ModelIndex(const char *m)
+{
META_ENGINE_HANDLE(int, 0, FN_MODELINDEX, pfnModelIndex, (m));
RETURN_API()
}
-int mm_ModelFrames(int modelIndex) {
+
+int mm_ModelFrames(int modelIndex)
+{
META_ENGINE_HANDLE(int, 0, FN_MODELFRAMES, pfnModelFrames, (modelIndex));
RETURN_API()
}
-void mm_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax) {
+void mm_SetSize(edict_t *e, const float *rgflMin, const float *rgflMax)
+{
META_ENGINE_HANDLE_void(FN_SETSIZE, pfnSetSize, (e, rgflMin, rgflMax));
RETURN_API_void()
}
-void mm_ChangeLevel(const char *s1, const char *s2) {
+
+void mm_ChangeLevel(const char *s1, const char *s2)
+{
META_ENGINE_HANDLE_void(FN_CHANGELEVEL, pfnChangeLevel, (s1, s2));
RETURN_API_void()
}
-void mm_GetSpawnParms(edict_t *ent) {
+
+void mm_GetSpawnParms(edict_t *ent)
+{
META_ENGINE_HANDLE_void(FN_GETSPAWNPARMS, pfnGetSpawnParms, (ent));
RETURN_API_void()
}
-void mm_SaveSpawnParms(edict_t *ent) {
+
+void mm_SaveSpawnParms(edict_t *ent)
+{
META_ENGINE_HANDLE_void(FN_SAVESPAWNPARMS, pfnSaveSpawnParms, (ent));
RETURN_API_void()
}
-float mm_VecToYaw(const float *rgflVector) {
+float mm_VecToYaw(const float *rgflVector)
+{
META_ENGINE_HANDLE(float, 0.0, FN_VECTOYAW, pfnVecToYaw, (rgflVector));
RETURN_API()
}
-void mm_VecToAngles(const float *rgflVectorIn, float *rgflVectorOut) {
+
+void mm_VecToAngles(const float *rgflVectorIn, float *rgflVectorOut)
+{
META_ENGINE_HANDLE_void(FN_VECTOANGLES, pfnVecToAngles, (rgflVectorIn, rgflVectorOut));
RETURN_API_void()
}
-void mm_MoveToOrigin(edict_t *ent, const float *pflGoal, float dist, int iMoveType) {
+
+void mm_MoveToOrigin(edict_t *ent, const float *pflGoal, float dist, int iMoveType)
+{
META_ENGINE_HANDLE_void(FN_MOVETOORIGIN, pfnMoveToOrigin, (ent, pflGoal, dist, iMoveType));
RETURN_API_void()
}
-void mm_ChangeYaw(edict_t *ent) {
+
+void mm_ChangeYaw(edict_t *ent)
+{
META_ENGINE_HANDLE_void(FN_CHANGEYAW, pfnChangeYaw, (ent));
RETURN_API_void()
}
-void mm_ChangePitch(edict_t *ent) {
+
+void mm_ChangePitch(edict_t *ent)
+{
META_ENGINE_HANDLE_void(FN_CHANGEPITCH, pfnChangePitch, (ent));
RETURN_API_void()
}
-edict_t *mm_FindEntityByString(edict_t *pEdictStartSearchAfter, const char *pszField, const char *pszValue) {
+edict_t *mm_FindEntityByString(edict_t *pEdictStartSearchAfter, const char *pszField, const char *pszValue)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_FINDENTITYBYSTRING, pfnFindEntityByString, (pEdictStartSearchAfter, pszField, pszValue));
RETURN_API()
}
-int mm_GetEntityIllum(edict_t *pEnt) {
+
+int mm_GetEntityIllum(edict_t *pEnt)
+{
META_ENGINE_HANDLE(int, 0, FN_GETENTITYILLUM, pfnGetEntityIllum, (pEnt));
RETURN_API()
}
-edict_t *mm_FindEntityInSphere(edict_t *pEdictStartSearchAfter, const float *org, float rad) {
+
+edict_t *mm_FindEntityInSphere(edict_t *pEdictStartSearchAfter, const float *org, float rad)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_FINDENTITYINSPHERE, pfnFindEntityInSphere, (pEdictStartSearchAfter, org, rad));
RETURN_API()
}
-edict_t *mm_FindClientInPVS(edict_t *pEdict) {
+
+edict_t *mm_FindClientInPVS(edict_t *pEdict)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_FINDCLIENTINPVS, pfnFindClientInPVS, (pEdict));
RETURN_API()
}
-edict_t *mm_EntitiesInPVS(edict_t *pplayer) {
+
+edict_t *mm_EntitiesInPVS(edict_t *pplayer)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_ENTITIESINPVS, pfnEntitiesInPVS, (pplayer));
RETURN_API()
}
-void mm_MakeVectors(const float *rgflVector) {
+void mm_MakeVectors(const float *rgflVector)
+{
META_ENGINE_HANDLE_void(FN_MAKEVECTORS, pfnMakeVectors, (rgflVector));
RETURN_API_void()
}
-void mm_AngleVectors(const float *rgflVector, float *forward, float *right, float *up) {
+
+void mm_AngleVectors(const float *rgflVector, float *forward, float *right, float *up)
+{
META_ENGINE_HANDLE_void(FN_ANGLEVECTORS, pfnAngleVectors, (rgflVector, forward, right, up));
RETURN_API_void()
}
-edict_t *mm_CreateEntity(void) {
+edict_t *mm_CreateEntity()
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_CREATEENTITY, pfnCreateEntity, ());
RETURN_API()
}
-void mm_RemoveEntity(edict_t *e) {
+
+void mm_RemoveEntity(edict_t *e)
+{
META_ENGINE_HANDLE_void(FN_REMOVEENTITY, pfnRemoveEntity, (e));
RETURN_API_void()
}
-edict_t *mm_CreateNamedEntity(int className) {
+
+edict_t *mm_CreateNamedEntity(int className)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_CREATENAMEDENTITY, pfnCreateNamedEntity, (className));
RETURN_API()
}
-void mm_MakeStatic(edict_t *ent) {
+void mm_MakeStatic(edict_t *ent)
+{
META_ENGINE_HANDLE_void(FN_MAKESTATIC, pfnMakeStatic, (ent));
RETURN_API_void()
}
-int mm_EntIsOnFloor(edict_t *e) {
+
+int mm_EntIsOnFloor(edict_t *e)
+{
META_ENGINE_HANDLE(int, 0, FN_ENTISONFLOOR, pfnEntIsOnFloor, (e));
RETURN_API()
}
-int mm_DropToFloor(edict_t *e) {
+
+int mm_DropToFloor(edict_t *e)
+{
META_ENGINE_HANDLE(int, 0, FN_DROPTOFLOOR, pfnDropToFloor, (e));
RETURN_API()
}
-int mm_WalkMove(edict_t *ent, float yaw, float dist, int iMode) {
+int mm_WalkMove(edict_t *ent, float yaw, float dist, int iMode)
+{
META_ENGINE_HANDLE(int, 0, FN_WALKMOVE, pfnWalkMove, (ent, yaw, dist, iMode));
RETURN_API()
}
-void mm_SetOrigin(edict_t *e, const float *rgflOrigin) {
+
+void mm_SetOrigin(edict_t *e, const float *rgflOrigin)
+{
META_ENGINE_HANDLE_void(FN_SETORIGIN, pfnSetOrigin, (e, rgflOrigin));
RETURN_API_void()
}
-void mm_EmitSound(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch) {
+void mm_EmitSound(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch)
+{
META_ENGINE_HANDLE_void(FN_EMITSOUND, pfnEmitSound, (entity, channel, sample, volume, attenuation, fFlags, pitch));
RETURN_API_void()
}
-void mm_EmitAmbientSound(edict_t *entity, float *pos, const char *samp, float vol, float attenuation, int fFlags, int pitch) {
+
+void mm_EmitAmbientSound(edict_t *entity, float *pos, const char *samp, float vol, float attenuation, int fFlags, int pitch)
+{
META_ENGINE_HANDLE_void(FN_EMITAMBIENTSOUND, pfnEmitAmbientSound, (entity, pos, samp, vol, attenuation, fFlags, pitch));
RETURN_API_void()
}
-void mm_TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr) {
+void mm_TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
+{
META_ENGINE_HANDLE_void(FN_TRACELINE, pfnTraceLine, (v1, v2, fNoMonsters, pentToSkip, ptr));
RETURN_API_void()
}
-void mm_TraceToss(edict_t *pent, edict_t *pentToIgnore, TraceResult *ptr) {
+
+void mm_TraceToss(edict_t *pent, edict_t *pentToIgnore, TraceResult *ptr)
+{
META_ENGINE_HANDLE_void(FN_TRACETOSS, pfnTraceToss, (pent, pentToIgnore, ptr));
RETURN_API_void()
}
-int mm_TraceMonsterHull(edict_t *pEdict, const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr) {
+
+int mm_TraceMonsterHull(edict_t *pEdict, const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
+{
META_ENGINE_HANDLE(int, 0, FN_TRACEMONSTERHULL, pfnTraceMonsterHull, (pEdict, v1, v2, fNoMonsters, pentToSkip, ptr));
RETURN_API()
}
-void mm_TraceHull(const float *v1, const float *v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult *ptr) {
+
+void mm_TraceHull(const float *v1, const float *v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult *ptr)
+{
META_ENGINE_HANDLE_void(FN_TRACEHULL, pfnTraceHull, (v1, v2, fNoMonsters, hullNumber, pentToSkip, ptr));
RETURN_API_void()
}
-void mm_TraceModel(const float *v1, const float *v2, int hullNumber, edict_t *pent, TraceResult *ptr) {
+
+void mm_TraceModel(const float *v1, const float *v2, int hullNumber, edict_t *pent, TraceResult *ptr)
+{
META_ENGINE_HANDLE_void(FN_TRACEMODEL, pfnTraceModel, (v1, v2, hullNumber, pent, ptr));
RETURN_API_void()
}
-const char *mm_TraceTexture(edict_t *pTextureEntity, const float *v1, const float *v2 ) {
+
+const char *mm_TraceTexture(edict_t *pTextureEntity, const float *v1, const float *v2)
+{
META_ENGINE_HANDLE(const char *, NULL, FN_TRACETEXTURE, pfnTraceTexture, (pTextureEntity, v1, v2));
RETURN_API()
}
-void mm_TraceSphere(const float *v1, const float *v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult *ptr) {
+
+void mm_TraceSphere(const float *v1, const float *v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult *ptr)
+{
META_ENGINE_HANDLE_void(FN_TRACESPHERE, pfnTraceSphere, (v1, v2, fNoMonsters, radius, pentToSkip, ptr));
RETURN_API_void()
}
-void mm_GetAimVector(edict_t *ent, float speed, float *rgflReturn) {
+
+void mm_GetAimVector(edict_t *ent, float speed, float *rgflReturn)
+{
META_ENGINE_HANDLE_void(FN_GETAIMVECTOR, pfnGetAimVector, (ent, speed, rgflReturn));
RETURN_API_void()
}
-void mm_ServerCommand(char *str) {
+void mm_ServerCommand(char *str)
+{
META_ENGINE_HANDLE_void(FN_SERVERCOMMAND, pfnServerCommand, (str));
RETURN_API_void()
}
-void mm_ServerExecute(void) {
+
+void mm_ServerExecute()
+{
META_ENGINE_HANDLE_void(FN_SERVEREXECUTE, pfnServerExecute, ());
RETURN_API_void()
}
-void mm_engClientCommand(edict_t *pEdict, char *szFmt, ...) {
+
+void mm_engClientCommand(edict_t *pEdict, char *szFmt, ...)
+{
META_ENGINE_HANDLE_void_varargs(FN_CLIENTCOMMAND_ENG, pfnClientCommand, pEdict, szFmt);
RETURN_API_void()
}
-void mm_ParticleEffect(const float *org, const float *dir, float color, float count) {
+void mm_ParticleEffect(const float *org, const float *dir, float color, float count)
+{
META_ENGINE_HANDLE_void(FN_PARTICLEEFFECT, pfnParticleEffect, (org, dir, color, count));
RETURN_API_void()
}
-void mm_LightStyle(int style, char *val) {
+
+void mm_LightStyle(int style, char *val)
+{
META_ENGINE_HANDLE_void(FN_LIGHTSTYLE, pfnLightStyle, (style, val));
RETURN_API_void()
}
-int mm_DecalIndex(const char *name) {
+
+int mm_DecalIndex(const char *name)
+{
META_ENGINE_HANDLE(int, 0, FN_DECALINDEX, pfnDecalIndex, (name));
RETURN_API()
}
-int mm_PointContents(const float *rgflVector) {
+
+int mm_PointContents(const float *rgflVector)
+{
META_ENGINE_HANDLE(int, 0, FN_POINTCONTENTS, pfnPointContents, (rgflVector));
RETURN_API()
}
-void mm_MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed) {
+void mm_MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
+{
META_ENGINE_HANDLE_void(FN_MESSAGEBEGIN, pfnMessageBegin, (msg_dest, msg_type, pOrigin, ed));
RETURN_API_void()
}
-void mm_MessageEnd(void) {
+
+void mm_MessageEnd()
+{
META_ENGINE_HANDLE_void(FN_MESSAGEEND, pfnMessageEnd, ());
RETURN_API_void()
}
-void mm_WriteByte(int iValue) {
+void mm_WriteByte(int iValue)
+{
META_ENGINE_HANDLE_void(FN_WRITEBYTE, pfnWriteByte, (iValue));
RETURN_API_void()
}
-void mm_WriteChar(int iValue) {
+
+void mm_WriteChar(int iValue)
+{
META_ENGINE_HANDLE_void(FN_WRITECHAR, pfnWriteChar, (iValue));
RETURN_API_void()
}
-void mm_WriteShort(int iValue) {
+
+void mm_WriteShort(int iValue)
+{
META_ENGINE_HANDLE_void(FN_WRITESHORT, pfnWriteShort, (iValue));
RETURN_API_void()
}
-void mm_WriteLong(int iValue) {
+
+void mm_WriteLong(int iValue)
+{
META_ENGINE_HANDLE_void(FN_WRITELONG, pfnWriteLong, (iValue));
RETURN_API_void()
}
-void mm_WriteAngle(float flValue) {
+
+void mm_WriteAngle(float flValue)
+{
META_ENGINE_HANDLE_void(FN_WRITEANGLE, pfnWriteAngle, (flValue));
RETURN_API_void()
}
-void mm_WriteCoord(float flValue) {
+
+void mm_WriteCoord(float flValue)
+{
META_ENGINE_HANDLE_void(FN_WRITECOORD, pfnWriteCoord, (flValue));
RETURN_API_void()
}
-void mm_WriteString(const char *sz) {
+
+void mm_WriteString(const char *sz)
+{
META_ENGINE_HANDLE_void(FN_WRITESTRING, pfnWriteString, (sz));
RETURN_API_void()
}
-void mm_WriteEntity(int iValue) {
+
+void mm_WriteEntity(int iValue)
+{
META_ENGINE_HANDLE_void(FN_WRITEENTITY, pfnWriteEntity, (iValue));
RETURN_API_void()
}
-void mm_CVarRegister(cvar_t *pCvar) {
+void mm_CVarRegister(cvar_t *pCvar)
+{
META_ENGINE_HANDLE_void(FN_CVARREGISTER, pfnCVarRegister, (pCvar));
RETURN_API_void()
}
-float mm_CVarGetFloat(const char *szVarName) {
+
+float mm_CVarGetFloat(const char *szVarName)
+{
META_ENGINE_HANDLE(float, 0.0, FN_CVARGETFLOAT, pfnCVarGetFloat, (szVarName));
RETURN_API()
}
-const char *mm_CVarGetString(const char *szVarName) {
+
+const char *mm_CVarGetString(const char *szVarName)
+{
META_ENGINE_HANDLE(const char *, NULL, FN_CVARGETSTRING, pfnCVarGetString, (szVarName));
RETURN_API()
}
-void mm_CVarSetFloat(const char *szVarName, float flValue) {
+
+void mm_CVarSetFloat(const char *szVarName, float flValue)
+{
META_ENGINE_HANDLE_void(FN_CVARSETFLOAT, pfnCVarSetFloat, (szVarName, flValue));
RETURN_API_void()
}
-void mm_CVarSetString(const char *szVarName, const char *szValue) {
+
+void mm_CVarSetString(const char *szVarName, const char *szValue)
+{
META_ENGINE_HANDLE_void(FN_CVARSETSTRING, pfnCVarSetString, (szVarName, szValue));
RETURN_API_void()
}
-void mm_AlertMessage(ALERT_TYPE atype, const char *szFmt, ...) {
+void mm_AlertMessage(ALERT_TYPE atype, const char *szFmt, ...)
+{
#ifndef UNFINISHED
META_ENGINE_HANDLE_void_varargs(FN_ALERTMESSAGE, pfnAlertMessage, atype, szFmt);
-#else /* UNFINISHED */
+#else
// Expand macro, since we need to do extra work here.
-
// usual setup
+
SETUP_API_CALLS_void(FN_ALERTMESSAGE, pfnAlertMessage, engine_info);
char buf[MAX_STRBUF_LEN];
va_list ap;
- int len;
- char *qmsg;
+
META_DEBUG(loglevel, ("In %s: fmt=%s", pfn_string, szFmt));
va_start(ap, szFmt);
- len=vsnprintf(buf, sizeof(buf), szFmt, ap) + 1;
+ int len = Q_vsnprintf(buf, sizeof(buf), szFmt, ap) + 1;
va_end(ap);
+
// pass logmsg string to log parsing thread
- /// qmsg=_strdup(buf);
- qmsg=(char *) malloc(len * sizeof(char));
- if(!qmsg)
+ /// qmsg = Q_strdup(buf);
+ char *qmsg = (char *)Q_malloc(len * sizeof(char));
+ if (!qmsg)
META_ERROR("malloc failed for logmsg to thread queue");
- else {
+ else
+ {
STRNCPY(qmsg, buf, len);
LogQueue->push(qmsg);
}
+
// usual passing to plugins/engine
CALL_PLUGIN_API_void(P_PRE, pfnAlertMessage, (atype, "%s", buf), engine_table);
CALL_ENGINE_API_void(pfnAlertMessage, (atype, "%s", buf));
CALL_PLUGIN_API_void(P_POST, pfnAlertMessage, (atype, "%s", buf), engine_post_table);
-#endif /* UNFINISHED */
+#endif // UNFINISHED
// usual return.
RETURN_API_void()
}
-#ifdef HLSDK_3_2_OLD_EIFACE
-void mm_EngineFprintf(FILE *pfile, const char *szFmt, ...) {
-#else
-void mm_EngineFprintf(void *pfile, const char *szFmt, ...) {
-#endif
+
+void mm_EngineFprintf(void *pfile, const char *szFmt, ...)
+{
META_ENGINE_HANDLE_void_varargs(FN_ENGINEFPRINTF, pfnEngineFprintf, pfile, szFmt);
RETURN_API_void()
}
-#ifdef HLSDK_3_2_OLD_EIFACE
-void *mm_PvAllocEntPrivateData(edict_t *pEdict, long cb) {
-#else
-void *mm_PvAllocEntPrivateData(edict_t *pEdict, int32 cb) {
-#endif
+void *mm_PvAllocEntPrivateData(edict_t *pEdict, int32 cb)
+{
META_ENGINE_HANDLE(void *, NULL, FN_PVALLOCENTPRIVATEDATA, pfnPvAllocEntPrivateData, (pEdict, cb));
RETURN_API()
}
-void *mm_PvEntPrivateData(edict_t *pEdict) {
+
+void *mm_PvEntPrivateData(edict_t *pEdict)
+{
META_ENGINE_HANDLE(void *, NULL, FN_PVENTPRIVATEDATA, pfnPvEntPrivateData, (pEdict));
RETURN_API()
}
-void mm_FreeEntPrivateData(edict_t *pEdict) {
+
+void mm_FreeEntPrivateData(edict_t *pEdict)
+{
META_ENGINE_HANDLE_void(FN_FREEENTPRIVATEDATA, pfnFreeEntPrivateData, (pEdict));
RETURN_API_void()
}
-const char *mm_SzFromIndex(int iString) {
+const char *mm_SzFromIndex(int iString)
+{
META_ENGINE_HANDLE(const char *, NULL, FN_SZFROMINDEX, pfnSzFromIndex, (iString));
RETURN_API()
}
-int mm_AllocString(const char *szValue) {
+
+int mm_AllocString(const char *szValue)
+{
META_ENGINE_HANDLE(int, 0, FN_ALLOCSTRING, pfnAllocString, (szValue));
RETURN_API()
}
-struct entvars_s *mm_GetVarsOfEnt(edict_t *pEdict) {
+struct entvars_s *mm_GetVarsOfEnt(edict_t *pEdict)
+{
META_ENGINE_HANDLE(struct entvars_s *, NULL, FN_GETVARSOFENT, pfnGetVarsOfEnt, (pEdict));
RETURN_API()
}
-edict_t *mm_PEntityOfEntOffset(int iEntOffset) {
+
+edict_t *mm_PEntityOfEntOffset(int iEntOffset)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_PENTITYOFENTOFFSET, pfnPEntityOfEntOffset, (iEntOffset));
RETURN_API()
}
-int mm_EntOffsetOfPEntity(const edict_t *pEdict) {
+
+int mm_EntOffsetOfPEntity(const edict_t *pEdict)
+{
META_ENGINE_HANDLE(int, 0, FN_ENTOFFSETOFPENTITY, pfnEntOffsetOfPEntity, (pEdict));
RETURN_API()
}
-int mm_IndexOfEdict(const edict_t *pEdict) {
+
+int mm_IndexOfEdict(const edict_t *pEdict)
+{
META_ENGINE_HANDLE(int, 0, FN_INDEXOFEDICT, pfnIndexOfEdict, (pEdict));
RETURN_API()
}
-edict_t *mm_PEntityOfEntIndex(int iEntIndex) {
+
+edict_t *mm_PEntityOfEntIndex(int iEntIndex)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_PENTITYOFENTINDEX, pfnPEntityOfEntIndex, (iEntIndex));
RETURN_API()
}
-edict_t *mm_FindEntityByVars(struct entvars_s *pvars) {
+
+edict_t *mm_FindEntityByVars(struct entvars_s *pvars)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_FINDENTITYBYVARS, pfnFindEntityByVars, (pvars));
RETURN_API()
}
-void *mm_GetModelPtr(edict_t *pEdict) {
+
+void *mm_GetModelPtr(edict_t *pEdict)
+{
META_ENGINE_HANDLE(void *, NULL, FN_GETMODELPTR, pfnGetModelPtr, (pEdict));
RETURN_API()
}
-int mm_RegUserMsg(const char *pszName, int iSize) {
+int mm_RegUserMsg(const char *pszName, int iSize)
+{
int imsgid;
- MRegMsg *nmsg=NULL;
+ MRegMsg *nmsg = nullptr;
META_ENGINE_HANDLE(int, 0, FN_REGUSERMSG, pfnRegUserMsg, (pszName, iSize));
+
// Expand the macro, since we need to do extra work.
/// RETURN_API()
- if (--CALL_API_count>0)
- /*Restore backup*/
+ if (--CALL_API_count > 0)
PublicMetaGlobals = backup_meta_globals;
- if(status==MRES_OVERRIDE) {
+
+ if (status == MRES_OVERRIDE)
+ {
META_DEBUG(loglevel, ("Returning (override) %s()", pfn_string));
- imsgid=override_ret;
+ imsgid = override_ret;
}
else
- imsgid=orig_ret;
+ imsgid = orig_ret;
// Add the msgid, name, and size to our saved list, if we haven't
// already.
- nmsg=g_regMsgs->find(imsgid);
- if(nmsg) {
- if(FStrEq(pszName, nmsg->name))
+ nmsg = g_regMsgs->find(imsgid);
+ if (nmsg)
+ {
+ if (FStrEq(pszName, nmsg->name))
// This name/msgid pair was already registered.
META_DEBUG(3, ("user message registered again: name=%s, msgid=%d", pszName, imsgid));
else
@@ -463,396 +555,494 @@ int mm_RegUserMsg(const char *pszName, int iSize) {
}
else
g_regMsgs->add(pszName, imsgid, iSize);
- return(imsgid);
+
+ return imsgid;
}
-void mm_AnimationAutomove(const edict_t *pEdict, float flTime) {
+void mm_AnimationAutomove(const edict_t *pEdict, float flTime)
+{
META_ENGINE_HANDLE_void(FN_ANIMATIONAUTOMOVE, pfnAnimationAutomove, (pEdict, flTime));
RETURN_API_void()
}
-void mm_GetBonePosition(const edict_t *pEdict, int iBone, float *rgflOrigin, float *rgflAngles ) {
+
+void mm_GetBonePosition(const edict_t *pEdict, int iBone, float *rgflOrigin, float *rgflAngles)
+{
META_ENGINE_HANDLE_void(FN_GETBONEPOSITION, pfnGetBonePosition, (pEdict, iBone, rgflOrigin, rgflAngles));
RETURN_API_void()
}
-#ifdef HLSDK_3_2_OLD_EIFACE
-unsigned long mm_FunctionFromName( const char *pName ) {
- META_ENGINE_HANDLE(unsigned long, 0, FN_FUNCTIONFROMNAME, pfnFunctionFromName, (pName));
-#else
-uint32 mm_FunctionFromName( const char *pName ) {
+uint32 mm_FunctionFromName(const char *pName)
+{
META_ENGINE_HANDLE(uint32, 0, FN_FUNCTIONFROMNAME, pfnFunctionFromName, (pName));
-#endif
RETURN_API()
}
-#ifdef HLSDK_3_2_OLD_EIFACE
-const char *mm_NameForFunction( unsigned long function ) {
-#else
-const char *mm_NameForFunction( uint32 function ) {
-#endif
+
+const char *mm_NameForFunction(uint32 function)
+{
META_ENGINE_HANDLE(const char *, NULL, FN_NAMEFORFUNCTION, pfnNameForFunction, (function));
RETURN_API()
}
-//! JOHN: engine callbacks so game DLL can print messages to individual clients
-void mm_ClientPrintf( edict_t *pEdict, PRINT_TYPE ptype, const char *szMsg ) {
+// JOHN: engine callbacks so game DLL can print messages to individual clients
+void mm_ClientPrintf(edict_t *pEdict, PRINT_TYPE ptype, const char *szMsg)
+{
META_ENGINE_HANDLE_void(FN_CLIENTPRINTF, pfnClientPrintf, (pEdict, ptype, szMsg));
RETURN_API_void()
}
-void mm_ServerPrint( const char *szMsg ) {
+
+void mm_ServerPrint(const char *szMsg)
+{
META_ENGINE_HANDLE_void(FN_SERVERPRINT, pfnServerPrint, (szMsg));
RETURN_API_void()
}
-//! these 3 added so game DLL can easily access client 'cmd' strings
-const char *mm_Cmd_Args( void ) {
+// these 3 added so game DLL can easily access client 'cmd' strings
+const char *mm_Cmd_Args()
+{
META_ENGINE_HANDLE(const char *, NULL, FN_CMD_ARGS, pfnCmd_Args, ());
RETURN_API()
}
-const char *mm_Cmd_Argv( int argc ) {
+
+const char *mm_Cmd_Argv(int argc)
+{
META_ENGINE_HANDLE(const char *, NULL, FN_CMD_ARGV, pfnCmd_Argv, (argc));
RETURN_API()
}
-int mm_Cmd_Argc( void ) {
+
+int mm_Cmd_Argc()
+{
META_ENGINE_HANDLE(int, 0, FN_CMD_ARGC, pfnCmd_Argc, ());
RETURN_API()
}
-void mm_GetAttachment(const edict_t *pEdict, int iAttachment, float *rgflOrigin, float *rgflAngles ) {
+void mm_GetAttachment(const edict_t *pEdict, int iAttachment, float *rgflOrigin, float *rgflAngles)
+{
META_ENGINE_HANDLE_void(FN_GETATTACHMENT, pfnGetAttachment, (pEdict, iAttachment, rgflOrigin, rgflAngles));
RETURN_API_void()
}
-void mm_CRC32_Init(CRC32_t *pulCRC) {
+void mm_CRC32_Init(CRC32_t *pulCRC)
+{
META_ENGINE_HANDLE_void(FN_CRC32_INIT, pfnCRC32_Init, (pulCRC));
RETURN_API_void()
}
-void mm_CRC32_ProcessBuffer(CRC32_t *pulCRC, void *p, int len) {
+void mm_CRC32_ProcessBuffer(CRC32_t *pulCRC, void *p, int len)
+{
META_ENGINE_HANDLE_void(FN_CRC32_PROCESSBUFFER, pfnCRC32_ProcessBuffer, (pulCRC, p, len));
RETURN_API_void()
}
-void mm_CRC32_ProcessByte(CRC32_t *pulCRC, unsigned char ch) {
+void mm_CRC32_ProcessByte(CRC32_t *pulCRC, unsigned char ch)
+{
META_ENGINE_HANDLE_void(FN_CRC32_PROCESSBYTE, pfnCRC32_ProcessByte, (pulCRC, ch));
RETURN_API_void()
}
-CRC32_t mm_CRC32_Final(CRC32_t pulCRC) {
+CRC32_t mm_CRC32_Final(CRC32_t pulCRC)
+{
META_ENGINE_HANDLE(CRC32_t, 0, FN_CRC32_FINAL, pfnCRC32_Final, (pulCRC));
RETURN_API()
}
-#ifdef HLSDK_3_2_OLD_EIFACE
-long mm_RandomLong(long lLow, long lHigh) {
- META_ENGINE_HANDLE(long, 0, FN_RANDOMLONG, pfnRandomLong, (lLow, lHigh));
-#else
-int32 mm_RandomLong(int32 lLow, int32 lHigh) {
+int32 mm_RandomLong(int32 lLow, int32 lHigh)
+{
META_ENGINE_HANDLE(int32, 0, FN_RANDOMLONG, pfnRandomLong, (lLow, lHigh));
-#endif
RETURN_API()
}
-float mm_RandomFloat(float flLow, float flHigh) {
+
+float mm_RandomFloat(float flLow, float flHigh)
+{
META_ENGINE_HANDLE(float, 0.0, FN_RANDOMFLOAT, pfnRandomFloat, (flLow, flHigh));
RETURN_API()
}
-void mm_SetView(const edict_t *pClient, const edict_t *pViewent ) {
+void mm_SetView(const edict_t *pClient, const edict_t *pViewent)
+{
META_ENGINE_HANDLE_void(FN_SETVIEW, pfnSetView, (pClient, pViewent));
RETURN_API_void()
}
-float mm_Time( void ) {
+
+float mm_Time()
+{
META_ENGINE_HANDLE(float, 0.0, FN_TIME, pfnTime, ());
RETURN_API()
}
-void mm_CrosshairAngle(const edict_t *pClient, float pitch, float yaw) {
+
+void mm_CrosshairAngle(const edict_t *pClient, float pitch, float yaw)
+{
META_ENGINE_HANDLE_void(FN_CROSSHAIRANGLE, pfnCrosshairAngle, (pClient, pitch, yaw));
RETURN_API_void()
}
-byte * mm_LoadFileForMe(char *filename, int *pLength) {
+byte *mm_LoadFileForMe(char *filename, int *pLength)
+{
META_ENGINE_HANDLE(byte *, NULL, FN_LOADFILEFORME, pfnLoadFileForMe, (filename, pLength));
RETURN_API()
}
-void mm_FreeFile(void *buffer) {
+
+void mm_FreeFile(void *buffer)
+{
META_ENGINE_HANDLE_void(FN_FREEFILE, pfnFreeFile, (buffer));
RETURN_API_void()
}
-//! trigger_endsection
-void mm_EndSection(const char *pszSectionName) {
+// trigger_endsection
+void mm_EndSection(const char *pszSectionName)
+{
META_ENGINE_HANDLE_void(FN_ENDSECTION, pfnEndSection, (pszSectionName));
RETURN_API_void()
}
-int mm_CompareFileTime(char *filename1, char *filename2, int *iCompare) {
+
+int mm_CompareFileTime(char *filename1, char *filename2, int *iCompare)
+{
META_ENGINE_HANDLE(int, 0, FN_COMPAREFILETIME, pfnCompareFileTime, (filename1, filename2, iCompare));
RETURN_API()
}
-void mm_GetGameDir(char *szGetGameDir) {
+
+void mm_GetGameDir(char *szGetGameDir)
+{
META_ENGINE_HANDLE_void(FN_GETGAMEDIR, pfnGetGameDir, (szGetGameDir));
RETURN_API_void()
}
-void mm_Cvar_RegisterVariable(cvar_t *variable) {
+
+void mm_Cvar_RegisterVariable(cvar_t *variable)
+{
META_ENGINE_HANDLE_void(FN_CVAR_REGISTERVARIABLE, pfnCvar_RegisterVariable, (variable));
RETURN_API_void()
}
-void mm_FadeClientVolume(const edict_t *pEdict, int fadePercent, int fadeOutSeconds, int holdTime, int fadeInSeconds) {
+
+void mm_FadeClientVolume(const edict_t *pEdict, int fadePercent, int fadeOutSeconds, int holdTime, int fadeInSeconds)
+{
META_ENGINE_HANDLE_void(FN_FADECLIENTVOLUME, pfnFadeClientVolume, (pEdict, fadePercent, fadeOutSeconds, holdTime, fadeInSeconds));
RETURN_API_void()
}
-void mm_SetClientMaxspeed(edict_t *pEdict, float fNewMaxspeed) {
+
+void mm_SetClientMaxspeed(edict_t *pEdict, float fNewMaxspeed)
+{
META_ENGINE_HANDLE_void(FN_SETCLIENTMAXSPEED, pfnSetClientMaxspeed, (pEdict, fNewMaxspeed));
RETURN_API_void()
}
-//! returns NULL if fake client can't be created
-edict_t * mm_CreateFakeClient(const char *netname) {
+
+// returns NULL if fake client can't be created
+edict_t *mm_CreateFakeClient(const char *netname)
+{
META_ENGINE_HANDLE(edict_t *, NULL, FN_CREATEFAKECLIENT, pfnCreateFakeClient, (netname));
RETURN_API()
}
-void mm_RunPlayerMove(edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec ) {
+
+void mm_RunPlayerMove(edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec)
+{
META_ENGINE_HANDLE_void(FN_RUNPLAYERMOVE, pfnRunPlayerMove, (fakeclient, viewangles, forwardmove, sidemove, upmove, buttons, impulse, msec));
RETURN_API_void()
}
-int mm_NumberOfEntities(void) {
+
+int mm_NumberOfEntities()
+{
META_ENGINE_HANDLE(int, 0, FN_NUMBEROFENTITIES, pfnNumberOfEntities, ());
RETURN_API()
}
-//! passing in NULL gets the serverinfo
-char *mm_GetInfoKeyBuffer(edict_t *e) {
+// passing in NULL gets the serverinfo
+char *mm_GetInfoKeyBuffer(edict_t *e)
+{
META_ENGINE_HANDLE(char *, NULL, FN_GETINFOKEYBUFFER, pfnGetInfoKeyBuffer, (e));
RETURN_API()
}
-char *mm_InfoKeyValue(char *infobuffer, const char *key) {
+
+char *mm_InfoKeyValue(char *infobuffer, const char *key)
+{
META_ENGINE_HANDLE(char *, NULL, FN_INFOKEYVALUE, pfnInfoKeyValue, (infobuffer, key));
RETURN_API()
}
-void mm_SetKeyValue(char *infobuffer, const char *key, const char *value) {
+
+void mm_SetKeyValue(char *infobuffer, const char *key, const char *value)
+{
META_ENGINE_HANDLE_void(FN_SETKEYVALUE, pfnSetKeyValue, (infobuffer, key, value));
RETURN_API_void()
}
-void mm_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value) {
+
+void mm_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value)
+{
META_ENGINE_HANDLE_void(FN_SETCLIENTKEYVALUE, pfnSetClientKeyValue, (clientIndex, infobuffer, key, value));
RETURN_API_void()
}
-int mm_IsMapValid(char *filename) {
+int mm_IsMapValid(char *filename)
+{
META_ENGINE_HANDLE(int, 0, FN_ISMAPVALID, pfnIsMapValid, (filename));
RETURN_API()
}
-void mm_StaticDecal( const float *origin, int decalIndex, int entityIndex, int modelIndex ) {
+
+void mm_StaticDecal(const float *origin, int decalIndex, int entityIndex, int modelIndex)
+{
META_ENGINE_HANDLE_void(FN_STATICDECAL, pfnStaticDecal, (origin, decalIndex, entityIndex, modelIndex));
RETURN_API_void()
}
-int mm_PrecacheGeneric(char *s) {
+
+int mm_PrecacheGeneric(char *s)
+{
META_ENGINE_HANDLE(int, 0, FN_PRECACHEGENERIC, pfnPrecacheGeneric, (s));
RETURN_API()
}
-//! returns the server assigned userid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
-int mm_GetPlayerUserId(edict_t *e ) {
+
+// returns the server assigned userid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
+int mm_GetPlayerUserId(edict_t *e)
+{
META_ENGINE_HANDLE(int, 0, FN_GETPLAYERUSERID, pfnGetPlayerUserId, (e));
RETURN_API()
}
-void mm_BuildSoundMsg(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
+
+void mm_BuildSoundMsg(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
{
META_ENGINE_HANDLE_void(FN_BUILDSOUNDMSG, pfnBuildSoundMsg, (entity, channel, sample, volume, attenuation, fFlags, pitch, msg_dest, msg_type, pOrigin, ed));
RETURN_API_void()
}
-//! is this a dedicated server?
-int mm_IsDedicatedServer(void) {
+
+// is this a dedicated server?
+int mm_IsDedicatedServer()
+{
META_ENGINE_HANDLE(int, 0, FN_ISDEDICATEDSERVER, pfnIsDedicatedServer, ());
RETURN_API()
}
-cvar_t *mm_CVarGetPointer(const char *szVarName) {
+
+cvar_t *mm_CVarGetPointer(const char *szVarName)
+{
META_ENGINE_HANDLE(cvar_t *, NULL, FN_CVARGETPOINTER, pfnCVarGetPointer, (szVarName));
RETURN_API()
}
-//! returns the server assigned WONid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
-unsigned int mm_GetPlayerWONId(edict_t *e) {
+
+// returns the server assigned WONid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
+unsigned int mm_GetPlayerWONId(edict_t *e)
+{
META_ENGINE_HANDLE(unsigned int, 0, FN_GETPLAYERWONID, pfnGetPlayerWONId, (e));
RETURN_API()
}
-//! YWB 8/1/99 TFF Physics additions
-void mm_Info_RemoveKey( char *s, const char *key ) {
+// YWB 8/1/99 TFF Physics additions
+void mm_Info_RemoveKey(char *s, const char *key)
+{
META_ENGINE_HANDLE_void(FN_INFO_REMOVEKEY, pfnInfo_RemoveKey, (s, key));
RETURN_API_void()
}
-const char *mm_GetPhysicsKeyValue( const edict_t *pClient, const char *key ) {
+
+const char *mm_GetPhysicsKeyValue(const edict_t *pClient, const char *key)
+{
META_ENGINE_HANDLE(const char *, NULL, FN_GETPHYSICSKEYVALUE, pfnGetPhysicsKeyValue, (pClient, key));
RETURN_API()
}
-void mm_SetPhysicsKeyValue( const edict_t *pClient, const char *key, const char *value ) {
+
+void mm_SetPhysicsKeyValue(const edict_t *pClient, const char *key, const char *value)
+{
META_ENGINE_HANDLE_void(FN_SETPHYSICSKEYVALUE, pfnSetPhysicsKeyValue, (pClient, key, value));
RETURN_API_void()
}
-const char *mm_GetPhysicsInfoString( const edict_t *pClient ) {
+
+const char *mm_GetPhysicsInfoString(const edict_t *pClient)
+{
META_ENGINE_HANDLE(const char *, NULL, FN_GETPHYSICSINFOSTRING, pfnGetPhysicsInfoString, (pClient));
RETURN_API()
}
-unsigned short mm_PrecacheEvent( int type, const char *psz ) {
+
+unsigned short mm_PrecacheEvent(int type, const char *psz)
+{
META_ENGINE_HANDLE(unsigned short, 0, FN_PRECACHEEVENT, pfnPrecacheEvent, (type, psz));
RETURN_API()
}
-void mm_PlaybackEvent( int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 )
+
+void mm_PlaybackEvent(int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2)
{
META_ENGINE_HANDLE_void(FN_PLAYBACKEVENT, pfnPlaybackEvent, (flags, pInvoker, eventindex, delay, origin, angles, fparam1, fparam2, iparam1, iparam2, bparam1, bparam2));
RETURN_API_void()
}
-unsigned char *mm_SetFatPVS( float *org ) {
+unsigned char *mm_SetFatPVS(float *org)
+{
META_ENGINE_HANDLE(unsigned char *, 0, FN_SETFATPVS, pfnSetFatPVS, (org));
RETURN_API()
}
-unsigned char *mm_SetFatPAS( float *org ) {
+
+unsigned char *mm_SetFatPAS(float *org)
+{
META_ENGINE_HANDLE(unsigned char *, 0, FN_SETFATPAS, pfnSetFatPAS, (org));
RETURN_API()
}
-int mm_CheckVisibility( edict_t *entity, unsigned char *pset ) {
+int mm_CheckVisibility(edict_t *entity, unsigned char *pset)
+{
META_ENGINE_HANDLE(int, 0, FN_CHECKVISIBILITY, pfnCheckVisibility, (entity, pset));
RETURN_API()
}
-void mm_DeltaSetField( struct delta_s *pFields, const char *fieldname ) {
+void mm_DeltaSetField(struct delta_s *pFields, const char *fieldname)
+{
META_ENGINE_HANDLE_void(FN_DELTASETFIELD, pfnDeltaSetField, (pFields, fieldname));
RETURN_API_void()
}
-void mm_DeltaUnsetField( struct delta_s *pFields, const char *fieldname ) {
+
+void mm_DeltaUnsetField(struct delta_s *pFields, const char *fieldname)
+{
META_ENGINE_HANDLE_void(FN_DELTAUNSETFIELD, pfnDeltaUnsetField, (pFields, fieldname));
RETURN_API_void()
}
-void mm_DeltaAddEncoder( char *name, void (*conditionalencode)( struct delta_s *pFields, const unsigned char *from, const unsigned char *to ) ) {
+
+void mm_DeltaAddEncoder(char *name, void (*conditionalencode)(struct delta_s *pFields, const unsigned char *from, const unsigned char *to))
+{
META_ENGINE_HANDLE_void(FN_DELTAADDENCODER, pfnDeltaAddEncoder, (name, conditionalencode));
RETURN_API_void()
}
-int mm_GetCurrentPlayer( void ) {
+
+int mm_GetCurrentPlayer()
+{
META_ENGINE_HANDLE(int, 0, FN_GETCURRENTPLAYER, pfnGetCurrentPlayer, ());
RETURN_API()
}
-int mm_CanSkipPlayer( const edict_t *player ) {
+
+int mm_CanSkipPlayer(const edict_t *player)
+{
META_ENGINE_HANDLE(int, 0, FN_CANSKIPPLAYER, pfnCanSkipPlayer, (player));
RETURN_API()
}
-int mm_DeltaFindField( struct delta_s *pFields, const char *fieldname ) {
+
+int mm_DeltaFindField(struct delta_s *pFields, const char *fieldname)
+{
META_ENGINE_HANDLE(int, 0, FN_DELTAFINDFIELD, pfnDeltaFindField, (pFields, fieldname));
RETURN_API()
}
-void mm_DeltaSetFieldByIndex( struct delta_s *pFields, int fieldNumber ) {
+
+void mm_DeltaSetFieldByIndex(struct delta_s *pFields, int fieldNumber)
+{
META_ENGINE_HANDLE_void(FN_DELTASETFIELDBYINDEX, pfnDeltaSetFieldByIndex, (pFields, fieldNumber));
RETURN_API_void()
}
-void mm_DeltaUnsetFieldByIndex( struct delta_s *pFields, int fieldNumber ) {
+
+void mm_DeltaUnsetFieldByIndex(struct delta_s *pFields, int fieldNumber)
+{
META_ENGINE_HANDLE_void(FN_DELTAUNSETFIELDBYINDEX, pfnDeltaUnsetFieldByIndex, (pFields, fieldNumber));
RETURN_API_void()
}
-void mm_SetGroupMask( int mask, int op ) {
+void mm_SetGroupMask(int mask, int op)
+{
META_ENGINE_HANDLE_void(FN_SETGROUPMASK, pfnSetGroupMask, (mask, op));
RETURN_API_void()
}
-int mm_engCreateInstancedBaseline( int classname, struct entity_state_s *baseline ) {
+int mm_engCreateInstancedBaseline(int classname, struct entity_state_s *baseline)
+{
META_ENGINE_HANDLE(int, 0, FN_CREATEINSTANCEDBASELINE, pfnCreateInstancedBaseline, (classname, baseline));
RETURN_API()
}
-void mm_Cvar_DirectSet( struct cvar_s *var, const char *value ) {
+
+void mm_Cvar_DirectSet(struct cvar_s *var, const char *value)
+{
META_ENGINE_HANDLE_void(FN_CVAR_DIRECTSET, pfnCvar_DirectSet, (var, value));
RETURN_API_void()
}
-//! Forces the client and server to be running with the same version of the specified file
-//!( e.g., a player model ).
-//! Calling this has no effect in single player
-void mm_ForceUnmodified( FORCE_TYPE type, float *mins, float *maxs, const char *filename ) {
+// Forces the client and server to be running with the same version of the specified file (e.g., a player model).
+// Calling this has no effect in single player
+void mm_ForceUnmodified(FORCE_TYPE type, float *mins, float *maxs, const char *filename)
+{
META_ENGINE_HANDLE_void(FN_FORCEUNMODIFIED, pfnForceUnmodified, (type, mins, maxs, filename));
RETURN_API_void()
}
-void mm_GetPlayerStats( const edict_t *pClient, int *ping, int *packet_loss ) {
+void mm_GetPlayerStats(const edict_t *pClient, int *ping, int *packet_loss)
+{
META_ENGINE_HANDLE_void(FN_GETPLAYERSTATS, pfnGetPlayerStats, (pClient, ping, packet_loss));
RETURN_API_void()
}
-void mm_AddServerCommand( char *cmd_name, void (*function) (void) ) {
+void mm_AddServerCommand(char *cmd_name, void (*function)())
+{
META_ENGINE_HANDLE_void(FN_ADDSERVERCOMMAND, pfnAddServerCommand, (cmd_name, function));
RETURN_API_void()
}
-// Added in SDK 2.2:
-
-//! For voice communications, set which clients hear eachother.
-//! NOTE: these functions take player entity indices (starting at 1).
-qboolean mm_Voice_GetClientListening(int iReceiver, int iSender) {
+// For voice communications, set which clients hear eachother.
+// NOTE: these functions take player entity indices (starting at 1).
+qboolean mm_Voice_GetClientListening(int iReceiver, int iSender)
+{
META_ENGINE_HANDLE(qboolean, false, FN_VOICE_GETCLIENTLISTENING, pfnVoice_GetClientListening, (iReceiver, iSender));
RETURN_API()
}
-qboolean mm_Voice_SetClientListening(int iReceiver, int iSender, qboolean bListen) {
+
+qboolean mm_Voice_SetClientListening(int iReceiver, int iSender, qboolean bListen)
+{
META_ENGINE_HANDLE(qboolean, false, FN_VOICE_SETCLIENTLISTENING, pfnVoice_SetClientListening, (iReceiver, iSender, bListen));
RETURN_API()
}
-// Added for HL 1109 (no SDK update):
-
-const char *mm_GetPlayerAuthId(edict_t *e) {
+const char *mm_GetPlayerAuthId(edict_t *e)
+{
META_ENGINE_HANDLE(const char *, NULL, FN_GETPLAYERAUTHID, pfnGetPlayerAuthId, (e));
RETURN_API()
}
-// Added 2003-11-10 (no SDK update):
-
-sequenceEntry_s *mm_SequenceGet(const char *fileName, const char *entryName) {
+sequenceEntry_s *mm_SequenceGet(const char *fileName, const char *entryName)
+{
META_ENGINE_HANDLE(sequenceEntry_s *, NULL, FN_SEQUENCEGET, pfnSequenceGet, (fileName, entryName));
RETURN_API()
}
-sentenceEntry_s *mm_SequencePickSentence(const char *groupName, int pickMethod, int *picked) {
+sentenceEntry_s *mm_SequencePickSentence(const char *groupName, int pickMethod, int *picked)
+{
META_ENGINE_HANDLE(sentenceEntry_s *, NULL, FN_SEQUENCEPICKSENTENCE, pfnSequencePickSentence, (groupName, pickMethod, picked));
RETURN_API()
}
-int mm_GetFileSize(char *filename) {
+int mm_GetFileSize(char *filename)
+{
META_ENGINE_HANDLE(int, 0, FN_GETFILESIZE, pfnGetFileSize, (filename));
RETURN_API()
}
-unsigned int mm_GetApproxWavePlayLen(const char *filepath) {
+unsigned int mm_GetApproxWavePlayLen(const char *filepath)
+{
META_ENGINE_HANDLE(unsigned int, 0, FN_GETAPPROXWAVEPLAYLEN, pfnGetApproxWavePlayLen, (filepath));
RETURN_API()
}
-int mm_IsCareerMatch(void) {
+int mm_IsCareerMatch()
+{
META_ENGINE_HANDLE(int, 0, FN_ISCAREERMATCH, pfnIsCareerMatch, ());
RETURN_API()
}
-int mm_GetLocalizedStringLength(const char *label) {
+int mm_GetLocalizedStringLength(const char *label)
+{
META_ENGINE_HANDLE(int, 0, FN_GETLOCALIZEDSTRINGLENGTH, pfnGetLocalizedStringLength, (label));
RETURN_API()
}
-void mm_RegisterTutorMessageShown(int mid) {
+void mm_RegisterTutorMessageShown(int mid)
+{
META_ENGINE_HANDLE_void(FN_REGISTERTUTORMESSAGESHOWN, pfnRegisterTutorMessageShown, (mid));
RETURN_API_void()
}
-int mm_GetTimesTutorMessageShown(int mid) {
+int mm_GetTimesTutorMessageShown(int mid)
+{
META_ENGINE_HANDLE(int, 0, FN_GETTIMESTUTORMESSAGESHOWN, pfnGetTimesTutorMessageShown, (mid));
RETURN_API()
}
-void mm_ProcessTutorMessageDecayBuffer(int *buffer, int bufferLength) {
+void mm_ProcessTutorMessageDecayBuffer(int *buffer, int bufferLength)
+{
META_ENGINE_HANDLE_void(FN_PROCESSTUTORMESSAGEDECAYBUFFER, pfnProcessTutorMessageDecayBuffer, (buffer, bufferLength));
RETURN_API_void()
}
-void mm_ConstructTutorMessageDecayBuffer(int *buffer, int bufferLength) {
+void mm_ConstructTutorMessageDecayBuffer(int *buffer, int bufferLength)
+{
META_ENGINE_HANDLE_void(FN_CONSTRUCTTUTORMESSAGEDECAYBUFFER, pfnConstructTutorMessageDecayBuffer, (buffer, bufferLength));
RETURN_API_void()
}
-void mm_ResetTutorMessageDecayData(void) {
+void mm_ResetTutorMessageDecayData()
+{
META_ENGINE_HANDLE_void(FN_RESETTUTORMESSAGEDECAYDATA, pfnResetTutorMessageDecayData, ());
RETURN_API_void()
}
-//Added 2005-08-11 (no SDK update)
void mm_QueryClientCvarValue(const edict_t *pEdict, const char *cvarName)
{
g_Players.set_player_cvar_query(pEdict, cvarName);
@@ -861,21 +1051,20 @@ void mm_QueryClientCvarValue(const edict_t *pEdict, const char *cvarName)
RETURN_API_void();
}
-//Added 2005-11-22 (no SDK update)
void mm_QueryClientCvarValue2(const edict_t *pEdict, const char *cvarName, int requestId)
{
META_ENGINE_HANDLE_void(FN_QUERYCLIENTCVARVALUE2, pfnQueryClientCvarValue2, (pEdict, cvarName, requestId));
RETURN_API_void();
}
-//Added 2009-06-17 (no SDK update)
int mm_EngCheckParm(const char *pchCmdLineToken, char **ppnext)
{
META_ENGINE_HANDLE(int, 0, FN_CHECKPARM, pfnEngCheckParm, (pchCmdLineToken, ppnext));
RETURN_API();
}
-enginefuncs_t _engfuncs = {
+enginefuncs_t _engfuncs =
+{
&mm_PrecacheModel, // pfnPrecacheModel()
&mm_PrecacheSound, // pfnPrecacheSound()
&mm_SetModel, // pfnSetModel()
@@ -893,10 +1082,10 @@ enginefuncs_t _engfuncs = {
&mm_ChangeYaw, // pfnChangeYaw()
&mm_ChangePitch, // pfnChangePitch()
- &mm_FindEntityByString, // pfnFindEntityByString()
+ &mm_FindEntityByString, // pfnFindEntityByString()
&mm_GetEntityIllum, // pfnGetEntityIllum()
- &mm_FindEntityInSphere, // pfnFindEntityInSphere()
- &mm_FindClientInPVS, // pfnFindClientInPVS()
+ &mm_FindEntityInSphere, // pfnFindEntityInSphere()
+ &mm_FindClientInPVS, // pfnFindClientInPVS()
&mm_EntitiesInPVS, // pfnEntitiesInPVS()
&mm_MakeVectors, // pfnMakeVectors()
@@ -904,7 +1093,7 @@ enginefuncs_t _engfuncs = {
&mm_CreateEntity, // pfnCreateEntity()
&mm_RemoveEntity, // pfnRemoveEntity()
- &mm_CreateNamedEntity, // pfnCreateNamedEntity()
+ &mm_CreateNamedEntity, // pfnCreateNamedEntity()
&mm_MakeStatic, // pfnMakeStatic()
&mm_EntIsOnFloor, // pfnEntIsOnFloor()
@@ -914,11 +1103,11 @@ enginefuncs_t _engfuncs = {
&mm_SetOrigin, // pfnSetOrigin()
&mm_EmitSound, // pfnEmitSound()
- &mm_EmitAmbientSound, // pfnEmitAmbientSound()
+ &mm_EmitAmbientSound, // pfnEmitAmbientSound()
&mm_TraceLine, // pfnTraceLine()
&mm_TraceToss, // pfnTraceToss()
- &mm_TraceMonsterHull, // pfnTraceMonsterHull()
+ &mm_TraceMonsterHull, // pfnTraceMonsterHull()
&mm_TraceHull, // pfnTraceHull()
&mm_TraceModel, // pfnTraceModel()
&mm_TraceTexture, // pfnTraceTexture()
@@ -927,7 +1116,7 @@ enginefuncs_t _engfuncs = {
&mm_ServerCommand, // pfnServerCommand()
&mm_ServerExecute, // pfnServerExecute()
- &mm_engClientCommand, // pfnClientCommand() // D'oh, ClientCommand in dllapi too.
+ &mm_engClientCommand, // pfnClientCommand() // D'oh, ClientCommand in dllapi too.
&mm_ParticleEffect, // pfnParticleEffect()
&mm_LightStyle, // pfnLightStyle()
@@ -955,41 +1144,41 @@ enginefuncs_t _engfuncs = {
&mm_AlertMessage, // pfnAlertMessage()
&mm_EngineFprintf, // pfnEngineFprintf()
- &mm_PvAllocEntPrivateData, // pfnPvAllocEntPrivateData()
- &mm_PvEntPrivateData, // pfnPvEntPrivateData()
- &mm_FreeEntPrivateData, // pfnFreeEntPrivateData()
+ &mm_PvAllocEntPrivateData, // pfnPvAllocEntPrivateData()
+ &mm_PvEntPrivateData, // pfnPvEntPrivateData()
+ &mm_FreeEntPrivateData, // pfnFreeEntPrivateData()
&mm_SzFromIndex, // pfnSzFromIndex()
&mm_AllocString, // pfnAllocString()
- &mm_GetVarsOfEnt, // pfnGetVarsOfEnt()
- &mm_PEntityOfEntOffset, // pfnPEntityOfEntOffset()
- &mm_EntOffsetOfPEntity, // pfnEntOffsetOfPEntity()
+ &mm_GetVarsOfEnt, // pfnGetVarsOfEnt()
+ &mm_PEntityOfEntOffset, // pfnPEntityOfEntOffset()
+ &mm_EntOffsetOfPEntity, // pfnEntOffsetOfPEntity()
&mm_IndexOfEdict, // pfnIndexOfEdict()
- &mm_PEntityOfEntIndex, // pfnPEntityOfEntIndex()
- &mm_FindEntityByVars, // pfnFindEntityByVars()
+ &mm_PEntityOfEntIndex, // pfnPEntityOfEntIndex()
+ &mm_FindEntityByVars, // pfnFindEntityByVars()
&mm_GetModelPtr, // pfnGetModelPtr()
&mm_RegUserMsg, // pfnRegUserMsg()
- &mm_AnimationAutomove, // pfnAnimationAutomove()
- &mm_GetBonePosition, // pfnGetBonePosition()
+ &mm_AnimationAutomove, // pfnAnimationAutomove()
+ &mm_GetBonePosition, // pfnGetBonePosition()
- &mm_FunctionFromName, // pfnFunctionFromName()
- &mm_NameForFunction, // pfnNameForFunction()
+ &mm_FunctionFromName, // pfnFunctionFromName()
+ &mm_NameForFunction, // pfnNameForFunction()
- &mm_ClientPrintf, // pfnClientPrintf() //! JOHN: engine callbacks so game DLL can print messages to individual clients
+ &mm_ClientPrintf, // pfnClientPrintf() // JOHN: engine callbacks so game DLL can print messages to individual clients
&mm_ServerPrint, // pfnServerPrint()
- &mm_Cmd_Args, // pfnCmd_Args() //! these 3 added
- &mm_Cmd_Argv, // pfnCmd_Argv() //! so game DLL can easily
- &mm_Cmd_Argc, // pfnCmd_Argc() //! access client 'cmd' strings
+ &mm_Cmd_Args, // pfnCmd_Args() // these 3 added
+ &mm_Cmd_Argv, // pfnCmd_Argv() // so game DLL can easily
+ &mm_Cmd_Argc, // pfnCmd_Argc() // access client 'cmd' strings
&mm_GetAttachment, // pfnGetAttachment()
&mm_CRC32_Init, // pfnCRC32_Init()
- &mm_CRC32_ProcessBuffer, // pfnCRC32_ProcessBuffer()
- &mm_CRC32_ProcessByte, // pfnCRC32_ProcessByte()
+ &mm_CRC32_ProcessBuffer, // pfnCRC32_ProcessBuffer()
+ &mm_CRC32_ProcessByte, // pfnCRC32_ProcessByte()
&mm_CRC32_Final, // pfnCRC32_Final()
&mm_RandomLong, // pfnRandomLong()
@@ -1002,91 +1191,82 @@ enginefuncs_t _engfuncs = {
&mm_LoadFileForMe, // pfnLoadFileForMe()
&mm_FreeFile, // pfnFreeFile()
- &mm_EndSection, // pfnEndSection() //! trigger_endsection
- &mm_CompareFileTime, // pfnCompareFileTime()
+ &mm_EndSection, // pfnEndSection() // trigger_endsection
+ &mm_CompareFileTime, // pfnCompareFileTime()
&mm_GetGameDir, // pfnGetGameDir()
- &mm_Cvar_RegisterVariable, // pfnCvar_RegisterVariable()
- &mm_FadeClientVolume, // pfnFadeClientVolume()
- &mm_SetClientMaxspeed, // pfnSetClientMaxspeed()
- &mm_CreateFakeClient, // pfnCreateFakeClient() //! returns NULL if fake client can't be created
+ &mm_Cvar_RegisterVariable, // pfnCvar_RegisterVariable()
+ &mm_FadeClientVolume, // pfnFadeClientVolume()
+ &mm_SetClientMaxspeed, // pfnSetClientMaxspeed()
+ &mm_CreateFakeClient, // pfnCreateFakeClient() // returns NULL if fake client can't be created
&mm_RunPlayerMove, // pfnRunPlayerMove()
- &mm_NumberOfEntities, // pfnNumberOfEntities()
+ &mm_NumberOfEntities, // pfnNumberOfEntities()
- &mm_GetInfoKeyBuffer, // pfnGetInfoKeyBuffer() //! passing in NULL gets the serverinfo
+ &mm_GetInfoKeyBuffer, // pfnGetInfoKeyBuffer() // passing in NULL gets the serverinfo
&mm_InfoKeyValue, // pfnInfoKeyValue()
&mm_SetKeyValue, // pfnSetKeyValue()
- &mm_SetClientKeyValue, // pfnSetClientKeyValue()
+ &mm_SetClientKeyValue, // pfnSetClientKeyValue()
&mm_IsMapValid, // pfnIsMapValid()
&mm_StaticDecal, // pfnStaticDecal()
- &mm_PrecacheGeneric, // pfnPrecacheGeneric()
- &mm_GetPlayerUserId, // pfnGetPlayerUserId() //! returns the server assigned userid for this player.
+ &mm_PrecacheGeneric, // pfnPrecacheGeneric()
+ &mm_GetPlayerUserId, // pfnGetPlayerUserId() // returns the server assigned userid for this player.
&mm_BuildSoundMsg, // pfnBuildSoundMsg()
- &mm_IsDedicatedServer, // pfnIsDedicatedServer() //! is this a dedicated server?
+ &mm_IsDedicatedServer, // pfnIsDedicatedServer() // is this a dedicated server?
&mm_CVarGetPointer, // pfnCVarGetPointer()
- &mm_GetPlayerWONId, // pfnGetPlayerWONId() //! returns the server assigned WONid for this player.
+ &mm_GetPlayerWONId, // pfnGetPlayerWONId() // returns the server assigned WONid for this player.
- //! YWB 8/1/99 TFF Physics additions
&mm_Info_RemoveKey, // pfnInfo_RemoveKey()
- &mm_GetPhysicsKeyValue, // pfnGetPhysicsKeyValue()
- &mm_SetPhysicsKeyValue, // pfnSetPhysicsKeyValue()
- &mm_GetPhysicsInfoString, // pfnGetPhysicsInfoString()
+ &mm_GetPhysicsKeyValue, // pfnGetPhysicsKeyValue()
+ &mm_SetPhysicsKeyValue, // pfnSetPhysicsKeyValue()
+ &mm_GetPhysicsInfoString, // pfnGetPhysicsInfoString()
&mm_PrecacheEvent, // pfnPrecacheEvent()
&mm_PlaybackEvent, // pfnPlaybackEvent()
&mm_SetFatPVS, // pfnSetFatPVS()
&mm_SetFatPAS, // pfnSetFatPAS()
- &mm_CheckVisibility, // pfnCheckVisibility()
+ &mm_CheckVisibility, // pfnCheckVisibility()
&mm_DeltaSetField, // pfnDeltaSetField()
- &mm_DeltaUnsetField, // pfnDeltaUnsetField()
- &mm_DeltaAddEncoder, // pfnDeltaAddEncoder()
- &mm_GetCurrentPlayer, // pfnGetCurrentPlayer()
+ &mm_DeltaUnsetField, // pfnDeltaUnsetField()
+ &mm_DeltaAddEncoder, // pfnDeltaAddEncoder()
+ &mm_GetCurrentPlayer, // pfnGetCurrentPlayer()
&mm_CanSkipPlayer, // pfnCanSkipPlayer()
&mm_DeltaFindField, // pfnDeltaFindField()
- &mm_DeltaSetFieldByIndex, // pfnDeltaSetFieldByIndex()
- &mm_DeltaUnsetFieldByIndex, // pfnDeltaUnsetFieldByIndex()
+ &mm_DeltaSetFieldByIndex, // pfnDeltaSetFieldByIndex()
+ &mm_DeltaUnsetFieldByIndex, // pfnDeltaUnsetFieldByIndex()
&mm_SetGroupMask, // pfnSetGroupMask()
- &mm_engCreateInstancedBaseline, // pfnCreateInstancedBaseline() // D'oh, CreateInstancedBaseline in dllapi too.
+ &mm_engCreateInstancedBaseline, // pfnCreateInstancedBaseline() // D'oh, CreateInstancedBaseline in dllapi too.
&mm_Cvar_DirectSet, // pfnCvar_DirectSet()
- &mm_ForceUnmodified, // pfnForceUnmodified()
+ &mm_ForceUnmodified, // pfnForceUnmodified()
&mm_GetPlayerStats, // pfnGetPlayerStats()
- &mm_AddServerCommand, // pfnAddServerCommand()
+ &mm_AddServerCommand, // pfnAddServerCommand()
- // Added in SDK 2l2:
- &mm_Voice_GetClientListening, // pfnVoice_GetClientListening()
- &mm_Voice_SetClientListening, // pfnVoice_SetClientListening()
+ &mm_Voice_GetClientListening, // pfnVoice_GetClientListening()
+ &mm_Voice_SetClientListening, // pfnVoice_SetClientListening()
- // Added for HL 1109 (no SDK update):
&mm_GetPlayerAuthId, // pfnGetPlayerAuthId()
- // Added 2003-11-10 (no SDK update):
- &mm_SequenceGet, // pfnSequenceGet()
- &mm_SequencePickSentence, // pfnSequencePickSentence()
- &mm_GetFileSize, // pfnGetFileSize()
- &mm_GetApproxWavePlayLen, // pfnGetApproxWavePlayLen()
- &mm_IsCareerMatch, // pfnIsCareerMatch()
+ &mm_SequenceGet, // pfnSequenceGet()
+ &mm_SequencePickSentence, // pfnSequencePickSentence()
+ &mm_GetFileSize, // pfnGetFileSize()
+ &mm_GetApproxWavePlayLen, // pfnGetApproxWavePlayLen()
+ &mm_IsCareerMatch, // pfnIsCareerMatch()
&mm_GetLocalizedStringLength, // pfnGetLocalizedStringLength()
- &mm_RegisterTutorMessageShown, // pfnRegisterTutorMessageShown()
- &mm_GetTimesTutorMessageShown, // pfnGetTimesTutorMessageShown()
+ &mm_RegisterTutorMessageShown, // pfnRegisterTutorMessageShown()
+ &mm_GetTimesTutorMessageShown, // pfnGetTimesTutorMessageShown()
&mm_ProcessTutorMessageDecayBuffer, // pfnProcessTutorMessageDecayBuffer()
&mm_ConstructTutorMessageDecayBuffer, // pfnConstructTutorMessageDecayBuffer()
&mm_ResetTutorMessageDecayData, // pfnResetTutorMessageDecayData()
- //Added 2005-08-11 (no SDK update)
&mm_QueryClientCvarValue, // pfnQueryClientCvarValue()
-
- //Added 2005-11-22 (no SDK update)
&mm_QueryClientCvarValue2, // pfnQueryClientCvarValue2()
-
- // Added 2009-06-17 (no SDK update)
- &mm_EngCheckParm // pfnCheckParm()
+ &mm_EngCheckParm // pfnCheckParm()
};
meta_enginefuncs_t meta_engfuncs(&_engfuncs);
diff --git a/metamod/src/engine_api.h b/metamod/src/engine_api.h
index a8e8c21..a805384 100644
--- a/metamod/src/engine_api.h
+++ b/metamod/src/engine_api.h
@@ -1,62 +1,23 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// engine_api.h - prototypes and typedefs for Half-Life engine functions
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef ENGINE_API_H
-#define ENGINE_API_H
+#pragma once
#include
// Plugin's GetEngineFunctions, called by metamod.
-typedef int (*GET_ENGINE_FUNCTIONS_FN) (enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion);
+typedef int (*GET_ENGINE_FUNCTIONS_FN)(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion);
// According to SDK engine/eiface.h:
-//! enginefuncs_t
-//! ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 138
+// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 138
#define ENGINE_INTERFACE_VERSION 138
// Protect against other projects which use this include file but use the
// normal enginefuncs_t type for their meta_engfuncs.
#ifdef METAMOD_CORE
-# include "meta_eiface.h" // meta_enginefuncs_t
-extern meta_enginefuncs_t meta_engfuncs;
+ #include "meta_eiface.h" // meta_enginefuncs_t
+ extern meta_enginefuncs_t meta_engfuncs;
#else
-extern enginefuncs_t meta_engfuncs;
+ extern enginefuncs_t meta_engfuncs;
#endif
-// From SDK engine/eiface.h:
extern int mm_PrecacheModel(const char *s);
extern int mm_PrecacheSound(const char *s);
extern void mm_SetModel(edict_t *e, const char *m);
@@ -83,7 +44,7 @@ extern edict_t *mm_EntitiesInPVS(edict_t *pplayer);
extern void mm_MakeVectors(const float *rgflVector);
extern void mm_AngleVectors(const float *rgflVector, float *forward, float *right, float *up);
-extern edict_t *mm_CreateEntity(void);
+extern edict_t *mm_CreateEntity();
extern void mm_RemoveEntity(edict_t *e);
extern edict_t *mm_CreateNamedEntity(int className);
@@ -102,12 +63,12 @@ extern void mm_TraceToss(edict_t *pent, edict_t *pentToIgnore, TraceResult *ptr)
extern int mm_TraceMonsterHull(edict_t *pEdict, const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr);
extern void mm_TraceHull(const float *v1, const float *v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult *ptr);
extern void mm_TraceModel(const float *v1, const float *v2, int hullNumber, edict_t *pent, TraceResult *ptr);
-extern const char *mm_TraceTexture(edict_t *pTextureEntity, const float *v1, const float *v2 );
+extern const char *mm_TraceTexture(edict_t *pTextureEntity, const float *v1, const float *v2);
extern void mm_TraceSphere(const float *v1, const float *v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult *ptr);
extern void mm_GetAimVector(edict_t *ent, float speed, float *rgflReturn);
extern void mm_ServerCommand(const char *str);
-extern void mm_ServerExecute(void);
+extern void mm_ServerExecute();
extern void ClientCommand(edict_t *pEdict, const char *szFmt, ...);
extern void mm_ParticleEffect(const float *org, const float *dir, float color, float count);
@@ -116,7 +77,7 @@ extern int mm_DecalIndex(const char *name);
extern int mm_PointContents(const float *rgflVector);
extern void mm_MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
-extern void mm_MessageEnd(void);
+extern void mm_MessageEnd();
extern void mm_WriteByte(int iValue);
extern void mm_WriteChar(int iValue);
@@ -129,22 +90,13 @@ extern void mm_WriteEntity(int iValue);
extern void mm_CVarRegister(cvar_t *pCvar);
extern float mm_CVarGetFloat(const char *szVarName);
-extern const char* mm_CVarGetString(const char *szVarName);
+extern const char *mm_CVarGetString(const char *szVarName);
extern void mm_CVarSetFloat(const char *szVarName, float flValue);
extern void mm_CVarSetString(const char *szVarName, const char *szValue);
extern void mm_AlertMessage(ALERT_TYPE atype, const char *szFmt, ...);
-#ifdef HLSDK_3_2_OLD_EIFACE
-extern void mm_EngineFprintf(FILE *pfile, const char *szFmt, ...);
-#else
extern void mm_EngineFprintf(void *pfile, const char *szFmt, ...);
-#endif
-
-#ifdef HLSDK_3_2_OLD_EIFACE
-extern void *mm_PvAllocEntPrivateData(edict_t *pEdict, long cb);
-#else
extern void *mm_PvAllocEntPrivateData(edict_t *pEdict, int32 cb);
-#endif
extern void *mm_PvEntPrivateData(edict_t *pEdict);
extern void mm_FreeEntPrivateData(edict_t *pEdict);
@@ -162,42 +114,33 @@ extern void *mm_GetModelPtr(edict_t *pEdict);
extern int mm_RegUserMsg(const char *pszName, int iSize);
extern void mm_AnimationAutomove(const edict_t *pEdict, float flTime);
-extern void mm_GetBonePosition(const edict_t *pEdict, int iBone, float *rgflOrigin, float *rgflAngles );
+extern void mm_GetBonePosition(const edict_t *pEdict, int iBone, float *rgflOrigin, float *rgflAngles);
-#ifdef HLSDK_3_2_OLD_EIFACE
-extern unsigned long mm_FunctionFromName( const char *pName );
-extern const char *mm_NameForFunction( unsigned long function );
-#else
-extern uint32 mm_FunctionFromName( const char *pName );
-extern const char *mm_NameForFunction( uint32 function );
-#endif
+extern uint32 mm_FunctionFromName(const char *pName);
+extern const char *mm_NameForFunction(uint32 function);
-extern void mm_ClientPrintf( edict_t *pEdict, PRINT_TYPE ptype, const char *szMsg ); //! JOHN: engine callbacks so game DLL can print messages to individual clients
-extern void mm_ServerPrint( const char *szMsg );
+extern void mm_ClientPrintf(edict_t *pEdict, PRINT_TYPE ptype, const char *szMsg); //! JOHN: engine callbacks so game DLL can print messages to individual clients
+extern void mm_ServerPrint(const char *szMsg);
-extern const char *mm_Cmd_Args( void ); //! these 3 added
-extern const char *mm_Cmd_Argv( int argc ); //! so game DLL can easily
-extern int mm_Cmd_Argc( void ); //! access client 'cmd' strings
+extern const char *mm_Cmd_Args(); //! these 3 added
+extern const char *mm_Cmd_Argv(int argc); //! so game DLL can easily
+extern int mm_Cmd_Argc(); //! access client 'cmd' strings
-extern void mm_GetAttachment(const edict_t *pEdict, int iAttachment, float *rgflOrigin, float *rgflAngles );
+extern void mm_GetAttachment(const edict_t *pEdict, int iAttachment, float *rgflOrigin, float *rgflAngles);
extern void mm_CRC32_Init(CRC32_t *pulCRC);
extern void mm_CRC32_ProcessBuffer(CRC32_t *pulCRC, void *p, int len);
extern void mm_CRC32_ProcessByte(CRC32_t *pulCRC, unsigned char ch);
extern CRC32_t mm_CRC32_Final(CRC32_t pulCRC);
-#ifdef HLSDK_3_2_OLD_EIFACE
-extern long mm_RandomLong(long lLow, long lHigh);
-#else
extern int32 mm_RandomLong(int32 lLow, int32 lHigh);
-#endif
extern float mm_RandomFloat(float flLow, float flHigh);
-extern void mm_SetView(const edict_t *pClient, const edict_t *pViewent );
-extern float mm_Time( void );
+extern void mm_SetView(const edict_t *pClient, const edict_t *pViewent);
+extern float mm_Time();
extern void mm_CrosshairAngle(const edict_t *pClient, float pitch, float yaw);
-extern byte * mm_LoadFileForMe(const char *filename, int *pLength);
+extern byte *mm_LoadFileForMe(const char *filename, int *pLength);
extern void mm_FreeFile(void *buffer);
extern void mm_EndSection(const char *pszSectionName); //! trigger_endsection
@@ -206,9 +149,9 @@ extern void mm_GetGameDir(char *szGetGameDir);
extern void mm_Cvar_RegisterVariable(cvar_t *variable);
extern void mm_FadeClientVolume(const edict_t *pEdict, int fadePercent, int fadeOutSeconds, int holdTime, int fadeInSeconds);
extern void mm_SetClientMaxspeed(const edict_t *pEdict, float fNewMaxspeed);
-extern edict_t * mm_CreateFakeClient(const char *netname); //! returns NULL if fake client can't be created
-extern void mm_RunPlayerMove(edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec );
-extern int mm_NumberOfEntities(void);
+extern edict_t *mm_CreateFakeClient(const char *netname); //! returns NULL if fake client can't be created
+extern void mm_RunPlayerMove(edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec);
+extern int mm_NumberOfEntities();
extern char *mm_GetInfoKeyBuffer(edict_t *e); //! passing in NULL gets the serverinfo
extern char *mm_InfoKeyValue(char *infobuffer, const char *key);
@@ -216,253 +159,218 @@ extern void mm_SetKeyValue(char *infobuffer, const char *key, const char *value)
extern void mm_SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value);
extern int mm_IsMapValid(char *filename);
-extern void mm_StaticDecal( const float *origin, int decalIndex, int entityIndex, int modelIndex );
+extern void mm_StaticDecal(const float *origin, int decalIndex, int entityIndex, int modelIndex);
extern int mm_PrecacheGeneric(const char *s);
-extern int mm_GetPlayerUserId(edict_t *e ); //! returns the server assigned userid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
+extern int mm_GetPlayerUserId(edict_t *e); //! returns the server assigned userid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
extern void mm_BuildSoundMsg(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
-extern int mm_IsDedicatedServer(void);//! is this a dedicated server?
+extern int mm_IsDedicatedServer();//! is this a dedicated server?
extern cvar_t *mm_CVarGetPointer(const char *szVarName);
extern unsigned int mm_GetPlayerWONId(edict_t *e); //! returns the server assigned WONid for this player. useful for logging frags, etc. returns -1 if the edict couldn't be found in the list of clients
-//! YWB 8/1/99 TFF Physics additions
-extern void mm_Info_RemoveKey( char *s, const char *key );
-extern const char *mm_GetPhysicsKeyValue( const edict_t *pClient, const char *key );
-extern void mm_SetPhysicsKeyValue( const edict_t *pClient, const char *key, const char *value );
-extern const char *mm_GetPhysicsInfoString( const edict_t *pClient );
-extern unsigned short mm_PrecacheEvent( int type, const char *psz );
-extern void mm_PlaybackEvent( int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 );
+// 8/1/99 TFF Physics additions
+extern void mm_Info_RemoveKey(char *s, const char *key);
+extern const char *mm_GetPhysicsKeyValue(const edict_t *pClient, const char *key);
+extern void mm_SetPhysicsKeyValue(const edict_t *pClient, const char *key, const char *value);
+extern const char *mm_GetPhysicsInfoString(const edict_t *pClient);
+extern unsigned short mm_PrecacheEvent(int type, const char *psz);
+extern void mm_PlaybackEvent(int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2);
+extern unsigned char *mm_SetFatPVS(float *org);
+extern unsigned char *mm_SetFatPAS(float *org);
+extern int mm_CheckVisibility(edict_t *entity, unsigned char *pset);
-extern unsigned char *mm_SetFatPVS( float *org );
-extern unsigned char *mm_SetFatPAS( float *org );
+extern void mm_DeltaSetField(struct delta_s *pFields, const char *fieldname);
+extern void mm_DeltaUnsetField(struct delta_s *pFields, const char *fieldname);
+extern void mm_DeltaAddEncoder(const char *name, void (*conditionalencode)(struct delta_s *pFields, const unsigned char *from, const unsigned char *to));
+extern int mm_GetCurrentPlayer();
+extern int mm_CanSkipPlayer(const edict_t *player);
+extern int mm_DeltaFindField(struct delta_s *pFields, const char *fieldname);
+extern void mm_DeltaSetFieldByIndex(struct delta_s *pFields, int fieldNumber);
+extern void mm_DeltaUnsetFieldByIndex(struct delta_s *pFields, int fieldNumber);
+extern void mm_SetGroupMask(int mask, int op);
+extern int CreateInstancedBaseline(int classname, struct entity_state_s *baseline);
+extern void mm_Cvar_DirectSet(struct cvar_s *var, const char *value);
-extern int mm_CheckVisibility( edict_t *entity, unsigned char *pset );
+// Forces the client and server to be running with the same version of the specified file e.g., a player model).
+// Calling this has no effect in single player
+extern void mm_ForceUnmodified(FORCE_TYPE type, float *mins, float *maxs, const char *filename);
+extern void mm_GetPlayerStats(const edict_t *pClient, int *ping, int *packet_loss);
-extern void mm_DeltaSetField( struct delta_s *pFields, const char *fieldname );
-extern void mm_DeltaUnsetField( struct delta_s *pFields, const char *fieldname );
-extern void mm_DeltaAddEncoder( const char *name, void (*conditionalencode)( struct delta_s *pFields, const unsigned char *from, const unsigned char *to ) );
-extern int mm_GetCurrentPlayer( void );
-extern int mm_CanSkipPlayer( const edict_t *player );
-extern int mm_DeltaFindField( struct delta_s *pFields, const char *fieldname );
-extern void mm_DeltaSetFieldByIndex( struct delta_s *pFields, int fieldNumber );
-extern void mm_DeltaUnsetFieldByIndex( struct delta_s *pFields, int fieldNumber );
-
-extern void mm_SetGroupMask( int mask, int op );
-
-extern int CreateInstancedBaseline( int classname, struct entity_state_s *baseline );
-extern void mm_Cvar_DirectSet( struct cvar_s *var, const char *value );
-
-//! Forces the client and server to be running with the same version of the specified file
-//!( e.g., a player model ).
-//! Calling this has no effect in single player
-extern void mm_ForceUnmodified( FORCE_TYPE type, float *mins, float *maxs, const char *filename );
-
-extern void mm_GetPlayerStats( const edict_t *pClient, int *ping, int *packet_loss );
-
-extern void mm_AddServerCommand( const char *cmd_name, void (*function) (void) );
-// Added in SDK 2.2:
+extern void mm_AddServerCommand(const char *cmd_name, void (*function)());
extern qboolean mm_Voice_GetClientListening(int iReceiver, int iSender);
extern qboolean mm_Voice_SetClientListening(int iReceiver, int iSender, qboolean bListen);
-// Added for HL 1109 (no SDK update):
extern const char *mm_pfnGetPlayerAuthId(edict_t *e);
-// Added 2003-11-10 (no SDK update):
-extern sequenceEntry_s * mm_SequenceGet(const char* fileName, const char* entryName);
-extern sentenceEntry_s * mm_SequencePickSentence(const char* groupName, int pickMethod, int *picked);
+extern sequenceEntry_s *mm_SequenceGet(const char *fileName, const char *entryName);
+extern sentenceEntry_s *mm_SequencePickSentence(const char *groupName, int pickMethod, int *picked);
extern int mm_GetFileSize(const char *filename);
extern unsigned int mm_GetApproxWavePlayLen(const char *filepath);
-extern int mm_IsCareerMatch(void);
+extern int mm_IsCareerMatch();
extern int mm_GetLocalizedStringLength(const char *label);
extern void mm_RegisterTutorMessageShown(int mid);
extern int mm_GetTimesTutorMessageShown(int mid);
extern void mm_ProcessTutorMessageDecayBuffer(int *buffer, int bufferLength);
extern void mm_ConstructTutorMessageDecayBuffer(int *buffer, int bufferLength);
-extern void mm_ResetTutorMessageDecayData(void);
-//Added 2005-08-11 (no SDK update)
-extern void mm_QueryClientCvarValue(const edict_t *pEdict, const char *cvarName); //! Obsolete! Use mm_QueryClientCvarValue2 instead
-//Added 2005-11-22 (no SDK update)
+extern void mm_ResetTutorMessageDecayData();
+
+extern void mm_QueryClientCvarValue(const edict_t *pEdict, const char *cvarName); //! Obsolete! Use mm_QueryClientCvarValue2 instead
extern void mm_QueryClientCvarValue2(const edict_t *pEdict, const char *cvarName, int requestID);
-//Added 2009-06-17 (no SDK update)
extern int mm_EngCheckParm(const char *pchCmdLineToken, char **ppnext);
-
// Typedefs for the above functions:
-
-typedef int (*FN_PRECACHEMODEL) (const char* s);
-typedef int (*FN_PRECACHESOUND) (const char* s);
-typedef void (*FN_SETMODEL) (edict_t *e, const char *m);
-typedef int (*FN_MODELINDEX) (const char *m);
-typedef int (*FN_MODELFRAMES) (int modelIndex);
-typedef void (*FN_SETSIZE) (edict_t *e, const float *rgflMin, const float *rgflMax);
-typedef void (*FN_CHANGELEVEL) (const char *s1, const char *s2);
-typedef void (*FN_GETSPAWNPARMS) (edict_t *ent);
-typedef void (*FN_SAVESPAWNPARMS) (edict_t *ent);
-typedef float (*FN_VECTOYAW) (const float *rgflVector);
-typedef void (*FN_VECTOANGLES) (const float *rgflVectorIn, float *rgflVectorOut);
-typedef void (*FN_MOVETOORIGIN) (edict_t *ent, const float *pflGoal, float dist, int iMoveType);
-typedef void (*FN_CHANGEYAW) (edict_t *ent);
-typedef void (*FN_CHANGEPITCH) (edict_t *ent);
-typedef edict_t * (*FN_FINDENTITYBYSTRING) (edict_t *pEdictStartSearchAfter, const char *pszField, const char *pszValue);
-typedef int (*FN_GETENTITYILLUM) (edict_t *pEnt);
-typedef edict_t * (*FN_FINDENTITYINSPHERE) (edict_t *pEdictStartSearchAfter, const float *org, float rad);
-typedef edict_t * (*FN_FINDCLIENTINPVS) (edict_t *pEdict);
-typedef edict_t * (*FN_ENTITIESINPVS) (edict_t *pplayer);
-typedef void (*FN_MAKEVECTORS) (const float *rgflVector);
-typedef void (*FN_ANGLEVECTORS) (const float *rgflVector, float *forward, float *right, float *up);
-typedef edict_t * (*FN_CREATEENTITY) (void);
-typedef void (*FN_REMOVEENTITY) (edict_t *e);
-typedef edict_t * (*FN_CREATENAMEDENTITY) (int className);
-typedef void (*FN_MAKESTATIC) (edict_t *ent);
-typedef int (*FN_ENTISONFLOOR) (edict_t *e);
-typedef int (*FN_DROPTOFLOOR) (edict_t *e);
-typedef int (*FN_WALKMOVE) (edict_t *ent, float yaw, float dist, int iMode);
-typedef void (*FN_SETORIGIN) (edict_t *e, const float *rgflOrigin);
-typedef void (*FN_EMITSOUND) (edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch);
-typedef void (*FN_EMITAMBIENTSOUND) (edict_t *entity, float *pos, const char *samp, float vol, float attenuation, int fFlags, int pitch);
-typedef void (*FN_TRACELINE) (const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr);
-typedef void (*FN_TRACETOSS) (edict_t *pent, edict_t *pentToIgnore, TraceResult *ptr);
-typedef int (*FN_TRACEMONSTERHULL) (edict_t *pEdict, const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr);
-typedef void (*FN_TRACEHULL) (const float *v1, const float *v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult *ptr);
-typedef void (*FN_TRACEMODEL) (const float *v1, const float *v2, int hullNumber, edict_t *pent, TraceResult *ptr);
-typedef const char * (*FN_TRACETEXTURE) (edict_t *pTextureEntity, const float *v1, const float *v2 );
-typedef void (*FN_TRACESPHERE) (const float *v1, const float *v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult *ptr);
-typedef void (*FN_GETAIMVECTOR) (edict_t *ent, float speed, float *rgflReturn);
-typedef void (*FN_SERVERCOMMAND) (char *str);
-typedef void (*FN_SERVEREXECUTE) (void);
-typedef void (*FN_CLIENTCOMMAND_ENG) (edict_t *pEdict, char *szFmt, ...);
-typedef void (*FN_PARTICLEEFFECT) (const float *org, const float *dir, float color, float count);
-typedef void (*FN_LIGHTSTYLE) (int style, char *val);
-typedef int (*FN_DECALINDEX) (const char *name);
-typedef int (*FN_POINTCONTENTS) (const float *rgflVector);
-typedef void (*FN_MESSAGEBEGIN) (int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
-typedef void (*FN_MESSAGEEND) (void);
-typedef void (*FN_WRITEBYTE) (int iValue);
-typedef void (*FN_WRITECHAR) (int iValue);
-typedef void (*FN_WRITESHORT) (int iValue);
-typedef void (*FN_WRITELONG) (int iValue);
-typedef void (*FN_WRITEANGLE) (float flValue);
-typedef void (*FN_WRITECOORD) (float flValue);
-typedef void (*FN_WRITESTRING) (const char *sz);
-typedef void (*FN_WRITEENTITY) (int iValue);
-typedef void (*FN_CVARREGISTER) (cvar_t *pCvar);
-typedef float (*FN_CVARGETFLOAT) (const char *szVarName);
-typedef const char * (*FN_CVARGETSTRING) (const char *szVarName);
-typedef void (*FN_CVARSETFLOAT) (const char *szVarName, float flValue);
-typedef void (*FN_CVARSETSTRING) (const char *szVarName, const char *szValue);
-typedef void (*FN_ALERTMESSAGE) (ALERT_TYPE atype, const char *szFmt, ...);
-#ifdef HLSDK_3_2_OLD_EIFACE
-typedef void (*FN_ENGINEFPRINTF) (FILE *pfile, const char *szFmt, ...);
-typedef void * (*FN_PVALLOCENTPRIVATEDATA) (edict_t *pEdict, long cb);
-#else
-typedef void (*FN_ENGINEFPRINTF) (void *pfile, const char *szFmt, ...);
-typedef void * (*FN_PVALLOCENTPRIVATEDATA) (edict_t *pEdict, int32 cb);
-#endif
-typedef void * (*FN_PVENTPRIVATEDATA) (edict_t *pEdict);
-typedef void (*FN_FREEENTPRIVATEDATA) (edict_t *pEdict);
-typedef const char * (*FN_SZFROMINDEX) (int iString);
-typedef int (*FN_ALLOCSTRING) (const char *szValue);
-typedef struct entvars_s * (*FN_GETVARSOFENT) (edict_t *pEdict);
-typedef edict_t * (*FN_PENTITYOFENTOFFSET) (int iEntOffset);
-typedef int (*FN_ENTOFFSETOFPENTITY) (const edict_t *pEdict);
-typedef int (*FN_INDEXOFEDICT) (const edict_t *pEdict);
-typedef edict_t * (*FN_PENTITYOFENTINDEX) (int iEntIndex);
-typedef edict_t * (*FN_FINDENTITYBYVARS) (struct entvars_s *pvars);
-typedef void * (*FN_GETMODELPTR) (edict_t *pEdict);
-typedef int (*FN_REGUSERMSG) (const char *pszName, int iSize);
-typedef void (*FN_ANIMATIONAUTOMOVE) (const edict_t *pEdict, float flTime);
-typedef void (*FN_GETBONEPOSITION) (const edict_t *pEdict, int iBone, float *rgflOrigin, float *rgflAngles );
-#ifdef HLSDK_3_2_OLD_EIFACE
-typedef unsigned long (*FN_FUNCTIONFROMNAME) ( const char *pName );
-typedef const char * (*FN_NAMEFORFUNCTION) ( unsigned long function );
-#else
-typedef uint32 (*FN_FUNCTIONFROMNAME) ( const char *pName );
-typedef const char * (*FN_NAMEFORFUNCTION) ( uint32 function );
-#endif
-typedef void (*FN_CLIENTPRINTF) ( edict_t *pEdict, PRINT_TYPE ptype, const char *szMsg );
-typedef void (*FN_SERVERPRINT) ( const char *szMsg );
-typedef const char * (*FN_CMD_ARGS) ( void );
-typedef const char * (*FN_CMD_ARGV) ( int argc );
-typedef int (*FN_CMD_ARGC) ( void );
-typedef void (*FN_GETATTACHMENT) (const edict_t *pEdict, int iAttachment, float *rgflOrigin, float *rgflAngles );
-typedef void (*FN_CRC32_INIT) (CRC32_t *pulCRC);
-typedef void (*FN_CRC32_PROCESSBUFFER) (CRC32_t *pulCRC, void *p, int len);
-typedef void (*FN_CRC32_PROCESSBYTE) (CRC32_t *pulCRC, unsigned char ch);
-typedef CRC32_t (*FN_CRC32_FINAL) (CRC32_t pulCRC);
-#ifdef HLSDK_3_2_OLD_EIFACE
-typedef long (*FN_RANDOMLONG) (long lLow, long lHigh);
-#else
-typedef int32 (*FN_RANDOMLONG) (int32 lLow, int32 lHigh);
-#endif
-typedef float (*FN_RANDOMFLOAT) (float flLow, float flHigh);
-typedef void (*FN_SETVIEW) (const edict_t *pClient, const edict_t *pViewent );
-typedef float (*FN_TIME) ( void );
-typedef void (*FN_CROSSHAIRANGLE) (const edict_t *pClient, float pitch, float yaw);
-typedef byte * (*FN_LOADFILEFORME) (char *filename, int *pLength);
-typedef void (*FN_FREEFILE) (void *buffer);
-typedef void (*FN_ENDSECTION) (const char *pszSectionName);
-typedef int (*FN_COMPAREFILETIME) (char *filename1, char *filename2, int *iCompare);
-typedef void (*FN_GETGAMEDIR) (char *szGetGameDir);
-typedef void (*FN_CVAR_REGISTERVARIABLE) (cvar_t *variable);
-typedef void (*FN_FADECLIENTVOLUME) (const edict_t *pEdict, int fadePercent, int fadeOutSeconds, int holdTime, int fadeInSeconds);
-typedef void (*FN_SETCLIENTMAXSPEED) (edict_t *pEdict, float fNewMaxspeed);
-typedef edict_t * (*FN_CREATEFAKECLIENT) (const char *netname);
-typedef void (*FN_RUNPLAYERMOVE) (edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec );
-typedef int (*FN_NUMBEROFENTITIES) (void);
-typedef char * (*FN_GETINFOKEYBUFFER) (edict_t *e);
-typedef char * (*FN_INFOKEYVALUE) (char *infobuffer, const char *key);
-typedef void (*FN_SETKEYVALUE) (char *infobuffer, const char *key, const char *value);
-typedef void (*FN_SETCLIENTKEYVALUE) (int clientIndex, char *infobuffer, const char *key, const char *value);
-typedef int (*FN_ISMAPVALID) (char *filename);
-typedef void (*FN_STATICDECAL) ( const float *origin, int decalIndex, int entityIndex, int modelIndex );
-typedef int (*FN_PRECACHEGENERIC) (char *s);
-typedef int (*FN_GETPLAYERUSERID) (edict_t *e );
-typedef void (*FN_BUILDSOUNDMSG) (edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
-typedef int (*FN_ISDEDICATEDSERVER) (void);
-typedef cvar_t * (*FN_CVARGETPOINTER) (const char *szVarName);
-typedef unsigned int (*FN_GETPLAYERWONID) (edict_t *e);
-typedef void (*FN_INFO_REMOVEKEY) ( char *s, const char *key );
-typedef const char * (*FN_GETPHYSICSKEYVALUE) ( const edict_t *pClient, const char *key );
-typedef void (*FN_SETPHYSICSKEYVALUE) ( const edict_t *pClient, const char *key, const char *value );
-typedef const char * (*FN_GETPHYSICSINFOSTRING) ( const edict_t *pClient );
-typedef unsigned short (*FN_PRECACHEEVENT) ( int type, const char *psz );
-typedef void (*FN_PLAYBACKEVENT) ( int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 );
-typedef unsigned char * (*FN_SETFATPVS) ( float *org );
-typedef unsigned char * (*FN_SETFATPAS) ( float *org );
-typedef int (*FN_CHECKVISIBILITY) ( edict_t *entity, unsigned char *pset );
-typedef void (*FN_DELTASETFIELD) ( struct delta_s *pFields, const char *fieldname );
-typedef void (*FN_DELTAUNSETFIELD) ( struct delta_s *pFields, const char *fieldname );
-typedef void (*FN_DELTAADDENCODER) ( char *name, void (*conditionalencode)( struct delta_s *pFields, const unsigned char *from, const unsigned char *to ) );
-typedef int (*FN_GETCURRENTPLAYER) ( void );
-typedef int (*FN_CANSKIPPLAYER) ( const edict_t *player );
-typedef int (*FN_DELTAFINDFIELD) ( struct delta_s *pFields, const char *fieldname );
-typedef void (*FN_DELTASETFIELDBYINDEX) ( struct delta_s *pFields, int fieldNumber );
-typedef void (*FN_DELTAUNSETFIELDBYINDEX) ( struct delta_s *pFields, int fieldNumber );
-typedef void (*FN_SETGROUPMASK) ( int mask, int op );
-typedef int (*FN_CREATEINSTANCEDBASELINE) ( int classname, struct entity_state_s *baseline );
-typedef void (*FN_CVAR_DIRECTSET) ( struct cvar_s *var, const char *value );
-typedef void (*FN_FORCEUNMODIFIED) ( FORCE_TYPE type, float *mins, float *maxs, const char *filename );
-typedef void (*FN_GETPLAYERSTATS) ( const edict_t *pClient, int *ping, int *packet_loss );
-typedef void (*FN_ADDSERVERCOMMAND) ( char *cmd_name, void (*function) (void) );
-// Added in SDK 2.2:
-typedef qboolean (*FN_VOICE_GETCLIENTLISTENING) (int iReceiver, int iSender);
-typedef qboolean (*FN_VOICE_SETCLIENTLISTENING) (int iReceiver, int iSender, qboolean bListen);
-// Added for HL 1109 (no SDK update):
-typedef const char * (*FN_GETPLAYERAUTHID) (edict_t *e);
-// Added 2003-11-10 (no SDK update):
-typedef sequenceEntry_s * (*FN_SEQUENCEGET) (const char* fileName, const char* entryName);
-typedef sentenceEntry_s * (*FN_SEQUENCEPICKSENTENCE) (const char* groupName, int pickMethod, int *picked);
-typedef int (*FN_GETFILESIZE) (char *filename);
-typedef unsigned int (*FN_GETAPPROXWAVEPLAYLEN) (const char *filepath);
-typedef int (*FN_ISCAREERMATCH) (void);
-typedef int (*FN_GETLOCALIZEDSTRINGLENGTH) (const char *label);
-typedef void (*FN_REGISTERTUTORMESSAGESHOWN) (int mid);
-typedef int (*FN_GETTIMESTUTORMESSAGESHOWN) (int mid);
-typedef void (*FN_PROCESSTUTORMESSAGEDECAYBUFFER) (int *buffer, int bufferLength);
-typedef void (*FN_CONSTRUCTTUTORMESSAGEDECAYBUFFER) (int *buffer, int bufferLength);
-typedef void (*FN_RESETTUTORMESSAGEDECAYDATA) (void);
-//Added 2005-08-11 (no SDK update)
-typedef void (*FN_QUERYCLIENTCVARVALUE)(const edict_t *pEdict, const char *cvarName); //! Obsolete! Use FN_QUERYCLIENTCVARVALUE2 instead
-//Added 2005-11-22 (no SDK update)
+typedef int (*FN_PRECACHEMODEL)(const char *s);
+typedef int (*FN_PRECACHESOUND)(const char *s);
+typedef void (*FN_SETMODEL)(edict_t *e, const char *m);
+typedef int (*FN_MODELINDEX)(const char *m);
+typedef int (*FN_MODELFRAMES)(int modelIndex);
+typedef void (*FN_SETSIZE)(edict_t *e, const float *rgflMin, const float *rgflMax);
+typedef void (*FN_CHANGELEVEL)(const char *s1, const char *s2);
+typedef void (*FN_GETSPAWNPARMS)(edict_t *ent);
+typedef void (*FN_SAVESPAWNPARMS)(edict_t *ent);
+typedef float (*FN_VECTOYAW)(const float *rgflVector);
+typedef void (*FN_VECTOANGLES)(const float *rgflVectorIn, float *rgflVectorOut);
+typedef void (*FN_MOVETOORIGIN)(edict_t *ent, const float *pflGoal, float dist, int iMoveType);
+typedef void (*FN_CHANGEYAW)(edict_t *ent);
+typedef void (*FN_CHANGEPITCH)(edict_t *ent);
+typedef edict_t *(*FN_FINDENTITYBYSTRING)(edict_t *pEdictStartSearchAfter, const char *pszField, const char *pszValue);
+typedef int (*FN_GETENTITYILLUM)(edict_t *pEnt);
+typedef edict_t *(*FN_FINDENTITYINSPHERE)(edict_t *pEdictStartSearchAfter, const float *org, float rad);
+typedef edict_t *(*FN_FINDCLIENTINPVS)(edict_t *pEdict);
+typedef edict_t *(*FN_ENTITIESINPVS)(edict_t *pplayer);
+typedef void (*FN_MAKEVECTORS)(const float *rgflVector);
+typedef void (*FN_ANGLEVECTORS)(const float *rgflVector, float *forward, float *right, float *up);
+typedef edict_t *(*FN_CREATEENTITY)();
+typedef void (*FN_REMOVEENTITY)(edict_t *e);
+typedef edict_t *(*FN_CREATENAMEDENTITY)(int className);
+typedef void (*FN_MAKESTATIC)(edict_t *ent);
+typedef int (*FN_ENTISONFLOOR)(edict_t *e);
+typedef int (*FN_DROPTOFLOOR)(edict_t *e);
+typedef int (*FN_WALKMOVE)(edict_t *ent, float yaw, float dist, int iMode);
+typedef void (*FN_SETORIGIN)(edict_t *e, const float *rgflOrigin);
+typedef void (*FN_EMITSOUND)(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch);
+typedef void (*FN_EMITAMBIENTSOUND)(edict_t *entity, float *pos, const char *samp, float vol, float attenuation, int fFlags, int pitch);
+typedef void (*FN_TRACELINE)(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr);
+typedef void (*FN_TRACETOSS)(edict_t *pent, edict_t *pentToIgnore, TraceResult *ptr);
+typedef int (*FN_TRACEMONSTERHULL)(edict_t *pEdict, const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr);
+typedef void (*FN_TRACEHULL)(const float *v1, const float *v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult *ptr);
+typedef void (*FN_TRACEMODEL)(const float *v1, const float *v2, int hullNumber, edict_t *pent, TraceResult *ptr);
+typedef const char *(*FN_TRACETEXTURE)(edict_t *pTextureEntity, const float *v1, const float *v2);
+typedef void (*FN_TRACESPHERE)(const float *v1, const float *v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult *ptr);
+typedef void (*FN_GETAIMVECTOR)(edict_t *ent, float speed, float *rgflReturn);
+typedef void (*FN_SERVERCOMMAND)(char *str);
+typedef void (*FN_SERVEREXECUTE)();
+typedef void (*FN_CLIENTCOMMAND_ENG)(edict_t *pEdict, char *szFmt, ...);
+typedef void (*FN_PARTICLEEFFECT)(const float *org, const float *dir, float color, float count);
+typedef void (*FN_LIGHTSTYLE)(int style, char *val);
+typedef int (*FN_DECALINDEX)(const char *name);
+typedef int (*FN_POINTCONTENTS)(const float *rgflVector);
+typedef void (*FN_MESSAGEBEGIN)(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
+typedef void (*FN_MESSAGEEND)();
+typedef void (*FN_WRITEBYTE)(int iValue);
+typedef void (*FN_WRITECHAR)(int iValue);
+typedef void (*FN_WRITESHORT)(int iValue);
+typedef void (*FN_WRITELONG)(int iValue);
+typedef void (*FN_WRITEANGLE)(float flValue);
+typedef void (*FN_WRITECOORD)(float flValue);
+typedef void (*FN_WRITESTRING)(const char *sz);
+typedef void (*FN_WRITEENTITY)(int iValue);
+typedef void (*FN_CVARREGISTER)(cvar_t *pCvar);
+typedef float (*FN_CVARGETFLOAT)(const char *szVarName);
+typedef const char *(*FN_CVARGETSTRING)(const char *szVarName);
+typedef void (*FN_CVARSETFLOAT)(const char *szVarName, float flValue);
+typedef void (*FN_CVARSETSTRING)(const char *szVarName, const char *szValue);
+typedef void (*FN_ALERTMESSAGE)(ALERT_TYPE atype, const char *szFmt, ...);
+typedef void (*FN_ENGINEFPRINTF)(void *pfile, const char *szFmt, ...);
+typedef void *(*FN_PVALLOCENTPRIVATEDATA)(edict_t *pEdict, int32 cb);
+typedef void *(*FN_PVENTPRIVATEDATA)(edict_t *pEdict);
+typedef void (*FN_FREEENTPRIVATEDATA)(edict_t *pEdict);
+typedef const char *(*FN_SZFROMINDEX)(int iString);
+typedef int (*FN_ALLOCSTRING)(const char *szValue);
+typedef struct entvars_s *(*FN_GETVARSOFENT)(edict_t *pEdict);
+typedef edict_t *(*FN_PENTITYOFENTOFFSET)(int iEntOffset);
+typedef int (*FN_ENTOFFSETOFPENTITY)(const edict_t *pEdict);
+typedef int (*FN_INDEXOFEDICT)(const edict_t *pEdict);
+typedef edict_t *(*FN_PENTITYOFENTINDEX)(int iEntIndex);
+typedef edict_t *(*FN_FINDENTITYBYVARS)(struct entvars_s *pvars);
+typedef void *(*FN_GETMODELPTR)(edict_t *pEdict);
+typedef int (*FN_REGUSERMSG)(const char *pszName, int iSize);
+typedef void (*FN_ANIMATIONAUTOMOVE)(const edict_t *pEdict, float flTime);
+typedef void (*FN_GETBONEPOSITION)(const edict_t *pEdict, int iBone, float *rgflOrigin, float *rgflAngles);
+typedef uint32 (*FN_FUNCTIONFROMNAME)(const char *pName);
+typedef const char *(*FN_NAMEFORFUNCTION)(uint32 function);
+typedef void (*FN_CLIENTPRINTF)(edict_t *pEdict, PRINT_TYPE ptype, const char *szMsg);
+typedef void (*FN_SERVERPRINT)(const char *szMsg);
+typedef const char *(*FN_CMD_ARGS)();
+typedef const char *(*FN_CMD_ARGV)(int argc);
+typedef int (*FN_CMD_ARGC)();
+typedef void (*FN_GETATTACHMENT)(const edict_t *pEdict, int iAttachment, float *rgflOrigin, float *rgflAngles);
+typedef void (*FN_CRC32_INIT)(CRC32_t *pulCRC);
+typedef void (*FN_CRC32_PROCESSBUFFER)(CRC32_t *pulCRC, void *p, int len);
+typedef void (*FN_CRC32_PROCESSBYTE)(CRC32_t *pulCRC, unsigned char ch);
+typedef CRC32_t (*FN_CRC32_FINAL)(CRC32_t pulCRC);
+typedef int32 (*FN_RANDOMLONG)(int32 lLow, int32 lHigh);
+typedef float (*FN_RANDOMFLOAT)(float flLow, float flHigh);
+typedef void (*FN_SETVIEW)(const edict_t *pClient, const edict_t *pViewent);
+typedef float (*FN_TIME)();
+typedef void (*FN_CROSSHAIRANGLE)(const edict_t *pClient, float pitch, float yaw);
+typedef byte *(*FN_LOADFILEFORME)(char *filename, int *pLength);
+typedef void (*FN_FREEFILE)(void *buffer);
+typedef void (*FN_ENDSECTION)(const char *pszSectionName);
+typedef int (*FN_COMPAREFILETIME)(char *filename1, char *filename2, int *iCompare);
+typedef void (*FN_GETGAMEDIR)(char *szGetGameDir);
+typedef void (*FN_CVAR_REGISTERVARIABLE)(cvar_t *variable);
+typedef void (*FN_FADECLIENTVOLUME)(const edict_t *pEdict, int fadePercent, int fadeOutSeconds, int holdTime, int fadeInSeconds);
+typedef void (*FN_SETCLIENTMAXSPEED)(edict_t *pEdict, float fNewMaxspeed);
+typedef edict_t *(*FN_CREATEFAKECLIENT)(const char *netname);
+typedef void (*FN_RUNPLAYERMOVE)(edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec);
+typedef int (*FN_NUMBEROFENTITIES)();
+typedef char *(*FN_GETINFOKEYBUFFER)(edict_t *e);
+typedef char *(*FN_INFOKEYVALUE)(char *infobuffer, const char *key);
+typedef void (*FN_SETKEYVALUE)(char *infobuffer, const char *key, const char *value);
+typedef void (*FN_SETCLIENTKEYVALUE)(int clientIndex, char *infobuffer, const char *key, const char *value);
+typedef int (*FN_ISMAPVALID)(char *filename);
+typedef void (*FN_STATICDECAL)(const float *origin, int decalIndex, int entityIndex, int modelIndex);
+typedef int (*FN_PRECACHEGENERIC)(char *s);
+typedef int (*FN_GETPLAYERUSERID)(edict_t *e);
+typedef void (*FN_BUILDSOUNDMSG)(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);
+typedef int (*FN_ISDEDICATEDSERVER)();
+typedef cvar_t *(*FN_CVARGETPOINTER)(const char *szVarName);
+typedef unsigned int (*FN_GETPLAYERWONID)(edict_t *e);
+typedef void (*FN_INFO_REMOVEKEY)(char *s, const char *key);
+typedef const char *(*FN_GETPHYSICSKEYVALUE)(const edict_t *pClient, const char *key);
+typedef void (*FN_SETPHYSICSKEYVALUE)(const edict_t *pClient, const char *key, const char *value);
+typedef const char *(*FN_GETPHYSICSINFOSTRING)(const edict_t *pClient);
+typedef unsigned short (*FN_PRECACHEEVENT)(int type, const char *psz);
+typedef void (*FN_PLAYBACKEVENT)(int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2);
+typedef unsigned char *(*FN_SETFATPVS)(float *org);
+typedef unsigned char *(*FN_SETFATPAS)(float *org);
+typedef int (*FN_CHECKVISIBILITY)(edict_t *entity, unsigned char *pset);
+typedef void (*FN_DELTASETFIELD)(struct delta_s *pFields, const char *fieldname);
+typedef void (*FN_DELTAUNSETFIELD)(struct delta_s *pFields, const char *fieldname);
+typedef void (*FN_DELTAADDENCODER)(char *name, void (*conditionalencode)(struct delta_s *pFields, const unsigned char *from, const unsigned char *to));
+typedef int (*FN_GETCURRENTPLAYER)();
+typedef int (*FN_CANSKIPPLAYER)(const edict_t *player);
+typedef int (*FN_DELTAFINDFIELD)(struct delta_s *pFields, const char *fieldname);
+typedef void (*FN_DELTASETFIELDBYINDEX)(struct delta_s *pFields, int fieldNumber);
+typedef void (*FN_DELTAUNSETFIELDBYINDEX)(struct delta_s *pFields, int fieldNumber);
+typedef void (*FN_SETGROUPMASK)(int mask, int op);
+typedef int (*FN_CREATEINSTANCEDBASELINE)(int classname, struct entity_state_s *baseline);
+typedef void (*FN_CVAR_DIRECTSET)(struct cvar_s *var, const char *value);
+typedef void (*FN_FORCEUNMODIFIED)(FORCE_TYPE type, float *mins, float *maxs, const char *filename);
+typedef void (*FN_GETPLAYERSTATS)(const edict_t *pClient, int *ping, int *packet_loss);
+typedef void (*FN_ADDSERVERCOMMAND)(char *cmd_name, void (*function)());
+typedef qboolean (*FN_VOICE_GETCLIENTLISTENING)(int iReceiver, int iSender);
+typedef qboolean (*FN_VOICE_SETCLIENTLISTENING)(int iReceiver, int iSender, qboolean bListen);
+typedef const char *(*FN_GETPLAYERAUTHID)(edict_t *e);
+typedef sequenceEntry_s *(*FN_SEQUENCEGET)(const char *fileName, const char *entryName);
+typedef sentenceEntry_s *(*FN_SEQUENCEPICKSENTENCE)(const char *groupName, int pickMethod, int *picked);
+typedef int (*FN_GETFILESIZE)(char *filename);
+typedef unsigned int (*FN_GETAPPROXWAVEPLAYLEN)(const char *filepath);
+typedef int (*FN_ISCAREERMATCH)();
+typedef int (*FN_GETLOCALIZEDSTRINGLENGTH)(const char *label);
+typedef void (*FN_REGISTERTUTORMESSAGESHOWN)(int mid);
+typedef int (*FN_GETTIMESTUTORMESSAGESHOWN)(int mid);
+typedef void (*FN_PROCESSTUTORMESSAGEDECAYBUFFER)(int *buffer, int bufferLength);
+typedef void (*FN_CONSTRUCTTUTORMESSAGEDECAYBUFFER)(int *buffer, int bufferLength);
+typedef void (*FN_RESETTUTORMESSAGEDECAYDATA)();
+typedef void (*FN_QUERYCLIENTCVARVALUE)(const edict_t *pEdict, const char *cvarName); // Use FN_QUERYCLIENTCVARVALUE2 instead
typedef void (*FN_QUERYCLIENTCVARVALUE2)(const edict_t *pEdict, const char *cvarName, int requestID);
-//Added 2009-06-17 (no SDK update)
typedef int (*FN_CHECKPARM)(const char *pchCmdLineToken, char **ppnext);
-
-#endif /* ENGINE_API_H */
diff --git a/metamod/src/engine_t.h b/metamod/src/engine_t.h
index 235fa1e..ae00c90 100644
--- a/metamod/src/engine_t.h
+++ b/metamod/src/engine_t.h
@@ -1,54 +1,15 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// engine_t.h - The engine_t type
-
-/*
- * Copyright (c) 2001-2006 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef MM_ENGINE_T_H
-#define MM_ENGINE_T_H
+#pragma once
#include "eiface.h" // engfuncs_t, globalvars_t
// Our structure for storing engine references.
-struct engine_t {
- engine_t() : funcs(NULL), globals(NULL), pl_funcs(NULL) {}
+struct engine_t
+{
+ engine_t() : funcs(nullptr), globals(nullptr), pl_funcs(nullptr) {}
- enginefuncs_t *funcs; // engine funcs
- globalvars_t *globals; // engine globals
- enginefuncs_t *pl_funcs; // "modified" eng funcs we give to plugins
+ enginefuncs_t *funcs; // engine funcs
+ globalvars_t *globals; // engine globals
+ enginefuncs_t *pl_funcs; // "modified" eng funcs we give to plugins
};
extern engine_t g_engine;
-
-#endif /* MM_ENGINE_T_H */
-
diff --git a/metamod/src/enginecallbacks.h b/metamod/src/enginecallbacks.h
index 5eb38bd..e45aa71 100644
--- a/metamod/src/enginecallbacks.h
+++ b/metamod/src/enginecallbacks.h
@@ -1,41 +1,4 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// enginecallbacks.h - wrapper for
-
-/*
- * Copyright (c) 2001-2006 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef MM_ENGINECALLBACKS_H
-#define MM_ENGINECALLBACKS_H
+#pragma once
// This file is a wrapper around the SDK's enginecallback.h file. We need
// this because we use a different type for the global object g_engfuncs,
@@ -44,35 +7,30 @@
// This is only done for files that belong to Metamod, not other projects
// like plugins that use this file, or others that include it, too.
// Since we don't have a clean seperation of include files right now we
-// "hack" our way around that by using a flag METAMOD_CORE which is set
+// "hack" our way around that by using a flag METAMOD_CORE which is set
// when compiling Metamod proper.
#ifdef METAMOD_CORE
-# include "meta_eiface.h" // HL_enginefuncs_t
+ #include "meta_eiface.h" // HL_enginefuncs_t
-// Use a #define to bend the enginefuncs_t type to our HL_enginefuncs_t
-// type instead as we now use that for the global object g_engfuncs.
-# define enginefuncs_t HL_enginefuncs_t
-#endif /* METAMOD_CORE */
+ // Use a #define to bend the enginefuncs_t type to our HL_enginefuncs_t
+ // type instead as we now use that for the global object g_engfuncs.
+ #define enginefuncs_t HL_enginefuncs_t
+#endif
#include // ALERT, etc
#ifdef METAMOD_CORE
-# undef enginefuncs_t
-#endif /* METAMOD_CORE */
+#undef enginefuncs_t
+#endif
// Also, create some additional macros for engine callback functions, which
// weren't in SDK dlls/enginecallbacks.h but probably should have been.
-
-#define GET_INFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
-#define INFOKEY_VALUE (*g_engfuncs.pfnInfoKeyValue)
-#define SET_CLIENT_KEYVALUE (*g_engfuncs.pfnSetClientKeyValue)
-#define REG_SVR_COMMAND (*g_engfuncs.pfnAddServerCommand)
-#define SERVER_PRINT (*g_engfuncs.pfnServerPrint)
-#define SET_SERVER_KEYVALUE (*g_engfuncs.pfnSetKeyValue)
-#define QUERY_CLIENT_CVAR_VALUE (*g_engfuncs.pfnQueryClientCvarValue)
+#define GET_INFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
+#define INFOKEY_VALUE (*g_engfuncs.pfnInfoKeyValue)
+#define SET_CLIENT_KEYVALUE (*g_engfuncs.pfnSetClientKeyValue)
+#define REG_SVR_COMMAND (*g_engfuncs.pfnAddServerCommand)
+#define SERVER_PRINT (*g_engfuncs.pfnServerPrint)
+#define SET_SERVER_KEYVALUE (*g_engfuncs.pfnSetKeyValue)
+#define QUERY_CLIENT_CVAR_VALUE (*g_engfuncs.pfnQueryClientCvarValue)
#define QUERY_CLIENT_CVAR_VALUE2 (*g_engfuncs.pfnQueryClientCvarValue2)
-
-
-#endif /* MM_ENGINECALLBACKS_H */
-
diff --git a/metamod/src/game_support.cpp b/metamod/src/game_support.cpp
index 9eb5053..86ef3bb 100644
--- a/metamod/src/game_support.cpp
+++ b/metamod/src/game_support.cpp
@@ -1,109 +1,81 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// game_support.cpp - info to recognize different HL mod "games"
-
-/*
- * Copyright (c) 2001-2013 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// Adapted from adminmod h_export.cpp:
//! this structure contains a list of supported mods and their dlls names
-//! To add support for another mod add an entry here, and add all the
+//! To add support for another mod add an entry here, and add all the
//! exported entities to link_func.cpp
-game_modlist_t known_games = {
- // name/gamedir linux_so win_dll osx_dylib desc
+const game_modinfo_t known_games[] = {
+ // name/gamedir linux_so win_dll desc
//
// Previously enumerated in this sourcefile, the list is now kept in a
- // separate file, generated based on game information stored in a
+ // separate file, generated based on game information stored in a
// convenient db.
- //
-#include "games.h"
-
+ { "cstrike", "cs.so", "mp.dll", "Counter-Strike" },
+ { "czero", "cs.so", "mp.dll", "Counter-Strike:Condition Zero" },
// End of list terminator:
- {NULL, NULL, NULL, NULL, NULL}
+ { NULL, NULL, NULL, NULL }
};
// Find a modinfo corresponding to the given game name.
-game_modinfo_t* lookup_game(const char* name)
+inline const game_modinfo_t *lookup_game(const char *name)
{
- for (int i = 0; known_games[i].name; i++) {
- auto imod = &known_games[i];
- if (strcasematch(imod->name, name))
- return imod;
+ for (auto& known : known_games)
+ {
+ if (known.name && Q_stricmp(known.name, name))
+ return &known;
}
+
// no match found
- return NULL;
+ return nullptr;
}
-mBOOL install_gamedll(char* from, const char* to)
+// Installs gamedll from Steam cache
+mBOOL install_gamedll(char *from, const char *to)
{
int length_in;
int length_out;
- if (NULL == from) return mFALSE;
- if (NULL == to) to = from;
+ if (!from)
+ return mFALSE;
- byte* cachefile = LOAD_FILE_FOR_ME(from, &length_in);
+ if (!to)
+ to = from;
+
+ byte *cachefile = LOAD_FILE_FOR_ME(from, &length_in);
// If the file seems to exist in the cache.
- if (NULL != cachefile) {
-
+ if (cachefile)
+ {
int fd = open(to, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
- if (fd < 0) {
- META_DEBUG(3, ("Installing gamedll from cache: Failed to create file %s: %s\n", to, strerror(errno)) );
+ if (fd < 0)
+ {
+ META_DEBUG(3, ("Installing gamedll from cache: Failed to create file %s: %s", to, strerror(errno)) );
FREE_FILE(cachefile);
return mFALSE;
}
- length_out = write(fd, cachefile, length_in);
+ length_out = Q_write(fd, cachefile, length_in);
FREE_FILE(cachefile);
close(fd);
// Writing the file was not successfull
- if (length_out != length_in) {
- META_DEBUG(3,("Installing gamedll from cache: Failed to write all %d bytes to file, only %d written: %s\n",
- length_in, length_out, strerror(errno)) );
+ if (length_out != length_in)
+ {
+ META_DEBUG(3, ("Installing gamedll from chache: Failed to write all %d bytes to file, only %d written: %s", length_in, length_out, strerror(errno)));
+
// Let's not leave a mess but clean up nicely.
- if (length_out >= 0) _unlink(to);
+ if (length_out >= 0)
+ _unlink(to);
+
return mFALSE;
}
- META_LOG("Installed gamedll %s from cache.\n", to);
-
+ META_LOG("Installed gamedll %s from cache.", to);
}
- else {
- META_DEBUG(3, ("Failed to install gamedll from cache: file %s not found in cache.\n", from) );
+ else
+ {
+ META_DEBUG(3, ("Failed to install gamedll from cache: file %s not found in cache.", from));
return mFALSE;
}
@@ -111,167 +83,63 @@ mBOOL install_gamedll(char* from, const char* to)
}
// Set all the fields in the gamedll struct, - based either on an entry in
-// known_games matching the current gamedir, or on one specified manually
+// known_games matching the current gamedir, or on one specified manually
// by the server admin.
//
// meta_errno values:
// - ME_NOTFOUND couldn't recognize game
-mBOOL setup_gamedll(gamedll_t* gamedll)
+mBOOL setup_gamedll(gamedll_t *gamedll)
{
- static char override_desc_buf[256];
- game_modinfo_t* known;
- const char* cp;
- const char* knownfn = 0;
- const char* usedfn = 0;
- char* strippedfn = 0;
- bool override = false;
+ const game_modinfo_t *known;
+ const char *knownfn = nullptr;
// Check for old-style "metagame.ini" file and complain.
if (valid_gamedir_file(OLD_GAMEDLL_TXT))
- META_ERROR("File '%s' is no longer supported; instead, specify override gamedll in %s or with '+localinfo mm_gamedll '", OLD_GAMEDLL_TXT, CONFIG_INI);
+ {
+ META_WARNING("File '%s' is no longer supported; instead, specify override gamedll in %s or with '+localinfo mm_gamedll '", OLD_GAMEDLL_TXT, CONFIG_INI);
+ }
// First, look for a known game, based on gamedir.
- if ((known = lookup_game(gamedll->name))) {
+ if ((known = lookup_game(gamedll->name)))
+ {
#ifdef _WIN32
- knownfn = _strdup(known->win_dll);
-#elif defined(linux)
- knownfn=_strdup(known->linux_so);
-#elif defined(__APPLE__)
- knownfn=_strdup(known->osx_dylib);
+ knownfn = known->win_dll;
#else
-#error "OS unrecognized"
-#endif /* _WIN32 */
- }
+ knownfn = known->linux_so;
+#endif
- // Neither override nor auto-detect found a gamedll.
- if (!known && !g_config->gamedll)
- RETURN_ERRNO(mFALSE, ME_NOTFOUND);
+ META_DEBUG(4, ("Checking for old version game DLL name '%s'.\n", knownfn));
+ Q_snprintf(gamedll->pathname, sizeof(gamedll->pathname), "dlls/%s", knownfn);
- // Use override-dll if specified.
- if (g_config->gamedll) {
- strncpy(gamedll->pathname, g_config->gamedll, sizeof gamedll->pathname - 1);
- gamedll->pathname[sizeof gamedll->pathname - 1] = '\0';
- override = true;
-
- // If the path is relative, the gamedll file will be missing and
- // it might be found in the cache file.
- if (!is_absolute_path(gamedll->pathname)) {
- // I abuse the real_pathname member here to pass a full pathname to
- // the install_gamedll function. I am somewhat opposed to be pushing
- // another MAX_PATH sized array on the stack, that's why.
- snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/%s", gamedll->gamedir, gamedll->pathname);
- // If we could successfully install the gamedll from the cache we
- // rectify the pathname to be a full pathname.
- if (install_gamedll(gamedll->pathname, gamedll->real_pathname)) {
- strncpy(gamedll->pathname, gamedll->real_pathname, sizeof gamedll->pathname - 1);
- gamedll->pathname[sizeof gamedll->pathname - 1] = '\0';
- }
+ // Check if the gamedll file exists. If not, try to install it from the cache.
+ if (!valid_gamedir_file(gamedll->pathname))
+ {
+ Q_snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/dlls/%s", gamedll->gamedir, knownfn);
+ install_gamedll(gamedll->pathname, gamedll->real_pathname);
}
}
- // Else use Auto-detect dll.
- else {
-#ifdef linux
- // The engine changed game dll lookup behaviour in that it strips
- // anything after the last '_' from the name and tries to load the
- // resulting name. The DSO names were changed and do not have the
- // '_i386' part in them anymore, so cs_i386.so became cs.so. We
- // have to adapt to that and try to load the DSO name without the
- // '_*' part first, to see if we have a new version file available.
-
- strippedfn = _strdup(knownfn);
-
- char *loc = strrchr(strippedfn, '_');
-
- // A small safety net here: make sure that we are dealing with
- // a file name at least four characters long and ending in
- // '.so'. This way we can be sure that we can safely overwrite
- // anything from the '_' on with '.so'.
- int size = 0;
- const char *ext;
- if(0 != loc) {
- size = strlen(strippedfn);
- ext = strippedfn + (size - 3);
- }
-
- if(0 != loc && size > 3 && 0 == _stricmp(ext, ".so")) {
-
- strcpy(loc, ".so");
- META_DEBUG(4, ("Checking for new version game DLL name '%s'.\n", strippedfn) );
-
- // Again, as above, I abuse the real_pathname member to store the full pathname
- // and the pathname member to store the relative name to pass it to the
- // install_gamedll function to save stack space. They are going
- // to get overwritten later on, so that's ok.
- snprintf(gamedll->pathname, sizeof(gamedll->pathname), "dlls/%s",
- strippedfn);
- // Check if the gamedll file exists. If not, try to install it from
- // the cache.
- mBOOL ok = mTRUE;
- if(!valid_gamedir_file(gamedll->pathname)) {
- snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/dlls/%s",
- gamedll->gamedir, strippedfn);
- ok = install_gamedll(gamedll->pathname, gamedll->real_pathname);
- }
- if(ok) usedfn = strippedfn;
- }
- else {
- META_DEBUG(4, ("Known game DLL name does not qualify for checking for a stripped version, skipping: '%s'.\n",
- strippedfn) );
- }
-#endif /* linux */
-
- // If no file to be used was found, try the old known DLL file
- // name.
- if (0 == usedfn) {
- META_DEBUG(4, ("Checking for old version game DLL name '%s'.\n", knownfn) );
- snprintf(gamedll->pathname, sizeof(gamedll->pathname), "dlls/%s", knownfn);
- // Check if the gamedll file exists. If not, try to install it from
- // the cache.
- if (!valid_gamedir_file(gamedll->pathname)) {
- snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/dlls/%s",
- gamedll->gamedir, knownfn);
- install_gamedll(gamedll->pathname, gamedll->real_pathname);
- }
- usedfn = knownfn;
- }
-
- // Now make an absolute path
- snprintf(gamedll->pathname, sizeof(gamedll->pathname), "%s/dlls/%s",
- gamedll->gamedir, usedfn);
+ else
+ {
+ // Neither known-list found a gamedll.
+ RETURN_ERRNO(mFALSE, ME_NOTFOUND);
}
+ Q_snprintf(gamedll->pathname, sizeof(gamedll->pathname), "%s/dlls/%s", gamedll->gamedir, knownfn);
+
// get filename from pathname
- cp = strrchr(gamedll->pathname, '/');
- if (cp) cp++;
- else cp = gamedll->pathname;
+ char *cp = Q_strrchr(gamedll->pathname, '/');
+ if (cp)
+ cp++;
+ else
+ cp = gamedll->pathname;
+
gamedll->file = cp;
- // If found, store also the supposed "real" dll path based on the
- // gamedir, in case it differs from the "override" dll path.
- if (known && override)
- snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname),
- "%s/dlls/%s", gamedll->gamedir, usedfn);
- else { // !known or !override
- strncpy(gamedll->real_pathname, gamedll->pathname, sizeof gamedll->real_pathname - 1);
- gamedll->real_pathname[sizeof gamedll->pathname - 1] = '\0';
- }
+ Q_strncpy(gamedll->real_pathname, gamedll->pathname, sizeof(gamedll->real_pathname) - 1);
+ gamedll->real_pathname[sizeof(gamedll->real_pathname) - 1] = '\0';
- if (override) {
- // generate a desc
- snprintf(override_desc_buf, sizeof(override_desc_buf),
- "%s (override)", gamedll->file);
- gamedll->desc = override_desc_buf;
- // log result
- META_LOG("Overriding game '%s' with dllfile '%s'", gamedll->name,
- gamedll->file);
- }
- else {
- gamedll->desc = known->desc;
- META_LOG("Recognized game '%s'; using dllfile '%s'", gamedll->name,
- gamedll->file);
- }
+ gamedll->desc = known->desc;
+ META_LOG("Recognized game '%s'; using dllfile '%s'", gamedll->name, gamedll->file);
- if (0 != strippedfn) free(strippedfn);
-
- return (mTRUE);
+ return mTRUE;
}
diff --git a/metamod/src/game_support.h b/metamod/src/game_support.h
index 8523d43..e564570 100644
--- a/metamod/src/game_support.h
+++ b/metamod/src/game_support.h
@@ -1,56 +1,16 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// game_support.h - structures for supporting different HL mod "games"
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef GAME_SUPPORT_H
-#define GAME_SUPPORT_H
-
-#include "types_meta.h" // mBOOL
-#include "metamod.h" // gamedll_t
+#include "types_meta.h"
+#include "metamod.h"
// Information we have about each game/mod DLL.
-typedef struct game_modinfo_s {
- const char *name; // name (the game dir)
+struct game_modinfo_t
+{
+ const char *name; // name (the game dir)
const char *linux_so; // filename of linux shared lib
const char *win_dll; // filename of win32 dll
const char *osx_dylib; // filename os osx dylib
- const char *desc; // our long-name description
-} game_modinfo_t;
+ const char *desc; // our long-name description
+};
-typedef game_modinfo_t game_modlist_t[];
-game_modinfo_t *lookup_game(const char *name);
mBOOL setup_gamedll(gamedll_t *gamedll);
-
-#endif /* GAME_SUPPORT_H */
diff --git a/metamod/src/games.h b/metamod/src/games.h
deleted file mode 100644
index a5773e5..0000000
--- a/metamod/src/games.h
+++ /dev/null
@@ -1,131 +0,0 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// games.h - list of supported game mods and their data
-
-/*
- * Copyright (c) 2001-2008 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game Engine ("HL
- * Engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL Engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-// This list is now kept in a separate file to facilitate generating the
-// list from game data stored in a convenient db.
-
-#ifdef __amd64__
-# define MODARCH "_amd64"
-#else
-# define MODARCH "_i386"
-#endif
-
-{"action", "ahl"MODARCH".so", "ahl.dll", "none", "Action Half-Life"},
-{"ag", "ag"MODARCH".so", "ag.dll", "none", "Adrenaline Gamer Steam"},
-{"ag3", "hl"MODARCH".so", "hl.dll", "none", "Adrenalinegamer 3.x"},
-{"aghl", "ag"MODARCH".so", "ag.dll", "none", "Adrenalinegamer 4.x"},
-{"arg", "arg"MODARCH".so", "hl.dll", "none", "Arg!"},
-{"asheep", "hl"MODARCH".so", "hl.dll", "none", "Azure Sheep"},
-{"bg", "bg"MODARCH".so", "bg.dll", "none", "The Battle Grounds"},
-{"bot", "bot"MODARCH".so", "bot.dll", "none", "Bot"},
-{"brainbread", "bb"MODARCH".so", "bb.dll", "none", "Brain Bread"},
-{"bumpercars", "hl"MODARCH".so", "hl.dll", "none", "Bumper Cars"},
-{"buzzybots", "bb"MODARCH".so", "bb.dll", "none", "BuzzyBots"},
-{"cs13", "cs"MODARCH".so", "mp.dll", "none", "Counter-Strike 1.3"},
-{"cstrike", "cs"MODARCH".so", "mp.dll", "cs.dylib", "Counter-Strike"},
-{"csv15", "cs"MODARCH".so", "mp.dll", "none", "CS 1.5 for Steam"},
-{"czero", "cs"MODARCH".so", "mp.dll", "cs.dylib", "Counter-Strike:Condition Zero"},
-{"dcrisis", "dc"MODARCH".so", "dc.dll", "none", "Desert Crisis"},
-{"dmc", "dmc"MODARCH".so", "dmc.dll", "dmc.dylib", "Deathmatch Classic"},
-{"dod", "dod"MODARCH".so", "dod.dll", "dod.dylib", "Day of Defeat"},
-{"dpb", "pb.i386.so", "pb.dll", "none", "Digital Paintball"},
-{"dragonmodz", "hl"MODARCH".so", "mp.dll", "none", "Dragon Mod Z"},
-{"esf", "hl"MODARCH".so", "hl.dll", "none", "Earth's Special Forces"},
-{"existence", "ex"MODARCH".so", "existence.dll", "none", "Existence"},
-{"firearms", "fa"MODARCH".so", "firearms.dll", "none", "Firearms"},
-{"firearms25", "fa"MODARCH".so", "firearms.dll", "none", "Retro Firearms"},
-{"freeze", "mp"MODARCH".so", "mp.dll", "none", "Freeze"},
-{"frontline", "front"MODARCH".so", "frontline.dll", "none", "Frontline Force"},
-{"gangstawars", "gangsta"MODARCH".so", "gwars27.dll", "none", "Gangsta Wars"},
-{"gangwars", "mp"MODARCH".so", "mp.dll", "none", "Gangwars"},
-{"gearbox", "opfor"MODARCH".so", "opfor.dll", "opfor.dylib", "Opposing Force"},
-{"globalwarfare", "gw"MODARCH".so", "mp.dll", "none", "Global Warfare"},
-{"goldeneye", "golden"MODARCH".so", "mp.dll", "none", "Goldeneye"},
-{"hl15we", "hl"MODARCH".so", "hl.dll", "none", "Half-Life 1.5: Weapon Edition"},
-{"hlrally", "hlr"MODARCH".so", "hlrally.dll", "none", "HL-Rally"},
-{"holywars", "hl"MODARCH".so", "holywars.dll", "none", "Holy Wars"},
-{"hostileintent", "hl"MODARCH".so", "hl.dll", "none", "Hostile Intent"},
-{"ios", "ios"MODARCH".so", "ios.dll", "none", "International Online Soccer"},
-{"judgedm", "judge"MODARCH".so", "mp.dll", "none", "Judgement"},
-{"kanonball", "hl"MODARCH".so", "kanonball.dll", "none", "Kanonball"},
-{"monkeystrike", "ms"MODARCH".so", "monkey.dll", "none", "Monkeystrike"},
-{"MorbidPR", "morbid"MODARCH".so", "morbid.dll", "none", "Morbid Inclination"},
-{"movein", "hl"MODARCH".so", "hl.dll", "none", "Move In!"},
-{"ns", "ns"MODARCH".so", "ns.dll", "none", "Natural Selection"},
-{"nsp", "ns"MODARCH".so", "ns.dll", "none", "Natural Selection Beta"},
-{"oel", "hl"MODARCH".so", "hl.dll", "none", "OeL Half-Life"},
-{"og", "og"MODARCH".so", "og.dll", "none", "Over Ground"},
-{"ol", "ol"MODARCH".so", "hl.dll", "none", "Outlawsmod"},
-{"ops1942", "spirit"MODARCH".so", "spirit.dll", "none", "Operations 1942"},
-{"osjb", "osjb"MODARCH".so", "jail.dll", "none", "Open-Source Jailbreak"},
-{"outbreak", "none", "hl.dll", "none", "Out Break"},
-{"oz", "mp"MODARCH".so", "mp.dll", "none", "Oz Deathmatch"},
-{"paintball", "pb"MODARCH".so", "mp.dll", "none", "Paintball"},
-{"penemy", "pe"MODARCH".so", "pe.dll", "none", "Public Enemy"},
-{"phineas", "phineas"MODARCH".so", "phineas.dll", "none", "Phineas Bot"},
-{"ponreturn", "ponr"MODARCH".so", "mp.dll", "none", "Point of No Return"},
-{"pvk", "hl"MODARCH".so", "hl.dll", "none", "Pirates, Vikings and Knights"},
-{"rc2", "rc2"MODARCH".so", "rc2.dll", "none", "Rocket Crowbar 2"},
-{"retrocs", "rcs"MODARCH".so", "rcs.dll", "none", "Retro Counter-Strike"},
-{"rewolf", "hl"MODARCH".so", "gunman.dll", "none", "Gunman Chronicles"},
-{"ricochet", "ricochet"MODARCH".so", "mp.dll", "ricochet.dylib", "Ricochet"},
-{"rockcrowbar", "rc"MODARCH".so", "rc.dll", "none", "Rocket Crowbar"},
-{"rspecies", "hl"MODARCH".so", "hl.dll", "none", "Rival Species"},
-{"scihunt", "shunt.so", "shunt.dll", "none", "Scientist Hunt"},
-{"sdmmod", "sdmmod"MODARCH".so", "sdmmod.dll", "none", "Special Death Match"},
-{"Ship", "ship"MODARCH".so", "ship.dll", "none", "The Ship"},
-{"si", "si"MODARCH".so", "si.dll", "none", "Science & Industry"},
-{"snow", "snow"MODARCH".so", "snow.dll", "none", "Snow-War"},
-{"stargatetc", "hl"MODARCH".so", "hl.dll", "none", "StargateTC"},
-{"svencoop", "hl"MODARCH".so", "hl.dll", "none", "Sven Coop"},
-{"swarm", "swarm"MODARCH".so", "swarm.dll", "none", "Swarm"},
-{"tfc", "tfc"MODARCH".so", "tfc.dll", "tfc.dylib", "Team Fortress Classic"},
-{"thewastes", "thewastes"MODARCH".so", "thewastes.dll", "none", "The Wastes"},
-{"timeless", "pt"MODARCH".so", "timeless.dll", "none", "Project Timeless"},
-{"tod", "hl"MODARCH".so", "hl.dll", "none", "Tour of Duty"},
-{"trainhunters", "th"MODARCH".so", "th.dll", "none", "Train Hunters"},
-{"trevenge", "trevenge.so", "trevenge.dll", "none", "The Terrorist Revenge"},
-{"TS", "ts"MODARCH".so", "mp.dll", "none", "The Specialists"},
-{"tt", "tt"MODARCH".so", "tt.dll", "none", "The Trenches"},
-{"underworld", "uw"MODARCH".so", "uw.dll", "none", "Underworld Bloodline"},
-{"valve", "hl"MODARCH".so", "hl.dll", "hl.dylib", "Half-Life Deathmatch"},
-{"vs", "vs"MODARCH".so", "mp.dll", "none", "VampireSlayer"},
-{"wantedhl", "hl"MODARCH".so", "wanted.dll", "none", "Wanted!"},
-{"wasteland", "whl_linux.so", "mp.dll", "none", "Wasteland"},
-{"weapon_wars", "ww"MODARCH".so", "hl.dll", "none", "Weapon Wars"},
-{"wizwars", "mp"MODARCH".so", "hl.dll", "none", "Wizard Wars"},
-{"wormshl", "wormshl_i586.so", "wormshl.dll", "none", "WormsHL"},
-{"zp", "none", "mp.dll", "none", "Zombie Panic"},
diff --git a/metamod/src/h_export.cpp b/metamod/src/h_export.cpp
index 9a6297d..a2d517b 100644
--- a/metamod/src/h_export.cpp
+++ b/metamod/src/h_export.cpp
@@ -1,37 +1,5 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// h_export.cpp - main exported DLL functionality
-
-// From SDK dlls/h_export.cpp:
-
-/***
-*
-* Copyright (c) 1999, 2000 Valve LLC. All rights reserved.
-*
-* This product contains software technology licensed from Id
-* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
-* All Rights Reserved.
-*
-* Use, distribution, and modification of this source code and/or resulting
-* object code is restricted to non-commercial enhancements to products from
-* Valve LLC. All other use, distribution, or modification is prohibited
-* without written permission from Valve LLC.
-*
-****/
-/*
-
-===== h_export.cpp ========================================================
-
- Entity classes exported by Halflife.
-
-*/
-
#include "precompiled.h"
-// From SDK dlls/h_export.cpp:
-
-
#ifdef _WIN32
//! Required DLL entry point
// The above SDK comment indicates this routine is required, but the MSDN
@@ -39,10 +7,12 @@
// completeness.
BOOL WINAPI DllMain(HINSTANCE /* hinstDLL */, DWORD fdwReason, LPVOID /* lpvReserved */)
{
- if (fdwReason == DLL_PROCESS_ATTACH) {
+ if (fdwReason == DLL_PROCESS_ATTACH)
+ {
/* nothing */
}
- else if (fdwReason == DLL_PROCESS_DETACH) {
+ else if (fdwReason == DLL_PROCESS_DETACH)
+ {
/* nothing */
}
return TRUE;
@@ -53,11 +23,13 @@ BOOL WINAPI DllMain(HINSTANCE /* hinstDLL */, DWORD fdwReason, LPVOID /* lpvRese
// just in case we come across a need to do something at dll load or
// unload.
// NOTE: These aren't actually called. Needs investigation.
-void _init(void) {
-// called before dlopen() returns
+void _init()
+{
+ // called before dlopen() returns
}
-void _fini(void) {
-// called before dlclose() returns
+void _fini()
+{
+ // called before dlclose() returns
}
#endif
@@ -71,7 +43,7 @@ engine_t g_engine;
// This appears to be the _first_ DLL routine called by the engine, so this
// is where we hook to load all the other DLLs (game, plugins, etc), which
// is actually all done in meta_startup().
-void WINAPI GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t* pGlobals)
+void WINAPI GiveFnptrsToDll(enginefuncs_t *pengfuncsFromEngine, globalvars_t *pGlobals)
{
gpGlobals = pGlobals;
g_engine.funcs = &g_engfuncs;
@@ -94,22 +66,22 @@ extern "C" void __cxa_pure_virtual(void)
void *operator new(size_t size)
{
- return malloc(size);
+ return Q_malloc(size);
}
void *operator new[](size_t size)
{
- return malloc(size);
+ return Q_malloc(size);
}
void operator delete(void *ptr)
{
- free(ptr);
+ Q_free(ptr);
}
void operator delete[](void * ptr)
{
- free(ptr);
+ Q_free(ptr);
}
#endif
diff --git a/metamod/src/h_export.h b/metamod/src/h_export.h
index 24754fb..84d6e25 100644
--- a/metamod/src/h_export.h
+++ b/metamod/src/h_export.h
@@ -1,49 +1,7 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// h_export.h - prototypes for h_export.cpp
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef H_EXPORT_H
-#define H_EXPORT_H
+#pragma once
#include "osdep.h" // DLLEXPORT, WINAPI, etc
// Our GiveFnptrsToDll, called by engine.
-typedef void (WINAPI *GIVE_ENGINE_FUNCTIONS_FN) (enginefuncs_t
- *pengfuncsFromEngine, globalvars_t *pGlobals);
-
-C_DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t *pengfuncsFromEngine,
- globalvars_t *pGlobals);
-
-#endif /* H_EXPORT_H */
+typedef void (WINAPI *GIVE_ENGINE_FUNCTIONS_FN)(enginefuncs_t *pengfuncsFromEngine, globalvars_t *pGlobals);
+C_DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t *pengfuncsFromEngine, globalvars_t *pGlobals);
diff --git a/metamod/src/info_name.h b/metamod/src/info_name.h
deleted file mode 100644
index fe128ad..0000000
--- a/metamod/src/info_name.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// info_name.h - name, desc, author, etc
-
-/*
- * Copyright (c) 2001-2013 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game Engine ("HL
- * Engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL Engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef INFO_NAME_H
-#define INFO_NAME_H
-
-#define VNAME "Metamod"
-#define VAUTHOR "Will Day "
-#define VURL "http://www.metamod.org/"
-
-#define COPYRIGHT_YEAR "2013"
-
-// Various strings for the Windows DLL Resources in res_meta.rc
-#define RC_COMMENTS "Metamod allows running multiple mod-like plugin DLLs, to add functionality or change the behavior of the running HLDS game mod. See " VURL
-#define RC_DESC "Metamod Half-Life MOD DLL"
-#define RC_FILENAME "METAMOD.DLL"
-#define RC_INTERNAL "METAMOD"
-#define RC_COPYRIGHT "Copyright© 2001-" COPYRIGHT_YEAR " Will Day; GPL licensed"
-#define RC_LICENSE "Licensed under the GNU General Public License"
-
-#endif /* INFO_NAME_H */
diff --git a/metamod/src/linkent.cpp b/metamod/src/linkent.cpp
index a28257b..4eb1b95 100644
--- a/metamod/src/linkent.cpp
+++ b/metamod/src/linkent.cpp
@@ -1,59 +1,29 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// linkent.cpp - export entities from mod "games" back to the HL engine
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// Function to perform common code of LINK_ENTITY_TO_GAME, rather than
// duplicating the code in ~2000 expanded macros. Based on code from Jussi
// Kivilinna .
void do_link_ent(ENTITY_FN *pfnEntity, int *missing, const char *entStr, entvars_t *pev)
-{;
- if(*missing) {
+{
+ if (*missing)
+ {
META_DEBUG(9, ("Skipping entity '%s'; was previously found missing", entStr));
return;
}
- if(!*pfnEntity) {
+
+ if (!*pfnEntity)
+ {
META_DEBUG(9, ("Looking up game entity '%s'", entStr));
- *pfnEntity = (ENTITY_FN) DLSYM(GameDLL.handle, entStr);
+ *pfnEntity = (ENTITY_FN)DLSYM(GameDLL.handle, entStr);
}
- if(!*pfnEntity) {
+
+ if (!*pfnEntity)
+ {
META_ERROR("Couldn't find game entity '%s' in game DLL '%s': %s", entStr, GameDLL.name, DLERROR());
- *missing=1;
+ *missing = 1;
return;
}
+
META_DEBUG(8, ("Linking game entity '%s'", entStr));
(*pfnEntity)(pev);
}
diff --git a/metamod/src/linkent.h b/metamod/src/linkent.h
index a488136..068c8f7 100644
--- a/metamod/src/linkent.h
+++ b/metamod/src/linkent.h
@@ -1,49 +1,4 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// linkent.h - export entities from mod "games" back to the HL engine
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef LINK_ENT_H
-#define LINK_ENT_H
-
-#include // always
-
-#include "osdep.h" // DLLEXPORT, etc
-#include "metamod.h" // GameDLL, etc
-#include "mlist.h" // MPluginList::find_match, etc
-#include "mplugin.h" // MPlugin::info, etc
-#include "log_meta.h" // META_DEBUG, etc
+#pragma once
// Comments from SDK dlls/util.h:
//! This is the glue that hooks .MAP entity class names to our CPP classes.
@@ -51,18 +6,16 @@
//! The function is used to intialize / allocate the object for the entity.
// Adapted from LINK_ENTITY_TO_FUNC in adminmod linkfunc.cpp.
-
-typedef void (*ENTITY_FN) (entvars_t *);
+typedef void (*ENTITY_FN)(entvars_t *);
// Function to perform common code of LINK_ENTITY_TO_GAME.
-void do_link_ent(ENTITY_FN *pfnEntity, int *missing, const char *entStr,
- entvars_t *pev);
+void do_link_ent(ENTITY_FN *pfnEntity, int *missing, const char *entStr, entvars_t *pev);
#define LINK_ENTITY_TO_GAME(entityName) \
C_DLLEXPORT void entityName(entvars_t *pev); \
void entityName(entvars_t *pev) { \
static ENTITY_FN pfnEntity = NULL; \
- static int missing=0; \
+ static int missing = 0; \
do_link_ent(&pfnEntity, &missing, STRINGIZE(entityName, 0), pev); \
}
@@ -83,33 +36,31 @@ void do_link_ent(ENTITY_FN *pfnEntity, int *missing, const char *entStr,
C_DLLEXPORT void entityName(entvars_t *pev); \
void entityName(entvars_t *pev) { \
static ENTITY_FN pfnEntity = NULL; \
- static int missing=0; \
+ static int missing = 0; \
const char *entStr; \
MPlugin *findp; \
entStr = STRINGIZE(entityName, 0); \
- if(missing) \
+ if (missing) \
return; \
- if(!pfnEntity) { \
- if(!(findp=g_plugins->find_match(pluginName))) { \
+ if (!pfnEntity) { \
+ if (!(findp = g_plugins->find_match(pluginName))) { \
META_ERROR("Couldn't find loaded plugin '%s' for plugin entity '%s'", pluginName, entStr); \
- missing=1; \
+ missing = 1; \
return; \
} \
- if(findp->info && findp->info->loadable != PT_STARTUP) { \
+ if (findp->info && findp->info->loadable != PT_STARTUP) { \
META_ERROR("Can't link entity '%s' for plugin '%s'; loadable != startup: %s", entStr, pluginName, findp->str_loadable()); \
- missing=1; \
+ missing = 1; \
return; \
} \
META_DEBUG(9, ("Looking up plugin entity '%s'", entStr)); \
pfnEntity = (ENTITY_FN) DLSYM(findp->handle, entStr); \
} \
- if(!pfnEntity) { \
+ if (!pfnEntity) { \
META_ERROR("Couldn't find plugin entity '%s' in plugin DLL '%s'", entStr, findp->file); \
- missing=1; \
+ missing = 1; \
return; \
} \
META_DEBUG(8, ("Linking plugin entity '%s'", entStr)); \
(*pfnEntity)(pev); \
}
-
-#endif /* LINK_ENT_H */
diff --git a/metamod/src/linkgame.cpp b/metamod/src/linkgame.cpp
index b3a7196..14d879e 100644
--- a/metamod/src/linkgame.cpp
+++ b/metamod/src/linkgame.cpp
@@ -1,39 +1,3 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// linkgame.cpp - export entities from mod "games" back to the HL engine
-
-/*
- * Copyright (c) 2001-2013 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// Entity list for gamedlls adapted from adminmod linkfunc.cpp.
diff --git a/metamod/src/log_meta.cpp b/metamod/src/log_meta.cpp
index ba958c0..cc600dd 100644
--- a/metamod/src/log_meta.cpp
+++ b/metamod/src/log_meta.cpp
@@ -1,42 +1,6 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// log_mega.cpp - logging routines
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
-cvar_t meta_debug = {"meta_debug", "0", FCVAR_EXTDLL , 0, NULL};
+cvar_t meta_debug = { "meta_debug", "0", FCVAR_EXTDLL , 0, nullptr };
enum MLOG_SERVICE
{
@@ -46,17 +10,17 @@ enum MLOG_SERVICE
mlsCLIENT
};
-static void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char* prefix, const char* fmt, va_list ap);
+static void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix, const char *fmt, va_list ap);
// Print to console.
-void META_CONS(const char* fmt, ...)
+void META_CONS(const char *fmt, ...)
{
va_list ap;
char buf[MAX_LOGMSG_LEN];
unsigned int len;
va_start(ap, fmt);
- len = vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
+ len = Q_vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
va_end(ap);
buf[len] = '\n';
@@ -65,9 +29,10 @@ void META_CONS(const char* fmt, ...)
SERVER_PRINT(buf);
}
-void META_DEV(const char* fmt, ...)
+void META_DEV(const char *fmt, ...)
{
- if (CVAR_GET_FLOAT && CVAR_GET_FLOAT("developer")) {
+ if (CVAR_GET_FLOAT && CVAR_GET_FLOAT("developer"))
+ {
va_list ap;
va_start(ap, fmt);
buffered_ALERT(mlsDEV, at_logged, "[META] dev:", fmt, ap);
@@ -75,7 +40,7 @@ void META_DEV(const char* fmt, ...)
}
}
-void META_INFO(const char* fmt, ...)
+void META_INFO(const char *fmt, ...)
{
va_list ap;
@@ -84,7 +49,7 @@ void META_INFO(const char* fmt, ...)
va_end(ap);
}
-void META_WARNING(const char* fmt, ...)
+void META_WARNING(const char *fmt, ...)
{
va_list ap;
@@ -93,7 +58,7 @@ void META_WARNING(const char* fmt, ...)
va_end(ap);
}
-void META_ERROR(const char* fmt, ...)
+void META_ERROR(const char *fmt, ...)
{
va_list ap;
@@ -102,7 +67,7 @@ void META_ERROR(const char* fmt, ...)
va_end(ap);
}
-void META_LOG(const char* fmt, ...)
+void META_LOG(const char *fmt, ...)
{
va_list ap;
@@ -112,14 +77,14 @@ void META_LOG(const char* fmt, ...)
}
// Print to client.
-void META_CLIENT(edict_t* pEntity, const char* fmt, ...)
+void META_CLIENT(edict_t *pEntity, const char *fmt, ...)
{
va_list ap;
char buf[MAX_CLIENTMSG_LEN];
unsigned int len;
va_start(ap, fmt);
- len = vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
+ len = Q_vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
va_end(ap);
buf[len] = '\n';
@@ -132,28 +97,29 @@ struct BufferedMessage
{
MLOG_SERVICE service;
ALERT_TYPE atype;
- const char* prefix;
+ const char *prefix;
char buf[MAX_LOGMSG_LEN];
- BufferedMessage* next;
+ BufferedMessage *next;
};
-static BufferedMessage* messageQueueStart = NULL;
-static BufferedMessage* messageQueueEnd = NULL;
+static BufferedMessage *messageQueueStart = nullptr;
+static BufferedMessage *messageQueueEnd = nullptr;
-void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char* prefix, const char* fmt, va_list ap)
+void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix, const char *fmt, va_list ap)
{
char buf[MAX_LOGMSG_LEN];
- BufferedMessage* msg;
- if (NULL != g_engfuncs.pfnAlertMessage) {
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ if (g_engfuncs.pfnAlertMessage)
+ {
+ Q_vsnprintf(buf, sizeof(buf), fmt, ap);
ALERT(atype, "%s %s\n", prefix, buf);
return;
}
// g_engine AlertMessage function not available. Buffer message.
- msg = new BufferedMessage;
- if (NULL == msg) {
+ BufferedMessage *msg = new BufferedMessage;
+ if (!msg)
+ {
// though luck, gonna lose this message
return;
}
@@ -161,13 +127,15 @@ void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char* prefix,
msg->service = service;
msg->atype = atype;
msg->prefix = prefix;
- vsnprintf(msg->buf, sizeof(buf), fmt, ap);
- msg->next = NULL;
+ Q_vsnprintf(msg->buf, sizeof(buf), fmt, ap);
+ msg->next = nullptr;
- if (NULL == messageQueueEnd) {
+ if (!messageQueueEnd)
+ {
messageQueueStart = messageQueueEnd = msg;
}
- else {
+ else
+ {
messageQueueEnd->next = msg;
messageQueueEnd = msg;
}
@@ -179,21 +147,23 @@ void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char* prefix,
// jumptable is set. Don't call it if it isn't set.
void flush_ALERT_buffer(void)
{
- BufferedMessage* msg = messageQueueStart;
- int dev = (int) CVAR_GET_FLOAT("developer");
+ BufferedMessage *msg = messageQueueStart;
+ int dev = (int)CVAR_GET_FLOAT("developer");
- while (NULL != msg) {
+ while (msg)
+ {
if (msg->service == mlsDEV && dev == 0) {
;
}
- else {
+ else
+ {
ALERT(msg->atype, "b>%s %s\n", msg->prefix, msg->buf);
}
+
messageQueueStart = messageQueueStart->next;
delete msg;
msg = messageQueueStart;
}
- messageQueueStart = messageQueueEnd = NULL;
+ messageQueueStart = messageQueueEnd = nullptr;
}
-
diff --git a/metamod/src/log_meta.h b/metamod/src/log_meta.h
index 4d67730..3e16ed7 100644
--- a/metamod/src/log_meta.h
+++ b/metamod/src/log_meta.h
@@ -1,43 +1,6 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// log_meta.h - functions & macros for logging
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef LOG_META_H
-#define LOG_META_H
-
-#include "enginecallbacks.h" // ALERT, etc
+#include "enginecallbacks.h" // ALERT, etc
#include "sdk_util.h" // UTIL_VarArgs, etc
// Debug logging.
@@ -65,7 +28,7 @@
// for times when it might be called as a single-statement result of an
// else (or other flow control).
//
-// As suggested by Jussi Kivilinna: Use "if(meta_debug.value < level); else
+// As suggested by Jussi Kivilinna: Use "if (meta_debug.value < level); else
// DO(something);" style because "meta_debug.value < level" is in most common
// case "false". Check disasm, contitional jumps are predicted not to be
// taken by CPU.
@@ -73,7 +36,7 @@
// Yes, it's all a bit of a hack.
#define META_DEBUG(level, args) \
- do { if(meta_debug.value < level) break; else ALERT(at_logged, "[META] (debug:%d) %s\n", level, UTIL_VarArgs args ); } while(0)
+ do { if (meta_debug.value < level) break; else ALERT(at_logged, "[META] (debug:%d) %s\n", level, UTIL_VarArgs args ); } while(0)
// max buffer size for printed messages
#define MAX_LOGMSG_LEN 1024
@@ -98,5 +61,3 @@ void META_LOG(const char *fmt, ...);
void META_CLIENT(edict_t *pEntity, const char *fmt, ...);
void flush_ALERT_buffer(void);
-
-#endif /* LOG_META_H */
diff --git a/metamod/src/meta_api.h b/metamod/src/meta_api.h
index b203cb0..d06cfa4 100644
--- a/metamod/src/meta_api.h
+++ b/metamod/src/meta_api.h
@@ -1,47 +1,10 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// meta_api.h - description of metamod's DLL interface
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef META_API_H
-#define META_API_H
+#pragma once
#include "dllapi.h" // GETENTITYAPI_FN, etc
-#include "engine_api.h" // GET_ENGINE_FUNCTIONS_FN, etc
+#include "engine_api.h" // GET_ENGINE_FUNCTIONS_FN, etc
#include "plinfo.h" // plugin_info_t, etc
-#include "mutil.h" // mutil_funcs_t, etc
#include "osdep.h" // DLLEXPORT, etc
+#include "mutil.h"
// Version consists of "major:minor", two separate integer numbers.
// Version 1 original
@@ -60,47 +23,48 @@
// Version 5:9 added GetGameInfo [v1.14]
// Version 5:10 added GINFO_REALDLL_FULLPATH for GetGameInfo [v1.17]
// Version 5:11 added plugin loading and unloading API [v1.18]
-// Version 5:12 added util code for checking player query status [v1.18]
-// Version 5:13 added cvarquery2 support and api for calling hook tables [v1.19]
+// Version 5:12 added IS_QUERYING_CLIENT_CVAR to mutils [v1.18]
+// Version 5:13 added MAKE_REQUESTID and GET_HOOK_TABLES to mutils [v1.19]
#define META_INTERFACE_VERSION "5:13"
-#ifdef UNFINISHED
-// Version 5:99 added event hook utility functions [v.???]
-#define META_INTERFACE_VERSION "5:99"
-#endif /* UNFINISHED */
-
// Flags returned by a plugin's api function.
// NOTE: order is crucial, as greater/less comparisons are made.
-typedef enum {
+enum META_RES
+{
MRES_UNSET = 0,
MRES_IGNORED, // plugin didn't take any action
MRES_HANDLED, // plugin did something, but real function should still be called
MRES_OVERRIDE, // call real function, but use my return value
MRES_SUPERCEDE, // skip real function; use my return value
-} META_RES;
+};
// Variables provided to plugins.
-typedef struct meta_globals_s {
+struct meta_globals_t
+{
META_RES mres; // writable; plugin's return flag
META_RES prev_mres; // readable; return flag of the previous plugin called
META_RES status; // readable; "highest" return flag so far
void *orig_ret; // readable; return value from "real" function
void *override_ret; // readable; return value from overriding/superceding plugin
-} meta_globals_t;
+};
extern meta_globals_t *gpMetaGlobals;
-#define SET_META_RESULT(result) gpMetaGlobals->mres=result
+#define SET_META_RESULT(result) gpMetaGlobals->mres = result
+
#define RETURN_META(result) \
- do { gpMetaGlobals->mres=result; return; } while(0)
+ do { gpMetaGlobals->mres = result; return; } while (0)
+
#define RETURN_META_VALUE(result, value) \
- do { gpMetaGlobals->mres=result; return(value); } while(0)
-#define META_RESULT_STATUS gpMetaGlobals->status
+ do { gpMetaGlobals->mres = result; return value; } while (0)
+
+#define META_RESULT_STATUS gpMetaGlobals->status
#define META_RESULT_PREVIOUS gpMetaGlobals->prev_mres
#define META_RESULT_ORIG_RET(type) *(type *)gpMetaGlobals->orig_ret
-#define META_RESULT_OVERRIDE_RET(type) *(type *)gpMetaGlobals->override_ret
+#define META_RESULT_OVERRIDE_RET(type) *(type *)gpMetaGlobals->override_ret
// Table of getapi functions, retrieved from each plugin.
-typedef struct {
+struct META_FUNCTIONS
+{
GETENTITYAPI_FN pfnGetEntityAPI;
GETENTITYAPI_FN pfnGetEntityAPI_Post;
GETENTITYAPI2_FN pfnGetEntityAPI2;
@@ -109,13 +73,14 @@ typedef struct {
GETNEWDLLFUNCTIONS_FN pfnGetNewDLLFunctions_Post;
GET_ENGINE_FUNCTIONS_FN pfnGetEngineFunctions;
GET_ENGINE_FUNCTIONS_FN pfnGetEngineFunctions_Post;
-} META_FUNCTIONS;
+};
// Pair of function tables provided by game DLL.
-typedef struct {
+struct gamedll_funcs_t
+{
DLL_FUNCTIONS *dllapi_table;
NEW_DLL_FUNCTIONS *newapi_table;
-} gamedll_funcs_t;
+};
// Declared in plugin; referenced in macros.
extern gamedll_funcs_t *gpGamedllFuncs;
@@ -126,112 +91,94 @@ extern mutil_funcs_t *gpMetaUtilFuncs;
// procedure. In particular, this will allow for DLL's that can be used as
// both standalone DLL's and metamod plugins. (optional; not required in
// plugin)
-C_DLLEXPORT void Meta_Init(void);
-typedef void (*META_INIT_FN) (void);
+C_DLLEXPORT void Meta_Init();
+typedef void (*META_INIT_FN)();
// Get info about plugin, compare meta_interface versions, provide meta
// utility callback functions.
-C_DLLEXPORT int Meta_Query(const char *interfaceVersion,
- plugin_info_t **plinfo,
- mutil_funcs_t *pMetaUtilFuncs);
-typedef int (*META_QUERY_FN) (const char *interfaceVersion,
- plugin_info_t **plinfo,
- mutil_funcs_t *pMetaUtilFuncs);
+C_DLLEXPORT int Meta_Query(char *interfaceVersion, plugin_info_t **plinfo, mutil_funcs_t *pMetaUtilFuncs);
+typedef int (*META_QUERY_FN) (char *interfaceVersion, plugin_info_t **plinfo, mutil_funcs_t *pMetaUtilFuncs);
-// Attach the plugin to the API; get the table of getapi functions; give
+// Attach the plugin to the API; get the table of getapi functions; give
// meta_globals and gamedll_funcs.
-C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now,
- META_FUNCTIONS *pFunctionTable,
- meta_globals_t *pMGlobals,
- gamedll_funcs_t *pGamedllFuncs);
-typedef int (*META_ATTACH_FN) (PLUG_LOADTIME now,
- META_FUNCTIONS *pFunctionTable,
- meta_globals_t *pMGlobals,
- gamedll_funcs_t *pGamedllFuncs);
+C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs);
+typedef int (*META_ATTACH_FN) (PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs);
// Detach the plugin; tell why and when.
C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
typedef int (*META_DETACH_FN) (PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
// Standard HL SDK interface function prototypes.
-C_DLLEXPORT int GetEntityAPI_Post(DLL_FUNCTIONS *pFunctionTable,
- int interfaceVersion );
-C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable,
- int *interfaceVersion );
+C_DLLEXPORT int GetEntityAPI_Post(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion );
+C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion );
// Additional SDK-like interface function prototypes.
-C_DLLEXPORT int GetNewDLLFunctions_Post(NEW_DLL_FUNCTIONS *pNewFunctionTable,
- int *interfaceVersion );
-C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine,
- int *interfaceVersion);
-C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine,
- int *interfaceVersion);
+C_DLLEXPORT int GetNewDLLFunctions_Post(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion );
+C_DLLEXPORT int GetEngineFunctions(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion);
+C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion);
// Convenience macros for accessing GameDLL functions. Note: these talk
// _directly_ to the gamedll, and are not multiplexed through Metamod to
// the other plugins.
// DLL API functions:
-#define MDLL_FUNC gpGamedllFuncs->dllapi_table
+#define MDLL_FUNC gpGamedllFuncs->dllapi_table
-#define MDLL_GameDLLInit MDLL_FUNC->pfnGameInit
-#define MDLL_Spawn MDLL_FUNC->pfnSpawn
-#define MDLL_Think MDLL_FUNC->pfnThink
-#define MDLL_Use MDLL_FUNC->pfnUse
-#define MDLL_Touch MDLL_FUNC->pfnTouch
-#define MDLL_Blocked MDLL_FUNC->pfnBlocked
-#define MDLL_KeyValue MDLL_FUNC->pfnKeyValue
-#define MDLL_Save MDLL_FUNC->pfnSave
-#define MDLL_Restore MDLL_FUNC->pfnRestore
+#define MDLL_GameDLLInit MDLL_FUNC->pfnGameInit
+#define MDLL_Spawn MDLL_FUNC->pfnSpawn
+#define MDLL_Think MDLL_FUNC->pfnThink
+#define MDLL_Use MDLL_FUNC->pfnUse
+#define MDLL_Touch MDLL_FUNC->pfnTouch
+#define MDLL_Blocked MDLL_FUNC->pfnBlocked
+#define MDLL_KeyValue MDLL_FUNC->pfnKeyValue
+#define MDLL_Save MDLL_FUNC->pfnSave
+#define MDLL_Restore MDLL_FUNC->pfnRestore
#define MDLL_ObjectCollsionBox MDLL_FUNC->pfnAbsBox
#define MDLL_SaveWriteFields MDLL_FUNC->pfnSaveWriteFields
-#define MDLL_SaveReadFields MDLL_FUNC->pfnSaveReadFields
+#define MDLL_SaveReadFields MDLL_FUNC->pfnSaveReadFields
#define MDLL_SaveGlobalState MDLL_FUNC->pfnSaveGlobalState
#define MDLL_RestoreGlobalState MDLL_FUNC->pfnRestoreGlobalState
#define MDLL_ResetGlobalState MDLL_FUNC->pfnResetGlobalState
-#define MDLL_ClientConnect MDLL_FUNC->pfnClientConnect
+#define MDLL_ClientConnect MDLL_FUNC->pfnClientConnect
#define MDLL_ClientDisconnect MDLL_FUNC->pfnClientDisconnect
-#define MDLL_ClientKill MDLL_FUNC->pfnClientKill
+#define MDLL_ClientKill MDLL_FUNC->pfnClientKill
#define MDLL_ClientPutInServer MDLL_FUNC->pfnClientPutInServer
-#define MDLL_ClientCommand MDLL_FUNC->pfnClientCommand
+#define MDLL_ClientCommand MDLL_FUNC->pfnClientCommand
#define MDLL_ClientUserInfoChanged MDLL_FUNC->pfnClientUserInfoChanged
-#define MDLL_ServerActivate MDLL_FUNC->pfnServerActivate
+#define MDLL_ServerActivate MDLL_FUNC->pfnServerActivate
#define MDLL_ServerDeactivate MDLL_FUNC->pfnServerDeactivate
-#define MDLL_PlayerPreThink MDLL_FUNC->pfnPlayerPreThink
+#define MDLL_PlayerPreThink MDLL_FUNC->pfnPlayerPreThink
#define MDLL_PlayerPostThink MDLL_FUNC->pfnPlayerPostThink
-#define MDLL_StartFrame MDLL_FUNC->pfnStartFrame
-#define MDLL_ParmsNewLevel MDLL_FUNC->pfnParmsNewLevel
+#define MDLL_StartFrame MDLL_FUNC->pfnStartFrame
+#define MDLL_ParmsNewLevel MDLL_FUNC->pfnParmsNewLevel
#define MDLL_ParmsChangeLevel MDLL_FUNC->pfnParmsChangeLevel
#define MDLL_GetGameDescription MDLL_FUNC->pfnGetGameDescription
#define MDLL_PlayerCustomization MDLL_FUNC->pfnPlayerCustomization
#define MDLL_SpectatorConnect MDLL_FUNC->pfnSpectatorConnect
#define MDLL_SpectatorDisconnect MDLL_FUNC->pfnSpectatorDisconnect
-#define MDLL_SpectatorThink MDLL_FUNC->pfnSpectatorThink
-#define MDLL_Sys_Error MDLL_FUNC->pfnSys_Error
-#define MDLL_PM_Move MDLL_FUNC->pfnPM_Move
-#define MDLL_PM_Init MDLL_FUNC->pfnPM_Init
+#define MDLL_SpectatorThink MDLL_FUNC->pfnSpectatorThink
+#define MDLL_Sys_Error MDLL_FUNC->pfnSys_Error
+#define MDLL_PM_Move MDLL_FUNC->pfnPM_Move
+#define MDLL_PM_Init MDLL_FUNC->pfnPM_Init
#define MDLL_PM_FindTextureType MDLL_FUNC->pfnPM_FindTextureType
#define MDLL_SetupVisibility MDLL_FUNC->pfnSetupVisibility
#define MDLL_UpdateClientData MDLL_FUNC->pfnUpdateClientData
-#define MDLL_AddToFullPack MDLL_FUNC->pfnAddToFullPack
-#define MDLL_CreateBaseline MDLL_FUNC->pfnCreateBaseline
+#define MDLL_AddToFullPack MDLL_FUNC->pfnAddToFullPack
+#define MDLL_CreateBaseline MDLL_FUNC->pfnCreateBaseline
#define MDLL_RegisterEncoders MDLL_FUNC->pfnRegisterEncoders
-#define MDLL_GetWeaponData MDLL_FUNC->pfnGetWeaponData
-#define MDLL_CmdStart MDLL_FUNC->pfnCmdStart
-#define MDLL_CmdEnd MDLL_FUNC->pfnCmdEnd
+#define MDLL_GetWeaponData MDLL_FUNC->pfnGetWeaponData
+#define MDLL_CmdStart MDLL_FUNC->pfnCmdStart
+#define MDLL_CmdEnd MDLL_FUNC->pfnCmdEnd
#define MDLL_ConnectionlessPacket MDLL_FUNC->pfnConnectionlessPacket
-#define MDLL_GetHullBounds MDLL_FUNC->pfnGetHullBounds
-#define MDLL_CreateInstancedBaselines MDLL_FUNC->pfnCreateInstancedBaselines
+#define MDLL_GetHullBounds MDLL_FUNC->pfnGetHullBounds
+#define MDLL_CreateInstancedBaselines MDLL_FUNC->pfnCreateInstancedBaselines
#define MDLL_InconsistentFile MDLL_FUNC->pfnInconsistentFile
#define MDLL_AllowLagCompensation MDLL_FUNC->pfnAllowLagCompensation
// NEW API functions:
-#define MNEW_FUNC gpGamedllFuncs->newapi_table
+#define MNEW_FUNC gpGamedllFuncs->newapi_table
#define MNEW_OnFreeEntPrivateData MNEW_FUNC->pfnOnFreeEntPrivateData
-#define MNEW_GameShutdown MNEW_FUNC->pfnGameShutdown
-#define MNEW_ShouldCollide MNEW_FUNC->pfnShouldCollide
-#define MNEW_CvarValue MNEW_FUNC->pfnCvarValue
-#define MNEW_CvarValue2 MNEW_FUNC->pfnCvarValue2
-
-#endif /* META_API_H */
+#define MNEW_GameShutdown MNEW_FUNC->pfnGameShutdown
+#define MNEW_ShouldCollide MNEW_FUNC->pfnShouldCollide
+#define MNEW_CvarValue MNEW_FUNC->pfnCvarValue
diff --git a/metamod/src/meta_eiface.cpp b/metamod/src/meta_eiface.cpp
index 724cfe1..16655c3 100644
--- a/metamod/src/meta_eiface.cpp
+++ b/metamod/src/meta_eiface.cpp
@@ -1,51 +1,5 @@
-
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// meta_eiface.cpp - wrapper for engine/dll interface
-
-/*
- * Copyright (c) 2001-2006 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
-
-// ------------------------------------------------------------------------
-// meta_new_dll_functions_t
-// ------------------------------------------------------------------------
-
-// static member initialisation
-int meta_new_dll_functions_t::sm_version = 0;
-
-
meta_new_dll_functions_t::meta_new_dll_functions_t(
void (*_pfnOnFreeEntPrivateData)(edict_t*),
void (*_pfnGameShutdown)(void),
@@ -61,104 +15,16 @@ meta_new_dll_functions_t::meta_new_dll_functions_t(
pfnCvarValue2 = _pfnCvarValue2;
}
-
-void meta_new_dll_functions_t::copy_to(NEW_DLL_FUNCTIONS* _pFuncs)
+void meta_new_dll_functions_t::copy_to(NEW_DLL_FUNCTIONS *_pFuncs)
{
- // This is where the magic happens. We check what version of the
- // NEW_DLL_FUNCTIONS interface the engine has and calculate the size of
- // that interface. Then we only copy the function pointers present in
- // that version over to the receiver, so that we do not overwrite his
- // memory with functions that he doesn't know of in his copy of the
- // struct.
- size_t size = get_size();
+#if 0
+ // TODO: Implemented check regamedll
+ // exit
- if (0 == size) {
- // Ok, this is a real problem and should *not* happen.
- // We try to work with NEW_DLL_FUNCTIONS without knowing what
- // interface the attached engine uses. This means that the classes
- // defined herein are not used in the way they are meant to because
- // someone forgot to first create a HL_enginefuncs_t object and
- // initialise it with the pointers passed from the engine.
- // We treat this as a major developer error and bluntly exit the
- // whole process, assuming that this will never happen on a
- // production server as it should have been caught by the developer
- // during testing.
- //
- // We use a printf() to complain since we do not know if we have
- // already attached to the engine and can use its alerting
- // functions. This should be augemnted with a windows version
- // popping open a message box.
- fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
- fprintf(stderr, "ERROR: INTERNAL ERROR.\n");
- fprintf(stderr, " Attempt to use meta_new_dll_functions_t without"
- " initialised engine interface version!\n");
- fprintf(stderr, " %s at %d\n", __FILE__, __LINE__);
- exit(1);
- }
-
- memcpy(_pFuncs, this, size);
+#endif
+ Q_memcpy(_pFuncs, this, sizeof(NEW_DLL_FUNCTIONS));
}
-
-int meta_new_dll_functions_t::determine_interface_version(void)
-{
- // If the meta_enginefuncs_t::version is 0, i.e. has not yet been
- // determined, that is a problem and an error. We should probably throw
- // a fit here or something.
- // For now we just return 0 and leave it to the caller to complain.
- if (meta_enginefuncs_t::version() == 0) return 0;
-
- // The default version is 1.
- sm_version = 1;
-
- // With the enginefuncs interface version 156 the function
- // pfnCvarValue() was added, which we call version 2.
- if (meta_enginefuncs_t::version() >= 156) sm_version = 2;
-
- // With the enginefuncs interface version 157 the function
- // pfnCvarValue2() was added, which we call version 3.
- if (meta_enginefuncs_t::version() >= 157) sm_version = 3;
-
- return sm_version;
-}
-
-
-size_t meta_new_dll_functions_t::get_size(int _version)
-{
- size_t size = sizeof(NEW_DLL_FUNCTIONS);
-
- if (0 == _version) {
- // Use the current engine's interface version
- _version = version();
-
- // Error: meta_enginefuncs_t::version probably not yet set up.
- if (0 == _version) return 0;
- }
-
- switch (_version) {
- case 1:
- // Version 1 is missing all functions from CvarValue() on.
- size -= sizeof(FN_CVARVALUE);
- case 2:
- // Version 2 is missing all functions from CvarValue2() on.
- size -= sizeof(FN_CVARVALUE2);
- }
-
- return size;
-}
-
-
-// --------------------------------------------------------------
-// meta_enginefuncs_t
-// --------------------------------------------------------------
-
-// static member initialisation
-int meta_enginefuncs_t::sm_version = 0;
-
-// -----------------------------------------------------------------
-// HL_enginefuncs
-// -----------------------------------------------------------------
-
void HL_enginefuncs_t::initialise_interface(enginefuncs_t* _pFuncs)
{
set_from(_pFuncs);
@@ -166,166 +32,4 @@ void HL_enginefuncs_t::initialise_interface(enginefuncs_t* _pFuncs)
// Now the pfnAlertMessage is available and we trust it to be a valid
// pointer, so flush the message buffer.
flush_ALERT_buffer();
-
- determine_engine_interface_version();
- fixup_engine_interface();
-}
-
-
-// The following part (i.e. the end) of the enginefuncs_t struct is
-// used to determine the engine interface version since it is the one
-// that changed since SDK 212 engines. We call this the "signature" of
-// the enginefuncs interface.
-//
-// Default version is 138. That's what the SDK says.
-//
-// 144: const char *(*pfnGetPlayerAuthId) ( edict_t *e );
-//
-// // PSV: Added for CZ training map
-// // const char *(*pfnKeyNameForBinding) ( const char* pBinding );
-//
-// sequenceEntry_s* (*pfnSequenceGet) ( const char* fileName, const char* entryName );
-// sentenceEntry_s* (*pfnSequencePickSentence) ( const char* groupName, int pickMethod, int *picked );
-//
-// // LH: Give access to filesize via filesystem
-// 147: int (*pfnGetFileSize) ( const char *filename );
-//
-// unsigned int (*pfnGetApproxWavePlayLen) (const char *filepath);
-// // MDC: Added for CZ career-mode
-// int (*pfnIsCareerMatch) ( void );
-//
-// // BGC: return the number of characters of the localized string referenced by using "label"
-// int (*pfnGetLocalizedStringLength) (const char *label);
-//
-// // BGC: added to facilitate persistent storage of tutor message decay values for
-// // different career game profiles. Also needs to persist regardless of mp.dll being
-// // destroyed and recreated.
-// void (*pfnRegisterTutorMessageShown) (int mid);
-// int (*pfnGetTimesTutorMessageShown) (int mid);
-// void (*pfnProcessTutorMessageDecayBuffer) (int *buffer, int bufferLength);
-// void (*pfnConstructTutorMessageDecayBuffer) (int *buffer, int bufferLength);
-// 155: void (*pfnResetTutorMessageDecayData) ( void );
-
-// 156: void (*pfnQueryClientCvarValue) ( const edict_t *player, const char *cvarName );
-// 157: void (*pfnQueryClientCvarValue2) ( const edict_t *player, const char *cvarName, int requestID );
-// 158: int (*pfnCheckParm) ( const char *pchCmdLineToke, char **ppnext );
-
-
-void HL_enginefuncs_t::determine_engine_interface_version(void) const
-{
- // We only need to do this once.
- if (0 != sm_version) {
- return;
- }
-
- // Now begins our heuristic, where we try to determine the engine
- // interface version.
- // As alluded to above we are currently only interested, and thus
- // only detect, versions 144, 147, 156 or 157 (defined by us).
-
- // The minimal default is 138.
- sm_version = 138;
-
- // If GetPlayerAuthId() is present, it is at least 144,
- // otherwise leave it at the default 138.
- // This may give incorrect results for *really* old engine versions,
- // i.e. pre 1.1.0.8. We live with that risk. No one uses them anymore.
- // Really.
- if (pfnGetPlayerAuthId == NULL) {
- return;
- }
- sm_version = 144;
-
- // The two function pointers for pfnSequenceGet() and
- // pfnSequencePickSentence() are only valid in a few engine versions
- // and are set to NULL in most other version, so they don't get
- // checked.
-
- // If pfnGetFileSize() is present, it is at least 147,
- // otherwise leave it at the so far determined value.
- if (pfnGetFileSize == NULL) {
- return;
- }
- sm_version = 147;
-
- // Now it gets a bit fuzzy. If all of the functions following GetFileSize()
- // but before QueryClientCvarValue() are valid, it is at least 155.
- // If even one of them is NULL, then our version can't be higher than 147,
- // so use 147. Actually, it could be that there exist engine
- // versions where one of them is NULL but the interface is still at
- // least 155. If such an engine is found in use, adaptions need to be
- // made.
- // (Yes, I know this could be done with a little hacky for() loop. We
- // don't need to do hacky here.)
- int cntInvals = 0;
- if (pfnGetApproxWavePlayLen == NULL) cntInvals++;
- if (pfnIsCareerMatch == NULL) cntInvals++;
- if (pfnGetLocalizedStringLength == NULL) cntInvals++;
- if (pfnRegisterTutorMessageShown == NULL) cntInvals++;
- if (pfnGetTimesTutorMessageShown == NULL) cntInvals++;
- if (pfnProcessTutorMessageDecayBuffer == NULL) cntInvals++;
- if (pfnConstructTutorMessageDecayBuffer == NULL) cntInvals++;
- if (pfnResetTutorMessageDecayData == NULL) cntInvals++;
-
- if (cntInvals > 0) {
- return;
- }
- sm_version = 155;
-
- // All functions up to QueryClientCvarValue() are valid.
- // If QueryClientCvarValue() is not valid, leave it at the so far
- // determined version. Otherwise the version is at least 156.
- if (pfnQueryClientCvarValue == NULL) {
- return;
- }
- sm_version = 156;
-
- // All functions up to QueryClientCvarValue2() are valid.
- // If QueryClientCvarValue2() is not valid, leave it at the so far
- // determined version. Otherwise the version is at least 157.
- if (pfnQueryClientCvarValue2 == NULL) {
- return;
- }
- sm_version = 157;
-
- // All functions up to CheckParm() are valid.
- // If CheckParm() is not valid, leave it at the so far determined
- // version. Otherwise the version is at least 158.
- if (pfnEngCheckParm == NULL) {
- return;
- }
- sm_version = 158;
-}
-
-
-void HL_enginefuncs_t::fixup_engine_interface(void)
-{
- // This function will make sure that all function pointers that aren't
- // valid are set to NULL, depending on the engine interface version.
- // Sometimes a pointer has a valid value although the function doesn't
- // exist in the interface version.
-
- switch (version()) {
- case 138:
- pfnGetPlayerAuthId = NULL;
- case 144:
- pfnSequenceGet = NULL;
- pfnSequencePickSentence = NULL;
- pfnGetFileSize = NULL;
- case 147:
- pfnGetApproxWavePlayLen = NULL;
- pfnIsCareerMatch = NULL;
- pfnGetLocalizedStringLength = NULL;
- pfnRegisterTutorMessageShown = NULL;
- pfnGetTimesTutorMessageShown = NULL;
- pfnProcessTutorMessageDecayBuffer = NULL;
- pfnConstructTutorMessageDecayBuffer = NULL;
- pfnResetTutorMessageDecayData = NULL;
- case 155:
- pfnQueryClientCvarValue = NULL;
- case 156:
- pfnQueryClientCvarValue2 = NULL;
- case 157:
- pfnEngCheckParm = NULL;
- }
}
diff --git a/metamod/src/meta_eiface.h b/metamod/src/meta_eiface.h
index 6fe134a..34186a1 100644
--- a/metamod/src/meta_eiface.h
+++ b/metamod/src/meta_eiface.h
@@ -1,69 +1,22 @@
-
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// meta_eiface.h - wrapper for engine/dll interface
-
-/*
- * Copyright (c) 2001-2006 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef MM_META_EIFACE_H
-#define MM_META_EIFACE_H
-
-#include // NEW_DLL_FUNCTIONS, enginefuncs_t
-
-#include // memset()
-
-
+#pragma once
// We use our own versions of the engine/dll interface structs. We add a
// few dummy entries to the end and set them to 0. That way we are
// protected from updates to the HL SDK adding new functions which would
// cause a) the game dll copying arbitrary values from us and b) the game
// dll overwriting our memory when using an old Metamod with a new game
-// dll.
+// dll.
-// --------------------------------------------------------------------
// meta_new_dll_functions_t
-// --------------------------------------------------------------------
-
-struct meta_new_dll_functions_t : public NEW_DLL_FUNCTIONS
+struct meta_new_dll_functions_t: public NEW_DLL_FUNCTIONS
{
meta_new_dll_functions_t();
meta_new_dll_functions_t(
- void (*pfnOnFreeEntPrivateData)(edict_t*),
- void (*pfnGameShutdown)(void),
- int (*pfnShouldCollide)(edict_t*, edict_t*),
- void (*pfnCvarValue)(const edict_t*, const char*),
- void (*pfnCvarValue2)(const edict_t*, int, const char*, const char*)
+ void (*pfnOnFreeEntPrivateData)(edict_t *),
+ void (*pfnGameShutdown)(),
+ int (*pfnShouldCollide)(edict_t *, edict_t *),
+ void (*pfnCvarValue)(const edict_t *, const char *),
+ void (*pfnCvarValue2)(const edict_t *, int, const char *, const char *)
);
meta_new_dll_functions_t(const meta_new_dll_functions_t&);
@@ -74,106 +27,33 @@ struct meta_new_dll_functions_t : public NEW_DLL_FUNCTIONS
// Copy the pointers from this object to a NEW_DLL_FUNCTIONS struct.
void copy_to(NEW_DLL_FUNCTIONS* pFuncs);
-
- // return the engine's version of NEW_DLL_FUNCTIONS
- int version(void);
-
-
-private:
-
- // data :
-
- // The NEW_DLL_FUNCTIONS struct also changed, but the version
- // number did not change. That begs the question why to have
- // it versioned in the first place, but whaddaya know.
- // While the official version is left at 1, we internally
- // calculate a different version of the engine's NEW_DLL_FUNCTIONS
- // struct since we know that the engine lies to us about the
- // version that it uses.
- //
- // The default version is 1.
- //
- // With the enginefuncs interface version 156 the function
- // pfnCvarValue() was added, which we call version 2.
- //
- // With the enginefuncs interface version 157 the function
- // pfnCvarValue2() was added, which we call version 3.
- //
- // If Valve ever decides to change the version of the
- // NEW_DLL_FUNCTIONS interface in the future (haha),
- // we are in trouble and will need to change our
- // internal versions.
-
- static int sm_version;
-
- // functions :
-
- // Calculates our idea of the engine's version of the
- // NEW_DLL_FUNCTIONS interface. Stores this version for future
- // reference in m_version and returns it.
- static int determine_interface_version(void);
-
- // Comfort function to determine the size of the NEW_DLL_FUNCTIONS
- // struct for the different versions.
- // If passed a version number other than 0, the size for that
- // specific version is returned.
- // If passed 0 as version number (default) the size for the version
- // that was determined to be the version of the currently connected
- // engine's interface. Should that version have not yet been
- // determined (via the enginefuncs_t interface), 0 is returned to
- // indicated this error state.
- size_t get_size(int version = 0);
};
-
-// Inline functions
-
inline meta_new_dll_functions_t::meta_new_dll_functions_t()
{
- memset(this, 0, sizeof(meta_new_dll_functions_t));
+ Q_memset(this, 0, sizeof(meta_new_dll_functions_t));
}
-
inline meta_new_dll_functions_t::meta_new_dll_functions_t(const meta_new_dll_functions_t& _rhs)
{
- memcpy(this, &_rhs, sizeof(NEW_DLL_FUNCTIONS));
+ Q_memcpy(this, &_rhs, sizeof(NEW_DLL_FUNCTIONS));
}
-
inline meta_new_dll_functions_t& meta_new_dll_functions_t::operator=(const meta_new_dll_functions_t& _rhs)
{
- memcpy(this, &_rhs, sizeof(NEW_DLL_FUNCTIONS));
+ Q_memcpy(this, &_rhs, sizeof(NEW_DLL_FUNCTIONS));
return *this;
}
-
inline void meta_new_dll_functions_t::set_from(NEW_DLL_FUNCTIONS* _pFuncs)
{
- memcpy(this, _pFuncs, sizeof(NEW_DLL_FUNCTIONS));
+ Q_memcpy(this, _pFuncs, sizeof(NEW_DLL_FUNCTIONS));
}
-
-inline int meta_new_dll_functions_t::version(void)
-{
- return sm_version ? sm_version : determine_interface_version();
-}
-
-
-// No meta version of DLL_FUNCTIONS because that won't be changing anymore.
-
-
-// --------------------------------------------------------------------
-// meta_enginefuncs_t
-// --------------------------------------------------------------------
-
-
// meta_enginefuncs_t
struct meta_enginefuncs_t : public enginefuncs_t
{
- meta_enginefuncs_t()
- {
- };
-
+ meta_enginefuncs_t() {};
meta_enginefuncs_t(enginefuncs_t* pFuncs)
{
set_from(pFuncs);
@@ -184,72 +64,26 @@ struct meta_enginefuncs_t : public enginefuncs_t
// Copy the pointers from this object to an enginefuncs_t struct.
void copy_to(enginefuncs_t* pFuncs);
-
- // The version of the engine functions interface. It is frozen at 138. But no one knows
- // when that was and what it looked like then. So we simply interprete it as the
- // number of functions that the enginefuncs struct contains.
- //
- // That means we get gaps inbetween versions and right now we can detect only
- // about five different versions anyway, but that suffices for the current itches
- // to get scratched.
- //
- // The default is hence 138.
- // A value of 0 means "not yet determined".
- // Other possible versions currently detectable:
- // 144: engine versions after 1.1.0.9 build 1996
- // 147: engine versions after build 2384 with pfnGetFileSize()
- // 155: all versions between build 2384 and the one
- // including pfnQueryClientCvarValue()
- // 156: includes pfnQueryClientCvarValue()
- // 157: includes pfnQueryClientCvarValue2()
- // 158: includes pfnCheckParm()
- static int sm_version;
- static int version(void);
};
-//
-// Inline functions
-//
-
inline void meta_enginefuncs_t::set_from(enginefuncs_t* _pFuncs)
{
- memcpy(this, _pFuncs, sizeof(enginefuncs_t));
+ Q_memcpy(this, _pFuncs, sizeof(enginefuncs_t));
}
-
inline void meta_enginefuncs_t::copy_to(enginefuncs_t* _pFuncs)
{
- memcpy(_pFuncs, this, sizeof(enginefuncs_t));
+ Q_memcpy(_pFuncs, this, sizeof(enginefuncs_t));
}
-
-inline int meta_enginefuncs_t::version(void)
-{
- return sm_version;
-}
-
-
-// --------------------------------------------------------------------
-// HL_enginefuncs_t
-// --------------------------------------------------------------------
-
-//
// This is a specialisation of the meta_enginefuncs_t struct which is only
// used for the initial copy of the engine functions, i.e. those we get
-// passed from the HL engine right at the beginning.
-// This specialisation does some extra initialisation when getting set up
-// like calculating the engine interface version and fixing up any invalid
-// pointers.
+// passed from the HL engine right at the beginning.
// Since there is only one master copy of engine functions this could be
// implemented as a singleton. This is left as an option for later.
-//
-struct HL_enginefuncs_t : public meta_enginefuncs_t
+struct HL_enginefuncs_t: public meta_enginefuncs_t
{
- // functions :
-
- HL_enginefuncs_t()
- {
- };
+ HL_enginefuncs_t() {};
// Fill this object with pointers copied from an enginefuncs_t struct
// and fixup the interface.
@@ -257,32 +91,15 @@ struct HL_enginefuncs_t : public meta_enginefuncs_t
// with the pointers passed from the HL engine.
void initialise_interface(enginefuncs_t* pFuncs);
-
private:
-
- // functions :
-
// Moving copy_to() and set_from() to the private space.
void set_from(enginefuncs_t* pFuncs)
{
meta_enginefuncs_t::set_from(pFuncs);
- };
+ }
void copy_to(enginefuncs_t* pFuncs)
{
meta_enginefuncs_t::copy_to(pFuncs);
- };
-
-
- // Determine the version of the engine interface from the
- // enginefuncs signature.
- void determine_engine_interface_version(void) const;
-
- // Fixup the enginefuncs pointers according to the determined
- // version as some pointers may be invalid.
- void fixup_engine_interface(void);
+ }
};
-
-
-#endif /* META_EIFACE_H */
-
diff --git a/metamod/src/metamod.cpp b/metamod/src/metamod.cpp
index 115b567..feb8c14 100644
--- a/metamod/src/metamod.cpp
+++ b/metamod/src/metamod.cpp
@@ -1,52 +1,17 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// metamod.cpp - (main) implementation of metamod operations
-
-/*
- * Copyright (c) 2001-2004 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
-cvar_t meta_version = {"metamod_version", VVERSION, FCVAR_SERVER , 0, NULL};
+cvar_t meta_version = { "metamod_version", APP_VERSION_STRD, FCVAR_SERVER, 0, nullptr };
MConfig static_config;
-MConfig* g_config = &static_config;
-option_t global_options[] = {
- {"debuglevel", CF_INT, &g_config->debuglevel, "0"},
- {"gamedll", CF_PATH, &g_config->gamedll, NULL},
- {"plugins_file", CF_PATH, &g_config->plugins_file, PLUGINS_INI},
- {"exec_cfg", CF_STR, &g_config->exec_cfg, EXEC_CFG},
+MConfig *g_config = &static_config;
+option_t global_options[] =
+{
+ { "debuglevel", CF_INT, &g_config->debuglevel, "0" },
+ { "plugins_file", CF_PATH, &g_config->plugins_file, PLUGINS_INI },
+ { "exec_cfg", CF_STR, &g_config->exec_cfg, EXEC_CFG },
+
// list terminator
- {NULL, CF_NONE, NULL, NULL}
+ { NULL, CF_NONE, NULL, NULL }
};
gamedll_t GameDLL;
@@ -56,10 +21,10 @@ meta_globals_t PrivateMetaGlobals;
meta_enginefuncs_t g_plugin_engfuncs;
-MPluginList* g_plugins;
-MRegCmdList* g_regCmds;
-MRegCvarList* g_regCvars;
-MRegMsgList* g_regMsgs;
+MPluginList *g_plugins;
+MRegCmdList *g_regCmds;
+MRegCvarList *g_regCvars;
+MRegMsgList *g_regMsgs;
MPlayerList g_Players;
@@ -69,31 +34,31 @@ int requestid_counter = 0;
#ifdef UNFINISHED
MHookList *Hooks;
-#endif /* UNFINISHED */
+#endif // UNFINISHED
// Very first metamod function that's run.
// Do startup operations...
-void metamod_startup(void)
+void metamod_startup()
{
- const char* mmfile = NULL;
- const char* cfile = NULL;
- const char* cp;
+ const char *mmfile = NULL;
+ const char *cfile = NULL;
+ const char *cp;
META_CONS(" ");
- META_CONS(" %s version %s Copyright (c) 2001-%s %s", VNAME, VVERSION, COPYRIGHT_YEAR, VAUTHOR);
- META_CONS(" %s comes with ABSOLUTELY NO WARRANTY; for details type `meta gpl'.", VNAME);
+ META_CONS(" Metamod version %s Copyright (c) 2001-2016 Will Day (modification ReHLDS Team)", APP_VERSION_STRD);
+ META_CONS(" Metamod comes with ABSOLUTELY NO WARRANTY; for details type `meta gpl'.");
META_CONS(" This is free software, and you are welcome to redistribute it");
META_CONS(" under certain conditions; type `meta gpl' for details.");
META_CONS(" ");
- META_LOG("%s v%s %s", VNAME, VVERSION, VDATE);
- META_LOG("by %s", VAUTHOR);
- META_LOG(" %s", VURL);
- META_LOG("compiled: %s %s (%s)", COMPILE_TIME, COMPILE_TZONE, OPT_TYPE);
+ META_CONS("Metamod v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
+ META_CONS("Metamod build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")");
+ META_CONS("Metamod from: " APP_COMMITS_URL APP_COMMIT_ID " " APP_COMMIT_AUTHOR "");
// If running with "+developer", allow an opportunity to break in with
// a debugger.
- if ((int) CVAR_GET_FLOAT("developer") != 0) {
+ if ((int) CVAR_GET_FLOAT("developer") != 0)
+ {
//sleep(10); // TODO: WAT??????
}
@@ -102,62 +67,66 @@ void metamod_startup(void)
// Get gamedir, very early on, because it seems we need it all over the
// place here at the start.
- if (!meta_init_gamedll()) {
+ if (!meta_init_gamedll())
+ {
META_ERROR("Failure to init game DLL; exiting...");
do_exit(1);
}
// Register various console commands and cvars.
- // Can I do these here, rather than waiting for GameDLLInit() ?
+ // Can I do these here, rather than waiting for GameDLLInit() ?
// Looks like it works okay..
meta_register_cmdcvar();
// Set a slight debug level for developer mode, if debug level not
// already set.
if ((int) CVAR_GET_FLOAT("developer") != 0 && meta_debug.value == 0)
- CVAR_SET_FLOAT("meta_debug", 3.0);
+ CVAR_SET_FLOAT("meta_debug", 3.0);
// Init default values
g_config->init(global_options);
// Find config file
cfile = CONFIG_INI;
- if ((cp = LOCALINFO("mm_configfile")) && *cp != '\0') {
+ if ((cp = LOCALINFO("mm_configfile")) && *cp != '\0')
+ {
META_LOG("Configfile specified via localinfo: %s", cp);
if (valid_gamedir_file(cp))
cfile = cp;
else
- META_ERROR("Empty/missing config.ini file: %s; falling back to %s",
- cp, cfile);
+ META_ERROR("Empty/missing config.ini file: %s; falling back to %s", cp, cfile);
}
// Load config file
if (valid_gamedir_file(cfile))
g_config->load(cfile);
else
- META_DEBUG(2, ("No config.ini file found: %s", CONFIG_INI));
+ META_DEBUG(2, ("No config.ini file found: %s", CONFIG_INI));
// Now, override config options with localinfo commandline options.
- if ((cp = LOCALINFO("mm_debug")) && *cp != '\0') {
+ if ((cp = LOCALINFO("mm_debug")) && *cp != '\0')
+ {
META_LOG("Debuglevel specified via localinfo: %s", cp);
g_config->set("debuglevel", cp);
}
- if ((cp = LOCALINFO("mm_gamedll")) && *cp != '\0') {
+ if ((cp = LOCALINFO("mm_gamedll")) && *cp != '\0')
+ {
META_LOG("Gamedll specified via localinfo: %s", cp);
g_config->set("gamedll", cp);
}
- if ((cp = LOCALINFO("mm_pluginsfile")) && *cp != '\0') {
+ if ((cp = LOCALINFO("mm_pluginsfile")) && *cp != '\0')
+ {
META_LOG("Pluginsfile specified via localinfo: %s", cp);
g_config->set("plugins_file", cp);
}
- if ((cp = LOCALINFO("mm_execcfg")) && *cp != '\0') {
+ if ((cp = LOCALINFO("mm_execcfg")) && *cp != '\0')
+ {
META_LOG("Execcfg specified via localinfo: %s", cp);
g_config->set("exec_cfg", cp);
}
-
// Check for an initial debug level, since cfg files don't get exec'd
// until later.
if (g_config->debuglevel != 0)
- CVAR_SET_FLOAT("meta_debug", g_config->debuglevel);
+ CVAR_SET_FLOAT("meta_debug", g_config->debuglevel);
// Prepare for registered commands from plugins.
g_regCmds = new MRegCmdList();
@@ -176,13 +145,14 @@ void metamod_startup(void)
g_engine.pl_funcs->pfnCVarRegister = meta_CVarRegister;
g_engine.pl_funcs->pfnCvar_RegisterVariable = meta_CVarRegister;
g_engine.pl_funcs->pfnRegUserMsg = meta_RegUserMsg;
+
if (g_engine.pl_funcs->pfnQueryClientCvarValue)
g_engine.pl_funcs->pfnQueryClientCvarValue = meta_QueryClientCvarValue;
#ifdef UNFINISHED
// Init the list of event/logline hooks.
Hooks = new MHookList();
-#endif /* UNFINISHED */
+#endif
// Before, we loaded plugins before loading the game DLL, so that if no
// plugins caught engine functions, we could pass engine funcs straight
@@ -201,28 +171,31 @@ void metamod_startup(void)
// does) then it needs to be non-null so META_ENGINE_HANDLE won't crash.
//
// However, having replaced valid_file with valid_gamedir_file, we need
- // to at least initialize the gameDLL to include the gamedir, before
+ // to at least initialize the gameDLL to include the gamedir, before
// looking for plugins.ini.
//
// In fact, we need gamedir even earlier, so moved up above.
// Fall back to old plugins filename, if configured one isn't found.
mmfile = PLUGINS_INI;
+
if (!valid_gamedir_file(PLUGINS_INI) && valid_gamedir_file(OLD_PLUGINS_INI))
mmfile = OLD_PLUGINS_INI;
if (valid_gamedir_file(g_config->plugins_file))
mmfile = g_config->plugins_file;
else
- META_ERROR("g_plugins file is empty/missing: %s; falling back to %s",
- g_config->plugins_file, mmfile);
+ META_ERROR("g_plugins file is empty/missing: %s; falling back to %s", g_config->plugins_file, mmfile);
g_plugins = new MPluginList(mmfile);
- if (!meta_load_gamedll()) {
+ if (!meta_load_gamedll())
+ {
META_ERROR("Failure to load game DLL; exiting...");
do_exit(1);
}
- if (!g_plugins->load()) {
+
+ if (!g_plugins->load())
+ {
META_ERROR("Failure to load plugins...");
// Exit on failure here? Dunno...
}
@@ -230,7 +203,7 @@ void metamod_startup(void)
#ifdef UNFINISHED
// Start up the log parsing thread.
startup_logparse_thread();
-#endif /* UNFINISHED */
+#endif
// Allow for commands to metamod plugins at startup. Autoexec.cfg is
// read too early, and server.cfg is read too late.
@@ -240,18 +213,21 @@ void metamod_startup(void)
// messages.
if (valid_gamedir_file(g_config->exec_cfg))
mmfile = g_config->exec_cfg;
+
else if (valid_gamedir_file(OLD_EXEC_CFG))
mmfile = OLD_EXEC_CFG;
else
mmfile = NULL;
- if (mmfile) {
+ if (mmfile)
+ {
if (mmfile[0] == '/')
META_ERROR("Cannot exec absolute pathnames: %s", mmfile);
- else {
- char cmd[NAME_MAX ];
+ else
+ {
+ char cmd[NAME_MAX];
META_LOG("Exec'ing metamod exec.cfg: %s...", mmfile);
- snprintf(cmd, sizeof(cmd), "exec %s\n", mmfile);
+ Q_snprintf(cmd, sizeof(cmd), "exec %s\n", mmfile);
SERVER_COMMAND(cmd);
}
}
@@ -262,10 +238,10 @@ void metamod_startup(void)
// - ME_NULLRESULT _getcwd failed
mBOOL meta_init_gamedll(void)
{
- char gamedir[PATH_MAX ];
- char* cp;
+ char gamedir[PATH_MAX];
+ char *cp;
- memset(&GameDLL, 0, sizeof(GameDLL));
+ Q_memset(&GameDLL, 0, sizeof(GameDLL));
GET_GAME_DIR(gamedir);
normalize_pathname(gamedir);
@@ -280,32 +256,37 @@ mBOOL meta_init_gamedll(void)
// Note: the code has always assumed the server op wouldn't do:
// hlds -game other/firearms
//
- if (is_absolute_path(gamedir)) {
+ if (is_absolute_path(gamedir))
+ {
// Old style; GET_GAME_DIR returned full pathname. Copy this into
// our gamedir, and truncate to get the game name.
// (note check for both linux and win32 full pathname.)
- strncpy(GameDLL.gamedir, gamedir, sizeof GameDLL.gamedir - 1);
- GameDLL.gamedir[sizeof GameDLL.gamedir - 1] = '\0';
- cp = strrchr(gamedir, '/') + 1;
- strncpy(GameDLL.name, cp, sizeof GameDLL.name - 1);
- GameDLL.name[sizeof GameDLL.name - 1] = '\0';
+ Q_strncpy(GameDLL.gamedir, gamedir, sizeof(GameDLL.gamedir) - 1);
+ GameDLL.gamedir[sizeof(GameDLL.gamedir) - 1] = '\0';
+
+ cp = Q_strrchr(gamedir, '/') + 1;
+
+ Q_strncpy(GameDLL.name, cp, sizeof(GameDLL.name) - 1);
+ GameDLL.name[sizeof(GameDLL.name) - 1] = '\0';
}
- else {
+ else
+ {
// New style; GET_GAME_DIR returned game name. Copy this into our
// game name, and prepend the current working directory.
- char buf[PATH_MAX ];
- if (!_getcwd(buf, sizeof(buf))) {
- META_ERROR("dll: Couldn't get cwd; %s", strerror(errno));
+ char buf[PATH_MAX];
+ if (!_getcwd(buf, sizeof(buf)))
+ {
+ META_WARNING("dll: Couldn't get cwd; %s", strerror(errno));
RETURN_ERRNO(mFALSE, ME_NULLRESULT);
}
- snprintf(GameDLL.gamedir, sizeof(GameDLL.gamedir), "%s/%s", buf, gamedir);
- strncpy(GameDLL.name, gamedir, sizeof GameDLL.name - 1);
- GameDLL.name[sizeof GameDLL.name - 1] = '\0';
+
+ Q_snprintf(GameDLL.gamedir, sizeof(GameDLL.gamedir), "%s/%s", buf, gamedir);
+ Q_strncpy(GameDLL.name, gamedir, sizeof(GameDLL.name) - 1);
+ GameDLL.name[sizeof(GameDLL.name) - 1] = '\0';
}
META_DEBUG(3, ("Game: %s", GameDLL.name));
-
- return (mTRUE);
+ return mTRUE;
}
// Load game DLL.
@@ -323,16 +304,17 @@ mBOOL meta_load_gamedll(void)
GETENTITYAPI2_FN pfn_getapi2;
GETENTITYAPI_FN pfn_getapi;
- if (!setup_gamedll(&GameDLL)) {
+ if (!setup_gamedll(&GameDLL))
+ {
META_ERROR("dll: Unrecognized game: %s", GameDLL.name);
// meta_errno should be already set in lookup_game()
- return (mFALSE);
+ return mFALSE;
}
// open the game DLL
- if (!(GameDLL.handle = DLOPEN(GameDLL.pathname))) {
- META_ERROR("dll: Couldn't load game DLL %s: %s", GameDLL.pathname,
- DLERROR());
+ if (!(GameDLL.handle = DLOPEN(GameDLL.pathname)))
+ {
+ META_ERROR("dll: Couldn't load game DLL %s: %s", GameDLL.pathname, DLERROR());
RETURN_ERRNO(mFALSE, ME_DLOPEN);
}
@@ -340,40 +322,39 @@ mBOOL meta_load_gamedll(void)
// wanted to catch one of the functions, but now that plugins are
// dynamically loadable at any time, we have to always pass our table,
// so that any plugin loaded later can catch what they need to.
- if ((pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN) DLSYM(GameDLL.handle,
- "GiveFnptrsToDll"))) {
+ if ((pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN) DLSYM(GameDLL.handle, "GiveFnptrsToDll")))
+ {
pfn_give_engfuncs(&meta_engfuncs, gpGlobals);
- META_DEBUG(3, ("dll: Game '%s': Called GiveFnptrsToDll",
- GameDLL.name));
+ META_DEBUG(3, ("dll: Game '%s': Called GiveFnptrsToDll", GameDLL.name));
}
- else {
- META_ERROR("dll: Couldn't find GiveFnptrsToDll() in game DLL '%s': %s",
- GameDLL.name, DLERROR());
+ else
+ {
+ META_ERROR("dll: Couldn't find GiveFnptrsToDll() in game DLL '%s': %s", GameDLL.name, DLERROR());
RETURN_ERRNO(mFALSE, ME_DLMISSING);
}
// Yes...another macro.
#define GET_FUNC_TABLE_FROM_GAME(gamedll, pfnGetFuncs, STR_GetFuncs, struct_field, API_TYPE, TABLE_TYPE, vers_pass, vers_int, vers_want, gotit) \
- if((pfnGetFuncs = (API_TYPE) DLSYM(gamedll.handle, STR_GetFuncs))) { \
- gamedll.funcs.struct_field = (TABLE_TYPE*) calloc(1, sizeof(TABLE_TYPE)); \
- if(!gamedll.funcs.struct_field) {\
+ if ((pfnGetFuncs = (API_TYPE) DLSYM(gamedll.handle, STR_GetFuncs))) { \
+ gamedll.funcs.struct_field = (TABLE_TYPE *)Q_calloc(1, sizeof(TABLE_TYPE)); \
+ if (!gamedll.funcs.struct_field) {\
META_ERROR("malloc failed for gamedll struct_field: %s", STR_GetFuncs); \
} \
- else if(pfnGetFuncs(gamedll.funcs.struct_field, vers_pass)) { \
+ else if (pfnGetFuncs(gamedll.funcs.struct_field, vers_pass)) { \
META_DEBUG(3, ("dll: Game '%s': Found %s", gamedll.name, STR_GetFuncs)); \
- gotit=1; \
+ gotit = 1; \
} \
else { \
META_ERROR("dll: Failure calling %s in game '%s'", STR_GetFuncs, gamedll.name); \
- free(gamedll.funcs.struct_field); \
- gamedll.funcs.struct_field=NULL; \
- if(vers_int != vers_want) { \
+ Q_free(gamedll.funcs.struct_field); \
+ gamedll.funcs.struct_field = NULL; \
+ if (vers_int != vers_want) { \
META_ERROR("dll: Interface version didn't match; we wanted %d, they had %d", vers_want, vers_int); \
/* reproduce error from engine */ \
META_CONS("=================="); \
META_CONS("Game DLL version mismatch"); \
META_CONS("DLL version is %d, engine version is %d", vers_int, vers_want); \
- if(vers_int > vers_want) \
+ if (vers_int > vers_want) \
META_CONS("g_engine appears to be outdated, check for updates"); \
else \
META_CONS("The game DLL for %s appears to be outdated, check for updates", GameDLL.name); \
@@ -384,37 +365,33 @@ mBOOL meta_load_gamedll(void)
} \
else { \
META_DEBUG(5, ("dll: Game '%s': No %s", gamedll.name, STR_GetFuncs)); \
- gamedll.funcs.struct_field=NULL; \
+ gamedll.funcs.struct_field = NULL; \
}
// Look for API-NEW interface in Game dll. We do this before API2/API, because
// that's what the engine appears to do..
iface_vers = NEW_DLL_FUNCTIONS_VERSION;
- GET_FUNC_TABLE_FROM_GAME(GameDLL, pfn_getapinew, "GetNewDLLFunctions", newapi_table,
- GETNEWDLLFUNCTIONS_FN, meta_new_dll_functions_t,
- &iface_vers, iface_vers, NEW_DLL_FUNCTIONS_VERSION, found);
+ GET_FUNC_TABLE_FROM_GAME(GameDLL, pfn_getapinew, "GetNewDLLFunctions", newapi_table, GETNEWDLLFUNCTIONS_FN, meta_new_dll_functions_t, &iface_vers, iface_vers, NEW_DLL_FUNCTIONS_VERSION, found);
// Look for API2 interface in plugin; preferred over API-1.
found = 0;
iface_vers = INTERFACE_VERSION;
- GET_FUNC_TABLE_FROM_GAME(GameDLL, pfn_getapi2, "GetEntityAPI2", dllapi_table,
- GETENTITYAPI2_FN, DLL_FUNCTIONS,
- &iface_vers, iface_vers, INTERFACE_VERSION, found);
+ GET_FUNC_TABLE_FROM_GAME(GameDLL, pfn_getapi2, "GetEntityAPI2", dllapi_table, GETENTITYAPI2_FN, DLL_FUNCTIONS, &iface_vers, iface_vers, INTERFACE_VERSION, found);
// Look for API-1 in plugin, if API2 interface wasn't found.
- if (!found) {
+ if (!found)
+ {
found = 0;
- GET_FUNC_TABLE_FROM_GAME(GameDLL, pfn_getapi, "GetEntityAPI", dllapi_table,
- GETENTITYAPI_FN, DLL_FUNCTIONS,
- INTERFACE_VERSION, INTERFACE_VERSION, INTERFACE_VERSION, found);
+ GET_FUNC_TABLE_FROM_GAME(GameDLL, pfn_getapi, "GetEntityAPI", dllapi_table, GETENTITYAPI_FN, DLL_FUNCTIONS, INTERFACE_VERSION, INTERFACE_VERSION, INTERFACE_VERSION, found);
}
// If didn't find either, return failure.
- if (!found) {
+ if (!found)
+ {
META_ERROR("dll: Couldn't find either GetEntityAPI nor GetEntityAPI2 in game DLL '%s'", GameDLL.name);
RETURN_ERRNO(mFALSE, ME_DLMISSING);
}
META_LOG("Game DLL for '%s' loaded successfully", GameDLL.desc);
- return (mTRUE);
+ return mTRUE;
}
diff --git a/metamod/src/metamod.h b/metamod/src/metamod.h
index 4e761fe..d834136 100644
--- a/metamod/src/metamod.h
+++ b/metamod/src/metamod.h
@@ -1,86 +1,50 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// metamod.h - (main) description of metamod operations
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef METAMOD_H
-#define METAMOD_H
+#pragma once
#include "meta_api.h" // META_RES, etc
-#include "mlist.h" // MPluginList, etc
-#include "mreg.h" // MRegCmdList, etc
+#include "mlist.h" // MPluginList, etc
+#include "mreg.h" // MRegCmdList, etc
#include "conf_meta.h" // MConfig
-#include "osdep.h" // NAME_MAX, etc
+#include "osdep.h" // NAME_MAX, etc
#include "types_meta.h" // mBOOL
-#include "mplayer.h" // MPlayerList
-#include "meta_eiface.h" // HL_enginefuncs_t, meta_enginefuncs_t
-#include "engine_t.h" // engine_t, g_engine
+#include "mplayer.h" // MPlayerList
+#include "meta_eiface.h" // HL_enginefuncs_t, meta_enginefuncs_t
+#include "engine_t.h" // engine_t, Engine
// file that lists plugins to load at startup
#define PLUGINS_INI "addons/metamod/plugins.ini"
-#define OLD_PLUGINS_INI "metamod.ini"
+#define OLD_PLUGINS_INI "metamod.ini"
// file that contains commands to metamod plugins at startup
#define EXEC_CFG "addons/metamod/exec.cfg"
-#define OLD_EXEC_CFG "metaexec.cfg"
+#define OLD_EXEC_CFG "metaexec.cfg"
// previously, file that contained path for an override-gamedll
-#define OLD_GAMEDLL_TXT "metagame.ini"
+#define OLD_GAMEDLL_TXT "metagame.ini"
// generic config file
#define CONFIG_INI "addons/metamod/config.ini"
-
// cvar to contain version
extern cvar_t meta_version;
// Info about the game dll/mod.
-typedef struct gamedll_s {
+struct gamedll_t
+{
char name[NAME_MAX]; // ie "cstrike" (from gamedir)
- const char *desc; // ie "Counter-Strike"
+ const char *desc; // ie "Counter-Strike"
char gamedir[PATH_MAX]; // ie "/home/willday/half-life/cstrike"
char pathname[PATH_MAX]; // ie "/home/willday/half-life/cstrike/dlls/cs_i386.so"
- char const *file; // ie "cs_i386.so"
+ char const *file; // ie "cs_i386.so"
char real_pathname[PATH_MAX]; // in case pathname overridden by bot, etc
DLHANDLE handle;
gamedll_funcs_t funcs; // dllapi_table, newapi_table
-} gamedll_t;
+};
+
extern gamedll_t GameDLL;
// SDK variables for storing engine funcs and globals.
extern HL_enginefuncs_t g_engfuncs;
-extern globalvars_t *gpGlobals;
+extern globalvars_t *gpGlobals;
// Our modified version of the engine funcs, to give to plugins.
extern meta_enginefuncs_t g_plugin_engfuncs;
@@ -103,7 +67,7 @@ extern MRegMsgList *g_regMsgs;
#ifdef UNFINISHED
// List of event/logline hooks requested by plugins.
extern MHookList *Hooks;
-#endif /* UNFINISHED */
+#endif
// Data provided to plugins.
// Separate copies to prevent plugins from modifying "readable" parts.
@@ -120,7 +84,7 @@ extern NEW_DLL_FUNCTIONS *pHookedNewDllFunctions;
// engine_api->pfnRunPlayerMove calls dllapi-functions before it returns.
// This causes problems with bots running as metamod plugins, because
// metamod assumed that PublicMetaGlobals is free to be used.
-// With call_count we can fix this by backuping up PublicMetaGlobals if
+// With call_count we can fix this by backuping up PublicMetaGlobals if
// it's already being used.
extern unsigned int CALL_API_count;
@@ -132,12 +96,12 @@ extern int requestid_counter;
// Max players is always 32, small enough that we can use a static array
extern MPlayerList g_Players;
-void metamod_startup(void);
+void metamod_startup();
-mBOOL meta_init_gamedll(void);
-mBOOL meta_load_gamedll(void);
+mBOOL meta_init_gamedll();
+mBOOL meta_load_gamedll();
-// ===== lotsa macros... ======================================================
+// lotsa macros...
// These are the meat of the metamod processing, and are as ugly as (or
// uglier) than they look. This is done via macros, because of the varying
@@ -192,16 +156,16 @@ mBOOL meta_load_gamedll(void);
// accept. Thus there are "_void" versions of the 5 macros; these are
// listed first.
-// ===== macros for void-returning functions ==================================
+// macros for void-returning functions
// declare/init some variables
#define SETUP_API_CALLS_void(FN_TYPE, pfnName, api_info_table) \
int i; \
- META_RES mres=MRES_UNSET, status=MRES_UNSET, prev_mres=MRES_UNSET; \
+ META_RES mres = MRES_UNSET, status = MRES_UNSET, prev_mres = MRES_UNSET; \
MPlugin *iplug; \
- FN_TYPE pfn_routine=NULL; \
- int loglevel=api_info_table.pfnName.loglevel; \
- const char *pfn_string=api_info_table.pfnName.name; \
+ FN_TYPE pfn_routine = NULL; \
+ int loglevel = api_info_table.pfnName.loglevel; \
+ const char *pfn_string = api_info_table.pfnName.name; \
meta_globals_t backup_meta_globals; \
/* fix bug with metamod-bot-plugins (hullu)*/ \
if (CALL_API_count++>0) \
@@ -210,12 +174,12 @@ mBOOL meta_load_gamedll(void);
// call each plugin
#define CALL_PLUGIN_API_void(post, pfnName, pfn_args, api_table) \
- prev_mres=MRES_UNSET; \
- for(i=0; i < g_plugins->endlist; i++) { \
- iplug=&g_plugins->plist[i]; \
+ prev_mres = MRES_UNSET; \
+ for (i = 0; i < g_plugins->endlist; i++) { \
+ iplug = &g_plugins->plist[i]; \
if (iplug->status != PL_RUNNING) \
continue; \
- if(iplug->api_table && (pfn_routine=iplug->api_table->pfnName)); \
+ if (iplug->api_table && (pfn_routine = iplug->api_table->pfnName)); \
else \
/* plugin doesn't provide this function */ \
continue; \
@@ -227,36 +191,36 @@ mBOOL meta_load_gamedll(void);
META_DEBUG(loglevel, ("Calling %s:%s%s()", iplug->file, pfn_string, (post?"_Post":""))); \
pfn_routine pfn_args; \
/* plugin's result code */ \
- mres=PublicMetaGlobals.mres; \
- if(mres > status) \
+ mres = PublicMetaGlobals.mres; \
+ if (mres > status) \
status = mres; \
/* save this for successive plugins to see */ \
prev_mres = mres; \
- if(mres==MRES_UNSET) \
+ if (mres == MRES_UNSET) \
META_ERROR("Plugin didn't set meta_result: %s:%s%s()", iplug->file, pfn_string, (post?"_Post":"")); \
- if(post && mres==MRES_SUPERCEDE) \
+ if (post && mres == MRES_SUPERCEDE) \
META_ERROR("MRES_SUPERCEDE not valid in Post functions: %s:%s%s()", iplug->file, pfn_string, (post?"_Post":"")); \
}
// call "real" function, from gamedll
#define CALL_GAME_API_void(pfnName, pfn_args, api_table) \
CALL_API_count--; \
- if(status==MRES_SUPERCEDE) { \
+ if (status == MRES_SUPERCEDE) { \
META_DEBUG(loglevel, ("Skipped (supercede) %s:%s()", GameDLL.file, pfn_string)); \
/* don't return here; superceded game routine, but still allow \
* _post routines to run. \
*/ \
} \
- else if(GameDLL.funcs.api_table) { \
- pfn_routine=GameDLL.funcs.api_table->pfnName; \
- if(pfn_routine) { \
+ else if (GameDLL.funcs.api_table) { \
+ pfn_routine = GameDLL.funcs.api_table->pfnName; \
+ if (pfn_routine) { \
META_DEBUG(loglevel, ("Calling %s:%s()", GameDLL.file, pfn_string)); \
pfn_routine pfn_args; \
} \
/* don't complain for NULL routines in NEW_DLL_FUNCTIONS */ \
- else if((void*) GameDLL.funcs.api_table != (void*) GameDLL.funcs.newapi_table) { \
+ else if ((void *)GameDLL.funcs.api_table != (void *)GameDLL.funcs.newapi_table) { \
META_ERROR("Couldn't find api call: %s:%s", GameDLL.file, pfn_string); \
- status=MRES_UNSET; \
+ status = MRES_UNSET; \
} \
} \
else { \
@@ -267,21 +231,21 @@ mBOOL meta_load_gamedll(void);
// call "real" function, from engine
#define CALL_ENGINE_API_void(pfnName, pfn_args) \
CALL_API_count--; \
- if(status==MRES_SUPERCEDE) { \
+ if (status == MRES_SUPERCEDE) { \
META_DEBUG(loglevel, ("Skipped (supercede) engine:%s()", pfn_string)); \
/* don't return here; superceded game routine, but still allow \
* _post routines to run. \
*/ \
} \
else { \
- pfn_routine=g_engine.funcs->pfnName; \
- if(pfn_routine) { \
+ pfn_routine = g_engine.funcs->pfnName; \
+ if (pfn_routine) { \
META_DEBUG(loglevel, ("Calling engine:%s()", pfn_string)); \
pfn_routine pfn_args; \
} \
else { \
META_ERROR("Couldn't find api call: engine:%s", pfn_string); \
- status=MRES_UNSET; \
+ status = MRES_UNSET; \
} \
} \
CALL_API_count++;
@@ -294,21 +258,21 @@ mBOOL meta_load_gamedll(void);
return;
-// ===== macros for type-returning functions ==================================
-
+// macros for type-returning functions
// declare/init some variables
+
#define SETUP_API_CALLS(ret_t, ret_init, FN_TYPE, pfnName, api_info_table) \
int i; \
- ret_t dllret=ret_init; \
- ret_t override_ret=ret_init; \
- ret_t pub_override_ret=ret_init; \
- ret_t orig_ret=ret_init; \
- ret_t pub_orig_ret=ret_init; \
- META_RES mres=MRES_UNSET, status=MRES_UNSET, prev_mres=MRES_UNSET; \
+ ret_t dllret = ret_init; \
+ ret_t override_ret = ret_init; \
+ ret_t pub_override_ret = ret_init; \
+ ret_t orig_ret = ret_init; \
+ ret_t pub_orig_ret = ret_init; \
+ META_RES mres = MRES_UNSET, status = MRES_UNSET, prev_mres = MRES_UNSET; \
MPlugin *iplug; \
- FN_TYPE pfn_routine=NULL; \
- int loglevel=api_info_table.pfnName.loglevel; \
- const char *pfn_string=api_info_table.pfnName.name; \
+ FN_TYPE pfn_routine = NULL; \
+ int loglevel = api_info_table.pfnName.loglevel; \
+ const char *pfn_string = api_info_table.pfnName.name; \
meta_globals_t backup_meta_globals; \
/*Fix bug with metamod-bot-plugins*/ \
if (CALL_API_count++>0) \
@@ -317,13 +281,13 @@ mBOOL meta_load_gamedll(void);
// call each plugin
#define CALL_PLUGIN_API(post, ret_init, pfnName, pfn_args, MRES_TYPE, api_table) \
- override_ret=ret_init; \
- prev_mres=MRES_UNSET; \
- for(i=0; i < g_plugins->endlist; i++) { \
+ override_ret = ret_init; \
+ prev_mres = MRES_UNSET; \
+ for (i = 0; i < g_plugins->endlist; i++) { \
if (g_plugins->plist[i].status != PL_RUNNING) \
continue; \
- iplug=&g_plugins->plist[i]; \
- if(iplug->api_table && (pfn_routine=iplug->api_table->pfnName)); \
+ iplug = &g_plugins->plist[i]; \
+ if (iplug->api_table && (pfn_routine = iplug->api_table->pfnName)); \
else \
/* plugin doesn't provide this function */ \
continue; \
@@ -333,31 +297,31 @@ mBOOL meta_load_gamedll(void);
PublicMetaGlobals.status = status; \
pub_orig_ret = orig_ret; \
PublicMetaGlobals.orig_ret = &pub_orig_ret; \
- if(status==MRES_TYPE) { \
+ if (status == MRES_TYPE) { \
pub_override_ret = override_ret; \
PublicMetaGlobals.override_ret = &pub_override_ret; \
} \
/* call plugin */ \
META_DEBUG(loglevel, ("Calling %s:%s%s()", iplug->file, pfn_string, (post?"_Post":""))); \
- dllret=pfn_routine pfn_args; \
+ dllret = pfn_routine pfn_args; \
/* plugin's result code */ \
- mres=PublicMetaGlobals.mres; \
- if(mres > status) \
+ mres = PublicMetaGlobals.mres; \
+ if (mres > status) \
status = mres; \
/* save this for successive plugins to see */ \
prev_mres = mres; \
- if(mres==MRES_TYPE) \
+ if (mres == MRES_TYPE) \
override_ret = pub_override_ret = dllret; \
- else if(mres==MRES_UNSET) \
+ else if (mres == MRES_UNSET) \
META_ERROR("Plugin didn't set meta_result: %s:%s%s()", iplug->file, pfn_string, (post?"_Post":"")); \
- else if(post && mres==MRES_SUPERCEDE) \
+ else if (post && mres == MRES_SUPERCEDE) \
META_ERROR("MRES_SUPERCEDE not valid in Post functions: %s:%s%s()", iplug->file, pfn_string, (post?"_Post":"")); \
}
// call "real" function, from gamedll
#define CALL_GAME_API(pfnName, pfn_args, api_table) \
CALL_API_count--; \
- if(status==MRES_SUPERCEDE) { \
+ if (status == MRES_SUPERCEDE) { \
META_DEBUG(loglevel, ("Skipped (supercede) %s:%s()", GameDLL.file, pfn_string)); \
orig_ret = pub_orig_ret = override_ret; \
PublicMetaGlobals.orig_ret = &pub_orig_ret; \
@@ -365,17 +329,17 @@ mBOOL meta_load_gamedll(void);
* _post routines to run. \
*/ \
} \
- else if(GameDLL.funcs.api_table) { \
- pfn_routine=GameDLL.funcs.api_table->pfnName; \
- if(pfn_routine) { \
+ else if (GameDLL.funcs.api_table) { \
+ pfn_routine = GameDLL.funcs.api_table->pfnName; \
+ if (pfn_routine) { \
META_DEBUG(loglevel, ("Calling %s:%s()", GameDLL.file, pfn_string)); \
- dllret=pfn_routine pfn_args; \
+ dllret = pfn_routine pfn_args; \
orig_ret = dllret; \
} \
/* don't complain for NULL routines in NEW_DLL_FUNCTIONS */ \
- else if((void*) GameDLL.funcs.api_table != (void*) GameDLL.funcs.newapi_table) { \
+ else if ((void *)GameDLL.funcs.api_table != (void *)GameDLL.funcs.newapi_table) { \
META_ERROR("Couldn't find api call: %s:%s", GameDLL.file, pfn_string); \
- status=MRES_UNSET; \
+ status = MRES_UNSET; \
} \
} \
else { \
@@ -386,7 +350,7 @@ mBOOL meta_load_gamedll(void);
// call "real" function, from engine
#define CALL_ENGINE_API(pfnName, pfn_args) \
CALL_API_count--; \
- if(status==MRES_SUPERCEDE) { \
+ if (status == MRES_SUPERCEDE) { \
META_DEBUG(loglevel, ("Skipped (supercede) engine:%s()", pfn_string)); \
orig_ret = pub_orig_ret = override_ret; \
PublicMetaGlobals.orig_ret = &pub_orig_ret; \
@@ -395,15 +359,15 @@ mBOOL meta_load_gamedll(void);
*/ \
} \
else { \
- pfn_routine=g_engine.funcs->pfnName; \
- if(pfn_routine) { \
+ pfn_routine = g_engine.funcs->pfnName; \
+ if (pfn_routine) { \
META_DEBUG(loglevel, ("Calling engine:%s()", pfn_string)); \
- dllret=pfn_routine pfn_args; \
+ dllret = pfn_routine pfn_args; \
orig_ret = dllret; \
} \
else { \
META_ERROR("Couldn't find api call: engine:%s", pfn_string); \
- status=MRES_UNSET; \
+ status = MRES_UNSET; \
} \
} \
CALL_API_count++;
@@ -413,14 +377,9 @@ mBOOL meta_load_gamedll(void);
if (--CALL_API_count>0) \
/*Restore backup*/ \
PublicMetaGlobals = backup_meta_globals; \
- if(status==MRES_OVERRIDE) { \
+ if (status == MRES_OVERRIDE) { \
META_DEBUG(loglevel, ("Returning (override) %s()", pfn_string)); \
- return(override_ret); \
+ return override_ret; \
} \
else \
- return(orig_ret);
-
-// ===== end macros ===========================================================
-
-
-#endif /* METAMOD_H */
+ return orig_ret;
diff --git a/metamod/src/mlist.cpp b/metamod/src/mlist.cpp
index 546f9f1..c677759 100644
--- a/metamod/src/mlist.cpp
+++ b/metamod/src/mlist.cpp
@@ -1,53 +1,19 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// mlist.cpp - functions for list of plugins (class MPluginList)
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// Constructor
MPluginList::MPluginList(const char* ifile) : size(MAX_PLUGINS), endlist(0)
{
// store filename of ini file
- strncpy(inifile, ifile, sizeof inifile - 1);
+ Q_strncpy(inifile, ifile, sizeof inifile - 1);
inifile[sizeof inifile - 1] = '\0';
// initialize array
- memset(plist, 0, sizeof(plist));
- for (int i = 0; i < size; i++) {
+ Q_memset(plist, 0, sizeof(plist));
+ for (int i = 0; i < size; i++)
+ {
plist[i].index = i + 1; // 1-based
}
+
endlist = 0;
}
@@ -55,12 +21,13 @@ MPluginList::MPluginList(const char* ifile) : size(MAX_PLUGINS), endlist(0)
// meta_errno values:
// - ME_ARGUMENT invalid pindex
// - ME_NOTFOUND couldn't find a matching plugin
-MPlugin* MPluginList::find(DLHANDLE handle)
+MPlugin *MPluginList::find(DLHANDLE handle)
{
if (!handle)
RETURN_ERRNO(NULL, ME_ARGUMENT);
- for (int i = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
if (plist[i].status < PL_VALID)
continue;
if (plist[i].handle == handle)
@@ -74,7 +41,7 @@ MPlugin* MPluginList::find(DLHANDLE handle)
// meta_errno values:
// - ME_ARGUMENT invalid pindex
// - ME_NOTFOUND couldn't find a matching plugin
-MPlugin* MPluginList::find(int pindex)
+MPlugin *MPluginList::find(int pindex)
{
if (pindex <= 0)
RETURN_ERRNO(NULL, ME_ARGUMENT);
@@ -90,14 +57,16 @@ MPlugin* MPluginList::find(int pindex)
// meta_errno values:
// - ME_ARGUMENT null plid_t
// - ME_NOTFOUND couldn't find a matching plugin
-MPlugin* MPluginList::find(plid_t id)
+MPlugin *MPluginList::find(plid_t id)
{
if (!id)
RETURN_ERRNO(NULL, ME_ARGUMENT);
- for (int i = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
if (plist[i].status < PL_VALID)
continue;
+
if (plist[i].info == id)
return &plist[i];
}
@@ -109,19 +78,22 @@ MPlugin* MPluginList::find(plid_t id)
// meta_errno values:
// - ME_ARGUMENT null path
// - ME_NOTFOUND couldn't find a matching plugin
-MPlugin* MPluginList::find(const char* findpath)
+MPlugin *MPluginList::find(const char* findpath)
{
if (!findpath)
RETURN_ERRNO(NULL, ME_ARGUMENT);
META_DEBUG(8, ("Looking for loaded plugin with dlfnamepath: %s", findpath));
- for (int i = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
META_DEBUG(9, ("Looking at: plugin %s loadedpath: %s", plist[i].file, plist[i].pathname));
if (plist[i].status < PL_VALID)
continue;
- if (!strcmp(plist[i].pathname, findpath)) {
+
+ if (!Q_strcmp(plist[i].pathname, findpath))
+ {
META_DEBUG(8, ("Found loaded plugin %s", plist[i].file));
return &plist[i];
}
@@ -136,104 +108,125 @@ MPlugin* MPluginList::find(const char* findpath)
// - ME_ARGUMENT null memptr
// - ME_NOTFOUND couldn't find a matching plugin
// - errno's from DLFNAME()
-MPlugin* MPluginList::find_memloc(void* memptr)
+MPlugin *MPluginList::find_memloc(void *memptr)
{
const char* dlfile;
if (!memptr)
RETURN_ERRNO(NULL, ME_ARGUMENT);
- if (!(dlfile = DLFNAME(memptr))) {
+ if (!(dlfile = DLFNAME(memptr)))
+ {
META_DEBUG(8, ("DLFNAME failed to find memloc %d", memptr));
// meta_errno should be already set in DLFNAME
return NULL;
}
+
return find(dlfile);
}
-// Find a plugin with non-ambiguous prefix string matching desc, file,
+// Find a plugin with non-ambiguous prefix string matching desc, file,
// name, or logtag.
// meta_errno values:
// - ME_ARGUMENT null prefix
// - ME_NOTFOUND couldn't find a matching plugin
// - ME_NOTUNIQ found multiple matches; no unique match
-MPlugin* MPluginList::find_match(const char* prefix)
+MPlugin *MPluginList::find_match(const char *prefix)
{
int i, len;
MPlugin *iplug, *pfound;
char buf[NAME_MAX ];
if (!prefix)
- RETURN_ERRNO(NULL, ME_ARGUMENT);
+ {
+ RETURN_ERRNO(NULL, ME_ARGUMENT);
+ }
+
pfound = NULL;
- len = strlen(prefix);
- snprintf(buf, sizeof(buf), "mm_%s", prefix);
- for (i = 0; i < endlist; i++) {
+ len = Q_strlen(prefix);
+ Q_snprintf(buf, sizeof(buf), "mm_%s", prefix);
+ for (i = 0; i < endlist; i++)
+ {
iplug = &plist[i];
if (iplug->status < PL_VALID)
continue;
- if (iplug->info && _strnicmp(iplug->info->name, prefix, len) == 0) {
+
+ if (iplug->info && Q_strnicmp(iplug->info->name, prefix, len) == 0)
+ {
if (pfound)
- RETURN_ERRNO(NULL, ME_NOTUNIQ);
+ RETURN_ERRNO(NULL, ME_NOTUNIQ);
+
pfound = iplug;
continue;
}
- else if (_strnicmp(iplug->desc, prefix, len) == 0) {
+ else if (Q_strnicmp(iplug->desc, prefix, len) == 0)
+ {
if (pfound)
- RETURN_ERRNO(NULL, ME_NOTUNIQ);
+ RETURN_ERRNO(NULL, ME_NOTUNIQ);
+
pfound = iplug;
continue;
}
- else if (_strnicmp(iplug->file, prefix, len) == 0) {
+ else if (Q_strnicmp(iplug->file, prefix, len) == 0)
+ {
if (pfound)
- RETURN_ERRNO(NULL, ME_NOTUNIQ);
+ RETURN_ERRNO(NULL, ME_NOTUNIQ);
+
pfound = iplug;
continue;
}
- else if (_strnicmp(iplug->file, buf, strlen(buf)) == 0) {
+ else if (Q_strnicmp(iplug->file, buf, Q_strlen(buf)) == 0)
+ {
if (pfound)
- RETURN_ERRNO(NULL, ME_NOTUNIQ);
+ RETURN_ERRNO(NULL, ME_NOTUNIQ);
+
pfound = iplug;
continue;
}
- else if (iplug->info
- && _strnicmp(iplug->info->logtag, prefix, len) == 0) {
+ else if (iplug->info && Q_strnicmp(iplug->info->logtag, prefix, len) == 0)
+ {
if (pfound)
- RETURN_ERRNO(NULL, ME_NOTUNIQ);
+ RETURN_ERRNO(NULL, ME_NOTUNIQ);
+
pfound = iplug;
continue;
}
}
+
if (pfound)
- return (pfound);
- else
+ return pfound;
+
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
-
-// Find a plugin with same file, logtag, desc or significant
+// Find a plugin with same file, logtag, desc or significant
// prefix of file. Uses the platform_match() method of MPlugin.
// meta_errno values:
// - ME_ARGUMENT null prefix
// - ME_NOTFOUND couldn't find a matching plugin
-MPlugin* MPluginList::find_match(MPlugin* pmatch)
+MPlugin *MPluginList::find_match(MPlugin* pmatch)
{
int i;
MPlugin *iplug, *pfound;
if (!pmatch)
- RETURN_ERRNO(NULL, ME_ARGUMENT);
+ {
+ RETURN_ERRNO(NULL, ME_ARGUMENT);
+ }
+
pfound = NULL;
- for (i = 0; i < endlist; i++) {
+ for (i = 0; i < endlist; i++)
+ {
iplug = &plist[i];
- if (pmatch->platform_match(iplug)) {
+ if (pmatch->platform_match(iplug))
+ {
pfound = iplug;
break;
}
}
if (pfound)
- return (pfound);
- else
+ return pfound;
+
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
@@ -242,44 +235,52 @@ MPlugin* MPluginList::plugin_addload(plid_t plid, const char* fname, PLUG_LOADTI
MPlugin pl_temp;
MPlugin *pl_found, *pl_added, *pl_loader;
- if (!(pl_loader = find(plid))) {
+ if (!(pl_loader = find(plid)))
+ {
META_DEBUG(1, ("Couldn't find plugin that gave this loading request!"));
RETURN_ERRNO(NULL, ME_BADREQ);
}
- memset(&pl_temp, 0, sizeof(pl_temp));
+ Q_memset(&pl_temp, 0, sizeof(pl_temp));
- if (!pl_temp.plugin_parseline(fname, pl_loader->index)) {
+ if (!pl_temp.plugin_parseline(fname, pl_loader->index))
+ {
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
- if (pl_temp.resolve() != mTRUE) {
+ if (pl_temp.resolve() != mTRUE)
+ {
META_DEBUG(1, ("Couldn't resolve given path into a file: %s", pl_temp.file));
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
- if ((pl_found = find(pl_temp.pathname))) {
+ if ((pl_found = find(pl_temp.pathname)))
+ {
META_DEBUG(1, ("Plugin '%s' already in current list; file=%s desc='%s'",
pl_temp.file, pl_found->file, pl_found->desc));
RETURN_ERRNO(NULL, ME_ALREADY);
}
- if (!(pl_added = add(&pl_temp))) {
+ if (!(pl_added = add(&pl_temp)))
+ {
META_DEBUG(1, ("Couldn't add plugin '%s' to list; see log", pl_temp.desc));
return NULL;
}
pl_added->action = PA_LOAD;
- if (!pl_added->load(now)) {
- if (meta_errno == ME_NOTALLOWED || meta_errno == ME_DELAYED) {
- META_DEBUG(1, ("Plugin '%s' couldn't attach; only allowed %s",
- pl_added->desc, pl_added->str_loadable(SL_ALLOWED)));
+ if (!pl_added->load(now))
+ {
+ if (meta_errno == ME_NOTALLOWED || meta_errno == ME_DELAYED)
+ {
+ META_DEBUG(1, ("Plugin '%s' couldn't attach; only allowed %s", pl_added->desc, pl_added->str_loadable(SL_ALLOWED)));
pl_added->clear();
}
- else if (pl_added->status == PL_OPENED) {
+ else if (pl_added->status == PL_OPENED)
+ {
META_DEBUG(1, ("Opened plugin '%s', but failed to attach; see log", pl_added->desc));
}
- else {
+ else
+ {
META_DEBUG(1, ("Couldn't load plugin '%s'; see log", pl_added->desc));
}
return NULL;
@@ -305,34 +306,41 @@ MPlugin* MPluginList::add(MPlugin* padd)
for (i = 0; i < endlist && plist[i].status != PL_EMPTY; i++);
// couldn't find a slot to use
- if (i == size) {
- META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)",
- padd->file, i);
+ if (i == size)
+ {
+ META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)", padd->file, i);
RETURN_ERRNO(NULL, ME_MAXREACHED);
}
// if we found the end of the list, advance end marker
if (i == endlist)
endlist++;
+
iplug = &plist[i];
// copy filename into this free slot
- strncpy(iplug->filename, padd->filename, sizeof iplug->filename - 1);
+ Q_strncpy(iplug->filename, padd->filename, sizeof iplug->filename - 1);
iplug->filename[sizeof iplug->filename - 1] = '\0';
+
// Copy file offset ptr.
// Can't just copy ptr, as it points to offset in padd, which will go
// away; need to point to corresponding offset in iplug.
iplug->file = iplug->filename + (padd->file - padd->filename);
+
// copy description
- strncpy(iplug->desc, padd->desc, sizeof iplug->desc - 1);
+ Q_strncpy(iplug->desc, padd->desc, sizeof iplug->desc - 1);
iplug->desc[sizeof iplug->desc - 1] = '\0';
+
// copy pathname
- strncpy(iplug->pathname, padd->pathname, sizeof iplug->pathname - 1);
+ Q_strncpy(iplug->pathname, padd->pathname, sizeof iplug->pathname - 1);
iplug->pathname[sizeof iplug->pathname - 1] = '\0';
+
// copy source
iplug->source = padd->source;
+
// copy status
iplug->status = padd->status;
+
//copy other things
iplug->source_plugin_index = padd->source_plugin_index;
@@ -345,60 +353,66 @@ MPlugin* MPluginList::add(MPlugin* padd)
// - ME_NOFILE ini file missing or empty
mBOOL MPluginList::ini_startup()
{
- FILE* fp;
+ FILE *fp;
char line[MAX_STRBUF_LEN];
int n, ln;
- MPlugin* pmatch;
+ MPlugin *pmatch;
- if (!valid_gamedir_file(inifile)) {
+ if (!valid_gamedir_file(inifile))
+ {
META_ERROR("ini: Metamod plugins file empty or missing: %s", inifile);
RETURN_ERRNO(mFALSE, ME_NOFILE);
}
- full_gamedir_path(inifile, inifile);
+ full_gamedir_path(inifile, inifile);
fp = fopen(inifile, "r");
- if (!fp) {
- META_ERROR("ini: Unable to open plugins file '%s': %s", inifile,
- strerror(errno));
+ if (!fp)
+ {
+ META_ERROR("ini: Unable to open plugins file '%s': %s", inifile, strerror(errno));
RETURN_ERRNO(mFALSE, ME_NOFILE);
}
META_LOG("ini: Begin reading plugins list: %s", inifile);
- for (n = 0 , ln = 1;
- !feof(fp) && fgets(line, sizeof(line), fp) && n < size;
- ln++) {
+ for (n = 0 , ln = 1; !feof(fp) && fgets(line, sizeof(line), fp) && n < size; ln++)
+ {
// Remove line terminations.
char* cp;
- if ((cp = strrchr(line, '\r')))
+ if ((cp = Q_strrchr(line, '\r')))
*cp = '\0';
- if ((cp = strrchr(line, '\n')))
+
+ if ((cp = Q_strrchr(line, '\n')))
*cp = '\0';
+
// Parse directly into next entry in array
- if (!plist[n].ini_parseline(line)) {
+ if (!plist[n].ini_parseline(line))
+ {
if (meta_errno == ME_FORMAT)
- META_ERROR("ini: Skipping malformed line %d of %s", ln,
- inifile);
+ {
+ META_ERROR("ini: Skipping malformed line %d of %s", ln, inifile);
+ }
continue;
}
// Check for a duplicate - an existing entry with this pathname.
- if (find(plist[n].pathname)) {
+ if (find(plist[n].pathname))
+ {
// Should we check platform specific level here?
- META_INFO("ini: Skipping duplicate plugin, line %d of %s: %s",
- ln, inifile, plist[n].pathname);
+ META_INFO("ini: Skipping duplicate plugin, line %d of %s: %s", ln, inifile, plist[n].pathname);
continue;
}
+
// Check for a matching platform with different platform specifics
// level.
- if (NULL != (pmatch = find_match(&plist[n]))) {
- if (pmatch->pfspecific >= plist[n].pfspecific) {
- META_DEBUG(1, ("ini: Skipping plugin, line %d of %s: plugin with higher platform specific level already exists. (%d >= %d)",
- ln, inifile, pmatch->pfspecific, plist[n].pfspecific));
+ if (NULL != (pmatch = find_match(&plist[n])))
+ {
+ if (pmatch->pfspecific >= plist[n].pfspecific)
+ {
+ META_DEBUG(1, ("ini: Skipping plugin, line %d of %s: plugin with higher platform specific level already exists. (%d >= %d)", ln, inifile, pmatch->pfspecific, plist[n].pfspecific));
continue;
}
- META_DEBUG(1, ("ini: Plugin in line %d overrides existing plugin with lower platform specific level %d, ours %d",
- ln, pmatch->pfspecific, plist[n].pfspecific));
+
+ META_DEBUG(1, ("ini: Plugin in line %d overrides existing plugin with lower platform specific level %d, ours %d", ln, pmatch->pfspecific, plist[n].pfspecific));
int _index = pmatch->index;
- memset(pmatch, 0, sizeof(MPlugin));
+ Q_memset(pmatch, 0, sizeof(MPlugin));
pmatch->index = _index;
}
plist[n].action = PA_LOAD;
@@ -406,14 +420,15 @@ mBOOL MPluginList::ini_startup()
n++;
endlist = n; // mark end of list
}
- META_LOG("ini: Finished reading plugins list: %s; Found %d plugins to load",
- inifile, n);
+ META_LOG("ini: Finished reading plugins list: %s; Found %d plugins to load", inifile, n);
fclose(fp);
- if (!n) {
+ if (!n)
+ {
META_ERROR("ini: Warning; no plugins found to load?");
}
- return (mTRUE);
+
+ return mTRUE;
}
// Re-read plugins.ini looking for added/deleted/changed plugins.
@@ -421,63 +436,69 @@ mBOOL MPluginList::ini_startup()
// - ME_NOFILE ini file missing or empty
mBOOL MPluginList::ini_refresh()
{
- FILE* fp;
+ FILE *fp;
char line[MAX_STRBUF_LEN];
int n, ln;
MPlugin pl_temp;
MPlugin *pl_found, *pl_added;
fp = fopen(inifile, "r");
- if (!fp) {
- META_ERROR("ini: Unable to open plugins file '%s': %s", inifile,
- strerror(errno));
+ if (!fp)
+ {
+ META_ERROR("ini: Unable to open plugins file '%s': %s", inifile, strerror(errno));
RETURN_ERRNO(mFALSE, ME_NOFILE);
}
META_LOG("ini: Begin re-reading plugins list: %s", inifile);
- for (n = 0 , ln = 1;
- !feof(fp) && fgets(line, sizeof(line), fp) && n < size;
- ln++) {
+ for (n = 0 , ln = 1; !feof(fp) && fgets(line, sizeof(line), fp) && n < size; ln++)
+ {
// Remove line terminations.
- char* cp;
- if ((cp = strrchr(line, '\r')))
+ char *cp;
+ if ((cp = Q_strrchr(line, '\r')))
*cp = '\0';
- if ((cp = strrchr(line, '\n')))
+
+ if ((cp = Q_strrchr(line, '\n')))
*cp = '\0';
+
// Parse into a temp plugin
- memset(&pl_temp, 0, sizeof(pl_temp));
- if (!pl_temp.ini_parseline(line)) {
+ Q_memset(&pl_temp, 0, sizeof(pl_temp));
+ if (!pl_temp.ini_parseline(line))
+ {
if (meta_errno == ME_FORMAT)
- META_ERROR("ini: Skipping malformed line %d of %s",
- ln, inifile);
+ {
+ META_ERROR("ini: Skipping malformed line %d of %s",ln, inifile);
+ }
continue;
}
// Try to find plugin with this pathname in the current list of
// plugins.
- if (!(pl_found = find(pl_temp.pathname))) {
+ if (!(pl_found = find(pl_temp.pathname)))
+ {
// Check for a matching platform with higher platform specifics
// level.
- if (NULL != (pl_found = find_match(&pl_temp))) {
- if (pl_found->pfspecific >= pl_temp.pfspecific) {
- META_DEBUG(1, ("ini: Skipping plugin, line %d of %s: plugin with higher platform specific level already exists. (%d >= %d)",
- ln, inifile, pl_found->pfspecific, pl_temp.pfspecific));
+ if (NULL != (pl_found = find_match(&pl_temp)))
+ {
+ if (pl_found->pfspecific >= pl_temp.pfspecific)
+ {
+ META_DEBUG(1, ("ini: Skipping plugin, line %d of %s: plugin with higher platform specific level already exists. (%d >= %d)", ln, inifile, pl_found->pfspecific, pl_temp.pfspecific));
continue;
}
- if (PA_LOAD == pl_found->action) {
- META_DEBUG(1, ("ini: Plugin in line %d overrides loading of plugin with lower platform specific level %d, ours %d",
- ln, pl_found->pfspecific, pl_temp.pfspecific));
+ if (PA_LOAD == pl_found->action)
+ {
+ META_DEBUG(1, ("ini: Plugin in line %d overrides loading of plugin with lower platform specific level %d, ours %d", ln, pl_found->pfspecific, pl_temp.pfspecific));
int _index = pl_found->index;
- memset(pl_found, 0, sizeof(MPlugin));
+ Q_memset(pl_found, 0, sizeof(MPlugin));
pl_found->index = _index;
}
- else {
- META_DEBUG(1, ("ini: Plugin in line %d should override existing plugin with lower platform specific level %d, ours %d. Unable to comply.",
- ln, pl_found->pfspecific, pl_temp.pfspecific));
+ else
+ {
+ META_DEBUG(1, ("ini: Plugin in line %d should override existing plugin with lower platform specific level %d, ours %d. Unable to comply.", ln, pl_found->pfspecific, pl_temp.pfspecific));
continue;
}
}
// new plugin; add to list
- if ((pl_added = add(&pl_temp))) {
+ if ((pl_added = add(&pl_temp)))
+ {
// try to load this plugin at the next opportunity
pl_added->action = PA_LOAD;
}
@@ -485,42 +506,49 @@ mBOOL MPluginList::ini_refresh()
// error details logged in add()
continue;
}
- else {
+ else
+ {
// This plugin is already in the current list of plugins.
// Pathname already matches. Recopy desc, if specified in
// plugins.ini.
- if (pl_temp.desc[0] != '<') {
- strncpy(pl_found->desc, pl_temp.desc, sizeof pl_found->desc - 1);
+ if (pl_temp.desc[0] != '<')
+ {
+ Q_strncpy(pl_found->desc, pl_temp.desc, sizeof pl_found->desc - 1);
pl_found->desc[sizeof pl_found->desc - 1] = '\0';
}
// Check the file to see if it looks like it's been modified
// since we last loaded it.
- if (!pl_found->newer_file()) {
- if (meta_errno == ME_NOFILE) {
- META_ERROR("ini: Skipping plugin, couldn't stat file '%s': %s",
- pl_found->pathname, strerror(errno));
+ if (!pl_found->newer_file())
+ {
+ if (meta_errno == ME_NOFILE)
+ {
+ META_ERROR("ini: Skipping plugin, couldn't stat file '%s': %s", pl_found->pathname, strerror(errno));
continue;
}
- else {
+ else
+ {
// File hasn't been updated.
// Keep plugin (don't let refresh() unload it).
pl_found->action = PA_KEEP;
}
}
// Newer file on disk.
- else if (pl_found->status >= PL_OPENED) {
+ else if (pl_found->status >= PL_OPENED)
+ {
META_DEBUG(2, ("ini: Plugin '%s' has newer file on disk", pl_found->desc));
pl_found->action = PA_RELOAD;
}
else
- META_ERROR("ini: Plugin '%s' has newer file, but unexpected status (%s)",
- pl_found->desc, pl_found->str_status());
+ META_ERROR("ini: Plugin '%s' has newer file, but unexpected status (%s)", pl_found->desc, pl_found->str_status());
}
- if (NULL != pl_found) {
+
+ if (pl_found)
+ {
META_LOG("ini: Read plugin config for: %s", pl_found->desc);
}
- else {
+ else
+ {
META_LOG("ini: Read plugin config for: %s", pl_temp.desc);
}
n++;
@@ -528,10 +556,12 @@ mBOOL MPluginList::ini_refresh()
META_LOG("ini: Finished reading plugins list: %s; Found %d plugins", inifile, n);
fclose(fp);
- if (!n) {
+ if (!n)
+ {
META_ERROR("ini: Warning; no plugins found to load?");
}
- return (mTRUE);
+
+ return mTRUE;
}
// Load a plugin from a console command.
@@ -549,61 +579,66 @@ mBOOL MPluginList::cmd_addload(const char* args)
// XXX move back to comands_meta ?
// parse into a temp plugin
- memset(&pl_temp, 0, sizeof(pl_temp));
- if (pl_temp.cmd_parseline(args) != mTRUE) {
+ Q_memset(&pl_temp, 0, sizeof(pl_temp));
+ if (pl_temp.cmd_parseline(args) != mTRUE)
+ {
META_CONS("Couldn't parse 'meta load' arguments: %s", args);
// meta_errno should be already set in cmd_parseline()
- return (mFALSE);
+ return mFALSE;
}
// resolve given path into a file; accepts various "shortcut"
// pathnames.
- if (pl_temp.resolve() != mTRUE) {
+ if (pl_temp.resolve() != mTRUE)
+ {
// Couldn't find a matching file on disk
- META_CONS("Couldn't resolve given path into a file: %s",
- pl_temp.file);
+ META_CONS("Couldn't resolve given path into a file: %s", pl_temp.file);
// meta_errno should be already set in resolve()
- return (mFALSE);
+ return mFALSE;
}
// Try to find plugin with this pathname in the current list of
// plugins.
- if ((pl_found = find(pl_temp.pathname))) {
+ if ((pl_found = find(pl_temp.pathname)))
+ {
// Already in list
- META_CONS("Plugin '%s' already in current list; file=%s desc='%s'",
- pl_temp.file, pl_found->file, pl_found->desc);
+ META_CONS("Plugin '%s' already in current list; file=%s desc='%s'", pl_temp.file, pl_found->file, pl_found->desc);
RETURN_ERRNO(mFALSE, ME_ALREADY);
}
// new plugin; add to list
- if (!(pl_added = add(&pl_temp))) {
+ if (!(pl_added = add(&pl_temp)))
+ {
META_CONS("Couldn't add plugin '%s' to list; see log", pl_temp.desc);
// meta_errno should be already set in add()
- return (mFALSE);
+ return mFALSE;
}
// try to load new plugin
pl_added->action = PA_LOAD;
- if (!pl_added->load(PT_ANYTIME)) {
+ if (!pl_added->load(PT_ANYTIME))
+ {
// load failed
if (meta_errno == ME_DELAYED)
- META_CONS("Loaded plugin '%s', but will wait to become active, %s",
- pl_added->desc, pl_added->str_loadable(SL_ALLOWED));
- else if (meta_errno == ME_NOTALLOWED) {
- META_CONS("Plugin '%s' couldn't attach; only allowed %s",
- pl_added->desc, pl_added->str_loadable(SL_ALLOWED));
+ META_CONS("Loaded plugin '%s', but will wait to become active, %s", pl_added->desc, pl_added->str_loadable(SL_ALLOWED));
+ else if (meta_errno == ME_NOTALLOWED)
+ {
+ META_CONS("Plugin '%s' couldn't attach; only allowed %s", pl_added->desc, pl_added->str_loadable(SL_ALLOWED));
pl_added->clear();
}
else if (pl_added->status == PL_OPENED)
META_CONS("Opened plugin '%s', but failed to attach; see log", pl_added->desc);
else
META_CONS("Couldn't load plugin '%s'; see log", pl_added->desc);
+
show(0);
// meta_errno should be already set in load()
- return (mFALSE);
+ return mFALSE;
}
+
META_CONS("Loaded plugin '%s' successfully", pl_added->desc);
show(0);
- return (mTRUE);
+
+ return mTRUE;
}
// Load plugins at startup.
@@ -611,26 +646,29 @@ mBOOL MPluginList::cmd_addload(const char* args)
// - errno's from ini_startup()
mBOOL MPluginList::load()
{
- int i, n;
-
- if (!ini_startup()) {
+ int n = 0;
+ if (!ini_startup())
+ {
META_ERROR("Problem loading plugins.ini: %s", inifile);
// meta_errno should be already set in ini_startup()
- return (mFALSE);
+ return mFALSE;
}
META_LOG("dll: Loading plugins...");
- for (i = 0 , n = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
if (plist[i].status < PL_VALID)
continue;
+
if (plist[i].load(PT_STARTUP) == mTRUE)
n++;
else
- // all plugins should be loadable at startup...
+ // all plugins should be loadable at startup...
META_ERROR("dll: Failed to load plugin '%s'", plist[i].file);
}
+
META_LOG("dll: Finished loading %d plugins", n);
- return (mTRUE);
+ return mTRUE;
}
// Update list of loaded plugins from ini file, and load any new/changed plugins.
@@ -641,18 +679,22 @@ mBOOL MPluginList::refresh(PLUG_LOADTIME now)
int i, ndone = 0, nkept = 0, nloaded = 0, nunloaded = 0, nreloaded = 0, ndelayed = 0;
MPlugin* iplug;
- if (!ini_refresh()) {
+ if (!ini_refresh())
+ {
META_ERROR("dll: Problem reloading plugins.ini: %s", inifile);
// meta_errno should be already set in ini_refresh()
- return (mFALSE);
+ return mFALSE;
}
META_LOG("dll: Updating plugins...");
- for (i = 0; i < endlist; i++) {
+ for (i = 0; i < endlist; i++)
+ {
iplug = &plist[i];
if (iplug->status < PL_VALID)
continue;
- switch (iplug->action) {
+
+ switch (iplug->action)
+ {
case PA_KEEP:
META_DEBUG(1, ("Keeping plugin '%s'", iplug->desc));
iplug->action = PA_NONE;
@@ -674,7 +716,8 @@ mBOOL MPluginList::refresh(PLUG_LOADTIME now)
break;
case PA_NONE:
// If previously loaded from ini, but apparently removed from new ini.
- if (iplug->source == PS_INI && iplug->status >= PL_RUNNING) {
+ if (iplug->source == PS_INI && iplug->status >= PL_RUNNING)
+ {
META_DEBUG(1, ("Unloading plugin '%s'", iplug->desc));
iplug->action = PA_UNLOAD;
if (iplug->unload(now, PNL_INI_DELETED, PNL_INI_DELETED))
@@ -708,9 +751,9 @@ mBOOL MPluginList::refresh(PLUG_LOADTIME now)
}
ndone++;
}
- META_LOG("dll: Finished updating %d plugins; kept %d, loaded %d, unloaded %d, reloaded %d, delayed %d",
- ndone, nkept, nloaded, nunloaded, nreloaded, ndelayed);
- return (mTRUE);
+
+ META_LOG("dll: Finished updating %d plugins; kept %d, loaded %d, unloaded %d, reloaded %d, delayed %d", ndone, nkept, nloaded, nunloaded, nreloaded, ndelayed);
+ return mTRUE;
}
// Re-enable any plugins currently paused.
@@ -718,10 +761,9 @@ mBOOL MPluginList::refresh(PLUG_LOADTIME now)
// - none
void MPluginList::unpause_all(void)
{
- int i;
- MPlugin* iplug;
- for (i = 0; i < endlist; i++) {
- iplug = &plist[i];
+ for (int i = 0; i < endlist; i++)
+ {
+ auto iplug = &plist[i];
if (iplug->status == PL_PAUSED)
iplug->unpause();
}
@@ -733,10 +775,9 @@ void MPluginList::unpause_all(void)
// - none
void MPluginList::retry_all(PLUG_LOADTIME now)
{
- int i;
- MPlugin* iplug;
- for (i = 0; i < endlist; i++) {
- iplug = &plist[i];
+ for (int i = 0; i < endlist; i++)
+ {
+ auto iplug = &plist[i];
if (iplug->action != PA_NONE)
iplug->retry(now, PNL_DELAYED);
}
@@ -747,91 +788,97 @@ void MPluginList::retry_all(PLUG_LOADTIME now)
// - none
void MPluginList::show(int source_index)
{
- int i, n = 0, r = 0;
- MPlugin* pl;
- char desc[15 + 1], file[16 + 1], vers[7 + 1]; // plus 1 for term null
+ int n = 0, r = 0;
+ MPlugin *pl;
+ char desc[15 + 1], file[16 + 1], vers[7 + 1]; // plus 1 for term null
if (source_index <= 0)
META_CONS("Currently loaded plugins:");
else
META_CONS("Child plugins:");
- META_CONS(" %*s %-*s %-4s %-4s %-*s v%-*s %-3s %-5s %-5s",
- WIDTH_MAX_PLUGINS, "",
- sizeof(desc) - 1, "description",
- "stat", "pend",
- sizeof(file) - 1, "file", sizeof(vers) - 1, "ers",
- "src", "load ", "unlod");
- for (i = 0; i < endlist; i++) {
+ META_CONS(" %*s %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, "", sizeof(desc) - 1, "description", "stat", "pend",
+ sizeof(file) - 1, "file", sizeof(vers) - 1, "ers", 2 + WIDTH_MAX_PLUGINS, "src", "load ", "unlod");
+
+ for (int i = 0; i < endlist; i++)
+ {
pl = &plist[i];
if (pl->status < PL_VALID)
continue;
- if ((source_index > 0) && (pl->source_plugin_index != source_index))
+
+ if (source_index > 0 && pl->source_plugin_index != source_index)
continue;
- strncpy(desc, pl->desc, sizeof desc - 1);
- desc[sizeof desc - 1] = '\0';
- strncpy(file, pl->file, sizeof file - 1);
- file[sizeof file - 1] = '\0';
- if (pl->info && pl->info->version) {
- strncpy(vers, pl->info->version, sizeof vers - 1);
- vers[sizeof vers - 1] = '\0';
+
+ Q_strncpy(desc, pl->desc, sizeof(desc) - 1);
+ desc[sizeof(desc) - 1] = '\0';
+
+ Q_strncpy(file, pl->file, sizeof(file) - 1);
+ file[sizeof(file) - 1] = '\0';
+
+ if (pl->info && pl->info->version)
+ {
+ Q_strncpy(vers, pl->info->version, sizeof(vers) - 1);
+ vers[sizeof(vers) - 1] = '\0';
}
- else {
- strncpy(vers, " -", sizeof vers - 1);
- vers[sizeof vers - 1] = '\0';
+ else
+ {
+ Q_strncpy(vers, " -", sizeof(vers) - 1);
+ vers[sizeof(vers) - 1] = '\0';
}
- META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-3s %-5s %-5s",
- WIDTH_MAX_PLUGINS, pl->index,
- sizeof(desc) - 1, desc,
- pl->str_status(ST_SHOW), pl->str_action(SA_SHOW),
- sizeof(file) - 1, file, sizeof(vers) - 1, vers,
- pl->str_source(SO_SHOW),
- pl->str_loadable(SL_SHOW), pl->str_unloadable(SL_SHOW));
+
+ META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, pl->index,
+ sizeof(desc) - 1, desc, pl->str_status(ST_SHOW), pl->str_action(SA_SHOW), sizeof(file) - 1, file, sizeof(vers) - 1, vers,
+ 2 + WIDTH_MAX_PLUGINS, pl->str_source(SO_SHOW), pl->str_loadable(SL_SHOW), pl->str_unloadable(SL_SHOW));
+
if (pl->status == PL_RUNNING)
r++;
n++;
}
+
META_CONS("%d plugins, %d running", n, r);
}
// List plugins and information to Player/client entity. Differs from the
// "meta list" console command in that:
// - Shows only "running" plugins, skipping any failed or paused plugins.
-// - Limited info about each plugin, mostly the "public" info (name, author,
+// - Limited info about each plugin, mostly the "public" info (name, author,
// etc).
// meta_errno values:
// - none
-void MPluginList::show_client(edict_t* pEntity)
+void MPluginList::show_client(edict_t *pEntity)
{
- int i, n = 0;
- MPlugin* pl;
+ int n = 0;
+ MPlugin *pl;
META_CLIENT(pEntity, "Currently running plugins:");
- for (i = 0; i < endlist; i++) {
+
+ for (int i = 0; i < endlist; i++)
+ {
pl = &plist[i];
- if (pl->status != PL_RUNNING)
+ if (pl->status != PL_RUNNING || !pl->info)
continue;
+
n++;
- META_CLIENT(pEntity, " [%3d] %s, v%s, %s, by %s, see %s",
- n,
- pl->info->name ? pl->info->name : "",
- pl->info->version ? pl->info->version : ">",
- pl->info->date ? pl->info->date : "<../../..>",
- pl->info->author ? pl->info->author : "",
- pl->info->url ? pl->info->url : "");
+ META_CLIENT(pEntity, " [%3d] %s, v%s, %s, by %s, see %s", n,
+ pl->info->name ? pl->info->name : "",
+ pl->info->version ? pl->info->version : ">",
+ pl->info->date ? pl->info->date : "<../../..>",
+ pl->info->author ? pl->info->author : "",
+ pl->info->url ? pl->info->url : "");
}
+
META_CLIENT(pEntity, "%d plugins", n);
}
mBOOL MPluginList::found_child_plugins(int source_index)
{
- int i;
-
if (source_index <= 0)
return mFALSE;
- for (i = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
if (plist[i].status < PL_VALID)
continue;
+
if (plist[i].source_plugin_index == source_index)
return mTRUE;
}
@@ -841,14 +888,14 @@ mBOOL MPluginList::found_child_plugins(int source_index)
void MPluginList::clear_source_plugin_index(int source_index)
{
- int i;
-
if (source_index <= 0)
return;
- for (i = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
if (plist[i].status < PL_VALID)
continue;
+
if (plist[i].source_plugin_index == source_index)
plist[i].source_plugin_index = -1;
}
diff --git a/metamod/src/mlist.h b/metamod/src/mlist.h
index c045ce0..699992e 100644
--- a/metamod/src/mlist.h
+++ b/metamod/src/mlist.h
@@ -1,90 +1,49 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// mlist.h - class and constants to describe a list of plugins
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef MLIST_H
-#define MLIST_H
+#pragma once
#include "types_meta.h" // mBOOL
#include "mplugin.h" // class MPlugin
-#include "plinfo.h" // plid_t, etc
+#include "plinfo.h" // plid_t, etc
// Max number of plugins we can manage. This is an arbitrary, fixed number,
// for convenience. It would probably be better to dynamically grow the
// list as needed, but we do this for now.
#define MAX_PLUGINS 50
+
// Width required to printf above MAX, for show() functions.
#define WIDTH_MAX_PLUGINS 2
-
// A list of plugins.
class MPluginList {
- public:
- // data:
- char inifile[PATH_MAX]; // full pathname
- MPlugin plist[MAX_PLUGINS]; // array of plugins
- int size; // size of list, ie MAX_PLUGINS
- int endlist; // index of last used entry
+public:
+ MPluginList(const char *ifile);
- // constructor:
- MPluginList(const char *ifile);
+ MPlugin *find(int pindex); // find by index
+ MPlugin *find(const char *findpath); // find by pathname
+ MPlugin *find(plid_t id); // find by plid_t
+ MPlugin *find_memloc(void *memptr); // find by memory location
+ MPlugin *find_match(const char *prefix); // find by partial prefix match
+ MPlugin *find_match(MPlugin *pmatch); // find by platform_match()
+ MPlugin *find(DLHANDLE handle); // find by handle
+ MPlugin *add(MPlugin *padd);
- // functions:
- MPlugin *find(int pindex); // find by index
- MPlugin *find(const char *findpath); // find by pathname
- MPlugin *find(plid_t id); // find by plid_t
- MPlugin *find_memloc(void *memptr); // find by memory location
- MPlugin *find_match(const char *prefix); // find by partial prefix match
- MPlugin *find_match(MPlugin *pmatch); // find by platform_match()
- MPlugin * find(DLHANDLE handle); // find by handle
- MPlugin *add(MPlugin *padd);
+ mBOOL found_child_plugins(int source_index);
- mBOOL found_child_plugins(int source_index);
+ mBOOL ini_startup(void); // read inifile at startup
+ mBOOL ini_refresh(void); // re-read inifile
+ mBOOL cmd_addload(const char *args); // load from console command
+ MPlugin *plugin_addload(plid_t plid, const char *fname, PLUG_LOADTIME now); //load from plugin
- mBOOL ini_startup(void); // read inifile at startup
- mBOOL ini_refresh(void); // re-read inifile
- mBOOL cmd_addload(const char *args); // load from console command
- MPlugin *plugin_addload(plid_t plid, const char *fname, PLUG_LOADTIME now); //load from plugin
+ mBOOL load(void); // load the list, at startup
+ mBOOL refresh(PLUG_LOADTIME now); // update from re-read inifile
+ void unpause_all(void); // unpause any paused plugins
+ void retry_all(PLUG_LOADTIME now); // retry any pending plugin actions
+ void show(int source_index = 0); // list plugins to console
+ void show_client(edict_t *pEntity); // list plugins to player client
+ void clear_source_plugin_index(int source_index);
- mBOOL load(void); // load the list, at startup
- mBOOL refresh(PLUG_LOADTIME now); // update from re-read inifile
- void unpause_all(void); // unpause any paused plugins
- void retry_all(PLUG_LOADTIME now); // retry any pending plugin actions
- void show(int source_index); // list plugins to console
- void show_client(edict_t *pEntity); // list plugins to player client
- void clear_source_plugin_index(int source_index);
+public:
+ char inifile[PATH_MAX]; // full pathname
+ MPlugin plist[MAX_PLUGINS]; // array of plugins
+ int size; // size of list, ie MAX_PLUGINS
+ int endlist; // index of last used entry
};
-
-#endif /* MLIST_H */
diff --git a/metamod/src/mplayer.cpp b/metamod/src/mplayer.cpp
index 7dcd8f9..0a343ec 100644
--- a/metamod/src/mplayer.cpp
+++ b/metamod/src/mplayer.cpp
@@ -1,43 +1,5 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// mplayer.cpp - methods of individual player (class MPlayer) and
-// list of players (class MPlayerList).
-
-/*
- * Copyright (c) 2005 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
-// Constructor
MPlayer::MPlayer() : isQueried(mFALSE)
{
}
@@ -45,64 +7,64 @@ MPlayer::MPlayer() : isQueried(mFALSE)
// Mark a player as querying a client cvar and stores the cvar name
// meta_errno values:
// - ME_ARGUMENT cvar is NULL
-void MPlayer::set_cvar_query(const char* cvar)
+void MPlayer::set_cvar_query(const char *cvar)
{
// Do not allow NULL as queried cvar since we use this as
// return value in is_querying_cvar as indication if a
// client cvar is queried.
- if (!cvar) {
+ if (!cvar)
+ {
meta_errno = ME_ARGUMENT;
return;
}
isQueried = mTRUE;
- strncpy(cvarName, cvar, sizeof cvarName - 1);
+ Q_strncpy(cvarName, cvar, sizeof cvarName - 1);
cvarName[sizeof cvarName - 1] = '\0';
}
// Unmark player as querying a client cvar
-void MPlayer::clear_cvar_query(const char* /*cvar*/)
+void MPlayer::clear_cvar_query(const char *cvar)
{
isQueried = mFALSE;
cvarName[0] = '\0';
}
-
// Check if a client cvar is queried for this player
// Returns NULL if not
// or the name of the cvar.
-const char* MPlayer::is_querying_cvar(void) const
+const char *MPlayer::is_querying_cvar(void) const
{
- if (isQueried) {
+ if (isQueried)
+ {
return cvarName;
}
- return NULL;
+ return nullptr;
}
// Mark a player as querying a client cvar and stores the cvar name
// meta_errno values:
// - ME_ARGUMENT cvar is NULL
-void MPlayerList::set_player_cvar_query(const edict_t* pEntity, const char* cvar)
+void MPlayerList::set_player_cvar_query(const edict_t *pEntity, const char *cvar)
{
int indx = ENTINDEX(pEntity);
-
- if (indx >= 1 && indx <= maxplayers)
+ if (indx >= 1 && indx <= gpGlobals->maxClients)
players[indx].set_cvar_query(cvar);
}
// Unmark player as querying a client cvar
-void MPlayerList::clear_player_cvar_query(const edict_t* pEntity, const char* cvar)
+void MPlayerList::clear_player_cvar_query(const edict_t *pEntity, const char *cvar)
{
int indx = ENTINDEX(pEntity);
-
- if (indx >= 1 && indx <= maxplayers)
+ if (indx >= 1 && indx <= gpGlobals->maxClients)
players[indx].clear_cvar_query(cvar);
}
void MPlayerList::clear_all_cvar_queries(void)
{
- for (int indx = 1; indx <= maxplayers; indx++) {
+ for (int indx = 1; indx <= gpGlobals->maxClients; indx++)
+ {
players[indx].clear_cvar_query();
}
}
@@ -112,11 +74,10 @@ void MPlayerList::clear_all_cvar_queries(void)
// or the name of the cvar.
// meta_errno values:
// - ME_NOTFOUND invalid entity
-const char* MPlayerList::is_querying_cvar(const edict_t* pEntity) const
+const char *MPlayerList::is_querying_cvar(const edict_t *pEntity) const
{
int indx = ENTINDEX(pEntity);
-
- if (indx >= 1 && indx <= maxplayers)
+ if (indx >= 1 && indx <= gpGlobals->maxClients)
return players[indx].is_querying_cvar();
RETURN_ERRNO(NULL, ME_NOTFOUND);
diff --git a/metamod/src/mplayer.h b/metamod/src/mplayer.h
index 18d6140..a90f94d 100644
--- a/metamod/src/mplayer.h
+++ b/metamod/src/mplayer.h
@@ -1,47 +1,6 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// mplayer.h - class to keep info about a player and a class listing all
-// players
-
-/*
- * Copyright (c) 2005 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef INCLUDE_METAMOD_PLAYER_H
-#define INCLUDE_METAMOD_PLAYER_H
-
-#include "types_meta.h" // mBOOL
-
-// Numbers of players limit set by the engine
-#define MAX_PLAYERS 32
+#include "types_meta.h"
// Info on an individual player
class MPlayer
@@ -49,28 +8,26 @@ class MPlayer
public:
MPlayer();
- void set_cvar_query(const char *cvar); // mark this player as querying a client cvar
- void clear_cvar_query(const char *cvar=NULL); // unmark this player as querying a client cvar
- const char *is_querying_cvar(void) const; // check if a player is querying a cvar. returns
-
+ void set_cvar_query(const char *cvar); // mark this player as querying a client cvar
+ void clear_cvar_query(const char *cvar = nullptr); // unmark this player as querying a client cvar
+ const char *is_querying_cvar() const; // check if a player is querying a cvar. returns
+
private:
- mBOOL isQueried; // is this player currently queried for a cvar value
- char cvarName[64]; // name of the cvar if getting queried
+ mBOOL isQueried; // is this player currently queried for a cvar value
+ char cvarName[64]; // name of the cvar if getting queried
};
// A list of players. The number of max players is fixed and small enough
// to use an array.
class MPlayerList
-{
+{
public:
- void set_player_cvar_query(const edict_t *pEntity, const char *cvar);
- void clear_player_cvar_query(const edict_t *pEntity, const char *cvar=NULL);
- void clear_all_cvar_queries(void);
+ void set_player_cvar_query(const edict_t *pEntity, const char *cvar);
+ void clear_player_cvar_query(const edict_t *pEntity, const char *cvar = nullptr);
+ void clear_all_cvar_queries();
const char *is_querying_cvar(const edict_t *pEntity) const;
private:
int maxplayers = 32;
- MPlayer players[MAX_PLAYERS + 1]; // array of players
+ MPlayer players[MAX_CLIENTS + 1]; // array of players
};
-
-#endif /* INCLUDE_METAMOD_PLAYER_H */
diff --git a/metamod/src/mplugin.cpp b/metamod/src/mplugin.cpp
index 330929b..1419d0a 100644
--- a/metamod/src/mplugin.cpp
+++ b/metamod/src/mplugin.cpp
@@ -1,39 +1,3 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// mplugin.cpp - functions for individual plugin (class MPlugin)
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// Parse a line from plugins.ini into a plugin.
@@ -41,26 +5,28 @@
// - ME_COMMENT ignored commented line
// - ME_FORMAT invalid line format
// - ME_OSNOTSUP plugin is not for this OS
-mBOOL MPlugin::ini_parseline(char* line)
+mBOOL MPlugin::ini_parseline(char *line)
{
- char* token;
- char* ptr_token;
- char* cp;
+ char *token;
+ char *ptr_token;
+ char *cp;
// skip whitespace at start of line
while (*line == ' ' || *line == '\t') line++;
// remove whitespace at end of line
- cp = line + strlen(line) - 1;
+ cp = line + Q_strlen(line) - 1;
while (*cp == ' ' || *cp == '\t') *cp-- = '\0';
// skip empty lines
- if (line[0] == '\0') {
+ if (line[0] == '\0')
+ {
META_DEBUG(7, ("ini: Ignoring empty line: %s", line));
RETURN_ERRNO(mFALSE, ME_BLANK);
}
- if (line[0] == '#' || line[0] == ';' || strstr(line, "//") == line) {
+ if (line[0] == '#' || line[0] == ';' || Q_strstr(line, "//") == line)
+ {
META_DEBUG(7, ("ini: Ignoring commented line: %s", line));
RETURN_ERRNO(mFALSE, ME_COMMENT);
}
@@ -69,13 +35,16 @@ mBOOL MPlugin::ini_parseline(char* line)
token = strtok_r(line, " \t", &ptr_token);
if (!token)
RETURN_ERRNO(mFALSE, ME_FORMAT);
- if (_stricmp(token, PLATFORM) == 0) {
+ if (Q_stricmp(token, PLATFORM) == 0)
+ {
pfspecific = 0;
}
- else if (_stricmp(token, PLATFORM_SPC) == 0) {
+ else if (Q_stricmp(token, PLATFORM_SPC) == 0)
+ {
pfspecific = 1;
}
- else {
+ else
+ {
// plugin is not for this OS
META_DEBUG(7, ("ini: Ignoring entry for %s", token));
RETURN_ERRNO(mFALSE, ME_OSNOTSUP);
@@ -84,12 +53,16 @@ mBOOL MPlugin::ini_parseline(char* line)
// grab filename
token = strtok_r(NULL, " \t\r\n", &ptr_token);
if (!token)
- RETURN_ERRNO(mFALSE, ME_FORMAT);
- strncpy(filename, token, sizeof filename - 1);
+ {
+ RETURN_ERRNO(mFALSE, ME_FORMAT);
+ }
+
+ Q_strncpy(filename, token, sizeof filename - 1);
filename[sizeof filename - 1] = '\0';
normalize_pathname(filename);
+
// Store name of just the actual _file_, without dir components.
- cp = strrchr(filename, '/');
+ cp = Q_strrchr(filename, '/');
if (cp)
file = cp + 1;
else
@@ -98,15 +71,17 @@ mBOOL MPlugin::ini_parseline(char* line)
// Grab description.
// Just get the the rest of the line, minus line-termination.
token = strtok_r(NULL, "\n\r", &ptr_token);
- if (token) {
+ if (token)
+ {
token = token + strspn(token, " \t"); // skip whitespace
- strncpy(desc, token, sizeof desc - 1);
+ Q_strncpy(desc, token, sizeof desc - 1);
desc[sizeof desc - 1] = '\0';
}
- else {
+ else
+ {
// If no description is specified, temporarily use plugin file,
// until plugin can be queried, and desc replaced with info->name.
- snprintf(desc, sizeof(desc), "<%s>", file);
+ Q_snprintf(desc, sizeof(desc), "<%s>", file);
}
// Make full pathname (from gamedir if relative, remove "..",
@@ -115,7 +90,7 @@ mBOOL MPlugin::ini_parseline(char* line)
source = PS_INI;
status = PL_VALID;
- return (mTRUE);
+ return mTRUE;
}
// Unload a plugin from plugin request
@@ -124,21 +99,25 @@ mBOOL MPlugin::ini_parseline(char* line)
mBOOL MPlugin::plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
PLUG_ACTION old_action;
- MPlugin* pl_unloader;
+ MPlugin *pl_unloader;
- if (!(pl_unloader = g_plugins->find(plid))) {
+ if (!(pl_unloader = g_plugins->find(plid)))
+ {
META_WARNING("dll: Not unloading plugin '%s'; plugin that requested unload is not found.", desc);
RETURN_ERRNO(mFALSE, ME_BADREQ);
}
- else if (pl_unloader->index == index) {
+ else if (pl_unloader->index == index)
+ {
META_WARNING("dll: Not unloading plugin '%s'; Plugin tried to unload itself.", desc);
RETURN_ERRNO(mFALSE, ME_UNLOAD_SELF);
}
- else if (is_unloader) {
+ else if (is_unloader)
+ {
META_WARNING("dll: Not unloading plugin '%s'; Plugin is unloading plugin that tried to unload it.", desc);
RETURN_ERRNO(mFALSE, ME_UNLOAD_UNLOADER);
}
- else {
+ else
+ {
unloader_index = pl_unloader->index;
}
@@ -148,7 +127,8 @@ mBOOL MPlugin::plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON re
//try unload
old_action = action;
action = PA_UNLOAD;
- if (unload(now, reason, PNL_PLG_FORCED)) {
+ if (unload(now, reason, PNL_PLG_FORCED))
+ {
META_DEBUG(1,("Unloaded plugin '%s'", desc));
pl_unloader->is_unloader = mFALSE;
return mTRUE;
@@ -157,7 +137,8 @@ mBOOL MPlugin::plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON re
pl_unloader->is_unloader = mFALSE;
//can't unload plugin now, set delayed
- if (meta_errno == ME_DELAYED) {
+ if (meta_errno == ME_DELAYED)
+ {
action = old_action;
meta_errno = ME_NOTALLOWED;
META_DEBUG(2, ("dll: Failed unload plugin '%s'; can't detach now: allowed=%s; now=%s", desc, str_unloadable(), str_loadtime(PT_ANYTIME, SL_SIMPLE)));
@@ -166,21 +147,21 @@ mBOOL MPlugin::plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON re
return mFALSE;
}
-// Parse a filename string from PEXT_LOAD_PLUGIN_BY_* function into a plugin.
+// Parse a filename string from PEXT_LOAD_PLUGIN_BY_ *function into a plugin.
// meta_errno values:
-mBOOL MPlugin::plugin_parseline(const char* fname, int loader_index)
+mBOOL MPlugin::plugin_parseline(const char *fname, int loader_index)
{
- char* cp;
+ char *cp;
source_plugin_index = loader_index;
- strncpy(filename, fname, sizeof filename - 1);
+ Q_strncpy(filename, fname, sizeof filename - 1);
filename[sizeof filename - 1] = '\0';
normalize_pathname(filename);
//store just name of the actual _file, without path
- cp = strrchr(filename, '/');
+ cp = Q_strrchr(filename, '/');
if (cp)
file = cp + 1;
else
@@ -188,7 +169,7 @@ mBOOL MPlugin::plugin_parseline(const char* fname, int loader_index)
//grab description
//temporarily use plugin file until plugin can be queried
- snprintf(desc, sizeof(desc), "<%s>", file);
+ Q_snprintf(desc, sizeof(desc), "<%s>", file);
//make full pathname
full_gamedir_path(filename, pathname);
@@ -202,30 +183,32 @@ mBOOL MPlugin::plugin_parseline(const char* fname, int loader_index)
// Parse a line from console "load" command into a plugin.
// meta_errno values:
// - ME_FORMAT invalid line format
-mBOOL MPlugin::cmd_parseline(const char* line)
+mBOOL MPlugin::cmd_parseline(const char *line)
{
char buf[NAME_MAX + PATH_MAX + MAX_DESC_LEN];
- char* token;
- char* ptr_token;
- char* cp;
+ char *token;
+ char *ptr_token;
+ char *cp;
- strncpy(buf, line, sizeof buf - 1);
+ Q_strncpy(buf, line, sizeof buf - 1);
buf[sizeof buf - 1] = '\0';
// remove "load"
token = strtok_r(buf, " \t", &ptr_token);
if (!token)
- RETURN_ERRNO(mFALSE, ME_FORMAT);
+ RETURN_ERRNO(mFALSE, ME_FORMAT);
// grab filename
token = strtok_r(NULL, " \t", &ptr_token);
if (!token)
- RETURN_ERRNO(mFALSE, ME_FORMAT);
- strncpy(filename, token, sizeof filename - 1);
+ RETURN_ERRNO(mFALSE, ME_FORMAT);
+
+ Q_strncpy(filename, token, sizeof filename - 1);
filename[sizeof filename - 1] = '\0';
normalize_pathname(filename);
+
// store name of just the actual _file_, without dir components
- cp = strrchr(filename, '/');
+ cp = Q_strrchr(filename, '/');
if (cp)
file = cp + 1;
else
@@ -234,15 +217,17 @@ mBOOL MPlugin::cmd_parseline(const char* line)
// Grab description.
// Specify no delimiter chars, as we just want the rest of the line.
token = strtok_r(NULL, "", &ptr_token);
- if (token) {
+ if (token)
+ {
token = token + strspn(token, " \t"); // skip whitespace
- strncpy(desc, token, sizeof desc - 1);
+ Q_strncpy(desc, token, sizeof desc - 1);
desc[sizeof desc - 1] = '\0';
}
- else {
+ else
+ {
// if no description is specified, temporarily use plugin file,
// until plugin can be queried, and desc replaced with info->name.
- snprintf(desc, sizeof(desc), "<%s>", file);
+ Q_snprintf(desc, sizeof(desc), "<%s>", file);
}
// Make full pathname (from gamedir if relative, remove "..",
@@ -251,7 +236,7 @@ mBOOL MPlugin::cmd_parseline(const char* line)
source = PS_CMD;
status = PL_VALID;
- return (mTRUE);
+ return mTRUE;
}
// Make sure this plugin has the necessary minimal information.
@@ -260,36 +245,40 @@ mBOOL MPlugin::cmd_parseline(const char* line)
mBOOL MPlugin::check_input(void)
{
// doublecheck our input/state
- if (status < PL_VALID) {
+ if (status < PL_VALID)
+ {
META_ERROR("dll: Tried to operate on plugin[%d] with a non-valid status (%d)", index, str_status());
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
- if (!file || !file[0]) {
- META_ERROR("dll: Tried to operate on plugin[%d] with an empty file",
- index);
+ if (!file || !file[0])
+ {
+ META_ERROR("dll: Tried to operate on plugin[%d] with an empty file", index);
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
- if (!filename[0]) {
- META_ERROR("dll: Tried to operate on plugin[%d] with an empty filename",
- index);
+ if (!filename[0])
+ {
+ META_ERROR("dll: Tried to operate on plugin[%d] with an empty filename", index);
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
- if (!pathname[0]) {
- META_ERROR("dll: Tried to operate on plugin[%d] with an empty pathname",
- index);
+ if (!pathname[0])
+ {
+ META_ERROR("dll: Tried to operate on plugin[%d] with an empty pathname", index);
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
- if (!desc[0]) {
+
+ if (!desc[0])
+ {
// if no description is specified, temporarily use plugin file,
// until plugin can be queried, and desc replaced with info->name.
- snprintf(desc, sizeof(desc), "<%s>", file);
+ Q_snprintf(desc, sizeof(desc), "<%s>", file);
}
- return (mTRUE);
+
+ return mTRUE;
}
// Try to resolve a plugin's filename as a (possibly partial) path to an
// actual filename on disk, to facilitate easier console load-command
-// arguments. Uses resolve_dirs, resolve_prefix, and resolve_suffix below.
+// arguments. Uses resolve_dirs, resolve_prefix, and resolve_suffix below.
// Example paths that it tries:
// filename
// Gamedir/filename.dll, Gamedir/filename.so
@@ -302,76 +291,89 @@ mBOOL MPlugin::check_input(void)
// - errno's from check_input()
mBOOL MPlugin::resolve(void)
{
- char* found;
- char* cp;
+ char *found;
+ char *cp;
int len;
- if (!check_input()) {
+
+ if (!check_input())
+ {
// details logged, meta_errno set in check_input()
- return (mFALSE);
+ return mFALSE;
}
if (is_absolute_path(filename))
found = resolve_prefix(filename);
else
found = resolve_dirs(filename);
- if (!found) {
+ if (!found)
+ {
META_DEBUG(2, ("Couldn't resolve '%s' to file", filename));
RETURN_ERRNO(mFALSE, ME_NOTFOUND);
}
+
META_DEBUG(2, ("Resolved '%s' to file '%s'", filename, found));
+
// store pathname: the resolved path (should be absolute)
- strncpy(pathname, found, sizeof pathname - 1);
+ Q_strncpy(pathname, found, sizeof pathname - 1);
pathname[sizeof pathname - 1] = '\0';
+
// store file: the name of the file (without dir)
- cp = strrchr(pathname, '/');
+ cp = Q_strrchr(pathname, '/');
if (cp)
file = cp + 1;
else
file = pathname;
+
// store pathname: the gamedir relative path, or an absolute path
- len = strlen(GameDLL.gamedir);
- if (_strnicmp(pathname, GameDLL.gamedir, len) == 0) {
- strncpy(filename, pathname + len + 1, sizeof filename - 1);
+ len = Q_strlen(GameDLL.gamedir);
+ if (Q_strnicmp(pathname, GameDLL.gamedir, len) == 0)
+ {
+ Q_strncpy(filename, pathname + len + 1, sizeof filename - 1);
filename[sizeof filename - 1] = '\0';
}
- else {
- strncpy(filename, pathname, sizeof filename - 1);
+ else
+ {
+ Q_strncpy(filename, pathname, sizeof filename - 1);
filename[sizeof filename - 1] = '\0';
}
- return (mTRUE);
+ return mTRUE;
}
-// For the given path, tries to find file in several possible
+// For the given path, tries to find file in several possible
// directories.
// Try:
// GAMEDIR/filename
// GAMEDIR/dlls/filename
// meta_errno values:
// - none
-char* MPlugin::resolve_dirs(char* path)
+char *MPlugin::resolve_dirs(char *path)
{
struct stat st;
static char buf[PATH_MAX ];
- char* found;
+ char *found;
+
+ Q_snprintf(buf, sizeof(buf), "%s/%s", GameDLL.gamedir, path);
- snprintf(buf, sizeof(buf), "%s/%s", GameDLL.gamedir, path);
// try this path
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return (buf);
+ return buf;
+
// try other file prefixes in this path
if ((found = resolve_prefix(buf)))
- return (found);
+ return found;
+
+ Q_snprintf(buf, sizeof(buf), "%s/dlls/%s", GameDLL.gamedir, path);
- snprintf(buf, sizeof(buf), "%s/dlls/%s", GameDLL.gamedir, path);
// try this path
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return (buf);
+ return buf;
+
// try other file prefixes for this path
if ((found = resolve_prefix(buf)))
- return (found);
+ return found;
- return (NULL);
+ return NULL;
}
// For the given path, tries several possible filename prefixes.
@@ -380,40 +382,45 @@ char* MPlugin::resolve_dirs(char* path)
// dir/file
// meta_errno values:
// - none
-char* MPlugin::resolve_prefix(char* path)
+char *MPlugin::resolve_prefix(char *path)
{
struct stat st;
char *cp, *fname;
char dname[PATH_MAX ];
static char buf[PATH_MAX ];
- char* found;
+ char *found;
// try "mm_" prefix FIRST.
// split into dirname and filename
- strncpy(dname, path, sizeof dname - 1);
+ Q_strncpy(dname, path, sizeof dname - 1);
dname[sizeof dname - 1] = '\0';
- cp = strrchr(dname, '/');
- if (cp) {
+
+ cp = Q_strrchr(dname, '/');
+ if (cp)
+ {
*cp = '\0';
fname = cp + 1;
- snprintf(buf, sizeof(buf), "%s/mm_%s", dname, fname);
+ Q_snprintf(buf, sizeof(buf), "%s/mm_%s", dname, fname);
}
- else {
+ else
+ {
// no directory in given path
- snprintf(buf, sizeof(buf), "mm_%s", path);
+ Q_snprintf(buf, sizeof(buf), "mm_%s", path);
}
+
// try this path
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return (buf);
+ return buf;
+
// try other suffixes for this path
if ((found = resolve_suffix(buf)))
- return (found);
+ return found;
// try other suffixes for the original path
if ((found = resolve_suffix(path)))
- return (found);
+ return found;
- return (NULL);
+ return NULL;
}
// For the given path, tries several different filename suffixes.
@@ -425,76 +432,78 @@ char* MPlugin::resolve_prefix(char* path)
// path_i386.so, path_i486.so, etc (if linux)
// meta_errno values:
// - none
-char* MPlugin::resolve_suffix(char* path)
+char *MPlugin::resolve_suffix(char *path)
{
struct stat st;
static char buf[PATH_MAX ];
- char* found;
+ char *found;
// Hmm, recursion.
- if (!strstr(path, "_mm")) {
- char* tmpbuf;
- snprintf(buf, sizeof(buf), "%s_mm", path);
- tmpbuf = _strdup(buf);
+ if (!Q_strstr(path, "_mm"))
+ {
+ char *tmpbuf;
+ Q_snprintf(buf, sizeof(buf), "%s_mm", path);
+ tmpbuf = Q_strdup(buf);
found = resolve_suffix(tmpbuf);
- free(tmpbuf);
- if (found) return (found);
+ Q_free(tmpbuf);
+ if (found) return found;
}
- if (!strstr(path, "_MM")) {
- char* tmpbuf;
- snprintf(buf, sizeof(buf), "%s_MM", path);
- tmpbuf = _strdup(buf);
+ else if (!Q_strstr(path, "_MM"))
+ {
+ char *tmpbuf;
+ Q_snprintf(buf, sizeof(buf), "%s_MM", path);
+ tmpbuf = Q_strdup(buf);
found = resolve_suffix(tmpbuf);
- free(tmpbuf);
- if (found) return (found);
+ Q_free(tmpbuf);
+ if (found) return found;
}
#ifdef _WIN32
- snprintf(buf, sizeof(buf), "%s.dll", path);
-#elif defined(linux)
- snprintf(buf, sizeof(buf), "%s.so", path);
-#elif defined(__APPLE__)
- snprintf(buf, sizeof(buf), "%s.dylib", path);
+ Q_snprintf(buf, sizeof(buf), "%s.dll", path);
#else
-#error "OS unrecognized"
-#endif /* _WIN32 */
+ Q_snprintf(buf, sizeof(buf), "%s.so", path);
+#endif
+
if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return (buf);
+ return buf;
-#ifdef linux
- snprintf(buf, sizeof(buf), "%s_i386.so", path);
- if(stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return(buf);
- snprintf(buf, sizeof(buf), "%s_i486.so", path);
- if(stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return(buf);
- snprintf(buf, sizeof(buf), "%s_i586.so", path);
- if(stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return(buf);
- snprintf(buf, sizeof(buf), "%s_i686.so", path);
- if(stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return(buf);
- snprintf(buf, sizeof(buf), "%s_amd64.so", path);
- if(stat(buf, &st) == 0 && S_ISREG(st.st_mode))
- return(buf);
-#endif /* linux */
+#ifndef _WIN32
+ Q_snprintf(buf, sizeof(buf), "%s_i386.so", path);
+ if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
+ return buf;
- return (NULL);
+ Q_snprintf(buf, sizeof(buf), "%s_i486.so", path);
+ if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
+ return buf;
+
+ Q_snprintf(buf, sizeof(buf), "%s_i586.so", path);
+ if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
+ return buf;
+
+ Q_snprintf(buf, sizeof(buf), "%s_i686.so", path);
+ if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
+ return buf;
+
+ Q_snprintf(buf, sizeof(buf), "%s_amd64.so", path);
+ if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
+ return buf;
+#endif
+
+ return NULL;
}
-
// Check if a passed string starts with a known platform postfix.
// It does not check beyond the period in order to work for both
// Linux and Win32.
-static mBOOL is_platform_postfix(char* pf)
+static mBOOL is_platform_postfix(char *pf)
{
if (NULL == pf) return mFALSE;
- if (0 == strncmp(pf, "_i386.", 6)) return mTRUE;
- if (0 == strncmp(pf, "_i486.", 6)) return mTRUE;
- if (0 == strncmp(pf, "_i586.", 6)) return mTRUE;
- if (0 == strncmp(pf, "_i686.", 6)) return mTRUE;
- if (0 == strncmp(pf, "_amd64.", 7)) return mTRUE;
+ if (0 == Q_strncmp(pf, "_i386.", 6)) return mTRUE;
+ if (0 == Q_strncmp(pf, "_i486.", 6)) return mTRUE;
+ if (0 == Q_strncmp(pf, "_i586.", 6)) return mTRUE;
+ if (0 == Q_strncmp(pf, "_i686.", 6)) return mTRUE;
+ if (0 == Q_strncmp(pf, "_amd64.", 7)) return mTRUE;
return mFALSE;
}
@@ -507,36 +516,44 @@ static mBOOL is_platform_postfix(char* pf)
// 2b. the description is the same, or
// 3. a significant part of the filename is the same.
// A significant part of a plugin name is currently defined to:
-// the part up to a known platform postfix as determined by
+// the part up to a known platform postfix as determined by
// the is_platform_postfix() function (see above), or
// the part up to the last dot, if one exists.
// meta_errno values:
// - none
-mBOOL MPlugin::platform_match(MPlugin* other)
+mBOOL MPlugin::platform_match(MPlugin *other)
{
char *end, *other_end;
int prefixlen;
- if (status == PL_EMPTY || other->status == PL_EMPTY) return mFALSE;
+ if (status == PL_EMPTY || other->status == PL_EMPTY)
+ return mFALSE;
- if (strcmp(file, other->file) == 0) return mTRUE;
-
- if (status >= PL_OPENED && other->status >= PL_OPENED &&
- strcmp(info->logtag, other->info->logtag) == 0)
+ if (Q_strcmp(file, other->file) == 0)
return mTRUE;
- if (*desc != '\0' && _stricmp(desc, other->desc) == 0) return mTRUE;
- end = strrchr(file, '_');
- if (end == NULL || !is_platform_postfix(end)) end = strrchr(file, '.');
- other_end = strrchr(other->file, '_');
- if (other_end == NULL || !is_platform_postfix(other_end)) other_end = strrchr(other->file, '.');
+ if (status >= PL_OPENED && other->status >= PL_OPENED && Q_strcmp(info->logtag, other->info->logtag) == 0)
+ return mTRUE;
- if (end == NULL || other_end == NULL) return mFALSE;
+ if (*desc != '\0' && Q_stricmp(desc, other->desc) == 0)
+ return mTRUE;
+
+ end = Q_strrchr(file, '_');
+ if (end == NULL || !is_platform_postfix(end)) end = Q_strrchr(file, '.');
+ other_end = Q_strrchr(other->file, '_');
+
+ if (other_end == NULL || !is_platform_postfix(other_end))
+ other_end = Q_strrchr(other->file, '.');
+
+ if (end == NULL || other_end == NULL)
+ return mFALSE;
prefixlen = end - file;
- if ((other_end - other->file) != prefixlen) return mFALSE;
+ if ((other_end - other->file) != prefixlen)
+ return mFALSE;
- if (strncmp(file, other->file, prefixlen) == 0) return mTRUE;
+ if (Q_strncmp(file, other->file, prefixlen) == 0)
+ return mTRUE;
return mFALSE;
}
@@ -554,28 +571,33 @@ mBOOL MPlugin::platform_match(MPlugin* other)
// - errno's from check_input()
mBOOL MPlugin::load(PLUG_LOADTIME now)
{
- if (!check_input()) {
+ if (!check_input())
+ {
// details logged, meta_errno set in check_input()
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
- if (status >= PL_RUNNING) {
- META_ERROR("dll: Not loading plugin '%s'; already loaded (status=%s)",
- desc, str_status());
+ if (status >= PL_RUNNING)
+ {
+ META_ERROR("dll: Not loading plugin '%s'; already loaded (status=%s)", desc, str_status());
RETURN_ERRNO(mFALSE, ME_ALREADY);
}
- if (action != PA_LOAD && action != PA_ATTACH) {
+ if (action != PA_LOAD && action != PA_ATTACH)
+ {
META_ERROR("dll: Not loading plugin '%s'; not marked for load (action=%s)", desc, str_action());
RETURN_ERRNO(mFALSE, ME_BADREQ);
}
- if (status < PL_OPENED) {
+ if (status < PL_OPENED)
+ {
// query plugin; open file and get info about it
- if (!query()) {
+ if (!query())
+ {
META_ERROR("dll: Skipping plugin '%s'; couldn't query", desc);
- if (meta_errno != ME_DLOPEN) {
- if (DLCLOSE(handle) != 0) {
- META_ERROR("dll: Couldn't close plugin file '%s': %s",
- file, DLERROR());
+ if (meta_errno != ME_DLOPEN)
+ {
+ if (DLCLOSE(handle) != 0)
+ {
+ META_ERROR("dll: Couldn't close plugin file '%s': %s", file, DLERROR());
}
else
handle = NULL;
@@ -583,22 +605,23 @@ mBOOL MPlugin::load(PLUG_LOADTIME now)
status = PL_BADFILE;
info = NULL; //prevent crash
// meta_errno should be already set in query()
- return (mFALSE);
+ return mFALSE;
}
status = PL_OPENED;
}
// are we allowed to attach this plugin at this time?
- if (info->loadable < now) {
- if (info->loadable > PT_STARTUP) {
+ if (info->loadable < now)
+ {
+ if (info->loadable > PT_STARTUP)
+ {
// will try to attach again at next opportunity
- META_DEBUG(2, ("dll: Delaying load plugin '%s'; can't attach now: allowed=%s; now=%s",
- desc, str_loadable(), str_loadtime(now, SL_SIMPLE)));
+ META_DEBUG(2, ("dll: Delaying load plugin '%s'; can't attach now: allowed=%s; now=%s", desc, str_loadable(), str_loadtime(now, SL_SIMPLE)));
RETURN_ERRNO(mFALSE, ME_DELAYED);
}
- else {
- META_DEBUG(2, ("dll: Failed load plugin '%s'; can't attach now: allowed=%s; now=%s",
- desc, str_loadable(), str_loadtime(now, SL_SIMPLE)));
+ else
+ {
+ META_DEBUG(2, ("dll: Failed load plugin '%s'; can't attach now: allowed=%s; now=%s", desc, str_loadable(), str_loadtime(now, SL_SIMPLE)));
// don't try to attach again later
action = PA_NONE;
RETURN_ERRNO(mFALSE, ME_NOTALLOWED);
@@ -606,7 +629,8 @@ mBOOL MPlugin::load(PLUG_LOADTIME now)
}
// attach plugin; get function tables
- if (attach(now) != mTRUE) {
+ if (attach(now) != mTRUE)
+ {
META_ERROR("dll: Failed to attach plugin '%s'", desc);
// Note we don't dlclose() here, since we're returning PL_FAILED,
// which implies that it's been dlopened and queried successfully.
@@ -615,14 +639,16 @@ mBOOL MPlugin::load(PLUG_LOADTIME now)
// (segfault) after dlclosed.
status = PL_FAILED;
// meta_errno should be already set in attach()
- return (mFALSE);
+ return mFALSE;
}
+
status = PL_RUNNING;
action = PA_NONE;
// If not loading at server startup, then need to call plugin's
// GameInit, since we've passed that.
- if (now != PT_STARTUP) {
+ if (now != PT_STARTUP)
+ {
FN_GAMEINIT pfn_gameinit = NULL;
if (dllapi_table && (pfn_gameinit = dllapi_table->pfnGameInit))
pfn_gameinit();
@@ -635,14 +661,14 @@ mBOOL MPlugin::load(PLUG_LOADTIME now)
META_LOG("dll: Loaded plugin '%s': %s v%s %s, %s", desc, info->name,
info->version, info->date, info->author);
- return (mTRUE);
+ return mTRUE;
}
// Query a plugin:
// - dlopen() the file, store the handle
// - dlsym() and call:
// Meta_Init (if present) - tell dll it'll be used as a metamod plugin
-// GiveFnptrsToDll - give engine function ptrs
+// GiveFnptrsToDll - give engine function ptrs
// Meta_Query - say "hi" and get info about plugin
// meta_errno values:
// - ME_DLOPEN dlopen/loadlibrary failed; see dlerror() for details
@@ -656,7 +682,8 @@ mBOOL MPlugin::query(void)
META_QUERY_FN pfn_query;
// open the plugin DLL
- if (!(handle = DLOPEN(pathname))) {
+ if (!(handle = DLOPEN(pathname)))
+ {
META_ERROR("dll: Failed query plugin '%s'; Couldn't open file '%s': %s",
desc, pathname, DLERROR());
RETURN_ERRNO(mFALSE, ME_DLOPEN);
@@ -668,12 +695,13 @@ mBOOL MPlugin::query(void)
// startup in GiveFnptrsToDll, and trying to load them as metamod
// plugins creates all sorts of crashes. So, we do a trivial check
// first to see if the DLL looks like a metamod plugin before
- // proceeding with the normal order. Note that we still have to call
- // GiveFnptrsToDll before Meta_Query, because the latter typically uses
- // engine functions like AlertMessage, which have to be passed along via
+ // proceeding with the normal order. Note that we still have to call
+ // GiveFnptrsToDll before Meta_Query, because the latter typically uses
+ // engine functions like AlertMessage, which have to be passed along via
// GiveFnptrsToDll.
pfn_query = (META_QUERY_FN) DLSYM(handle, "Meta_Query");
- if (!pfn_query) {
+ if (!pfn_query)
+ {
META_ERROR("dll: Failed query plugin '%s'; Couldn't find Meta_Query(): %s", desc, DLERROR());
// caller will dlclose()
RETURN_ERRNO(mFALSE, ME_DLMISSING);
@@ -681,7 +709,7 @@ mBOOL MPlugin::query(void)
// Call Meta_Init, if present. This is an optional plugin routine to
// allow plugin to do any special initializing or other processing
- // prior to the standard query/attach procedure.
+ // prior to the standard query/attach procedure.
//
// In particular, this should allow for DLL's that can operate as both
// a standalone dll AND a metamod plugin. This routine has to be
@@ -694,17 +722,20 @@ mBOOL MPlugin::query(void)
// plugin can NOT use any g_engine functions, as they haven't been
// provided yet (done next, in GiveFnptrsToDll).
pfn_init = (META_INIT_FN) DLSYM(handle, "Meta_Init");
- if (pfn_init) {
+ if (pfn_init)
+ {
pfn_init();
META_DEBUG(6, ("dll: Plugin '%s': Called Meta_Init()", desc));
}
- else {
+ else
+ {
META_DEBUG(5, ("dll: no Meta_Init present in plugin '%s'", desc));
// don't return; not an error
}
// pass on engine function table and globals to plugin
- if (!(pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN) DLSYM(handle, "GiveFnptrsToDll"))) {
+ if (!(pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN) DLSYM(handle, "GiveFnptrsToDll")))
+ {
// META_ERROR("dll: Couldn't find GiveFnptrsToDll() in plugin '%s': %s", desc, DLERROR());
META_ERROR("dll: Failed query plugin '%s'; Couldn't find GiveFnptrsToDll(): %s", desc, DLERROR());
// caller will dlclose()
@@ -717,16 +748,19 @@ mBOOL MPlugin::query(void)
// plugin's info structure.
meta_errno = ME_NOERROR;
info = NULL;
+
// Make a copy of the meta_util function table for each plugin, for the
// same reason.
- memcpy(&mutil_funcs, &MetaUtilFunctions, sizeof(mutil_funcs));
+ Q_memcpy(&mutil_funcs, &MetaUtilFunctions, sizeof(mutil_funcs));
- if (pfn_query(META_INTERFACE_VERSION, &info, &mutil_funcs) != TRUE) {
+ if (pfn_query(META_INTERFACE_VERSION, &info, &mutil_funcs) != TRUE)
+ {
META_ERROR("dll: Failed query plugin '%s'; Meta_Query returned error",
desc);
meta_errno = ME_DLERROR;
}
- else {
+ else
+ {
META_DEBUG(6, ("dll: Plugin '%s': Called Meta_Query() successfully",
desc));
}
@@ -740,20 +774,23 @@ mBOOL MPlugin::query(void)
//
// Note, this check is done regardless of whether meta_query returns an
// error.
- if (info && !FStrEq(info->ifvers, META_INTERFACE_VERSION)) {
+ if (info && !FStrEq(info->ifvers, META_INTERFACE_VERSION))
+ {
int mmajor = 0, mminor = 0, pmajor = 0, pminor = 0;
META_DEBUG(3, ("dll: Note: Plugin '%s' interface version didn't match; expected %s, found %s", desc, META_INTERFACE_VERSION, info->ifvers));
sscanf(META_INTERFACE_VERSION, "%d:%d", &mmajor, &mminor);
sscanf(info->ifvers, "%d:%d", &pmajor, &pminor);
- // If plugin has later interface version, it's incompatible
+ // If plugin has later interface version, it's incompatible
// (update metamod).
- if (pmajor > mmajor || (pmajor == mmajor && pminor > mminor)) {
+ if (pmajor > mmajor || (pmajor == mmajor && pminor > mminor))
+ {
META_ERROR("dll: Plugin '%s' requires a newer version of Metamod (Metamod needs at least interface %s not the current %s)", desc, info->ifvers, META_INTERFACE_VERSION);
meta_errno = ME_IFVERSION;
}
// If plugin has older major interface version, it's incompatible
// (update plugin).
- else if (pmajor < mmajor) {
+ else if (pmajor < mmajor)
+ {
META_ERROR("dll: Plugin '%s' is out of date and incompatible with this version of Metamod; please find a newer version of the plugin (plugin needs at least interface %s not the current %s)", desc, META_INTERFACE_VERSION, info->ifvers);
meta_errno = ME_IFVERSION;
}
@@ -762,38 +799,42 @@ mBOOL MPlugin::query(void)
else if (pmajor == mmajor && pminor < mminor)
META_LOG("dll: Note: plugin '%s' is using an older interface version (%s), not the latest interface version (%s); there might be an updated version of the plugin", desc, info->ifvers, META_INTERFACE_VERSION);
else
- META_LOG("dll: Plugin '%s': unexpected version comparision; metavers=%s, mmajor=%d, mminor=%d; plugvers=%s, pmajor=%d, pminor=%d",
- desc, META_INTERFACE_VERSION, mmajor, mminor, info->ifvers, pmajor, pminor);
+ META_LOG("dll: Plugin '%s': unexpected version comparision; metavers=%s, mmajor=%d, mminor=%d; plugvers=%s, pmajor=%d, pminor=%d", desc, META_INTERFACE_VERSION, mmajor, mminor, info->ifvers, pmajor, pminor);
}
- if (meta_errno == ME_IFVERSION) {
+ if (meta_errno == ME_IFVERSION)
+ {
META_ERROR("dll: Rejected plugin '%s' due to interface version incompatibility (mm=%s, pl=%s)", desc, META_INTERFACE_VERSION, info->ifvers);
// meta_errno is set already above
// caller will dlclose()
- return (mFALSE);
+ return mFALSE;
}
else if (meta_errno != ME_NOERROR)
// some other error, already logged
- return (mFALSE);
+ return mFALSE;
- if (!info) {
+ if (!info)
+ {
META_ERROR("dll: Failed query plugin '%s'; Empty info structure", desc);
// caller will dlclose()
RETURN_ERRNO(mFALSE, ME_NULLRESULT);
}
+
// Replace temporary desc with plugin's internal name.
- if (desc[0] == '<') {
- strncpy(desc, info->name, sizeof desc - 1);
+ if (desc[0] == '<')
+ {
+ Q_strncpy(desc, info->name, sizeof desc - 1);
desc[sizeof desc - 1] = '\0';
}
+
META_DEBUG(6, ("dll: Plugin '%s': Query successful", desc));
- return (mTRUE);
+ return mTRUE;
}
// Attach a plugin:
// - dlsym() and call:
// Meta_Attach - get table of api tables, give meta_globals
-// - if provided by plugin, call various "Get" function pointers,
+// - if provided by plugin, call various "Get" function pointers,
// and store resulting function tables:
// GetEntityAPI (std)
// GetEntityAPI2 (std sdk2)
@@ -819,60 +860,66 @@ mBOOL MPlugin::attach(PLUG_LOADTIME now)
// Make copy of gameDLL's function tables for each plugin, so we don't
// risk the plugins screwing with the tables everyone uses.
- if (GameDLL.funcs.dllapi_table && !gamedll_funcs.dllapi_table) {
- gamedll_funcs.dllapi_table = (DLL_FUNCTIONS *) malloc(sizeof(DLL_FUNCTIONS));
- if (!gamedll_funcs.dllapi_table) {
+ if (GameDLL.funcs.dllapi_table && !gamedll_funcs.dllapi_table)
+ {
+ gamedll_funcs.dllapi_table = (DLL_FUNCTIONS *)Q_malloc(sizeof(DLL_FUNCTIONS));
+ if (!gamedll_funcs.dllapi_table)
+ {
META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for dllapi_table");
RETURN_ERRNO(mFALSE, ME_NOMEM);
}
- memcpy(gamedll_funcs.dllapi_table, GameDLL.funcs.dllapi_table,
- sizeof(DLL_FUNCTIONS));
+ Q_memcpy(gamedll_funcs.dllapi_table, GameDLL.funcs.dllapi_table, sizeof(DLL_FUNCTIONS));
}
- if (GameDLL.funcs.newapi_table && !gamedll_funcs.newapi_table) {
- gamedll_funcs.newapi_table = (NEW_DLL_FUNCTIONS *) calloc(1, sizeof(meta_new_dll_functions_t));
- if (!gamedll_funcs.newapi_table) {
+ if (GameDLL.funcs.newapi_table && !gamedll_funcs.newapi_table)
+ {
+ gamedll_funcs.newapi_table = (NEW_DLL_FUNCTIONS *)Q_calloc(1, sizeof(meta_new_dll_functions_t));
+ if (!gamedll_funcs.newapi_table)
+ {
META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for newapi_table");
RETURN_ERRNO(mFALSE, ME_NOMEM);
}
- static_cast(gamedll_funcs.newapi_table)->set_from(GameDLL.funcs.newapi_table);
+ static_cast(gamedll_funcs.newapi_table)->set_from(GameDLL.funcs.newapi_table);
}
- if (!(pfn_attach = (META_ATTACH_FN) DLSYM(handle, "Meta_Attach"))) {
+ if (!(pfn_attach = (META_ATTACH_FN) DLSYM(handle, "Meta_Attach")))
+ {
META_ERROR("dll: Failed attach plugin '%s': Couldn't find Meta_Attach(): %s", desc, DLERROR());
// caller will dlclose()
RETURN_ERRNO(mFALSE, ME_DLMISSING);
}
- memset(&meta_table, 0, sizeof(meta_table));
+ Q_memset(&meta_table, 0, sizeof(meta_table));
// get table of function tables,
// give public meta globals
ret = pfn_attach(now, &meta_table, &PublicMetaGlobals, &gamedll_funcs);
- if (ret != TRUE) {
+ if (ret != TRUE)
+ {
META_ERROR("dll: Failed attach plugin '%s': Error from Meta_Attach(): %d", desc, ret);
// caller will dlclose()
RETURN_ERRNO(mFALSE, ME_DLERROR);
}
+
META_DEBUG(6, ("dll: Plugin '%s': Called Meta_Attach() successfully", desc));
// Rather than duplicate code, we use another ugly macro. Again,
// a function isn't an option since we have varying types.
#define GET_FUNC_TABLE_FROM_PLUGIN(pfnGetFuncs, STR_GetFuncs, struct_field, API_TYPE, TABLE_TYPE, vers_pass, vers_int, vers_want) \
- if(meta_table.pfnGetFuncs) { \
+ if (meta_table.pfnGetFuncs) { \
if (!struct_field) \
- struct_field = (TABLE_TYPE*) calloc(1, sizeof(TABLE_TYPE)); \
- if(meta_table.pfnGetFuncs(struct_field, vers_pass)) { \
+ struct_field = (TABLE_TYPE *)Q_calloc(1, sizeof(TABLE_TYPE)); \
+ if (meta_table.pfnGetFuncs(struct_field, vers_pass)) { \
META_DEBUG(3, ("dll: Plugin '%s': Found %s", desc, STR_GetFuncs)); \
} \
else { \
META_ERROR("dll: Failure calling %s in plugin '%s'", STR_GetFuncs, desc); \
- if(vers_int != vers_want) \
+ if (vers_int != vers_want) \
META_ERROR("dll: Interface version didn't match; expected %d, found %d", vers_want, vers_int); \
} \
} \
else { \
META_DEBUG(5, ("dll: Plugin '%s': No %s", desc, STR_GetFuncs)); \
if (struct_field) \
- free(struct_field); \
- struct_field=NULL; \
+ Q_free(struct_field); \
+ struct_field = NULL; \
}
// Look for API-NEW interface in plugin. We do this before API2/API, because
@@ -886,60 +933,37 @@ mBOOL MPlugin::attach(PLUG_LOADTIME now)
// with older gamedlls which do not use the API-NEW themselves.
// It is yet unknown if this causes any problems in the engine.
iface_vers = NEW_DLL_FUNCTIONS_VERSION;
- GET_FUNC_TABLE_FROM_PLUGIN(pfnGetNewDLLFunctions,
- "GetNewDLLFunctions", newapi_table,
- NEW_DLL_FUNCTIONS_FN, meta_new_dll_functions_t,
- &iface_vers, iface_vers, NEW_DLL_FUNCTIONS_VERSION);
+ GET_FUNC_TABLE_FROM_PLUGIN(pfnGetNewDLLFunctions, "GetNewDLLFunctions", newapi_table, NEW_DLL_FUNCTIONS_FN, meta_new_dll_functions_t, &iface_vers, iface_vers, NEW_DLL_FUNCTIONS_VERSION);
+
iface_vers = NEW_DLL_FUNCTIONS_VERSION;
- GET_FUNC_TABLE_FROM_PLUGIN(pfnGetNewDLLFunctions_Post,
- "GetNewDLLFunctions_Post", newapi_post_table,
- NEW_DLL_FUNCTIONS_FN, meta_new_dll_functions_t,
- &iface_vers, iface_vers, NEW_DLL_FUNCTIONS_VERSION);
+ GET_FUNC_TABLE_FROM_PLUGIN(pfnGetNewDLLFunctions_Post, "GetNewDLLFunctions_Post", newapi_post_table, NEW_DLL_FUNCTIONS_FN, meta_new_dll_functions_t, &iface_vers, iface_vers, NEW_DLL_FUNCTIONS_VERSION);
// Look for API2 interface in plugin; preferred over API-1.
iface_vers = INTERFACE_VERSION;
- GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI2,
- "GetEntityAPI2", dllapi_table,
- APIFUNCTION2, DLL_FUNCTIONS,
- &iface_vers, iface_vers, INTERFACE_VERSION);
+ GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI2, "GetEntityAPI2", dllapi_table, APIFUNCTION2, DLL_FUNCTIONS, &iface_vers, iface_vers, INTERFACE_VERSION);
+
iface_vers = INTERFACE_VERSION;
- GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI2_Post,
- "GetEntityAPI2_Post", dllapi_post_table,
- APIFUNCTION2, DLL_FUNCTIONS,
- &iface_vers, iface_vers, INTERFACE_VERSION);
+ GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI2_Post, "GetEntityAPI2_Post", dllapi_post_table, APIFUNCTION2, DLL_FUNCTIONS, &iface_vers, iface_vers, INTERFACE_VERSION);
// Look for old-style API in plugin, if API2 interface wasn't found.
if (!dllapi_table && !dllapi_post_table) {
- GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI,
- "GetEntityAPI", dllapi_table,
- APIFUNCTION, DLL_FUNCTIONS,
- INTERFACE_VERSION, INTERFACE_VERSION, INTERFACE_VERSION);
- GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI_Post,
- "GetEntityAPI_Post", dllapi_post_table,
- APIFUNCTION, DLL_FUNCTIONS,
- INTERFACE_VERSION, INTERFACE_VERSION, INTERFACE_VERSION);
+ GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI, "GetEntityAPI", dllapi_table, APIFUNCTION, DLL_FUNCTIONS, INTERFACE_VERSION, INTERFACE_VERSION, INTERFACE_VERSION);
+ GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI_Post, "GetEntityAPI_Post", dllapi_post_table, APIFUNCTION, DLL_FUNCTIONS, INTERFACE_VERSION, INTERFACE_VERSION, INTERFACE_VERSION);
}
// Look for g_engine interface.
iface_vers = ENGINE_INTERFACE_VERSION;
- GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEngineFunctions,
- "GetEngineFunctions", engine_table,
- GET_ENGINE_FUNCTIONS_FN, meta_enginefuncs_t,
- &iface_vers, iface_vers, ENGINE_INTERFACE_VERSION);
- iface_vers = ENGINE_INTERFACE_VERSION;
- GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEngineFunctions_Post,
- "GetEngineFunctions_Post", engine_post_table,
- GET_ENGINE_FUNCTIONS_FN, meta_enginefuncs_t,
- &iface_vers, iface_vers, ENGINE_INTERFACE_VERSION);
+ GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEngineFunctions, "GetEngineFunctions", engine_table, GET_ENGINE_FUNCTIONS_FN, meta_enginefuncs_t, &iface_vers, iface_vers, ENGINE_INTERFACE_VERSION);
- if (!dllapi_table && !dllapi_post_table
- && !newapi_table && !newapi_post_table
- && !engine_table && !engine_post_table) {
+ iface_vers = ENGINE_INTERFACE_VERSION;
+ GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEngineFunctions_Post, "GetEngineFunctions_Post", engine_post_table, GET_ENGINE_FUNCTIONS_FN, meta_enginefuncs_t, &iface_vers, iface_vers, ENGINE_INTERFACE_VERSION);
+
+ if (!dllapi_table && !dllapi_post_table && !newapi_table && !newapi_post_table && !engine_table && !engine_post_table) {
META_LOG("dll: Plugin '%s' isn't catching _any_ functions ??", desc);
}
time_loaded = time(NULL);
- return (mTRUE);
+ return mTRUE;
}
// Unload a plugin. Check time, detach.
@@ -952,35 +976,44 @@ mBOOL MPlugin::attach(PLUG_LOADTIME now)
// - errno's from check_input()
mBOOL MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, PL_UNLOAD_REASON real_reason)
{
- if (!check_input()) {
+ if (!check_input())
+ {
// details logged, meta_errno set in check_input()
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
- if (status < PL_RUNNING) {
- if (reason != PNL_CMD_FORCED && reason != PNL_RELOAD) {
+ if (status < PL_RUNNING)
+ {
+ if (reason != PNL_CMD_FORCED && reason != PNL_RELOAD)
+ {
META_ERROR("dll: Not unloading plugin '%s'; already unloaded (status=%s)", desc, str_status());
RETURN_ERRNO(mFALSE, ME_ALREADY);
}
}
- if (action != PA_UNLOAD && action != PA_RELOAD) {
+ if (action != PA_UNLOAD && action != PA_RELOAD)
+ {
META_WARNING("dll: Not unloading plugin '%s'; not marked for unload (action=%s)", desc, str_action());
RETURN_ERRNO(mFALSE, ME_BADREQ);
}
// Are we allowed to detach this plugin at this time?
// If forcing unload, we disregard when plugin wants to be unloaded.
- if (info && info->unloadable < now) {
- if (reason == PNL_CMD_FORCED) {
+ if (info && info->unloadable < now)
+ {
+ if (reason == PNL_CMD_FORCED)
+ {
META_DEBUG(2, ("dll: Forced unload plugin '%s' overriding allowed times: allowed=%s; now=%s", desc, str_unloadable(), str_loadtime(now, SL_SIMPLE)));
}
- else {
- if (info->unloadable > PT_STARTUP) {
+ else
+ {
+ if (info->unloadable > PT_STARTUP)
+ {
META_DEBUG(2, ("dll: Delaying unload plugin '%s'; can't detach now: allowed=%s; now=%s", desc, str_unloadable(), str_loadtime(now, SL_SIMPLE)));
// caller should give message to user
// try to unload again at next opportunity
RETURN_ERRNO(mFALSE, ME_DELAYED);
}
- else {
+ else
+ {
META_DEBUG(2, ("dll: Failed unload plugin '%s'; can't detach now: allowed=%s; now=%s", desc, str_unloadable(), str_loadtime(now, SL_SIMPLE)));
// don't try to unload again later
action = PA_NONE;
@@ -995,17 +1028,21 @@ mBOOL MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, PL_UNLOAD_REAS
// indicates these two routines should match call for call.
// detach plugin
- if (!detach(now, reason)) {
- if (reason == PNL_RELOAD) {
+ if (!detach(now, reason))
+ {
+ if (reason == PNL_RELOAD)
+ {
META_DEBUG(2, ("dll: Reload plugin '%s' overriding failed detach", desc));
}
- else if (reason == PNL_CMD_FORCED) {
+ else if (reason == PNL_CMD_FORCED)
+ {
META_DEBUG(2, ("dll: Forced unload plugin '%s' overriding failed detach"));
}
- else {
+ else
+ {
META_WARNING("dll: Failed to detach plugin '%s'; ", desc);
// meta_errno should be already set in detach()
- return (mFALSE);
+ return mFALSE;
}
}
@@ -1021,28 +1058,32 @@ mBOOL MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, PL_UNLOAD_REAS
#ifdef UNFINISHED
// Remove all requested hooks from this plugin (by index number).
Hooks->remove_all(info);
-#endif /* UNFINISHED */
+#endif
// Close the file. Note: after this, attempts to reference any memory
// locations in the file will produce a segfault.
- if (DLCLOSE(handle) != 0) {
+ if (DLCLOSE(handle) != 0)
+ {
// If DLL cannot be closed, OS is badly broken or we are giving invalid handle.
// So we don't return here but instead remove plugin from our listings.
META_WARNING("dll: Couldn't close plugin file '%s': %s", file, DLERROR());
}
handle = NULL;
- if (action == PA_UNLOAD) {
+ if (action == PA_UNLOAD)
+ {
status = PL_EMPTY;
clear();
}
- else if (action == PA_RELOAD) {
+ else if (action == PA_RELOAD)
+ {
status = PL_VALID;
action = PA_LOAD;
clear();
}
+
META_LOG("dll: Unloaded plugin '%s' for reason '%s'", desc, str_reason(reason, real_reason));
- return (mTRUE);
+ return mTRUE;
}
// Inform plugin we're going to unload it.
@@ -1060,19 +1101,22 @@ mBOOL MPlugin::detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
if (!handle)
return mTRUE;
- if (!(pfn_detach = (META_DETACH_FN) DLSYM(handle, "Meta_Detach"))) {
+ if (!(pfn_detach = (META_DETACH_FN) DLSYM(handle, "Meta_Detach")))
+ {
META_ERROR("dll: Error detach plugin '%s': Couldn't find Meta_Detach(): %s", desc, DLERROR());
// caller will dlclose()
RETURN_ERRNO(mFALSE, ME_DLMISSING);
}
ret = pfn_detach(now, reason);
- if (ret != TRUE) {
+ if (ret != TRUE)
+ {
META_ERROR("dll: Failed detach plugin '%s': Error from Meta_Detach(): %d", desc, ret);
RETURN_ERRNO(mFALSE, ME_DLERROR);
}
+
META_DEBUG(6, ("dll: Plugin '%s': Called Meta_Detach() successfully", desc));
- return (mTRUE);
+ return mTRUE;
}
// Reload a plugin; unload and load again.
@@ -1083,20 +1127,24 @@ mBOOL MPlugin::detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
// - errno's from load()
mBOOL MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
- if (!check_input()) {
+ if (!check_input())
+ {
// details logged, meta_errno set in check_input()
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
// Are we allowed to load this plugin at this time?
// If we cannot load the plugin after unloading it, we keep it.
- if (info && info->loadable < now) {
- if (info->loadable > PT_STARTUP) {
+ if (info && info->loadable < now)
+ {
+ if (info->loadable > PT_STARTUP)
+ {
META_DEBUG(2, ("dll: Delaying reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", desc, str_loadable(), str_loadtime(now, SL_SIMPLE)));
// caller should give message to user
// try to reload again at next opportunity
RETURN_ERRNO(mFALSE, ME_DELAYED);
}
- else {
+ else
+ {
META_DEBUG(2, ("dll: Failed reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", desc, str_loadable(), str_loadtime(now, SL_SIMPLE)));
// don't try to reload again later
action = PA_NONE;
@@ -1104,21 +1152,27 @@ mBOOL MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
}
}
- if (status < PL_RUNNING) {
+ if (status < PL_RUNNING)
+ {
META_WARNING("dll: Plugin '%s' isn't running; Forcing unload plugin for reloading", desc);
reason = PNL_RELOAD;
}
- if (!unload(now, reason, reason)) {
+
+ if (!unload(now, reason, reason))
+ {
META_WARNING("dll: Failed to unload plugin '%s' for reloading", desc);
// meta_errno should be set already in unload()
- return (mFALSE);
+ return mFALSE;
}
- if (!load(now)) {
+
+ if (!load(now))
+ {
META_WARNING("dll: Failed to reload plugin '%s' after unloading", desc);
// meta_errno should be set already in load()
- return (mFALSE);
+ return mFALSE;
}
- return (mTRUE);
+
+ return mTRUE;
}
// Pause a plugin; temporarily disabled for API routines.
@@ -1126,19 +1180,22 @@ mBOOL MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
// - ME_ALREADY this plugin already paused
// - ME_BADREQ can't pause; not running
// - ME_NOTALLOWED plugin doesn't want to be paused
-mBOOL MPlugin::pause(void)
+mBOOL MPlugin::pause()
{
- if (status == PL_PAUSED) {
+ if (status == PL_PAUSED)
+ {
META_ERROR("Not pausing plugin '%s'; already paused", desc);
RETURN_ERRNO(mFALSE, ME_ALREADY);
}
- if (status != PL_RUNNING) {
+ if (status != PL_RUNNING)
+ {
META_ERROR("Cannot pause plugin '%s'; not currently running (status=%s)", desc, str_status());
RETURN_ERRNO(mFALSE, ME_BADREQ);
}
// are we allowed to pause this plugin?
- if (info->unloadable < PT_ANYPAUSE) {
+ if (info->unloadable < PT_ANYPAUSE)
+ {
META_ERROR("Cannot pause plugin '%s'; not allowed by plugin (allowed=%s)", desc, str_unloadable());
action = PA_NONE;
RETURN_ERRNO(mFALSE, ME_NOTALLOWED);
@@ -1146,21 +1203,23 @@ mBOOL MPlugin::pause(void)
status = PL_PAUSED;
META_LOG("Paused plugin '%s'", desc);
- return (mTRUE);
+ return mTRUE;
}
// Unpause a plugin.
// meta_errno values:
// - ME_BADREQ can't unpause; not paused
-mBOOL MPlugin::unpause(void)
+mBOOL MPlugin::unpause()
{
- if (status != PL_PAUSED) {
+ if (status != PL_PAUSED)
+ {
META_ERROR("Cannot unpause plugin '%s'; not currently paused (status=%s)", desc, str_status());
RETURN_ERRNO(mFALSE, ME_BADREQ);
}
+
status = PL_RUNNING;
META_LOG("Unpaused plugin '%s'", desc);
- return (mTRUE);
+ return mTRUE;
}
// Retry pending action, presumably from a previous failure.
@@ -1172,14 +1231,15 @@ mBOOL MPlugin::unpause(void)
mBOOL MPlugin::retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
if (action == PA_LOAD)
- return (load(now));
+ return load(now);
else if (action == PA_ATTACH)
- return (load(now));
+ return load(now);
else if (action == PA_UNLOAD)
- return (unload(now, reason, reason));
+ return unload(now, reason, reason);
else if (action == PA_RELOAD)
- return (reload(now, reason));
- else {
+ return reload(now, reason);
+ else
+ {
META_ERROR("No pending action to retry for plugin '%s'; (status=%s, action=%s)", desc, str_status(), str_action());
RETURN_ERRNO(mFALSE, ME_BADREQ);
}
@@ -1192,28 +1252,29 @@ mBOOL MPlugin::retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
// - ME_DLERROR failed to dlclose
mBOOL MPlugin::clear(void)
{
- if (status != PL_FAILED && status != PL_BADFILE
- && status != PL_EMPTY && status != PL_OPENED) {
+ if (status != PL_FAILED && status != PL_BADFILE && status != PL_EMPTY && status != PL_OPENED)
+ {
META_ERROR("Cannot clear plugin '%s'; not marked as failed, empty, or open (status=%s)", desc, str_status());
RETURN_ERRNO(mFALSE, ME_BADREQ);
}
// If file is open, close the file. Note: after this, attempts to
// reference any memory locations in the file will produce a segfault.
- if (handle && DLCLOSE(handle) != 0) {
+ if (handle && DLCLOSE(handle) != 0)
+ {
META_ERROR("dll: Couldn't close plugin file '%s': %s", file, DLERROR());
status = PL_FAILED;
RETURN_ERRNO(mFALSE, ME_DLERROR);
}
handle = NULL;
- if (gamedll_funcs.dllapi_table) free(gamedll_funcs.dllapi_table);
- if (gamedll_funcs.newapi_table) free(gamedll_funcs.newapi_table);
- if (dllapi_table) free(dllapi_table);
- if (dllapi_post_table) free(dllapi_post_table);
- if (newapi_table) free(newapi_table);
- if (newapi_post_table) free(newapi_post_table);
- if (engine_table) free(engine_table);
- if (engine_post_table) free(engine_post_table);
+ if (gamedll_funcs.dllapi_table) Q_free(gamedll_funcs.dllapi_table);
+ if (gamedll_funcs.newapi_table) Q_free(gamedll_funcs.newapi_table);
+ if (dllapi_table) Q_free(dllapi_table);
+ if (dllapi_post_table) Q_free(dllapi_post_table);
+ if (newapi_table) Q_free(newapi_table);
+ if (newapi_post_table) Q_free(newapi_post_table);
+ if (engine_table) Q_free(engine_table);
+ if (engine_post_table) Q_free(engine_post_table);
status = PL_EMPTY;
action = PA_NULL;
@@ -1231,15 +1292,17 @@ mBOOL MPlugin::clear(void)
source_plugin_index = 0;
unloader_index = 0;
is_unloader = mFALSE;
- return (mTRUE);
+
+ return mTRUE;
}
// List information about plugin to console.
-void MPlugin::show(void)
+void MPlugin::show()
{
char *cp, *tstr;
- int n, width;
- width = 13;
+ const int width = 13;
+ int n;
+
META_CONS("%*s: %s", width, "name", info ? info->name : "(nil)");
META_CONS("%*s: %s", width, "desc", desc);
META_CONS("%*s: %s", width, "status", str_status());
@@ -1257,21 +1320,26 @@ void MPlugin::show(void)
META_CONS("%*s: %s", width, "url", info ? info->url : "(nil)");
META_CONS("%*s: %s", width, "logtag", info ? info->logtag : "(nil)");
META_CONS("%*s: %s", width, "ifvers", info ? info->ifvers : "(nil)");
+
// ctime() includes newline at EOL
tstr = ctime(&time_loaded);
- if ((cp = strchr(tstr, '\n')))
+ if ((cp = Q_strchr(tstr, '\n')))
*cp = '\0';
+
META_CONS("%*s: %s", width, "last loaded", tstr);
// XXX show file time ?
- if (dllapi_table) {
+ if (dllapi_table)
+ {
META_CONS("DLLAPI functions:");
- SHOW_DEF_DLLAPI(dllapi_table, " ", "");
+ SHOW_DEF_DLLAPI(dllapi_table," ", "");
META_CONS("%d functions (dllapi)", n);
}
else
META_CONS("No DLLAPI functions.");
- if (dllapi_post_table) {
+
+ if (dllapi_post_table)
+ {
META_CONS("DLLAPI-Post functions:");
SHOW_DEF_DLLAPI(dllapi_post_table, " ", "_Post");
META_CONS("%d functions (dllapi post)", n);
@@ -1279,14 +1347,17 @@ void MPlugin::show(void)
else
META_CONS("No DLLAPI-Post functions.");
- if (newapi_table) {
+ if (newapi_table)
+ {
META_CONS("NEWAPI functions:");
SHOW_DEF_NEWAPI(newapi_table, " ", "");
META_CONS("%d functions (newapi)", n);
}
else
META_CONS("No NEWAPI functions.");
- if (newapi_post_table) {
+
+ if (newapi_post_table)
+ {
META_CONS("NEWAPI-Post functions:");
SHOW_DEF_NEWAPI(newapi_post_table, " ", "_Post");
META_CONS("%d functions (newapi post)", n);
@@ -1294,22 +1365,27 @@ void MPlugin::show(void)
else
META_CONS("No NEWAPI-Post functions.");
- if (engine_table) {
- META_CONS("g_engine functions:");
+ if (engine_table)
+ {
+ META_CONS("Engine functions:");
SHOW_DEF_ENGINE(engine_table, " ", "");
META_CONS("%d functions (engine)", n);
}
else
- META_CONS("No g_engine functions.");
- if (engine_post_table) {
- META_CONS("g_engine-Post functions:");
+ META_CONS("No Engine functions.");
+
+ if (engine_post_table)
+ {
+ META_CONS("Engine-Post functions:");
SHOW_DEF_ENGINE(engine_post_table, " ", "_Post");
META_CONS("%d functions (engine post)", n);
}
else
- META_CONS("No g_engine-Post functions.");
+ META_CONS("No Engine-Post functions.");
+
g_regCmds->show(index);
g_regCvars->show(index);
+
if (g_plugins->found_child_plugins(index))
g_plugins->show(index);
else
@@ -1321,20 +1397,20 @@ void MPlugin::show(void)
// meta_errno values:
// - ME_NOFILE couldn't find file
// - ME_NOERROR no error; false indicates file not newer
-mBOOL MPlugin::newer_file(void)
+mBOOL MPlugin::newer_file()
{
struct stat st;
time_t file_time;
if (stat(pathname, &st) != 0)
- RETURN_ERRNO(mFALSE, ME_NOFILE);
- file_time = max(st.st_ctime, st.st_mtime);
- META_DEBUG(5, ("newer_file? file=%s; load=%d, file=%d; ctime=%d, mtime=%d",
- file, time_loaded, file_time, st.st_ctime, st.st_mtime));
+ RETURN_ERRNO(mFALSE, ME_NOFILE);
+
+ file_time = st.st_ctime > st.st_mtime ? st.st_ctime : st.st_mtime;
+ META_DEBUG(5, ("newer_file? file=%s; load=%d, file=%d; ctime=%d, mtime=%d", file, time_loaded, file_time, st.st_ctime, st.st_mtime));
if (file_time > time_loaded)
- return (mTRUE);
+ return mTRUE;
else
- RETURN_ERRNO(mFALSE, ME_NOERROR);
+ RETURN_ERRNO(mFALSE, ME_NOERROR);
}
// Return a string describing status of plugin.
@@ -1342,33 +1418,34 @@ mBOOL MPlugin::newer_file(void)
// SHOW is max 4 chars, for "show" output.
// meta_errno values:
// - none
-const char* MPlugin::str_status(STR_STATUS fmt)
+const char *MPlugin::str_status(STR_STATUS fmt)
{
- switch (status) {
+ switch (status)
+ {
case PL_EMPTY:
- if (fmt == ST_SHOW) return ("empt");
- else return ("empty");
+ if (fmt == ST_SHOW) return "empt";
+ else return "empty";
case PL_VALID:
- if (fmt == ST_SHOW) return ("info");
- else return ("valid");
+ if (fmt == ST_SHOW) return"info";
+ else return "valid";
case PL_BADFILE:
- if (fmt == ST_SHOW) return ("badf");
- else return ("badfile");
+ if (fmt == ST_SHOW) return "badf";
+ else return "badfile";
case PL_OPENED:
- if (fmt == ST_SHOW) return ("open");
- else return ("opened");
+ if (fmt == ST_SHOW) return "open";
+ else return "opened";
case PL_FAILED:
- if (fmt == ST_SHOW) return ("fail");
- else return ("failed");
+ if (fmt == ST_SHOW) return "fail";
+ else return "failed";
case PL_RUNNING:
- if (fmt == ST_SHOW) return ("RUN");
- else return ("running");
+ if (fmt == ST_SHOW) return "RUN";
+ else return "running";
case PL_PAUSED:
- if (fmt == ST_SHOW) return ("PAUS");
- else return ("paused");
+ if (fmt == ST_SHOW) return "PAUS";
+ else return "paused";
default:
- if (fmt == ST_SHOW) return (UTIL_VarArgs("UNK%d", status));
- return (UTIL_VarArgs("unknown (%d)", status));
+ if (fmt == ST_SHOW) return UTIL_VarArgs("UNK%d", status);
+ return UTIL_VarArgs("unknown (%d)", status);
}
}
@@ -1377,33 +1454,34 @@ const char* MPlugin::str_status(STR_STATUS fmt)
// SHOW is max 4 chars, for "show" output.
// meta_errno values:
// - none
-const char* MPlugin::str_action(STR_ACTION fmt)
+const char *MPlugin::str_action(STR_ACTION fmt)
{
- switch (action) {
+ switch (action)
+ {
case PA_NULL:
- if (fmt == SA_SHOW) return ("NULL");
- else return ("null");
+ if (fmt == SA_SHOW) return "NULL";
+ else return "null";
case PA_NONE:
- if (fmt == SA_SHOW) return (" - ");
- else return ("none");
+ if (fmt == SA_SHOW) return " - ";
+ else return "none";
case PA_KEEP:
- if (fmt == SA_SHOW) return ("keep");
- else return ("keep");
+ if (fmt == SA_SHOW) return "keep";
+ else return "keep";
case PA_LOAD:
- if (fmt == SA_SHOW) return ("load");
- else return ("load");
+ if (fmt == SA_SHOW) return "load";
+ else return "load";
case PA_ATTACH:
- if (fmt == SA_SHOW) return ("atch");
- else return ("attach");
+ if (fmt == SA_SHOW) return "atch";
+ else return "attach";
case PA_UNLOAD:
- if (fmt == SA_SHOW) return ("unld");
- else return ("unload");
+ if (fmt == SA_SHOW) return "unld";
+ else return "unload";
case PA_RELOAD:
- if (fmt == SA_SHOW) return ("relo");
- else return ("reload");
+ if (fmt == SA_SHOW) return "relo";
+ else return "reload";
default:
- if (fmt == SA_SHOW) return (UTIL_VarArgs("UNK%d", action));
- else return (UTIL_VarArgs("unknown (%d)", action));
+ if (fmt == SA_SHOW) return UTIL_VarArgs("UNK%d", action);
+ else return UTIL_VarArgs("unknown (%d)", action);
}
}
@@ -1414,101 +1492,97 @@ const char* MPlugin::str_action(STR_ACTION fmt)
// NOW is to describe current situation of load/unload attempt.
// meta_errno values:
// - none
-const char* MPlugin::str_loadtime(PLUG_LOADTIME ptime, STR_LOADTIME fmt)
+const char *MPlugin::str_loadtime(PLUG_LOADTIME ptime, STR_LOADTIME fmt)
{
- switch (ptime) {
- case PT_NEVER:
- if (fmt == SL_SHOW) return ("Never");
- else return ("never");
- case PT_STARTUP:
- if (fmt == SL_SHOW) return ("Start");
- else if (fmt == SL_ALLOWED) return ("at server startup");
- else if (fmt == SL_NOW) return ("during server startup");
- else return ("startup");
- case PT_CHANGELEVEL:
- if (fmt == SL_SHOW) return ("Chlvl");
- else if (fmt == SL_ALLOWED) return ("at changelevel");
- else if (fmt == SL_NOW) return ("during changelevel");
- else return ("changelevel");
- case PT_ANYTIME:
- if (fmt == SL_SHOW) return ("ANY");
- else if (fmt == SL_ALLOWED) return ("at any time");
- else if (fmt == SL_NOW) return ("during map");
- else return ("anytime");
- case PT_ANYPAUSE:
- if (fmt == SL_SHOW) return ("Pause");
- else if (fmt == SL_ALLOWED) return ("at any time, and pausable");
- else if (fmt == SL_NOW) return ("for requested pause");
- else return ("pausable");
- default:
- if (fmt == SL_SHOW) return (UTIL_VarArgs("UNK-%d", ptime));
- else return (UTIL_VarArgs("unknown (%d)", ptime));
- }
+ static const char *rPrintLoadTime[][26] = {
+ // SL_SIMPLE // SL_SHOW // SL_ALLOWED // SL_NOW
+ { "never", "Never", "never", "never" }, // PT_NEVER
+ { "startup", "Start", "at server startup", "during server startup" }, // PT_STARTUP
+ { "changelevel","Chlvl", "at changelevel", "during changelevel" }, // PT_CHANGELEVEL
+ { "anytime", "ANY", "at any time", "during map" }, // PT_ANYTIME
+ { "pausable", "Pause", "at any time, and pausable", "for requested pause" }, // PT_ANYPAUSE
+ };
+
+ if (ptime >= PT_NEVER || ptime <= PT_ANYPAUSE)
+ return rPrintLoadTime[ptime][fmt];
+
+ if (fmt == SL_SHOW)
+ return UTIL_VarArgs("UNK-%d", ptime);
+
+ return UTIL_VarArgs("unknown (%d)", ptime);
}
// Return a string describing why a plugin is to be unloaded.
// meta_errno values:
// - none
-const char* MPlugin::str_reason(PL_UNLOAD_REASON preason, PL_UNLOAD_REASON preal_reason)
+const char *MPlugin::str_reason(PL_UNLOAD_REASON preason, PL_UNLOAD_REASON preal_reason)
{
char buf[128];
if (preason == PNL_PLUGIN)
preason = PNL_NULL;
- if (preason == PNL_PLG_FORCED)
+ else if (preason == PNL_PLG_FORCED)
preason = PNL_NULL;
- switch (preal_reason) {
+ switch (preal_reason)
+ {
case PNL_NULL:
- return ("null");
+ return "null";
case PNL_INI_DELETED:
- return ("deleted from ini file");
+ return "deleted from ini file";
case PNL_FILE_NEWER:
- return ("file on disk is newer");
+ return "file on disk is newer";
case PNL_COMMAND:
- return ("server command");
+ return "server command";
case PNL_CMD_FORCED:
- return ("forced by server command");
+ return "forced by server command";
case PNL_PLUGIN:
- strncpy(buf, str_reason(PNL_NULL, preason), sizeof buf - 1);
- buf[sizeof buf - 1] = '\0';
- return (UTIL_VarArgs("%s (request from plugin[%d])", buf, unloader_index));
+ {
+ Q_strncpy(buf, str_reason(PNL_NULL, preason), sizeof(buf) - 1);
+ buf[sizeof(buf) - 1] = '\0';
+
+ return UTIL_VarArgs("%s (request from plugin[%d])", buf, unloader_index);
+ }
case PNL_PLG_FORCED:
- strncpy(buf, str_reason(PNL_NULL, preason), sizeof buf - 1);
- buf[sizeof buf - 1] = '\0';
- return (UTIL_VarArgs("%s (forced request from plugin[%d])", buf, unloader_index));
+ {
+ Q_strncpy(buf, str_reason(PNL_NULL, preason), sizeof(buf) - 1);
+ buf[sizeof(buf) - 1] = '\0';
+
+ return UTIL_VarArgs("%s (forced request from plugin[%d])", buf, unloader_index);
+ }
case PNL_RELOAD:
- return ("reloading");
+ return "reloading";
default:
- return (UTIL_VarArgs("unknown (%d)", preal_reason));
+ return UTIL_VarArgs("unknown (%d)", preal_reason);
}
}
// Return a string describing how the plugin was loaded.
// meta_errno values:
// - none
-const char* MPlugin::str_source(STR_SOURCE fmt)
+const char *MPlugin::str_source(STR_SOURCE fmt)
{
- switch (source) {
+ switch (source)
+ {
case PS_INI:
- if (fmt == SO_SHOW) return ("ini");
- else return ("ini file");
+ if (fmt == SO_SHOW) return "ini";
+ else return "ini file";
case PS_CMD:
- if (fmt == SO_SHOW) return ("cmd");
- else return ("console command");
+ if (fmt == SO_SHOW) return "cmd";
+ else return "console command";
case PS_PLUGIN:
- if (source_plugin_index <= 0) {
- if (fmt == SO_SHOW)
- return ("plUN");
- else
- return ("unloaded plugin");
+ if (source_plugin_index <= 0)
+ {
+ if (fmt == SO_SHOW) return "plUN";
+ else return "unloaded plugin";
}
- else {
- if (fmt == SO_SHOW) return (UTIL_VarArgs("pl%d", source_plugin_index));
- else return (UTIL_VarArgs("plugin [%d]", source_plugin_index));
+ else
+ {
+ if (fmt == SO_SHOW) return UTIL_VarArgs("pl%d", source_plugin_index);
+ else return UTIL_VarArgs("plugin [%d]", source_plugin_index);
}
default:
- if (fmt == SO_SHOW) return (UTIL_VarArgs("UNK%d", source));
- else return (UTIL_VarArgs("unknown (%d)", source));
+ if (fmt == SO_SHOW) return UTIL_VarArgs("UNK%d", source);
+ else return UTIL_VarArgs("unknown (%d)", source);
}
}
diff --git a/metamod/src/mplugin.h b/metamod/src/mplugin.h
index 995ebf3..58c0c40 100644
--- a/metamod/src/mplugin.h
+++ b/metamod/src/mplugin.h
@@ -1,67 +1,24 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// mplugin.h - class and types to describe an individual plugin
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef MPLUGIN_H
-#define MPLUGIN_H
-
-#include // time_t, etc
-
-#include // DLL_FUNCTIONS, etc
-
-#include "types_meta.h" // mBOOL
-#include "meta_api.h" // GETENTITYAPI_FN, etc
-#include "api_info.h" // dllapi_info, etc
-#include "support_meta.h" // MAX_DESC_LEN
+#pragma once
+#include "api_info.h"
+#include "support_meta.h"
// Flags to indicate current "load" state of plugin.
// NOTE: order is important, as greater/less comparisons are made.
-typedef enum {
- PL_EMPTY = 0, // empty slot
+enum PLUG_STATUS
+{
+ PL_EMPTY = 0, // empty slot
PL_VALID, // has valid info in it
- PL_BADFILE, // nonexistent file (open failed),
- // or not a valid plugin file (query failed)
+ PL_BADFILE, // nonexistent file (open failed), or not a valid plugin file (query failed)
PL_OPENED, // dlopened and queried
PL_FAILED, // opened, but failed to attach or unattach
PL_RUNNING, // attached and running
PL_PAUSED, // attached but paused
-} PLUG_STATUS;
+};
// Action to take for plugin at next opportunity.
-typedef enum {
+enum PLUG_ACTION
+{
PA_NULL = 0,
PA_NONE, // no action needed right now
PA_KEEP, // keep, after ini refresh
@@ -69,138 +26,140 @@ typedef enum {
PA_ATTACH, // attach
PA_UNLOAD, // unload (detach, dlclose)
PA_RELOAD, // unload and load again
-} PLUG_ACTION;
+};
// Flags to indicate from where the plugin was loaded.
-typedef enum {
+enum PLOAD_SOURCE
+{
PS_INI = 0, // was loaded from the plugins.ini
PS_CMD, // was loaded via a server command
- PS_PLUGIN, // was loaded via a plugin
-} PLOAD_SOURCE;
+ PS_PLUGIN, // was loaded by other plugin
+};
// Flags for how to word description of plugin loadtime.
-typedef enum {
- SL_SIMPLE = 0, // single word
+enum STR_LOADTIME
+{
+ SL_SIMPLE = 0, // single word
SL_SHOW, // for "show" output, 5 chars
SL_ALLOWED, // when plugin is allowed to load/unload
SL_NOW, // current situation
-} STR_LOADTIME;
+};
// Flags for how to format description of status.
-typedef enum {
- ST_SIMPLE = 0, // single word
+enum STR_STATUS
+{
+ ST_SIMPLE = 0, // single word
ST_SHOW, // for "show" output, 4 chars
-} STR_STATUS;
+};
// Flags for how to format description of action.
-typedef enum {
- SA_SIMPLE = 0, // single word
+enum STR_ACTION
+{
+ SA_SIMPLE = 0, // single word
SA_SHOW, // for "show" output, 4 chars
-} STR_ACTION;
+};
// Flags for how to format description of source.
-typedef enum {
- SO_SIMPLE = 0, // two words
+enum STR_SOURCE
+{
+ SO_SIMPLE = 0, // two words
SO_SHOW, // for "list" output, 3 chars
-} STR_SOURCE;
+};
// An individual plugin.
class MPlugin {
- private:
- mBOOL query(void);
- mBOOL attach(PLUG_LOADTIME now);
- mBOOL detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
- gamedll_funcs_t gamedll_funcs;
- mutil_funcs_t mutil_funcs;
- public:
- // data:
- int index; // 1-based
- char filename[PATH_MAX]; // ie "dlls/mm_test_i386.so", from inifile
- char *file; // ie "mm_test_i386.so", ptr from filename
- char desc[MAX_DESC_LEN]; // ie "Test metamod plugin", from inifile
- char pathname[PATH_MAX]; // UNIQUE, ie "/home/willday/half-life/cstrike/dlls/mm_test_i386.so", built with GameDLL.gamedir
- int pfspecific; // level of specific platform affinity, used during load time
- PLUG_STATUS status; // current status of plugin (loaded, etc)
- PLUG_ACTION action; // what to do with plugin (load, unload, etc)
- PLOAD_SOURCE source; // source of the request to load the plugin
+private:
+ mBOOL query();
+ mBOOL attach(PLUG_LOADTIME now);
+ mBOOL detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
+ gamedll_funcs_t gamedll_funcs;
+ mutil_funcs_t mutil_funcs;
- DLHANDLE handle; // handle for dlopen, dlsym, etc
- plugin_info_t *info; // information plugin provides about itself
- time_t time_loaded; // when plugin was loaded
- int source_plugin_index; // who loaded this plugin
- int unloader_index;
- mBOOL is_unloader; // fix to prevent other plugins unload active unloader.
+public:
+ int index; // 1-based
+ char filename[PATH_MAX]; // ie "dlls/mm_test_i386.so", from inifile
+ char *file; // ie "mm_test_i386.so", ptr from filename
+ char desc[MAX_DESC_LEN]; // ie "Test metamod plugin", from inifile
+ char pathname[PATH_MAX]; // UNIQUE, ie "/home/willday/half-life/cstrike/dlls/mm_test_i386.so", built with GameDLL.gamedir
+ int pfspecific; // level of specific platform affinity, used during load time
+ PLUG_STATUS status; // current status of plugin (loaded, etc)
+ PLUG_ACTION action; // what to do with plugin (load, unload, etc)
+ PLOAD_SOURCE source; // source of the request to load the plugin
- DLL_FUNCTIONS *dllapi_table;
- DLL_FUNCTIONS *dllapi_post_table;
- NEW_DLL_FUNCTIONS *newapi_table;
- NEW_DLL_FUNCTIONS *newapi_post_table;
- enginefuncs_t *engine_table;
- enginefuncs_t *engine_post_table;
+ DLHANDLE handle; // handle for dlopen, dlsym, etc
+ plugin_info_t *info; // information plugin provides about itself
+ time_t time_loaded; // when plugin was loaded
+ int source_plugin_index; // who loaded this plugin
+ int unloader_index;
+ mBOOL is_unloader; // fix to prevent other plugins unload active unloader.
- // functions:
-
- mBOOL ini_parseline(char *line); // parse line from inifile
- mBOOL cmd_parseline(const char *line); // parse from console command
- mBOOL plugin_parseline(const char *fname, int loader_index); // parse from plugin
- mBOOL check_input(void);
+ DLL_FUNCTIONS *dllapi_table;
+ DLL_FUNCTIONS *dllapi_post_table;
+ NEW_DLL_FUNCTIONS *newapi_table;
+ NEW_DLL_FUNCTIONS *newapi_post_table;
+ enginefuncs_t *engine_table;
+ enginefuncs_t *engine_post_table;
- mBOOL resolve(void); // find a matching file on disk
- char *resolve_dirs(char *path);
- char *resolve_prefix(char *path);
- char *resolve_suffix(char *path);
+ mBOOL ini_parseline(char *line); // parse line from inifile
+ mBOOL cmd_parseline(const char *line); // parse from console command
+ mBOOL plugin_parseline(const char *fname, int loader_index); // parse from plugin
+ mBOOL check_input();
- mBOOL platform_match(MPlugin* plugin);
-
- mBOOL load(PLUG_LOADTIME now);
- mBOOL unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, PL_UNLOAD_REASON real_reason);
- mBOOL reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
- mBOOL pause(void);
- mBOOL unpause(void);
- mBOOL retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // if previously failed
- mBOOL clear(void);
- mBOOL plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // other plugin unloading
- void show(void); // print info about plugin to console
+ mBOOL resolve(); // find a matching file on disk
+ char *resolve_dirs(char *path);
+ char *resolve_prefix(char *path);
+ char *resolve_suffix(char *path);
- mBOOL newer_file(void); // check for newer file on disk
+ mBOOL platform_match(MPlugin* plugin);
- // output string functions
- const char *str_status(STR_STATUS fmt);
- const char *str_action(STR_ACTION fmt);
- const char *str_source(STR_SOURCE fmt);
+ mBOOL load(PLUG_LOADTIME now);
+ mBOOL unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, PL_UNLOAD_REASON real_reason);
+ mBOOL reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
+ mBOOL pause();
+ mBOOL unpause();
+ mBOOL retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // if previously failed
+ mBOOL clear();
+ mBOOL plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // other plugin unloading
+ void show(); // print info about plugin to console
- const char *str_reason(PL_UNLOAD_REASON preason, PL_UNLOAD_REASON preal_reason);
- const char *str_loadtime(PLUG_LOADTIME pallow, STR_LOADTIME fmt);
+ mBOOL newer_file(); // check for newer file on disk
- const char *str_status(void) { return(str_status(ST_SIMPLE)); };
- const char *str_action(void) { return(str_action(SA_SIMPLE)); };
- const char *str_source(void) { return(str_source(SO_SIMPLE)); };
+ const char *str_status(STR_STATUS fmt);
+ const char *str_action(STR_ACTION fmt);
+ const char *str_source(STR_SOURCE fmt);
- const char *str_loadable(void) {
- if(info) return(str_loadtime(info->loadable, SL_SIMPLE));
- else return(" -");
- };
- const char *str_unloadable(void) {
- if(info) return(str_loadtime(info->unloadable, SL_SIMPLE));
- else return(" -");
- };
- const char *str_loadable(STR_LOADTIME fmt) {
- if(info) return(str_loadtime(info->loadable, fmt));
- else return(" -");
- };
- const char *str_unloadable(STR_LOADTIME fmt) {
- if(info) return(str_loadtime(info->unloadable, fmt));
- else return(" -");
- };
+ const char *str_reason(PL_UNLOAD_REASON preason, PL_UNLOAD_REASON preal_reason);
+ const char *str_loadtime(PLUG_LOADTIME pallow, STR_LOADTIME fmt);
+
+ const char *str_status() { return str_status(ST_SIMPLE); };
+ const char *str_action() { return str_action(SA_SIMPLE); };
+ const char *str_source() { return str_source(SO_SIMPLE); };
+
+ const char *str_loadable() {
+ if (info) return str_loadtime(info->loadable, SL_SIMPLE);
+ else return " -";
+ };
+ const char *str_unloadable() {
+ if (info) return str_loadtime(info->unloadable, SL_SIMPLE);
+ else return " -";
+ };
+ const char *str_loadable(STR_LOADTIME fmt) {
+ if (info) return str_loadtime(info->loadable, fmt);
+ else return " -";
+ };
+ const char *str_unloadable(STR_LOADTIME fmt) {
+ if (info) return str_loadtime(info->unloadable, fmt);
+ else return " -";
+ };
};
// Macros used by MPlugin::show(), to list the functions that the plugin
// catches.
#define SHOW_IFDEF(api_table, info_table, pfnName, pre_str, post_str) \
- if(api_table->pfnName) { META_CONS("%s%s%s", pre_str, info_table.pfnName.name, post_str); n++;}
+ if (api_table->pfnName) { META_CONS("%s%s%s", pre_str, info_table.pfnName.name, post_str); n++;}
#define SHOW_DEF_DLLAPI(api_table, pre_str, post_str) \
- n=0; \
+ n = 0; \
SHOW_IFDEF(api_table, dllapi_info, pfnGameInit, pre_str, post_str); \
SHOW_IFDEF(api_table, dllapi_info, pfnSpawn, pre_str, post_str); \
SHOW_IFDEF(api_table, dllapi_info, pfnThink, pre_str, post_str); \
@@ -253,14 +212,14 @@ class MPlugin {
SHOW_IFDEF(api_table, dllapi_info, pfnAllowLagCompensation, pre_str, post_str);
#define SHOW_DEF_NEWAPI(api_table, pre_str, post_str) \
- n=0; \
+ n = 0; \
SHOW_IFDEF(api_table, newapi_info, pfnOnFreeEntPrivateData, pre_str, post_str); \
SHOW_IFDEF(api_table, newapi_info, pfnGameShutdown, pre_str, post_str); \
SHOW_IFDEF(api_table, newapi_info, pfnShouldCollide, pre_str, post_str); \
SHOW_IFDEF(api_table, newapi_info, pfnCvarValue, pre_str, post_str);
#define SHOW_DEF_ENGINE(api_table, pre_str, post_str) \
- n=0; \
+ n = 0; \
SHOW_IFDEF(api_table, engine_info, pfnPrecacheModel, pre_str, post_str); \
SHOW_IFDEF(api_table, engine_info, pfnPrecacheSound, pre_str, post_str); \
SHOW_IFDEF(api_table, engine_info, pfnSetModel, pre_str, post_str); \
@@ -418,6 +377,3 @@ class MPlugin {
SHOW_IFDEF(api_table, engine_info, pfnResetTutorMessageDecayData, pre_str, post_str); \
SHOW_IFDEF(api_table, engine_info, pfnQueryClientCvarValue, pre_str, post_str); \
SHOW_IFDEF(api_table, engine_info, pfnEngCheckParm, pre_str, post_str);
-
-
-#endif /* MPLUGIN_H */
diff --git a/metamod/src/mreg.cpp b/metamod/src/mreg.cpp
index d91a1bb..b1506bf 100644
--- a/metamod/src/mreg.cpp
+++ b/metamod/src/mreg.cpp
@@ -1,50 +1,5 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// mreg.cpp - functions for registered items (classes MRegCmd, MRegCmdList)
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
-#ifdef linux
-// enable extra routines in system header files, like strsignal
-# ifndef _GNU_SOURCE
-# define _GNU_SOURCE
-# endif
-#endif /* linux */
-
-///// class MRegCmd:
-
// Init values. It would probably be more "proper" to use containers and
// constructors, rather than arrays and init-functions.
void MRegCmd::init(int idx)
@@ -62,54 +17,56 @@ void MRegCmd::init(int idx)
// meta_errno values:
// - ME_BADREQ function disabled/invalid
// - ME_ARGUMENT function pointer is null
-mBOOL MRegCmd::call(void)
+mBOOL MRegCmd::call()
{
mBOOL ret;
// can we expect to call this function?
if (status != RG_VALID)
- RETURN_ERRNO(mFALSE, ME_BADREQ);
+ RETURN_ERRNO(mFALSE, ME_BADREQ);
+
if (!pfnCmd)
- RETURN_ERRNO(mFALSE, ME_ARGUMENT);
+ RETURN_ERRNO(mFALSE, ME_ARGUMENT);
// try to call this function
ret = os_safe_call(pfnCmd);
- if (!ret) {
+ if (!ret)
+ {
META_DEBUG(4, ("Plugin reg_cmd '%s' called after unloaded; removed from list", name));
status = RG_INVALID;
pfnCmd = NULL;
// NOTE: we can't free the malloc'd space for the name, as that
// would just re-introduce the segfault problem..
}
+
// meta_errno (if failed) is set already in os_safe_call()
- return (ret);
+ return ret;
}
-
-///// class MRegCmdList:
-
-// Constructor
-MRegCmdList::MRegCmdList(void)
+MRegCmdList::MRegCmdList()
: mlist(0), size(REG_CMD_GROWSIZE), endlist(0)
{
int i;
- mlist = (MRegCmd *) malloc(size * sizeof(MRegCmd));
+ mlist = (MRegCmd *)Q_malloc(size * sizeof(MRegCmd));
+
// initialize array
for (i = 0; i < size; i++)
mlist[i].init(i + 1); // 1-based index
+
endlist = 0;
}
// Try to find a registered function with the given name.
// meta_errno values:
// - ME_NOTFOUND couldn't find a matching function
-MRegCmd* MRegCmdList::find(const char* findname)
+MRegCmd *MRegCmdList::find(const char *findname)
{
- int i;
- for (i = 0; i < endlist; i++) {
- if (!_stricmp(mlist[i].name, findname))
- return (&mlist[i]);
+ for (int i = 0; i < endlist; i++)
+ {
+ if (!Q_stricmp(mlist[i].name, findname))
+ return &mlist[i];
}
+
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
@@ -118,121 +75,128 @@ MRegCmd* MRegCmdList::find(const char* findname)
// (meta_AddServerCommand).
// meta_errno values:
// - ME_NOMEM couldn't realloc or malloc for various parts
-MRegCmd* MRegCmdList::add(const char* addname)
+MRegCmd *MRegCmdList::add(const char *addname)
{
- MRegCmd* icmd;
-
- if (endlist == size) {
+ if (endlist == size)
+ {
// grow array
- MRegCmd* temp;
- int i, newsize;
- newsize = size + REG_CMD_GROWSIZE;
+ int newsize = size + REG_CMD_GROWSIZE;
META_DEBUG(6, ("Growing reg cmd list from %d to %d", size, newsize));
- temp = (MRegCmd *) realloc(mlist, newsize * sizeof(MRegCmd));
- if (!temp) {
+
+ MRegCmd *temp = (MRegCmd *) realloc(mlist, newsize * sizeof(MRegCmd));
+ if (!temp)
+ {
META_ERROR("Couldn't grow registered command list to %d for '%s': %s", newsize, addname, strerror(errno));
RETURN_ERRNO(NULL, ME_NOMEM);
}
+
mlist = temp;
size = newsize;
+
// initialize new (unused) entries
- for (i = endlist; i < size; i++)
+ for (int i = endlist; i < size; i++)
mlist[i].init(i + 1); // 1-based
}
- icmd = &mlist[endlist];
+ MRegCmd *icmd = &mlist[endlist];
// Malloc space separately for the command name, because:
- // - Can't point to memory loc in plugin (another segv waiting to
+ // - Can't point to memory loc in plugin (another segv waiting to
// happen).
- // - Can't point to memory in mlist which might get moved later by
+ // - Can't point to memory in mlist which might get moved later by
// realloc (again, segv).
- icmd->name = _strdup(addname);
- if (!icmd->name) {
- META_ERROR("Couldn't _strdup for adding reg cmd name '%s': %s",
- addname, strerror(errno));
+ icmd->name = Q_strdup(addname);
+ if (!icmd->name)
+ {
+ META_ERROR("Couldn't Q_strdup for adding reg cmd name '%s': %s", addname, strerror(errno));
RETURN_ERRNO(NULL, ME_NOMEM);
}
- endlist++;
- return (icmd);
+ endlist++;
+ return icmd;
}
// Disable any functions belonging to the given plugin (by index id).
void MRegCmdList::disable(int plugin_id)
{
- int i;
- for (i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++)
+ {
if (mlist[i].plugid == plugin_id)
mlist[i].status = RG_INVALID;
}
}
// List all the registered commands.
-void MRegCmdList::show(void)
+void MRegCmdList::show()
{
- int i, n = 0, a = 0;
- MRegCmd* icmd;
- MPlugin* iplug;
+ int n = 0, a = 0;
+ MRegCmd *icmd;
+ MPlugin *iplug;
char bplug[18 + 1]; // +1 for term null
META_CONS("Registered plugin commands:");
- META_CONS(" %*s %-*s %-s",
- WIDTH_MAX_REG, "",
- sizeof(bplug) - 1, "plugin", "command");
- for (i = 0; i < endlist; i++) {
+ META_CONS(" %*s %-*s %-s", WIDTH_MAX_REG, "", sizeof(bplug) - 1, "plugin", "command");
+ for (int i = 0; i < endlist; i++)
+ {
icmd = &mlist[i];
- if (icmd->status == RG_VALID) {
+ if (icmd->status == RG_VALID)
+ {
iplug = g_plugins->find(icmd->plugid);
- if (iplug) {
- strncpy(bplug, iplug->desc, sizeof bplug - 1);
+ if (iplug)
+ {
+ Q_strncpy(bplug, iplug->desc, sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0';
}
- else {
- strncpy(bplug, "(unknown)", sizeof bplug - 1);
+ else
+ {
+ Q_strncpy(bplug, "(unknown)", sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0';
}
}
- else {
- strncpy(bplug, "(unloaded)", sizeof bplug - 1);
+ else
+ {
+ Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0';
}
- META_CONS(" [%*d] %-*s %-s",
- WIDTH_MAX_REG, icmd->index,
- sizeof(bplug) - 1, bplug,
- icmd->name);
- if (icmd->status == RG_VALID) a++;
+
+ META_CONS(" [%*d] %-*s %-s", WIDTH_MAX_REG, icmd->index, sizeof(bplug) - 1, bplug, icmd->name);
+ if (icmd->status == RG_VALID)
+ a++;
+
n++;
}
+
META_CONS("%d commands, %d available (%d allocated)", n, a, size);
}
// List all the registered commands for the given plugin id.
void MRegCmdList::show(int plugin_id)
{
- int i, n = 0;
- MRegCmd* icmd;
+ int n = 0;
+ MRegCmd *icmd;
// If OS doesn't support DLFNAME, then we can't know what the plugin's
// registered cvars are.
DLFNAME(NULL);
- if (meta_errno == ME_OSNOTSUP) {
+ if (meta_errno == ME_OSNOTSUP)
+ {
META_CONS("Registered commands: unknown (can't get info under this OS)");
return;
}
META_CONS("Registered commands:");
- for (i = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
icmd = &mlist[i];
+
if (icmd->plugid != plugin_id)
continue;
+
META_CONS(" %s", icmd->name);
n++;
}
+
META_CONS("%d commands", n);
}
-
-///// class MRegCvar:
-
// Init values. It would probably be more "proper" to use containers and
// constructors, rather than arrays and init-functions.
void MRegCvar::init(int idx)
@@ -246,34 +210,33 @@ void MRegCvar::init(int idx)
// Set the cvar, copying values from given cvar.
// meta_errno values:
// - ME_ARGUMENT given cvar doesn't match this cvar
-mBOOL MRegCvar::set(cvar_t* src)
+mBOOL MRegCvar::set(cvar_t *src)
{
- if (_stricmp(src->name, data->name)) {
- META_ERROR("Tried to set cvar with mismatched name; src=%s dst=%s",
- src->name, data->name);
+ if (Q_stricmp(src->name, data->name))
+ {
+ META_ERROR("Tried to set cvar with mismatched name; src=%s dst=%s", src->name, data->name);
RETURN_ERRNO(mFALSE, ME_ARGUMENT);
}
+
// Would like to free() existing string, but can't tell where it was
// allocated...
- data->string = _strdup(src->string);
+ data->string = Q_strdup(src->string);
data->flags = src->flags;
data->value = src->value;
data->next = src->next;
- return (mTRUE);
+ return mTRUE;
}
-
-///// class MRegCvarList:
-
// Constructor
-MRegCvarList::MRegCvarList(void)
+MRegCvarList::MRegCvarList()
: vlist(0), size(REG_CVAR_GROWSIZE), endlist(0)
{
- int i;
- vlist = (MRegCvar *) malloc(size * sizeof(MRegCvar));
+ vlist = (MRegCvar *)Q_malloc(size * sizeof(MRegCvar));
+
// initialize array
- for (i = 0; i < size; i++)
- vlist[i].init(i + 1); // 1-based
+ for (int i = 0; i < size; i++)
+ vlist[i].init(i + 1); // 1 - based
+
endlist = 0;
}
@@ -282,62 +245,63 @@ MRegCvarList::MRegCvarList(void)
// cvar::set().
// meta_errno values:
// - ME_NOMEM couldn't alloc or realloc for various parts
-MRegCvar* MRegCvarList::add(const char* addname)
+MRegCvar *MRegCvarList::add(const char *addname)
{
- MRegCvar* icvar;
-
- if (endlist == size) {
+ MRegCvar *icvar;
+ if (endlist == size)
+ {
// grow array
- MRegCvar* temp;
- int i, newsize;
- newsize = size + REG_CVAR_GROWSIZE;
+ int newsize = size + REG_CVAR_GROWSIZE;
+
META_DEBUG(6, ("Growing reg cvar list from %d to %d", size, newsize));
- temp = (MRegCvar *) realloc(vlist, newsize * sizeof(MRegCvar));
- if (!temp) {
+ MRegCvar *temp = (MRegCvar *) realloc(vlist, newsize * sizeof(MRegCvar));
+ if (!temp)
+ {
META_ERROR("Couldn't grow registered cvar list to %d for '%s'; %s", newsize, addname, strerror(errno));
RETURN_ERRNO(NULL, ME_NOMEM);
}
vlist = temp;
size = newsize;
// initialize new (unused) entries
- for (i = endlist; i < size; i++)
+ for (int i = endlist; i < size; i++)
vlist[i].init(i + 1); // 1-based
}
icvar = &vlist[endlist];
// Malloc space for the cvar and cvar name, for two reasons:
- // - Can't point to memory loc in plugin (another segv waiting to
+ // - Can't point to memory loc in plugin (another segv waiting to
// happen).
- // - Can't point to memory in vlist which might get moved later by
+ // - Can't point to memory in vlist which might get moved later by
// realloc (again, segv).
- icvar->data = (cvar_t *) malloc(sizeof(cvar_t));
- if (!icvar->data) {
- META_ERROR("Couldn't malloc cvar for adding reg cvar name '%s': %s",
- addname, strerror(errno));
+ icvar->data = (cvar_t *)Q_malloc(sizeof(cvar_t));
+ if (!icvar->data)
+ {
+ META_ERROR("Couldn't malloc cvar for adding reg cvar name '%s': %s", addname, strerror(errno));
RETURN_ERRNO(NULL, ME_NOMEM);
}
- icvar->data->name = _strdup(addname);
- if (!icvar->data->name) {
- META_ERROR("Couldn't _strdup for adding reg cvar name '%s': %s",
- addname, strerror(errno));
+
+ icvar->data->name = Q_strdup(addname);
+ if (!icvar->data->name)
+ {
+ META_ERROR("Couldn't Q_strdup for adding reg cvar name '%s': %s", addname, strerror(errno));
RETURN_ERRNO(NULL, ME_NOMEM);
}
endlist++;
-
- return (icvar);
+ return icvar;
}
// Try to find a registered cvar with the given name.
// meta_errno values:
// - ME_NOTFOUND couldn't find a matching cvar
-MRegCvar* MRegCvarList::find(const char* findname)
+MRegCvar *MRegCvarList::find(const char *findname)
{
- int i;
- for (i = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
if (!_stricmp(vlist[i].data->name, findname))
- return (&vlist[i]);
+ return &vlist[i];
}
+
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
@@ -345,10 +309,12 @@ MRegCvar* MRegCvarList::find(const char* findname)
void MRegCvarList::disable(int plugin_id)
{
int i;
- MRegCvar* icvar;
- for (i = 0; i < size; i++) {
+ MRegCvar *icvar;
+ for (i = 0; i < size; i++)
+ {
icvar = &vlist[i];
- if (icvar->plugid == plugin_id) {
+ if (icvar->plugid == plugin_id)
+ {
icvar->status = RG_INVALID;
icvar->plugid = 0;
// Decided not to do this, in order to keep pre-existing values
@@ -359,48 +325,46 @@ void MRegCvarList::disable(int plugin_id)
}
// List all the registered cvars.
-void MRegCvarList::show(void)
+void MRegCvarList::show()
{
int i, n = 0, a = 0;
- MRegCvar* icvar;
- MPlugin* iplug;
+ MRegCvar *icvar;
+ MPlugin *iplug;
char bplug[13 + 1], bname[20 + 1], bval[15 + 1]; // +1 for term null
META_CONS("Registered plugin cvars:");
- META_CONS(" %*s %-*s %-*s %*s %s",
- WIDTH_MAX_REG, "",
- sizeof(bplug) - 1, "plugin",
- sizeof(bname) - 1, "cvar",
- sizeof(bval) - 1, "float value",
- "string value");
- for (i = 0; i < endlist; i++) {
+ META_CONS(" %*s %-*s %-*s %*s %s", WIDTH_MAX_REG, "", sizeof(bplug) - 1, "plugin", sizeof(bname) - 1, "cvar", sizeof(bval) - 1, "float value", "string value");
+ for (i = 0; i < endlist; i++)
+ {
icvar = &vlist[i];
- if (icvar->status == RG_VALID) {
+ if (icvar->status == RG_VALID)
+ {
iplug = g_plugins->find(icvar->plugid);
- if (iplug) {
- strncpy(bplug, iplug->desc, sizeof bplug - 1);
+ if (iplug)
+ {
+ Q_strncpy(bplug, iplug->desc, sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0';
}
- else {
- strncpy(bplug, "(unknown)", sizeof bplug - 1);
+ else
+ {
+ Q_strncpy(bplug, "(unknown)", sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0';
}
}
- else {
- strncpy(bplug, "(unloaded)", sizeof bplug - 1);
+ else
+ {
+ Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1);
bplug[sizeof bplug - 1] = '\0';
}
- strncpy(bname, icvar->data->name, sizeof bname - 1);
+ Q_strncpy(bname, icvar->data->name, sizeof bname - 1);
bname[sizeof bname - 1] = '\0';
- snprintf(bval, sizeof(bval), "%f", icvar->data->value);
- META_CONS(" [%*d] %-*s %-*s %*s %s",
- WIDTH_MAX_REG, icvar->index,
- sizeof(bplug) - 1, bplug,
- sizeof(bname) - 1, bname,
- sizeof(bval) - 1, bval,
- icvar->data->string);
- if (icvar->status == RG_VALID) a++;
+ Q_snprintf(bval, sizeof(bval), "%f", icvar->data->value);
+ META_CONS(" [%*d] %-*s %-*s %*s %s", WIDTH_MAX_REG, icvar->index, sizeof(bplug) - 1, bplug, sizeof(bname) - 1, bname, sizeof(bval) - 1, bval, icvar->data->string);
+
+ if (icvar->status == RG_VALID)
+ a++;
+
n++;
}
META_CONS("%d cvars, %d available (%d allocated)", n, a, size);
@@ -409,68 +373,63 @@ void MRegCvarList::show(void)
// List the registered cvars for the given plugin id.
void MRegCvarList::show(int plugin_id)
{
- int i, n = 0;
- MRegCvar* icvar;
+ int n = 0;
+ MRegCvar *icvar;
char bname[30 + 1], bval[15 + 1]; // +1 for term null
// If OS doesn't support DLFNAME, then we can't know what the plugin's
// registered cvars are.
DLFNAME(NULL);
- if (meta_errno == ME_OSNOTSUP) {
+ if (meta_errno == ME_OSNOTSUP)
+ {
META_CONS("Registered cvars: unknown (can't get info under this OS)");
return;
}
- META_CONS("%-*s %*s %s",
- sizeof(bname) - 1, "Registered cvars:",
- sizeof(bval) - 1, "float value",
- "string value");
- for (i = 0; i < endlist; i++) {
+
+ META_CONS("%-*s %*s %s", sizeof(bname) - 1, "Registered cvars:", sizeof(bval) - 1, "float value", "string value");
+ for (int i = 0; i < endlist; i++)
+ {
icvar = &vlist[i];
if (icvar->plugid != plugin_id)
continue;
- strncpy(bname, icvar->data->name, sizeof bname - 1);
+
+ Q_strncpy(bname, icvar->data->name, sizeof bname - 1);
bname[sizeof bname - 1] = '\0';
- snprintf(bval, sizeof(bval), "%f", icvar->data->value);
- META_CONS(" %-*s %*s %s",
- sizeof(bname) - 1, bname,
- sizeof(bval) - 1, bval,
- icvar->data->string);
+ Q_snprintf(bval, sizeof(bval), "%f", icvar->data->value);
+ META_CONS(" %-*s %*s %s", sizeof(bname) - 1, bname, sizeof(bval) - 1, bval, icvar->data->string);
n++;
}
+
META_CONS("%d cvars", n);
}
-
-///// class MRegMsgList:
-
// Constructor
-MRegMsgList::MRegMsgList(void)
+MRegMsgList::MRegMsgList()
: size(MAX_REG_MSGS), endlist(0)
{
- int i;
// initialize array
- memset(mlist, 0, sizeof(mlist));
- for (i = 0; i < size; i++) {
+ Q_memset(mlist, 0, sizeof(mlist));
+ for (int i = 0; i < size; i++)
+ {
mlist[i].index = i + 1; // 1-based
}
+
endlist = 0;
}
// Add the given user msg the list and return the instance.
// meta_errno values:
// - ME_MAXREACHED reached max number of msgs allowed
-MRegMsg* MRegMsgList::add(const char* addname, int addmsgid, int addsize)
+MRegMsg *MRegMsgList::add(const char *addname, int addmsgid, int addsize)
{
- MRegMsg* imsg;
-
- if (endlist == size) {
+ if (endlist == size)
+ {
// all slots used
- META_ERROR("Couldn't add registered msg '%s' to list; reached max msgs (%d)",
- addname, size);
+ META_ERROR("Couldn't add registered msg '%s' to list; reached max msgs (%d)", addname, size);
RETURN_ERRNO(NULL, ME_MAXREACHED);
}
- imsg = &mlist[endlist];
+ MRegMsg *imsg = &mlist[endlist];
endlist++;
// Copy msg data into empty slot.
@@ -480,54 +439,54 @@ MRegMsg* MRegMsgList::add(const char* addname, int addmsgid, int addsize)
imsg->msgid = addmsgid;
imsg->size = addsize;
- return (imsg);
+ return imsg;
}
// Try to find a registered msg with the given name.
// meta_errno values:
// - ME_NOTFOUND couldn't find a matching cvar
-MRegMsg* MRegMsgList::find(const char* findname)
+MRegMsg *MRegMsgList::find(const char *findname)
{
- int i;
- for (i = 0; i < endlist; i++) {
- if (!strcmp(mlist[i].name, findname))
- return (&mlist[i]);
+ for (int i = 0; i < endlist; i++)
+ {
+ if (!Q_strcmp(mlist[i].name, findname))
+ return &mlist[i];
}
+
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
// Try to find a registered msg with the given msgid.
// meta_errno values:
// - ME_NOTFOUND couldn't find a matching cvar
-MRegMsg* MRegMsgList::find(int findmsgid)
+MRegMsg *MRegMsgList::find(int findmsgid)
{
- int i;
- for (i = 0; i < endlist; i++) {
+ for (int i = 0; i < endlist; i++)
+ {
if (mlist[i].msgid == findmsgid)
- return (&mlist[i]);
+ return &mlist[i];
}
+
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
// List the registered usermsgs for the gamedll.
-void MRegMsgList::show(void)
+void MRegMsgList::show()
{
int i, n = 0;
- MRegMsg* imsg;
+ MRegMsg *imsg;
char bname[25 + 1]; // +1 for term null
- META_CONS("%-*s %5s %5s",
- sizeof(bname) - 1, "Game registered user msgs:", "msgid", "size");
- for (i = 0; i < endlist; i++) {
+ META_CONS("%-*s %5s %5s", sizeof(bname) - 1, "Game registered user msgs:", "msgid", "size");
+ for (i = 0; i < endlist; i++)
+ {
imsg = &mlist[i];
- strncpy(bname, imsg->name, sizeof bname - 1);
+
+ Q_strncpy(bname, imsg->name, sizeof bname - 1);
bname[sizeof bname - 1] = '\0';
- META_CONS(" %-*s %3d %3d",
- sizeof(bname) - 1, bname,
- imsg->msgid,
- imsg->size);
+ META_CONS(" %-*s %3d %3d", sizeof(bname) - 1, bname, imsg->msgid, imsg->size);
n++;
}
+
META_CONS("%d game user msgs", n);
}
-
diff --git a/metamod/src/mreg.h b/metamod/src/mreg.h
index 48648c2..da4c9ce 100644
--- a/metamod/src/mreg.h
+++ b/metamod/src/mreg.h
@@ -1,53 +1,15 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// mreg.h - description of registered items (classes MRegCmd, MRegCmdList)
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef MREG_H
-#define MREG_H
-
+#pragma once
#include "types_meta.h" // mBOOL
-// Number of entries to add to reglists when they need to grow. Typically
+// Number of entries to add to reglists when they need to grow. Typically
// more cvars than commands, so we grow them at different increments.
#define REG_CMD_GROWSIZE 32
#define REG_CVAR_GROWSIZE 64
// Width required to printf a Reg*List index number, for show() functions.
// This used to correspond to the number of digits in MAX_REG, which was a
-// fixed, compile-time limit. However, now that the reg lists are grown
-// dynamically, this has less strong correspondance to list sizes. So for
+// fixed, compile-time limit. However, now that the reg lists are grown
+// dynamically, this has less strong correspondance to list sizes. So for
// the moment, it reflects what one might normally expect to be the max
// width needed to print an index number; 4 allows 9999 (which is a damn
// lot, if you ask me).
@@ -57,130 +19,113 @@
#define MAX_REG_MSGS 256
// Flags to indicate if given cvar or func is part of a loaded plugin.
-typedef enum {
- RG_INVALID,
- RG_VALID,
-} REG_STATUS;
+enum REG_STATUS { RG_INVALID, RG_VALID };
// Pointer to function registered by AddServerCommand.
-typedef void (*REG_CMD_FN) (void);
-
+typedef void (*REG_CMD_FN)();
// An individual registered function/command.
class MRegCmd {
+public:
friend class MRegCmdList;
- private:
- // data:
- int index; // 1-based
- public:
- char *name; // space is malloc'd
- REG_CMD_FN pfnCmd; // pointer to the function
- int plugid; // index id of corresponding plugin
- REG_STATUS status; // whether corresponding plugin is loaded
- // functions:
- void init(int idx); // init values, as not using constructors
- mBOOL call(void); // try to call the function
-};
+ char *name; // space is malloc'd
+ REG_CMD_FN pfnCmd; // pointer to the function
+ int plugid; // index id of corresponding plugin
+ REG_STATUS status; // whether corresponding plugin is loaded
+
+ void init(int idx); // init values, as not using constructors
+ mBOOL call(); // try to call the function
+
+private:
+ int index; // 1-based
+};
// A list of registered commands.
class MRegCmdList {
- private:
- // data:
- MRegCmd *mlist; // malloc'd array of registered commands
- int size; // current size of list
- int endlist; // index of last used entry
- // Private; to satisfy -Weffc++ "has pointer data members but does
- // not override" copy/assignment constructor.
- void operator=(const MRegCmdList &src);
- MRegCmdList(const MRegCmdList &src);
+public:
+ MRegCmdList();
- public:
- // constructor:
- MRegCmdList(void);
+ MRegCmd *find(const char *findname); // find by MRegCmd->name
+ MRegCmd *add(const char *addname);
+ void disable(int plugin_id); // change status to Invalid
+ void show(); // list all funcs to console
+ void show(int plugin_id); // list given plugin's funcs to console
- // functions:
- MRegCmd *find(const char *findname); // find by MRegCmd->name
- MRegCmd *add(const char *addname);
- void disable(int plugin_id); // change status to Invalid
- void show(void); // list all funcs to console
- void show(int plugin_id); // list given plugin's funcs to console
+private:
+ MRegCmd *mlist; // malloc'd array of registered commands
+ int size; // current size of list
+ int endlist; // index of last used entry
+
+ // Private; to satisfy -Weffc++ "has pointer data members but does
+ // not override" copy/assignment constructor.
+ void operator=(const MRegCmdList &src);
+ MRegCmdList(const MRegCmdList &src);
};
-
-
// An individual registered cvar.
class MRegCvar {
+public:
friend class MRegCvarList;
- private:
- // data:
- int index; // 1-based
- public:
- cvar_t *data; // actual cvar structure, malloc'd
- int plugid; // index id of corresponding plugin
- REG_STATUS status; // whether corresponding plugin is loaded
- // functions:
- void init(int idx); // init values, as not using constructors
- mBOOL set(cvar_t *src);
-};
+ cvar_t *data; // actual cvar structure, malloc'd
+ int plugid; // index id of corresponding plugin
+ REG_STATUS status; // whether corresponding plugin is loaded
+
+ void init(int idx); // init values, as not using constructors
+ mBOOL set(cvar_t *src);
+
+private:
+ int index; // 1-based
+};
// A list of registered cvars.
class MRegCvarList {
- private:
- // data:
- MRegCvar *vlist; // malloc'd array of registered cvars
- int size; // size of list, ie MAX_REG_CVARS
- int endlist; // index of last used entry
- // Private; to satisfy -Weffc++ "has pointer data members but does
- // not override" copy/assignment constructor.
- void operator=(const MRegCvarList &src);
- MRegCvarList(const MRegCvarList &src);
- public:
- // constructor:
- MRegCvarList(void);
+public:
+ MRegCvarList();
- // functions:
- MRegCvar *add(const char *addname);
- MRegCvar *find(const char *findname); // find by MRegCvar->data.name
- void disable(int plugin_id); // change status to Invalid
- void show(void); // list all cvars to console
- void show(int plugin_id); // list given plugin's cvars to console
+ MRegCvar *add(const char *addname);
+ MRegCvar *find(const char *findname); // find by MRegCvar->data.name
+ void disable(int plugin_id); // change status to Invalid
+ void show(); // list all cvars to console
+ void show(int plugin_id); // list given plugin's cvars to console
+
+private:
+ MRegCvar *vlist; // malloc'd array of registered cvars
+ int size; // size of list, ie MAX_REG_CVARS
+ int endlist; // index of last used entry
+ // Private; to satisfy -Weffc++ "has pointer data members but does
+ // not override" copy/assignment constructor.
+ void operator=(const MRegCvarList &src);
+ MRegCvarList(const MRegCvarList &src);
};
-
-
// An individual registered user msg, from gamedll.
class MRegMsg {
+public:
friend class MRegMsgList;
- private:
- // data:
- int index; // 1-based
- public:
- const char *name; // name, assumed constant string in gamedll
- int msgid; // msgid, assigned by engine
- int size; // size, if given by gamedll
-};
+ const char *name; // name, assumed constant string in gamedll
+ int msgid; // msgid, assigned by engine
+ int size; // size, if given by gamedll
+
+private:
+ int index; // 1-based
+};
// A list of registered user msgs.
class MRegMsgList {
- private:
- // data:
- MRegMsg mlist[MAX_REG_MSGS]; // array of registered msgs
- int size; // size of list, ie MAX_REG_MSGS
- int endlist; // index of last used entry
+public:
+ MRegMsgList();
- public:
- // constructor:
- MRegMsgList(void);
+ MRegMsg *add(const char *addname, int addmsgid, int addsize);
+ MRegMsg *find(const char *findname);
+ MRegMsg *find(int findmsgid);
+ void show(); // list all msgs to console
- // functions:
- MRegMsg *add(const char *addname, int addmsgid, int addsize);
- MRegMsg *find(const char *findname);
- MRegMsg *find(int findmsgid);
- void show(void); // list all msgs to console
-};
-
-#endif /* MREG_H */
+private:
+ MRegMsg mlist[MAX_REG_MSGS]; // array of registered msgs
+ int size; // size of list, ie MAX_REG_MSGS
+ int endlist; // index of last used entry
+};
\ No newline at end of file
diff --git a/metamod/src/mutil.cpp b/metamod/src/mutil.cpp
index 7e0b04b..1a265b5 100644
--- a/metamod/src/mutil.cpp
+++ b/metamod/src/mutil.cpp
@@ -1,39 +1,3 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// mutil.cpp - utility functions to provide to plugins
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
hudtextparms_t default_csay_tparms = {
@@ -46,19 +10,20 @@ hudtextparms_t default_csay_tparms = {
};
// Log to console; newline added.
-void mutil_LogConsole(plid_t /* plid */, const char* fmt, ...)
+void mutil_LogConsole(plid_t plid, const char *fmt, ...)
{
va_list ap;
char buf[MAX_LOGMSG_LEN];
unsigned int len;
va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ Q_vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
+
// end msg with newline
- len = strlen(buf);
+ len = Q_strlen(buf);
if (len < sizeof(buf) - 2) // -1 null, -1 for newline
- strcat(buf, "\n");
+ Q_strcat(buf, "\n");
else
buf[len - 1] = '\n';
@@ -66,29 +31,27 @@ void mutil_LogConsole(plid_t /* plid */, const char* fmt, ...)
}
// Log regular message to logs; newline added.
-void mutil_LogMessage(plid_t plid, const char* fmt, ...)
+void mutil_LogMessage(plid_t plid, const char *fmt, ...)
{
va_list ap;
char buf[MAX_LOGMSG_LEN];
- plugin_info_t* plinfo;
+ plugin_info_t *plinfo = (plugin_info_t *)plid;
- plinfo = (plugin_info_t *)plid;
va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ Q_vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
ALERT(at_logged, "[%s] %s\n", plinfo->logtag, buf);
}
// Log an error message to logs; newline added.
-void mutil_LogError(plid_t plid, const char* fmt, ...)
+void mutil_LogError(plid_t plid, const char *fmt, ...)
{
va_list ap;
char buf[MAX_LOGMSG_LEN];
- plugin_info_t* plinfo;
+ plugin_info_t *plinfo = (plugin_info_t *)plid;
- plinfo = (plugin_info_t *)plid;
va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ Q_vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
ALERT(at_logged, "[%s] ERROR: %s\n", plinfo->logtag, buf);
}
@@ -105,7 +68,7 @@ void mutil_LogDeveloper(plid_t plid, const char* fmt, ...)
plinfo = (plugin_info_t *)plid;
va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ Q_vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
ALERT(at_logged, "[%s] dev: %s\n", plinfo->logtag, buf);
}
@@ -131,17 +94,17 @@ void mutil_CenterSayParms(plid_t plid, hudtextparms_t tparms, const char* fmt, .
// Print a center-message, with text parameters and varargs. Provides
// functionality to the above center_say interfaces.
-void mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms,
- const char* fmt, va_list ap)
+void mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const char* fmt, va_list ap)
{
char buf[MAX_LOGMSG_LEN];
int n;
- edict_t* pEntity;
+ edict_t *pEntity;
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ Q_vsnprintf(buf, sizeof(buf), fmt, ap);
mutil_LogMessage(plid, "(centersay) %s", buf);
- for (n = 1; n <= gpGlobals->maxClients; n++) {
+ for (n = 1; n <= gpGlobals->maxClients; n++)
+ {
pEntity = INDEXENT(n);
if (FNullEnt(pEntity) || pEntity->free)
continue;
@@ -152,104 +115,101 @@ void mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms,
// Allow plugins to call the entity functions in the GameDLL. In
// particular, calling "player()" as needed by most Bots. Suggested by
// Jussi Kivilinna.
-qboolean mutil_CallGameEntity(plid_t plid, const char* entStr, entvars_t* pev)
+qboolean mutil_CallGameEntity(plid_t plid, const char *entStr, entvars_t *pev)
{
- plugin_info_t* plinfo;
- ENTITY_FN pfnEntity;
-
- plinfo = (plugin_info_t *)plid;
- META_DEBUG(8, ("Looking up game entity '%s' for plugin '%s'", entStr,
- plinfo->name));
- pfnEntity = (ENTITY_FN) DLSYM(GameDLL.handle, entStr);
- if (!pfnEntity) {
+ plugin_info_t *plinfo = (plugin_info_t *)plid;
+ META_DEBUG(8, ("Looking up game entity '%s' for plugin '%s'", entStr, plinfo->name));
+ ENTITY_FN pfnEntity = (ENTITY_FN) DLSYM(GameDLL.handle, entStr);
+ if (!pfnEntity)
+ {
META_ERROR("Couldn't find game entity '%s' in game DLL '%s' for plugin '%s'", entStr, GameDLL.name, plinfo->name);
- return (false);
+ return false;
}
- META_DEBUG(7, ("Calling game entity '%s' for plugin '%s'", entStr,
- plinfo->name));
+
+ META_DEBUG(7, ("Calling game entity '%s' for plugin '%s'", entStr, plinfo->name));
(*pfnEntity)(pev);
- return (true);
+ return true;
}
// Find a usermsg, registered by the gamedll, with the corresponding
// msgname, and return remaining info about it (msgid, size).
int mutil_GetUserMsgID(plid_t plid, const char* msgname, int* size)
{
- plugin_info_t* plinfo;
- MRegMsg* umsg;
+ plugin_info_t *plinfo = (plugin_info_t *)plid;
+ META_DEBUG(8, ("Looking up usermsg name '%s' for plugin '%s'", msgname, plinfo->name));
- plinfo = (plugin_info_t *)plid;
- META_DEBUG(8, ("Looking up usermsg name '%s' for plugin '%s'", msgname,
- plinfo->name));
- umsg = g_regMsgs->find(msgname);
- if (umsg) {
+ MRegMsg *umsg = g_regMsgs->find(msgname);
+ if (umsg)
+ {
if (size)
*size = umsg->size;
- return (umsg->msgid);
+ return umsg->msgid;
}
else
- return (0);
+ return 0;
}
// Find a usermsg, registered by the gamedll, with the corresponding
// msgid, and return remaining info about it (msgname, size).
-const char* mutil_GetUserMsgName(plid_t plid, int msgid, int* size)
+const char* mutil_GetUserMsgName(plid_t plid, int msgid, int *size)
{
- plugin_info_t* plinfo;
- MRegMsg* umsg;
+ plugin_info_t *plinfo = (plugin_info_t *)plid;
+ META_DEBUG(8, ("Looking up usermsg id '%d' for plugin '%s'", msgid, plinfo->name));
- plinfo = (plugin_info_t *)plid;
- META_DEBUG(8, ("Looking up usermsg id '%d' for plugin '%s'", msgid,
- plinfo->name));
// Guess names for any built-in g_engine messages mentioned in the SDK;
// from dlls/util.h.
- if (msgid < 64) {
- switch (msgid) {
+ if (msgid < 64)
+ {
+ switch (msgid)
+ {
case SVC_TEMPENTITY:
if (size) *size = -1;
- return ("tempentity?");
+ return "tempentity?";
case SVC_INTERMISSION:
if (size) *size = -1;
- return ("intermission?");
+ return "intermission?";
case SVC_CDTRACK:
if (size) *size = -1;
- return ("cdtrack?");
+ return "cdtrack?";
case SVC_WEAPONANIM:
if (size) *size = -1;
- return ("weaponanim?");
+ return "weaponanim?";
case SVC_ROOMTYPE:
if (size) *size = -1;
- return ("roomtype?");
+ return "roomtype?";
case SVC_DIRECTOR:
if (size) *size = -1;
- return ("director?");
+ return "director?";
}
}
- umsg = g_regMsgs->find(msgid);
- if (umsg) {
+
+ MRegMsg *umsg = g_regMsgs->find(msgid);
+ if (umsg)
+ {
if (size)
*size = umsg->size;
// 'name' is assumed to be a constant string, allocated in the
// gamedll.
- return (umsg->name);
+ return umsg->name;
}
else
- return (NULL);
+ return NULL;
}
// Return the full path of the plugin's loaded dll/so file.
const char* mutil_GetPluginPath(plid_t plid)
{
static char buf[PATH_MAX ];
- MPlugin* plug;
+ MPlugin *plug;
plug = g_plugins->find(plid);
- if (!plug) {
- META_ERROR("GetPluginPath: couldn't find plugin '%s'",
- plid->name);
- return (NULL);
+ if (!plug)
+ {
+ META_ERROR("GetPluginPath: couldn't find plugin '%s'", plid->name);
+ return NULL;
}
- strncpy(buf, plug->pathname, sizeof buf - 1);
+
+ Q_strncpy(buf, plug->pathname, sizeof buf - 1);
buf[sizeof buf - 1] = '\0';
return buf;
}
@@ -258,8 +218,9 @@ const char* mutil_GetPluginPath(plid_t plid)
const char* mutil_GetGameInfo(plid_t plid, ginfo_t type)
{
static char buf[MAX_STRBUF_LEN];
- const char* cp;
- switch (type) {
+ const char *cp;
+ switch (type)
+ {
case GINFO_NAME:
cp = GameDLL.name;
break;
@@ -279,43 +240,47 @@ const char* mutil_GetGameInfo(plid_t plid, ginfo_t type)
cp = GameDLL.real_pathname;
break;
default:
- META_ERROR("GetGameInfo: invalid request '%d' from plugin '%s'",
- type, plid->name);
- return (NULL);
+ META_ERROR("GetGameInfo: invalid request '%d' from plugin '%s'", type, plid->name);
+ return NULL;
}
- strncpy(buf, cp, sizeof buf - 1);
+
+ Q_strncpy(buf, cp, sizeof buf - 1);
buf[sizeof buf - 1] = '\0';
return buf;
}
-int mutil_LoadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, void** plugin_handle)
+int mutil_LoadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, void **plugin_handle)
{
- MPlugin* pl_loaded;
-
- if (NULL == fname) {
+ MPlugin *pl_loaded;
+ if (!fname)
+ {
return ME_ARGUMENT;
}
meta_errno = ME_NOERROR;
- if (! (pl_loaded = g_plugins->plugin_addload(plid, fname, now))) {
+ if (!(pl_loaded = g_plugins->plugin_addload(plid, fname, now)))
+ {
if (plugin_handle)
- *plugin_handle = NULL;
+ *plugin_handle = nullptr;
+
return meta_errno;
}
- else {
+ else
+ {
if (plugin_handle)
*plugin_handle = (void *)pl_loaded->handle;
return 0;
}
}
-int mutil_UnloadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
+int mutil_UnloadMetaPlugin(plid_t plid, const char *fname, PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
- MPlugin* findp = NULL;
+ MPlugin *findp = nullptr;
int pindex;
- char* endptr;
+ char *endptr;
- if (NULL == fname) {
+ if (!fname)
+ {
return ME_ARGUMENT;
}
@@ -336,11 +301,12 @@ int mutil_UnloadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, PL
return meta_errno;
}
-int mutil_UnloadMetaPluginByHandle(plid_t plid, void* plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
+int mutil_UnloadMetaPluginByHandle(plid_t plid, void *plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
- MPlugin* findp;
+ MPlugin *findp;
- if (NULL == plugin_handle) {
+ if (!plugin_handle)
+ {
return ME_ARGUMENT;
}
@@ -355,90 +321,92 @@ int mutil_UnloadMetaPluginByHandle(plid_t plid, void* plugin_handle, PLUG_LOADTI
return meta_errno;
}
-const char* mutil_IsQueryingClientCvar(plid_t /*plid*/, const edict_t* pEdict)
+const char* mutil_IsQueryingClientCvar(plid_t plid, const edict_t* pEdict)
{
return g_Players.is_querying_cvar(pEdict);
}
-int mutil_MakeRequestId(plid_t /*plid*/)
+int mutil_MakeRequestId(plid_t plid)
{
//the offset is to distinguish from gamedll requests, if any
- return (abs(0xbeef << 16) + (++requestid_counter));
+ return abs(0xbeef << 16) + (++requestid_counter);
}
-void mutil_GetHookTables(plid_t /*plid*/, enginefuncs_t** peng, DLL_FUNCTIONS** pdll, NEW_DLL_FUNCTIONS** pnewdll)
+void mutil_GetHookTables(plid_t plid, enginefuncs_t** peng, DLL_FUNCTIONS** pdll, NEW_DLL_FUNCTIONS** pnewdll)
{
if (peng)
*peng = &meta_engfuncs;
+
if (pdll)
*pdll = pHookedDllFunctions;
+
if (pnewdll)
*pnewdll = pHookedNewDllFunctions;
}
#ifdef UNFINISHED
-int mutil_HookGameEvent(plid_t plid, game_event_t event,
- event_func_t pfnHandle)
+
+int mutil_HookGameEvent(plid_t plid, game_event_t event, event_func_t pfnHandle)
{
- return(Hooks->add(plid, event, pfnHandle));
+ return Hooks->add(plid, event, pfnHandle);
}
-int mutil_HookLogTrigger(plid_t plid, const char *trigger,
- logmatch_func_t pfnHandle)
+int mutil_HookLogTrigger(plid_t plid, const char *trigger, logmatch_func_t pfnHandle)
{
- return(Hooks->add(plid, H_TRIGGER, trigger, pfnHandle));
+ return Hooks->add(plid, H_TRIGGER, trigger, pfnHandle);
}
-int mutil_HookLogString(plid_t plid, const char *string,
- logmatch_func_t pfnHandle)
+int mutil_HookLogString(plid_t plid, const char *string, logmatch_func_t pfnHandle)
{
- return(Hooks->add(plid, H_STRING, string, pfnHandle));
+ return Hooks->add(plid, H_STRING, string, pfnHandle);
}
-int mutil_HookLogRegex(plid_t plid, const char *pattern,
- logmatch_func_t pfnHandle)
+int mutil_HookLogRegex(plid_t plid, const char *pattern, logmatch_func_t pfnHandle)
{
- return(Hooks->add(plid, H_STRING, pattern, pfnHandle));
+ return Hooks->add(plid, H_STRING, pattern, pfnHandle);
}
-qboolean mutil_RemoveHookID(plid_t plid, int hookid) {
- mBOOL ret;
- ret=Hooks->remove(plid, hookid);
- if(ret==mTRUE) return(true);
- else return(false);
+qboolean mutil_RemoveHookID(plid_t plid, int hookid)
+{
+ if (Hooks->remove(plid, hookid))
+ return true;
+
+ return false;
}
-int mutil_RemoveHookAll(plid_t plid) {
- return(Hooks->remove_all(plid));
+int mutil_RemoveHookAll(plid_t plid)
+{
+ return Hooks->remove_all(plid);
}
-#endif /* UNFINISHED */
+
+#endif // UNFINISHED
// Meta Utility Function table.
mutil_funcs_t MetaUtilFunctions = {
- mutil_LogConsole, // pfnLogConsole
- mutil_LogMessage, // pfnLogMessage
- mutil_LogError, // pfnLogError
- mutil_LogDeveloper, // pfnLogDeveloper
- mutil_CenterSay, // pfnCenterSay
- mutil_CenterSayParms, // pfnCenterSayParms
- mutil_CenterSayVarargs, // pfnCenterSayVarargs
- mutil_CallGameEntity, // pfnCallGameEntity
- mutil_GetUserMsgID, // pfnGetUserMsgID
- mutil_GetUserMsgName, // pfnGetUserMsgName
- mutil_GetPluginPath, // pfnGetPluginPath
- mutil_GetGameInfo, // pfnGetGameInfo
- mutil_LoadMetaPlugin, // pfnLoadPlugin
- mutil_UnloadMetaPlugin, // pfnUnloadPlugin
- mutil_UnloadMetaPluginByHandle, //pfnUnloadPluginByHandle
- mutil_IsQueryingClientCvar, //pfnIsQueryingClientCvar
- mutil_MakeRequestId, // pfnMakeRequestId
- mutil_GetHookTables, // pfnGetHookTables
+ mutil_LogConsole, // pfnLogConsole
+ mutil_LogMessage, // pfnLogMessage
+ mutil_LogError, // pfnLogError
+ mutil_LogDeveloper, // pfnLogDeveloper
+ mutil_CenterSay, // pfnCenterSay
+ mutil_CenterSayParms, // pfnCenterSayParms
+ mutil_CenterSayVarargs, // pfnCenterSayVarargs
+ mutil_CallGameEntity, // pfnCallGameEntity
+ mutil_GetUserMsgID, // pfnGetUserMsgID
+ mutil_GetUserMsgName, // pfnGetUserMsgName
+ mutil_GetPluginPath, // pfnGetPluginPath
+ mutil_GetGameInfo, // pfnGetGameInfo
+ mutil_LoadMetaPlugin, // pfnLoadPlugin
+ mutil_UnloadMetaPlugin, // pfnUnloadPlugin
+ mutil_UnloadMetaPluginByHandle, // pfnUnloadPluginByHandle
+ mutil_IsQueryingClientCvar, // pfnIsQueryingClientCvar
+ mutil_MakeRequestId, // pfnMakeRequestId
+ mutil_GetHookTables, // pfnGetHookTables
#ifdef UNFINISHED
- mutil_HookGameEvent, // pfnGameEvent
- mutil_HookLogTrigger, // pfnLogTrigger
- mutil_HookLogString, // pfnLogString
+ mutil_HookGameEvent, // pfnGameEvent
+ mutil_HookLogTrigger, // pfnLogTrigger
+ mutil_HookLogString, // pfnLogString
mutil_HookLogRegex, // pfnLogRegex
mutil_RemoveHookID, // pfnRemoveHookID
- mutil_RemoveHookAll, // pfnRemoveHookAll
-#endif /* UNFINISHED */
+ mutil_RemoveHookAll, // pfnRemoveHookAll
+#endif // UNFINISHED
};
diff --git a/metamod/src/mutil.h b/metamod/src/mutil.h
index 9d545a6..1c7c020 100644
--- a/metamod/src/mutil.h
+++ b/metamod/src/mutil.h
@@ -1,94 +1,53 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// mutil.h - prototypes for utility functions to provide to plugins
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef MUTIL_H
-#define MUTIL_H
-
-#include "plinfo.h" // plugin_info_t, etc
+#include "plinfo.h" // plugin_info_t, etc
#include "sdk_util.h" // hudtextparms_t, etc
// max buffer size for printed messages
-#define MAX_LOGMSG_LEN 1024
+#define MAX_LOGMSG_LEN 1024
// For GetGameInfo:
-typedef enum {
+enum ginfo_t
+{
GINFO_NAME = 0,
GINFO_DESC,
GINFO_GAMEDIR,
GINFO_DLL_FULLPATH,
GINFO_DLL_FILENAME,
GINFO_REALDLL_FULLPATH,
-} ginfo_t;
+};
// Meta Utility Function table type.
-typedef struct meta_util_funcs_s {
+struct mutil_funcs_t
+{
void (*pfnLogConsole) (plid_t plid, const char *fmt, ...);
void (*pfnLogMessage) (plid_t plid, const char *fmt, ...);
void (*pfnLogError) (plid_t plid, const char *fmt, ...);
void (*pfnLogDeveloper) (plid_t plid, const char *fmt, ...);
void (*pfnCenterSay) (plid_t plid, const char *fmt, ...);
- void (*pfnCenterSayParms) (plid_t plid, hudtextparms_t tparms,
- const char *fmt, ...);
- void (*pfnCenterSayVarargs) (plid_t plid, hudtextparms_t tparms,
- const char *fmt, va_list ap);
- qboolean (*pfnCallGameEntity) (plid_t plid, const char *entStr,
- entvars_t *pev);
- int (*pfnGetUserMsgID) (plid_t plid, const char *msgname, int *size);
- const char *(*pfnGetUserMsgName) (plid_t plid, int msgid, int *size);
- const char *(*pfnGetPluginPath) (plid_t plid);
- const char *(*pfnGetGameInfo) (plid_t plid, ginfo_t tag);
- int (*pfnLoadPlugin) (plid_t plid, const char *cmdline, PLUG_LOADTIME now, void **plugin_handle);
- int (*pfnUnloadPlugin) (plid_t plid, const char *cmdline, PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
- int (*pfnUnloadPluginByHandle) (plid_t plid, void *plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
- const char *(*pfnIsQueryingClientCvar) (plid_t plid, const edict_t *pEdict);
- int (*pfnMakeRequestId) (plid_t plid);
+ void (*pfnCenterSayParms) (plid_t plid, hudtextparms_t tparms, const char *fmt, ...);
+ void (*pfnCenterSayVarargs) (plid_t plid, hudtextparms_t tparms, const char *fmt, va_list ap);
+ qboolean (*pfnCallGameEntity) (plid_t plid, const char *entStr, entvars_t *pev);
+ int (*pfnGetUserMsgID) (plid_t plid, const char *msgname, int *size);
+ const char * (*pfnGetUserMsgName) (plid_t plid, int msgid, int *size);
+ const char * (*pfnGetPluginPath) (plid_t plid);
+ const char * (*pfnGetGameInfo) (plid_t plid, ginfo_t tag);
+ int (*pfnLoadPlugin) (plid_t plid, const char *cmdline, PLUG_LOADTIME now, void **plugin_handle);
+ int (*pfnUnloadPlugin) (plid_t plid, const char *cmdline, PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
+ int (*pfnUnloadPluginByHandle) (plid_t plid, void *plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
+ const char * (*pfnIsQueryingClientCvar) (plid_t plid, const edict_t *pEdict);
+ int (*pfnMakeRequestId) (plid_t plid);
void (*pfnGetHookTables) (plid_t plid, enginefuncs_t **peng, DLL_FUNCTIONS **pdll, NEW_DLL_FUNCTIONS **pnewdll);
#ifdef UNFINISHED
- int (*pfnHookGameEvent) (plid_t plid, game_event_t event,
- event_func_t pfnHandle);
- int (*pfnHookLogTrigger) (plid_t plid, const char *trigger,
- logmatch_func_t pfnHandle);
- int (*pfnHookLogString) (plid_t plid, const char *string,
- logmatch_func_t pfnHandle);
- int (*pfnHookLogRegex) (plid_t plid, const char *pattern,
- logmatch_func_t pfnHandle);
+ int (*pfnHookGameEvent) (plid_t plid, game_event_t event, event_func_t pfnHandle);
+ int (*pfnHookLogTrigger) (plid_t plid, const char *trigger, logmatch_func_t pfnHandle);
+ int (*pfnHookLogString) (plid_t plid, const char *string, logmatch_func_t pfnHandle);
+ int (*pfnHookLogRegex) (plid_t plid, const char *pattern, logmatch_func_t pfnHandle);
qboolean (*pfnRemoveHookID) (plid_t plid, int hookid);
- int (*pfnRemoveHookAll) (plid_t plid);
-#endif /* UNFINISHED */
-} mutil_funcs_t;
+ int (*pfnRemoveHookAll) (plid_t plid);
+#endif
+};
+
extern mutil_funcs_t MetaUtilFunctions;
// Meta Utility Functions
@@ -98,10 +57,8 @@ void mutil_LogError(plid_t plid, const char *fmt, ...);
void mutil_LogDeveloper(plid_t plid, const char *fmt, ...);
void mutil_CenterSay(plid_t plid, const char *fmt, ...);
-void mutil_CenterSayParms(plid_t plid, hudtextparms_t tparms,
- const char *fmt, ...);
-void mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms,
- const char *fmt, va_list ap);
+void mutil_CenterSayParms(plid_t plid, hudtextparms_t tparms, const char *fmt, ...);
+void mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const char *fmt, va_list ap);
qboolean mutil_CallGameEntity(plid_t plid, const char *entStr, entvars_t *pev);
@@ -114,18 +71,14 @@ int mutil_MakeRequestId(plid_t plid);
void mutil_GetHookTables(plid_t plid, enginefuncs_t **peng, DLL_FUNCTIONS **pdll, NEW_DLL_FUNCTIONS **pnewdll);
#ifdef UNFINISHED
-int mutil_HookGameEvent(plid_t plid, game_event_t event,
- event_func_t pfnHandle);
-int mutil_HookLogTrigger(plid_t plid, const char *trigger,
- logmatch_func_t pfnHandle);
-int mutil_HookLogString(plid_t plid, const char *string,
- logmatch_func_t pfnHandle);
-int mutil_HookLogRegex(plid_t plid, const char *pattern,
- logmatch_func_t pfnHandle);
+int mutil_HookGameEvent(plid_t plid, game_event_t event, event_func_t pfnHandle);
+int mutil_HookLogTrigger(plid_t plid, const char *trigger, logmatch_func_t pfnHandle);
+int mutil_HookLogString(plid_t plid, const char *string, logmatch_func_t pfnHandle);
+int mutil_HookLogRegex(plid_t plid, const char *pattern, logmatch_func_t pfnHandle);
qboolean mutil_RemoveHookID(plid_t plid, int hookid);
int mutil_RemoveHookAll(plid_t plid);
-#endif /* UNFINISHED */
+#endif
// Convenience macros for MetaUtil functions
#define LOG_CONSOLE (*gpMetaUtilFuncs->pfnLogConsole)
@@ -154,6 +107,4 @@ int mutil_RemoveHookAll(plid_t plid);
#define HOOK_LOG_REGEX (*gpMetaUtilFuncs->pfnHookLogRegex)
#define REMOVE_HOOK_ID (*gpMetaUtilFuncs->pfnRemoveHookID)
#define REMOVE_HOOK_ALL (*gpMetaUtilFuncs->pfnRemoveHookAll)
-#endif /* UNFINISHED */
-
-#endif /* MUTIL_H */
+#endif
diff --git a/metamod/src/osdep.cpp b/metamod/src/osdep.cpp
index 6efe904..2815a91 100644
--- a/metamod/src/osdep.cpp
+++ b/metamod/src/osdep.cpp
@@ -1,39 +1,3 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// osdep.cpp - routines for operating system differences
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
mBOOL dlclose_handle_invalid;
@@ -41,12 +5,12 @@ mBOOL dlclose_handle_invalid;
// To keep the rest of the sources clean and keep not only OS but also
// compiler dependant differences in this file, we define a local function
// to set the new handler.
-void mm_set_new_handler( void )
+void mm_set_new_handler()
{
#if defined(_MSC_VER) && (_MSC_VER < 1300)
- _set_new_handler(meta_new_handler);
+ _set_new_handler(meta_new_handler);
#else
- std::set_new_handler(meta_new_handler);
+ std::set_new_handler(meta_new_handler);
#endif
}
@@ -54,56 +18,57 @@ void mm_set_new_handler( void )
// Since windows doesn't provide a verison of strtok_r(), we include one
// here. This may or may not operate exactly like strtok_r(), but does
// what we need it it do.
-char *my_strtok_r(char *s, const char *delim, char **ptrptr) {
- char *begin=NULL;
- char *end=NULL;
- char *rest=NULL;
- if(s)
- begin=s;
+char *my_strtok_r(char *s, const char *delim, char **ptrptr)
+{
+ char *begin = nullptr;
+ char *end = nullptr;
+ char *rest = nullptr;
+ if (s)
+ begin = s;
else
- begin=*ptrptr;
- if(!begin)
- return(NULL);
- end=strpbrk(begin, delim);
- if(end) {
- *end='\0';
- rest=end+1;
- *ptrptr=rest+strspn(rest, delim);
+ begin = *ptrptr;
+ if (!begin)
+ return nullptr;
+
+ end = strpbrk(begin, delim);
+ if (end)
+ {
+ *end = '\0';
+ rest = end + 1;
+ *ptrptr = rest + strspn(rest, delim);
}
else
- *ptrptr=NULL;
- return(begin);
-}
-#endif /* _WIN32 */
+ *ptrptr = nullptr;
+ return begin;
+}
+#endif // _WIN32
#ifdef _WIN32
// Windows doesn't provide a functon analagous to dlerr() that returns a
// string describing the error, so we include one here, as exampled at:
-// http://msdn.microsoft.com/library/en-us/debug/errors_0sdh.asp
+// http://msdn.microsoft.com/library/en-us/debug/errors_0sdh.asp
// except without FORMAT_MESSAGE_ALLOCATE_BUFFER, since we use a local
// static buffer.
-const char *str_GetLastError(void) {
+const char *str_GetLastError()
+{
static char buf[MAX_STRBUF_LEN];
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //! Default language
- (LPTSTR) &buf, MAX_STRBUF_LEN-1, NULL);
- return(buf);
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, MAX_STRBUF_LEN - 1, NULL);
+ return buf;
}
-#endif /* _WIN32 */
-
+#endif
// Find the filename of the DLL/shared-lib where the given memory location
// exists.
#if defined(linux) || defined(__APPLE__)
// Errno values:
// - ME_NOTFOUND couldn't find a sharedlib that contains memory location
-const char *DLFNAME(void *memptr) {
+const char *DLFNAME(void *memptr)
+{
Dl_info dli;
- memset(&dli, 0, sizeof(dli));
- if(dladdr(memptr, &dli))
- return(dli.dli_fname);
+ Q_memset(&dli, 0, sizeof(dli));
+ if (dladdr(memptr, &dli))
+ return dli.dli_fname;
else
RETURN_ERRNO(NULL, ME_NOTFOUND);
}
@@ -129,31 +94,34 @@ const char *DLFNAME(void *memptr) {
//
// Errno values:
// - ME_NOTFOUND couldn't find a DLL that contains memory location
-const char *DLFNAME(void *memptr) {
+const char *DLFNAME(void *memptr)
+{
MEMORY_BASIC_INFORMATION MBI;
static char fname[PATH_MAX];
- memset(fname, 0, sizeof(fname));
+ Q_memset(fname, 0, sizeof(fname));
if (!VirtualQuery(memptr, &MBI, sizeof(MBI)))
RETURN_ERRNO(NULL, ME_NOTFOUND);
+
if (MBI.State != MEM_COMMIT)
RETURN_ERRNO(NULL, ME_NOTFOUND);
- if(!MBI.AllocationBase)
+
+ if (!MBI.AllocationBase)
RETURN_ERRNO(NULL, ME_NOTFOUND);
-
+
// MSDN indicates that GetModuleFileName will leave string
// null-terminated, even if it's truncated because buffer is too small.
- if(!GetModuleFileName((HMODULE)MBI.AllocationBase, fname,
+ if (!GetModuleFileName((HMODULE)MBI.AllocationBase, fname,
sizeof(fname)-1))
RETURN_ERRNO(NULL, ME_NOTFOUND);
- if(!fname[0])
+ if (!fname[0])
RETURN_ERRNO(NULL, ME_NOTFOUND);
-
+
normalize_pathname(fname);
- return(fname);
+ return fname;
}
-#endif /* _WIN32 */
+#endif // _WIN32
// Determine whether the given memory location is valid (ie whether we
@@ -165,11 +133,12 @@ const char *DLFNAME(void *memptr) {
// we need it for in this particular situation.
// meta_errno values:
// - ME_NOTFOUND couldn't find a matching sharedlib for this ptr
-mBOOL IS_VALID_PTR(void *memptr) {
+mBOOL IS_VALID_PTR(void *memptr)
+{
Dl_info dli;
- memset(&dli, 0, sizeof(dli));
- if(dladdr(memptr, &dli))
- return(mTRUE);
+ Q_memset(&dli, 0, sizeof(dli));
+ if (dladdr(memptr, &dli))
+ return mTRUE;
else
RETURN_ERRNO(mFALSE, ME_NOTFOUND);
}
@@ -177,40 +146,47 @@ mBOOL IS_VALID_PTR(void *memptr) {
// Use the native windows routine IsBadCodePtr.
// meta_errno values:
// - ME_BADMEMPTR not a valid memory pointer
-mBOOL IS_VALID_PTR(void *memptr) {
- if(IsBadCodePtr((FARPROC) memptr))
+mBOOL IS_VALID_PTR(void *memptr)
+{
+ if (IsBadCodePtr((FARPROC) memptr))
RETURN_ERRNO(mFALSE, ME_BADMEMPTR);
else
- return(mTRUE);
+ return mTRUE;
}
-#endif /* _WIN32 */
+#endif // _WIN32
// This used to be OS-dependent, as it used a SEGV signal handler under
// linux, but that was removed because (a) it masked legitimate segfaults
// in plugin commands and produced confusing output ("plugin has been
// unloaded", when really it segfaultd), and (b) wasn't necessary since
// IS_VALID_PTR() should cover the situation.
-mBOOL os_safe_call(REG_CMD_FN pfn) {
+mBOOL os_safe_call(REG_CMD_FN pfn)
+{
// try and see if this is a valid memory location
- if(!IS_VALID_PTR((void *) pfn))
+ if (!IS_VALID_PTR((void *)pfn))
// meta_errno should be already set in is_valid_ptr()
- return(mFALSE);
+ return mFALSE;
pfn();
- return(mTRUE);
+ return mTRUE;
}
// See comments in osdep.h.
-#if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1300))
-void MM_CDECL meta_new_handler(void) {
- // This merely because we don't want the program to exit if new()
- // fails..
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+void __cdecl meta_new_handler()
+{
return;
}
#elif defined(_MSC_VER)
-int meta_new_handler(size_t size) {
+int meta_new_handler(size_t size)
+{
// This merely because we don't want the program to exit if new()
// fails..
- return(0);
+ return 0;
}
-#endif /* _MSC_VER */
+#else
+void meta_new_handler()
+{
+ return;
+}
+#endif
diff --git a/metamod/src/osdep.h b/metamod/src/osdep.h
index 2dd5b68..a164e5b 100644
--- a/metamod/src/osdep.h
+++ b/metamod/src/osdep.h
@@ -1,194 +1,108 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// osdep.h - operating system dependencies
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef OSDEP_H
-#define OSDEP_H
-
-#include // strerror()
-#include // isupper, tolower
-#include // errno
+#pragma once
// Various differences between WIN32 and Linux.
-
#include "types_meta.h" // mBOOL
-#include "mreg.h" // REG_CMD_FN, etc
+#include "mreg.h" // REG_CMD_FN, etc
#include "log_meta.h" // LOG_ERROR, etc
+// String describing platform/DLL-type, for matching lines in plugins.ini.
+#ifdef _WIN32
+ #define UNUSED /**/
+
+ #define PLATFORM "mswin"
+ #define PLATFORM_SPC "win32"
+ #define PLATFORM_DLEXT ".dll"
+#else
+ #define UNUSED __attribute__((unused))
+
+ #define PLATFORM "linux"
+ #define PLATFORM_SPC "lin32"
+ #define PLATFORM_DLEXT ".so"
+#endif
+
extern mBOOL dlclose_handle_invalid;
-// String describing platform/DLL-type, for matching lines in plugins.ini.
-#ifdef __linux
- #define PLATFORM "linux"
-# ifdef __amd64__
- #define PLATFORM_SPC "lin64"
-# else
- #define PLATFORM_SPC "lin32"
-# endif
-#elif defined(_WIN32)
- #define PLATFORM "mswin"
- #define PLATFORM_SPC "win32"
-#elif defined(__APPLE__)
- #define PLATFORM "osx"
- #define PLATFORM_SPC "osx32"
-#else /* unknown */
- #error "OS unrecognized"
-#endif /* unknown */
-
-
-// Macro for function-exporting from DLL..
-// from SDK dlls/cbase.h:
-//! C functions for external declarations that call the appropriate C++ methods
-
-// Windows uses "__declspec(dllexport)" to mark functions in the DLL that
-// should be visible/callable externally.
-//
-// It also apparently requires WINAPI for GiveFnptrsToDll().
-//
-// See doc/notes_windows_coding for more information..
-
-// Attributes to specify an "exported" function, visible from outside the
-// DLL.
-#undef DLLEXPORT
-#ifdef _WIN32
- #define DLLEXPORT __declspec(dllexport)
- // WINAPI should be provided in the windows compiler headers.
- // It's usually defined to something like "__stdcall".
-#elif defined(__GNUC__)
-# if __GNUC__ >= 4
- #define DLLEXPORT __attribute__ ((visibility("default")))
-# else
- #define DLLEXPORT /* */
-# endif
- #define WINAPI /* */
-#endif /* linux */
-
-#ifdef __GNUC__
-# define DECLSPEC(kw)
-# define ATTRIBUTE(kw) __attribute__((kw))
-# define MM_CDECL
-#elif defined(_MSC_VER)
-# define DECLSPEC(kw) __declspec(kw)
-# define ATTRIBUTE(kw)
-# define MM_CDECL __cdecl
-#endif /* _MSC_VER */
-
-
-// Simplified macro for declaring/defining exported DLL functions. They
-// need to be 'extern "C"' so that the C++ compiler enforces parameter
-// type-matching, rather than considering routines with mis-matched
-// arguments/types to be overloaded functions...
-//
-// AFAIK, this is os-independent, but it's included here in osdep.h where
-// DLLEXPORT is defined, for convenience.
-#define C_DLLEXPORT extern "C" DLLEXPORT
-
-
-#ifdef _MSC_VER
- // Disable MSVC warning:
- // 4390 : empty controlled statement found; is this what was intended?
- // generated by the RETURN macros.
- #pragma warning(disable: 4390)
-#endif /* _MSC_VER */
-
-
// Functions & types for DLL open/close/etc operations.
-#if defined(__linux) || defined(__APPLE__)
- #include
- typedef void* DLHANDLE;
- typedef void* DLFUNC;
- inline DLHANDLE DLOPEN(const char *filename) {
- return(dlopen(filename, RTLD_NOW));
- }
- inline DLFUNC DLSYM(DLHANDLE handle, const char *string) {
- return(dlsym(handle, string));
- }
- inline int DLCLOSE(DLHANDLE handle) {
- if (!handle) {
- dlclose_handle_invalid = mTRUE;
- return(1);
- }
- dlclose_handle_invalid = mFALSE;
- return(dlclose(handle));
- }
- inline const char* DLERROR(void) {
- if (dlclose_handle_invalid)
- return("Invalid handle.");
- return(dlerror());
- }
-#elif defined(_WIN32)
+#ifdef _WIN32
typedef HINSTANCE DLHANDLE;
typedef FARPROC DLFUNC;
- inline DLHANDLE DLOPEN(const char *filename) {
- return(LoadLibrary(filename));
+ inline DLHANDLE DLOPEN(const char *filename)
+ {
+ return LoadLibraryA(filename);
}
- inline DLFUNC DLSYM(DLHANDLE handle, const char *string) {
- return(GetProcAddress(handle, string));
+ inline DLFUNC DLSYM(DLHANDLE handle, const char *string)
+ {
+ return GetProcAddress(handle, string);
}
- inline int DLCLOSE(DLHANDLE handle) {
- if (!handle) {
+ inline int DLCLOSE(DLHANDLE handle)
+ {
+ if (!handle)
+ {
dlclose_handle_invalid = mTRUE;
- return(1);
+ return 1;
}
+
dlclose_handle_invalid = mFALSE;
// NOTE: Windows FreeLibrary returns success=nonzero, fail=zero,
// which is the opposite of the unix convention, thus the '!'.
- return(!FreeLibrary(handle));
+ return !FreeLibrary(handle);
}
// Windows doesn't provide a function corresponding to dlerror(), so
// we make our own.
- const char *str_GetLastError(void);
- inline const char* DLERROR(void) {
+ const char *str_GetLastError();
+ inline const char *DLERROR()
+ {
if (dlclose_handle_invalid)
- return("Invalid handle.");
- return(str_GetLastError());
+ return "Invalid handle.";
+
+ return str_GetLastError();
}
-#endif /* _WIN32 */
+#else
+ typedef void *DLHANDLE;
+ typedef void *DLFUNC;
+ inline DLHANDLE DLOPEN(const char *filename)
+ {
+ return dlopen(filename, RTLD_NOW);
+ }
+ inline DLFUNC DLSYM(DLHANDLE handle, const char *string)
+ {
+ return dlsym(handle, string);
+ }
+ // dlclose crashes if handle is null.
+ inline int DLCLOSE(DLHANDLE handle)
+ {
+ if (!handle)
+ {
+ dlclose_handle_invalid = mTRUE;
+ return 1;
+ }
+ dlclose_handle_invalid = mFALSE;
+ return dlclose(handle);
+ }
+ inline const char *DLERROR()
+ {
+ if (dlclose_handle_invalid)
+ return "Invalid handle.";
+
+ return dlerror();
+ }
+#endif
+
const char *DLFNAME(void *memptr);
mBOOL IS_VALID_PTR(void *memptr);
-
// Attempt to call the given function pointer, without segfaulting.
mBOOL os_safe_call(REG_CMD_FN pfn);
-
// Windows doesn't have an strtok_r() routine, so we write our own.
#ifdef _WIN32
#define strtok_r(s, delim, ptrptr) my_strtok_r(s, delim, ptrptr)
char *my_strtok_r(char *s, const char *delim, char **ptrptr);
-#endif /* _WIN32 */
+#else
+// Linux doesn't have an strlwr() routine, so we write our own.
+ #define strlwr(s) my_strlwr(s)
+ char *my_strlwr(char *s);
+#endif // _WIN32
// Set filename and pathname maximum lengths. Note some windows compilers
@@ -204,15 +118,14 @@ mBOOL os_safe_call(REG_CMD_FN pfn);
#include
#define NAME_MAX _MAX_FNAME
#define PATH_MAX _MAX_PATH
-#endif /* _WIN32 */
-
+#endif // _WIN32
// Various other windows routine differences.
#if defined(__linux) || defined(__APPLE__)
#include // sleep
#ifndef O_BINARY
#define O_BINARY 0
- #endif
+ #endif
#elif defined(_WIN32)
#define snprintf _snprintf
#define vsnprintf _vsnprintf
@@ -222,7 +135,7 @@ mBOOL os_safe_call(REG_CMD_FN pfn);
#define read _read
#define write _write
#define close _close
-#endif /* _WIN32 */
+#endif // _WIN32
#ifdef __GNUC__
#include // _getcwd
@@ -244,7 +157,7 @@ mBOOL os_safe_call(REG_CMD_FN pfn);
#ifndef S_IWUSR
#define S_IWUSR _S_IWRITE
#endif
-
+
// The following two are defined neither in mingw nor in MSVC
#ifndef S_IRGRP
#define S_IRGRP S_IRUSR
@@ -252,15 +165,14 @@ mBOOL os_safe_call(REG_CMD_FN pfn);
#ifndef S_IWGRP
#define S_IWGRP S_IWUSR
#endif
-#endif /* _WIN32 */
-
+#endif // _WIN32
// Our handler for new().
//
// Thanks to notes from:
// http://dragon.klte.hu/~kollarl/C++/node45.html
//
-// At one point it appeared MSVC++ was no longer different from gcc, according
+// At one point it appeared MSVC++ was no longer different from gcc, according
// to:
// http://msdn.microsoft.com/library/en-us/vclang98/stdlib/info/NEW.asp
//
@@ -273,80 +185,86 @@ mBOOL os_safe_call(REG_CMD_FN pfn);
// MSVCRT debugging sources) should never be used. It is just an ugly
// hack to make STL compile. It does _not_ set the new handler but
// always calls _set_new_handler(0) instead. _set_new_handler is the
-// "real" function and uses the "old" semantic; handler-type is:
+// "real" function and uses the "old" semantic; handler-type is:
// int newhandler(size_t)
//
-#if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1300))
- void MM_CDECL meta_new_handler(void);
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+ void __cdecl meta_new_handler();
#elif defined(_MSC_VER)
int meta_new_handler(size_t size);
-#endif /* _MSC_VER */
-
+#else
+ void meta_new_handler();
+#endif
// To keep the rest of the sources clean and keep not only OS but also
// compiler dependant differences in this file, we define a local function
// to set the new handler.
void mm_set_new_handler( void );
-
-
// Thread handling...
#if defined(__linux) || defined(__APPLE__)
#include
- typedef pthread_t THREAD_T;
+ typedef pthread_t THREAD_T;
// returns 0==success, non-zero==failure
- inline int THREAD_CREATE(THREAD_T *tid, void (*func)(void)) {
+ inline int THREAD_CREATE(THREAD_T *tid, void (*func)())
+ {
int ret;
- ret=pthread_create(tid, NULL, (void *(*)(void*)) func, NULL);
- if(ret != 0) {
+ ret = pthread_create(tid, NULL, (void *(*)(void*)) func, NULL);
+ if (ret != 0)
+ {
META_ERROR("Failure starting thread: %s", strerror(ret));
- return(ret);
+ return ret;
}
- ret=pthread_detach(*tid);
- if(ret != 0)
+
+ ret = pthread_detach(*tid);
+ if (ret != 0)
META_ERROR("Failure detaching thread: %s", strerror(ret));
- return(ret);
+ return ret;
}
#elif defined(_WIN32)
// See:
// http://msdn.microsoft.com/library/en-us/dllproc/prothred_4084.asp
- typedef DWORD THREAD_T;
+ typedef DWORD THREAD_T;
// returns 0==success, non-zero==failure
- inline int THREAD_CREATE(THREAD_T *tid, void (*func)(void)) {
+ inline int THREAD_CREATE(THREAD_T *tid, void (*func)())
+ {
HANDLE ret;
// win32 returns NULL==failure, non-NULL==success
- ret=CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, NULL, 0, tid);
- if(ret==NULL)
+ ret = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, NULL, 0, tid);
+ if (ret == NULL)
META_ERROR("Failure starting thread: %s", str_GetLastError());
- return(ret==NULL);
+ return ret == NULL;
}
-#endif /* _WIN32 */
+#endif // _WIN32
#define THREAD_OK 0
// Mutex handling...
#if defined(__linux) || defined(__APPLE__)
typedef pthread_mutex_t MUTEX_T;
- inline int MUTEX_INIT(MUTEX_T *mutex) {
+ inline int MUTEX_INIT(MUTEX_T *mutex)
+ {
int ret;
- ret=pthread_mutex_init(mutex, NULL);
- if(ret!=THREAD_OK)
+ ret = pthread_mutex_init(mutex, NULL);
+ if (ret != THREAD_OK)
META_ERROR("mutex_init failed: %s", strerror(ret));
- return(ret);
+ return ret;
}
- inline int MUTEX_LOCK(MUTEX_T *mutex) {
+ inline int MUTEX_LOCK(MUTEX_T *mutex)
+ {
int ret;
- ret=pthread_mutex_lock(mutex);
- if(ret!=THREAD_OK)
+ ret = pthread_mutex_lock(mutex);
+ if (ret != THREAD_OK)
META_ERROR("mutex_lock failed: %s", strerror(ret));
- return(ret);
+ return ret;
}
- inline int MUTEX_UNLOCK(MUTEX_T *mutex) {
+ inline int MUTEX_UNLOCK(MUTEX_T *mutex)
+ {
int ret;
- ret=pthread_mutex_unlock(mutex);
- if(ret!=THREAD_OK)
+ ret = pthread_mutex_unlock(mutex);
+ if (ret != THREAD_OK)
META_ERROR("mutex_unlock failed: %s", strerror(ret));
- return(ret);
+ return ret;
}
#elif defined(_WIN32)
// Win32 has "mutexes" as well, but CS's are simpler.
@@ -354,44 +272,50 @@ void mm_set_new_handler( void );
// http://msdn.microsoft.com/library/en-us/dllproc/synchro_2a2b.asp
typedef CRITICAL_SECTION MUTEX_T;
// Note win32 routines don't return any error (return void).
- inline int MUTEX_INIT(MUTEX_T *mutex) {
+ inline int MUTEX_INIT(MUTEX_T *mutex)
+ {
InitializeCriticalSection(mutex);
- return(THREAD_OK);
+ return THREAD_OK;
}
- inline int MUTEX_LOCK(MUTEX_T *mutex) {
+ inline int MUTEX_LOCK(MUTEX_T *mutex)
+ {
EnterCriticalSection(mutex);
- return(THREAD_OK);
+ return THREAD_OK;
}
- inline int MUTEX_UNLOCK(MUTEX_T *mutex) {
+ inline int MUTEX_UNLOCK(MUTEX_T *mutex)
+ {
LeaveCriticalSection(mutex);
- return(THREAD_OK);
+ return THREAD_OK;
}
-#endif /* _WIN32 (mutex) */
+#endif // _WIN32
// Condition variables...
#if defined(__linux) || defined(__APPLE__)
typedef pthread_cond_t COND_T;
- inline int COND_INIT(COND_T *cond) {
+ inline int COND_INIT(COND_T *cond)
+ {
int ret;
- ret=pthread_cond_init(cond, NULL);
- if(ret!=THREAD_OK)
+ ret = pthread_cond_init(cond, NULL);
+ if (ret != THREAD_OK)
META_ERROR("cond_init failed: %s", strerror(ret));
- return(ret);
+ return ret;
}
- inline int COND_WAIT(COND_T *cond, MUTEX_T *mutex) {
+ inline int COND_WAIT(COND_T *cond, MUTEX_T *mutex)
+ {
int ret;
- ret=pthread_cond_wait(cond, mutex);
- if(ret!=THREAD_OK)
+ ret = pthread_cond_wait(cond, mutex);
+ if (ret != THREAD_OK)
META_ERROR("cond_wait failed: %s", strerror(ret));
- return(ret);
+ return ret;
}
- inline int COND_SIGNAL(COND_T *cond) {
+ inline int COND_SIGNAL(COND_T *cond)
+ {
int ret;
- ret=pthread_cond_signal(cond);
- if(ret!=THREAD_OK)
+ ret = pthread_cond_signal(cond);
+ if (ret != THREAD_OK)
META_ERROR("cond_signal failed: %s", strerror(ret));
- return(ret);
+ return ret;
}
#elif defined(_WIN32)
// Since win32 doesn't provide condition-variables, we have to model
@@ -407,46 +331,52 @@ void mm_set_new_handler( void );
//
// See also:
// http://msdn.microsoft.com/library/en-us/dllproc/synchro_8ann.asp
- typedef HANDLE COND_T;
- inline int COND_INIT(COND_T *cond) {
+ typedef HANDLE COND_T;
+ inline int COND_INIT(COND_T *cond)
+ {
*cond = CreateEvent(NULL, // security attributes (none)
FALSE, // manual-reset type (false==auto-reset)
FALSE, // initial state (unsignaled)
NULL); // object name (unnamed)
// returns NULL on error
- if(*cond==NULL) {
+ if (*cond == NULL)
+ {
META_ERROR("cond_init failed: %s", str_GetLastError());
- return(-1);
+ return -1;
}
else
- return(0);
+ return 0;
}
- inline int COND_WAIT(COND_T *cond, MUTEX_T *mutex) {
+ inline int COND_WAIT(COND_T *cond, MUTEX_T *mutex)
+ {
DWORD ret;
LeaveCriticalSection(mutex);
- ret=WaitForSingleObject(*cond, INFINITE);
+ ret = WaitForSingleObject(*cond, INFINITE);
EnterCriticalSection(mutex);
// returns WAIT_OBJECT_0 if object was signaled; other return
// values indicate errors.
- if(ret == WAIT_OBJECT_0)
- return(0);
- else {
+ if (ret == WAIT_OBJECT_0)
+ return 0;
+ else
+ {
META_ERROR("cond_wait failed: %s", str_GetLastError());
- return(-1);
+ return -1;
}
}
- inline int COND_SIGNAL(COND_T *cond) {
+ inline int COND_SIGNAL(COND_T *cond)
+ {
BOOL ret;
- ret=SetEvent(*cond);
+ ret = SetEvent(*cond);
// returns zero on failure
- if(ret==0) {
+ if (ret == 0)
+ {
META_ERROR("cond_signal failed: %s", str_GetLastError());
- return(-1);
+ return -1;
}
else
- return(0);
+ return 0;
}
-#endif /* _WIN32 (condition variable) */
+#endif // _WIN32
// Normalize/standardize a pathname.
// - For win32, this involves:
@@ -459,17 +389,20 @@ void mm_set_new_handler( void );
#if defined(__linux) || defined(__APPLE__)
#define normalize_pathname(a)
#elif defined(_WIN32)
-inline void normalize_pathname(char *path) {
+inline void normalize_pathname(char *path)
+{
char *cp;
META_DEBUG(8, ("normalize: %s", path));
- for(cp=path; *cp; cp++) {
- if(isupper(*cp)) *cp=tolower(*cp);
- if(*cp=='\\') *cp='/';
+ for (cp = path; *cp; cp++)
+ {
+ if (isupper(*cp)) *cp = tolower(*cp);
+ if (*cp == '\\') *cp = '/';
}
+
META_DEBUG(8, ("normalized: %s", path));
}
-#endif /* _WIN32 */
+#endif // _WIN32
// Indicate if pathname appears to be an absolute-path. Under linux this
// is a leading slash (/). Under win32, this can be:
@@ -477,51 +410,55 @@ inline void normalize_pathname(char *path) {
// - a toplevel path (ie "\blah")
// - a UNC network address (ie "\\srv1\blah").
// Also, handle both native and normalized pathnames.
-inline int is_absolute_path(const char *path) {
- if(path[0]=='/') return(TRUE);
+inline int is_absolute_path(const char *path)
+{
+ if (path[0] == '/') return TRUE;
#ifdef _WIN32
- if(path[1]==':') return(TRUE);
- if(path[0]=='\\') return(TRUE);
-#endif /* _WIN32 */
- return(FALSE);
+ if (path[1] == ':') return TRUE;
+ if (path[0] == '\\') return TRUE;
+#endif // _WIN32
+ return FALSE;
}
#ifdef _WIN32
// Buffer pointed to by resolved_name is assumed to be able to store a
// string of PATH_MAX length.
-inline char *realpath(const char *file_name, char *resolved_name) {
+inline char *realpath(const char *file_name, char *resolved_name)
+{
int ret;
- ret=GetFullPathName(file_name, PATH_MAX, resolved_name, NULL);
- if(ret > PATH_MAX) {
- errno=ENAMETOOLONG;
- return(NULL);
+ ret = GetFullPathName(file_name, PATH_MAX, resolved_name, NULL);
+ if (ret > PATH_MAX)
+ {
+ errno = ENAMETOOLONG;
+ return NULL;
}
- else if(ret > 0) {
+ else if (ret > 0)
+ {
HANDLE handle;
WIN32_FIND_DATA find_data;
- handle=FindFirstFile(resolved_name, &find_data);
- if(INVALID_HANDLE_VALUE == handle) {
- errno=ENOENT;
+ handle = FindFirstFile(resolved_name, &find_data);
+ if (INVALID_HANDLE_VALUE == handle)
+ {
+ errno = ENOENT;
return NULL;
}
+
FindClose(handle);
normalize_pathname(resolved_name);
- return(resolved_name);
+ return resolved_name;
}
- else
- return(NULL);
+
+ return NULL;
}
-#endif /* _WIN32 */
+#endif // _WIN32
// Generic "error string" from a recent OS call. For linux, this is based
// on errno. For win32, it's based on GetLastError.
-inline const char *str_os_error(void) {
-#if defined(__linux) || defined(__APPLE__)
- return(strerror(errno));
-#elif defined(_WIN32)
- return(str_GetLastError());
-#endif /* _WIN32 */
+inline const char *str_os_error()
+{
+#ifdef _WIN32
+ return str_GetLastError();
+#else
+ return strerror(errno);
+#endif
}
-
-
-#endif /* OSDEP_H */
diff --git a/metamod/src/plinfo.h b/metamod/src/plinfo.h
index 6ac55cb..9d40002 100644
--- a/metamod/src/plinfo.h
+++ b/metamod/src/plinfo.h
@@ -1,82 +1,48 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// plinfo.h - typedefs for plugin info structure
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef PLINFO_H
-#define PLINFO_H
+#pragma once
// Flags for plugin to indicate when it can be be loaded/unloaded.
// NOTE: order is crucial, as greater/less comparisons are made.
-typedef enum {
+enum PLUG_LOADTIME
+{
PT_NEVER = 0,
- PT_STARTUP, // should only be loaded/unloaded at initial hlds execution
+ PT_STARTUP, // should only be loaded/unloaded at initial hlds execution
PT_CHANGELEVEL, // can be loaded/unloaded between maps
- PT_ANYTIME, // can be loaded/unloaded at any time
+ PT_ANYTIME, // can be loaded/unloaded at any time
PT_ANYPAUSE, // can be loaded/unloaded at any time, and can be "paused" during a map
-} PLUG_LOADTIME;
+};
// Flags to indicate why the plugin is being unloaded.
-typedef enum {
+enum PL_UNLOAD_REASON
+{
PNL_NULL = 0,
PNL_INI_DELETED, // was deleted from plugins.ini
PNL_FILE_NEWER, // file on disk is newer than last load
PNL_COMMAND, // requested by server/console command
PNL_CMD_FORCED, // forced by server/console command
PNL_DELAYED, // delayed from previous request; can't tell origin
-//only used for 'real_reason' on MPlugin::unload()
- PNL_PLUGIN, // requested by plugin function call
+
+ // only used for 'real_reason' on MPlugin::unload()
+ PNL_PLUGIN, // requested by plugin function call
PNL_PLG_FORCED, // forced by plugin function call
- PNL_RELOAD, // forced unload by reload()
-} PL_UNLOAD_REASON;
+ PNL_RELOAD, // forced unload by reload()
+};
// Information plugin provides about itself.
-typedef struct {
- const char *ifvers; // meta_interface version
- const char *name; // full name of plugin
+struct plugin_info_t
+{
+ const char *ifvers; // meta_interface version
+ const char *name; // full name of plugin
const char *version; // version
- const char *date; // date
- const char *author; // author name/email
- const char *url; // URL
- const char *logtag; // log message prefix (unused right now)
+ const char *date; // date
+ const char *author; // author name/email
+ const char *url; // URL
+ const char *logtag; // log message prefix (unused right now)
PLUG_LOADTIME loadable; // when loadable
PLUG_LOADTIME unloadable; // when unloadable
-} plugin_info_t;
+};
+
extern plugin_info_t Plugin_info;
// Plugin identifier, passed to all Meta Utility Functions.
-typedef plugin_info_t* plid_t;
-#define PLID &Plugin_info
-
-#endif /* PLINFO_H */
+typedef plugin_info_t *plid_t;
+#define PLID &Plugin_info
diff --git a/metamod/src/precompiled.h b/metamod/src/precompiled.h
index 3ba44cc..a77a83d 100644
--- a/metamod/src/precompiled.h
+++ b/metamod/src/precompiled.h
@@ -1,31 +1,20 @@
#pragma once
+#include "version/appversion.h"
+
#if defined(linux) || defined(__APPLE__)
// enable extra routines in system header files, like dladdr
-# ifndef _GNU_SOURCE
-# define _GNU_SOURCE
-# endif
-#include // dlopen, dladdr, etc
+#ifndef _GNU_SOURCE
+ #define _GNU_SOURCE
+#endif
#include // sigaction, etc
-#include // sigsetjmp, longjmp, etc
-#endif /* linux */
-
-#if defined(_MSC_VER) && (_MSC_VER < 1300)
-# include // set_new_handler()
-#else
-# include // set_new_handler()
#endif
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
+#if defined(_MSC_VER) && (_MSC_VER < 1300)
+#include // set_new_handler()
+#else
+#include // set_new_handler()
+#endif
#include
#include
@@ -36,9 +25,6 @@
#include "commands_meta.h"
#include "metamod.h"
#include "log_meta.h"
-#include "info_name.h"
-#include "vdate.h"
-#include "vers_meta.h"
#include "conf_meta.h"
#include "support_meta.h"
#include "dllapi.h"
diff --git a/metamod/src/reg_support.cpp b/metamod/src/reg_support.cpp
index 0ec20d6..cd9f7e1 100644
--- a/metamod/src/reg_support.cpp
+++ b/metamod/src/reg_support.cpp
@@ -1,49 +1,5 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// reg_support.cpp - support for things "registered" by plugins (console
-// cmds, cvars, msgs, etc)
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
-#ifdef linux
-// enable extra routines in system header files, like strsignal
-# ifndef _GNU_SOURCE
-# define _GNU_SOURCE
-# endif
-#endif /* linux */
-
// "Register" support.
//
// This code is necessary to support the different "register" engine
@@ -86,29 +42,30 @@
// Windows didn't seem to have a similar routine, and I couldn't find
// another way to get the information..
-
// Generic command handler, passed to the engine for any AddServerCommand
// calls made by the plugin. It finds the appropriate plugin function
// pointer to call based on CMD_ARGV(0).
-void meta_command_handler(void)
+void meta_command_handler()
{
- MRegCmd* icmd;
- const char* cmd;
-
META_DEBUG(5, ("called: meta_command_handler; arg0=%s args='%s'", CMD_ARGV(0), CMD_ARGS()));
- cmd = CMD_ARGV(0);
- if (!cmd) {
+ const char *cmd = CMD_ARGV(0);
+ if (!cmd)
+ {
META_ERROR("Null command name in meta_command_handler() ??");
return;
}
- icmd = g_regCmds->find(cmd);
- if (!icmd) {
+ MRegCmd *icmd = g_regCmds->find(cmd);
+ if (!icmd)
+ {
META_ERROR("Couldn't find registered plugin command: %s", cmd);
return;
}
+
if (icmd->call() != mTRUE)
+ {
META_CONS("[metamod: command '%s' unavailable; plugin unloaded]", cmd);
+ }
}
@@ -118,18 +75,19 @@ void meta_command_handler(void)
// engine a command string and function pointer allocated locally (in the
// metamod DLL).
//
-// The string handed to the engine is just a _strdup() of the plugin's
+// The string handed to the engine is just a Q_strdup() of the plugin's
// string. The function pointer handed to the engine is actually a pointer
// to a generic command-handler function (see above).
-void meta_AddServerCommand(char* cmd_name, void (*function)(void))
+void meta_AddServerCommand(char *cmd_name, void (*function)())
{
- MPlugin* iplug = NULL;
- MRegCmd* icmd = NULL;
+ MPlugin *iplug = NULL;
+ MRegCmd *icmd = NULL;
META_DEBUG(4, ("called: meta_AddServerCommand; cmd_name=%s, function=%d", cmd_name, function));
// try to find which plugin is registering this command
- if (!(iplug = g_plugins->find_memloc((void *)function))) {
+ if (!(iplug = g_plugins->find_memloc((void *)function)))
+ {
// if this isn't supported on this OS, don't log an error
if (meta_errno != ME_OSNOTSUP)
META_ERROR("Failed to find memloc for regcmd '%s'", cmd_name);
@@ -137,13 +95,16 @@ void meta_AddServerCommand(char* cmd_name, void (*function)(void))
// See if this command was previously registered, ie a "reloaded" plugin.
icmd = g_regCmds->find(cmd_name);
- if (!icmd) {
+ if (!icmd)
+ {
// If not found, add.
icmd = g_regCmds->add(cmd_name);
- if (!icmd) {
+ if (!icmd)
+ {
// error details logged in add()
return;
}
+
// Only register if not previously registered..
REG_SVR_COMMAND(icmd->name, meta_command_handler);
}
@@ -165,47 +126,51 @@ void meta_AddServerCommand(char* cmd_name, void (*function)(void))
// locally (in the metamod DLL).
//
// The cvar handed to the engine is globally allocated in the metamod.dll;
-// the "name" and "string" fields are _strdup()'s of the plugin's strings.
+// the "name" and "string" fields are Q_strdup()'s of the plugin's strings.
// Note that, once this is done, the cvar_t allocated in the plugin is no
// longer used for _anything_. As long as everything sets/gets the cvar
// values via the engine functions, this will work fine. If the plugin
// code tries to _directly_ read/set the fields of its own cvar structures,
// it will fail to work properly.
-void meta_CVarRegister(cvar_t* pCvar)
+void meta_CVarRegister(cvar_t *pCvar)
{
- MPlugin* iplug = NULL;
- MRegCvar* icvar = NULL;
+ MPlugin *iplug = nullptr;
+ MRegCvar *icvar = nullptr;
META_DEBUG(4, ("called: meta_CVarRegister; name=%s", pCvar->name));
// try to find which plugin is registering this cvar
- if (!(iplug = g_plugins->find_memloc((void *)pCvar))) {
+ if (!(iplug = g_plugins->find_memloc((void *)pCvar)))
+ {
// if this isn't supported on this OS, don't log an error
if (meta_errno != ME_OSNOTSUP)
// Note: if cvar_t was malloc'd by the plugin, we can't
// determine the calling plugin. Thus, this becomes a Debug
// rather than Error message.
- META_DEBUG(1, ("Failed to find memloc for regcvar '%s'",
- pCvar->name));
+ META_DEBUG(1, ("Failed to find memloc for regcvar '%s'", pCvar->name));
}
// See if this cvar was previously registered, ie a "reloaded" plugin.
icvar = g_regCvars->find(pCvar->name);
- if (!icvar) {
+ if (!icvar)
+ {
// If not found, add.
icvar = g_regCvars->add(pCvar->name);
- if (!icvar) {
+ if (!icvar)
+ {
// error details logged in add()
return;
}
+
// Reset to given value
icvar->set(pCvar);
CVAR_REGISTER(icvar->data);
}
+
// Note: if not a new cvar, then we don't set the values, and just keep
// the pre-existing value.
-
icvar->status = RG_VALID;
+
// Store which plugin this is for, if we know. Use '0' for unknown
// plugin, as plugin index starts at 1.
if (iplug)
@@ -214,7 +179,6 @@ void meta_CVarRegister(cvar_t* pCvar)
icvar->plugid = 0;
}
-
// Replacement for engine routine RegUserMsg; called by plugins. Rather
// than handing the engine the plugin's string (which is allocated in the
// plugin DLL), this hands the engine a string allocated from the stack.
@@ -228,20 +192,15 @@ void meta_CVarRegister(cvar_t* pCvar)
// commands and cvars). This merely provides differently located storage
// for the string.
-int meta_RegUserMsg(const char* pszName, int iSize)
+int meta_RegUserMsg(const char *pszName, int iSize)
{
- char* cp;
-
- cp = _strdup(pszName);
- return (REG_USER_MSG(cp, iSize));
+ char *cp = Q_strdup(pszName);
+ return REG_USER_MSG(cp, iSize);
}
// Intercept and record queries
-void meta_QueryClientCvarValue(const edict_t* player, const char* cvarName)
+void meta_QueryClientCvarValue(const edict_t *player, const char *cvarName)
{
g_Players.set_player_cvar_query(player, cvarName);
-
(*g_engfuncs.pfnQueryClientCvarValue)(player, cvarName);
}
-
-
diff --git a/metamod/src/reg_support.h b/metamod/src/reg_support.h
index 0c50f38..212da9e 100644
--- a/metamod/src/reg_support.h
+++ b/metamod/src/reg_support.h
@@ -1,48 +1,7 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// reg_support.h - functions for "registered" cmd/cvar/msg support
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef REG_SUPPORT_H
-#define REG_SUPPORT_H
-
-#include "mreg.h" // REG_CMD_FN, etc
-
-void meta_command_handler(void);
+void meta_command_handler();
void meta_AddServerCommand(char *cmd_name, REG_CMD_FN function);
void meta_CVarRegister(cvar_t *pCvar);
int meta_RegUserMsg(const char *pszName, int iSize);
void meta_QueryClientCvarValue(const edict_t *player, const char *cvarName);
-
-#endif /* REG_SUPPORT_H */
diff --git a/metamod/src/sdk_util.cpp b/metamod/src/sdk_util.cpp
index 6eec14e..88865fd 100644
--- a/metamod/src/sdk_util.cpp
+++ b/metamod/src/sdk_util.cpp
@@ -1,61 +1,26 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// sdk_util.cpp - utility routines from HL SDK util.cpp
-
-// Selected portions of dlls/util.cpp from SDK 2.1.
-// Functions copied from there as needed...
-// And modified to avoid buffer overflows (argh).
-// Also modified to remove dependency on CBaseEntity class.
-
-/***
-*
-* Copyright (c) 1999, 2000 Valve LLC. All rights reserved.
-*
-* This product contains software technology licensed from Id
-* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
-* All Rights Reserved.
-*
-* Use, distribution, and modification of this source code and/or resulting
-* object code is restricted to non-commercial enhancements to products from
-* Valve LLC. All other use, distribution, or modification is prohibited
-* without written permission from Valve LLC.
-*
-****/
-/*
-
-===== util.cpp ========================================================
-
- Utility code. Really not optional after all.
-
-*/
-
#include "precompiled.h"
-char* UTIL_VarArgs(char *format, ...)
+char *UTIL_VarArgs(char *format, ...)
{
- va_list argptr;
- static char string[1024];
+ va_list argptr;
+ static char string[1024];
va_start(argptr, format);
- vsnprintf(string, sizeof(string), format, argptr);
+ Q_vsnprintf(string, sizeof(string), format, argptr);
va_end(argptr);
return string;
}
-
-//=========================================================
// UTIL_LogPrintf - Prints a logged message to console.
// Preceded by LOG: ( timestamp ) < message >
-//=========================================================
void UTIL_LogPrintf(char *fmt, ...)
{
- va_list argptr;
- static char string[1024];
+ va_list argptr;
+ static char string[1024];
va_start(argptr, fmt);
- vsnprintf(string, sizeof(string), fmt, argptr);
+ Q_vsnprintf(string, sizeof(string), fmt, argptr);
va_end(argptr);
// Print to server console
diff --git a/metamod/src/sdk_util.h b/metamod/src/sdk_util.h
index b700bcf..18239ab 100644
--- a/metamod/src/sdk_util.h
+++ b/metamod/src/sdk_util.h
@@ -1,59 +1,14 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// sdk_util.h - wrapper & extension of util.h from HL SDK
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-// Wrap util.h from SDK with ifndef/endif, to avoid problems from multiple
-// inclusions. Dunno why Valve didn't do that in util.h themselves..
-
-#ifndef SDK_UTIL_H
-#define SDK_UTIL_H
+#pragma once
// We're not including the DBG_EntOfVars and DBG_AssertFunction routines
// mentioned in the SDK util.h, so we're going to unset DEBUG here so that
// we don't get "unresolved symbol" errors.
#ifdef DEBUG
#undef DEBUG
-#endif /* DEBUG */
+#endif
// Inlcude local enginecallbacks wrapper *first* so that the g_engfuncs
// type is correct and the header protection is already
// defined.
#include "enginecallbacks.h"
-
#include
-
-
-
-#endif /* SDK_UTIL_H */
diff --git a/metamod/src/studioapi.cpp b/metamod/src/studioapi.cpp
index 42f169f..b33f4f3 100644
--- a/metamod/src/studioapi.cpp
+++ b/metamod/src/studioapi.cpp
@@ -1,39 +1,3 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// studio.cpp - player model blending interfaces
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
// Another GET-API routine, another interface version.
@@ -56,8 +20,8 @@ C_DLLEXPORT int Server_GetBlendingInterface(int version,
float (*rotationmatrix)[3][4],
float (*bonetransform)[MAXSTUDIOBONES][3][4])
{
- static GETBLENDAPI_FN getblend=NULL;
- static int missing=0;
+ static GETBLENDAPI_FN getblend = NULL;
+ static int missing = 0;
// Note that we're not checking if
// (version==SV_BLENDING_INTERFACE_VERSION) because at this point, we
@@ -72,21 +36,24 @@ C_DLLEXPORT int Server_GetBlendingInterface(int version,
// mismatch?", but this will only show in "developer" (-dev) mode.
META_DEBUG(6, ("called: Server_GetBlendingInterface; version=%d", version));
- if(missing) {
+ if (missing)
+ {
META_DEBUG(6, ("Skipping Server_GetBlendingInterface; was previously found missing"));
- return(0);
+ return 0;
}
- if(!getblend) {
+ if (!getblend)
+ {
META_DEBUG(6, ("Looking up Server_GetBlendingInterface"));
getblend = (GETBLENDAPI_FN) DLSYM(GameDLL.handle,
"Server_GetBlendingInterface");
}
- if(!getblend) {
+ if (!getblend)
+ {
META_DEBUG(6, ("Couldn't find Server_GetBlendingInterface in game DLL '%s': %s", GameDLL.name, DLERROR()));
- missing=1;
- return(0);
+ missing = 1;
+ return 0;
}
+
META_DEBUG(6, ("Calling Server_GetBlendingInterface"));
- return((getblend)(version, ppinterface, pstudio, rotationmatrix,
- bonetransform));
+ return (getblend)(version, ppinterface, pstudio, rotationmatrix, bonetransform);
}
diff --git a/metamod/src/studioapi.h b/metamod/src/studioapi.h
index eded726..486881d 100644
--- a/metamod/src/studioapi.h
+++ b/metamod/src/studioapi.h
@@ -1,47 +1,10 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// studio.cpp - player model blending interfaces
+#include
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef STUDIOAPI_H
-#define STUDIOAPI_H
-
-#include // MAXSTUDIOBONES
-
-// Typedef for Server_GetBlendingInterface() from Eric Smith on the hlcoders
+// Typedef for Server_GetBlendingInterface() from Eric Smith on the hlcoders
// mailing list.
-typedef int (*GETBLENDAPI_FN) (int version,
+typedef int (*GETBLENDAPI_FN)(int version,
struct sv_blending_interface_s **ppinterface,
struct engine_studio_api_s *pstudio,
float (*rotationmatrix)[3][4],
@@ -52,5 +15,3 @@ extern int mm_Server_GetBlendingInterface(int version,
struct engine_studio_api_s *pstudio,
float (*rotationmatrix)[3][4],
float (*bonetransform)[MAXSTUDIOBONES][3][4]);
-
-#endif /* STUDIOAPI_H */
diff --git a/metamod/src/support_meta.cpp b/metamod/src/support_meta.cpp
index a7a3255..f0ec827 100644
--- a/metamod/src/support_meta.cpp
+++ b/metamod/src/support_meta.cpp
@@ -1,47 +1,12 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// support_meta.cpp - generic support routines
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
#include "precompiled.h"
META_ERRNO meta_errno;
-void do_exit(int exitval)
+void __declspec(noreturn) do_exit(int exitval)
{
- sleep(3);
- exit(exitval);
+ //TerminateProcess(GetCurrentProcess(), 1);
+ *((int *)NULL) = 0;
+ while (true);
}
// Checks for a non-empty file, relative to the gamedir if necessary.
@@ -58,40 +23,44 @@ int valid_gamedir_file(const char* path)
int ret, reg, size;
if (!path)
- return (FALSE);
+ return FALSE;
- if (!strcmp(path, "/dev/null"))
- return (TRUE);
+ if (!Q_strcmp(path, "/dev/null"))
+ return TRUE;
- if (is_absolute_path(path)) {
- strncpy(buf, path, sizeof(buf));
+ if (is_absolute_path(path))
+ {
+ Q_strncpy(buf, path, sizeof(buf));
buf[sizeof buf - 1] = '\0';
}
else
snprintf(buf, sizeof(buf), "%s/%s", GameDLL.gamedir, path);
ret = stat(buf, &st);
- if (ret != 0) {
+ if (ret != 0)
+ {
META_DEBUG(5, ("Unable to stat '%s': %s", buf, strerror(errno)));
- return (FALSE);
+ return FALSE;
}
reg = S_ISREG(st.st_mode);
- if (!reg) {
+ if (!reg)
+ {
META_DEBUG(5, ("Not a regular file: %s", buf));
- return (FALSE);
+ return FALSE;
}
size = st.st_size;
- if (!size) {
+ if (!size)
+ {
META_DEBUG(5, ("Empty file: %s", buf));
- return (FALSE);
+ return FALSE;
}
if (ret == 0 && reg && size)
- return (TRUE);
+ return TRUE;
else
- return (FALSE);
+ return FALSE;
}
// Turns path into a full path:
@@ -99,26 +68,29 @@ int valid_gamedir_file(const char* path)
// - calls realpath() to collapse ".." and such
// - calls normalize_pathname() to fix backslashes, etc
//
-// Much like realpath, buffer pointed to by fullpath is assumed to be
+// Much like realpath, buffer pointed to by fullpath is assumed to be
// able to store a string of PATH_MAX length.
char* full_gamedir_path(const char* path, char* fullpath)
{
char buf[PATH_MAX ];
// Build pathname from filename, plus gamedir if relative path.
- if (is_absolute_path(path)) {
- strncpy(buf, path, sizeof buf - 1);
+ if (is_absolute_path(path))
+ {
+ Q_strncpy(buf, path, sizeof buf - 1);
buf[sizeof buf - 1] = '\0';
}
- else
- snprintf(buf, sizeof(buf), "%s/%s", GameDLL.gamedir, path);
+ else snprintf(buf, sizeof(buf), "%s/%s", GameDLL.gamedir, path);
+
// Remove relative path components, if possible.
- if (!realpath(buf, fullpath)) {
+ if (!realpath(buf, fullpath))
+ {
META_DEBUG(4, ("Unable to get realpath for '%s': %s", buf, str_os_error()));
- strncpy(fullpath, path, PATH_MAX - 1);
- fullpath[PATH_MAX - 1] = '\0';
+ Q_strncpy(fullpath, path, sizeof(fullpath) - 1);
+ fullpath[sizeof(fullpath) - 1] = '\0';
}
+
// Replace backslashes, etc.
normalize_pathname(fullpath);
- return (fullpath);
+ return fullpath;
}
diff --git a/metamod/src/support_meta.h b/metamod/src/support_meta.h
index 25f264a..3a675a7 100644
--- a/metamod/src/support_meta.h
+++ b/metamod/src/support_meta.h
@@ -1,120 +1,12 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
+#pragma once
-// support_meta.h - generic support macros
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef SUPPORT_META_H
-#define SUPPORT_META_H
-
-#include // strcpy(), strncat()
-#include // stat
-#include // stat
+#include // stat
+#include // stat
#include "osdep.h" // _stricmp, S_ISREG,
-void do_exit(int exitval) ATTRIBUTE(__noreturn__);
+void __declspec(noreturn) do_exit(int exitval);
-// Unlike snprintf(), strncpy() doesn't necessarily null-terminate the
-// target. It appears the former function reasonably considers the given
-// size to be "max size of target string" (including the null-terminator),
-// whereas strncpy() strangely considers the given size to be "total number
-// of bytes to copy". Note strncpy() _always_ writes n bytes, whereas
-// snprintf() writes a _max_ of n bytes (incl the NULL). If strncpy()
-// needs to write extra bytes to reach n, it uses NULLs, so the target
-// _can_ be null-terminated, but only if the source string would have fit
-// anyway - in which case why not just use strcpy() instead?
-//
-// Thus, it appears strncpy() is not only unsafe, it's also inefficient,
-// and seemingly no better than plain strcpy() anyway.
-//
-// With this logic, strncpy() doesn't appear to be much of a "str" function
-// at all, IMHO.
-//
-// Strncat works better, although it considers the given size to be "number
-// of bytes to append", and doesn't include the null-terminator in that
-// count. Thus, we can use it for what we want to do, by setting the
-// target to zero-length (NULL in first byte), and copying n-1 bytes
-// (leaving room for the null-termiator).
-//
-// Why does it have to be soo haaard...
-
-// Also note, some kind of wrapper is necessary to group the two
-// statements into one, for use in situations like non-braced else
-// statements.
-
-// Technique 1: use "do..while":
-#if 0
-#define STRNCPY(dst, src, size) \
- do { strcpy(dst, "\0"); strncat(dst, src, size-1); } while(0)
-#endif
-
-// Technique 2: use parens and commas:
-#if 0
-#define STRNCPY(dst, src, size) \
- (strcpy(dst, "\0"), strncat(dst, src, size-1))
-#endif
-
-inline int strnmatch(const char *s1, const char *s2, size_t n) {
- if(!s1 || !s2)
- return(0);
- else
- return(!strncmp(s1, s2, n));
-}
-inline int strcasematch(const char *s1, const char *s2) {
- if(!s1 || !s2)
- return(0);
- else
- return(!_stricmp(s1, s2));
-}
-inline int strncasematch(const char *s1, const char *s2, size_t n) {
- if(!s1 || !s2)
- return(0);
- else
- return(!_strnicmp(s1, s2, n));
-}
-
-inline int old_valid_file(char *path) {
- char *cp;
- int len, ret;
- cp = (char *) LOAD_FILE_FOR_ME(path, &len);
- if(cp && len)
- ret=1;
- else
- ret=0;
- FREE_FILE(cp);
- return(ret);
-}
int valid_gamedir_file(const char *path);
char *full_gamedir_path(const char *path, char *fullpath);
@@ -124,12 +16,8 @@ char *full_gamedir_path(const char *path, char *fullpath);
// specify strings used for all the debugging/log messages.
#define STRINGIZE(name, len) #name+len
-
// Max description length for plugins.ini and other places.
#define MAX_DESC_LEN 256
-
// For various character string buffers.
#define MAX_STRBUF_LEN 1024
-
-#endif /* SUPPORT_META_H */
diff --git a/metamod/src/types_meta.h b/metamod/src/types_meta.h
index 98b5271..b74bf20 100644
--- a/metamod/src/types_meta.h
+++ b/metamod/src/types_meta.h
@@ -1,82 +1,42 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// types_meta.h - common internal type, etc definitions
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef TYPES_META_H
-#define TYPES_META_H
+#pragma once
// Our own boolean type, for stricter type matching.
-typedef enum mBOOL {
- mFALSE = 0,
- mTRUE,
-} mBOOL;
+enum mBOOL { mFALSE = 0, mTRUE, };
// Like C's errno, for our various functions; describes causes of failure
// or mFALSE returns.
-typedef enum {
+enum META_ERRNO
+{
ME_NOERROR = 0,
- ME_FORMAT, // invalid format
- ME_COMMENT, // ignored comment
- ME_BLANK, // ignored blank (empty) line
- ME_ALREADY, // request had already been done
- ME_DELAYED, // request is delayed
+ ME_FORMAT, // invalid format
+ ME_COMMENT, // ignored comment
+ ME_BLANK, // ignored blank (empty) line
+ ME_ALREADY, // request had already been done
+ ME_DELAYED, // request is delayed
ME_NOTALLOWED, // request not allowed
- ME_SKIPPED, // request is being skipped for whatever reason
- ME_BADREQ, // invalid request for this
+ ME_SKIPPED, // request is being skipped for whatever reason
+ ME_BADREQ, // invalid request for this
ME_ARGUMENT, // invalid arguments
ME_NULLRESULT, // resulting data was empty or null
ME_MAXREACHED, // reached max/limit
- ME_NOTUNIQ, // not unique (ambigious match)
+ ME_NOTUNIQ, // not unique (ambigious match)
ME_NOTFOUND, // in find operation, match not found
- ME_NOFILE, // file empty or missing
- ME_NOMEM, // malloc failed
+ ME_NOFILE, // file empty or missing
+ ME_NOMEM, // malloc failed
ME_BADMEMPTR, // invalid memory address
ME_OSNOTSUP, // OS doesn't support this operation
- ME_DLOPEN, // failed to open shared lib/dll
+ ME_DLOPEN, // failed to open shared lib/dll
ME_DLMISSING, // symbol missing in lib/dll
- ME_DLERROR, // some other error encountered calling functions from dll
+ ME_DLERROR, // some other error encountered calling functions from dll
ME_IFVERSION, // incompatible interface version
ME_UNLOAD_UNLOADER, // tried to unload unloader
ME_UNLOAD_SELF, // tried to unload self
-} META_ERRNO;
+};
+
extern META_ERRNO meta_errno;
#define RETURN_ERRNO(retval, errval) \
- do { meta_errno=errval; return(retval); } while(0)
+ do { meta_errno = errval; return retval; } while (0)
#define RETURN_LOGERR_ERRNO(errargs, retval, errval) \
- do { META_ERROR errargs ; meta_errno=errval; return(retval); } while(0)
-
-#endif /* TYPES_META_H */
+ do { META_ERROR errargs; meta_errno = errval; return retval; } while (0)
diff --git a/metamod/src/utils.cpp b/metamod/src/utils.cpp
index bef460b..d18116f 100644
--- a/metamod/src/utils.cpp
+++ b/metamod/src/utils.cpp
@@ -2,20 +2,20 @@
bool is_yes(const char* str)
{
- return !strcmp(str, "true") || !strcmp(str, "yes") || !strcmp(str, "1");
+ return !Q_strcmp(str, "true") || !Q_strcmp(str, "yes") || !Q_strcmp(str, "1");
}
bool is_no(const char* str)
{
- return !strcmp(str, "false") || !strcmp(str, "no") || !strcmp(str, "0");
+ return !Q_strcmp(str, "false") || !Q_strcmp(str, "no") || !Q_strcmp(str, "0");
}
char* ENTITY_KEYVALUE(edict_t* entity, char* key)
{
- return (INFOKEY_VALUE(GET_INFOKEYBUFFER(entity), key));
+ return INFOKEY_VALUE(GET_INFOKEYBUFFER(entity), key);
}
const char* LOCALINFO(char* key)
{
- return (ENTITY_KEYVALUE(NULL, key));
+ return ENTITY_KEYVALUE(NULL, key);
}
diff --git a/metamod/src/vdate.cpp b/metamod/src/vdate.cpp
deleted file mode 100644
index 078fa45..0000000
--- a/metamod/src/vdate.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// vdate.cpp - compile-time version date
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#include "precompiled.h"
-
-// Grab date/time of compile. The Makefile is set up to recompile this
-// module before each link, so that this will always indicate the time the
-// library was compiled and linked.
-
-// This is in a separate file from vers_*, so it can be generically used by
-// multiple projects.
-
-char const *COMPILE_TIME=__DATE__ ", " __TIME__;
-
-#ifndef COMPILE_TZ
-# define COMPILE_TZ ""
-#endif
-
-char const *COMPILE_TZONE = COMPILE_TZ;
-
-// Include a string for /usr/bin/ident.
-
-char const *vstring="\n$Pg: " VNAME " -- " VVERSION " | " __DATE__ " - " __TIME__ " $\n";
diff --git a/metamod/src/vdate.h b/metamod/src/vdate.h
deleted file mode 100644
index b9f6e9f..0000000
--- a/metamod/src/vdate.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// vdate.h - compile-time version date
-
-/*
- * Copyright (c) 2001-2003 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef VDATE_H
-#define VDATE_H
-
-extern char const *COMPILE_TIME;
-
-extern char const *COMPILE_TZONE;
-
-#endif /* VDATE_H */
diff --git a/metamod/src/vers_meta.h b/metamod/src/vers_meta.h
deleted file mode 100644
index d5baf14..0000000
--- a/metamod/src/vers_meta.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// vi: set ts=4 sw=4 :
-// vim: set tw=75 :
-
-// vers_meta.h - version info, intended to be common among DLLs distributed
-// with metamod.
-
-/*
- * Copyright (c) 2001-2013 Will Day
- *
- * This file is part of Metamod.
- *
- * Metamod is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * Metamod is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Metamod; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * In addition, as a special exception, the author gives permission to
- * link the code of this program with the Half-Life Game g_engine ("HL
- * g_engine") and Modified Game Libraries ("MODs") developed by Valve,
- * L.L.C ("Valve"). You must obey the GNU General Public License in all
- * respects for all of the code used other than the HL g_engine and MODs
- * from Valve. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If
- * you do not wish to do so, delete this exception statement from your
- * version.
- *
- */
-
-#ifndef VERS_META_H
-#define VERS_META_H
-
-#ifndef OPT_TYPE
-# if defined(_MSC_VER) && defined(_DEBUG)
-# define OPT_TYPE "msc debugging"
-# elif defined(_MSC_VER) && defined(NDEBUG)
-# define OPT_TYPE "msc optimized"
-# else
-# define OPT_TYPE "default"
-# endif /* _MSC_VER */
-#endif /* not OPT_TYPE */
-
-#define VDATE "2013-09-26"
-#define VVERSION "1.21.1-am"
-#define RC_VERS_DWORD 1,21,1,0 // Version Windows DLL Resources in res_meta.rc
-
-#endif /* VERS_META_H */