Merge branch 'master' of https://github.com/alliedmodders/sourcemod into mapchooser-updates

This commit is contained in:
Ross Bemrose 2015-01-06 10:04:25 -05:00
commit a9961d3bb4
19 changed files with 164 additions and 222 deletions

View File

@ -195,15 +195,20 @@ IPluginRuntime *CPlugin::GetRuntime()
void CPlugin::SetErrorState(PluginStatus status, const char *error_fmt, ...)
{
PluginStatus old_status = m_status;
m_status = status;
if (old_status == Plugin_Running)
if (m_status == Plugin_Running)
{
/* Tell everyone we're now paused */
g_PluginSys._SetPauseState(this, true);
SetPauseState(true);
/* If we won't recover from this error, drop everything and pause dependent plugins too! */
if (status == Plugin_Failed)
{
DropEverything();
}
}
/* SetPauseState sets the status to Plugin_Paused, but we might want to see some other status set. */
m_status = status;
va_list ap;
va_start(ap, error_fmt);
smcore.FormatArgs(m_errormsg, sizeof(m_errormsg), error_fmt, ap);
@ -531,7 +536,8 @@ bool CPlugin::SetPauseState(bool paused)
if (paused && GetStatus() != Plugin_Running)
{
return false;
} else if (!paused && GetStatus() != Plugin_Paused) {
}
else if (!paused && GetStatus() != Plugin_Paused && GetStatus() != Plugin_Error) {
return false;
}
@ -539,6 +545,12 @@ bool CPlugin::SetPauseState(bool paused)
{
LibraryActions(LibraryAction_Removed);
}
else
{
// Set to running again BEFORE trying to call OnPluginPauseChange ;)
m_status = Plugin_Running;
m_pRuntime->SetPauseState(false);
}
IPluginFunction *pFunction = m_pRuntime->GetFunctionByName("OnPluginPauseChange");
if (pFunction)
@ -552,9 +564,6 @@ bool CPlugin::SetPauseState(bool paused)
{
m_status = Plugin_Paused;
m_pRuntime->SetPauseState(true);
} else {
m_status = Plugin_Running;
m_pRuntime->SetPauseState(false);
}
g_PluginSys._SetPauseState(this, paused);
@ -1138,7 +1147,7 @@ void CPluginManager::LoadAll_SecondPass()
if (!RunSecondPass(pPlugin, error, sizeof(error)))
{
g_Logger.LogError("[SM] Unable to load plugin \"%s\": %s", pPlugin->GetFilename(), error);
pPlugin->SetErrorState(Plugin_Failed, "%s", error);
pPlugin->SetErrorState(Plugin_BadLoad, "%s", error);
}
}
}
@ -1496,11 +1505,9 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin)
if (pPlugin->GetStatus() == Plugin_Error)
{
/* If we got here, all natives are okay again! */
pPlugin->m_status = Plugin_Running;
if (pPlugin->m_pRuntime->IsPaused())
{
pPlugin->m_pRuntime->SetPauseState(false);
_SetPauseState(pPlugin, false);
pPlugin->SetPauseState(false);
}
}
}
@ -2217,7 +2224,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
const sm_plugininfo_t *info = pl->GetPublicInfo();
rootmenu->ConsolePrint(" Filename: %s", pl->GetFilename());
if (pl->GetStatus() <= Plugin_Error)
if (pl->GetStatus() <= Plugin_Error || pl->GetStatus() == Plugin_Failed)
{
if (IS_STR_FILLED(info->name))
{
@ -2240,7 +2247,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
{
rootmenu->ConsolePrint(" URL: %s", info->url);
}
if (pl->GetStatus() == Plugin_Error)
if (pl->GetStatus() == Plugin_Error || pl->GetStatus() == Plugin_Failed)
{
rootmenu->ConsolePrint(" Error: %s", pl->m_errormsg);
}

View File

@ -597,7 +597,7 @@ REGISTER_NATIVES(cellArrayNatives)
{"ArrayList.Set", SetArrayCell},
{"ArrayList.SetString", SetArrayString},
{"ArrayList.SetArray", SetArrayArray},
{"ArrayList.Erease", RemoveFromArray},
{"ArrayList.Erase", RemoveFromArray},
{"ArrayList.ShiftUp", ShiftArrayUp},
{"ArrayList.SwapAt", SwapArrayItems},
{"ArrayList.Clone", CloneArray},

View File

@ -380,7 +380,7 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
if (params[0] == 1)
{
pPlugin->SetErrorState(Plugin_Error, "%s", str);
pPlugin->SetErrorState(Plugin_Failed, "%s", str);
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", str);
}
@ -391,12 +391,12 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
pPlugin->SetErrorState(Plugin_Error, "%s", str);
pPlugin->SetErrorState(Plugin_Failed, "%s", str);
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "Formatting error (%s)", str);
}
else
{
pPlugin->SetErrorState(Plugin_Error, "%s", buffer);
pPlugin->SetErrorState(Plugin_Failed, "%s", buffer);
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", buffer);
}
}
@ -774,4 +774,4 @@ REGISTER_NATIVES(coreNatives)
{"LoadFromAddress", LoadFromAddress},
{"StoreToAddress", StoreToAddress},
{NULL, NULL},
};
};

