Move gnprintf/atcprintf from core to logic.
This commit is contained in:
		
							parent
							
								
									9d2bee261c
								
							
						
					
					
						commit
						e78fe93e92
					
				| @ -75,6 +75,7 @@ binary.sources += [ | ||||
|   'Logger.cpp', | ||||
|   'smn_core.cpp', | ||||
|   'smn_menus.cpp', | ||||
|   'sprintf.cpp', | ||||
| ] | ||||
| if builder.target_platform == 'windows': | ||||
|   binary.sources += ['thread/WinThreads.cpp'] | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /**
 | ||||
|  * vim: set ts=4 : | ||||
|  * vim: set ts=4 sw=4 tw=99 noet : | ||||
|  * ============================================================================= | ||||
|  * SourceMod | ||||
|  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved. | ||||
| @ -32,6 +32,7 @@ | ||||
| #include "common_logic.h" | ||||
| #include "PhraseCollection.h" | ||||
| #include "Translator.h" | ||||
| #include "sprintf.h" | ||||
| #include <am-string.h> | ||||
| 
 | ||||
| CPhraseCollection::CPhraseCollection() | ||||
| @ -114,7 +115,7 @@ bool CPhraseCollection::FormatString(char *buffer, | ||||
| 	unsigned int arg; | ||||
| 
 | ||||
| 	arg = 0; | ||||
| 	if (!smcore.gnprintf(buffer, maxlength, format, this, params, numparams, arg, pOutLength, pFailPhrase)) | ||||
| 	if (!gnprintf(buffer, maxlength, format, this, params, numparams, arg, pOutLength, pFailPhrase)) | ||||
| 	{ | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| @ -40,6 +40,7 @@ | ||||
| #include <ILibrarySys.h> | ||||
| #include "PhraseCollection.h" | ||||
| #include "stringutil.h" | ||||
| #include "sprintf.h" | ||||
| #include <am-string.h> | ||||
| 
 | ||||
| Translator g_Translator; | ||||
| @ -1059,7 +1060,7 @@ bool Translator::FormatString(char *buffer, | ||||
| 	unsigned int arg; | ||||
| 
 | ||||
| 	arg = 0; | ||||
| 	if (!smcore.gnprintf(buffer, maxlength, format, pPhrases, params, numparams, arg, pOutLength, pFailPhrase)) | ||||
| 	if (!gnprintf(buffer, maxlength, format, pPhrases, params, numparams, arg, pOutLength, pFailPhrase)) | ||||
| 	{ | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| @ -51,6 +51,7 @@ | ||||
| #include "AdminCache.h" | ||||
| #include "ProfileTools.h" | ||||
| #include "Logger.h" | ||||
| #include "sprintf.h" | ||||
| 
 | ||||
| sm_core_t smcore; | ||||
| IHandleSys *handlesys = &g_HandleSys; | ||||
| @ -124,6 +125,7 @@ static sm_logic_t logic = | ||||
| 	g_pThreader, | ||||
| 	&g_Translator, | ||||
| 	stristr, | ||||
| 	atcprintf, | ||||
| 	CoreTranslate, | ||||
| 	AddCorePhraseFile, | ||||
| 	UTIL_ReplaceAll, | ||||
|  | ||||
| @ -52,7 +52,7 @@ using namespace SourceHook; | ||||
|  * Add 1 to the RHS of this expression to bump the intercom file | ||||
|  * This is to prevent mismatching core/logic binaries | ||||
|  */ | ||||
| #define SM_LOGIC_MAGIC		(0x0F47C0DE - 33) | ||||
| #define SM_LOGIC_MAGIC		(0x0F47C0DE - 34) | ||||
| 
 | ||||
