private static IEnumerator AddAvatarToList(string avatarId, string avatarName) { bool found = false; foreach (string avatarfavId in AvatarFavMod.favoriteAvatarList) { if (avatarfavId == avatarId) { found = true; VRCModLogger.LogError("[VRCheatAvatarfileImporter] Avatar " + avatarName + " already exist in list"); break; } } if (!found) { using (WWW avtrRequest = new WWW(API.GetApiUrl() + "avatars/" + avatarId + "?apiKey=" + AvatarFavMod.GetApiKey())) { yield return(avtrRequest); int rc = WebRequestsUtils.GetResponseCode(avtrRequest); if (rc == 200) { string uuid = APIUser.CurrentUser?.id ?? ""; SerializableApiAvatar aa = null; try { aa = JsonConvert.DeserializeObject <SerializableApiAvatar>(avtrRequest.text); } catch (Exception e) { VRCModLogger.LogError("[VRCheatAvatarfileImporter] Unable to add the avatar " + avatarName + ": Unable to parse the API response. " + e); } if (aa != null) { if (aa.authorId != uuid) { if (aa.releaseStatus == "public") { VRCModLogger.Log("[VRCheatAvatarfileImporter] Adding avatar " + avatarName + " to the database"); yield return(AddAvatar(avatarId, avatarName)); } else { VRCModLogger.Log("[VRCheatAvatarfileImporter] Unable to add the avatar " + avatarName + ": This avatar is not public anymore (private)"); } } else { VRCModLogger.Log("[VRCheatAvatarfileImporter] Unable to add the avatar " + avatarName + ": This avatar is own avatar"); } } } else { VRCModLogger.Log("[VRCheatAvatarfileImporter] Unable to add the avatar " + avatarName + ": This avatar is not public anymore (deleted)"); } } } }
private IEnumerator CheckAndWearAvatar() { //DebugUtils.PrintHierarchy(pageAvatar.avatar.transform, 0); PipelineManager avatarPipelineManager = pageAvatar.avatar.GetComponentInChildren <PipelineManager>(); if (avatarPipelineManager == null) // Avoid avatars locking for builds <625 { VRCModLogger.Log("[AvatarFav] Current avatar prefab name: " + pageAvatar.avatar.transform.GetChild(0).name); if (pageAvatar.avatar.transform.GetChild(0).name == "avatar_loading2(Clone)") { VRCUiPopupManagerUtils.ShowPopup("Error", "Please wait for this avatar to finish loading before wearing it", "Close", () => VRCUiPopupManagerUtils.GetVRCUiPopupManager().HideCurrentPopup()); } else { baseChooseEvent.Invoke(); } } else { bool copied = false; string avatarBlueprintID = avatarPipelineManager?.blueprintId ?? ""; if (!avatarBlueprintID.Equals("") && !avatarBlueprintID.Equals(pageAvatar.avatar.apiAvatar.id)) { copied = true; } using (WWW avtrRequest = new WWW(API.GetApiUrl() + "avatars/" + (copied ? avatarBlueprintID : pageAvatar.avatar.apiAvatar.id) + "?apiKey=" + GetApiKey())) { yield return(avtrRequest); int rc = WebRequestsUtils.GetResponseCode(avtrRequest); if (rc == 200) { try { string uuid = APIUser.CurrentUser?.id ?? ""; SerializableApiAvatar aa = JsonConvert.DeserializeObject <SerializableApiAvatar>(avtrRequest.text); if (aa.releaseStatus.Equals("public") || aa.authorId.Equals(uuid)) { baseChooseEvent.Invoke(); } else { if (copied) { VRCUiPopupManagerUtils.ShowPopup("Error", "Unable to put this avatar: This avatar is not the original one, and the one is not public anymore (private)", "Close", () => VRCUiPopupManagerUtils.GetVRCUiPopupManager().HideCurrentPopup()); } else { VRCUiPopupManagerUtils.ShowPopup("Error", "Unable to put this avatar: This avatar is not public anymore (private)", "Close", () => VRCUiPopupManagerUtils.GetVRCUiPopupManager().HideCurrentPopup()); } } } catch (Exception e) { VRCModLogger.LogError(e.ToString()); VRCUiPopupManagerUtils.ShowPopup("Error", "Unable to put this avatar: Unable to parse API response", "Close", () => VRCUiPopupManagerUtils.GetVRCUiPopupManager().HideCurrentPopup()); } } else { if (copied) { VRCUiPopupManagerUtils.ShowPopup("Error", "Unable to put this avatar: This avatar is not the original one, and the one is not public anymore (deleted)", "Close", () => VRCUiPopupManagerUtils.GetVRCUiPopupManager().HideCurrentPopup()); } else { VRCUiPopupManagerUtils.ShowPopup("Error", "Unable to put this avatar: This avatar is not public anymore (deleted)", "Close", () => VRCUiPopupManagerUtils.GetVRCUiPopupManager().HideCurrentPopup()); } } } } }