void NextMapManager::OnSourceModLevelChange( const char *mapName ) { /* Skip the first 'mapchange' when the server starts up */ if (m_tempChangeInfo.startTime != 0) { if (strcmp(mapName, m_tempChangeInfo.m_mapName) == 0) { /* The map change was as we expected */ m_mapHistory.push_back(new MapChangeData(lastMap, m_tempChangeInfo.m_changeReason, m_tempChangeInfo.startTime)); } else { /* Something intercepted the mapchange */ char newReason[255]; UTIL_Format(newReason, sizeof(newReason), "%s (Map overridden)", m_tempChangeInfo.m_changeReason); m_mapHistory.push_back(new MapChangeData(lastMap, newReason, m_tempChangeInfo.startTime)); } /* TODO: Should this be customizable? */ if (m_mapHistory.size() > 20) { SourceHook::List<MapChangeData *>::iterator iter; iter = m_mapHistory.begin(); delete (MapChangeData *)*iter; m_mapHistory.erase(iter); } } m_tempChangeInfo.m_mapName[0] ='\0'; m_tempChangeInfo.m_changeReason[0] = '\0'; m_tempChangeInfo.startTime = time(NULL); UTIL_Format(lastMap, sizeof(lastMap), mapName); }
void LibrarySystem::GetPlatformErrorEx(int code, char *error, size_t maxlength) { if (error && maxlength) { #if defined PLATFORM_WINDOWS if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)error, maxlength, NULL) == 0) { UTIL_Format(error, maxlength, "error code %08x", code); } #elif defined PLATFORM_LINUX const char *ae = strerror_r(code, error, maxlength); if (ae != error) { UTIL_Format(error, maxlength, "%s", ae); } #elif defined PLATFORM_POSIX strerror_r(code, error, maxlength); #endif } }
void Debugger::FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLength) { const char *filename = ""; char native[sNAMEMAX+1]; CList<CScript,AMX*>::iterator a = g_loadedscripts.find(amx); if (a) filename = (*a).getName(); size_t len = strlen(filename); for (size_t i=len-1; i<len; i--) { if ((filename[i] == '/' || filename[i] == '\\') && i != len - 1) { filename = &(filename[i+1]); break; } } if (error == AMX_ERR_EXIT) { UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - %s", error, filename, GenericError(AMX_ERR_EXIT)); } else if (error == AMX_ERR_NATIVE) { amx_GetNative(amx, reinterpret_cast<long>(amx->usertags[UT_NATIVE]), native); UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") (native \"%s\") - debug not enabled!", error, filename, native); } else { UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - debug not enabled!", error, filename); } }
CDirectory::CDirectory(const char *path) { #if defined PLATFORM_WINDOWS char newpath[PLATFORM_MAX_PATH]; UTIL_Format(newpath, sizeof(newpath) - 1, "%s\\*.*", path); m_dir = FindFirstFile(newpath, &m_fd); if (!IsValid()) { m_fd.cFileName[0] = '\0'; } #elif defined PLATFORM_POSIX m_dir = opendir(path); if (IsValid()) { m_ep = readdir(m_dir); // TODO: we need to read past "." and ".."! UTIL_Format(m_origpath, sizeof(m_origpath) - 1, "%s", path); } else { m_ep = nullptr; } #endif }
SMCError TextParsers::ParseSMCFile(const char *file, ITextListener_SMC *smc_listener, SMCStates *states, char *buffer, size_t maxsize) { const char *errstr; FILE *fp = fopen(file, "rt"); if (fp == NULL) { char error[256] = "unknown"; if (states != NULL) { states->line = 0; states->col = 0; } /*libsys->GetPlatformError(error, sizeof(error));*/ UTIL_Format(buffer, maxsize, "File could not be opened: %s", error); return SMCError_StreamOpen; } SMCError result = ParseStream_SMC(fp, FileStreamReader, smc_listener, states); fclose(fp); errstr = GetSMCErrorString(result); UTIL_Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); return result; }
void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const char *video, bool bLongLoading) #endif { if (g_forcedChange) { g_Logger.LogMessage("[SM] Changed map to \"%s\"", map); RETURN_META(MRES_IGNORED); } const char *newmap = sm_nextmap.GetString(); if (newmap[0] == 0 || !engine->IsMapValid(newmap)) { RETURN_META(MRES_IGNORED); } g_Logger.LogMessage("[SM] Changed map to \"%s\"", newmap); UTIL_Format(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), newmap); UTIL_Format(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change"); #if SOURCE_ENGINE != SE_DARKMESSIAH RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown)); #else RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown, video, bLongLoading)); #endif }
METAMOD_PLUGIN *_GetPluginPtr(const char *path, int fail_api) { METAMOD_FN_ORIG_LOAD fn; METAMOD_PLUGIN *pl; int ret; if (!(g_hCore=openlib(path))) { #if defined __linux__ || defined __APPLE__ UTIL_Format(s_FailPlugin.error_buffer, sizeof(s_FailPlugin.error_buffer), "%s", dlerror()); #else DWORD err = GetLastError(); if (FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), s_FailPlugin.error_buffer, sizeof(s_FailPlugin.error_buffer), NULL) == 0) { UTIL_Format(s_FailPlugin.error_buffer, sizeof(s_FailPlugin.error_buffer), "unknown error %x", err); } #endif s_FailPlugin.fail_version = fail_api; return (METAMOD_PLUGIN *)&s_FailPlugin; } if (!(fn=(METAMOD_FN_ORIG_LOAD)findsym(g_hCore, "CreateInterface"))) { goto error; } pl = (METAMOD_PLUGIN *)fn(METAMOD_PLAPI_NAME, &ret); if (!pl) { goto error; } return pl; error: closelib(g_hCore); g_hCore = NULL; return NULL; }
void NextMapManager::ForceChangeLevel( const char *mapName, const char* changeReason ) { /* Store the mapname and reason */ UTIL_Format(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), mapName); UTIL_Format(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), changeReason); /* Change level and skip our hook */ g_forcedChange = true; engine->ChangeLevel(mapName, NULL); g_forcedChange = false; }
cell PSKeyValueF(const char *name, AMX *amx, cell *params) { if (params[1]==0) { MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!"); return 0; } KeyValueData kvd; char StrData[1024]; UTIL_Format(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2])); kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname)); kvd.szKeyName=name; kvd.szValue=&StrData[0]; kvd.fHandled=0; //printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue); MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd); return 1; }
unsigned int CValveMenuDisplay::DrawItem(const ItemDrawInfo &item) { if (m_NextPos > 9 || !CanDrawItem(item.style)) { return 0; } /** * For these cases we can't draw anything at all, but * we can at least bump the position since we were explicitly asked to. */ if ((item.style & ITEMDRAW_NOTEXT) || (item.style & ITEMDRAW_SPACER)) { return m_NextPos++; } char buffer[255]; UTIL_Format(buffer, sizeof(buffer), "%d. %s", m_NextPos, item.display); KeyValues *ki = m_pKv->FindKey(g_OptionNumTable[m_NextPos], true); ki->SetString("command", g_OptionCmdTable[m_NextPos]); ki->SetString("msg", buffer); return m_NextPos++; }
// native geoip_region_code(const ip[], result[], len); static cell AMX_NATIVE_CALL amx_geoip_region_code(AMX *amx, cell *params) { int length; int finalLength = 0; char code[12]; // This should be largely enough to hold xx-yyyy and more if needed. char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length)); const char *pathCountry[] = { "country", "iso_code", NULL }; const char *countryCode = lookupString(ip, pathCountry, &length); if (countryCode) { finalLength = length + 1; // + 1 for dash. UTIL_Format(code, finalLength + 1, "%s-", countryCode); // + EOS. const char *pathRegion[] = { "subdivisions", "0", "iso_code", NULL }; // First result. const char *regionCode = lookupString(ip, pathRegion, &length); if (regionCode) { finalLength += length; strncat(code, regionCode, length); } else { finalLength = 0; } } return MF_SetAmxString(amx, params[2], finalLength ? code : "", ke::Min(finalLength, params[3])); }
EXPORT void *CreateInterface(const char *pName, int *pReturnCode) { if (strcmp(pName, METAMOD_PLAPI_NAME) == 0) { char our_file[256]; if (!GetFileOfAddress((void *)CreateInterface_MMS, our_file, sizeof(our_file))) { return NULL; } /* Go backwards and get the first token */ size_t len = strlen(our_file); for (size_t i = len; i-- > 0;) { if (IsPathSepChar(our_file[i])) { our_file[i] = '\0'; break; } } char new_file[256]; UTIL_Format(new_file, sizeof(new_file), "%s" PATH_SEP_CHAR MMS_1_4_EP1_FILE, our_file); return TryAndLoadLibrary(new_file); } return NULL; }
ConfigResult Translator::OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength) { if (strcasecmp(key, "ServerLang") == 0) { if (source == ConfigSource_Console) { unsigned int index; if (!GetLanguageByCode(value, &index)) { UTIL_Format(error, maxlength, "Language code \"%s\" is not registered", value); return ConfigResult_Reject; } m_ServerLang = index; } else { strncopy(m_InitialLang, value, sizeof(m_InitialLang)); } return ConfigResult_Accept; } return ConfigResult_Ignore; }
void SourceModBase::DoGlobalPluginLoads() { char config_path[PLATFORM_MAX_PATH]; char plugins_path[PLATFORM_MAX_PATH]; BuildPath(Path_SM, config_path, sizeof(config_path), "configs/plugin_settings.cfg"); BuildPath(Path_SM, plugins_path, sizeof(plugins_path), "plugins"); /* Load any auto extensions */ extsys->TryAutoload(); /* Fire the extensions ready message */ g_SMAPI->MetaFactory(SOURCEMOD_NOTICE_EXTENSIONS, NULL, NULL); /* Load any game extension */ const char *game_ext; if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL) { char path[PLATFORM_MAX_PATH]; UTIL_Format(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext); extsys->LoadAutoExtension(path); } scripts->LoadAll(config_path, plugins_path); }
IPhraseFile *CPhraseCollection::AddPhraseFile(const char *filename) { size_t i; unsigned int fid; IPhraseFile *pFile; char full_name[PLATFORM_MAX_PATH]; /* No compat shim here. The user should have read the doc. */ UTIL_Format(full_name, sizeof(full_name), "%s.txt", filename); fid = g_Translator.FindOrAddPhraseFile(full_name); pFile = g_Translator.GetFileByIndex(fid); for (i = 0; i < m_Files.size(); i++) { if (m_Files[i] == pFile) { return pFile; } } m_Files.push_back(pFile); return pFile; }
ConfigResult PlayerManager::OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength) { if (strcmp(key, "PassInfoVar") == 0) { if (strcmp(value, "_password") != 0) { m_PassInfoVar.assign(value); } return ConfigResult_Accept; } else if (strcmp(key, "AllowClLanguageVar") == 0) { if (strcasecmp(value, "on") == 0) { m_QueryLang = true; } else if (strcasecmp(value, "off") == 0) { m_QueryLang = false; } else { UTIL_Format(error, maxlength, "Invalid value: must be \"on\" or \"off\""); return ConfigResult_Reject; } return ConfigResult_Accept; } return ConfigResult_Ignore; }
static cell_t smn_KvSetVector(IPluginContext *pCtx, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError herr; HandleSecurity sec; KeyValueStack *pStk; sec.pOwner = NULL; sec.pIdentity = g_pCoreIdent; if ((herr=handlesys->ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr); } char *key; char buffer[64]; cell_t *vector; pCtx->LocalToStringNULL(params[2], &key); pCtx->LocalToPhysAddr(params[3], &vector); UTIL_Format(buffer, sizeof(buffer), "%f %f %f", sp_ctof(vector[0]), sp_ctof(vector[1]), sp_ctof(vector[2])); pStk->pCurRoot.front()->SetString(key, buffer); return 1; }
IExtension *CExtensionManager::FindExtensionByFile(const char *file) { List<CExtension *>::iterator iter; CExtension *pExt; /* Chomp off the path */ char lookup[PLATFORM_MAX_PATH]; g_LibSys.GetFileFromPath(lookup, sizeof(lookup), file); for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { pExt = (*iter); char short_file[PLATFORM_MAX_PATH]; g_LibSys.GetFileFromPath(short_file, sizeof(short_file), pExt->GetFilename()); if (strcmp(lookup, short_file) == 0) { return pExt; } } /* If we got no results, test if there was a platform extension. * If not, add one. */ if (!strstr(file, "." PLATFORM_LIB_EXT)) { char path[PLATFORM_MAX_PATH]; UTIL_Format(path, sizeof(path), "%s.%s", file, PLATFORM_LIB_EXT); return FindExtensionByFile(path); } return NULL; }
funcenum_t *funcenum_for_symbol(symbol *sym) { functag_t ft; memset(&ft, 0, sizeof(ft)); ft.ret_tag = sym->tag; ft.usage = uPUBLIC & (sym->usage & uRETVALUE); ft.argcount = 0; ft.ommittable = FALSE; for (arginfo *arg = sym->dim.arglist; arg->ident; arg++) { funcarg_t *dest = &ft.args[ft.argcount++]; dest->tagcount = arg->numtags; memcpy(dest->tags, arg->tags, arg->numtags * sizeof(int)); dest->dimcount = arg->numdim; memcpy(dest->dims, arg->dim, arg->numdim * sizeof(int)); dest->ident = arg->ident; dest->fconst = !!(arg->usage & uCONST); dest->ommittable = FALSE; } char name[METHOD_NAMEMAX+1]; UTIL_Format(name, sizeof(name), "::ft:%s:%d:%d", sym->name, sym->addr, sym->codeaddr); funcenum_t *fe = funcenums_add(name); functags_add(fe, &ft); return fe; }
bool Load(SourceMM::PluginId id, SourceMM::ISmmAPI *ismm, char *error, size_t maxlength, bool late) { if (error != NULL && maxlength != 0) { UTIL_Format(error, maxlength, "%s", error_buffer); } return false; }
cell_t AddSettingsMenuItem(IPluginContext *pContext, const cell_t *params) { if (g_ClientPrefs.Database == NULL && !g_ClientPrefs.databaseLoading) { return pContext->ThrowNativeError("Clientprefs is disabled due to a failed database connection"); } char *display; pContext->LocalToString(params[3], &display); /* Register a callback */ ItemHandler *pItem = new ItemHandler; pItem->isAutoMenu = false; pItem->forward = forwards->CreateForwardEx(NULL, ET_Ignore, 5, NULL, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell); pItem->forward->AddFunction(pContext, static_cast<funcid_t>(params[1])); char info[20]; AutoMenuData *data = new AutoMenuData; data->datavalue = params[2]; data->handler = pItem; UTIL_Format(info, sizeof(info), "%x", data); ItemDrawInfo draw(display, 0); g_CookieManager.clientMenu->AppendItem(info, draw); /* Track this in case the plugin unloads */ IPlugin *pPlugin = plsys->FindPluginByContext(pContext->GetContext()); SourceHook::List<char *> *pList = NULL; if (!pPlugin->GetProperty("SettingsMenuItems", (void **)&pList, false) || !pList) { pList = new SourceHook::List<char *>; pPlugin->SetProperty("SettingsMenuItems", pList); } char *copyarray = new char[strlen(display)+1]; UTIL_Format(copyarray, strlen(display)+1, "%s", display); pList->push_back(copyarray); return 0; }
int Debugger::FormatError(char *buffer, size_t maxLength) { if (!ErrorExists()) return -1; assert(m_Top >= 0 && m_Top < (int)m_pCalls.size()); Tracer *pTracer = m_pCalls[m_Top]; int error = pTracer->m_Error; const char *gen_err = GenericError(error); int size = 0; //trace_info_t *pTrace = pTracer->GetEnd(); //cell cip = _CipAsVa(m_pAmx->cip); //cell *p_cip = NULL; //int amx_err = AMX_ERR_NONE; size += UTIL_Format(buffer, maxLength, "Run time error %d: %s ", error, gen_err); buffer += size; maxLength -= size; if (error == AMX_ERR_NATIVE || error == AMX_ERR_INVNATIVE) { char native_name[sNAMEMAX+1]; int num = 0; /*//go two instructions back cip -= (sizeof(cell) * 2); int instr = _GetOpcodeFromCip(cip, p_cip); if (instr == OP_SYSREQ_C) { num = (int)*p_cip; }*/ //New code only requires this... num = (int)(_INT_PTR)m_pAmx->usertags[UT_NATIVE]; /*amx_err = */amx_GetNative(m_pAmx, num, native_name); /*if (num) amx_err = amx_GetNative(m_pAmx, (int)*p_cip, native_name); else amx_err = AMX_ERR_NOTFOUND;*/ //if (!amx_err) size += UTIL_Format(buffer, maxLength, "(native \"%s\")", native_name); } return size; }
size_t LibrarySystem::GetFileFromPath(char* buffer, size_t maxlength, const char* path) { size_t length = strlen(path); for (size_t i = length - 1; i <= length - 1; i--) { if (path[i] == '/' #if defined PLATFORM_WINDOWS || path[i] == '\\' #endif ) { return UTIL_Format(buffer, maxlength, "%s", &path[i + 1]); } } /* We scanned and found no path separator */ return UTIL_Format(buffer, maxlength, "%s", path); }
void CHalfLife2::AddDelayedKick(int client, int userid, const char *msg) { DelayedKickInfo kick; kick.client = client; kick.userid = userid; UTIL_Format(kick.buffer, sizeof(kick.buffer), "%s", msg); m_DelayedKicks.push(kick); }
void CRadioMenuPlayer::Radio_Init(int keys, const char *title, const char *text) { if (title[0] != '\0') { display_len = UTIL_Format(display_pkt, sizeof(display_pkt), "%s\n%s", title, text); } else { display_len = UTIL_Format(display_pkt, sizeof(display_pkt), "%s", text); } display_keys = keys; }
void RunThreadPart() { m_pDatabase->LockForFullAtomicOperation(); m_pQuery = m_pDatabase->DoQuery(m_Query.c_str()); if (!m_pQuery) { UTIL_Format(error, sizeof(error), "%s", m_pDatabase->GetError()); } m_pDatabase->UnlockFromFullAtomicOperation(); }
static cell AMX_NATIVE_CALL log_error(AMX *amx, cell *params) { int len; char *err = format_amxstring(amx, params, 2, len); UTIL_Format(g_errorStr, sizeof(g_errorStr), "%s", err); g_CurError = params[1]; return 1; }
void CmdChangeLevelCallback(const CCommand &command) { #else void CmdChangeLevelCallback() { CCommand command; #endif if (command.ArgC() < 2) { return; } if (g_NextMap.m_tempChangeInfo.m_mapName[0] == '\0') { UTIL_Format(g_NextMap.m_tempChangeInfo.m_mapName, sizeof(g_NextMap.m_tempChangeInfo.m_mapName), command.Arg(1)); UTIL_Format(g_NextMap.m_tempChangeInfo.m_changeReason, sizeof(g_NextMap.m_tempChangeInfo.m_changeReason), "changelevel Command"); } }
static void NERRS(IPluginContext *pContext,char* format,...) { va_list ap; va_start(ap, format); char buffer[2000]; UTIL_Format(buffer,sizeof(buffer),format,ap); pContext->ThrowNativeError(buffer); va_end(ap); }
void StubPlugin::BindToSourcemod() { char error[256]; if (!SM_LoadExtension(error, sizeof(error))) { char message[512]; UTIL_Format(message, sizeof(message), "Could not load as a SourceMod extension: %s\n", error); engine->LogPrint(message); } }