| 387 | } |
| 388 | |
| 389 | void LevelScriptLoader::OnLevelCallback(Actors::ActorBase* initiator, uint8_t* eventParams) |
| 390 | { |
| 391 | std::uint32_t callbackId = eventParams[0]; |
| 392 | if (!_enabledCallbacks[callbackId]) { |
| 393 | return; |
| 394 | } |
| 395 | |
| 396 | if (eventParams[2]) { // Vanish |
| 397 | _enabledCallbacks.reset(callbackId); |
| 398 | } |
| 399 | |
| 400 | char funcName[32]; |
| 401 | std::size_t length = formatInto(funcName, "onFunction{}", callbackId); |
| 402 | funcName[length] = '\0'; |
| 403 | |
| 404 | asIScriptFunction* func = GetMainModule()->GetFunctionByName(funcName); |
| 405 | if (func != nullptr) { |
| 406 | OnBeforeScriptCall(); |
| 407 | asIScriptContext* ctx = GetEngine()->RequestContext(); |
| 408 | |
| 409 | ctx->Prepare(func); |
| 410 | |
| 411 | std::int32_t paramIdx = 0; |
| 412 | std::int32_t typeId = 0; |
| 413 | if (func->GetParam(paramIdx, &typeId) >= 0) { |
| 414 | if ((typeId & (asTYPEID_OBJHANDLE | asTYPEID_APPOBJECT)) == (asTYPEID_OBJHANDLE | asTYPEID_APPOBJECT)) { |
| 415 | asITypeInfo* typeInfo = GetEngine()->GetTypeInfoById(typeId); |
| 416 | if (typeInfo->GetName() == "jjPLAYER"_s) { |
| 417 | if (auto* player = runtime_cast<Actors::Player>(initiator)) { |
| 418 | jjPLAYER* p = GetPlayerBackingStore(player); |
| 419 | ctx->SetArgObject(0, p); |
| 420 | } else { |
| 421 | // Player is required but wasn't provided |
| 422 | return; |
| 423 | } |
| 424 | } |
| 425 | paramIdx++; |
| 426 | } |
| 427 | } |
| 428 | if (func->GetParam(paramIdx, &typeId) >= 0) { |
| 429 | if (typeId == asTYPEID_BOOL || typeId == asTYPEID_INT8 || typeId == asTYPEID_UINT8) { |
| 430 | ctx->SetArgByte(1, eventParams[1]); |
| 431 | paramIdx++; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | std::int32_t r = ctx->Execute(); |
| 436 | if (r == asEXECUTION_EXCEPTION) { |
| 437 | AS_LOG_EXCEPTION(ctx); |
| 438 | } |
| 439 | |
| 440 | GetEngine()->ReturnContext(ctx); |
| 441 | OnAfterScriptCall(); |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | LOGW("Callback function \"{}\" was not found in the script. Please correct the code and try again.", funcName); |
| 446 | } |
no test coverage detected