ygopro-msg-encode 1.1.1 → 1.1.2
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 +641 -443
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +678 -481
- package/dist/index.mjs.map +3 -3
- package/dist/src/protos/common/index.d.ts +1 -0
- package/package.json +1 -1
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,
|
|
@@ -586,449 +587,6 @@ var PayloadBase = class {
|
|
|
586
587
|
};
|
|
587
588
|
PayloadBase.identifier = 0;
|
|
588
589
|
|
|
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
590
|
// src/vendor/ocgcore-constants.ts
|
|
1033
591
|
var OcgcoreCommonConstants = {
|
|
1034
592
|
ACTIVITY_ATTACK: 5,
|
|
@@ -1391,6 +949,645 @@ var OcgcoreCommonConstants = {
|
|
|
1391
949
|
TYPE_XYZ: 8388608
|
|
1392
950
|
};
|
|
1393
951
|
|
|
952
|
+
// src/protos/common/card-data.ts
|
|
953
|
+
var CARD_ARTWORK_VERSIONS_OFFSET = 20;
|
|
954
|
+
var CARD_BLACK_LUSTER_SOLDIER2 = 5405695;
|
|
955
|
+
var CARD_MARINE_DOLPHIN = 78734254;
|
|
956
|
+
var CARD_TWINKLE_MOSS = 13857930;
|
|
957
|
+
function checkSetcode(setcode, value) {
|
|
958
|
+
const settype = value & 4095;
|
|
959
|
+
const setsubtype = value & 61440;
|
|
960
|
+
return setcode && (setcode & 4095) === settype && (setcode & setsubtype) === setsubtype;
|
|
961
|
+
}
|
|
962
|
+
function isAlternative(code, alias) {
|
|
963
|
+
if (code === CARD_BLACK_LUSTER_SOLDIER2) {
|
|
964
|
+
return false;
|
|
965
|
+
}
|
|
966
|
+
return alias && alias < code + CARD_ARTWORK_VERSIONS_OFFSET && code < alias + CARD_ARTWORK_VERSIONS_OFFSET;
|
|
967
|
+
}
|
|
968
|
+
var CardData = class extends PayloadBase {
|
|
969
|
+
/**
|
|
970
|
+
* Check if this card belongs to a specific setcode
|
|
971
|
+
* @param value The setcode value to check against
|
|
972
|
+
* @returns true if the card belongs to the setcode
|
|
973
|
+
*/
|
|
974
|
+
isSetCard(value) {
|
|
975
|
+
for (const x of this.setcode) {
|
|
976
|
+
if (!x) {
|
|
977
|
+
return false;
|
|
978
|
+
}
|
|
979
|
+
if (checkSetcode(x, value)) {
|
|
980
|
+
return true;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Get the original code of this card (handles alternate artworks)
|
|
987
|
+
* @returns The original card code
|
|
988
|
+
*/
|
|
989
|
+
getOriginalCode() {
|
|
990
|
+
return isAlternative(this.code, this.alias) ? this.alias : this.code;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Check if this card can be declared with the given opcode filter
|
|
994
|
+
* @param opcode Array of opcodes that define the filter expression
|
|
995
|
+
* @returns true if the card can be declared
|
|
996
|
+
*/
|
|
997
|
+
isDeclarable(opcode) {
|
|
998
|
+
const stack = [];
|
|
999
|
+
for (const it of opcode) {
|
|
1000
|
+
switch (it) {
|
|
1001
|
+
case OcgcoreCommonConstants.OPCODE_ADD: {
|
|
1002
|
+
if (stack.length >= 2) {
|
|
1003
|
+
const rhs = stack.pop();
|
|
1004
|
+
const lhs = stack.pop();
|
|
1005
|
+
stack.push(lhs + rhs);
|
|
1006
|
+
}
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1009
|
+
case OcgcoreCommonConstants.OPCODE_SUB: {
|
|
1010
|
+
if (stack.length >= 2) {
|
|
1011
|
+
const rhs = stack.pop();
|
|
1012
|
+
const lhs = stack.pop();
|
|
1013
|
+
stack.push(lhs - rhs);
|
|
1014
|
+
}
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
case OcgcoreCommonConstants.OPCODE_MUL: {
|
|
1018
|
+
if (stack.length >= 2) {
|
|
1019
|
+
const rhs = stack.pop();
|
|
1020
|
+
const lhs = stack.pop();
|
|
1021
|
+
stack.push(lhs * rhs);
|
|
1022
|
+
}
|
|
1023
|
+
break;
|
|
1024
|
+
}
|
|
1025
|
+
case OcgcoreCommonConstants.OPCODE_DIV: {
|
|
1026
|
+
if (stack.length >= 2) {
|
|
1027
|
+
const rhs = stack.pop();
|
|
1028
|
+
const lhs = stack.pop();
|
|
1029
|
+
stack.push(Math.floor(lhs / rhs));
|
|
1030
|
+
}
|
|
1031
|
+
break;
|
|
1032
|
+
}
|
|
1033
|
+
case OcgcoreCommonConstants.OPCODE_AND: {
|
|
1034
|
+
if (stack.length >= 2) {
|
|
1035
|
+
const rhs = stack.pop();
|
|
1036
|
+
const lhs = stack.pop();
|
|
1037
|
+
stack.push(lhs && rhs ? 1 : 0);
|
|
1038
|
+
}
|
|
1039
|
+
break;
|
|
1040
|
+
}
|
|
1041
|
+
case OcgcoreCommonConstants.OPCODE_OR: {
|
|
1042
|
+
if (stack.length >= 2) {
|
|
1043
|
+
const rhs = stack.pop();
|
|
1044
|
+
const lhs = stack.pop();
|
|
1045
|
+
stack.push(lhs || rhs ? 1 : 0);
|
|
1046
|
+
}
|
|
1047
|
+
break;
|
|
1048
|
+
}
|
|
1049
|
+
case OcgcoreCommonConstants.OPCODE_NEG: {
|
|
1050
|
+
if (stack.length >= 1) {
|
|
1051
|
+
const val = stack.pop();
|
|
1052
|
+
stack.push(-val);
|
|
1053
|
+
}
|
|
1054
|
+
break;
|
|
1055
|
+
}
|
|
1056
|
+
case OcgcoreCommonConstants.OPCODE_NOT: {
|
|
1057
|
+
if (stack.length >= 1) {
|
|
1058
|
+
const val = stack.pop();
|
|
1059
|
+
stack.push(!val ? 1 : 0);
|
|
1060
|
+
}
|
|
1061
|
+
break;
|
|
1062
|
+
}
|
|
1063
|
+
case OcgcoreCommonConstants.OPCODE_ISCODE: {
|
|
1064
|
+
if (stack.length >= 1) {
|
|
1065
|
+
const code = stack.pop();
|
|
1066
|
+
stack.push(this.code === code ? 1 : 0);
|
|
1067
|
+
}
|
|
1068
|
+
break;
|
|
1069
|
+
}
|
|
1070
|
+
case OcgcoreCommonConstants.OPCODE_ISSETCARD: {
|
|
1071
|
+
if (stack.length >= 1) {
|
|
1072
|
+
const setCode = stack.pop();
|
|
1073
|
+
const res = this.isSetCard(setCode);
|
|
1074
|
+
stack.push(res ? 1 : 0);
|
|
1075
|
+
}
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
case OcgcoreCommonConstants.OPCODE_ISTYPE: {
|
|
1079
|
+
if (stack.length >= 1) {
|
|
1080
|
+
const val = stack.pop();
|
|
1081
|
+
stack.push(this.type & val ? 1 : 0);
|
|
1082
|
+
}
|
|
1083
|
+
break;
|
|
1084
|
+
}
|
|
1085
|
+
case OcgcoreCommonConstants.OPCODE_ISRACE: {
|
|
1086
|
+
if (stack.length >= 1) {
|
|
1087
|
+
const raceVal = stack.pop();
|
|
1088
|
+
stack.push(this.race & raceVal ? 1 : 0);
|
|
1089
|
+
}
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
case OcgcoreCommonConstants.OPCODE_ISATTRIBUTE: {
|
|
1093
|
+
if (stack.length >= 1) {
|
|
1094
|
+
const attributeVal = stack.pop();
|
|
1095
|
+
stack.push(this.attribute & attributeVal ? 1 : 0);
|
|
1096
|
+
}
|
|
1097
|
+
break;
|
|
1098
|
+
}
|
|
1099
|
+
default: {
|
|
1100
|
+
stack.push(it);
|
|
1101
|
+
break;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
if (stack.length !== 1 || stack[0] === 0) {
|
|
1106
|
+
return false;
|
|
1107
|
+
}
|
|
1108
|
+
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);
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
__decorateClass([
|
|
1112
|
+
BinaryField("u32", 0)
|
|
1113
|
+
], CardData.prototype, "code", 2);
|
|
1114
|
+
__decorateClass([
|
|
1115
|
+
BinaryField("u32", 4)
|
|
1116
|
+
], CardData.prototype, "alias", 2);
|
|
1117
|
+
__decorateClass([
|
|
1118
|
+
BinaryField("u16", 8, 16)
|
|
1119
|
+
], CardData.prototype, "setcode", 2);
|
|
1120
|
+
__decorateClass([
|
|
1121
|
+
BinaryField("u32", 40)
|
|
1122
|
+
], CardData.prototype, "type", 2);
|
|
1123
|
+
__decorateClass([
|
|
1124
|
+
BinaryField("u32", 44)
|
|
1125
|
+
], CardData.prototype, "level", 2);
|
|
1126
|
+
__decorateClass([
|
|
1127
|
+
BinaryField("u32", 48)
|
|
1128
|
+
], CardData.prototype, "attribute", 2);
|
|
1129
|
+
__decorateClass([
|
|
1130
|
+
BinaryField("u32", 52)
|
|
1131
|
+
], CardData.prototype, "race", 2);
|
|
1132
|
+
__decorateClass([
|
|
1133
|
+
BinaryField("i32", 56)
|
|
1134
|
+
], CardData.prototype, "attack", 2);
|
|
1135
|
+
__decorateClass([
|
|
1136
|
+
BinaryField("i32", 60)
|
|
1137
|
+
], CardData.prototype, "defense", 2);
|
|
1138
|
+
__decorateClass([
|
|
1139
|
+
BinaryField("u32", 64)
|
|
1140
|
+
], CardData.prototype, "lscale", 2);
|
|
1141
|
+
__decorateClass([
|
|
1142
|
+
BinaryField("u32", 68)
|
|
1143
|
+
], CardData.prototype, "rscale", 2);
|
|
1144
|
+
__decorateClass([
|
|
1145
|
+
BinaryField("u32", 72)
|
|
1146
|
+
], CardData.prototype, "linkMarker", 2);
|
|
1147
|
+
|
|
1148
|
+
// src/protos/ctos/base.ts
|
|
1149
|
+
var YGOProCtosBase = class extends PayloadBase {
|
|
1150
|
+
/**
|
|
1151
|
+
* Serialize to full payload including header (length + identifier + body)
|
|
1152
|
+
* Format: [length 2 bytes LE][identifier 1 byte][body]
|
|
1153
|
+
* Length = 1 (identifier) + body.length
|
|
1154
|
+
*/
|
|
1155
|
+
toFullPayload() {
|
|
1156
|
+
const body = this.toPayload();
|
|
1157
|
+
const length = 1 + body.length;
|
|
1158
|
+
const fullPayload = new Uint8Array(3 + body.length);
|
|
1159
|
+
fullPayload[0] = length & 255;
|
|
1160
|
+
fullPayload[1] = length >> 8 & 255;
|
|
1161
|
+
fullPayload[2] = this.identifier;
|
|
1162
|
+
fullPayload.set(body, 3);
|
|
1163
|
+
return fullPayload;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Deserialize from full payload including header (length + identifier + body)
|
|
1167
|
+
* Format: [length 2 bytes LE][identifier 1 byte][body]
|
|
1168
|
+
* @param data - Full payload data
|
|
1169
|
+
* @returns this instance
|
|
1170
|
+
* @throws Error if data is too short or identifier mismatch
|
|
1171
|
+
*/
|
|
1172
|
+
fromFullPayload(data) {
|
|
1173
|
+
if (data.length < 3) {
|
|
1174
|
+
throw new Error(
|
|
1175
|
+
`CTOS payload too short: expected at least 3 bytes, got ${data.length}`
|
|
1176
|
+
);
|
|
1177
|
+
}
|
|
1178
|
+
const declaredLength = data[0] | data[1] << 8;
|
|
1179
|
+
const identifier = data[2];
|
|
1180
|
+
if (identifier !== this.identifier) {
|
|
1181
|
+
throw new Error(
|
|
1182
|
+
`CTOS identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
const expectedTotalLength = 3 + declaredLength - 1;
|
|
1186
|
+
if (data.length < expectedTotalLength) {
|
|
1187
|
+
throw new Error(
|
|
1188
|
+
`CTOS payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
|
|
1192
|
+
return this.fromPayload(bodyData);
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
// src/proto-base/registry-base.ts
|
|
1197
|
+
var RegistryBase = class {
|
|
1198
|
+
constructor(payloadClass, options = {}) {
|
|
1199
|
+
this.payloadClass = payloadClass;
|
|
1200
|
+
this.options = options;
|
|
1201
|
+
this.protos = /* @__PURE__ */ new Map();
|
|
1202
|
+
}
|
|
1203
|
+
register(proto) {
|
|
1204
|
+
const identifier = proto.identifier;
|
|
1205
|
+
this.protos.set(identifier, proto);
|
|
1206
|
+
}
|
|
1207
|
+
get(identifier) {
|
|
1208
|
+
return this.protos.get(identifier);
|
|
1209
|
+
}
|
|
1210
|
+
getInstanceFromPayload(data) {
|
|
1211
|
+
const identifier = data[this.options.identifierOffset ?? 0];
|
|
1212
|
+
const proto = this.get(identifier);
|
|
1213
|
+
if (!proto) {
|
|
1214
|
+
return void 0;
|
|
1215
|
+
}
|
|
1216
|
+
return new proto().fromPayload(
|
|
1217
|
+
data.slice(this.options.dataOffset ?? 0)
|
|
1218
|
+
);
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
// src/protos/ctos/proto/response.ts
|
|
1223
|
+
var YGOProCtosResponse = class extends YGOProCtosBase {
|
|
1224
|
+
fromPayload(data) {
|
|
1225
|
+
this.response = data;
|
|
1226
|
+
return this;
|
|
1227
|
+
}
|
|
1228
|
+
toPayload() {
|
|
1229
|
+
return this.response || new Uint8Array(0);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
YGOProCtosResponse.identifier = 1;
|
|
1233
|
+
|
|
1234
|
+
// src/protos/ctos/proto/update-deck.ts
|
|
1235
|
+
var import_ygopro_deck_encode = __toESM(require("ygopro-deck-encode"));
|
|
1236
|
+
var YGOProCtosUpdateDeck = class extends YGOProCtosBase {
|
|
1237
|
+
constructor() {
|
|
1238
|
+
super();
|
|
1239
|
+
this.deck = new import_ygopro_deck_encode.default();
|
|
1240
|
+
}
|
|
1241
|
+
fromPayload(data) {
|
|
1242
|
+
this.deck = import_ygopro_deck_encode.default.fromUpdateDeckPayload(data);
|
|
1243
|
+
return this;
|
|
1244
|
+
}
|
|
1245
|
+
toPayload() {
|
|
1246
|
+
return this.deck.toUpdateDeckPayload();
|
|
1247
|
+
}
|
|
1248
|
+
fromPartial(data) {
|
|
1249
|
+
if (data.deck) {
|
|
1250
|
+
this.deck = new import_ygopro_deck_encode.default(data.deck);
|
|
1251
|
+
}
|
|
1252
|
+
return this;
|
|
1253
|
+
}
|
|
1254
|
+
copy() {
|
|
1255
|
+
const copied = new this.constructor();
|
|
1256
|
+
copied.deck = new import_ygopro_deck_encode.default(this.deck);
|
|
1257
|
+
return copied;
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
YGOProCtosUpdateDeck.identifier = 2;
|
|
1261
|
+
|
|
1262
|
+
// src/protos/ctos/proto/hand-result.ts
|
|
1263
|
+
var YGOProCtosHandResult = class extends YGOProCtosBase {
|
|
1264
|
+
};
|
|
1265
|
+
YGOProCtosHandResult.identifier = 3;
|
|
1266
|
+
__decorateClass([
|
|
1267
|
+
BinaryField("u8", 0)
|
|
1268
|
+
], YGOProCtosHandResult.prototype, "res", 2);
|
|
1269
|
+
|
|
1270
|
+
// src/protos/ctos/proto/tp-result.ts
|
|
1271
|
+
var YGOProCtosTpResult = class extends YGOProCtosBase {
|
|
1272
|
+
};
|
|
1273
|
+
YGOProCtosTpResult.identifier = 4;
|
|
1274
|
+
__decorateClass([
|
|
1275
|
+
BinaryField("u8", 0)
|
|
1276
|
+
], YGOProCtosTpResult.prototype, "res", 2);
|
|
1277
|
+
|
|
1278
|
+
// src/protos/ctos/proto/player-info.ts
|
|
1279
|
+
var YGOProCtosPlayerInfo = class extends YGOProCtosBase {
|
|
1280
|
+
};
|
|
1281
|
+
YGOProCtosPlayerInfo.identifier = 16;
|
|
1282
|
+
__decorateClass([
|
|
1283
|
+
BinaryField("utf16", 0, 20)
|
|
1284
|
+
], YGOProCtosPlayerInfo.prototype, "name", 2);
|
|
1285
|
+
|
|
1286
|
+
// src/protos/ctos/proto/create-game.ts
|
|
1287
|
+
var YGOProCtosCreateGame = class extends YGOProCtosBase {
|
|
1288
|
+
};
|
|
1289
|
+
YGOProCtosCreateGame.identifier = 17;
|
|
1290
|
+
__decorateClass([
|
|
1291
|
+
BinaryField(() => HostInfo, 0)
|
|
1292
|
+
], YGOProCtosCreateGame.prototype, "info", 2);
|
|
1293
|
+
__decorateClass([
|
|
1294
|
+
BinaryField("utf16", 20, 20)
|
|
1295
|
+
], YGOProCtosCreateGame.prototype, "name", 2);
|
|
1296
|
+
__decorateClass([
|
|
1297
|
+
BinaryField("utf16", 60, 20)
|
|
1298
|
+
], YGOProCtosCreateGame.prototype, "pass", 2);
|
|
1299
|
+
|
|
1300
|
+
// src/protos/ctos/proto/join-game.ts
|
|
1301
|
+
var YGOProCtosJoinGame = class extends YGOProCtosBase {
|
|
1302
|
+
};
|
|
1303
|
+
YGOProCtosJoinGame.identifier = 18;
|
|
1304
|
+
__decorateClass([
|
|
1305
|
+
BinaryField("u16", 0)
|
|
1306
|
+
], YGOProCtosJoinGame.prototype, "version", 2);
|
|
1307
|
+
__decorateClass([
|
|
1308
|
+
BinaryField("u32", 4)
|
|
1309
|
+
], YGOProCtosJoinGame.prototype, "gameid", 2);
|
|
1310
|
+
__decorateClass([
|
|
1311
|
+
BinaryField("utf16", 8, 20)
|
|
1312
|
+
], YGOProCtosJoinGame.prototype, "pass", 2);
|
|
1313
|
+
|
|
1314
|
+
// src/protos/ctos/proto/leave-game.ts
|
|
1315
|
+
var YGOProCtosLeaveGame = class extends YGOProCtosBase {
|
|
1316
|
+
};
|
|
1317
|
+
YGOProCtosLeaveGame.identifier = 19;
|
|
1318
|
+
|
|
1319
|
+
// src/protos/ctos/proto/surrender.ts
|
|
1320
|
+
var YGOProCtosSurrender = class extends YGOProCtosBase {
|
|
1321
|
+
};
|
|
1322
|
+
YGOProCtosSurrender.identifier = 20;
|
|
1323
|
+
|
|
1324
|
+
// src/protos/ctos/proto/time-confirm.ts
|
|
1325
|
+
var YGOProCtosTimeConfirm = class extends YGOProCtosBase {
|
|
1326
|
+
};
|
|
1327
|
+
YGOProCtosTimeConfirm.identifier = 21;
|
|
1328
|
+
|
|
1329
|
+
// src/protos/ctos/proto/chat.ts
|
|
1330
|
+
var YGOProCtosChat = class extends YGOProCtosBase {
|
|
1331
|
+
constructor() {
|
|
1332
|
+
super();
|
|
1333
|
+
this.msg = "";
|
|
1334
|
+
}
|
|
1335
|
+
fromPayload(data) {
|
|
1336
|
+
const decoder = new TextDecoder("utf-16le");
|
|
1337
|
+
this.msg = decoder.decode(data).replace(/\0+$/, "");
|
|
1338
|
+
return this;
|
|
1339
|
+
}
|
|
1340
|
+
toPayload() {
|
|
1341
|
+
const encoder = new TextEncoder();
|
|
1342
|
+
const utf8 = encoder.encode(this.msg);
|
|
1343
|
+
const decoder = new TextDecoder("utf-8");
|
|
1344
|
+
const text = decoder.decode(utf8);
|
|
1345
|
+
const utf16 = new Uint16Array(text.length + 1);
|
|
1346
|
+
for (let i = 0; i < text.length; i++) {
|
|
1347
|
+
utf16[i] = text.charCodeAt(i);
|
|
1348
|
+
}
|
|
1349
|
+
utf16[text.length] = 0;
|
|
1350
|
+
const result = new Uint8Array(utf16.buffer);
|
|
1351
|
+
return result;
|
|
1352
|
+
}
|
|
1353
|
+
fromPartial(data) {
|
|
1354
|
+
if (data.msg !== void 0) {
|
|
1355
|
+
this.msg = data.msg;
|
|
1356
|
+
}
|
|
1357
|
+
return this;
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
YGOProCtosChat.identifier = 22;
|
|
1361
|
+
|
|
1362
|
+
// src/protos/ctos/proto/external-address.ts
|
|
1363
|
+
var YGOProCtosExternalAddress = class extends YGOProCtosBase {
|
|
1364
|
+
constructor() {
|
|
1365
|
+
super();
|
|
1366
|
+
this.real_ip = "0.0.0.0";
|
|
1367
|
+
this.hostname = "";
|
|
1368
|
+
}
|
|
1369
|
+
// Convert IPv4 string to uint32 (network byte order / big endian)
|
|
1370
|
+
ipToUint32(ip) {
|
|
1371
|
+
let ipv4 = ip;
|
|
1372
|
+
if (ip.startsWith("::ffff:")) {
|
|
1373
|
+
ipv4 = ip.substring(7);
|
|
1374
|
+
}
|
|
1375
|
+
const parts = ipv4.split(".");
|
|
1376
|
+
if (parts.length !== 4) {
|
|
1377
|
+
return 0;
|
|
1378
|
+
}
|
|
1379
|
+
const bytes = parts.map((p) => parseInt(p, 10));
|
|
1380
|
+
if (bytes.some((b) => isNaN(b) || b < 0 || b > 255)) {
|
|
1381
|
+
return 0;
|
|
1382
|
+
}
|
|
1383
|
+
return bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
|
|
1384
|
+
}
|
|
1385
|
+
// Convert uint32 (network byte order / big endian) to IPv4 string
|
|
1386
|
+
uint32ToIp(value) {
|
|
1387
|
+
const byte1 = value >>> 24 & 255;
|
|
1388
|
+
const byte2 = value >>> 16 & 255;
|
|
1389
|
+
const byte3 = value >>> 8 & 255;
|
|
1390
|
+
const byte4 = value & 255;
|
|
1391
|
+
return `${byte1}.${byte2}.${byte3}.${byte4}`;
|
|
1392
|
+
}
|
|
1393
|
+
fromPayload(data) {
|
|
1394
|
+
if (data.length < 4) {
|
|
1395
|
+
throw new Error("CTOS_EXTERNAL_ADDRESS data too short");
|
|
1396
|
+
}
|
|
1397
|
+
const ipUint32 = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
|
|
1398
|
+
this.real_ip = this.uint32ToIp(ipUint32);
|
|
1399
|
+
if (data.length > 4) {
|
|
1400
|
+
const decoder = new TextDecoder("utf-16le");
|
|
1401
|
+
this.hostname = decoder.decode(data.slice(4)).replace(/\0+$/, "");
|
|
1402
|
+
} else {
|
|
1403
|
+
this.hostname = "";
|
|
1404
|
+
}
|
|
1405
|
+
return this;
|
|
1406
|
+
}
|
|
1407
|
+
toPayload() {
|
|
1408
|
+
const encoder = new TextEncoder();
|
|
1409
|
+
const utf8 = encoder.encode(this.hostname);
|
|
1410
|
+
const decoder = new TextDecoder("utf-8");
|
|
1411
|
+
const text = decoder.decode(utf8);
|
|
1412
|
+
const utf16 = new Uint16Array(text.length + 1);
|
|
1413
|
+
for (let i = 0; i < text.length; i++) {
|
|
1414
|
+
utf16[i] = text.charCodeAt(i);
|
|
1415
|
+
}
|
|
1416
|
+
utf16[text.length] = 0;
|
|
1417
|
+
const result = new Uint8Array(4 + utf16.byteLength);
|
|
1418
|
+
const ipUint32 = this.ipToUint32(this.real_ip);
|
|
1419
|
+
result[0] = ipUint32 >>> 24 & 255;
|
|
1420
|
+
result[1] = ipUint32 >>> 16 & 255;
|
|
1421
|
+
result[2] = ipUint32 >>> 8 & 255;
|
|
1422
|
+
result[3] = ipUint32 & 255;
|
|
1423
|
+
result.set(new Uint8Array(utf16.buffer), 4);
|
|
1424
|
+
return result;
|
|
1425
|
+
}
|
|
1426
|
+
fromPartial(data) {
|
|
1427
|
+
if (data.real_ip !== void 0) {
|
|
1428
|
+
this.real_ip = data.real_ip;
|
|
1429
|
+
}
|
|
1430
|
+
if (data.hostname !== void 0) {
|
|
1431
|
+
this.hostname = data.hostname;
|
|
1432
|
+
}
|
|
1433
|
+
return this;
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
YGOProCtosExternalAddress.identifier = 23;
|
|
1437
|
+
|
|
1438
|
+
// src/protos/ctos/proto/hs-toduelist.ts
|
|
1439
|
+
var YGOProCtosHsToDuelist = class extends YGOProCtosBase {
|
|
1440
|
+
};
|
|
1441
|
+
YGOProCtosHsToDuelist.identifier = 32;
|
|
1442
|
+
|
|
1443
|
+
// src/protos/ctos/proto/hs-toobserver.ts
|
|
1444
|
+
var YGOProCtosHsToObserver = class extends YGOProCtosBase {
|
|
1445
|
+
};
|
|
1446
|
+
YGOProCtosHsToObserver.identifier = 33;
|
|
1447
|
+
|
|
1448
|
+
// src/protos/ctos/proto/hs-ready.ts
|
|
1449
|
+
var YGOProCtosHsReady = class extends YGOProCtosBase {
|
|
1450
|
+
};
|
|
1451
|
+
YGOProCtosHsReady.identifier = 34;
|
|
1452
|
+
|
|
1453
|
+
// src/protos/ctos/proto/hs-notready.ts
|
|
1454
|
+
var YGOProCtosHsNotReady = class extends YGOProCtosBase {
|
|
1455
|
+
};
|
|
1456
|
+
YGOProCtosHsNotReady.identifier = 35;
|
|
1457
|
+
|
|
1458
|
+
// src/protos/ctos/proto/kick.ts
|
|
1459
|
+
var YGOProCtosKick = class extends YGOProCtosBase {
|
|
1460
|
+
};
|
|
1461
|
+
YGOProCtosKick.identifier = 36;
|
|
1462
|
+
__decorateClass([
|
|
1463
|
+
BinaryField("u8", 0)
|
|
1464
|
+
], YGOProCtosKick.prototype, "pos", 2);
|
|
1465
|
+
|
|
1466
|
+
// src/protos/ctos/proto/hs-start.ts
|
|
1467
|
+
var YGOProCtosHsStart = class extends YGOProCtosBase {
|
|
1468
|
+
};
|
|
1469
|
+
YGOProCtosHsStart.identifier = 37;
|
|
1470
|
+
|
|
1471
|
+
// src/protos/ctos/proto/request-field.ts
|
|
1472
|
+
var YGOProCtosRequestField = class extends YGOProCtosBase {
|
|
1473
|
+
};
|
|
1474
|
+
YGOProCtosRequestField.identifier = 48;
|
|
1475
|
+
|
|
1476
|
+
// src/protos/ctos/registry.ts
|
|
1477
|
+
var YGOProCtos = new RegistryBase(YGOProCtosBase, {
|
|
1478
|
+
identifierOffset: 2,
|
|
1479
|
+
dataOffset: 3
|
|
1480
|
+
});
|
|
1481
|
+
YGOProCtos.register(YGOProCtosResponse);
|
|
1482
|
+
YGOProCtos.register(YGOProCtosUpdateDeck);
|
|
1483
|
+
YGOProCtos.register(YGOProCtosHandResult);
|
|
1484
|
+
YGOProCtos.register(YGOProCtosTpResult);
|
|
1485
|
+
YGOProCtos.register(YGOProCtosPlayerInfo);
|
|
1486
|
+
YGOProCtos.register(YGOProCtosCreateGame);
|
|
1487
|
+
YGOProCtos.register(YGOProCtosJoinGame);
|
|
1488
|
+
YGOProCtos.register(YGOProCtosLeaveGame);
|
|
1489
|
+
YGOProCtos.register(YGOProCtosSurrender);
|
|
1490
|
+
YGOProCtos.register(YGOProCtosTimeConfirm);
|
|
1491
|
+
YGOProCtos.register(YGOProCtosChat);
|
|
1492
|
+
YGOProCtos.register(YGOProCtosExternalAddress);
|
|
1493
|
+
YGOProCtos.register(YGOProCtosHsToDuelist);
|
|
1494
|
+
YGOProCtos.register(YGOProCtosHsToObserver);
|
|
1495
|
+
YGOProCtos.register(YGOProCtosHsReady);
|
|
1496
|
+
YGOProCtos.register(YGOProCtosHsNotReady);
|
|
1497
|
+
YGOProCtos.register(YGOProCtosKick);
|
|
1498
|
+
YGOProCtos.register(YGOProCtosHsStart);
|
|
1499
|
+
YGOProCtos.register(YGOProCtosRequestField);
|
|
1500
|
+
|
|
1501
|
+
// src/protos/stoc/base.ts
|
|
1502
|
+
var YGOProStocBase = class extends PayloadBase {
|
|
1503
|
+
/**
|
|
1504
|
+
* Serialize to full payload including header (length + identifier + body)
|
|
1505
|
+
* Format: [length 2 bytes LE][identifier 1 byte][body]
|
|
1506
|
+
* Length = 1 (identifier) + body.length
|
|
1507
|
+
*/
|
|
1508
|
+
toFullPayload() {
|
|
1509
|
+
const body = this.toPayload();
|
|
1510
|
+
const length = 1 + body.length;
|
|
1511
|
+
const fullPayload = new Uint8Array(3 + body.length);
|
|
1512
|
+
fullPayload[0] = length & 255;
|
|
1513
|
+
fullPayload[1] = length >> 8 & 255;
|
|
1514
|
+
fullPayload[2] = this.identifier;
|
|
1515
|
+
fullPayload.set(body, 3);
|
|
1516
|
+
return fullPayload;
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Deserialize from full payload including header (length + identifier + body)
|
|
1520
|
+
* Format: [length 2 bytes LE][identifier 1 byte][body]
|
|
1521
|
+
* @param data - Full payload data
|
|
1522
|
+
* @returns this instance
|
|
1523
|
+
* @throws Error if data is too short or identifier mismatch
|
|
1524
|
+
*/
|
|
1525
|
+
fromFullPayload(data) {
|
|
1526
|
+
if (data.length < 3) {
|
|
1527
|
+
throw new Error(
|
|
1528
|
+
`STOC payload too short: expected at least 3 bytes, got ${data.length}`
|
|
1529
|
+
);
|
|
1530
|
+
}
|
|
1531
|
+
const declaredLength = data[0] | data[1] << 8;
|
|
1532
|
+
const identifier = data[2];
|
|
1533
|
+
if (identifier !== this.identifier) {
|
|
1534
|
+
throw new Error(
|
|
1535
|
+
`STOC identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
|
|
1536
|
+
);
|
|
1537
|
+
}
|
|
1538
|
+
const expectedTotalLength = 3 + declaredLength - 1;
|
|
1539
|
+
if (data.length < expectedTotalLength) {
|
|
1540
|
+
throw new Error(
|
|
1541
|
+
`STOC payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
|
|
1545
|
+
return this.fromPayload(bodyData);
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
|
|
1549
|
+
// src/protos/msg/base.ts
|
|
1550
|
+
var YGOProMsgBase = class extends PayloadBase {
|
|
1551
|
+
fromPayload(data) {
|
|
1552
|
+
if (data.length < 1) {
|
|
1553
|
+
throw new Error("MSG data too short");
|
|
1554
|
+
}
|
|
1555
|
+
const msgType = data[0];
|
|
1556
|
+
if (msgType !== this.identifier) {
|
|
1557
|
+
throw new Error(
|
|
1558
|
+
`MSG type mismatch: expected ${this.identifier}, got ${msgType}`
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
return super.fromPayload(data.slice(1));
|
|
1562
|
+
}
|
|
1563
|
+
toPayload() {
|
|
1564
|
+
const payload = super.toPayload();
|
|
1565
|
+
const result = new Uint8Array(1 + payload.length);
|
|
1566
|
+
result[0] = this.identifier;
|
|
1567
|
+
result.set(payload, 1);
|
|
1568
|
+
return result;
|
|
1569
|
+
}
|
|
1570
|
+
opponentView() {
|
|
1571
|
+
return this.copy();
|
|
1572
|
+
}
|
|
1573
|
+
teammateView() {
|
|
1574
|
+
return this.copy();
|
|
1575
|
+
}
|
|
1576
|
+
observerView() {
|
|
1577
|
+
return this.opponentView();
|
|
1578
|
+
}
|
|
1579
|
+
playerView(playerId) {
|
|
1580
|
+
if (typeof this["player"] === "number") {
|
|
1581
|
+
const selfPlayerId = this["player"];
|
|
1582
|
+
if (selfPlayerId === playerId) {
|
|
1583
|
+
return this.copy();
|
|
1584
|
+
}
|
|
1585
|
+
return this.opponentView();
|
|
1586
|
+
}
|
|
1587
|
+
return this.copy();
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
|
|
1394
1591
|
// src/protos/msg/proto/add-counter.ts
|
|
1395
1592
|
var YGOProMsgAddCounter = class extends YGOProMsgBase {
|
|
1396
1593
|
};
|
|
@@ -5655,6 +5852,7 @@ var RoomStatus = /* @__PURE__ */ ((RoomStatus2) => {
|
|
|
5655
5852
|
0 && (module.exports = {
|
|
5656
5853
|
BattleCmdType,
|
|
5657
5854
|
BinaryField,
|
|
5855
|
+
CardData,
|
|
5658
5856
|
CardQuery,
|
|
5659
5857
|
CardQuery_CardLocation,
|
|
5660
5858
|
CardQuery_Counter,
|