@tsukilabs/nil-ffi 0.7.0

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.js ADDED
@@ -0,0 +1,741 @@
1
+ import * as ffi from "node:ffi";
2
+ import { isNil } from "es-toolkit/predicate";
3
+ import * as process from "node:process";
4
+ //#region src/ptr.ts
5
+ function allocBuffer(size) {
6
+ return Buffer.alloc(size ?? pointerSize());
7
+ }
8
+ function readBufferPtr(buffer) {
9
+ if (pointerSize() === 8) return buffer.readBigUInt64LE();
10
+ else return BigInt(buffer.readUInt32LE());
11
+ }
12
+ function pointerSize() {
13
+ if (process.arch === "x64" || process.arch === "arm64") return 8;
14
+ else return 4;
15
+ }
16
+ //#endregion
17
+ //#region ../bindings/dist/index.js
18
+ var ffi_Status = /* @__PURE__ */ function(ffi_Status) {
19
+ ffi_Status[ffi_Status["OK"] = 0] = "OK";
20
+ ffi_Status[ffi_Status["ERR_NULL_POINTER"] = 1] = "ERR_NULL_POINTER";
21
+ ffi_Status[ffi_Status["ERR_NOTHING_TO_POLL"] = 2] = "ERR_NOTHING_TO_POLL";
22
+ ffi_Status[ffi_Status["ERR_SERIALIZATION"] = 3] = "ERR_SERIALIZATION";
23
+ ffi_Status[ffi_Status["ERR_UNKNOWN"] = 2147483647] = "ERR_UNKNOWN";
24
+ return ffi_Status;
25
+ }({});
26
+ //! Copyright (C) Call of Nil contributors
27
+ //! SPDX-License-Identifier: AGPL-3.0-only
28
+ //#endregion
29
+ //#region src/error.ts
30
+ var FfiError = class FfiError extends Error {
31
+ constructor(message, options) {
32
+ const status = options?.status ?? ffi_Status.ERR_UNKNOWN;
33
+ if (!message && status !== ffi_Status.OK) {
34
+ for (const [key, value] of Object.entries(ffi_Status)) if (value === status) {
35
+ message = key;
36
+ break;
37
+ }
38
+ }
39
+ message ??= "ERR_UNKNOWN";
40
+ super(message, options);
41
+ this.name = "FfiError";
42
+ this.status = status;
43
+ }
44
+ static fromStatus(status) {
45
+ return new FfiError(null, { status });
46
+ }
47
+ };
48
+ var HandleClosedError = class extends Error {
49
+ constructor(options) {
50
+ super("handle is closed", options);
51
+ this.name = "HandleClosedError";
52
+ }
53
+ };
54
+ //#endregion
55
+ //#region src/queue.ts
56
+ var Queue = class Queue {
57
+ static {
58
+ this.POLL_INTERVAL = 16;
59
+ }
60
+ static {
61
+ this.LIMIT_PER_TICK = 200;
62
+ }
63
+ constructor(handle) {
64
+ this.pending = /* @__PURE__ */ new Map();
65
+ this.disposed = false;
66
+ this.functions = handle.functions;
67
+ }
68
+ [Symbol.dispose]() {
69
+ if (this.disposed) return;
70
+ this.disposed = true;
71
+ this.rejectAll(new HandleClosedError());
72
+ }
73
+ request(start) {
74
+ if (this.disposed) return Promise.reject(new HandleClosedError());
75
+ return new Promise((resolve, reject) => {
76
+ let id;
77
+ try {
78
+ id = start();
79
+ } catch (err) {
80
+ reject(err);
81
+ return;
82
+ }
83
+ this.pending.set(id, {
84
+ resolve,
85
+ reject
86
+ });
87
+ this.startPolling();
88
+ });
89
+ }
90
+ startPolling() {
91
+ if (isNil(this.timer) && !this.disposed) this.timer = setTimeout(() => this.poll(), 0);
92
+ }
93
+ poll() {
94
+ this.timer = null;
95
+ if (!this.disposed && this.pending.size > 0) try {
96
+ for (let i = 0; i < Queue.LIMIT_PER_TICK; i++) if (!this.pollOnce()) break;
97
+ } catch (err) {
98
+ this.rejectAll(err);
99
+ return;
100
+ }
101
+ if (!this.disposed && this.pending.size > 0) this.timer = setTimeout(() => this.poll(), Queue.POLL_INTERVAL);
102
+ }
103
+ pollOnce() {
104
+ const out = allocBuffer();
105
+ const status = this.functions.nil_ffi_poll(out);
106
+ if (status === ffi_Status.ERR_NOTHING_TO_POLL) return false;
107
+ if (status !== ffi_Status.OK) throw FfiError.fromStatus(status);
108
+ const ptr = readBufferPtr(out);
109
+ if (ptr === 0n) throw new Error("unexpected null pointer");
110
+ let json;
111
+ try {
112
+ json = ffi.toString(ptr);
113
+ } finally {
114
+ this.functions.nil_ffi_free_str(ptr);
115
+ }
116
+ const entry = JSON.parse(json);
117
+ const response = JSON.parse(entry.json_str);
118
+ const pending = this.pending.get(response.id);
119
+ if (!pending) return true;
120
+ this.pending.delete(response.id);
121
+ if (response.kind === "ok") pending.resolve(response.data);
122
+ else pending.reject(new FfiError(response.error, { status: response.status }));
123
+ return true;
124
+ }
125
+ rejectAll(error) {
126
+ if (!isNil(this.timer)) {
127
+ clearTimeout(this.timer);
128
+ this.timer = null;
129
+ }
130
+ for (const { reject } of this.pending.values()) reject(error);
131
+ this.pending.clear();
132
+ }
133
+ };
134
+ //#endregion
135
+ //#region src/def.ts
136
+ var definitions = {
137
+ nil_ffi_free_str: {
138
+ arguments: [ffi.types.POINTER],
139
+ return: ffi.types.VOID
140
+ },
141
+ nil_ffi_poll: {
142
+ arguments: [ffi.types.POINTER],
143
+ return: ffi.types.INT_32
144
+ },
145
+ nil_ffi_shutdown: {
146
+ arguments: [],
147
+ return: ffi.types.VOID
148
+ },
149
+ nil_ffi_version: {
150
+ arguments: [],
151
+ return: ffi.types.UINT_32
152
+ },
153
+ nil_client_version: {
154
+ arguments: [],
155
+ return: ffi.types.UINT_32
156
+ },
157
+ nil_is_local: {
158
+ arguments: [],
159
+ return: ffi.types.UINT_32
160
+ },
161
+ nil_is_ready: {
162
+ arguments: [],
163
+ return: ffi.types.UINT_32
164
+ },
165
+ nil_is_remote: {
166
+ arguments: [],
167
+ return: ffi.types.UINT_32
168
+ },
169
+ nil_server_addr: {
170
+ arguments: [],
171
+ return: ffi.types.UINT_32
172
+ },
173
+ nil_set_user_agent: {
174
+ arguments: [ffi.types.POINTER],
175
+ return: ffi.types.UINT_32
176
+ },
177
+ nil_stop_client: {
178
+ arguments: [],
179
+ return: ffi.types.UINT_32
180
+ },
181
+ nil_update_client: {
182
+ arguments: [ffi.types.POINTER],
183
+ return: ffi.types.UINT_32
184
+ },
185
+ nil_user_agent: {
186
+ arguments: [],
187
+ return: ffi.types.UINT_32
188
+ },
189
+ nil_world: {
190
+ arguments: [],
191
+ return: ffi.types.UINT_32
192
+ },
193
+ nil_add_academy_recruit_order: {
194
+ arguments: [ffi.types.POINTER],
195
+ return: ffi.types.UINT_32
196
+ },
197
+ nil_add_prefecture_build_order: {
198
+ arguments: [ffi.types.POINTER],
199
+ return: ffi.types.UINT_32
200
+ },
201
+ nil_add_stable_recruit_order: {
202
+ arguments: [ffi.types.POINTER],
203
+ return: ffi.types.UINT_32
204
+ },
205
+ nil_add_workshop_recruit_order: {
206
+ arguments: [ffi.types.POINTER],
207
+ return: ffi.types.UINT_32
208
+ },
209
+ nil_authorize: {
210
+ arguments: [ffi.types.POINTER],
211
+ return: ffi.types.UINT_32
212
+ },
213
+ nil_cancel_academy_recruit_order: {
214
+ arguments: [ffi.types.POINTER],
215
+ return: ffi.types.UINT_32
216
+ },
217
+ nil_cancel_maneuver: {
218
+ arguments: [ffi.types.POINTER],
219
+ return: ffi.types.UINT_32
220
+ },
221
+ nil_cancel_prefecture_build_order: {
222
+ arguments: [ffi.types.POINTER],
223
+ return: ffi.types.UINT_32
224
+ },
225
+ nil_cancel_stable_recruit_order: {
226
+ arguments: [ffi.types.POINTER],
227
+ return: ffi.types.UINT_32
228
+ },
229
+ nil_cancel_workshop_recruit_order: {
230
+ arguments: [ffi.types.POINTER],
231
+ return: ffi.types.UINT_32
232
+ },
233
+ nil_cheat_fill_world: {
234
+ arguments: [ffi.types.POINTER],
235
+ return: ffi.types.UINT_32
236
+ },
237
+ nil_cheat_get_academy_recruit_queue: {
238
+ arguments: [ffi.types.POINTER],
239
+ return: ffi.types.UINT_32
240
+ },
241
+ nil_cheat_get_academy_recruit_queues: {
242
+ arguments: [ffi.types.POINTER],
243
+ return: ffi.types.UINT_32
244
+ },
245
+ nil_cheat_get_all_academy_recruit_queues: {
246
+ arguments: [ffi.types.POINTER],
247
+ return: ffi.types.UINT_32
248
+ },
249
+ nil_cheat_get_all_prefecture_build_queues: {
250
+ arguments: [ffi.types.POINTER],
251
+ return: ffi.types.UINT_32
252
+ },
253
+ nil_cheat_get_all_stable_recruit_queues: {
254
+ arguments: [ffi.types.POINTER],
255
+ return: ffi.types.UINT_32
256
+ },
257
+ nil_cheat_get_build_steps: {
258
+ arguments: [ffi.types.POINTER],
259
+ return: ffi.types.UINT_32
260
+ },
261
+ nil_cheat_get_cities: {
262
+ arguments: [ffi.types.POINTER],
263
+ return: ffi.types.UINT_32
264
+ },
265
+ nil_cheat_get_city: {
266
+ arguments: [ffi.types.POINTER],
267
+ return: ffi.types.UINT_32
268
+ },
269
+ nil_cheat_get_ethics: {
270
+ arguments: [ffi.types.POINTER],
271
+ return: ffi.types.UINT_32
272
+ },
273
+ nil_cheat_get_idle_armies_at: {
274
+ arguments: [ffi.types.POINTER],
275
+ return: ffi.types.UINT_32
276
+ },
277
+ nil_cheat_get_idle_personnel_at: {
278
+ arguments: [ffi.types.POINTER],
279
+ return: ffi.types.UINT_32
280
+ },
281
+ nil_cheat_get_infrastructure: {
282
+ arguments: [ffi.types.POINTER],
283
+ return: ffi.types.UINT_32
284
+ },
285
+ nil_cheat_get_maneuvers: {
286
+ arguments: [ffi.types.POINTER],
287
+ return: ffi.types.UINT_32
288
+ },
289
+ nil_cheat_get_maneuvers_of: {
290
+ arguments: [ffi.types.POINTER],
291
+ return: ffi.types.UINT_32
292
+ },
293
+ nil_cheat_get_player: {
294
+ arguments: [ffi.types.POINTER],
295
+ return: ffi.types.UINT_32
296
+ },
297
+ nil_cheat_get_players: {
298
+ arguments: [ffi.types.POINTER],
299
+ return: ffi.types.UINT_32
300
+ },
301
+ nil_cheat_get_prefecture_build_queue: {
302
+ arguments: [ffi.types.POINTER],
303
+ return: ffi.types.UINT_32
304
+ },
305
+ nil_cheat_get_prefecture_build_queues: {
306
+ arguments: [ffi.types.POINTER],
307
+ return: ffi.types.UINT_32
308
+ },
309
+ nil_cheat_get_resources: {
310
+ arguments: [ffi.types.POINTER],
311
+ return: ffi.types.UINT_32
312
+ },
313
+ nil_cheat_get_stable_recruit_queue: {
314
+ arguments: [ffi.types.POINTER],
315
+ return: ffi.types.UINT_32
316
+ },
317
+ nil_cheat_get_stable_recruit_queues: {
318
+ arguments: [ffi.types.POINTER],
319
+ return: ffi.types.UINT_32
320
+ },
321
+ nil_cheat_get_storage_capacity: {
322
+ arguments: [ffi.types.POINTER],
323
+ return: ffi.types.UINT_32
324
+ },
325
+ nil_cheat_set_bot_ethics: {
326
+ arguments: [ffi.types.POINTER],
327
+ return: ffi.types.UINT_32
328
+ },
329
+ nil_cheat_set_building_level: {
330
+ arguments: [ffi.types.POINTER],
331
+ return: ffi.types.UINT_32
332
+ },
333
+ nil_cheat_set_food: {
334
+ arguments: [ffi.types.POINTER],
335
+ return: ffi.types.UINT_32
336
+ },
337
+ nil_cheat_set_iron: {
338
+ arguments: [ffi.types.POINTER],
339
+ return: ffi.types.UINT_32
340
+ },
341
+ nil_cheat_set_max_food: {
342
+ arguments: [ffi.types.POINTER],
343
+ return: ffi.types.UINT_32
344
+ },
345
+ nil_cheat_set_max_infrastructure: {
346
+ arguments: [ffi.types.POINTER],
347
+ return: ffi.types.UINT_32
348
+ },
349
+ nil_cheat_set_max_iron: {
350
+ arguments: [ffi.types.POINTER],
351
+ return: ffi.types.UINT_32
352
+ },
353
+ nil_cheat_set_max_resources: {
354
+ arguments: [ffi.types.POINTER],
355
+ return: ffi.types.UINT_32
356
+ },
357
+ nil_cheat_set_max_silo_resources: {
358
+ arguments: [ffi.types.POINTER],
359
+ return: ffi.types.UINT_32
360
+ },
361
+ nil_cheat_set_max_stone: {
362
+ arguments: [ffi.types.POINTER],
363
+ return: ffi.types.UINT_32
364
+ },
365
+ nil_cheat_set_max_warehouse_resources: {
366
+ arguments: [ffi.types.POINTER],
367
+ return: ffi.types.UINT_32
368
+ },
369
+ nil_cheat_set_max_wood: {
370
+ arguments: [ffi.types.POINTER],
371
+ return: ffi.types.UINT_32
372
+ },
373
+ nil_cheat_set_resources: {
374
+ arguments: [ffi.types.POINTER],
375
+ return: ffi.types.UINT_32
376
+ },
377
+ nil_cheat_set_stability: {
378
+ arguments: [ffi.types.POINTER],
379
+ return: ffi.types.UINT_32
380
+ },
381
+ nil_cheat_set_stone: {
382
+ arguments: [ffi.types.POINTER],
383
+ return: ffi.types.UINT_32
384
+ },
385
+ nil_cheat_set_wood: {
386
+ arguments: [ffi.types.POINTER],
387
+ return: ffi.types.UINT_32
388
+ },
389
+ nil_cheat_skip_round: {
390
+ arguments: [ffi.types.POINTER],
391
+ return: ffi.types.UINT_32
392
+ },
393
+ nil_cheat_spawn_bot: {
394
+ arguments: [ffi.types.POINTER],
395
+ return: ffi.types.UINT_32
396
+ },
397
+ nil_cheat_spawn_city: {
398
+ arguments: [ffi.types.POINTER],
399
+ return: ffi.types.UINT_32
400
+ },
401
+ nil_cheat_spawn_personnel: {
402
+ arguments: [ffi.types.POINTER],
403
+ return: ffi.types.UINT_32
404
+ },
405
+ nil_create_remote_world: {
406
+ arguments: [ffi.types.POINTER],
407
+ return: ffi.types.UINT_32
408
+ },
409
+ nil_create_user: {
410
+ arguments: [ffi.types.POINTER],
411
+ return: ffi.types.UINT_32
412
+ },
413
+ nil_delete_remote_world: {
414
+ arguments: [ffi.types.POINTER],
415
+ return: ffi.types.UINT_32
416
+ },
417
+ nil_forward_report: {
418
+ arguments: [ffi.types.POINTER],
419
+ return: ffi.types.UINT_32
420
+ },
421
+ nil_get_academy_recruit_catalog: {
422
+ arguments: [ffi.types.POINTER],
423
+ return: ffi.types.UINT_32
424
+ },
425
+ nil_get_armies: {
426
+ arguments: [ffi.types.POINTER],
427
+ return: ffi.types.UINT_32
428
+ },
429
+ nil_get_army: {
430
+ arguments: [ffi.types.POINTER],
431
+ return: ffi.types.UINT_32
432
+ },
433
+ nil_get_army_owner: {
434
+ arguments: [ffi.types.POINTER],
435
+ return: ffi.types.UINT_32
436
+ },
437
+ nil_get_bot_coords: {
438
+ arguments: [ffi.types.POINTER],
439
+ return: ffi.types.UINT_32
440
+ },
441
+ nil_get_chat_history: {
442
+ arguments: [ffi.types.POINTER],
443
+ return: ffi.types.UINT_32
444
+ },
445
+ nil_get_cities: {
446
+ arguments: [ffi.types.POINTER],
447
+ return: ffi.types.UINT_32
448
+ },
449
+ nil_get_city: {
450
+ arguments: [ffi.types.POINTER],
451
+ return: ffi.types.UINT_32
452
+ },
453
+ nil_get_city_score: {
454
+ arguments: [ffi.types.POINTER],
455
+ return: ffi.types.UINT_32
456
+ },
457
+ nil_get_continent_size: {
458
+ arguments: [ffi.types.POINTER],
459
+ return: ffi.types.UINT_32
460
+ },
461
+ nil_get_idle_armies_at: {
462
+ arguments: [ffi.types.POINTER],
463
+ return: ffi.types.UINT_32
464
+ },
465
+ nil_get_idle_armies_coords: {
466
+ arguments: [ffi.types.POINTER],
467
+ return: ffi.types.UINT_32
468
+ },
469
+ nil_get_maneuver: {
470
+ arguments: [ffi.types.POINTER],
471
+ return: ffi.types.UINT_32
472
+ },
473
+ nil_get_player: {
474
+ arguments: [ffi.types.POINTER],
475
+ return: ffi.types.UINT_32
476
+ },
477
+ nil_get_player_coords: {
478
+ arguments: [ffi.types.POINTER],
479
+ return: ffi.types.UINT_32
480
+ },
481
+ nil_get_player_ids: {
482
+ arguments: [ffi.types.POINTER],
483
+ return: ffi.types.UINT_32
484
+ },
485
+ nil_get_player_maintenance: {
486
+ arguments: [ffi.types.POINTER],
487
+ return: ffi.types.UINT_32
488
+ },
489
+ nil_get_player_military: {
490
+ arguments: [ffi.types.POINTER],
491
+ return: ffi.types.UINT_32
492
+ },
493
+ nil_get_player_status: {
494
+ arguments: [ffi.types.POINTER],
495
+ return: ffi.types.UINT_32
496
+ },
497
+ nil_get_player_storage_capacity: {
498
+ arguments: [ffi.types.POINTER],
499
+ return: ffi.types.UINT_32
500
+ },
501
+ nil_get_player_worlds: {
502
+ arguments: [ffi.types.POINTER],
503
+ return: ffi.types.UINT_32
504
+ },
505
+ nil_get_precursor_coords: {
506
+ arguments: [ffi.types.POINTER],
507
+ return: ffi.types.UINT_32
508
+ },
509
+ nil_get_prefecture_build_catalog: {
510
+ arguments: [ffi.types.POINTER],
511
+ return: ffi.types.UINT_32
512
+ },
513
+ nil_get_public_bot: {
514
+ arguments: [ffi.types.POINTER],
515
+ return: ffi.types.UINT_32
516
+ },
517
+ nil_get_public_bots: {
518
+ arguments: [ffi.types.POINTER],
519
+ return: ffi.types.UINT_32
520
+ },
521
+ nil_get_public_cities: {
522
+ arguments: [ffi.types.POINTER],
523
+ return: ffi.types.UINT_32
524
+ },
525
+ nil_get_public_city: {
526
+ arguments: [ffi.types.POINTER],
527
+ return: ffi.types.UINT_32
528
+ },
529
+ nil_get_public_field: {
530
+ arguments: [ffi.types.POINTER],
531
+ return: ffi.types.UINT_32
532
+ },
533
+ nil_get_public_fields: {
534
+ arguments: [ffi.types.POINTER],
535
+ return: ffi.types.UINT_32
536
+ },
537
+ nil_get_public_player: {
538
+ arguments: [ffi.types.POINTER],
539
+ return: ffi.types.UINT_32
540
+ },
541
+ nil_get_public_players: {
542
+ arguments: [ffi.types.POINTER],
543
+ return: ffi.types.UINT_32
544
+ },
545
+ nil_get_public_precursor: {
546
+ arguments: [ffi.types.POINTER],
547
+ return: ffi.types.UINT_32
548
+ },
549
+ nil_get_public_precursors: {
550
+ arguments: [ffi.types.POINTER],
551
+ return: ffi.types.UINT_32
552
+ },
553
+ nil_get_rank: {
554
+ arguments: [ffi.types.POINTER],
555
+ return: ffi.types.UINT_32
556
+ },
557
+ nil_get_ranking: {
558
+ arguments: [ffi.types.POINTER],
559
+ return: ffi.types.UINT_32
560
+ },
561
+ nil_get_remote_world: {
562
+ arguments: [ffi.types.POINTER],
563
+ return: ffi.types.UINT_32
564
+ },
565
+ nil_get_remote_world_limit: {
566
+ arguments: [],
567
+ return: ffi.types.UINT_32
568
+ },
569
+ nil_get_remote_world_limit_per_user: {
570
+ arguments: [],
571
+ return: ffi.types.UINT_32
572
+ },
573
+ nil_get_remote_worlds: {
574
+ arguments: [],
575
+ return: ffi.types.UINT_32
576
+ },
577
+ nil_get_round: {
578
+ arguments: [ffi.types.POINTER],
579
+ return: ffi.types.UINT_32
580
+ },
581
+ nil_get_server_kind: {
582
+ arguments: [],
583
+ return: ffi.types.UINT_32
584
+ },
585
+ nil_get_stable_recruit_catalog: {
586
+ arguments: [ffi.types.POINTER],
587
+ return: ffi.types.UINT_32
588
+ },
589
+ nil_get_workshop_recruit_catalog: {
590
+ arguments: [ffi.types.POINTER],
591
+ return: ffi.types.UINT_32
592
+ },
593
+ nil_get_world_bots: {
594
+ arguments: [ffi.types.POINTER],
595
+ return: ffi.types.UINT_32
596
+ },
597
+ nil_get_world_config: {
598
+ arguments: [ffi.types.POINTER],
599
+ return: ffi.types.UINT_32
600
+ },
601
+ nil_get_world_personnel: {
602
+ arguments: [ffi.types.POINTER],
603
+ return: ffi.types.UINT_32
604
+ },
605
+ nil_get_world_players: {
606
+ arguments: [ffi.types.POINTER],
607
+ return: ffi.types.UINT_32
608
+ },
609
+ nil_get_world_precursors: {
610
+ arguments: [ffi.types.POINTER],
611
+ return: ffi.types.UINT_32
612
+ },
613
+ nil_get_world_stats: {
614
+ arguments: [ffi.types.POINTER],
615
+ return: ffi.types.UINT_32
616
+ },
617
+ nil_player_exists: {
618
+ arguments: [ffi.types.POINTER],
619
+ return: ffi.types.UINT_32
620
+ },
621
+ nil_push_chat_message: {
622
+ arguments: [ffi.types.POINTER],
623
+ return: ffi.types.UINT_32
624
+ },
625
+ nil_rename_city: {
626
+ arguments: [ffi.types.POINTER],
627
+ return: ffi.types.UINT_32
628
+ },
629
+ nil_request_maneuver: {
630
+ arguments: [ffi.types.POINTER],
631
+ return: ffi.types.UINT_32
632
+ },
633
+ nil_save_local_world: {
634
+ arguments: [ffi.types.POINTER],
635
+ return: ffi.types.UINT_32
636
+ },
637
+ nil_search_city: {
638
+ arguments: [ffi.types.POINTER],
639
+ return: ffi.types.UINT_32
640
+ },
641
+ nil_search_public_city: {
642
+ arguments: [ffi.types.POINTER],
643
+ return: ffi.types.UINT_32
644
+ },
645
+ nil_server_version: {
646
+ arguments: [],
647
+ return: ffi.types.UINT_32
648
+ },
649
+ nil_set_player_ready: {
650
+ arguments: [ffi.types.POINTER],
651
+ return: ffi.types.UINT_32
652
+ },
653
+ nil_set_player_status: {
654
+ arguments: [ffi.types.POINTER],
655
+ return: ffi.types.UINT_32
656
+ },
657
+ nil_simulate_battle: {
658
+ arguments: [ffi.types.POINTER],
659
+ return: ffi.types.UINT_32
660
+ },
661
+ nil_spawn_player: {
662
+ arguments: [ffi.types.POINTER],
663
+ return: ffi.types.UINT_32
664
+ },
665
+ nil_start_round: {
666
+ arguments: [ffi.types.POINTER],
667
+ return: ffi.types.UINT_32
668
+ },
669
+ nil_toggle_building: {
670
+ arguments: [ffi.types.POINTER],
671
+ return: ffi.types.UINT_32
672
+ },
673
+ nil_user_exists: {
674
+ arguments: [ffi.types.POINTER],
675
+ return: ffi.types.UINT_32
676
+ },
677
+ nil_validate_token: {
678
+ arguments: [ffi.types.POINTER],
679
+ return: ffi.types.UINT_32
680
+ }
681
+ };
682
+ //#endregion
683
+ //#region package.json
684
+ var version = "0.7.0";
685
+ //#endregion
686
+ //#region src/index.ts
687
+ var Nil = class {
688
+ constructor(dll) {
689
+ this.disposed = false;
690
+ if (!dll.endsWith(ffi.suffix)) dll = `${dll}.${ffi.suffix}`;
691
+ this.handle = ffi.dlopen(dll, definitions);
692
+ this.functions = this.handle.functions;
693
+ this.queue = new Queue(this.handle);
694
+ this.setUserAgent(`nil-ffi-node/${version}`);
695
+ }
696
+ [Symbol.dispose]() {
697
+ this.close();
698
+ }
699
+ close() {
700
+ if (this.disposed) return;
701
+ this.disposed = true;
702
+ this.queue[Symbol.dispose]();
703
+ this.functions.nil_ffi_shutdown();
704
+ this.handle[Symbol.dispose]();
705
+ }
706
+ async getClientVersion() {
707
+ this.throwIfClosed();
708
+ return this.queue.request(() => {
709
+ return this.functions.nil_client_version();
710
+ });
711
+ }
712
+ async getFfiVersion() {
713
+ this.throwIfClosed();
714
+ return this.queue.request(() => {
715
+ return this.functions.nil_ffi_version();
716
+ });
717
+ }
718
+ async getUserAgent() {
719
+ this.throwIfClosed();
720
+ return this.queue.request(() => {
721
+ return this.functions.nil_user_agent();
722
+ });
723
+ }
724
+ async getWorld() {
725
+ this.throwIfClosed();
726
+ return this.queue.request(() => {
727
+ return this.functions.nil_world();
728
+ });
729
+ }
730
+ async setUserAgent(userAgent) {
731
+ this.throwIfClosed();
732
+ await this.queue.request(() => {
733
+ return this.functions.nil_set_user_agent(userAgent);
734
+ });
735
+ }
736
+ throwIfClosed() {
737
+ if (this.disposed) throw new HandleClosedError();
738
+ }
739
+ };
740
+ //#endregion
741
+ export { FfiError, HandleClosedError, Nil, definitions };