ygopro-msg-encode 1.1.19 → 1.1.21

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
@@ -1359,6 +1359,74 @@ var RegistryBase = class {
1359
1359
  data.slice(this.options.dataOffset ?? 0)
1360
1360
  );
1361
1361
  }
1362
+ getInstancesFromPayload(data) {
1363
+ const instances = [];
1364
+ const identifierOffset = this.options.identifierOffset ?? 0;
1365
+ const dataOffset = this.options.dataOffset ?? 0;
1366
+ const minLength = Math.max(identifierOffset + 1, dataOffset);
1367
+ let remaining = data;
1368
+ while (remaining.length > 0) {
1369
+ if (remaining.length < minLength) {
1370
+ break;
1371
+ }
1372
+ try {
1373
+ const instance = this.getInstanceFromPayload(remaining);
1374
+ if (!instance) {
1375
+ break;
1376
+ }
1377
+ const consumed = dataOffset + instance.toPayload().length;
1378
+ if (consumed <= 0 || consumed > remaining.length) {
1379
+ break;
1380
+ }
1381
+ instances.push(instance);
1382
+ remaining = remaining.slice(consumed);
1383
+ } catch {
1384
+ break;
1385
+ }
1386
+ }
1387
+ return instances;
1388
+ }
1389
+ };
1390
+
1391
+ // src/proto-base/proto-registry-base.ts
1392
+ var ProtoRegistryBase = class extends RegistryBase {
1393
+ static {
1394
+ __name(this, "ProtoRegistryBase");
1395
+ }
1396
+ constructor(payloadClass) {
1397
+ super(payloadClass, {
1398
+ identifierOffset: 2,
1399
+ dataOffset: 3
1400
+ });
1401
+ }
1402
+ getInstancesFromPayload(data) {
1403
+ const instances = [];
1404
+ let offset = 0;
1405
+ while (offset + 2 <= data.length) {
1406
+ const declaredLength = data[offset] | data[offset + 1] << 8;
1407
+ if (declaredLength <= 0) {
1408
+ break;
1409
+ }
1410
+ const packetLength = 2 + declaredLength;
1411
+ if (offset + packetLength > data.length) {
1412
+ break;
1413
+ }
1414
+ const chunk = data.slice(offset, offset + packetLength);
1415
+ const identifier = chunk[2];
1416
+ const proto = this.get(identifier);
1417
+ if (!proto) {
1418
+ break;
1419
+ }
1420
+ try {
1421
+ const instance = new proto().fromFullPayload(chunk);
1422
+ instances.push(instance);
1423
+ } catch {
1424
+ break;
1425
+ }
1426
+ offset += packetLength;
1427
+ }
1428
+ return instances;
1429
+ }
1362
1430
  };
1363
1431
 
1364
1432
  // src/protos/ctos/proto/response.ts
@@ -1716,10 +1784,7 @@ var YGOProCtosRequestField = class extends YGOProCtosBase {
1716
1784
  };
1717
1785
 
1718
1786
  // src/protos/ctos/registry.ts
1719
- var YGOProCtos = new RegistryBase(YGOProCtosBase, {
1720
- identifierOffset: 2,
1721
- dataOffset: 3
1722
- });
1787
+ var YGOProCtos = new ProtoRegistryBase(YGOProCtosBase);
1723
1788
  YGOProCtos.register(YGOProCtosResponse);
1724
1789
  YGOProCtos.register(YGOProCtosUpdateDeck);
1725
1790
  YGOProCtos.register(YGOProCtosHandResult);
@@ -4329,6 +4394,18 @@ var YGOProMsgSelectCard = class extends YGOProMsgResponseBase {
4329
4394
  static {
4330
4395
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_CARD;
4331
4396
  }
4397
+ maskedView(playerId) {
4398
+ const view = this.copy();
4399
+ for (const card of view.cards || []) {
4400
+ if (card.controller !== playerId) {
4401
+ card.code = 0;
4402
+ }
4403
+ }
4404
+ return view;
4405
+ }
4406
+ playerView(playerId) {
4407
+ return this.maskedView(playerId);
4408
+ }
4332
4409
  responsePlayer() {
4333
4410
  return this.player;
4334
4411
  }
@@ -5096,6 +5173,18 @@ var YGOProMsgSelectTribute = class extends YGOProMsgResponseBase {
5096
5173
  static {
5097
5174
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_TRIBUTE;
5098
5175
  }
5176
+ maskedView(playerId) {
5177
+ const view = this.copy();
5178
+ for (const card of view.cards || []) {
5179
+ if (card.controller !== playerId) {
5180
+ card.code = 0;
5181
+ }
5182
+ }
5183
+ return view;
5184
+ }
5185
+ playerView(playerId) {
5186
+ return this.maskedView(playerId);
5187
+ }
5099
5188
  responsePlayer() {
5100
5189
  return this.player;
5101
5190
  }
@@ -5187,6 +5276,23 @@ var YGOProMsgSelectUnselectCard = class extends YGOProMsgResponseBase {
5187
5276
  static {
5188
5277
  this.identifier = OcgcoreCommonConstants.MSG_SELECT_UNSELECT_CARD;
5189
5278
  }
5279
+ maskedView(playerId) {
5280
+ const view = this.copy();
5281
+ for (const card of view.selectableCards || []) {
5282
+ if (card.controller !== playerId) {
5283
+ card.code = 0;
5284
+ }
5285
+ }
5286
+ for (const card of view.unselectableCards || []) {
5287
+ if (card.controller !== playerId) {
5288
+ card.code = 0;
5289
+ }
5290
+ }
5291
+ return view;
5292
+ }
5293
+ playerView(playerId) {
5294
+ return this.maskedView(playerId);
5295
+ }
5190
5296
  responsePlayer() {
5191
5297
  return this.player;
5192
5298
  }
@@ -6646,10 +6752,7 @@ __decorateClass([
6646
6752
  ], YGOProStocSrvproRoomlist.prototype, "rooms", 2);
6647
6753
 
6648
6754
  // src/protos/stoc/registry.ts
6649
- var YGOProStoc = new RegistryBase(YGOProStocBase, {
6650
- identifierOffset: 2,
6651
- dataOffset: 3
6652
- });
6755
+ var YGOProStoc = new ProtoRegistryBase(YGOProStocBase);
6653
6756
  YGOProStoc.register(YGOProStocGameMsg);
6654
6757
  YGOProStoc.register(YGOProStocErrorMsg);
6655
6758
  YGOProStoc.register(YGOProStocSelectHand);
@@ -6694,6 +6797,7 @@ export {
6694
6797
  OcgcoreScriptConstants,
6695
6798
  PayloadBase,
6696
6799
  PlayerChangeState,
6800
+ ProtoRegistryBase,
6697
6801
  RegistryBase,
6698
6802
  RoomStatus,
6699
6803
  SEND_TO_ALL,