| #if defined SM_LOGIC | ||||
| class IVEngineServer | ||||
| @ -297,9 +297,6 @@ struct sm_core_t | ||||
| 	void			(*ConPrint)(const char *message); | ||||
| 	const char *	(*GetCvarString)(ConVar*); | ||||
| 	bool			(*GetCvarBool)(ConVar*); | ||||
| 	bool			(*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **, | ||||
| 	                            unsigned int, unsigned int &, size_t *, const char **); | ||||
| 	size_t			(*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *); | ||||
| 	bool            (*GetGameName)(char *buffer, size_t maxlength); | ||||
| 	const char *    (*GetGameDescription)(); | ||||
| 	const char *    (*GetSourceEngineName)(); | ||||
| @ -319,6 +316,9 @@ struct sm_core_t | ||||
| 	int				(*GetImmunityMode)(); | ||||
| 	void			(*UpdateAdminCmdFlags)(const char *cmd, OverrideType type, FlagBits bits, bool remove); | ||||
| 	bool			(*LookForCommandAdminFlags)(const char *cmd, FlagBits *pFlags); | ||||
| 	bool            (*DescribePlayer)(int index, const char **namep, const char **authp, int *useridp); | ||||
| 	int             (*MaxClients)(); | ||||
| 	int             (*GetGlobalTarget)(); | ||||
| 	const char		*gamesuffix; | ||||
| 	/* Data */ | ||||
| 	ServerGlobals   *serverGlobals; | ||||
| @ -334,6 +334,7 @@ struct sm_logic_t | ||||
| 	IThreader		*threader; | ||||
| 	ITranslator		*translator; | ||||
| 	const char      *(*stristr)(const char *, const char *); | ||||
| 	size_t			(*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *); | ||||
| 	bool			(*CoreTranslate)(char *,  size_t, const char *, unsigned int, size_t *, ...); | ||||
| 	void            (*AddCorePhraseFile)(const char *filename); | ||||
| 	unsigned int	(*ReplaceAll)(char*, size_t, const char *, const char *, bool); | ||||
|  | ||||
| @ -35,6 +35,7 @@ | ||||
| #include <IPlayerHelpers.h> | ||||
| #include <ISourceMod.h> | ||||
| #include <ITranslator.h> | ||||
| #include "sprintf.h" | ||||
| 
 | ||||
| static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params) | ||||
| { | ||||
| @ -90,7 +91,7 @@ static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params) | ||||
| 	int arg = 2; | ||||
| 
 | ||||
| 	pCtx->LocalToString(params[1], &fmt); | ||||
| 	size_t res = smcore.atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg); | ||||
| 	size_t res = atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg); | ||||
| 
 | ||||
| 	buffer[res++] = '\n'; | ||||
| 	buffer[res] = '\0'; | ||||
| @ -129,7 +130,7 @@ static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params) | ||||
| 	int arg = 3; | ||||
| 
 | ||||
| 	pCtx->LocalToString(params[2], &fmt); | ||||
| 	size_t res = smcore.atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg); | ||||
| 	size_t res = atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg); | ||||
| 
 | ||||
| 	buffer[res++] = '\n'; | ||||
| 	buffer[res] = '\0'; | ||||
|  | ||||
| @ -35,6 +35,7 @@ | ||||
| #include "common_logic.h" | ||||
| #include "ShareSys.h" | ||||
| #include "PluginSys.h" | ||||
| #include "sprintf.h" | ||||
| 
 | ||||
| using namespace SourceHook; | ||||
| 
 | ||||
| @ -412,7 +413,7 @@ static cell_t FormatNativeString(IPluginContext *pContext, const cell_t *params) | ||||
| 	size_t written; | ||||
| 	{ | ||||
| 		DetectExceptions eh(pContext); | ||||
| 		written = smcore.atcprintf(output_buffer, maxlen, format_buffer, s_curcaller, s_curparams, &var_param); | ||||
| 		written = atcprintf(output_buffer, maxlen, format_buffer, s_curcaller, s_curparams, &var_param); | ||||
| 		if (eh.HasException()) | ||||
| 			return 0; | ||||
| 	} | ||||
|  | ||||
| @ -40,6 +40,7 @@ | ||||
| #include <ITranslator.h> | ||||
| #include "common_logic.h" | ||||
| #include "Logger.h" | ||||
| #include "sprintf.h" | ||||
| #include <am-utility.h> | ||||
| #include "handle_helpers.h" | ||||
| 
 | ||||
| @ -774,7 +775,7 @@ static cell_t sm_WriteFileLine(IPluginContext *pContext, const cell_t *params) | ||||
| 	char buffer[2048]; | ||||
| 	{ | ||||
| 		DetectExceptions eh(pContext); | ||||
| 		smcore.atcprintf(buffer, sizeof(buffer), fmt, pContext, params, &arg); | ||||
| 		atcprintf(buffer, sizeof(buffer), fmt, pContext, params, &arg); | ||||
| 		if (eh.HasException()) | ||||
| 			return 0; | ||||
| 	} | ||||
| @ -809,7 +810,7 @@ static cell_t sm_BuildPath(IPluginContext *pContext, const cell_t *params) | ||||
| 
 | ||||
