-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
158 lines (141 loc) · 5.3 KB
/
Program.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
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
using System.Text;
using System.Runtime.Serialization.Json;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Collections;
using ws2Parse.PE;
namespace ws2Parse
{
internal class Program
{
static void Main(string[] args)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
//CLegacyFunctions.UpdateVM1993();
//CLegacyFunctions.SaveArgTypes(@"E:\GalGames_Work\OnWork\个人研究向\懱尡斉杮懱\1993.txt");
if (args.Length < 3)
{
Console.WriteLine("使用方法:ws2Parse.exe [AdvHD主程序路径] [存放ws2文件的文件夹路径] [功能(d:解包|r:封包)]");
return;
}
CLegacyFunctions.SetArgTypes(ArgAnalyzer.ExtractArgTypes(args[0]));
//CLegacyFunctions.SaveArgTypes(@"E:\GalGames_Work\OnWork\个人研究向\懱尡斉杮懱\1996.txt");
switch(args[2])
{
case "d":
ExportAllStrings(args[1]);
break;
case "p":
ReassembleAllScripts(args[1]);
break;
case "dc":
DecompileScripts(args[1]);
break;
default:
Console.WriteLine("未知模式,请检查您的输入!");
break;
}
//ReAssemWithUtf8(args[0]);
//ReassembleAllScripts(args[0]);
//DecryptScripts(args[0]);
//ws.Decompile(args[0]);
//ws.ImportStrings(args[0]);
//ws.Assem(args[0]);
//WS2Script.Encrypt(ref script);
//File.WriteAllBytes(BaseBame + ".ws2", script);
}
static void ReAssemWithUtf8(string folder)
{
WS2Script ws = new();
ws.Load(@"start.ws2");
//ws.LoadJson(@"start.json");
ws.Assemble(@"start.ws2", true);
foreach (string file in Directory.EnumerateFiles(folder, "*.ws2", SearchOption.TopDirectoryOnly))
{
ws.Load(file);
ws.Assemble(file, true);
}
}
static void ExportAllStrings(string folder, bool decrypt = false)
{
WS2Script ws = new();
foreach (string file in Directory.EnumerateFiles(folder, "*.ws2", SearchOption.TopDirectoryOnly))
{
ws.Load(file, decrypt);
ws.ExportStrings(file);
}
using (StreamWriter sw = new StreamWriter(Path.Combine(folder, "人名表.txt")))
{
sw.WriteLine(JsonConvert.SerializeObject(ws.char_names, Formatting.Indented));
sw.Flush();
sw.Close();
}
Console.WriteLine(string.Format("总字数统计:约{0}字", ws.total_chars));
}
static void ReassembleAllScripts(string folder, bool importstrings = true, bool decrypt = false, bool encrypt = false)
{
WS2Script ws = new();
try
{
if(JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(Path.Combine(folder, "人名表.txt"))) is Dictionary<string, string> dic)
{
ws.char_names = dic;
}
else
{
throw new Exception("人名表反序列化错误。");
}
}catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
Console.Error.WriteLine("读取人名表的时候出错啦!检查一下吧");
return;
}
foreach (string file in Directory.EnumerateFiles(folder, "*.ws2", SearchOption.TopDirectoryOnly))
{
Console.WriteLine($"Processing: {file}");
ws.Load(file, decrypt);
string txt_file = Path.ChangeExtension(file, "txt");
if(File.Exists(txt_file) && importstrings)
{
ws.ImportStrings(txt_file);
}
ws.Assemble(file, encrypt);
}
}
static void DecompileScripts(string input, bool decrypt = false)
{
WS2Script ws = new();
if (Directory.Exists(input))
{
foreach (string file in Directory.EnumerateFiles(input, "*.ws2", SearchOption.TopDirectoryOnly))
{
Console.WriteLine($"Processing: {file}");
ws.Load(file, decrypt);
ws.Decompile(file);
}
}
else
{
Console.WriteLine($"Processing: {input}");
ws.Load(input, decrypt);
ws.Decompile(input);
}
}
static void DecryptScripts(string input)
{
WS2Script ws = new();
if (Directory.Exists(input))
{
foreach (string file in Directory.EnumerateFiles(input, "*.ws2", SearchOption.TopDirectoryOnly))
{
ws.DecryptScript(file);
}
}
else
{
ws.DecryptScript(input);
}
}
}
}