working weapon concealment
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.369" />
|
||||
<Compile Include="..\SendProxyNative.cs" Link="SendProxyNative.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,91 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Timers;
|
||||
using SendProxyInterop;
|
||||
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;
|
||||
|
||||
namespace SendProxyHealth23;
|
||||
|
||||
public sealed class SendProxyHealth23Plugin : BasePlugin
|
||||
{
|
||||
private const int RecipientAll = -1;
|
||||
private const int SpoofedHealth = 23;
|
||||
|
||||
private readonly Dictionary<int, int> _rulesByPawnIndex = new();
|
||||
private SendProxyNative? _sendProxy;
|
||||
private Timer? _syncTimer;
|
||||
|
||||
public override string ModuleName => "SendProxy Health 23";
|
||||
public override string ModuleVersion => "0.1.0";
|
||||
public override string ModuleAuthor => "OpenAI Codex";
|
||||
|
||||
public override void Load(bool hotReload)
|
||||
{
|
||||
_sendProxy = SendProxyNative.FromGameDirectory(Server.GameDirectory);
|
||||
_syncTimer = AddTimer(0.25f, SyncRules, TimerFlags.REPEAT);
|
||||
Server.NextFrame(SyncRules);
|
||||
}
|
||||
|
||||
public override void Unload(bool hotReload)
|
||||
{
|
||||
_syncTimer?.Kill();
|
||||
ClearRules();
|
||||
_sendProxy?.Dispose();
|
||||
_sendProxy = null;
|
||||
}
|
||||
|
||||
private void SyncRules()
|
||||
{
|
||||
if (_sendProxy == null)
|
||||
return;
|
||||
|
||||
int[] desiredPawnIndexes;
|
||||
try
|
||||
{
|
||||
desiredPawnIndexes = Utilities.GetPlayers()
|
||||
.Select(player => player.PlayerPawn.Value)
|
||||
.Where(pawn => pawn != null && pawn.IsValid)
|
||||
.Select(pawn => (int)pawn!.Index)
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
}
|
||||
catch (NativeException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var desired = desiredPawnIndexes.ToHashSet();
|
||||
|
||||
foreach (int pawnIndex in _rulesByPawnIndex.Keys.Except(desired).ToArray())
|
||||
{
|
||||
_sendProxy.RemoveOverride(_rulesByPawnIndex[pawnIndex]);
|
||||
_rulesByPawnIndex.Remove(pawnIndex);
|
||||
}
|
||||
|
||||
foreach (int pawnIndex in desiredPawnIndexes)
|
||||
{
|
||||
if (_rulesByPawnIndex.ContainsKey(pawnIndex))
|
||||
continue;
|
||||
|
||||
int ruleId = _sendProxy.SetInt32(
|
||||
RecipientAll,
|
||||
pawnIndex,
|
||||
"CBaseEntity",
|
||||
"m_iHealth",
|
||||
SpoofedHealth);
|
||||
|
||||
if (ruleId != 0)
|
||||
_rulesByPawnIndex[pawnIndex] = ruleId;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearRules()
|
||||
{
|
||||
if (_sendProxy == null)
|
||||
return;
|
||||
|
||||
foreach (int ruleId in _rulesByPawnIndex.Values)
|
||||
_sendProxy.RemoveOverride(ruleId);
|
||||
_rulesByPawnIndex.Clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user