View File

@ -572,6 +572,47 @@ static cell_t ReferenceToBCompatRef(IPluginContext *pContext, const cell_t *para
return g_HL2.ReferenceToBCompatRef(params[1]);
}
// Must match ClientRangeType enum in halflife.inc
enum class ClientRangeType : cell_t
{
Visibility = 0,
Audibility,
};
static cell_t GetClientsInRange(IPluginContext *pContext, const cell_t *params)
{
cell_t *origin;
pContext->LocalToPhysAddr(params[1], &origin);
Vector vOrigin(sp_ctof(origin[0]), sp_ctof(origin[1]), sp_ctof(origin[2]));
ClientRangeType rangeType = (ClientRangeType) params[2];
CBitVec<ABSOLUTE_PLAYER_LIMIT> players;
engine->Message_DetermineMulticastRecipients(rangeType == ClientRangeType::Audibility, vOrigin, players);
cell_t *outPlayers;
pContext->LocalToPhysAddr(params[3], &outPlayers);
int maxPlayers = params[4];
int curPlayers = 0;
int index = players.FindNextSetBit(0);
while (index > -1 && curPlayers < maxPlayers)
{
int entidx = index + 1;
CPlayer *pPlayer = g_Players.GetPlayerByIndex(entidx);
if (pPlayer && pPlayer->IsInGame())
{
outPlayers[curPlayers++] = entidx;
}
index = players.FindNextSetBit(index + 1);
}
return curPlayers;
}
REGISTER_NATIVES(halflifeNatives)
{
{"CreateFakeClient", CreateFakeClient},
@ -607,5 +648,6 @@ REGISTER_NATIVES(halflifeNatives)
{"EntIndexToEntRef", IndexToReference},
{"EntRefToEntIndex", ReferenceToIndex},
{"MakeCompatEntRef", ReferenceToBCompatRef},
{"GetClientsInRange", GetClientsInRange},
{NULL, NULL},
};

View File

