[K-Relay] PermaCloak

Hello.
I made PermaCloak plugin which allows you to use your cloak multiple times without cheat engine
Using this few times in short period of times will cause disconnect so I think its best to use it in something like ocean to prevent others from teleporting to you.
There is a lot of space for improvements, that is why I provide source code here.
Code
Code:
using Lib_K_Relay;
using Lib_K_Relay.Interface;
using Lib_K_Relay.Networking;
using Lib_K_Relay.Networking.Packets;
using Lib_K_Relay.Networking.Packets.Client;
using Lib_K_Relay.Utilities;
using System.Collections.Generic;
namespace PermaCloak
{
public class PermaCloak : IPlugin
{
private bool _enabled;
private bool galiu = true;
private Dictionary<Client, UseItemPacket> _useItemMap = new Dictionary<Client, UseItemPacket>();
private int TimesRepeat = 2;
private int itemUseTime = 5500;
public string GetAuthor()
{ return "Einaras"; }
public string GetName()
{ return "Perma Cloak"; }
public string GetDescription()
{ return "Automatically cloaks instantly after invisibility expires\nTo set an ammont of times that you want to cloak, use /c (number)\nType /c and Perma Clock will activate after you use your ability\n\nUsing this a lot in short period of time will most likely cause disconnect"; }
public string[] GetCommands()
{ return new string[] { "/c", "/c (NUMBER)", "/time (ability time in milliseconds)" }; }
public void Initialize(Proxy proxy)
{
proxy.ClientDisconnected += OnClientDisconnected;
proxy.ClientConnected += OnClientConnected;
proxy.ClientConnected += (c) => _useItemMap.Add(c, null);
proxy.ClientDisconnected += (c) => _useItemMap.Remove(c);
proxy.HookPacket(PacketType.USEITEM, OnUseItem);
proxy.HookCommand("c", OnCCommand);
proxy.HookCommand("time", onTimecommand);
}
private void onTimecommand(Client client, string command, string[] args)
{
if (args.Length == 0) return;
int n;
bool isNumeric = int.TryParse(args[0], out n);
if (isNumeric)
itemUseTime = n;
else
return;
}
private void OnClientConnected(Client client){galiu = true;}
private void OnClientDisconnected(Client client){galiu = false;}
private void OnUseItem(Client client, Packet packet)
{
if (client.PlayerData.Class == Classes****gue)
{
_useItemMap[client] = packet as UseItemPacket;
UseItemPacket us = (UseItemPacket)packet;
if (us.SlotObject.SlotId == 1 && _enabled)
{
_enabled = false;
PluginUtils.Delay(itemUseTime-100, () => SendUseItem(client, 1150, 1));
}
}
}
private void OnCCommand(Client client, string command, string[] args)
{
if (args.Length == 0)
{
if (!_enabled)
_enabled = true;
}
else
{
int n;
bool isNumeric = int.TryParse(args[0], out n);
if (isNumeric)
TimesRepeat = n;
}
}
private void SendUseItem(Client client, int i, int v)
{
if (galiu)
{
client.PreviousTime = client.PreviousTime + i;
UseItemPacket useItem = _useItemMap[client];
useItem.Time = client.Time;
useItem.ItemUsePos = client.PlayerData.Pos;
client.SendToServer(useItem);
v++;
if (v < TimesRepeat)
PluginUtils.Delay(itemUseTime-100, () => SendUseItem(client, 1150 * v, v));
}
}
}
}
Since this is very unstable, I decided that I will add a command that you have to write before you use your cloak. This way you will use plugin less often which means more play time without disconnect :D (and I couldn't think of other way to make it more easy to use)
To set the amount of times you want to use your cloak over and over again, you have to write "/c (number)"
To activate permacloak, you have to write "/c" before using your cloak
Default ability time is set to 5.5 seconds. To change this, you have to write "/time (and then time in milliseconds)"
Default repeat time is 2 times.
Thanks to Kronks for K-relay and for code that I used from his AutoAbility plugin.
Thanks to @New for idea and code.
Virusⓘ scansⓘ
