forked from cdj68765/PEPlugin-Git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTranslateMod.cs
384 lines (368 loc) · 14.2 KB
/
TranslateMod.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml.Serialization;
using static PE多功能信息处理插件.Class2;
using static PE多功能信息处理插件.Program;
namespace PE多功能信息处理插件
{
internal class TranslateMod
{
private bool Read = false;
private bool ReadW = true;
private bool Write = false;
public List<FormText> Readinfo = new List<FormText>();
private List<FormText> Writeinfo = new List<FormText>();
private readonly Regex regex = new Regex(@"^[A-Za-z0-9.: -]+$", RegexOptions.Compiled);
public TranslateMod()
{
Write = false;
SwichControl(ARGS.Host.Connector.Form as Form, 0);
/* using (Stream Filestream = new FileStream(new FileInfo(ARGS.Host.Connector.System.HostApplicationPath).DirectoryName + @"\_data\boot3.xml", FileMode.OpenOrCreate))
{
XmlSerializer Ser = new XmlSerializer(typeof(FormText[]));
Ser.Serialize(Filestream, Readinfo.ToArray());
}*/
}
public TranslateMod(List<FormText> Writeinfo, bool Read = true)
{
Write = true;
this.ReadW = Read;
this.Writeinfo = new List<FormText>(Writeinfo);
SwichControl(ARGS.Host.Connector.Form as Form, 0);
}
public void SwichControl(dynamic Obj, int count)
{
if (Obj is Form)
{
if (count < 4)
{
Interlocked.Increment(ref count);
GetOrChangeForm(Obj as Form, count);
}
}
else if (Obj is Control)
{
GetOrChangeControl(Obj as Control, count);
}
else if (Obj is ToolStripItem)
{
GetOrChangeToolStripItem(Obj as ToolStripItem, count);
}
}
private void GetOrChangeToolStripItem(ToolStripItem toolStripItem, int count)
{
if (toolStripItem is ToolStripComboBox)
{
var ComboBox = toolStripItem as ToolStripComboBox;
if (Read)
{
var StringBuild = new StringBuilder();
foreach (var item in ComboBox.Items)
{
ReadAdd(item.ToString(), ComboBox.Name);
}
}
if (Write)
{
/* var tempinfo = Writeinfo.FirstOrDefault(x => x.ID == ComboBox.Name && x.Parent == (ComboBox.Owner != null ? ComboBox.Owner.Name : "null"));
if (tempinfo != null)
{
var StringSplit = tempinfo.text.Split('|');
for (int i = 0; i < ComboBox.Items.Count; i++)
{
ComboBox.Items[i] = StringSplit[i];
}
}*/
for (int i = 0; i < ComboBox.Items.Count; i++)
{
var temp = WriteAdd(ComboBox.Items[i].ToString(), ComboBox.Name);
if (temp != null)
{
ComboBox.Items[i] = temp;
}
}
}
}
else if (toolStripItem.Text != "0" && !string.IsNullOrWhiteSpace(toolStripItem.Text))
{
if (toolStripItem.Name == "MenuItem_TopMost" && FormTopMost == null)
{
FormTopMost = toolStripItem;
}
if (Read)
{
ReadAdd(toolStripItem.Text, toolStripItem.Name);
ReadAdd(toolStripItem.ToolTipText, toolStripItem.Name);
}
if (Write)
{
toolStripItem.Text = WriteAdd(toolStripItem.Text, toolStripItem.Name);
toolStripItem.ToolTipText = WriteAdd(toolStripItem.ToolTipText, toolStripItem.Name);
/* if (Writeinfo != null)
{
var tempinfo = Writeinfo.FirstOrDefault(x => x.ID == toolStripItem.Name && x.Parent == (toolStripItem.Owner != null ? toolStripItem.Owner.Name : "null"));
if (tempinfo != null)
{
toolStripItem.Text = tempinfo.text;
toolStripItem.ToolTipText = tempinfo.ToolTipText;
}
}*/
}
}
foreach (var fi in toolStripItem.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
{
var obj = fi.GetValue(toolStripItem);
SwichControl(obj, count);
}
}
private string WriteAdd(string v, string v2)
{
if (CheckBox(v))
{
if (ReadW)
{
var temp = Writeinfo.FirstOrDefault(x => x.OriText == v && x.ControlName == v2);
if (temp != null)
{
v = temp.TransText;
if (!ReadW)
{
v = temp.OriText;
}
temp.Count -= 1;
if (temp.Count == 0)
{
Writeinfo.Remove(temp);
}
}
}
else
{
var temp = Writeinfo.FirstOrDefault(x => x.TransText == v && x.ControlName == v2);
if (temp != null)
{
v = temp.OriText;
temp.Count -= 1;
if (temp.Count == 0)
{
Writeinfo.Remove(temp);
}
}
}
}
return v;
}
private void ReadAdd(string v, string v2)
{
if (!CheckBox(v)) return;
var Find = Readinfo.FirstOrDefault(x => x.OriText == v && x.ControlName == v2);
if (Find == null)
{
Readinfo.Add(new FormText(v, 1, v2));
return;
}
else
{
Find.Count += 1;
}
}
bool CheckBox(string v)
{
if (v == null)
{
return false;
}
foreach (var item in v.Select(x => x.ToString()).ToArray())
{
if (Convert.ToChar(item) > 128)
{
return true;
}
}
return false;
}
private void GetOrChangeControl(Control Control, int count)
{
if (Control is ComboBox)
{
var ComboBox = Control as ComboBox;
if (ComboBox.Items.Count > 1)
{
if (Read)
{
var StringBuild = new StringBuilder();
foreach (var item in ComboBox.Items)
{
ReadAdd(item.ToString(), ComboBox.Name);
}
}
if (Write)
{
for (int i = 0; i < ComboBox.Items.Count; i++)
{
var temp = WriteAdd(ComboBox.Items[i].ToString(), ComboBox.Name);
if (temp!=null)
{
ComboBox.Items[i] = temp;
}
}
/* var tempinfo = Writeinfo.FirstOrDefault(x => x.ID == ComboBox.Name && x.Parent == (ComboBox.Parent != null ? ComboBox.Parent.Name : "null"));
if (tempinfo != null)
{
var StringSplit = tempinfo.text.Split(new char[] { '|' }, System.StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < StringSplit.Length; i++)
{
ComboBox.Items[i] = StringSplit[i];
}
}*/
}
}
}
else if (Control is TabPage)
{
var TabPage = Control as TabPage;
if (ReadW)
{
if (TabPage.Name == "tabPage5")
{
if (Bonepage == null)
{
Bonepage = TabPage;
foreach (Control item in TabPage.Controls)
{
if (item.Name.EndsWith("Find"))
{
BoneSearch = item as TextBox;
break;
}
}
}
}
else if (TabPage.Name == "tabPage9")
{
if (Bodypage == null)
{
Bodypage = TabPage;
foreach (Control item in TabPage.Controls)
{
if (item.Name.EndsWith("Find"))
{
BodySearch = item as TextBox;
break;
}
}
}
}
else if (TabPage.Name == "tabPage10")
{
if (jointpage == null)
{
jointpage = TabPage;
foreach (Control item in TabPage.Controls)
{
if (item.Name.EndsWith("Find"))
{
JointSearch = item as TextBox;
break;
}
}
}
}
ReadAdd(TabPage.Text, TabPage.Name);
}
if (Write)
{
TabPage.Text= WriteAdd(TabPage.Text, TabPage.Name);
/* if (Writeinfo != null)
{
var tempinfo = Writeinfo.FirstOrDefault(x => x.ID == TabPage.Name && x.Parent == (TabPage.Parent != null ? TabPage.Parent.Name : "null"));
if (tempinfo != null)
{
TabPage.Text = tempinfo.text;
}
}*/
}
}
else if (Control.Text != "0" && !string.IsNullOrWhiteSpace(Control.Text))
{
if (!regex.IsMatch(Control.Text))
{
if (Control.Name.ToString() == "")
{
ReadAdd(Control.Text, "TextBox");
}
else if (Control.Name.ToString() == "btnGetObject")
{
if (btnGetObject == null) btnGetObject = Control as Button;
}
else
{
if (Control.Name == "lblInfo_PmxVer" || Control.Name == "label80")
{
return;
}
if (Read)
{
ReadAdd(Control.Text, Control.Name);
}
if (Write)
{
/* if (Writeinfo != null)
{
var tempinfo = Writeinfo.FirstOrDefault(x => x.ID == Control.Name && x.Parent == (Control.Parent != null ? Control.Parent.Name : "null"));
if (tempinfo != null)
{
Control.Text = tempinfo.text;
}
}*/
Control.Text= WriteAdd(Control.Text, Control.Name);
}
}
}
}
else if (Control.Name == "vtCtrl")
{
foreach (var fi in Control.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
{
SwichControl(fi.GetValue(Control), count);
}
}
else if (Control is ContextMenuStrip)
{
if (Control.Name == "contextMaterial" && contextMaterial == null)
{
contextMaterial = Control as ContextMenuStrip;
}
}
}
private FormText TempForm = new FormText();
private void GetOrChangeForm(Form form, int count)
{
if (form.Name == "PmxViewEdit")
{
form.Font = new System.Drawing.Font("MS UI Gothic", 9f);
}
if(Read)
{
ReadAdd(form.Text,form.Name);
}
if(Write)
{
form.Text= WriteAdd(form.Text, form.Name);
/* var temp = Writeinfo.FirstOrDefault(x => x.ID == form.Name && x.Parent == (form.Parent!=null? form.Parent.Name:"null"));
if(temp!=null) form.Name = temp.text;*/
}
foreach (var fi in form.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
{
SwichControl(fi.GetValue(form), count);
}
}
}
}