@ -51,7 +51,9 @@ IPlayerInfoManager *playerinfo = NULL;
IBaseFileSystem *basefilesystem = NULL;
IFileSystem *filesystem = NULL;
IEngineSound *enginesound = NULL;
#if SOURCE_ENGINE >= SE_ORANGEBOX
IServerTools *servertools = NULL;
#endif
IServerPluginHelpers *serverpluginhelpers = NULL;
IServerPluginCallbacks *vsp_interface = NULL;
int vsp_version = 0;
@ -70,7 +72,9 @@ bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen
GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetFileSystemFactory, filesystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
#if SOURCE_ENGINE >= SE_ORANGEBOX
GET_V_IFACE_CURRENT(GetServerFactory, servertools, IServerTools, VSERVERTOOLS_INTERFACE_VERSION);
#endif
#if SOURCE_ENGINE != SE_DOTA
GET_V_IFACE_CURRENT(GetEngineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
#endif

View File

@ -102,7 +102,9 @@ extern IPlayerInfoManager *playerinfo;
extern IBaseFileSystem *basefilesystem;
extern IFileSystem *filesystem;
extern IEngineSound *enginesound;
#if SOURCE_ENGINE >= SE_ORANGEBOX
extern IServerTools *servertools;
#endif
extern IServerPluginHelpers *serverpluginhelpers;
extern IServerPluginCallbacks *vsp_interface;
extern int vsp_version;

View File

@ -219,6 +219,26 @@ bool SDKHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
return false;
}
buffer[0] = '\0';
if (!gameconfs->LoadGameConfigFile("sdkhooks.games", &g_pGameConf, buffer, sizeof(buffer)))
{
if (buffer[0])
{
g_pSM->Format(error, maxlength, "Could not read sdkhooks.games gamedata: %s", buffer);
}
return false;
}
CUtlVector<IEntityListener *> *entListeners = EntListeners();
if (!entListeners)
{
g_pSM->Format(error, maxlength, "Failed to setup entity listeners");
return false;
}
entListeners->AddToTail(this);
sharesys->AddDependency(myself, "bintools.ext", true, true);
sharesys->AddNatives(myself, g_Natives);
sharesys->RegisterLibrary(myself, "sdkhooks");
@ -237,26 +257,6 @@ bool SDKHooks::SDK_OnLoad(char *error, size_t maxlength, bool late)
#endif
g_pOnLevelInit = forwards->CreateForward("OnLevelInit", ET_Hook, 2, NULL, Param_String, Param_String);
buffer[0] = '\0';
if (!gameconfs->LoadGameConfigFile("sdkhooks.games", &g_pGameConf, buffer, sizeof(buffer)))
{
if (buffer[0])
{
g_pSM->Format(error, maxlength, "Could not read sdkhooks.games gamedata: %s", buffer);
}
return false;
}
CUtlVector<IEntityListener *> *entListeners = EntListeners();
if (!entListeners)
{
g_pSM->Format(error, maxlength, "Failed to setup entity listeners");
return false;
}
entListeners->AddToTail(this);
SetupHooks();
#if SOURCE_ENGINE >= SE_ORANGEBOX

View File

@ -822,11 +822,11 @@ void UTIL_DrawDataTable(FILE *fp, datamap_t *pMap, int level)
if (externalname == NULL)
{
fprintf(fp,"%s- %s (%s)(%i Bytes)\n", spaces, pMap->dataDesc[i].fieldName, flags, pMap->dataDesc[i].fieldSizeInBytes);
fprintf(fp, "%s- %s (Offset %d) (%s)(%i Bytes)\n", spaces, pMap->dataDesc[i].fieldName, GetTypeDescOffs(&pMap->dataDesc[i]), flags, pMap->dataDesc[i].fieldSizeInBytes);
}
else
{
fprintf(fp,"%s- %s (%s)(%i Bytes) - %s\n", spaces, pMap->dataDesc[i].fieldName, flags, pMap->dataDesc[i].fieldSizeInBytes, externalname);
fprintf(fp, "%s- %s (Offset %d) (%s)(%i Bytes) - %s\n", spaces, pMap->dataDesc[i].fieldName, GetTypeDescOffs(&pMap->dataDesc[i]), flags, pMap->dataDesc[i].fieldSizeInBytes, externalname);
}
}
}

View File

