15
15
import com .aliucord .patcher .PreHook ;
16
16
import com .aliucord .Utils ;
17
17
import com .aliucord .utils .GsonUtils ;
18
- import com .aliucord .utils .ReflectUtils ;
19
18
import com .discord .api .channel .Channel ;
20
19
import com .discord .models .commands .Application ;
21
20
import com .discord .models .commands .ApplicationCommand ;
@@ -51,6 +50,13 @@ final class Patches {
51
50
private Method handleDiscoverCommandsUpdateMethod ;
52
51
private Method handleQueryCommandsUpdateMethod ;
53
52
private Field applicationCommandCountField ;
53
+ private Field storeApplicationCommandsQueryField ;
54
+ private Field errorResponseErrorField ;
55
+ private Field skemaErrorSubErrorsField ;
56
+ private Field skemaErrorErrorsField ;
57
+ private Field skemaErrorItemCodeField ;
58
+ private Field skemaErrorItemMessageField ;
59
+ private Field storeApplicationCommandsBuiltInCommandsProviderField ;
54
60
55
61
Patches (Logger logger ) throws Throwable {
56
62
this .logger = logger ;
@@ -67,6 +73,20 @@ public void loadPatches(Context context) throws Throwable {
67
73
this .handleQueryCommandsUpdateMethod .setAccessible (true );
68
74
this .applicationCommandCountField = Application .class .getDeclaredField ("commandCount" );
69
75
this .applicationCommandCountField .setAccessible (true );
76
+ this .storeApplicationCommandsQueryField = StoreApplicationCommands .class .getDeclaredField ("query" );
77
+ this .storeApplicationCommandsQueryField .setAccessible (true );
78
+ this .errorResponseErrorField = Error .Response .class .getDeclaredField ("skemaError" );
79
+ this .errorResponseErrorField .setAccessible (true );
80
+ this .skemaErrorSubErrorsField = Error .SkemaError .class .getDeclaredField ("subErrors" );
81
+ this .skemaErrorSubErrorsField .setAccessible (true );
82
+ this .skemaErrorErrorsField = Error .SkemaError .class .getDeclaredField ("errors" );
83
+ this .skemaErrorErrorsField .setAccessible (true );
84
+ this .skemaErrorItemCodeField = Error .SkemaErrorItem .class .getDeclaredField ("code" );
85
+ this .skemaErrorItemCodeField .setAccessible (true );
86
+ this .skemaErrorItemMessageField = Error .SkemaErrorItem .class .getDeclaredField ("message" );
87
+ this .skemaErrorItemMessageField .setAccessible (true );
88
+ this .storeApplicationCommandsBuiltInCommandsProviderField = StoreApplicationCommands .class .getDeclaredField ("builtInCommandsProvider" );
89
+ this .storeApplicationCommandsBuiltInCommandsProviderField .setAccessible (true );
70
90
71
91
var storeApplicationCommands = StoreStream .getApplicationCommands ();
72
92
var storeChannelsSelected = StoreStream .getChannelsSelected ();
@@ -107,7 +127,7 @@ public void loadPatches(Context context) throws Throwable {
107
127
108
128
var applicationIndexSource = Patches .applicationIndexSourceFromContext (this_ .$guildId , storeChannelsSelected );
109
129
try {
110
- ReflectUtils . setField (this_ .this$0 , "query" , this_ .$query );
130
+ storeApplicationCommandsQueryField . set (this_ .this$0 , this_ .$query );
111
131
this .passCommandData (this_ .this$0 , applicationIndexSource , RequestSource .QUERY );
112
132
} catch (Exception e ) {
113
133
throw new RuntimeException (e );
@@ -180,18 +200,12 @@ public void loadPatches(Context context) throws Throwable {
180
200
var errorResponse = ((MessageResult .UnknownFailure ) result )
181
201
.getError ()
182
202
.getResponse ();
183
- var error = ReflectUtils .getField (errorResponse , "skemaError" );
184
- var dataErrors = (List <Error .SkemaErrorItem >) ReflectUtils .getField (
185
- ((Map <String , Error .SkemaError >) ReflectUtils .getField (
186
- error ,
187
- "subErrors"
188
- ))
189
- .get ("data" ),
190
- "errors"
191
- );
203
+ var error = this .errorResponseErrorField .get (errorResponse );
204
+ var subErrors = ((Map <String , Error .SkemaError >) skemaErrorSubErrorsField .get (error ));
205
+ var dataErrors = (List <Error .SkemaErrorItem >) skemaErrorErrorsField .get (subErrors .get ("data" ));
192
206
193
207
for (var dataError : dataErrors ) {
194
- var errorCode = (String ) ReflectUtils . getField (dataError , "code" );
208
+ var errorCode = (String ) this . skemaErrorItemCodeField . get (dataError );
195
209
if (errorCode .equals ("INTERACTION_APPLICATION_COMMAND_INVALID_VERSION" )) {
196
210
ApplicationIndexSource applicationIndexSource = null ;
197
211
var guildId = localSendData .component3 ();
@@ -203,7 +217,7 @@ public void loadPatches(Context context) throws Throwable {
203
217
}
204
218
this .cleanApplicationIndexCache (applicationIndexSource );
205
219
206
- var errorMessage = (String ) ReflectUtils . getField (dataError , "message" );
220
+ var errorMessage = (String ) this . skemaErrorItemMessageField . get (dataError );
207
221
Utils .showToast (errorMessage );
208
222
209
223
break ;
@@ -237,7 +251,7 @@ private void passCommandData(StoreApplicationCommands storeApplicationCommands,
237
251
238
252
var applications = new ArrayList <Application >(applicationIndex .applications .values ());
239
253
Collections .sort (applications , (left , right ) -> left .getName ().compareTo (right .getName ()));
240
- applications .add (((BuiltInCommandsProvider ) ReflectUtils . getField (storeApplicationCommands , "builtInCommandsProvider" )).getBuiltInApplication ());
254
+ applications .add (((BuiltInCommandsProvider ) this . storeApplicationCommandsBuiltInCommandsProviderField . get (storeApplicationCommands )).getBuiltInApplication ());
241
255
this .handleGuildApplicationsUpdateMethod .invoke (storeApplicationCommands , applications );
242
256
243
257
switch (requestSource ) {
0 commit comments