Merge pull request #448 from alliedmodders/use-blamepluginerror

Update SP and use BlamePluginError in sdkhooks and sdktools.
This commit is contained in:
Fyren 2015-11-18 18:33:10 -07:00
commit 0e80ffef55
4 changed files with 60 additions and 38 deletions

View File

@ -157,39 +157,60 @@ int DebugReport::_GetPluginIndex(IPluginContext *ctx)
void DebugReport::ReportError(const IErrorReport &report, IFrameIterator &iter) void DebugReport::ReportError(const IErrorReport &report, IFrameIterator &iter)
{ {
// Find the nearest plugin to blame.
const char *blame = nullptr; const char *blame = nullptr;
for (; !iter.Done(); iter.Next()) { if (report.Blame())
if (iter.IsScriptedFrame()) { {
blame = report.Blame()->DebugName();
} else {
// Find the nearest plugin to blame.
for (; !iter.Done(); iter.Next())
{
if (iter.IsScriptedFrame())
{
IPlugin *plugin = pluginsys->FindPluginByContext(iter.Context()->GetContext()); IPlugin *plugin = pluginsys->FindPluginByContext(iter.Context()->GetContext());
if (plugin) if (plugin)
{
blame = plugin->GetFilename(); blame = plugin->GetFilename();
else } else {
blame = iter.Context()->GetRuntime()->GetFilename(); blame = iter.Context()->GetRuntime()->GetFilename();
}
break; break;
} }
} }
}
iter.Reset(); iter.Reset();
g_Logger.LogError("[SM] Exception reported: %s", report.Message()); g_Logger.LogError("[SM] Exception reported: %s", report.Message());
if (blame) if (blame)
g_Logger.LogError("[SM] Blaming plugin: %s", blame); {
g_Logger.LogError("[SM] Blaming: %s()", blame);
}
if (!iter.Done())
{
g_Logger.LogError("[SM] Call stack trace:"); g_Logger.LogError("[SM] Call stack trace:");
for (int index = 0; !iter.Done(); iter.Next(), index++) { for (int index = 0; !iter.Done(); iter.Next(), index++)
{
const char *fn = iter.FunctionName(); const char *fn = iter.FunctionName();
if (!fn) if (!fn)
{
fn = "<unknown function>"; fn = "<unknown function>";
}
if (iter.IsNativeFrame()) { if (iter.IsNativeFrame())
{
g_Logger.LogError("[SM] [%d] %s", index, fn); g_Logger.LogError("[SM] [%d] %s", index, fn);
continue; continue;
} }
if (iter.IsScriptedFrame()) { if (iter.IsScriptedFrame())
{
const char *file = iter.FilePath(); const char *file = iter.FilePath();
if (!file) if (!file)
{
file = "<unknown>"; file = "<unknown>";
}
g_Logger.LogError("[SM] [%d] Line %d, %s::%s()", g_Logger.LogError("[SM] [%d] Line %d, %s::%s()",
index, index,
iter.LineNumber(), iter.LineNumber(),
@ -198,3 +219,4 @@ void DebugReport::ReportError(const IErrorReport &report, IFrameIterator &iter)
} }
} }
} }
}

View File

@ -1059,13 +1059,13 @@ int SDKHooks::HandleOnTakeDamageHook(CTakeDamageInfoHack &info, SDKHookType hook
CBaseEntity *pEntAttacker = gamehelpers->ReferenceToEntity(attacker); CBaseEntity *pEntAttacker = gamehelpers->ReferenceToEntity(attacker);
if (!pEntAttacker) if (!pEntAttacker)
{ {
callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for attacker is invalid", attacker); callback->GetParentContext()->BlamePluginError(callback, "Callback-provided entity %d for attacker is invalid", attacker);
RETURN_META_VALUE(MRES_IGNORED, 0); RETURN_META_VALUE(MRES_IGNORED, 0);
} }
CBaseEntity *pEntInflictor = gamehelpers->ReferenceToEntity(inflictor); CBaseEntity *pEntInflictor = gamehelpers->ReferenceToEntity(inflictor);
if (!pEntInflictor) if (!pEntInflictor)
{ {
callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for inflictor is invalid", inflictor); callback->GetParentContext()->BlamePluginError(callback, "Callback-provided entity %d for inflictor is invalid", inflictor);
RETURN_META_VALUE(MRES_IGNORED, 0); RETURN_META_VALUE(MRES_IGNORED, 0);
} }
@ -1442,13 +1442,13 @@ void SDKHooks::Hook_TraceAttack(CTakeDamageInfoHack &info, const Vector &vecDir,
CBaseEntity *pEntAttacker = gamehelpers->ReferenceToEntity(attacker); CBaseEntity *pEntAttacker = gamehelpers->ReferenceToEntity(attacker);
if(!pEntAttacker) if(!pEntAttacker)
{ {
callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for attacker is invalid", attacker); callback->GetParentContext()->BlamePluginError(callback, "Callback-provided entity %d for attacker is invalid", attacker);
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
CBaseEntity *pEntInflictor = gamehelpers->ReferenceToEntity(inflictor); CBaseEntity *pEntInflictor = gamehelpers->ReferenceToEntity(inflictor);
if(!pEntInflictor) if(!pEntInflictor)
{ {
callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for inflictor is invalid", inflictor); callback->GetParentContext()->BlamePluginError(callback, "Callback-provided entity %d for inflictor is invalid", inflictor);
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }

View File

@ -410,9 +410,9 @@ void SoundHooks::OnEmitSound(IRecipientFilter &filter, int iEntIndex, int iChann
if (!pPlayer) if (!pPlayer)
{ {
pFunc->GetParentContext()->ThrowNativeError("Client index %d is invalid", client); pFunc->GetParentContext()->BlamePluginError(pFunc, "Callback-provided client index %d is invalid", client);
} else if (!pPlayer->IsInGame()) { } else if (!pPlayer->IsInGame()) {
pFunc->GetParentContext()->ThrowNativeError("Client %d is not connected", client); pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not connected", client);
} else { } else {
continue; continue;
} }
@ -548,9 +548,9 @@ void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChan
if (!pPlayer) if (!pPlayer)
{ {
pFunc->GetParentContext()->ThrowNativeError("Client index %d is invalid", client); pFunc->GetParentContext()->BlamePluginError(pFunc, "Client index %d is invalid", client);
} else if (!pPlayer->IsInGame()) { } else if (!pPlayer->IsInGame()) {
pFunc->GetParentContext()->ThrowNativeError("Client %d is not connected", client); pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not connected", client);
} else { } else {
continue; continue;
} }

@ -1 +1 @@
Subproject commit dde42ef136c59ae125169a850298b1383e53afb6 Subproject commit 22e7ddeeac40503d51a27e228e8de49ca49566af