koishipro-core.js 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/README.md +20 -14
- package/dist/index.cjs +411 -192
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +438 -228
- package/dist/index.mjs.map +4 -4
- package/dist/src/adapters/index.d.ts +0 -1
- package/dist/src/card-reader/dir-card-reader.d.ts +3 -0
- package/dist/src/card-reader/index.d.ts +2 -0
- package/dist/src/card-reader/sqljs-card-reader.d.ts +5 -0
- package/dist/src/ocgcore-duel.d.ts +2 -1
- package/dist/src/play-yrp.d.ts +11 -0
- package/dist/src/script-reader/dir-script-reader-ex.d.ts +2 -0
- package/dist/src/script-reader/index.d.ts +2 -0
- package/dist/src/script-reader/script-readers.d.ts +10 -0
- package/dist/src/utility/index.d.ts +1 -0
- package/dist/src/utility/node-fs.d.ts +11 -0
- package/dist/src/utility/search-zips.d.ts +6 -0
- package/index.ts +2 -1
- package/package.json +1 -1
- package/dist/src/adapters/script-readers.d.ts +0 -4
- package/dist/src/sqljs-card-reader.d.ts +0 -3
package/dist/index.cjs
CHANGED
|
@@ -38,12 +38,16 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
38
38
|
var index_exports = {};
|
|
39
39
|
__export(index_exports, {
|
|
40
40
|
CardDataStruct: () => CardDataStruct,
|
|
41
|
+
DirCardReader: () => DirCardReader,
|
|
41
42
|
DirReader: () => DirReader,
|
|
43
|
+
DirScriptReader: () => DirScriptReader,
|
|
44
|
+
DirScriptReaderEx: () => DirScriptReaderEx,
|
|
42
45
|
LEN_EMPTY: () => LEN_EMPTY,
|
|
43
46
|
LEN_FAIL: () => LEN_FAIL,
|
|
44
47
|
LEN_HEADER: () => LEN_HEADER,
|
|
45
48
|
MESSAGE_BUFFER_SIZE: () => MESSAGE_BUFFER_SIZE,
|
|
46
49
|
MapReader: () => MapReader,
|
|
50
|
+
MapScriptReader: () => MapScriptReader,
|
|
47
51
|
OcgcoreCommonConstants: () => OcgcoreCommonConstants,
|
|
48
52
|
OcgcoreDuel: () => OcgcoreDuel,
|
|
49
53
|
OcgcoreDuelOptionFlag: () => OcgcoreDuelOptionFlag,
|
|
@@ -53,7 +57,11 @@ __export(index_exports, {
|
|
|
53
57
|
OcgcoreWrapper: () => OcgcoreWrapper,
|
|
54
58
|
QUERY_BUFFER_SIZE: () => QUERY_BUFFER_SIZE,
|
|
55
59
|
REGISTRY_BUFFER_SIZE: () => REGISTRY_BUFFER_SIZE,
|
|
60
|
+
SqljsCardReader: () => SqljsCardReader,
|
|
56
61
|
ZipReader: () => ZipReader,
|
|
62
|
+
ZipScriptReader: () => ZipScriptReader,
|
|
63
|
+
consumeResponseFromOcgcoreProcess: () => consumeResponseFromOcgcoreProcess,
|
|
64
|
+
createDuelFromYrp: () => createDuelFromYrp,
|
|
57
65
|
createOcgcoreWrapper: () => createOcgcoreWrapper,
|
|
58
66
|
createSqljsCardReader: () => createSqljsCardReader,
|
|
59
67
|
normalizeStartDuelOptions: () => normalizeStartDuelOptions,
|
|
@@ -64,6 +72,7 @@ __export(index_exports, {
|
|
|
64
72
|
parseRegistryKeys: () => parseRegistryKeys,
|
|
65
73
|
playYrp: () => playYrp,
|
|
66
74
|
playYrpStep: () => playYrpStep,
|
|
75
|
+
processYrpDuelStep: () => processYrpDuelStep,
|
|
67
76
|
testCard: () => testCard
|
|
68
77
|
});
|
|
69
78
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -556,6 +565,7 @@ var OcgcoreDuel = class {
|
|
|
556
565
|
this.duelPtr = duelPtr;
|
|
557
566
|
this.returnPtr = 0;
|
|
558
567
|
this.returnSize = 512;
|
|
568
|
+
this.ended = false;
|
|
559
569
|
}
|
|
560
570
|
startDuel(options) {
|
|
561
571
|
if (!this.returnPtr) {
|
|
@@ -565,6 +575,8 @@ var OcgcoreDuel = class {
|
|
|
565
575
|
this.ocgcoreWrapper.ocgcoreModule._start_duel(this.duelPtr, optionValue);
|
|
566
576
|
}
|
|
567
577
|
endDuel() {
|
|
578
|
+
if (this.ended) return;
|
|
579
|
+
this.ended = true;
|
|
568
580
|
this.ocgcoreWrapper.ocgcoreModule._end_duel(this.duelPtr);
|
|
569
581
|
if (this.returnPtr) {
|
|
570
582
|
this.ocgcoreWrapper.free(this.returnPtr);
|
|
@@ -685,6 +697,10 @@ var OcgcoreDuel = class {
|
|
|
685
697
|
this.ocgcoreWrapper.ocgcoreModule._set_responsei(this.duelPtr, value);
|
|
686
698
|
}
|
|
687
699
|
setResponse(response) {
|
|
700
|
+
if (typeof response === "number") {
|
|
701
|
+
this.setResponseInt(response);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
688
704
|
if (response.length > this.returnSize) {
|
|
689
705
|
this.ocgcoreWrapper.free(this.returnPtr);
|
|
690
706
|
this.returnPtr = this.ocgcoreWrapper.malloc(response.length);
|
|
@@ -1212,114 +1228,6 @@ async function createOcgcoreWrapper(options = {}) {
|
|
|
1212
1228
|
return new OcgcoreWrapper(moduleInstance);
|
|
1213
1229
|
}
|
|
1214
1230
|
|
|
1215
|
-
// src/adapters/script-readers.ts
|
|
1216
|
-
var import_jszip = __toESM(require("jszip"));
|
|
1217
|
-
var SCRIPT_PREFIX = "./script/";
|
|
1218
|
-
function normalizePath(input) {
|
|
1219
|
-
let path = input.replace(/\\/g, "/");
|
|
1220
|
-
if (path.startsWith(SCRIPT_PREFIX)) {
|
|
1221
|
-
path = path.slice(SCRIPT_PREFIX.length);
|
|
1222
|
-
}
|
|
1223
|
-
return path;
|
|
1224
|
-
}
|
|
1225
|
-
function buildCandidates(filename) {
|
|
1226
|
-
const entries = [
|
|
1227
|
-
filename,
|
|
1228
|
-
`specials/${filename}`,
|
|
1229
|
-
`expansions/script/${filename}`,
|
|
1230
|
-
`script/${filename}`
|
|
1231
|
-
];
|
|
1232
|
-
const candidates = [];
|
|
1233
|
-
for (const entry of entries) {
|
|
1234
|
-
candidates.push(entry);
|
|
1235
|
-
if (!entry.startsWith("./")) {
|
|
1236
|
-
const dotEntry = entry.startsWith("/") ? `./${entry.slice(1)}` : `./${entry}`;
|
|
1237
|
-
candidates.push(dotEntry);
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
return candidates;
|
|
1241
|
-
}
|
|
1242
|
-
function joinPath(baseDir, relativePath) {
|
|
1243
|
-
const pathMod = getNodePath();
|
|
1244
|
-
if (pathMod) {
|
|
1245
|
-
return pathMod.join(baseDir, relativePath);
|
|
1246
|
-
}
|
|
1247
|
-
const trimmedBase = baseDir.replace(/[/\\]+$/, "");
|
|
1248
|
-
const trimmedRel = relativePath.replace(/^[/\\]+/, "");
|
|
1249
|
-
return `${trimmedBase}/${trimmedRel}`;
|
|
1250
|
-
}
|
|
1251
|
-
function MapReader(...maps) {
|
|
1252
|
-
return (path) => {
|
|
1253
|
-
const filename = normalizePath(path);
|
|
1254
|
-
if (!filename.toLowerCase().endsWith(".lua")) {
|
|
1255
|
-
return null;
|
|
1256
|
-
}
|
|
1257
|
-
const candidates = buildCandidates(filename);
|
|
1258
|
-
for (const candidate of candidates) {
|
|
1259
|
-
for (const map of maps) {
|
|
1260
|
-
if (map.has(candidate)) {
|
|
1261
|
-
return map.get(candidate) ?? null;
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
return null;
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
function DirReader(...baseDirs) {
|
|
1269
|
-
const fs = getNodeFs();
|
|
1270
|
-
return (path) => {
|
|
1271
|
-
const filename = normalizePath(path);
|
|
1272
|
-
if (!filename.toLowerCase().endsWith(".lua")) {
|
|
1273
|
-
return null;
|
|
1274
|
-
}
|
|
1275
|
-
const candidates = buildCandidates(filename);
|
|
1276
|
-
for (const baseDir of baseDirs) {
|
|
1277
|
-
for (const candidate of candidates) {
|
|
1278
|
-
const normalized = candidate.startsWith("/") ? candidate.slice(1) : candidate;
|
|
1279
|
-
const fullPath = joinPath(baseDir, normalized);
|
|
1280
|
-
if (fs.existsSync(fullPath)) {
|
|
1281
|
-
return fs.readFileSync(fullPath);
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
return null;
|
|
1286
|
-
};
|
|
1287
|
-
}
|
|
1288
|
-
function normalizeZipEntryName(name) {
|
|
1289
|
-
const normalized = name.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
1290
|
-
const names = /* @__PURE__ */ new Set();
|
|
1291
|
-
names.add(normalized);
|
|
1292
|
-
if (normalized.startsWith("script/")) {
|
|
1293
|
-
names.add(normalized.slice("script/".length));
|
|
1294
|
-
}
|
|
1295
|
-
return Array.from(names);
|
|
1296
|
-
}
|
|
1297
|
-
async function ZipReader(...inputs) {
|
|
1298
|
-
const maps = await Promise.all(
|
|
1299
|
-
inputs.map(async (data) => {
|
|
1300
|
-
const zip = await import_jszip.default.loadAsync(data);
|
|
1301
|
-
const map = /* @__PURE__ */ new Map();
|
|
1302
|
-
const entries = Object.values(zip.files);
|
|
1303
|
-
await Promise.all(
|
|
1304
|
-
entries.map(async (entry) => {
|
|
1305
|
-
if (entry.dir) {
|
|
1306
|
-
return;
|
|
1307
|
-
}
|
|
1308
|
-
if (!entry.name.toLowerCase().endsWith(".lua")) {
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1311
|
-
const content = await entry.async("uint8array");
|
|
1312
|
-
for (const name of normalizeZipEntryName(entry.name)) {
|
|
1313
|
-
map.set(name, content);
|
|
1314
|
-
}
|
|
1315
|
-
})
|
|
1316
|
-
);
|
|
1317
|
-
return map;
|
|
1318
|
-
})
|
|
1319
|
-
);
|
|
1320
|
-
return MapReader(...maps);
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
1231
|
// src/vendor/script-constants.ts
|
|
1324
1232
|
var OcgcoreScriptConstants = {
|
|
1325
1233
|
ACTIVITY_ATTACK: 5,
|
|
@@ -2158,7 +2066,207 @@ var OcgcoreScriptConstants = {
|
|
|
2158
2066
|
TYPE_XYZ: 8388608
|
|
2159
2067
|
};
|
|
2160
2068
|
|
|
2161
|
-
// src/
|
|
2069
|
+
// src/script-reader/script-readers.ts
|
|
2070
|
+
var import_jszip = __toESM(require("jszip"));
|
|
2071
|
+
var SCRIPT_PREFIX = "./script/";
|
|
2072
|
+
function normalizePath(input) {
|
|
2073
|
+
let path = input.replace(/\\/g, "/");
|
|
2074
|
+
if (path.startsWith(SCRIPT_PREFIX)) {
|
|
2075
|
+
path = path.slice(SCRIPT_PREFIX.length);
|
|
2076
|
+
}
|
|
2077
|
+
return path;
|
|
2078
|
+
}
|
|
2079
|
+
function buildCandidates(filename) {
|
|
2080
|
+
const entries = [
|
|
2081
|
+
filename,
|
|
2082
|
+
`specials/${filename}`,
|
|
2083
|
+
`expansions/script/${filename}`,
|
|
2084
|
+
`script/${filename}`
|
|
2085
|
+
];
|
|
2086
|
+
const candidates = [];
|
|
2087
|
+
for (const entry of entries) {
|
|
2088
|
+
candidates.push(entry);
|
|
2089
|
+
if (!entry.startsWith("./")) {
|
|
2090
|
+
const dotEntry = entry.startsWith("/") ? `./${entry.slice(1)}` : `./${entry}`;
|
|
2091
|
+
candidates.push(dotEntry);
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
return candidates;
|
|
2095
|
+
}
|
|
2096
|
+
function joinPath(baseDir, relativePath) {
|
|
2097
|
+
const pathMod = getNodePath();
|
|
2098
|
+
if (pathMod) {
|
|
2099
|
+
return pathMod.join(baseDir, relativePath);
|
|
2100
|
+
}
|
|
2101
|
+
const trimmedBase = baseDir.replace(/[/\\]+$/, "");
|
|
2102
|
+
const trimmedRel = relativePath.replace(/^[/\\]+/, "");
|
|
2103
|
+
return `${trimmedBase}/${trimmedRel}`;
|
|
2104
|
+
}
|
|
2105
|
+
function MapScriptReader(...maps) {
|
|
2106
|
+
return (path) => {
|
|
2107
|
+
const filename = normalizePath(path);
|
|
2108
|
+
if (!filename.toLowerCase().endsWith(".lua")) {
|
|
2109
|
+
return null;
|
|
2110
|
+
}
|
|
2111
|
+
const candidates = buildCandidates(filename);
|
|
2112
|
+
for (const candidate of candidates) {
|
|
2113
|
+
for (const map of maps) {
|
|
2114
|
+
if (map.has(candidate)) {
|
|
2115
|
+
return map.get(candidate) ?? null;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
return null;
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
function DirScriptReader(...baseDirs) {
|
|
2123
|
+
const fs = getNodeFs();
|
|
2124
|
+
return (path) => {
|
|
2125
|
+
const filename = normalizePath(path);
|
|
2126
|
+
if (!filename.toLowerCase().endsWith(".lua")) {
|
|
2127
|
+
return null;
|
|
2128
|
+
}
|
|
2129
|
+
const candidates = buildCandidates(filename);
|
|
2130
|
+
for (const baseDir of baseDirs) {
|
|
2131
|
+
for (const candidate of candidates) {
|
|
2132
|
+
const normalized = candidate.startsWith("/") ? candidate.slice(1) : candidate;
|
|
2133
|
+
const fullPath = joinPath(baseDir, normalized);
|
|
2134
|
+
if (fs.existsSync(fullPath)) {
|
|
2135
|
+
return fs.readFileSync(fullPath);
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
return null;
|
|
2140
|
+
};
|
|
2141
|
+
}
|
|
2142
|
+
function normalizeZipEntryName(name) {
|
|
2143
|
+
const normalized = name.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
2144
|
+
const names = /* @__PURE__ */ new Set();
|
|
2145
|
+
names.add(normalized);
|
|
2146
|
+
if (normalized.startsWith("script/")) {
|
|
2147
|
+
names.add(normalized.slice("script/".length));
|
|
2148
|
+
}
|
|
2149
|
+
return Array.from(names);
|
|
2150
|
+
}
|
|
2151
|
+
async function ZipScriptReader(...inputs) {
|
|
2152
|
+
const maps = await Promise.all(
|
|
2153
|
+
inputs.map(async (data) => {
|
|
2154
|
+
const zip = await import_jszip.default.loadAsync(data);
|
|
2155
|
+
const map = /* @__PURE__ */ new Map();
|
|
2156
|
+
const entries = Object.values(zip.files);
|
|
2157
|
+
await Promise.all(
|
|
2158
|
+
entries.map(async (entry) => {
|
|
2159
|
+
if (entry.dir) {
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2162
|
+
if (!entry.name.toLowerCase().endsWith(".lua")) {
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
const content = await entry.async("uint8array");
|
|
2166
|
+
for (const name of normalizeZipEntryName(entry.name)) {
|
|
2167
|
+
map.set(name, content);
|
|
2168
|
+
}
|
|
2169
|
+
})
|
|
2170
|
+
);
|
|
2171
|
+
return map;
|
|
2172
|
+
})
|
|
2173
|
+
);
|
|
2174
|
+
return MapScriptReader(...maps);
|
|
2175
|
+
}
|
|
2176
|
+
function MapReader(...maps) {
|
|
2177
|
+
return MapScriptReader(...maps);
|
|
2178
|
+
}
|
|
2179
|
+
function DirReader(...baseDirs) {
|
|
2180
|
+
return DirScriptReader(...baseDirs);
|
|
2181
|
+
}
|
|
2182
|
+
async function ZipReader(...inputs) {
|
|
2183
|
+
return ZipScriptReader(...inputs);
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
// src/utility/search-zips.ts
|
|
2187
|
+
function joinPath2(pathMod, baseDir, rel) {
|
|
2188
|
+
if (pathMod) {
|
|
2189
|
+
return pathMod.join(baseDir, rel);
|
|
2190
|
+
}
|
|
2191
|
+
const trimmedBase = baseDir.replace(/[/\\]+$/, "");
|
|
2192
|
+
const trimmedRel = rel.replace(/^[/\\]+/, "");
|
|
2193
|
+
return `${trimmedBase}/${trimmedRel}`;
|
|
2194
|
+
}
|
|
2195
|
+
async function safeReadDir(fs, dirPath) {
|
|
2196
|
+
try {
|
|
2197
|
+
return await fs.promises.readdir(dirPath);
|
|
2198
|
+
} catch {
|
|
2199
|
+
return [];
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
async function searchZips(fs, pathMod, baseDir) {
|
|
2203
|
+
const results = [];
|
|
2204
|
+
const rootEntries = await safeReadDir(fs, baseDir);
|
|
2205
|
+
for (const entry of rootEntries) {
|
|
2206
|
+
const lower = entry.toLowerCase();
|
|
2207
|
+
if (!lower.endsWith(".zip") && !lower.endsWith(".ypk")) {
|
|
2208
|
+
continue;
|
|
2209
|
+
}
|
|
2210
|
+
const fullPath = joinPath2(pathMod, baseDir, entry);
|
|
2211
|
+
try {
|
|
2212
|
+
const stats = await fs.promises.stat(fullPath);
|
|
2213
|
+
if (stats.isFile()) {
|
|
2214
|
+
results.push(fullPath);
|
|
2215
|
+
}
|
|
2216
|
+
} catch {
|
|
2217
|
+
continue;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
const expansionsDir = joinPath2(pathMod, baseDir, "expansions");
|
|
2221
|
+
const expansionEntries = await safeReadDir(fs, expansionsDir);
|
|
2222
|
+
for (const entry of expansionEntries) {
|
|
2223
|
+
const lower = entry.toLowerCase();
|
|
2224
|
+
if (!lower.endsWith(".zip") && !lower.endsWith(".ypk")) {
|
|
2225
|
+
continue;
|
|
2226
|
+
}
|
|
2227
|
+
const fullPath = joinPath2(pathMod, expansionsDir, entry);
|
|
2228
|
+
try {
|
|
2229
|
+
const stats = await fs.promises.stat(fullPath);
|
|
2230
|
+
if (stats.isFile()) {
|
|
2231
|
+
results.push(fullPath);
|
|
2232
|
+
}
|
|
2233
|
+
} catch {
|
|
2234
|
+
continue;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
return results;
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
// src/script-reader/dir-script-reader-ex.ts
|
|
2241
|
+
function getNodeModuleOrThrow(value, label) {
|
|
2242
|
+
if (!value) {
|
|
2243
|
+
throw new Error(`${label} is not supported in this runtime.`);
|
|
2244
|
+
}
|
|
2245
|
+
return value;
|
|
2246
|
+
}
|
|
2247
|
+
async function DirScriptReaderEx(...baseDirs) {
|
|
2248
|
+
const fs = getNodeModuleOrThrow(getNodeFs(), "DirScriptReaderEx");
|
|
2249
|
+
const pathMod = getNodeModuleOrThrow(getNodePath(), "DirScriptReaderEx");
|
|
2250
|
+
const fsReader = DirScriptReader(...baseDirs);
|
|
2251
|
+
const zipInputs = [];
|
|
2252
|
+
for (const baseDir of baseDirs) {
|
|
2253
|
+
const zipPaths = await searchZips(fs, pathMod, baseDir);
|
|
2254
|
+
for (const zipPath of zipPaths) {
|
|
2255
|
+
try {
|
|
2256
|
+
zipInputs.push(await fs.promises.readFile(zipPath));
|
|
2257
|
+
} catch {
|
|
2258
|
+
continue;
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
if (zipInputs.length === 0) {
|
|
2263
|
+
return fsReader;
|
|
2264
|
+
}
|
|
2265
|
+
const zipReader = await ZipScriptReader(...zipInputs);
|
|
2266
|
+
return (path) => fsReader(path) ?? zipReader(path);
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
// src/card-reader/sqljs-card-reader.ts
|
|
2162
2270
|
function toUint16ArrayFromSetcode(value) {
|
|
2163
2271
|
let raw = typeof value === "bigint" ? value : BigInt(value >>> 0);
|
|
2164
2272
|
const list = new Uint16Array(16);
|
|
@@ -2239,7 +2347,7 @@ function queryOne(db, cardId) {
|
|
|
2239
2347
|
attribute: row[8]
|
|
2240
2348
|
});
|
|
2241
2349
|
}
|
|
2242
|
-
function
|
|
2350
|
+
function SqljsCardReader(...dbs) {
|
|
2243
2351
|
return (cardId) => {
|
|
2244
2352
|
for (const db of dbs) {
|
|
2245
2353
|
const data = queryOne(db, cardId);
|
|
@@ -2250,6 +2358,105 @@ function createSqljsCardReader(...dbs) {
|
|
|
2250
2358
|
return null;
|
|
2251
2359
|
};
|
|
2252
2360
|
}
|
|
2361
|
+
function createSqljsCardReader(...dbs) {
|
|
2362
|
+
return SqljsCardReader(...dbs);
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
// src/card-reader/dir-card-reader.ts
|
|
2366
|
+
var import_jszip2 = __toESM(require("jszip"));
|
|
2367
|
+
function joinPath3(pathMod, baseDir, rel) {
|
|
2368
|
+
if (pathMod) {
|
|
2369
|
+
return pathMod.join(baseDir, rel);
|
|
2370
|
+
}
|
|
2371
|
+
const trimmedBase = baseDir.replace(/[/\\]+$/, "");
|
|
2372
|
+
const trimmedRel = rel.replace(/^[/\\]+/, "");
|
|
2373
|
+
return `${trimmedBase}/${trimmedRel}`;
|
|
2374
|
+
}
|
|
2375
|
+
function getNodeModuleOrThrow2(value, label) {
|
|
2376
|
+
if (!value) {
|
|
2377
|
+
throw new Error(`${label} is not supported in this runtime.`);
|
|
2378
|
+
}
|
|
2379
|
+
return value;
|
|
2380
|
+
}
|
|
2381
|
+
async function safeReadDir2(fs, dirPath) {
|
|
2382
|
+
try {
|
|
2383
|
+
return await fs.promises.readdir(dirPath);
|
|
2384
|
+
} catch {
|
|
2385
|
+
return [];
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
async function collectFsDbPaths(fs, pathMod, baseDir) {
|
|
2389
|
+
const results = [];
|
|
2390
|
+
const baseDb = joinPath3(pathMod, baseDir, "cards.cdb");
|
|
2391
|
+
try {
|
|
2392
|
+
const stats = await fs.promises.stat(baseDb);
|
|
2393
|
+
if (stats.isFile()) {
|
|
2394
|
+
results.push(baseDb);
|
|
2395
|
+
}
|
|
2396
|
+
} catch {
|
|
2397
|
+
}
|
|
2398
|
+
const expansionsDir = joinPath3(pathMod, baseDir, "expansions");
|
|
2399
|
+
const entries = await safeReadDir2(fs, expansionsDir);
|
|
2400
|
+
for (const entry of entries) {
|
|
2401
|
+
if (!entry.toLowerCase().endsWith(".cdb")) {
|
|
2402
|
+
continue;
|
|
2403
|
+
}
|
|
2404
|
+
const fullPath = joinPath3(pathMod, expansionsDir, entry);
|
|
2405
|
+
try {
|
|
2406
|
+
const stats = await fs.promises.stat(fullPath);
|
|
2407
|
+
if (stats.isFile()) {
|
|
2408
|
+
results.push(fullPath);
|
|
2409
|
+
}
|
|
2410
|
+
} catch {
|
|
2411
|
+
continue;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
return results;
|
|
2415
|
+
}
|
|
2416
|
+
function isRootCdbEntry(entryName) {
|
|
2417
|
+
const normalized = entryName.replace(/\\/g, "/").replace(/^\.?\//, "");
|
|
2418
|
+
return !normalized.includes("/") && normalized.toLowerCase().endsWith(".cdb");
|
|
2419
|
+
}
|
|
2420
|
+
async function DirCardReader(sqljs, ...baseDirs) {
|
|
2421
|
+
const fs = getNodeModuleOrThrow2(getNodeFs(), "DirCardReader");
|
|
2422
|
+
const pathMod = getNodeModuleOrThrow2(getNodePath(), "DirCardReader");
|
|
2423
|
+
const dbs = [];
|
|
2424
|
+
for (const baseDir of baseDirs) {
|
|
2425
|
+
const dbPaths = await collectFsDbPaths(fs, pathMod, baseDir);
|
|
2426
|
+
for (const dbPath of dbPaths) {
|
|
2427
|
+
try {
|
|
2428
|
+
const bytes = await fs.promises.readFile(dbPath);
|
|
2429
|
+
dbs.push(new sqljs.Database(bytes));
|
|
2430
|
+
} catch {
|
|
2431
|
+
continue;
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
for (const baseDir of baseDirs) {
|
|
2436
|
+
const zipPaths = await searchZips(fs, pathMod, baseDir);
|
|
2437
|
+
for (const zipPath of zipPaths) {
|
|
2438
|
+
try {
|
|
2439
|
+
const bytes = await fs.promises.readFile(zipPath);
|
|
2440
|
+
const zip = await import_jszip2.default.loadAsync(bytes);
|
|
2441
|
+
const entries = Object.values(zip.files);
|
|
2442
|
+
for (const entry of entries) {
|
|
2443
|
+
if (entry.dir || !isRootCdbEntry(entry.name)) {
|
|
2444
|
+
continue;
|
|
2445
|
+
}
|
|
2446
|
+
try {
|
|
2447
|
+
const content = await entry.async("uint8array");
|
|
2448
|
+
dbs.push(new sqljs.Database(content));
|
|
2449
|
+
} catch {
|
|
2450
|
+
continue;
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
} catch {
|
|
2454
|
+
continue;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
return SqljsCardReader(...dbs);
|
|
2459
|
+
}
|
|
2253
2460
|
|
|
2254
2461
|
// src/play-yrp.ts
|
|
2255
2462
|
var import_ygopro_yrp_encode = require("ygopro-yrp-encode");
|
|
@@ -2260,14 +2467,6 @@ function normalizeYrp(input) {
|
|
|
2260
2467
|
}
|
|
2261
2468
|
return new import_ygopro_yrp_encode.YGOProYrp().fromYrp(input);
|
|
2262
2469
|
}
|
|
2263
|
-
function createReplayDuel(wrapper, yrp) {
|
|
2264
|
-
const header = yrp.header;
|
|
2265
|
-
const seedSequence = header?.seedSequence ?? [];
|
|
2266
|
-
if (seedSequence.length > 0) {
|
|
2267
|
-
return wrapper.createDuelV2(seedSequence);
|
|
2268
|
-
}
|
|
2269
|
-
return wrapper.createDuel(header?.seed ?? 0);
|
|
2270
|
-
}
|
|
2271
2470
|
function loadDeck(duel, deck, owner, player) {
|
|
2272
2471
|
if (!deck) return;
|
|
2273
2472
|
for (const code of deck.main ?? []) {
|
|
@@ -2311,86 +2510,97 @@ function loadTagDeck(duel, deck, owner) {
|
|
|
2311
2510
|
function setRegistryValue(duel, key, value) {
|
|
2312
2511
|
duel.setRegistryValue(key, value);
|
|
2313
2512
|
}
|
|
2314
|
-
function
|
|
2513
|
+
function createDuelFromYrp(wrapper, yrpInput) {
|
|
2315
2514
|
const yrp = normalizeYrp(yrpInput);
|
|
2316
|
-
const
|
|
2317
|
-
const
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2515
|
+
const header = yrp.header;
|
|
2516
|
+
const seedSequence = header?.seedSequence ?? [];
|
|
2517
|
+
const duel = seedSequence.length > 0 ? wrapper.createDuelV2(seedSequence) : wrapper.createDuel(header?.seed ?? 0);
|
|
2518
|
+
setRegistryValue(duel, "duel_mode", yrp.isTag ? "tag" : "single");
|
|
2519
|
+
setRegistryValue(duel, "start_lp", String(yrp.startLp));
|
|
2520
|
+
setRegistryValue(duel, "start_hand", String(yrp.startHand));
|
|
2521
|
+
setRegistryValue(duel, "draw_count", String(yrp.drawCount));
|
|
2522
|
+
const playerNames = yrp.isTag ? [
|
|
2523
|
+
yrp.hostName,
|
|
2524
|
+
yrp.tagHostName ?? "",
|
|
2525
|
+
yrp.tagClientName ?? "",
|
|
2526
|
+
yrp.clientName
|
|
2527
|
+
] : [yrp.hostName, yrp.clientName];
|
|
2528
|
+
for (let i = 0; i < playerNames.length; i++) {
|
|
2529
|
+
setRegistryValue(duel, `player_name_${i}`, playerNames[i] ?? "");
|
|
2530
|
+
}
|
|
2531
|
+
setRegistryValue(duel, "player_type_0", "0");
|
|
2532
|
+
setRegistryValue(duel, "player_type_1", "1");
|
|
2533
|
+
duel.setPlayerInfo({
|
|
2534
|
+
player: 0,
|
|
2535
|
+
lp: yrp.startLp,
|
|
2536
|
+
startHand: yrp.startHand,
|
|
2537
|
+
drawCount: yrp.drawCount
|
|
2538
|
+
});
|
|
2539
|
+
duel.setPlayerInfo({
|
|
2540
|
+
player: 1,
|
|
2541
|
+
lp: yrp.startLp,
|
|
2542
|
+
startHand: yrp.startHand,
|
|
2543
|
+
drawCount: yrp.drawCount
|
|
2544
|
+
});
|
|
2545
|
+
duel.preloadScript("./script/patches/entry.lua");
|
|
2546
|
+
duel.preloadScript("./script/special.lua");
|
|
2547
|
+
duel.preloadScript("./script/init.lua");
|
|
2548
|
+
if (yrp.isSingleMode && yrp.singleScript) {
|
|
2549
|
+
duel.preloadScript(`./single/${yrp.singleScript}`);
|
|
2550
|
+
} else if (yrp.isTag) {
|
|
2551
|
+
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2552
|
+
loadTagDeck(duel, yrp.tagHostDeck, 0);
|
|
2553
|
+
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2554
|
+
loadTagDeck(duel, yrp.tagClientDeck, 1);
|
|
2555
|
+
} else {
|
|
2556
|
+
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2557
|
+
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2558
|
+
}
|
|
2559
|
+
duel.startDuel(yrp.opt >>> 0);
|
|
2560
|
+
return { yrp, duel };
|
|
2561
|
+
}
|
|
2562
|
+
function consumeResponseFromOcgcoreProcess(duel, result, responses) {
|
|
2563
|
+
if (result.raw.length > 0 && result.raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
|
|
2564
|
+
throw new Error("Got MSG_RETRY");
|
|
2565
|
+
}
|
|
2566
|
+
if (result.status === 0) {
|
|
2567
|
+
return false;
|
|
2568
|
+
}
|
|
2569
|
+
if (result.status === 1) {
|
|
2570
|
+
if (result.raw.length === 0) {
|
|
2571
|
+
return false;
|
|
2337
2572
|
}
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
player: 0,
|
|
2342
|
-
lp: yrp.startLp,
|
|
2343
|
-
startHand: yrp.startHand,
|
|
2344
|
-
drawCount: yrp.drawCount
|
|
2345
|
-
});
|
|
2346
|
-
duel.setPlayerInfo({
|
|
2347
|
-
player: 1,
|
|
2348
|
-
lp: yrp.startLp,
|
|
2349
|
-
startHand: yrp.startHand,
|
|
2350
|
-
drawCount: yrp.drawCount
|
|
2351
|
-
});
|
|
2352
|
-
duel.preloadScript("./script/patches/entry.lua");
|
|
2353
|
-
duel.preloadScript("./script/special.lua");
|
|
2354
|
-
duel.preloadScript("./script/init.lua");
|
|
2355
|
-
if (yrp.isSingleMode && yrp.singleScript) {
|
|
2356
|
-
duel.preloadScript(`./single/${yrp.singleScript}`);
|
|
2357
|
-
} else if (yrp.isTag) {
|
|
2358
|
-
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2359
|
-
loadTagDeck(duel, yrp.tagHostDeck, 0);
|
|
2360
|
-
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2361
|
-
loadTagDeck(duel, yrp.tagClientDeck, 1);
|
|
2362
|
-
} else {
|
|
2363
|
-
loadDeck(duel, yrp.hostDeck, 0, 0);
|
|
2364
|
-
loadDeck(duel, yrp.clientDeck, 1, 1);
|
|
2573
|
+
const response = responses.shift();
|
|
2574
|
+
if (!response) {
|
|
2575
|
+
return true;
|
|
2365
2576
|
}
|
|
2366
|
-
duel.
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
continue;
|
|
2382
|
-
}
|
|
2383
|
-
const response = responses.shift();
|
|
2384
|
-
if (!response) {
|
|
2385
|
-
break;
|
|
2386
|
-
}
|
|
2387
|
-
duel.setResponse(response);
|
|
2388
|
-
continue;
|
|
2389
|
-
}
|
|
2577
|
+
duel.setResponse(response);
|
|
2578
|
+
return false;
|
|
2579
|
+
}
|
|
2580
|
+
return true;
|
|
2581
|
+
}
|
|
2582
|
+
function* processYrpDuelStep(duel, yrp) {
|
|
2583
|
+
const responses = yrp.responses.slice();
|
|
2584
|
+
while (true) {
|
|
2585
|
+
const result = duel.process();
|
|
2586
|
+
yield {
|
|
2587
|
+
duel,
|
|
2588
|
+
result,
|
|
2589
|
+
responses
|
|
2590
|
+
};
|
|
2591
|
+
if (consumeResponseFromOcgcoreProcess(duel, result, responses)) {
|
|
2390
2592
|
break;
|
|
2391
2593
|
}
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
function* playYrpStep(ocgcoreWrapper, yrpInput) {
|
|
2597
|
+
const { yrp, duel } = createDuelFromYrp(ocgcoreWrapper, yrpInput);
|
|
2598
|
+
try {
|
|
2599
|
+
for (const stepResult of processYrpDuelStep(duel, yrp)) {
|
|
2600
|
+
yield stepResult;
|
|
2601
|
+
}
|
|
2392
2602
|
} finally {
|
|
2393
|
-
endDuel();
|
|
2603
|
+
duel.endDuel();
|
|
2394
2604
|
}
|
|
2395
2605
|
}
|
|
2396
2606
|
var playYrp = (ocgcoreWrapper, yrpInput) => {
|
|
@@ -2451,12 +2661,16 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
2451
2661
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2452
2662
|
0 && (module.exports = {
|
|
2453
2663
|
CardDataStruct,
|
|
2664
|
+
DirCardReader,
|
|
2454
2665
|
DirReader,
|
|
2666
|
+
DirScriptReader,
|
|
2667
|
+
DirScriptReaderEx,
|
|
2455
2668
|
LEN_EMPTY,
|
|
2456
2669
|
LEN_FAIL,
|
|
2457
2670
|
LEN_HEADER,
|
|
2458
2671
|
MESSAGE_BUFFER_SIZE,
|
|
2459
2672
|
MapReader,
|
|
2673
|
+
MapScriptReader,
|
|
2460
2674
|
OcgcoreCommonConstants,
|
|
2461
2675
|
OcgcoreDuel,
|
|
2462
2676
|
OcgcoreDuelOptionFlag,
|
|
@@ -2466,7 +2680,11 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
2466
2680
|
OcgcoreWrapper,
|
|
2467
2681
|
QUERY_BUFFER_SIZE,
|
|
2468
2682
|
REGISTRY_BUFFER_SIZE,
|
|
2683
|
+
SqljsCardReader,
|
|
2469
2684
|
ZipReader,
|
|
2685
|
+
ZipScriptReader,
|
|
2686
|
+
consumeResponseFromOcgcoreProcess,
|
|
2687
|
+
createDuelFromYrp,
|
|
2470
2688
|
createOcgcoreWrapper,
|
|
2471
2689
|
createSqljsCardReader,
|
|
2472
2690
|
normalizeStartDuelOptions,
|
|
@@ -2477,6 +2695,7 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
2477
2695
|
parseRegistryKeys,
|
|
2478
2696
|
playYrp,
|
|
2479
2697
|
playYrpStep,
|
|
2698
|
+
processYrpDuelStep,
|
|
2480
2699
|
testCard
|
|
2481
2700
|
});
|
|
2482
2701
|
//# sourceMappingURL=index.cjs.map
|