@ -29,13 +29,6 @@
"windows" "11"
"linux" "13"
}
"EntInfo"
{
"windows" "4"
"linux" "4"
"mac" "4"
}
}
"Signatures"
@ -54,24 +47,15 @@
}
}
/* CGlobalEntityList */
"#default"
{
/* These games do have symbols in the linux binaries */
"#supported"
"Keys"
{
"game" "fof"
"game" "nmrih"
"UseInvalidUniverseInSteam2IDs" "1"
}
"Offsets"
{
/* Offset into LevelShutdown */
"gEntList"
{
"windows" "11"
}
"EntInfo"
{
"windows" "4"
@ -79,28 +63,5 @@
"mac" "4"
}
}
"Signatures"
{
"LevelShutdown"
{
"library" "server"
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
}
"gEntList"
{
"library" "server"
"linux" "@gEntList"
"mac" "@gEntList"
}
}
}
"#default"
{
"Keys"
{
"UseInvalidUniverseInSteam2IDs" "1"
}
}
}

View File

@ -71,7 +71,7 @@ public OnPluginStart()
LoadTranslations("common.phrases");
LoadTranslations("basetriggers.phrases");
g_Cvar_TriggerShow = CreateConVar("sm_trigger_show", "1", "Display triggers message to all players? (0 off, 1 on, def. 1)", 0, true, 0.0, true, 1.0);
g_Cvar_TriggerShow = CreateConVar("sm_trigger_show", "0", "Display triggers message to all players? (0 off, 1 on, def. 0)", 0, true, 0.0, true, 1.0);
g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0);
g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire");

View File

