Skip to content

Commit e09be49

Browse files
committed
Add Wallhack Dynamic colour
1 parent bf63dda commit e09be49

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

src/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class FunniesConfig : BasePluginConfig
1414

1515
public class WallHackConfig
1616
{
17+
[JsonPropertyName("DynamicColor")] public bool dynamicColor { get; set; } = true;
1718
[JsonPropertyName("ColorR")] public byte R { get; set; } = 171;
1819
[JsonPropertyName("ColorG")] public byte G { get; set; } = 75;
1920
[JsonPropertyName("ColorB")] public byte B { get; set; } = 209;

src/Modules/SelfDamage.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ public static HookResult OnPlayerShoot(EventWeaponFire @event, GameEventInfo inf
5555

5656
int damage = getWeaponDamage(@event.Weapon);
5757

58-
int newHealth = @event.Userid.PlayerPawn.Value.Health - damage;
59-
60-
player.PlayerPawn.Value.Health = newHealth;
58+
int newHealth = player.PlayerPawn.Value.Health - damage;
6159

6260
if (newHealth <= 0)
6361
{

src/Modules/Wallhack.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,34 @@ public static HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo in
3636
if (player!.Team < CsTeam.Terrorist) return HookResult.Continue; // if player isnt on a team
3737
// var gameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First();
3838
// if (gameRules.GameRules!.WarmupPeriod) return HookResult.Continue;
39-
4039

4140
CreateWallhackData(player!);
4241

4342
return HookResult.Continue;
4443
}
4544

45+
public static HookResult OnPlayerTakeDamage(EventPlayerHurt @event, GameEventInfo info)
46+
{
47+
if (Globals.Config.WallHackConfig.dynamicColor)
48+
{
49+
Globals.WallhackData.TryGetValue(@event.Userid, out var wallhackData);
50+
51+
var health = @event.Health;
52+
53+
health = Math.Clamp(health, 1, 100);
54+
55+
float t = (health - 1) / 99f;
56+
57+
int r = (int)(255 * (1f - t));
58+
int g = (int)(255 * t);
59+
60+
wallhackData.GlowEnt.Glow.GlowColorOverride = Color.FromArgb(255 , r, g, 0);
61+
Utilities.SetStateChanged(wallhackData.GlowEnt, "CBaseModelEntity", "m_Glow");
62+
}
63+
64+
return HookResult.Continue;
65+
}
66+
4667
public static HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
4768
{
4869
var player = @event.Userid;
@@ -102,10 +123,18 @@ private static void CreateWallhackData(CCSPlayerController player)
102123

103124
glowEntity.DispatchSpawn();
104125
modelRelay.DispatchSpawn();
126+
127+
Color color = Color.FromArgb(255, Globals.Config.WallHackConfig.R, Globals.Config.WallHackConfig.G, Globals.Config.WallHackConfig.B);
128+
129+
if (Globals.Config.WallHackConfig.dynamicColor)
130+
{
131+
color = Color.FromArgb(255, 0, 255, 0);
132+
}
133+
105134

106135
glowEntity.Glow.GlowRange = 5000;
107136
glowEntity.Glow.GlowRangeMin = 0;
108-
glowEntity.Glow.GlowColorOverride = Color.FromArgb(255, Globals.Config.WallHackConfig.R, Globals.Config.WallHackConfig.G, Globals.Config.WallHackConfig.B);
137+
glowEntity.Glow.GlowColorOverride = color;
109138
glowEntity.Glow.GlowTeam = -1;
110139
glowEntity.Glow.GlowType = 3;
111140

@@ -133,6 +162,7 @@ public static void Setup()
133162
Globals.Plugin.RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);
134163
Globals.Plugin.RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn, HookMode.Post);
135164
Globals.Plugin.RegisterEventHandler<EventPlayerTeam>(OnPlayerChangeTeam, HookMode.Post);
165+
Globals.Plugin.RegisterEventHandler<EventPlayerHurt>(OnPlayerTakeDamage);
136166

137167
Globals.Plugin.AddCommand("css_wh", "Gives a player walls", CommandWallhack.OnWallhackCommand);
138168
Globals.Plugin.AddCommand("css_wallhack", "Gives a player walls", CommandWallhack.OnWallhackCommand);

0 commit comments

Comments
 (0)