ygopro-msg-encode 1.0.1

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.
Files changed (178) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +25 -0
  3. package/.prettierrc +4 -0
  4. package/AGENTS.md +12 -0
  5. package/CHANGES.md +270 -0
  6. package/CTOS_STOC_IMPLEMENTATION.md +279 -0
  7. package/FINAL_SUMMARY.md +357 -0
  8. package/FULL_PAYLOAD_SUMMARY.md +491 -0
  9. package/FULL_PAYLOAD_UPDATE.md +598 -0
  10. package/IMPLEMENTATION_SUMMARY.md +294 -0
  11. package/LICENSE +22 -0
  12. package/MSG_IMPLEMENTATION_SUMMARY.md +358 -0
  13. package/OPPONENT_VIEW_SUMMARY.md +387 -0
  14. package/PROJECT_COMPLETE.md +565 -0
  15. package/QUICK_REFERENCE.md +352 -0
  16. package/README.md +494 -0
  17. package/REAL_IP_STRING_UPDATE.md +289 -0
  18. package/TESTS_MIGRATION.md +342 -0
  19. package/VARIABLE_LENGTH_STRINGS.md +224 -0
  20. package/VARIABLE_LENGTH_UPDATE.md +229 -0
  21. package/dist/index.cjs +5131 -0
  22. package/dist/index.cjs.map +7 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.mjs +5185 -0
  25. package/dist/index.mjs.map +7 -0
  26. package/dist/src/binary/binary-meta.d.ts +18 -0
  27. package/dist/src/binary/fill-binary-fields.d.ts +2 -0
  28. package/dist/src/metadata.d.ts +10 -0
  29. package/dist/src/proto-base/payload-base.d.ts +8 -0
  30. package/dist/src/proto-base/registry-base.d.ts +13 -0
  31. package/dist/src/protos/common/host-info.d.ts +12 -0
  32. package/dist/src/protos/common/index.d.ts +1 -0
  33. package/dist/src/protos/ctos/base.d.ts +17 -0
  34. package/dist/src/protos/ctos/index.d.ts +3 -0
  35. package/dist/src/protos/ctos/proto/chat.d.ts +9 -0
  36. package/dist/src/protos/ctos/proto/create-game.d.ts +8 -0
  37. package/dist/src/protos/ctos/proto/external-address.d.ts +12 -0
  38. package/dist/src/protos/ctos/proto/hand-result.d.ts +5 -0
  39. package/dist/src/protos/ctos/proto/hs-notready.d.ts +4 -0
  40. package/dist/src/protos/ctos/proto/hs-ready.d.ts +4 -0
  41. package/dist/src/protos/ctos/proto/hs-start.d.ts +4 -0
  42. package/dist/src/protos/ctos/proto/hs-toduelist.d.ts +4 -0
  43. package/dist/src/protos/ctos/proto/hs-toobserver.d.ts +4 -0
  44. package/dist/src/protos/ctos/proto/index.d.ts +19 -0
  45. package/dist/src/protos/ctos/proto/join-game.d.ts +7 -0
  46. package/dist/src/protos/ctos/proto/kick.d.ts +5 -0
  47. package/dist/src/protos/ctos/proto/leave-game.d.ts +4 -0
  48. package/dist/src/protos/ctos/proto/player-info.d.ts +5 -0
  49. package/dist/src/protos/ctos/proto/request-field.d.ts +4 -0
  50. package/dist/src/protos/ctos/proto/response.d.ts +7 -0
  51. package/dist/src/protos/ctos/proto/surrender.d.ts +4 -0
  52. package/dist/src/protos/ctos/proto/time-confirm.d.ts +4 -0
  53. package/dist/src/protos/ctos/proto/tp-result.d.ts +5 -0
  54. package/dist/src/protos/ctos/proto/update-deck.d.ts +11 -0
  55. package/dist/src/protos/ctos/registry.d.ts +3 -0
  56. package/dist/src/protos/msg/base.d.ts +9 -0
  57. package/dist/src/protos/msg/index.d.ts +3 -0
  58. package/dist/src/protos/msg/proto/add-counter.d.ts +9 -0
  59. package/dist/src/protos/msg/proto/announce-attrib.d.ts +7 -0
  60. package/dist/src/protos/msg/proto/announce-card.d.ts +7 -0
  61. package/dist/src/protos/msg/proto/announce-number.d.ts +7 -0
  62. package/dist/src/protos/msg/proto/announce-race.d.ts +7 -0
  63. package/dist/src/protos/msg/proto/attack-disabled.d.ts +4 -0
  64. package/dist/src/protos/msg/proto/attack.d.ts +12 -0
  65. package/dist/src/protos/msg/proto/battle.d.ts +18 -0
  66. package/dist/src/protos/msg/proto/become-target.d.ts +6 -0
  67. package/dist/src/protos/msg/proto/cancel-target.d.ts +11 -0
  68. package/dist/src/protos/msg/proto/card-hint.d.ts +10 -0
  69. package/dist/src/protos/msg/proto/card-query.d.ts +38 -0
  70. package/dist/src/protos/msg/proto/card-target.d.ts +11 -0
  71. package/dist/src/protos/msg/proto/chain-disabled.d.ts +5 -0
  72. package/dist/src/protos/msg/proto/chain-end.d.ts +4 -0
  73. package/dist/src/protos/msg/proto/chain-negated.d.ts +5 -0
  74. package/dist/src/protos/msg/proto/chain-solved.d.ts +5 -0
  75. package/dist/src/protos/msg/proto/chain-solving.d.ts +5 -0
  76. package/dist/src/protos/msg/proto/chained.d.ts +5 -0
  77. package/dist/src/protos/msg/proto/chaining.d.ts +12 -0
  78. package/dist/src/protos/msg/proto/confirm-cards.d.ts +16 -0
  79. package/dist/src/protos/msg/proto/confirm-decktop.d.ts +14 -0
  80. package/dist/src/protos/msg/proto/confirm-extratop.d.ts +14 -0
  81. package/dist/src/protos/msg/proto/damage-step-end.d.ts +4 -0
  82. package/dist/src/protos/msg/proto/damage-step-start.d.ts +4 -0
  83. package/dist/src/protos/msg/proto/damage.d.ts +6 -0
  84. package/dist/src/protos/msg/proto/deck-top.d.ts +8 -0
  85. package/dist/src/protos/msg/proto/draw.d.ts +8 -0
  86. package/dist/src/protos/msg/proto/equip.d.ts +12 -0
  87. package/dist/src/protos/msg/proto/field-disabled.d.ts +5 -0
  88. package/dist/src/protos/msg/proto/flipsummoned.d.ts +4 -0
  89. package/dist/src/protos/msg/proto/flipsummoning.d.ts +9 -0
  90. package/dist/src/protos/msg/proto/hand-res.d.ts +5 -0
  91. package/dist/src/protos/msg/proto/hint.d.ts +7 -0
  92. package/dist/src/protos/msg/proto/index.d.ts +85 -0
  93. package/dist/src/protos/msg/proto/lpupdate.d.ts +6 -0
  94. package/dist/src/protos/msg/proto/match-kill.d.ts +5 -0
  95. package/dist/src/protos/msg/proto/missed-effect.d.ts +7 -0
  96. package/dist/src/protos/msg/proto/move.d.ts +14 -0
  97. package/dist/src/protos/msg/proto/new-phase.d.ts +5 -0
  98. package/dist/src/protos/msg/proto/new-turn.d.ts +5 -0
  99. package/dist/src/protos/msg/proto/pay-lpcost.d.ts +6 -0
  100. package/dist/src/protos/msg/proto/player-hint.d.ts +7 -0
  101. package/dist/src/protos/msg/proto/pos-change.d.ts +12 -0
  102. package/dist/src/protos/msg/proto/random-selected.d.ts +7 -0
  103. package/dist/src/protos/msg/proto/recover.d.ts +6 -0
  104. package/dist/src/protos/msg/proto/reload-field.d.ts +36 -0
  105. package/dist/src/protos/msg/proto/remove-counter.d.ts +9 -0
  106. package/dist/src/protos/msg/proto/reset-time.d.ts +6 -0
  107. package/dist/src/protos/msg/proto/retry.d.ts +4 -0
  108. package/dist/src/protos/msg/proto/reverse-deck.d.ts +4 -0
  109. package/dist/src/protos/msg/proto/rock-paper-scissors.d.ts +5 -0
  110. package/dist/src/protos/msg/proto/select-battlecmd.d.ts +25 -0
  111. package/dist/src/protos/msg/proto/select-card.d.ts +17 -0
  112. package/dist/src/protos/msg/proto/select-chain.d.ts +19 -0
  113. package/dist/src/protos/msg/proto/select-counter.d.ts +17 -0
  114. package/dist/src/protos/msg/proto/select-disfield.d.ts +7 -0
  115. package/dist/src/protos/msg/proto/select-effectyn.d.ts +11 -0
  116. package/dist/src/protos/msg/proto/select-idlecmd.d.ts +37 -0
  117. package/dist/src/protos/msg/proto/select-option.d.ts +7 -0
  118. package/dist/src/protos/msg/proto/select-place.d.ts +7 -0
  119. package/dist/src/protos/msg/proto/select-position.d.ts +7 -0
  120. package/dist/src/protos/msg/proto/select-sum.d.ts +20 -0
  121. package/dist/src/protos/msg/proto/select-tribute.d.ts +18 -0
  122. package/dist/src/protos/msg/proto/select-unselect-card.d.ts +20 -0
  123. package/dist/src/protos/msg/proto/select-yesno.d.ts +6 -0
  124. package/dist/src/protos/msg/proto/set.d.ts +5 -0
  125. package/dist/src/protos/msg/proto/shuffle-deck.d.ts +5 -0
  126. package/dist/src/protos/msg/proto/shuffle-extra.d.ts +8 -0
  127. package/dist/src/protos/msg/proto/shuffle-hand.d.ts +8 -0
  128. package/dist/src/protos/msg/proto/shuffle-set-card.d.ts +17 -0
  129. package/dist/src/protos/msg/proto/sort-card.d.ts +13 -0
  130. package/dist/src/protos/msg/proto/spsummoned.d.ts +4 -0
  131. package/dist/src/protos/msg/proto/spsummoning.d.ts +9 -0
  132. package/dist/src/protos/msg/proto/start.d.ts +14 -0
  133. package/dist/src/protos/msg/proto/summoned.d.ts +4 -0
  134. package/dist/src/protos/msg/proto/summoning.d.ts +9 -0
  135. package/dist/src/protos/msg/proto/swap-grave-deck.d.ts +5 -0
  136. package/dist/src/protos/msg/proto/swap.d.ts +12 -0
  137. package/dist/src/protos/msg/proto/tag-swap.d.ts +14 -0
  138. package/dist/src/protos/msg/proto/toss-coin.d.ts +7 -0
  139. package/dist/src/protos/msg/proto/toss-dice.d.ts +7 -0
  140. package/dist/src/protos/msg/proto/update-card.d.ts +14 -0
  141. package/dist/src/protos/msg/proto/update-data.d.ts +12 -0
  142. package/dist/src/protos/msg/proto/waiting.d.ts +4 -0
  143. package/dist/src/protos/msg/proto/win.d.ts +6 -0
  144. package/dist/src/protos/msg/registry.d.ts +3 -0
  145. package/dist/src/protos/stoc/base.d.ts +17 -0
  146. package/dist/src/protos/stoc/index.d.ts +3 -0
  147. package/dist/src/protos/stoc/proto/change-side.d.ts +4 -0
  148. package/dist/src/protos/stoc/proto/chat.d.ts +10 -0
  149. package/dist/src/protos/stoc/proto/create-game.d.ts +5 -0
  150. package/dist/src/protos/stoc/proto/deck-count.d.ts +5 -0
  151. package/dist/src/protos/stoc/proto/duel-end.d.ts +4 -0
  152. package/dist/src/protos/stoc/proto/duel-start.d.ts +4 -0
  153. package/dist/src/protos/stoc/proto/error-msg.d.ts +6 -0
  154. package/dist/src/protos/stoc/proto/field-finish.d.ts +4 -0
  155. package/dist/src/protos/stoc/proto/game-msg.d.ts +9 -0
  156. package/dist/src/protos/stoc/proto/hand-result.d.ts +6 -0
  157. package/dist/src/protos/stoc/proto/hs-player-change.d.ts +5 -0
  158. package/dist/src/protos/stoc/proto/hs-player-enter.d.ts +6 -0
  159. package/dist/src/protos/stoc/proto/hs-watch-change.d.ts +5 -0
  160. package/dist/src/protos/stoc/proto/index.d.ts +24 -0
  161. package/dist/src/protos/stoc/proto/join-game.d.ts +6 -0
  162. package/dist/src/protos/stoc/proto/leave-game.d.ts +5 -0
  163. package/dist/src/protos/stoc/proto/replay.d.ts +11 -0
  164. package/dist/src/protos/stoc/proto/select-hand.d.ts +4 -0
  165. package/dist/src/protos/stoc/proto/select-tp.d.ts +4 -0
  166. package/dist/src/protos/stoc/proto/srvpro-roomlist.d.ts +18 -0
  167. package/dist/src/protos/stoc/proto/teammate-surrender.d.ts +4 -0
  168. package/dist/src/protos/stoc/proto/time-limit.d.ts +6 -0
  169. package/dist/src/protos/stoc/proto/tp-result.d.ts +4 -0
  170. package/dist/src/protos/stoc/proto/type-change.d.ts +5 -0
  171. package/dist/src/protos/stoc/proto/waiting-side.d.ts +4 -0
  172. package/dist/src/protos/stoc/registry.d.ts +3 -0
  173. package/dist/src/vendor/ocgcore-constants.d.ts +360 -0
  174. package/dist/src/vendor/script-constants.d.ts +836 -0
  175. package/index.ts +6 -0
  176. package/package.json +74 -0
  177. package/scripts/gen-constants.js +156 -0
  178. package/tsconfig.json +20 -0
