Cstrike: cs_set_user_zoom - Use a more event-based approach when mode is 0
This commit is contained in:
		| @@ -14,6 +14,7 @@ binary.sources = [ | ||||
|   'CstrikeNatives.cpp', | ||||
|   'CstrikeHacks.cpp', | ||||
|   'CstrikeUtils.cpp', | ||||
|   'CstrikeUserMessages.cpp', | ||||
|   'CstrikeHLTypeConversion.cpp', | ||||
|   '../../../public/memtools/MemoryUtils.cpp', | ||||
|   '../../../public/memtools/CDetour/detours.cpp', | ||||
|   | ||||
| @@ -23,15 +23,6 @@ void ShutdownHacks(); | ||||
| void ToggleDetour_ClientCommands(bool enable); | ||||
| void ToggleDetour_BuyCommands(bool enable); | ||||
|  | ||||
| extern int MessageIdArmorType; | ||||
| extern int MessageIdMoney; | ||||
| extern int MessageIdResetHUD; | ||||
| extern int MessageIdScoreAttrib; | ||||
| extern int MessageIdScoreInfo; | ||||
| extern int MessageIdStatusIcon; | ||||
| extern int MessageIdTeamInfo; | ||||
| extern int MessageIdTextMsg; | ||||
|  | ||||
| extern AMX_NATIVE_INFO CstrikeNatives[]; | ||||
|  | ||||
| extern IGameConfig *MainConfig; | ||||
|   | ||||
| @@ -15,23 +15,15 @@ | ||||
| #include "CstrikePlayer.h" | ||||
| #include "CstrikeUtils.h" | ||||
| #include "CstrikeHacks.h" | ||||
| #include "CstrikeUserMessages.h" | ||||
| #include "CstrikeHLTypeConversion.h" | ||||
| #include <CDetour/detours.h> | ||||
|  | ||||
| CCstrikePlayer g_players[33]; | ||||
| int g_zooming[33] = {0}; | ||||
| int Zooming[33]; | ||||
|  | ||||
| bool NoKifesMode = false; | ||||
|  | ||||
| int MessageIdArmorType; | ||||
| int MessageIdMoney; | ||||
| int MessageIdResetHUD; | ||||
| int MessageIdScoreAttrib; | ||||
| int MessageIdScoreInfo; | ||||
| int MessageIdStatusIcon; | ||||
| int MessageIdTeamInfo; | ||||
| int MessageIdTextMsg; | ||||
|  | ||||
| // native cs_set_user_money(index, money, flash = 1); | ||||
| static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) | ||||
| { | ||||
| @@ -879,6 +871,8 @@ static cell AMX_NATIVE_CALL cs_set_user_model(AMX *amx, cell *params) | ||||
| 	g_players[index].SetModel(modelName); | ||||
| 	g_players[index].SetModelled(true); | ||||
|  | ||||
| 	EnableMessageHooks(); | ||||
|  | ||||
| 	SETCLIENTKEYVALUE(index, GETINFOKEYBUFFER(pPlayer), "model", const_cast<char*>(g_players[index].GetModel())); | ||||
|  | ||||
| 	return 1; | ||||
| @@ -1323,7 +1317,7 @@ static cell AMX_NATIVE_CALL cs_set_user_zoom(AMX *amx, cell *params) | ||||
| 	int mode = params[3]; | ||||
| 	int weapon = *static_cast<int *>(MF_PlayerPropAddr(index, Player_CurrentWeapon)); | ||||
| 	 | ||||
| 	g_zooming[index] = 0; | ||||
| 	Zooming[index] = 0; | ||||
|  | ||||
| 	if (type == CS_RESET_ZOOM) | ||||
| 	{ | ||||
| @@ -1371,7 +1365,8 @@ static cell AMX_NATIVE_CALL cs_set_user_zoom(AMX *amx, cell *params) | ||||
|  | ||||
| 	if (!mode) | ||||
| 	{ | ||||
| 		g_zooming[index] = value; | ||||
| 		Zooming[index] = value; | ||||
| 		EnableMessageHooks(); | ||||
| 	} | ||||
|  | ||||
| 	set_pdata<int>(pPlayer, m_iFOV, value); | ||||
| @@ -1772,31 +1767,11 @@ AMX_NATIVE_INFO CstrikeNatives[] = | ||||
| 	{nullptr,						nullptr} | ||||
| }; | ||||
|  | ||||
| void MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)  | ||||
| { | ||||
| 	// Reset player model a short while (MODELRESETTIME) after this if they are using an edited model. | ||||
| 	if(msg_type == MessageIdResetHUD)  | ||||
| 	{ | ||||
| 		int entityIndex = ENTINDEX(ed); | ||||
|  | ||||
| 		if (g_zooming[entityIndex]) | ||||
| 			g_zooming[entityIndex] = 0; | ||||
|  | ||||
| 		if(g_players[entityIndex].GetModelled()) | ||||
| 			g_players[entityIndex].SetInspectModel(true); | ||||
| 			//g_players[ENTINDEX(ed)].SetTime(gpGlobals->time + MODELRESETTIME); | ||||
| 	} | ||||
|  | ||||
| 	RETURN_META(MRES_IGNORED); | ||||
| } | ||||
|  | ||||
|  | ||||
| /***GetEntityAPI2******************/ | ||||
| void ClientDisconnect(edict_t *pEntity)  | ||||
| { | ||||
| 	int index = ENTINDEX(pEntity); | ||||
| 	g_players[index].SetModelled(false); | ||||
| 	g_zooming[index] = 0; | ||||
| 	Zooming[index] = 0; | ||||
|  | ||||
| 	RETURN_META(MRES_IGNORED); | ||||
| } | ||||
| @@ -1830,16 +1805,3 @@ void PlayerPostThink(edict_t* pPlayer) | ||||
| 	} | ||||
| 	RETURN_META(MRES_IGNORED); | ||||
| } | ||||
|  | ||||
| void PlayerPreThink(edict_t *pPlayer) | ||||
| { | ||||
| 	GET_OFFSET_NO_ERROR("CBasePlayer", m_iFOV); | ||||
|  | ||||
| 	int entityIndex = ENTINDEX(pPlayer); | ||||
| 	if (g_zooming[entityIndex]) | ||||
| 	{ | ||||
| 		set_pdata<int>(pPlayer, m_iFOV, g_zooming[entityIndex]); | ||||
| 	} | ||||
|  | ||||
| 	RETURN_META(MRES_IGNORED); | ||||
| } | ||||
|   | ||||
| @@ -34,4 +34,7 @@ private: | ||||
| 	char model[32]; | ||||
| }; | ||||
|  | ||||
| extern CCstrikePlayer g_players[33]; | ||||
| extern int Zooming[33]; | ||||
|  | ||||
| #endif // !defined(INCLUDED_CCSTRIKEPLAYER) | ||||
|   | ||||
							
								
								
									
										157
									
								
								modules/cstrike/cstrike/CstrikeUserMessages.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										157
									
								
								modules/cstrike/cstrike/CstrikeUserMessages.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,157 @@ | ||||
