-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0c0de9
commit 71aca7c
Showing
31 changed files
with
375 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace cs2 | ||
{ | ||
|
||
struct CSceneObject; | ||
|
||
struct SceneObjectUpdaterHandle_t { | ||
using sceneObject = CSceneObject*; | ||
|
||
void* updaterFunctionParameter; | ||
std::uint64_t(*updaterFunction)(void* parameter); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#pragma once | ||
|
||
#include <CS2/Constants/ColorConstants.h> | ||
#include <FeatureHelpers/TeamNumber.h> | ||
|
||
#include "ModelGlowState.h" | ||
|
||
extern "C" std::uint64_t PlayerPawn_sceneObjectUpdater_asm(cs2::C_CSPlayerPawn* playerPawn) noexcept; | ||
extern "C" std::uint64_t PlayerPawn_sceneObjectUpdater_cpp(cs2::C_CSPlayerPawn* playerPawn) noexcept; | ||
|
||
template <typename HookContext> | ||
class ModelGlow { | ||
public: | ||
ModelGlow(HookContext& hookContext) noexcept | ||
: hookContext{hookContext} | ||
{ | ||
} | ||
|
||
void updateSceneObjectUpdaterHook(auto&& playerPawn) const noexcept | ||
{ | ||
if (!shouldUpdateSceneObjectUpdaterHook()) | ||
return; | ||
|
||
if (shouldGlowPlayerModel(playerPawn)) | ||
hookPlayerSceneObjectUpdater(playerPawn); | ||
else | ||
unhookPlayerSceneObjectUpdater(playerPawn); | ||
} | ||
|
||
void applyModelGlow(auto&& playerPawn) const noexcept | ||
{ | ||
if (shouldRun() && shouldGlowPlayerModel(playerPawn)) | ||
playerPawn.baseEntity().applySpawnProtectionEffectRecursively(getColor(playerPawn)); | ||
} | ||
|
||
void onEntityListTraversed() const noexcept | ||
{ | ||
if (state().masterSwitch == ModelGlowState::State::Disabling) { | ||
state().masterSwitch = ModelGlowState::State::Disabled; | ||
hookContext.hooks().viewRenderHook.decrementReferenceCount(); | ||
} | ||
|
||
if (state().playerModelGlow == ModelGlowState::State::Disabling) | ||
state().playerModelGlow = ModelGlowState::State::Disabled; | ||
} | ||
|
||
private: | ||
[[nodiscard]] bool shouldUpdateSceneObjectUpdaterHook() const noexcept | ||
{ | ||
return state().masterSwitch != ModelGlowState::State::Disabled && state().playerModelGlow != ModelGlowState::State::Disabled; | ||
} | ||
|
||
[[nodiscard]] bool shouldRun() const noexcept | ||
{ | ||
return state().masterSwitch == ModelGlowState::State::Enabled && state().playerModelGlow == ModelGlowState::State::Enabled; | ||
} | ||
|
||
void hookPlayerSceneObjectUpdater(auto&& playerPawn) const noexcept | ||
{ | ||
if (!hasSceneObjectUpdaterHooked(playerPawn)) { | ||
storeOriginalSceneObjectUpdater(playerPawn); | ||
hookSceneObjectUpdater(playerPawn); | ||
} | ||
} | ||
|
||
void unhookPlayerSceneObjectUpdater(auto&& playerPawn) const noexcept | ||
{ | ||
if (hasSceneObjectUpdaterHooked(playerPawn)) | ||
playerPawn.setSceneObjectUpdater(state().originalPlayerPawnSceneObjectUpdater); | ||
} | ||
|
||
void storeOriginalSceneObjectUpdater(auto&& playerPawn) const noexcept | ||
{ | ||
if (state().originalPlayerPawnSceneObjectUpdater == nullptr) | ||
state().originalPlayerPawnSceneObjectUpdater = playerPawn.getSceneObjectUpdater(); | ||
} | ||
|
||
[[nodiscard]] bool hasSceneObjectUpdaterHooked(auto&& playerPawn) const noexcept | ||
{ | ||
return playerPawn.getSceneObjectUpdater() == &PlayerPawn_sceneObjectUpdater_cpp; | ||
} | ||
|
||
void hookSceneObjectUpdater(auto&& playerPawn) const noexcept | ||
{ | ||
playerPawn.setSceneObjectUpdater(&PlayerPawn_sceneObjectUpdater_cpp); | ||
} | ||
|
||
[[nodiscard]] bool shouldGlowPlayerModel(auto&& playerPawn) const noexcept | ||
{ | ||
return playerPawn.isAlive().value_or(true) | ||
&& playerPawn.health().greaterThan(0).valueOr(true) | ||
&& !playerPawn.isControlledByLocalPlayer() | ||
&& playerPawn.isTTorCT() | ||
&& (!state().showOnlyEnemies || playerPawn.isEnemy().value_or(true)); | ||
} | ||
|
||
[[nodiscard]] auto& state() const noexcept | ||
{ | ||
return hookContext.featuresStates().visualFeaturesStates.modelGlowState; | ||
} | ||
|
||
[[nodiscard]] cs2::Color getColor(auto&& playerPawn) const noexcept | ||
{ | ||
switch (playerPawn.teamNumber()) { | ||
case TeamNumber::TT: return cs2::Color{255, 179, 0}; | ||
case TeamNumber::CT: return cs2::Color{0, 127, 255}; | ||
default: return cs2::kColorWhite; | ||
} | ||
} | ||
|
||
HookContext& hookContext; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <CS2/Classes/Entities/C_CSPlayerPawn.h> | ||
|
||
struct ModelGlowState { | ||
enum class State : std::uint8_t { | ||
Enabled, | ||
Disabling, | ||
Disabled | ||
}; | ||
|
||
State masterSwitch{State::Disabled}; | ||
State playerModelGlow{State::Enabled}; | ||
bool showOnlyEnemies{true}; | ||
|
||
std::uint64_t(*originalPlayerPawnSceneObjectUpdater)(cs2::C_CSPlayerPawn* playerPawn){nullptr}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <FeatureHelpers/FeatureToggle.h> | ||
|
||
template <typename HookContext> | ||
class ModelGlowToggle { | ||
public: | ||
ModelGlowToggle(HookContext& hookContext) noexcept | ||
: hookContext{hookContext} | ||
{ | ||
} | ||
|
||
void updateMasterSwitch(char option) noexcept | ||
{ | ||
switch (option) { | ||
case '0': | ||
state().masterSwitch = ModelGlowState::State::Enabled; | ||
hookContext.hooks().viewRenderHook.incrementReferenceCount(); | ||
break; | ||
case '1': | ||
state().masterSwitch = ModelGlowState::State::Disabling; | ||
break; | ||
} | ||
} | ||
|
||
void updatePlayerModelGlowToggle(char option) noexcept | ||
{ | ||
switch (option) { | ||
case '0': state().playerModelGlow = ModelGlowState::State::Enabled; state().showOnlyEnemies = true; break; | ||
case '1': state().playerModelGlow = ModelGlowState::State::Enabled; state().showOnlyEnemies = false; break; | ||
case '2': state().playerModelGlow = ModelGlowState::State::Disabling; break; | ||
} | ||
} | ||
|
||
private: | ||
[[nodiscard]] auto& state() const noexcept | ||
{ | ||
return hookContext.featuresStates().visualFeaturesStates.modelGlowState; | ||
} | ||
|
||
HookContext& hookContext; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.