Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.61 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. using VRC.Core.BestHTTP;
  8. using VRC.Core.BestHTTP.Authentication;
  9. using VRC.Core.BestHTTP.Cookies;
  10. using VRC.Core.BestHTTP.JSON;
  11.  
  12. namespace VRC.Core
  13. {
  14. // Token: 0x02000015 RID: 21
  15. public static class API
  16. {
  17. // Token: 0x06000077 RID: 119 RVA: 0x00003E70 File Offset: 0x00002070
  18. public static void SetOrganization(string s)
  19. {
  20. API.API_ORGANIZATION = s;
  21. }
  22.  
  23. // Token: 0x06000078 RID: 120 RVA: 0x00003E78 File Offset: 0x00002078
  24. public static string GetOrganization()
  25. {
  26. return API.API_ORGANIZATION;
  27. }
  28.  
  29. // Token: 0x06000079 RID: 121 RVA: 0x00003E80 File Offset: 0x00002080
  30. public static bool IsReady()
  31. {
  32. return API.API_ORGANIZATION != null && API.API_ONLINE_MODE != ApiOnlineMode.Uninitialized;
  33. }
  34.  
  35. // Token: 0x0600007A RID: 122 RVA: 0x00003E9C File Offset: 0x0000209C
  36. public static T FromCacheOrNew<T>(string id, float maxCacheAge = -1f) where T : ApiModel, ApiCacheObject, new()
  37. {
  38. T t = Activator.CreateInstance<T>();
  39. t.id = id;
  40. T t2 = t;
  41. if (!ApiCache.Fetch<T>(id, ref t2, maxCacheAge))
  42. {
  43. ApiCache.Save(id, t2, false);
  44. }
  45. return t2;
  46. }
  47.  
  48. // Token: 0x0600007B RID: 123 RVA: 0x00003EDC File Offset: 0x000020DC
  49. public static T CreateFromJson<T>(Dictionary<string, object> json) where T : ApiModel, ApiCacheObject, new()
  50. {
  51. T result;
  52. try
  53. {
  54. T t = Activator.CreateInstance<T>();
  55. string str = null;
  56. if (!t.SetApiFieldsFromJson(json, ref str))
  57. {
  58. Debug.LogError(typeof(T).Name + ": Unable to CreateFromJson: " + str);
  59. result = (T)((object)null);
  60. }
  61. else
  62. {
  63. result = t;
  64. }
  65. }
  66. catch (Exception ex)
  67. {
  68. Debug.LogError(string.Concat(new string[]
  69. {
  70. typeof(T).Name,
  71. ": Unable to CreateFromJson: ",
  72. ex.Message,
  73. "\n",
  74. ex.StackTrace
  75. }));
  76. result = (T)((object)null);
  77. }
  78. return result;
  79. }
  80.  
  81. // Token: 0x0600007C RID: 124 RVA: 0x00003FB0 File Offset: 0x000021B0
  82. public static T Clone<T>(ApiModel model) where T : ApiModel, ApiCacheObject, new()
  83. {
  84. return model.Clone(typeof(T), null) as T;
  85. }
  86.  
  87. // Token: 0x0600007D RID: 125 RVA: 0x00003FD0 File Offset: 0x000021D0
  88. public static T Fetch<T>(string id, Action<ApiContainer> onSuccess = null, Action<ApiContainer> onFailure = null, bool disableCache = false) where T : ApiModel, ApiCacheObject, new()
  89. {
  90. API.<Fetch>c__AnonStorey7<T> <Fetch>c__AnonStorey = new API.<Fetch>c__AnonStorey7<T>();
  91. <Fetch>c__AnonStorey.onSuccess = onSuccess;
  92. API.<Fetch>c__AnonStorey7<T> <Fetch>c__AnonStorey2 = <Fetch>c__AnonStorey;
  93. T model = Activator.CreateInstance<T>();
  94. model.id = id;
  95. <Fetch>c__AnonStorey2.model = model;
  96. if (!disableCache && ApiCache.Fetch<T>(id, ref <Fetch>c__AnonStorey.model, 3600f))
  97. {
  98. if (<Fetch>c__AnonStorey.onSuccess != null)
  99. {
  100. UpdateDelegator.Dispatch(delegate
  101. {
  102. <Fetch>c__AnonStorey.onSuccess(new ApiModelContainer<T>(<Fetch>c__AnonStorey.model));
  103. });
  104. }
  105. return <Fetch>c__AnonStorey.model;
  106. }
  107. <Fetch>c__AnonStorey.model.Fetch(<Fetch>c__AnonStorey.onSuccess, onFailure, null, false);
  108. return <Fetch>c__AnonStorey.model;
  109. }
  110.  
  111. // Token: 0x0600007E RID: 126 RVA: 0x00004064 File Offset: 0x00002264
  112. public static void Delete<T>(string id, Action<ApiContainer> onSuccess = null, Action<ApiContainer> onFailure = null) where T : ApiModel, ApiCacheObject, new()
  113. {
  114. T t = Activator.CreateInstance<T>();
  115. t.id = id;
  116. T t2 = t;
  117. t2.Delete(onSuccess, onFailure);
  118. }
  119.  
  120. // Token: 0x0600007F RID: 127 RVA: 0x00004098 File Offset: 0x00002298
  121. public static void Save(ApiModel model, Action<ApiContainer> onSuccess = null, Action<ApiContainer> onFailure = null)
  122. {
  123. model.Save(onSuccess, onFailure);
  124. }
  125.  
  126. // Token: 0x06000080 RID: 128 RVA: 0x000040A4 File Offset: 0x000022A4
  127. public static void Save(IEnumerable<ApiModel> models, Action<ApiContainer> onSuccess = null, Action<ApiContainer> onFailure = null)
  128. {
  129. foreach (ApiModel apiModel in models)
  130. {
  131. apiModel.Save(onSuccess, onFailure);
  132. }
  133. }
  134.  
  135. // Token: 0x06000081 RID: 129 RVA: 0x00004104 File Offset: 0x00002304
  136. public static void Post(ApiModel model, Action<ApiContainer> onSuccess = null, Action<ApiContainer> onFailure = null)
  137. {
  138. model.Post(onSuccess, onFailure, null);
  139. }
  140.  
  141. // Token: 0x06000082 RID: 130 RVA: 0x00004110 File Offset: 0x00002310
  142. public static void Post(IEnumerable<ApiModel> models, Action<ApiContainer> onSuccess = null, Action<ApiContainer> onFailure = null)
  143. {
  144. foreach (ApiModel apiModel in models)
  145. {
  146. apiModel.Post(onSuccess, onFailure, null);
  147. }
  148. }
  149.  
  150. // Token: 0x17000006 RID: 6
  151. // (get) Token: 0x06000083 RID: 131 RVA: 0x00004170 File Offset: 0x00002370
  152. public static string DeviceID
  153. {
  154. get
  155. {
  156. return SystemInfo.deviceUniqueIdentifier;
  157. }
  158. }
  159.  
  160. // Token: 0x06000084 RID: 132 RVA: 0x00004178 File Offset: 0x00002378
  161. public static List<string> GetIds(IEnumerable<ApiModel> models)
  162. {
  163. List<string> list = new List<string>();
  164. foreach (ApiModel apiModel in models)
  165. {
  166. list.Add(apiModel.id);
  167. }
  168. return list;
  169. }
  170.  
  171. // Token: 0x06000085 RID: 133 RVA: 0x000041E4 File Offset: 0x000023E4
  172. public static string GetAssetPlatformString()
  173. {
  174. RuntimePlatform platform = Application.platform;
  175. if (platform == RuntimePlatform.WindowsPlayer || platform == RuntimePlatform.WindowsEditor)
  176. {
  177. return "standalonewindows";
  178. }
  179. return "unknownplatform";
  180. }
  181.  
  182. // Token: 0x06000086 RID: 134 RVA: 0x00004210 File Offset: 0x00002410
  183. public static void SetApiUrlFromEnvironment(ApiServerEnvironment env)
  184. {
  185. API.SetApiUrl(API.GetApiUrlForEnvironment(env));
  186. }
  187.  
  188. // Token: 0x06000087 RID: 135 RVA: 0x00004220 File Offset: 0x00002420
  189. public static string GetApiUrlForEnvironment(ApiServerEnvironment env)
  190. {
  191. switch (env)
  192. {
  193. case ApiServerEnvironment.Dev:
  194. return "https://dev-api.vrchat.cloud/api/1/";
  195. case ApiServerEnvironment.Beta:
  196. return "https://beta-api.vrchat.cloud/api/1/";
  197. case ApiServerEnvironment.Release:
  198. return "https://api.vrchat.cloud/api/1/";
  199. default:
  200. Debug.LogError("Unknown server environment! " + env.ToString());
  201. return string.Empty;
  202. }
  203. }
  204.  
  205. // Token: 0x06000088 RID: 136 RVA: 0x00004278 File Offset: 0x00002478
  206. public static void SetApiUrl(string url)
  207. {
  208. API.API_URL = url;
  209. }
  210.  
  211. // Token: 0x06000089 RID: 137 RVA: 0x00004280 File Offset: 0x00002480
  212. public static string GetApiUrl()
  213. {
  214. return API.API_URL;
  215. }
  216.  
  217. // Token: 0x0600008A RID: 138 RVA: 0x00004288 File Offset: 0x00002488
  218. public static bool IsDevApi()
  219. {
  220. return API.GetApiUrl() == "https://dev-api.vrchat.cloud/api/1/";
  221. }
  222.  
  223. // Token: 0x0600008B RID: 139 RVA: 0x0000429C File Offset: 0x0000249C
  224. public static void SendGetRequest(string target, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null, bool disableCache = false, float cacheLifetime = 3600f)
  225. {
  226. API.SendRequest(target, HTTPMethods.Get, responseContainer, requestParams, true, true, disableCache, cacheLifetime);
  227. }
  228.  
  229. // Token: 0x0600008C RID: 140 RVA: 0x000042B8 File Offset: 0x000024B8
  230. public static void SendPostRequest(string target, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null)
  231. {
  232. API.SendRequest(target, HTTPMethods.Post, responseContainer, requestParams, true, true, false, 3600f);
  233. }
  234.  
  235. // Token: 0x0600008D RID: 141 RVA: 0x000042D8 File Offset: 0x000024D8
  236. public static void SendPutRequest(string target, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null)
  237. {
  238. API.SendRequest(target, HTTPMethods.Put, responseContainer, requestParams, true, true, false, 3600f);
  239. }
  240.  
  241. // Token: 0x0600008E RID: 142 RVA: 0x000042F8 File Offset: 0x000024F8
  242. public static void SendDeleteRequest(string target, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null)
  243. {
  244. API.SendRequest(target, HTTPMethods.Delete, responseContainer, requestParams, true, true, false, 3600f);
  245. }
  246.  
  247. // Token: 0x0600008F RID: 143 RVA: 0x00004318 File Offset: 0x00002518
  248. public static List<T> ConvertJsonListToModelList<T>(List<object> json, ref string error, float dataTimestamp) where T : ApiModel, new()
  249. {
  250. if (json == null)
  251. {
  252. return null;
  253. }
  254. List<T> result;
  255. try
  256. {
  257. List<T> list = new List<T>();
  258. foreach (object obj in json)
  259. {
  260. Dictionary<string, object> fields = obj as Dictionary<string, object>;
  261. T item = Activator.CreateInstance<T>();
  262. if (!item.SetApiFieldsFromJson(fields, ref error))
  263. {
  264. return null;
  265. }
  266. list.Add(item);
  267. }
  268. result = list;
  269. }
  270. catch (Exception ex)
  271. {
  272. error = "An exception was caught when filling the models: " + ex.Message + "\n" + ex.StackTrace;
  273. result = null;
  274. }
  275. return result;
  276. }
  277.  
  278. // Token: 0x06000090 RID: 144 RVA: 0x00004408 File Offset: 0x00002608
  279. public static void SendRequest(string endpoint, HTTPMethods method, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null, bool needsAPIKey = true, bool authenticationRequired = true, bool disableCache = false, float cacheLifetime = 3600f)
  280. {
  281. string text = (!disableCache) ? "cyan" : "red";
  282. Logger.Log(string.Concat(new object[]
  283. {
  284. "<color=",
  285. text,
  286. ">Dispatch ",
  287. method,
  288. " ",
  289. endpoint,
  290. (requestParams == null) ? string.Empty : (" params: " + Json.Encode(requestParams)),
  291. " disableCache: ",
  292. disableCache.ToString(),
  293. "</color>"
  294. }), DebugLevel.API);
  295. UpdateDelegator.Dispatch(delegate
  296. {
  297. API.SendRequestInternal(endpoint, method, responseContainer, requestParams, needsAPIKey, authenticationRequired, disableCache, cacheLifetime);
  298. });
  299. }
  300.  
  301. // Token: 0x06000091 RID: 145 RVA: 0x00004514 File Offset: 0x00002714
  302. private static void SendRequestInternal(string endpoint, HTTPMethods method, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null, bool needsAPIKey = true, bool authenticationRequired = true, bool disableCache = false, float cacheLifetime = 3600f)
  303. {
  304. if (responseContainer == null)
  305. {
  306. responseContainer = new ApiContainer();
  307. }
  308. if (API.API_ONLINE_MODE == ApiOnlineMode.Offline)
  309. {
  310. API.SendOfflineRequest(endpoint, method, responseContainer, requestParams);
  311. return;
  312. }
  313. if (API.API_ONLINE_MODE == ApiOnlineMode.Uninitialized)
  314. {
  315. Debug.LogError("Api Web Request send before online mode is initialized.");
  316. }
  317. string apiUrl = API.GetApiUrl();
  318. Action action = delegate()
  319. {
  320. string uri = apiUrl + endpoint;
  321. UriBuilder uriBuilder = new UriBuilder(uri);
  322. if (!string.IsNullOrEmpty(API.ApiKey))
  323. {
  324. API.AppendQuery(ref uriBuilder, "apiKey=" + API.ApiKey);
  325. }
  326. if (API.API_ORGANIZATION == null)
  327. {
  328. throw new Exception("ApiModel does not have it's organization set!");
  329. }
  330. API.AppendQuery(ref uriBuilder, "organization=" + API.API_ORGANIZATION);
  331. string text = null;
  332. if (requestParams != null)
  333. {
  334. if (method == HTTPMethods.Get)
  335. {
  336. foreach (KeyValuePair<string, object> keyValuePair in requestParams)
  337. {
  338. string str;
  339. if (keyValuePair.Value is string)
  340. {
  341. str = (keyValuePair.Value as string);
  342. }
  343. else if (typeof(List<>).IsAssignableFrom(keyValuePair.Value.GetType()))
  344. {
  345. str = Json.Encode((keyValuePair.Value as IList).Cast<object>().ToArray<object>());
  346. }
  347. else
  348. {
  349. str = Json.Encode(keyValuePair.Value);
  350. }
  351. API.AppendQuery(ref uriBuilder, keyValuePair.Key + "=" + str);
  352. }
  353. }
  354. else
  355. {
  356. text = Json.Encode(requestParams);
  357. }
  358. }
  359. string uriPath = uriBuilder.Uri.PathAndQuery;
  360. bool useCache = !disableCache && method == HTTPMethods.Get;
  361. ApiCache.CachedResponse cachedResponse = (!useCache) ? null : ApiCache.GetOrClearCachedResponse(uriBuilder.Uri.PathAndQuery, cacheLifetime);
  362. if (cachedResponse != null)
  363. {
  364. Logger.Log(string.Concat(new object[]
  365. {
  366. "<color=cyan>Using cached ",
  367. method,
  368. " request to ",
  369. uriBuilder.Uri,
  370. "</color>"
  371. }), DebugLevel.API);
  372. try
  373. {
  374. if (responseContainer.OnComplete(true, uriBuilder.Uri.PathAndQuery, 200, string.Empty, () => cachedResponse.Data, () => cachedResponse.DataAsText, cachedResponse.Timestamp))
  375. {
  376. responseContainer.OnSuccess(responseContainer);
  377. }
  378. else
  379. {
  380. Debug.LogError("Something went wrong re-serving data from cache.");
  381. }
  382. }
  383. catch (Exception exception)
  384. {
  385. Debug.LogException(exception);
  386. }
  387. }
  388. else if (method == HTTPMethods.Get && API.activeRequests.ContainsKey(uriPath))
  389. {
  390. Logger.Log(string.Concat(new object[]
  391. {
  392. "<color=cyan>Piggy-backing ",
  393. method,
  394. " request to ",
  395. uriBuilder.Uri,
  396. "</color>"
  397. }), DebugLevel.API);
  398. OnRequestFinishedDelegate originalCallback = API.activeRequests[uriPath].Callback;
  399. API.activeRequests[uriPath].Callback = delegate(HTTPRequest req, HTTPResponse resp)
  400. {
  401. if (API.activeRequests.ContainsKey(uriPath))
  402. {
  403. API.activeRequests.Remove(uriPath);
  404. }
  405. if (originalCallback != null)
  406. {
  407. originalCallback(req, resp);
  408. }
  409. try
  410. {
  411. APIResponseHandler.HandleReponse(0, req, resp, responseContainer, 2, useCache);
  412. }
  413. catch (Exception exception2)
  414. {
  415. Debug.LogException(exception2);
  416. }
  417. };
  418. }
  419. else
  420. {
  421. int requestId = ++API.lastRequestId;
  422. Logger.Log(string.Concat(new object[]
  423. {
  424. "<color=lightblue>[",
  425. requestId,
  426. "] Sending ",
  427. method,
  428. " request to ",
  429. uriBuilder.Uri,
  430. "</color>"
  431. }), DebugLevel.API);
  432. HTTPRequest httprequest = new HTTPRequest(uriBuilder.Uri, delegate(HTTPRequest req, HTTPResponse resp)
  433. {
  434. if (API.activeRequests.ContainsKey(uriPath))
  435. {
  436. API.activeRequests.Remove(uriPath);
  437. }
  438. APIResponseHandler.HandleReponse(requestId, req, resp, responseContainer, 2, useCache);
  439. });
  440. if (method == HTTPMethods.Get)
  441. {
  442. API.activeRequests.Add(uriPath, httprequest);
  443. }
  444. httprequest.AddHeader("X-Requested-With", "XMLHttpRequest");
  445. httprequest.AddHeader("X-MacAddress", API.DeviceID);
  446. httprequest.AddHeader("Content-Type", (method != HTTPMethods.Get) ? "application/json" : "application/x-www-form-urlencoded");
  447. httprequest.AddHeader("Origin", "vrchat.com");
  448. httprequest.MethodType = method;
  449. httprequest.Credentials = (ApiCredentials.GetWebCredentials() as Credentials);
  450. if (authenticationRequired && ApiCredentials.GetAuthToken() != null)
  451. {
  452. List<Cookie> cookies = httprequest.Cookies;
  453. cookies.Add(new Cookie("auth", ApiCredentials.GetAuthToken()));
  454. httprequest.Cookies = cookies;
  455. }
  456. httprequest.ConnectTimeout = TimeSpan.FromSeconds(20.0);
  457. httprequest.Timeout = TimeSpan.FromSeconds(20.0);
  458. if (!string.IsNullOrEmpty(text))
  459. {
  460. httprequest.RawData = Encoding.UTF8.GetBytes(text);
  461. }
  462. httprequest.DisableCache = true;
  463. httprequest.Send();
  464. }
  465. string key = endpoint.ToLower().Split(new char[]
  466. {
  467. '?'
  468. })[0];
  469. if (!API.EndpointAccessTimes.ContainsKey(key))
  470. {
  471. API.EndpointAccessTimes.Add(key, new API.EndpointAccessEntry
  472. {
  473. count = 1,
  474. time = Time.realtimeSinceStartup
  475. });
  476. }
  477. else
  478. {
  479. API.EndpointAccessTimes[key].time = Time.realtimeSinceStartup;
  480. API.EndpointAccessTimes[key].count++;
  481. }
  482. };
  483. if (needsAPIKey && !API.IsOffline())
  484. {
  485. API.FetchApiKey(action, null);
  486. }
  487. else
  488. {
  489. action();
  490. }
  491. }
  492.  
  493. // Token: 0x06000092 RID: 146 RVA: 0x000045EC File Offset: 0x000027EC
  494. private static void AppendQuery(ref UriBuilder baseUri, string queryToAppend)
  495. {
  496. if (baseUri.Query != null && baseUri.Query.Length > 1)
  497. {
  498. baseUri.Query = baseUri.Query.Substring(1) + "&" + queryToAppend;
  499. }
  500. else
  501. {
  502. baseUri.Query = queryToAppend;
  503. }
  504. }
  505.  
  506. // Token: 0x06000093 RID: 147 RVA: 0x00004644 File Offset: 0x00002844
  507. private static void FetchApiKey(Action onSuccess = null, Action<string> onError = null)
  508. {
  509. Action onInit = delegate()
  510. {
  511. if (RemoteConfig.IsInitialized())
  512. {
  513. API.ApiKey = RemoteConfig.GetString("clientApiKey");
  514. if (string.IsNullOrEmpty(API.ApiKey))
  515. {
  516. Logger.LogError("Could not fetch client api key - unknown error.", DebugLevel.Always);
  517. if (onError != null)
  518. {
  519. onError("Could not fetch client api key - unknown error.");
  520. }
  521. }
  522. else if (onSuccess != null)
  523. {
  524. onSuccess();
  525. }
  526. }
  527. else
  528. {
  529. Logger.LogWarning("Could not fetch client api key - config not initialized.", DebugLevel.Always);
  530. if (onError != null)
  531. {
  532. onError("Could not fetch client api key - config not initialized.");
  533. }
  534. }
  535. };
  536. if (string.IsNullOrEmpty(API.ApiKey))
  537. {
  538. RemoteConfig.Init(onInit, null);
  539. }
  540. else if (onSuccess != null)
  541. {
  542. onSuccess();
  543. }
  544. }
  545.  
  546. // Token: 0x06000094 RID: 148 RVA: 0x000046A4 File Offset: 0x000028A4
  547. public static void SetOnlineMode(bool online, string organization = null)
  548. {
  549. if (!online)
  550. {
  551. API.API_ONLINE_MODE = ApiOnlineMode.Offline;
  552. string text = Resources.Load<TextAsset>("offline").text;
  553. object obj = Json.Decode(text);
  554. API.offlineQueries = (obj as List<object>);
  555. }
  556. else
  557. {
  558. API.API_ONLINE_MODE = ApiOnlineMode.Online;
  559. }
  560. if (!string.IsNullOrEmpty(organization))
  561. {
  562. API.SetOrganization(organization);
  563. }
  564. }
  565.  
  566. // Token: 0x06000095 RID: 149 RVA: 0x000046FC File Offset: 0x000028FC
  567. public static bool IsOffline()
  568. {
  569. return API.API_ONLINE_MODE == ApiOnlineMode.Offline;
  570. }
  571.  
  572. // Token: 0x06000096 RID: 150 RVA: 0x00004708 File Offset: 0x00002908
  573. public static ApiServerEnvironment GetServerEnvironmentForApiUrl()
  574. {
  575. return API.GetServerEnvironmentForApiUrl(API.API_URL);
  576. }
  577.  
  578. // Token: 0x06000097 RID: 151 RVA: 0x00004714 File Offset: 0x00002914
  579. public static ApiServerEnvironment GetServerEnvironmentForApiUrl(string url)
  580. {
  581. if (API.GetApiUrl() == "https://api.vrchat.cloud/api/1/")
  582. {
  583. return ApiServerEnvironment.Release;
  584. }
  585. if (API.GetApiUrl() == "https://beta-api.vrchat.cloud/api/1/")
  586. {
  587. return ApiServerEnvironment.Beta;
  588. }
  589. if (API.GetApiUrl() == "https://dev-api.vrchat.cloud/api/1/")
  590. {
  591. return ApiServerEnvironment.Dev;
  592. }
  593. Debug.LogError("GetServerEnvironmentForApiUrl: unknown api url: " + url);
  594. return ApiServerEnvironment.Release;
  595. }
  596.  
  597. // Token: 0x06000098 RID: 152 RVA: 0x00004774 File Offset: 0x00002974
  598. private static void SendOfflineRequest(string endpoint, HTTPMethods method, ApiContainer responseContainer = null, Dictionary<string, object> requestParams = null)
  599. {
  600. foreach (object obj in API.offlineQueries)
  601. {
  602. Dictionary<string, object> dictionary = obj as Dictionary<string, object>;
  603. if (dictionary["url"].ToString() == endpoint)
  604. {
  605. object result = dictionary["result"];
  606. string s = Json.Encode(result);
  607. byte[] data = Encoding.UTF8.GetBytes(s);
  608. responseContainer.OnComplete(true, endpoint, 200, string.Empty, () => data, () => Json.Encode(result), -1f);
  609. if (!responseContainer.IsValid)
  610. {
  611. if (responseContainer.OnError != null)
  612. {
  613. responseContainer.OnError(responseContainer);
  614. }
  615. }
  616. else if (responseContainer.OnSuccess != null)
  617. {
  618. responseContainer.OnSuccess(responseContainer);
  619. }
  620. }
  621. }
  622. Debug.LogError("Query used by application in offline mode not found - " + endpoint);
  623. responseContainer.Error = "query not found in offline results - " + endpoint;
  624. if (responseContainer.OnError != null)
  625. {
  626. responseContainer.OnError(responseContainer);
  627. }
  628. }
  629.  
  630. // Token: 0x04000043 RID: 67
  631. public const string devApiUrl = "https://dev-api.vrchat.cloud/api/1/";
  632.  
  633. // Token: 0x04000044 RID: 68
  634. public const string betaApiUrl = "https://beta-api.vrchat.cloud/api/1/";
  635.  
  636. // Token: 0x04000045 RID: 69
  637. public const string releaseApiUrl = "https://api.vrchat.cloud/api/1/";
  638.  
  639. // Token: 0x04000046 RID: 70
  640. public const float ResponseCacheLifetime = 3600f;
  641.  
  642. // Token: 0x04000047 RID: 71
  643. public const int MAX_RETRY_COUNT = 2;
  644.  
  645. // Token: 0x04000048 RID: 72
  646. public static string API_URL = "https://api.vrchat.cloud/api/1/";
  647.  
  648. // Token: 0x04000049 RID: 73
  649. public static string API_ORGANIZATION = "vrchat";
  650.  
  651. // Token: 0x0400004A RID: 74
  652. public static ApiOnlineMode API_ONLINE_MODE = ApiOnlineMode.Uninitialized;
  653.  
  654. // Token: 0x0400004B RID: 75
  655. public static string ApiKey;
  656.  
  657. // Token: 0x0400004C RID: 76
  658. public static Dictionary<string, API.EndpointAccessEntry> EndpointAccessTimes = new Dictionary<string, API.EndpointAccessEntry>();
  659.  
  660. // Token: 0x0400004D RID: 77
  661. private static int lastRequestId = -1;
  662.  
  663. // Token: 0x0400004E RID: 78
  664. private static Dictionary<string, HTTPRequest> activeRequests = new Dictionary<string, HTTPRequest>();
  665.  
  666. // Token: 0x0400004F RID: 79
  667. private static List<object> offlineQueries;
  668.  
  669. // Token: 0x02000016 RID: 22
  670. public class EndpointAccessEntry
  671. {
  672. // Token: 0x04000050 RID: 80
  673. public float time;
  674.  
  675. // Token: 0x04000051 RID: 81
  676. public int count;
  677. }
  678. }
  679. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement