private static void OnContainerSuccess(ApiContainer container) { if (container == null) { return; } ApiModelListContainer <APIUser> listContainer = container.TryCast <ApiModelListContainer <APIUser> >(); if (listContainer != null) { try { for (int i = 0; i < listContainer.ResponseList.Count; i++) { cachedUsers[listContainer.ResponseModels.get_Item(i).id] = new UserInfoExtensionsAPIUser(listContainer.ResponseList.get_Item(i)); } } catch (Exception ex) { MelonLogger.Error("Failed while caching user from list:\n" + ex.ToString()); } } else if (container.Model != null && container.Model.GetIl2CppType() == Il2CppType.Of <APIUser>()) { try { cachedUsers[container.Model.id] = new UserInfoExtensionsAPIUser(container.Data); } catch (Exception ex) { MelonLogger.Error("Failed while caching user:\n" + ex.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 }); }