-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInfiniteRangeMelee.cs
More file actions
213 lines (181 loc) · 7.06 KB
/
Copy pathInfiniteRangeMelee.cs
File metadata and controls
213 lines (181 loc) · 7.06 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
using System;
using System.IO;
using System.Text;
using System.Text.Json;
namespace DungeonRampageCheat
{
public class InfiniteRangeMelee
{
private string gamePath = "";
public bool SetGamePath(string path)
{
if (Directory.Exists(path))
{
string testFile = Path.Combine(path, "Resources", "Combat", "AttackTimeline.json");
if (File.Exists(testFile))
{
gamePath = path;
return true;
}
}
return false;
}
public int ApplyInfiniteRange(double multiplier)
{
if (string.IsNullOrEmpty(gamePath))
return -1;
int total = 0;
string mainFile = Path.Combine(gamePath, "Resources", "Combat", "AttackTimeline.json");
if (File.Exists(mainFile))
{
total += ModifyRadius(mainFile, multiplier);
}
total += ModifyCharacterRadius("Berserker", multiplier);
total += ModifyCharacterRadius("ranger", multiplier);
total += ModifyCharacterRadius("wizard", multiplier);
total += ModifyCharacterRadius("chef", multiplier);
return total;
}
public int RestoreOriginal()
{
if (string.IsNullOrEmpty(gamePath))
return -1;
int restored = 0;
string mainFile = Path.Combine(gamePath, "Resources", "Combat", "AttackTimeline.json");
string mainBackup = mainFile + ".backup_original";
if (File.Exists(mainBackup))
{
File.Copy(mainBackup, mainFile, true);
restored++;
}
restored += RestoreCharacterRadius("Berserker");
restored += RestoreCharacterRadius("ranger");
restored += RestoreCharacterRadius("wizard");
restored += RestoreCharacterRadius("chef");
return restored;
}
private int ModifyCharacterRadius(string dirName, double multiplier)
{
string charDir = Path.Combine(gamePath, "Resources", "Art3D", "Avatar", dirName);
int total = 0;
if (Directory.Exists(charDir))
{
foreach (var file in Directory.GetFiles(charDir, "db_time_*.json"))
{
total += ModifyRadius(file, multiplier);
}
}
return total;
}
private int RestoreCharacterRadius(string dirName)
{
string charDir = Path.Combine(gamePath, "Resources", "Art3D", "Avatar", dirName);
int restored = 0;
if (Directory.Exists(charDir))
{
foreach (var file in Directory.GetFiles(charDir, "db_time_*.json"))
{
string backupPath = file + ".backup_original";
if (File.Exists(backupPath))
{
File.Copy(backupPath, file, true);
restored++;
}
}
}
return restored;
}
private int ModifyRadius(string filePath, double multiplier)
{
try
{
string backupPath = filePath + ".backup_original";
if (!File.Exists(backupPath))
File.Copy(filePath, backupPath, true);
string jsonText = File.ReadAllText(filePath);
using JsonDocument doc = JsonDocument.Parse(jsonText);
using MemoryStream stream = new();
using Utf8JsonWriter writer = new(stream, new JsonWriterOptions { Indented = false });
int count = ProcessRadiusRecursive(writer, doc.RootElement, multiplier);
writer.Flush();
string modifiedJson = Encoding.UTF8.GetString(stream.ToArray());
File.WriteAllText(filePath, modifiedJson, Encoding.UTF8);
return count;
}
catch
{
return 0;
}
}
private int ProcessRadiusRecursive(Utf8JsonWriter writer, JsonElement element, double multiplier)
{
int count = 0;
switch (element.ValueKind)
{
case JsonValueKind.Object:
writer.WriteStartObject();
bool isCircleCollider = false;
foreach (var prop in element.EnumerateObject())
{
if (prop.Name == "type" && prop.Value.ValueKind == JsonValueKind.String &&
prop.Value.GetString() == "circleCollider")
{
isCircleCollider = true;
break;
}
}
foreach (var prop in element.EnumerateObject())
{
writer.WritePropertyName(prop.Name);
if (isCircleCollider && prop.Name == "radius" && prop.Value.ValueKind == JsonValueKind.Number)
{
writer.WriteNumberValue(prop.Value.GetDouble() * multiplier);
count++;
}
else
{
count += ProcessRadiusRecursive(writer, prop.Value, multiplier);
}
}
writer.WriteEndObject();
break;
case JsonValueKind.Array:
writer.WriteStartArray();
foreach (var item in element.EnumerateArray())
count += ProcessRadiusRecursive(writer, item, multiplier);
writer.WriteEndArray();
break;
default:
WriteJsonValue(writer, element);
break;
}
return count;
}
private void WriteJsonValue(Utf8JsonWriter writer, JsonElement element)
{
switch (element.ValueKind)
{
case JsonValueKind.String:
writer.WriteStringValue(element.GetString());
break;
case JsonValueKind.Number:
if (element.TryGetInt32(out int intValue))
writer.WriteNumberValue(intValue);
else if (element.TryGetInt64(out long longValue))
writer.WriteNumberValue(longValue);
else
writer.WriteNumberValue(element.GetDouble());
break;
case JsonValueKind.True:
writer.WriteBooleanValue(true);
break;
case JsonValueKind.False:
writer.WriteBooleanValue(false);
break;
case JsonValueKind.Null:
writer.WriteNullValue();
break;
}
}
}
}