-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathJORServer.cpp
More file actions
830 lines (688 loc) · 23.5 KB
/
JORServer.cpp
File metadata and controls
830 lines (688 loc) · 23.5 KB
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
#include "JSystem/JSystem.h" // IWYU pragma: keep
#include "JSystem/JHostIO/JORServer.h"
#include "JSystem/JHostIO/JORReflexible.h"
#include "JSystem/JHostIO/JORFile.h"
#include "JSystem/JHostIO/JORHostInfo.h"
#include "JSystem/JSupport/JSUMemoryStream.h"
#include <string>
void JOREventCallbackListNode::JORAppend() {
JORServer* pServer = JORServer::getInstance();
JUT_ASSERT(51, pServer!=NULL);
pServer->appendEventCallbackListNode(this);
}
void JOREventCallbackListNode::JORRemove() {
JORServer* pServer = JORServer::getInstance();
JUT_ASSERT(57, pServer!=NULL);
pServer->removeEventCallbackListNode(this);
}
JOREventCallbackListNode::JOREventCallbackListNode(u32 param_0, u32 param_1, bool append) {
field_0xc = param_0;
field_0x10 = param_1;
if (append) {
JORAppend();
}
}
JOREventCallbackListNode::~JOREventCallbackListNode() {
JORRemove();
}
#if DEBUG
void JORReflexible::listen(u32 command, const JOREvent* event) {
switch (command) {
case JORServer::ECommand_GenObjInfo:
genObjectInfo((JORGenEvent*)event);
break;
case JORServer::ECommand_NodeEvent:
listenNodeEvent((JORNodeEvent*)event);
break;
case JORServer::ECommand_PropertyEvent:
listenPropertyEvent((JORPropertyEvent*)event);
break;
}
}
void JORReflexible::genObjectInfo(const JORGenEvent* event) {
JORMContext* mctx = getJORServer()->attachMCTX(MCTX_MSG_GEN_OBJ_INFO);
mctx->startNode("", this, 0, 0);
genMessage(mctx);
mctx->endNode();
getJORServer()->releaseMCTX(mctx);
}
void JORReflexible::listenNodeEvent(const JORNodeEvent*) {}
void JORReflexible::listenPropertyEvent(const JORPropertyEvent* pEvent) {
if (pEvent->kind & JORPropertyEvent::EKind_HasListener) {
JORServer* pServer = getJORServer();
JORPropertyEvent* event = (JORPropertyEvent*)pEvent;
event->kind &= ~JORPropertyEvent::EKind_HasListener;
switch (pEvent->type) {
case 'RNGf':
case 'RNGi':
case 'RBTN':
case 'CMBX':
if (pEvent->field_0x14 >= 4) {
pEvent->field_0x10->listenPropertyEvent(pEvent);
}
break;
case 'CHBX':
if (pEvent->field_0x14 >= 4) {
pEvent->field_0x10->listenPropertyEvent(pEvent);
}
break;
case 'EDBX':
case 'BUTN':
pEvent->field_0x10->listenPropertyEvent(pEvent);
break;
}
event->kind |= JORPropertyEvent::EKind_HasListener;
} else if (!(pEvent->kind & JORPropertyEvent::EKind_ValueID)) {
switch (pEvent->type) {
case 'RBTN':
case 'RNGi':
case 'RNGf':
case 'CMBX':
if (pEvent->field_0x14 >= 4) {
JORPropertyEvent* event = (JORPropertyEvent*)pEvent;
JORServer::defSetVal((void*)event->id, event->kind, event->field_0x18.U32);
}
break;
case 'CHBX':
if (pEvent->field_0x14 >= 4) {
JORPropertyEvent* event = (JORPropertyEvent*)pEvent;
JORServer::defSetBitVal((void*)event->id, event->kind, (u16)event->field_0x18.U16[0], (u16)event->field_0x18.U16[1]);
}
break;
case 'EDBX':
JORPropertyEvent* event = (JORPropertyEvent*)pEvent;
JSUMemoryInputStream stream(&event->field_0x18, event->field_0x14);
stream >> (char*)event->id;
break;
}
return;
}
}
#endif
JORServer* JORServer::instance;
JORServer* JORServer::create() {
if (instance == NULL) {
instance = new JORServer();
}
return instance;
}
void JORServer::defSetVal(void* ptr, u32 kind, s32 val) {
switch (jhostio::GetEKindSize(kind)) {
case jhostio::EKind_8B:
*(u8*)ptr = val;
break;
case jhostio::EKind_16B:
*(u16*)ptr = val;
break;
case jhostio::EKind_32B:
*(u32*)ptr = val;
break;
}
}
void JORServer::defSetBitVal(void* ptr, u32 kind, u16 param_2, u16 param_3) {
param_2 &= param_3;
switch (jhostio::GetEKindSize(kind)) {
case jhostio::EKind_8B: {
u8* kptr = (u8*)ptr;
*kptr &= (u8)~param_3;
*kptr |= (u8)param_2;
break;
}
case jhostio::EKind_16B: {
u16* kptr = (u16*)ptr;
*kptr &= (u16)~param_3;
*kptr |= param_2;
}
}
}
JORMContext* JORServer::attachMCTX(u32 msgID) {
m_context.bufInit();
m_context.putMsgID(msgID);
return &m_context;
}
void JORServer::releaseMCTX(JORMContext* mctx) {
ASSERTMSGLINE(292, mctx->msgSize() < 0x10000, "JORServer:releaseMCTX: context buffer probably overflowed.\n");
if (mctx->msgSize() > 4) {
const s32 var_r28 = send(mctx->msgPtr(), mctx->msgSize());
}
}
void JORServer::receive(const char* pBuffer, s32 length) {
JSUMemoryInputStream stream(pBuffer, length);
u32 command;
stream >> command;
if (!stream.isGood()) {
OS_REPORT("JORServer::receive : データが足りない\n");
OS_REPORT("JORServer::receive : データが足りない\n");
return;
}
switch (command) {
case ECommand_GetRootObj:
if (mp_rootObj != NULL) {
OS_REPORT("Get RootObject ref(%08X)\n", mp_rootObj);
m_context.bufInit();
m_context.putMsgID(MCTX_MSG_GET_ROOT_OBJ);
m_context.genRootNode(m_rootName, mp_rootObj, field_0x10064, field_0x10068);
send(m_context.msgPtr(), m_context.msgSize());
}
break;
case ECommand_NodeEvent: {
u32 obj_addr;
stream.read(obj_addr);
JORNodeEvent* pEvent = (JORNodeEvent*)(pBuffer + stream.getPosition());
stream.skip(4);
#if DEBUG
if (stream.isGood()) {
reinterpret_cast<JORReflexible*>(obj_addr)->listen(command, pEvent);
}
#endif
}
break;
case ECommand_PropertyEvent: {
u32 obj_addr;
stream.read(obj_addr);
JORPropertyEvent* pEvent = (JORPropertyEvent*)(pBuffer + stream.getPosition());
stream.skip(0x18);
if (stream.isGood()) {
stream.skip(pEvent->field_0x14);
}
#if DEBUG
if (stream.isGood()) {
reinterpret_cast<JORReflexible*>(obj_addr)->listen(command, pEvent);
}
#endif
}
break;
case ECommand_GenObjInfo: {
u32 obj_addr;
stream.read(obj_addr);
#if DEBUG
if (stream.isGood()) {
reinterpret_cast<JORReflexible*>(obj_addr)->listen(command, NULL);
}
#endif
}
break;
case ECommand_FIO:
fio_dispatchMessage_(stream);
break;
case ECommand_DIR:
dir_dispatchMessage_(stream);
break;
case ECommand_ReadResultS32:
readResultS32_(stream);
break;
case ECommand_HostInfo:
hostinfo_dispatchMessage_(stream);
break;
case ECommand_ReadResultU32:
readResultU32_(stream);
break;
case ECommand_ReadOrEvent:
readOrEvent_(stream);
break;
}
}
void JORServer::fio_openFile_(JSUMemoryInputStream& stream) {
u32 file_addr;
stream >> file_addr;
JORFile* file = (JORFile*)file_addr;
u32 handle;
stream >> handle;
u32 file_len;
stream >> file_len;
u16 filename_len;
u16 basename_len;
u16 extension_name_len;
stream >> filename_len >> basename_len >> extension_name_len;
strncpy(file->getFilename(), (const char*)stream.getPointer(), filename_len);
file->getFilename()[filename_len] = 0;
file->setHandle(handle);
file->setFileLength(file_len);
file->setNFileName((u16)filename_len);
file->setNBaseName((u16)basename_len);
file->setNExtensionName((u16)extension_name_len);
file->setStatus(JORFile::EStatus_READ_DATA);
}
void JORServer::fio_closeFile_(JSUMemoryInputStream& stream) {
u32 file_addr;
stream >> file_addr;
JORFile* file = (JORFile*)file_addr;
u32 sp8;
stream >> sp8;
if (sp8 == 0) {
OS_REPORT("Close Failed!\n");
}
file->setStatus(JORFile::EStatus_READ_END);
}
void JORServer::fio_readData_(JSUMemoryInputStream& stream) {
u32 file_addr;
stream >> file_addr;
JORFile* file = (JORFile*)file_addr;
u32 status;
stream >> status;
if (status == JORFile::EStatus_READ_BEGIN) {
file->setStatus(status);
} else if (status == JORFile::EStatus_WRITE_BEGIN) {
file->setStatus(status);
} else if (status == JORFile::EStatus_WRITE_DATA) {
u32 position, data;
stream >> position >> data;
file->getDataStream().seek(position, JSUStreamSeekFrom_SET);
file->getDataStream().write(stream.getPointer(), data);
file->setStatus(status);
} else if (status == JORFile::EStatus_WRITE_END) {
file->setStatus(status);
}
}
void JORServer::fio_writeData_(JSUMemoryInputStream& stream) {
u32 file_addr;
stream >> file_addr;
JORFile* file = (JORFile*)file_addr;
u32 status;
stream >> status;
file->setStatus(status);
}
void JORServer::fio_dispatchMessage_(JSUMemoryInputStream& stream) {
u32 command;
stream >> command;
switch (command) {
case JORFile::ECommand_OPEN:
fio_openFile_(stream);
break;
case JORFile::ECommand_CLOSE:
fio_closeFile_(stream);
break;
case JORFile::ECommand_READ:
fio_readData_(stream);
break;
case JORFile::ECommand_WRITE:
fio_writeData_(stream);
break;
}
}
void JORServer::dir_dispatchMessage_(JSUMemoryInputStream& stream) {
u32 command, status, dir_addr;
stream >> command >> dir_addr >> status;
JORDir* dir = (JORDir*)dir_addr;
dir->setStatus(status);
if (status != 2) {
switch (command) {
case 1:
break;
case 2:
dir_findFirstFile_(stream, dir);
break;
case 3:
dir_findNextFile_(stream, dir);
break;
case 0:
dir_browseForFolder_(stream, dir);
break;
case 5:
dir_browseForFolder_(stream, dir);
break;
}
}
}
void JORServer::dir_findFirstFile_(JSUMemoryInputStream& stream, JORDir* directory) {
char namebuf[256];
u32 attribute, lo_time, hi_time, handle;
stream >> handle >> attribute >> lo_time >> hi_time >> namebuf;
directory->setFindHandle(handle);
directory->setFileAttribute(attribute);
directory->setLowDateTime(lo_time);
directory->setHighDateTime(hi_time);
strncpy(directory->getFilename(), namebuf, sizeof(namebuf) - 1);
}
void JORServer::dir_findNextFile_(JSUMemoryInputStream& stream, JORDir* directory) {
char namebuf[256];
u32 attribute, lo_time, hi_time;
stream >> attribute >> lo_time >> hi_time >> namebuf;
directory->setFileAttribute(attribute);
directory->setLowDateTime(lo_time);
directory->setHighDateTime(hi_time);
strncpy(directory->getFilename(), namebuf, sizeof(namebuf) - 1);
}
void JORServer::dir_browseForFolder_(JSUMemoryInputStream& stream, JORDir* directory) {
char namebuf[256];
u32 attribute, lo_time, hi_time;
stream >> attribute >> lo_time >> hi_time >> namebuf;
directory->setFileAttribute(attribute);
directory->setLowDateTime(lo_time);
directory->setHighDateTime(hi_time);
strncpy(directory->getFilename(), namebuf, sizeof(namebuf) - 1);
}
void JORServer::hostinfo_dispatchMessage_(JSUMemoryInputStream& stream) {
u32 command, spC, hostinfo_addr;
stream >> command >> hostinfo_addr >> spC;
JORHostInfo* hostinfo = (JORHostInfo*)hostinfo_addr;
hostinfo->setResult(spC != 0 ? 1 : 2);
if (spC != 0) {
switch (command) {
case HOSTINFO_REQ_COMPUTER_NAME:
hostinfo_recvString_(stream, (JORHostInfo_String*)hostinfo);
break;
case HOSTINFO_REQ_USERNAME:
hostinfo_recvString_(stream, (JORHostInfo_String*)hostinfo);
break;
case HOSTINFO_REQ_LOCAL_TIME:
hostinfo_localTime_(stream, (JORHostInfo_CalendarTime*)hostinfo);
break;
}
}
}
void JORServer::hostinfo_recvString_(JSUMemoryInputStream& stream, JORHostInfo_String* pString) {
char buffer[256];
stream >> buffer;
strncpy(pString->getString(), buffer, pString->getBufferSize());
}
void JORServer::hostinfo_localTime_(JSUMemoryInputStream& stream, JORHostInfo_CalendarTime* pCalendarTime) {
u16 year, month, weekday, monthday, hours, minutes, seconds, milliseconds;
stream >> year
>> month
>> weekday
>> monthday
>> hours
>> minutes
>> seconds
>> milliseconds;
OSCalendarTime* pTime = pCalendarTime->getCalendarTime();
pTime->sec = seconds;
pTime->min = minutes;
pTime->hour = hours;
pTime->mday = monthday;
pTime->mon = month - 1;
pTime->year = year;
pTime->wday = weekday;
pTime->msec = milliseconds;
pTime->usec = 0;
pTime->yday = monthday + JORGetYearDays(year, month - 1);
}
void JORServer::sendReset() {
u32 spC = JHIhtonl(0);
send(&spC, 4);
}
void JORServer::setRootNode(const char* name, JORReflexible* node, u32 param_2, u32 param_3) {
mp_rootObj = node;
if (name == NULL) {
name = "ルート";
}
strncpy(m_rootName, name, sizeof(m_rootName) - 1);
m_rootName[sizeof(m_rootName) - 1] = 0;
field_0x10064 = param_2;
field_0x10068 = param_3;
}
void JORServer::readResultU32_(JSUMemoryInputStream& stream) {
u32 ptr_addr, val;
stream >> ptr_addr >> val;
u32* ptr = (u32*)ptr_addr;
*ptr = val;
}
void JORServer::readResultS32_(JSUMemoryInputStream& stream) {
u32 ptr_addr, val;
stream >> ptr_addr >> val;
s32* ptr = (s32*)ptr_addr;
*ptr = val;
}
void JORServer::readOrEvent_(JSUMemoryInputStream& stream) {
if (m_eventDone) {
stream >> m_eventNum;
u16 name_len;
stream >> name_len;
if (name_len >= 0x1000) {
name_len = 0x1000 - 1;
}
stream.read(m_eventName, name_len);
m_eventName[name_len] = 0;
m_event = true;
}
}
void JORServer::doneEvent() {
if (!m_eventDone) {
m_eventDone = true;
u32 sp8 = JHIhtonl(0x10);
send(&sp8, 4);
}
}
void JORMContext::genNodeSub(const char* name, JORReflexible* node, u32 param_2, u32 param_3) {
mOutputStream << name;
putNode(node);
mOutputStream << param_2;
if (param_2 & 4) {
mOutputStream << param_3;
}
}
void JORMContext::endNode() {
mOutputStream << MCTX_COMMAND_END_NODE;
}
void JORMContext::invalidNode(JORReflexible* node, u32 param_1) {
mOutputStream << MCTX_COMMAND_INVALID_NODE;
putNode(node);
mOutputStream << param_1;
}
void JORMContext::genControl(u32 type, u32 kind, const char* label, u32 style, u32 id,
JOREventListener* pListener, u32 initValue)
{
mOutputStream << type << kind << label << style << id;
if (kind & JORPropertyEvent::EKind_HasListener) {
mOutputStream << (uintptr_t)pListener;
}
if ((kind & JORPropertyEvent::EKind_ValueID) && type != 'EDBX') {
kind |= 0x20;
}
if (jhostio::GetEKindSize(kind) != 0) {
mOutputStream << initValue;
}
}
void JORMContext::genSliderSub(u32 kind, const char* label, u32 id, u32 style, s32 initValue, s32 rangeMin,
s32 rangeMax, JOREventListener* pListener, u16 posX, u16 posY,
u16 width, u16 height)
{
if (pListener != NULL) {
kind |= JORPropertyEvent::EKind_HasListener;
}
mOutputStream << MCTX_COMMAND_GEN_CONTROL;
genControl(kind & JORPropertyEvent::EKind_FloatValue ? 'RNGf' : 'RNGi', kind, label, style, id, pListener, initValue);
mOutputStream << rangeMin << rangeMax;
mOutputStream << posX << posY << width << height;
}
void JORMContext::genCheckBoxSub(u32 kind, const char* label, u32 id, u32 style, u16 initValue, u16 mask,
JOREventListener* pListener, u16 posX, u16 posY, u16 width,
u16 height)
{
if (pListener != NULL) {
kind |= JORPropertyEvent::EKind_HasListener;
}
mOutputStream << MCTX_COMMAND_GEN_CONTROL;
genControl('CHBX', kind, label, style, id, pListener, (mask << 0x10) | initValue);
mOutputStream << posX << posY << width << height;
}
void JORMContext::startSelectorSub(u32 type, u32 kind, const char* label, u32 id, u32 style, s32 initValue,
JOREventListener* pListener, u16 posX, u16 posY, u16 width,
u16 height)
{
if (pListener != NULL) {
kind |= JORPropertyEvent::EKind_HasListener;
}
mOutputStream << MCTX_COMMAND_START_SELECTOR;
genControl(type, kind, label, style, id, pListener, initValue);
mOutputStream << posX << posY << width << height;
}
void JORMContext::endSelectorSub() {
mOutputStream << MCTX_COMMAND_END_SELECTOR;
}
void JORMContext::genSelectorItemSub(const char* label, s32 itemNo, u32 param_2, u16 posX,
u16 posY, u16 width, u16 height)
{
mOutputStream << MCTX_COMMAND_SELECTOR_ITEM << label << (u32)itemNo;
mOutputStream << param_2 << posX << posY << width << height;
}
void JORMContext::genButton(const char* label, u32 id, u32 style, JOREventListener* pListener,
u16 posX, u16 posY, u16 width, u16 height)
{
u32 kind = 0;
if (pListener != NULL) {
kind |= JORPropertyEvent::EKind_HasListener;
}
mOutputStream << MCTX_COMMAND_GEN_CONTROL;
genControl('BUTN', kind, label, style, id, pListener, 0);
mOutputStream << posX << posY << width << height;
}
void JORMContext::genLabel(const char* label, u32 id, u32 style, JOREventListener* pListener,
u16 posX, u16 posY, u16 width, u16 height)
{
u32 kind = 0;
if (pListener != NULL) {
kind |= JORPropertyEvent::EKind_HasListener;
}
mOutputStream << MCTX_COMMAND_GEN_CONTROL;
genControl('LABL', kind, label, style, id, pListener, 0);
mOutputStream << posX << posY << width << height;
}
void JORMContext::genGroupBox(const char* label, u32 id, u32 style, JOREventListener* pListener,
u16 posX, u16 posY, u16 width, u16 height)
{
u32 kind = 0;
if (pListener != NULL) {
kind |= JORPropertyEvent::EKind_HasListener;
}
mOutputStream << MCTX_COMMAND_GEN_CONTROL;
genControl('GRBX', kind, label, style, id, pListener, 0);
mOutputStream << posX << posY << width << height;
}
void JORMContext::genEditBoxID(const char* label, u32 id, const char* string, u16 length, u32 style,
JOREventListener* pListener, u16 posX, u16 posY, u16 width, u16 height)
{
u32 kind = 0;
if (pListener != NULL) {
kind |= JORPropertyEvent::EKind_HasListener;
}
mOutputStream << MCTX_COMMAND_GEN_CONTROL;
genControl('EDBX', kind | JORPropertyEvent::EKind_ValueID, label, style, id, pListener, 0);
mOutputStream << length << string;
mOutputStream << posX << posY << width << height;
}
void JORMContext::updateControl(u32 mode, u32 id, u32 param_2) {
mOutputStream << MCTX_COMMAND_UPDATE_CONTROL << mode << id;
if (mode & 1) {
mOutputStream << param_2;
}
}
void JORMContext::updateControl(u32 mode, u32 id, const char* param_2) {
if (mode & 2) {
mOutputStream << MCTX_COMMAND_UPDATE_CONTROL << mode << id << param_2;
}
}
void JORMContext::updateSliderSub(u32 mode, u32 id, s32 value, s32 rangeMin, s32 rangeMax, u32 param_5) {
updateControl(mode, id, param_5);
if (mode & 2) {
mOutputStream << value;
}
if (mode & 4) {
mOutputStream << rangeMin << rangeMax;
}
}
void JORMContext::updateCheckBoxSub(u32 mode, u32 id, u16 value, u16 mask, u32 param_4) {
mOutputStream << MCTX_COMMAND_UPDATE_CONTROL << (mode | JORPropertyEvent::EKind_HasListener) << id << (u32)mask;
if (mode & 1) {
mOutputStream << param_4;
}
if (mode & 2) {
mOutputStream << (u32)((mask << 0x10) | value);
}
}
void JORMContext::updateSelectorSub(u32 mode, u32 id, s32 value, u32 param_3) {
updateControl(mode, id, param_3);
if (mode & 2) {
mOutputStream << value;
}
}
void JORMContext::updateEditBoxID(u32 mode, u32 id, const char* string, u32 param_3, u16 length) {
updateControl(mode, id, param_3);
if (mode & 2) {
mOutputStream << string;
}
if (mode & 0x10) {
mOutputStream << length;
}
}
void JORMContext::editComboBoxItem(u32 param_0, u32 id, const char* param_2, s32 param_3, u32 param_4) {
updateControl(8, id, (u32)0);
mOutputStream << param_0 << param_4 << param_2 << param_3;
}
void JORMContext::openFile(JORFile* pFile, u32 flags, const char* path, const char* extMask,
u32 maskSize, const char* defaultExt, const char* param_6, const char* fileSuffix)
{
if (defaultExt != NULL) {
flags |= JORFile::EFlags_DEFAULT_EXT;
}
if (param_6 != NULL) {
flags |= JORFile::EFlags_UNK_0x20;
}
if (fileSuffix != NULL) {
flags |= JORFile::EFlags_HAS_SUFFIX;
}
mOutputStream << (u32)JORFile::ECommand_OPEN << (uintptr_t)pFile << flags << path;
mOutputStream << (u16)maskSize;
mOutputStream.write(extMask, maskSize);
if (defaultExt != NULL) {
mOutputStream << defaultExt;
}
if (param_6 != NULL) {
mOutputStream << param_6;
}
if (fileSuffix != NULL) {
mOutputStream << fileSuffix;
}
}
void JORMContext::closeFile(JORFile* pFile) {
mOutputStream << (u32)JORFile::ECommand_CLOSE << (uintptr_t)pFile << pFile->getHandle();
}
void JORMContext::readBegin(JORFile* pFile, s32 size) {
mOutputStream << (u32)JORFile::ECommand_READ
<< (u32)JORFile::EStatus_READ_BEGIN
<< (uintptr_t)pFile
<< pFile->getHandle()
<< (u32)size;
}
void JORMContext::readData(JORFile* pFile) {
mOutputStream << (u32)JORFile::ECommand_READ
<< (u32)JORFile::EStatus_READ_DATA
<< (uintptr_t)pFile
<< pFile->getHandle();
}
void JORMContext::writeBegin(JORFile* pFile, u16 flags, u32 size) {
mOutputStream << (u32)JORFile::ECommand_WRITE
<< (u32)JORFile::EStatus_WRITE_BEGIN
<< (uintptr_t)pFile
<< pFile->getHandle()
<< (u32)size
<< (u32)flags;
}
void JORMContext::writeData(JORFile* pFile, const void* pBuffer, s32 size, u32 position) {
mOutputStream << (u32)JORFile::ECommand_WRITE
<< (u32)JORFile::EStatus_WRITE_DATA
<< (uintptr_t)pFile
<< pFile->getHandle()
<< (u32)position;
mOutputStream << (u16)size;
mOutputStream.write(pBuffer, size);
}
void JORMContext::writeDone(JORFile* pFile, u32 size) {
mOutputStream << (u32)JORFile::ECommand_WRITE
<< (u32)JORFile::EStatus_WRITE_END
<< (uintptr_t)pFile
<< pFile->getHandle()
<< (u32)size;
}
void JORMContext::openMessageBox(void* param_0, u32 style, const char* message, const char* title) {
mOutputStream << (uintptr_t)param_0 << (u32)style << message << title;
}
void JORMContext::sendHostInfoRequest(u32 requestType, JORHostInfo* pHostInfo) {
mOutputStream << requestType << (uintptr_t)pHostInfo;
}
void JORMContext::sendShellExecuteRequest(void* param_0, const char* param_1, const char* param_2,
const char* param_3, const char* param_4, int param_5)
{
mOutputStream << (uintptr_t)param_0 << param_1 << param_2 << param_3 << param_4 << (u32)param_5;
}