package/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './src/binary/binary-meta';
2
+ export * from './src/binary/fill-binary-fields';
3
+ export * from './src/protos/common';
4
+ export * from './src/protos/ctos';
5
+ export * from './src/protos/stoc';
6
+ export * from './src/protos/msg';
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "ygopro-msg-encode",
3
+ "description": "TS lib for encode / decode YGOPro proto",
4
+ "version": "1.0.1",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.cjs",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "lint": "eslint --fix .",
17
+ "build": "node build.js",
18
+ "build:cjs": "node build.js cjs",
19
+ "build:esm": "node build.js esm",
20
+ "build:types": "node build.js types",
21
+ "clean": "node build.js clean",
22
+ "test": "jest --passWithNoTests",
23
+ "start": "node dist/index.cjs",
24
+ "gen-constants": "node scripts/gen-constants.js"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/purerosefallen/ygopro-msg-encode.git"
29
+ },
30
+ "author": "Nanahira <nanahira@momobako.com>",
31
+ "license": "MIT",
32
+ "keywords": [],
33
+ "bugs": {
34
+ "url": "https://github.com/purerosefallen/ygopro-msg-encode/issues"
35
+ },
36
+ "homepage": "https://github.com/purerosefallen/ygopro-msg-encode",
37
+ "jest": {
38
+ "moduleFileExtensions": [
39
+ "js",
40
+ "json",
41
+ "ts"
42
+ ],
43
+ "rootDir": "tests",
44
+ "testRegex": ".*\\.spec\\.ts$",
45
+ "transform": {
46
+ "^.+\\.(t|j)s$": "ts-jest"
47
+ },
48
+ "collectCoverageFrom": [
49
+ "**/*.(t|j)s"
50
+ ],
51
+ "coverageDirectory": "../coverage",
52
+ "testEnvironment": "node"
53
+ },
54
+ "devDependencies": {
55
+ "@types/jest": "^30.0.0",
56
+ "@types/node": "^25.2.0",
57
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
58
+ "@typescript-eslint/parser": "^6.21.0",
59
+ "esbuild": "^0.27.2",
60
+ "esbuild-register": "^3.6.0",
61
+ "eslint": "8.22.0",
62
+ "eslint-config-prettier": "^9.1.2",
63
+ "eslint-plugin-prettier": "^5.5.5",
64
+ "jest": "^30.2.0",
65
+ "prettier": "^3.8.1",
66
+ "ts-jest": "^29.4.6",
67
+ "typescript": "^5.9.3"
68
+ },
69
+ "dependencies": {
70
+ "typed-reflector": "^1.0.14",
71
+ "ygopro-deck-encode": "^1.0.15",
72
+ "ygopro-yrp-encode": "^1.0.1"
73
+ }
74
+ }
@@ -0,0 +1,156 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const ROOT = path.resolve(__dirname, '..');
5
+ const COMMON_H = '/home/nanahira/ygo/ygopro/ocgcore/common.h';
6
+ const SCRIPT_CONSTANT_LUA = '/home/nanahira/ygo/ygopro/script/constant.lua';
7
+ const OUT_OCORE = path.join(ROOT, 'src', 'vendor', 'ocgcore-constants.ts');
8
+ const OUT_SCRIPT = path.join(ROOT, 'src', 'vendor', 'script-constants.ts');
9
+
10
+ function readFileSafe(file) {
11
+ try {
12
+ return fs.readFileSync(file, 'utf8');
13
+ } catch (err) {
14
+ console.error(`[gen-constants] Failed to read: ${file}`);
15
+ throw err;
16
+ }
17
+ }
18
+
19
+ function parseNumber(raw) {
20
+ const cleaned = raw.replace(/\s+/g, '');
21
+ if (/^0x[0-9a-fA-F]+$/.test(cleaned)) return Number.parseInt(cleaned, 16);
22
+ if (/^\d+$/.test(cleaned)) return Number.parseInt(cleaned, 10);
23
+ return null;
24
+ }
25
+
26
+ function sanitizeExpr(expr) {
27
+ return expr
28
+ .replace(/\/\/.*$/g, '')
29
+ .replace(/\/\*.*?\*\//g, '')
30
+ .replace(/\bU\b/g, '')
31
+ .replace(/\bUL\b/g, '')
32
+ .replace(/\bULL\b/g, '')
33
+ .replace(/\bL\b/g, '')
34
+ .replace(/\s+/g, '');
35
+ }
36
+
37
+ function evalExpr(expr, constants) {
38
+ const clean = sanitizeExpr(expr);
39
+ const tokens = clean
40
+ .replace(/<<|>>/g, (m) => ` ${m} `)
41
+ .split(/\s+/)
42
+ .filter(Boolean)
43
+ .flatMap((token) => token.split(/([+\-*/()|&~^<>])/).filter(Boolean));
44
+
45
+ const values = tokens.map((t) => {
46
+ if (
47
+ t === '+' ||
48
+ t === '-' ||
49
+ t === '*' ||
50
+ t === '/' ||
51
+ t === '(' ||
52
+ t === ')' ||
53
+ t === '|' ||
54
+ t === '&' ||
55
+ t === '~' ||
56
+ t === '^' ||
57
+ t === '<' ||
58
+ t === '>' ||
59
+ t === '<<' ||
60
+ t === '>>'
61
+ ) {
62
+ return t;
63
+ }
64
+ const num = parseNumber(t);
65
+ if (num !== null) return num;
66
+ if (Object.prototype.hasOwnProperty.call(constants, t)) return constants[t];
67
+ return NaN;
68
+ });
69
+
70
+ if (values.some((v) => Number.isNaN(v))) {
71
+ return null;
72
+ }
73
+
74
+ const exprStr = values.join('');
75
+ // eslint-disable-next-line no-new-func
76
+ return Function(`"use strict";return (${exprStr});`)();
77
+ }
78
+
79
+ function parseCDefines(source) {
80
+ const lines = source.split(/\r?\n/);
81
+ const constants = {};
82
+
83
+ for (const line of lines) {
84
+ const trimmed = line.trim();
85
+ if (!trimmed.startsWith('#define ')) continue;
86
+ const content = trimmed.slice('#define '.length).trim();
87
+ if (!content) continue;
88
+ const parts = content.split(/\s+/);
89
+ const name = parts.shift();
90
+ if (!name) continue;
91
+ if (name.includes('(')) continue; // macro with args
92
+ const valueRaw = parts.join(' ');
93
+ if (!valueRaw) continue;
94
+ const value = evalExpr(valueRaw, constants);
95
+ if (typeof value === 'number' && Number.isFinite(value)) {
96
+ constants[name] = value;
97
+ }
98
+ }
99
+
100
+ return constants;
101
+ }
102
+
103
+ function parseLuaConstants(source) {
104
+ const lines = source.split(/\r?\n/);
105
+ const constants = {};
106
+
107
+ for (const line of lines) {
108
+ const trimmed = line.trim();
109
+ if (!trimmed || trimmed.startsWith('--')) continue;
110
+ const match = /^([A-Z0-9_]+)\s*=\s*([^\-]+?)(?:\s+--.*)?$/.exec(trimmed);
111
+ if (!match) continue;
112
+ const name = match[1];
113
+ const valueRaw = match[2].trim();
114
+ const value = evalExpr(valueRaw, constants);
115
+ if (typeof value === 'number' && Number.isFinite(value)) {
116
+ constants[name] = value;
117
+ }
118
+ }
119
+
120
+ return constants;
121
+ }
122
+
123
+ function emitConstantsTs(objectName, constants, sourcePath) {
124
+ const keys = Object.keys(constants).sort();
125
+ const lines = [];
126
+ lines.push(`// Generated from ${sourcePath}`);
127
+ lines.push(`export const ${objectName} = {`);
128
+ for (const key of keys) {
129
+ const value = constants[key];
130
+ lines.push(` ${key}: ${value},`);
131
+ }
132
+ lines.push(`} as const;`);
133
+ lines.push('');
134
+ return lines.join('\n');
135
+ }
136
+
137
+ function writeFile(file, content) {
138
+ fs.mkdirSync(path.dirname(file), { recursive: true });
139
+ fs.writeFileSync(file, content, 'utf8');
140
+ }
141
+
142
+ function main() {
143
+ const commonSource = readFileSafe(COMMON_H);
144
+ const luaSource = readFileSafe(SCRIPT_CONSTANT_LUA);
145
+
146
+ const ocgcoreConstants = parseCDefines(commonSource);
147
+ const scriptConstants = parseLuaConstants(luaSource);
148
+
149
+ writeFile(OUT_OCORE, emitConstantsTs('OcgcoreCommonConstants', ocgcoreConstants, COMMON_H));
150
+ writeFile(OUT_SCRIPT, emitConstantsTs('OcgcoreScriptConstants', scriptConstants, SCRIPT_CONSTANT_LUA));
151
+
152
+ console.log(`[gen-constants] Wrote ${Object.keys(ocgcoreConstants).length} common.h constants`);
153
+ console.log(`[gen-constants] Wrote ${Object.keys(scriptConstants).length} constant.lua constants`);
154
+ }
155
+
156
+ main();
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "module": "commonjs",
5
+ "target": "es2021",
6
+ "esModuleInterop": true,
7
+ "emitDecoratorMetadata": true,
8
+ "experimentalDecorators": true,
9
+ "declaration": true,
10
+ "sourceMap": true
11
+ },
12
+ "compileOnSave": true,
13
+ "allowJs": true,
14
+ "include": [
15
+ "*.ts",
16
+ "src/**/*.ts",
17
+ "test/**/*.ts",
18
+ "tests/**/*.ts"
19
+ ]
20
+ }