| 	{ | ||||
| 		DetectExceptions eh(pContext); | ||||
| 		smcore.atcprintf(path, sizeof(path), fmt, pContext, params, &arg); | ||||
| 		atcprintf(path, sizeof(path), fmt, pContext, params, &arg); | ||||
| 		if (eh.HasException()) | ||||
| 			return 0; | ||||
| 	} | ||||
|  | ||||
| @ -35,6 +35,7 @@ | ||||
| #include <ITextParsers.h> | ||||
| #include <ctype.h> | ||||
| #include "stringutil.h" | ||||
| #include "sprintf.h" | ||||
| #include <am-string.h> | ||||
| 
 | ||||
| inline const char *_strstr(const char *str, const char *substr) | ||||
| @ -188,7 +189,7 @@ static cell_t sm_formatex(IPluginContext *pCtx, const cell_t *params) | ||||
| 
 | ||||
| 	pCtx->LocalToString(params[1], &buf); | ||||
| 	pCtx->LocalToString(params[3], &fmt); | ||||
| 	res = smcore.atcprintf(buf, static_cast<size_t>(params[2]), fmt, pCtx, params, &arg); | ||||
| 	res = atcprintf(buf, static_cast<size_t>(params[2]), fmt, pCtx, params, &arg); | ||||
| 
 | ||||
| 	return static_cast<cell_t>(res); | ||||
| } | ||||
| @ -257,7 +258,7 @@ static cell_t sm_format(IPluginContext *pCtx, const cell_t *params) | ||||
| 	} | ||||
| 
 | ||||
| 	buf = (copy) ? __copy_buf : destbuf; | ||||
| 	res = smcore.atcprintf(buf, maxlen, fmt, pCtx, params, &arg); | ||||
| 	res = atcprintf(buf, maxlen, fmt, pCtx, params, &arg); | ||||
| 
 | ||||
| 	if (copy) | ||||
| 	{ | ||||
| @ -307,7 +308,7 @@ static cell_t sm_vformat(IPluginContext *pContext, const cell_t *params) | ||||
| 
 | ||||
| 	pContext->LocalToString(params[3], &format); | ||||
| 
 | ||||
| 	size_t total = smcore.atcprintf(destination, maxlen, format, pContext, local_params, &vargPos); | ||||
| 	size_t total = atcprintf(destination, maxlen, format, pContext, local_params, &vargPos); | ||||
| 
 | ||||
| 	/* Perform copy-on-write if we need to */ | ||||
| 	if (copy) | ||||
|  | ||||
							
								
								
									
										1261
									
								
								core/logic/sprintf.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1261
									
								
								core/logic/sprintf.cpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										56
									
								
								core/logic/sprintf.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								core/logic/sprintf.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,56 @@ | ||||
| // vim: set ts=4 sw=4 tw=99 noet :
 | ||||
| // =============================================================================
 | ||||
| // SourceMod
 | ||||
| // Copyright (C) 2004-2015 AlliedModders LLC.  All rights reserved.
 | ||||
| // =============================================================================
 | ||||
| //
 | ||||
| // This program is free software; you can redistribute it and/or modify it under
 | ||||
| // the terms of the GNU General Public License, version 3.0, as published by the
 | ||||
| // Free Software Foundation.
 | ||||
| // 
 | ||||
| // This program is distributed in the hope that it will be useful, but WITHOUT
 | ||||
| // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 | ||||
| // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 | ||||
| // details.
 | ||||
| //
 | ||||
| // You should have received a copy of the GNU General Public License along with
 | ||||
| // this program.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
| //
 | ||||
| // As a special exception, AlliedModders LLC gives you permission to link the
 | ||||
| // code of this program (as well as its derivative works) to "Half-Life 2," the
 | ||||
| // "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
 | ||||
| // by the Valve Corporation.  You must obey the GNU General Public License in
 | ||||
| // all respects for all other code used.  Additionally, AlliedModders LLC grants
 | ||||
| // this exception to all derivative works.  AlliedModders LLC defines further
 | ||||
| // exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
 | ||||
| // or <http://www.sourcemod.net/license.php>.
 | ||||
| #ifndef _include_sourcemod_core_logic_sprintf_h_ | ||||
| #define _include_sourcemod_core_logic_sprintf_h_ | ||||
| 
 | ||||
| #include <sp_vm_api.h> | ||||
| 
 | ||||
| // "AMX Templated Cell Printf", originally. SourceMod doesn't have cell-strings
 | ||||
| // so this is a normal sprintf(), except that its variadic arguments are
 | ||||
| // derived from scripted arguments.
 | ||||
| size_t atcprintf(char *buffer, | ||||
|                  size_t maxlen, | ||||
|                  const char *format, | ||||
|                  SourcePawn::IPluginContext *pCtx, | ||||
|                  const cell_t *params, | ||||
|                  int *param); | ||||
| 
 | ||||
| // "Generic Printf", originally. This is similar to atcprintf, except arguments
 | ||||
| // are provided as an array of opaque pointers, rather than scripted arguments
 | ||||
| // or C++ va_lists. This is essentially what Core uses to translate and format
 | ||||
| // phrases internally.
 | ||||
| bool gnprintf(char *buffer, | ||||
|               size_t maxlen, | ||||
|               const char *format, | ||||
|               IPhraseCollection *pPhrases, | ||||
|               void **params, | ||||
|               unsigned int numparams, | ||||
|               unsigned int &curparam, | ||||
|               size_t *pOutLength, | ||||
|               const char **pFailPhrase); | ||||
| 
 | ||||
| #endif // _include_sourcemod_core_logic_sprintf_h_
 | ||||
| @ -516,6 +516,33 @@ void do_global_plugin_loads() | ||||
| 	g_SourceMod.DoGlobalPluginLoads(); | ||||
| } | ||||
| 
 | ||||
