forked from Kylemc1413/NjsFixer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
121 lines (113 loc) · 4.94 KB
/
Config.cs
File metadata and controls
121 lines (113 loc) · 4.94 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
using System.Collections.Generic;
using System.IO;
using System;
using System.Collections;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Linq;
using UnityEngine;
namespace NjsFixer
{
public class NjsPref
{
public float njs = 12f;
public float jumpDistance = 24f;
public NjsPref(float njs, float jumpDistance)
{
this.njs = njs;
this.jumpDistance = jumpDistance;
}
}
public class NjsFixerConfig
{
public float njs = 0;
public float bpm = 0;
public float spawnOffset = 0;
public bool enabled = false;
public bool enabledInPractice = false;
public bool dontForceNJS = false;
public float jumpDistance = 24f;
public int minJumpDistance = 20;
public int maxJumpDistance = 30;
public bool usePreferredJumpDistanceValues = false;
public List<NjsPref> preferredValues = new List<NjsPref>();
public NjsFixerConfig()
{
}
[JsonConstructor]
public NjsFixerConfig(float njs, float bpm, float spawnOffset, bool enabled, bool enabledInPractice, bool dontForceNJS, float jumpDistance, int minJumpDistance, int maxJumpDistance, bool usePreferredJumpDistanceValues, List<NjsPref> preferredValues)
{
this.njs = njs;
this.bpm = bpm;
this.spawnOffset = spawnOffset;
this.enabled = enabled;
this.enabledInPractice = enabledInPractice;
this.dontForceNJS = dontForceNJS;
this.jumpDistance = jumpDistance;
this.minJumpDistance = minJumpDistance;
this.maxJumpDistance = maxJumpDistance;
this.usePreferredJumpDistanceValues = usePreferredJumpDistanceValues;
this.preferredValues = preferredValues;
}
}
public class Config
{
public static NjsFixerConfig UserConfig { get; private set; }
public static string ConfigPath { get; private set; } = Path.Combine(IPA.Utilities.UnityGame.UserDataPath, "NjsFixer.json");
private static bool CheckForOldConfig()
{
return File.Exists(Path.Combine(IPA.Utilities.UnityGame.UserDataPath, "NjsFixer.ini")) && !File.Exists(Path.Combine(IPA.Utilities.UnityGame.UserDataPath, "NjsFixer.json"));
}
public static void Read()
{
if (!File.Exists(ConfigPath))
{
if (CheckForOldConfig())
{
var oldConfig = new BS_Utils.Utilities.Config("NjsFixer");
UserConfig = new NjsFixerConfig();
UserConfig.njs = oldConfig.GetFloat("NjsFixer", "njs", 0, true);
UserConfig.bpm = oldConfig.GetFloat("NjsFixer", "bpm", 0, true);
UserConfig.spawnOffset = oldConfig.GetFloat("NjsFixer", "spawnOffset", 0, true);
UserConfig.enabled = oldConfig.GetBool("NjsFixer", "Enabled", false, true);
UserConfig.dontForceNJS = oldConfig.GetBool("NjsFixer", "DontForceNJS", false, true);
UserConfig.jumpDistance = oldConfig.GetFloat("NjsFixer", "DesiredJumpDistance", 24f, true);
UserConfig.minJumpDistance = oldConfig.GetInt("NjsFixer", "minJumpDistance", 20, true);
UserConfig.maxJumpDistance = oldConfig.GetInt("NjsFixer", "maxJumpDistance", 30, true);
try
{
File.Delete(Path.Combine(IPA.Utilities.UnityGame.UserDataPath, "NjsFixer.ini"));
}
catch (Exception ex)
{
Logger.log.Warn($"Failed to delete old NjsFixer Config file {ex}");
}
}
else
{
UserConfig = new NjsFixerConfig();
}
Write();
}
else
{
UserConfig = JsonConvert.DeserializeObject<NjsFixerConfig>(File.ReadAllText(ConfigPath));
}
UserConfig.preferredValues = UserConfig.preferredValues.OrderByDescending(x => x.njs).ToList();
/*
njs = ModPrefs.GetFloat("NjsFixer", "njs", 0, true);
bpm = ModPrefs.GetFloat("NjsFixer", "bpm", 0, true);
spawnOffset = ModPrefs.GetFloat("NjsFixer", "spawnOffset", 0, true);
enabled = ModPrefs.GetBool("NjsFixer", "Enabled", false, true);
dontForceNJS = ModPrefs.GetBool("NjsFixer", "DontForceNJS", false, true);
jumpDistance = ModPrefs.GetFloat("NjsFixer", "DesiredJumpDistance", 24f, true);
*/
}
public static void Write()
{
UserConfig.preferredValues = UserConfig.preferredValues.OrderByDescending(x => x.njs).ToList();
Logger.log.Debug("Writing Config to file");
File.WriteAllText(ConfigPath, JsonConvert.SerializeObject(UserConfig, Formatting.Indented));
}
}
}