-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChatSpammer.cs
111 lines (86 loc) · 3.4 KB
/
ChatSpammer.cs
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 BrokeProtocol.Utility.Networking;
using BrokeProtocolClient.settings;
using BrokeProtocolClient.utils;
using ENet;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace BrokeProtocolClient.modules.misc
{
class ChatSpammer : Module
{
public ModeSetting mode = new ModeSetting("Mode", Mode.Input);
public FileSetting file = new FileSetting("Messages file", FileManager.MainFolderPath + FileManager.MessagesFile);
public NumberSetting delay = new NumberSetting("Delay (seconds)", 0.5, 10, 2.5, 0.5);
public InputSetting message = new InputSetting("Message", 64, "BPclient on top!");
public BooleanSetting randomize = new BooleanSetting("Add random text", false);
public NumberSetting randomLength = new NumberSetting("Length of the random text", 1, 64, 5, 1);
readonly static System.Random random = new System.Random();
readonly string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
IEnumerator spammer;
public ChatSpammer() : base(Categories.Misc, "Chat spammer", "Spams chat messages")
{
addSetting(mode);
addSetting(file);
addSetting(delay);
addSetting(message);
addSetting(randomize);
addSetting(randomLength);
}
public override void onActivate()
{
if (spammer != null) return;
spammer = SpammerThread();
getClient().StartCoroutine(spammer);
}
public override void onDeactivate()
{
if (spammer == null) return;
getClient().StopCoroutine(spammer);
spammer = null;
}
public override void onRender()
{
}
public override void onUpdate()
{
}
private IEnumerator SpammerThread()
{
if (!getClient().ClManager.myPlayer) setEnabled(false);
while (true)
{
if (!mode.isMode((int)Mode.File))
yield return new WaitForSeconds(delay.getValueFloat());
if (!getClient().ClManager.myPlayer) setEnabled(false);
if (mode.isMode((int)Mode.Input))
{
// If randomize is enabled add random characters to the end of the message
string messege = randomize.isEnabled()
? $"{message.getValue()} {new string(Enumerable.Repeat(chars, randomLength.getValueInt()).Select(s => s[random.Next(s.Length)]).ToArray())}"
: message.getValue();
PlayerUtils.SendMessage(messege);
}
else if (mode.isMode((int)Mode.File))
{
string[] lines = File.ReadAllLines(FileManager.MainFolderPath + FileManager.MessagesFile);
foreach (string line in lines)
{
PlayerUtils.SendMessage(line);
yield return new WaitForSeconds(delay.getValueFloat());
}
}
}
}
enum Mode
{
Input,
File
}
}
}