diff --git a/metamod/src/api_info.cpp b/metamod/src/api_info.cpp index 2fdee04..fdf5446 100644 --- a/metamod/src/api_info.cpp +++ b/metamod/src/api_info.cpp @@ -6,233 +6,235 @@ #define ENGAPI_ENTRY(name, loglevel) API_ENTRY(enginefuncs_t, name, loglevel) // trace flag, loglevel, name -dllapi_info_t g_dllapi_info = { - DLLAPI_ENTRY(GameInit, 1), // pfnGameInit - DLLAPI_ENTRY(Spawn, 2), // pfnSpawn - DLLAPI_ENTRY(Think, 2), // pfnThink - DLLAPI_ENTRY(Use, 2), // pfnUse - DLLAPI_ENTRY(Touch, 2), // pfnTouch - DLLAPI_ENTRY(Blocked, 2), // pfnBlocked - DLLAPI_ENTRY(KeyValue, 4), // pfnKeyValue - DLLAPI_ENTRY(Save, 4), // pfnSave - DLLAPI_ENTRY(Restore, 4), // pfnRestore - DLLAPI_ENTRY(SetAbsBox, 2), // pfnSetAbsBox - DLLAPI_ENTRY(SaveWriteFields, 4), // pfnSaveWriteFields - DLLAPI_ENTRY(SaveReadFields, 4), // pfnSaveReadFields - DLLAPI_ENTRY(SaveGlobalState, 4), // pfnSaveGlobalState +dllapi_info_t g_dllapi_info = +{ + DLLAPI_ENTRY(GameInit, 1), // pfnGameInit + DLLAPI_ENTRY(Spawn, 2), // pfnSpawn + DLLAPI_ENTRY(Think, 2), // pfnThink + DLLAPI_ENTRY(Use, 2), // pfnUse + DLLAPI_ENTRY(Touch, 2), // pfnTouch + DLLAPI_ENTRY(Blocked, 2), // pfnBlocked + DLLAPI_ENTRY(KeyValue, 4), // pfnKeyValue + DLLAPI_ENTRY(Save, 4), // pfnSave + DLLAPI_ENTRY(Restore, 4), // pfnRestore + DLLAPI_ENTRY(SetAbsBox, 2), // pfnSetAbsBox + DLLAPI_ENTRY(SaveWriteFields, 4), // pfnSaveWriteFields + DLLAPI_ENTRY(SaveReadFields, 4), // pfnSaveReadFields + DLLAPI_ENTRY(SaveGlobalState, 4), // pfnSaveGlobalState DLLAPI_ENTRY(RestoreGlobalState, 4), // pfnRestoreGlobalState - DLLAPI_ENTRY(ResetGlobalState, 4), // pfnResetGlobalState - DLLAPI_ENTRY(ClientConnect, 1), // pfnClientConnect - DLLAPI_ENTRY(ClientDisconnect, 1), // pfnClientDisconnect - DLLAPI_ENTRY(ClientKill, 2), // pfnClientKill - DLLAPI_ENTRY(ClientPutInServer, 1), // pfnClientPutInServer - DLLAPI_ENTRY(ClientCommand, 2), // pfnClientCommand - DLLAPI_ENTRY(ClientUserInfoChanged, 2), // pfnClientUserInfoChanged - DLLAPI_ENTRY(ServerActivate, 1), // pfnServerActivate - DLLAPI_ENTRY(ServerDeactivate, 1), // pfnServerDeactivate - DLLAPI_ENTRY(PlayerPreThink, 3), // pfnPlayerPreThink - DLLAPI_ENTRY(PlayerPostThink, 3), // pfnPlayerPostThink - DLLAPI_ENTRY(StartFrame, 4), // pfnStartFrame - DLLAPI_ENTRY(ParmsNewLevel, 4), // pfnParmsNewLevel - DLLAPI_ENTRY(ParmsChangeLevel, 4), // pfnParmsChangeLevel + DLLAPI_ENTRY(ResetGlobalState, 4), // pfnResetGlobalState + DLLAPI_ENTRY(ClientConnect, 1), // pfnClientConnect + DLLAPI_ENTRY(ClientDisconnect, 1), // pfnClientDisconnect + DLLAPI_ENTRY(ClientKill, 2), // pfnClientKill + DLLAPI_ENTRY(ClientPutInServer, 1), // pfnClientPutInServer + DLLAPI_ENTRY(ClientCommand, 2), // pfnClientCommand + DLLAPI_ENTRY(ClientUserInfoChanged, 2), // pfnClientUserInfoChanged + DLLAPI_ENTRY(ServerActivate, 1), // pfnServerActivate + DLLAPI_ENTRY(ServerDeactivate, 1), // pfnServerDeactivate + DLLAPI_ENTRY(PlayerPreThink, 3), // pfnPlayerPreThink + DLLAPI_ENTRY(PlayerPostThink, 3), // pfnPlayerPostThink + DLLAPI_ENTRY(StartFrame, 4), // pfnStartFrame + DLLAPI_ENTRY(ParmsNewLevel, 4), // pfnParmsNewLevel + DLLAPI_ENTRY(ParmsChangeLevel, 4), // pfnParmsChangeLevel DLLAPI_ENTRY(GetGameDescription, 3), // pfnGetGameDescription - DLLAPI_ENTRY(PlayerCustomization, 4), // pfnPlayerCustomization - DLLAPI_ENTRY(SpectatorConnect, 3), // pfnSpectatorConnect - DLLAPI_ENTRY(SpectatorDisconnect, 3), // pfnSpectatorDisconnect - DLLAPI_ENTRY(SpectatorThink, 3), // pfnSpectatorThink - DLLAPI_ENTRY(Sys_Error, 4), // pfnSys_Error - DLLAPI_ENTRY(PM_Move, 3), // pfnPM_Move - DLLAPI_ENTRY(PM_Init, 1), // pfnPM_Init + DLLAPI_ENTRY(PlayerCustomization, 4), // pfnPlayerCustomization + DLLAPI_ENTRY(SpectatorConnect, 3), // pfnSpectatorConnect + DLLAPI_ENTRY(SpectatorDisconnect, 3), // pfnSpectatorDisconnect + DLLAPI_ENTRY(SpectatorThink, 3), // pfnSpectatorThink + DLLAPI_ENTRY(Sys_Error, 4), // pfnSys_Error + DLLAPI_ENTRY(PM_Move, 3), // pfnPM_Move + DLLAPI_ENTRY(PM_Init, 1), // pfnPM_Init DLLAPI_ENTRY(PM_FindTextureType, 3), // pfnPM_FindTextureType - DLLAPI_ENTRY(SetupVisibility, 3), // pfnSetupVisibility - DLLAPI_ENTRY(UpdateClientData, 3), // pfnUpdateClientData - DLLAPI_ENTRY(AddToFullPack, 3), // pfnAddToFullPack - DLLAPI_ENTRY(CreateBaseline, 4), // pfnCreateBaseline - DLLAPI_ENTRY(RegisterEncoders, 4), // pfnRegisterEncoders - DLLAPI_ENTRY(GetWeaponData, 3), // pfnGetWeaponData - DLLAPI_ENTRY(CmdStart, 3), // pfnCmdStart - DLLAPI_ENTRY(CmdEnd, 3), // pfnCmdEnd - DLLAPI_ENTRY(ConnectionlessPacket, 4), // pfnConnectionlessPacket - DLLAPI_ENTRY(GetHullBounds, 3), // pfnGetHullBounds + DLLAPI_ENTRY(SetupVisibility, 3), // pfnSetupVisibility + DLLAPI_ENTRY(UpdateClientData, 3), // pfnUpdateClientData + DLLAPI_ENTRY(AddToFullPack, 3), // pfnAddToFullPack + DLLAPI_ENTRY(CreateBaseline, 4), // pfnCreateBaseline + DLLAPI_ENTRY(RegisterEncoders, 4), // pfnRegisterEncoders + DLLAPI_ENTRY(GetWeaponData, 3), // pfnGetWeaponData + DLLAPI_ENTRY(CmdStart, 3), // pfnCmdStart + DLLAPI_ENTRY(CmdEnd, 3), // pfnCmdEnd + DLLAPI_ENTRY(ConnectionlessPacket, 4), // pfnConnectionlessPacket + DLLAPI_ENTRY(GetHullBounds, 3), // pfnGetHullBounds DLLAPI_ENTRY(CreateInstancedBaselines, 4), // pfnCreateInstancedBaselines - DLLAPI_ENTRY(InconsistentFile, 3), // pfnInconsistentFile - DLLAPI_ENTRY(AllowLagCompensation, 4), // pfnAllowLagCompensation + DLLAPI_ENTRY(InconsistentFile, 3), // pfnInconsistentFile + DLLAPI_ENTRY(AllowLagCompensation, 4), // pfnAllowLagCompensation { 0, "", 0 }, }; newapi_info_t g_newapi_info = { NEWAPI_ENTRY(OnFreeEntPrivateData, 3), // pfnOnFreeEntPrivateData - NEWAPI_ENTRY(GameShutdown, 3), // pfnGameShutdown - NEWAPI_ENTRY(ShouldCollide, 3), // pfnShouldCollide - NEWAPI_ENTRY(CvarValue, 2), // pfnCvarValue + NEWAPI_ENTRY(GameShutdown, 3), // pfnGameShutdown + NEWAPI_ENTRY(ShouldCollide, 3), // pfnShouldCollide + NEWAPI_ENTRY(CvarValue, 2), // pfnCvarValue NEWAPI_ENTRY(CvarValue2, 2), // pfnCvarValue2 { 0, "", 0 }, }; -engine_info_t g_engineapi_info = { - ENGAPI_ENTRY(PrecacheModel, 2), // pfnPrecacheModel - ENGAPI_ENTRY(PrecacheSound, 2), // pfnPrecacheSound - ENGAPI_ENTRY(SetModel, 2), // pfnSetModel - ENGAPI_ENTRY(ModelIndex, 2), // pfnModelIndex - ENGAPI_ENTRY(ModelFrames, 3), // pfnModelFrames - ENGAPI_ENTRY(SetSize, 2), // pfnSetSize - ENGAPI_ENTRY(ChangeLevel, 2), // pfnChangeLevel - ENGAPI_ENTRY(GetSpawnParms, 4), // pfnGetSpawnParms - ENGAPI_ENTRY(SaveSpawnParms, 4), // pfnSaveSpawnParms - ENGAPI_ENTRY(VecToYaw, 3), // pfnVecToYaw - ENGAPI_ENTRY(VecToAngles, 3), // pfnVecToAngles - ENGAPI_ENTRY(MoveToOrigin, 3), // pfnMoveToOrigin - ENGAPI_ENTRY(ChangeYaw, 3), // pfnChangeYaw - ENGAPI_ENTRY(ChangePitch, 3), // pfnChangePitch - ENGAPI_ENTRY(FindEntityByString, 2), // pfnFindEntityByString - ENGAPI_ENTRY(GetEntityIllum, 4), // pfnGetEntityIllum - ENGAPI_ENTRY(FindEntityInSphere, 2), // pfnFindEntityInSphere - ENGAPI_ENTRY(FindClientInPVS, 2), // pfnFindClientInPVS - ENGAPI_ENTRY(EntitiesInPVS, 2), // pfnEntitiesInPVS - ENGAPI_ENTRY(MakeVectors, 3), // pfnMakeVectors - ENGAPI_ENTRY(AngleVectors, 3), // pfnAngleVectors - ENGAPI_ENTRY(CreateEntity, 2), // pfnCreateEntity - ENGAPI_ENTRY(RemoveEntity, 2), // pfnRemoveEntity - ENGAPI_ENTRY(CreateNamedEntity, 2), // pfnCreateNamedEntity - ENGAPI_ENTRY(MakeStatic, 2), // pfnMakeStatic - ENGAPI_ENTRY(EntIsOnFloor, 2), // pfnEntIsOnFloor - ENGAPI_ENTRY(DropToFloor, 2), // pfnDropToFloor - ENGAPI_ENTRY(WalkMove, 2), // pfnWalkMove - ENGAPI_ENTRY(SetOrigin, 2), // pfnSetOrigin - ENGAPI_ENTRY(EmitSound, 2), // pfnEmitSound - ENGAPI_ENTRY(EmitAmbientSound, 2), // pfnEmitAmbientSound - ENGAPI_ENTRY(TraceLine, 2), // pfnTraceLine - ENGAPI_ENTRY(TraceToss, 2), // pfnTraceToss - ENGAPI_ENTRY(TraceMonsterHull, 2), // pfnTraceMonsterHull - ENGAPI_ENTRY(TraceHull, 2), // pfnTraceHull - ENGAPI_ENTRY(TraceModel, 2), // pfnTraceModel - ENGAPI_ENTRY(TraceTexture, 2), // pfnTraceTexture // CS: when moving - ENGAPI_ENTRY(TraceSphere, 2), // pfnTraceSphere - ENGAPI_ENTRY(GetAimVector, 2), // pfnGetAimVector - ENGAPI_ENTRY(ServerCommand, 3), // pfnServerCommand - ENGAPI_ENTRY(ServerExecute, 3), // pfnServerExecute - ENGAPI_ENTRY(ClientCommand, 3), // pfnClientCommand // d'oh, ClientCommand in dllapi too - ENGAPI_ENTRY(ParticleEffect, 4), // pfnParticleEffect - ENGAPI_ENTRY(LightStyle, 2), // pfnLightStyle - ENGAPI_ENTRY(DecalIndex, 2), // pfnDecalIndex - ENGAPI_ENTRY(PointContents, 2), // pfnPointContents // CS: when moving - ENGAPI_ENTRY(MessageBegin, 3), // pfnMessageBegin - ENGAPI_ENTRY(MessageEnd, 3), // pfnMessageEnd - ENGAPI_ENTRY(WriteByte, 3), // pfnWriteByte - ENGAPI_ENTRY(WriteChar, 3), // pfnWriteChar - ENGAPI_ENTRY(WriteShort, 3), // pfnWriteShort - ENGAPI_ENTRY(WriteLong, 3), // pfnWriteLong - ENGAPI_ENTRY(WriteAngle, 3), // pfnWriteAngle - ENGAPI_ENTRY(WriteCoord, 3), // pfnWriteCoord - ENGAPI_ENTRY(WriteString, 3), // pfnWriteString - ENGAPI_ENTRY(WriteEntity, 3), // pfnWriteEntity - ENGAPI_ENTRY(CVarRegister, 2), // pfnCVarRegister - ENGAPI_ENTRY(CVarGetFloat, 2), // pfnCVarGetFloat - ENGAPI_ENTRY(CVarGetString, 2), // pfnCVarGetString - ENGAPI_ENTRY(CVarSetFloat, 2), // pfnCVarSetFloat - ENGAPI_ENTRY(CVarSetString, 2), // pfnCVarSetString - ENGAPI_ENTRY(AlertMessage, 3), // pfnAlertMessage - ENGAPI_ENTRY(EngineFprintf, 3), // pfnEngineFprintf - ENGAPI_ENTRY(PvAllocEntPrivateData, 2), // pfnPvAllocEntPrivateData - ENGAPI_ENTRY(PvEntPrivateData, 2), // pfnPvEntPrivateData - ENGAPI_ENTRY(FreeEntPrivateData, 2), // pfnFreeEntPrivateData - ENGAPI_ENTRY(SzFromIndex, 3), // pfnSzFromIndex - ENGAPI_ENTRY(AllocString, 3), // pfnAllocString - ENGAPI_ENTRY(GetVarsOfEnt, 2), // pfnGetVarsOfEnt - ENGAPI_ENTRY(PEntityOfEntOffset, 3), // pfnPEntityOfEntOffset - ENGAPI_ENTRY(EntOffsetOfPEntity, 3), // pfnEntOffsetOfPEntity - ENGAPI_ENTRY(IndexOfEdict, 3), // pfnIndexOfEdict - ENGAPI_ENTRY(PEntityOfEntIndex, 3), // pfnPEntityOfEntIndex - ENGAPI_ENTRY(FindEntityByVars, 3), // pfnFindEntityByVars - ENGAPI_ENTRY(GetModelPtr, 3), // pfnGetModelPtr - ENGAPI_ENTRY(RegUserMsg, 3), // pfnRegUserMsg - ENGAPI_ENTRY(AnimationAutomove, 2), // pfnAnimationAutomove - ENGAPI_ENTRY(GetBonePosition, 2), // pfnGetBonePosition - ENGAPI_ENTRY(FunctionFromName, 4), // pfnFunctionFromName - ENGAPI_ENTRY(NameForFunction, 4), // pfnNameForFunction - ENGAPI_ENTRY(ClientPrintf, 3), // pfnClientPrintf - ENGAPI_ENTRY(ServerPrint, 3), // pfnServerPrint - ENGAPI_ENTRY(Cmd_Args, 3), // pfnCmd_Args - ENGAPI_ENTRY(Cmd_Argv, 3), // pfnCmd_Argv - ENGAPI_ENTRY(Cmd_Argc, 3), // pfnCmd_Argc - ENGAPI_ENTRY(GetAttachment, 2), // pfnGetAttachment - ENGAPI_ENTRY(CRC32_Init, 4), // pfnCRC32_Init - ENGAPI_ENTRY(CRC32_ProcessBuffer, 4), // pfnCRC32_ProcessBuffer - ENGAPI_ENTRY(CRC32_ProcessByte, 4), // pfnCRC32_ProcessByte - ENGAPI_ENTRY(CRC32_Final, 4), // pfnCRC32_Final - ENGAPI_ENTRY(RandomLong, 3), // pfnRandomLong - ENGAPI_ENTRY(RandomFloat, 3), // pfnRandomFloat // CS: when firing - ENGAPI_ENTRY(SetView, 2), // pfnSetView - ENGAPI_ENTRY(Time, 2), // pfnTime - ENGAPI_ENTRY(CrosshairAngle, 2), // pfnCrosshairAngle - ENGAPI_ENTRY(LoadFileForMe, 4), // pfnLoadFileForMe - ENGAPI_ENTRY(FreeFile, 4), // pfnFreeFile - ENGAPI_ENTRY(EndSection, 4), // pfnEndSection - ENGAPI_ENTRY(CompareFileTime, 4), // pfnCompareFileTime - ENGAPI_ENTRY(GetGameDir, 3), // pfnGetGameDir - ENGAPI_ENTRY(Cvar_RegisterVariable, 2), // pfnCvar_RegisterVariable - ENGAPI_ENTRY(FadeClientVolume, 2), // pfnFadeClientVolume - ENGAPI_ENTRY(SetClientMaxspeed, 3), // pfnSetClientMaxspeed - ENGAPI_ENTRY(CreateFakeClient, 2), // pfnCreateFakeClient - ENGAPI_ENTRY(RunPlayerMove, 3), // pfnRunPlayerMove - ENGAPI_ENTRY(NumberOfEntities, 2), // pfnNumberOfEntities - ENGAPI_ENTRY(GetInfoKeyBuffer, 2), // pfnGetInfoKeyBuffer - ENGAPI_ENTRY(InfoKeyValue, 2), // pfnInfoKeyValue - ENGAPI_ENTRY(SetKeyValue, 2), // pfnSetKeyValue - ENGAPI_ENTRY(SetClientKeyValue, 2), // pfnSetClientKeyValue - ENGAPI_ENTRY(IsMapValid, 2), // pfnIsMapValid - ENGAPI_ENTRY(StaticDecal, 2), // pfnStaticDecal - ENGAPI_ENTRY(PrecacheGeneric, 2), // pfnPrecacheGeneric - ENGAPI_ENTRY(GetPlayerUserId, 2), // pfnGetPlayerUserId - ENGAPI_ENTRY(BuildSoundMsg, 2), // pfnBuildSoundMsg - ENGAPI_ENTRY(IsDedicatedServer, 2), // pfnIsDedicatedServer - ENGAPI_ENTRY(CVarGetPointer, 3), // pfnCVarGetPointer - ENGAPI_ENTRY(GetPlayerWONId, 4), // pfnGetPlayerWONId - ENGAPI_ENTRY(Info_RemoveKey, 2), // pfnInfo_RemoveKey - ENGAPI_ENTRY(GetPhysicsKeyValue, 2), // pfnGetPhysicsKeyValue - ENGAPI_ENTRY(SetPhysicsKeyValue, 2), // pfnSetPhysicsKeyValue - ENGAPI_ENTRY(GetPhysicsInfoString, 2), // pfnGetPhysicsInfoString - ENGAPI_ENTRY(PrecacheEvent, 2), // pfnPrecacheEvent - ENGAPI_ENTRY(PlaybackEvent, 2), // pfnPlaybackEvent - ENGAPI_ENTRY(SetFatPVS, 2), // pfnSetFatPVS - ENGAPI_ENTRY(SetFatPAS, 2), // pfnSetFatPAS - ENGAPI_ENTRY(CheckVisibility, 2), // pfnCheckVisibility - ENGAPI_ENTRY(DeltaSetField, 3), // pfnDeltaSetField - ENGAPI_ENTRY(DeltaUnsetField, 3), // pfnDeltaUnsetField - ENGAPI_ENTRY(DeltaAddEncoder, 3), // pfnDeltaAddEncoder - ENGAPI_ENTRY(GetCurrentPlayer, 2), // pfnGetCurrentPlayer - ENGAPI_ENTRY(CanSkipPlayer, 2), // pfnCanSkipPlayer - ENGAPI_ENTRY(DeltaFindField, 3), // pfnDeltaFindField - ENGAPI_ENTRY(DeltaSetFieldByIndex, 3), // pfnDeltaSetFieldByIndex - ENGAPI_ENTRY(DeltaUnsetFieldByIndex, 3), // pfnDeltaUnsetFieldByIndex - ENGAPI_ENTRY(SetGroupMask, 2), // pfnSetGroupMask - ENGAPI_ENTRY(CreateInstancedBaseline, 3), // pfnCreateInstancedBaseline // d'oh, CreateInstancedBaseline in dllapi too - ENGAPI_ENTRY(Cvar_DirectSet, 2), // pfnCvar_DirectSet - ENGAPI_ENTRY(ForceUnmodified, 2), // pfnForceUnmodified - ENGAPI_ENTRY(GetPlayerStats, 2), // pfnGetPlayerStats - ENGAPI_ENTRY(AddServerCommand, 2), // pfnAddServerCommand +engine_info_t g_engineapi_info = +{ + ENGAPI_ENTRY(PrecacheModel, 2), // pfnPrecacheModel + ENGAPI_ENTRY(PrecacheSound, 2), // pfnPrecacheSound + ENGAPI_ENTRY(SetModel, 2), // pfnSetModel + ENGAPI_ENTRY(ModelIndex, 2), // pfnModelIndex + ENGAPI_ENTRY(ModelFrames, 3), // pfnModelFrames + ENGAPI_ENTRY(SetSize, 2), // pfnSetSize + ENGAPI_ENTRY(ChangeLevel, 2), // pfnChangeLevel + ENGAPI_ENTRY(GetSpawnParms, 4), // pfnGetSpawnParms + ENGAPI_ENTRY(SaveSpawnParms, 4), // pfnSaveSpawnParms + ENGAPI_ENTRY(VecToYaw, 3), // pfnVecToYaw + ENGAPI_ENTRY(VecToAngles, 3), // pfnVecToAngles + ENGAPI_ENTRY(MoveToOrigin, 3), // pfnMoveToOrigin + ENGAPI_ENTRY(ChangeYaw, 3), // pfnChangeYaw + ENGAPI_ENTRY(ChangePitch, 3), // pfnChangePitch + ENGAPI_ENTRY(FindEntityByString, 2), // pfnFindEntityByString + ENGAPI_ENTRY(GetEntityIllum, 4), // pfnGetEntityIllum + ENGAPI_ENTRY(FindEntityInSphere, 2), // pfnFindEntityInSphere + ENGAPI_ENTRY(FindClientInPVS, 2), // pfnFindClientInPVS + ENGAPI_ENTRY(EntitiesInPVS, 2), // pfnEntitiesInPVS + ENGAPI_ENTRY(MakeVectors, 3), // pfnMakeVectors + ENGAPI_ENTRY(AngleVectors, 3), // pfnAngleVectors + ENGAPI_ENTRY(CreateEntity, 2), // pfnCreateEntity + ENGAPI_ENTRY(RemoveEntity, 2), // pfnRemoveEntity + ENGAPI_ENTRY(CreateNamedEntity, 2), // pfnCreateNamedEntity + ENGAPI_ENTRY(MakeStatic, 2), // pfnMakeStatic + ENGAPI_ENTRY(EntIsOnFloor, 2), // pfnEntIsOnFloor + ENGAPI_ENTRY(DropToFloor, 2), // pfnDropToFloor + ENGAPI_ENTRY(WalkMove, 2), // pfnWalkMove + ENGAPI_ENTRY(SetOrigin, 2), // pfnSetOrigin + ENGAPI_ENTRY(EmitSound, 2), // pfnEmitSound + ENGAPI_ENTRY(EmitAmbientSound, 2), // pfnEmitAmbientSound + ENGAPI_ENTRY(TraceLine, 2), // pfnTraceLine + ENGAPI_ENTRY(TraceToss, 2), // pfnTraceToss + ENGAPI_ENTRY(TraceMonsterHull, 2), // pfnTraceMonsterHull + ENGAPI_ENTRY(TraceHull, 2), // pfnTraceHull + ENGAPI_ENTRY(TraceModel, 2), // pfnTraceModel + ENGAPI_ENTRY(TraceTexture, 2), // pfnTraceTexture + ENGAPI_ENTRY(TraceSphere, 2), // pfnTraceSphere + ENGAPI_ENTRY(GetAimVector, 2), // pfnGetAimVector + ENGAPI_ENTRY(ServerCommand, 3), // pfnServerCommand + ENGAPI_ENTRY(ServerExecute, 3), // pfnServerExecute + ENGAPI_ENTRY(ClientCommand, 3), // pfnClientCommand + ENGAPI_ENTRY(ParticleEffect, 4), // pfnParticleEffect + ENGAPI_ENTRY(LightStyle, 2), // pfnLightStyle + ENGAPI_ENTRY(DecalIndex, 2), // pfnDecalIndex + ENGAPI_ENTRY(PointContents, 2), // pfnPointContents + ENGAPI_ENTRY(MessageBegin, 3), // pfnMessageBegin + ENGAPI_ENTRY(MessageEnd, 3), // pfnMessageEnd + ENGAPI_ENTRY(WriteByte, 3), // pfnWriteByte + ENGAPI_ENTRY(WriteChar, 3), // pfnWriteChar + ENGAPI_ENTRY(WriteShort, 3), // pfnWriteShort + ENGAPI_ENTRY(WriteLong, 3), // pfnWriteLong + ENGAPI_ENTRY(WriteAngle, 3), // pfnWriteAngle + ENGAPI_ENTRY(WriteCoord, 3), // pfnWriteCoord + ENGAPI_ENTRY(WriteString, 3), // pfnWriteString + ENGAPI_ENTRY(WriteEntity, 3), // pfnWriteEntity + ENGAPI_ENTRY(CVarRegister, 2), // pfnCVarRegister + ENGAPI_ENTRY(CVarGetFloat, 2), // pfnCVarGetFloat + ENGAPI_ENTRY(CVarGetString, 2), // pfnCVarGetString + ENGAPI_ENTRY(CVarSetFloat, 2), // pfnCVarSetFloat + ENGAPI_ENTRY(CVarSetString, 2), // pfnCVarSetString + ENGAPI_ENTRY(AlertMessage, 3), // pfnAlertMessage + ENGAPI_ENTRY(EngineFprintf, 3), // pfnEngineFprintf + ENGAPI_ENTRY(PvAllocEntPrivateData, 2), // pfnPvAllocEntPrivateData + ENGAPI_ENTRY(PvEntPrivateData, 2), // pfnPvEntPrivateData + ENGAPI_ENTRY(FreeEntPrivateData, 2), // pfnFreeEntPrivateData + ENGAPI_ENTRY(SzFromIndex, 3), // pfnSzFromIndex + ENGAPI_ENTRY(AllocString, 3), // pfnAllocString + ENGAPI_ENTRY(GetVarsOfEnt, 2), // pfnGetVarsOfEnt + ENGAPI_ENTRY(PEntityOfEntOffset, 3), // pfnPEntityOfEntOffset + ENGAPI_ENTRY(EntOffsetOfPEntity, 3), // pfnEntOffsetOfPEntity + ENGAPI_ENTRY(IndexOfEdict, 3), // pfnIndexOfEdict + ENGAPI_ENTRY(PEntityOfEntIndex, 3), // pfnPEntityOfEntIndex + ENGAPI_ENTRY(FindEntityByVars, 3), // pfnFindEntityByVars + ENGAPI_ENTRY(GetModelPtr, 3), // pfnGetModelPtr + ENGAPI_ENTRY(RegUserMsg, 3), // pfnRegUserMsg + ENGAPI_ENTRY(AnimationAutomove, 2), // pfnAnimationAutomove + ENGAPI_ENTRY(GetBonePosition, 2), // pfnGetBonePosition + ENGAPI_ENTRY(FunctionFromName, 4), // pfnFunctionFromName + ENGAPI_ENTRY(NameForFunction, 4), // pfnNameForFunction + ENGAPI_ENTRY(ClientPrintf, 3), // pfnClientPrintf + ENGAPI_ENTRY(ServerPrint, 3), // pfnServerPrint + ENGAPI_ENTRY(Cmd_Args, 3), // pfnCmd_Args + ENGAPI_ENTRY(Cmd_Argv, 3), // pfnCmd_Argv + ENGAPI_ENTRY(Cmd_Argc, 3), // pfnCmd_Argc + ENGAPI_ENTRY(GetAttachment, 2), // pfnGetAttachment + ENGAPI_ENTRY(CRC32_Init, 4), // pfnCRC32_Init + ENGAPI_ENTRY(CRC32_ProcessBuffer, 4), // pfnCRC32_ProcessBuffer + ENGAPI_ENTRY(CRC32_ProcessByte, 4), // pfnCRC32_ProcessByte + ENGAPI_ENTRY(CRC32_Final, 4), // pfnCRC32_Final + ENGAPI_ENTRY(RandomLong, 3), // pfnRandomLong + ENGAPI_ENTRY(RandomFloat, 3), // pfnRandomFloat + ENGAPI_ENTRY(SetView, 2), // pfnSetView + ENGAPI_ENTRY(Time, 2), // pfnTime + ENGAPI_ENTRY(CrosshairAngle, 2), // pfnCrosshairAngle + ENGAPI_ENTRY(LoadFileForMe, 4), // pfnLoadFileForMe + ENGAPI_ENTRY(FreeFile, 4), // pfnFreeFile + ENGAPI_ENTRY(EndSection, 4), // pfnEndSection + ENGAPI_ENTRY(CompareFileTime, 4), // pfnCompareFileTime + ENGAPI_ENTRY(GetGameDir, 3), // pfnGetGameDir + ENGAPI_ENTRY(Cvar_RegisterVariable, 2), // pfnCvar_RegisterVariable + ENGAPI_ENTRY(FadeClientVolume, 2), // pfnFadeClientVolume + ENGAPI_ENTRY(SetClientMaxspeed, 3), // pfnSetClientMaxspeed + ENGAPI_ENTRY(CreateFakeClient, 2), // pfnCreateFakeClient + ENGAPI_ENTRY(RunPlayerMove, 3), // pfnRunPlayerMove + ENGAPI_ENTRY(NumberOfEntities, 2), // pfnNumberOfEntities + ENGAPI_ENTRY(GetInfoKeyBuffer, 2), // pfnGetInfoKeyBuffer + ENGAPI_ENTRY(InfoKeyValue, 2), // pfnInfoKeyValue + ENGAPI_ENTRY(SetKeyValue, 2), // pfnSetKeyValue + ENGAPI_ENTRY(SetClientKeyValue, 2), // pfnSetClientKeyValue + ENGAPI_ENTRY(IsMapValid, 2), // pfnIsMapValid + ENGAPI_ENTRY(StaticDecal, 2), // pfnStaticDecal + ENGAPI_ENTRY(PrecacheGeneric, 2), // pfnPrecacheGeneric + ENGAPI_ENTRY(GetPlayerUserId, 2), // pfnGetPlayerUserId + ENGAPI_ENTRY(BuildSoundMsg, 2), // pfnBuildSoundMsg + ENGAPI_ENTRY(IsDedicatedServer, 2), // pfnIsDedicatedServer + ENGAPI_ENTRY(CVarGetPointer, 3), // pfnCVarGetPointer + ENGAPI_ENTRY(GetPlayerWONId, 4), // pfnGetPlayerWONId + ENGAPI_ENTRY(Info_RemoveKey, 2), // pfnInfo_RemoveKey + ENGAPI_ENTRY(GetPhysicsKeyValue, 2), // pfnGetPhysicsKeyValue + ENGAPI_ENTRY(SetPhysicsKeyValue, 2), // pfnSetPhysicsKeyValue + ENGAPI_ENTRY(GetPhysicsInfoString, 2), // pfnGetPhysicsInfoString + ENGAPI_ENTRY(PrecacheEvent, 2), // pfnPrecacheEvent + ENGAPI_ENTRY(PlaybackEvent, 2), // pfnPlaybackEvent + ENGAPI_ENTRY(SetFatPVS, 2), // pfnSetFatPVS + ENGAPI_ENTRY(SetFatPAS, 2), // pfnSetFatPAS + ENGAPI_ENTRY(CheckVisibility, 2), // pfnCheckVisibility + ENGAPI_ENTRY(DeltaSetField, 3), // pfnDeltaSetField + ENGAPI_ENTRY(DeltaUnsetField, 3), // pfnDeltaUnsetField + ENGAPI_ENTRY(DeltaAddEncoder, 3), // pfnDeltaAddEncoder + ENGAPI_ENTRY(GetCurrentPlayer, 2), // pfnGetCurrentPlayer + ENGAPI_ENTRY(CanSkipPlayer, 2), // pfnCanSkipPlayer + ENGAPI_ENTRY(DeltaFindField, 3), // pfnDeltaFindField + ENGAPI_ENTRY(DeltaSetFieldByIndex, 3), // pfnDeltaSetFieldByIndex + ENGAPI_ENTRY(DeltaUnsetFieldByIndex, 3), // pfnDeltaUnsetFieldByIndex + ENGAPI_ENTRY(SetGroupMask, 2), // pfnSetGroupMask + ENGAPI_ENTRY(CreateInstancedBaseline, 3), // pfnCreateInstancedBaseline + ENGAPI_ENTRY(Cvar_DirectSet, 2), // pfnCvar_DirectSet + ENGAPI_ENTRY(ForceUnmodified, 2), // pfnForceUnmodified + ENGAPI_ENTRY(GetPlayerStats, 2), // pfnGetPlayerStats + ENGAPI_ENTRY(AddServerCommand, 2), // pfnAddServerCommand - ENGAPI_ENTRY(Voice_GetClientListening, 2), // Voice_GetClientListening - ENGAPI_ENTRY(Voice_SetClientListening, 2), // Voice_SetClientListening - ENGAPI_ENTRY(GetPlayerAuthId, 2), // pfnGetPlayerAuthId - ENGAPI_ENTRY(SequenceGet, 2), // pfnSequenceGet + ENGAPI_ENTRY(Voice_GetClientListening, 2), // Voice_GetClientListening + ENGAPI_ENTRY(Voice_SetClientListening, 2), // Voice_SetClientListening + ENGAPI_ENTRY(GetPlayerAuthId, 2), // pfnGetPlayerAuthId + ENGAPI_ENTRY(SequenceGet, 2), // pfnSequenceGet - ENGAPI_ENTRY(SequencePickSentence, 2), // pfnSequencePickSentence - ENGAPI_ENTRY(GetFileSize, 4), // pfnGetFileSize - ENGAPI_ENTRY(GetApproxWavePlayLen, 4), // pfnGetApproxWavePlayLen - ENGAPI_ENTRY(IsCareerMatch, 4), // pfnIsCareerMatch - ENGAPI_ENTRY(GetLocalizedStringLength, 4), // pfnGetLocalizedStringLength - ENGAPI_ENTRY(RegisterTutorMessageShown, 4), // pfnRegisterTutorMessageShown - ENGAPI_ENTRY(GetTimesTutorMessageShown, 4), // pfnGetTimesTutorMessageShown + ENGAPI_ENTRY(SequencePickSentence, 2), // pfnSequencePickSentence + ENGAPI_ENTRY(GetFileSize, 4), // pfnGetFileSize + ENGAPI_ENTRY(GetApproxWavePlayLen, 4), // pfnGetApproxWavePlayLen + ENGAPI_ENTRY(IsCareerMatch, 4), // pfnIsCareerMatch + ENGAPI_ENTRY(GetLocalizedStringLength, 4), // pfnGetLocalizedStringLength + ENGAPI_ENTRY(RegisterTutorMessageShown, 4), // pfnRegisterTutorMessageShown + ENGAPI_ENTRY(GetTimesTutorMessageShown, 4), // pfnGetTimesTutorMessageShown ENGAPI_ENTRY(ProcessTutorMessageDecayBuffer, 4), // pfnProcessTutorMessageDecayBuffer ENGAPI_ENTRY(ConstructTutorMessageDecayBuffer, 4), // pfnConstructTutorMessageDecayBuffer ENGAPI_ENTRY(ResetTutorMessageDecayData, 4), // pfnResetTutorMessageDecayData - ENGAPI_ENTRY(QueryClientCvarValue, 2), //pfnQueryClientCvarValue - ENGAPI_ENTRY(QueryClientCvarValue2, 2), //pfnQueryClientCvarValue2 - ENGAPI_ENTRY(EngCheckParm, 2), //pfnCheckParm + ENGAPI_ENTRY(QueryClientCvarValue, 2), //pfnQueryClientCvarValue + ENGAPI_ENTRY(QueryClientCvarValue2, 2), //pfnQueryClientCvarValue2 + ENGAPI_ENTRY(EngCheckParm, 2), //pfnCheckParm // end { 0, "", 0 }, diff --git a/metamod/src/api_info.h b/metamod/src/api_info.h index 85742b6..e5713c8 100644 --- a/metamod/src/api_info.h +++ b/metamod/src/api_info.h @@ -11,9 +11,9 @@ enum : uint8 struct api_info_t { - size_t offset; - const char *name; - size_t loglevel; + size_t offset; + const char* name; + size_t loglevel; }; // DLL api functions diff --git a/metamod/src/callback_jit.cpp b/metamod/src/callback_jit.cpp index e46763d..c4b012b 100644 --- a/metamod/src/callback_jit.cpp +++ b/metamod/src/callback_jit.cpp @@ -2,31 +2,25 @@ CJit g_jit; -class CUniqueLabel +class CUniqueLabel : public std::string { public: - CUniqueLabel(const char* name) : m_name(name) + CUniqueLabel(const char* name) : std::string(std::string(name) + std::to_string(m_unique_index++)) { - m_name += std::to_string(m_unique_index++); - } - - operator std::string&() - { - return m_name; } private: - std::string m_name; static size_t m_unique_index; }; + size_t CUniqueLabel::m_unique_index; class CForwardCallbackJIT : public jitasm::function { public: - CForwardCallbackJIT(jitdata_t *jitdata); + CForwardCallbackJIT(jitdata_t* jitdata); void naked_main(); - void call_func(jitasm::Frontend::Reg32 addr); + void call_func(Reg32 addr); private: jitdata_t* m_jitdata; @@ -280,10 +274,10 @@ void CForwardCallbackJIT::naked_main() ret(); } -void CForwardCallbackJIT::call_func(jitasm::Frontend::Reg32 addr) +void CForwardCallbackJIT::call_func(Reg32 addr) { const size_t fixed_args_count = m_jitdata->args_count - (m_jitdata->has_varargs ? 1u /* excluding format string */ : 0u); - const size_t strbuf_offset = m_jitdata->has_ret ? sizeof(int) * 2 /* orig + over */ : 0; + const size_t strbuf_offset = m_jitdata->has_ret ? sizeof(int) * 2u /* orig + over */ : 0u; // push formatted buf instead of format string if (m_jitdata->has_varargs) { @@ -360,8 +354,8 @@ bool CJit::is_hook_needed(jitdata_t* jitdata) for (int i = 0; i < jitdata->plugins_count; i++) { auto plug = &jitdata->plugins[i]; - const size_t fn_table = *(size_t *)(size_t(plug) + jitdata->table_offset); - const size_t fn_table_post = *(size_t *)(size_t(plug) + jitdata->post_table_offset); + const size_t fn_table = *(size_t *)(size_t(plug) + jitdata->table_offset); + const size_t fn_table_post = *(size_t *)(size_t(plug) + jitdata->post_table_offset); if (fn_table || fn_table_post) { return true; diff --git a/metamod/src/callback_jit.h b/metamod/src/callback_jit.h index 056e722..a9640f7 100644 --- a/metamod/src/callback_jit.h +++ b/metamod/src/callback_jit.h @@ -4,29 +4,29 @@ struct jitdata_t { - size_t pfn_original; - size_t pfn_offset; // from fn table - uint8 args_count; - bool has_ret; - bool has_varargs; - uint8 mm_hook_time; - size_t mm_hook; + size_t pfn_original; + size_t pfn_offset; // from fn table + uint8 args_count; + bool has_ret; + bool has_varargs; + uint8 mm_hook_time; + size_t mm_hook; - MPlugin* plugins; - int plugins_count; - size_t table_offset; // from MPlugin - size_t post_table_offset; // from MPlugin + MPlugin* plugins; + int plugins_count; + size_t table_offset; // from MPlugin + size_t post_table_offset; // from MPlugin }; struct compile_data_t { - const char* name; - size_t offset; - uint8 args_count; - bool has_ret; - bool has_varargs; - uint8 mm_hook_time; - size_t mm_hook; + const char* name; + size_t offset; + uint8 args_count; + bool has_ret; + bool has_varargs; + uint8 mm_hook_time; + size_t mm_hook; }; template @@ -89,7 +89,6 @@ public: private: static bool is_hook_needed(jitdata_t* jitdata); -private: static_allocator m_callback_allocator; static_allocator m_tramp_allocator; }; diff --git a/metamod/src/commands_meta.cpp b/metamod/src/commands_meta.cpp index b11dfdb..46f2e0a 100644 --- a/metamod/src/commands_meta.cpp +++ b/metamod/src/commands_meta.cpp @@ -45,10 +45,8 @@ void EXT_FUNC server_meta() { const char *cmd = CMD_ARGV(1); - for (auto& meta_cmd : g_meta_cmds) - { - if (!Q_strcmp(cmd, meta_cmd.name)) - { + for (auto& meta_cmd : g_meta_cmds) { + if (!Q_strcmp(cmd, meta_cmd.name)) { meta_cmd.handler(); return; } @@ -67,14 +65,11 @@ void EXT_FUNC client_meta(edict_t* pEntity) // arguments: none if (!Q_strcmp(cmd, "version")) client_meta_version(pEntity); - else if (!Q_strcmp(cmd, "list")) client_meta_pluginlist(pEntity); - else - { + else { META_CLIENT(pEntity, "Unrecognized meta command: %s", cmd); client_meta_usage(pEntity); - return; } } @@ -114,8 +109,7 @@ void client_meta_usage(edict_t *pEntity) // "meta version" console command. void cmd_meta_version() { - if (CMD_ARGC() != 2) - { + if (CMD_ARGC() != 2) { META_CONS("usage: meta version"); return; } @@ -128,8 +122,7 @@ void cmd_meta_version() // "meta version" client command. void client_meta_version(edict_t *pEntity) { - if (CMD_ARGC() != 2) - { + if (CMD_ARGC() != 2) { META_CLIENT(pEntity, "usage: meta version"); return; } @@ -176,8 +169,7 @@ void cmd_meta_gpl() // "meta game" console command. void cmd_meta_game() { - if (CMD_ARGC() != 2) - { + if (CMD_ARGC() != 2) { META_CONS("usage: meta game"); return; } @@ -194,15 +186,13 @@ void cmd_meta_game() // "meta refresh" console command. 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) != true) - { + if (!g_plugins->refresh(PT_ANYTIME)) { META_LOG("Refresh failed."); } } @@ -210,20 +200,18 @@ void cmd_meta_refresh() // "meta list" console command. void cmd_meta_pluginlist() { - if (CMD_ARGC() != 2) - { + if (CMD_ARGC() != 2) { META_CONS("usage: meta list"); return; } - g_plugins->show(0); + g_plugins->show(); } // "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; } @@ -234,8 +222,7 @@ void client_meta_pluginlist(edict_t* pEntity) // "meta cmds" console command. void cmd_meta_cmdlist() { - if (CMD_ARGC() != 2) - { + if (CMD_ARGC() != 2) { META_CONS("usage: meta cmds"); return; } @@ -246,8 +233,7 @@ void cmd_meta_cmdlist() // "meta cvars" console command. void cmd_meta_cvarlist() { - if (CMD_ARGC() != 2) - { + if (CMD_ARGC() != 2) { META_CONS("usage: meta cvars"); return; } @@ -258,8 +244,7 @@ void cmd_meta_cvarlist() // "meta config" console command. void cmd_meta_config() { - if (CMD_ARGC() != 2) - { + if (CMD_ARGC() != 2) { META_CONS("usage: meta cvars"); return; } @@ -271,8 +256,7 @@ void cmd_meta_config() 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:"); @@ -305,8 +289,7 @@ void cmd_doplug(PLUG_CMD pcmd) int argc = CMD_ARGC(); 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"); @@ -314,8 +297,7 @@ void cmd_doplug(PLUG_CMD pcmd) } // i = 2 to skip first arg, as that's the "cmd" - for (int i = 2; i < argc; i++) - { + for (int i = 2; i < argc; i++) { const char *arg = CMD_ARGV(i); MPlugin *findp; char *endptr; @@ -333,27 +315,22 @@ 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 && unique) - { + if (pcmd == PC_REQUIRE) { + if (findp && findp->status() >= PL_RUNNING && unique) { 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 && !unique) - { + if (findp && !unique) { 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)); } @@ -371,8 +348,7 @@ void cmd_doplug(PLUG_CMD pcmd) return; } - switch (pcmd) - { + switch (pcmd) { case PC_PAUSE: if (findp->pause()) META_CONS("Paused plugin '%s'", findp->description()); @@ -388,8 +364,7 @@ void cmd_doplug(PLUG_CMD pcmd) case PC_UNLOAD: { findp->set_action(PA_UNLOAD); - if (findp->unload(PT_ANYTIME, PNL_COMMAND)) - { + if (findp->unload(PT_ANYTIME, PNL_COMMAND)) { META_CONS("Unloaded plugin '%s'", findp->description()); g_plugins->show(); } @@ -402,8 +377,7 @@ void cmd_doplug(PLUG_CMD pcmd) case PC_FORCE_UNLOAD: { findp->set_action(PA_UNLOAD); - if (findp->unload(PT_ANYTIME, PNL_CMD_FORCED)) - { + if (findp->unload(PT_ANYTIME, PNL_CMD_FORCED)) { META_CONS("Forced unload plugin '%s'", findp->description()); g_plugins->show(); } @@ -430,9 +404,8 @@ void cmd_doplug(PLUG_CMD pcmd) else META_CONS("Retry failed for plugin '%s'", findp->description()); break; - case PC_CLEAR: - if (!findp->clear()) - { + case PC_CLEAR: + if (!findp->clear()) { META_CONS("Clear failed for plugin '%s'", findp->description()); return; } @@ -443,7 +416,7 @@ void cmd_doplug(PLUG_CMD pcmd) case PC_INFO: findp->show(); break; - default: + 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 5c48dbf..241061e 100644 --- a/metamod/src/commands_meta.h +++ b/metamod/src/commands_meta.h @@ -4,16 +4,16 @@ // "load" operates on a non-existing plugin thus isn't included here. enum PLUG_CMD { - PC_NULL = 0, - PC_PAUSE, // pause the plugin - PC_UNPAUSE, // unpause the plugin - PC_UNLOAD, // unload the plugin - PC_RELOAD, // unload the plugin and load it again - PC_RETRY, // retry a failed operation (usually load/attach) - PC_INFO, // show all info about the plugin - PC_CLEAR, // remove a failed plugin from the list + PC_NULL, + PC_PAUSE, // pause the plugin + PC_UNPAUSE, // unpause the plugin + PC_UNLOAD, // unload the plugin + PC_RELOAD, // unload the plugin and load it again + PC_RETRY, // retry a failed operation (usually load/attach) + PC_INFO, // show all info about the plugin + 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 + PC_REQUIRE, // require that this plugin is loaded/running }; void meta_register_cmdcvar(); @@ -35,7 +35,7 @@ void cmd_meta_config(); void cmd_doplug(PLUG_CMD pcmd); -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); +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); diff --git a/metamod/src/conf_meta.cpp b/metamod/src/conf_meta.cpp index fd151f1..d3ac978 100644 --- a/metamod/src/conf_meta.cpp +++ b/metamod/src/conf_meta.cpp @@ -14,15 +14,14 @@ 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 = m_list; optp->name; optp++) - { + for (auto optp = m_list; optp->name; optp++) { if (!Q_strcmp(optp->name, lookup)) { return optp; } } - + return nullptr; } @@ -38,19 +37,17 @@ bool MConfig::set(const char* key, const char* value) const bool MConfig::set(option_t* setp, const char* setstr) { char pathbuf[PATH_MAX]; - int* optval = (int *) setp->dest; - char** optstr = (char **) setp->dest; + int* optval = (int *)setp->dest; + char** optstr = (char **)setp->dest; // cvar_t *optcvar = (cvar_t *) setp->dest; // SETOPT_FN optcmd = (SETOPT_FN) setp->dest; if (!setstr) return true; - 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 false; } @@ -58,16 +55,13 @@ bool MConfig::set(option_t* setp, const char* 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 false; @@ -76,13 +70,13 @@ bool MConfig::set(option_t* setp, const char* setstr) break; case CF_STR: if (*optstr) - Q_free(*optstr); + Q_free(*optstr); *optstr = Q_strdup(setstr); META_DEBUG(3, "set config string: %s = %s", setp->name, *optstr); break; case CF_PATH: if (*optstr) - Q_free(*optstr); + Q_free(*optstr); full_gamedir_path(setstr, pathbuf); *optstr = Q_strdup(pathbuf); META_DEBUG(3, "set config path: %s = %s", setp->name, *optstr); @@ -99,48 +93,42 @@ bool MConfig::load(const char* fn) { char loadfile[PATH_MAX]; char line[MAX_CONF_LEN]; - char *optname, *optval; - option_t* optp; // Make full pathname (from gamedir if relative, collapse "..", // backslashes, etc). full_gamedir_path(fn, loadfile); FILE* fp = fopen(loadfile, "r"); - if (!fp) - { + if (!fp) { META_ERROR("unable to open config file '%s': %s", loadfile, strerror(errno)); return false; } META_DEBUG(2, "Loading from config file: %s", loadfile); - for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++) - { + for (int ln = 1; !feof(fp) && fgets(line, sizeof line, fp); ln++) { if (line[0] == '#' || line[0] == ';' || !Q_strncmp(line, "//", 2)) continue; - if (!(optname = strtok(line, " \t\r\n"))) - { + char* optname = strtok(line, " \t\r\n"); + if (!optname) { META_ERROR("'%s' line %d: bad config format: missing option", loadfile, ln); continue; } - - if (!(optval = strtok(nullptr, "\r\n"))) - { + + char *optval = strtok(nullptr, "\r\n"); + if (!optval) { META_ERROR("'%s' line %d: bad config format: missing value", loadfile, ln); continue; } - if (!(optp = find(optname))) - { + auto optp = find(optname); + if (!optp) { META_ERROR("'%s' line %d: unknown option name '%s'", loadfile, ln, optname); continue; } - if (!set(optp, optval)) - { + if (!set(optp, optval)) { META_ERROR("'%s' line %d: unable to set option '%s' value '%s'", loadfile, ln, optname, optval); - continue; } } @@ -153,15 +141,13 @@ void MConfig::show() const { META_CONS("Config options from localinfo and %s:", m_filename); - for (auto optp = m_list; optp->name; optp++) - { - int *optval = (int *)optp->dest; - char **optstr = (char **)optp->dest; + for (auto optp = m_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; @@ -186,8 +172,7 @@ void MConfig::set_directory() GetModuleFileName(hModule, m_directory, sizeof m_directory); #else Dl_info addrInfo; - if (dladdr((void *)GiveFnptrsToDll, &addrInfo)) - { + if (dladdr((void *)GiveFnptrsToDll, &addrInfo)) { Q_strncpy(m_directory, addrInfo.dli_fname, sizeof m_directory - 1); m_directory[sizeof m_directory - 1] = '\0'; } @@ -196,7 +181,7 @@ void MConfig::set_directory() normalize_path(m_directory); // get directory - char *dir = Q_strrchr(m_directory, '/'); + char* dir = Q_strrchr(m_directory, '/'); if (dir) { *dir = '\0'; } diff --git a/metamod/src/conf_meta.h b/metamod/src/conf_meta.h index 17047e3..cdefdd5 100644 --- a/metamod/src/conf_meta.h +++ b/metamod/src/conf_meta.h @@ -15,10 +15,10 @@ enum cf_type_t 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 + 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 @@ -26,28 +26,28 @@ class MConfig public: MConfig(); - void init(option_t *global_options); - bool load(const char *filename); - bool set(const char *key, const char *value) const; + void init(option_t* global_options); + bool load(const char* filename); + bool set(const char* key, const char* value) const; void show() const; void set_directory(); - const char *directory() const; + const char* directory() const; - int m_debuglevel; // to use for meta_debug - char *m_gamedll; // string if specified in config.ini - char *m_exec_cfg; // ie exec.cfg + int m_debuglevel; // to use for meta_debug + char* m_gamedll; // string if specified in config.ini + char* m_exec_cfg; // ie exec.cfg int m_clientmeta; private: - option_t *m_list; - char *m_filename; + option_t* m_list; + char* m_filename; char m_directory[MAX_PATH]; - option_t *find(const char *lookup) const; - static bool set(option_t *setp, const char *value); + option_t* find(const char* lookup) const; + static bool set(option_t* setp, const char* value); }; -inline const char *MConfig::directory() const +inline const char* MConfig::directory() const { return m_directory; } diff --git a/metamod/src/dllapi.cpp b/metamod/src/dllapi.cpp index b214672..510c616 100644 --- a/metamod/src/dllapi.cpp +++ b/metamod/src/dllapi.cpp @@ -12,7 +12,7 @@ NEW_DLL_FUNCTIONS sNewFunctionTable; NEW_DLL_FUNCTIONS sNewFunctionTable_jit; NEW_DLL_FUNCTIONS *pHookedNewDllFunctions = &sNewFunctionTable; -void MM_PRE_HOOK EXT_FUNC mm_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128] ) +void MM_PRE_HOOK EXT_FUNC mm_ClientConnect(edict_t *pEntity, const char *, const char *, char [128]) { g_players.clear_player_cvar_query(pEntity); } @@ -149,13 +149,11 @@ compile_data_t g_newdllfunc_cdata[] = 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; } - if (interfaceVersion != INTERFACE_VERSION) - { + if (interfaceVersion != INTERFACE_VERSION) { META_ERROR("GetEntityAPI version mismatch; requested=%d ours=%d", interfaceVersion, INTERFACE_VERSION); return FALSE; } @@ -168,13 +166,11 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi { META_DEBUG(3, "called: GetEntityAPI2; version=%d", *interfaceVersion); - if (!pFunctionTable) - { + if (!pFunctionTable) { META_ERROR("GetEntityAPI2 called with null pFunctionTable"); return FALSE; } - if (*interfaceVersion != INTERFACE_VERSION) - { + 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; @@ -196,13 +192,11 @@ C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *in return FALSE; #endif - if (!pNewFunctionTable) - { + if (!pNewFunctionTable) { META_ERROR("GetNewDLLFunctions called with null pNewFunctionTable"); return FALSE; } - if (*interfaceVersion != NEW_DLL_FUNCTIONS_VERSION) - { + 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; diff --git a/metamod/src/dllapi.h b/metamod/src/dllapi.h index edbf9de..8f2ac0f 100644 --- a/metamod/src/dllapi.h +++ b/metamod/src/dllapi.h @@ -4,13 +4,13 @@ typedef void (*FN_GAMEINIT)(); // 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); -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); +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); #ifdef METAMOD_CORE void compile_gamedll_callbacks(); diff --git a/metamod/src/engine_api.cpp b/metamod/src/engine_api.cpp index 48ea1dd..b047efc 100644 --- a/metamod/src/engine_api.cpp +++ b/metamod/src/engine_api.cpp @@ -34,12 +34,12 @@ compile_data_t g_engfuncs_cdata[] = { CDATA_ENG(pfnPrecacheModel), // pfnPrecacheModel() CDATA_ENG(pfnPrecacheSound), // pfnPrecacheSound() - CDATA_ENG(pfnSetModel), // pfnSetModel() + CDATA_ENG(pfnSetModel), // pfnSetModel() CDATA_ENG(pfnModelIndex), // pfnModelIndex() - CDATA_ENG(pfnModelFrames), // pfnModelFrames() + CDATA_ENG(pfnModelFrames), // pfnModelFrames() - CDATA_ENG(pfnSetSize), // pfnSetSize() - CDATA_ENG(pfnChangeLevel), // pfnChangeLevel() + CDATA_ENG(pfnSetSize), // pfnSetSize() + CDATA_ENG(pfnChangeLevel), // pfnChangeLevel() CDATA_ENG(pfnGetSpawnParms), // pfnGetSpawnParms() CDATA_ENG(pfnSaveSpawnParms), // pfnSaveSpawnParms() diff --git a/metamod/src/engine_api.h b/metamod/src/engine_api.h index 337ec14..234fe57 100644 --- a/metamod/src/engine_api.h +++ b/metamod/src/engine_api.h @@ -3,7 +3,7 @@ struct enginefuncs_s; // Plugin's GetEngineFunctions, called by metamod. -typedef int (*GET_ENGINE_FUNCTIONS_FN)(enginefuncs_s *pengfuncsFromEngine, int *interfaceVersion); +typedef int (*GET_ENGINE_FUNCTIONS_FN)(enginefuncs_s* pengfuncsFromEngine, int* interfaceVersion); // According to SDK engine/eiface.h: // ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 138 @@ -12,9 +12,9 @@ typedef int (*GET_ENGINE_FUNCTIONS_FN)(enginefuncs_s *pengfuncsFromEngine, int * // Protect against other projects which use this include file but use the // normal enginefuncs_t type for their meta_engfuncs. #ifdef METAMOD_CORE - extern enginefuncs_t g_meta_engfuncs; +extern enginefuncs_t g_meta_engfuncs; - void compile_engine_callbacks(); +void compile_engine_callbacks(); #else extern enginefuncs_t meta_engfuncs; #endif diff --git a/metamod/src/engine_t.h b/metamod/src/engine_t.h index 47aaaad..ff8802e 100644 --- a/metamod/src/engine_t.h +++ b/metamod/src/engine_t.h @@ -3,11 +3,13 @@ // Our structure for storing engine references. struct engine_t { - engine_t() : funcs(nullptr), globals(nullptr), pl_funcs(nullptr) {} + 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; diff --git a/metamod/src/enginecallbacks.h b/metamod/src/enginecallbacks.h index 187209c..db1536a 100644 --- a/metamod/src/enginecallbacks.h +++ b/metamod/src/enginecallbacks.h @@ -12,17 +12,13 @@ #include // ALERT, etc -#ifdef 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 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) diff --git a/metamod/src/game_support.cpp b/metamod/src/game_support.cpp index 10bd0e0..4da2afc 100644 --- a/metamod/src/game_support.cpp +++ b/metamod/src/game_support.cpp @@ -11,17 +11,16 @@ const game_modinfo_t g_known_games[] = { // separate file, generated based on game information stored in a // convenient db. { "cstrike", "cs.so", "mp.dll", "Counter-Strike" }, - { "czero", "cs.so", "mp.dll", "Counter-Strike:Condition Zero" }, + { "czero", "cs.so", "mp.dll", "Counter-Strike:Condition Zero" }, // End of list terminator: { nullptr, nullptr, nullptr, nullptr } }; // Find a modinfo corresponding to the given game name. -inline const game_modinfo_t *lookup_game(const char *name) +static const game_modinfo_t *lookup_game(const char *name) { - for (auto& known : g_known_games) - { + for (auto& known : g_known_games) { if (known.name && !Q_stricmp(known.name, name)) return &known; } @@ -33,35 +32,30 @@ inline const game_modinfo_t *lookup_game(const char *name) // Installs gamedll from Steam cache bool install_gamedll(char *from, const char *to) { - int length_in; - int length_out; - if (!from) return false; if (!to) to = from; + int length_in; byte *cachefile = LOAD_FILE_FOR_ME(from, &length_in); // If the file seems to exist in the cache. - if (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) - { + if (fd < 0) { META_DEBUG(3, "Installing gamedll from cache: Failed to create file %s: %s", to, strerror(errno)); FREE_FILE(cachefile); return false; } - length_out = Q_write(fd, cachefile, length_in); + int length_out = Q_write(fd, cachefile, length_in); FREE_FILE(cachefile); close(fd); // Writing the file was not successfull - if (length_out != length_in) - { + 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. @@ -73,8 +67,7 @@ bool install_gamedll(char *from, const char *to) META_LOG("Installed gamedll %s from cache.", to); } - else - { + else { META_DEBUG(3, "Failed to install gamedll from cache: file %s not found in cache.", from); return false; } @@ -95,8 +88,7 @@ bool setup_gamedll(gamedll_t *gamedll) const char *knownfn = nullptr; // First, look for a known game, based on gamedir. - if ((known = lookup_game(gamedll->name))) - { + if ((known = lookup_game(gamedll->name))) { #ifdef _WIN32 knownfn = known->win_dll; #else @@ -109,22 +101,19 @@ bool setup_gamedll(gamedll_t *gamedll) return false; // Use override-dll if specified. - if (g_config->m_gamedll) - { + if (g_config->m_gamedll) { Q_strncpy(gamedll->pathname, g_config->m_gamedll, sizeof gamedll->pathname - 1); gamedll->pathname[sizeof gamedll->pathname - 1] = '\0'; // If the path is relative, the gamedll file will be missing and // it might be found in the cache file. - if (!is_abs_path(gamedll->pathname)) - { + if (!is_abs_path(gamedll->pathname)) { char szInstallPath[MAX_PATH]; Q_snprintf(szInstallPath, sizeof(szInstallPath), "%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, szInstallPath)) - { + if (install_gamedll(gamedll->pathname, szInstallPath)) { Q_strncpy(gamedll->pathname, szInstallPath, sizeof(gamedll->pathname)); } } @@ -132,12 +121,10 @@ bool setup_gamedll(gamedll_t *gamedll) override = true; } // Else use Known-list dll. - else if (known) - { + else if (known) { Q_snprintf(gamedll->pathname, sizeof(gamedll->pathname), "%s/dlls/%s", gamedll->gamedir, knownfn); } - else - { + else { // Neither override nor known-list found a gamedll. return false; } @@ -153,26 +140,22 @@ bool setup_gamedll(gamedll_t *gamedll) // 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) - { + if (known && override) { Q_snprintf(gamedll->real_pathname, sizeof(gamedll->real_pathname), "%s/dlls/%s", gamedll->gamedir, knownfn); } - else - { + else { Q_strncpy(gamedll->real_pathname, gamedll->pathname, sizeof gamedll->real_pathname - 1); gamedll->real_pathname[sizeof gamedll->real_pathname - 1] = '\0'; } - if (override) - { + if (override) { // generate a desc Q_snprintf(gamedll->desc, sizeof(gamedll->desc), "%s (override)", gamedll->file); // log result META_LOG("Overriding game '%s' with dllfile '%s'", gamedll->name, gamedll->file); } - else if (known) - { + else if (known) { Q_strncpy(gamedll->desc, known->desc, sizeof gamedll->desc - 1); gamedll->desc[sizeof gamedll->desc - 1] = '\0'; diff --git a/metamod/src/game_support.h b/metamod/src/game_support.h index 366abfb..34aea07 100644 --- a/metamod/src/game_support.h +++ b/metamod/src/game_support.h @@ -5,10 +5,10 @@ // Information we have about each game/mod DLL. 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 *desc; // our long-name description + 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* desc; // our long-name description }; -bool setup_gamedll(gamedll_t *gamedll); +bool setup_gamedll(gamedll_t* gamedll); diff --git a/metamod/src/h_export.cpp b/metamod/src/h_export.cpp index ffb6348..b9ae98d 100644 --- a/metamod/src/h_export.cpp +++ b/metamod/src/h_export.cpp @@ -1,38 +1,5 @@ #include "precompiled.h" -#ifdef _WIN32 -//! Required DLL entry point -// The above SDK comment indicates this routine is required, but the MSDN -// documentation indicates it's actually optional. We keep it, though, for -// completeness. -BOOL WINAPI DllMain(HINSTANCE /* hinstDLL */, DWORD fdwReason, LPVOID /* lpvReserved */) -{ - if (fdwReason == DLL_PROCESS_ATTACH) - { - /* nothing */ - } - else if (fdwReason == DLL_PROCESS_DETACH) - { - /* nothing */ - } - return TRUE; -} -#elif defined(linux) || defined(__APPLE__) -// Linux routines to correspond to ATTACH and DETACH cases above. These -// aren't required by linux, but are included here for completeness, and -// 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() -{ - // called before dlopen() returns -} -void _fini() -{ - // called before dlclose() returns -} -#endif - //! Holds engine functionality callbacks enginefuncs_t g_engfuncs; globalvars_t* gpGlobals; @@ -43,7 +10,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; diff --git a/metamod/src/h_export.h b/metamod/src/h_export.h index ab3ffb3..9f95777 100644 --- a/metamod/src/h_export.h +++ b/metamod/src/h_export.h @@ -1,5 +1,5 @@ #pragma once // 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); +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/linkent.cpp b/metamod/src/linkent.cpp index f1dcacf..20c124e 100644 --- a/metamod/src/linkent.cpp +++ b/metamod/src/linkent.cpp @@ -3,22 +3,19 @@ // 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 NOINLINE do_link_ent(ENTITY_FN *pfnEntity, int *missing, const char *entStr, entvars_t *pev) +void NOINLINE 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)g_GameDLL.sys_module.getsym(entStr); } - if (!*pfnEntity) - { + if (!*pfnEntity) { META_ERROR("Couldn't find game entity '%s' in game DLL '%s': %s", entStr, g_GameDLL.name, CSysModule::getloaderror()); *missing = 1; return; diff --git a/metamod/src/linkent.h b/metamod/src/linkent.h index 85d872a..7a16a75 100644 --- a/metamod/src/linkent.h +++ b/metamod/src/linkent.h @@ -9,7 +9,7 @@ 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) { \ diff --git a/metamod/src/log_meta.cpp b/metamod/src/log_meta.cpp index 585debd..3d0678b 100644 --- a/metamod/src/log_meta.cpp +++ b/metamod/src/log_meta.cpp @@ -1,6 +1,13 @@ #include "precompiled.h" -cvar_t g_meta_debug = { "meta_debug", "0", FCVAR_EXTDLL , 0, nullptr }; +cvar_t g_meta_debug = +{ + "meta_debug", + "0", + FCVAR_EXTDLL, + 0, + nullptr +}; enum MLOG_SERVICE { @@ -10,10 +17,10 @@ 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, ...) { char buf[MAX_LOGMSG_LEN]; @@ -28,10 +35,9 @@ 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); @@ -39,7 +45,7 @@ void META_DEV(const char *fmt, ...) } } -void META_INFO(const char *fmt, ...) +void META_INFO(const char* fmt, ...) { va_list ap; va_start(ap, fmt); @@ -47,7 +53,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; va_start(ap, fmt); @@ -55,7 +61,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; va_start(ap, fmt); @@ -63,7 +69,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; va_start(ap, fmt); @@ -84,7 +90,7 @@ void NOINLINE META_DEBUG_(int level, const char* fmt, ...) } // Print to client. -void META_CLIENT(edict_t *pEntity, const char *fmt, ...) +void META_CLIENT(edict_t* pEntity, const char* fmt, ...) { char buf[MAX_CLIENTMSG_LEN]; @@ -103,29 +109,27 @@ 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 *g_messageQueueStart = nullptr; -static BufferedMessage *g_messageQueueEnd = nullptr; +static BufferedMessage* g_messageQueueStart; +static BufferedMessage* g_messageQueueEnd; -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]; - if (g_engfuncs.pfnAlertMessage) - { + 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. - BufferedMessage *msg = new BufferedMessage; - if (!msg) - { + BufferedMessage* msg = new BufferedMessage; + if (!msg) { // though luck, gonna lose this message return; } @@ -136,12 +140,10 @@ void buffered_ALERT(MLOG_SERVICE service, ALERT_TYPE atype, const char *prefix, Q_vsnprintf(msg->buf, sizeof buf, fmt, ap); msg->next = nullptr; - if (!g_messageQueueEnd) - { + if (!g_messageQueueEnd) { g_messageQueueStart = g_messageQueueEnd = msg; } - else - { + else { g_messageQueueEnd->next = msg; g_messageQueueEnd = msg; } @@ -153,16 +155,13 @@ 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() { - BufferedMessage *msg = g_messageQueueStart; + BufferedMessage* msg = g_messageQueueStart; int dev = (int)CVAR_GET_FLOAT("developer"); - while (msg) - { + while (msg) { if (msg->service == mlsDEV && dev == 0) { - ; } - else - { + else { ALERT(msg->atype, "b>%s %s\n", msg->prefix, msg->buf); } diff --git a/metamod/src/log_meta.h b/metamod/src/log_meta.h index 8f319d0..67401e8 100644 --- a/metamod/src/log_meta.h +++ b/metamod/src/log_meta.h @@ -1,27 +1,27 @@ #pragma once -// max buffer size for printed messages -#define MAX_LOGMSG_LEN 1024 - -// max buffer size for client messages -#define MAX_CLIENTMSG_LEN 128 +enum +{ + MAX_LOGMSG_LEN = 1024, // max buffer size for printed messages + MAX_CLIENTMSG_LEN = 128 // max buffer size for client messages +}; extern cvar_t g_meta_debug; -template -void META_DEBUG(int level, const char* fmt, t_args... args) +template +void META_DEBUG(int level, const char* fmt, t_args ... args) { if (unlikely(g_meta_debug.value >= level)) META_DEBUG_(level, fmt, args...); } -void META_CONS(const char *fmt, ...); -void META_DEV(const char *fmt, ...); -void META_INFO(const char *fmt, ...); -void META_WARNING(const char *fmt, ...); -void META_ERROR(const char *fmt, ...); -void META_LOG(const char *fmt, ...); +void META_CONS(const char* fmt, ...); +void META_DEV(const char* fmt, ...); +void META_INFO(const char* fmt, ...); +void META_WARNING(const char* fmt, ...); +void META_ERROR(const char* fmt, ...); +void META_LOG(const char* fmt, ...); void META_DEBUG_(int level, const char* fmt, ...); -void META_CLIENT(edict_t *pEntity, const char *fmt, ...); +void META_CLIENT(edict_t* pEntity, const char* fmt, ...); void flush_ALERT_buffer(); diff --git a/metamod/src/metamod.cpp b/metamod/src/metamod.cpp index 8720a24..1ebdb87 100644 --- a/metamod/src/metamod.cpp +++ b/metamod/src/metamod.cpp @@ -37,8 +37,6 @@ int g_requestid_counter = 0; // Do startup operations... void metamod_startup() { - const char *cp; - char configFile[MAX_PATH]; char pluginFile[MAX_PATH]; char execFile[MAX_PATH]; @@ -60,8 +58,7 @@ void metamod_startup() // 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); } @@ -73,19 +70,18 @@ void metamod_startup() // Set a slight debug level for developer mode, if debug level not // already set. - if ((int)CVAR_GET_FLOAT("developer") != 0 && g_meta_debug.value == 0) + if (CVAR_GET_FLOAT("developer") != 0.0 && g_meta_debug.value == 0.0) CVAR_SET_FLOAT("meta_debug", 3.0); // Init default values g_config->init(g_global_options); // Find config file - if ((cp = LOCALINFO("mm_configfile")) && *cp != '\0') - { + const char *cp = LOCALINFO("mm_configfile"); + if (cp && *cp != '\0') { META_LOG("Configfile specified via localinfo: %s", cp); - if (is_file_exists_in_gamedir(cp)) - { + if (is_file_exists_in_gamedir(cp)) { Q_strncpy(configFile, cp, sizeof configFile - 1); configFile[sizeof configFile - 1] = '\0'; } @@ -93,8 +89,7 @@ void metamod_startup() META_ERROR("Empty/missing config.ini file: %s; falling back to %s", cp, configFile); } - if (!is_file_exists_in_gamedir(configFile)) - { + if (!is_file_exists_in_gamedir(configFile)) { Q_strncpy(configFile, g_config->directory(), sizeof configFile - 1); configFile[sizeof configFile - 1] = '\0'; @@ -105,8 +100,7 @@ void metamod_startup() } Q_strcat(configFile, "/" CONFIG_INI); - if (!is_file_exists_in_gamedir(configFile)) - { + if (!is_file_exists_in_gamedir(configFile)) { META_DEBUG(2, "No config.ini file found: %s", CONFIG_INI); } } @@ -116,39 +110,39 @@ void metamod_startup() g_config->load(configFile); // Now, override config options with localinfo commandline options. - if ((cp = LOCALINFO("mm_debug")) && *cp != '\0') - { + cp = LOCALINFO("mm_debug"); + if (cp && *cp != '\0') { META_LOG("Debuglevel specified via localinfo: %s", cp); g_config->set("debuglevel", cp); } - if ((cp = LOCALINFO("mm_gamedll")) && *cp != '\0') - { + cp = LOCALINFO("mm_gamedll"); + if (cp && *cp != '\0') { META_LOG("Gamedll specified via localinfo: %s", cp); g_config->set("gamedll", cp); } - if ((cp = LOCALINFO("mm_pluginsfile")) && *cp != '\0') - { + cp = LOCALINFO("mm_pluginsfile"); + if (cp && *cp != '\0') { META_LOG("Pluginsfile specified via localinfo: %s", cp); g_config->set("plugins_file", cp); } - if ((cp = LOCALINFO("mm_execcfg")) && *cp != '\0') - { + cp = LOCALINFO("mm_execcfg"); + if (cp && *cp != '\0') { META_LOG("Execcfg specified via localinfo: %s", cp); g_config->set("exec_cfg", cp); } - if ((cp = LOCALINFO("mm_clientmeta")) && *cp != '\0') - { + cp = LOCALINFO("mm_clientmeta"); + if (cp && *cp != '\0') { META_LOG("Clientmeta specified via localinfo: %s", cp); g_config->set("clientmeta", cp); } // Check for an initial debug level, since cfg files don't get exec'd // until later. - if (g_config->m_debuglevel != 0) + if (g_config->m_debuglevel) CVAR_SET_FLOAT("meta_debug", g_config->m_debuglevel); if (!g_config->m_clientmeta) disable_clientcommand_fwd(); @@ -197,8 +191,7 @@ void metamod_startup() // In fact, we need gamedir even earlier, so moved up above. // Load plugins file - if (!is_file_exists_in_gamedir(pluginFile)) - { + if (!is_file_exists_in_gamedir(pluginFile)) { Q_strncpy(pluginFile, g_config->directory(), sizeof pluginFile - 1); pluginFile[sizeof pluginFile - 1] = '\0'; @@ -209,22 +202,19 @@ void metamod_startup() } Q_strcat(pluginFile, "/" PLUGINS_INI); - if (!is_file_exists_in_gamedir(pluginFile)) - { + if (!is_file_exists_in_gamedir(pluginFile)) { META_DEBUG(2, "No plugins.ini file found: %s", PLUGINS_INI); } } g_plugins = new MPluginList(pluginFile); - 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... } @@ -237,18 +227,15 @@ void metamod_startup() // Only attempt load if the file appears to exist and be non-empty, to // avoid confusing users with "couldn't exec exec.cfg" console // messages. - if (g_config->m_exec_cfg) - { + if (g_config->m_exec_cfg) { Q_strncpy(execFile, g_config->m_exec_cfg, sizeof execFile - 1); execFile[sizeof execFile - 1] = '\0'; } - if (is_file_exists_in_gamedir(execFile)) - { + if (is_file_exists_in_gamedir(execFile)) { if (execFile[0] == '/') META_ERROR("Cannot exec absolute pathnames: %s", execFile); - else - { + else { char cmd[NAME_MAX]; META_LOG("Exec'ing metamod exec.cfg: %s...", execFile); Q_snprintf(cmd, sizeof cmd, "exec %s\n", execFile); @@ -262,11 +249,9 @@ void metamod_startup() // - ME_NULLRESULT _getcwd failed bool meta_init_gamedll() { - char gamedir[PATH_MAX]; - char *cp; - Q_memset(&g_GameDLL, 0, sizeof g_GameDLL); + char gamedir[PATH_MAX]; GET_GAME_DIR(gamedir); normalize_path(gamedir); @@ -280,26 +265,23 @@ bool meta_init_gamedll() // Note: the code has always assumed the server op wouldn't do: // hlds -game other/firearms // - if (is_abs_path(gamedir)) - { + if (is_abs_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.) Q_strncpy(g_GameDLL.gamedir, gamedir, sizeof g_GameDLL.gamedir - 1); g_GameDLL.gamedir[sizeof g_GameDLL.gamedir - 1] = '\0'; - cp = Q_strrchr(gamedir, '/') + 1; + char* cp = Q_strrchr(gamedir, '/') + 1; Q_strncpy(g_GameDLL.name, cp, sizeof g_GameDLL.name - 1); g_GameDLL.name[sizeof g_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)) - { + if (!_getcwd(buf, sizeof buf)) { META_WARNING("dll: Couldn't get cwd; %s", strerror(errno)); return false; } @@ -358,7 +340,7 @@ bool get_function_table(const char* ifname, int ifvers_mm, table_t*& table, size template bool get_function_table_old(const char* ifname, int ifvers_mm, table_t*& table, size_t table_size = sizeof(table_t)) { - typedef int (*getfunc_t)(table_t *pFunctionTable, int interfaceVersion); + typedef int(*getfunc_t)(table_t *pFunctionTable, int interfaceVersion); auto pfnGetFuncs = (getfunc_t)g_GameDLL.sys_module.getsym(ifname); @@ -389,16 +371,14 @@ bool get_function_table_old(const char* ifname, int ifvers_mm, table_t*& table, // (GiveFnptrsToDll, GetEntityAPI, GetEntityAPI2) bool meta_load_gamedll() { - if (!setup_gamedll(&g_GameDLL)) - { + if (!setup_gamedll(&g_GameDLL)) { META_ERROR("dll: Unrecognized game: %s", g_GameDLL.name); // meta_errno should be already set in lookup_game() return false; } // open the game DLL - if (!g_GameDLL.sys_module.load(g_GameDLL.pathname)) - { + if (!g_GameDLL.sys_module.load(g_GameDLL.pathname)) { META_ERROR("dll: Couldn't load game DLL %s: %s", g_GameDLL.pathname, CSysModule::getloaderror()); return false; } @@ -411,14 +391,11 @@ bool meta_load_gamedll() // dynamically loadable at any time, we have to always pass our table, // so that any plugin loaded later can catch what they need to. auto pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN)g_GameDLL.sys_module.getsym("GiveFnptrsToDll"); - - if (pfn_give_engfuncs) - { + if (pfn_give_engfuncs) { pfn_give_engfuncs(&g_meta_engfuncs, gpGlobals); META_DEBUG(3, "dll: Game '%s': Called GiveFnptrsToDll", g_GameDLL.name); } - else - { + else { META_ERROR("dll: Couldn't find GiveFnptrsToDll() in game DLL '%s'", g_GameDLL.name); return false; } diff --git a/metamod/src/metamod.h b/metamod/src/metamod.h index 036da33..4cd80f9 100644 --- a/metamod/src/metamod.h +++ b/metamod/src/metamod.h @@ -18,39 +18,39 @@ extern cvar_t g_meta_version; // Info about the game dll/mod. struct gamedll_t { - char name[NAME_MAX]; // ie "cstrike" (from gamedir) - char desc[NAME_MAX]; // 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 real_pathname[PATH_MAX]; // in case pathname overridden by bot, etc + char name[NAME_MAX]; // ie "cstrike" (from gamedir) + char desc[NAME_MAX]; // 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 real_pathname[PATH_MAX]; // in case pathname overridden by bot, etc CSysModule sys_module; - gamedll_funcs_t funcs; // dllapi_table, newapi_table + gamedll_funcs_t funcs; // dllapi_table, newapi_table }; extern gamedll_t g_GameDLL; // SDK variables for storing engine funcs and globals. extern enginefuncs_t g_engfuncs; -extern globalvars_t *gpGlobals; +extern globalvars_t* gpGlobals; // Our modified version of the engine funcs, to give to plugins. extern enginefuncs_t g_plugin_engfuncs; // g_config structure. -extern MConfig *g_config; +extern MConfig* g_config; // List of plugins loaded/opened/running. -extern MPluginList *g_plugins; +extern MPluginList* g_plugins; // List of command functions registered by plugins. -extern MRegCmdList *g_regCmds; +extern MRegCmdList* g_regCmds; // List of cvar structures registered by plugins. -extern MRegCvarList *g_regCvars; +extern MRegCvarList* g_regCvars; // List of user messages registered by gamedll. -extern MRegMsgList *g_regMsgs; +extern MRegMsgList* g_regMsgs; #ifdef METAMOD_CORE ALIGN16 @@ -62,8 +62,8 @@ ALIGN16 extern meta_globals_t g_metaGlobals; // hook function tables -extern DLL_FUNCTIONS *pHookedDllFunctions; -extern NEW_DLL_FUNCTIONS *pHookedNewDllFunctions; +extern DLL_FUNCTIONS* pHookedDllFunctions; +extern NEW_DLL_FUNCTIONS* pHookedNewDllFunctions; // (patch by hullu) // Safety check for metamod-bot-plugin bugfix. diff --git a/metamod/src/metamod_rehlds_api.cpp b/metamod/src/metamod_rehlds_api.cpp index 4256e71..5847a3d 100644 --- a/metamod/src/metamod_rehlds_api.cpp +++ b/metamod/src/metamod_rehlds_api.cpp @@ -45,7 +45,8 @@ bool rehlds_api_try_init(CSysModule* engineModule, char* failureReason) return true; } -bool meta_init_rehlds_api() { +bool meta_init_rehlds_api() +{ char failReason[2048]; #ifdef WIN32 diff --git a/metamod/src/mlist.cpp b/metamod/src/mlist.cpp index 59238e9..89a217f 100644 --- a/metamod/src/mlist.cpp +++ b/metamod/src/mlist.cpp @@ -9,8 +9,7 @@ MPluginList::MPluginList(const char* ifile) : m_max_loaded_count(0) // initialize array Q_memset(m_plist, 0, sizeof m_plist); - for (int i = 0; i < MAX_PLUGINS; i++) - { + for (int i = 0; i < MAX_PLUGINS; i++) { new(m_plist + i) MPlugin(i + 1); // 1-based } @@ -28,13 +27,12 @@ int MPluginList::getmaxcount() const } // Find a plugin based on the plugin handle. -MPlugin *MPluginList::find(module_handle_t handle) +MPlugin* MPluginList::find(module_handle_t handle) { if (!handle) return nullptr; - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { if (m_plist[i].m_status < PL_VALID) continue; if (handle == m_plist[i].m_sys_module.gethandle()) @@ -45,7 +43,7 @@ MPlugin *MPluginList::find(module_handle_t handle) } // Find a plugin based on the plugin index #. -MPlugin *MPluginList::find(int pindex) +MPlugin* MPluginList::find(int pindex) { if (pindex <= 0) return nullptr; @@ -53,18 +51,17 @@ MPlugin *MPluginList::find(int pindex) auto pfound = &m_plist[pindex - 1]; if (pfound->m_status < PL_VALID) return nullptr; - + return pfound; } // Find a plugin with the given plid. -MPlugin *MPluginList::find(plid_t id) +MPlugin* MPluginList::find(plid_t id) { if (!id) return nullptr; - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { if (m_plist[i].m_status < PL_VALID) continue; if (m_plist[i].m_info == id) @@ -75,22 +72,20 @@ MPlugin *MPluginList::find(plid_t id) } // Find a plugin with the given pathname. -MPlugin *MPluginList::find(const char* findpath) +MPlugin* MPluginList::find(const char* findpath) { if (!findpath) return nullptr; META_DEBUG(8, "Looking for loaded plugin with path: %s", findpath); - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { META_DEBUG(9, "Looking at: plugin %s loadedpath: %s", m_plist[i].m_file, m_plist[i].m_pathname); if (m_plist[i].m_status < PL_VALID) continue; - if (!Q_strcmp(m_plist[i].m_pathname, findpath)) - { + if (!Q_strcmp(m_plist[i].m_pathname, findpath)) { META_DEBUG(8, "Found loaded plugin %s", m_plist[i].m_file); return &m_plist[i]; } @@ -101,7 +96,7 @@ MPlugin *MPluginList::find(const char* findpath) } // Find a plugin that uses the given memory location. -MPlugin *MPluginList::find_memloc(void *memptr) +MPlugin* MPluginList::find_memloc(void* memptr) { for (int i = 0; i < m_max_loaded_count; i++) { auto iplug = &m_plist[i]; @@ -115,7 +110,7 @@ MPlugin *MPluginList::find_memloc(void *memptr) // Find a plugin with non-ambiguous prefix string matching desc, file, // name, or logtag. -MPlugin *MPluginList::find_match(const char *prefix, bool& unique) +MPlugin* MPluginList::find_match(const char* prefix, bool& unique) { if (!prefix) { return nullptr; @@ -124,8 +119,7 @@ MPlugin *MPluginList::find_match(const char *prefix, bool& unique) MPlugin* pfound = nullptr; size_t len = Q_strlen(prefix); - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { auto plug = &m_plist[i]; if (plug->m_status < PL_VALID) continue; @@ -133,8 +127,7 @@ MPlugin *MPluginList::find_match(const char *prefix, bool& unique) if (plug->info() && !Q_strnicmp(plug->info()->name, prefix, len) || !Q_strnicmp(plug->m_desc, prefix, len) || !Q_strnicmp(plug->m_file, prefix, len) - || plug->info() && !Q_strnicmp(plug->info()->logtag, prefix, len)) - { + || plug->info() && !Q_strnicmp(plug->info()->logtag, prefix, len)) { if (pfound) { unique = false; break; @@ -150,14 +143,13 @@ MPlugin *MPluginList::find_match(const char *prefix, bool& unique) // Find a plugin with same file, logtag, desc or significant // prefix of file. Uses the platform_match() method of MPlugin. -MPlugin *MPluginList::find_match(MPlugin* pmatch) +MPlugin* MPluginList::find_match(MPlugin* pmatch) { if (!pmatch) { return nullptr; } - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { auto plug = &m_plist[i]; if (pmatch->platform_match(plug)) { @@ -187,28 +179,23 @@ MPlugin* MPluginList::plugin_addload(plid_t plid, const char* fname, PLUG_LOADTI } auto pl_found = find(pl_temp.m_pathname); - if (pl_found) - { + if (pl_found) { META_DEBUG(1, "Plugin '%s' already in current list; file=%s desc='%s'", pl_temp.m_file, pl_found->m_file, pl_found->m_desc); return pl_found; } auto pl_added = add(&pl_temp); - if (!pl_added) - { + if (!pl_added) { META_DEBUG(1, "Couldn't add plugin '%s' to list; see log", pl_temp.m_desc); return nullptr; } pl_added->m_action = PA_LOAD; - if (!pl_added->load(now)) - { - if (pl_added->m_status == PL_OPENED) - { + if (!pl_added->load(now)) { + if (pl_added->m_status == PL_OPENED) { META_DEBUG(1, "Opened plugin '%s', but failed to attach; see log", pl_added->m_desc); } - else - { + else { META_DEBUG(1, "Couldn't load plugin '%s'; see log", pl_added->m_desc); } return nullptr; @@ -239,8 +226,7 @@ MPlugin* MPluginList::add(MPlugin* padd) auto iplug = find_empty_slot(); // couldn't find a slot to use - if (!iplug) - { + if (!iplug) { META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)", padd->m_file, MAX_PLUGINS); return nullptr; } @@ -276,23 +262,20 @@ bool MPluginList::ini_startup() char line[MAX_STRBUF_LEN]; int n, ln; - if (!is_file_exists_in_gamedir(m_inifile)) - { + if (!is_file_exists_in_gamedir(m_inifile)) { META_ERROR("ini: Metamod plugins file empty or missing: %s", m_inifile); return false; } full_gamedir_path(m_inifile, m_inifile); FILE* fp = fopen(m_inifile, "r"); - if (!fp) - { + if (!fp) { META_ERROR("ini: Unable to open plugins file '%s': %s", m_inifile, strerror(errno)); return false; } META_LOG("ini: Begin reading plugins list: %s", m_inifile); - for (n = 0, ln = 1; !feof(fp) && fgets(line, sizeof line, fp) && n < MAX_PLUGINS; ln++) - { + for (n = 0 , ln = 1; !feof(fp) && fgets(line, sizeof line, fp) && n < MAX_PLUGINS; ln++) { // Remove line terminations. char* cp; if ((cp = Q_strrchr(line, '\r'))) @@ -304,10 +287,9 @@ bool MPluginList::ini_startup() // Parse directly into next entry in array if (!m_plist[n].ini_parseline(line)) continue; - + // Check for a duplicate - an existing entry with this pathname. - if (find(m_plist[n].m_pathname)) - { + if (find(m_plist[n].m_pathname)) { // Should we check platform specific level here? META_INFO("ini: Skipping duplicate plugin, line %d of %s: %s", ln, m_inifile, m_plist[n].m_pathname); continue; @@ -316,8 +298,7 @@ bool MPluginList::ini_startup() // Check for a matching platform with different platform specifics // level. auto pmatch = find_match(&m_plist[n]); - if (pmatch) - { + if (pmatch) { META_DEBUG(1, "ini: Plugin in line %d overrides existing plugin", ln); int index = pmatch->m_index; Q_memset(pmatch, 0, sizeof(MPlugin)); @@ -344,17 +325,15 @@ bool MPluginList::ini_refresh() int n, ln; FILE* fp = fopen(m_inifile, "r"); - if (!fp) - { + if (!fp) { META_ERROR("ini: Unable to open plugins file '%s': %s", m_inifile, strerror(errno)); return false; } META_LOG("ini: Begin re-reading plugins list: %s", m_inifile); - for (n = 0 , ln = 1; !feof(fp) && fgets(line, sizeof line, fp) && n < MAX_PLUGINS; ln++) - { + for (n = 0 , ln = 1; !feof(fp) && fgets(line, sizeof line, fp) && n < MAX_PLUGINS; ln++) { // Remove line terminations. - char *cp; + char* cp; if ((cp = Q_strrchr(line, '\r'))) *cp = '\0'; @@ -363,38 +342,32 @@ bool MPluginList::ini_refresh() // Parse into a temp plugin MPlugin pl_temp = {}; - if (!pl_temp.ini_parseline(line)) - { - META_ERROR("ini: Skipping malformed line %d of %s",ln, m_inifile); + if (!pl_temp.ini_parseline(line)) { + META_ERROR("ini: Skipping malformed line %d of %s", ln, m_inifile); continue; } // Try to find plugin with this pathname in the current list of // plugins. auto pl_found = find(pl_temp.m_pathname); - if (!pl_found) - { + if (!pl_found) { // Check for a matching platform with higher platform specifics // level. pl_found = find_match(&pl_temp); - if (pl_found) - { - if (pl_found->m_action == PA_LOAD) - { + if (pl_found) { + if (pl_found->m_action == PA_LOAD) { META_DEBUG(1, "ini: Plugin in line %d overrides loading of plugin", ln); int _index = pl_found->m_index; Q_memset(pl_found, 0, sizeof(MPlugin)); pl_found->m_index = _index; } - else - { + else { META_DEBUG(1, "ini: Plugin in line %d should override existing plugin. Unable to comply.", ln); continue; } } // new plugin; add to list auto pl_added = add(&pl_temp); - if (pl_added) - { + if (pl_added) { // try to load this plugin at the next opportunity pl_added->m_action = PA_LOAD; } @@ -402,26 +375,22 @@ bool 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.m_desc[0] != '<') - { + if (pl_temp.m_desc[0] != '<') { Q_strncpy(pl_found->m_desc, pl_temp.m_desc, sizeof pl_found->m_desc - 1); pl_found->m_desc[sizeof pl_found->m_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 (!pl_found->newer_file()) { pl_found->m_action = PA_KEEP; } // Newer file on disk. - else if (pl_found->m_status >= PL_OPENED) - { + else if (pl_found->m_status >= PL_OPENED) { META_DEBUG(2, "ini: Plugin '%s' has newer file on disk", pl_found->m_desc); pl_found->m_action = PA_RELOAD; } @@ -449,16 +418,14 @@ bool MPluginList::ini_refresh() bool MPluginList::cmd_addload(const char* args) { MPlugin pl_temp = {}; - if (!pl_temp.cmd_parseline(args)) - { + if (!pl_temp.cmd_parseline(args)) { META_CONS("Couldn't parse 'meta load' arguments: %s", args); return false; } // resolve given path into a file; accepts various "shortcut" // pathnames. - if (!pl_temp.resolve()) - { + if (!pl_temp.resolve()) { // Couldn't find a matching file on disk META_CONS("Couldn't resolve given path into a file: %s", pl_temp.m_file); return false; @@ -467,24 +434,21 @@ bool MPluginList::cmd_addload(const char* args) // Try to find plugin with this pathname in the current list of // plugins. auto pl_found = find(pl_temp.m_pathname); - if (pl_found) - { + if (pl_found) { // Already in list META_CONS("Plugin '%s' already in current list; file=%s desc='%s'", pl_temp.m_file, pl_found->m_file, pl_found->m_desc); return false; } // new plugin; add to list auto pl_added = add(&pl_temp); - if (!pl_added) - { + if (!pl_added) { META_CONS("Couldn't add plugin '%s' to list; see log", pl_temp.m_desc); return false; } // try to load new plugin pl_added->m_action = PA_LOAD; - if (!pl_added->load(PT_ANYTIME)) - { + if (!pl_added->load(PT_ANYTIME)) { // load failed if (pl_added->m_status == PL_OPENED) META_CONS("Opened plugin '%s', but failed to attach; see log", pl_added->m_desc); @@ -505,22 +469,20 @@ bool MPluginList::cmd_addload(const char* args) bool MPluginList::load() { int n = 0; - if (!ini_startup()) - { + if (!ini_startup()) { META_ERROR("Problem loading plugins.ini: %s", m_inifile); return false; } META_LOG("dll: Loading plugins..."); - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { if (m_plist[i].m_status < PL_VALID) continue; if (m_plist[i].load(PT_STARTUP)) n++; else - // all plugins should be loadable at startup... + // all plugins should be loadable at startup... META_ERROR("dll: Failed to load plugin '%s'", m_plist[i].m_file); } @@ -534,21 +496,18 @@ bool MPluginList::refresh(PLUG_LOADTIME now) { int ndone = 0, nkept = 0, nloaded = 0, nunloaded = 0, nreloaded = 0, ndelayed = 0; - if (!ini_refresh()) - { + if (!ini_refresh()) { META_ERROR("dll: Problem reloading plugins.ini: %s", m_inifile); return false; } META_LOG("dll: Updating plugins..."); - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { auto iplug = &m_plist[i]; if (iplug->m_status < PL_VALID) continue; - switch (iplug->m_action) - { + switch (iplug->m_action) { case PA_KEEP: META_DEBUG(1, "Keeping plugin '%s'", iplug->m_desc); iplug->m_action = PA_NONE; @@ -570,8 +529,7 @@ bool MPluginList::refresh(PLUG_LOADTIME now) break; case PA_NONE: // If previously loaded from ini, but apparently removed from new ini. - if (iplug->m_source == PS_INI && iplug->m_status >= PL_RUNNING) - { + if (iplug->m_source == PS_INI && iplug->m_status >= PL_RUNNING) { META_DEBUG(1, "Unloading plugin '%s'", iplug->m_desc); iplug->m_action = PA_UNLOAD; if (iplug->unload(now, PNL_INI_DELETED)) @@ -614,8 +572,7 @@ bool MPluginList::refresh(PLUG_LOADTIME now) // Re-enable any plugins currently paused. void MPluginList::unpause_all() { - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { auto iplug = &m_plist[i]; if (iplug->m_status == PL_PAUSED) iplug->unpause(); @@ -626,8 +583,7 @@ void MPluginList::unpause_all() // until changelevel. void MPluginList::retry_all(PLUG_LOADTIME now) { - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { auto iplug = &m_plist[i]; if (iplug->m_action != PA_NONE) iplug->retry(now, PNL_DELAYED); @@ -638,7 +594,7 @@ void MPluginList::retry_all(PLUG_LOADTIME now) void MPluginList::show(int source_index) { int n = 0, r = 0; - char desc[15 + 1], file[16 + 1], vers[7 + 1]; // plus 1 for term null + char desc[15 + 1], file[16 + 1], vers[7 + 1]; // plus 1 for term null if (source_index <= 0) META_CONS("Currently loaded plugins:"); @@ -646,10 +602,9 @@ void MPluginList::show(int source_index) META_CONS("Child plugins:"); 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"); + sizeof file - 1, "file", sizeof vers - 1, "ers", 2 + WIDTH_MAX_PLUGINS, "src", "load ", "unlod"); - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { auto pl = &m_plist[i]; if (pl->m_status < PL_VALID) continue; @@ -663,20 +618,18 @@ void MPluginList::show(int source_index) Q_strncpy(file, pl->m_file, sizeof file - 1); file[sizeof file - 1] = '\0'; - if (pl->info() && pl->info()->version) - { + if (pl->info() && pl->info()->version) { Q_strncpy(vers, pl->info()->version, sizeof vers - 1); vers[sizeof vers - 1] = '\0'; } - else - { + else { Q_strncpy(vers, " -", sizeof vers - 1); vers[sizeof vers - 1] = '\0'; } META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-*s %-5s %-5s", WIDTH_MAX_PLUGINS, pl->m_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)); + 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->m_status == PL_RUNNING) r++; @@ -691,24 +644,23 @@ void MPluginList::show(int source_index) // - Shows only "running" plugins, skipping any failed or paused plugins. // - Limited info about each plugin, mostly the "public" info (name, author, // etc). -void MPluginList::show_client(edict_t *pEntity) +void MPluginList::show_client(edict_t* pEntity) { int n = 0; META_CLIENT(pEntity, "Currently running plugins:"); - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { auto pl = &m_plist[i]; if (pl->m_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 : ""); + 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); @@ -719,8 +671,7 @@ bool MPluginList::found_child_plugins(int source_index) const if (source_index <= 0) return false; - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { if (m_plist[i].m_status < PL_VALID) continue; @@ -736,8 +687,7 @@ void MPluginList::clear_source_plugin_index(int source_index) if (source_index <= 0) return; - for (int i = 0; i < m_max_loaded_count; i++) - { + for (int i = 0; i < m_max_loaded_count; i++) { if (m_plist[i].m_status < PL_VALID) continue; diff --git a/metamod/src/mlist.h b/metamod/src/mlist.h index 4781f6f..7c50229 100644 --- a/metamod/src/mlist.h +++ b/metamod/src/mlist.h @@ -15,38 +15,38 @@ class MPluginList { public: - MPluginList(const char *ifile); + MPluginList(const char* ifile); - MPlugin *getlist(); + MPlugin* getlist(); int getmaxcount() const; - 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, bool& unique); // find by partial prefix match - MPlugin *find_match(MPlugin *pmatch); // find by platform_match() - MPlugin *find(module_handle_t handle); // find by handle - MPlugin *find_empty_slot(); - MPlugin *add(MPlugin *padd); + 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, bool& unique); // find by partial prefix match + MPlugin* find_match(MPlugin* pmatch); // find by platform_match() + MPlugin* find(module_handle_t handle); // find by handle + MPlugin* find_empty_slot(); + MPlugin* add(MPlugin* padd); bool found_child_plugins(int source_index) const; - bool ini_startup(); // read inifile at startup - bool ini_refresh(); // re-read inifile - bool cmd_addload(const char *args); // load from console command - MPlugin *plugin_addload(plid_t plid, const char *fname, PLUG_LOADTIME now); //load from plugin + bool ini_startup(); // read inifile at startup + bool ini_refresh(); // re-read inifile + bool cmd_addload(const char* args); // load from console command + MPlugin* plugin_addload(plid_t plid, const char* fname, PLUG_LOADTIME now); //load from plugin - bool load(); // load the list, at startup - bool refresh(PLUG_LOADTIME now); // update from re-read inifile - void unpause_all(); // 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 + bool load(); // load the list, at startup + bool refresh(PLUG_LOADTIME now); // update from re-read inifile + void unpause_all(); // 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); private: - int m_max_loaded_count; // index of last used entry - MPlugin m_plist[MAX_PLUGINS]; // array of plugins - char m_inifile[PATH_MAX]; // full pathname + int m_max_loaded_count; // index of last used entry + MPlugin m_plist[MAX_PLUGINS]; // array of plugins + char m_inifile[PATH_MAX]; // full pathname }; diff --git a/metamod/src/mplayer.cpp b/metamod/src/mplayer.cpp index 120b141..7d1449b 100644 --- a/metamod/src/mplayer.cpp +++ b/metamod/src/mplayer.cpp @@ -7,13 +7,12 @@ MPlayer::MPlayer() : m_isQueried(false) // 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) { return; } @@ -23,7 +22,7 @@ void MPlayer::set_cvar_query(const char *cvar) } // Unmark player as querying a client cvar -void MPlayer::clear_cvar_query(const char *cvar) +void MPlayer::clear_cvar_query(const char* cvar) { m_isQueried = false; g_cvarName[0] = '\0'; @@ -32,10 +31,9 @@ void MPlayer::clear_cvar_query(const char *cvar) // 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() const +const char* MPlayer::is_querying_cvar() const { - if (m_isQueried) - { + if (m_isQueried) { return g_cvarName; } @@ -45,7 +43,7 @@ const char *MPlayer::is_querying_cvar() const // 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 <= gpGlobals->maxClients) @@ -53,7 +51,7 @@ void MPlayerList::set_player_cvar_query(const edict_t *pEntity, const char *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 <= gpGlobals->maxClients) @@ -62,8 +60,7 @@ void MPlayerList::clear_player_cvar_query(const edict_t *pEntity, const char *cv void MPlayerList::clear_all_cvar_queries() { - for (int indx = 1; indx <= gpGlobals->maxClients; indx++) - { + for (int indx = 1; indx <= gpGlobals->maxClients; indx++) { m_players[indx].clear_cvar_query(); } } @@ -73,7 +70,7 @@ void MPlayerList::clear_all_cvar_queries() // 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 <= gpGlobals->maxClients) diff --git a/metamod/src/mplayer.h b/metamod/src/mplayer.h index d62eca6..8e3f4da 100644 --- a/metamod/src/mplayer.h +++ b/metamod/src/mplayer.h @@ -6,13 +6,13 @@ 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 = nullptr); // unmark this player as querying a client cvar - const char *is_querying_cvar() 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: - bool m_isQueried; // is this player currently queried for a cvar value - char g_cvarName[64]; // name of the cvar if getting queried + bool m_isQueried; // is this player currently queried for a cvar value + char g_cvarName[64]; // name of the cvar if getting queried }; // A list of players. The number of max players is fixed and small enough @@ -20,12 +20,12 @@ private: 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 = nullptr); + 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; + const char* is_querying_cvar(const edict_t* pEntity) const; private: int m_maxplayers = 32; - MPlayer m_players[MAX_CLIENTS + 1]; // array of players + MPlayer m_players[MAX_CLIENTS + 1]; // array of players }; diff --git a/metamod/src/mplugin.cpp b/metamod/src/mplugin.cpp index fd2264c..86c2998 100644 --- a/metamod/src/mplugin.cpp +++ b/metamod/src/mplugin.cpp @@ -1,12 +1,12 @@ #include "precompiled.h" const char *MPlugin::s_rPrintLoadTime[][4] = { - // 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 + // 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 }; // ReSharper disable once CppPossiblyUninitializedMember @@ -70,14 +70,12 @@ bool MPlugin::ini_parseline(char *line) // Grab description. // Just get the the rest of the line, minus line-termination. token = strtok_r(nullptr, "\n\r", &ptr_token); - if (token) - { + if (token) { token = token + strspn(token, " \t"); // skip whitespace Q_strncpy(m_desc, token, sizeof m_desc - 1); m_desc[sizeof m_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. Q_snprintf(m_desc, sizeof m_desc, "<%s>", m_file); @@ -550,12 +548,11 @@ bool MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) // try to reload again at next opportunity return false; } - else { - META_DEBUG(2, "dll: Failed reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", m_desc, str_loadable(), str_loadtime(now, SL_SIMPLE)); - // don't try to reload again later - m_action = PA_NONE; - return false; - } + + META_DEBUG(2, "dll: Failed reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", m_desc, str_loadable(), str_loadtime(now, SL_SIMPLE)); + // don't try to reload again later + m_action = PA_NONE; + return false; } if (m_status < PL_RUNNING) { @@ -697,7 +694,7 @@ bool MPlugin::plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON rea META_WARNING("dll: Not unloading plugin '%s'; Plugin is unloading plugin that tried to unload it.", m_desc); return false; } - + m_unloader_index = pl_unloader->index(); //block unloader from being unloaded by other plugin @@ -744,8 +741,7 @@ bool MPlugin::query() // engine functions like AlertMessage, which have to be passed along via // GiveFnptrsToDll. auto pfn_query = (META_QUERY_FN)m_sys_module.getsym("Meta_Query"); - if (!pfn_query) - { + if (!pfn_query) { META_ERROR("dll: Failed query plugin '%s'; Couldn't find Meta_Query(): %s", m_desc, "function not found"); // caller will dlclose() return false; @@ -766,21 +762,18 @@ bool MPlugin::query() // plugin can NOT use any g_engine functions, as they haven't been // provided yet (done next, in GiveFnptrsToDll). auto pfn_init = (META_INIT_FN)m_sys_module.getsym("Meta_Init"); - if (pfn_init) - { + if (pfn_init) { pfn_init(); META_DEBUG(6, "dll: Plugin '%s': Called Meta_Init()", m_desc); } - else - { + else { META_DEBUG(5, "dll: no Meta_Init present in plugin '%s'", m_desc); // don't return; not an error } // pass on engine function table and globals to plugin auto pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN)m_sys_module.getsym("GiveFnptrsToDll"); - if (!pfn_give_engfuncs) - { + if (!pfn_give_engfuncs) { META_ERROR("dll: Failed query plugin '%s'; Couldn't find GiveFnptrsToDll(): %s", m_desc, "function not found"); return false; } @@ -796,12 +789,10 @@ bool MPlugin::query() // same reason. Q_memcpy(&m_mutil_funcs, &g_MetaUtilFunctions, sizeof m_mutil_funcs); - if (pfn_query(META_INTERFACE_VERSION, &m_info, &m_mutil_funcs) != TRUE) - { + if (pfn_query(META_INTERFACE_VERSION, &m_info, &m_mutil_funcs) != TRUE) { META_ERROR("dll: Failed query plugin '%s'; Meta_Query returned error", m_desc); } - else - { + else { META_DEBUG(6, "dll: Plugin '%s': Called Meta_Query() successfully", m_desc); } @@ -820,23 +811,20 @@ bool MPlugin::query() return false; } - if (Q_strcmp(m_info->ifvers, META_INTERFACE_VERSION)) - { + if (Q_strcmp(m_info->ifvers, META_INTERFACE_VERSION)) { int mmajor, mminor, pmajor, pminor; META_DEBUG(3, "dll: Note: Plugin '%s' interface version didn't match; expected %s, found %s", m_desc, META_INTERFACE_VERSION, m_info->ifvers); sscanf(META_INTERFACE_VERSION, "%i:%i", &mmajor, &mminor); sscanf(m_info->ifvers, "%i:%i", &pmajor, &pminor); // 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)", m_desc, m_info->ifvers, META_INTERFACE_VERSION); return false; } // If plugin has older major interface version, it's incompatible // (update plugin). - if (pmajor < mmajor) - { + 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)", m_desc, META_INTERFACE_VERSION, m_info->ifvers); return false; } @@ -855,8 +843,7 @@ bool MPlugin::query() } // Replace temporary desc with plugin's internal name. - if (m_desc[0] == '<') - { + if (m_desc[0] == '<') { Q_strncpy(m_desc, m_info->name, sizeof m_desc - 1); m_desc[sizeof m_desc - 1] = '\0'; } @@ -934,29 +921,24 @@ bool 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 (g_GameDLL.funcs.dllapi_table && !m_gamedll_funcs.dllapi_table) - { + if (g_GameDLL.funcs.dllapi_table && !m_gamedll_funcs.dllapi_table) { m_gamedll_funcs.dllapi_table = (DLL_FUNCTIONS *)Q_malloc(sizeof(DLL_FUNCTIONS)); - if (!m_gamedll_funcs.dllapi_table) - { + if (!m_gamedll_funcs.dllapi_table) { META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for dllapi_table"); return false; } Q_memcpy(m_gamedll_funcs.dllapi_table, g_GameDLL.funcs.dllapi_table, sizeof(DLL_FUNCTIONS)); } - if (g_GameDLL.funcs.newapi_table && !m_gamedll_funcs.newapi_table) - { + if (g_GameDLL.funcs.newapi_table && !m_gamedll_funcs.newapi_table) { m_gamedll_funcs.newapi_table = (NEW_DLL_FUNCTIONS *)Q_malloc(sizeof(NEW_DLL_FUNCTIONS)); - if (!m_gamedll_funcs.newapi_table) - { + if (!m_gamedll_funcs.newapi_table) { META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for newapi_table"); return false; } Q_memcpy(m_gamedll_funcs.newapi_table, g_GameDLL.funcs.newapi_table, sizeof(NEW_DLL_FUNCTIONS)); } auto pfn_attach = (META_ATTACH_FN)m_sys_module.getsym("Meta_Attach"); - if (!pfn_attach) - { + if (!pfn_attach) { META_ERROR("dll: Failed attach plugin '%s': Couldn't find Meta_Attach(): %s", m_desc, "function not found"); return false; } @@ -966,8 +948,7 @@ bool MPlugin::attach(PLUG_LOADTIME now) // get table of function tables, // give public meta globals qboolean ret = pfn_attach(now, &meta_table, &g_metaGlobals, &m_gamedll_funcs); - if (ret != TRUE) - { + if (ret != TRUE) { META_ERROR("dll: Failed attach plugin '%s': Error from Meta_Attach(): %d", m_desc, ret); return false; } @@ -1014,16 +995,14 @@ bool MPlugin::detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) return true; auto pfn_detach = (META_DETACH_FN)m_sys_module.getsym("Meta_Detach"); - if (!pfn_detach) - { + if (!pfn_detach) { META_ERROR("dll: Error detach plugin '%s': Couldn't find Meta_Detach(): %s", m_desc, "function not found"); // caller will dlclose() return false; } int ret = pfn_detach(now, reason); - if (ret != TRUE) - { + if (ret != TRUE) { META_ERROR("dll: Failed detach plugin '%s': Error from Meta_Detach(): %d", m_desc, ret); return false; } @@ -1118,7 +1097,7 @@ bool MPlugin::newer_file() const META_DEBUG(5, "newer_file? file=%s; load=%d, file=%d; ctime=%d, mtime=%d", m_file, m_time_loaded, file_time, st.st_ctime, st.st_mtime); if (file_time > m_time_loaded) return true; - + return false; } @@ -1134,7 +1113,7 @@ const char *MPlugin::str_status(STR_STATUS fmt) const case PL_BADFILE: return show ? "badf" : "badfile"; case PL_OPENED: return show ? "open" : "opened"; case PL_FAILED: return show ? "fail" : "failed"; - case PL_RUNNING: return show ? "RUN" : "running"; + case PL_RUNNING: return show ? "RUN" : "running"; case PL_PAUSED: return show ? "PAUS" : "paused"; default: return UTIL_VarArgs(show ? "UNK%d" : "unknown (%d)", m_status); } @@ -1146,16 +1125,15 @@ const char *MPlugin::str_status(STR_STATUS fmt) const const char *MPlugin::str_action(STR_ACTION fmt) const { bool show = fmt == ST_SHOW; - switch (m_action) - { - case PA_NULL: return "null"; - case PA_NONE: return show ? " - " : "none"; - case PA_KEEP: return "keep"; - case PA_LOAD: return "load"; - case PA_ATTACH: return show ? "atch" : "attach"; - case PA_UNLOAD: return show ? "unld" : "unload"; - case PA_RELOAD: return show ? "relo" : "reload"; - default: return UTIL_VarArgs(show ? "UNK%d" : "unknown (%d)", m_action); + switch (m_action) { + case PA_NULL: return "null"; + case PA_NONE: return show ? " - " : "none"; + case PA_KEEP: return "keep"; + case PA_LOAD: return "load"; + case PA_ATTACH: return show ? "atch" : "attach"; + case PA_UNLOAD: return show ? "unld" : "unload"; + case PA_RELOAD: return show ? "relo" : "reload"; + default: return UTIL_VarArgs(show ? "UNK%d" : "unknown (%d)", m_action); } } @@ -1167,9 +1145,9 @@ const char *MPlugin::str_source(STR_SOURCE fmt) const case PS_INI: return show ? "ini" : "ini file"; case PS_CMD: return show ? "cmd" : "console command"; case PS_PLUGIN: - if (m_source_plugin_index <= 0) - return show ? "plUN" : "unloaded plugin"; - return show ? UTIL_VarArgs("pl%d", m_source_plugin_index) : UTIL_VarArgs("plugin [%s]", g_plugins->find(m_source_plugin_index)->description()); + if (m_source_plugin_index <= 0) + return show ? "plUN" : "unloaded plugin"; + return show ? UTIL_VarArgs("pl%d", m_source_plugin_index) : UTIL_VarArgs("plugin [%s]", g_plugins->find(m_source_plugin_index)->description()); default: return UTIL_VarArgs(show ? "UNK%d" : "unknown (%d)", m_source); } } diff --git a/metamod/src/mplugin.h b/metamod/src/mplugin.h index 075090b..3aad46f 100644 --- a/metamod/src/mplugin.h +++ b/metamod/src/mplugin.h @@ -6,7 +6,7 @@ // NOTE: order is important, as greater/less comparisons are made. enum PLUG_STATUS : uint8 { - PL_EMPTY, // empty slot + PL_EMPTY, // empty slot PL_VALID, // has valid info in it PL_BADFILE, // nonexistent file (open failed), or not a valid plugin file (query failed) PL_OPENED, // dlopened and queried @@ -30,7 +30,7 @@ enum PLUG_ACTION : uint8 // Flags to indicate from where the plugin was loaded. enum PLOAD_SOURCE : uint8 { - PS_INI, // was loaded from the plugins.ini + PS_INI, // was loaded from the plugins.ini PS_CMD, // was loaded via a server command PS_PLUGIN, // was loaded by other plugin }; @@ -38,7 +38,7 @@ enum PLOAD_SOURCE : uint8 // Flags for how to word description of plugin loadtime. enum STR_LOADTIME : uint8 { - SL_SIMPLE = 0, // single word + SL_SIMPLE, // single word SL_SHOW, // for "show" output, 5 chars SL_ALLOWED, // when plugin is allowed to load/unload SL_NOW, // current situation @@ -78,28 +78,28 @@ public: MPlugin(); MPlugin(int index); - bool ini_parseline(char *line); // parse line from .ini file - bool cmd_parseline(const char *line); // parse from console command - bool plugin_parseline(const char *fname, int loader_index); // parse from plugin - bool check_input(); // check filename, path, status + bool ini_parseline(char *line); // parse line from .ini file + bool cmd_parseline(const char *line); // parse from console command + bool plugin_parseline(const char *fname, int loader_index); // parse from plugin + bool check_input(); // check filename, path, status bool resolve(); // find a matching file on disk char *resolve_dirs(const char *path, char *tempbuf, size_t bufsize) const; // try resolve filename in different dirs char *resolve_suffix(const char *path, char *tempbuf, size_t bufsize) const; // try resolve given filename with different suffixes - bool platform_match(MPlugin* plugin) const; // check if a given plugin is the same but possibly for a different platform + bool platform_match(MPlugin* plugin) const; // check if a given plugin is the same but possibly for a different platform - bool load(PLUG_LOADTIME now); // load parsed plugin + bool load(PLUG_LOADTIME now); // load parsed plugin bool unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason); bool reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason); bool pause(); bool unpause(); - bool retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // if previously failed + bool retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // if previously failed bool clear(); bool plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // other plugin unloading - void show(); // print info about plugin to console + void show(); // print info about plugin to console - bool newer_file() const; // check for newer file on disk + bool newer_file() const; // check for newer file on disk const char *str_status(STR_STATUS fmt = ST_SIMPLE) const; const char *str_action(STR_ACTION fmt = SA_SIMPLE) const; @@ -126,8 +126,8 @@ public: void set_action(PLUG_ACTION action); private: - bool query(); // check exports, call init, getfnptrs and query - bool attach(PLUG_LOADTIME now); // call attach + bool query(); // check exports, call init, getfnptrs and query + bool attach(PLUG_LOADTIME now); // call attach bool detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // call detach PLUG_STATUS m_status; // current status of plugin (loaded, etc) diff --git a/metamod/src/mreg.cpp b/metamod/src/mreg.cpp index db53082..1b0b554 100644 --- a/metamod/src/mreg.cpp +++ b/metamod/src/mreg.cpp @@ -18,7 +18,8 @@ bool MRegCmd::call() const void MRegCmd::disable() { - m_pfunction = [](){}; + m_pfunction = []() { + }; m_plugid = 0; m_status = RG_INVALID; } @@ -44,10 +45,9 @@ MRegCmdList::~MRegCmdList() } } -MRegCmd *MRegCmdList::find(const char *name) const +MRegCmd* MRegCmdList::find(const char* name) const { - for (auto reg : m_list) - { + for (auto reg : m_list) { if (!Q_stricmp(reg->m_name, name)) return reg; } @@ -55,7 +55,7 @@ MRegCmd *MRegCmdList::find(const char *name) const return nullptr; } -MRegCmd *MRegCmdList::add(char *addname, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin) +MRegCmd* MRegCmdList::add(char* addname, REG_CMD_FN cmd_handler, MPlugin* cmd_plugin) { auto reg = new MRegCmd(addname, cmd_handler, cmd_plugin); m_list.push_back(reg); @@ -106,17 +106,14 @@ void MRegCmdList::show() const META_CONS("Registered plugin commands:"); META_CONS(" %*s %-*s %-s", WIDTH_MAX_REG, "", sizeof bplug - 1, "plugin", "command"); - for (auto reg : m_list) - { - if (reg->m_status == RG_VALID) - { + for (auto reg : m_list) { + if (reg->m_status == RG_VALID) { auto iplug = g_plugins->find(reg->m_plugid); Q_strncpy(bplug, iplug ? iplug->description() : "(unknown)", sizeof bplug - 1); bplug[sizeof bplug - 1] = '\0'; } - else - { + else { Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1); bplug[sizeof bplug - 1] = '\0'; } @@ -137,8 +134,7 @@ void MRegCmdList::show(int plugin_id) const META_CONS("Registered commands:"); - for (auto reg : m_list) - { + for (auto reg : m_list) { if (reg->m_plugid != plugin_id) continue; @@ -183,17 +179,16 @@ MRegCvarList::~MRegCvarList() } } -MRegCvar *MRegCvarList::add(cvar_t* src, MPlugin* plugin) +MRegCvar* MRegCvarList::add(cvar_t* src, MPlugin* plugin) { - MRegCvar *reg_cvar = new MRegCvar(src, plugin); + MRegCvar* reg_cvar = new MRegCvar(src, plugin); m_list.push_back(reg_cvar); return reg_cvar; } -MRegCvar *MRegCvarList::find(const char *findname) +MRegCvar* MRegCvarList::find(const char* findname) { - for (auto reg : m_list) - { + for (auto reg : m_list) { if (!Q_stricmp(reg->m_cvar->name, findname)) return reg; } @@ -204,10 +199,8 @@ MRegCvar *MRegCvarList::find(const char *findname) // Disable any cvars belonging to the given plugin (by index id). void MRegCvarList::disable(int plugin_id) const { - for (auto reg : m_list) - { - if (reg->m_plugid == plugin_id) - { + for (auto reg : m_list) { + if (reg->m_plugid == plugin_id) { reg->m_status = RG_INVALID; reg->m_plugid = 0; } @@ -222,17 +215,14 @@ void MRegCvarList::show() const 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 (auto reg : m_list) - { - if (reg->m_status == RG_VALID) - { + + for (auto reg : m_list) { + if (reg->m_status == RG_VALID) { auto plug = g_plugins->find(reg->m_plugid); Q_strncpy(bplug, plug ? plug->description() : "(unknown)", sizeof bplug - 1); bplug[sizeof bplug - 1] = '\0'; } - else - { + else { Q_strncpy(bplug, "(unloaded)", sizeof bplug - 1); bplug[sizeof bplug - 1] = '\0'; } @@ -256,9 +246,8 @@ void MRegCvarList::show(int plugin_id) const char bname[30 + 1], bval[15 + 1]; // +1 for term null META_CONS("%-*s %*s %s", sizeof bname - 1, "Registered cvars:", sizeof bval - 1, "float value", "string value"); - - for (auto reg : m_list) - { + + for (auto reg : m_list) { if (reg->m_plugid != plugin_id) continue; @@ -274,7 +263,6 @@ void MRegCvarList::show(int plugin_id) const MRegMsg::MRegMsg(const char* name, int msgid, int size) : m_name(name), m_msgid(msgid), m_size(size) { - } const char* MRegMsg::getname() const @@ -303,7 +291,7 @@ MRegMsgList::~MRegMsgList() } } -MRegMsg *MRegMsgList::add(const char *addname, int addmsgid, int addsize) +MRegMsg* MRegMsgList::add(const char* addname, int addmsgid, int addsize) { // Copy msg data into empty slot. // Note: 'addname' assumed to be a constant string allocated in the @@ -313,10 +301,9 @@ MRegMsg *MRegMsgList::add(const char *addname, int addmsgid, int addsize) return msg; } -MRegMsg *MRegMsgList::find(const char *findname) +MRegMsg* MRegMsgList::find(const char* findname) { - for (auto msg : m_list) - { + for (auto msg : m_list) { if (!Q_strcmp(msg->m_name, findname)) return msg; } @@ -324,7 +311,7 @@ MRegMsg *MRegMsgList::find(const char *findname) return nullptr; } -MRegMsg *MRegMsgList::find(int findmsgid) +MRegMsg* MRegMsgList::find(int findmsgid) { for (auto msg : m_list) { if (msg->m_msgid == findmsgid) @@ -341,7 +328,7 @@ void MRegMsgList::show() char bname[25 + 1]; // +1 for term null META_CONS("%-*s %5s %5s", sizeof bname - 1, "Game registered user msgs:", "msgid", "size"); - + for (auto msg : m_list) { Q_strncpy(bname, msg->m_name, sizeof bname - 1); bname[sizeof bname - 1] = '\0'; diff --git a/metamod/src/mreg.h b/metamod/src/mreg.h index 3efadbf..0245000 100644 --- a/metamod/src/mreg.h +++ b/metamod/src/mreg.h @@ -7,13 +7,23 @@ // 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). -#define WIDTH_MAX_REG 4 +enum +{ + WIDTH_MAX_REG = 4 +}; // Max number of registered user msgs we can manage. -#define MAX_REG_MSGS 256 +enum +{ + MAX_REG_MSGS = 256 +}; // Flags to indicate if given cvar or func is part of a loaded plugin. -enum REG_STATUS { RG_INVALID, RG_VALID }; +enum REG_STATUS +{ + RG_INVALID, + RG_VALID +}; // Pointer to function registered by AddServerCommand. typedef void (*REG_CMD_FN)(); diff --git a/metamod/src/mutil.cpp b/metamod/src/mutil.cpp index 3284afb..9b9abcd 100644 --- a/metamod/src/mutil.cpp +++ b/metamod/src/mutil.cpp @@ -73,7 +73,7 @@ static const char* g_engine_msg_names[] = }; // Log to console; newline added. -void EXT_FUNC mutil_LogConsole(plid_t plid, const char *fmt, ...) +void EXT_FUNC mutil_LogConsole(plid_t plid, const char* fmt, ...) { char buf[MAX_LOGMSG_LEN]; @@ -89,7 +89,7 @@ void EXT_FUNC mutil_LogConsole(plid_t plid, const char *fmt, ...) } // Log regular message to logs; newline added. -void EXT_FUNC mutil_LogMessage(plid_t plid, const char *fmt, ...) +void EXT_FUNC mutil_LogMessage(plid_t plid, const char* fmt, ...) { char buf[MAX_LOGMSG_LEN]; @@ -102,7 +102,7 @@ void EXT_FUNC mutil_LogMessage(plid_t plid, const char *fmt, ...) } // Log an error message to logs; newline added. -void EXT_FUNC mutil_LogError(plid_t plid, const char *fmt, ...) +void EXT_FUNC mutil_LogError(plid_t plid, const char* fmt, ...) { char buf[MAX_LOGMSG_LEN]; @@ -158,13 +158,12 @@ void EXT_FUNC mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const c mutil_LogMessage(plid, "(centersay) %s", buf); - for (int n = 1; n <= gpGlobals->maxClients; n++) - { + for (int n = 1; n <= gpGlobals->maxClients; n++) { auto pEntity = INDEXENT(n); if (FNullEnt(pEntity) || pEntity->free) continue; - + UTIL_HudMessage(pEntity, tparms, buf); } } @@ -172,13 +171,12 @@ void EXT_FUNC mutil_CenterSayVarargs(plid_t plid, hudtextparms_t tparms, const c // Allow plugins to call the entity functions in the GameDLL. In // particular, calling "player()" as needed by most Bots. Suggested by // Jussi Kivilinna. -qboolean EXT_FUNC mutil_CallGameEntity(plid_t plid, const char *entStr, entvars_t *pev) +qboolean EXT_FUNC mutil_CallGameEntity(plid_t plid, const char* entStr, entvars_t* pev) { META_DEBUG(8, "Looking up game entity '%s' for plugin '%s'", entStr, plid->name); ENTITY_FN pfnEntity = (ENTITY_FN)g_GameDLL.sys_module.getsym(entStr); - - if (!pfnEntity) - { + + if (!pfnEntity) { META_ERROR("Couldn't find game entity '%s' in game DLL '%s' for plugin '%s'", entStr, g_GameDLL.name, plid->name); return false; } @@ -194,10 +192,9 @@ int EXT_FUNC mutil_GetUserMsgID(plid_t plid, const char* msgname, int* size) { META_DEBUG(8, "Looking up usermsg name '%s' for plugin '%s'", msgname, plid->name); - MRegMsg *umsg = g_regMsgs->find(msgname); + MRegMsg* umsg = g_regMsgs->find(msgname); - if (umsg) - { + if (umsg) { if (size) *size = umsg->getsize(); return umsg->getid(); } @@ -208,35 +205,33 @@ int EXT_FUNC mutil_GetUserMsgID(plid_t plid, const char* msgname, int* size) return n; } } - + return 0; } // Find a usermsg, registered by the gamedll, with the corresponding // msgid, and return remaining info about it (msgname, size). -const char* EXT_FUNC mutil_GetUserMsgName(plid_t plid, int msgid, int *size) +const char* EXT_FUNC mutil_GetUserMsgName(plid_t plid, int msgid, int* size) { - plugin_info_t *plinfo = (plugin_info_t *)plid; + plugin_info_t* 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 < arraysize(g_engine_msg_names)) - { + if (msgid < arraysize(g_engine_msg_names)) { if (size) *size = -1; return g_engine_msg_names[msgid]; } - MRegMsg *umsg = g_regMsgs->find(msgid); - - if (umsg) - { + MRegMsg* umsg = g_regMsgs->find(msgid); + + if (umsg) { if (size) *size = umsg->getsize(); // 'name' is assumed to be a constant string, allocated in the // gamedll. return umsg->getname(); } - + return nullptr; } @@ -246,8 +241,7 @@ const char* EXT_FUNC mutil_GetPluginPath(plid_t plid) static char buf[PATH_MAX]; auto plug = g_plugins->find(plid); - if (!plug) - { + if (!plug) { META_ERROR("GetPluginPath: couldn't find plugin '%s'", plid->name); return nullptr; } @@ -261,10 +255,9 @@ const char* EXT_FUNC mutil_GetPluginPath(plid_t plid) const char* EXT_FUNC mutil_GetGameInfo(plid_t plid, ginfo_t type) { static char buf[MAX_STRBUF_LEN]; - const char *cp; + const char* cp; - switch (type) - { + switch (type) { case GINFO_NAME: cp = g_GameDLL.name; break; @@ -293,16 +286,14 @@ const char* EXT_FUNC mutil_GetGameInfo(plid_t plid, ginfo_t type) return buf; } -int EXT_FUNC mutil_LoadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, void **plugin_handle) +int EXT_FUNC mutil_LoadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, void** plugin_handle) { - if (!fname) - { + if (!fname) { return 1; } auto pl_loaded = g_plugins->plugin_addload(plid, fname, now); - if (!pl_loaded) - { + if (!pl_loaded) { if (plugin_handle) *plugin_handle = nullptr; @@ -317,16 +308,15 @@ int EXT_FUNC mutil_LoadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME return 0; } -int EXT_FUNC mutil_UnloadMetaPlugin(plid_t plid, const char *fname, PLUG_LOADTIME now, PL_UNLOAD_REASON reason) +int EXT_FUNC mutil_UnloadMetaPlugin(plid_t plid, const char* fname, PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { - MPlugin *findp; + MPlugin* findp; - if (!fname) - { + if (!fname) { return 1; } - char *endptr; + char* endptr; int pindex = strtol(fname, &endptr, 10); bool unique = true; @@ -346,10 +336,9 @@ int EXT_FUNC mutil_UnloadMetaPlugin(plid_t plid, const char *fname, PLUG_LOADTIM return 1; } -int EXT_FUNC mutil_UnloadMetaPluginByHandle(plid_t plid, void *plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason) +int EXT_FUNC mutil_UnloadMetaPluginByHandle(plid_t plid, void* plugin_handle, PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { - if (!plugin_handle) - { + if (!plugin_handle) { return 1; } @@ -391,22 +380,22 @@ void EXT_FUNC mutil_GetHookTables(plid_t plid, enginefuncs_t** peng, DLL_FUNCTIO // Meta Utility Function table. mutil_funcs_t g_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_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_IsQueryingClientCvar, // pfnIsQueryingClientCvar + mutil_MakeRequestId, // pfnMakeRequestId + mutil_GetHookTables, // pfnGetHookTables }; diff --git a/metamod/src/mutil.h b/metamod/src/mutil.h index e886ed6..37ec342 100644 --- a/metamod/src/mutil.h +++ b/metamod/src/mutil.h @@ -4,9 +4,6 @@ #include #include -// max buffer size for printed messages -#define MAX_LOGMSG_LEN 1024 - // For GetGameInfo: enum ginfo_t { @@ -26,18 +23,18 @@ struct mutil_funcs_t 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); }; @@ -64,21 +61,21 @@ int mutil_MakeRequestId(plid_t plid); void mutil_GetHookTables(plid_t plid, enginefuncs_t **peng, DLL_FUNCTIONS **pdll, NEW_DLL_FUNCTIONS **pnewdll); // Convenience macros for MetaUtil functions -#define LOG_CONSOLE (*gpMetaUtilFuncs->pfnLogConsole) -#define LOG_MESSAGE (*gpMetaUtilFuncs->pfnLogMessage) -#define LOG_ERROR (*gpMetaUtilFuncs->pfnLogError) -#define LOG_DEVELOPER (*gpMetaUtilFuncs->pfnLogDeveloper) -#define CENTER_SAY (*gpMetaUtilFuncs->pfnCenterSay) -#define CENTER_SAY_PARMS (*gpMetaUtilFuncs->pfnCenterSayParms) -#define CENTER_SAY_VARARGS (*gpMetaUtilFuncs->pfnCenterSayVarargs) -#define CALL_GAME_ENTITY (*gpMetaUtilFuncs->pfnCallGameEntity) -#define GET_USER_MSG_ID (*gpMetaUtilFuncs->pfnGetUserMsgID) -#define GET_USER_MSG_NAME (*gpMetaUtilFuncs->pfnGetUserMsgName) -#define GET_PLUGIN_PATH (*gpMetaUtilFuncs->pfnGetPluginPath) -#define GET_GAME_INFO (*gpMetaUtilFuncs->pfnGetGameInfo) -#define LOAD_PLUGIN (*gpMetaUtilFuncs->pfnLoadPlugin) -#define UNLOAD_PLUGIN (*gpMetaUtilFuncs->pfnUnloadPlugin) +#define LOG_CONSOLE (*gpMetaUtilFuncs->pfnLogConsole) +#define LOG_MESSAGE (*gpMetaUtilFuncs->pfnLogMessage) +#define LOG_ERROR (*gpMetaUtilFuncs->pfnLogError) +#define LOG_DEVELOPER (*gpMetaUtilFuncs->pfnLogDeveloper) +#define CENTER_SAY (*gpMetaUtilFuncs->pfnCenterSay) +#define CENTER_SAY_PARMS (*gpMetaUtilFuncs->pfnCenterSayParms) +#define CENTER_SAY_VARARGS (*gpMetaUtilFuncs->pfnCenterSayVarargs) +#define CALL_GAME_ENTITY (*gpMetaUtilFuncs->pfnCallGameEntity) +#define GET_USER_MSG_ID (*gpMetaUtilFuncs->pfnGetUserMsgID) +#define GET_USER_MSG_NAME (*gpMetaUtilFuncs->pfnGetUserMsgName) +#define GET_PLUGIN_PATH (*gpMetaUtilFuncs->pfnGetPluginPath) +#define GET_GAME_INFO (*gpMetaUtilFuncs->pfnGetGameInfo) +#define LOAD_PLUGIN (*gpMetaUtilFuncs->pfnLoadPlugin) +#define UNLOAD_PLUGIN (*gpMetaUtilFuncs->pfnUnloadPlugin) #define UNLOAD_PLUGIN_BY_HANDLE (*gpMetaUtilFuncs->pfnUnloadPluginByHandle) #define IS_QUERYING_CLIENT_CVAR (*gpMetaUtilFuncs->pfnIsQueryingClientCvar) -#define MAKE_REQUESTID (*gpMetaUtilFuncs->pfnMakeRequestId) -#define GET_HOOK_TABLES (*gpMetaUtilFuncs->pfnGetHookTables) +#define MAKE_REQUESTID (*gpMetaUtilFuncs->pfnMakeRequestId) +#define GET_HOOK_TABLES (*gpMetaUtilFuncs->pfnGetHookTables) diff --git a/metamod/src/osdep.cpp b/metamod/src/osdep.cpp index d825d8f..02db753 100644 --- a/metamod/src/osdep.cpp +++ b/metamod/src/osdep.cpp @@ -47,15 +47,15 @@ static ElfW(Addr) dlsize(void* base) ehdr = (ElfW(Ehdr) *)base; - /* Find the first program header */ +/* Find the first program header */ phdr = (ElfW(Phdr)*)((ElfW(Addr))ehdr + ehdr->e_phoff); - /* Find the final PT_LOAD segment's extent */ +/* Find the final PT_LOAD segment's extent */ for (int i = 0; i < ehdr->e_phnum; ++i) if (phdr[i].p_type == PT_LOAD) end = phdr[i].p_vaddr + phdr[i].p_memsz; - /* The start (virtual) address is always zero, so just return end.*/ +/* The start (virtual) address is always zero, so just return end.*/ return end; } @@ -135,7 +135,7 @@ const char* CSysModule::getloaderror() // http://msdn.microsoft.com/library/en-us/debug/errors_0sdh.asp // except without FORMAT_MESSAGE_ALLOCATE_BUFFER, since we use a local // static buffer. -static const char *str_GetLastError() +static const char* str_GetLastError() { static char buf[MAX_STRBUF_LEN]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, MAX_STRBUF_LEN - 1, nullptr); diff --git a/metamod/src/plinfo.h b/metamod/src/plinfo.h index 876429e..2fb30b0 100644 --- a/metamod/src/plinfo.h +++ b/metamod/src/plinfo.h @@ -5,10 +5,10 @@ enum PLUG_LOADTIME { PT_NEVER, - 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_ANYPAUSE, // can be loaded/unloaded at any time, and can be "paused" during a map + 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_ANYPAUSE, // can be loaded/unloaded at any time, and can be "paused" during a map }; // Flags to indicate why the plugin is being unloaded. @@ -21,24 +21,24 @@ enum PL_UNLOAD_REASON 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() + PNL_RELOAD, // forced unload by reload() }; // Information plugin provides about itself. 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) - PLUG_LOADTIME loadable; // when loadable - PLUG_LOADTIME unloadable; // when unloadable + 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) + PLUG_LOADTIME loadable; // when loadable + PLUG_LOADTIME unloadable; // when unloadable }; extern plugin_info_t Plugin_info; diff --git a/metamod/src/reg_support.cpp b/metamod/src/reg_support.cpp index bef7b25..afd536b 100644 --- a/metamod/src/reg_support.cpp +++ b/metamod/src/reg_support.cpp @@ -2,17 +2,15 @@ void EXT_FUNC meta_command_handler() { - const char *cmd = CMD_ARGV(0); - MRegCmd *icmd = g_regCmds->find(cmd); + const char* cmd = CMD_ARGV(0); + MRegCmd* icmd = g_regCmds->find(cmd); - if (!icmd) - { + if (!icmd) { META_ERROR("Couldn't find registered plugin command: %s", cmd); return; } - if (!icmd->call()) - { + if (!icmd->call()) { META_CONS("[metamod: command '%s' unavailable; plugin unloaded]", cmd); } } @@ -26,9 +24,9 @@ void EXT_FUNC meta_command_handler() // 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 EXT_FUNC meta_AddServerCommand(char *cmd_name, void (*function)()) +void EXT_FUNC meta_AddServerCommand(char* cmd_name, void (*function)()) { - MPlugin *plug = g_plugins->find_memloc(function); + MPlugin* plug = g_plugins->find_memloc(function); META_DEBUG(4, "called: meta_AddServerCommand; cmd_name=%s, function=%d, plugin=%s", cmd_name, function, plug ? plug->file() : "unknown"); @@ -38,8 +36,7 @@ void EXT_FUNC meta_AddServerCommand(char *cmd_name, void (*function)()) // See if this command was previously registered, ie a "reloaded" plugin. auto cmd = g_regCmds->find(cmd_name); - if (!cmd) - { + if (!cmd) { // If not found, add. cmd = g_regCmds->add(cmd_name, function, plug); REG_SVR_COMMAND(cmd->getname(), g_RehldsFuncs ? cmd->gethandler() : meta_command_handler); @@ -58,23 +55,21 @@ void EXT_FUNC meta_AddServerCommand(char *cmd_name, void (*function)()) // 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 EXT_FUNC meta_CVarRegister(cvar_t *pCvar) +void EXT_FUNC meta_CVarRegister(cvar_t* pCvar) { - MPlugin *plug = g_plugins->find_memloc(pCvar); + MPlugin* plug = g_plugins->find_memloc(pCvar); META_DEBUG(4, "called: meta_CVarRegister; name=%s", pCvar->name); // try to find which plugin is registering this cvar - if (!plug) - { + if (!plug) { META_DEBUG(1, "Failed to find memloc for regcvar '%s'", pCvar->name); } // See if this cvar was previously registered, ie a "reloaded" plugin. auto reg = g_regCvars->find(pCvar->name); - if (!reg) - { + if (!reg) { reg = g_regCvars->add(pCvar, plug); CVAR_REGISTER(reg->getcvar()); } @@ -93,14 +88,14 @@ void EXT_FUNC meta_CVarRegister(cvar_t *pCvar) // commands and cvars). This merely provides differently located storage // for the string. -int EXT_FUNC meta_RegUserMsg(const char *pszName, int iSize) +int EXT_FUNC meta_RegUserMsg(const char* pszName, int iSize) { - char *cp = Q_strdup(pszName); + char* cp = Q_strdup(pszName); return REG_USER_MSG(cp, iSize); } // Intercept and record queries -void EXT_FUNC meta_QueryClientCvarValue(const edict_t *player, const char *cvarName) +void EXT_FUNC 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 212da9e..1f5a70f 100644 --- a/metamod/src/reg_support.h +++ b/metamod/src/reg_support.h @@ -1,7 +1,7 @@ #pragma once 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); +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); diff --git a/metamod/src/sdk_util.cpp b/metamod/src/sdk_util.cpp index 5a979c9..6c473f8 100644 --- a/metamod/src/sdk_util.cpp +++ b/metamod/src/sdk_util.cpp @@ -1,6 +1,6 @@ #include "precompiled.h" -char *UTIL_VarArgs(const char *format, ...) +char* UTIL_VarArgs(const char* format, ...) { va_list argptr; static char string[1024]; @@ -22,7 +22,7 @@ unsigned short FixedUnsigned16(float value, float scale) return (unsigned short)clamp(int(value * scale), 0, USHRT_MAX); } -void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const char *pMessage) +void UTIL_HudMessage(edict_t* pEntity, const hudtextparms_t& textparms, const char* pMessage) { if (FNullEnt(pEntity) || pEntity->free) return; @@ -50,7 +50,7 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const ch WRITE_SHORT(FixedUnsigned16(textparms.holdTime, 1 << 8)); if (textparms.effect == 2) - WRITE_SHORT(FixedUnsigned16(textparms.fxTime, 1 << 8)); + WRITE_SHORT(FixedUnsigned16(textparms.fxTime, 1 << 8)); if (strlen(pMessage) < 512) { WRITE_STRING(pMessage); diff --git a/metamod/src/sdk_util.h b/metamod/src/sdk_util.h index 5141fe2..37a7318 100644 --- a/metamod/src/sdk_util.h +++ b/metamod/src/sdk_util.h @@ -13,5 +13,5 @@ #include "enginecallbacks.h" #include -char *UTIL_VarArgs(const char *format, ...); -void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const char *pMessage); +char* UTIL_VarArgs(const char* format, ...); +void UTIL_HudMessage(edict_t* pEntity, const hudtextparms_t& textparms, const char* pMessage); diff --git a/metamod/src/studioapi.cpp b/metamod/src/studioapi.cpp index dc7d664..ac77441 100644 --- a/metamod/src/studioapi.cpp +++ b/metamod/src/studioapi.cpp @@ -15,10 +15,10 @@ // http://www.mail-archive.com/hlcoders@list.valvesoftware.com/msg02724.html C_DLLEXPORT int Server_GetBlendingInterface(int version, - struct sv_blending_interface_s **ppinterface, - struct engine_studio_api_s *pstudio, - float (*rotationmatrix)[3][4], - float (*bonetransform)[MAXSTUDIOBONES][3][4]) + struct sv_blending_interface_s** ppinterface, + struct engine_studio_api_s* pstudio, + float (*rotationmatrix)[3][4], + float (*bonetransform)[MAXSTUDIOBONES][3][4]) { static GETBLENDAPI_FN getblend = NULL; static int missing = 0; @@ -36,18 +36,15 @@ 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; } - if (!getblend) - { + if (!getblend) { META_DEBUG(6, "Looking up Server_GetBlendingInterface"); getblend = (GETBLENDAPI_FN)g_GameDLL.sys_module.getsym("Server_GetBlendingInterface"); } - if (!getblend) - { + if (!getblend) { META_DEBUG(6, "Couldn't find Server_GetBlendingInterface in game DLL '%s': %s", g_GameDLL.name, "function not found"); missing = 1; return 0; diff --git a/metamod/src/studioapi.h b/metamod/src/studioapi.h index 486881d..5a8da98 100644 --- a/metamod/src/studioapi.h +++ b/metamod/src/studioapi.h @@ -5,13 +5,13 @@ // Typedef for Server_GetBlendingInterface() from Eric Smith on the hlcoders // mailing list. typedef int (*GETBLENDAPI_FN)(int version, - struct sv_blending_interface_s **ppinterface, - struct engine_studio_api_s *pstudio, - float (*rotationmatrix)[3][4], - float (*bonetransform)[MAXSTUDIOBONES][3][4]); + struct sv_blending_interface_s** ppinterface, + struct engine_studio_api_s* pstudio, + float (*rotationmatrix)[3][4], + float (*bonetransform)[MAXSTUDIOBONES][3][4]); extern int mm_Server_GetBlendingInterface(int version, - struct sv_blending_interface_s **ppinterface, - struct engine_studio_api_s *pstudio, - float (*rotationmatrix)[3][4], - float (*bonetransform)[MAXSTUDIOBONES][3][4]); + struct sv_blending_interface_s** ppinterface, + struct engine_studio_api_s* pstudio, + float (*rotationmatrix)[3][4], + float (*bonetransform)[MAXSTUDIOBONES][3][4]); diff --git a/metamod/src/utils.cpp b/metamod/src/utils.cpp index c537a58..d50267d 100644 --- a/metamod/src/utils.cpp +++ b/metamod/src/utils.cpp @@ -30,7 +30,6 @@ const char* LOCALINFO(char* key) static_allocator::static_allocator(memory_protection protection) : m_protection(protection) { - } char* static_allocator::allocate(const size_t n) @@ -82,11 +81,11 @@ void static_allocator::allocate_page() // 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 *mm_strtok_r(char *s, const char *delim, char **ptrptr) +char* mm_strtok_r(char* s, const char* delim, char** ptrptr) { - char *begin = nullptr; - char *end = nullptr; - char *rest = nullptr; + char* begin = nullptr; + char* end = nullptr; + char* rest = nullptr; if (s) begin = s; else @@ -107,9 +106,9 @@ char *mm_strtok_r(char *s, const char *delim, char **ptrptr) } #endif // _WIN32 -char *trimbuf(char *str) +char* trimbuf(char* str) { - char *ibuf; + char* ibuf; if (str == nullptr) return nullptr; for (ibuf = str; *ibuf && (byte)(*ibuf) < (byte)0x80 && isspace(*ibuf); ++ibuf) @@ -127,11 +126,10 @@ char *trimbuf(char *str) return str; } -void normalize_path(char *path) +void normalize_path(char* path) { #ifdef _WIN32 - for (char* cp = path; *cp; cp++) - { + for (char* cp = path; *cp; cp++) { if (isupper(*cp)) *cp = tolower(*cp); @@ -141,7 +139,7 @@ void normalize_path(char *path) #endif } -bool is_abs_path(const char *path) +bool is_abs_path(const char* path) { if (path[0] == '/') return true; #ifdef _WIN32 @@ -151,7 +149,7 @@ bool is_abs_path(const char *path) return false; } -bool is_valid_path(const char *path) +bool is_valid_path(const char* path) { struct stat st; return !stat(path, &st) && S_ISREG(st.st_mode); @@ -169,15 +167,14 @@ bool is_platform_postfix(const char* pf) } #ifdef _WIN32 -char *realpath(const char *file_name, char *resolved_name) +char* realpath(const char* file_name, char* resolved_name) { int ret = GetFullPathName(file_name, PATH_MAX, resolved_name, nullptr); - if (ret > PATH_MAX) { errno = ENAMETOOLONG; return nullptr; } - + if (ret > 0) { WIN32_FIND_DATA find_data; HANDLE handle = FindFirstFile(resolved_name, &find_data); @@ -208,7 +205,7 @@ void __declspec(noreturn) do_exit(int exitval) // Also, formerly named just "valid_file". // // Special-case-recognize "/dev/null" as a valid file. -bool is_file_exists_in_gamedir(const char *path) +bool is_file_exists_in_gamedir(const char* path) { char buf[PATH_MAX];