Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Fix for 1095 - AH
Browse files Browse the repository at this point in the history
  • Loading branch information
loukylor committed May 18, 2021
1 parent aeae85b commit 77780e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
47 changes: 32 additions & 15 deletions AvatarHider/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static void OnAvatarChanged(VRCAvatarManager manager, GameObject gameObj
{
if (manager.field_Private_VRCPlayer_0 == null) return;

int photonId = manager.field_Private_VRCPlayer_0.field_Private_PhotonView_0.field_Private_Int32_0;
int photonId = manager.field_Private_VRCPlayer_0.prop_PlayerNet_0.prop_PhotonView_0.field_Private_Int32_0;

if (!players.ContainsKey(photonId)) return;

Expand All @@ -42,15 +42,16 @@ private static void OnAvatarChanged(VRCAvatarManager manager, GameObject gameObj
RefreshManager.RefreshPlayer(players[photonId], Player.prop_Player_0.transform.position);
else
if (Config.IncludeHiddenAvatars.Value && players[photonId].isHidden)
players[photonId].SetInActive();
players[photonId].SetInActive();

}

private static void OnPlayerJoin(Player player)
{
if (player == null || player.prop_APIUser_0.id == APIUser.CurrentUser.id) return;

int photonId = player.prop_VRCPlayer_0.field_Private_PhotonView_0.field_Private_Int32_0;

int photonId = player.prop_VRCPlayer_0.prop_PlayerNet_0.prop_PhotonView_0.field_Private_Int32_0;
if (players.ContainsKey(photonId)) return;

AvatarHiderPlayer playerProp = new AvatarHiderPlayer()
Expand All @@ -71,10 +72,11 @@ private static void OnPlayerJoin(Player player)
}
private static void OnPlayerLeave(Player player)
{
int photonId = player.prop_VRCPlayer_0.field_Private_PhotonView_0.field_Private_Int32_0;

players.Remove(photonId);
filteredPlayers.Remove(photonId);
if (TryGetPlayerFromId(player.prop_APIUser_0.id, out AvatarHiderPlayer avatarHiderPlayer))
{
players.Remove(avatarHiderPlayer.photonId);
filteredPlayers.Remove(avatarHiderPlayer.photonId);
}
}

private static void OnFriend(APIUser apiUser)
Expand Down Expand Up @@ -178,15 +180,30 @@ public static List<AvatarHiderPlayer> RefreshFilteredList()
return removedPlayers;
}

public static void HideOrShowAvatar(AvatarHiderPlayer playerProp)
public static void HideOrShowAvatar(AvatarHiderPlayer avatarHiderPlayer)
{
if (playerProp.userId == APIUser.CurrentUser.id)
if (avatarHiderPlayer.userId == APIUser.CurrentUser.id)
return;
if (Config.IncludeHiddenAvatars.Value && playerProp.isHidden)
playerProp.SetInActive();
else if ((Config.IgnoreFriends.Value && playerProp.isFriend) ||
(Config.ExcludeShownAvatars.Value && playerProp.isShown))
playerProp.SetActive();
if (Config.IncludeHiddenAvatars.Value && avatarHiderPlayer.isHidden)
avatarHiderPlayer.SetInActive();
else if ((Config.IgnoreFriends.Value && avatarHiderPlayer.isFriend) ||
(Config.ExcludeShownAvatars.Value && avatarHiderPlayer.isShown))
avatarHiderPlayer.SetActive();
}

public static bool TryGetPlayerFromId(string userId, out AvatarHiderPlayer avatarHiderPlayer)
{
foreach (AvatarHiderPlayer loopedAvatarHiderPlayer in players.Values)
{
if (loopedAvatarHiderPlayer.userId == userId)
{
avatarHiderPlayer = loopedAvatarHiderPlayer;
return true;
}
}

avatarHiderPlayer = null;
return false;
}
}
}
2 changes: 1 addition & 1 deletion AvatarHider/Utilities/NetworkEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void NetworkInit()

AvatarHiderMod.Instance.Harmony.Patch(typeof(APIUser).GetMethod("LocalAddFriend"), null, new HarmonyMethod(typeof(NetworkEvents).GetMethod(nameof(OnFriend), BindingFlags.NonPublic | BindingFlags.Static)));
AvatarHiderMod.Instance.Harmony.Patch(typeof(APIUser).GetMethod("UnfriendUser"), null, new HarmonyMethod(typeof(NetworkEvents).GetMethod(nameof(OnUnfriend), BindingFlags.NonPublic | BindingFlags.Static)));
AvatarHiderMod.Instance.Harmony.Patch(typeof(VRCAvatarManager).GetMethod($"Method_Private_Boolean_GameObject_String_Single_String_PDM_0"), null, new HarmonyMethod(typeof(NetworkEvents).GetMethod(nameof(OnAvatarChange), BindingFlags.NonPublic | BindingFlags.Static)));
AvatarHiderMod.Instance.Harmony.Patch(typeof(VRCAvatarManager).GetMethod("Method_Private_Boolean_GameObject_String_Single_String_PDM_0"), null, new HarmonyMethod(typeof(NetworkEvents).GetMethod(nameof(OnAvatarChange), BindingFlags.NonPublic | BindingFlags.Static)));
AvatarHiderMod.Instance.Harmony.Patch(typeof(ModerationManager).GetMethod("Method_Private_Void_String_ModerationType_Action_1_ApiPlayerModeration_Action_1_String_0"), new HarmonyMethod(typeof(NetworkEvents).GetMethod(nameof(OnPlayerModerationSend), BindingFlags.NonPublic | BindingFlags.Static)));
AvatarHiderMod.Instance.Harmony.Patch(typeof(ModerationManager).GetMethod("Method_Private_Void_String_ModerationType_0"), new HarmonyMethod(typeof(NetworkEvents).GetMethod(nameof(OnPlayerModerationRemove), BindingFlags.NonPublic | BindingFlags.Static)));

Expand Down

0 comments on commit 77780e4

Please sign in to comment.