Skip to content

Commit

Permalink
debug error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Oct 5, 2023
1 parent a191fb0 commit 95e0e56
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/bo4-dll/detours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,33 @@ static cliconnect::DetourInfo<bo4::BuiltinFunction, UINT32, bo4::BuiltinType*, i

// Custom detours
static void ScrVm_Error(UINT64 code, scriptinstance::ScriptInstance inst, char* unk, bool terminal) {
if (code == custom_gsc_func::custom_error_id) { // detect custom error
static CHAR errorBuffer[2][0x200] = { 0 };
if (code == custom_gsc_func::custom_error_id) { // ACTS detect custom error, the error is already set
LOG_ERROR("VM {} ACTS Error '{}' terminal={}", scriptinstance::Name(inst), unk, terminal ? "true" : "false");
}
else if (code == 2737681163) { // Assert(val, msg) with message error
const auto* msg = bo4::ScrVm_GetString(inst, 2);
snprintf(errorBuffer[inst], sizeof(errorBuffer[inst]), "assert fail: %s", msg);
bo4::scrVarPub[inst].error_message = errorBuffer[inst];
}
else if (code == 1385570291) { // AssertMsg(msg)
const auto* msg = bo4::ScrVm_GetString(inst, 1);
snprintf(errorBuffer[inst], sizeof(errorBuffer[inst]), "assert fail: %s", msg);
bo4::scrVarPub[inst].error_message = errorBuffer[inst];
}
else if (code == 2532286589) { // ErrorMsg(msg)
const auto* msg = bo4::ScrVm_GetString(inst, 1);
snprintf(errorBuffer[inst], sizeof(errorBuffer[inst]), "error: %s", msg);
bo4::scrVarPub[inst].error_message = errorBuffer[inst];
}
else {
auto desc = error_handler::FindDesc((UINT32)code);
LOG_ERROR("VM {} Error code={} '{}' terminal={}", scriptinstance::Name(inst), code, unk, terminal ? "true" : "false");
if (desc) {
// update the error info to match the error
bo4::scrVarPub[inst].error_message = desc;
}

}
dScrVm_Error(code, inst, unk, terminal);
}
Expand Down
20 changes: 20 additions & 0 deletions src/bo4-dll/error_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ std::unordered_map<UINT64, LPCCH> error_handler::errors = {
{ 1895566756, "dvar is not a 3d vector, but GetDvarVector3D has been called on it" },
{ 4163774148, "Optional argument must be a float or integer type" },
{ 941828720, "exitlevel already called" },
{ 1047729873, "exitlevel already called" },
{ 946363963, "Invalid opcode" },
{ 4047738848, "Invalid opcode (Recovery)" },
{ 4106063796, "key value provided for array is not valid" },
Expand All @@ -49,6 +50,25 @@ std::unordered_map<UINT64, LPCCH> error_handler::errors = {
{ 2572009355, "vector scale expecting vector" },
{ 2269096660, "vector scale expecting vector" },
{ 3222417139, "size cannot be applied to type" },
{ 219569925, "hasperk() can only be called on local players" },
{ 968521323, "player hasperk(<localClientNum>, <perk>): localClientNum out of range" },
{ 57350207, "Unknown perk" },
{ 3015158315, "getperks() can only be called on local players" },
{ 3990130335, "player getperks(<localClientNum>): localClientNum out of range" },
{ 665902298, "Parameter must be an array" },
{ 2687742442, "Forced script exception." },
{ 1850691545, "Debug Break" },
{ 2344222932, "assert fail" },
{ 209668787, "RandomInt parm must be positive integer." },
{ 753495682, "RandomIntRange's second parameter must be greater than the first." },
{ 1045192683, "Scr_RandomFloatRange's second parameter must be greater than the first." },

// messages handled by detours
{ 2737681163, "assert fail (with message)" },
{ 1385570291, "assert fail (with message)" },
{ 2532286589, "error message"},


};

LPCCH error_handler::FindDesc(UINT64 code) {
Expand Down

0 comments on commit 95e0e56

Please sign in to comment.