-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatches.cs
More file actions
80 lines (62 loc) · 2.44 KB
/
Patches.cs
File metadata and controls
80 lines (62 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections;
using System.Collections.Generic;
using HarmonyLib;
using Il2CppRUMBLE.MeshGeneration;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using MelonLoader;
using UnityEngine;
namespace CustomAvatars;
public class Patches
{
public static Queue<Player> downloadQueue = new();
public static HashSet<string> activeDownloads = new();
private static int MAX_CONCURRENT => Main.instance.MaxConcurrentDownloads.Value;
[HarmonyPatch(typeof(PlayerVisuals), nameof(PlayerVisuals.ApplyPlayerVisuals))]
public static class Patch_PlayerVisuals_ApplyPlayerVisuals
{
static void Postfix(PlayerVisuals __instance, PlayerCharacterBaker.GeneratedPlayerVisuals generatedVisuals)
{
var player = __instance.parentController.assignedPlayer;
if (player == null) return;
string id = player.Data.GeneralData.PlayFabMasterId;
if (activeDownloads.Contains(id))
return;
Main.DebugLog($"Enqueue {id} for download.");
downloadQueue.Enqueue(player);
ProcessQueue();
}
}
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.DeActivate))]
public static class Patch_PlayerController_DeActivate
{
static void Prefix(PlayerController __instance)
{
var customRig = __instance.GetComponent<CustomRig>();
if (customRig != null)
Object.Destroy(customRig);
}
}
public static void ProcessQueue()
{
Main.DebugLog($"ProcessQueue | active: {activeDownloads.Count}/{MAX_CONCURRENT}, queued: {downloadQueue.Count}");
while (activeDownloads.Count < MAX_CONCURRENT && downloadQueue.Count > 0)
{
var player = downloadQueue.Dequeue();
string id = player.Data.GeneralData.PlayFabMasterId;
Main.DebugLog($"Dequeue {id}");
if (!activeDownloads.Add(id))
continue;
MelonCoroutines.Start(HandleAvatarForRemotePlayer(player, id));
}
}
private static IEnumerator HandleAvatarForRemotePlayer(Player player, string id)
{
yield return RigManager.LoadAndApplyAvatarForPlayer(player, onDone: success =>
{
Main.DebugLog($"Done {id} | success: {success}");
activeDownloads.Remove(id);
ProcessQueue();
});
}
}