forked from bttf92/FusionLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomModelHandler.cs
91 lines (79 loc) · 2.56 KB
/
CustomModelHandler.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
using GTA;
using GTA.Native;
using System;
using System.Collections.Generic;
namespace FusionLibrary
{
public class CustomModel
{
public string Name { get; }
public Model Model { get; }
public CustomModel(string name)
{
Name = name;
Model = new Model(name);
}
public CustomModel(Model model)
{
Name = model.Hash.ToString();
Model = model;
}
public Model Request()
{
return FusionUtils.LoadAndRequestModel(Model, Name);
}
public static implicit operator Model(CustomModel customModel)
{
return customModel.Request();
}
public static implicit operator string(CustomModel customModel)
{
return customModel.Name;
}
public static implicit operator CustomModel(Model model)
{
return new CustomModel(model);
}
public static implicit operator InputArgument(CustomModel customModel)
{
return new InputArgument((ulong)customModel.Request().Hash);
}
public override string ToString()
{
return Name;
}
}
public class CustomModelHandler
{
protected static List<CustomModel> GetAllModels(Type type)
{
System.Reflection.FieldInfo[] fields = type.GetFields();
List<CustomModel> models = new List<CustomModel>();
foreach (System.Reflection.FieldInfo field in fields)
{
object obj = field.GetValue(null);
if (obj.GetType() == typeof(CustomModel))
{
CustomModel modelObj = (CustomModel)obj;
models.Add(modelObj);
}
else if (obj.GetType() == typeof(Dictionary<int, CustomModel>))
{
Dictionary<int, CustomModel> dict = (Dictionary<int, CustomModel>)obj;
models.AddRange(dict.Values);
}
else if (obj.GetType() == typeof(Dictionary<string, CustomModel>))
{
Dictionary<string, CustomModel> dict = (Dictionary<string, CustomModel>)obj;
models.AddRange(dict.Values);
}
else if (obj.GetType() == typeof(List<CustomModel>))
{
List<CustomModel> dict = (List<CustomModel>)obj;
models.AddRange(dict);
}
}
return models;
}
}
}