-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunMatchPlugin.cs
More file actions
295 lines (272 loc) · 10.5 KB
/
FunMatchPlugin.cs
File metadata and controls
295 lines (272 loc) · 10.5 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Admin;
using System.Text.Json;
namespace FunMatchPlugin;
public class FunMatchPlugin: BasePlugin , IPluginConfig<FunMatchPluginConfig>
{
public override string ModuleName => "Fun Match Plugin";
public override string ModuleVersion => "1.1.1";
public FunMatchPluginConfig Config {get;set;} = new();
public override void Load(bool hotReload)
{
Console.WriteLine("Fun Match Plugin Load!");
InstallFun(Config);
InstallCustomModes();
//FunC4EveryWhere funC4EveryWhere = new(this);
//FunLists.Add(funC4EveryWhere);
}
public void OnConfigParsed(FunMatchPluginConfig config)
{
Console.WriteLine("Parsing config");
Config = config;
}
private void InstallCustomModes()
{
var configdirectory = Path.Combine(Application.RootDirectory, "configs/plugins/FunMatchPlugin");
if (!Path.Exists(configdirectory)) Directory.CreateDirectory(configdirectory);
var configpath = Path.Combine(configdirectory,"CustomModes.json");
if (!File.Exists(configpath)) return;
var dir_addons = Directory.GetParent(Application.RootDirectory);
var dir_csgo = Directory.GetParent(dir_addons!.FullName);
var path_cfg = Path.Combine(dir_csgo!.FullName,"cfg");
using (StreamReader r = new StreamReader(configpath))
{
string json = r.ReadToEnd();
CustomModesConfig customModesConfig = JsonSerializer.Deserialize<CustomModesConfig>(json)!;
foreach (var mode in customModesConfig.Modes)
{
var fun_cfg_game = Path.Combine(path_cfg,mode.Fun_cfgfilename);
var fun_cfg_config = Path.Combine(configdirectory,mode.Fun_cfgfilename);
var endfun_cfg_game = Path.Combine(path_cfg,mode.Endfun_cfgfilename);
var endfun_cfg_config = Path.Combine(configdirectory,mode.Endfun_cfgfilename);
File.Copy(fun_cfg_config,fun_cfg_game,true);
File.Copy(endfun_cfg_config,endfun_cfg_game,true);
FunLists.Add(new FunCustomConsoleMode(mode.Decr,mode.Fun_cfgfilename,mode.Endfun_cfgfilename));
}
}
}
private void InstallFun(FunMatchPluginConfig config)
{
if (config.IsFunBulletTeleportOn)
{
FunBulletTeleport funBulletTeleport = new (this);
FunLists.Add(funBulletTeleport);
}
if (config.IsFunHealTeammatesOn)
{
FunHealTeammates funHealTeammates = new(this)
{
BurnAfterSecond = config.FunHealTeammatesBurnAfterSecond,
BurnDamage = config.FunHealTeammatesBurnDamage,
HealValue = config.FunHealTeammatesHealValue,
};
FunLists.Add(funHealTeammates);
}
if (config.IsFunHealthRaidOn)
{
FunHealthRaid funHealthRaid = new (this)
{
initHP = config.FunHealthRaidinitHP,
maxRaid = config.FunHealthRaidmaxRaid,
RaidScale = config.FunHealthRaidScale,
};
FunLists.Add(funHealthRaid);
}
if (config.IsFunHighHPOn)
{
FunHighHP funHighHP = new (this)
{
maxHP = config.FunHighHPmaxHP,
armor = config.FunHighHParmor,
};
FunLists.Add(funHighHP);
}
if (config.IsFunInfiniteGrenadeOn)
{
FunInfiniteGrenade funFunInfiniteGrenade = new (this);
FunLists.Add(funFunInfiniteGrenade);
}
if (config.IsFunJumpOrDieOn)
{
FunJumpOrDie funJumpOrDie = new(this)
{
BurnAfterSecond = config.FunJumpOrDieBurnAfterSecond,
BurnDamage = config.FunJumpOrDieBurnDamage,
};
FunLists.Add(funJumpOrDie);
}
if (config.IsFunNoClipOn)
{
FunNoClip funNoClip = new (this){
interval = config.FunNoClipinterval,
};
FunLists.Add(funNoClip);
}
if (config.IsFunPlayerShootExChangeOn)
{
FunPlayerShootExChange funPlayerShootExChange = new (this);
FunLists.Add(funPlayerShootExChange);
}
if (config.IsFunToTheMoonOn)
{
FunToTheMoon funToTheMoon = new(this)
{
gravity = config.FunToTheMoongravity,
BulletGiveAbsV = config.FunToTheMoonBulletGiveAbsV,
};
FunLists.Add(funToTheMoon);
}
if (config.IsFunWNoStopOn)
{
FunWNoStop funWNoStop = new (this)
{
BurnAfterSecond = config.FunWNoStopBurnAfterSecond,
BurnDamage = config.FunWNoStopBurnDamage,
};
FunLists.Add(funWNoStop);
}
if (config.IsFunDropWeaponOnShootOn)
{
FunDropWeaponOnShoot funDropWeaponOnShoot = new();
FunLists.Add(funDropWeaponOnShoot);
}
if (config.IsFunChangeWeaponOnShootOn)
{
FunChangeWeaponOnShoot funChangeWeaponOnShoot = new();
FunLists.Add(funChangeWeaponOnShoot);
}
if (config.IsFunFootBallOn)
{
FunFootBall funFootBall = new();
FunLists.Add(funFootBall);
RegisterListener<Listeners.OnServerPrecacheResources>((manifest) =>
{
manifest.AddResource("models/props/de_dust/hr_dust/dust_soccerball/dust_soccer_ball001.vmdl");
manifest.AddResource("models/props_fairgrounds/fairgrounds_flagpole01.vmdl");
});
}
}
private Random rd = new Random();
public void LoadRandomFun()
{
if (CurrentActiceFunIndex >= 0) return;
CurrentActiceFunIndex = rd.Next(0,FunLists.Count);
FunLists[CurrentActiceFunIndex].Fun(this);
if (DisPlayHelp) FunLists[CurrentActiceFunIndex].DisPlayHelp();
}
public void UnLoadFun()
{
if (CurrentActiceFunIndex < 0) return;
FunLists[CurrentActiceFunIndex].EndFun(this);
}
public void LoadFunByIndex(int index)
{
if (index < 0 || index >=FunLists.Count) return;
FunLists[index].Fun(this);
if (DisPlayHelp) FunLists[index].DisPlayHelp();
}
public void UnLoadFunByIndex(int index)
{
if (index < 0 || index >=FunLists.Count) return;
FunLists[index].EndFun(this);
}
public void LoadFunByName(string name)
{
}
public bool DisPlayHelp = true;
private int CurrentActiceFunIndex = -1;
private List<FunBaseClass> FunLists = new List<FunBaseClass>();
private bool EnableRandom = true;
private GameEventHandler<EventRoundStart> ?ManualLoadHander;
private int ManualLoadIndex = -1;
[GameEventHandler]
public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
{
if (!EnableRandom) return HookResult.Continue;
UnLoadFun();
CurrentActiceFunIndex = -1;
Server.NextFrame(()=>{
LoadRandomFun();
});
return HookResult.Continue;
}
[ConsoleCommand("fun_load", "Load fun by num")]
[CommandHelper(minArgs: 1, usage: "[num]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/root")]
public void OnLoadFunCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
int num;
int.TryParse(commandInfo.GetArg(1),out num);
if (num <= 0 || num >FunLists.Count)
{
commandInfo.ReplyToCommand($"Invalid num. pls input num from {1} - {FunLists.Count}");
return;
}
if (ManualLoadHander is not null)
{
commandInfo.ReplyToCommand($"Alraedy loaded {ManualLoadIndex + 1} Manually, Pls !fun_load first");
return;
}
ManualLoadIndex = num - 1;
LoadFunByIndex(ManualLoadIndex);
RegisterEventHandler (ManualLoadHander = (@event, info) =>
{
UnLoadFunByIndex(ManualLoadIndex);
Server.NextFrame(()=>{
LoadFunByIndex(ManualLoadIndex);
});
return HookResult.Continue;
});
}
[ConsoleCommand("!fun_load", "UnLoad fun Manually")]
[CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/root")]
public void OnUnLoadFunCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
UnLoadFunByIndex(ManualLoadIndex);
DeregisterEventHandler(ManualLoadHander!);
ManualLoadHander = null;
commandInfo.ReplyToCommand($"Unloaded {ManualLoadIndex + 1}");
}
[ConsoleCommand("fun_lists", "Lists Avaliable Fun")]
[CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
public void OnListFunCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
for (int i = 0;i < FunLists.Count; i++)
{
commandInfo.ReplyToCommand($"{i + 1} {FunLists[i].Decription}");
}
}
[ConsoleCommand("fun_displayhelp", "DisPlay Help Fun")]
[CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/root")]
public void OnDisPlayHelpCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
DisPlayHelp = true;
}
[ConsoleCommand("!fun_displayhelp", "Don't DisPlay Help Fun")]
[CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/root")]
public void OnDontDisPlayHelpCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
DisPlayHelp = false;
}
[ConsoleCommand("!fun_random", "Don't random Fun everyround")]
[CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/root")]
public void OnDontRandomCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
EnableRandom = false;
UnLoadFun();
}
[ConsoleCommand("fun_random", "random Fun everyround")]
[CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/root")]
public void OnRandomCommand(CCSPlayerController? player, CommandInfo commandInfo)
{
EnableRandom = true;
}
}