ygopro-msg-encode 1.1.1 → 1.1.3

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
@@ -39,6 +39,7 @@ var index_exports = {};
39
39
  __export(index_exports, {
40
40
  BattleCmdType: () => BattleCmdType,
41
41
  BinaryField: () => BinaryField,
42
+ CardData: () => CardData,
42
43
  CardQuery: () => CardQuery,
43
44
  CardQuery_CardLocation: () => CardQuery_CardLocation,
44
45
  CardQuery_Counter: () => CardQuery_Counter,
@@ -55,6 +56,8 @@ __export(index_exports, {
55
56
  OcgcoreScriptConstants: () => OcgcoreScriptConstants,
56
57
  PlayerChangeState: () => PlayerChangeState,
57
58
  RoomStatus: () => RoomStatus,
59
+ SEND_TO_ALL: () => SEND_TO_ALL,
60
+ SEND_TO_PLAYERS: () => SEND_TO_PLAYERS,
58
61
  SrvproRoomInfo: () => SrvproRoomInfo,
59
62
  TurnPlayerResult: () => TurnPlayerResult,
60
63
  YGOProCtos: () => YGOProCtos,
@@ -586,449 +589,6 @@ var PayloadBase = class {
586
589
  };
587
590
  PayloadBase.identifier = 0;
588
591
 
589
- // src/protos/ctos/base.ts
590
- var YGOProCtosBase = class extends PayloadBase {
591
- /**
592
- * Serialize to full payload including header (length + identifier + body)
593
- * Format: [length 2 bytes LE][identifier 1 byte][body]
594
- * Length = 1 (identifier) + body.length
595
- */
596
- toFullPayload() {
597
- const body = this.toPayload();
598
- const length = 1 + body.length;
599
- const fullPayload = new Uint8Array(3 + body.length);
600
- fullPayload[0] = length & 255;
601
- fullPayload[1] = length >> 8 & 255;
602
- fullPayload[2] = this.identifier;
603
- fullPayload.set(body, 3);
604
- return fullPayload;
605
- }
606
- /**
607
- * Deserialize from full payload including header (length + identifier + body)
608
- * Format: [length 2 bytes LE][identifier 1 byte][body]
609
- * @param data - Full payload data
610
- * @returns this instance
611
- * @throws Error if data is too short or identifier mismatch
612
- */
613
- fromFullPayload(data) {
614
- if (data.length < 3) {
615
- throw new Error(
616
- `CTOS payload too short: expected at least 3 bytes, got ${data.length}`
617
- );
618
- }
619
- const declaredLength = data[0] | data[1] << 8;
620
- const identifier = data[2];
621
- if (identifier !== this.identifier) {
622
- throw new Error(
623
- `CTOS identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
624
- );
625
- }
626
- const expectedTotalLength = 3 + declaredLength - 1;
627
- if (data.length < expectedTotalLength) {
628
- throw new Error(
629
- `CTOS payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
630
- );
631
- }
632
- const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
633
- return this.fromPayload(bodyData);
634
- }
635
- };
636
-
637
- // src/proto-base/registry-base.ts
638
- var RegistryBase = class {
639
- constructor(payloadClass, options = {}) {
640
- this.payloadClass = payloadClass;
641
- this.options = options;
642
- this.protos = /* @__PURE__ */ new Map();
643
- }
644
- register(proto) {
645
- const identifier = proto.identifier;
646
- this.protos.set(identifier, proto);
647
- }
648
- get(identifier) {
649
- return this.protos.get(identifier);
650
- }
651
- getInstanceFromPayload(data) {
652
- const identifier = data[this.options.identifierOffset ?? 0];
653
- const proto = this.get(identifier);
654
- if (!proto) {
655
- return void 0;
656
- }
657
- return new proto().fromPayload(
658
- data.slice(this.options.dataOffset ?? 0)
659
- );
660
- }
661
- };
662
-
663
- // src/protos/ctos/proto/response.ts
664
- var YGOProCtosResponse = class extends YGOProCtosBase {
665
- fromPayload(data) {
666
- this.response = data;
667
- return this;
668
- }
669
- toPayload() {
670
- return this.response || new Uint8Array(0);
671
- }
672
- };
673
- YGOProCtosResponse.identifier = 1;
674
-
675
- // src/protos/ctos/proto/update-deck.ts
676
- var import_ygopro_deck_encode = __toESM(require("ygopro-deck-encode"));
677
- var YGOProCtosUpdateDeck = class extends YGOProCtosBase {
678
- constructor() {
679
- super();
680
- this.deck = new import_ygopro_deck_encode.default();
681
- }
682
- fromPayload(data) {
683
- this.deck = import_ygopro_deck_encode.default.fromUpdateDeckPayload(data);
684
- return this;
685
- }
686
- toPayload() {
687
- return this.deck.toUpdateDeckPayload();
688
- }
689
- fromPartial(data) {
690
- if (data.deck) {
691
- this.deck = new import_ygopro_deck_encode.default(data.deck);
692
- }
693
- return this;
694
- }
695
- copy() {
696
- const copied = new this.constructor();
697
- copied.deck = new import_ygopro_deck_encode.default(this.deck);
698
- return copied;
699
- }
700
- };
701
- YGOProCtosUpdateDeck.identifier = 2;
702
-
703
- // src/protos/ctos/proto/hand-result.ts
704
- var YGOProCtosHandResult = class extends YGOProCtosBase {
705
- };
706
- YGOProCtosHandResult.identifier = 3;
707
- __decorateClass([
708
- BinaryField("u8", 0)
709
- ], YGOProCtosHandResult.prototype, "res", 2);
710
-
711
- // src/protos/ctos/proto/tp-result.ts
712
- var YGOProCtosTpResult = class extends YGOProCtosBase {
713
- };
714
- YGOProCtosTpResult.identifier = 4;
715
- __decorateClass([
716
- BinaryField("u8", 0)
717
- ], YGOProCtosTpResult.prototype, "res", 2);
718
-
719
- // src/protos/ctos/proto/player-info.ts
720
- var YGOProCtosPlayerInfo = class extends YGOProCtosBase {
721
- };
722
- YGOProCtosPlayerInfo.identifier = 16;
723
- __decorateClass([
724
- BinaryField("utf16", 0, 20)
725
- ], YGOProCtosPlayerInfo.prototype, "name", 2);
726
-
727
- // src/protos/ctos/proto/create-game.ts
728
- var YGOProCtosCreateGame = class extends YGOProCtosBase {
729
- };
730
- YGOProCtosCreateGame.identifier = 17;
731
- __decorateClass([
732
- BinaryField(() => HostInfo, 0)
733
- ], YGOProCtosCreateGame.prototype, "info", 2);
734
- __decorateClass([
735
- BinaryField("utf16", 20, 20)
736
- ], YGOProCtosCreateGame.prototype, "name", 2);
737
- __decorateClass([
738
- BinaryField("utf16", 60, 20)
739
- ], YGOProCtosCreateGame.prototype, "pass", 2);
740
-
741
- // src/protos/ctos/proto/join-game.ts
742
- var YGOProCtosJoinGame = class extends YGOProCtosBase {
743
- };
744
- YGOProCtosJoinGame.identifier = 18;
745
- __decorateClass([
746
- BinaryField("u16", 0)
747
- ], YGOProCtosJoinGame.prototype, "version", 2);
748
- __decorateClass([
749
- BinaryField("u32", 4)
750
- ], YGOProCtosJoinGame.prototype, "gameid", 2);
751
- __decorateClass([
752
- BinaryField("utf16", 8, 20)
753
- ], YGOProCtosJoinGame.prototype, "pass", 2);
754
-
755
- // src/protos/ctos/proto/leave-game.ts
756
- var YGOProCtosLeaveGame = class extends YGOProCtosBase {
757
- };
758
- YGOProCtosLeaveGame.identifier = 19;
759
-
760
- // src/protos/ctos/proto/surrender.ts
761
- var YGOProCtosSurrender = class extends YGOProCtosBase {
762
- };
763
- YGOProCtosSurrender.identifier = 20;
764
-
765
- // src/protos/ctos/proto/time-confirm.ts
766
- var YGOProCtosTimeConfirm = class extends YGOProCtosBase {
767
- };
768
- YGOProCtosTimeConfirm.identifier = 21;
769
-
770
- // src/protos/ctos/proto/chat.ts
771
- var YGOProCtosChat = class extends YGOProCtosBase {
772
- constructor() {
773
- super();
774
- this.msg = "";
775
- }
776
- fromPayload(data) {
777
- const decoder = new TextDecoder("utf-16le");
778
- this.msg = decoder.decode(data).replace(/\0+$/, "");
779
- return this;
780
- }
781
- toPayload() {
782
- const encoder = new TextEncoder();
783
- const utf8 = encoder.encode(this.msg);
784
- const decoder = new TextDecoder("utf-8");
785
- const text = decoder.decode(utf8);
786
- const utf16 = new Uint16Array(text.length + 1);
787
- for (let i = 0; i < text.length; i++) {
788
- utf16[i] = text.charCodeAt(i);
789
- }
790
- utf16[text.length] = 0;
791
- const result = new Uint8Array(utf16.buffer);
792
- return result;
793
- }
794
- fromPartial(data) {
795
- if (data.msg !== void 0) {
796
- this.msg = data.msg;
797
- }
798
- return this;
799
- }
800
- };
801
- YGOProCtosChat.identifier = 22;
802
-
803
- // src/protos/ctos/proto/external-address.ts
804
- var YGOProCtosExternalAddress = class extends YGOProCtosBase {
805
- constructor() {
806
- super();
807
- this.real_ip = "0.0.0.0";
808
- this.hostname = "";
809
- }
810
- // Convert IPv4 string to uint32 (network byte order / big endian)
811
- ipToUint32(ip) {
812
- let ipv4 = ip;
813
- if (ip.startsWith("::ffff:")) {
814
- ipv4 = ip.substring(7);
815
- }
816
- const parts = ipv4.split(".");
817
- if (parts.length !== 4) {
818
- return 0;
819
- }
820
- const bytes = parts.map((p) => parseInt(p, 10));
821
- if (bytes.some((b) => isNaN(b) || b < 0 || b > 255)) {
822
- return 0;
823
- }
824
- return bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
825
- }
826
- // Convert uint32 (network byte order / big endian) to IPv4 string
827
- uint32ToIp(value) {
828
- const byte1 = value >>> 24 & 255;
829
- const byte2 = value >>> 16 & 255;
830
- const byte3 = value >>> 8 & 255;
831
- const byte4 = value & 255;
832
- return `${byte1}.${byte2}.${byte3}.${byte4}`;
833
- }
834
- fromPayload(data) {
835
- if (data.length < 4) {
836
- throw new Error("CTOS_EXTERNAL_ADDRESS data too short");
837
- }
838
- const ipUint32 = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
839
- this.real_ip = this.uint32ToIp(ipUint32);
840
- if (data.length > 4) {
841
- const decoder = new TextDecoder("utf-16le");
842
- this.hostname = decoder.decode(data.slice(4)).replace(/\0+$/, "");
843
- } else {
844
- this.hostname = "";
845
- }
846
- return this;
847
- }
848
- toPayload() {
849
- const encoder = new TextEncoder();
850
- const utf8 = encoder.encode(this.hostname);
851
- const decoder = new TextDecoder("utf-8");
852
- const text = decoder.decode(utf8);
853
- const utf16 = new Uint16Array(text.length + 1);
854
- for (let i = 0; i < text.length; i++) {
855
- utf16[i] = text.charCodeAt(i);
856
- }
857
- utf16[text.length] = 0;
858
- const result = new Uint8Array(4 + utf16.byteLength);
859
- const ipUint32 = this.ipToUint32(this.real_ip);
860
- result[0] = ipUint32 >>> 24 & 255;
861
- result[1] = ipUint32 >>> 16 & 255;
862
- result[2] = ipUint32 >>> 8 & 255;
863
- result[3] = ipUint32 & 255;
864
- result.set(new Uint8Array(utf16.buffer), 4);
865
- return result;
866
- }
867
- fromPartial(data) {
868
- if (data.real_ip !== void 0) {
869
- this.real_ip = data.real_ip;
870
- }
871
- if (data.hostname !== void 0) {
872
- this.hostname = data.hostname;
873
- }
874
- return this;
875
- }
876
- };
877
- YGOProCtosExternalAddress.identifier = 23;
878
-
879
- // src/protos/ctos/proto/hs-toduelist.ts
880
- var YGOProCtosHsToDuelist = class extends YGOProCtosBase {
881
- };
882
- YGOProCtosHsToDuelist.identifier = 32;
883
-
884
- // src/protos/ctos/proto/hs-toobserver.ts
885
- var YGOProCtosHsToObserver = class extends YGOProCtosBase {
886
- };
887
- YGOProCtosHsToObserver.identifier = 33;
888
-
889
- // src/protos/ctos/proto/hs-ready.ts
890
- var YGOProCtosHsReady = class extends YGOProCtosBase {
891
- };
892
- YGOProCtosHsReady.identifier = 34;
893
-
894
- // src/protos/ctos/proto/hs-notready.ts
895
- var YGOProCtosHsNotReady = class extends YGOProCtosBase {
896
- };
897
- YGOProCtosHsNotReady.identifier = 35;
898
-
899
- // src/protos/ctos/proto/kick.ts
900
- var YGOProCtosKick = class extends YGOProCtosBase {
901
- };
902
- YGOProCtosKick.identifier = 36;
903
- __decorateClass([
904
- BinaryField("u8", 0)
905
- ], YGOProCtosKick.prototype, "pos", 2);
906
-
907
- // src/protos/ctos/proto/hs-start.ts
908
- var YGOProCtosHsStart = class extends YGOProCtosBase {
909
- };
910
- YGOProCtosHsStart.identifier = 37;
911
-
912
- // src/protos/ctos/proto/request-field.ts
913
- var YGOProCtosRequestField = class extends YGOProCtosBase {
914
- };
915
- YGOProCtosRequestField.identifier = 48;
916
-
917
- // src/protos/ctos/registry.ts
918
- var YGOProCtos = new RegistryBase(YGOProCtosBase, {
919
- identifierOffset: 2,
920
- dataOffset: 3
921
- });
922
- YGOProCtos.register(YGOProCtosResponse);
923
- YGOProCtos.register(YGOProCtosUpdateDeck);
924
- YGOProCtos.register(YGOProCtosHandResult);
925
- YGOProCtos.register(YGOProCtosTpResult);
926
- YGOProCtos.register(YGOProCtosPlayerInfo);
927
- YGOProCtos.register(YGOProCtosCreateGame);
928
- YGOProCtos.register(YGOProCtosJoinGame);
929
- YGOProCtos.register(YGOProCtosLeaveGame);
930
- YGOProCtos.register(YGOProCtosSurrender);
931
- YGOProCtos.register(YGOProCtosTimeConfirm);
932
- YGOProCtos.register(YGOProCtosChat);
933
- YGOProCtos.register(YGOProCtosExternalAddress);
934
- YGOProCtos.register(YGOProCtosHsToDuelist);
935
- YGOProCtos.register(YGOProCtosHsToObserver);
936
- YGOProCtos.register(YGOProCtosHsReady);
937
- YGOProCtos.register(YGOProCtosHsNotReady);
938
- YGOProCtos.register(YGOProCtosKick);
939
- YGOProCtos.register(YGOProCtosHsStart);
940
- YGOProCtos.register(YGOProCtosRequestField);
941
-
942
- // src/protos/stoc/base.ts
943
- var YGOProStocBase = class extends PayloadBase {
944
- /**
945
- * Serialize to full payload including header (length + identifier + body)
946
- * Format: [length 2 bytes LE][identifier 1 byte][body]
947
- * Length = 1 (identifier) + body.length
948
- */
949
- toFullPayload() {
950
- const body = this.toPayload();
951
- const length = 1 + body.length;
952
- const fullPayload = new Uint8Array(3 + body.length);
953
- fullPayload[0] = length & 255;
954
- fullPayload[1] = length >> 8 & 255;
955
- fullPayload[2] = this.identifier;
956
- fullPayload.set(body, 3);
957
- return fullPayload;
958
- }
959
- /**
960
- * Deserialize from full payload including header (length + identifier + body)
961
- * Format: [length 2 bytes LE][identifier 1 byte][body]
962
- * @param data - Full payload data
963
- * @returns this instance
964
- * @throws Error if data is too short or identifier mismatch
965
- */
966
- fromFullPayload(data) {
967
- if (data.length < 3) {
968
- throw new Error(
969
- `STOC payload too short: expected at least 3 bytes, got ${data.length}`
970
- );
971
- }
972
- const declaredLength = data[0] | data[1] << 8;
973
- const identifier = data[2];
974
- if (identifier !== this.identifier) {
975
- throw new Error(
976
- `STOC identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
977
- );
978
- }
979
- const expectedTotalLength = 3 + declaredLength - 1;
980
- if (data.length < expectedTotalLength) {
981
- throw new Error(
982
- `STOC payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
983
- );
984
- }
985
- const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
986
- return this.fromPayload(bodyData);
987
- }
988
- };
989
-
990
- // src/protos/msg/base.ts
991
- var YGOProMsgBase = class extends PayloadBase {
992
- fromPayload(data) {
993
- if (data.length < 1) {
994
- throw new Error("MSG data too short");
995
- }
996
- const msgType = data[0];
997
- if (msgType !== this.identifier) {
998
- throw new Error(
999
- `MSG type mismatch: expected ${this.identifier}, got ${msgType}`
1000
- );
1001
- }
1002
- return super.fromPayload(data.slice(1));
1003
- }
1004
- toPayload() {
1005
- const payload = super.toPayload();
1006
- const result = new Uint8Array(1 + payload.length);
1007
- result[0] = this.identifier;
1008
- result.set(payload, 1);
1009
- return result;
1010
- }
1011
- opponentView() {
1012
- return this.copy();
1013
- }
1014
- teammateView() {
1015
- return this.copy();
1016
- }
1017
- observerView() {
1018
- return this.opponentView();
1019
- }
1020
- playerView(playerId) {
1021
- if (typeof this["player"] === "number") {
1022
- const selfPlayerId = this["player"];
1023
- if (selfPlayerId === playerId) {
1024
- return this.copy();
1025
- }
1026
- return this.opponentView();
1027
- }
1028
- return this.copy();
1029
- }
1030
- };
1031
-
1032
592
  // src/vendor/ocgcore-constants.ts
1033
593
  var OcgcoreCommonConstants = {
1034
594
  ACTIVITY_ATTACK: 5,
@@ -1391,273 +951,203 @@ var OcgcoreCommonConstants = {
1391
951
  TYPE_XYZ: 8388608
1392
952
  };
1393
953
 
1394
- // src/protos/msg/proto/add-counter.ts
1395
- var YGOProMsgAddCounter = class extends YGOProMsgBase {
1396
- };
1397
- YGOProMsgAddCounter.identifier = OcgcoreCommonConstants.MSG_ADD_COUNTER;
1398
- __decorateClass([
1399
- BinaryField("u16", 0)
1400
- ], YGOProMsgAddCounter.prototype, "counterType", 2);
1401
- __decorateClass([
1402
- BinaryField("u8", 2)
1403
- ], YGOProMsgAddCounter.prototype, "controller", 2);
1404
- __decorateClass([
1405
- BinaryField("u8", 3)
1406
- ], YGOProMsgAddCounter.prototype, "location", 2);
1407
- __decorateClass([
1408
- BinaryField("u8", 4)
1409
- ], YGOProMsgAddCounter.prototype, "sequence", 2);
1410
- __decorateClass([
1411
- BinaryField("u16", 5)
1412
- ], YGOProMsgAddCounter.prototype, "count", 2);
1413
-
1414
- // src/protos/msg/with-response-base.ts
1415
- var YGOProMsgResponseBase = class extends YGOProMsgBase {
1416
- defaultResponse() {
1417
- return void 0;
1418
- }
1419
- };
1420
-
1421
- // src/protos/msg/proto/announce-attrib.ts
1422
- var YGOProMsgAnnounceAttrib = class extends YGOProMsgResponseBase {
1423
- responsePlayer() {
1424
- return this.player;
1425
- }
1426
- prepareResponse(attributes) {
1427
- const buffer = new Uint8Array(4);
1428
- const view = new DataView(buffer.buffer);
1429
- view.setInt32(0, attributes, true);
1430
- return buffer;
1431
- }
1432
- };
1433
- YGOProMsgAnnounceAttrib.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_ATTRIB;
1434
- __decorateClass([
1435
- BinaryField("u8", 0)
1436
- ], YGOProMsgAnnounceAttrib.prototype, "player", 2);
1437
- __decorateClass([
1438
- BinaryField("u8", 1)
1439
- ], YGOProMsgAnnounceAttrib.prototype, "count", 2);
1440
- __decorateClass([
1441
- BinaryField("u32", 2)
1442
- ], YGOProMsgAnnounceAttrib.prototype, "availableAttributes", 2);
1443
-
1444
- // src/protos/msg/proto/announce-card.ts
1445
- var YGOProMsgAnnounceCard = class extends YGOProMsgResponseBase {
1446
- responsePlayer() {
1447
- return this.player;
1448
- }
1449
- prepareResponse(cardCode) {
1450
- const buffer = new Uint8Array(4);
1451
- const view = new DataView(buffer.buffer);
1452
- view.setInt32(0, cardCode, true);
1453
- return buffer;
1454
- }
1455
- };
1456
- YGOProMsgAnnounceCard.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_CARD;
1457
- __decorateClass([
1458
- BinaryField("u8", 0)
1459
- ], YGOProMsgAnnounceCard.prototype, "player", 2);
1460
- __decorateClass([
1461
- BinaryField("u8", 1)
1462
- ], YGOProMsgAnnounceCard.prototype, "count", 2);
1463
- __decorateClass([
1464
- BinaryField("i32", 2, (obj) => obj.count)
1465
- ], YGOProMsgAnnounceCard.prototype, "opcodes", 2);
1466
-
1467
- // src/protos/msg/index-response.ts
1468
- var INDEX_RESPONSE_SYMBOL = /* @__PURE__ */ Symbol("IndexResponse");
1469
- var IndexResponse = (index) => ({
1470
- [INDEX_RESPONSE_SYMBOL]: true,
1471
- index
1472
- });
1473
- var isIndexResponse = (obj) => {
1474
- return obj != null && obj[INDEX_RESPONSE_SYMBOL] === true;
1475
- };
1476
-
1477
- // src/protos/msg/proto/announce-number.ts
1478
- var YGOProMsgAnnounceNumber = class extends YGOProMsgResponseBase {
1479
- responsePlayer() {
1480
- return this.player;
1481
- }
1482
- prepareResponse(option) {
1483
- let index;
1484
- if (isIndexResponse(option)) {
1485
- index = option.index;
1486
- if (index < 0 || index >= this.count) {
1487
- throw new TypeError(`Index out of range: ${index}`);
1488
- }
1489
- } else {
1490
- index = this.numbers.indexOf(option);
1491
- if (index === -1) {
1492
- throw new TypeError(`Number not found: ${option}`);
1493
- }
1494
- }
1495
- const buffer = new Uint8Array(4);
1496
- const view = new DataView(buffer.buffer);
1497
- view.setInt32(0, index, true);
1498
- return buffer;
1499
- }
1500
- };
1501
- YGOProMsgAnnounceNumber.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_NUMBER;
1502
- __decorateClass([
1503
- BinaryField("u8", 0)
1504
- ], YGOProMsgAnnounceNumber.prototype, "player", 2);
1505
- __decorateClass([
1506
- BinaryField("u8", 1)
1507
- ], YGOProMsgAnnounceNumber.prototype, "count", 2);
1508
- __decorateClass([
1509
- BinaryField("i32", 2, (obj) => obj.count)
1510
- ], YGOProMsgAnnounceNumber.prototype, "numbers", 2);
1511
-
1512
- // src/protos/msg/proto/announce-race.ts
1513
- var YGOProMsgAnnounceRace = class extends YGOProMsgResponseBase {
1514
- responsePlayer() {
1515
- return this.player;
1516
- }
1517
- prepareResponse(races) {
1518
- const buffer = new Uint8Array(4);
1519
- const view = new DataView(buffer.buffer);
1520
- view.setInt32(0, races, true);
1521
- return buffer;
1522
- }
1523
- };
1524
- YGOProMsgAnnounceRace.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_RACE;
1525
- __decorateClass([
1526
- BinaryField("u8", 0)
1527
- ], YGOProMsgAnnounceRace.prototype, "player", 2);
1528
- __decorateClass([
1529
- BinaryField("u8", 1)
1530
- ], YGOProMsgAnnounceRace.prototype, "count", 2);
1531
- __decorateClass([
1532
- BinaryField("u32", 2)
1533
- ], YGOProMsgAnnounceRace.prototype, "availableRaces", 2);
1534
-
1535
- // src/protos/msg/proto/attack.ts
1536
- var YGOProMsgAttack_CardLocation = class {
1537
- };
1538
- __decorateClass([
1539
- BinaryField("u8", 0)
1540
- ], YGOProMsgAttack_CardLocation.prototype, "controller", 2);
1541
- __decorateClass([
1542
- BinaryField("u8", 1)
1543
- ], YGOProMsgAttack_CardLocation.prototype, "location", 2);
1544
- __decorateClass([
1545
- BinaryField("u8", 2)
1546
- ], YGOProMsgAttack_CardLocation.prototype, "sequence", 2);
1547
- __decorateClass([
1548
- BinaryField("u8", 3)
1549
- ], YGOProMsgAttack_CardLocation.prototype, "position", 2);
1550
- var YGOProMsgAttack = class extends YGOProMsgBase {
1551
- };
1552
- YGOProMsgAttack.identifier = OcgcoreCommonConstants.MSG_ATTACK;
1553
- __decorateClass([
1554
- BinaryField(() => YGOProMsgAttack_CardLocation, 0)
1555
- ], YGOProMsgAttack.prototype, "attacker", 2);
1556
- __decorateClass([
1557
- BinaryField(() => YGOProMsgAttack_CardLocation, 4)
1558
- ], YGOProMsgAttack.prototype, "defender", 2);
1559
-
1560
- // src/protos/msg/proto/attack-disabled.ts
1561
- var YGOProMsgAttackDisabled = class extends YGOProMsgBase {
1562
- };
1563
- YGOProMsgAttackDisabled.identifier = OcgcoreCommonConstants.MSG_ATTACK_DISABLED;
1564
-
1565
- // src/protos/msg/proto/battle.ts
1566
- var YGOProMsgBattle_CardLocation = class {
1567
- };
1568
- __decorateClass([
1569
- BinaryField("u8", 0)
1570
- ], YGOProMsgBattle_CardLocation.prototype, "controller", 2);
1571
- __decorateClass([
1572
- BinaryField("u8", 1)
1573
- ], YGOProMsgBattle_CardLocation.prototype, "location", 2);
1574
- __decorateClass([
1575
- BinaryField("u8", 2)
1576
- ], YGOProMsgBattle_CardLocation.prototype, "sequence", 2);
1577
- __decorateClass([
1578
- BinaryField("u8", 3)
1579
- ], YGOProMsgBattle_CardLocation.prototype, "position", 2);
1580
- var YGOProMsgBattle_CardStats = class {
1581
- };
1582
- __decorateClass([
1583
- BinaryField(() => YGOProMsgBattle_CardLocation, 0)
1584
- ], YGOProMsgBattle_CardStats.prototype, "location", 2);
1585
- __decorateClass([
1586
- BinaryField("i32", 4)
1587
- ], YGOProMsgBattle_CardStats.prototype, "atk", 2);
1588
- __decorateClass([
1589
- BinaryField("i32", 8)
1590
- ], YGOProMsgBattle_CardStats.prototype, "def", 2);
1591
- var YGOProMsgBattle = class extends YGOProMsgBase {
1592
- };
1593
- YGOProMsgBattle.identifier = OcgcoreCommonConstants.MSG_BATTLE;
1594
- __decorateClass([
1595
- BinaryField(() => YGOProMsgBattle_CardStats, 0)
1596
- ], YGOProMsgBattle.prototype, "attacker", 2);
1597
- __decorateClass([
1598
- BinaryField(() => YGOProMsgBattle_CardStats, 12)
1599
- ], YGOProMsgBattle.prototype, "defender", 2);
1600
- __decorateClass([
1601
- BinaryField("u8", 24)
1602
- ], YGOProMsgBattle.prototype, "battleDamageCalc", 2);
1603
-
1604
- // src/protos/msg/proto/become-target.ts
1605
- var YGOProMsgBecomeTarget = class extends YGOProMsgBase {
1606
- };
1607
- YGOProMsgBecomeTarget.identifier = OcgcoreCommonConstants.MSG_BECOME_TARGET;
1608
- __decorateClass([
1609
- BinaryField("u8", 0)
1610
- ], YGOProMsgBecomeTarget.prototype, "count", 2);
1611
- __decorateClass([
1612
- BinaryField("i32", 1, (obj) => obj.count)
1613
- ], YGOProMsgBecomeTarget.prototype, "targets", 2);
1614
-
1615
- // src/protos/msg/proto/cancel-target.ts
1616
- var YGOProMsgCancelTarget_CardLocation = class {
954
+ // src/protos/common/card-data.ts
955
+ var CARD_ARTWORK_VERSIONS_OFFSET = 20;
956
+ var CARD_BLACK_LUSTER_SOLDIER2 = 5405695;
957
+ var CARD_MARINE_DOLPHIN = 78734254;
958
+ var CARD_TWINKLE_MOSS = 13857930;
959
+ function checkSetcode(setcode, value) {
960
+ const settype = value & 4095;
961
+ const setsubtype = value & 61440;
962
+ return setcode && (setcode & 4095) === settype && (setcode & setsubtype) === setsubtype;
963
+ }
964
+ function isAlternative(code, alias) {
965
+ if (code === CARD_BLACK_LUSTER_SOLDIER2) {
966
+ return false;
967
+ }
968
+ return alias && alias < code + CARD_ARTWORK_VERSIONS_OFFSET && code < alias + CARD_ARTWORK_VERSIONS_OFFSET;
969
+ }
970
+ var CardData = class extends PayloadBase {
971
+ /**
972
+ * Check if this card belongs to a specific setcode
973
+ * @param value The setcode value to check against
974
+ * @returns true if the card belongs to the setcode
975
+ */
976
+ isSetCard(value) {
977
+ for (const x of this.setcode) {
978
+ if (!x) {
979
+ return false;
980
+ }
981
+ if (checkSetcode(x, value)) {
982
+ return true;
983
+ }
984
+ }
985
+ return false;
986
+ }
987
+ /**
988
+ * Get the original code of this card (handles alternate artworks)
989
+ * @returns The original card code
990
+ */
991
+ getOriginalCode() {
992
+ return isAlternative(this.code, this.alias) ? this.alias : this.code;
993
+ }
994
+ /**
995
+ * Check if this card can be declared with the given opcode filter
996
+ * @param opcode Array of opcodes that define the filter expression
997
+ * @returns true if the card can be declared
998
+ */
999
+ isDeclarable(opcode) {
1000
+ const stack = [];
1001
+ for (const it of opcode) {
1002
+ switch (it) {
1003
+ case OcgcoreCommonConstants.OPCODE_ADD: {
1004
+ if (stack.length >= 2) {
1005
+ const rhs = stack.pop();
1006
+ const lhs = stack.pop();
1007
+ stack.push(lhs + rhs);
1008
+ }
1009
+ break;
1010
+ }
1011
+ case OcgcoreCommonConstants.OPCODE_SUB: {
1012
+ if (stack.length >= 2) {
1013
+ const rhs = stack.pop();
1014
+ const lhs = stack.pop();
1015
+ stack.push(lhs - rhs);
1016
+ }
1017
+ break;
1018
+ }
1019
+ case OcgcoreCommonConstants.OPCODE_MUL: {
1020
+ if (stack.length >= 2) {
1021
+ const rhs = stack.pop();
1022
+ const lhs = stack.pop();
1023
+ stack.push(lhs * rhs);
1024
+ }
1025
+ break;
1026
+ }
1027
+ case OcgcoreCommonConstants.OPCODE_DIV: {
1028
+ if (stack.length >= 2) {
1029
+ const rhs = stack.pop();
1030
+ const lhs = stack.pop();
1031
+ stack.push(Math.floor(lhs / rhs));
1032
+ }
1033
+ break;
1034
+ }
1035
+ case OcgcoreCommonConstants.OPCODE_AND: {
1036
+ if (stack.length >= 2) {
1037
+ const rhs = stack.pop();
1038
+ const lhs = stack.pop();
1039
+ stack.push(lhs && rhs ? 1 : 0);
1040
+ }
1041
+ break;
1042
+ }
1043
+ case OcgcoreCommonConstants.OPCODE_OR: {
1044
+ if (stack.length >= 2) {
1045
+ const rhs = stack.pop();
1046
+ const lhs = stack.pop();
1047
+ stack.push(lhs || rhs ? 1 : 0);
1048
+ }
1049
+ break;
1050
+ }
1051
+ case OcgcoreCommonConstants.OPCODE_NEG: {
1052
+ if (stack.length >= 1) {
1053
+ const val = stack.pop();
1054
+ stack.push(-val);
1055
+ }
1056
+ break;
1057
+ }
1058
+ case OcgcoreCommonConstants.OPCODE_NOT: {
1059
+ if (stack.length >= 1) {
1060
+ const val = stack.pop();
1061
+ stack.push(!val ? 1 : 0);
1062
+ }
1063
+ break;
1064
+ }
1065
+ case OcgcoreCommonConstants.OPCODE_ISCODE: {
1066
+ if (stack.length >= 1) {
1067
+ const code = stack.pop();
1068
+ stack.push(this.code === code ? 1 : 0);
1069
+ }
1070
+ break;
1071
+ }
1072
+ case OcgcoreCommonConstants.OPCODE_ISSETCARD: {
1073
+ if (stack.length >= 1) {
1074
+ const setCode = stack.pop();
1075
+ const res = this.isSetCard(setCode);
1076
+ stack.push(res ? 1 : 0);
1077
+ }
1078
+ break;
1079
+ }
1080
+ case OcgcoreCommonConstants.OPCODE_ISTYPE: {
1081
+ if (stack.length >= 1) {
1082
+ const val = stack.pop();
1083
+ stack.push(this.type & val ? 1 : 0);
1084
+ }
1085
+ break;
1086
+ }
1087
+ case OcgcoreCommonConstants.OPCODE_ISRACE: {
1088
+ if (stack.length >= 1) {
1089
+ const raceVal = stack.pop();
1090
+ stack.push(this.race & raceVal ? 1 : 0);
1091
+ }
1092
+ break;
1093
+ }
1094
+ case OcgcoreCommonConstants.OPCODE_ISATTRIBUTE: {
1095
+ if (stack.length >= 1) {
1096
+ const attributeVal = stack.pop();
1097
+ stack.push(this.attribute & attributeVal ? 1 : 0);
1098
+ }
1099
+ break;
1100
+ }
1101
+ default: {
1102
+ stack.push(it);
1103
+ break;
1104
+ }
1105
+ }
1106
+ }
1107
+ if (stack.length !== 1 || stack[0] === 0) {
1108
+ return false;
1109
+ }
1110
+ return this.code === CARD_MARINE_DOLPHIN || this.code === CARD_TWINKLE_MOSS || !this.alias && (this.type & (OcgcoreCommonConstants.TYPE_MONSTER | OcgcoreCommonConstants.TYPE_TOKEN)) !== (OcgcoreCommonConstants.TYPE_MONSTER | OcgcoreCommonConstants.TYPE_TOKEN);
1111
+ }
1617
1112
  };
1618
1113
  __decorateClass([
1619
- BinaryField("u8", 0)
1620
- ], YGOProMsgCancelTarget_CardLocation.prototype, "controller", 2);
1114
+ BinaryField("u32", 0)
1115
+ ], CardData.prototype, "code", 2);
1621
1116
  __decorateClass([
1622
- BinaryField("u8", 1)
1623
- ], YGOProMsgCancelTarget_CardLocation.prototype, "location", 2);
1117
+ BinaryField("u32", 4)
1118
+ ], CardData.prototype, "alias", 2);
1624
1119
  __decorateClass([
1625
- BinaryField("u8", 2)
1626
- ], YGOProMsgCancelTarget_CardLocation.prototype, "sequence", 2);
1627
- var YGOProMsgCancelTarget = class extends YGOProMsgBase {
1628
- };
1629
- YGOProMsgCancelTarget.identifier = OcgcoreCommonConstants.MSG_CANCEL_TARGET;
1120
+ BinaryField("u16", 8, 16)
1121
+ ], CardData.prototype, "setcode", 2);
1630
1122
  __decorateClass([
1631
- BinaryField(() => YGOProMsgCancelTarget_CardLocation, 0)
1632
- ], YGOProMsgCancelTarget.prototype, "card1", 2);
1123
+ BinaryField("u32", 40)
1124
+ ], CardData.prototype, "type", 2);
1633
1125
  __decorateClass([
1634
- BinaryField(() => YGOProMsgCancelTarget_CardLocation, 3)
1635
- ], YGOProMsgCancelTarget.prototype, "card2", 2);
1636
-
1637
- // src/protos/msg/proto/card-hint.ts
1638
- var YGOProMsgCardHint = class extends YGOProMsgBase {
1639
- };
1640
- YGOProMsgCardHint.identifier = OcgcoreCommonConstants.MSG_CARD_HINT;
1126
+ BinaryField("u32", 44)
1127
+ ], CardData.prototype, "level", 2);
1641
1128
  __decorateClass([
1642
- BinaryField("u8", 0)
1643
- ], YGOProMsgCardHint.prototype, "controller", 2);
1129
+ BinaryField("u32", 48)
1130
+ ], CardData.prototype, "attribute", 2);
1644
1131
  __decorateClass([
1645
- BinaryField("u8", 1)
1646
- ], YGOProMsgCardHint.prototype, "location", 2);
1132
+ BinaryField("u32", 52)
1133
+ ], CardData.prototype, "race", 2);
1647
1134
  __decorateClass([
1648
- BinaryField("u8", 2)
1649
- ], YGOProMsgCardHint.prototype, "sequence", 2);
1135
+ BinaryField("i32", 56)
1136
+ ], CardData.prototype, "attack", 2);
1650
1137
  __decorateClass([
1651
- BinaryField("u8", 3)
1652
- ], YGOProMsgCardHint.prototype, "subsequence", 2);
1138
+ BinaryField("i32", 60)
1139
+ ], CardData.prototype, "defense", 2);
1653
1140
  __decorateClass([
1654
- BinaryField("u8", 4)
1655
- ], YGOProMsgCardHint.prototype, "type", 2);
1141
+ BinaryField("u32", 64)
1142
+ ], CardData.prototype, "lscale", 2);
1656
1143
  __decorateClass([
1657
- BinaryField("i32", 5)
1658
- ], YGOProMsgCardHint.prototype, "value", 2);
1144
+ BinaryField("u32", 68)
1145
+ ], CardData.prototype, "rscale", 2);
1146
+ __decorateClass([
1147
+ BinaryField("u32", 72)
1148
+ ], CardData.prototype, "linkMarker", 2);
1659
1149
 
