-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTranslator.cs
55 lines (49 loc) · 2.04 KB
/
Translator.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
using Il2CppInspector.PluginAPI;
using Il2CppInspector.PluginAPI.V100;
using Il2CppTranslator.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Il2CppTranslator
{
public class Translator
{
private IPlugin Plugin { get; }
public List<Type> Translated;
public Il2CppInspector.Reflection.TypeModel Model;
public List<Il2CppInspector.Reflection.TypeInfo> Types;
public List<Il2CppInspector.Reflection.FieldInfo> Fields;
public List<(string, string)> Translations;
public Translator(object plugin, Il2CppInspector.Reflection.TypeModel model)
{
Translations = new List<(string, string)>();
Translated = new List<Type>();
if (!(plugin is IPlugin)) throw new ArgumentException("Argument 0 must implement IPlugin");
Plugin = (IPlugin)plugin;
Model = model;
Types = Model.Types.Where(t => t.Assembly.ShortName == "Assembly-CSharp.dll").ToList();
Fields = Types.SelectMany(t => t.DeclaredFields).ToList();
}
public void StartTranslating()
{
PluginServices services = PluginServices.For(Plugin);
var translators = LocateTranslators(Plugin.GetType().Assembly).ToList();
foreach (var translator in translators)
{
services.StatusUpdate($"Translating {translator.Name}");
Il2CppInspector.Reflection.TypeInfo type = TypeTranslator.GetMatchingType(translator, this);
if (type == null)
{
continue;
}
TypeTranslator.TranslateRecursively(translator, type, this);
}
}
private IEnumerable<Type> LocateTranslators(Assembly assembly)
{
var translators = assembly.GetTypes().Where(type => Attribute.IsDefined(type, typeof(TranslatorAttribute)));
return translators.TopologicalSort(t => t.GetType(), t => t.GetDependecies());
}
}
}