@tsukilabs/nil-ffi 0.7.10 → 0.7.12

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 CHANGED
@@ -1,13 +1,184 @@
1
1
  import * as ffi from "node:ffi";
2
- import * as path from "node:path";
2
+ import { EventEmitter } from "node:events";
3
+ import { isNil } from "es-toolkit/predicate";
3
4
  import * as process from "node:process";
4
5
  import { cwd } from "node:process";
6
+ import { ffi_Status } from "@tsukilabs/nil-bindings";
7
+ import * as path from "node:path";
5
8
  import { existsSync } from "node:fs";
6
9
  import * as fs from "node:fs/promises";
7
- import { ffi_Status } from "@tsukilabs/nil-bindings";
8
10
  import { attemptAsync } from "es-toolkit/util";
9
- import { EventEmitter } from "node:events";
10
- import { isNil } from "es-toolkit/predicate";
11
+ //#region src/request.ts
12
+ //! Copyright (C) Call of Nil contributors
13
+ //! SPDX-License-Identifier: AGPL-3.0-only
14
+ var RequestId = class {
15
+ #current = 0;
16
+ next() {
17
+ if (this.#current >= 4294967295) this.#current = 0;
18
+ return ++this.#current;
19
+ }
20
+ };
21
+ //#endregion
22
+ //#region src/ptr.ts
23
+ //! Copyright (C) Call of Nil contributors
24
+ //! SPDX-License-Identifier: AGPL-3.0-only
25
+ function allocBuffer(size) {
26
+ return Buffer.alloc(size ?? pointerSize());
27
+ }
28
+ function readBufferPtr(buffer) {
29
+ if (pointerSize() === 8) return buffer.readBigUInt64LE();
30
+ else return BigInt(buffer.readUInt32LE());
31
+ }
32
+ function pointerSize() {
33
+ if (process.arch === "x64" || process.arch === "arm64") return 8;
34
+ else return 4;
35
+ }
36
+ //#endregion
37
+ //#region src/error.ts
38
+ //! Copyright (C) Call of Nil contributors
39
+ //! SPDX-License-Identifier: AGPL-3.0-only
40
+ var NilError = class NilError extends Error {
41
+ constructor(message, options) {
42
+ const status = options?.status ?? ffi_Status.ERR_UNKNOWN;
43
+ if (!message && status !== ffi_Status.OK) {
44
+ for (const [key, value] of Object.entries(ffi_Status)) if (value === status) {
45
+ message = key;
46
+ break;
47
+ }
48
+ }
49
+ message ??= "ERR_UNKNOWN";
50
+ super(message, options);
51
+ this.name = "NilError";
52
+ this.status = status;
53
+ }
54
+ static fromStatus(status) {
55
+ return new NilError(null, { status });
56
+ }
57
+ };
58
+ var HandleClosedError = class extends Error {
59
+ constructor(options) {
60
+ super("handle is closed", options);
61
+ this.name = "HandleClosedError";
62
+ }
63
+ };
64
+ var UnknownResponseError = class extends Error {
65
+ constructor(response, options) {
66
+ super(`got unknown response with id ${response.id}`, options);
67
+ this.name = "UnknownResponseError";
68
+ this.response = response;
69
+ }
70
+ };
71
+ //#endregion
72
+ //#region src/queue.ts
73
+ //! Copyright (C) Call of Nil contributors
74
+ //! SPDX-License-Identifier: AGPL-3.0-only
75
+ var QueueEmitter = class extends EventEmitter {
76
+ emit(event, ...args) {
77
+ return super.emit(event, ...args);
78
+ }
79
+ on(event, listener) {
80
+ return super.on(event, listener);
81
+ }
82
+ };
83
+ var Queue = class Queue {
84
+ static {
85
+ this.POLL_INTERVAL = 16;
86
+ }
87
+ static {
88
+ this.LIMIT_PER_TICK = 200;
89
+ }
90
+ constructor(handle, options) {
91
+ this.disposed = false;
92
+ this.emitter = new QueueEmitter();
93
+ this.requestId = new RequestId();
94
+ this.pendingRequests = /* @__PURE__ */ new Map();
95
+ this.functions = handle.functions;
96
+ this.errorHandler = options?.onError ?? console.error;
97
+ this.emitter.on("error", this.errorHandler);
98
+ this.emitter.on("response", this.onResponse.bind(this));
99
+ this.timer = setTimeout(() => this.drain(), 0);
100
+ }
101
+ [Symbol.dispose]() {
102
+ if (this.disposed) return;
103
+ this.disposed = true;
104
+ this.rejectAll(new HandleClosedError());
105
+ this.emitter.removeAllListeners();
106
+ }
107
+ request(start) {
108
+ if (this.disposed) return Promise.reject(new HandleClosedError());
109
+ const requestId = this.requestId.next();
110
+ return new Promise((resolve, reject) => {
111
+ this.pendingRequests.set(requestId, {
112
+ resolve,
113
+ reject
114
+ });
115
+ try {
116
+ start(requestId);
117
+ } catch (err) {
118
+ this.pendingRequests.delete(requestId);
119
+ reject(err);
120
+ }
121
+ });
122
+ }
123
+ drain() {
124
+ if (this.disposed) return;
125
+ this.clearTimeout();
126
+ try {
127
+ for (let i = 0; i < Queue.LIMIT_PER_TICK; i++) if (!this.poll()) break;
128
+ } catch (err) {
129
+ this.emitter.emit("error", err);
130
+ }
131
+ this.timer = setTimeout(() => this.drain(), Queue.POLL_INTERVAL);
132
+ }
133
+ poll() {
134
+ const out = allocBuffer();
135
+ const status = this.functions.nil_ffi_poll(out);
136
+ if (status === ffi_Status.ERR_NOTHING_TO_POLL) return false;
137
+ if (status !== ffi_Status.OK) throw NilError.fromStatus(status);
138
+ const ptr = readBufferPtr(out);
139
+ if (ptr === 0n) throw new Error("failed to poll: unexpected null pointer");
140
+ try {
141
+ const json = ffi.toString(ptr) ?? "";
142
+ const entry = JSON.parse(json);
143
+ this.dispatch(entry);
144
+ } finally {
145
+ this.functions.nil_ffi_free_str(ptr);
146
+ }
147
+ return true;
148
+ }
149
+ dispatch(entry) {
150
+ switch (entry.kind) {
151
+ case "response": {
152
+ const response = JSON.parse(entry.jsonStr);
153
+ this.emitter.emit("response", response);
154
+ break;
155
+ }
156
+ }
157
+ }
158
+ rejectAll(error) {
159
+ this.clearTimeout();
160
+ this.pendingRequests.values().forEach(({ reject }) => reject(error));
161
+ this.pendingRequests.clear();
162
+ }
163
+ clearTimeout() {
164
+ if (!isNil(this.timer)) {
165
+ clearTimeout(this.timer);
166
+ this.timer = null;
167
+ }
168
+ }
169
+ onResponse(response) {
170
+ const pending = this.pendingRequests.get(response.id);
171
+ if (pending) {
172
+ this.pendingRequests.delete(response.id);
173
+ if (response.kind === "ok") pending.resolve(response.data);
174
+ else {
175
+ const { status, error } = response;
176
+ pending.reject(new NilError(error, { status }));
177
+ }
178
+ } else this.emitter.emit("error", new UnknownResponseError(response));
179
+ }
180
+ };
181
+ //#endregion
11
182
  //#region src/def.ts
12
183
  //! Copyright (C) Call of Nil contributors
13
184
  //! SPDX-License-Identifier: AGPL-3.0-only
@@ -84,6 +255,10 @@ var definitions = {
84
255
  arguments: [ffi.types.UINT_32],
85
256
  return: ffi.types.VOID
86
257
  },
258
+ nil_runtime_global_queue_depth: {
259
+ arguments: [ffi.types.UINT_32],
260
+ return: ffi.types.VOID
261
+ },
87
262
  nil_runtime_num_alive_tasks: {
88
263
  arguments: [ffi.types.UINT_32],
89
264
  return: ffi.types.VOID
@@ -240,6 +415,10 @@ var definitions = {
240
415
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
241
416
  return: ffi.types.VOID
242
417
  },
418
+ nil_cheat_set_market_fee: {
419
+ arguments: [ffi.types.UINT_32, ffi.types.POINTER],
420
+ return: ffi.types.VOID
421
+ },
243
422
  nil_cheat_set_max_food: {
244
423
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
245
424
  return: ffi.types.VOID
@@ -372,6 +551,14 @@ var definitions = {
372
551
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
373
552
  return: ffi.types.VOID
374
553
  },
554
+ nil_get_market: {
555
+ arguments: [ffi.types.UINT_32, ffi.types.POINTER],
556
+ return: ffi.types.VOID
557
+ },
558
+ nil_get_market_fee: {
559
+ arguments: [ffi.types.UINT_32, ffi.types.POINTER],
560
+ return: ffi.types.VOID
561
+ },
375
562
  nil_get_player: {
376
563
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
377
564
  return: ffi.types.VOID
@@ -512,6 +699,10 @@ var definitions = {
512
699
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
513
700
  return: ffi.types.VOID
514
701
  },
702
+ nil_get_world_rulers: {
703
+ arguments: [ffi.types.UINT_32, ffi.types.POINTER],
704
+ return: ffi.types.VOID
705
+ },
515
706
  nil_get_world_stats: {
516
707
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
517
708
  return: ffi.types.VOID
@@ -544,6 +735,10 @@ var definitions = {
544
735
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
545
736
  return: ffi.types.VOID
546
737
  },
738
+ nil_send_resources: {
739
+ arguments: [ffi.types.UINT_32, ffi.types.POINTER],
740
+ return: ffi.types.VOID
741
+ },
547
742
  nil_server_version: {
548
743
  arguments: [ffi.types.UINT_32],
549
744
  return: ffi.types.VOID
@@ -582,224 +777,402 @@ var definitions = {
582
777
  }
583
778
  };
584
779
  //#endregion
585
- //#region src/error.ts
780
+ //#region package.json
781
+ var version = "0.7.12";
782
+ //#endregion
783
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
784
+ function __decorate(decorators, target, key, desc) {
785
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
786
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
787
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
788
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
789
+ }
790
+ //#endregion
791
+ //#region src/index.ts
586
792
  //! Copyright (C) Call of Nil contributors
587
793
  //! SPDX-License-Identifier: AGPL-3.0-only
588
- var NilError = class NilError extends Error {
589
- constructor(message, options) {
590
- const status = options?.status ?? ffi_Status.ERR_UNKNOWN;
591
- if (!message && status !== ffi_Status.OK) {
592
- for (const [key, value] of Object.entries(ffi_Status)) if (value === status) {
593
- message = key;
594
- break;
595
- }
596
- }
597
- message ??= "ERR_UNKNOWN";
598
- super(message, options);
599
- this.name = "NilError";
600
- this.status = status;
601
- }
602
- static fromStatus(status) {
603
- return new NilError(null, { status });
794
+ var VERSION = version;
795
+ var USER_AGENT = `nil-ffi-node/${VERSION}`;
796
+ var Nil = class Nil {
797
+ constructor(dll, options) {
798
+ this.closed = false;
799
+ if (!dll.endsWith(ffi.suffix)) dll = `${dll}.${ffi.suffix}`;
800
+ this.path = path.resolve(dll);
801
+ this.handle = ffi.dlopen(dll, definitions);
802
+ this.functions = this.handle.functions;
803
+ this.queue = new Queue(this.handle, options);
604
804
  }
605
- };
606
- var HandleClosedError = class extends Error {
607
- constructor(options) {
608
- super("handle is closed", options);
609
- this.name = "HandleClosedError";
805
+ async [Symbol.asyncDispose]() {
806
+ await this.close();
610
807
  }
611
- };
612
- var UnknownResponseError = class extends Error {
613
- constructor(response, options) {
614
- super(`got unknown response with id ${response.id}`, options);
615
- this.name = "UnknownResponseError";
616
- this.response = response;
808
+ async #close() {
809
+ if (this.closed) return;
810
+ this.closed = true;
811
+ await attemptAsync(this.stopClient.bind(this));
812
+ await attemptAsync(this.stopServer.bind(this));
813
+ this.queue[Symbol.dispose]();
814
+ this.functions.nil_ffi_shutdown();
815
+ this.handle[Symbol.dispose]();
617
816
  }
618
- };
619
- //#endregion
620
- //#region src/request.ts
621
- //! Copyright (C) Call of Nil contributors
622
- //! SPDX-License-Identifier: AGPL-3.0-only
623
- var RequestId = class {
624
- #current = 0;
625
- next() {
626
- if (this.#current >= 4294967295) this.#current = 0;
627
- return ++this.#current;
817
+ async close() {
818
+ this.closePromise ??= this.#close().finally(() => void (this.closePromise = null));
819
+ return this.closePromise;
628
820
  }
629
- };
630
- //#endregion
631
- //#region src/ptr.ts
632
- //! Copyright (C) Call of Nil contributors
633
- //! SPDX-License-Identifier: AGPL-3.0-only
634
- function allocBuffer(size) {
635
- return Buffer.alloc(size ?? pointerSize());
636
- }
637
- function readBufferPtr(buffer) {
638
- if (pointerSize() === 8) return buffer.readBigUInt64LE();
639
- else return BigInt(buffer.readUInt32LE());
640
- }
641
- function pointerSize() {
642
- if (process.arch === "x64" || process.arch === "arm64") return 8;
643
- else return 4;
644
- }
645
- //#endregion
646
- //#region src/queue.ts
647
- //! Copyright (C) Call of Nil contributors
648
- //! SPDX-License-Identifier: AGPL-3.0-only
649
- var QueueEmitter = class extends EventEmitter {
650
- emit(event, ...args) {
651
- return super.emit(event, ...args);
821
+ isClosed() {
822
+ return this.closed;
652
823
  }
653
- on(event, listener) {
654
- return super.on(event, listener);
824
+ static async init(dll, options) {
825
+ const nil = new Nil(dll, options);
826
+ await nil.setUserAgent(USER_AGENT);
827
+ return nil;
655
828
  }
656
- };
657
- var Queue = class Queue {
658
- static {
659
- this.POLL_INTERVAL = 16;
829
+ static async initLatest(options) {
830
+ const dll = await this.downloadLatest(options);
831
+ return this.init(dll, options);
660
832
  }
661
- static {
662
- this.LIMIT_PER_TICK = 200;
833
+ static async downloadLatest(options) {
834
+ const file = `libnil.${ffi.suffix}`;
835
+ const filePath = path.resolve(options?.outDir ?? cwd(), file);
836
+ if (!(options?.overwrite ?? true) && existsSync(filePath)) return filePath;
837
+ const response = await fetch(`https://tsukilabs.dev.br/download/nil/${file}`, { headers: { "User-Agent": USER_AGENT } });
838
+ if (!response.ok) throw new Error(`failed to download ${file}: ${response.status} ${response.statusText}`);
839
+ const bytes = await response.bytes();
840
+ await fs.writeFile(filePath, bytes);
841
+ return filePath;
663
842
  }
664
- constructor(handle, options) {
665
- this.disposed = false;
666
- this.emitter = new QueueEmitter();
667
- this.requestId = new RequestId();
668
- this.pendingRequests = /* @__PURE__ */ new Map();
669
- this.functions = handle.functions;
670
- this.errorHandler = options?.onError ?? console.error;
671
- this.emitter.on("error", this.errorHandler);
672
- this.emitter.on("response", this.onResponse.bind(this));
673
- this.timer = setTimeout(() => this.drain(), 0);
843
+ async addAcademyRecruitOrder(req) {
844
+ return this.queue.request((requestId) => {
845
+ this.functions.nil_add_academy_recruit_order(requestId, JSON.stringify(req));
846
+ });
674
847
  }
675
- [Symbol.dispose]() {
676
- if (this.disposed) return;
677
- this.disposed = true;
678
- this.rejectAll(new HandleClosedError());
679
- this.emitter.removeAllListeners();
848
+ async addPrefectureBuildOrder(req) {
849
+ return this.queue.request((requestId) => {
850
+ this.functions.nil_add_prefecture_build_order(requestId, JSON.stringify(req));
851
+ });
680
852
  }
681
- request(start) {
682
- if (this.disposed) return Promise.reject(new HandleClosedError());
683
- const requestId = this.requestId.next();
684
- return new Promise((resolve, reject) => {
685
- this.pendingRequests.set(requestId, {
686
- resolve,
687
- reject
688
- });
689
- try {
690
- start(requestId);
691
- } catch (err) {
692
- this.pendingRequests.delete(requestId);
693
- reject(err);
694
- }
853
+ async addStableRecruitOrder(req) {
854
+ return this.queue.request((requestId) => {
855
+ this.functions.nil_add_stable_recruit_order(requestId, JSON.stringify(req));
695
856
  });
696
857
  }
697
- drain() {
698
- if (this.disposed) return;
699
- this.clearTimeout();
700
- try {
701
- for (let i = 0; i < Queue.LIMIT_PER_TICK; i++) if (!this.poll()) break;
702
- } catch (err) {
703
- this.emitter.emit("error", err);
704
- }
705
- this.timer = setTimeout(() => this.drain(), Queue.POLL_INTERVAL);
858
+ async addWorkshopRecruitOrder(req) {
859
+ return this.queue.request((requestId) => {
860
+ this.functions.nil_add_workshop_recruit_order(requestId, JSON.stringify(req));
861
+ });
706
862
  }
707
- poll() {
708
- const out = allocBuffer();
709
- const status = this.functions.nil_ffi_poll(out);
710
- if (status === ffi_Status.ERR_NOTHING_TO_POLL) return false;
711
- if (status !== ffi_Status.OK) throw NilError.fromStatus(status);
712
- const ptr = readBufferPtr(out);
713
- if (ptr === 0n) throw new Error("failed to poll: unexpected null pointer");
714
- try {
715
- const json = ffi.toString(ptr) ?? "";
716
- const entry = JSON.parse(json);
717
- this.dispatch(entry);
718
- } finally {
719
- this.functions.nil_ffi_free_str(ptr);
720
- }
721
- return true;
863
+ async authorize(req) {
864
+ return this.queue.request((requestId) => {
865
+ this.functions.nil_authorize(requestId, JSON.stringify(req));
866
+ });
867
+ }
868
+ async cancelAcademyRecruitOrder(req) {
869
+ return this.queue.request((requestId) => {
870
+ this.functions.nil_cancel_academy_recruit_order(requestId, JSON.stringify(req));
871
+ });
872
+ }
873
+ async cancelManeuver(req) {
874
+ return this.queue.request((requestId) => {
875
+ this.functions.nil_cancel_maneuver(requestId, JSON.stringify(req));
876
+ });
877
+ }
878
+ async cancelPrefectureBuildOrder(req) {
879
+ return this.queue.request((requestId) => {
880
+ this.functions.nil_cancel_prefecture_build_order(requestId, JSON.stringify(req));
881
+ });
882
+ }
883
+ async cancelStableRecruitOrder(req) {
884
+ return this.queue.request((requestId) => {
885
+ this.functions.nil_cancel_stable_recruit_order(requestId, JSON.stringify(req));
886
+ });
887
+ }
888
+ async cancelWorkshopRecruitOrder(req) {
889
+ return this.queue.request((requestId) => {
890
+ this.functions.nil_cancel_workshop_recruit_order(requestId, JSON.stringify(req));
891
+ });
892
+ }
893
+ async cheatFillWorld(req) {
894
+ return this.queue.request((requestId) => {
895
+ this.functions.nil_cheat_fill_world(requestId, JSON.stringify(req));
896
+ });
897
+ }
898
+ async cheatGetAcademyRecruitQueue(req) {
899
+ return this.queue.request((requestId) => {
900
+ this.functions.nil_cheat_get_academy_recruit_queue(requestId, JSON.stringify(req));
901
+ });
902
+ }
903
+ async cheatGetAcademyRecruitQueues(req) {
904
+ return this.queue.request((requestId) => {
905
+ this.functions.nil_cheat_get_academy_recruit_queues(requestId, JSON.stringify(req));
906
+ });
907
+ }
908
+ async cheatGetAllAcademyRecruitQueues(req) {
909
+ return this.queue.request((requestId) => {
910
+ this.functions.nil_cheat_get_all_academy_recruit_queues(requestId, JSON.stringify(req));
911
+ });
912
+ }
913
+ async cheatGetAllPrefectureBuildQueues(req) {
914
+ return this.queue.request((requestId) => {
915
+ this.functions.nil_cheat_get_all_prefecture_build_queues(requestId, JSON.stringify(req));
916
+ });
917
+ }
918
+ async cheatGetAllStableRecruitQueues(req) {
919
+ return this.queue.request((requestId) => {
920
+ this.functions.nil_cheat_get_all_stable_recruit_queues(requestId, JSON.stringify(req));
921
+ });
922
+ }
923
+ async cheatGetBuildSteps(req) {
924
+ return this.queue.request((requestId) => {
925
+ this.functions.nil_cheat_get_build_steps(requestId, JSON.stringify(req));
926
+ });
927
+ }
928
+ async cheatGetCities(req) {
929
+ return this.queue.request((requestId) => {
930
+ this.functions.nil_cheat_get_cities(requestId, JSON.stringify(req));
931
+ });
932
+ }
933
+ async cheatGetCity(req) {
934
+ return this.queue.request((requestId) => {
935
+ this.functions.nil_cheat_get_city(requestId, JSON.stringify(req));
936
+ });
937
+ }
938
+ async cheatGetEthics(req) {
939
+ return this.queue.request((requestId) => {
940
+ this.functions.nil_cheat_get_ethics(requestId, JSON.stringify(req));
941
+ });
942
+ }
943
+ async cheatGetIdleArmiesAt(req) {
944
+ return this.queue.request((requestId) => {
945
+ this.functions.nil_cheat_get_idle_armies_at(requestId, JSON.stringify(req));
946
+ });
947
+ }
948
+ async cheatGetIdlePersonnelAt(req) {
949
+ return this.queue.request((requestId) => {
950
+ this.functions.nil_cheat_get_idle_personnel_at(requestId, JSON.stringify(req));
951
+ });
952
+ }
953
+ async cheatGetInfrastructure(req) {
954
+ return this.queue.request((requestId) => {
955
+ this.functions.nil_cheat_get_infrastructure(requestId, JSON.stringify(req));
956
+ });
957
+ }
958
+ async cheatGetManeuvers(req) {
959
+ return this.queue.request((requestId) => {
960
+ this.functions.nil_cheat_get_maneuvers(requestId, JSON.stringify(req));
961
+ });
962
+ }
963
+ async cheatGetManeuversOf(req) {
964
+ return this.queue.request((requestId) => {
965
+ this.functions.nil_cheat_get_maneuvers_of(requestId, JSON.stringify(req));
966
+ });
967
+ }
968
+ async cheatGetPlayer(req) {
969
+ return this.queue.request((requestId) => {
970
+ this.functions.nil_cheat_get_player(requestId, JSON.stringify(req));
971
+ });
972
+ }
973
+ async cheatGetPlayers(req) {
974
+ return this.queue.request((requestId) => {
975
+ this.functions.nil_cheat_get_players(requestId, JSON.stringify(req));
976
+ });
977
+ }
978
+ async cheatGetPrefectureBuildQueue(req) {
979
+ return this.queue.request((requestId) => {
980
+ this.functions.nil_cheat_get_prefecture_build_queue(requestId, JSON.stringify(req));
981
+ });
982
+ }
983
+ async cheatGetPrefectureBuildQueues(req) {
984
+ return this.queue.request((requestId) => {
985
+ this.functions.nil_cheat_get_prefecture_build_queues(requestId, JSON.stringify(req));
986
+ });
987
+ }
988
+ async cheatGetResources(req) {
989
+ return this.queue.request((requestId) => {
990
+ this.functions.nil_cheat_get_resources(requestId, JSON.stringify(req));
991
+ });
992
+ }
993
+ async cheatGetStableRecruitQueue(req) {
994
+ return this.queue.request((requestId) => {
995
+ this.functions.nil_cheat_get_stable_recruit_queue(requestId, JSON.stringify(req));
996
+ });
997
+ }
998
+ async cheatGetStableRecruitQueues(req) {
999
+ return this.queue.request((requestId) => {
1000
+ this.functions.nil_cheat_get_stable_recruit_queues(requestId, JSON.stringify(req));
1001
+ });
1002
+ }
1003
+ async cheatGetStorageCapacity(req) {
1004
+ return this.queue.request((requestId) => {
1005
+ this.functions.nil_cheat_get_storage_capacity(requestId, JSON.stringify(req));
1006
+ });
1007
+ }
1008
+ async cheatSetBotEthics(req) {
1009
+ return this.queue.request((requestId) => {
1010
+ this.functions.nil_cheat_set_bot_ethics(requestId, JSON.stringify(req));
1011
+ });
1012
+ }
1013
+ async cheatSetBuildingLevel(req) {
1014
+ return this.queue.request((requestId) => {
1015
+ this.functions.nil_cheat_set_building_level(requestId, JSON.stringify(req));
1016
+ });
1017
+ }
1018
+ async cheatSetFood(req) {
1019
+ return this.queue.request((requestId) => {
1020
+ this.functions.nil_cheat_set_food(requestId, JSON.stringify(req));
1021
+ });
1022
+ }
1023
+ async cheatSetIron(req) {
1024
+ return this.queue.request((requestId) => {
1025
+ this.functions.nil_cheat_set_iron(requestId, JSON.stringify(req));
1026
+ });
1027
+ }
1028
+ async cheatSetMarketFee(req) {
1029
+ return this.queue.request((requestId) => {
1030
+ this.functions.nil_cheat_set_market_fee(requestId, JSON.stringify(req));
1031
+ });
1032
+ }
1033
+ async cheatSetMaxFood(req) {
1034
+ return this.queue.request((requestId) => {
1035
+ this.functions.nil_cheat_set_max_food(requestId, JSON.stringify(req));
1036
+ });
1037
+ }
1038
+ async cheatSetMaxInfrastructure(req) {
1039
+ return this.queue.request((requestId) => {
1040
+ this.functions.nil_cheat_set_max_infrastructure(requestId, JSON.stringify(req));
1041
+ });
1042
+ }
1043
+ async cheatSetMaxIron(req) {
1044
+ return this.queue.request((requestId) => {
1045
+ this.functions.nil_cheat_set_max_iron(requestId, JSON.stringify(req));
1046
+ });
1047
+ }
1048
+ async cheatSetMaxResources(req) {
1049
+ return this.queue.request((requestId) => {
1050
+ this.functions.nil_cheat_set_max_resources(requestId, JSON.stringify(req));
1051
+ });
1052
+ }
1053
+ async cheatSetMaxSiloResources(req) {
1054
+ return this.queue.request((requestId) => {
1055
+ this.functions.nil_cheat_set_max_silo_resources(requestId, JSON.stringify(req));
1056
+ });
1057
+ }
1058
+ async cheatSetMaxStone(req) {
1059
+ return this.queue.request((requestId) => {
1060
+ this.functions.nil_cheat_set_max_stone(requestId, JSON.stringify(req));
1061
+ });
1062
+ }
1063
+ async cheatSetMaxWarehouseResources(req) {
1064
+ return this.queue.request((requestId) => {
1065
+ this.functions.nil_cheat_set_max_warehouse_resources(requestId, JSON.stringify(req));
1066
+ });
1067
+ }
1068
+ async cheatSetMaxWood(req) {
1069
+ return this.queue.request((requestId) => {
1070
+ this.functions.nil_cheat_set_max_wood(requestId, JSON.stringify(req));
1071
+ });
1072
+ }
1073
+ async cheatSetResources(req) {
1074
+ return this.queue.request((requestId) => {
1075
+ this.functions.nil_cheat_set_resources(requestId, JSON.stringify(req));
1076
+ });
1077
+ }
1078
+ async cheatSetStability(req) {
1079
+ return this.queue.request((requestId) => {
1080
+ this.functions.nil_cheat_set_stability(requestId, JSON.stringify(req));
1081
+ });
1082
+ }
1083
+ async cheatSetStone(req) {
1084
+ return this.queue.request((requestId) => {
1085
+ this.functions.nil_cheat_set_stone(requestId, JSON.stringify(req));
1086
+ });
1087
+ }
1088
+ async cheatSetWood(req) {
1089
+ return this.queue.request((requestId) => {
1090
+ this.functions.nil_cheat_set_wood(requestId, JSON.stringify(req));
1091
+ });
1092
+ }
1093
+ async cheatSkipRound(req) {
1094
+ return this.queue.request((requestId) => {
1095
+ this.functions.nil_cheat_skip_round(requestId, JSON.stringify(req));
1096
+ });
1097
+ }
1098
+ async cheatSpawnBot(req) {
1099
+ return this.queue.request((requestId) => {
1100
+ this.functions.nil_cheat_spawn_bot(requestId, JSON.stringify(req));
1101
+ });
1102
+ }
1103
+ async cheatSpawnCity(req) {
1104
+ return this.queue.request((requestId) => {
1105
+ this.functions.nil_cheat_spawn_city(requestId, JSON.stringify(req));
1106
+ });
1107
+ }
1108
+ async cheatSpawnPersonnel(req) {
1109
+ return this.queue.request((requestId) => {
1110
+ this.functions.nil_cheat_spawn_personnel(requestId, JSON.stringify(req));
1111
+ });
1112
+ }
1113
+ async createRemoteWorld(req) {
1114
+ return this.queue.request((requestId) => {
1115
+ this.functions.nil_create_remote_world(requestId, JSON.stringify(req));
1116
+ });
1117
+ }
1118
+ async createUser(req) {
1119
+ return this.queue.request((requestId) => {
1120
+ this.functions.nil_create_user(requestId, JSON.stringify(req));
1121
+ });
1122
+ }
1123
+ async deleteRemoteWorld(req) {
1124
+ return this.queue.request((requestId) => {
1125
+ this.functions.nil_delete_remote_world(requestId, JSON.stringify(req));
1126
+ });
722
1127
  }
723
- dispatch(entry) {
724
- switch (entry.kind) {
725
- case "response": {
726
- const response = JSON.parse(entry.jsonStr);
727
- this.emitter.emit("response", response);
728
- break;
729
- }
730
- }
1128
+ async forwardReport(req) {
1129
+ return this.queue.request((requestId) => {
1130
+ this.functions.nil_forward_report(requestId, JSON.stringify(req));
1131
+ });
731
1132
  }
732
- rejectAll(error) {
733
- this.clearTimeout();
734
- this.pendingRequests.values().forEach(({ reject }) => reject(error));
735
- this.pendingRequests.clear();
1133
+ async getAcademyRecruitCatalog(req) {
1134
+ return this.queue.request((requestId) => {
1135
+ this.functions.nil_get_academy_recruit_catalog(requestId, JSON.stringify(req));
1136
+ });
736
1137
  }
737
- clearTimeout() {
738
- if (!isNil(this.timer)) {
739
- clearTimeout(this.timer);
740
- this.timer = null;
741
- }
1138
+ async getArmies(req) {
1139
+ return this.queue.request((requestId) => {
1140
+ this.functions.nil_get_armies(requestId, JSON.stringify(req));
1141
+ });
742
1142
  }
743
- onResponse(response) {
744
- const pending = this.pendingRequests.get(response.id);
745
- if (pending) {
746
- this.pendingRequests.delete(response.id);
747
- if (response.kind === "ok") pending.resolve(response.data);
748
- else {
749
- const { status, error } = response;
750
- pending.reject(new NilError(error, { status }));
751
- }
752
- } else this.emitter.emit("error", new UnknownResponseError(response));
1143
+ async getArmy(req) {
1144
+ return this.queue.request((requestId) => {
1145
+ this.functions.nil_get_army(requestId, JSON.stringify(req));
1146
+ });
753
1147
  }
754
- };
755
- //#endregion
756
- //#region package.json
757
- var version = "0.7.10";
758
- //#endregion
759
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
760
- function __decorate(decorators, target, key, desc) {
761
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
762
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
763
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
764
- return c > 3 && r && Object.defineProperty(target, key, r), r;
765
- }
766
- //#endregion
767
- //#region src/index.ts
768
- //! Copyright (C) Call of Nil contributors
769
- //! SPDX-License-Identifier: AGPL-3.0-only
770
- var VERSION = version;
771
- var USER_AGENT = `nil-ffi-node/${VERSION}`;
772
- var Nil = class Nil {
773
- constructor(dll, options) {
774
- this.closed = false;
775
- if (!dll.endsWith(ffi.suffix)) dll = `${dll}.${ffi.suffix}`;
776
- this.path = path.resolve(dll);
777
- this.handle = ffi.dlopen(dll, definitions);
778
- this.functions = this.handle.functions;
779
- this.queue = new Queue(this.handle, options);
1148
+ async getArmyOwner(req) {
1149
+ return this.queue.request((requestId) => {
1150
+ this.functions.nil_get_army_owner(requestId, JSON.stringify(req));
1151
+ });
780
1152
  }
781
- async [Symbol.asyncDispose]() {
782
- await this.close();
1153
+ async getBotCoords(req) {
1154
+ return this.queue.request((requestId) => {
1155
+ this.functions.nil_get_bot_coords(requestId, JSON.stringify(req));
1156
+ });
783
1157
  }
784
- async #close() {
785
- if (this.closed) return;
786
- this.closed = true;
787
- await attemptAsync(this.stopClient.bind(this));
788
- await attemptAsync(this.stopServer.bind(this));
789
- this.queue[Symbol.dispose]();
790
- this.functions.nil_ffi_shutdown();
791
- this.handle[Symbol.dispose]();
1158
+ async getChatHistory(req) {
1159
+ return this.queue.request((requestId) => {
1160
+ this.functions.nil_get_chat_history(requestId, JSON.stringify(req));
1161
+ });
792
1162
  }
793
- async close() {
794
- this.closePromise ??= this.#close();
795
- return this.closePromise;
1163
+ async getCities(req) {
1164
+ return this.queue.request((requestId) => {
1165
+ this.functions.nil_get_cities(requestId, JSON.stringify(req));
1166
+ });
796
1167
  }
797
- isClosed() {
798
- return this.closed;
1168
+ async getCity(req) {
1169
+ return this.queue.request((requestId) => {
1170
+ this.functions.nil_get_city(requestId, JSON.stringify(req));
1171
+ });
799
1172
  }
800
- async authorize(req) {
1173
+ async getCityScore(req) {
801
1174
  return this.queue.request((requestId) => {
802
- this.functions.nil_authorize(requestId, JSON.stringify(req));
1175
+ this.functions.nil_get_city_score(requestId, JSON.stringify(req));
803
1176
  });
804
1177
  }
805
1178
  async getClientVersion() {
@@ -807,26 +1180,156 @@ var Nil = class Nil {
807
1180
  this.functions.nil_client_version(requestId);
808
1181
  });
809
1182
  }
1183
+ async getContinentSize(req) {
1184
+ return this.queue.request((requestId) => {
1185
+ this.functions.nil_get_continent_size(requestId, JSON.stringify(req));
1186
+ });
1187
+ }
810
1188
  async getFfiVersion() {
811
1189
  return this.queue.request((requestId) => {
812
1190
  this.functions.nil_ffi_version(requestId);
813
1191
  });
814
1192
  }
1193
+ async getIdleArmiesAt(req) {
1194
+ return this.queue.request((requestId) => {
1195
+ this.functions.nil_get_idle_armies_at(requestId, JSON.stringify(req));
1196
+ });
1197
+ }
1198
+ async getIdleArmiesCoords(req) {
1199
+ return this.queue.request((requestId) => {
1200
+ this.functions.nil_get_idle_armies_coords(requestId, JSON.stringify(req));
1201
+ });
1202
+ }
1203
+ async getManeuver(req) {
1204
+ return this.queue.request((requestId) => {
1205
+ this.functions.nil_get_maneuver(requestId, JSON.stringify(req));
1206
+ });
1207
+ }
1208
+ async getMarket(req) {
1209
+ return this.queue.request((requestId) => {
1210
+ this.functions.nil_get_market(requestId, JSON.stringify(req));
1211
+ });
1212
+ }
1213
+ async getMarketFee(req) {
1214
+ return this.queue.request((requestId) => {
1215
+ this.functions.nil_get_market_fee(requestId, JSON.stringify(req));
1216
+ });
1217
+ }
815
1218
  async getPlayer(req) {
816
1219
  return this.queue.request((requestId) => {
817
1220
  this.functions.nil_get_player(requestId, JSON.stringify(req));
818
1221
  });
819
1222
  }
1223
+ async getPlayerCoords(req) {
1224
+ return this.queue.request((requestId) => {
1225
+ this.functions.nil_get_player_coords(requestId, JSON.stringify(req));
1226
+ });
1227
+ }
820
1228
  async getPlayerIds(req) {
821
1229
  return this.queue.request((requestId) => {
822
1230
  this.functions.nil_get_player_ids(requestId, JSON.stringify(req));
823
1231
  });
824
1232
  }
1233
+ async getPlayerMaintenance(req) {
1234
+ return this.queue.request((requestId) => {
1235
+ this.functions.nil_get_player_maintenance(requestId, JSON.stringify(req));
1236
+ });
1237
+ }
1238
+ async getPlayerMilitary(req) {
1239
+ return this.queue.request((requestId) => {
1240
+ this.functions.nil_get_player_military(requestId, JSON.stringify(req));
1241
+ });
1242
+ }
825
1243
  async getPlayerStatus(req) {
826
1244
  return this.queue.request((requestId) => {
827
1245
  this.functions.nil_get_player_status(requestId, JSON.stringify(req));
828
1246
  });
829
1247
  }
1248
+ async getPlayerStorageCapacity(req) {
1249
+ return this.queue.request((requestId) => {
1250
+ this.functions.nil_get_player_storage_capacity(requestId, JSON.stringify(req));
1251
+ });
1252
+ }
1253
+ async getPlayerWorlds(req) {
1254
+ return this.queue.request((requestId) => {
1255
+ this.functions.nil_get_player_worlds(requestId, JSON.stringify(req));
1256
+ });
1257
+ }
1258
+ async getPrecursorCoords(req) {
1259
+ return this.queue.request((requestId) => {
1260
+ this.functions.nil_get_precursor_coords(requestId, JSON.stringify(req));
1261
+ });
1262
+ }
1263
+ async getPrefectureBuildCatalog(req) {
1264
+ return this.queue.request((requestId) => {
1265
+ this.functions.nil_get_prefecture_build_catalog(requestId, JSON.stringify(req));
1266
+ });
1267
+ }
1268
+ async getPublicBot(req) {
1269
+ return this.queue.request((requestId) => {
1270
+ this.functions.nil_get_public_bot(requestId, JSON.stringify(req));
1271
+ });
1272
+ }
1273
+ async getPublicBots(req) {
1274
+ return this.queue.request((requestId) => {
1275
+ this.functions.nil_get_public_bots(requestId, JSON.stringify(req));
1276
+ });
1277
+ }
1278
+ async getPublicCities(req) {
1279
+ return this.queue.request((requestId) => {
1280
+ this.functions.nil_get_public_cities(requestId, JSON.stringify(req));
1281
+ });
1282
+ }
1283
+ async getPublicCity(req) {
1284
+ return this.queue.request((requestId) => {
1285
+ this.functions.nil_get_public_city(requestId, JSON.stringify(req));
1286
+ });
1287
+ }
1288
+ async getPublicField(req) {
1289
+ return this.queue.request((requestId) => {
1290
+ this.functions.nil_get_public_field(requestId, JSON.stringify(req));
1291
+ });
1292
+ }
1293
+ async getPublicFields(req) {
1294
+ return this.queue.request((requestId) => {
1295
+ this.functions.nil_get_public_fields(requestId, JSON.stringify(req));
1296
+ });
1297
+ }
1298
+ async getPublicPlayer(req) {
1299
+ return this.queue.request((requestId) => {
1300
+ this.functions.nil_get_public_player(requestId, JSON.stringify(req));
1301
+ });
1302
+ }
1303
+ async getPublicPlayers(req) {
1304
+ return this.queue.request((requestId) => {
1305
+ this.functions.nil_get_public_players(requestId, JSON.stringify(req));
1306
+ });
1307
+ }
1308
+ async getPublicPrecursor(req) {
1309
+ return this.queue.request((requestId) => {
1310
+ this.functions.nil_get_public_precursor(requestId, JSON.stringify(req));
1311
+ });
1312
+ }
1313
+ async getPublicPrecursors(req) {
1314
+ return this.queue.request((requestId) => {
1315
+ this.functions.nil_get_public_precursors(requestId, JSON.stringify(req));
1316
+ });
1317
+ }
1318
+ async getRank(req) {
1319
+ return this.queue.request((requestId) => {
1320
+ this.functions.nil_get_rank(requestId, JSON.stringify(req));
1321
+ });
1322
+ }
1323
+ async getRanking(req) {
1324
+ return this.queue.request((requestId) => {
1325
+ this.functions.nil_get_ranking(requestId, JSON.stringify(req));
1326
+ });
1327
+ }
1328
+ async getRemoteWorld(req) {
1329
+ return this.queue.request((requestId) => {
1330
+ this.functions.nil_get_remote_world(requestId, JSON.stringify(req));
1331
+ });
1332
+ }
830
1333
  async getRemoteWorldLimit() {
831
1334
  return this.queue.request((requestId) => {
832
1335
  this.functions.nil_get_remote_world_limit(requestId);
@@ -842,6 +1345,16 @@ var Nil = class Nil {
842
1345
  this.functions.nil_get_remote_worlds(requestId);
843
1346
  });
844
1347
  }
1348
+ async getRound(req) {
1349
+ return this.queue.request((requestId) => {
1350
+ this.functions.nil_get_round(requestId, JSON.stringify(req));
1351
+ });
1352
+ }
1353
+ async getRuntimeGlobalQueueDepth() {
1354
+ return this.queue.request((requestId) => {
1355
+ this.functions.nil_runtime_global_queue_depth(requestId);
1356
+ });
1357
+ }
845
1358
  async getRuntimeNumAliveTasks() {
846
1359
  return this.queue.request((requestId) => {
847
1360
  this.functions.nil_runtime_num_alive_tasks(requestId);
@@ -862,16 +1375,66 @@ var Nil = class Nil {
862
1375
  this.functions.nil_get_server_kind(requestId);
863
1376
  });
864
1377
  }
1378
+ async getServerVersion() {
1379
+ return this.queue.request((requestId) => {
1380
+ this.functions.nil_server_version(requestId);
1381
+ });
1382
+ }
1383
+ async getStableRecruitCatalog(req) {
1384
+ return this.queue.request((requestId) => {
1385
+ this.functions.nil_get_stable_recruit_catalog(requestId, JSON.stringify(req));
1386
+ });
1387
+ }
865
1388
  async getUserAgent() {
866
1389
  return this.queue.request((requestId) => {
867
1390
  this.functions.nil_user_agent(requestId);
868
1391
  });
869
1392
  }
1393
+ async getWorkshopRecruitCatalog(req) {
1394
+ return this.queue.request((requestId) => {
1395
+ this.functions.nil_get_workshop_recruit_catalog(requestId, JSON.stringify(req));
1396
+ });
1397
+ }
1398
+ async getWorldBots(req) {
1399
+ return this.queue.request((requestId) => {
1400
+ this.functions.nil_get_world_bots(requestId, JSON.stringify(req));
1401
+ });
1402
+ }
1403
+ async getWorldConfig(req) {
1404
+ return this.queue.request((requestId) => {
1405
+ this.functions.nil_get_world_config(requestId, JSON.stringify(req));
1406
+ });
1407
+ }
870
1408
  async getWorldId() {
871
1409
  return this.queue.request((requestId) => {
872
1410
  this.functions.nil_world(requestId);
873
1411
  });
874
1412
  }
1413
+ async getWorldPersonnel(req) {
1414
+ return this.queue.request((requestId) => {
1415
+ this.functions.nil_get_world_personnel(requestId, JSON.stringify(req));
1416
+ });
1417
+ }
1418
+ async getWorldPlayers(req) {
1419
+ return this.queue.request((requestId) => {
1420
+ this.functions.nil_get_world_players(requestId, JSON.stringify(req));
1421
+ });
1422
+ }
1423
+ async getWorldPrecursors(req) {
1424
+ return this.queue.request((requestId) => {
1425
+ this.functions.nil_get_world_precursors(requestId, JSON.stringify(req));
1426
+ });
1427
+ }
1428
+ async getWorldRulers(req) {
1429
+ return this.queue.request((requestId) => {
1430
+ this.functions.nil_get_world_rulers(requestId, JSON.stringify(req));
1431
+ });
1432
+ }
1433
+ async getWorldStats(req) {
1434
+ return this.queue.request((requestId) => {
1435
+ this.functions.nil_get_world_stats(requestId, JSON.stringify(req));
1436
+ });
1437
+ }
875
1438
  async isHost() {
876
1439
  return this.queue.request((requestId) => {
877
1440
  this.functions.nil_is_host(requestId);
@@ -897,6 +1460,46 @@ var Nil = class Nil {
897
1460
  this.functions.nil_player_exists(requestId, JSON.stringify(req));
898
1461
  });
899
1462
  }
1463
+ async pushChatMessage(req) {
1464
+ return this.queue.request((requestId) => {
1465
+ this.functions.nil_push_chat_message(requestId, JSON.stringify(req));
1466
+ });
1467
+ }
1468
+ async renameCity(req) {
1469
+ return this.queue.request((requestId) => {
1470
+ this.functions.nil_rename_city(requestId, JSON.stringify(req));
1471
+ });
1472
+ }
1473
+ async requestManeuver(req) {
1474
+ return this.queue.request((requestId) => {
1475
+ this.functions.nil_request_maneuver(requestId, JSON.stringify(req));
1476
+ });
1477
+ }
1478
+ async saveLocalWorld(req) {
1479
+ return this.queue.request((requestId) => {
1480
+ this.functions.nil_save_local_world(requestId, JSON.stringify(req));
1481
+ });
1482
+ }
1483
+ async searchCity(req) {
1484
+ return this.queue.request((requestId) => {
1485
+ this.functions.nil_search_city(requestId, JSON.stringify(req));
1486
+ });
1487
+ }
1488
+ async searchPublicCity(req) {
1489
+ return this.queue.request((requestId) => {
1490
+ this.functions.nil_search_public_city(requestId, JSON.stringify(req));
1491
+ });
1492
+ }
1493
+ async sendResources(req) {
1494
+ return this.queue.request((requestId) => {
1495
+ this.functions.nil_send_resources(requestId, JSON.stringify(req));
1496
+ });
1497
+ }
1498
+ async setPlayerReady(req) {
1499
+ return this.queue.request((requestId) => {
1500
+ this.functions.nil_set_player_ready(requestId, JSON.stringify(req));
1501
+ });
1502
+ }
900
1503
  async setPlayerStatus(req) {
901
1504
  return this.queue.request((requestId) => {
902
1505
  this.functions.nil_set_player_status(requestId, JSON.stringify(req));
@@ -907,11 +1510,21 @@ var Nil = class Nil {
907
1510
  this.functions.nil_set_user_agent(requestId, JSON.stringify(userAgent));
908
1511
  });
909
1512
  }
1513
+ async simulateBattle(req) {
1514
+ return this.queue.request((requestId) => {
1515
+ this.functions.nil_simulate_battle(requestId, JSON.stringify(req));
1516
+ });
1517
+ }
910
1518
  async spawnPlayer(req) {
911
1519
  return this.queue.request((requestId) => {
912
1520
  this.functions.nil_spawn_player(requestId, JSON.stringify(req));
913
1521
  });
914
1522
  }
1523
+ async startRound(req) {
1524
+ return this.queue.request((requestId) => {
1525
+ this.functions.nil_start_round(requestId, JSON.stringify(req));
1526
+ });
1527
+ }
915
1528
  async startServer(options) {
916
1529
  return this.queue.request((requestId) => {
917
1530
  this.functions.nil_start_server(requestId, JSON.stringify(options));
@@ -932,64 +1545,171 @@ var Nil = class Nil {
932
1545
  this.functions.nil_stop_server(requestId);
933
1546
  });
934
1547
  }
1548
+ async toggleBuilding(req) {
1549
+ return this.queue.request((requestId) => {
1550
+ this.functions.nil_toggle_building(requestId, JSON.stringify(req));
1551
+ });
1552
+ }
935
1553
  async updateClient(options) {
936
1554
  return this.queue.request((requestId) => {
937
1555
  this.functions.nil_update_client(requestId, JSON.stringify(options));
938
1556
  });
939
1557
  }
1558
+ async userExists(req) {
1559
+ return this.queue.request((requestId) => {
1560
+ this.functions.nil_user_exists(requestId, JSON.stringify(req));
1561
+ });
1562
+ }
940
1563
  async validateToken(req) {
941
1564
  return this.queue.request((requestId) => {
942
1565
  this.functions.nil_validate_token(requestId, JSON.stringify(req));
943
1566
  });
944
1567
  }
945
- static async init(dll, options) {
946
- const nil = new Nil(dll, options);
947
- await nil.setUserAgent(USER_AGENT);
948
- return nil;
949
- }
950
- static async initLatest(options) {
951
- const dll = await this.downloadLatest(options);
952
- return this.init(dll, options);
953
- }
954
- static async downloadLatest(options) {
955
- const file = `libnil.${ffi.suffix}`;
956
- const filePath = path.resolve(options?.outDir ?? cwd(), file);
957
- if (!(options?.overwrite ?? true) && existsSync(filePath)) return filePath;
958
- const response = await fetch(`https://tsukilabs.dev.br/download/nil/${file}`, { headers: { "User-Agent": USER_AGENT } });
959
- if (!response.ok) throw new Error(`failed to download ${file}: ${response.status} ${response.statusText}`);
960
- const bytes = await response.bytes();
961
- await fs.writeFile(filePath, bytes);
962
- return filePath;
963
- }
964
1568
  };
1569
+ __decorate([ThrowIfClosed], Nil.prototype, "addAcademyRecruitOrder", null);
1570
+ __decorate([ThrowIfClosed], Nil.prototype, "addPrefectureBuildOrder", null);
1571
+ __decorate([ThrowIfClosed], Nil.prototype, "addStableRecruitOrder", null);
1572
+ __decorate([ThrowIfClosed], Nil.prototype, "addWorkshopRecruitOrder", null);
965
1573
  __decorate([ThrowIfClosed], Nil.prototype, "authorize", null);
1574
+ __decorate([ThrowIfClosed], Nil.prototype, "cancelAcademyRecruitOrder", null);
1575
+ __decorate([ThrowIfClosed], Nil.prototype, "cancelManeuver", null);
1576
+ __decorate([ThrowIfClosed], Nil.prototype, "cancelPrefectureBuildOrder", null);
1577
+ __decorate([ThrowIfClosed], Nil.prototype, "cancelStableRecruitOrder", null);
1578
+ __decorate([ThrowIfClosed], Nil.prototype, "cancelWorkshopRecruitOrder", null);
1579
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatFillWorld", null);
1580
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetAcademyRecruitQueue", null);
1581
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetAcademyRecruitQueues", null);
1582
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetAllAcademyRecruitQueues", null);
1583
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetAllPrefectureBuildQueues", null);
1584
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetAllStableRecruitQueues", null);
1585
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetBuildSteps", null);
1586
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetCities", null);
1587
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetCity", null);
1588
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetEthics", null);
1589
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetIdleArmiesAt", null);
1590
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetIdlePersonnelAt", null);
1591
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetInfrastructure", null);
1592
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetManeuvers", null);
1593
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetManeuversOf", null);
1594
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetPlayer", null);
1595
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetPlayers", null);
1596
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetPrefectureBuildQueue", null);
1597
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetPrefectureBuildQueues", null);
1598
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetResources", null);
1599
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetStableRecruitQueue", null);
1600
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetStableRecruitQueues", null);
1601
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatGetStorageCapacity", null);
1602
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetBotEthics", null);
1603
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetBuildingLevel", null);
1604
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetFood", null);
1605
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetIron", null);
1606
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMarketFee", null);
1607
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMaxFood", null);
1608
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMaxInfrastructure", null);
1609
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMaxIron", null);
1610
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMaxResources", null);
1611
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMaxSiloResources", null);
1612
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMaxStone", null);
1613
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMaxWarehouseResources", null);
1614
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetMaxWood", null);
1615
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetResources", null);
1616
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetStability", null);
1617
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetStone", null);
1618
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSetWood", null);
1619
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSkipRound", null);
1620
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSpawnBot", null);
1621
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSpawnCity", null);
1622
+ __decorate([ThrowIfClosed], Nil.prototype, "cheatSpawnPersonnel", null);
1623
+ __decorate([ThrowIfClosed], Nil.prototype, "createRemoteWorld", null);
1624
+ __decorate([ThrowIfClosed], Nil.prototype, "createUser", null);
1625
+ __decorate([ThrowIfClosed], Nil.prototype, "deleteRemoteWorld", null);
1626
+ __decorate([ThrowIfClosed], Nil.prototype, "forwardReport", null);
1627
+ __decorate([ThrowIfClosed], Nil.prototype, "getAcademyRecruitCatalog", null);
1628
+ __decorate([ThrowIfClosed], Nil.prototype, "getArmies", null);
1629
+ __decorate([ThrowIfClosed], Nil.prototype, "getArmy", null);
1630
+ __decorate([ThrowIfClosed], Nil.prototype, "getArmyOwner", null);
1631
+ __decorate([ThrowIfClosed], Nil.prototype, "getBotCoords", null);
1632
+ __decorate([ThrowIfClosed], Nil.prototype, "getChatHistory", null);
1633
+ __decorate([ThrowIfClosed], Nil.prototype, "getCities", null);
1634
+ __decorate([ThrowIfClosed], Nil.prototype, "getCity", null);
1635
+ __decorate([ThrowIfClosed], Nil.prototype, "getCityScore", null);
966
1636
  __decorate([ThrowIfClosed], Nil.prototype, "getClientVersion", null);
1637
+ __decorate([ThrowIfClosed], Nil.prototype, "getContinentSize", null);
967
1638
  __decorate([ThrowIfClosed], Nil.prototype, "getFfiVersion", null);
1639
+ __decorate([ThrowIfClosed], Nil.prototype, "getIdleArmiesAt", null);
1640
+ __decorate([ThrowIfClosed], Nil.prototype, "getIdleArmiesCoords", null);
1641
+ __decorate([ThrowIfClosed], Nil.prototype, "getManeuver", null);
1642
+ __decorate([ThrowIfClosed], Nil.prototype, "getMarket", null);
1643
+ __decorate([ThrowIfClosed], Nil.prototype, "getMarketFee", null);
968
1644
  __decorate([ThrowIfClosed], Nil.prototype, "getPlayer", null);
1645
+ __decorate([ThrowIfClosed], Nil.prototype, "getPlayerCoords", null);
969
1646
  __decorate([ThrowIfClosed], Nil.prototype, "getPlayerIds", null);
1647
+ __decorate([ThrowIfClosed], Nil.prototype, "getPlayerMaintenance", null);
1648
+ __decorate([ThrowIfClosed], Nil.prototype, "getPlayerMilitary", null);
970
1649
  __decorate([ThrowIfClosed], Nil.prototype, "getPlayerStatus", null);
1650
+ __decorate([ThrowIfClosed], Nil.prototype, "getPlayerStorageCapacity", null);
1651
+ __decorate([ThrowIfClosed], Nil.prototype, "getPlayerWorlds", null);
1652
+ __decorate([ThrowIfClosed], Nil.prototype, "getPrecursorCoords", null);
1653
+ __decorate([ThrowIfClosed], Nil.prototype, "getPrefectureBuildCatalog", null);
1654
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicBot", null);
1655
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicBots", null);
1656
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicCities", null);
1657
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicCity", null);
1658
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicField", null);
1659
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicFields", null);
1660
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicPlayer", null);
1661
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicPlayers", null);
1662
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicPrecursor", null);
1663
+ __decorate([ThrowIfClosed], Nil.prototype, "getPublicPrecursors", null);
1664
+ __decorate([ThrowIfClosed], Nil.prototype, "getRank", null);
1665
+ __decorate([ThrowIfClosed], Nil.prototype, "getRanking", null);
1666
+ __decorate([ThrowIfClosed], Nil.prototype, "getRemoteWorld", null);
971
1667
  __decorate([ThrowIfClosed], Nil.prototype, "getRemoteWorldLimit", null);
972
1668
  __decorate([ThrowIfClosed], Nil.prototype, "getRemoteWorldLimitPerUser", null);
973
1669
  __decorate([ThrowIfClosed], Nil.prototype, "getRemoteWorlds", null);
1670
+ __decorate([ThrowIfClosed], Nil.prototype, "getRound", null);
1671
+ __decorate([ThrowIfClosed], Nil.prototype, "getRuntimeGlobalQueueDepth", null);
974
1672
  __decorate([ThrowIfClosed], Nil.prototype, "getRuntimeNumAliveTasks", null);
975
1673
  __decorate([ThrowIfClosed], Nil.prototype, "getRuntimeNumWorkers", null);
976
1674
  __decorate([ThrowIfClosed], Nil.prototype, "getServerAddr", null);
977
1675
  __decorate([ThrowIfClosed], Nil.prototype, "getServerKind", null);
1676
+ __decorate([ThrowIfClosed], Nil.prototype, "getServerVersion", null);
1677
+ __decorate([ThrowIfClosed], Nil.prototype, "getStableRecruitCatalog", null);
978
1678
  __decorate([ThrowIfClosed], Nil.prototype, "getUserAgent", null);
1679
+ __decorate([ThrowIfClosed], Nil.prototype, "getWorkshopRecruitCatalog", null);
1680
+ __decorate([ThrowIfClosed], Nil.prototype, "getWorldBots", null);
1681
+ __decorate([ThrowIfClosed], Nil.prototype, "getWorldConfig", null);
979
1682
  __decorate([ThrowIfClosed], Nil.prototype, "getWorldId", null);
1683
+ __decorate([ThrowIfClosed], Nil.prototype, "getWorldPersonnel", null);
1684
+ __decorate([ThrowIfClosed], Nil.prototype, "getWorldPlayers", null);
1685
+ __decorate([ThrowIfClosed], Nil.prototype, "getWorldPrecursors", null);
1686
+ __decorate([ThrowIfClosed], Nil.prototype, "getWorldRulers", null);
1687
+ __decorate([ThrowIfClosed], Nil.prototype, "getWorldStats", null);
980
1688
  __decorate([ThrowIfClosed], Nil.prototype, "isHost", null);
981
1689
  __decorate([ThrowIfClosed], Nil.prototype, "isLocal", null);
982
1690
  __decorate([ThrowIfClosed], Nil.prototype, "isReady", null);
983
1691
  __decorate([ThrowIfClosed], Nil.prototype, "isRemote", null);
984
1692
  __decorate([ThrowIfClosed], Nil.prototype, "playerExists", null);
1693
+ __decorate([ThrowIfClosed], Nil.prototype, "pushChatMessage", null);
1694
+ __decorate([ThrowIfClosed], Nil.prototype, "renameCity", null);
1695
+ __decorate([ThrowIfClosed], Nil.prototype, "requestManeuver", null);
1696
+ __decorate([ThrowIfClosed], Nil.prototype, "saveLocalWorld", null);
1697
+ __decorate([ThrowIfClosed], Nil.prototype, "searchCity", null);
1698
+ __decorate([ThrowIfClosed], Nil.prototype, "searchPublicCity", null);
1699
+ __decorate([ThrowIfClosed], Nil.prototype, "sendResources", null);
1700
+ __decorate([ThrowIfClosed], Nil.prototype, "setPlayerReady", null);
985
1701
  __decorate([ThrowIfClosed], Nil.prototype, "setPlayerStatus", null);
986
1702
  __decorate([ThrowIfClosed], Nil.prototype, "setUserAgent", null);
1703
+ __decorate([ThrowIfClosed], Nil.prototype, "simulateBattle", null);
987
1704
  __decorate([ThrowIfClosed], Nil.prototype, "spawnPlayer", null);
1705
+ __decorate([ThrowIfClosed], Nil.prototype, "startRound", null);
988
1706
  __decorate([ThrowIfClosed], Nil.prototype, "startServer", null);
989
1707
  __decorate([ThrowIfClosed], Nil.prototype, "startServerWithSavedata", null);
990
1708
  __decorate([ThrowIfClosed], Nil.prototype, "stopClient", null);
991
1709
  __decorate([ThrowIfClosed], Nil.prototype, "stopServer", null);
1710
+ __decorate([ThrowIfClosed], Nil.prototype, "toggleBuilding", null);
992
1711
  __decorate([ThrowIfClosed], Nil.prototype, "updateClient", null);
1712
+ __decorate([ThrowIfClosed], Nil.prototype, "userExists", null);
993
1713
  __decorate([ThrowIfClosed], Nil.prototype, "validateToken", null);
994
1714
  function ThrowIfClosed(_target, _key, descriptor) {
995
1715
  const method = descriptor.value;