ygopro-msg-encode 1.0.3 → 1.0.5

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.
Files changed (35) hide show
  1. package/COMPOSITE_FIELDS_AUDIT.md +275 -0
  2. package/COMPOSITE_FIELDS_GUIDE.md +303 -0
  3. package/DECK_COUNT_EXPLANATION.md +124 -0
  4. package/PROTOCOL_VERIFICATION_SUMMARY.md +410 -0
  5. package/README.md +4 -0
  6. package/REFACTOR_COMPOSITE_FIELDS.md +242 -0
  7. package/dist/index.cjs +144 -5
  8. package/dist/index.cjs.map +2 -2
  9. package/dist/index.mjs +143 -5
  10. package/dist/index.mjs.map +2 -2
  11. package/dist/src/protos/msg/proto/announce-attrib.d.ts +1 -0
  12. package/dist/src/protos/msg/proto/announce-card.d.ts +1 -0
  13. package/dist/src/protos/msg/proto/announce-number.d.ts +1 -0
  14. package/dist/src/protos/msg/proto/announce-race.d.ts +1 -0
  15. package/dist/src/protos/msg/proto/select-battlecmd.d.ts +1 -0
  16. package/dist/src/protos/msg/proto/select-card.d.ts +1 -0
  17. package/dist/src/protos/msg/proto/select-chain.d.ts +1 -0
  18. package/dist/src/protos/msg/proto/select-counter.d.ts +1 -0
  19. package/dist/src/protos/msg/proto/select-disfield.d.ts +1 -0
  20. package/dist/src/protos/msg/proto/select-effectyn.d.ts +1 -0
  21. package/dist/src/protos/msg/proto/select-idlecmd.d.ts +1 -0
  22. package/dist/src/protos/msg/proto/select-option.d.ts +1 -0
  23. package/dist/src/protos/msg/proto/select-place.d.ts +1 -0
  24. package/dist/src/protos/msg/proto/select-position.d.ts +1 -0
  25. package/dist/src/protos/msg/proto/select-sum.d.ts +1 -0
  26. package/dist/src/protos/msg/proto/select-tribute.d.ts +1 -0
  27. package/dist/src/protos/msg/proto/select-unselect-card.d.ts +1 -0
  28. package/dist/src/protos/msg/proto/select-yesno.d.ts +1 -0
  29. package/dist/src/protos/msg/proto/sort-card.d.ts +1 -0
  30. package/dist/src/protos/msg/proto/start.d.ts +17 -0
  31. package/dist/src/protos/msg/with-response-base.d.ts +1 -0
  32. package/dist/src/protos/stoc/proto/deck-count.d.ts +15 -1
  33. package/dist/src/protos/stoc/proto/hs-player-change.d.ts +23 -0
  34. package/dist/src/protos/stoc/proto/type-change.d.ts +23 -0
  35. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1242,6 +1242,9 @@ var YGOProMsgAnnounceAttrib = class extends YGOProMsgResponseBase {
1242
1242
  static {
1243
1243
  this.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_ATTRIB;
1244
1244
  }
1245
+ responsePlayer() {
1246
+ return this.player;
1247
+ }
1245
1248
  prepareResponse(attributes) {
1246
1249
  const buffer = new Uint8Array(4);
1247
1250
  const view = new DataView(buffer.buffer);
@@ -1264,6 +1267,9 @@ var YGOProMsgAnnounceCard = class extends YGOProMsgResponseBase {
1264
1267
  static {
1265
1268
  this.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_CARD;
1266
1269
  }
1270
+ responsePlayer() {
1271
+ return this.player;
1272
+ }
1267
1273
  prepareResponse(cardCode) {
1268
1274
  const buffer = new Uint8Array(4);
1269
1275
  const view = new DataView(buffer.buffer);
@@ -1296,6 +1302,9 @@ var YGOProMsgAnnounceNumber = class extends YGOProMsgResponseBase {
1296
1302
  static {
1297
1303
  this.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_NUMBER;
1298
1304
  }
1305
+ responsePlayer() {
1306
+ return this.player;
1307
+ }
1299
1308
  prepareResponse(option) {
1300
1309
  let index;
1301
1310
  if (isIndexResponse(option)) {
@@ -1330,6 +1339,9 @@ var YGOProMsgAnnounceRace = class extends YGOProMsgResponseBase {
1330
1339
  static {
1331
1340
  this.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_RACE;
1332
1341
  }
1342
+ responsePlayer() {
1343
+ return this.player;
1344
+ }
1333
1345
  prepareResponse(races) {
1334
1346
  const buffer = new Uint8Array(4);
1335
1347
  const view = new DataView(buffer.buffer);
@@ -2634,6 +2646,9 @@ var YGOProMsgSelectBattleCmd = class extends YGOProMsgResponseBase {
2634
2646
  static {
2635
2647
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_BATTLECMD;
2636
2648
  }
2649
+ responsePlayer() {
2650
+ return this.player;
2651
+ }
2637
2652
  prepareResponse(type, option) {
2638
2653
  let sequence;
2639
2654
  if (type === 0 /* ACTIVATE */) {
@@ -2751,6 +2766,9 @@ var YGOProMsgSelectCard = class extends YGOProMsgResponseBase {
2751
2766
  static {
2752
2767
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_CARD;
2753
2768
  }
2769
+ responsePlayer() {
2770
+ return this.player;
2771
+ }
2754
2772
  defaultResponse() {
2755
2773
  if (this.cancelable === 0) {
2756
2774
  return void 0;
@@ -2765,6 +2783,7 @@ var YGOProMsgSelectCard = class extends YGOProMsgResponseBase {
2765
2783
  return buffer2;
2766
2784
  }
2767
2785
  const indices = [];
2786
+ const usedIndices = /* @__PURE__ */ new Set();
2768
2787
  for (const option of cardOptions) {
2769
2788
  let index;
2770
2789
  if (isIndexResponse(option)) {
@@ -2774,13 +2793,14 @@ var YGOProMsgSelectCard = class extends YGOProMsgResponseBase {
2774
2793
  }
2775
2794
  } else {
2776
2795
  index = this.cards.findIndex(
2777
- (card) => (option.code == null || card.code === option.code) && (option.controller == null || card.controller === option.controller) && (option.location == null || card.location === option.location) && (option.sequence == null || card.sequence === option.sequence)
2796
+ (card, idx) => !usedIndices.has(idx) && (option.code == null || card.code === option.code) && (option.controller == null || card.controller === option.controller) && (option.location == null || card.location === option.location) && (option.sequence == null || card.sequence === option.sequence)
2778
2797
  );
2779
2798
  if (index === -1) {
2780
2799
  throw new TypeError("Card not found");
2781
2800
  }
2782
2801
  }
2783
2802
  indices.push(index);
2803
+ usedIndices.add(index);
2784
2804
  }
2785
2805
  const buffer = new Uint8Array(1 + indices.length);
2786
2806
  buffer[0] = indices.length;
@@ -2840,6 +2860,9 @@ var YGOProMsgSelectChain = class extends YGOProMsgResponseBase {
2840
2860
  static {
2841
2861
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_CHAIN;
2842
2862
  }
2863
+ responsePlayer() {
2864
+ return this.player;
2865
+ }
2843
2866
  defaultResponse() {
2844
2867
  const hasForced = this.chains.some((chain) => chain.forced !== 0);
2845
2868
  if (hasForced) {
@@ -2911,6 +2934,9 @@ var YGOProMsgSelectCounter = class extends YGOProMsgResponseBase {
2911
2934
  static {
2912
2935
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_COUNTER;
2913
2936
  }
2937
+ responsePlayer() {
2938
+ return this.player;
2939
+ }
2914
2940
  prepareResponse(counterOptions) {
2915
2941
  const counterCounts = new Array(this.count).fill(0);
2916
2942
  for (const option of counterOptions) {
@@ -2960,6 +2986,9 @@ var YGOProMsgSelectDisField = class extends YGOProMsgResponseBase {
2960
2986
  static {
2961
2987
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_DISFIELD;
2962
2988
  }
2989
+ responsePlayer() {
2990
+ return this.player;
2991
+ }
2963
2992
  prepareResponse(places) {
2964
2993
  const buffer = new Uint8Array(places.length * 3);
2965
2994
  places.forEach((place, i) => {
@@ -2985,6 +3014,9 @@ var YGOProMsgSelectEffectYn = class extends YGOProMsgResponseBase {
2985
3014
  static {
2986
3015
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_EFFECTYN;
2987
3016
  }
3017
+ responsePlayer() {
3018
+ return this.player;
3019
+ }
2988
3020
  defaultResponse() {
2989
3021
  return this.prepareResponse(false);
2990
3022
  }
@@ -3065,6 +3097,9 @@ var YGOProMsgSelectIdleCmd = class extends YGOProMsgResponseBase {
3065
3097
  static {
3066
3098
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_IDLECMD;
3067
3099
  }
3100
+ responsePlayer() {
3101
+ return this.player;
3102
+ }
3068
3103
  prepareResponse(type, option) {
3069
3104
  let sequence;
3070
3105
  if (type === 0 /* SUMMON */ || type === 1 /* SPSUMMON */ || type === 2 /* REPOS */ || type === 3 /* MSET */ || type === 4 /* SSET */ || type === 5 /* ACTIVATE */) {
@@ -3236,6 +3271,9 @@ var YGOProMsgSelectOption = class extends YGOProMsgResponseBase {
3236
3271
  static {
3237
3272
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_OPTION;
3238
3273
  }
3274
+ responsePlayer() {
3275
+ return this.player;
3276
+ }
3239
3277
  prepareResponse(option) {
3240
3278
  let index;
3241
3279
  if (isIndexResponse(option)) {
@@ -3270,6 +3308,9 @@ var YGOProMsgSelectPlace = class extends YGOProMsgResponseBase {
3270
3308
  static {
3271
3309
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_PLACE;
3272
3310
  }
3311
+ responsePlayer() {
3312
+ return this.player;
3313
+ }
3273
3314
  prepareResponse(places) {
3274
3315
  const buffer = new Uint8Array(places.length * 3);
3275
3316
  places.forEach((place, i) => {
@@ -3295,6 +3336,9 @@ var YGOProMsgSelectPosition = class extends YGOProMsgResponseBase {
3295
3336
  static {
3296
3337
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_POSITION;
3297
3338
  }
3339
+ responsePlayer() {
3340
+ return this.player;
3341
+ }
3298
3342
  prepareResponse(position) {
3299
3343
  const buffer = new Uint8Array(4);
3300
3344
  const view = new DataView(buffer.buffer);
@@ -3334,6 +3378,9 @@ var YGOProMsgSelectSum = class extends YGOProMsgResponseBase {
3334
3378
  static {
3335
3379
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_SUM;
3336
3380
  }
3381
+ responsePlayer() {
3382
+ return this.player;
3383
+ }
3337
3384
  prepareResponse(cardOptions) {
3338
3385
  const indices = [];
3339
3386
  for (const option of cardOptions) {
@@ -3423,6 +3470,9 @@ var YGOProMsgSelectTribute = class extends YGOProMsgResponseBase {
3423
3470
  static {
3424
3471
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_TRIBUTE;
3425
3472
  }
3473
+ responsePlayer() {
3474
+ return this.player;
3475
+ }
3426
3476
  defaultResponse() {
3427
3477
  if (this.cancelable === 0) {
3428
3478
  return void 0;
@@ -3437,6 +3487,7 @@ var YGOProMsgSelectTribute = class extends YGOProMsgResponseBase {
3437
3487
  return buffer2;
3438
3488
  }
3439
3489
  const indices = [];
3490
+ const usedIndices = /* @__PURE__ */ new Set();
3440
3491
  for (const option of cardOptions) {
3441
3492
  let index;
3442
3493
  if (isIndexResponse(option)) {
@@ -3446,13 +3497,14 @@ var YGOProMsgSelectTribute = class extends YGOProMsgResponseBase {
3446
3497
  }
3447
3498
  } else {
3448
3499
  index = this.cards.findIndex(
3449
- (card) => (option.code == null || card.code === option.code) && (option.controller == null || card.controller === option.controller) && (option.location == null || card.location === option.location) && (option.sequence == null || card.sequence === option.sequence)
3500
+ (card, idx) => !usedIndices.has(idx) && (option.code == null || card.code === option.code) && (option.controller == null || card.controller === option.controller) && (option.location == null || card.location === option.location) && (option.sequence == null || card.sequence === option.sequence)
3450
3501
  );
3451
3502
  if (index === -1) {
3452
3503
  throw new TypeError("Card not found");
3453
3504
  }
3454
3505
  }
3455
3506
  indices.push(index);
3507
+ usedIndices.add(index);
3456
3508
  }
3457
3509
  const buffer = new Uint8Array(1 + indices.length);
3458
3510
  buffer[0] = indices.length;
@@ -3503,6 +3555,9 @@ var YGOProMsgSelectUnselectCard = class extends YGOProMsgResponseBase {
3503
3555
  static {
3504
3556
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_UNSELECT_CARD;
3505
3557
  }
3558
+ responsePlayer() {
3559
+ return this.player;
3560
+ }
3506
3561
  defaultResponse() {
3507
3562
  if (this.cancelable === 0 && this.finishable === 0) {
3508
3563
  return void 0;
@@ -3588,6 +3643,9 @@ var YGOProMsgSelectYesNo = class extends YGOProMsgResponseBase {
3588
3643
  static {
3589
3644
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_YESNO;
3590
3645
  }
3646
+ responsePlayer() {
3647
+ return this.player;
3648
+ }
3591
3649
  defaultResponse() {
3592
3650
  return this.prepareResponse(false);
3593
3651
  }
@@ -3731,6 +3789,9 @@ var YGOProMsgSortCard = class extends YGOProMsgResponseBase {
3731
3789
  static {
3732
3790
  this.identifier = OcgcoreCommonConstants.MSG_SORT_CARD;
3733
3791
  }
3792
+ responsePlayer() {
3793
+ return this.player;
3794
+ }
3734
3795
  defaultResponse() {
3735
3796
  return this.prepareResponse(null);
3736
3797
  }
@@ -3739,6 +3800,7 @@ var YGOProMsgSortCard = class extends YGOProMsgResponseBase {
3739
3800
  return new Uint8Array([255]);
3740
3801
  }
3741
3802
  const indices = [];
3803
+ const usedIndices = /* @__PURE__ */ new Set();
3742
3804
  for (const option of sortedOptions) {
3743
3805
  let index;
3744
3806
  if (isIndexResponse(option)) {
@@ -3748,13 +3810,14 @@ var YGOProMsgSortCard = class extends YGOProMsgResponseBase {
3748
3810
  }
3749
3811
  } else {
3750
3812
  index = this.cards.findIndex(
3751
- (card) => (option.code == null || card.code === option.code) && (option.controller == null || card.controller === option.controller) && (option.location == null || card.location === option.location) && (option.sequence == null || card.sequence === option.sequence)
3813
+ (card, idx) => !usedIndices.has(idx) && (option.code == null || card.code === option.code) && (option.controller == null || card.controller === option.controller) && (option.location == null || card.location === option.location) && (option.sequence == null || card.sequence === option.sequence)
3752
3814
  );
3753
3815
  if (index === -1) {
3754
3816
  throw new TypeError("Card not found");
3755
3817
  }
3756
3818
  }
3757
3819
  indices.push(index);
3820
+ usedIndices.add(index);
3758
3821
  }
3759
3822
  const buffer = new Uint8Array(indices.length);
3760
3823
  indices.forEach((idx, i) => {
@@ -3815,6 +3878,24 @@ var YGOProMsgStart = class extends YGOProMsgBase {
3815
3878
  static {
3816
3879
  this.identifier = 4;
3817
3880
  }
3881
+ /**
3882
+ * Get/Set player number (low 4 bits, 0-3)
3883
+ */
3884
+ get playerNumber() {
3885
+ return this.playerType & 15;
3886
+ }
3887
+ set playerNumber(value) {
3888
+ this.playerType = this.playerType & 240 | value & 15;
3889
+ }
3890
+ /**
3891
+ * Get/Set observer flag (high 4 bits, 0x00 or 0x10)
3892
+ */
3893
+ get observerFlag() {
3894
+ return this.playerType & 240;
3895
+ }
3896
+ set observerFlag(value) {
3897
+ this.playerType = this.playerType & 15 | value & 240;
3898
+ }
3818
3899
  };
3819
3900
  __decorateClass([
3820
3901
  BinaryField("u8", 0)
@@ -5190,14 +5271,28 @@ var YGOProStocWaitingSide = class extends YGOProStocBase {
5190
5271
  };
5191
5272
 
5192
5273
  // src/protos/stoc/proto/deck-count.ts
5274
+ var YGOProStocDeckCount_DeckInfo = class {
5275
+ };
5276
+ __decorateClass([
5277
+ BinaryField("i16", 0)
5278
+ ], YGOProStocDeckCount_DeckInfo.prototype, "main", 2);
5279
+ __decorateClass([
5280
+ BinaryField("i16", 2)
5281
+ ], YGOProStocDeckCount_DeckInfo.prototype, "extra", 2);
5282
+ __decorateClass([
5283
+ BinaryField("i16", 4)
5284
+ ], YGOProStocDeckCount_DeckInfo.prototype, "side", 2);
5193
5285
  var YGOProStocDeckCount = class extends YGOProStocBase {
5194
5286
  static {
5195
5287
  this.identifier = 9;
5196
5288
  }
5197
5289
  };
5198
5290
  __decorateClass([
5199
- BinaryField("i16", 0, 6)
5200
- ], YGOProStocDeckCount.prototype, "counts", 2);
5291
+ BinaryField(() => YGOProStocDeckCount_DeckInfo, 0)
5292
+ ], YGOProStocDeckCount.prototype, "player0DeckCount", 2);
5293
+ __decorateClass([
5294
+ BinaryField(() => YGOProStocDeckCount_DeckInfo, 6)
5295
+ ], YGOProStocDeckCount.prototype, "player1DeckCount", 2);
5201
5296
 
5202
5297
  // src/protos/stoc/proto/create-game.ts
5203
5298
  var YGOProStocCreateGame = class extends YGOProStocBase {
@@ -5224,6 +5319,29 @@ var YGOProStocTypeChange = class extends YGOProStocBase {
5224
5319
  static {
5225
5320
  this.identifier = 19;
5226
5321
  }
5322
+ /**
5323
+ * Get/Set player position (low 4 bits, 0-7)
5324
+ */
5325
+ get playerPosition() {
5326
+ return this.type & 15;
5327
+ }
5328
+ set playerPosition(value) {
5329
+ this.type = this.type & 240 | value & 15;
5330
+ }
5331
+ /**
5332
+ * Get/Set host flag (high 4 bits)
5333
+ * Returns true if this player is the host
5334
+ */
5335
+ get isHost() {
5336
+ return (this.type >> 4 & 15) !== 0;
5337
+ }
5338
+ set isHost(value) {
5339
+ if (value) {
5340
+ this.type = this.type & 15 | 16;
5341
+ } else {
5342
+ this.type = this.type & 15;
5343
+ }
5344
+ }
5227
5345
  };
5228
5346
  __decorateClass([
5229
5347
  BinaryField("u8", 0)
@@ -5365,6 +5483,25 @@ var YGOProStocHsPlayerChange = class extends YGOProStocBase {
5365
5483
  static {
5366
5484
  this.identifier = 33;
5367
5485
  }
5486
+ /**
5487
+ * Get/Set player state (low 4 bits)
5488
+ * Can be a PlayerChangeState enum value or a player position (0-7) for position changes
5489
+ */
5490
+ get playerState() {
5491
+ return this.status & 15;
5492
+ }
5493
+ set playerState(value) {
5494
+ this.status = this.status & 240 | value & 15;
5495
+ }
5496
+ /**
5497
+ * Get/Set player position (high 4 bits, 0-3)
5498
+ */
5499
+ get playerPosition() {
5500
+ return this.status >> 4 & 15;
5501
+ }
5502
+ set playerPosition(value) {
5503
+ this.status = this.status & 15 | (value & 15) << 4;
5504
+ }
5368
5505
  };
5369
5506
  __decorateClass([
5370
5507
  BinaryField("u8", 0)
@@ -5706,6 +5843,7 @@ export {
5706
5843
  YGOProStocChat,
5707
5844
  YGOProStocCreateGame,
5708
5845
  YGOProStocDeckCount,
5846
+ YGOProStocDeckCount_DeckInfo,
5709
5847
  YGOProStocDuelEnd,
5710
5848
  YGOProStocDuelStart,
5711
5849
  YGOProStocErrorMsg,