ygopro-msg-encode 1.1.6 → 1.1.8

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
@@ -54,7 +54,9 @@ __export(index_exports, {
54
54
  NetPlayerType: () => NetPlayerType,
55
55
  OcgcoreCommonConstants: () => OcgcoreCommonConstants,
56
56
  OcgcoreScriptConstants: () => OcgcoreScriptConstants,
57
+ PayloadBase: () => PayloadBase,
57
58
  PlayerChangeState: () => PlayerChangeState,
59
+ RegistryBase: () => RegistryBase,
58
60
  RoomStatus: () => RoomStatus,
59
61
  SEND_TO_ALL: () => SEND_TO_ALL,
60
62
  SEND_TO_PLAYERS: () => SEND_TO_PLAYERS,
@@ -198,6 +200,7 @@ __export(index_exports, {
198
200
  YGOProMsgUpdateData: () => YGOProMsgUpdateData,
199
201
  YGOProMsgWaiting: () => YGOProMsgWaiting,
200
202
  YGOProMsgWin: () => YGOProMsgWin,
203
+ YGOProProtoBase: () => YGOProProtoBase,
201
204
  YGOProStoc: () => YGOProStoc,
202
205
  YGOProStocBase: () => YGOProStocBase,
203
206
  YGOProStocChangeSide: () => YGOProStocChangeSide,
@@ -371,7 +374,8 @@ var fillBinaryFields = (obj, data, useClass) => {
371
374
  return;
372
375
  }
373
376
  if (type === "utf8" || type === "utf16") {
374
- const byteLength = resolveLength(obj, info.length, key);
377
+ const lengthValue = resolveLength(obj, info.length, key);
378
+ const byteLength = type === "utf16" ? lengthValue * 2 : lengthValue;
375
379
  obj[key] = readString(type, offset, byteLength);
376
380
  totalSize = Math.max(totalSize, offset + byteLength);
377
381
  return;
@@ -428,7 +432,8 @@ var toBinaryFields = (obj, useClass) => {
428
432
  }
429
433
  }
430
434
  } else if (type === "utf8" || type === "utf16") {
431
- const byteLength = resolveLength(obj, info.length, key);
435
+ const lengthValue = resolveLength(obj, info.length, key);
436
+ const byteLength = type === "utf16" ? lengthValue * 2 : lengthValue;
432
437
  totalSize = Math.max(totalSize, offset + byteLength);
433
438
  } else {
434
439
  const typeSize = getTypeSize(type);
@@ -506,7 +511,8 @@ var toBinaryFields = (obj, useClass) => {
506
511
  return;
507
512
  }
508
513
  if (type === "utf8" || type === "utf16") {
509
- const byteLength = resolveLength(obj, info.length, key);
514
+ const lengthValue = resolveLength(obj, info.length, key);
515
+ const byteLength = type === "utf16" ? lengthValue * 2 : lengthValue;
510
516
  writeString(type, offset, byteLength, value);
511
517
  return;
512
518
  }
@@ -1454,8 +1460,11 @@ var CardQuery = class {
1454
1460
  }
1455
1461
  };
1456
1462
 
1457
- // src/protos/ctos/base.ts
1458
- var YGOProCtosBase = class extends PayloadBase {
1463
+ // src/proto-base/ygopro-proto-base.ts
1464
+ var YGOProProtoBase = class extends PayloadBase {
1465
+ get messageDirection() {
1466
+ return this.constructor.messageDirection;
1467
+ }
1459
1468
  /**
1460
1469
  * Serialize to full payload including header (length + identifier + body)
1461
1470
  * Format: [length 2 bytes LE][identifier 1 byte][body]
@@ -1481,26 +1490,32 @@ var YGOProCtosBase = class extends PayloadBase {
1481
1490
  fromFullPayload(data) {
1482
1491
  if (data.length < 3) {
1483
1492
  throw new Error(
1484
- `CTOS payload too short: expected at least 3 bytes, got ${data.length}`
1493
+ `${this.messageDirection} payload too short: expected at least 3 bytes, got ${data.length}`
1485
1494
  );
1486
1495
  }
1487
1496
  const declaredLength = data[0] | data[1] << 8;
1488
1497
  const identifier = data[2];
1489
1498
  if (identifier !== this.identifier) {
1490
1499
  throw new Error(
1491
- `CTOS identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
1500
+ `${this.messageDirection} identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
1492
1501
  );
1493
1502
  }
1494
1503
  const expectedTotalLength = 3 + declaredLength - 1;
1495
1504
  if (data.length < expectedTotalLength) {
1496
1505
  throw new Error(
1497
- `CTOS payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
1506
+ `${this.messageDirection} payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
1498
1507
  );
1499
1508
  }
1500
1509
  const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
1501
1510
  return this.fromPayload(bodyData);
1502
1511
  }
1503
1512
  };
1513
+ YGOProProtoBase.messageDirection = "";
1514
+
1515
+ // src/protos/ctos/base.ts
1516
+ var YGOProCtosBase = class extends YGOProProtoBase {
1517
+ };
1518
+ YGOProCtosBase.messageDirection = "CTOS";
1504
1519
 
1505
1520
  // src/proto-base/registry-base.ts
1506
1521
  var RegistryBase = class {
@@ -1636,7 +1651,7 @@ var YGOProCtosTimeConfirm = class extends YGOProCtosBase {
1636
1651
  YGOProCtosTimeConfirm.identifier = 21;
1637
1652
 
1638
1653
  // src/protos/ctos/proto/chat.ts
1639
- var YGOProCtosChat = class extends YGOProCtosBase {
1654
+ var _YGOProCtosChat = class _YGOProCtosChat extends YGOProCtosBase {
1640
1655
  constructor() {
1641
1656
  super();
1642
1657
  this.msg = "";
@@ -1647,10 +1662,7 @@ var YGOProCtosChat = class extends YGOProCtosBase {
1647
1662
  return this;
1648
1663
  }
1649
1664
  toPayload() {
1650
- const encoder = new TextEncoder();
1651
- const utf8 = encoder.encode(this.msg);
1652
- const decoder = new TextDecoder("utf-8");
1653
- const text = decoder.decode(utf8);
1665
+ const text = this.msg.length > _YGOProCtosChat.MAX_LENGTH ? this.msg.substring(0, _YGOProCtosChat.MAX_LENGTH) : this.msg;
1654
1666
  const utf16 = new Uint16Array(text.length + 1);
1655
1667
  for (let i = 0; i < text.length; i++) {
1656
1668
  utf16[i] = text.charCodeAt(i);
@@ -1666,10 +1678,12 @@ var YGOProCtosChat = class extends YGOProCtosBase {
1666
1678
  return this;
1667
1679
  }
1668
1680
  };
1669
- YGOProCtosChat.identifier = 22;
1681
+ _YGOProCtosChat.identifier = 22;
1682
+ _YGOProCtosChat.MAX_LENGTH = 256;
1683
+ var YGOProCtosChat = _YGOProCtosChat;
1670
1684
 
1671
1685
  // src/protos/ctos/proto/external-address.ts
1672
- var YGOProCtosExternalAddress = class extends YGOProCtosBase {
1686
+ var _YGOProCtosExternalAddress = class _YGOProCtosExternalAddress extends YGOProCtosBase {
1673
1687
  constructor() {
1674
1688
  super();
1675
1689
  this.real_ip = "0.0.0.0";
@@ -1714,10 +1728,10 @@ var YGOProCtosExternalAddress = class extends YGOProCtosBase {
1714
1728
  return this;
1715
1729
  }
1716
1730
  toPayload() {
1717
- const encoder = new TextEncoder();
1718
- const utf8 = encoder.encode(this.hostname);
1719
- const decoder = new TextDecoder("utf-8");
1720
- const text = decoder.decode(utf8);
1731
+ const text = this.hostname.length > _YGOProCtosExternalAddress.MAX_HOSTNAME_LENGTH ? this.hostname.substring(
1732
+ 0,
1733
+ _YGOProCtosExternalAddress.MAX_HOSTNAME_LENGTH
1734
+ ) : this.hostname;
1721
1735
  const utf16 = new Uint16Array(text.length + 1);
1722
1736
  for (let i = 0; i < text.length; i++) {
1723
1737
  utf16[i] = text.charCodeAt(i);
@@ -1742,7 +1756,9 @@ var YGOProCtosExternalAddress = class extends YGOProCtosBase {
1742
1756
  return this;
1743
1757
  }
1744
1758
  };
1745
- YGOProCtosExternalAddress.identifier = 23;
1759
+ _YGOProCtosExternalAddress.identifier = 23;
1760
+ _YGOProCtosExternalAddress.MAX_HOSTNAME_LENGTH = 256;
1761
+ var YGOProCtosExternalAddress = _YGOProCtosExternalAddress;
1746
1762
 
1747
1763
  // src/protos/ctos/proto/hs-toduelist.ts
1748
1764
  var YGOProCtosHsToDuelist = class extends YGOProCtosBase {
@@ -1808,52 +1824,9 @@ YGOProCtos.register(YGOProCtosHsStart);
1808
1824
  YGOProCtos.register(YGOProCtosRequestField);
1809
1825
 
1810
1826
  // src/protos/stoc/base.ts
1811
- var YGOProStocBase = class extends PayloadBase {
1812
- /**
1813
- * Serialize to full payload including header (length + identifier + body)
1814
- * Format: [length 2 bytes LE][identifier 1 byte][body]
1815
- * Length = 1 (identifier) + body.length
1816
- */
1817
- toFullPayload() {
1818
- const body = this.toPayload();
1819
- const length = 1 + body.length;
1820
- const fullPayload = new Uint8Array(3 + body.length);
1821
- fullPayload[0] = length & 255;
1822
- fullPayload[1] = length >> 8 & 255;
1823
- fullPayload[2] = this.identifier;
1824
- fullPayload.set(body, 3);
1825
- return fullPayload;
1826
- }
1827
- /**
1828
- * Deserialize from full payload including header (length + identifier + body)
1829
- * Format: [length 2 bytes LE][identifier 1 byte][body]
1830
- * @param data - Full payload data
1831
- * @returns this instance
1832
- * @throws Error if data is too short or identifier mismatch
1833
- */
1834
- fromFullPayload(data) {
1835
- if (data.length < 3) {
1836
- throw new Error(
1837
- `STOC payload too short: expected at least 3 bytes, got ${data.length}`
1838
- );
1839
- }
1840
- const declaredLength = data[0] | data[1] << 8;
1841
- const identifier = data[2];
1842
- if (identifier !== this.identifier) {
1843
- throw new Error(
1844
- `STOC identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
1845
- );
1846
- }
1847
- const expectedTotalLength = 3 + declaredLength - 1;
1848
- if (data.length < expectedTotalLength) {
1849
- throw new Error(
1850
- `STOC payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
1851
- );
1852
- }
1853
- const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
1854
- return this.fromPayload(bodyData);
1855
- }
1827
+ var YGOProStocBase = class extends YGOProProtoBase {
1856
1828
  };
1829
+ YGOProStocBase.messageDirection = "STOC";
1857
1830
 
1858
1831
  // src/protos/network-enums.ts
1859
1832
  var HandResult = /* @__PURE__ */ ((HandResult2) => {
@@ -5811,7 +5784,7 @@ __decorateClass([
5811
5784
  ], YGOProStocTimeLimit.prototype, "left_time", 2);
5812
5785
 
5813
5786
  // src/protos/stoc/proto/chat.ts
5814
- var YGOProStocChat = class extends YGOProStocBase {
5787
+ var _YGOProStocChat = class _YGOProStocChat extends YGOProStocBase {
5815
5788
  constructor() {
5816
5789
  super();
5817
5790
  this.player_type = 0;
@@ -5831,10 +5804,7 @@ var YGOProStocChat = class extends YGOProStocBase {
5831
5804
  return this;
5832
5805
  }
5833
5806
  toPayload() {
5834
- const encoder = new TextEncoder();
5835
- const utf8 = encoder.encode(this.msg);
5836
- const decoder = new TextDecoder("utf-8");
5837
- const text = decoder.decode(utf8);
5807
+ const text = this.msg.length > _YGOProStocChat.MAX_LENGTH ? this.msg.substring(0, _YGOProStocChat.MAX_LENGTH) : this.msg;
5838
5808
  const utf16 = new Uint16Array(text.length + 1);
5839
5809
  for (let i = 0; i < text.length; i++) {
5840
5810
  utf16[i] = text.charCodeAt(i);
@@ -5856,7 +5826,9 @@ var YGOProStocChat = class extends YGOProStocBase {
5856
5826
  return this;
5857
5827
  }
5858
5828
  };
5859
- YGOProStocChat.identifier = 25;
5829
+ _YGOProStocChat.identifier = 25;
5830
+ _YGOProStocChat.MAX_LENGTH = 256;
5831
+ var YGOProStocChat = _YGOProStocChat;
5860
5832
 
5861
5833
  // src/protos/stoc/proto/hs-player-enter.ts
5862
5834
  var YGOProStocHsPlayerEnter = class extends YGOProStocBase {
@@ -6006,7 +5978,9 @@ YGOProStoc.register(YGOProStocSrvproRoomlist);
6006
5978
  NetPlayerType,
6007
5979
  OcgcoreCommonConstants,
6008
5980
  OcgcoreScriptConstants,
5981
+ PayloadBase,
6009
5982
  PlayerChangeState,
5983
+ RegistryBase,
6010
5984
  RoomStatus,
6011
5985
  SEND_TO_ALL,
6012
5986
  SEND_TO_PLAYERS,
@@ -6150,6 +6124,7 @@ YGOProStoc.register(YGOProStocSrvproRoomlist);
6150
6124
  YGOProMsgUpdateData,
6151
6125
  YGOProMsgWaiting,
6152
6126
  YGOProMsgWin,
6127
+ YGOProProtoBase,
6153
6128
  YGOProStoc,
6154
6129
  YGOProStocBase,
6155
6130
  YGOProStocChangeSide,