This repository was archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCustomGameStats.cs
128 lines (105 loc) · 4.04 KB
/
CustomGameStats.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using SharedModConfig;
namespace CustomGameStats
{
[BepInPlugin(GUID, NAME, VERSION)]
[BepInDependency(DEPENDENT, BepInDependency.DependencyFlags.HardDependency)]
public class CustomGameStats : BaseUnityPlugin
{
public const string GUID = "com.theinterstice.customgamestats";
public const string NAME = "Custom Game Stats";
public const string VERSION = "2.1.5";
public const string DEPENDENT = SharedModConfig.SharedModConfig.GUID;
public static CustomGameStats Instance { get; private set; }
public static ModConfig PlayerConfig { get; private set; }
public static ModConfig AIConfig { get; private set; }
public static string Dir { get; private set; } = $@"Mods\ModConfigs\{ Settings.ModName }\";
internal void Awake()
{
Instance = this;
var _obj = gameObject;
_obj.AddComponent<StatManager>();
_obj.AddComponent<RPCManager>();
var _harmony = new Harmony(GUID);
_harmony.PatchAll();
}
internal void Start()
{
Init();
PlayerConfig = SetupConfig(Settings.PlayerStatsTitle);
PlayerConfig.Register();
AIConfig = SetupConfig(Settings.AIStatsTitle);
AIConfig.Register();
Logger.Log(LogLevel.Message, $"{ NAME } v{ VERSION } initialized!");
}
public void ResetConfig(string flag)
{
if (flag == Settings.PlayerStatsTitle)
{
foreach (BBSetting _setting in PlayerConfig.Settings)
{
_setting.SetValue(_setting.DefaultValue);
}
}
if (flag == Settings.AIStatsTitle)
{
foreach (BBSetting _setting in AIConfig.Settings)
{
_setting.SetValue(_setting.DefaultValue);
}
}
}
private void Init()
{
ModSettings _ms = new ModSettings();
string _file = $@"Mods\{ Settings.ModName }.json";
string _path = $@"Mods\ModConfigs\{ Settings.ModName}";
if (!Directory.Exists(Dir))
{
Directory.CreateDirectory(Dir);
}
if (!File.Exists(_file))
{
_ms.FirstRun = true;
File.WriteAllText(_file, JsonUtility.ToJson(_ms));
}
ModSettings _settings = JsonUtility.FromJson<ModSettings>(File.ReadAllText(_file));
if (!_settings.FirstRun) { return; }
if (File.Exists($"{ _path }{ Settings.PlayerStatsTitle }.xml")) { File.Delete($"{ _path }{ Settings.PlayerStatsTitle }.xml"); }
if (File.Exists($"{ _path }{ Settings.AIStatsTitle }.xml")) { File.Delete($"{ _path }{ Settings.AIStatsTitle }.xml"); }
Directory.Delete(Dir, true);
Directory.CreateDirectory(Dir);
_ms.FirstRun = false;
File.WriteAllText(_file, JsonUtility.ToJson(_ms));
}
private ModConfig SetupConfig(string flag)
{
List<BBSetting> _bbs = new List<BBSetting>();
if (flag == Settings.AIStatsTitle)
{
var _settings = new Settings();
_bbs.AddRange(_settings.RulesSettings);
_bbs.AddRange(_settings.CharacterSettings);
}
if (flag == Settings.PlayerStatsTitle)
{
var _settings = new Settings();
_bbs.AddRange(_settings.RulesSettings);
_bbs.AddRange(_settings.PlayerSettings);
_bbs.AddRange(_settings.CharacterSettings);
}
ModConfig _config = new ModConfig
{
ModName = $"{ Settings.ModName }{ flag }",
SettingsVersion = 1.0,
Settings = _bbs
};
return _config;
}
}
}