-
Notifications
You must be signed in to change notification settings - Fork 2
/
battle_rpc_send.c
451 lines (389 loc) · 10.3 KB
/
battle_rpc_send.c
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#include "battle.h"
#include "battle_rpc.h"
#include "move_etc.h"
// from battle_interp.c
// u8 b_buffer_A[4][0x200]; // 02022BC4
// u8 b_buffer_B[4][0x200]; // 020233C4
u8 b_codegen_buffer[0x100];
// 0800D8B0
void b_prepare_buffer(u8 dst_id, u8 *src, u16 length) {
if (b_type_flags & BATTLE_LINK)
return b_prepare_buffer_wireless(dst_id, src, length);
if (dst_id >= 2) return;
u8 (*dst_buffer)[0x200] = dst_id ? b_buffer_B : b_buffer_A;
u8 *dst = &dst[b_active_side];
memcpy(dst, src, length);
}
// 0800D9EC
// void b_prepare_buffer_wireless(u8 dst_id, u8 *src, u16 length) {
// // TODO
// }
// 0800DFA4 (getattr)
void bt_00_emit(u8 target, u8 a, u8 b) {
b_codegen_buffer[0] = 0x00;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = b;
b_codegen_buffer[3] = 0x00;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800DFC8 (setattr)
void bt_01_emit(u8 target, u8 a, u8 b) {
b_codegen_buffer[0] = 0x01;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = b;
b_codegen_buffer[3] = 0x00;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800DFF0
void bt_02_emit(u8 target, u8 a, u8 b, u8 len, u8 *data) {
b_codegen_buffer[0] = 0x02;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = b;
for (u32 i=0; i<len; i++)
b_codegen_buffer[3+i] = data[i];
b_prepare_buffer(target, b_codegen_buffer, 3+len);
}
// 0800E030
void bt_03_emit(u8 target, u8 a, u8 len, u8 *data) {
b_codegen_buffer[0] = 0x02;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = len;
for (u32 i=0; i<len; i++)
b_codegen_buffer[3+i] = data[i];
b_prepare_buffer(target, b_codegen_buffer, 3+len);
}
// 0800E070
void bt_04_emit(u8 target) {
b_codegen_buffer[0] = 0x04;
b_codegen_buffer[1] = 0x04;
b_codegen_buffer[2] = 0x04;
b_codegen_buffer[3] = 0x04;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E090
void bt_05_emit(u8 target, u8 a, u8 b, u8 c) {
b_codegen_buffer[0] = 0x05;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = b;
b_codegen_buffer[3] = c;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E0B4
void bt_06_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x06;
b_codegen_buffer[1] = a;
b_prepare_buffer(target, b_codegen_buffer, 2);
}
// 0800E0D4
void bt_07_emit(u8 target) {
b_codegen_buffer[0] = 0x07;
b_codegen_buffer[1] = 0x07;
b_codegen_buffer[2] = 0x07;
b_codegen_buffer[3] = 0x07;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E0F4
void bt_08_emit(u8 target) {
b_codegen_buffer[0] = 0x08;
b_codegen_buffer[1] = 0x08;
b_codegen_buffer[2] = 0x08;
b_codegen_buffer[3] = 0x08;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E114
void bt_09_emit(u8 target) {
b_codegen_buffer[0] = 0x09;
b_codegen_buffer[1] = 0x09;
b_codegen_buffer[2] = 0x09;
b_codegen_buffer[3] = 0x09;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E134
void bt_0A_emit(u8 target) {
b_codegen_buffer[0] = 0x0A;
b_codegen_buffer[1] = 0x0A;
b_codegen_buffer[2] = 0x0A;
b_codegen_buffer[3] = 0x0A;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E154
void bt_0B_emit(u8 target) {
b_codegen_buffer[0] = 0x0B;
b_codegen_buffer[1] = 0x0B;
b_codegen_buffer[2] = 0x0B;
b_codegen_buffer[3] = 0x0B;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E174
void bt_0C_emit(u8 target) {
b_codegen_buffer[0] = 0x0C;
b_codegen_buffer[1] = 0x0C;
b_codegen_buffer[2] = 0x0C;
b_codegen_buffer[3] = 0x0C;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E194
void bt_0D_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x0D;
b_codegen_buffer[1] = a;
b_prepare_buffer(target, b_codegen_buffer, 2);
}
// 0800E1B4
void bt_0E_emit(u8 target, ...) {
// TODO
}
// 0800E1FC
void bt_0F_emit(u8 target, u16 moveid, u8 b, u16 c, u32 damage, u8 happiness, struct disable *d) {
u16 weather;
u8 mlc = b_move_loop_counter;
if (
ability_check(as_update_bits_for_mud_and_water_sport, 0, ab_cloud_nine, 0) ||
ability_check(as_update_bits_for_mud_and_water_sport, 0, ab_air_lock, 0)
)
weather = 0;
else
weather = b_weather;
b_codegen_buffer[0] = 0x0F;
b_codegen_buffer[1] = moveid;
b_codegen_buffer[2] = moveid >> 8;
b_codegen_buffer[3] = b;
b_codegen_buffer[4] = c;
b_codegen_buffer[5] = c >> 8;
b_codegen_buffer[6] = damage;
b_codegen_buffer[7] = damage >> 8;
b_codegen_buffer[8] = damage >> 16;
b_codegen_buffer[9] = damage >> 24;
b_codegen_buffer[10] = happiness;
b_codegen_buffer[11] = mlc;
b_codegen_buffer[12] = weather;
b_codegen_buffer[13] = weather >> 8;
b_codegen_buffer[14] = 0;
b_codegen_buffer[15] = 0;
memcpy(b_codegen_buffer+16, d, 16);
b_prepare_buffer(target, b_codegen_buffer, 0x2C);
}
// 0800E2D4
void bt_10_emit(u8 target, ...) {
// TODO
}
// 0800E3EC
void bt_11_emit(u8 target, ...) {
// TODO
}
// 0800E4D4
void bt_12_emit(u8 target, u8 a, u16 b) {
b_codegen_buffer[0] = 0x12;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = b;
b_codegen_buffer[3] = b >> 8;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E500 (unused)
void bt_13_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x13;
b_codegen_buffer[1] = a;
b_prepare_buffer(target, b_codegen_buffer, 2);
}
// 0800E520
void bt_14_emit(u8 target, u8 a, u8 b, void *c) {
b_codegen_buffer[0] = 0x14;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = b;
b_codegen_buffer[3] = 0;
memcpy(b_codegen_buffer+4, c, 0x14);
b_prepare_buffer(target, b_codegen_buffer, 0x18);
}
// 0800E55C
void bt_15_emit(u8 target, u8 *a) {
b_codegen_buffer[0] = 0x15;
b_codegen_buffer[1] = a[0];
b_codegen_buffer[2] = a[1];
b_codegen_buffer[3] = a[2];
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E590
void bt_16_emit(u8 target, u8 a, u8 b, u8 c, u8 *d) {
b_codegen_buffer[0] = 0x16;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = b;
b_codegen_buffer[3] = c;
b_codegen_buffer[4] = d[0];
b_codegen_buffer[5] = d[1];
b_codegen_buffer[6] = d[2];
// sic: 7 is uninitialized
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E5CC
void bt_17_emit(u8 target) {
b_codegen_buffer[0] = 0x17;
b_codegen_buffer[1] = 0x17;
b_codegen_buffer[2] = 0x17;
b_codegen_buffer[3] = 0x17;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E5EC (healthbar update)
void bt_18_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x18;
b_codegen_buffer[1] = 0;
b_codegen_buffer[2] = a;
b_codegen_buffer[3] = a >> 8;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E624
void bt_19_emit(u8 target, u8 a, u16 b) {
b_codegen_buffer[0] = 0x19;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = b;
b_codegen_buffer[3] = b >> 8;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E658
void bt_1A_emit(u8 target, u32 a, u32 b) {
b_codegen_buffer[0] = 0x1A;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = a >> 8;
b_codegen_buffer[3] = a >> 16;
b_codegen_buffer[4] = a >> 24;
b_codegen_buffer[5] = b;
b_codegen_buffer[6] = b >> 8;
b_codegen_buffer[7] = b >> 16;
b_codegen_buffer[8] = b >> 24;
b_prepare_buffer(target, b_codegen_buffer, 9);
}
// 0800E6AC
void bt_1B_emit(u8 target, u32 a, u8 b) {
b_codegen_buffer[0] = 0x1A;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = a >> 8;
b_codegen_buffer[3] = a >> 16;
b_codegen_buffer[4] = a >> 24;
b_codegen_buffer[5] = b;
b_prepare_buffer(target, b_codegen_buffer, 6);
}
// 0800E6E8
void bt_1C_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x1C;
b_codegen_buffer[1] = a;
b_prepare_buffer(target, b_codegen_buffer, 2);
}
// 0800E708 (the code can be emmited but isn't implemented by any of the seven tables)
// // //
// 0800E904
void bt_25_emit(u8 target) {
b_codegen_buffer[0] = 0x25;
b_codegen_buffer[1] = 0x25;
b_codegen_buffer[2] = 0x25;
b_codegen_buffer[3] = 0x25;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E944
void bt_27_emit(u8 target) {
b_codegen_buffer[0] = 0x27;
b_codegen_buffer[1] = 0x27;
b_codegen_buffer[2] = 0x27;
b_codegen_buffer[3] = 0x27;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// // //
// 0800E964
void bt_28_emit(u8 target) {
b_codegen_buffer[0] = 0x28;
b_codegen_buffer[1] = 0x28;
b_codegen_buffer[2] = 0x28;
b_codegen_buffer[3] = 0x28;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E984
void bt_29_emit(u8 target) {
b_codegen_buffer[0] = 0x29;
b_codegen_buffer[1] = 0x29;
b_codegen_buffer[2] = 0x29;
b_codegen_buffer[3] = 0x29;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800E9A4
void bt_2A_emit(u8 target) {
b_codegen_buffer[0] = 0x2A;
b_codegen_buffer[1] = 0x2A;
b_codegen_buffer[2] = 0x2A;
b_codegen_buffer[3] = 0x2A;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// // //
// 0800EA1C
void bt_2D_emit(u8 target) {
b_codegen_buffer[0] = 0x2D;
b_codegen_buffer[1] = 0x2D;
b_codegen_buffer[2] = 0x2D;
b_codegen_buffer[3] = 0x2D;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800EA3C
void bt_2E_emit(u8 target, u8 environment_index) {
b_codegen_buffer[0] = 0x2E;
b_codegen_buffer[1] = environment_index;
b_prepare_buffer(target, b_codegen_buffer, 2);
}
// 0800EA5C
void bt_2F_emit(u8 target) {
b_codegen_buffer[0] = 0x2F;
b_codegen_buffer[1] = 0x2F;
b_codegen_buffer[2] = 0x2F;
b_codegen_buffer[3] = 0x2F;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800EA7C
void bt_30_emit(u8 target, ...) {
// TODO
}
// 0800EAC4
void bt_31_emit(u8 target) {
b_codegen_buffer[0] = 0x31;
b_codegen_buffer[1] = 0x31;
b_codegen_buffer[2] = 0x31;
b_codegen_buffer[3] = 0x31;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800EAE4
void bt_32_emit(u8 target) {
b_codegen_buffer[0] = 0x32;
b_codegen_buffer[1] = 0x32;
b_codegen_buffer[2] = 0x32;
b_codegen_buffer[3] = 0x32;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800EB04
void bt_33_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x33;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = 0x33;
b_codegen_buffer[3] = 0x33;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800EB28 (move animation)
void bt_34_emit(u8 target, u8 a, u16 bb) {
b_codegen_buffer[0] = 0x34;
b_codegen_buffer[1] = a;
b_codegen_buffer[2] = bb;
b_codegen_buffer[3] = bb >> 8;
b_prepare_buffer(target, b_codegen_buffer, 4);
}
// 0800EB54
void bt_35_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x35;
b_codegen_buffer[1] = a;
b_prepare_buffer(target, b_codegen_buffer, 2);
}
// TODO: find bt_36_emit
// 0800EB94
void bt_37_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x37;
b_codegen_buffer[1] = a;
b_prepare_buffer(target, b_codegen_buffer, 2);
}
// 0800EB74
void bt_38_emit(u8 target, u8 a) {
b_codegen_buffer[0] = 0x38;
b_codegen_buffer[1] = a;
b_prepare_buffer(target, b_codegen_buffer, 2);
}