Skip to content

Commit

Permalink
TEMP FIX FOR KNIVES
Browse files Browse the repository at this point in the history
  • Loading branch information
daffyyyy committed Nov 26, 2023
1 parent 7bb97af commit a42e9a3
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public override void Load(bool hotReload)
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventItemPickup>(OnItemPickup, HookMode.Pre);
RegisterEventHandler<EventItemRemove>(OnItemRemove);

if (hotReload)
{
Expand All @@ -137,6 +138,13 @@ public override void Load(bool hotReload)

LoadSkinsFromFile(ModuleDirectory + "/skins.json");
}

private HookResult OnItemRemove(EventItemRemove @event, GameEventInfo info)
{
Console.WriteLine(@event.Defindex);
return HookResult.Continue;
}

public void OnConfigParsed(WeaponPaintsConfig config)
{
if (!config.GlobalShare)
Expand Down Expand Up @@ -330,8 +338,8 @@ private void OnClientDisconnect(int playerSlot)

private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsValid || !player.PlayerPawn.IsValid)
CCSPlayerController? player = @event.Userid;
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
{
return HookResult.Continue;
}
Expand Down Expand Up @@ -528,7 +536,7 @@ private void RemoveKnifeFromPlayer(CCSPlayerController? player)
if (weapons != null && weapons.Count > 0)
{
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));

foreach (var weapon in weapons)
{
Expand All @@ -538,12 +546,16 @@ private void RemoveKnifeFromPlayer(CCSPlayerController? player)
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
{
NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3");
AddTimer(0.2f, () =>
{
CEntityInstance knife = new(weapon.Value.Handle);
dropWeapon(service.Handle, weapon.Handle);
AddTimer(0.3f, () => knife.Remove());
AddTimer(0.5f, () => service.DropActivePlayerWeapon(weapon.Value));

/*
CEntityInstance knife = new(weapon.Value.Handle);
AddTimer(1.0f, () => {
knife.Remove();
if (knife != null && knife.IsValid && player.PawnIsAlive)
});
*/

break;
}
}
Expand Down Expand Up @@ -639,7 +651,9 @@ private void SetupKnifeMenu()
if (player!.PawnIsAlive)
{
if (PlayerHasKnife(player))
{
RemoveKnifeFromPlayer(player);
}
g_changedKnife.Add((int)player.EntityIndex!.Value.Value);
GiveKnifeToPlayer(player);
Expand Down

0 comments on commit a42e9a3

Please sign in to comment.