private static void WhitelistUser(APIUser user) { if (user == null) { return; } if (UserPermissionHandler.IsWhitelisted(user.id)) { UserPermissionHandler.RemoveFromWhitelist(user.id); MelonLogger.Msg($"{user.displayName} removed from whitelist"); Utilities.QueueHudMessage($"{user.displayName} removed from whitelist"); } else { if (UserPermissionHandler.IsBlacklisted(user.id)) { UserPermissionHandler.RemoveFromBlacklist(user.id); } UserPermissionHandler.AddToWhitelist(user); MelonLogger.Msg($"{user.displayName} added to whitelist"); Utilities.QueueHudMessage($"{user.displayName} added to whitelist"); } UserPermissionHandler.SaveSettings(); }
private static void ShowUsers() { ICustomShowableLayoutedMenu userPermissionsPopup = ExpansionKitApi.CreateCustomFullMenuPopup(LayoutDescription.WideSlimList); if (UserPermissionHandler.BlacklistedUsers.Count > 0) { userPermissionsPopup.AddLabel("Blacklisted Users"); foreach (UserPermissionHandler.PermissionEntry blacklistedUser in UserPermissionHandler.BlacklistedUsers) { userPermissionsPopup.AddSimpleButton( blacklistedUser.DisplayName, () => { userPermissionsPopup.Hide(); UserPermissionHandler.RemoveFromBlacklist(blacklistedUser.UserId); UserPermissionHandler.SaveSettings(); ShowUsers(); }); } userPermissionsPopup.AddSpacer(); } if (UserPermissionHandler.WhitelistedUsers.Count > 0) { userPermissionsPopup.AddLabel("Whitelisted Users"); foreach (UserPermissionHandler.PermissionEntry whitelistedUser in UserPermissionHandler.WhitelistedUsers) { userPermissionsPopup.AddSimpleButton( whitelistedUser.DisplayName, () => { userPermissionsPopup.Hide(); UserPermissionHandler.RemoveFromWhitelist(whitelistedUser.UserId); UserPermissionHandler.SaveSettings(); ShowUsers(); }); } userPermissionsPopup.AddSpacer(); } userPermissionsPopup.AddSimpleButton("Close", () => userPermissionsPopup.Hide()); userPermissionsPopup.Show(); }
public override void OnApplicationStart() { Utilities.LoggerInstance = LoggerInstance; advInvPreferencesCategory = MelonPreferences.CreateCategory("AdvancedInvites", "Advanced Invites"); advInvPreferencesCategory.CreateEntry("DeleteNotifications", InviteHandler.DeleteNotifications, "Delete Notification After Successful Use"); advInvPreferencesCategory.CreateEntry("BlacklistEnabled", blacklistEnabled, "Blacklist System"); advInvPreferencesCategory.CreateEntry("WhitelistEnabled", whitelistEnabled, "Whitelist System"); advInvPreferencesCategory.CreateEntry("NotificationVolume", .8f, "Notification Volume"); advInvPreferencesCategory.CreateEntry("JoinMeNotifyRequest", joinMeNotifyRequest, "Join Me Req Notification Sound"); advInvPreferencesCategory.CreateEntry("IgnoreBusyStatus", ignoreBusyStatus, "Ignore Busy Status"); advInvPreferencesCategory.CreateEntry("InviteSoundEnabled", true, "Invite Sound"); advInvPreferencesCategory.CreateEntry("InviteRequestSoundEnabled", true, "Invite-Request Sound"); advInvPreferencesCategory.CreateEntry("VoteToKickSoundEnabled", false, "Vote-Kick Sound", true); advInvPreferencesCategory.CreateEntry("FriendRequestSoundEnabled", false, "Friend-Request Sound", true); OnPreferencesLoaded(); Localization.Load(); #if DEBUG DebugTesting.Test(); try { MethodInfo sendNotificationMethod = typeof(NotificationManager).GetMethod( nameof(NotificationManager.Method_Public_Void_String_String_String_String_NotificationDetails_ArrayOf_Byte_0), BindingFlags.Public | BindingFlags.Instance); HarmonyInstance.Patch( sendNotificationMethod, new HarmonyMethod(typeof(AdvancedInviteSystem).GetMethod(nameof(SendNotificationPatch), BindingFlags.NonPublic | BindingFlags.Static))); } catch (Exception e) { Utilities.LoggerInstance.Error("Error Patching SendNotification: " + e.Message); } #endif try { // Appears to be NotificationManager.Method_Private_Void_Notification_1 MethodInfo acceptNotificationMethod = typeof(NotificationManager).GetMethods(BindingFlags.Public | BindingFlags.Instance).Single( m => m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(Notification) && m.Name.IndexOf("PDM", StringComparison.OrdinalIgnoreCase) == -1 && m.XRefScanFor("AcceptNotification for notification:") && m.XRefScanFor("Could not accept notification because notification details is null")); acceptNotificationDelegate = Patch <AcceptNotificationDelegate>(acceptNotificationMethod, GetDetour(nameof(AcceptNotificationPatch))); } catch (Exception e) { Utilities.LoggerInstance.Error("Error Patching AcceptNotification: " + e.Message); } try { //Appears to be NotificationManager.Method_Private_String_Notification_1 MethodInfo addNotificationMethod = typeof(NotificationManager.ObjectNPrivateSealedNoVoBonoNo0).GetMethods(BindingFlags.Public | BindingFlags.Instance).Single( m => m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(Notification) && m.Name.IndexOf("addNotification", StringComparison.OrdinalIgnoreCase) >= 0); addNotificationDelegate = Patch <AddNotificationDelegate>(addNotificationMethod, GetDetour(nameof(AddNotificationPatch))); } catch (Exception e) { Utilities.LoggerInstance.Error("Error Patching AddNotification: " + e.Message); } try { // Faded to and joined and initialized room MethodInfo fadeMethod = typeof(VRCUiManager).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).First( m => m.Name.StartsWith("Method_Public_Void_String_Single_Action_") && m.Name.IndexOf("PDM", StringComparison.OrdinalIgnoreCase) == -1 && m.GetParameters().Length == 3); origFadeTo = Patch <FadeTo>(fadeMethod, GetDetour(nameof(FadeToPatch))); } catch (Exception e) { Utilities.LoggerInstance.Error("Error Patching FadeTo: " + e.Message); } UserPermissionHandler.LoadSettings(); WorldPermissionHandler.LoadSettings(); UiButtons.Initialize(); SoundPlayer.Initialize(); }
private static void HandleNotification(ref Notification notification) { if (Utilities.GetStreamerMode()) { return; } // Original code doesn't handle much outside worlds so if (Utilities.CurrentRoom() == null || Utilities.CurrentWorldInstance() == null) { return; } if (notification.notificationType != null) { switch (notification.notificationType.ToLowerInvariant()) { case "invite": #if DEBUG if (notification.details?.keys != null) { foreach (string key in notification.details?.keys) { Utilities.LoggerInstance.Msg("Invite Details Key: " + key); if (notification.details != null) { Utilities.LoggerInstance.Msg("Invite Details Value: " + notification.details[key].ToString()); } } } #endif if (APIUser.CurrentUser.statusIsSetToDoNotDisturb && !ignoreBusyStatus) { return; } string worldId = notification.details?["worldId"].ToString().Split(':')[0]; if (blacklistEnabled && (UserPermissionHandler.IsBlacklisted(notification.senderUserId) || WorldPermissionHandler.IsBlacklisted(worldId))) { Utilities.DeleteNotification(notification); return; } if (inviteSoundEnabled) { SoundPlayer.PlayNotificationSound(SoundPlayer.NotificationType.Invite); } break; case "requestinvite": if (blacklistEnabled && UserPermissionHandler.IsBlacklisted(notification.senderUserId)) { Utilities.DeleteNotification(notification); return; } if (APIUser.CurrentUser.statusIsSetToDoNotDisturb && !ignoreBusyStatus) { return; } if (whitelistEnabled && UserPermissionHandler.IsWhitelisted(notification.senderUserId)) { if (!Utilities.AllowedToInvite()) { if (inviteRequestSoundEnabled) { SoundPlayer.PlayNotificationSound(SoundPlayer.NotificationType.InviteRequest); } return; } if (notification.details?.ContainsKey("platform") == true && !Utilities.IsPlatformCompatibleWithCurrentWorld(notification.details["platform"].ToString())) { if (!APIUser.CurrentUser.statusIsSetToJoinMe) { // Bool's doesn't work and closes the game. just let it through //Utilities.SendIncompatiblePlatformNotification(__0.senderUserId); //Utilities.DeleteNotification(__0); if (inviteRequestSoundEnabled) { SoundPlayer.PlayNotificationSound(SoundPlayer.NotificationType.InviteRequest); } } return; } // Double Sending if (!APIUser.CurrentUser.statusIsSetToJoinMe) { Utilities.AcceptInviteRequest(notification.senderUserId, notification.senderUsername); Utilities.DeleteNotification(notification); } if (APIUser.CurrentUser.statusIsSetToJoinMe && joinMeNotifyRequest) { if (inviteRequestSoundEnabled) { SoundPlayer.PlayNotificationSound(SoundPlayer.NotificationType.InviteRequest); } } } else { if (Utilities.AllowedToInvite()) { if (APIUser.CurrentUser.statusIsSetToJoinMe && !joinMeNotifyRequest) { return; } } if (inviteRequestSoundEnabled) { SoundPlayer.PlayNotificationSound(SoundPlayer.NotificationType.InviteRequest); } } return; // ReSharper disable StringLiteralTypo case "votetokick": if (voteToKickSoundEnabled) { SoundPlayer.PlayNotificationSound(SoundPlayer.NotificationType.VoteToKick); } break; case "friendrequest": if (friendRequestSoundEnabled) { SoundPlayer.PlayNotificationSound(SoundPlayer.NotificationType.FriendRequest); } break; default: return; } } }
public override void OnApplicationStart() { advInvPreferencesCategory = MelonPreferences.CreateCategory("AdvancedInvites", "Advanced Invites"); advInvPreferencesCategory.CreateEntry("DeleteNotifications", InviteHandler.DeleteNotifications, "Delete Notification After Successful Use"); advInvPreferencesCategory.CreateEntry("BlacklistEnabled", blacklistEnabled, "Blacklist System"); advInvPreferencesCategory.CreateEntry("WhitelistEnabled", whitelistEnabled, "Whitelist System"); advInvPreferencesCategory.CreateEntry("NotificationVolume", .8f, "Notification Volume"); advInvPreferencesCategory.CreateEntry("JoinMeNotifyRequest", joinMeNotifyRequest, "Join Me Req Notification Sound"); advInvPreferencesCategory.CreateEntry("IgnoreBusyStatus", ignoreBusyStatus, "Ignore Busy Status"); advInvPreferencesCategory.CreateEntry("InviteSoundEnabled", true, "Invite Sound"); advInvPreferencesCategory.CreateEntry("InviteRequestSoundEnabled", true, "Invite-Request Sound"); advInvPreferencesCategory.CreateEntry("VoteToKickSoundEnabled", false, "Vote-Kick Sound", true); advInvPreferencesCategory.CreateEntry("FriendRequestSoundEnabled", false, "Friend-Request Sound", true); OnPreferencesLoaded(); Localization.Load(); #if DEBUG DebugTesting.Test(); try { MethodInfo sendNotificationMethod = typeof(NotificationManager).GetMethod( nameof(NotificationManager.Method_Public_Void_String_String_String_String_NotificationDetails_ArrayOf_Byte_0), BindingFlags.Public | BindingFlags.Instance); Harmony.Patch(sendNotificationMethod, new HarmonyMethod( typeof(AdvancedInviteSystem).GetMethod(nameof(SendNotificationPatch), BindingFlags.NonPublic | BindingFlags.Static))); } catch (Exception e) { MelonLogger.Error("Error Patching SendNotification: " + e.Message); } #endif try { unsafe { // Appears to be NotificationManager.Method_Private_Void_Notification_1 MethodInfo acceptNotificationMethod = typeof(NotificationManager).GetMethods(BindingFlags.Public | BindingFlags.Instance).Single( m => m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(Notification) && m.XRefScanFor("AcceptNotification for notification:")); IntPtr originalMethod = *(IntPtr *)(IntPtr)UnhollowerUtils .GetIl2CppMethodInfoPointerFieldForGeneratedMethod(acceptNotificationMethod).GetValue(null); MelonUtils.NativeHookAttach( (IntPtr)(&originalMethod), typeof(AdvancedInviteSystem).GetMethod(nameof(AcceptNotificationPatch), BindingFlags.Static | BindingFlags.NonPublic) !.MethodHandle .GetFunctionPointer()); acceptNotificationDelegate = Marshal.GetDelegateForFunctionPointer <AcceptNotificationDelegate>(originalMethod); } } catch (Exception e) { MelonLogger.Error("Error Patching AcceptNotification: " + e.Message); } try { //Appears to be NotificationManager.Method_Private_String_Notification_1 MethodInfo addNotificationMethod = typeof(NotificationManager).GetMethods(BindingFlags.Public | BindingFlags.Instance).Single( m => m.Name.StartsWith("Method_Private_") && m.ReturnType == typeof(string) && m.GetParameters().Length == 1 && m.GetParameters()[0].ParameterType == typeof(Notification) && m.XRefScanFor("imageUrl")); Harmony.Patch( addNotificationMethod, postfix: new HarmonyMethod( typeof(AdvancedInviteSystem).GetMethod(nameof(AddNotificationPatch), BindingFlags.NonPublic | BindingFlags.Static))); } catch (Exception e) { MelonLogger.Error("Error Patching AddNotification: " + e.Message); } UserPermissionHandler.LoadSettings(); WorldPermissionHandler.LoadSettings(); MelonCoroutines.Start(WaitForVrChatUiManager()); }