This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AvatarUtils.cs
257 lines (223 loc) · 10.8 KB
/
AvatarUtils.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
using BestHTTP.JSON;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using UnityEngine;
using VRC;
using VRC.Core;
using VRC.Core.BestHTTP;
using VRC.UI;
namespace VRCTools
{
public abstract class AvatarUtils
{
private static List<Action> cb = new List<Action>();
public static void Init()
{
}
public static void Update()
{
try
{
lock (cb)
{
foreach (Action a in cb)
{
a();
}
cb.Clear();
}
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.O))
{
if (PlayerManager.GetCurrentPlayer() == null)
{
VRCToolsLogger.Info("Unable to get current player");
VRCToolsMainComponent.MessageGUI(Color.red, "Unable to get current player", 3);
}
else
{
VRCPlayer vrcPlayer1 = PlayerManager.GetCurrentPlayer().vrcPlayer;
ApiAvatar apiAvatar1 = DeobfGetters.getApiAvatar();
if (apiAvatar1 == null)
{
VRCToolsLogger.Error("Your avatar couldn't be retrieved. Maybe your Assembly-CSharp.dll is in the wrong version ?");
return;
}
Boolean f = false;
if (apiAvatar1.releaseStatus != "public")
{
VRCToolsMainComponent.MessageGUI(Color.red, "Couldn't add avatar to list: This avatar is not public ! (" + apiAvatar1.name + ")", 3);
}
foreach (String s in apiAvatar1.tags) if (s == "favorite") { f = true; break; }
if (!f)
{
VRCToolsLogger.Info("Adding avatar to favorite: " + apiAvatar1.name);
VRCToolsLogger.Info("Description: " + apiAvatar1.description);
int rc = VRCTServerManager.AddAvatar(apiAvatar1);
if (rc == ReturnCodes.SUCCESS)
{
apiAvatar1.tags.Add("favorite");
VRCToolsMainComponent.MessageGUI(Color.green, "Successfully favorited avatar " + apiAvatar1.name, 3);
}
else if (rc == ReturnCodes.AVATAR_ALREADY_IN_FAV)
{
apiAvatar1.tags.Add("favorite");
VRCToolsMainComponent.MessageGUI(Color.yellow, "Already in favorite list: " + apiAvatar1.name, 3);
}
else if (rc == ReturnCodes.AVATAR_PRIVATE)
{
apiAvatar1.tags.Add("favorite");
VRCToolsMainComponent.MessageGUI(Color.red, "Couldn't add avatar to list: This avatar is not public ! (" + apiAvatar1.name + ")", 3);
}
else VRCToolsMainComponent.MessageGUI(Color.red, "Unable to favorite avatar (error " + rc + "): " + apiAvatar1.name, 3);
}
else
{
VRCToolsLogger.Info("This avatar is already in favorite list");
VRCToolsMainComponent.MessageGUI(Color.yellow, "Already in favorite list: " + apiAvatar1.name, 3);
}
}
}
}
catch (Exception e)
{
VRCToolsLogger.Error(e.ToString());
}
}
public static void FetchFavList(string endpoint, HTTPMethods method, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null, bool needsAPIKey = true, bool authenticationRequired = true, bool disableCache = false, float cacheLifetime = 3600f)
{
string text = (!disableCache) ? "cyan" : "red";
VRC.Core.Logger.Log(string.Concat(new object[]
{
"<color=",
text,
">Dispatch ",
method,
" ",
endpoint,
(requestParams == null) ? string.Empty : (" params: " + Json.Encode(requestParams)),
" disableCache: ",
disableCache.ToString(),
"</color>"
}), DebugLevel.API);
MethodInfo UpdateDelegatorMethod = typeof(API).Assembly.GetType("VRC.Core.UpdateDelegator").GetMethod(
"Dispatch",
BindingFlags.Static | BindingFlags.Public,
null,
new Type[] { typeof(Action) },
null
);
Action delegateAction = delegate
{
MethodInfo SendRequestInternalMethod = typeof(API).GetMethod(
"SendRequestInternal",
BindingFlags.Static | BindingFlags.NonPublic,
null,
new Type[] { typeof(string), typeof(HTTPMethods), typeof(ApiContainer), typeof(Dictionary<string, object>), typeof(bool), typeof(bool), typeof(bool), typeof(float) },
null
);
if (endpoint == "avatars" && requestParams.ContainsKey("user") && requestParams["user"] == "me")
{
ApiModelListContainer<ApiAvatar> rc = new ApiModelListContainer<ApiAvatar>
{
OnSuccess = delegate (ApiContainer c)
{
Thread t = new Thread(new ThreadStart(() => {
List<object> avatarsFav = VRCTServerManager.GetAvatars();
((List<object>)c.Data).AddRange(avatarsFav);
MethodInfo SetResponseModelsMethod = typeof(ApiModelListContainer<ApiAvatar>).GetMethod(
"set_ResponseModels",
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new Type[] { typeof(List<ApiAvatar>) },
null
);
String responseError = "";
SetResponseModelsMethod.Invoke(c, new object[] { API.ConvertJsonListToModelList<ApiAvatar>((List<object>)c.Data, ref responseError, c.DataTimestamp) });
lock (cb)
{
cb.Add(
new Action(() => {
responseContainer.OnSuccess(c);
})
);
}
}));
t.Start();
},
OnError = delegate (ApiContainer c)
{
responseContainer.OnError(c);
}
};
SendRequestInternalMethod.Invoke(null, new object[] { endpoint, method, rc, requestParams, needsAPIKey, authenticationRequired, disableCache, cacheLifetime });
}
else
{
SendRequestInternalMethod.Invoke(null, new object[] { endpoint, method, responseContainer, requestParams, needsAPIKey, authenticationRequired, disableCache, cacheLifetime });
}
};
UpdateDelegatorMethod.Invoke(null, new object[] { delegateAction });
}
/*
public static void FetchFavList(string endpoint, HTTPMethods method, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null, bool needsAPIKey = true, bool authenticationRequired = true, bool disableCache = false, float cacheLifetime = 3600f)
{
string text = (!disableCache) ? "cyan" : "red";
Debug.Log(string.Concat(new object[]
{
"<color=",
text,
">Dispatch ",
method,
" ",
endpoint,
(requestParams == null) ? string.Empty : (" params: " + Json.Encode(requestParams)),
" disableCache: ",
disableCache.ToString(),
"</color>"
}));
UpdateDelegator.Dispatch(delegate
{
if (false && endpoint == "avatars" && requestParams.ContainsKey("user") && requestParams["user"] == "me")
{
//*
MethodInfo m = typeof(ApiModel).GetMethod(
"SendRequest",
BindingFlags.Static | BindingFlags.NonPublic,
null,
new Type[] { typeof(string), typeof(HTTPMethods), typeof(Dictionary<string, string>), typeof(Action<string>), typeof(Action<Dictionary<string, object>>), typeof(Action<List<object>>), typeof(Action<string>), typeof(bool), typeof(bool), typeof(float) },
null
);
* /
/*
Action<List<object>> sc = new Action<List<object>>((list) => {
Thread t = new Thread(new ThreadStart(() => {
list.AddRange(VRCTServerManager.GetAvatars());
lock (cb)
{
cb.Add(
new Action(() => {
successCallback(list);
})
);
}
}));
t.Start();
});
Action<string> ec = new Action<string>((error) => {
errorCallback(error);
});
* /
//m.Invoke(null, new object[] { "avatars", HTTPMethods.Get, requestParams, null, null, sc, ec, needsAPIKey, authenticationRequired, cacheLifetime });
}
else
{
API.SendRequestInternal(endpoint, method, responseContainer, requestParams, needsAPIKey, authenticationRequired, disableCache, cacheLifetime);
}
});
}
*/
}
}