public OBFUnityActionInternal(Type type, object instance) { MethodInfo[] addRemoveMethods = type.GetMethods().Where(a => a.GetParameters().Length > 0 && a.GetParameters()[0].ParameterType == typeof(UnityAction <T>)).ToArray(); if (addRemoveMethods.Length < 2) { ExtendedLogger.LogError("Failed to find required UnityActionInternal functions for type: " + type.Name + "!"); return; } if (addRemoveMethods[0].GetMethodBody().GetILAsByteArray().Length > addRemoveMethods[1].GetMethodBody().GetILAsByteArray().Length) { MethodAdd = addRemoveMethods[0]; MethodRemove = addRemoveMethods[1]; } else { MethodAdd = addRemoveMethods[1]; MethodRemove = addRemoveMethods[0]; } MethodExecute = type.GetMethods().First(a => a.GetParameters()[0].ParameterType == typeof(T)); ExtendedLogger.Log("Found Execute method in " + type.Name + " with name: " + MethodExecute.Name + "!"); ExtendedLogger.Log("Found Add method in " + type.Name + " with name: " + MethodAdd.Name + "!"); ExtendedLogger.Log("Found Remove method in " + type.Name + " with name: " + MethodRemove.Name + "!"); Instance = instance; }
public VRCEUiText(string name, Vector2 position, string text, Transform parent = null) { // Get required information Transform orgControl = VRCEUi.InternalUserInfoScreen.UsernameText; if (orgControl == null) { ExtendedLogger.LogError("Could not find Username text!"); Success = false; return; } // Duplicate object GameObject goControl = GameObject.Instantiate(orgControl.gameObject); if (goControl == null) { ExtendedLogger.LogError("Could not duplicate Favorite button!"); Success = false; return; } // Set UI properties Control = goControl.transform; TextControl = Control.GetComponent <Text>().transform; // Remove components that may cause issues GameObject.DestroyImmediate(Control.GetComponent <RectTransform>()); // Set control properties Text = TextControl.GetComponent <Text>(); // Set required parts if (parent != null) { Control.SetParent(parent); } goControl.name = name; // Modify RectTransform Position = Control.GetComponent <RectTransform>(); RectTransform tmpRT = orgControl.GetComponent <RectTransform>(); Position.localScale = tmpRT.localScale; Position.anchoredPosition = tmpRT.anchoredPosition; Position.sizeDelta = tmpRT.sizeDelta; Position.localPosition = new Vector3(position.x, position.y, 0f); Position.localRotation = tmpRT.localRotation; // Change UI properties Text.text = text; // Finish Success = true; }
private static void SetupUserInfo(PageUserInfo __instance) { SelectedAPI = __instance.user; ExtendedUser eUser = ExtendedServer.Users.FirstOrDefault(a => a.UniqueID == SelectedAPI.id); VRCExtended.ToggleUserInfoMore(false); VRCEUi.InternalUserInfoScreen.Moderator.gameObject.SetActive(false); if (APIUser.CurrentUser.id == __instance.user.id) { VRCExtended.UserInfoLastLogin.Text.text = ""; VRCExtended.UserInfoMore.Button.interactable = false; } else { APIUser.FetchUser(__instance.user.id, (APIUser user) => { if (string.IsNullOrEmpty(user.last_login)) { return; } DateTime dt = DateTime.Parse(user.last_login); if (ModPrefs.GetBool("vrcextended", "useDTFormat")) { VRCExtended.UserInfoLastLogin.Text.text = "Last login: "******"MM.dd.yyyy hh:mm tt"); } else { VRCExtended.UserInfoLastLogin.Text.text = "Last login: "******"dd.MM.yyyy hh:mm"); } }, (string error) => { ExtendedLogger.LogError(error); }); VRCExtended.UserInfoMore.Button.interactable = true; if (eUser != null) { VRCExtended.UserInfoColliderControl.Button.interactable = true; VRCExtended.UserInfoColliderControl.Text.text = (eUser.HasColliders ? "Disable colliders" : "Enable colliders"); } else { VRCExtended.UserInfoColliderControl.Button.interactable = false; VRCExtended.UserInfoColliderControl.Text.text = "Not in world!"; } } }
public static void Setup() { // Setup harmony instances HarmonyInstance iSetupUserInfo = HarmonyInstance.Create("vrcextended.pageuserinfo.setupuserinfo"); // Patch try { iSetupUserInfo.Patch(typeof(PageUserInfo).GetMethods(BindingFlags.Public | BindingFlags.Instance).First(a => a.Name == "SetupUserInfo" && a.GetParameters().Length > 1), null, new HarmonyMethod(typeof(Patch_PageUserInfo).GetMethod("SetupUserInfo", BindingFlags.NonPublic | BindingFlags.Static))); ExtendedLogger.Log("Patched PageUserInfo.SetupUserInfo"); } catch (Exception ex) { ExtendedLogger.LogError("Failed to patch PageUserInfo!", ex); return; } }
public static void Setup() { // Setup harmony instances HarmonyInstance iEnter = HarmonyInstance.Create("vrcextended.portalinternal.enter"); // Patch try { iEnter.Patch(typeof(PortalInternal).GetMethod("Enter", BindingFlags.Public | BindingFlags.Instance), new HarmonyMethod(typeof(Patch_PortalInternal).GetMethod("Enter", BindingFlags.Static | BindingFlags.NonPublic))); ExtendedLogger.Log("Patched PortalInternal.Enter"); } catch (Exception ex) { ExtendedLogger.LogError("Failed to patch PortalInternal: " + ex); return; } }
public static Transform DuplicateButton(Transform button, string name, string text, Vector2 offset, Transform parent = null) { // Create new one GameObject goButton = GameObject.Instantiate(button.gameObject); if (goButton == null) { ExtendedLogger.LogError("Could not duplicate button!"); return(null); } // Get UI components Button objButton = goButton.GetComponentInChildren <Button>(); Text objText = goButton.GetComponentInChildren <Text>(); // Destroy broke components GameObject.DestroyImmediate(goButton.GetComponent <RectTransform>()); // Set required parts if (parent != null) { goButton.transform.SetParent(parent); } goButton.name = name; // Modify RectTransform RectTransform rtOriginal = button.GetComponent <RectTransform>(); RectTransform rtNew = goButton.GetComponent <RectTransform>(); rtNew.localScale = rtOriginal.localScale; rtNew.anchoredPosition = rtOriginal.anchoredPosition; rtNew.sizeDelta = rtOriginal.sizeDelta; rtNew.localPosition = rtOriginal.localPosition + new Vector3(offset.x, offset.y, 0f); rtNew.localRotation = rtOriginal.localRotation; // Change UI properties objText.text = text; objButton.onClick = new Button.ButtonClickedEvent(); // Finish return(goButton.transform); }
internal static void Setup() { // Network manager setup _networkManagerType = typeof(PlayerManager).Assembly.GetType("NetworkManager"); if (_networkManagerType == null) { ExtendedLogger.LogError("Failed to get NetworkManager!"); return; } ExtendedLogger.Log("Found NetworkManager!"); _networkManagerInstance = _networkManagerType.GetField("Instance", BindingFlags.Public | BindingFlags.Static); if (_networkManagerInstance == null) { ExtendedLogger.LogError("Failed to get NetworkManager Instance!"); return; } ExtendedLogger.Log("Found NetworkManager Instance!"); FieldInfo onPlayerJoinedEvent = _networkManagerType.GetField("OnPlayerJoinedEvent", BindingFlags.Public | BindingFlags.Instance); if (onPlayerJoinedEvent == null) { ExtendedLogger.LogError("Failed to get NetworkManager OnPlayerJoinedEvent!"); return; } ExtendedLogger.Log("Found NetworkManager OnPlayerJoinedEvent!"); FieldInfo onPlayerLeftEvent = _networkManagerType.GetField("OnPlayerLeftEvent", BindingFlags.Public | BindingFlags.Instance); if (onPlayerLeftEvent == null) { ExtendedLogger.LogError("Failed to get NetworkManager OnPlayerLeftEvent!"); return; } ExtendedLogger.Log("Found NetworkManager OnPlayerLeftEvent!"); Type unityActionInternalType = onPlayerJoinedEvent.FieldType; if (unityActionInternalType == null) { ExtendedLogger.LogError("Failed to get UnityActionInternal!"); return; } ExtendedLogger.Log("Found UnityActionInternal named " + unityActionInternalType.Name + "!"); _networkManager_OnPlayerJoinedEvent = new OBFUnityActionInternal <Player>(unityActionInternalType, onPlayerJoinedEvent.GetValue(_networkManagerInstance.GetValue(null))); _networkManager_OnPlayerLeftEvent = new OBFUnityActionInternal <Player>(unityActionInternalType, onPlayerLeftEvent.GetValue(_networkManagerInstance.GetValue(null))); _networkManager_OnPlayerJoinedEvent.Add(new UnityAction <Player>(delegate(Player player) { if (OnPlayerJoined != null) { OnPlayerJoined(new VRCEPlayer(player)); } })); _networkManager_OnPlayerLeftEvent.Add(new UnityAction <Player>(delegate(Player player) { if (OnPlayerLeft != null) { OnPlayerLeft(new VRCEPlayer(player)); } })); }
public VRCEUiVolumeControl(string name, Vector2 position, string text, float value = 1f, Transform parent = null) { // Get required information Transform orgVolumeMaster = VRCEUi.InternalSettingsScreen.VolumeMaster; if (orgVolumeMaster == null) { ExtendedLogger.LogError("Could not find VolumeMaster!"); Success = false; return; } // Duplicate object GameObject goVolumeControl = GameObject.Instantiate(orgVolumeMaster.gameObject); if (goVolumeControl == null) { ExtendedLogger.LogError("Could not duplicate VolumeMaster!"); Success = false; return; } // Set UI properties VolumeControl = goVolumeControl.transform; FillArea = VolumeControl.Find("FillArea"); SliderLabel = VolumeControl.Find("SliderLabel"); Label = VolumeControl.Find("Label"); // Remove components that may cause issues GameObject.DestroyImmediate(VolumeControl.GetComponent <UiSettingConfig>()); GameObject.DestroyImmediate(VolumeControl.GetComponent <RectTransform>()); // Set control properties Text = Label.GetComponent <Text>(); Slider = VolumeControl.GetComponent <Slider>(); // Set required parts if (parent != null) { VolumeControl.SetParent(parent); } goVolumeControl.name = name; // Modify RectTransform Position = VolumeControl.GetComponent <RectTransform>(); RectTransform tmpRT = orgVolumeMaster.GetComponent <RectTransform>(); Position.localScale = tmpRT.localScale; Position.anchoredPosition = tmpRT.anchoredPosition; Position.sizeDelta = tmpRT.sizeDelta; Position.localPosition = new Vector3(position.x, position.y, 0f); Position.localRotation = tmpRT.localRotation; Label.GetComponent <RectTransform>().localPosition = Label.GetComponent <RectTransform>().localPosition + new Vector3(50f, 0f, 0f); // Change UI properties Text.text = text; Slider.value = value; // Finish Success = true; }