ygopro-msg-encode 1.1.25 → 1.1.26

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.cjs CHANGED
@@ -199,6 +199,8 @@ __export(index_exports, {
199
199
  YGOProMsgTagSwap: () => YGOProMsgTagSwap,
200
200
  YGOProMsgTossCoin: () => YGOProMsgTossCoin,
201
201
  YGOProMsgTossDice: () => YGOProMsgTossDice,
202
+ YGOProMsgUnequip: () => YGOProMsgUnequip,
203
+ YGOProMsgUnequip_CardLocation: () => YGOProMsgUnequip_CardLocation,
202
204
  YGOProMsgUpdateCard: () => YGOProMsgUpdateCard,
203
205
  YGOProMsgUpdateData: () => YGOProMsgUpdateData,
204
206
  YGOProMsgWaiting: () => YGOProMsgWaiting,
@@ -231,9 +233,13 @@ __export(index_exports, {
231
233
  YGOProStocTpResult: () => YGOProStocTpResult,
232
234
  YGOProStocTypeChange: () => YGOProStocTypeChange,
233
235
  YGOProStocWaitingSide: () => YGOProStocWaitingSide,
236
+ createClearedCardQuery: () => createClearedCardQuery,
237
+ createCodeHiddenCardQuery: () => createCodeHiddenCardQuery,
234
238
  fillBinaryFields: () => fillBinaryFields,
235
239
  isIndexResponse: () => isIndexResponse,
240
+ parseCardQueryChunk: () => parseCardQueryChunk,
236
241
  serializeCardQuery: () => serializeCardQuery,
242
+ serializeCardQueryChunk: () => serializeCardQueryChunk,
237
243
  toBinaryFields: () => toBinaryFields
238
244
  });
239
245
  module.exports = __toCommonJS(index_exports);
@@ -1484,6 +1490,60 @@ function serializeCardQuery(card) {
1484
1490
  return new Uint8Array(view.buffer, view.byteOffset, offset);
1485
1491
  }
1486
1492
  __name(serializeCardQuery, "serializeCardQuery");
1493
+ function parseCardQueryChunk(data, offset = 0, context = "CardQuery") {
1494
+ if (offset + 4 > data.length) {
1495
+ throw new Error(`${context} chunk header truncated`);
1496
+ }
1497
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
1498
+ const length = view.getInt32(offset, true);
1499
+ if (length < 4) {
1500
+ throw new Error(`${context} invalid chunk length: ${length}`);
1501
+ }
1502
+ if (offset + length > data.length) {
1503
+ throw new Error(`${context} chunk payload truncated`);
1504
+ }
1505
+ const card = new CardQuery();
1506
+ card.queryLength = length;
1507
+ if (length === 4) {
1508
+ card.flags = 0;
1509
+ card.empty = true;
1510
+ return { card, length };
1511
+ }
1512
+ const payload = data.slice(offset + 4, offset + length);
1513
+ card.fromPayload(payload);
1514
+ return { card, length };
1515
+ }
1516
+ __name(parseCardQueryChunk, "parseCardQueryChunk");
1517
+ function serializeCardQueryChunk(card) {
1518
+ const flags = card?.flags ?? 0;
1519
+ const queryLength = card?.queryLength;
1520
+ if (flags === 0 && card?.empty && (!queryLength || queryLength <= 4)) {
1521
+ return { length: 4, payload: new Uint8Array(0) };
1522
+ }
1523
+ if (flags === 0 && queryLength && queryLength > 4) {
1524
+ return { length: queryLength, payload: new Uint8Array(queryLength - 4) };
1525
+ }
1526
+ const payload = serializeCardQuery(card);
1527
+ return { length: 4 + payload.length, payload };
1528
+ }
1529
+ __name(serializeCardQueryChunk, "serializeCardQueryChunk");
1530
+ function createClearedCardQuery(source) {
1531
+ const card = new CardQuery();
1532
+ card.flags = 0;
1533
+ card.empty = true;
1534
+ card.queryLength = source?.queryLength;
1535
+ return card;
1536
+ }
1537
+ __name(createClearedCardQuery, "createClearedCardQuery");
1538
+ function createCodeHiddenCardQuery(source) {
1539
+ const card = new CardQuery();
1540
+ card.flags = OcgcoreCommonConstants.QUERY_CODE;
1541
+ card.code = 0;
1542
+ card.empty = false;
1543
+ card.queryLength = source?.queryLength;
1544
+ return card;
1545
+ }
1546
+ __name(createCodeHiddenCardQuery, "createCodeHiddenCardQuery");
1487
1547
 
1488
1548
  // src/proto-base/ygopro-proto-base.ts
1489
1549
  var _YGOProProtoBase = class _YGOProProtoBase extends PayloadBase {
@@ -2362,6 +2422,9 @@ __decorateClass([
2362
2422
  __decorateClass([
2363
2423
  BinaryField("u8", 2)
2364
2424
  ], _YGOProMsgCancelTarget_CardLocation.prototype, "sequence", 2);
2425
+ __decorateClass([
2426
+ BinaryField("u8", 3)
2427
+ ], _YGOProMsgCancelTarget_CardLocation.prototype, "position", 2);
2365
2428
  var YGOProMsgCancelTarget_CardLocation = _YGOProMsgCancelTarget_CardLocation;
2366
2429
  var _YGOProMsgCancelTarget = class _YGOProMsgCancelTarget extends YGOProMsgBase {
2367
2430
  };
@@ -2371,7 +2434,7 @@ __decorateClass([
2371
2434
  BinaryField(() => YGOProMsgCancelTarget_CardLocation, 0)
2372
2435
  ], _YGOProMsgCancelTarget.prototype, "card1", 2);
2373
2436
  __decorateClass([
2374
- BinaryField(() => YGOProMsgCancelTarget_CardLocation, 3)
2437
+ BinaryField(() => YGOProMsgCancelTarget_CardLocation, 4)
2375
2438
  ], _YGOProMsgCancelTarget.prototype, "card2", 2);
2376
2439
  var YGOProMsgCancelTarget = _YGOProMsgCancelTarget;
2377
2440
 
@@ -2413,6 +2476,9 @@ __decorateClass([
2413
2476
  __decorateClass([
2414
2477
  BinaryField("u8", 2)
2415
2478
  ], _YGOProMsgCardTarget_CardLocation.prototype, "sequence", 2);
2479
+ __decorateClass([
2480
+ BinaryField("u8", 3)
2481
+ ], _YGOProMsgCardTarget_CardLocation.prototype, "position", 2);
2416
2482
  var YGOProMsgCardTarget_CardLocation = _YGOProMsgCardTarget_CardLocation;
2417
2483
  var _YGOProMsgCardTarget = class _YGOProMsgCardTarget extends YGOProMsgBase {
2418
2484
  };
@@ -2422,7 +2488,7 @@ __decorateClass([
2422
2488
  BinaryField(() => YGOProMsgCardTarget_CardLocation, 0)
2423
2489
  ], _YGOProMsgCardTarget.prototype, "card1", 2);
2424
2490
  __decorateClass([
2425
- BinaryField(() => YGOProMsgCardTarget_CardLocation, 3)
2491
+ BinaryField(() => YGOProMsgCardTarget_CardLocation, 4)
2426
2492
  ], _YGOProMsgCardTarget.prototype, "card2", 2);
2427
2493
  var YGOProMsgCardTarget = _YGOProMsgCardTarget;
2428
2494
 
@@ -3598,6 +3664,9 @@ __decorateClass([
3598
3664
  __decorateClass([
3599
3665
  BinaryField("u8", 2)
3600
3666
  ], _YGOProMsgEquip_CardLocation.prototype, "sequence", 2);
3667
+ __decorateClass([
3668
+ BinaryField("u8", 3)
3669
+ ], _YGOProMsgEquip_CardLocation.prototype, "position", 2);
3601
3670
  var YGOProMsgEquip_CardLocation = _YGOProMsgEquip_CardLocation;
3602
3671
  var _YGOProMsgEquip = class _YGOProMsgEquip extends YGOProMsgBase {
3603
3672
  };
@@ -3607,11 +3676,8 @@ __decorateClass([
3607
3676
  BinaryField(() => YGOProMsgEquip_CardLocation, 0)
3608
3677
  ], _YGOProMsgEquip.prototype, "equip", 2);
3609
3678
  __decorateClass([
3610
- BinaryField(() => YGOProMsgEquip_CardLocation, 3)
3679
+ BinaryField(() => YGOProMsgEquip_CardLocation, 4)
3611
3680
  ], _YGOProMsgEquip.prototype, "target", 2);
3612
- __decorateClass([
3613
- BinaryField("u8", 6)
3614
- ], _YGOProMsgEquip.prototype, "position", 2);
3615
3681
  var YGOProMsgEquip = _YGOProMsgEquip;
3616
3682
 
3617
3683
  // src/protos/msg/proto/field-disabled.ts
@@ -5768,10 +5834,16 @@ var _YGOProMsgSwap = class _YGOProMsgSwap extends YGOProMsgBase {
5768
5834
  __name(_YGOProMsgSwap, "YGOProMsgSwap");
5769
5835
  _YGOProMsgSwap.identifier = OcgcoreCommonConstants.MSG_SWAP;
5770
5836
  __decorateClass([
5771
- BinaryField(() => YGOProMsgSwap_CardLocation, 0)
5772
- ], _YGOProMsgSwap.prototype, "card1", 2);
5837
+ BinaryField("i32", 0)
5838
+ ], _YGOProMsgSwap.prototype, "code1", 2);
5773
5839
  __decorateClass([
5774
5840
  BinaryField(() => YGOProMsgSwap_CardLocation, 4)
5841
+ ], _YGOProMsgSwap.prototype, "card1", 2);
5842
+ __decorateClass([
5843
+ BinaryField("i32", 8)
5844
+ ], _YGOProMsgSwap.prototype, "code2", 2);
5845
+ __decorateClass([
5846
+ BinaryField(() => YGOProMsgSwap_CardLocation, 12)
5775
5847
  ], _YGOProMsgSwap.prototype, "card2", 2);
5776
5848
  var YGOProMsgSwap = _YGOProMsgSwap;
5777
5849
 
@@ -5875,16 +5947,38 @@ __decorateClass([
5875
5947
  ], _YGOProMsgTossDice.prototype, "results", 2);
5876
5948
  var YGOProMsgTossDice = _YGOProMsgTossDice;
5877
5949
 
5950
+ // src/protos/msg/proto/unequip.ts
5951
+ var _YGOProMsgUnequip_CardLocation = class _YGOProMsgUnequip_CardLocation {
5952
+ };
5953
+ __name(_YGOProMsgUnequip_CardLocation, "YGOProMsgUnequip_CardLocation");
5954
+ __decorateClass([
5955
+ BinaryField("u8", 0)
5956
+ ], _YGOProMsgUnequip_CardLocation.prototype, "controller", 2);
5957
+ __decorateClass([
5958
+ BinaryField("u8", 1)
5959
+ ], _YGOProMsgUnequip_CardLocation.prototype, "location", 2);
5960
+ __decorateClass([
5961
+ BinaryField("u8", 2)
5962
+ ], _YGOProMsgUnequip_CardLocation.prototype, "sequence", 2);
5963
+ __decorateClass([
5964
+ BinaryField("u8", 3)
5965
+ ], _YGOProMsgUnequip_CardLocation.prototype, "position", 2);
5966
+ var YGOProMsgUnequip_CardLocation = _YGOProMsgUnequip_CardLocation;
5967
+ var _YGOProMsgUnequip = class _YGOProMsgUnequip extends YGOProMsgBase {
5968
+ };
5969
+ __name(_YGOProMsgUnequip, "YGOProMsgUnequip");
5970
+ _YGOProMsgUnequip.identifier = 95;
5971
+ __decorateClass([
5972
+ BinaryField(() => YGOProMsgUnequip_CardLocation, 0)
5973
+ ], _YGOProMsgUnequip.prototype, "card", 2);
5974
+ var YGOProMsgUnequip = _YGOProMsgUnequip;
5975
+
5878
5976
  // src/protos/msg/proto/update-card.ts
5879
5977
  var _YGOProMsgUpdateCard = class _YGOProMsgUpdateCard extends YGOProMsgBase {
5880
5978
  opponentView() {
5881
5979
  const copy = this.copy();
5882
5980
  if (copy.card?.position && copy.card.position & OcgcoreCommonConstants.POS_FACEDOWN) {
5883
- const clearedCard = new CardQuery();
5884
- clearedCard.flags = OcgcoreCommonConstants.QUERY_CODE;
5885
- clearedCard.code = 0;
5886
- clearedCard.empty = false;
5887
- copy.card = clearedCard;
5981
+ copy.card = createCodeHiddenCardQuery(copy.card);
5888
5982
  }
5889
5983
  return copy;
5890
5984
  }
@@ -5917,31 +6011,26 @@ var _YGOProMsgUpdateCard = class _YGOProMsgUpdateCard extends YGOProMsgBase {
5917
6011
  this.location = data[2];
5918
6012
  this.sequence = data[3];
5919
6013
  const queryDataWithLength = data.slice(4);
5920
- if (queryDataWithLength.length < 8) {
5921
- throw new Error("Query data too short");
5922
- }
5923
- const view = new DataView(
5924
- queryDataWithLength.buffer,
5925
- queryDataWithLength.byteOffset,
5926
- queryDataWithLength.byteLength
6014
+ const { card } = parseCardQueryChunk(
6015
+ queryDataWithLength,
6016
+ 0,
6017
+ "MSG_UPDATE_CARD"
5927
6018
  );
5928
- const length = view.getInt32(0, true);
5929
- const cardQueryData = queryDataWithLength.slice(4, length);
5930
- this.card = new CardQuery();
5931
- this.card.fromPayload(cardQueryData);
6019
+ this.card = card;
5932
6020
  return this;
5933
6021
  }
5934
6022
  toPayload() {
5935
- const cardPayload = serializeCardQuery(this.card);
5936
- const length = 4 + cardPayload.length;
5937
- const result = new Uint8Array(4 + length);
6023
+ const chunk = serializeCardQueryChunk(this.card);
6024
+ const result = new Uint8Array(4 + chunk.length);
5938
6025
  const view = new DataView(result.buffer);
5939
6026
  result[0] = this.identifier;
5940
6027
  result[1] = this.controller;
5941
6028
  result[2] = this.location;
5942
6029
  result[3] = this.sequence;
5943
- view.setInt32(4, length, true);
5944
- result.set(cardPayload, 8);
6030
+ view.setInt32(4, chunk.length, true);
6031
+ if (chunk.payload.length > 0) {
6032
+ result.set(chunk.payload, 8);
6033
+ }
5945
6034
  return result;
5946
6035
  }
5947
6036
  getRequireRefreshCards() {
@@ -5960,15 +6049,33 @@ var YGOProMsgUpdateCard = _YGOProMsgUpdateCard;
5960
6049
 
5961
6050
  // src/protos/msg/proto/update-data.ts
5962
6051
  var _YGOProMsgUpdateData = class _YGOProMsgUpdateData extends YGOProMsgBase {
6052
+ shouldHideForOpponent(card) {
6053
+ if (this.location === OcgcoreScriptConstants.LOCATION_GRAVE) {
6054
+ return false;
6055
+ }
6056
+ if (this.location === OcgcoreScriptConstants.LOCATION_HAND) {
6057
+ return !card.position || !(card.position & OcgcoreCommonConstants.POS_FACEUP);
6058
+ }
6059
+ return !!(card.position && card.position & OcgcoreCommonConstants.POS_FACEDOWN);
6060
+ }
6061
+ shouldHideForTeammate(card) {
6062
+ if (this.location === OcgcoreScriptConstants.LOCATION_MZONE || this.location === OcgcoreScriptConstants.LOCATION_SZONE || this.location === OcgcoreScriptConstants.LOCATION_REMOVED || this.location === OcgcoreScriptConstants.LOCATION_GRAVE) {
6063
+ return false;
6064
+ }
6065
+ if (this.location === OcgcoreScriptConstants.LOCATION_HAND) {
6066
+ return !card.position || !(card.position & OcgcoreCommonConstants.POS_FACEUP);
6067
+ }
6068
+ if (this.location === OcgcoreScriptConstants.LOCATION_EXTRA) {
6069
+ return !!(card.position && card.position & OcgcoreCommonConstants.POS_FACEDOWN);
6070
+ }
6071
+ return false;
6072
+ }
5963
6073
  opponentView() {
5964
6074
  const copy = this.copy();
5965
6075
  if (copy.cards) {
5966
6076
  copy.cards = copy.cards.map((card) => {
5967
- if (card.position && card.position & OcgcoreCommonConstants.POS_FACEDOWN) {
5968
- const clearedCard = new CardQuery();
5969
- clearedCard.flags = 0;
5970
- clearedCard.empty = true;
5971
- return clearedCard;
6077
+ if (this.shouldHideForOpponent(card)) {
6078
+ return createClearedCardQuery(card);
5972
6079
  }
5973
6080
  return card;
5974
6081
  });
@@ -5976,25 +6083,16 @@ var _YGOProMsgUpdateData = class _YGOProMsgUpdateData extends YGOProMsgBase {
5976
6083
  return copy;
5977
6084
  }
5978
6085
  teammateView() {
5979
- if (this.location === OcgcoreScriptConstants.LOCATION_MZONE || this.location === OcgcoreScriptConstants.LOCATION_SZONE) {
5980
- return this.copy();
5981
- } else if (this.location === OcgcoreScriptConstants.LOCATION_HAND) {
5982
- const copy = this.copy();
5983
- if (copy.cards) {
5984
- copy.cards = copy.cards.map((card) => {
5985
- if (!card.position || !(card.position & OcgcoreCommonConstants.POS_FACEUP)) {
5986
- const clearedCard = new CardQuery();
5987
- clearedCard.flags = 0;
5988
- clearedCard.empty = true;
5989
- return clearedCard;
5990
- }
5991
- return card;
5992
- });
5993
- }
5994
- return copy;
5995
- } else {
5996
- return this.copy();
6086
+ const copy = this.copy();
6087
+ if (copy.cards) {
6088
+ copy.cards = copy.cards.map((card) => {
6089
+ if (this.shouldHideForTeammate(card)) {
6090
+ return createClearedCardQuery(card);
6091
+ }
6092
+ return card;
6093
+ });
5997
6094
  }
6095
+ return copy;
5998
6096
  }
5999
6097
  fromPayload(data) {
6000
6098
  if (data.length < 1) {
@@ -6013,35 +6111,24 @@ var _YGOProMsgUpdateData = class _YGOProMsgUpdateData extends YGOProMsgBase {
6013
6111
  this.location = data[2];
6014
6112
  this.cards = [];
6015
6113
  let offset = 3;
6016
- const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
6017
- while (offset + 4 <= data.length) {
6018
- const chunkLen = view.getInt32(offset, true);
6019
- if (chunkLen <= 0) {
6020
- break;
6021
- }
6022
- const end = Math.min(data.length, offset + chunkLen);
6023
- if (chunkLen <= 4) {
6024
- const card = new CardQuery();
6025
- card.flags = 0;
6026
- card.empty = true;
6027
- this.cards.push(card);
6028
- } else {
6029
- const cardQueryData = data.slice(offset + 4, end);
6030
- const card = new CardQuery();
6031
- card.fromPayload(cardQueryData);
6032
- this.cards.push(card);
6033
- }
6034
- offset += chunkLen;
6114
+ while (offset < data.length) {
6115
+ const { card, length } = parseCardQueryChunk(
6116
+ data,
6117
+ offset,
6118
+ "MSG_UPDATE_DATA"
6119
+ );
6120
+ this.cards.push(card);
6121
+ offset += length;
6035
6122
  }
6036
6123
  return this;
6037
6124
  }
6038
6125
  toPayload() {
6039
6126
  let totalSize = 3;
6040
- const cardPayloads = [];
6127
+ const chunks = [];
6041
6128
  for (const card of this.cards || []) {
6042
- const payload = serializeCardQuery(card);
6043
- cardPayloads.push(payload);
6044
- totalSize += 4 + payload.length;
6129
+ const chunk = serializeCardQueryChunk(card);
6130
+ chunks.push(chunk);
6131
+ totalSize += chunk.length;
6045
6132
  }
6046
6133
  const result = new Uint8Array(totalSize);
6047
6134
  const view = new DataView(result.buffer);
@@ -6049,12 +6136,13 @@ var _YGOProMsgUpdateData = class _YGOProMsgUpdateData extends YGOProMsgBase {
6049
6136
  result[offset++] = this.identifier;
6050
6137
  result[offset++] = this.player;
6051
6138
  result[offset++] = this.location;
6052
- for (const payload of cardPayloads) {
6053
- const length = 4 + payload.length;
6054
- view.setInt32(offset, length, true);
6139
+ for (const chunk of chunks) {
6140
+ view.setInt32(offset, chunk.length, true);
6055
6141
  offset += 4;
6056
- result.set(payload, offset);
6057
- offset += payload.length;
6142
+ if (chunk.payload.length > 0) {
6143
+ result.set(chunk.payload, offset);
6144
+ offset += chunk.payload.length;
6145
+ }
6058
6146
  }
6059
6147
  return result;
6060
6148
  }
@@ -6143,6 +6231,7 @@ YGOProMessages.register(YGOProMsgDraw);
6143
6231
  YGOProMessages.register(YGOProMsgDamage);
6144
6232
  YGOProMessages.register(YGOProMsgRecover);
6145
6233
  YGOProMessages.register(YGOProMsgEquip);
6234
+ YGOProMessages.register(YGOProMsgUnequip);
6146
6235
  YGOProMessages.register(YGOProMsgLpUpdate);
6147
6236
  YGOProMessages.register(YGOProMsgCardTarget);
6148
6237
  YGOProMessages.register(YGOProMsgCancelTarget);
@@ -6756,6 +6845,8 @@ YGOProStoc.register(YGOProStocSrvproRoomlist);
6756
6845
  YGOProMsgTagSwap,
6757
6846
  YGOProMsgTossCoin,
6758
6847
  YGOProMsgTossDice,
6848
+ YGOProMsgUnequip,
6849
+ YGOProMsgUnequip_CardLocation,
6759
6850
  YGOProMsgUpdateCard,
6760
6851
  YGOProMsgUpdateData,
6761
6852
  YGOProMsgWaiting,
@@ -6788,9 +6879,13 @@ YGOProStoc.register(YGOProStocSrvproRoomlist);
6788
6879
  YGOProStocTpResult,
6789
6880
  YGOProStocTypeChange,
6790
6881
  YGOProStocWaitingSide,
6882
+ createClearedCardQuery,
6883
+ createCodeHiddenCardQuery,
6791
6884
  fillBinaryFields,
6792
6885
  isIndexResponse,
6886
+ parseCardQueryChunk,
6793
6887
  serializeCardQuery,
6888
+ serializeCardQueryChunk,
6794
6889
  toBinaryFields
6795
6890
  });
6796
6891
  //# sourceMappingURL=index.cjs.map