-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIRfresh_Patch.cs
159 lines (115 loc) · 5 KB
/
UIRfresh_Patch.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using Assets.Scripts.Database;
using Assets.Scripts.PeroTools.Commons;
using Assets.Scripts.UI.Controls;
using Assets.Scripts.UI.Panels;
using CharacterScoreboard;
using HarmonyLib;
using Il2CppNewtonsoft.Json.Linq;
using System.Collections.Generic;
[HarmonyPatch(typeof(PnlRank), "UIRefresh")]
internal static class UIRefresh_Patch
{
public static string lastUIUpdatedUID;
public static Dictionary<string, RankCell[][]> scorebaordData = new Dictionary<string, RankCell[][]>();
public static Dictionary<string, bool> tainted = new Dictionary<string, bool>();
[HarmonyPostfix, HarmonyPriority(Priority.Last)]
private static void Postfix(PnlRank __instance, string uid)
{
fixToggle();
lastUIUpdatedUID = uid;
if (PrefferenceManager.LCSEnabled)
upDatedScoreboardLCS(__instance, uid);
else if (PrefferenceManager.OCSEnabled)
upDatedScoreboardOCS(__instance, uid);
}
private static void upDatedScoreboardLCS(PnlRank __instance, string uid)
{
RankCell[] cells = __instance.scrollView.GetComponentsInChildren<RankCell>();
JObject runs = Registry.getStage(uid.Split('_')[0], int.Parse(uid.Split('_')[1]));
Il2CppSystem.Collections.Generic.List<string> keysT = JsonUtils.Keys(runs);
Il2CppSystem.Collections.Generic.List<string> keys = new Il2CppSystem.Collections.Generic.List<string>();
foreach (string key in keysT)
{
int i = 0;
for (i = 0; i < keys.Count; i++)
{
if ((float)runs[key]["score"] > (float)runs[keysT[i]]["score"])
break;
}
keys.Insert(i, key);
}
for (int index = 0; index < cells.Length; index++)
{
if (index > keys.Count - 1)
{
cells[index].txtNumber.text = " ";
cells[index].txtAcc.text = " ";
cells[index].txtPlayerName.text = " ";
cells[index].txtScore.text = " ";
continue;
}
string key = keys[index];
JObject run = runs[key].Cast<JObject>();
string name = DBUtils.getCharacterElfinNameByIds(key);
float acc;
if (!float.TryParse(run["acc"].ToString(), out acc))
continue;
int score;
if (!int.TryParse(run["score"].ToString(), out score))
continue;
cells[index].SetValue(index + 1, name, score, acc / 100);
}
__instance.txtServerName.text = DBUtils.getCharacterElfinNameByIds(DataHelper.selectedRoleIndex + "&" + DataHelper.selectedElfinIndex);
}
private static void upDatedScoreboardOCS(PnlRank __instance, string uid)
{
if (__instance.m_Ranks.entries.Count > 0 && __instance.m_Ranks.ContainsKey(uid))
{
JArray ranks = __instance.m_Ranks[uid].Cast<JArray>();
RankCell[] cells = __instance.scrollView.GetComponentsInChildren<RankCell>();
int smallerCount = ranks.Count > cells.Length ? cells.Length : ranks.Count;
if (ranks.Count > 0 && cells.Length > 0)
for (int index = 0; index < (smallerCount > 100 ? 100 : smallerCount); index++)
{
JObject data = ranks[index].Cast<JObject>();
string newNick = DBUtils.getCharacterElfinNameByIds(data["play"]["character_uid"].ToString() + "&" + data["play"]["elfin_uid"].ToString());
float acc;
if (!float.TryParse(data["play"]["acc"].ToString(), out acc))
continue;
int score;
if (!int.TryParse(data["play"]["score"].ToString(), out score))
continue;
cells[index].SetValue(index + 1, newNick, score, acc / 100);
}
}
__instance.txtServerName.text = DBUtils.getCharacterElfinNameByIds(DataHelper.selectedRoleIndex + "&" + DataHelper.selectedElfinIndex);
}
public static void fixToggle()
{
if(ToggleManager.OCSToggle)
{
UnityEngine.UI.Text component = ToggleManager.OCSToggle.transform.Find("Txt").GetComponent<UnityEngine.UI.Text>();
component.text = "OCS".ToUpper();
}
if (ToggleManager.LCSToggle)
{
UnityEngine.UI.Text component = ToggleManager.LCSToggle.transform.Find("Txt").GetComponent<UnityEngine.UI.Text>();
component.text = "LCS".ToUpper();
}
}
/*
public static Dictionary<string, string> refreshedAfterChange = new Dictionary<string, string>();
[HarmonyPrefix]
private static bool Prefix(string uid)
{
if (refreshedAfterChange.ContainsKey(uid) || uid == null || !PrefferenceManager.LCSEnabled) return true;
if (ToggleManager.rank != null)
{
refreshedAfterChange.Add(uid, "yes");
ToggleManager.rank.RefreshGeneral(uid);
return false;
}
return true;
}
*/
}