This repository was archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagicBulletFix.cs
More file actions
111 lines (90 loc) · 3.78 KB
/
MagicBulletFix.cs
File metadata and controls
111 lines (90 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System.Numerics;
using System.Text.Json.Serialization;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Config;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
namespace MagicBulletFix;
public enum FixMethod_t
{
ALLOW = 0,
IGNORE = 1,
REFLECT = 2,
REFLECT_SAFE = 3
}
public class MagicBulletFixConfig : BasePluginConfig
{
[JsonPropertyName("ChatMessage")] public string ChatMessage { get; set; } = " \u0002Applied Magic Bullet penalty.";
[JsonPropertyName("FixMethod")] public FixMethod_t FixMethod { get; set; } = FixMethod_t.IGNORE;
[JsonPropertyName("ReflectScale")] public float ReflectScale { get; set; } = 1f;
}
public class CMagicBulletFix : BasePlugin, IPluginConfig<MagicBulletFixConfig>
{
public override string ModuleName => "Magic Bullet Fix";
public override string ModuleVersion => "1.0";
public override string ModuleAuthor => "jon & sapphyrus";
public override string ModuleDescription => "Blocks magic bullet with configurability";
public MagicBulletFixConfig Config { get; set; }
public HashSet<uint> magicBullets = new();
public Dictionary<uint, int> magicBulletWarnings = new();
public void OnConfigParsed(MagicBulletFixConfig config)
{
Config = config;
}
public override void Load(bool hotReload)
{
Console.WriteLine("Loaded MagicBulletFix");
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(h =>
{
var damageInfo = h.GetParam<CTakeDamageInfo>(1);
if (magicBullets.Contains(damageInfo.Attacker.Index) && damageInfo.Attacker.Value != null)
{
switch (Config.FixMethod)
{
case FixMethod_t.ALLOW:
break;
case FixMethod_t.IGNORE:
damageInfo.Damage = 0;
break;
case FixMethod_t.REFLECT:
case FixMethod_t.REFLECT_SAFE:
damageInfo.Damage *= Config.ReflectScale;
h.SetParam<CEntityInstance>(0, damageInfo.Attacker.Value);
if (Config.FixMethod == FixMethod_t.REFLECT_SAFE)
damageInfo.DamageFlags |= TakeDamageFlags_t.DFLAG_PREVENT_DEATH; //https://docs.cssharp.dev/api/CounterStrikeSharp.API.Core.TakeDamageFlags_t.html
break;
}
return HookResult.Changed;
}
return HookResult.Continue;
}, HookMode.Pre);
RegisterEventHandler<EventBulletFlightResolution>((evt, info) =>
{
if (evt.StartX == 0 && evt.StartY == 0 && evt.StartZ == 0)
{
if (magicBullets.Count == 0)
{
Server.NextFrame(() =>
{
magicBullets.Clear();
});
}
magicBullets.Add(evt.Userid.Pawn.Index);
if (!magicBulletWarnings.ContainsKey(evt.Userid.Pawn.Index) || Server.TickCount - magicBulletWarnings[evt.Userid.Pawn.Index] > Server.TickInterval * 5)
{
magicBulletWarnings[evt.Userid.Pawn.Index] = Server.TickCount;
CCSPlayerController penaltyReceiver = evt.Userid;
Server.NextFrame(() =>
{
penaltyReceiver.PrintToChat(Config.ChatMessage);
});
}
return HookResult.Handled;
}
return HookResult.Continue;
});
}
}