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.mjs CHANGED
@@ -1264,6 +1264,60 @@ function serializeCardQuery(card) {
1264
1264
  return new Uint8Array(view.buffer, view.byteOffset, offset);
1265
1265
  }
1266
1266
  __name(serializeCardQuery, "serializeCardQuery");
1267
+ function parseCardQueryChunk(data, offset = 0, context = "CardQuery") {
1268
+ if (offset + 4 > data.length) {
1269
+ throw new Error(`${context} chunk header truncated`);
1270
+ }
1271
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
1272
+ const length = view.getInt32(offset, true);
1273
+ if (length < 4) {
1274
+ throw new Error(`${context} invalid chunk length: ${length}`);
1275
+ }
1276
+ if (offset + length > data.length) {
1277
+ throw new Error(`${context} chunk payload truncated`);
1278
+ }
1279
+ const card = new CardQuery();
1280
+ card.queryLength = length;
1281
+ if (length === 4) {
1282
+ card.flags = 0;
1283
+ card.empty = true;
1284
+ return { card, length };
1285
+ }
1286
+ const payload = data.slice(offset + 4, offset + length);
1287
+ card.fromPayload(payload);
1288
+ return { card, length };
1289
+ }
1290
+ __name(parseCardQueryChunk, "parseCardQueryChunk");
1291
+ function serializeCardQueryChunk(card) {
1292
+ const flags = card?.flags ?? 0;
1293
+ const queryLength = card?.queryLength;
1294
+ if (flags === 0 && card?.empty && (!queryLength || queryLength <= 4)) {
1295
+ return { length: 4, payload: new Uint8Array(0) };
1296
+ }
1297
+ if (flags === 0 && queryLength && queryLength > 4) {
1298
+ return { length: queryLength, payload: new Uint8Array(queryLength - 4) };
1299
+ }
1300
+ const payload = serializeCardQuery(card);
1301
+ return { length: 4 + payload.length, payload };
1302
+ }
1303
+ __name(serializeCardQueryChunk, "serializeCardQueryChunk");
1304
+ function createClearedCardQuery(source) {
1305
+ const card = new CardQuery();
1306
+ card.flags = 0;
1307
+ card.empty = true;
1308
+ card.queryLength = source?.queryLength;
1309
+ return card;
1310
+ }
1311
+ __name(createClearedCardQuery, "createClearedCardQuery");
1312
+ function createCodeHiddenCardQuery(source) {
1313
+ const card = new CardQuery();
1314
+ card.flags = OcgcoreCommonConstants.QUERY_CODE;
1315
+ card.code = 0;
1316
+ card.empty = false;
1317
+ card.queryLength = source?.queryLength;
1318
+ return card;
1319
+ }
1320
+ __name(createCodeHiddenCardQuery, "createCodeHiddenCardQuery");
1267
1321
 
1268
1322
  // src/proto-base/ygopro-proto-base.ts
