-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExtensions.cs
More file actions
98 lines (98 loc) · 5.04 KB
/
Copy pathExtensions.cs
File metadata and controls
98 lines (98 loc) · 5.04 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
namespace SC2Expansion{
public static class ModelArrayExtensions{
public static AbilityModel GetAbility(this Il2CppReferenceArray<Model>array,string name){
return array.GetModels<AbilityModel>().First(a=>a.modelName==name);
}
public static T GetModel<T>(this Il2CppReferenceArray<Model>array)where T:Model{
return array.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()).Cast<T>();
}
public static T GetModel<T>(this Il2CppReferenceArray<Model>array,string modelName)where T:Model{
return array.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()&&a.name.Contains(modelName)).Cast<T>();
}
public static void WriteIl2CppObjToFile(this Il2CppSystem.Object obj,string path){
try{
System.IO.File.WriteAllText(path,Il2CppNewtonsoft.Json.JsonConvert.SerializeObject(obj,new JsonSerializerSettings(){
Formatting=Formatting.Indented,_referenceLoopHandling=new(ReferenceLoopHandling.Ignore)}));
Log("object dumped to "+path);
}catch(Exception error){
PrintError(error);
}
}
public static Il2CppReferenceArray<T>GetModels<T>(this Il2CppReferenceArray<Model>array)where T:Model{
Model[]models=array.Where(a=>a.GetIl2CppType()==Il2CppType.Of<T>()).ToArray();
Il2CppReferenceArray<T>returnArray=new Il2CppReferenceArray<T>(models.Length);
for(int i=0;i<models.Length;i++){
returnArray[i]=models[i].Cast<T>();
}
return returnArray;
}
public static bool HasModel<T>(this Il2CppReferenceArray<Model>array)where T:Model{
foreach(Model model in array){
if(model.GetIl2CppType()==Il2CppType.Of<T>()){
return true;
}
}
return false;
}
public static T GetModelClone<T>(this Il2CppReferenceArray<Model>array)where T:Model{
return array.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()).Clone<T>();
}
public static T GetModelClone<T>(this Il2CppReferenceArray<Model>array,string modelName)where T:Model{
return array.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()&&a.name.Contains(modelName)).Clone<T>();
}
}
public static class Il2CppListBehaviourExtensions{
public static T GetBehaviour<T>(this Il2CppSystem.Collections.Generic.List<RootBehavior>list)where T:RootBehavior{
return list._items.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()).Cast<T>();
}
public static T GetBehaviour<T>(this Il2CppSystem.Collections.Generic.List<RootBehavior>list,string modelName)where T:RootBehavior{
return list._items.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()&&a.model.name.Contains(modelName)).Cast<T>();
}
}
public static class ModelListExtensions{
//for some fucking reason, name does not work on abilities and modelname is what you do instead. wtf
public static AbilityModel GetAbility(this List<Model>list,string name){
return list.GetModels<AbilityModel>().First(a=>a.modelName==name);
}
public static T GetModel<T>(this List<Model>list)where T:Model{
return list.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()).Cast<T>();
}
public static void RemoveModel<T>(this List<Model>list)where T:Model{
list.Remove(list.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()));
}
public static void RemoveModel(this List<Model>list,string modelName){
list.Remove(list.First(a=>a.name.Contains(modelName)));
}
public static T GetModel<T>(this List<Model>list,string modelName)where T:Model{
return list.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()&&a.name.Contains(modelName)).Cast<T>();
}
public static List<T>GetModels<T>(this List<Model>list)where T:Model{
//as much as i would love to cast the result via the builtin methods, runtime says no.
//no casting il2cpp types like that and already have this on il2cppreferencearray so...
List<T>returnList=new List<T>();
foreach(Model model in list.Where(a=>a.GetIl2CppType()==Il2CppType.Of<T>())){
returnList.Add(model.Cast<T>());
}
return returnList;
}
public static T GetModelClone<T>(this List<Model>list)where T:Model{
return list.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()).Clone<T>();
}
public static T GetModelClone<T>(this List<Model>list,string modelName)where T:Model{
return list.First(a=>a.GetIl2CppType()==Il2CppType.Of<T>()&&a.name.Contains(modelName)).Clone<T>();
}
public static bool HasModel<T>(this List<Model>list)where T:Model{
foreach(Model model in list){
if(model.GetIl2CppType()==Il2CppType.Of<T>()){
return true;
}
}
return false;
}
}
public static class ModelExtensions{
public static T Clone<T>(this Model model)where T:Model{
return model.Clone().Cast<T>();
}
}
}