1660
- // src/protos/msg/proto/card-query.ts
1150
+ // src/protos/common/card-query.ts
1661
1151
  var CardQuery_CardLocation = class {
1662
1152
  };
1663
1153
  var CardQuery_Counter = class {
@@ -1774,195 +1264,986 @@ var CardQuery = class {
1774
1264
  offset += 4;
1775
1265
  }
1776
1266
  }
1777
- if (this.flags & OcgcoreCommonConstants.QUERY_OWNER) {
1778
- this.owner = view.getInt32(offset, true);
1267
+ if (this.flags & OcgcoreCommonConstants.QUERY_OWNER) {
1268
+ this.owner = view.getInt32(offset, true);
1269
+ offset += 4;
1270
+ }
1271
+ if (this.flags & OcgcoreCommonConstants.QUERY_STATUS) {
1272
+ this.status = view.getInt32(offset, true);
1273
+ offset += 4;
1274
+ }
1275
+ if (this.flags & OcgcoreCommonConstants.QUERY_LSCALE) {
1276
+ this.lscale = view.getInt32(offset, true);
1277
+ offset += 4;
1278
+ }
1279
+ if (this.flags & OcgcoreCommonConstants.QUERY_RSCALE) {
1280
+ this.rscale = view.getInt32(offset, true);
1281
+ offset += 4;
1282
+ }
1283
+ if (this.flags & OcgcoreCommonConstants.QUERY_LINK) {
1284
+ this.link = view.getInt32(offset, true);
1285
+ offset += 4;
1286
+ this.linkMarker = view.getInt32(offset, true);
1287
+ offset += 4;
1288
+ }
1289
+ return this;
1290
+ }
1291
+ toPayload() {
1292
+ let size = 4;
1293
+ const flags = this.flags;
1294
+ if (flags & OcgcoreCommonConstants.QUERY_CODE) size += 4;
1295
+ if (flags & OcgcoreCommonConstants.QUERY_POSITION) size += 4;
1296
+ if (flags & OcgcoreCommonConstants.QUERY_ALIAS) size += 4;
1297
+ if (flags & OcgcoreCommonConstants.QUERY_TYPE) size += 4;
1298
+ if (flags & OcgcoreCommonConstants.QUERY_LEVEL) size += 4;
1299
+ if (flags & OcgcoreCommonConstants.QUERY_RANK) size += 4;
1300
+ if (flags & OcgcoreCommonConstants.QUERY_ATTRIBUTE) size += 4;
1301
+ if (flags & OcgcoreCommonConstants.QUERY_RACE) size += 4;
1302
+ if (flags & OcgcoreCommonConstants.QUERY_ATTACK) size += 4;
1303
+ if (flags & OcgcoreCommonConstants.QUERY_DEFENSE) size += 4;
1304
+ if (flags & OcgcoreCommonConstants.QUERY_BASE_ATTACK) size += 4;
1305
+ if (flags & OcgcoreCommonConstants.QUERY_BASE_DEFENSE) size += 4;
1306
+ if (flags & OcgcoreCommonConstants.QUERY_REASON) size += 4;
1307
+ if (flags & OcgcoreCommonConstants.QUERY_REASON_CARD) size += 4;
1308
+ if (flags & OcgcoreCommonConstants.QUERY_EQUIP_CARD) size += 4;
1309
+ if (flags & OcgcoreCommonConstants.QUERY_TARGET_CARD) {
1310
+ size += 4 + (this.targetCards?.length || 0) * 4;
1311
+ }
1312
+ if (flags & OcgcoreCommonConstants.QUERY_OVERLAY_CARD) {
1313
+ size += 4 + (this.overlayCards?.length || 0) * 4;
1314
+ }
1315
+ if (flags & OcgcoreCommonConstants.QUERY_COUNTERS) {
1316
+ size += 4 + (this.counters?.length || 0) * 4;
1317
+ }
1318
+ if (flags & OcgcoreCommonConstants.QUERY_OWNER) size += 4;
1319
+ if (flags & OcgcoreCommonConstants.QUERY_STATUS) size += 4;
1320
+ if (flags & OcgcoreCommonConstants.QUERY_LSCALE) size += 4;
1321
+ if (flags & OcgcoreCommonConstants.QUERY_RSCALE) size += 4;
1322
+ if (flags & OcgcoreCommonConstants.QUERY_LINK) size += 8;
1323
+ const result = new Uint8Array(size);
1324
+ const view = new DataView(result.buffer);
1325
+ let offset = 0;
1326
+ view.setInt32(offset, this.flags, true);
1327
+ offset += 4;
1328
+ if (this.empty || this.flags === 0) {
1329
+ return result;
1330
+ }
1331
+ if (flags & OcgcoreCommonConstants.QUERY_CODE) {
1332
+ view.setInt32(offset, this.code || 0, true);
1333
+ offset += 4;
1334
+ }
1335
+ if (flags & OcgcoreCommonConstants.QUERY_POSITION) {
1336
+ const pdata = (this.position || 0) << 24 >>> 0;
1337
+ view.setInt32(offset, pdata, true);
1338
+ offset += 4;
1339
+ }
1340
+ if (flags & OcgcoreCommonConstants.QUERY_ALIAS) {
1341
+ view.setInt32(offset, this.alias || 0, true);
1342
+ offset += 4;
1343
+ }
1344
+ if (flags & OcgcoreCommonConstants.QUERY_TYPE) {
1345
+ view.setInt32(offset, this.type || 0, true);
1346
+ offset += 4;
1347
+ }
1348
+ if (flags & OcgcoreCommonConstants.QUERY_LEVEL) {
1349
+ view.setInt32(offset, this.level || 0, true);
1350
+ offset += 4;
1351
+ }
1352
+ if (flags & OcgcoreCommonConstants.QUERY_RANK) {
1353
+ view.setInt32(offset, this.rank || 0, true);
1354
+ offset += 4;
1355
+ }
1356
+ if (flags & OcgcoreCommonConstants.QUERY_ATTRIBUTE) {
1357
+ view.setInt32(offset, this.attribute || 0, true);
1358
+ offset += 4;
1359
+ }
1360
+ if (flags & OcgcoreCommonConstants.QUERY_RACE) {
1361
+ view.setInt32(offset, this.race || 0, true);
1362
+ offset += 4;
1363
+ }
1364
+ if (flags & OcgcoreCommonConstants.QUERY_ATTACK) {
1365
+ view.setInt32(offset, this.attack || 0, true);
1366
+ offset += 4;
1367
+ }
1368
+ if (flags & OcgcoreCommonConstants.QUERY_DEFENSE) {
1369
+ view.setInt32(offset, this.defense || 0, true);
1370
+ offset += 4;
1371
+ }
1372
+ if (flags & OcgcoreCommonConstants.QUERY_BASE_ATTACK) {
1373
+ view.setInt32(offset, this.baseAttack || 0, true);
1374
+ offset += 4;
1375
+ }
1376
+ if (flags & OcgcoreCommonConstants.QUERY_BASE_DEFENSE) {
1377
+ view.setInt32(offset, this.baseDefense || 0, true);
1378
+ offset += 4;
1379
+ }
1380
+ if (flags & OcgcoreCommonConstants.QUERY_REASON) {
1381
+ view.setInt32(offset, this.reason || 0, true);
1382
+ offset += 4;
1383
+ }
1384
+ if (flags & OcgcoreCommonConstants.QUERY_REASON_CARD) {
1385
+ view.setInt32(offset, 0, true);
1386
+ offset += 4;
1387
+ }
1388
+ if (flags & OcgcoreCommonConstants.QUERY_EQUIP_CARD) {
1389
+ const card = this.equipCard || {
1390
+ controller: 0,
1391
+ location: 0,
1392
+ sequence: 0
1393
+ };
1394
+ view.setUint8(offset, card.controller);
1395
+ view.setUint8(offset + 1, card.location);
1396
+ view.setUint8(offset + 2, card.sequence);
1397
+ view.setUint8(offset + 3, 0);
1398
+ offset += 4;
1399
+ }
1400
+ if (flags & OcgcoreCommonConstants.QUERY_TARGET_CARD) {
1401
+ const targets = this.targetCards || [];
1402
+ view.setInt32(offset, targets.length, true);
1403
+ offset += 4;
1404
+ for (const target of targets) {
1405
+ view.setUint8(offset, target.controller);
1406
+ view.setUint8(offset + 1, target.location);
1407
+ view.setUint8(offset + 2, target.sequence);
1408
+ view.setUint8(offset + 3, 0);
1409
+ offset += 4;
1410
+ }
1411
+ }
1412
+ if (flags & OcgcoreCommonConstants.QUERY_OVERLAY_CARD) {
1413
+ const overlays = this.overlayCards || [];
1414
+ view.setInt32(offset, overlays.length, true);
1415
+ offset += 4;
1416
+ for (const card of overlays) {
1417
+ view.setInt32(offset, card, true);
1418
+ offset += 4;
1419
+ }
1420
+ }
1421
+ if (flags & OcgcoreCommonConstants.QUERY_COUNTERS) {
1422
+ const counters = this.counters || [];
1423
+ view.setInt32(offset, counters.length, true);
1424
+ offset += 4;
1425
+ for (const counter of counters) {
1426
+ view.setUint16(offset, counter.type, true);
1427
+ view.setUint16(offset + 2, counter.count, true);
1428
+ offset += 4;
1429
+ }
1430
+ }
1431
+ if (flags & OcgcoreCommonConstants.QUERY_OWNER) {
1432
+ view.setInt32(offset, this.owner || 0, true);
1779
1433
  offset += 4;
1780
1434
  }
1781
- if (this.flags & OcgcoreCommonConstants.QUERY_STATUS) {
1782
- this.status = view.getInt32(offset, true);
1435
+ if (flags & OcgcoreCommonConstants.QUERY_STATUS) {
1436
+ view.setInt32(offset, this.status || 0, true);
1783
1437
  offset += 4;
1784
1438
  }
1785
- if (this.flags & OcgcoreCommonConstants.QUERY_LSCALE) {
1786
- this.lscale = view.getInt32(offset, true);
1439
+ if (flags & OcgcoreCommonConstants.QUERY_LSCALE) {
1440
+ view.setInt32(offset, this.lscale || 0, true);
1787
1441
  offset += 4;
1788
1442
  }
1789
- if (this.flags & OcgcoreCommonConstants.QUERY_RSCALE) {
1790
- this.rscale = view.getInt32(offset, true);
1443
+ if (flags & OcgcoreCommonConstants.QUERY_RSCALE) {
1444
+ view.setInt32(offset, this.rscale || 0, true);
1791
1445
  offset += 4;
1792
1446
  }
1793
- if (this.flags & OcgcoreCommonConstants.QUERY_LINK) {
1794
- this.link = view.getInt32(offset, true);
1447
+ if (flags & OcgcoreCommonConstants.QUERY_LINK) {
1448
+ view.setInt32(offset, this.link || 0, true);
1795
1449
  offset += 4;
1796
- this.linkMarker = view.getInt32(offset, true);
1450
+ view.setInt32(offset, this.linkMarker || 0, true);
1797
1451
  offset += 4;
1798
1452
  }
1799
- return this;
1453
+ return new Uint8Array(view.buffer, view.byteOffset, offset);
1800
1454
  }
1801
- toPayload() {
1802
- let size = 4;
1803
- const flags = this.flags;
1804
- if (flags & OcgcoreCommonConstants.QUERY_CODE) size += 4;
1805
- if (flags & OcgcoreCommonConstants.QUERY_POSITION) size += 4;
1806
- if (flags & OcgcoreCommonConstants.QUERY_ALIAS) size += 4;
1807
- if (flags & OcgcoreCommonConstants.QUERY_TYPE) size += 4;
1808
- if (flags & OcgcoreCommonConstants.QUERY_LEVEL) size += 4;
1809
- if (flags & OcgcoreCommonConstants.QUERY_RANK) size += 4;
1810
- if (flags & OcgcoreCommonConstants.QUERY_ATTRIBUTE) size += 4;
1811
- if (flags & OcgcoreCommonConstants.QUERY_RACE) size += 4;
1812
- if (flags & OcgcoreCommonConstants.QUERY_ATTACK) size += 4;
1813
- if (flags & OcgcoreCommonConstants.QUERY_DEFENSE) size += 4;
1814
- if (flags & OcgcoreCommonConstants.QUERY_BASE_ATTACK) size += 4;
1815
- if (flags & OcgcoreCommonConstants.QUERY_BASE_DEFENSE) size += 4;
1816
- if (flags & OcgcoreCommonConstants.QUERY_REASON) size += 4;
1817
- if (flags & OcgcoreCommonConstants.QUERY_REASON_CARD) size += 4;
1818
- if (flags & OcgcoreCommonConstants.QUERY_EQUIP_CARD) size += 4;
1819
- if (flags & OcgcoreCommonConstants.QUERY_TARGET_CARD) {
1820
- size += 4 + (this.targetCards?.length || 0) * 4;
1821
- }
1822
- if (flags & OcgcoreCommonConstants.QUERY_OVERLAY_CARD) {
1823
- size += 4 + (this.overlayCards?.length || 0) * 4;
1824
- }
1825
- if (flags & OcgcoreCommonConstants.QUERY_COUNTERS) {
1826
- size += 4 + (this.counters?.length || 0) * 4;
1827
- }
1828
- if (flags & OcgcoreCommonConstants.QUERY_OWNER) size += 4;
1829
- if (flags & OcgcoreCommonConstants.QUERY_STATUS) size += 4;
1830
- if (flags & OcgcoreCommonConstants.QUERY_LSCALE) size += 4;
1831
- if (flags & OcgcoreCommonConstants.QUERY_RSCALE) size += 4;
1832
- if (flags & OcgcoreCommonConstants.QUERY_LINK) size += 8;
1833
- const result = new Uint8Array(size);
1834
- const view = new DataView(result.buffer);
1835
- let offset = 0;
1836
- view.setInt32(offset, this.flags, true);
1837
- offset += 4;
1838
- if (this.empty || this.flags === 0) {
1839
- return result;
1840
- }
1841
- if (flags & OcgcoreCommonConstants.QUERY_CODE) {
1842
- view.setInt32(offset, this.code || 0, true);
1843
- offset += 4;
1844
- }
1845
- if (flags & OcgcoreCommonConstants.QUERY_POSITION) {
1846
- const pdata = (this.position || 0) << 24 >>> 0;
1847
- view.setInt32(offset, pdata, true);
1848
- offset += 4;
1455
+ };
1456
+
1457
+ // src/protos/ctos/base.ts
1458
+ var YGOProCtosBase = class extends PayloadBase {
1459
+ /**
1460
+ * Serialize to full payload including header (length + identifier + body)
1461
+ * Format: [length 2 bytes LE][identifier 1 byte][body]
1462
+ * Length = 1 (identifier) + body.length
1463
+ */
1464
+ toFullPayload() {
1465
+ const body = this.toPayload();
1466
+ const length = 1 + body.length;
1467
+ const fullPayload = new Uint8Array(3 + body.length);
1468
+ fullPayload[0] = length & 255;
1469
+ fullPayload[1] = length >> 8 & 255;
1470
+ fullPayload[2] = this.identifier;
1471
+ fullPayload.set(body, 3);
1472
+ return fullPayload;
1473
+ }
1474
+ /**
1475
+ * Deserialize from full payload including header (length + identifier + body)
1476
+ * Format: [length 2 bytes LE][identifier 1 byte][body]
1477
+ * @param data - Full payload data
1478
+ * @returns this instance
1479
+ * @throws Error if data is too short or identifier mismatch
1480
+ */
1481
+ fromFullPayload(data) {
1482
+ if (data.length < 3) {
1483
+ throw new Error(
1484
+ `CTOS payload too short: expected at least 3 bytes, got ${data.length}`
1485
+ );
1849
1486
  }
1850
- if (flags & OcgcoreCommonConstants.QUERY_ALIAS) {
1851
- view.setInt32(offset, this.alias || 0, true);
1852
- offset += 4;
1487
+ const declaredLength = data[0] | data[1] << 8;
1488
+ const identifier = data[2];
1489
+ if (identifier !== this.identifier) {
1490
+ throw new Error(
1491
+ `CTOS identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
1492
+ );
1853
1493
  }
1854
- if (flags & OcgcoreCommonConstants.QUERY_TYPE) {
1855
- view.setInt32(offset, this.type || 0, true);
1856
- offset += 4;
1494
+ const expectedTotalLength = 3 + declaredLength - 1;
1495
+ if (data.length < expectedTotalLength) {
1496
+ throw new Error(
1497
+ `CTOS payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
1498
+ );
1857
1499
  }
1858
- if (flags & OcgcoreCommonConstants.QUERY_LEVEL) {
1859
- view.setInt32(offset, this.level || 0, true);
1860
- offset += 4;
1500
+ const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
1501
+ return this.fromPayload(bodyData);
1502
+ }
1503
+ };
1504
+
1505
+ // src/proto-base/registry-base.ts
1506
+ var RegistryBase = class {
1507
+ constructor(payloadClass, options = {}) {
1508
+ this.payloadClass = payloadClass;
1509
+ this.options = options;
1510
+ this.protos = /* @__PURE__ */ new Map();
1511
+ }
1512
+ register(proto) {
1513
+ const identifier = proto.identifier;
1514
+ this.protos.set(identifier, proto);
1515
+ }
1516
+ get(identifier) {
1517
+ return this.protos.get(identifier);
1518
+ }
1519
+ getInstanceFromPayload(data) {
1520
+ const identifier = data[this.options.identifierOffset ?? 0];
1521
+ const proto = this.get(identifier);
1522
+ if (!proto) {
1523
+ return void 0;
1861
1524
  }
1862
- if (flags & OcgcoreCommonConstants.QUERY_RANK) {
1863
- view.setInt32(offset, this.rank || 0, true);
1864
- offset += 4;
1525
+ return new proto().fromPayload(
1526
+ data.slice(this.options.dataOffset ?? 0)
1527
+ );
1528
+ }
1529
+ };
1530
+
1531
+ // src/protos/ctos/proto/response.ts
1532
+ var YGOProCtosResponse = class extends YGOProCtosBase {
1533
+ fromPayload(data) {
1534
+ this.response = data;
1535
+ return this;
1536
+ }
1537
+ toPayload() {
1538
+ return this.response || new Uint8Array(0);
1539
+ }
1540
+ };
1541
+ YGOProCtosResponse.identifier = 1;
1542
+
1543
+ // src/protos/ctos/proto/update-deck.ts
1544
+ var import_ygopro_deck_encode = __toESM(require("ygopro-deck-encode"));
1545
+ var YGOProCtosUpdateDeck = class extends YGOProCtosBase {
1546
+ constructor() {
1547
+ super();
1548
+ this.deck = new import_ygopro_deck_encode.default();
1549
+ }
1550
+ fromPayload(data) {
1551
+ this.deck = import_ygopro_deck_encode.default.fromUpdateDeckPayload(data);
1552
+ return this;
1553
+ }
1554
+ toPayload() {
1555
+ return this.deck.toUpdateDeckPayload();
1556
+ }
1557
+ fromPartial(data) {
1558
+ if (data.deck) {
1559
+ this.deck = new import_ygopro_deck_encode.default(data.deck);
1865
1560
  }
1866
- if (flags & OcgcoreCommonConstants.QUERY_ATTRIBUTE) {
1867
- view.setInt32(offset, this.attribute || 0, true);
1868
- offset += 4;
1561
+ return this;
1562
+ }
1563
+ copy() {
1564
+ const copied = new this.constructor();
1565
+ copied.deck = new import_ygopro_deck_encode.default(this.deck);
1566
+ return copied;
1567
+ }
1568
+ };
1569
+ YGOProCtosUpdateDeck.identifier = 2;
1570
+
1571
+ // src/protos/ctos/proto/hand-result.ts
1572
+ var YGOProCtosHandResult = class extends YGOProCtosBase {
1573
+ };
1574
+ YGOProCtosHandResult.identifier = 3;
1575
+ __decorateClass([
1576
+ BinaryField("u8", 0)
1577
+ ], YGOProCtosHandResult.prototype, "res", 2);
1578
+
1579
+ // src/protos/ctos/proto/tp-result.ts
1580
+ var YGOProCtosTpResult = class extends YGOProCtosBase {
1581
+ };
1582
+ YGOProCtosTpResult.identifier = 4;
1583
+ __decorateClass([
1584
+ BinaryField("u8", 0)
1585
+ ], YGOProCtosTpResult.prototype, "res", 2);
1586
+
1587
+ // src/protos/ctos/proto/player-info.ts
1588
+ var YGOProCtosPlayerInfo = class extends YGOProCtosBase {
1589
+ };
1590
+ YGOProCtosPlayerInfo.identifier = 16;
1591
+ __decorateClass([
1592
+ BinaryField("utf16", 0, 20)
1593
+ ], YGOProCtosPlayerInfo.prototype, "name", 2);
1594
+
1595
+ // src/protos/ctos/proto/create-game.ts
1596
+ var YGOProCtosCreateGame = class extends YGOProCtosBase {
1597
+ };
1598
+ YGOProCtosCreateGame.identifier = 17;
1599
+ __decorateClass([
1600
+ BinaryField(() => HostInfo, 0)
1601
+ ], YGOProCtosCreateGame.prototype, "info", 2);
1602
+ __decorateClass([
1603
+ BinaryField("utf16", 20, 20)
1604
+ ], YGOProCtosCreateGame.prototype, "name", 2);
1605
+ __decorateClass([
1606
+ BinaryField("utf16", 60, 20)
1607
+ ], YGOProCtosCreateGame.prototype, "pass", 2);
1608
+
1609
+ // src/protos/ctos/proto/join-game.ts
1610
+ var YGOProCtosJoinGame = class extends YGOProCtosBase {
1611
+ };
1612
+ YGOProCtosJoinGame.identifier = 18;
1613
+ __decorateClass([
1614
+ BinaryField("u16", 0)
1615
+ ], YGOProCtosJoinGame.prototype, "version", 2);
1616
+ __decorateClass([
1617
+ BinaryField("u32", 4)
1618
+ ], YGOProCtosJoinGame.prototype, "gameid", 2);
1619
+ __decorateClass([
1620
+ BinaryField("utf16", 8, 20)
1621
+ ], YGOProCtosJoinGame.prototype, "pass", 2);
1622
+
1623
+ // src/protos/ctos/proto/leave-game.ts
1624
+ var YGOProCtosLeaveGame = class extends YGOProCtosBase {
1625
+ };
1626
+ YGOProCtosLeaveGame.identifier = 19;
1627
+
1628
+ // src/protos/ctos/proto/surrender.ts
1629
+ var YGOProCtosSurrender = class extends YGOProCtosBase {
1630
+ };
1631
+ YGOProCtosSurrender.identifier = 20;
1632
+
1633
+ // src/protos/ctos/proto/time-confirm.ts
1634
+ var YGOProCtosTimeConfirm = class extends YGOProCtosBase {
1635
+ };
1636
+ YGOProCtosTimeConfirm.identifier = 21;
1637
+
1638
+ // src/protos/ctos/proto/chat.ts
1639
+ var YGOProCtosChat = class extends YGOProCtosBase {
1640
+ constructor() {
1641
+ super();
1642
+ this.msg = "";
1643
+ }
1644
+ fromPayload(data) {
1645
+ const decoder = new TextDecoder("utf-16le");
1646
+ this.msg = decoder.decode(data).replace(/\0+$/, "");
1647
+ return this;
1648
+ }
1649
+ 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);
1654
+ const utf16 = new Uint16Array(text.length + 1);
1655
+ for (let i = 0; i < text.length; i++) {
1656
+ utf16[i] = text.charCodeAt(i);
1869
1657
  }
1870
- if (flags & OcgcoreCommonConstants.QUERY_RACE) {
1871
- view.setInt32(offset, this.race || 0, true);
1872
- offset += 4;
1658
+ utf16[text.length] = 0;
1659
+ const result = new Uint8Array(utf16.buffer);
1660
+ return result;
1661
+ }
1662
+ fromPartial(data) {
1663
+ if (data.msg !== void 0) {
1664
+ this.msg = data.msg;
1873
1665
  }
1874
- if (flags & OcgcoreCommonConstants.QUERY_ATTACK) {
1875
- view.setInt32(offset, this.attack || 0, true);
1876
- offset += 4;
1666
+ return this;
1667
+ }
1668
+ };
1669
+ YGOProCtosChat.identifier = 22;
1670
+
1671
+ // src/protos/ctos/proto/external-address.ts
1672
+ var YGOProCtosExternalAddress = class extends YGOProCtosBase {
1673
+ constructor() {
1674
+ super();
1675
+ this.real_ip = "0.0.0.0";
1676
+ this.hostname = "";
1677
+ }
1678
+ // Convert IPv4 string to uint32 (network byte order / big endian)
1679
+ ipToUint32(ip) {
1680
+ let ipv4 = ip;
1681
+ if (ip.startsWith("::ffff:")) {
1682
+ ipv4 = ip.substring(7);
1877
1683
  }
1878
- if (flags & OcgcoreCommonConstants.QUERY_DEFENSE) {
1879
- view.setInt32(offset, this.defense || 0, true);
1880
- offset += 4;
1684
+ const parts = ipv4.split(".");
1685
+ if (parts.length !== 4) {
1686
+ return 0;
1881
1687
  }
1882
- if (flags & OcgcoreCommonConstants.QUERY_BASE_ATTACK) {
1883
- view.setInt32(offset, this.baseAttack || 0, true);
1884
- offset += 4;
1688
+ const bytes = parts.map((p) => parseInt(p, 10));
1689
+ if (bytes.some((b) => isNaN(b) || b < 0 || b > 255)) {
1690
+ return 0;
1885
1691
  }
1886
- if (flags & OcgcoreCommonConstants.QUERY_BASE_DEFENSE) {
1887
- view.setInt32(offset, this.baseDefense || 0, true);
1888
- offset += 4;
1692
+ return bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
1693
+ }
1694
+ // Convert uint32 (network byte order / big endian) to IPv4 string
1695
+ uint32ToIp(value) {
1696
+ const byte1 = value >>> 24 & 255;
1697
+ const byte2 = value >>> 16 & 255;
1698
+ const byte3 = value >>> 8 & 255;
1699
+ const byte4 = value & 255;
1700
+ return `${byte1}.${byte2}.${byte3}.${byte4}`;
1701
+ }
1702
+ fromPayload(data) {
1703
+ if (data.length < 4) {
1704
+ throw new Error("CTOS_EXTERNAL_ADDRESS data too short");
1889
1705
  }
1890
- if (flags & OcgcoreCommonConstants.QUERY_REASON) {
1891
- view.setInt32(offset, this.reason || 0, true);
1892
- offset += 4;
1706
+ const ipUint32 = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
1707
+ this.real_ip = this.uint32ToIp(ipUint32);
1708
+ if (data.length > 4) {
1709
+ const decoder = new TextDecoder("utf-16le");
1710
+ this.hostname = decoder.decode(data.slice(4)).replace(/\0+$/, "");
1711
+ } else {
1712
+ this.hostname = "";
1893
1713
  }
1894
- if (flags & OcgcoreCommonConstants.QUERY_REASON_CARD) {
1895
- view.setInt32(offset, 0, true);
1896
- offset += 4;
1714
+ return this;
1715
+ }
1716
+ 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);
1721
+ const utf16 = new Uint16Array(text.length + 1);
1722
+ for (let i = 0; i < text.length; i++) {
1723
+ utf16[i] = text.charCodeAt(i);
1897
1724
  }
1898
- if (flags & OcgcoreCommonConstants.QUERY_EQUIP_CARD) {
1899
- const card = this.equipCard || {
1900
- controller: 0,
1901
- location: 0,
1902
- sequence: 0
1903
- };
1904
- view.setUint8(offset, card.controller);
1905
- view.setUint8(offset + 1, card.location);
1906
- view.setUint8(offset + 2, card.sequence);
1907
- view.setUint8(offset + 3, 0);
1908
- offset += 4;
1725
+ utf16[text.length] = 0;
1726
+ const result = new Uint8Array(4 + utf16.byteLength);
1727
+ const ipUint32 = this.ipToUint32(this.real_ip);
1728
+ result[0] = ipUint32 >>> 24 & 255;
1729
+ result[1] = ipUint32 >>> 16 & 255;
1730
+ result[2] = ipUint32 >>> 8 & 255;
1731
+ result[3] = ipUint32 & 255;
1732
+ result.set(new Uint8Array(utf16.buffer), 4);
1733
+ return result;
1734
+ }
1735
+ fromPartial(data) {
1736
+ if (data.real_ip !== void 0) {
1737
+ this.real_ip = data.real_ip;
1909
1738
  }
1910
- if (flags & OcgcoreCommonConstants.QUERY_TARGET_CARD) {
1911
- const targets = this.targetCards || [];
1912
- view.setInt32(offset, targets.length, true);
1913
- offset += 4;
1914
- for (const target of targets) {
1915
- view.setUint8(offset, target.controller);
1916
- view.setUint8(offset + 1, target.location);
1917
- view.setUint8(offset + 2, target.sequence);
1918
- view.setUint8(offset + 3, 0);
1919
- offset += 4;
1920
- }
1739
+ if (data.hostname !== void 0) {
1740
+ this.hostname = data.hostname;
1921
1741
  }
1922
- if (flags & OcgcoreCommonConstants.QUERY_OVERLAY_CARD) {
1923
- const overlays = this.overlayCards || [];
1924
- view.setInt32(offset, overlays.length, true);
1925
- offset += 4;
1926
- for (const card of overlays) {
1927
- view.setInt32(offset, card, true);
1928
- offset += 4;
1929
- }
1742
+ return this;
1743
+ }
1744
+ };
1745
+ YGOProCtosExternalAddress.identifier = 23;
1746
+
1747
+ // src/protos/ctos/proto/hs-toduelist.ts
1748
+ var YGOProCtosHsToDuelist = class extends YGOProCtosBase {
1749
+ };
1750
+ YGOProCtosHsToDuelist.identifier = 32;
1751
+
1752
+ // src/protos/ctos/proto/hs-toobserver.ts
1753
+ var YGOProCtosHsToObserver = class extends YGOProCtosBase {
1754
+ };
1755
+ YGOProCtosHsToObserver.identifier = 33;
1756
+
1757
+ // src/protos/ctos/proto/hs-ready.ts
1758
+ var YGOProCtosHsReady = class extends YGOProCtosBase {
1759
+ };
1760
+ YGOProCtosHsReady.identifier = 34;
1761
+
1762
+ // src/protos/ctos/proto/hs-notready.ts
1763
+ var YGOProCtosHsNotReady = class extends YGOProCtosBase {
1764
+ };
1765
+ YGOProCtosHsNotReady.identifier = 35;
1766
+
1767
+ // src/protos/ctos/proto/kick.ts
1768
+ var YGOProCtosKick = class extends YGOProCtosBase {
1769
+ };
1770
+ YGOProCtosKick.identifier = 36;
1771
+ __decorateClass([
1772
+ BinaryField("u8", 0)
1773
+ ], YGOProCtosKick.prototype, "pos", 2);
1774
+
1775
+ // src/protos/ctos/proto/hs-start.ts
1776
+ var YGOProCtosHsStart = class extends YGOProCtosBase {
1777
+ };
1778
+ YGOProCtosHsStart.identifier = 37;
1779
+
1780
+ // src/protos/ctos/proto/request-field.ts
1781
+ var YGOProCtosRequestField = class extends YGOProCtosBase {
1782
+ };
1783
+ YGOProCtosRequestField.identifier = 48;
1784
+
1785
+ // src/protos/ctos/registry.ts
1786
+ var YGOProCtos = new RegistryBase(YGOProCtosBase, {
1787
+ identifierOffset: 2,
1788
+ dataOffset: 3
1789
+ });
1790
+ YGOProCtos.register(YGOProCtosResponse);
1791
+ YGOProCtos.register(YGOProCtosUpdateDeck);
1792
+ YGOProCtos.register(YGOProCtosHandResult);
1793
+ YGOProCtos.register(YGOProCtosTpResult);
1794
+ YGOProCtos.register(YGOProCtosPlayerInfo);
1795
+ YGOProCtos.register(YGOProCtosCreateGame);
1796
+ YGOProCtos.register(YGOProCtosJoinGame);
1797
+ YGOProCtos.register(YGOProCtosLeaveGame);
1798
+ YGOProCtos.register(YGOProCtosSurrender);
1799
+ YGOProCtos.register(YGOProCtosTimeConfirm);
1800
+ YGOProCtos.register(YGOProCtosChat);
1801
+ YGOProCtos.register(YGOProCtosExternalAddress);
1802
+ YGOProCtos.register(YGOProCtosHsToDuelist);
1803
+ YGOProCtos.register(YGOProCtosHsToObserver);
1804
+ YGOProCtos.register(YGOProCtosHsReady);
1805
+ YGOProCtos.register(YGOProCtosHsNotReady);
1806
+ YGOProCtos.register(YGOProCtosKick);
1807
+ YGOProCtos.register(YGOProCtosHsStart);
1808
+ YGOProCtos.register(YGOProCtosRequestField);
1809
+
1810
+ // 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
+ );
1930
1839
  }
1931
- if (flags & OcgcoreCommonConstants.QUERY_COUNTERS) {
1932
- const counters = this.counters || [];
1933
- view.setInt32(offset, counters.length, true);
1934
- offset += 4;
1935
- for (const counter of counters) {
1936
- view.setUint16(offset, counter.type, true);
1937
- view.setUint16(offset + 2, counter.count, true);
1938
- offset += 4;
1939
- }
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
+ );
1940
1846
  }
1941
- if (flags & OcgcoreCommonConstants.QUERY_OWNER) {
1942
- view.setInt32(offset, this.owner || 0, true);
1943
- offset += 4;
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
+ );
1944
1852
  }
1945
- if (flags & OcgcoreCommonConstants.QUERY_STATUS) {
1946
- view.setInt32(offset, this.status || 0, true);
1947
- offset += 4;
1853
+ const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
1854
+ return this.fromPayload(bodyData);
1855
+ }
1856
+ };
1857
+
1858
+ // src/protos/network-enums.ts
1859
+ var HandResult = /* @__PURE__ */ ((HandResult2) => {
1860
+ HandResult2[HandResult2["ROCK"] = 1] = "ROCK";
1861
+ HandResult2[HandResult2["SCISSORS"] = 2] = "SCISSORS";
1862
+ HandResult2[HandResult2["PAPER"] = 3] = "PAPER";
1863
+ return HandResult2;
1864
+ })(HandResult || {});
1865
+ var TurnPlayerResult = /* @__PURE__ */ ((TurnPlayerResult2) => {
1866
+ TurnPlayerResult2[TurnPlayerResult2["SECOND"] = 0] = "SECOND";
1867
+ TurnPlayerResult2[TurnPlayerResult2["FIRST"] = 1] = "FIRST";
1868
+ return TurnPlayerResult2;
1869
+ })(TurnPlayerResult || {});
1870
+ var NetPlayerType = /* @__PURE__ */ ((NetPlayerType2) => {
1871
+ NetPlayerType2[NetPlayerType2["PLAYER1"] = 0] = "PLAYER1";
1872
+ NetPlayerType2[NetPlayerType2["PLAYER2"] = 1] = "PLAYER2";
1873
+ NetPlayerType2[NetPlayerType2["PLAYER3"] = 2] = "PLAYER3";
1874
+ NetPlayerType2[NetPlayerType2["PLAYER4"] = 3] = "PLAYER4";
1875
+ NetPlayerType2[NetPlayerType2["PLAYER5"] = 4] = "PLAYER5";
1876
+ NetPlayerType2[NetPlayerType2["PLAYER6"] = 5] = "PLAYER6";
1877
+ NetPlayerType2[NetPlayerType2["OBSERVER"] = 7] = "OBSERVER";
1878
+ return NetPlayerType2;
1879
+ })(NetPlayerType || {});
1880
+ var ChatColor = /* @__PURE__ */ ((ChatColor2) => {
1881
+ ChatColor2[ChatColor2["LIGHTBLUE"] = 8] = "LIGHTBLUE";
1882
+ ChatColor2[ChatColor2["RED"] = 11] = "RED";
1883
+ ChatColor2[ChatColor2["GREEN"] = 12] = "GREEN";
1884
+ ChatColor2[ChatColor2["BLUE"] = 13] = "BLUE";
1885
+ ChatColor2[ChatColor2["BABYBLUE"] = 14] = "BABYBLUE";
1886
+ ChatColor2[ChatColor2["PINK"] = 15] = "PINK";
1887
+ ChatColor2[ChatColor2["YELLOW"] = 16] = "YELLOW";
1888
+ ChatColor2[ChatColor2["WHITE"] = 17] = "WHITE";
1889
+ ChatColor2[ChatColor2["GRAY"] = 18] = "GRAY";
1890
+ ChatColor2[ChatColor2["DARKGRAY"] = 19] = "DARKGRAY";
1891
+ return ChatColor2;
1892
+ })(ChatColor || {});
1893
+ var GameMode = /* @__PURE__ */ ((GameMode2) => {
1894
+ GameMode2[GameMode2["SINGLE"] = 0] = "SINGLE";
1895
+ GameMode2[GameMode2["MATCH"] = 1] = "MATCH";
1896
+ GameMode2[GameMode2["TAG"] = 2] = "TAG";
1897
+ return GameMode2;
1898
+ })(GameMode || {});
1899
+ var ErrorMessageType = /* @__PURE__ */ ((ErrorMessageType2) => {
1900
+ ErrorMessageType2[ErrorMessageType2["JOINERROR"] = 1] = "JOINERROR";
1901
+ ErrorMessageType2[ErrorMessageType2["DECKERROR"] = 2] = "DECKERROR";
1902
+ ErrorMessageType2[ErrorMessageType2["SIDEERROR"] = 3] = "SIDEERROR";
1903
+ ErrorMessageType2[ErrorMessageType2["VERERROR"] = 4] = "VERERROR";
1904
+ return ErrorMessageType2;
1905
+ })(ErrorMessageType || {});
1906
+ var DeckErrorType = /* @__PURE__ */ ((DeckErrorType2) => {
1907
+ DeckErrorType2[DeckErrorType2["LFLIST"] = 1] = "LFLIST";
1908
+ DeckErrorType2[DeckErrorType2["OCGONLY"] = 2] = "OCGONLY";
1909
+ DeckErrorType2[DeckErrorType2["TCGONLY"] = 3] = "TCGONLY";
1910
+ DeckErrorType2[DeckErrorType2["UNKNOWNCARD"] = 4] = "UNKNOWNCARD";
1911
+ DeckErrorType2[DeckErrorType2["CARDCOUNT"] = 5] = "CARDCOUNT";
1912
+ DeckErrorType2[DeckErrorType2["MAINCOUNT"] = 6] = "MAINCOUNT";
1913
+ DeckErrorType2[DeckErrorType2["EXTRACOUNT"] = 7] = "EXTRACOUNT";
1914
+ DeckErrorType2[DeckErrorType2["SIDECOUNT"] = 8] = "SIDECOUNT";
1915
+ DeckErrorType2[DeckErrorType2["NOTAVAIL"] = 9] = "NOTAVAIL";
1916
+ return DeckErrorType2;
1917
+ })(DeckErrorType || {});
1918
+ var PlayerChangeState = /* @__PURE__ */ ((PlayerChangeState2) => {
1919
+ PlayerChangeState2[PlayerChangeState2["OBSERVE"] = 8] = "OBSERVE";
1920
+ PlayerChangeState2[PlayerChangeState2["READY"] = 9] = "READY";
1921
+ PlayerChangeState2[PlayerChangeState2["NOTREADY"] = 10] = "NOTREADY";
1922
+ PlayerChangeState2[PlayerChangeState2["LEAVE"] = 11] = "LEAVE";
1923
+ return PlayerChangeState2;
1924
+ })(PlayerChangeState || {});
1925
+ var RoomStatus = /* @__PURE__ */ ((RoomStatus2) => {
1926
+ RoomStatus2[RoomStatus2["WAITING"] = 0] = "WAITING";
1927
+ RoomStatus2[RoomStatus2["DUELING"] = 1] = "DUELING";
1928
+ RoomStatus2[RoomStatus2["SIDING"] = 2] = "SIDING";
1929
+ return RoomStatus2;
1930
+ })(RoomStatus || {});
1931
+
1932
+ // src/protos/msg/base.ts
1933
+ var SEND_TO_PLAYERS = [0, 1];
1934
+ var SEND_TO_ALL = [0, 1, 7 /* OBSERVER */];
1935
+ var YGOProMsgBase = class extends PayloadBase {
1936
+ fromPayload(data) {
1937
+ if (data.length < 1) {
1938
+ throw new Error("MSG data too short");
1948
1939
  }
1949
- if (flags & OcgcoreCommonConstants.QUERY_LSCALE) {
1950
- view.setInt32(offset, this.lscale || 0, true);
1951
- offset += 4;
1940
+ const msgType = data[0];
1941
+ if (msgType !== this.identifier) {
1942
+ throw new Error(
1943
+ `MSG type mismatch: expected ${this.identifier}, got ${msgType}`
1944
+ );
1952
1945
  }
1953
- if (flags & OcgcoreCommonConstants.QUERY_RSCALE) {
1954
- view.setInt32(offset, this.rscale || 0, true);
1955
- offset += 4;
1946
+ return super.fromPayload(data.slice(1));
1947
+ }
1948
+ toPayload() {
1949
+ const payload = super.toPayload();
1950
+ const result = new Uint8Array(1 + payload.length);
1951
+ result[0] = this.identifier;
1952
+ result.set(payload, 1);
1953
+ return result;
1954
+ }
1955
+ opponentView() {
1956
+ return this.copy();
1957
+ }
1958
+ teammateView() {
1959
+ return this.copy();
1960
+ }
1961
+ observerView() {
1962
+ return this.opponentView();
1963
+ }
1964
+ playerView(playerId) {
1965
+ if (typeof this["player"] === "number") {
1966
+ const selfPlayerId = this["player"];
1967
+ if (selfPlayerId === playerId) {
1968
+ return this.copy();
1969
+ }
1970
+ return this.opponentView();
1956
1971
  }
1957
- if (flags & OcgcoreCommonConstants.QUERY_LINK) {
1958
- view.setInt32(offset, this.link || 0, true);
1959
- offset += 4;
1960
- view.setInt32(offset, this.linkMarker || 0, true);
1961
- offset += 4;
1972
+ return this.copy();
1973
+ }
1974
+ getSendTargets() {
1975
+ return SEND_TO_ALL;
1976
+ }
1977
+ };
1978
+
1979
+ // src/protos/msg/proto/add-counter.ts
1980
+ var YGOProMsgAddCounter = class extends YGOProMsgBase {
1981
+ };
1982
+ YGOProMsgAddCounter.identifier = OcgcoreCommonConstants.MSG_ADD_COUNTER;
1983
+ __decorateClass([
1984
+ BinaryField("u16", 0)
1985
+ ], YGOProMsgAddCounter.prototype, "counterType", 2);
1986
+ __decorateClass([
1987
+ BinaryField("u8", 2)
1988
+ ], YGOProMsgAddCounter.prototype, "controller", 2);
1989
+ __decorateClass([
1990
+ BinaryField("u8", 3)
1991
+ ], YGOProMsgAddCounter.prototype, "location", 2);
1992
+ __decorateClass([
1993
+ BinaryField("u8", 4)
1994
+ ], YGOProMsgAddCounter.prototype, "sequence", 2);
1995
+ __decorateClass([
1996
+ BinaryField("u16", 5)
1997
+ ], YGOProMsgAddCounter.prototype, "count", 2);
1998
+
1999
+ // src/protos/msg/with-response-base.ts
2000
+ var YGOProMsgResponseBase = class extends YGOProMsgBase {
2001
+ defaultResponse() {
2002
+ return void 0;
2003
+ }
2004
+ getSendTargets() {
2005
+ return [this.responsePlayer()];
2006
+ }
2007
+ };
2008
+
2009
+ // src/protos/msg/proto/announce-attrib.ts
2010
+ var YGOProMsgAnnounceAttrib = class extends YGOProMsgResponseBase {
2011
+ responsePlayer() {
2012
+ return this.player;
2013
+ }
2014
+ prepareResponse(attributes) {
2015
+ const buffer = new Uint8Array(4);
2016
+ const view = new DataView(buffer.buffer);
2017
+ view.setInt32(0, attributes, true);
2018
+ return buffer;
2019
+ }
2020
+ };
2021
+ YGOProMsgAnnounceAttrib.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_ATTRIB;
2022
+ __decorateClass([
2023
+ BinaryField("u8", 0)
2024
+ ], YGOProMsgAnnounceAttrib.prototype, "player", 2);
2025
+ __decorateClass([
2026
+ BinaryField("u8", 1)
2027
+ ], YGOProMsgAnnounceAttrib.prototype, "count", 2);
2028
+ __decorateClass([
2029
+ BinaryField("u32", 2)
2030
+ ], YGOProMsgAnnounceAttrib.prototype, "availableAttributes", 2);
2031
+
2032
+ // src/protos/msg/proto/announce-card.ts
2033
+ var YGOProMsgAnnounceCard = class extends YGOProMsgResponseBase {
2034
+ responsePlayer() {
2035
+ return this.player;
2036
+ }
2037
+ prepareResponse(cardCode) {
2038
+ const buffer = new Uint8Array(4);
2039
+ const view = new DataView(buffer.buffer);
2040
+ view.setInt32(0, cardCode, true);
2041
+ return buffer;
2042
+ }
2043
+ };
2044
+ YGOProMsgAnnounceCard.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_CARD;
2045
+ __decorateClass([
2046
+ BinaryField("u8", 0)
2047
+ ], YGOProMsgAnnounceCard.prototype, "player", 2);
2048
+ __decorateClass([
2049
+ BinaryField("u8", 1)
2050
+ ], YGOProMsgAnnounceCard.prototype, "count", 2);
2051
+ __decorateClass([
2052
+ BinaryField("i32", 2, (obj) => obj.count)
2053
+ ], YGOProMsgAnnounceCard.prototype, "opcodes", 2);
2054
+
2055
+ // src/protos/msg/index-response.ts
2056
+ var INDEX_RESPONSE_SYMBOL = /* @__PURE__ */ Symbol("IndexResponse");
2057
+ var IndexResponse = (index) => ({
2058
+ [INDEX_RESPONSE_SYMBOL]: true,
2059
+ index
2060
+ });
2061
+ var isIndexResponse = (obj) => {
2062
+ return obj != null && obj[INDEX_RESPONSE_SYMBOL] === true;
2063
+ };
2064
+
2065
+ // src/protos/msg/proto/announce-number.ts
2066
+ var YGOProMsgAnnounceNumber = class extends YGOProMsgResponseBase {
2067
+ responsePlayer() {
2068
+ return this.player;
2069
+ }
2070
+ prepareResponse(option) {
2071
+ let index;
2072
+ if (isIndexResponse(option)) {
2073
+ index = option.index;
2074
+ if (index < 0 || index >= this.count) {
2075
+ throw new TypeError(`Index out of range: ${index}`);
2076
+ }
2077
+ } else {
2078
+ index = this.numbers.indexOf(option);
2079
+ if (index === -1) {
2080
+ throw new TypeError(`Number not found: ${option}`);
2081
+ }
1962
2082
  }
1963
- return new Uint8Array(view.buffer, view.byteOffset, offset);
2083
+ const buffer = new Uint8Array(4);
2084
+ const view = new DataView(buffer.buffer);
2085
+ view.setInt32(0, index, true);
2086
+ return buffer;
2087
+ }
2088
+ };
2089
+ YGOProMsgAnnounceNumber.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_NUMBER;
2090
+ __decorateClass([
2091
+ BinaryField("u8", 0)
2092
+ ], YGOProMsgAnnounceNumber.prototype, "player", 2);
2093
+ __decorateClass([
2094
+ BinaryField("u8", 1)
2095
+ ], YGOProMsgAnnounceNumber.prototype, "count", 2);
2096
+ __decorateClass([
2097
+ BinaryField("i32", 2, (obj) => obj.count)
2098
+ ], YGOProMsgAnnounceNumber.prototype, "numbers", 2);
2099
+
2100
+ // src/protos/msg/proto/announce-race.ts
2101
+ var YGOProMsgAnnounceRace = class extends YGOProMsgResponseBase {
2102
+ responsePlayer() {
2103
+ return this.player;
1964
2104
  }
2105
+ prepareResponse(races) {
2106
+ const buffer = new Uint8Array(4);
2107
+ const view = new DataView(buffer.buffer);
2108
+ view.setInt32(0, races, true);
2109
+ return buffer;
2110
+ }
2111
+ };
2112
+ YGOProMsgAnnounceRace.identifier = OcgcoreCommonConstants.MSG_ANNOUNCE_RACE;
2113
+ __decorateClass([
2114
+ BinaryField("u8", 0)
2115
+ ], YGOProMsgAnnounceRace.prototype, "player", 2);
2116
+ __decorateClass([
2117
+ BinaryField("u8", 1)
2118
+ ], YGOProMsgAnnounceRace.prototype, "count", 2);
2119
+ __decorateClass([
2120
+ BinaryField("u32", 2)
2121
+ ], YGOProMsgAnnounceRace.prototype, "availableRaces", 2);
2122
+
2123
+ // src/protos/msg/proto/attack.ts
2124
+ var YGOProMsgAttack_CardLocation = class {
2125
+ };
2126
+ __decorateClass([
2127
+ BinaryField("u8", 0)
2128
+ ], YGOProMsgAttack_CardLocation.prototype, "controller", 2);
2129
+ __decorateClass([
2130
+ BinaryField("u8", 1)
2131
+ ], YGOProMsgAttack_CardLocation.prototype, "location", 2);
2132
+ __decorateClass([
2133
+ BinaryField("u8", 2)
2134
+ ], YGOProMsgAttack_CardLocation.prototype, "sequence", 2);
2135
+ __decorateClass([
2136
+ BinaryField("u8", 3)
2137
+ ], YGOProMsgAttack_CardLocation.prototype, "position", 2);
2138
+ var YGOProMsgAttack = class extends YGOProMsgBase {
2139
+ };
2140
+ YGOProMsgAttack.identifier = OcgcoreCommonConstants.MSG_ATTACK;
2141
+ __decorateClass([
2142
+ BinaryField(() => YGOProMsgAttack_CardLocation, 0)
2143
+ ], YGOProMsgAttack.prototype, "attacker", 2);
2144
+ __decorateClass([
2145
+ BinaryField(() => YGOProMsgAttack_CardLocation, 4)
2146
+ ], YGOProMsgAttack.prototype, "defender", 2);
2147
+
2148
+ // src/protos/msg/proto/attack-disabled.ts
2149
+ var YGOProMsgAttackDisabled = class extends YGOProMsgBase {
2150
+ };
2151
+ YGOProMsgAttackDisabled.identifier = OcgcoreCommonConstants.MSG_ATTACK_DISABLED;
2152
+
2153
+ // src/protos/msg/proto/battle.ts
2154
+ var YGOProMsgBattle_CardLocation = class {
2155
+ };
2156
+ __decorateClass([
2157
+ BinaryField("u8", 0)
2158
+ ], YGOProMsgBattle_CardLocation.prototype, "controller", 2);
2159
+ __decorateClass([
2160
+ BinaryField("u8", 1)
2161
+ ], YGOProMsgBattle_CardLocation.prototype, "location", 2);
2162
+ __decorateClass([
2163
+ BinaryField("u8", 2)
2164
+ ], YGOProMsgBattle_CardLocation.prototype, "sequence", 2);
2165
+ __decorateClass([
2166
+ BinaryField("u8", 3)
2167
+ ], YGOProMsgBattle_CardLocation.prototype, "position", 2);
2168
+ var YGOProMsgBattle_CardStats = class {
2169
+ };
2170
+ __decorateClass([
2171
+ BinaryField(() => YGOProMsgBattle_CardLocation, 0)
2172
+ ], YGOProMsgBattle_CardStats.prototype, "location", 2);
2173
+ __decorateClass([
2174
+ BinaryField("i32", 4)
2175
+ ], YGOProMsgBattle_CardStats.prototype, "atk", 2);
2176
+ __decorateClass([
2177
+ BinaryField("i32", 8)
2178
+ ], YGOProMsgBattle_CardStats.prototype, "def", 2);
2179
+ var YGOProMsgBattle = class extends YGOProMsgBase {
2180
+ };
2181
+ YGOProMsgBattle.identifier = OcgcoreCommonConstants.MSG_BATTLE;
2182
+ __decorateClass([
2183
+ BinaryField(() => YGOProMsgBattle_CardStats, 0)
2184
+ ], YGOProMsgBattle.prototype, "attacker", 2);
2185
+ __decorateClass([
2186
+ BinaryField(() => YGOProMsgBattle_CardStats, 12)
2187
+ ], YGOProMsgBattle.prototype, "defender", 2);
2188
+ __decorateClass([
2189
+ BinaryField("u8", 24)
2190
+ ], YGOProMsgBattle.prototype, "battleDamageCalc", 2);
2191
+
2192
+ // src/protos/msg/proto/become-target.ts
2193
+ var YGOProMsgBecomeTarget = class extends YGOProMsgBase {
2194
+ };
2195
+ YGOProMsgBecomeTarget.identifier = OcgcoreCommonConstants.MSG_BECOME_TARGET;
2196
+ __decorateClass([
2197
+ BinaryField("u8", 0)
2198
+ ], YGOProMsgBecomeTarget.prototype, "count", 2);
2199
+ __decorateClass([
2200
+ BinaryField("i32", 1, (obj) => obj.count)
2201
+ ], YGOProMsgBecomeTarget.prototype, "targets", 2);
2202
+
2203
+ // src/protos/msg/proto/cancel-target.ts
2204
+ var YGOProMsgCancelTarget_CardLocation = class {
2205
+ };
2206
+ __decorateClass([
2207
+ BinaryField("u8", 0)
2208
+ ], YGOProMsgCancelTarget_CardLocation.prototype, "controller", 2);
2209
+ __decorateClass([
2210
+ BinaryField("u8", 1)
2211
+ ], YGOProMsgCancelTarget_CardLocation.prototype, "location", 2);
2212
+ __decorateClass([
2213
+ BinaryField("u8", 2)
2214
+ ], YGOProMsgCancelTarget_CardLocation.prototype, "sequence", 2);
2215
+ var YGOProMsgCancelTarget = class extends YGOProMsgBase {
2216
+ };
2217
+ YGOProMsgCancelTarget.identifier = OcgcoreCommonConstants.MSG_CANCEL_TARGET;
2218
+ __decorateClass([
2219
+ BinaryField(() => YGOProMsgCancelTarget_CardLocation, 0)
2220
+ ], YGOProMsgCancelTarget.prototype, "card1", 2);
2221
+ __decorateClass([
2222
+ BinaryField(() => YGOProMsgCancelTarget_CardLocation, 3)
2223
+ ], YGOProMsgCancelTarget.prototype, "card2", 2);
2224
+
2225
+ // src/protos/msg/proto/card-hint.ts
2226
+ var YGOProMsgCardHint = class extends YGOProMsgBase {
1965
2227
  };
2228
+ YGOProMsgCardHint.identifier = OcgcoreCommonConstants.MSG_CARD_HINT;
2229
+ __decorateClass([
2230
+ BinaryField("u8", 0)
2231
+ ], YGOProMsgCardHint.prototype, "controller", 2);
2232
+ __decorateClass([
2233
+ BinaryField("u8", 1)
2234
+ ], YGOProMsgCardHint.prototype, "location", 2);
2235
+ __decorateClass([
2236
+ BinaryField("u8", 2)
2237
+ ], YGOProMsgCardHint.prototype, "sequence", 2);
2238
+ __decorateClass([
2239
+ BinaryField("u8", 3)
2240
+ ], YGOProMsgCardHint.prototype, "subsequence", 2);
2241
+ __decorateClass([
2242
+ BinaryField("u8", 4)
2243
+ ], YGOProMsgCardHint.prototype, "type", 2);
2244
+ __decorateClass([
2245
+ BinaryField("i32", 5)
2246
+ ], YGOProMsgCardHint.prototype, "value", 2);
1966
2247
 
1967
2248
  // src/protos/msg/proto/card-target.ts
1968
2249
  var YGOProMsgCardTarget_CardLocation = class {
@@ -2091,6 +2372,12 @@ var YGOProMsgConfirmCards = class extends YGOProMsgBase {
2091
2372
  });
2092
2373
  return view;
2093
2374
  }
2375
+ getSendTargets() {
2376
+ if (this.cards.length > 0 && this.cards[0].location === 1) {
2377
+ return [this.player];
2378
+ }
2379
+ return SEND_TO_ALL;
2380
+ }
2094
2381
  };
2095
2382
  YGOProMsgConfirmCards.identifier = OcgcoreCommonConstants.MSG_CONFIRM_CARDS;
2096
2383
  __decorateClass([
@@ -2321,7 +2608,18 @@ __decorateClass([
2321
2608
  ], YGOProMsgHandRes.prototype, "result", 2);
2322
2609
 
2323
2610
  // src/protos/msg/proto/hint.ts
2611
+ var HINT_TYPES_SEND_TO_SELF = /* @__PURE__ */ new Set([1, 2, 3, 5]);
2612
+ var HINT_TYPES_SEND_TO_OPPONENT = /* @__PURE__ */ new Set([4, 6, 7, 8, 9, 11]);
2324
2613
  var YGOProMsgHint = class extends YGOProMsgBase {
2614
+ getSendTargets() {
2615
+ if (HINT_TYPES_SEND_TO_SELF.has(this.type)) {
2616
+ return [this.player];
2617
+ }
2618
+ if (HINT_TYPES_SEND_TO_OPPONENT.has(this.type)) {
2619
+ return [1 - this.player, 7 /* OBSERVER */];
2620
+ }
2621
+ return SEND_TO_ALL;
2622
+ }
2325
2623
  };
2326
2624
  YGOProMsgHint.identifier = OcgcoreCommonConstants.MSG_HINT;
2327
2625
  __decorateClass([
@@ -2355,6 +2653,9 @@ __decorateClass([
2355
2653
 
2356
2654
  // src/protos/msg/proto/missed-effect.ts
2357
2655
  var YGOProMsgMissedEffect = class extends YGOProMsgBase {
2656
+ getSendTargets() {
2657
+ return [this.player];
2658
+ }
2358
2659
  };
2359
2660
  YGOProMsgMissedEffect.identifier = OcgcoreCommonConstants.MSG_MISSED_EFFECT;
2360
2661
  __decorateClass([
@@ -2656,6 +2957,9 @@ __decorateClass([
2656
2957
 
2657
2958
  // src/protos/msg/proto/reset-time.ts
2658
2959
  var YGOProMsgResetTime = class extends YGOProMsgBase {
2960
+ getSendTargets() {
2961
+ return [];
2962
+ }
2659
2963
  };
2660
2964
  YGOProMsgResetTime.identifier = OcgcoreCommonConstants.MSG_RESET_TIME;
2661
2965
  __decorateClass([
@@ -2667,6 +2971,9 @@ __decorateClass([
2667
2971
 
2668
2972
  // src/protos/msg/proto/retry.ts
2669
2973
  var YGOProMsgRetry = class extends YGOProMsgBase {
2974
+ getSendTargets() {
2975
+ return [];
2976
+ }
2670
2977
  };
2671
2978
  YGOProMsgRetry.identifier = OcgcoreCommonConstants.MSG_RETRY;
2672
2979
 
@@ -2676,7 +2983,18 @@ var YGOProMsgReverseDeck = class extends YGOProMsgBase {
2676
2983
  YGOProMsgReverseDeck.identifier = OcgcoreCommonConstants.MSG_REVERSE_DECK;
2677
2984
 
2678
2985
  // src/protos/msg/proto/rock-paper-scissors.ts
2679
- var YGOProMsgRockPaperScissors = class extends YGOProMsgBase {
2986
+ var YGOProMsgRockPaperScissors = class extends YGOProMsgResponseBase {
2987
+ responsePlayer() {
2988
+ return this.player;
2989
+ }
2990
+ prepareResponse(choice) {
2991
+ if (choice < 1 /* ROCK */ || choice > 3 /* PAPER */) {
2992
+ throw new TypeError(`Invalid choice: ${choice}. Must be 1 (ROCK), 2 (SCISSORS), or 3 (PAPER)`);
2993
+ }
2994
+ const buffer = new Uint8Array(1);
2995
+ buffer[0] = choice;
2996
+ return buffer;
2997
+ }
2680
2998
  };
2681
2999
  YGOProMsgRockPaperScissors.identifier = OcgcoreCommonConstants.MSG_ROCK_PAPER_SCISSORS;
2682
3000
  __decorateClass([
@@ -4996,6 +5314,9 @@ var YGOProMsgUpdateCard = class extends YGOProMsgBase {
4996
5314
  result.set(cardPayload, 8);
4997
5315
  return result;
4998
5316
  }
5317
+ getSendTargets() {
5318
+ return [this.controller, 1 - this.controller, 7 /* OBSERVER */];
5319
+ }
4999
5320
  };
5000
5321
  YGOProMsgUpdateCard.identifier = OcgcoreCommonConstants.MSG_UPDATE_CARD;
5001
5322
 
@@ -5099,12 +5420,18 @@ var YGOProMsgUpdateData = class extends YGOProMsgBase {
5099
5420
  }
5100
5421
  return result;
5101
5422
  }
5423
+ getSendTargets() {
5424
+ return [this.player, 1 - this.player, 7 /* OBSERVER */];
5425
+ }
5102
5426
  };
5103
5427
  YGOProMsgUpdateData.identifier = 6;
5104
5428
 
5105
5429
  // src/protos/msg/proto/waiting.ts
5106
5430
  var YGOProMsgWaiting = class extends YGOProMsgBase {
5107
5431
  // MSG_WAITING
5432
+ getSendTargets() {
5433
+ return [];
5434
+ }
5108
5435
  };
5109
5436
  YGOProMsgWaiting.identifier = 3;
5110
5437
 
@@ -5577,84 +5904,11 @@ YGOProStoc.register(YGOProStocHsWatchChange);
5577
5904
  YGOProStoc.register(YGOProStocTeammateSurrender);
5578
5905
  YGOProStoc.register(YGOProStocFieldFinish);
5579
5906
  YGOProStoc.register(YGOProStocSrvproRoomlist);
5580
-
5581
- // src/protos/network-enums.ts
5582
- var HandResult = /* @__PURE__ */ ((HandResult2) => {
5583
- HandResult2[HandResult2["ROCK"] = 1] = "ROCK";
5584
- HandResult2[HandResult2["SCISSORS"] = 2] = "SCISSORS";
5585
- HandResult2[HandResult2["PAPER"] = 3] = "PAPER";
5586
- return HandResult2;
5587
- })(HandResult || {});
5588
- var TurnPlayerResult = /* @__PURE__ */ ((TurnPlayerResult2) => {
5589
- TurnPlayerResult2[TurnPlayerResult2["SECOND"] = 0] = "SECOND";
5590
- TurnPlayerResult2[TurnPlayerResult2["FIRST"] = 1] = "FIRST";
5591
- return TurnPlayerResult2;
5592
- })(TurnPlayerResult || {});
5593
- var NetPlayerType = /* @__PURE__ */ ((NetPlayerType2) => {
5594
- NetPlayerType2[NetPlayerType2["PLAYER1"] = 0] = "PLAYER1";
5595
- NetPlayerType2[NetPlayerType2["PLAYER2"] = 1] = "PLAYER2";
5596
- NetPlayerType2[NetPlayerType2["PLAYER3"] = 2] = "PLAYER3";
5597
- NetPlayerType2[NetPlayerType2["PLAYER4"] = 3] = "PLAYER4";
5598
- NetPlayerType2[NetPlayerType2["PLAYER5"] = 4] = "PLAYER5";
5599
- NetPlayerType2[NetPlayerType2["PLAYER6"] = 5] = "PLAYER6";
5600
- NetPlayerType2[NetPlayerType2["OBSERVER"] = 7] = "OBSERVER";
5601
- return NetPlayerType2;
5602
- })(NetPlayerType || {});
5603
- var ChatColor = /* @__PURE__ */ ((ChatColor2) => {
5604
- ChatColor2[ChatColor2["LIGHTBLUE"] = 8] = "LIGHTBLUE";
5605
- ChatColor2[ChatColor2["RED"] = 11] = "RED";
5606
- ChatColor2[ChatColor2["GREEN"] = 12] = "GREEN";
5607
- ChatColor2[ChatColor2["BLUE"] = 13] = "BLUE";
5608
- ChatColor2[ChatColor2["BABYBLUE"] = 14] = "BABYBLUE";
5609
- ChatColor2[ChatColor2["PINK"] = 15] = "PINK";
5610
- ChatColor2[ChatColor2["YELLOW"] = 16] = "YELLOW";
5611
- ChatColor2[ChatColor2["WHITE"] = 17] = "WHITE";
5612
- ChatColor2[ChatColor2["GRAY"] = 18] = "GRAY";
5613
- ChatColor2[ChatColor2["DARKGRAY"] = 19] = "DARKGRAY";
5614
- return ChatColor2;
5615
- })(ChatColor || {});
5616
- var GameMode = /* @__PURE__ */ ((GameMode2) => {
5617
- GameMode2[GameMode2["SINGLE"] = 0] = "SINGLE";
5618
- GameMode2[GameMode2["MATCH"] = 1] = "MATCH";
5619
- GameMode2[GameMode2["TAG"] = 2] = "TAG";
5620
- return GameMode2;
5621
- })(GameMode || {});
5622
- var ErrorMessageType = /* @__PURE__ */ ((ErrorMessageType2) => {
5623
- ErrorMessageType2[ErrorMessageType2["JOINERROR"] = 1] = "JOINERROR";
5624
- ErrorMessageType2[ErrorMessageType2["DECKERROR"] = 2] = "DECKERROR";
5625
- ErrorMessageType2[ErrorMessageType2["SIDEERROR"] = 3] = "SIDEERROR";
5626
- ErrorMessageType2[ErrorMessageType2["VERERROR"] = 4] = "VERERROR";
5627
- return ErrorMessageType2;
5628
- })(ErrorMessageType || {});
5629
- var DeckErrorType = /* @__PURE__ */ ((DeckErrorType2) => {
5630
- DeckErrorType2[DeckErrorType2["LFLIST"] = 1] = "LFLIST";
5631
- DeckErrorType2[DeckErrorType2["OCGONLY"] = 2] = "OCGONLY";
5632
- DeckErrorType2[DeckErrorType2["TCGONLY"] = 3] = "TCGONLY";
5633
- DeckErrorType2[DeckErrorType2["UNKNOWNCARD"] = 4] = "UNKNOWNCARD";
5634
- DeckErrorType2[DeckErrorType2["CARDCOUNT"] = 5] = "CARDCOUNT";
5635
- DeckErrorType2[DeckErrorType2["MAINCOUNT"] = 6] = "MAINCOUNT";
5636
- DeckErrorType2[DeckErrorType2["EXTRACOUNT"] = 7] = "EXTRACOUNT";
5637
- DeckErrorType2[DeckErrorType2["SIDECOUNT"] = 8] = "SIDECOUNT";
5638
- DeckErrorType2[DeckErrorType2["NOTAVAIL"] = 9] = "NOTAVAIL";
5639
- return DeckErrorType2;
5640
- })(DeckErrorType || {});
5641
- var PlayerChangeState = /* @__PURE__ */ ((PlayerChangeState2) => {
5642
- PlayerChangeState2[PlayerChangeState2["OBSERVE"] = 8] = "OBSERVE";
5643
- PlayerChangeState2[PlayerChangeState2["READY"] = 9] = "READY";
5644
- PlayerChangeState2[PlayerChangeState2["NOTREADY"] = 10] = "NOTREADY";
5645
- PlayerChangeState2[PlayerChangeState2["LEAVE"] = 11] = "LEAVE";
5646
- return PlayerChangeState2;
5647
- })(PlayerChangeState || {});
5648
- var RoomStatus = /* @__PURE__ */ ((RoomStatus2) => {
5649
- RoomStatus2[RoomStatus2["WAITING"] = 0] = "WAITING";
5650
- RoomStatus2[RoomStatus2["DUELING"] = 1] = "DUELING";
5651
- RoomStatus2[RoomStatus2["SIDING"] = 2] = "SIDING";
5652
- return RoomStatus2;
5653
- })(RoomStatus || {});
5654
5907
  // Annotate the CommonJS export names for ESM import in node:
5655
5908
  0 && (module.exports = {
5656
5909
  BattleCmdType,
5657
5910
  BinaryField,
5911
+ CardData,
5658
5912
  CardQuery,
5659
5913
  CardQuery_CardLocation,
5660
5914
  CardQuery_Counter,
@@ -5671,6 +5925,8 @@ var RoomStatus = /* @__PURE__ */ ((RoomStatus2) => {
5671
5925
  OcgcoreScriptConstants,
5672
5926
  PlayerChangeState,
5673
5927
  RoomStatus,
5928
+ SEND_TO_ALL,
5929
+ SEND_TO_PLAYERS,
5674
5930
  SrvproRoomInfo,
5675
5931
  TurnPlayerResult,
5676
5932
  YGOProCtos,