koishipro-core.js 1.0.9 → 1.1.0
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 +146 -269
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +154 -271
- 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/play-yrp.d.ts +7 -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/src/utility/load-node-module.d.ts +0 -1
- package/dist/vendor/libocgcore.shared.d.ts +7 -7
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
29
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
30
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
31
|
+
if (decorator = decorators[i])
|
|
32
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
33
|
+
if (kind && result) __defProp(target, key, result);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
28
36
|
|
|
29
37
|
// index.ts
|
|
30
38
|
var index_exports = {};
|
|
@@ -55,6 +63,7 @@ __export(index_exports, {
|
|
|
55
63
|
parseRegistryDump: () => parseRegistryDump,
|
|
56
64
|
parseRegistryKeys: () => parseRegistryKeys,
|
|
57
65
|
playYrp: () => playYrp,
|
|
66
|
+
playYrpStep: () => playYrpStep,
|
|
58
67
|
testCard: () => testCard
|
|
59
68
|
});
|
|
60
69
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -431,9 +440,6 @@ var LEN_EMPTY = 4;
|
|
|
431
440
|
var LEN_HEADER = 8;
|
|
432
441
|
|
|
433
442
|
// src/utility/binary.ts
|
|
434
|
-
function readU8(buf, offset) {
|
|
435
|
-
return buf[offset] ?? 0;
|
|
436
|
-
}
|
|
437
443
|
function readU16(buf, offset) {
|
|
438
444
|
return new DataView(buf.buffer, buf.byteOffset, buf.byteLength).getUint16(
|
|
439
445
|
offset,
|
|
@@ -446,160 +452,22 @@ function readI32(buf, offset) {
|
|
|
446
452
|
true
|
|
447
453
|
);
|
|
448
454
|
}
|
|
449
|
-
function readU32(buf, offset) {
|
|
450
|
-
return new DataView(buf.buffer, buf.byteOffset, buf.byteLength).getUint32(
|
|
451
|
-
offset,
|
|
452
|
-
true
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
455
|
|
|
456
456
|
// src/utility/utf8.ts
|
|
457
457
|
var encoder = new TextEncoder();
|
|
458
458
|
var decoder = new TextDecoder("utf-8");
|
|
459
|
-
function encodeUtf8(value) {
|
|
460
|
-
return encoder.encode(value);
|
|
461
|
-
}
|
|
462
459
|
function decodeUtf8(value) {
|
|
463
460
|
return decoder.decode(value);
|
|
464
461
|
}
|
|
465
462
|
|
|
466
463
|
// src/adapters/ocgcore-parsers.ts
|
|
467
|
-
|
|
468
|
-
let offset = 0;
|
|
469
|
-
const flags = readI32(payload, offset) >>> 0;
|
|
470
|
-
offset += 4;
|
|
471
|
-
const info = { flags, empty: flags === 0 };
|
|
472
|
-
if (flags === 0) {
|
|
473
|
-
return info;
|
|
474
|
-
}
|
|
475
|
-
if (flags & OcgcoreCommonConstants.QUERY_CODE) {
|
|
476
|
-
info.code = readI32(payload, offset);
|
|
477
|
-
offset += 4;
|
|
478
|
-
}
|
|
479
|
-
if (flags & OcgcoreCommonConstants.QUERY_POSITION) {
|
|
480
|
-
const pdata = readI32(payload, offset);
|
|
481
|
-
offset += 4;
|
|
482
|
-
info.position = (pdata >>> 24 & 255) >>> 0;
|
|
483
|
-
}
|
|
484
|
-
if (flags & OcgcoreCommonConstants.QUERY_ALIAS) {
|
|
485
|
-
info.alias = readI32(payload, offset);
|
|
486
|
-
offset += 4;
|
|
487
|
-
}
|
|
488
|
-
if (flags & OcgcoreCommonConstants.QUERY_TYPE) {
|
|
489
|
-
info.type = readI32(payload, offset);
|
|
490
|
-
offset += 4;
|
|
491
|
-
}
|
|
492
|
-
if (flags & OcgcoreCommonConstants.QUERY_LEVEL) {
|
|
493
|
-
info.level = readI32(payload, offset);
|
|
494
|
-
offset += 4;
|
|
495
|
-
}
|
|
496
|
-
if (flags & OcgcoreCommonConstants.QUERY_RANK) {
|
|
497
|
-
info.rank = readI32(payload, offset);
|
|
498
|
-
offset += 4;
|
|
499
|
-
}
|
|
500
|
-
if (flags & OcgcoreCommonConstants.QUERY_ATTRIBUTE) {
|
|
501
|
-
info.attribute = readI32(payload, offset);
|
|
502
|
-
offset += 4;
|
|
503
|
-
}
|
|
504
|
-
if (flags & OcgcoreCommonConstants.QUERY_RACE) {
|
|
505
|
-
info.race = readI32(payload, offset);
|
|
506
|
-
offset += 4;
|
|
507
|
-
}
|
|
508
|
-
if (flags & OcgcoreCommonConstants.QUERY_ATTACK) {
|
|
509
|
-
info.attack = readI32(payload, offset);
|
|
510
|
-
offset += 4;
|
|
511
|
-
}
|
|
512
|
-
if (flags & OcgcoreCommonConstants.QUERY_DEFENSE) {
|
|
513
|
-
info.defense = readI32(payload, offset);
|
|
514
|
-
offset += 4;
|
|
515
|
-
}
|
|
516
|
-
if (flags & OcgcoreCommonConstants.QUERY_BASE_ATTACK) {
|
|
517
|
-
info.baseAttack = readI32(payload, offset);
|
|
518
|
-
offset += 4;
|
|
519
|
-
}
|
|
520
|
-
if (flags & OcgcoreCommonConstants.QUERY_BASE_DEFENSE) {
|
|
521
|
-
info.baseDefense = readI32(payload, offset);
|
|
522
|
-
offset += 4;
|
|
523
|
-
}
|
|
524
|
-
if (flags & OcgcoreCommonConstants.QUERY_REASON) {
|
|
525
|
-
info.reason = readI32(payload, offset);
|
|
526
|
-
offset += 4;
|
|
527
|
-
}
|
|
528
|
-
if (flags & OcgcoreCommonConstants.QUERY_REASON_CARD) {
|
|
529
|
-
offset += 4;
|
|
530
|
-
}
|
|
531
|
-
if (flags & OcgcoreCommonConstants.QUERY_EQUIP_CARD) {
|
|
532
|
-
const controller = readU8(payload, offset) >>> 0;
|
|
533
|
-
const location = readU8(payload, offset + 1) >>> 0;
|
|
534
|
-
const sequence = readU8(payload, offset + 2) >>> 0;
|
|
535
|
-
info.equipCard = { controller, location, sequence };
|
|
536
|
-
offset += 4;
|
|
537
|
-
}
|
|
538
|
-
if (flags & OcgcoreCommonConstants.QUERY_TARGET_CARD) {
|
|
539
|
-
const count = readI32(payload, offset);
|
|
540
|
-
offset += 4;
|
|
541
|
-
const targets = [];
|
|
542
|
-
for (let i = 0; i < count; i++) {
|
|
543
|
-
const controller = readU8(payload, offset) >>> 0;
|
|
544
|
-
const location = readU8(payload, offset + 1) >>> 0;
|
|
545
|
-
const sequence = readU8(payload, offset + 2) >>> 0;
|
|
546
|
-
targets.push({ controller, location, sequence });
|
|
547
|
-
offset += 4;
|
|
548
|
-
}
|
|
549
|
-
info.targetCards = targets;
|
|
550
|
-
}
|
|
551
|
-
if (flags & OcgcoreCommonConstants.QUERY_OVERLAY_CARD) {
|
|
552
|
-
const count = readI32(payload, offset);
|
|
553
|
-
offset += 4;
|
|
554
|
-
const overlay = [];
|
|
555
|
-
for (let i = 0; i < count; i++) {
|
|
556
|
-
overlay.push(readI32(payload, offset));
|
|
557
|
-
offset += 4;
|
|
558
|
-
}
|
|
559
|
-
info.overlayCards = overlay;
|
|
560
|
-
}
|
|
561
|
-
if (flags & OcgcoreCommonConstants.QUERY_COUNTERS) {
|
|
562
|
-
const count = readI32(payload, offset);
|
|
563
|
-
offset += 4;
|
|
564
|
-
const counters = [];
|
|
565
|
-
for (let i = 0; i < count; i++) {
|
|
566
|
-
const type = readU16(payload, offset) >>> 0;
|
|
567
|
-
const ccount = readU16(payload, offset + 2) >>> 0;
|
|
568
|
-
counters.push({ type, count: ccount });
|
|
569
|
-
offset += 4;
|
|
570
|
-
}
|
|
571
|
-
info.counters = counters;
|
|
572
|
-
}
|
|
573
|
-
if (flags & OcgcoreCommonConstants.QUERY_OWNER) {
|
|
574
|
-
info.owner = readI32(payload, offset);
|
|
575
|
-
offset += 4;
|
|
576
|
-
}
|
|
577
|
-
if (flags & OcgcoreCommonConstants.QUERY_STATUS) {
|
|
578
|
-
info.status = readI32(payload, offset);
|
|
579
|
-
offset += 4;
|
|
580
|
-
}
|
|
581
|
-
if (flags & OcgcoreCommonConstants.QUERY_LSCALE) {
|
|
582
|
-
info.lscale = readI32(payload, offset);
|
|
583
|
-
offset += 4;
|
|
584
|
-
}
|
|
585
|
-
if (flags & OcgcoreCommonConstants.QUERY_RSCALE) {
|
|
586
|
-
info.rscale = readI32(payload, offset);
|
|
587
|
-
offset += 4;
|
|
588
|
-
}
|
|
589
|
-
if (flags & OcgcoreCommonConstants.QUERY_LINK) {
|
|
590
|
-
info.link = readI32(payload, offset);
|
|
591
|
-
offset += 4;
|
|
592
|
-
info.linkMarker = readI32(payload, offset);
|
|
593
|
-
offset += 4;
|
|
594
|
-
}
|
|
595
|
-
return info;
|
|
596
|
-
}
|
|
464
|
+
var import_ygopro_msg_encode = require("ygopro-msg-encode");
|
|
597
465
|
function parseCardQuery(raw, length) {
|
|
598
466
|
if (length <= LEN_HEADER) {
|
|
599
467
|
return null;
|
|
600
468
|
}
|
|
601
469
|
const payload = raw.subarray(4, length);
|
|
602
|
-
return
|
|
470
|
+
return new import_ygopro_msg_encode.CardQuery().fromPayload(payload);
|
|
603
471
|
}
|
|
604
472
|
function parseFieldCardQuery(raw, length) {
|
|
605
473
|
const cards = [];
|
|
@@ -611,85 +479,20 @@ function parseFieldCardQuery(raw, length) {
|
|
|
611
479
|
}
|
|
612
480
|
const end = Math.min(length, offset + chunkLen);
|
|
613
481
|
if (chunkLen <= LEN_HEADER) {
|
|
614
|
-
|
|
482
|
+
const emptyCard = new import_ygopro_msg_encode.CardQuery();
|
|
483
|
+
emptyCard.flags = 0;
|
|
484
|
+
emptyCard.empty = true;
|
|
485
|
+
cards.push(emptyCard);
|
|
615
486
|
} else {
|
|
616
487
|
const payload = raw.subarray(offset + 4, end);
|
|
617
|
-
cards.push(
|
|
488
|
+
cards.push(new import_ygopro_msg_encode.CardQuery().fromPayload(payload));
|
|
618
489
|
}
|
|
619
490
|
offset += chunkLen;
|
|
620
491
|
}
|
|
621
492
|
return cards;
|
|
622
493
|
}
|
|
623
494
|
function parseFieldInfo(raw) {
|
|
624
|
-
|
|
625
|
-
const message = readU8(raw, offset++) >>> 0;
|
|
626
|
-
const duelRule = readU8(raw, offset++) >>> 0;
|
|
627
|
-
const players = [];
|
|
628
|
-
for (let i = 0; i < 2; i++) {
|
|
629
|
-
const lp = readI32(raw, offset) >>> 0;
|
|
630
|
-
offset += 4;
|
|
631
|
-
const mzone = [];
|
|
632
|
-
for (let seq = 0; seq < 7; seq++) {
|
|
633
|
-
const occupied = readU8(raw, offset++) >>> 0 !== 0;
|
|
634
|
-
if (occupied) {
|
|
635
|
-
const position = readU8(raw, offset++) >>> 0;
|
|
636
|
-
const xyzCount = readU8(raw, offset++) >>> 0;
|
|
637
|
-
mzone.push({ occupied, position, xyzCount });
|
|
638
|
-
} else {
|
|
639
|
-
mzone.push({ occupied });
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
const szone = [];
|
|
643
|
-
for (let seq = 0; seq < 8; seq++) {
|
|
644
|
-
const occupied = readU8(raw, offset++) >>> 0 !== 0;
|
|
645
|
-
if (occupied) {
|
|
646
|
-
const position = readU8(raw, offset++) >>> 0;
|
|
647
|
-
szone.push({ occupied, position });
|
|
648
|
-
} else {
|
|
649
|
-
szone.push({ occupied });
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
const deckCount = readU8(raw, offset++) >>> 0;
|
|
653
|
-
const handCount = readU8(raw, offset++) >>> 0;
|
|
654
|
-
const graveCount = readU8(raw, offset++) >>> 0;
|
|
655
|
-
const removedCount = readU8(raw, offset++) >>> 0;
|
|
656
|
-
const extraCount = readU8(raw, offset++) >>> 0;
|
|
657
|
-
const extraPCount = readU8(raw, offset++) >>> 0;
|
|
658
|
-
players[i] = {
|
|
659
|
-
lp,
|
|
660
|
-
mzone,
|
|
661
|
-
szone,
|
|
662
|
-
deckCount,
|
|
663
|
-
handCount,
|
|
664
|
-
graveCount,
|
|
665
|
-
removedCount,
|
|
666
|
-
extraCount,
|
|
667
|
-
extraPCount
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
const chainCount = readU8(raw, offset++) >>> 0;
|
|
671
|
-
const chains = [];
|
|
672
|
-
for (let i = 0; i < chainCount; i++) {
|
|
673
|
-
const code = readU32(raw, offset) >>> 0;
|
|
674
|
-
offset += 4;
|
|
675
|
-
const infoLocation = readU32(raw, offset) >>> 0;
|
|
676
|
-
offset += 4;
|
|
677
|
-
const chainCard = {
|
|
678
|
-
controller: (infoLocation & 255) >>> 0,
|
|
679
|
-
location: (infoLocation >>> 8 & 255) >>> 0,
|
|
680
|
-
sequence: (infoLocation >>> 16 & 255) >>> 0,
|
|
681
|
-
subSequence: (infoLocation >>> 24 & 255) >>> 0
|
|
682
|
-
};
|
|
683
|
-
const trigger = {
|
|
684
|
-
controller: readU8(raw, offset++) >>> 0,
|
|
685
|
-
location: readU8(raw, offset++) >>> 0,
|
|
686
|
-
sequence: readU8(raw, offset++) >>> 0
|
|
687
|
-
};
|
|
688
|
-
const description = readU32(raw, offset) >>> 0;
|
|
689
|
-
offset += 4;
|
|
690
|
-
chains.push({ code, chainCard, trigger, description });
|
|
691
|
-
}
|
|
692
|
-
return { message, duelRule, players, chains };
|
|
495
|
+
return new import_ygopro_msg_encode.YGOProMsgReloadField().fromPayload(raw);
|
|
693
496
|
}
|
|
694
497
|
function parseRegistryKeys(raw) {
|
|
695
498
|
const keys = [];
|
|
@@ -746,6 +549,7 @@ function normalizeStartDuelOptions(options) {
|
|
|
746
549
|
}
|
|
747
550
|
|
|
748
551
|
// src/ocgcore-duel.ts
|
|
552
|
+
var import_ygopro_msg_encode2 = require("ygopro-msg-encode");
|
|
749
553
|
var OcgcoreDuel = class {
|
|
750
554
|
constructor(ocgcoreWrapper, duelPtr) {
|
|
751
555
|
this.ocgcoreWrapper = ocgcoreWrapper;
|
|
@@ -771,9 +575,9 @@ var OcgcoreDuel = class {
|
|
|
771
575
|
setPlayerInfo(info) {
|
|
772
576
|
this.ocgcoreWrapper.ocgcoreModule._set_player_info(
|
|
773
577
|
this.duelPtr,
|
|
774
|
-
info.
|
|
578
|
+
info.player,
|
|
775
579
|
info.lp,
|
|
776
|
-
info.
|
|
580
|
+
info.startHand,
|
|
777
581
|
info.drawCount
|
|
778
582
|
);
|
|
779
583
|
}
|
|
@@ -794,15 +598,27 @@ var OcgcoreDuel = class {
|
|
|
794
598
|
const result = this.ocgcoreWrapper.ocgcoreModule._process(this.duelPtr);
|
|
795
599
|
const length = (result & 268435455) >>> 0;
|
|
796
600
|
const status = (result >>> 28 & 15) >>> 0;
|
|
797
|
-
const
|
|
798
|
-
|
|
601
|
+
const messageData = this.getMessage(length);
|
|
602
|
+
let parsedMessage;
|
|
603
|
+
if (messageData.raw.length > 0) {
|
|
604
|
+
try {
|
|
605
|
+
parsedMessage = import_ygopro_msg_encode2.YGOProMessages.getInstanceFromPayload(messageData.raw);
|
|
606
|
+
} catch (e) {
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return {
|
|
610
|
+
length: messageData.length,
|
|
611
|
+
raw: messageData.raw,
|
|
612
|
+
status,
|
|
613
|
+
message: parsedMessage
|
|
614
|
+
};
|
|
799
615
|
}
|
|
800
616
|
newCard(card) {
|
|
801
617
|
this.ocgcoreWrapper.ocgcoreModule._new_card(
|
|
802
618
|
this.duelPtr,
|
|
803
619
|
card.code,
|
|
804
620
|
card.owner,
|
|
805
|
-
card.
|
|
621
|
+
card.player,
|
|
806
622
|
card.location,
|
|
807
623
|
card.sequence,
|
|
808
624
|
card.position
|
|
@@ -820,7 +636,7 @@ var OcgcoreDuel = class {
|
|
|
820
636
|
const ptr = this.ocgcoreWrapper.malloc(QUERY_BUFFER_SIZE);
|
|
821
637
|
const length = this.ocgcoreWrapper.ocgcoreModule._query_card(
|
|
822
638
|
this.duelPtr,
|
|
823
|
-
query.
|
|
639
|
+
query.player,
|
|
824
640
|
query.location,
|
|
825
641
|
query.sequence,
|
|
826
642
|
query.queryFlag,
|
|
@@ -835,7 +651,7 @@ var OcgcoreDuel = class {
|
|
|
835
651
|
queryFieldCount(query) {
|
|
836
652
|
return this.ocgcoreWrapper.ocgcoreModule._query_field_count(
|
|
837
653
|
this.duelPtr,
|
|
838
|
-
query.
|
|
654
|
+
query.player,
|
|
839
655
|
query.location
|
|
840
656
|
);
|
|
841
657
|
}
|
|
@@ -843,7 +659,7 @@ var OcgcoreDuel = class {
|
|
|
843
659
|
const ptr = this.ocgcoreWrapper.malloc(QUERY_BUFFER_SIZE);
|
|
844
660
|
const length = this.ocgcoreWrapper.ocgcoreModule._query_field_card(
|
|
845
661
|
this.duelPtr,
|
|
846
|
-
query.
|
|
662
|
+
query.player,
|
|
847
663
|
query.location,
|
|
848
664
|
query.queryFlag,
|
|
849
665
|
ptr,
|
|
@@ -887,13 +703,11 @@ var OcgcoreDuel = class {
|
|
|
887
703
|
);
|
|
888
704
|
}
|
|
889
705
|
getRegistryValue(key) {
|
|
890
|
-
const keyBytes = encodeUtf8(key);
|
|
891
706
|
const outPtr = this.ocgcoreWrapper.malloc(REGISTRY_BUFFER_SIZE);
|
|
892
707
|
const length = this.ocgcoreWrapper.useTmpData(
|
|
893
708
|
(keyPtr) => this.ocgcoreWrapper.ocgcoreModule._get_registry_value(
|
|
894
709
|
this.duelPtr,
|
|
895
710
|
keyPtr,
|
|
896
|
-
keyBytes.length,
|
|
897
711
|
outPtr
|
|
898
712
|
),
|
|
899
713
|
key
|
|
@@ -905,15 +719,11 @@ var OcgcoreDuel = class {
|
|
|
905
719
|
return { length, raw, value, text };
|
|
906
720
|
}
|
|
907
721
|
setRegistryValue(key, value) {
|
|
908
|
-
const keyBytes = encodeUtf8(key);
|
|
909
|
-
const valueBytes = encodeUtf8(value);
|
|
910
722
|
this.ocgcoreWrapper.useTmpData(
|
|
911
723
|
(keyPtr, valuePtr) => this.ocgcoreWrapper.ocgcoreModule._set_registry_value(
|
|
912
724
|
this.duelPtr,
|
|
913
725
|
keyPtr,
|
|
914
|
-
|
|
915
|
-
valuePtr,
|
|
916
|
-
valueBytes.length
|
|
726
|
+
valuePtr
|
|
917
727
|
),
|
|
918
728
|
key,
|
|
919
729
|
value
|
|
@@ -941,24 +751,84 @@ var OcgcoreDuel = class {
|
|
|
941
751
|
);
|
|
942
752
|
const raw = this.ocgcoreWrapper.copyHeap(outPtr, Math.max(0, length));
|
|
943
753
|
this.ocgcoreWrapper.free(outPtr);
|
|
944
|
-
const
|
|
945
|
-
|
|
754
|
+
const dict = {};
|
|
755
|
+
if (length > 0) {
|
|
756
|
+
const entries = parseRegistryDump(raw);
|
|
757
|
+
for (const entry of entries) {
|
|
758
|
+
if (entry.valueText !== void 0) {
|
|
759
|
+
dict[entry.key] = entry.valueText;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return { length, raw, dict };
|
|
946
764
|
}
|
|
947
765
|
loadRegistry(input) {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
this.
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
766
|
+
if (input instanceof Uint8Array) {
|
|
767
|
+
this.ocgcoreWrapper.useTmpData(
|
|
768
|
+
(ptr) => this.ocgcoreWrapper.ocgcoreModule._load_registry(
|
|
769
|
+
this.duelPtr,
|
|
770
|
+
ptr,
|
|
771
|
+
input.length
|
|
772
|
+
),
|
|
773
|
+
input
|
|
774
|
+
);
|
|
775
|
+
} else {
|
|
776
|
+
for (const [key, value] of Object.entries(input)) {
|
|
777
|
+
this.setRegistryValue(key, value);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
956
780
|
}
|
|
957
781
|
};
|
|
958
782
|
|
|
959
783
|
// src/structs/card-data.ts
|
|
960
|
-
var
|
|
961
|
-
var
|
|
784
|
+
var import_ygopro_msg_encode3 = require("ygopro-msg-encode");
|
|
785
|
+
var _CardDataStruct = class _CardDataStruct {
|
|
786
|
+
static fromBytes(data) {
|
|
787
|
+
const obj = new _CardDataStruct();
|
|
788
|
+
(0, import_ygopro_msg_encode3.fillBinaryFields)(obj, data, _CardDataStruct);
|
|
789
|
+
return obj;
|
|
790
|
+
}
|
|
791
|
+
toBytes() {
|
|
792
|
+
return (0, import_ygopro_msg_encode3.toBinaryFields)(this, _CardDataStruct);
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
__decorateClass([
|
|
796
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 0)
|
|
797
|
+
], _CardDataStruct.prototype, "code", 2);
|
|
798
|
+
__decorateClass([
|
|
799
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 4)
|
|
800
|
+
], _CardDataStruct.prototype, "alias", 2);
|
|
801
|
+
__decorateClass([
|
|
802
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u16", 8, 16)
|
|
803
|
+
], _CardDataStruct.prototype, "setcode", 2);
|
|
804
|
+
__decorateClass([
|
|
805
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 40)
|
|
806
|
+
], _CardDataStruct.prototype, "type", 2);
|
|
807
|
+
__decorateClass([
|
|
808
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 44)
|
|
809
|
+
], _CardDataStruct.prototype, "level", 2);
|
|
810
|
+
__decorateClass([
|
|
811
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 48)
|
|
812
|
+
], _CardDataStruct.prototype, "attribute", 2);
|
|
813
|
+
__decorateClass([
|
|
814
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 52)
|
|
815
|
+
], _CardDataStruct.prototype, "race", 2);
|
|
816
|
+
__decorateClass([
|
|
817
|
+
(0, import_ygopro_msg_encode3.BinaryField)("i32", 56)
|
|
818
|
+
], _CardDataStruct.prototype, "attack", 2);
|
|
819
|
+
__decorateClass([
|
|
820
|
+
(0, import_ygopro_msg_encode3.BinaryField)("i32", 60)
|
|
821
|
+
], _CardDataStruct.prototype, "defense", 2);
|
|
822
|
+
__decorateClass([
|
|
823
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 64)
|
|
824
|
+
], _CardDataStruct.prototype, "lscale", 2);
|
|
825
|
+
__decorateClass([
|
|
826
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 68)
|
|
827
|
+
], _CardDataStruct.prototype, "rscale", 2);
|
|
828
|
+
__decorateClass([
|
|
829
|
+
(0, import_ygopro_msg_encode3.BinaryField)("u32", 72)
|
|
830
|
+
], _CardDataStruct.prototype, "linkMarker", 2);
|
|
831
|
+
var CardDataStruct = _CardDataStruct;
|
|
962
832
|
|
|
963
833
|
// src/types/ocgcore-enums.ts
|
|
964
834
|
var OcgcoreMessageType = /* @__PURE__ */ ((OcgcoreMessageType2) => {
|
|
@@ -1056,15 +926,14 @@ var OcgcoreWrapper = class {
|
|
|
1056
926
|
if (!data) {
|
|
1057
927
|
return 0;
|
|
1058
928
|
}
|
|
1059
|
-
const CardDataCtor = CardDataStruct;
|
|
1060
929
|
let buf;
|
|
1061
|
-
if (data instanceof
|
|
1062
|
-
buf =
|
|
930
|
+
if (data instanceof CardDataStruct) {
|
|
931
|
+
buf = data.toBytes();
|
|
1063
932
|
} else {
|
|
1064
|
-
const cardData = new
|
|
933
|
+
const cardData = new CardDataStruct();
|
|
1065
934
|
cardData.code = data.code;
|
|
1066
935
|
cardData.alias = data.alias;
|
|
1067
|
-
const targetSetcode =
|
|
936
|
+
const targetSetcode = new Uint16Array(16);
|
|
1068
937
|
targetSetcode.fill(0);
|
|
1069
938
|
if (data.setcode instanceof Uint16Array && data.setcode.length === 16) {
|
|
1070
939
|
targetSetcode.set(data.setcode);
|
|
@@ -1073,6 +942,7 @@ var OcgcoreWrapper = class {
|
|
|
1073
942
|
targetSetcode[i] = data.setcode[i];
|
|
1074
943
|
}
|
|
1075
944
|
}
|
|
945
|
+
cardData.setcode = targetSetcode;
|
|
1076
946
|
cardData.type = data.type;
|
|
1077
947
|
cardData.level = data.level;
|
|
1078
948
|
cardData.attribute = data.attribute;
|
|
@@ -1082,7 +952,7 @@ var OcgcoreWrapper = class {
|
|
|
1082
952
|
cardData.lscale = data.lscale;
|
|
1083
953
|
cardData.rscale = data.rscale;
|
|
1084
954
|
cardData.linkMarker = data.linkMarker;
|
|
1085
|
-
buf =
|
|
955
|
+
buf = cardData.toBytes();
|
|
1086
956
|
}
|
|
1087
957
|
this.heapU8.set(buf, cardDataPtr);
|
|
1088
958
|
return 0;
|
|
@@ -1258,9 +1128,7 @@ function normalizeOcgcoreFactory(mod) {
|
|
|
1258
1128
|
|
|
1259
1129
|
// src/utility/load-node-module.ts
|
|
1260
1130
|
function loadNodeModule(id, altId) {
|
|
1261
|
-
const req =
|
|
1262
|
-
'return typeof require !== "undefined" ? require : undefined'
|
|
1263
|
-
)();
|
|
1131
|
+
const req = typeof module.require !== "undefined" ? module.require : void 0;
|
|
1264
1132
|
if (!req) {
|
|
1265
1133
|
return null;
|
|
1266
1134
|
}
|
|
@@ -2400,13 +2268,13 @@ function createReplayDuel(wrapper, yrp) {
|
|
|
2400
2268
|
}
|
|
2401
2269
|
return wrapper.createDuel(header?.seed ?? 0);
|
|
2402
2270
|
}
|
|
2403
|
-
function loadDeck(duel, deck, owner,
|
|
2271
|
+
function loadDeck(duel, deck, owner, player) {
|
|
2404
2272
|
if (!deck) return;
|
|
2405
2273
|
for (const code of deck.main ?? []) {
|
|
2406
2274
|
duel.newCard({
|
|
2407
2275
|
code,
|
|
2408
2276
|
owner,
|
|
2409
|
-
|
|
2277
|
+
player,
|
|
2410
2278
|
location: LOCATION_DECK,
|
|
2411
2279
|
sequence: 0,
|
|
2412
2280
|
position: POS_FACEDOWN_DEFENSE
|
|
@@ -2416,7 +2284,7 @@ function loadDeck(duel, deck, owner, playerId) {
|
|
|
2416
2284
|
duel.newCard({
|
|
2417
2285
|
code,
|
|
2418
2286
|
owner,
|
|
2419
|
-
|
|
2287
|
+
player,
|
|
2420
2288
|
location: LOCATION_EXTRA,
|
|
2421
2289
|
sequence: 0,
|
|
2422
2290
|
position: POS_FACEDOWN_DEFENSE
|
|
@@ -2443,9 +2311,8 @@ function loadTagDeck(duel, deck, owner) {
|
|
|
2443
2311
|
function setRegistryValue(duel, key, value) {
|
|
2444
2312
|
duel.setRegistryValue(key, value);
|
|
2445
2313
|
}
|
|
2446
|
-
|
|
2314
|
+
function* playYrpStep(ocgcoreWrapper, yrpInput) {
|
|
2447
2315
|
const yrp = normalizeYrp(yrpInput);
|
|
2448
|
-
const messages = [];
|
|
2449
2316
|
const responses = yrp.responses.slice();
|
|
2450
2317
|
const duel = createReplayDuel(ocgcoreWrapper, yrp);
|
|
2451
2318
|
let ended = false;
|
|
@@ -2471,15 +2338,15 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
|
|
|
2471
2338
|
setRegistryValue(duel, "player_type_0", "0");
|
|
2472
2339
|
setRegistryValue(duel, "player_type_1", "1");
|
|
2473
2340
|
duel.setPlayerInfo({
|
|
2474
|
-
|
|
2341
|
+
player: 0,
|
|
2475
2342
|
lp: yrp.startLp,
|
|
2476
|
-
|
|
2343
|
+
startHand: yrp.startHand,
|
|
2477
2344
|
drawCount: yrp.drawCount
|
|
2478
2345
|
});
|
|
2479
2346
|
duel.setPlayerInfo({
|
|
2480
|
-
|
|
2347
|
+
player: 1,
|
|
2481
2348
|
lp: yrp.startLp,
|
|
2482
|
-
|
|
2349
|
+
startHand: yrp.startHand,
|
|
2483
2350
|
drawCount: yrp.drawCount
|
|
2484
2351
|
});
|
|
2485
2352
|
duel.preloadScript("./script/patches/entry.lua");
|
|
@@ -2498,16 +2365,19 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
|
|
|
2498
2365
|
}
|
|
2499
2366
|
duel.startDuel(yrp.opt >>> 0);
|
|
2500
2367
|
while (true) {
|
|
2501
|
-
const
|
|
2502
|
-
|
|
2503
|
-
|
|
2368
|
+
const result = duel.process();
|
|
2369
|
+
yield {
|
|
2370
|
+
duel,
|
|
2371
|
+
result
|
|
2372
|
+
};
|
|
2373
|
+
if (result.raw.length > 0 && result.raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
|
|
2504
2374
|
throw new Error("Got MSG_RETRY");
|
|
2505
2375
|
}
|
|
2506
|
-
if (status === 0) {
|
|
2376
|
+
if (result.status === 0) {
|
|
2507
2377
|
continue;
|
|
2508
2378
|
}
|
|
2509
|
-
if (status === 1) {
|
|
2510
|
-
if (raw.length === 0) {
|
|
2379
|
+
if (result.status === 1) {
|
|
2380
|
+
if (result.raw.length === 0) {
|
|
2511
2381
|
continue;
|
|
2512
2382
|
}
|
|
2513
2383
|
const response = responses.shift();
|
|
@@ -2522,7 +2392,13 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
|
|
|
2522
2392
|
} finally {
|
|
2523
2393
|
endDuel();
|
|
2524
2394
|
}
|
|
2525
|
-
|
|
2395
|
+
}
|
|
2396
|
+
var playYrp = (ocgcoreWrapper, yrpInput) => {
|
|
2397
|
+
const results = [];
|
|
2398
|
+
for (const result of playYrpStep(ocgcoreWrapper, yrpInput)) {
|
|
2399
|
+
results.push(result.result.raw);
|
|
2400
|
+
}
|
|
2401
|
+
return results;
|
|
2526
2402
|
};
|
|
2527
2403
|
|
|
2528
2404
|
// src/test-card.ts
|
|
@@ -2541,13 +2417,13 @@ function testCard(ocgcoreWrapper, ...ids) {
|
|
|
2541
2417
|
});
|
|
2542
2418
|
duel.preloadScript("./script/special.lua");
|
|
2543
2419
|
duel.preloadScript("./script/init.lua");
|
|
2544
|
-
duel.setPlayerInfo({
|
|
2545
|
-
duel.setPlayerInfo({
|
|
2420
|
+
duel.setPlayerInfo({ player: 0, lp: 8e3, startHand: 5, drawCount: 1 });
|
|
2421
|
+
duel.setPlayerInfo({ player: 1, lp: 8e3, startHand: 5, drawCount: 1 });
|
|
2546
2422
|
for (const code of ids) {
|
|
2547
2423
|
duel.newCard({
|
|
2548
2424
|
code,
|
|
2549
2425
|
owner: 0,
|
|
2550
|
-
|
|
2426
|
+
player: 0,
|
|
2551
2427
|
location: LOCATION_DECK2,
|
|
2552
2428
|
sequence: 0,
|
|
2553
2429
|
position: POS_FACEUP_ATTACK
|
|
@@ -2600,6 +2476,7 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
2600
2476
|
parseRegistryDump,
|
|
2601
2477
|
parseRegistryKeys,
|
|
2602
2478
|
playYrp,
|
|
2479
|
+
playYrpStep,
|
|
2603
2480
|
testCard
|
|
2604
2481
|
});
|
|
2605
2482
|
//# sourceMappingURL=index.cjs.map
|