koishipro-core.js 1.0.10 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +248 -38
- package/dist/index.cjs +126 -257
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +135 -259
- package/dist/index.mjs.map +3 -3
- package/dist/src/adapters/ocgcore-parsers.d.ts +11 -5
- package/dist/src/ocgcore-duel.d.ts +1 -1
- package/dist/src/structs/card-data.d.ts +5 -3
- package/dist/src/types/card-data.d.ts +1 -3
- package/dist/src/types/ocgcore-params.d.ts +6 -6
- package/dist/src/types/ocgcore-results.d.ts +6 -77
- package/dist/vendor/libocgcore.shared.d.ts +7 -7
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
1
12
|
// index.ts
|
|
2
|
-
import { Buffer } from "buffer";
|
|
13
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
3
14
|
|
|
4
15
|
// src/vendor/ocgcore-constants.ts
|
|
5
16
|
var OcgcoreCommonConstants = {
|
|
@@ -372,9 +383,6 @@ var LEN_EMPTY = 4;
|
|
|
372
383
|
var LEN_HEADER = 8;
|
|
373
384
|
|
|
374
385
|
// src/utility/binary.ts
|
|
375
|
-
function readU8(buf, offset) {
|
|
376
|
-
return buf[offset] ?? 0;
|
|
377
|
-
}
|
|
378
386
|
function readU16(buf, offset) {
|
|
379
387
|
return new DataView(buf.buffer, buf.byteOffset, buf.byteLength).getUint16(
|
|
380
388
|
offset,
|
|
@@ -387,160 +395,22 @@ function readI32(buf, offset) {
|
|
|
387
395
|
true
|
|
388
396
|
);
|
|
389
397
|
}
|
|
390
|
-
function readU32(buf, offset) {
|
|
391
|
-
return new DataView(buf.buffer, buf.byteOffset, buf.byteLength).getUint32(
|
|
392
|
-
offset,
|
|
393
|
-
true
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
398
|
|
|
397
399
|
// src/utility/utf8.ts
|
|
398
400
|
var encoder = new TextEncoder();
|
|
399
401
|
var decoder = new TextDecoder("utf-8");
|
|
400
|
-
function encodeUtf8(value) {
|
|
401
|
-
return encoder.encode(value);
|
|
402
|
-
}
|
|
403
402
|
function decodeUtf8(value) {
|
|
404
403
|
return decoder.decode(value);
|
|
405
404
|
}
|
|
406
405
|
|
|
407
406
|
// src/adapters/ocgcore-parsers.ts
|
|
408
|
-
|
|
409
|
-
let offset = 0;
|
|
410
|
-
const flags = readI32(payload, offset) >>> 0;
|
|
411
|
-
offset += 4;
|
|
412
|
-
const info = { flags, empty: flags === 0 };
|
|
413
|
-
if (flags === 0) {
|
|
414
|
-
return info;
|
|
415
|
-
}
|
|
416
|
-
if (flags & OcgcoreCommonConstants.QUERY_CODE) {
|
|
417
|
-
info.code = readI32(payload, offset);
|
|
418
|
-
offset += 4;
|
|
419
|
-
}
|
|
420
|
-
if (flags & OcgcoreCommonConstants.QUERY_POSITION) {
|
|
421
|
-
const pdata = readI32(payload, offset);
|
|
422
|
-
offset += 4;
|
|
423
|
-
info.position = (pdata >>> 24 & 255) >>> 0;
|
|
424
|
-
}
|
|
425
|
-
if (flags & OcgcoreCommonConstants.QUERY_ALIAS) {
|
|
426
|
-
info.alias = readI32(payload, offset);
|
|
427
|
-
offset += 4;
|
|
428
|
-
}
|
|
429
|
-
if (flags & OcgcoreCommonConstants.QUERY_TYPE) {
|
|
430
|
-
info.type = readI32(payload, offset);
|
|
431
|
-
offset += 4;
|
|
432
|
-
}
|
|
433
|
-
if (flags & OcgcoreCommonConstants.QUERY_LEVEL) {
|
|
434
|
-
info.level = readI32(payload, offset);
|
|
435
|
-
offset += 4;
|
|
436
|
-
}
|
|
437
|
-
if (flags & OcgcoreCommonConstants.QUERY_RANK) {
|
|
438
|
-
info.rank = readI32(payload, offset);
|
|
439
|
-
offset += 4;
|
|
440
|
-
}
|
|
441
|
-
if (flags & OcgcoreCommonConstants.QUERY_ATTRIBUTE) {
|
|
442
|
-
info.attribute = readI32(payload, offset);
|
|
443
|
-
offset += 4;
|
|
444
|
-
}
|
|
445
|
-
if (flags & OcgcoreCommonConstants.QUERY_RACE) {
|
|
446
|
-
info.race = readI32(payload, offset);
|
|
447
|
-
offset += 4;
|
|
448
|
-
}
|
|
449
|
-
if (flags & OcgcoreCommonConstants.QUERY_ATTACK) {
|
|
450
|
-
info.attack = readI32(payload, offset);
|
|
451
|
-
offset += 4;
|
|
452
|
-
}
|
|
453
|
-
if (flags & OcgcoreCommonConstants.QUERY_DEFENSE) {
|
|
454
|
-
info.defense = readI32(payload, offset);
|
|
455
|
-
offset += 4;
|
|
456
|
-
}
|
|
457
|
-
if (flags & OcgcoreCommonConstants.QUERY_BASE_ATTACK) {
|
|
458
|
-
info.baseAttack = readI32(payload, offset);
|
|
459
|
-
offset += 4;
|
|
460
|
-
}
|
|
461
|
-
if (flags & OcgcoreCommonConstants.QUERY_BASE_DEFENSE) {
|
|
462
|
-
info.baseDefense = readI32(payload, offset);
|
|
463
|
-
offset += 4;
|
|
464
|
-
}
|
|
465
|
-
if (flags & OcgcoreCommonConstants.QUERY_REASON) {
|
|
466
|
-
info.reason = readI32(payload, offset);
|
|
467
|
-
offset += 4;
|
|
468
|
-
}
|
|
469
|
-
if (flags & OcgcoreCommonConstants.QUERY_REASON_CARD) {
|
|
470
|
-
offset += 4;
|
|
471
|
-
}
|
|
472
|
-
if (flags & OcgcoreCommonConstants.QUERY_EQUIP_CARD) {
|
|
473
|
-
const controller = readU8(payload, offset) >>> 0;
|
|
474
|
-
const location = readU8(payload, offset + 1) >>> 0;
|
|
475
|
-
const sequence = readU8(payload, offset + 2) >>> 0;
|
|
476
|
-
info.equipCard = { controller, location, sequence };
|
|
477
|
-
offset += 4;
|
|
478
|
-
}
|
|
479
|
-
if (flags & OcgcoreCommonConstants.QUERY_TARGET_CARD) {
|
|
480
|
-
const count = readI32(payload, offset);
|
|
481
|
-
offset += 4;
|
|
482
|
-
const targets = [];
|
|
483
|
-
for (let i = 0; i < count; i++) {
|
|
484
|
-
const controller = readU8(payload, offset) >>> 0;
|
|
485
|
-
const location = readU8(payload, offset + 1) >>> 0;
|
|
486
|
-
const sequence = readU8(payload, offset + 2) >>> 0;
|
|
487
|
-
targets.push({ controller, location, sequence });
|
|
488
|
-
offset += 4;
|
|
489
|
-
}
|
|
490
|
-
info.targetCards = targets;
|
|
491
|
-
}
|
|
492
|
-
if (flags & OcgcoreCommonConstants.QUERY_OVERLAY_CARD) {
|
|
493
|
-
const count = readI32(payload, offset);
|
|
494
|
-
offset += 4;
|
|
495
|
-
const overlay = [];
|
|
496
|
-
for (let i = 0; i < count; i++) {
|
|
497
|
-
overlay.push(readI32(payload, offset));
|
|
498
|
-
offset += 4;
|
|
499
|
-
}
|
|
500
|
-
info.overlayCards = overlay;
|
|
501
|
-
}
|
|
502
|
-
if (flags & OcgcoreCommonConstants.QUERY_COUNTERS) {
|
|
503
|
-
const count = readI32(payload, offset);
|
|
504
|
-
offset += 4;
|
|
505
|
-
const counters = [];
|
|
506
|
-
for (let i = 0; i < count; i++) {
|
|
507
|
-
const type = readU16(payload, offset) >>> 0;
|
|
508
|
-
const ccount = readU16(payload, offset + 2) >>> 0;
|
|
509
|
-
counters.push({ type, count: ccount });
|
|
510
|
-
offset += 4;
|
|
511
|
-
}
|
|
512
|
-
info.counters = counters;
|
|
513
|
-
}
|
|
514
|
-
if (flags & OcgcoreCommonConstants.QUERY_OWNER) {
|
|
515
|
-
info.owner = readI32(payload, offset);
|
|
516
|
-
offset += 4;
|
|
517
|
-
}
|
|
518
|
-
if (flags & OcgcoreCommonConstants.QUERY_STATUS) {
|
|
519
|
-
info.status = readI32(payload, offset);
|
|
520
|
-
offset += 4;
|
|
521
|
-
}
|
|
522
|
-
if (flags & OcgcoreCommonConstants.QUERY_LSCALE) {
|
|
523
|
-
info.lscale = readI32(payload, offset);
|
|
524
|
-
offset += 4;
|
|
525
|
-
}
|
|
526
|
-
if (flags & OcgcoreCommonConstants.QUERY_RSCALE) {
|
|
527
|
-
info.rscale = readI32(payload, offset);
|
|
528
|
-
offset += 4;
|
|
529
|
-
}
|
|
530
|
-
if (flags & OcgcoreCommonConstants.QUERY_LINK) {
|
|
531
|
-
info.link = readI32(payload, offset);
|
|
532
|
-
offset += 4;
|
|
533
|
-
info.linkMarker = readI32(payload, offset);
|
|
534
|
-
offset += 4;
|
|
535
|
-
}
|
|
536
|
-
return info;
|
|
537
|
-
}
|
|
407
|
+
import { CardQuery, YGOProMsgReloadField } from "ygopro-msg-encode";
|
|
538
408
|
function parseCardQuery(raw, length) {
|
|
539
409
|
if (length <= LEN_HEADER) {
|
|
540
410
|
return null;
|
|
541
411
|
}
|
|
542
412
|
const payload = raw.subarray(4, length);
|
|
543
|
-
return
|
|
413
|
+
return new CardQuery().fromPayload(payload);
|
|
544
414
|
}
|
|
545
415
|
function parseFieldCardQuery(raw, length) {
|
|
546
416
|
const cards = [];
|
|
@@ -552,85 +422,20 @@ function parseFieldCardQuery(raw, length) {
|
|
|
552
422
|
}
|
|
553
423
|
const end = Math.min(length, offset + chunkLen);
|
|
554
424
|
if (chunkLen <= LEN_HEADER) {
|
|
555
|
-
|
|
425
|
+
const emptyCard = new CardQuery();
|
|
426
|
+
emptyCard.flags = 0;
|
|
427
|
+
emptyCard.empty = true;
|
|
428
|
+
cards.push(emptyCard);
|
|
556
429
|
} else {
|
|
557
430
|
const payload = raw.subarray(offset + 4, end);
|
|
558
|
-
cards.push(
|
|
431
|
+
cards.push(new CardQuery().fromPayload(payload));
|
|
559
432
|
}
|
|
560
433
|
offset += chunkLen;
|
|
561
434
|
}
|
|
562
435
|
return cards;
|
|
563
436
|
}
|
|
564
437
|
function parseFieldInfo(raw) {
|
|
565
|
-
|
|
566
|
-
const message = readU8(raw, offset++) >>> 0;
|
|
567
|
-
const duelRule = readU8(raw, offset++) >>> 0;
|
|
568
|
-
const players = [];
|
|
569
|
-
for (let i = 0; i < 2; i++) {
|
|
570
|
-
const lp = readI32(raw, offset) >>> 0;
|
|
571
|
-
offset += 4;
|
|
572
|
-
const mzone = [];
|
|
573
|
-
for (let seq = 0; seq < 7; seq++) {
|
|
574
|
-
const occupied = readU8(raw, offset++) >>> 0 !== 0;
|
|
575
|
-
if (occupied) {
|
|
576
|
-
const position = readU8(raw, offset++) >>> 0;
|
|
577
|
-
const xyzCount = readU8(raw, offset++) >>> 0;
|
|
578
|
-
mzone.push({ occupied, position, xyzCount });
|
|
579
|
-
} else {
|
|
580
|
-
mzone.push({ occupied });
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
const szone = [];
|
|
584
|
-
for (let seq = 0; seq < 8; seq++) {
|
|
585
|
-
const occupied = readU8(raw, offset++) >>> 0 !== 0;
|
|
586
|
-
if (occupied) {
|
|
587
|
-
const position = readU8(raw, offset++) >>> 0;
|
|
588
|
-
szone.push({ occupied, position });
|
|
589
|
-
} else {
|
|
590
|
-
szone.push({ occupied });
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
const deckCount = readU8(raw, offset++) >>> 0;
|
|
594
|
-
const handCount = readU8(raw, offset++) >>> 0;
|
|
595
|
-
const graveCount = readU8(raw, offset++) >>> 0;
|
|
596
|
-
const removedCount = readU8(raw, offset++) >>> 0;
|
|
597
|
-
const extraCount = readU8(raw, offset++) >>> 0;
|
|
598
|
-
const extraPCount = readU8(raw, offset++) >>> 0;
|
|
599
|
-
players[i] = {
|
|
600
|
-
lp,
|
|
601
|
-
mzone,
|
|
602
|
-
szone,
|
|
603
|
-
deckCount,
|
|
604
|
-
handCount,
|
|
605
|
-
graveCount,
|
|
606
|
-
removedCount,
|
|
607
|
-
extraCount,
|
|
608
|
-
extraPCount
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
const chainCount = readU8(raw, offset++) >>> 0;
|
|
612
|
-
const chains = [];
|
|
613
|
-
for (let i = 0; i < chainCount; i++) {
|
|
614
|
-
const code = readU32(raw, offset) >>> 0;
|
|
615
|
-
offset += 4;
|
|
616
|
-
const infoLocation = readU32(raw, offset) >>> 0;
|
|
617
|
-
offset += 4;
|
|
618
|
-
const chainCard = {
|
|
619
|
-
controller: (infoLocation & 255) >>> 0,
|
|
620
|
-
location: (infoLocation >>> 8 & 255) >>> 0,
|
|
621
|
-
sequence: (infoLocation >>> 16 & 255) >>> 0,
|
|
622
|
-
subSequence: (infoLocation >>> 24 & 255) >>> 0
|
|
623
|
-
};
|
|
624
|
-
const trigger = {
|
|
625
|
-
controller: readU8(raw, offset++) >>> 0,
|
|
626
|
-
location: readU8(raw, offset++) >>> 0,
|
|
627
|
-
sequence: readU8(raw, offset++) >>> 0
|
|
628
|
-
};
|
|
629
|
-
const description = readU32(raw, offset) >>> 0;
|
|
630
|
-
offset += 4;
|
|
631
|
-
chains.push({ code, chainCard, trigger, description });
|
|
632
|
-
}
|
|
633
|
-
return { message, duelRule, players, chains };
|
|
438
|
+
return new YGOProMsgReloadField().fromPayload(raw);
|
|
634
439
|
}
|
|
635
440
|
function parseRegistryKeys(raw) {
|
|
636
441
|
const keys = [];
|
|
@@ -687,6 +492,7 @@ function normalizeStartDuelOptions(options) {
|
|
|
687
492
|
}
|
|
688
493
|
|
|
689
494
|
// src/ocgcore-duel.ts
|
|
495
|
+
import { YGOProMessages } from "ygopro-msg-encode";
|
|
690
496
|
var OcgcoreDuel = class {
|
|
691
497
|
constructor(ocgcoreWrapper, duelPtr) {
|
|
692
498
|
this.ocgcoreWrapper = ocgcoreWrapper;
|
|
@@ -712,9 +518,9 @@ var OcgcoreDuel = class {
|
|
|
712
518
|
setPlayerInfo(info) {
|
|
713
519
|
this.ocgcoreWrapper.ocgcoreModule._set_player_info(
|
|
714
520
|
this.duelPtr,
|
|
715
|
-
info.
|
|
521
|
+
info.player,
|
|
716
522
|
info.lp,
|
|
717
|
-
info.
|
|
523
|
+
info.startHand,
|
|
718
524
|
info.drawCount
|
|
719
525
|
);
|
|
720
526
|
}
|
|
@@ -735,15 +541,27 @@ var OcgcoreDuel = class {
|
|
|
735
541
|
const result = this.ocgcoreWrapper.ocgcoreModule._process(this.duelPtr);
|
|
736
542
|
const length = (result & 268435455) >>> 0;
|
|
737
543
|
const status = (result >>> 28 & 15) >>> 0;
|
|
738
|
-
const
|
|
739
|
-
|
|
544
|
+
const messageData = this.getMessage(length);
|
|
545
|
+
let parsedMessage;
|
|
546
|
+
if (messageData.raw.length > 0) {
|
|
547
|
+
try {
|
|
548
|
+
parsedMessage = YGOProMessages.getInstanceFromPayload(messageData.raw);
|
|
549
|
+
} catch (e) {
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
length: messageData.length,
|
|
554
|
+
raw: messageData.raw,
|
|
555
|
+
status,
|
|
556
|
+
message: parsedMessage
|
|
557
|
+
};
|
|
740
558
|
}
|
|
741
559
|
newCard(card) {
|
|
742
560
|
this.ocgcoreWrapper.ocgcoreModule._new_card(
|
|
743
561
|
this.duelPtr,
|
|
744
562
|
card.code,
|
|
745
563
|
card.owner,
|
|
746
|
-
card.
|
|
564
|
+
card.player,
|
|
747
565
|
card.location,
|
|
748
566
|
card.sequence,
|
|
749
567
|
card.position
|
|
@@ -761,7 +579,7 @@ var OcgcoreDuel = class {
|
|
|
761
579
|
const ptr = this.ocgcoreWrapper.malloc(QUERY_BUFFER_SIZE);
|
|
762
580
|
const length = this.ocgcoreWrapper.ocgcoreModule._query_card(
|
|
763
581
|
this.duelPtr,
|
|
764
|
-
query.
|
|
582
|
+
query.player,
|
|
765
583
|
query.location,
|
|
766
584
|
query.sequence,
|
|
767
585
|
query.queryFlag,
|
|
@@ -776,7 +594,7 @@ var OcgcoreDuel = class {
|
|
|
776
594
|
queryFieldCount(query) {
|
|
777
595
|
return this.ocgcoreWrapper.ocgcoreModule._query_field_count(
|
|
778
596
|
this.duelPtr,
|
|
779
|
-
query.
|
|
597
|
+
query.player,
|
|
780
598
|
query.location
|
|
781
599
|
);
|
|
782
600
|
}
|
|
@@ -784,7 +602,7 @@ var OcgcoreDuel = class {
|
|
|
784
602
|
const ptr = this.ocgcoreWrapper.malloc(QUERY_BUFFER_SIZE);
|
|
785
603
|
const length = this.ocgcoreWrapper.ocgcoreModule._query_field_card(
|
|
786
604
|
this.duelPtr,
|
|
787
|
-
query.
|
|
605
|
+
query.player,
|
|
788
606
|
query.location,
|
|
789
607
|
query.queryFlag,
|
|
790
608
|
ptr,
|
|
@@ -828,13 +646,11 @@ var OcgcoreDuel = class {
|
|
|
828
646
|
);
|
|
829
647
|
}
|
|
830
648
|
getRegistryValue(key) {
|
|
831
|
-
const keyBytes = encodeUtf8(key);
|
|
832
649
|
const outPtr = this.ocgcoreWrapper.malloc(REGISTRY_BUFFER_SIZE);
|
|
833
650
|
const length = this.ocgcoreWrapper.useTmpData(
|
|
834
651
|
(keyPtr) => this.ocgcoreWrapper.ocgcoreModule._get_registry_value(
|
|
835
652
|
this.duelPtr,
|
|
836
653
|
keyPtr,
|
|
837
|
-
keyBytes.length,
|
|
838
654
|
outPtr
|
|
839
655
|
),
|
|
840
656
|
key
|
|
@@ -846,15 +662,11 @@ var OcgcoreDuel = class {
|
|
|
846
662
|
return { length, raw, value, text };
|
|
847
663
|
}
|
|
848
664
|
setRegistryValue(key, value) {
|
|
849
|
-
const keyBytes = encodeUtf8(key);
|
|
850
|
-
const valueBytes = encodeUtf8(value);
|
|
851
665
|
this.ocgcoreWrapper.useTmpData(
|
|
852
666
|
(keyPtr, valuePtr) => this.ocgcoreWrapper.ocgcoreModule._set_registry_value(
|
|
853
667
|
this.duelPtr,
|
|
854
668
|
keyPtr,
|
|
855
|
-
|
|
856
|
-
valuePtr,
|
|
857
|
-
valueBytes.length
|
|
669
|
+
valuePtr
|
|
858
670
|
),
|
|
859
671
|
key,
|
|
860
672
|
value
|
|
@@ -882,24 +694,88 @@ var OcgcoreDuel = class {
|
|
|
882
694
|
);
|
|
883
695
|
const raw = this.ocgcoreWrapper.copyHeap(outPtr, Math.max(0, length));
|
|
884
696
|
this.ocgcoreWrapper.free(outPtr);
|
|
885
|
-
const
|
|
886
|
-
|
|
697
|
+
const dict = {};
|
|
698
|
+
if (length > 0) {
|
|
699
|
+
const entries = parseRegistryDump(raw);
|
|
700
|
+
for (const entry of entries) {
|
|
701
|
+
if (entry.valueText !== void 0) {
|
|
702
|
+
dict[entry.key] = entry.valueText;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return { length, raw, dict };
|
|
887
707
|
}
|
|
888
708
|
loadRegistry(input) {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
this.
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
709
|
+
if (input instanceof Uint8Array) {
|
|
710
|
+
this.ocgcoreWrapper.useTmpData(
|
|
711
|
+
(ptr) => this.ocgcoreWrapper.ocgcoreModule._load_registry(
|
|
712
|
+
this.duelPtr,
|
|
713
|
+
ptr,
|
|
714
|
+
input.length
|
|
715
|
+
),
|
|
716
|
+
input
|
|
717
|
+
);
|
|
718
|
+
} else {
|
|
719
|
+
for (const [key, value] of Object.entries(input)) {
|
|
720
|
+
this.setRegistryValue(key, value);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
897
723
|
}
|
|
898
724
|
};
|
|
899
725
|
|
|
900
726
|
// src/structs/card-data.ts
|
|
901
|
-
import
|
|
902
|
-
|
|
727
|
+
import {
|
|
728
|
+
BinaryField,
|
|
729
|
+
fillBinaryFields,
|
|
730
|
+
toBinaryFields
|
|
731
|
+
} from "ygopro-msg-encode";
|
|
732
|
+
var _CardDataStruct = class _CardDataStruct {
|
|
733
|
+
static fromBytes(data) {
|
|
734
|
+
const obj = new _CardDataStruct();
|
|
735
|
+
fillBinaryFields(obj, data, _CardDataStruct);
|
|
736
|
+
return obj;
|
|
737
|
+
}
|
|
738
|
+
toBytes() {
|
|
739
|
+
return toBinaryFields(this, _CardDataStruct);
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
__decorateClass([
|
|
743
|
+
BinaryField("u32", 0)
|
|
744
|
+
], _CardDataStruct.prototype, "code", 2);
|
|
745
|
+
__decorateClass([
|
|
746
|
+
BinaryField("u32", 4)
|
|
747
|
+
], _CardDataStruct.prototype, "alias", 2);
|
|
748
|
+
__decorateClass([
|
|
749
|
+
BinaryField("u16", 8, 16)
|
|
750
|
+
], _CardDataStruct.prototype, "setcode", 2);
|
|
751
|
+
__decorateClass([
|
|
752
|
+
BinaryField("u32", 40)
|
|
753
|
+
], _CardDataStruct.prototype, "type", 2);
|
|
754
|
+
__decorateClass([
|
|
755
|
+
BinaryField("u32", 44)
|
|
756
|
+
], _CardDataStruct.prototype, "level", 2);
|
|
757
|
+
__decorateClass([
|
|
758
|
+
BinaryField("u32", 48)
|
|
759
|
+
], _CardDataStruct.prototype, "attribute", 2);
|
|
760
|
+
__decorateClass([
|
|
761
|
+
BinaryField("u32", 52)
|
|
762
|
+
], _CardDataStruct.prototype, "race", 2);
|
|
763
|
+
__decorateClass([
|
|
764
|
+
BinaryField("i32", 56)
|
|
765
|
+
], _CardDataStruct.prototype, "attack", 2);
|
|
766
|
+
__decorateClass([
|
|
767
|
+
BinaryField("i32", 60)
|
|
768
|
+
], _CardDataStruct.prototype, "defense", 2);
|
|
769
|
+
__decorateClass([
|
|
770
|
+
BinaryField("u32", 64)
|
|
771
|
+
], _CardDataStruct.prototype, "lscale", 2);
|
|
772
|
+
__decorateClass([
|
|
773
|
+
BinaryField("u32", 68)
|
|
774
|
+
], _CardDataStruct.prototype, "rscale", 2);
|
|
775
|
+
__decorateClass([
|
|
776
|
+
BinaryField("u32", 72)
|
|
777
|
+
], _CardDataStruct.prototype, "linkMarker", 2);
|
|
778
|
+
var CardDataStruct = _CardDataStruct;
|
|
903
779
|
|
|
904
780
|
// src/types/ocgcore-enums.ts
|
|
905
781
|
var OcgcoreMessageType = /* @__PURE__ */ ((OcgcoreMessageType2) => {
|
|
@@ -997,15 +873,14 @@ var OcgcoreWrapper = class {
|
|
|
997
873
|
if (!data) {
|
|
998
874
|
return 0;
|
|
999
875
|
}
|
|
1000
|
-
const CardDataCtor = CardDataStruct;
|
|
1001
876
|
let buf;
|
|
1002
|
-
if (data instanceof
|
|
1003
|
-
buf =
|
|
877
|
+
if (data instanceof CardDataStruct) {
|
|
878
|
+
buf = data.toBytes();
|
|
1004
879
|
} else {
|
|
1005
|
-
const cardData = new
|
|
880
|
+
const cardData = new CardDataStruct();
|
|
1006
881
|
cardData.code = data.code;
|
|
1007
882
|
cardData.alias = data.alias;
|
|
1008
|
-
const targetSetcode =
|
|
883
|
+
const targetSetcode = new Uint16Array(16);
|
|
1009
884
|
targetSetcode.fill(0);
|
|
1010
885
|
if (data.setcode instanceof Uint16Array && data.setcode.length === 16) {
|
|
1011
886
|
targetSetcode.set(data.setcode);
|
|
@@ -1014,6 +889,7 @@ var OcgcoreWrapper = class {
|
|
|
1014
889
|
targetSetcode[i] = data.setcode[i];
|
|
1015
890
|
}
|
|
1016
891
|
}
|
|
892
|
+
cardData.setcode = targetSetcode;
|
|
1017
893
|
cardData.type = data.type;
|
|
1018
894
|
cardData.level = data.level;
|
|
1019
895
|
cardData.attribute = data.attribute;
|
|
@@ -1023,7 +899,7 @@ var OcgcoreWrapper = class {
|
|
|
1023
899
|
cardData.lscale = data.lscale;
|
|
1024
900
|
cardData.rscale = data.rscale;
|
|
1025
901
|
cardData.linkMarker = data.linkMarker;
|
|
1026
|
-
buf =
|
|
902
|
+
buf = cardData.toBytes();
|
|
1027
903
|
}
|
|
1028
904
|
this.heapU8.set(buf, cardDataPtr);
|
|
1029
905
|
return 0;
|
|
@@ -2313,13 +2189,13 @@ function createReplayDuel(wrapper, yrp) {
|
|
|
2313
2189
|
}
|
|
2314
2190
|
return wrapper.createDuel(header?.seed ?? 0);
|
|
2315
2191
|
}
|
|
2316
|
-
function loadDeck(duel, deck, owner,
|
|
2192
|
+
function loadDeck(duel, deck, owner, player) {
|
|
2317
2193
|
if (!deck) return;
|
|
2318
2194
|
for (const code of deck.main ?? []) {
|
|
2319
2195
|
duel.newCard({
|
|
2320
2196
|
code,
|
|
2321
2197
|
owner,
|
|
2322
|
-
|
|
2198
|
+
player,
|
|
2323
2199
|
location: LOCATION_DECK,
|
|
2324
2200
|
sequence: 0,
|
|
2325
2201
|
position: POS_FACEDOWN_DEFENSE
|
|
@@ -2329,7 +2205,7 @@ function loadDeck(duel, deck, owner, playerId) {
|
|
|
2329
2205
|
duel.newCard({
|
|
2330
2206
|
code,
|
|
2331
2207
|
owner,
|
|
2332
|
-
|
|
2208
|
+
player,
|
|
2333
2209
|
location: LOCATION_EXTRA,
|
|
2334
2210
|
sequence: 0,
|
|
2335
2211
|
position: POS_FACEDOWN_DEFENSE
|
|
@@ -2383,15 +2259,15 @@ function* playYrpStep(ocgcoreWrapper, yrpInput) {
|
|
|
2383
2259
|
setRegistryValue(duel, "player_type_0", "0");
|
|
2384
2260
|
setRegistryValue(duel, "player_type_1", "1");
|
|
2385
2261
|
duel.setPlayerInfo({
|
|
2386
|
-
|
|
2262
|
+
player: 0,
|
|
2387
2263
|
lp: yrp.startLp,
|
|
2388
|
-
|
|
2264
|
+
startHand: yrp.startHand,
|
|
2389
2265
|
drawCount: yrp.drawCount
|
|
2390
2266
|
});
|
|
2391
2267
|
duel.setPlayerInfo({
|
|
2392
|
-
|
|
2268
|
+
player: 1,
|
|
2393
2269
|
lp: yrp.startLp,
|
|
2394
|
-
|
|
2270
|
+
startHand: yrp.startHand,
|
|
2395
2271
|
drawCount: yrp.drawCount
|
|
2396
2272
|
});
|
|
2397
2273
|
duel.preloadScript("./script/patches/entry.lua");
|
|
@@ -2462,13 +2338,13 @@ function testCard(ocgcoreWrapper, ...ids) {
|
|
|
2462
2338
|
});
|
|
2463
2339
|
duel.preloadScript("./script/special.lua");
|
|
2464
2340
|
duel.preloadScript("./script/init.lua");
|
|
2465
|
-
duel.setPlayerInfo({
|
|
2466
|
-
duel.setPlayerInfo({
|
|
2341
|
+
duel.setPlayerInfo({ player: 0, lp: 8e3, startHand: 5, drawCount: 1 });
|
|
2342
|
+
duel.setPlayerInfo({ player: 1, lp: 8e3, startHand: 5, drawCount: 1 });
|
|
2467
2343
|
for (const code of ids) {
|
|
2468
2344
|
duel.newCard({
|
|
2469
2345
|
code,
|
|
2470
2346
|
owner: 0,
|
|
2471
|
-
|
|
2347
|
+
player: 0,
|
|
2472
2348
|
location: LOCATION_DECK2,
|
|
2473
2349
|
sequence: 0,
|
|
2474
2350
|
position: POS_FACEUP_ATTACK
|
|
@@ -2491,7 +2367,7 @@ function testCard(ocgcoreWrapper, ...ids) {
|
|
|
2491
2367
|
|
|
2492
2368
|
// index.ts
|
|
2493
2369
|
if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
2494
|
-
globalThis.Buffer =
|
|
2370
|
+
globalThis.Buffer = Buffer2;
|
|
2495
2371
|
}
|
|
2496
2372
|
export {
|
|
2497
2373
|
CardDataStruct,
|