| 553 | } |
| 554 | |
| 555 | void ScriptExtender::PostStartup() |
| 556 | { |
| 557 | if (postStartupDone_) return; |
| 558 | |
| 559 | std::lock_guard _(globalStateLock_); |
| 560 | // We need to initialize the function library here, as GlobalAllocator isn't available in Init(). |
| 561 | if (Libraries.PostStartupFindLibraries()) { |
| 562 | lua::InitObjectProxyPropertyMaps(); |
| 563 | TypeInformationRepository::GetInstance().Initialize(); |
| 564 | lua::RegisterLibraries(); |
| 565 | TypeInformationRepository::GetInstance().Finalize(); |
| 566 | |
| 567 | // Jank workaround to game bug where the reference count for FixedString 0 (the "Cast" key) |
| 568 | // gets erroneously decremented during module load. |
| 569 | FixedString cast("Cast"); |
| 570 | const_cast<FixedStringBase::Header*>(cast.GetMetadata())->RefCount = 100000; |
| 571 | |
| 572 | engineHooks_.HookAll(); |
| 573 | hooks_.Startup(); |
| 574 | server_.PostStartup(); |
| 575 | client_.PostStartup(); |
| 576 | |
| 577 | luaBuiltinBundle_.SetResourcePath(config_.LuaBuiltinResourceDirectory); |
| 578 | if (!luaBuiltinBundle_.LoadBuiltinResource(IDR_LUA_BUILTIN_BUNDLE)) { |
| 579 | ERR("Failed to load Lua builtin resource bundle!"); |
| 580 | } |
| 581 | |
| 582 | engineHooks_.FileReader__ctor.SetWrapper(&ScriptExtender::OnFileReaderCreate, this); |
| 583 | //engineHooks_.Kernel_FindFirstFileW.SetWrapper(&ScriptExtender::OnFindFirstFileW, this); |
| 584 | //engineHooks_.Kernel_FindNextFileW.SetWrapper(&ScriptExtender::OnFindNextFileW, this); |
| 585 | //engineHooks_.Kernel_FindClose.SetWrapper(&ScriptExtender::OnFindClose, this); |
| 586 | |
| 587 | engineHooks_.RPGStats__Load.SetWrapper(&ScriptExtender::OnStatsLoad, this); |
| 588 | engineHooks_.ecs__EntityWorld__Update.SetWrapper(&ScriptExtender::OnECSUpdate, this); |
| 589 | engineHooks_.ecs__EntityWorld__FlushECBs.SetPreHook(&ScriptExtender::OnECSFlushECBs, this); |
| 590 | engineHooks_.eoc__AiGrid__FindPath.SetPreHook(&ScriptExtender::OnFindPath, this); |
| 591 | } |
| 592 | |
| 593 | GameVersionInfo gameVersion; |
| 594 | if (Libraries.GetGameVersion(gameVersion) && !gameVersion.IsSupported()) { |
| 595 | std::stringstream ss; |
| 596 | ss << "Your game version (v" << gameVersion.Major << "." << gameVersion.Minor << "." << gameVersion.Revision << "." << gameVersion.Build |
| 597 | << ") is not supported by the Script Extender"; |
| 598 | Libraries.ShowStartupError(ss.str().c_str(), true, false); |
| 599 | } else if (Libraries.CriticalInitializationFailed()) { |
| 600 | Libraries.ShowStartupError("A severe error has occurred during Script Extender initialization. Extension features will be unavailable.", true, false); |
| 601 | } else if (Libraries.InitializationFailed()) { |
| 602 | Libraries.ShowStartupError("An error has occurred during Script Extender initialization. Some extension features might be unavailable.", true, false); |
| 603 | } |
| 604 | |
| 605 | HookStateMachineUpdates(); |
| 606 | |
| 607 | postStartupDone_ = true; |
| 608 | } |
| 609 | |
| 610 | void ScriptExtender::InitRuntimeLogging() |
| 611 | { |
nothing calls this directly
no test coverage detected