-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathServerConfig.cs
92 lines (72 loc) · 2.69 KB
/
ServerConfig.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
using System.Text.Json;
namespace OpenPrefirePrac;
public class DefaultConfig
{
public int Difficulty { get; set; } = 3;
public int TrainingMode { get; set; } = 0;
public int BotWeapon {get; set; } = 0;
/*
* 0 = disabled.
* 1 = css based aim lock.
* 2 = behavior tree based aim lock (hard).
*/
public int BotAimLock {get; set; } = 1;
public int EquipPlayer { get; set; } = 1;
private string _moduleDirectory = "";
public DefaultConfig()
{
// DeserializeConstructor
}
public DefaultConfig(string moduleDirectory)
{
_moduleDirectory = moduleDirectory;
}
public void LoadDefaultSettings()
{
string path = $"{_moduleDirectory}/default_cfg.json";
if (!File.Exists(path))
{
// Use default settings
Console.WriteLine("[OpenPrefirePrac] No custom settings provided. Will use default settings.");
}
else
{
// Load settings from default_cfg.json
JsonSerializerOptions options = new JsonSerializerOptions
{
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
};
string jsonString = File.ReadAllText(path);
try
{
DefaultConfig jsonConfig = JsonSerializer.Deserialize<DefaultConfig>(jsonString, options)!;
if (jsonConfig.Difficulty > -1 && jsonConfig.Difficulty < 6)
{
Difficulty = jsonConfig.Difficulty;
}
if (jsonConfig.TrainingMode > -1 && jsonConfig.TrainingMode < 2)
{
TrainingMode = jsonConfig.TrainingMode;
}
if (jsonConfig.BotWeapon > -1 && jsonConfig.BotWeapon < 5)
{
BotWeapon = jsonConfig.BotWeapon;
}
if (jsonConfig.BotAimLock > -1 && jsonConfig.BotAimLock < 3)
{
BotAimLock = jsonConfig.BotAimLock;
}
if (jsonConfig.EquipPlayer > -1 && jsonConfig.EquipPlayer < 2)
{
EquipPlayer = jsonConfig.EquipPlayer;
}
Console.WriteLine($"[OpenPrefirePrac] Using default settings: Difficulty = {Difficulty}, TrainingMode = {TrainingMode}, BotWeapon = {BotWeapon}, BotAimLock = {BotAimLock}, EquipPlayer = {EquipPlayer}");
}
catch (System.Exception)
{
Console.WriteLine("[OpenPrefirePrac] Failed to load custom settings. Will use default settings.");
}
}
}
}