| static bool describe_player(int index, const char **namep, const char **authp, int *useridp) | ||||
| { | ||||
| 	CPlayer *player = g_Players.GetPlayerByIndex(index); | ||||
| 	if (!player || !player->IsConnected()) | ||||
| 		return false; | ||||
| 
 | ||||
| 	if (namep) | ||||
| 		*namep = player->GetName(); | ||||
| 	if (authp) { | ||||
| 		const char *auth = player->GetAuthString(); | ||||
| 		*authp = (auth && *auth) ? auth : "STEAM_ID_PENDING"; | ||||
| 	} | ||||
| 	if (useridp) | ||||
| 		*useridp = GetPlayerUserId(player->GetEdict()); | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| static int get_max_clients() | ||||
| { | ||||
| 	return g_Players.MaxClients(); | ||||
| } | ||||
| 
 | ||||
| static int get_global_target() | ||||
| { | ||||
| 	return g_SourceMod.GetGlobalTarget(); | ||||
| } | ||||
| 
 | ||||
| #if defined METAMOD_PLAPI_VERSION | ||||
| #if SOURCE_ENGINE == SE_LEFT4DEAD | ||||
| #define GAMEFIX "2.l4d" | ||||
| @ -587,8 +614,6 @@ static sm_core_t core_bridge = | ||||
| 	conprint, | ||||
| 	get_cvar_string, | ||||
| 	get_cvar_bool, | ||||
| 	gnprintf, | ||||
| 	atcprintf, | ||||
| 	get_game_name, | ||||
| 	get_game_description, | ||||
| 	get_source_engine_name, | ||||
| @ -608,6 +633,9 @@ static sm_core_t core_bridge = | ||||
| 	get_immunity_mode, | ||||
| 	update_admin_cmd_flags, | ||||
| 	look_for_cmd_admin_flags, | ||||
| 	describe_player, | ||||
| 	get_max_clients, | ||||
| 	get_global_target, | ||||
| 	GAMEFIX, | ||||
| 	&serverGlobals, | ||||
| }; | ||||
|  | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -42,17 +42,7 @@ using namespace SourceMod; | ||||
| 
 | ||||
| #define IS_STR_FILLED(var) (var[0] != '\0') | ||||
| 
 | ||||
| size_t atcprintf(char *buffer, size_t maxlen, const char *format, IPluginContext *pCtx, const cell_t *params, int *param); | ||||
| unsigned int strncopy(char *dest, const char *src, size_t count); | ||||
| bool gnprintf(char *buffer, | ||||
| 			  size_t maxlen, | ||||
| 			  const char *format, | ||||
| 			  IPhraseCollection *pPhrases, | ||||
| 			  void **params, | ||||
| 			  unsigned int numparams, | ||||
| 			  unsigned int &curparam, | ||||
| 			  size_t *pOutLength, | ||||
| 			  const char **pFailPhrase); | ||||
| size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...); | ||||
| size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap); | ||||
| char *sm_strdup(const char *str); | ||||
|  | ||||
| @ -588,7 +588,7 @@ size_t SourceModBase::FormatString(char *buffer, size_t maxlength, IPluginContex | ||||
| 
 | ||||
| 	int lparam = ++param; | ||||
| 
 | ||||
| 	return atcprintf(buffer, maxlength, fmt, pContext, params, &lparam); | ||||
| 	return logicore.atcprintf(buffer, maxlength, fmt, pContext, params, &lparam); | ||||
| } | ||||
| 
 | ||||
| const char *SourceModBase::GetSourceModPath() const | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user