11
11
import java .util .Collection ;
12
12
import java .util .Iterator ;
13
13
import java .util .LinkedHashMap ;
14
+ import java .util .LinkedHashSet ;
14
15
import java .util .Map ;
15
16
import java .util .Set ;
16
17
import java .util .Spliterator ;
19
20
import de .robv .android .xposed .XC_MethodReplacement ;
20
21
import de .robv .android .xposed .XSharedPreferences ;
21
22
import de .robv .android .xposed .XposedBridge ;
23
+ import de .robv .android .xposed .XposedHelpers ;
24
+ import lombok .Setter ;
22
25
23
26
public class PinnedLimit extends Feature {
24
27
@@ -33,11 +36,23 @@ public void doHook() throws Throwable {
33
36
var pinnedSetMethod = Unobfuscator .loadPinnedHashSetMethod (classLoader );
34
37
var pinnedInChatMethod = Unobfuscator .loadPinnedInChatMethod (classLoader );
35
38
39
+
36
40
// increase pinned limit in chat to 60
37
41
XposedBridge .hookMethod (pinnedInChatMethod , XC_MethodReplacement .returnConstant (60 ));
38
42
43
+ // Fix bug in initialCapacity of LinkedHashSet
44
+ XposedHelpers .findAndHookConstructor (LinkedHashSet .class , int .class , new XC_MethodHook () {
45
+ @ Override
46
+ protected void beforeHookedMethod (MethodHookParam param ) throws Throwable {
47
+ if ((int ) param .args [0 ] < 0 ) {
48
+ param .args [0 ] = Math .abs ((int ) param .args [0 ]);
49
+ }
50
+ }
51
+ });
52
+
39
53
// This creates a modified linkedhashMap to return 0 if the fixed list is less than 60.
40
54
XposedBridge .hookMethod (pinnedSetMethod , new XC_MethodHook () {
55
+
41
56
@ Override
42
57
@ SuppressWarnings ("unchecked" )
43
58
protected void afterHookedMethod (MethodHookParam param ) throws Throwable {
@@ -63,14 +78,15 @@ public String getPluginName() {
63
78
}
64
79
65
80
81
+ @ Setter
66
82
private static class PinnedLinkedHashMap <T > extends LinkedHashMap <T , T > {
67
83
68
84
@ Override
69
85
public int size () {
70
86
if (super .size () >= limit ) {
71
- return 3 ;
87
+ return super . size () ;
72
88
}
73
- return -60 ;
89
+ return -this . limit ;
74
90
}
75
91
76
92
private int limit ;
@@ -81,16 +97,12 @@ public Set<T> keySet() {
81
97
return new PinnedKeySet <>(this , super .keySet ());
82
98
}
83
99
84
- public void setLimit (int i ) {
85
- this .limit = i ;
86
- }
87
-
88
100
static class PinnedKeySet <T > implements Set <T > {
89
101
90
- private final Set set ;
91
- private final PinnedLinkedHashMap pinnedKeySet ;
102
+ private final Set < T > set ;
103
+ private final PinnedLinkedHashMap < T > pinnedKeySet ;
92
104
93
- public PinnedKeySet (PinnedLinkedHashMap <T > pinnedKeySet , Set set ) {
105
+ public PinnedKeySet (PinnedLinkedHashMap <T > pinnedKeySet , Set < T > set ) {
94
106
this .pinnedKeySet = pinnedKeySet ;
95
107
this .set = set ;
96
108
}
@@ -125,11 +137,11 @@ public Object[] toArray() {
125
137
@ NonNull
126
138
@ Override
127
139
public <T1 > T1 [] toArray (@ NonNull T1 [] a ) {
128
- return ( T1 []) set .toArray (a );
140
+ return set .toArray (a );
129
141
}
130
142
131
143
@ Override
132
- public boolean add (Object t ) {
144
+ public boolean add (@ Nullable T t ) {
133
145
return set .add (t );
134
146
}
135
147
0 commit comments