| // vim: set ts=4 sw=4 tw=99 noet: | ||||
| // | ||||
| // AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO"). | ||||
| // Copyright (C) The AMX Mod X Development Team. | ||||
| // | ||||
| // This software is licensed under the GNU General Public License, version 3 or higher. | ||||
| // Additional exceptions apply. For full license details, see LICENSE.txt or visit: | ||||
| //     https://alliedmods.net/amxmodx-license | ||||
|  | ||||
| // | ||||
| // Counter-Strike Module | ||||
| // | ||||
|  | ||||
| #include <amxxmodule.h> | ||||
| #include "CstrikeUserMessages.h" | ||||
| #include "CstrikeUtils.h" | ||||
| #include "CstrikeHacks.h" | ||||
| #include "CstrikePlayer.h" | ||||
|  | ||||
| bool ShouldBlock; | ||||
| bool ShouldBlockHLTV; | ||||
|  | ||||
| int MessageIdArmorType; | ||||
| int MessageIdHLTV; | ||||
| int MessageIdMoney; | ||||
| int MessageIdResetHUD; | ||||
| int MessageIdScoreAttrib; | ||||
| int MessageIdScoreInfo; | ||||
| int MessageIdSetFOV; | ||||
| int MessageIdStatusIcon; | ||||
| int MessageIdTeamInfo; | ||||
| int MessageIdTextMsg; | ||||
|  | ||||
| struct UserMsg | ||||
| { | ||||
| 	const char* name; | ||||
| 	int*        id; | ||||
| }; | ||||
|  | ||||
| UserMsg MessagesList[] = | ||||
| { | ||||
| 	{ "ArmorType"  , &MessageIdArmorType   }, | ||||
| 	{ "HLTV"       , &MessageIdHLTV        }, | ||||
| 	{ "CurWeapon"  , &MessageIdMoney       }, | ||||
| 	{ "ResetHUD"   , &MessageIdResetHUD    }, | ||||
| 	{ "ScoreAttrib", &MessageIdScoreAttrib }, | ||||
| 	{ "ScoreInfo"  , &MessageIdScoreInfo   }, | ||||
| 	{ "SetFOV"     , &MessageIdSetFOV      }, | ||||
| 	{ "StatusIcon" , &MessageIdStatusIcon  }, | ||||
| 	{ "TeamInfo"   , &MessageIdTeamInfo    }, | ||||
| 	{ "TextMsg"    , &MessageIdTextMsg     }, | ||||
| 	{ nullptr      , nullptr               } | ||||
| }; | ||||
|  | ||||
| int OnRegUserMsg_Post(const char *pszName, int iSize) | ||||
| { | ||||
| 	for (size_t i = 0; MessagesList[i].name; ++i) | ||||
| 	{ | ||||
| 		if (!*MessagesList[i].id && strcmp(MessagesList[i].name, pszName) == 0) | ||||
| 		{ | ||||
| 			*MessagesList[i].id = META_RESULT_ORIG_RET(int); | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	RETURN_META_VALUE(MRES_IGNORED, 0); | ||||
| } | ||||
|  | ||||
| void OnMessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *pEntity) | ||||
| { | ||||
| 	switch (msg_dest) | ||||
| 	{ | ||||
| 		case MSG_ONE: | ||||
| 		case MSG_ONE_UNRELIABLE: | ||||
| 		{ | ||||
| 			if (msg_type == MessageIdSetFOV) | ||||
| 			{ | ||||
| 				int index = ENTINDEX(pEntity); | ||||
|  | ||||
| 				if (Zooming[index]) | ||||
| 				{ | ||||
| 					GET_OFFSET_NO_ERROR("CBasePlayer", m_iFOV); | ||||
|  | ||||
| 					if (get_pdata<int>(pEntity, m_iFOV) != Zooming[index]) | ||||
| 					{ | ||||
| 						set_pdata<int>(pEntity, m_iFOV, Zooming[index]); | ||||
|  | ||||
| 						ShouldBlock = true; | ||||
| 						ShouldBlockHLTV = true; | ||||
|  | ||||
| 						RETURN_META(MRES_SUPERCEDE); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			else if (msg_type == MessageIdResetHUD) | ||||
| 			{ | ||||
| 				int index = ENTINDEX(pEntity); | ||||
|  | ||||
| 				if (Zooming[index]) | ||||
| 					Zooming[index] = 0; | ||||
|  | ||||
| 				if (g_players[index].GetModelled()) | ||||
| 					g_players[index].SetInspectModel(true); | ||||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| 		case MSG_SPEC: | ||||
| 		{ | ||||
| 			if (msg_type == MessageIdHLTV && ShouldBlockHLTV) | ||||
| 			{ | ||||
| 				ShouldBlock = true; | ||||
| 				ShouldBlockHLTV = false; | ||||
|  | ||||
| 				RETURN_META(MRES_SUPERCEDE); | ||||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if (ShouldBlockHLTV) | ||||
| 	{ | ||||
| 		ShouldBlockHLTV = false; | ||||
| 	} | ||||
|  | ||||
| 	RETURN_META(MRES_IGNORED); | ||||
| } | ||||
|  | ||||
| void OnWriteByte(int iValue) | ||||
| { | ||||
| 	if (ShouldBlock)  | ||||
| 	{ | ||||
| 		RETURN_META(MRES_SUPERCEDE); | ||||
| 	} | ||||
|  | ||||
| 	RETURN_META(MRES_IGNORED); | ||||
| } | ||||
|  | ||||
| void OnMessageEnd(void) | ||||
| { | ||||
| 	if (ShouldBlock) | ||||
| 	{ | ||||
| 		ShouldBlock = false; | ||||
| 		RETURN_META(MRES_SUPERCEDE); | ||||
| 	} | ||||
|  | ||||
| 	RETURN_META(MRES_IGNORED); | ||||
| } | ||||
|  | ||||
| void EnableMessageHooks() | ||||
| { | ||||
| 	if (!g_pengfuncsTable->pfnMessageBegin) | ||||
| 	{ | ||||
| 		g_pengfuncsTable->pfnMessageBegin = OnMessageBegin; | ||||
| 		g_pengfuncsTable->pfnWriteByte    = OnWriteByte; | ||||
| 		g_pengfuncsTable->pfnMessageEnd   = OnMessageEnd; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										30
									
								
								modules/cstrike/cstrike/CstrikeUserMessages.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								modules/cstrike/cstrike/CstrikeUserMessages.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| // vim: set ts=4 sw=4 tw=99 noet: | ||||
| // | ||||
| // AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO"). | ||||
| // Copyright (C) The AMX Mod X Development Team. | ||||
| // | ||||
| // This software is licensed under the GNU General Public License, version 3 or higher. | ||||
| // Additional exceptions apply. For full license details, see LICENSE.txt or visit: | ||||
| //     https://alliedmods.net/amxmodx-license | ||||
|  | ||||
| // | ||||
| // Counter-Strike Module | ||||
| // | ||||
|  | ||||
| #ifndef CSTRIKE_USER_MESSAGES_H | ||||
| #define CSTRIKE_USER_MESSAGES_H | ||||
|  | ||||
| extern int MessageIdArmorType; | ||||
| extern int MessageIdHLTV; | ||||
| extern int MessageIdMoney; | ||||
| extern int MessageIdResetHUD; | ||||
| extern int MessageIdScoreAttrib; | ||||
| extern int MessageIdScoreInfo; | ||||
| extern int MessageIdSetFOV; | ||||
| extern int MessageIdStatusIcon; | ||||
| extern int MessageIdTeamInfo; | ||||
| extern int MessageIdTextMsg; | ||||
|  | ||||
| void EnableMessageHooks(); | ||||
|  | ||||
| #endif // CSTRIKE_USER_MESSAGES_H | ||||
| @@ -22,25 +22,6 @@ IGameConfig *MainConfig; | ||||
| IGameConfig *OffsetConfig; | ||||
| IGameConfigManager *ConfigManager; | ||||
|  | ||||
| struct UserMsg | ||||
| { | ||||
| 	const char* name; | ||||
| 	int*        id; | ||||
| }; | ||||
|  | ||||
| UserMsg MessagesList[] = | ||||
| { | ||||
| 	{ "ArmorType"  , &MessageIdArmorType   }, | ||||
| 	{ "CurWeapon"  , &MessageIdMoney       }, | ||||
| 	{ "ResetHUD"   , &MessageIdResetHUD    }, | ||||
| 	{ "ScoreAttrib", &MessageIdScoreAttrib }, | ||||
| 	{ "ScoreInfo"  , &MessageIdScoreInfo   }, | ||||
| 	{ "StatusIcon" , &MessageIdStatusIcon  }, | ||||
| 	{ "TeamInfo"   , &MessageIdTeamInfo    }, | ||||
| 	{ "TextMsg"    , &MessageIdTextMsg     }, | ||||
| 	{ nullptr      , nullptr               } | ||||
| }; | ||||
|  | ||||
| int AmxxCheckGame(const char *game) | ||||
| { | ||||
| 	if (strcasecmp(game, "cstrike") == 0 || | ||||
| @@ -100,20 +81,6 @@ void OnPluginsLoaded() | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int OnRegUserMsg_Post(const char *pszName, int iSize) | ||||
| { | ||||
| 	for (size_t i = 0; MessagesList[i].name; ++i) | ||||
| 	{ | ||||
| 		if (!*MessagesList[i].id && strcmp(MessagesList[i].name, pszName) == 0) | ||||
| 		{ | ||||
| 			*MessagesList[i].id = META_RESULT_ORIG_RET(int); | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	RETURN_META_VALUE(MRES_IGNORED, 0); | ||||
| } | ||||
|  | ||||
| void OnAmxxDetach() | ||||
| { | ||||
| 	ConfigManager->CloseGameConfigFile(MainConfig); | ||||
|   | ||||
| @@ -125,7 +125,7 @@ | ||||
| #define FN_ClientUserInfoChanged		ClientUserInfoChanged		/* pfnClientUserInfoChanged()	(wd) Client has updated their setinfo structure */ | ||||
| // #define FN_ServerActivate			ServerActivate				/* pfnServerActivate()			(wd) Server is starting a new map */ | ||||
| // #define FN_ServerDeactivate			ServerDeactivate			/* pfnServerDeactivate()		(wd) Server is leaving the map (shutdown or changelevel); SDK2 */ | ||||
| #define FN_PlayerPreThink				PlayerPreThink				/* pfnPlayerPreThink() */ | ||||
| // #define FN_PlayerPreThink			PlayerPreThink				/* pfnPlayerPreThink() */ | ||||
| #define FN_PlayerPostThink				PlayerPostThink				/* pfnPlayerPostThink() */ | ||||
| // #define FN_StartFrame				StartFrame					/* pfnStartFrame() */ | ||||
| // #define FN_ParmsNewLevel				ParmsNewLevel				/* pfnParmsNewLevel() */ | ||||
| @@ -252,7 +252,7 @@ | ||||
| // #define FN_LightStyle						LightStyle | ||||
| // #define FN_DecalIndex						DecalIndex | ||||
| // #define FN_PointContents						PointContents | ||||
| #define FN_MessageBegin						MessageBegin | ||||
| // #define FN_MessageBegin						MessageBegin | ||||
| // #define FN_MessageEnd						MessageEnd | ||||
| // #define FN_WriteByte							WriteByte | ||||
| // #define FN_WriteChar							WriteChar | ||||
|   | ||||
| @@ -149,6 +149,7 @@ | ||||
|     <ClCompile Include="..\CstrikeHLTypeConversion.cpp" /> | ||||
|     <ClCompile Include="..\CstrikeNatives.cpp" /> | ||||
|     <ClCompile Include="..\CstrikePlayer.cpp" /> | ||||
|     <ClCompile Include="..\CstrikeUserMessages.cpp" /> | ||||
|     <ClCompile Include="..\CstrikeUtils.cpp" /> | ||||
|     <ClCompile Include="..\..\..\..\public\sdk\amxxmodule.cpp" /> | ||||
|   </ItemGroup> | ||||
| @@ -160,6 +161,7 @@ | ||||
|     <ClInclude Include="..\CstrikeDatas.h" /> | ||||
|     <ClInclude Include="..\CstrikeHacks.h" /> | ||||
|     <ClInclude Include="..\CstrikePlayer.h" /> | ||||
|     <ClInclude Include="..\CstrikeUserMessages.h" /> | ||||
|     <ClInclude Include="..\moduleconfig.h" /> | ||||
|     <ClInclude Include="..\..\..\..\public\sdk\amxxmodule.h" /> | ||||
|     <ClInclude Include="..\CstrikeUtils.h" /> | ||||
|   | ||||
| @@ -59,6 +59,9 @@ | ||||
|     <ClCompile Include="..\CstrikeHLTypeConversion.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\CstrikeUserMessages.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\CstrikePlayer.h"> | ||||
| @@ -91,6 +94,9 @@ | ||||
|     <ClInclude Include="..\CstrikeHacks.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\CstrikeUserMessages.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <None Include="..\..\..\..\plugins\include\cstrike.inc"> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user