-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfig.cs
More file actions
135 lines (119 loc) · 3.73 KB
/
Copy pathConfig.cs
File metadata and controls
135 lines (119 loc) · 3.73 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
using System.Text.Json;
using Il2CppSystem.IO;
using Il2CppSystem.Text;
namespace TSKHook;
public class TSKConfig
{
public static double Speed;
public static int FPS;
public static bool TranslationEnabled;
public static int width;
public static int height;
public static float zoom;
public static void Read()
{
if (File.Exists("./BepInEx/plugins/config.json"))
{
var content = File.InternalReadAllText("./BepInEx/plugins/config.json", Encoding.UTF8);
var doc = JsonDocument.Parse(content);
var config = doc.RootElement;
var needWrite = false;
if (config.TryGetProperty("speed", out var sValue))
{
Speed = sValue.GetDouble();
}
else
{
Speed = 0.5;
needWrite = true;
}
if (config.TryGetProperty("fps", out var fValue))
{
FPS = fValue.GetInt32();
}
else
{
FPS = 60;
needWrite = true;
}
if (config.TryGetProperty("translation", out var tValue))
{
TranslationEnabled = tValue.GetBoolean();
}
else
{
TranslationEnabled = true;
needWrite = true;
}
if (config.TryGetProperty("width", out var wValue))
{
width = wValue.GetInt32();
}
else
{
width = 1280;
needWrite = true;
}
if (config.TryGetProperty("height", out var hValue))
{
height = hValue.GetInt32();
}
else
{
height = 720;
needWrite = true;
}
if (config.TryGetProperty("zoom", out var zValue))
{
zoom = (float)zValue.GetDouble();
}
else
{
zoom = 1.0f;
needWrite = true;
}
if (needWrite) WriteJsonFile(Speed, FPS, TranslationEnabled, width, width, zoom);
Plugin.Global.Log.LogInfo("Current setting:");
Plugin.Global.Log.LogInfo("Game speed(each step): " + Speed);
Plugin.Global.Log.LogInfo("FPS: " + FPS);
Plugin.Global.Log.LogInfo("Translation: " + (TranslationEnabled ? "Enabled" : "Disabled"));
Plugin.Global.Log.LogInfo("Zoom ratio: " + zoom);
}
else
{
Plugin.Global.Log.LogWarning("config.json not found!!!");
Plugin.Global.Log.LogWarning("Using default config.");
Speed = 0.5;
FPS = 60;
TranslationEnabled = true;
width = 1280;
height = 720;
zoom = 1.0f;
// Create default JSON file
WriteJsonFile(0.5, 60, true, width, height, zoom);
}
}
public static void WriteJsonFile(double speed, int fps, bool enabled, int w, int h, float z)
{
var config = new config
{
speed = speed,
fps = fps,
translation = enabled,
width = w,
height = h,
zoom = z
};
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText("./BepInEx/plugins/config.json", json);
}
public class config
{
public double speed { get; set; }
public int fps { get; set; }
public bool translation { get; set; }
public int width { get; set; }
public int height { get; set; }
public float zoom { get; set; }
}
}