@ -67,7 +67,7 @@ methodmap ArrayList < Handle {
public native ArrayList(int blocksize=1, int startsize=0);
// Clears an array of all entries. This is the same as Resize(0).
public native void ClearArray();
public native void Clear();
// Clones an array, returning a new handle with the same size and data.
// This should NOT be confused with CloneHandle. This is a completely new

View File

@ -477,13 +477,13 @@ stock Database SQLite_UseDatabase(const char[] database,
char[] error,
maxlength)
{
new Handle kv, Handle db;
Handle kv, db;
kv = CreateKeyValues("");
KvSetString(kv, "driver", "sqlite");
KvSetString(kv, "database", database);
db = SQL_ConnectCustom(kv, error, int maxlength, false);
db = SQL_ConnectCustom(kv, error, maxlength, false);
CloseHandle(kv);
@ -641,7 +641,7 @@ stock bool SQL_QuoteString(Handle database,
maxlength,
&written=0)
{
return SQL_EscapeString(database, string, buffer, int maxlength, written);
return SQL_EscapeString(database, string, buffer, maxlength, written);
}
/**

View File

@ -624,3 +624,21 @@ native EntRefToEntIndex(ref);
*/
native MakeCompatEntRef(ref);
enum ClientRangeType
{
RangeType_Visibility = 0,
RangeType_Audibility,
}
/**
* Find clients that are potentially in range of a position.
*
* @param origin Coordinates from which to test range.
* @param rangeType Range type to use for filtering clients.
* @param clients Array to which found client indexes will be written.
* @param size Maximum size of clients array.
* @return Number of client indexes written to clients array.
*/
native int GetClientsInRange(float origin[3], ClientRangeType rangeType, int[] clients, int size);

View File

@ -264,7 +264,9 @@ typeset SDKHookCB
// OnTakeDamagePost
// OnTakeDamageAlivePost
function void (int victim, int attacker, int inflictor, float damage, int damagetype);
function void (int victim, int attacker, int inflictor, float damage, int damagetype, const float damageForce[3], const float damagePosition[3]);
function void (int victim, int attacker, int inflictor, float damage, int damagetype, int weapon, const float damageForce[3], const float damagePosition[3]);
function void (int victim, int attacker, int inflictor, float damage, int damagetype, int weapon,
const float damageForce[3], const float damagePosition[3], int damagecustom);
// FireBulletsPost
function void (int client, int shots, const char[] weaponname);

View File

@ -487,7 +487,6 @@ enum TokenKind {
tpDEFINE,
tpELSE, /* #else */
tpELSEIF, /* #elseif */
tpEMIT,
tpENDIF,
tpENDINPUT,
tpENDSCRPT,

View File

@ -1445,12 +1445,25 @@ static void dodecl(const token_t *tok)
return;
}
int fpublic = (tok->id == tPUBLIC);
int fstock = (tok->id == tSTOCK);
int fstatic = (tok->id == tSTATIC);
int fpublic = FALSE, fstock = FALSE, fstatic = FALSE, fconst = FALSE;
switch (tok->id) {
case tPUBLIC:
fpublic = TRUE;
break;
case tSTOCK:
fstock = TRUE;
if (matchtoken(tSTATIC))
fstatic = TRUE;
break;
case tSTATIC:
fstatic = TRUE;
if (fstatic && matchtoken(tSTOCK))
fstock = TRUE;
// For compatibility, we must include this case. Though "stock" should
// come first.
if (matchtoken(tSTOCK))
fstock = TRUE;
break;
}
int flags = DECLFLAG_MAYBE_FUNCTION | DECLFLAG_VARIABLE | DECLFLAG_ENUMROOT;
if (tok->id == tNEW)
@ -1462,7 +1475,13 @@ static void dodecl(const token_t *tok)
decl.type.tag = 0;
}
if (!decl.opertok && (tok->id == tNEW || decl.type.has_postdims || !lexpeek('('))) {
// Hacky bag o' hints as to whether this is a variable decl.
bool probablyVariable = tok->id == tNEW ||
decl.type.has_postdims ||
!lexpeek('(') ||
((decl.type.usage & uCONST) == uCONST);
if (!decl.opertok && probablyVariable) {
if (tok->id == tNEW && decl.type.is_new)
error(143);
if (decl.type.tag & STRUCTTAG) {
@ -4628,9 +4647,9 @@ static void decl_enum(int vclass)
char *str;
int tag,explicittag;
cell increment,multiplier;
constvalue *enumroot;
LayoutSpec spec;
symbol *enumsym = nullptr;
constvalue *enumroot = nullptr;
/* get an explicit tag, if any (we need to remember whether an explicit
* tag was passed, even if that explicit tag was "_:", so we cannot call

View File

@ -1036,10 +1036,6 @@ static int command(void)
} /* if */
if (!cp_set(name))
error(FATAL_ERROR_NO_CODEPAGE);
} else if (strcmp(str,"compress")==0) {
cell val;
preproc_expr(&val,NULL);
sc_compress=(int)val; /* switch code packing on/off */
} else if (strcmp(str,"ctrlchar")==0) {
while (*lptr<=' ' && *lptr!='\0')
lptr++;
@ -1059,70 +1055,6 @@ static int command(void)
lptr=(unsigned char*)strchr((char*)lptr,'\0'); /* skip to end (ignore "extra characters on line") */
} else if (strcmp(str,"dynamic")==0) {
preproc_expr(&pc_stksize,NULL);
} else if (!strcmp(str,"library")
||!strcmp(str,"reqclass")
||!strcmp(str,"loadlib")
||!strcmp(str,"explib")
||!strcmp(str,"expclass")
||!strcmp(str,"defclasslib")) {
char name[sNAMEMAX+1],sname[sNAMEMAX+1];
const char *prefix="";
sname[0]='\0';
sname[1]='\0';
if (!strcmp(str,"library"))
prefix="??li_";
else if (!strcmp(str,"reqclass"))
prefix="??rc_";
else if (!strcmp(str,"loadlib"))
prefix="??f_";
else if (!strcmp(str,"explib"))
prefix="??el_";
else if (!strcmp(str,"expclass"))
prefix="??ec_";
else if (!strcmp(str,"defclasslib"))
prefix="??d_";
while (*lptr<=' ' && *lptr!='\0')
lptr++;
if (*lptr=='"') {
lptr=getstring((unsigned char*)name,sizeof name,lptr);
} else {
int i;
for (i=0; i<sizeof name && (alphanum(*lptr) || *lptr=='-'); i++,lptr++)
name[i]=*lptr;
name[i]='\0';
if (!strncmp(str,"exp",3) || !strncmp(str,"def",3)) {
while (*lptr && isspace(*lptr))
lptr++;
for (i=1; i<sizeof sname && alphanum(*lptr); i++,lptr++)
sname[i]=*lptr;
sname[i]='\0';
if (!sname[1]) {
error(45);
} else {
sname[0]='_';
}
}
} /* if */
if (strlen(name)==0) {
curlibrary=NULL;
} else if (strcmp(name,"-")==0) {
pc_addlibtable=FALSE;
} else {
/* add the name if it does not yet exist in the table */
char newname[sNAMEMAX+1];
if (strlen(name)+strlen(prefix)+strlen(sname)<=sNAMEMAX) {
strcpy(newname,prefix);
strcat(newname,name);
strcat(newname,sname);
if (find_constval(&libname_tab,newname,0)==NULL) {
if (!strcmp(str,"library") || !strcmp(str,"reqclass")) {
curlibrary=append_constval(&libname_tab,newname,1,0);
} else {
append_constval(&libname_tab,newname,1,0);
}
}
}
} /* if */
} else if (strcmp(str,"rational")==0) {
char name[sNAMEMAX+1];
cell digits=0;
@ -1222,62 +1154,6 @@ static int command(void)
inpf=NULL;
} /* if */
break;
#if !defined NOEMIT
case tpEMIT: {
/* write opcode to output file */
char name[40];
int i;
while (*lptr<=' ' && *lptr!='\0')
lptr++;
for (i=0; i<40 && (isalpha(*lptr) || *lptr=='.'); i++,lptr++)
name[i]=(char)tolower(*lptr);
name[i]='\0';
stgwrite("\t");
stgwrite(name);
stgwrite(" ");
code_idx+=opcodes(1);
/* write parameter (if any) */
while (*lptr<=' ' && *lptr!='\0')
lptr++;
if (*lptr!='\0') {
symbol *sym;
tok=lex(&val,&str);
switch (tok) {
case tNUMBER:
case tRATIONAL:
outval(val,FALSE);
code_idx+=opargs(1);
break;
case tSYMBOL:
sym=findloc(str);
if (sym==NULL)
sym=findglb(str,sSTATEVAR);
if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0)) {
error(17,str); /* undefined symbol */
} else {
outval(sym->addr,FALSE);
/* mark symbol as "used", unknown whether for read or write */
markusage(sym,uREAD | uWRITTEN);
code_idx+=opargs(1);
} /* if */
break;
default: {
char s2[20];
extern const char *sc_tokens[];/* forward declaration */
if (tok<256)
sprintf(s2,"%c",(char)tok);
else
strcpy(s2,sc_tokens[tok-tFIRST]);
error(1,sc_tokens[tSYMBOL-tFIRST],s2);
break;
} /* case */
} /* switch */
} /* if */
stgwrite("\n");
check_empty(lptr);
break;
} /* case */
#endif
#if !defined NO_DEFINE
case tpDEFINE: {
ret=CMD_DEFINE;
@ -2047,7 +1923,7 @@ const char *sc_tokens[] = {
"volatile",
"while",
"with",
"#assert", "#define", "#else", "#elseif", "#emit", "#endif", "#endinput",
"#assert", "#define", "#else", "#elseif", "#endif", "#endinput",
"#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma",
"#tryinclude", "#undef",
";", ";", "-integer value-", "-rational value-", "-identifier-",

View File

@ -0,0 +1,5 @@
static stock const X = 5;
stock static const Y = 6;
public main()
{}

View File

@ -0,0 +1,7 @@
static stock const X = 5;
stock static const Y = 6;
public main()
{
return X + Y;
}