-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTyranoScript.cs
More file actions
196 lines (179 loc) · 7.41 KB
/
TyranoScript.cs
File metadata and controls
196 lines (179 loc) · 7.41 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
/*
* Copyright (C) 2025 Tekat, ha-ves
*
* This program is licensed under the GNU Affero General Public License v3 or later.
* See <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TyranoScriptMemoryUnlocker.Asar;
#pragma warning disable IDE0130
namespace TyranoScriptMemoryUnlocker.TyranoScript
{
public static class TyranoScript
{
internal static IEnumerable<string> GetUnlockableCG(StreamReader reader)
{
string? line;
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
if (line.Length < 4 || line[0] != '[' || line[^1] != ']') continue;
var inner = line[1..^1].Trim();
if (inner.StartsWith("cg_image_button "))
{
int storageIdx = inner.IndexOf("graphic=");
if (storageIdx != -1)
{
int valStart = storageIdx + 9;
int valEnd = inner.IndexOf('"', valStart);
if (valEnd > valStart)
{
var val = inner[valStart..valEnd]
.Split(',', StringSplitOptions.RemoveEmptyEntries);
foreach (var v in val)
yield return v;
}
}
}
}
}
internal static IEnumerable<KeyValuePair<string, string>> GetUnlockableReplay(StreamReader reader)
{
string? line;
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
if (line.Length < 4 || line[0] != '[' || line[^1] != ']') continue;
var inner = line[1..^1].Trim();
if (inner.StartsWith("setreplay "))
{
int nameIdx = inner.IndexOf("name=");
int storageIdx = inner.IndexOf("storage=");
if (nameIdx != -1 && storageIdx != -1)
{
int valStart = nameIdx + 6;
int valEnd = inner.IndexOf('"', valStart);
if (valEnd > valStart)
{
var val = inner[valStart..valEnd];
int valsStart = storageIdx + 9;
int valsEnd = inner.IndexOf('"', valsStart);
if (valsEnd > valsStart)
{
var vals = inner[valsStart..valsEnd];
if (val.Length > 0 && vals.Length > 0)
{
yield return new KeyValuePair<string, string>(val, vals);
}
}
}
}
}
}
}
internal static IEnumerable<string> GetReplayButton(StreamReader reader)
{
string? line;
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
if (line.Length < 4 || line[0] != '[' || line[^1] != ']') continue;
var inner = line[1..^1].Trim();
if (inner.StartsWith("replay_image_button "))
{
int storageIdx = inner.IndexOf("name=");
if (storageIdx != -1)
{
int valStart = storageIdx + 6;
int valEnd = inner.IndexOf('"', valStart);
if (valEnd > valStart)
{
var val = inner[valStart..valEnd];
yield return val;
}
}
}
}
}
internal class BaseTag_CG
{
public string? Storage { get; set; }
}
internal class SetReplayTag : BaseTag_CG
{
public string? Name { get; set; }
}
internal static IEnumerable<BaseTag_CG> GetCGAndSetreplayTags(StreamReader reader)
{
string? line;
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
if (line.Length < 4 || line[0] != '[' || line[^1] != ']') continue;
var inner = line[1..^1].Trim();
if (inner.StartsWith("cg "))
{
int storageIdx = inner.IndexOf("storage=");
if (storageIdx != -1)
{
int valStart = storageIdx + 9;
int valEnd = inner.IndexOf('"', valStart);
if (valEnd > valStart)
{
var val = inner[valStart..valEnd];
yield return new BaseTag_CG { Storage = val };
}
}
}
else if (inner.StartsWith("setreplay "))
{
int nameIdx = inner.IndexOf("name=");
int storageIdx = inner.IndexOf("storage=");
if (nameIdx != -1 && storageIdx != -1)
{
int valStart = nameIdx + 6;
int valEnd = inner.IndexOf('"', valStart);
if (valEnd > valStart)
{
var val = inner[valStart..valEnd];
int valsStart = storageIdx + 9;
int valsEnd = inner.IndexOf('"', valsStart);
if (valsEnd > valsStart)
{
var vals = inner[valsStart..valsEnd];
if (val.Length > 0 && vals.Length > 0)
{
yield return new SetReplayTag
{
Name = val,
Storage = vals
};
}
}
}
}
}
}
}
internal static IEnumerable<AsarFileEntry> FindFilesByExt(AsarArchive asar, string ext, string? searchTopPath = null)
{
ext = ext.StartsWith('.') ? ext : '.' + ext;
var searchdir = searchTopPath is null ? asar.Files : asar.Files[searchTopPath];
if (searchdir is AsarFileEntry)
{
throw new ArgumentException("The provided argument is not a directory in the Asar archive.", nameof(searchTopPath));
}
return FindFilesByExt((AsarDirectoryEntry?)searchdir, ext);
}
internal static IEnumerable<AsarFileEntry> FindFilesByExt(AsarDirectoryEntry? files, string ext)
{
var currdirfiles = files?.EnumerateFiles()?.Where(fl => Path.GetExtension(fl.Name) == ext);
var nextdirfiles = files?.EnumerateDirectories()?.SelectMany(dir => FindFilesByExt(dir, ext));
return currdirfiles?.Concat(nextdirfiles ?? []) ?? nextdirfiles?.Concat(currdirfiles ?? []) ?? [];
}
}
}