-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUtil.cs
151 lines (108 loc) · 4.41 KB
/
Util.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using LavishScriptAPI;
using LavishScriptAPI.Interfaces;
using InnerSpaceAPI;
namespace Aion.isxAion
{
internal class Util
{
private static T[] PrefixArray<T>(T First, T[] Rest)
{
T[] NewArray = new T[Rest.Length + 1];
NewArray[0] = First;
for (int i = 0; i < Rest.Length; i++)
NewArray[i + 1] = Rest[i];
return NewArray;
}
private static List<T> IndexToLavishScriptObjectList<T>(LavishScriptObject Index)
{
List<T> List = new List<T>();
int Count = Index.GetMember<int>("Used");
ConstructorInfo constructor = typeof(T).GetConstructor(new Type[] { typeof(LavishScriptObject) });
for (int i = 1; i <= Count; i++)
List.Add((T)constructor.Invoke(new object[] { Index.GetIndex(i.ToString()) }));
return List;
}
private static List<T> IndexToStructList<T>(LavishScriptObject Index)
{
List<T> List = new List<T>();
int Count = Index.GetMember<int>("Used");
for (int i = 1; i <= Count; i++)
List.Add(Index.GetIndex<T>(i.ToString()));
return List;
}
private static List<T> IndexToList<T>(LavishScriptObject Index)
{
if (typeof(T).IsSubclassOf(typeof(LavishScriptObject)))
return IndexToLavishScriptObjectList<T>(Index);
else
return IndexToStructList<T>(Index);
}
private static T IndexToLavishScriptObject<T>(LavishScriptObject Index, int number)
{
ConstructorInfo constructor = typeof(T).GetConstructor(new Type[] { typeof(LavishScriptObject) });
return (T)constructor.Invoke(new object[] { Index.GetIndex(number.ToString()) });
}
public static T GetIndexMember<T>(LavishScriptObject Index, int number)
{
if (typeof(T).IsSubclassOf(typeof(LavishScriptObject)))
return (T)typeof(T).GetConstructor(new Type[] { typeof(LavishScriptObject) }).Invoke(new object[] { Index.GetIndex(number.ToString()) });
else
return Index.GetIndex<T>(number.ToString());
}
internal static List<T> GetListFromMethod<T>(ILSObject Obj, string MethodName, string LSTypeName, params string[] Args)
{
if (Obj == null || !Obj.IsValid)
return null;
LavishScriptObject Index = LavishScript.Objects.NewObject("index:" + LSTypeName);
string[] allargs = PrefixArray<string>(Index.LSReference, Args);
Obj.ExecuteMethod(MethodName, allargs);
LavishScriptObject used = Index.GetMember("Used");
if (LavishScriptObject.IsNullOrInvalid(used))
return null;
return IndexToList<T>(Index);
}
internal static T GetFromIndexMethod<T>(ILSObject Obj, string MethodName, string LSTypeName, int number, params string[] Args)
{
// argument is 0-based
number += 1;
if (Obj == null || !Obj.IsValid || number <= 0)
return default(T);
LavishScriptObject Index = LavishScript.Objects.NewObject("index:" + LSTypeName);
string[] allargs = PrefixArray<string>(Index.LSReference, Args);
Obj.ExecuteMethod(MethodName, allargs);
LavishScriptObject used = Index.GetMember("Used");
// if it failed or we want one off the end, return
if (LavishScriptObject.IsNullOrInvalid(used) || used.GetValue<int>() < number)
return default(T);
return GetIndexMember<T>(Index, number);
}
internal static List<T> GetListFromMember<T>(ILSObject Obj, string MemberName, string LSTypeName, params string[] Args)
{
if (Obj == null || !Obj.IsValid)
return null;
LavishScriptObject Index = LavishScript.Objects.NewObject("index:" + LSTypeName);
string[] allargs = PrefixArray<string>(Index.LSReference, Args);
LavishScriptObject retval = Obj.GetMember(MemberName, allargs);
if (LavishScriptObject.IsNullOrInvalid(retval))
return null;
return IndexToList<T>(Index);
}
internal static T GetFromIndexMember<T>(ILSObject Obj, string MemberName, string LSTypeName, int number, params string[] Args)
{
// argument is 0-based
number += 1;
if (Obj == null || !Obj.IsValid)
return default(T);
LavishScriptObject Index = LavishScript.Objects.NewObject("index:" + LSTypeName);
string[] allargs = PrefixArray<string>(Index.LSReference, Args);
LavishScriptObject retval = Obj.GetMember(MemberName, allargs);
if (LavishScriptObject.IsNullOrInvalid(retval) || retval.GetValue<int>() < number)
return default(T);
return GetIndexMember<T>(Index, number);
}
}
}