ygopro-msg-encode 1.1.24 → 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
@@ -3932,13 +3998,16 @@ var _YGOProMsgPosChange = class _YGOProMsgPosChange extends YGOProMsgBase {
3932
3998
  __name(_YGOProMsgPosChange, "YGOProMsgPosChange");
3933
3999
  _YGOProMsgPosChange.identifier = OcgcoreCommonConstants.MSG_POS_CHANGE;
3934
4000
  __decorateClass([
3935
- BinaryField(() => YGOProMsgPosChange_CardLocation, 0)
4001
+ BinaryField("i32", 0)
4002
+ ], _YGOProMsgPosChange.prototype, "code", 2);
4003
+ __decorateClass([
4004
+ BinaryField(() => YGOProMsgPosChange_CardLocation, 4)
3936
4005
  ], _YGOProMsgPosChange.prototype, "card", 2);
3937
4006
  __decorateClass([
3938
- BinaryField("u8", 3)
4007
+ BinaryField("u8", 7)
3939
4008
  ], _YGOProMsgPosChange.prototype, "previousPosition", 2);
3940
4009
  __decorateClass([
3941
- BinaryField("u8", 4)
4010
+ BinaryField("u8", 8)
3942
4011
  ], _YGOProMsgPosChange.prototype, "currentPosition", 2);
3943
4012
  var YGOProMsgPosChange = _YGOProMsgPosChange;
3944
4013
 
@@ -5765,10 +5834,16 @@ var _YGOProMsgSwap = class _YGOProMsgSwap extends YGOProMsgBase {
5765
5834
  __name(_YGOProMsgSwap, "YGOProMsgSwap");
5766
5835
  _YGOProMsgSwap.identifier = OcgcoreCommonConstants.MSG_SWAP;
5767
5836
  __decorateClass([
5768
- BinaryField(() => YGOProMsgSwap_CardLocation, 0)
5769
- ], _YGOProMsgSwap.prototype, "card1", 2);
5837
+ BinaryField("i32", 0)
5838
+ ], _YGOProMsgSwap.prototype, "code1", 2);
5770
5839
  __decorateClass([
5771
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)
5772
5847
  ], _YGOProMsgSwap.prototype, "card2", 2);
5773
5848
  var YGOProMsgSwap = _YGOProMsgSwap;
5774
5849
 
@@ -5872,16 +5947,38 @@ __decorateClass([
5872
5947
  ], _YGOProMsgTossDice.prototype, "results", 2);
5873
5948
  var YGOProMsgTossDice = _YGOProMsgTossDice;
5874
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
+
5875
5976
  // src/protos/msg/proto/update-card.ts
