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/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
- function parseCardInfo(payload) {
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 parseCardInfo(payload);
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
- cards.push({ flags: 0, empty: true });
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(parseCardInfo(payload));
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
- let offset = 0;
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.playerId,
521
+ info.player,
716
522
  info.lp,
717
- info.startCount,
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 message = this.getMessage(length);
739
- return { length: message.length, raw: message.raw, status };
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.playerId,
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.playerId,
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.playerId,
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.playerId,
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
- keyBytes.length,
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 entries = length >= 0 ? parseRegistryDump(raw) : [];
886
- return { length, raw, entries };
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
- this.ocgcoreWrapper.useTmpData(
890
- (ptr) => this.ocgcoreWrapper.ocgcoreModule._load_registry(
891
- this.duelPtr,
892
- ptr,
893
- input.length
894
- ),
895
- input
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 Struct from "typed-struct";
902
- var CardDataStruct = new Struct().UInt32LE("code").UInt32LE("alias").UInt16Array("setcode", 16).UInt32LE("type").UInt32LE("level").UInt32LE("attribute").UInt32LE("race").Int32LE("attack").Int32LE("defense").UInt32LE("lscale").UInt32LE("rscale").UInt32LE("linkMarker").compile();
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 CardDataCtor) {
1003
- buf = CardDataStruct.raw(data);
877
+ if (data instanceof CardDataStruct) {
878
+ buf = data.toBytes();
1004
879
  } else {
1005
- const cardData = new CardDataCtor();
880
+ const cardData = new CardDataStruct();
1006
881
  cardData.code = data.code;
1007
882
  cardData.alias = data.alias;
1008
- const targetSetcode = cardData.setcode;
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 = CardDataStruct.raw(cardData);
902
+ buf = cardData.toBytes();
1027
903
  }
1028
904
  this.heapU8.set(buf, cardDataPtr);
1029
905
  return 0;
@@ -1226,9 +1102,7 @@ import JSZip from "jszip";
1226
1102
 
1227
1103
  // src/utility/load-node-module.ts
1228
1104
  function loadNodeModule(id, altId) {
1229
- const req = new Function(
1230
- 'return typeof require !== "undefined" ? require : undefined'
1231
- )();
1105
+ const req = typeof module.require !== "undefined" ? module.require : void 0;
1232
1106
  if (!req) {
1233
1107
  return null;
1234
1108
  }
@@ -2315,13 +2189,13 @@ function createReplayDuel(wrapper, yrp) {
2315
2189
  }
2316
2190
  return wrapper.createDuel(header?.seed ?? 0);
2317
2191
  }
2318
- function loadDeck(duel, deck, owner, playerId) {
2192
+ function loadDeck(duel, deck, owner, player) {
2319
2193
  if (!deck) return;
2320
2194
  for (const code of deck.main ?? []) {
2321
2195
  duel.newCard({
2322
2196
  code,
2323
2197
  owner,
2324
- playerId,
2198
+ player,
2325
2199
  location: LOCATION_DECK,
2326
2200
  sequence: 0,
2327
2201
  position: POS_FACEDOWN_DEFENSE
@@ -2331,7 +2205,7 @@ function loadDeck(duel, deck, owner, playerId) {
2331
2205
  duel.newCard({
2332
2206
  code,
2333
2207
  owner,
2334
- playerId,
2208
+ player,
2335
2209
  location: LOCATION_EXTRA,
2336
2210
  sequence: 0,
2337
2211
  position: POS_FACEDOWN_DEFENSE
@@ -2358,9 +2232,8 @@ function loadTagDeck(duel, deck, owner) {
2358
2232
  function setRegistryValue(duel, key, value) {
2359
2233
  duel.setRegistryValue(key, value);
2360
2234
  }
2361
- var playYrp = (ocgcoreWrapper, yrpInput) => {
2235
+ function* playYrpStep(ocgcoreWrapper, yrpInput) {
2362
2236
  const yrp = normalizeYrp(yrpInput);
2363
- const messages = [];
2364
2237
  const responses = yrp.responses.slice();
2365
2238
  const duel = createReplayDuel(ocgcoreWrapper, yrp);
2366
2239
  let ended = false;
@@ -2386,15 +2259,15 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
2386
2259
  setRegistryValue(duel, "player_type_0", "0");
2387
2260
  setRegistryValue(duel, "player_type_1", "1");
2388
2261
  duel.setPlayerInfo({
2389
- playerId: 0,
2262
+ player: 0,
2390
2263
  lp: yrp.startLp,
2391
- startCount: yrp.startHand,
2264
+ startHand: yrp.startHand,
2392
2265
  drawCount: yrp.drawCount
2393
2266
  });
2394
2267
  duel.setPlayerInfo({
2395
- playerId: 1,
2268
+ player: 1,
2396
2269
  lp: yrp.startLp,
2397
- startCount: yrp.startHand,
2270
+ startHand: yrp.startHand,
2398
2271
  drawCount: yrp.drawCount
2399
2272
  });
2400
2273
  duel.preloadScript("./script/patches/entry.lua");
@@ -2413,16 +2286,19 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
2413
2286
  }
2414
2287
  duel.startDuel(yrp.opt >>> 0);
2415
2288
  while (true) {
2416
- const { raw, status } = duel.process();
2417
- messages.push(raw);
2418
- if (raw.length > 0 && raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
2289
+ const result = duel.process();
2290
+ yield {
2291
+ duel,
2292
+ result
2293
+ };
2294
+ if (result.raw.length > 0 && result.raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
2419
2295
  throw new Error("Got MSG_RETRY");
2420
2296
  }
2421
- if (status === 0) {
2297
+ if (result.status === 0) {
2422
2298
  continue;
2423
2299
  }
2424
- if (status === 1) {
2425
- if (raw.length === 0) {
2300
+ if (result.status === 1) {
2301
+ if (result.raw.length === 0) {
2426
2302
  continue;
2427
2303
  }
2428
2304
  const response = responses.shift();
@@ -2437,7 +2313,13 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
2437
2313
  } finally {
2438
2314
  endDuel();
2439
2315
  }
2440
- return messages;
2316
+ }
2317
+ var playYrp = (ocgcoreWrapper, yrpInput) => {
2318
+ const results = [];
2319
+ for (const result of playYrpStep(ocgcoreWrapper, yrpInput)) {
2320
+ results.push(result.result.raw);
2321
+ }
2322
+ return results;
2441
2323
  };
2442
2324
 
2443
2325
  // src/test-card.ts
@@ -2456,13 +2338,13 @@ function testCard(ocgcoreWrapper, ...ids) {
2456
2338
  });
2457
2339
  duel.preloadScript("./script/special.lua");
2458
2340
  duel.preloadScript("./script/init.lua");
2459
- duel.setPlayerInfo({ playerId: 0, lp: 8e3, startCount: 5, drawCount: 1 });
2460
- duel.setPlayerInfo({ playerId: 1, lp: 8e3, startCount: 5, drawCount: 1 });
2341
+ duel.setPlayerInfo({ player: 0, lp: 8e3, startHand: 5, drawCount: 1 });
2342
+ duel.setPlayerInfo({ player: 1, lp: 8e3, startHand: 5, drawCount: 1 });
2461
2343
  for (const code of ids) {
2462
2344
  duel.newCard({
2463
2345
  code,
2464
2346
  owner: 0,
2465
- playerId: 0,
2347
+ player: 0,
2466
2348
  location: LOCATION_DECK2,
2467
2349
  sequence: 0,
2468
2350
  position: POS_FACEUP_ATTACK
@@ -2485,7 +2367,7 @@ function testCard(ocgcoreWrapper, ...ids) {
2485
2367
 
2486
2368
  // index.ts
2487
2369
  if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
2488
- globalThis.Buffer = Buffer;
2370
+ globalThis.Buffer = Buffer2;
2489
2371
  }
2490
2372
  export {
2491
2373
  CardDataStruct,
@@ -2514,6 +2396,7 @@ export {
2514
2396
  parseRegistryDump,
2515
2397
  parseRegistryKeys,
2516
2398
  playYrp,
2399
+ playYrpStep,
2517
2400
  testCard
2518
2401
  };
2519
2402
  //# sourceMappingURL=index.mjs.map