@@ -79,6 +79,8 @@ static NetworkHandler()
79
79
handlers . Add ( 133 , new HandleDoorSetOpen ( ) ) ;
80
80
handlers . Add ( 143 , new HandleGeneratorSetTimeLeft ( ) ) ;
81
81
handlers . Add ( 131 , new HandleGeneratorUnlock ( ) ) ;
82
+ handlers . Add ( 180 , new EventHandler ( ) ) ;
83
+ handlers . Add ( 181 , new EventHandler ( ) ) ;
82
84
}
83
85
public static void handleJsmod2 ( int id , String json , Dictionary < string , string > mapper , TcpClient client )
84
86
{
@@ -147,13 +149,100 @@ public static JsonSetting[] getOne(string id,object val,IdMapping mapping)
147
149
{
148
150
return new [ ] { new JsonSetting ( Lib . getInt ( id ) , val , mapping ) } ;
149
151
}
152
+
153
+ public static object getTypeValue ( string val )
154
+ {
155
+ int i1 ;
156
+ bool b = int . TryParse ( val , out i1 ) ;
157
+ if ( b )
158
+ {
159
+ return i1 ;
160
+ }
161
+
162
+ bool b1 ;
163
+ b = bool . TryParse ( val , out b1 ) ;
164
+ if ( b )
165
+ {
166
+ return b1 ;
167
+ }
168
+
169
+ float f1 ;
170
+ b = float . TryParse ( val , out f1 ) ;
171
+ if ( b )
172
+ {
173
+ return f1 ;
174
+ }
175
+
176
+ Vector vector = Lib . getVector ( val ) ;
177
+
178
+ if ( vector != null )
179
+ {
180
+ return vector ;
181
+ }
182
+
183
+ char c1 ;
184
+
185
+ b = char . TryParse ( val , out c1 ) ;
186
+ if ( b )
187
+ {
188
+ return c1 ;
189
+ }
190
+
191
+ return val ;
192
+
193
+ }
150
194
}
151
195
152
196
public interface Handler
153
197
{
154
198
JsonSetting [ ] handle ( object api , Dictionary < string , string > mapper ) ;
155
199
}
156
200
201
+ public class EventHandler : Handler
202
+ {
203
+ public JsonSetting [ ] handle ( object api , Dictionary < string , string > mapper )
204
+ {
205
+ Type type = api . GetType ( ) ;
206
+ if ( mapper [ "id" ] . Equals ( "180" ) ) //180 Get
207
+ {
208
+ object obj = type . GetField ( mapper [ "field" ] ) . GetValue ( api ) ;
209
+ Type returnType = obj . GetType ( ) ;
210
+ bool isCommonType = returnType == typeof ( string ) || returnType == typeof ( bool ) ||
211
+ returnType == typeof ( float )
212
+ || returnType == typeof ( double ) || returnType == typeof ( String ) ||
213
+ returnType == typeof ( Vector )
214
+ || returnType == typeof ( int ) || returnType == typeof ( long ) || returnType == typeof ( char )
215
+ || returnType == typeof ( byte ) || returnType == typeof ( short ) ;
216
+ if ( isCommonType )
217
+ {
218
+ return Utils . getOne ( mapper [ "id" ] , obj , null ) ;
219
+ }
220
+ if ( returnType == typeof ( List < Vector > ) )
221
+ {
222
+ List < Vector > vectors = ( List < Vector > ) obj ;
223
+ JsonSetting [ ] settings = new JsonSetting [ vectors . Count ] ;
224
+ for ( int i = 0 ; i < settings . Length ; i ++ )
225
+ {
226
+ settings [ i ] = new JsonSetting ( Lib . getInt ( mapper [ "id" ] ) , vectors [ i ] , null ) ;
227
+ }
228
+
229
+ return settings ;
230
+ }
231
+ return null ;
232
+ }
233
+
234
+ string fieldName = mapper [ "field" ] ;
235
+ string val = mapper [ fieldName ] ;
236
+ object result = Utils . getTypeValue ( val ) ;
237
+ if ( mapper . ContainsKey ( "apiId" ) )
238
+ {
239
+ result = ProxyHandler . handler . apiMapping [ val ] ;
240
+ }
241
+ type . GetField ( fieldName ) . SetValue ( api , result ) ;
242
+ return null ;
243
+ }
244
+ }
245
+
157
246
public class HandleGeneratorGetEngaged : Handler
158
247
{
159
248
public JsonSetting [ ] handle ( object api , Dictionary < string , string > mapper )
0 commit comments