1269
1323
  var YGOProProtoBase = class extends PayloadBase {
@@ -2250,6 +2304,9 @@ __decorateClass([
2250
2304
  __decorateClass([
2251
2305
  BinaryField("u8", 2)
2252
2306
  ], YGOProMsgCancelTarget_CardLocation.prototype, "sequence", 2);
2307
+ __decorateClass([
2308
+ BinaryField("u8", 3)
2309
+ ], YGOProMsgCancelTarget_CardLocation.prototype, "position", 2);
2253
2310
  var YGOProMsgCancelTarget = class extends YGOProMsgBase {
2254
2311
  static {
2255
2312
  __name(this, "YGOProMsgCancelTarget");
@@ -2262,7 +2319,7 @@ __decorateClass([
2262
2319
  BinaryField(() => YGOProMsgCancelTarget_CardLocation, 0)
2263
2320
  ], YGOProMsgCancelTarget.prototype, "card1", 2);
2264
2321
  __decorateClass([
2265
- BinaryField(() => YGOProMsgCancelTarget_CardLocation, 3)
2322
+ BinaryField(() => YGOProMsgCancelTarget_CardLocation, 4)
2266
2323
  ], YGOProMsgCancelTarget.prototype, "card2", 2);
2267
2324
 
2268
2325
  // src/protos/msg/proto/card-hint.ts
@@ -2308,6 +2365,9 @@ __decorateClass([
2308
2365
  __decorateClass([
2309
2366
  BinaryField("u8", 2)
2310
2367
  ], YGOProMsgCardTarget_CardLocation.prototype, "sequence", 2);
2368
+ __decorateClass([
2369
+ BinaryField("u8", 3)
2370
+ ], YGOProMsgCardTarget_CardLocation.prototype, "position", 2);
2311
2371
  var YGOProMsgCardTarget = class extends YGOProMsgBase {
2312
2372
  static {
2313
2373
  __name(this, "YGOProMsgCardTarget");
@@ -2320,7 +2380,7 @@ __decorateClass([
2320
2380
  BinaryField(() => YGOProMsgCardTarget_CardLocation, 0)
2321
2381
  ], YGOProMsgCardTarget.prototype, "card1", 2);
2322
2382
  __decorateClass([
2323
- BinaryField(() => YGOProMsgCardTarget_CardLocation, 3)
2383
+ BinaryField(() => YGOProMsgCardTarget_CardLocation, 4)
2324
2384
  ], YGOProMsgCardTarget.prototype, "card2", 2);
2325
2385
 
2326
2386
  // src/protos/msg/proto/chain-disabled.ts
@@ -3546,6 +3606,9 @@ __decorateClass([
3546
3606
  __decorateClass([
3547
3607
  BinaryField("u8", 2)
3548
3608
  ], YGOProMsgEquip_CardLocation.prototype, "sequence", 2);
3609
+ __decorateClass([
3610
+ BinaryField("u8", 3)
3611
+ ], YGOProMsgEquip_CardLocation.prototype, "position", 2);
3549
3612
  var YGOProMsgEquip = class extends YGOProMsgBase {
3550
3613
  static {
3551
3614
  __name(this, "YGOProMsgEquip");
@@ -3558,11 +3621,8 @@ __decorateClass([
3558
3621
  BinaryField(() => YGOProMsgEquip_CardLocation, 0)
3559
3622
  ], YGOProMsgEquip.prototype, "equip", 2);
3560
3623
  __decorateClass([
3561
- BinaryField(() => YGOProMsgEquip_CardLocation, 3)
3624
+ BinaryField(() => YGOProMsgEquip_CardLocation, 4)
3562
3625
  ], YGOProMsgEquip.prototype, "target", 2);
3563
- __decorateClass([
3564
- BinaryField("u8", 6)
3565
- ], YGOProMsgEquip.prototype, "position", 2);
3566
3626
 
3567
3627
  // src/protos/msg/proto/field-disabled.ts
3568
3628
  var YGOProMsgFieldDisabled = class extends YGOProMsgBase {
@@ -3927,13 +3987,16 @@ var YGOProMsgPosChange = class extends YGOProMsgBase {
3927
3987
  }
3928
3988
  };
3929
3989
  __decorateClass([
3930
- BinaryField(() => YGOProMsgPosChange_CardLocation, 0)
3990
+ BinaryField("i32", 0)
3991
+ ], YGOProMsgPosChange.prototype, "code", 2);
3992
+ __decorateClass([
3993
+ BinaryField(() => YGOProMsgPosChange_CardLocation, 4)
3931
3994
  ], YGOProMsgPosChange.prototype, "card", 2);
3932
3995
  __decorateClass([
3933
- BinaryField("u8", 3)
3996
+ BinaryField("u8", 7)
3934
3997
  ], YGOProMsgPosChange.prototype, "previousPosition", 2);
3935
3998
  __decorateClass([
3936
- BinaryField("u8", 4)
3999
+ BinaryField("u8", 8)
3937
4000
  ], YGOProMsgPosChange.prototype, "currentPosition", 2);
3938
4001
 
3939
4002
  // src/protos/msg/proto/random-selected.ts
@@ -5881,10 +5944,16 @@ var YGOProMsgSwap = class extends YGOProMsgBase {
5881
5944
  }
5882
5945
  };
5883
5946
  __decorateClass([
5884
- BinaryField(() => YGOProMsgSwap_CardLocation, 0)
5885
- ], YGOProMsgSwap.prototype, "card1", 2);
5947
+ BinaryField("i32", 0)
5948
+ ], YGOProMsgSwap.prototype, "code1", 2);
5886
5949
  __decorateClass([
5887
5950
  BinaryField(() => YGOProMsgSwap_CardLocation, 4)
5951
+ ], YGOProMsgSwap.prototype, "card1", 2);
5952
+ __decorateClass([
5953
+ BinaryField("i32", 8)
5954
+ ], YGOProMsgSwap.prototype, "code2", 2);
5955
+ __decorateClass([
5956
+ BinaryField(() => YGOProMsgSwap_CardLocation, 12)
5888
5957
  ], YGOProMsgSwap.prototype, "card2", 2);
5889
5958
 
5890
5959
  // src/protos/msg/proto/swap-grave-deck.ts
@@ -5999,6 +6068,36 @@ __decorateClass([
5999
6068
  BinaryField("u8", 2, (obj) => obj.count)
6000
6069
  ], YGOProMsgTossDice.prototype, "results", 2);
6001
6070
 
6071
+ // src/protos/msg/proto/unequip.ts
6072
+ var YGOProMsgUnequip_CardLocation = class {
6073
+ static {
6074
+ __name(this, "YGOProMsgUnequip_CardLocation");
6075
+ }
6076
+ };
6077
+ __decorateClass([
6078
+ BinaryField("u8", 0)
6079
+ ], YGOProMsgUnequip_CardLocation.prototype, "controller", 2);
6080
+ __decorateClass([
6081
+ BinaryField("u8", 1)
6082
+ ], YGOProMsgUnequip_CardLocation.prototype, "location", 2);
6083
+ __decorateClass([
6084
+ BinaryField("u8", 2)
6085
+ ], YGOProMsgUnequip_CardLocation.prototype, "sequence", 2);
6086
+ __decorateClass([
6087
+ BinaryField("u8", 3)
6088
+ ], YGOProMsgUnequip_CardLocation.prototype, "position", 2);
6089
+ var YGOProMsgUnequip = class extends YGOProMsgBase {
6090
+ static {
6091
+ __name(this, "YGOProMsgUnequip");
6092
+ }
6093
+ static {
6094
+ this.identifier = 95;
6095
+ }
6096
+ };
6097
+ __decorateClass([
6098
+ BinaryField(() => YGOProMsgUnequip_CardLocation, 0)
6099
+ ], YGOProMsgUnequip.prototype, "card", 2);
6100
+
6002
6101
  // src/protos/msg/proto/update-card.ts
6003
6102
  var YGOProMsgUpdateCard = class extends YGOProMsgBase {
6004
6103
  static {
@@ -6010,11 +6109,7 @@ var YGOProMsgUpdateCard = class extends YGOProMsgBase {
6010
6109
  opponentView() {
6011
6110
  const copy = this.copy();
6012
6111
  if (copy.card?.position && copy.card.position & OcgcoreCommonConstants.POS_FACEDOWN) {
6013
- const clearedCard = new CardQuery();
6014
- clearedCard.flags = OcgcoreCommonConstants.QUERY_CODE;
6015
- clearedCard.code = 0;
6016
- clearedCard.empty = false;
6017
- copy.card = clearedCard;
6112
+ copy.card = createCodeHiddenCardQuery(copy.card);
6018
6113
  }
6019
6114
  return copy;
6020
6115
  }
@@ -6047,31 +6142,26 @@ var YGOProMsgUpdateCard = class extends YGOProMsgBase {
6047
6142
  this.location = data[2];
6048
6143
  this.sequence = data[3];
6049
6144
  const queryDataWithLength = data.slice(4);
6050
- if (queryDataWithLength.length < 8) {
6051
- throw new Error("Query data too short");
6052
- }
6053
- const view = new DataView(
6054
- queryDataWithLength.buffer,
6055
- queryDataWithLength.byteOffset,
6056
- queryDataWithLength.byteLength
6145
+ const { card } = parseCardQueryChunk(
6146
+ queryDataWithLength,
6147
+ 0,
6148
+ "MSG_UPDATE_CARD"
6057
6149
  );
6058
- const length = view.getInt32(0, true);
6059
- const cardQueryData = queryDataWithLength.slice(4, length);
6060
- this.card = new CardQuery();
6061
- this.card.fromPayload(cardQueryData);
6150
+ this.card = card;
6062
6151
  return this;
6063
6152
  }
6064
6153
  toPayload() {
6065
- const cardPayload = serializeCardQuery(this.card);
6066
- const length = 4 + cardPayload.length;
6067
- const result = new Uint8Array(4 + length);
6154
+ const chunk = serializeCardQueryChunk(this.card);
6155
+ const result = new Uint8Array(4 + chunk.length);
6068
6156
  const view = new DataView(result.buffer);
6069
6157
  result[0] = this.identifier;
6070
6158
  result[1] = this.controller;
6071
6159
  result[2] = this.location;
6072
6160
  result[3] = this.sequence;
6073
- view.setInt32(4, length, true);
6074
- result.set(cardPayload, 8);
6161
+ view.setInt32(4, chunk.length, true);
6162
+ if (chunk.payload.length > 0) {
6163
+ result.set(chunk.payload, 8);
6164
+ }
6075
6165
  return result;
6076
6166
  }
6077
6167
  getRequireRefreshCards() {
@@ -6093,15 +6183,33 @@ var YGOProMsgUpdateData = class extends YGOProMsgBase {
6093
6183
  static {
6094
6184
  this.identifier = 6;
6095
6185
  }
6186
+ shouldHideForOpponent(card) {
6187
+ if (this.location === OcgcoreScriptConstants.LOCATION_GRAVE) {
6188
+ return false;
6189
+ }
6190
+ if (this.location === OcgcoreScriptConstants.LOCATION_HAND) {
6191
+ return !card.position || !(card.position & OcgcoreCommonConstants.POS_FACEUP);
6192
+ }
6193
+ return !!(card.position && card.position & OcgcoreCommonConstants.POS_FACEDOWN);
6194
+ }
6195
+ shouldHideForTeammate(card) {
6196
+ if (this.location === OcgcoreScriptConstants.LOCATION_MZONE || this.location === OcgcoreScriptConstants.LOCATION_SZONE || this.location === OcgcoreScriptConstants.LOCATION_REMOVED || this.location === OcgcoreScriptConstants.LOCATION_GRAVE) {
6197
+ return false;
6198
+ }
6199
+ if (this.location === OcgcoreScriptConstants.LOCATION_HAND) {
6200
+ return !card.position || !(card.position & OcgcoreCommonConstants.POS_FACEUP);
6201
+ }
6202
+ if (this.location === OcgcoreScriptConstants.LOCATION_EXTRA) {
6203
+ return !!(card.position && card.position & OcgcoreCommonConstants.POS_FACEDOWN);
6204
+ }
6205
+ return false;
6206
+ }
6096
6207
  opponentView() {
6097
6208
  const copy = this.copy();
6098
6209
  if (copy.cards) {
6099
6210
  copy.cards = copy.cards.map((card) => {
6100
- if (card.position && card.position & OcgcoreCommonConstants.POS_FACEDOWN) {
6101
- const clearedCard = new CardQuery();
6102
- clearedCard.flags = 0;
6103
- clearedCard.empty = true;
6104
- return clearedCard;
6211
+ if (this.shouldHideForOpponent(card)) {
6212
+ return createClearedCardQuery(card);
6105
6213
  }
6106
6214
  return card;
6107
6215
  });
@@ -6109,25 +6217,16 @@ var YGOProMsgUpdateData = class extends YGOProMsgBase {
6109
6217
  return copy;
6110
6218
  }
6111
6219
  teammateView() {
6112
- if (this.location === OcgcoreScriptConstants.LOCATION_MZONE || this.location === OcgcoreScriptConstants.LOCATION_SZONE) {
6113
- return this.copy();
6114
- } else if (this.location === OcgcoreScriptConstants.LOCATION_HAND) {
6115
- const copy = this.copy();
6116
- if (copy.cards) {
6117
- copy.cards = copy.cards.map((card) => {
6118
- if (!card.position || !(card.position & OcgcoreCommonConstants.POS_FACEUP)) {
6119
- const clearedCard = new CardQuery();
6120
- clearedCard.flags = 0;
6121
- clearedCard.empty = true;
6122
- return clearedCard;
6123
- }
6124
- return card;
6125
- });
6126
- }
6127
- return copy;
6128
- } else {
6129
- return this.copy();
6220
+ const copy = this.copy();
6221
+ if (copy.cards) {
6222
+ copy.cards = copy.cards.map((card) => {
6223
+ if (this.shouldHideForTeammate(card)) {
6224
+ return createClearedCardQuery(card);
6225
+ }
6226
+ return card;
6227
+ });
6130
6228
  }
6229
+ return copy;
6131
6230
  }
6132
6231
  fromPayload(data) {
6133
6232
  if (data.length < 1) {
@@ -6146,35 +6245,24 @@ var YGOProMsgUpdateData = class extends YGOProMsgBase {
6146
6245
  this.location = data[2];
6147
6246
  this.cards = [];
6148
6247
  let offset = 3;
6149
- const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
6150
- while (offset + 4 <= data.length) {
6151
- const chunkLen = view.getInt32(offset, true);
6152
- if (chunkLen <= 0) {
6153
- break;
6154
- }
6155
- const end = Math.min(data.length, offset + chunkLen);
6156
- if (chunkLen <= 4) {
6157
- const card = new CardQuery();
6158
- card.flags = 0;
6159
- card.empty = true;
6160
- this.cards.push(card);
6161
- } else {
6162
- const cardQueryData = data.slice(offset + 4, end);
6163
- const card = new CardQuery();
6164
- card.fromPayload(cardQueryData);
6165
- this.cards.push(card);
6166
- }
6167
- offset += chunkLen;
6248
+ while (offset < data.length) {
6249
+ const { card, length } = parseCardQueryChunk(
6250
+ data,
6251
+ offset,
6252
+ "MSG_UPDATE_DATA"
6253
+ );
6254
+ this.cards.push(card);
6255
+ offset += length;
6168
6256
  }
6169
6257
  return this;
6170
6258
  }
6171
6259
  toPayload() {
6172
6260
  let totalSize = 3;
6173
- const cardPayloads = [];
6261
+ const chunks = [];
6174
6262
  for (const card of this.cards || []) {
6175
- const payload = serializeCardQuery(card);
6176
- cardPayloads.push(payload);
6177
- totalSize += 4 + payload.length;
6263
+ const chunk = serializeCardQueryChunk(card);
6264
+ chunks.push(chunk);
6265
+ totalSize += chunk.length;
6178
6266
  }
6179
6267
  const result = new Uint8Array(totalSize);
6180
6268
  const view = new DataView(result.buffer);
@@ -6182,12 +6270,13 @@ var YGOProMsgUpdateData = class extends YGOProMsgBase {
6182
6270
  result[offset++] = this.identifier;
6183
6271
  result[offset++] = this.player;
6184
6272
  result[offset++] = this.location;
6185
- for (const payload of cardPayloads) {
6186
- const length = 4 + payload.length;
6187
- view.setInt32(offset, length, true);
6273
+ for (const chunk of chunks) {
6274
+ view.setInt32(offset, chunk.length, true);
6188
6275
  offset += 4;
6189
- result.set(payload, offset);
6190
- offset += payload.length;
6276
+ if (chunk.payload.length > 0) {
6277
+ result.set(chunk.payload, offset);
6278
+ offset += chunk.payload.length;
6279
+ }
6191
6280
  }
6192
6281
  return result;
6193
6282
  }
@@ -6279,6 +6368,7 @@ YGOProMessages.register(YGOProMsgDraw);
6279
6368
  YGOProMessages.register(YGOProMsgDamage);
6280
6369
  YGOProMessages.register(YGOProMsgRecover);
6281
6370
  YGOProMessages.register(YGOProMsgEquip);
6371
+ YGOProMessages.register(YGOProMsgUnequip);
6282
6372
  YGOProMessages.register(YGOProMsgLpUpdate);
6283
6373
  YGOProMessages.register(YGOProMsgCardTarget);
6284
6374
  YGOProMessages.register(YGOProMsgCancelTarget);
@@ -6967,6 +7057,8 @@ export {
6967
7057
  YGOProMsgTagSwap,
6968
7058
  YGOProMsgTossCoin,
6969
7059
  YGOProMsgTossDice,
7060
+ YGOProMsgUnequip,
7061
+ YGOProMsgUnequip_CardLocation,
6970
7062
  YGOProMsgUpdateCard,
6971
7063
  YGOProMsgUpdateData,
6972
7064
  YGOProMsgWaiting,
@@ -6999,9 +7091,13 @@ export {
6999
7091
  YGOProStocTpResult,
7000
7092
  YGOProStocTypeChange,
7001
7093
  YGOProStocWaitingSide,
7094
+ createClearedCardQuery,
7095
+ createCodeHiddenCardQuery,
7002
7096
  fillBinaryFields,
7003
7097
  isIndexResponse,
7098
+ parseCardQueryChunk,
7004
7099
  serializeCardQuery,
7100
+ serializeCardQueryChunk,
7005
7101
  toBinaryFields
7006
7102
  };
7007
7103
  //# sourceMappingURL=index.mjs.map