|
4 | 4 | #include "Hooks/PeepEventsHook.h" |
5 | 5 | #include "Utils/ReturnAddress.h" |
6 | 6 |
|
| 7 | +[[NOINLINE]] void finishInit(auto& hookContext) |
| 8 | +{ |
| 9 | + hookContext.entityClassifier().init(hookContext); |
| 10 | + if (const auto mainMenu{hookContext.patternSearchResults().template get<MainMenuPanelPointer>()}; mainMenu && *mainMenu) |
| 11 | + hookContext.template make<PanoramaGUI>().init(hookContext.template make<PanoramaUiPanel>((*mainMenu)->uiPanel)); |
| 12 | + hookContext.config().init(); |
| 13 | + hookContext.config().scheduleLoad(); |
| 14 | + hookContext.hooks().peepEventsHook.disable(); |
| 15 | + hookContext.hooks().viewRenderHook.install(); |
| 16 | +} |
| 17 | + |
7 | 18 | int SDLHook_PeepEvents(void* events, int numevents, int action, unsigned minType, unsigned maxType) noexcept |
8 | 19 | { |
9 | | - return GlobalContext::instance().peepEventsHook(events, numevents, action, minType, maxType); |
| 20 | + const auto initInProgress = !HookContext<GlobalContext>::isGlobalContextComplete(); |
| 21 | + if (initInProgress) |
| 22 | + HookContext<GlobalContext>::initCompleteGlobalContextFromGameThread(); |
| 23 | + |
| 24 | + HookContext<GlobalContext> hookContext; |
| 25 | + |
| 26 | + if (initInProgress) |
| 27 | + finishInit(hookContext); |
| 28 | + |
| 29 | + return hookContext.hooks().peepEventsHook.original(events, numevents, action, minType, maxType); |
| 30 | +} |
| 31 | + |
| 32 | +[[NOINLINE]] void unload(auto& hookContext) noexcept |
| 33 | +{ |
| 34 | + hookContext.template make<BombTimer>().onUnload(); |
| 35 | + hookContext.template make<DefusingAlert>().onUnload(); |
| 36 | + hookContext.template make<PostRoundTimer>().onUnload(); |
| 37 | + hookContext.template make<OutlineGlow>().onUnload(); |
| 38 | + hookContext.template make<BombStatusPanel>().onUnload(); |
| 39 | + hookContext.template make<InWorldPanels>().onUnload(); |
| 40 | + hookContext.template make<PanoramaGUI>().onUnload(); |
| 41 | + hookContext.hooks().viewRenderHook.uninstall(); |
| 42 | + hookContext.template make<ClientModeHooks>().restoreGetViewmodelFov(); |
| 43 | + hookContext.template make<PlayerModelGlowPreview>().onUnload(); |
| 44 | + hookContext.template make<WeaponModelGlowPreview>().onUnload(); |
| 45 | + hookContext.template make<NoScopeInaccuracyVis>().onUnload(); |
| 46 | + hookContext.template make<BombPlantAlert>().onUnload(); |
| 47 | + |
| 48 | + hookContext.template make<EntitySystem>().forEachNetworkableEntityIdentity([&hookContext](const auto& entityIdentity) { |
| 49 | + auto&& baseEntity = hookContext.template make<BaseEntity>(static_cast<cs2::C_BaseEntity*>(entityIdentity.entity)); |
| 50 | + const auto entityTypeInfo = baseEntity.classify(); |
| 51 | + if (entityTypeInfo.template is<cs2::C_CSPlayerPawn>()) |
| 52 | + hookContext.template make<ModelGlow>().onUnload()(PlayerModelGlow{hookContext}, baseEntity.template as<PlayerPawn>()); |
| 53 | + else if (entityTypeInfo.template is<cs2::C_C4>()) |
| 54 | + hookContext.template make<ModelGlow>().onUnload()(DroppedBombModelGlow{hookContext}, baseEntity.template as<BaseWeapon>()); |
| 55 | + else if (entityTypeInfo.template is<cs2::CBaseAnimGraph>()) |
| 56 | + hookContext.template make<ModelGlow>().onUnload()(DefuseKitModelGlow{hookContext}, baseEntity); |
| 57 | + else if (entityTypeInfo.template is<cs2::CPlantedC4>()) |
| 58 | + hookContext.template make<ModelGlow>().onUnload()(TickingBombModelGlow{hookContext}, baseEntity.template as<PlantedC4>()); |
| 59 | + else if (entityTypeInfo.isGrenadeProjectile()) |
| 60 | + hookContext.template make<ModelGlow>().onUnload()(GrenadeProjectileModelGlow{hookContext}, baseEntity); |
| 61 | + else if (entityTypeInfo.isWeapon()) |
| 62 | + hookContext.template make<ModelGlow>().onUnload()(WeaponModelGlow{hookContext}, baseEntity.template as<BaseWeapon>()); |
| 63 | + }); |
10 | 64 | } |
11 | 65 |
|
12 | 66 | void ViewRenderHook_onRenderStart(cs2::CViewRender* thisptr) noexcept |
13 | 67 | { |
14 | | - const auto unloadFlag = GlobalContext::instance().onRenderStartHook(thisptr); |
15 | | - if (unloadFlag) |
16 | | - GlobalContext::destroyInstance(); |
| 68 | + HookContext<GlobalContext> hookContext; |
| 69 | + hookContext.hooks().viewRenderHook.getOriginalOnRenderStart()(thisptr); |
| 70 | + hookContext.make<InWorldPanels>().updateState(); |
| 71 | + SoundWatcher<decltype(hookContext)> soundWatcher{hookContext.soundWatcherState(), hookContext}; |
| 72 | + soundWatcher.update(); |
| 73 | + SoundFeatures{hookContext.soundWatcherState(), hookContext.hooks().viewRenderHook, hookContext}.runOnViewMatrixUpdate(); |
| 74 | + |
| 75 | + hookContext.make<NoScopeInaccuracyVis>().update(); |
| 76 | + hookContext.make<RenderingHookEntityLoop>().run(); |
| 77 | + hookContext.make<GlowSceneObjects>().removeUnreferencedObjects(); |
| 78 | + hookContext.make<DefusingAlert>().run(); |
| 79 | + hookContext.make<KillfeedPreserver>().run(); |
| 80 | + hookContext.make<BombStatusPanelManager>().run(); |
| 81 | + hookContext.make<InWorldPanels>().hideUnusedPanels(); |
| 82 | + |
| 83 | + UnloadFlag unloadFlag; |
| 84 | + hookContext.make<PanoramaGUI>().run(unloadFlag); |
| 85 | + hookContext.config().update(); |
| 86 | + hookContext.config().performFileOperation(); |
| 87 | + |
| 88 | + if (unloadFlag) { |
| 89 | + unload(hookContext); |
| 90 | + HookContext<GlobalContext>::destroyGlobalContext(); |
| 91 | + } |
17 | 92 | } |
18 | 93 |
|
19 | 94 | LINUX_ONLY([[gnu::aligned(8)]]) std::uint64_t PlayerPawn_sceneObjectUpdater(cs2::C_CSPlayerPawn* playerPawn, void* unknown, bool unknownBool) noexcept |
20 | 95 | { |
21 | | - return GlobalContext::instance().playerPawnSceneObjectUpdater(playerPawn, unknown, unknownBool); |
| 96 | + HookContext<GlobalContext> hookContext; |
| 97 | + const auto originalReturnValue = hookContext.featuresStates().visualFeaturesStates.modelGlowState.originalPlayerPawnSceneObjectUpdater(playerPawn, unknown, unknownBool); |
| 98 | + |
| 99 | + auto&& playerPawn_ = hookContext.make<PlayerPawn>(playerPawn); |
| 100 | + if (auto&& previewPlayer = playerPawn_.template cast<PreviewPlayer>(); !previewPlayer) |
| 101 | + hookContext.make<ModelGlow>().updateInSceneObjectUpdater()(PlayerModelGlow{hookContext}, playerPawn_, EntityTypeInfo{}); |
| 102 | + else |
| 103 | + hookContext.make<PlayerModelGlowPreview>().applyPreviewPlayerModelGlow(previewPlayer); |
| 104 | + |
| 105 | + return originalReturnValue; |
22 | 106 | } |
23 | 107 |
|
24 | 108 | LINUX_ONLY([[gnu::aligned(8)]]) std::uint64_t Weapon_sceneObjectUpdater(cs2::C_CSWeaponBase* weapon, void* unknown, bool unknownBool) noexcept |
25 | 109 | { |
26 | | - return GlobalContext::instance().weaponSceneObjectUpdater(weapon, unknown, unknownBool); |
| 110 | + HookContext<GlobalContext> hookContext; |
| 111 | + const auto originalReturnValue = hookContext.featuresStates().visualFeaturesStates.modelGlowState.originalWeaponSceneObjectUpdater(weapon, unknown, unknownBool); |
| 112 | + if (auto&& c4 = hookContext.make<BaseWeapon>(weapon).template cast<C4>()) |
| 113 | + hookContext.make<ModelGlow>().updateInSceneObjectUpdater()(DroppedBombModelGlow{hookContext}, c4.baseWeapon(), EntityTypeInfo{}); |
| 114 | + else |
| 115 | + hookContext.make<ModelGlow>().updateInSceneObjectUpdater()(WeaponModelGlow{hookContext}, hookContext.make<BaseWeapon>(weapon), hookContext.make<BaseWeapon>(weapon).baseEntity().classify()); |
| 116 | + return originalReturnValue; |
27 | 117 | } |
28 | 118 |
|
29 | 119 | float ClientModeHook_getViewmodelFov(cs2::ClientModeCSNormal* clientMode) noexcept |
30 | 120 | { |
31 | | - return GlobalContext::instance().getViewmodelFovHook(clientMode); |
| 121 | + HookContext<GlobalContext> hookContext; |
| 122 | + const auto originalFov = hookContext.hooks().originalGetViewmodelFov(clientMode); |
| 123 | + if (auto&& viewmodelMod = hookContext.template make<ViewmodelMod>(); viewmodelMod.shouldModifyViewmodelFov()) |
| 124 | + return viewmodelMod.viewmodelFov(); |
| 125 | + return originalFov; |
32 | 126 | } |
0 commit comments