5876
5977
  var _YGOProMsgUpdateCard = class _YGOProMsgUpdateCard extends YGOProMsgBase {
5877
5978
  opponentView() {
5878
5979
  const copy = this.copy();
5879
5980
  if (copy.card?.position && copy.card.position & OcgcoreCommonConstants.POS_FACEDOWN) {
5880
- const clearedCard = new CardQuery();
5881
- clearedCard.flags = OcgcoreCommonConstants.QUERY_CODE;
5882
- clearedCard.code = 0;
5883
- clearedCard.empty = false;
5884
- copy.card = clearedCard;
5981
+ copy.card = createCodeHiddenCardQuery(copy.card);
5885
5982
  }
5886
5983
  return copy;
5887
5984
  }
@@ -5914,31 +6011,26 @@ var _YGOProMsgUpdateCard = class _YGOProMsgUpdateCard extends YGOProMsgBase {
5914
6011
  this.location = data[2];
5915
6012
  this.sequence = data[3];
5916
6013
  const queryDataWithLength = data.slice(4);
5917
- if (queryDataWithLength.length < 8) {
5918
- throw new Error("Query data too short");
5919
- }
5920
- const view = new DataView(
5921
- queryDataWithLength.buffer,
5922
- queryDataWithLength.byteOffset,
5923
- queryDataWithLength.byteLength
6014
+ const { card } = parseCardQueryChunk(
6015
+ queryDataWithLength,
6016
+ 0,
6017
+ "MSG_UPDATE_CARD"
5924
6018
  );
5925
- const length = view.getInt32(0, true);
5926
- const cardQueryData = queryDataWithLength.slice(4, length);
5927
- this.card = new CardQuery();
5928
- this.card.fromPayload(cardQueryData);
6019
+ this.card = card;
5929
6020
  return this;
5930
6021
  }
5931
6022
  toPayload() {
5932
- const cardPayload = serializeCardQuery(this.card);
5933
- const length = 4 + cardPayload.length;
5934
- const result = new Uint8Array(4 + length);
6023
+ const chunk = serializeCardQueryChunk(this.card);
6024
+ const result = new Uint8Array(4 + chunk.length);
5935
6025
  const view = new DataView(result.buffer);
5936
6026
  result[0] = this.identifier;
5937
6027
  result[1] = this.controller;
5938
6028
  result[2] = this.location;
5939
6029
  result[3] = this.sequence;
5940
- view.setInt32(4, length, true);
5941
- result.set(cardPayload, 8);
6030
+ view.setInt32(4, chunk.length, true);
6031
+ if (chunk.payload.length > 0) {
6032
+ result.set(chunk.payload, 8);
6033
+ }
5942
6034
  return result;
5943
6035
  }
5944
6036
  getRequireRefreshCards() {
@@ -5957,15 +6049,33 @@ var YGOProMsgUpdateCard = _YGOProMsgUpdateCard;
5957
6049
 
5958
6050
  // src/protos/msg/proto/update-data.ts
5959
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
+ }
5960
6073
  opponentView() {
5961
6074
  const copy = this.copy();
5962
6075
  if (copy.cards) {
5963
6076
  copy.cards = copy.cards.map((card) => {
5964
- if (card.position && card.position & OcgcoreCommonConstants.POS_FACEDOWN) {
5965
- const clearedCard = new CardQuery();
5966
- clearedCard.flags = 0;
5967
- clearedCard.empty = true;
5968
- return clearedCard;
6077
+ if (this.shouldHideForOpponent(card)) {
6078
+ return createClearedCardQuery(card);
5969
6079
  }
5970
6080
  return card;
5971
6081
  });
@@ -5973,25 +6083,16 @@ var _YGOProMsgUpdateData = class _YGOProMsgUpdateData extends YGOProMsgBase {
5973
6083
  return copy;
5974
6084
  }
5975
6085
  teammateView() {
5976
- if (this.location === OcgcoreScriptConstants.LOCATION_MZONE || this.location === OcgcoreScriptConstants.LOCATION_SZONE) {
5977
- return this.copy();
5978
- } else if (this.location === OcgcoreScriptConstants.LOCATION_HAND) {
5979
- const copy = this.copy();
5980
- if (copy.cards) {
5981
- copy.cards = copy.cards.map((card) => {
5982
- if (!card.position || !(card.position & OcgcoreCommonConstants.POS_FACEUP)) {
5983
- const clearedCard = new CardQuery();
5984
- clearedCard.flags = 0;
5985
- clearedCard.empty = true;
5986
- return clearedCard;
5987
- }
5988
- return card;
5989
- });
5990
- }
5991
- return copy;
5992
- } else {
5993
- 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
+ });
5994
6094
  }
6095
+ return copy;
5995
6096
  }
5996
6097
  fromPayload(data) {
5997
6098
  if (data.length < 1) {
@@ -6010,35 +6111,24 @@ var _YGOProMsgUpdateData = class _YGOProMsgUpdateData extends YGOProMsgBase {
6010
6111
  this.location = data[2];
6011
6112
  this.cards = [];
6012
6113
  let offset = 3;
6013
- const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
6014
- while (offset + 4 <= data.length) {
6015
- const chunkLen = view.getInt32(offset, true);
6016
- if (chunkLen <= 0) {
6017
- break;
6018
- }
6019
- const end = Math.min(data.length, offset + chunkLen);
6020
- if (chunkLen <= 4) {
6021
- const card = new CardQuery();
6022
- card.flags = 0;
6023
- card.empty = true;
6024
- this.cards.push(card);
6025
- } else {
6026
- const cardQueryData = data.slice(offset + 4, end);
6027
- const card = new CardQuery();
6028
- card.fromPayload(cardQueryData);
6029
- this.cards.push(card);
6030
- }
6031
- 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;
6032
6122
  }
6033
6123
  return this;
6034
6124
  }
6035
6125
  toPayload() {
6036
6126
  let totalSize = 3;
6037
- const cardPayloads = [];
6127
+ const chunks = [];
6038
6128
  for (const card of this.cards || []) {
6039
- const payload = serializeCardQuery(card);
6040
- cardPayloads.push(payload);
6041
- totalSize += 4 + payload.length;
6129
+ const chunk = serializeCardQueryChunk(card);
6130
+ chunks.push(chunk);
6131
+ totalSize += chunk.length;
6042
6132
  }
6043
6133
  const result = new Uint8Array(totalSize);
6044
6134
  const view = new DataView(result.buffer);
@@ -6046,12 +6136,13 @@ var _YGOProMsgUpdateData = class _YGOProMsgUpdateData extends YGOProMsgBase {
6046
6136
  result[offset++] = this.identifier;
6047
6137
  result[offset++] = this.player;
6048
6138
  result[offset++] = this.location;
6049
- for (const payload of cardPayloads) {
6050
- const length = 4 + payload.length;
6051
- view.setInt32(offset, length, true);
6139
+ for (const chunk of chunks) {
6140
+ view.setInt32(offset, chunk.length, true);
6052
6141
  offset += 4;
6053
- result.set(payload, offset);
6054
- offset += payload.length;
6142
+ if (chunk.payload.length > 0) {
6143
+ result.set(chunk.payload, offset);
6144
+ offset += chunk.payload.length;
6145
+ }
6055
6146
  }
6056
6147
  return result;
6057
6148
  }
@@ -6140,6 +6231,7 @@ YGOProMessages.register(YGOProMsgDraw);
6140
6231
  YGOProMessages.register(YGOProMsgDamage);
6141
6232
  YGOProMessages.register(YGOProMsgRecover);
6142
6233
  YGOProMessages.register(YGOProMsgEquip);
6234
+ YGOProMessages.register(YGOProMsgUnequip);
6143
6235
  YGOProMessages.register(YGOProMsgLpUpdate);
6144
6236
  YGOProMessages.register(YGOProMsgCardTarget);
6145
6237
  YGOProMessages.register(YGOProMsgCancelTarget);
@@ -6753,6 +6845,8 @@ YGOProStoc.register(YGOProStocSrvproRoomlist);
6753
6845
  YGOProMsgTagSwap,
6754
6846
  YGOProMsgTossCoin,
6755
6847
  YGOProMsgTossDice,
6848
+ YGOProMsgUnequip,
6849
+ YGOProMsgUnequip_CardLocation,
6756
6850
  YGOProMsgUpdateCard,
6757
6851
  YGOProMsgUpdateData,
6758
6852
  YGOProMsgWaiting,
@@ -6785,9 +6879,13 @@ YGOProStoc.register(YGOProStocSrvproRoomlist);
6785
6879
  YGOProStocTpResult,
6786
6880
  YGOProStocTypeChange,
6787
6881
  YGOProStocWaitingSide,
6882
+ createClearedCardQuery,
6883
+ createCodeHiddenCardQuery,
6788
6884
  fillBinaryFields,
6789
6885
  isIndexResponse,
6886
+ parseCardQueryChunk,
6790
6887
  serializeCardQuery,
6888
+ serializeCardQueryChunk,
6791
6889
  toBinaryFields
6792
6890
  });
6793
6891
  //# sourceMappingURL=index.cjs.map