@tsukilabs/nil-ffi 0.7.11 → 0.7.13

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
@@ -244,6 +415,10 @@ var definitions = {
244
415
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
245
416
  return: ffi.types.VOID
246
417
  },
418
+ nil_cheat_set_market_fee: {
419
+ arguments: [ffi.types.UINT_32, ffi.types.POINTER],
420
+ return: ffi.types.VOID
421
+ },
247
422
  nil_cheat_set_max_food: {
248
423
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
249
424
  return: ffi.types.VOID
@@ -376,6 +551,14 @@ var definitions = {
376
551
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
377
552
  return: ffi.types.VOID
378
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
+ },
379
562
  nil_get_player: {
380
563
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
381
564
  return: ffi.types.VOID
@@ -516,6 +699,10 @@ var definitions = {
516
699
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
517
700
  return: ffi.types.VOID
518
701
  },
702
+ nil_get_world_rulers: {
703
+ arguments: [ffi.types.UINT_32, ffi.types.POINTER],
704
+ return: ffi.types.VOID
705
+ },
519
706
  nil_get_world_stats: {
520
707
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
521
708
  return: ffi.types.VOID
@@ -548,6 +735,10 @@ var definitions = {
548
735
  arguments: [ffi.types.UINT_32, ffi.types.POINTER],
549
736
  return: ffi.types.VOID
550
737
  },
738
+ nil_send_resources: {
739
+ arguments: [ffi.types.UINT_32, ffi.types.POINTER],
740
+ return: ffi.types.VOID
741
+ },
551
742
  nil_server_version: {
552
743
  arguments: [ffi.types.UINT_32],
553
744
  return: ffi.types.VOID
@@ -586,224 +777,402 @@ var definitions = {
586
777
  }
587
778
  };
588
779
  //#endregion
589
- //#region src/error.ts
780
+ //#region package.json
781
+ var version = "0.7.13";
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
590
792
  //! Copyright (C) Call of Nil contributors
591
793
  //! SPDX-License-Identifier: AGPL-3.0-only
592
- var NilError = class NilError extends Error {
593
- constructor(message, options) {
594
- const status = options?.status ?? ffi_Status.ERR_UNKNOWN;
595
- if (!message && status !== ffi_Status.OK) {
596
- for (const [key, value] of Object.entries(ffi_Status)) if (value === status) {
597
- message = key;
598
- break;
599
- }
600
- }
601
- message ??= "ERR_UNKNOWN";
602
- super(message, options);
603
- this.name = "NilError";
604
- this.status = 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);
605
804
  }
606
- static fromStatus(status) {
607
- return new NilError(null, { status });
805
+ async [Symbol.asyncDispose]() {
806
+ await this.close();
608
807
  }
609
- };
610
- var HandleClosedError = class extends Error {
611
- constructor(options) {
612
- super("handle is closed", options);
613
- this.name = "HandleClosedError";
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]();
614
816
  }
615
- };
616
- var UnknownResponseError = class extends Error {
617
- constructor(response, options) {
618
- super(`got unknown response with id ${response.id}`, options);
619
- this.name = "UnknownResponseError";
620
- this.response = response;
817
+ async close() {
818
+ this.closePromise ??= this.#close().finally(() => void (this.closePromise = null));
819
+ return this.closePromise;
621
820
  }
622
- };
623
- //#endregion
624
- //#region src/request.ts
625
- //! Copyright (C) Call of Nil contributors
626
- //! SPDX-License-Identifier: AGPL-3.0-only
627
- var RequestId = class {
628
- #current = 0;
629
- next() {
630
- if (this.#current >= 4294967295) this.#current = 0;
631
- return ++this.#current;
821
+ isClosed() {
822
+ return this.closed;
632
823
  }
633
- };
634
- //#endregion
635
- //#region src/ptr.ts
636
- //! Copyright (C) Call of Nil contributors
637
- //! SPDX-License-Identifier: AGPL-3.0-only
638
- function allocBuffer(size) {
639
- return Buffer.alloc(size ?? pointerSize());
640
- }
641
- function readBufferPtr(buffer) {
642
- if (pointerSize() === 8) return buffer.readBigUInt64LE();
643
- else return BigInt(buffer.readUInt32LE());
644
- }
645
- function pointerSize() {
646
- if (process.arch === "x64" || process.arch === "arm64") return 8;
647
- else return 4;
648
- }
649
- //#endregion
650
- //#region src/queue.ts
651
- //! Copyright (C) Call of Nil contributors
652
- //! SPDX-License-Identifier: AGPL-3.0-only
653
- var QueueEmitter = class extends EventEmitter {
654
- emit(event, ...args) {
655
- return super.emit(event, ...args);
824
+ static async init(dll, options) {
825
+ const nil = new Nil(dll, options);
826
+ await nil.setUserAgent(USER_AGENT);
827
+ return nil;
656
828
  }
657
- on(event, listener) {
658
- return super.on(event, listener);
829
+ static async initLatest(options) {
830
+ const dll = await this.downloadLatest(options);
831
+ return this.init(dll, options);
659
832
  }
660
- };
661
- var Queue = class Queue {
662
- static {
663
- this.POLL_INTERVAL = 16;
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;
664
842
  }
665
- static {
666
- this.LIMIT_PER_TICK = 200;
843
+ async addAcademyRecruitOrder(req) {
844
+ return this.queue.request((requestId) => {
845
+ this.functions.nil_add_academy_recruit_order(requestId, JSON.stringify(req));
846
+ });
667
847
  }
668
- constructor(handle, options) {
669
- this.disposed = false;
670
- this.emitter = new QueueEmitter();
671
- this.requestId = new RequestId();
672
- this.pendingRequests = /* @__PURE__ */ new Map();
673
- this.functions = handle.functions;
674
- this.errorHandler = options?.onError ?? console.error;
675
- this.emitter.on("error", this.errorHandler);
676
- this.emitter.on("response", this.onResponse.bind(this));
677
- this.timer = setTimeout(() => this.drain(), 0);
848
+ async addPrefectureBuildOrder(req) {
849
+ return this.queue.request((requestId) => {
850
+ this.functions.nil_add_prefecture_build_order(requestId, JSON.stringify(req));
851
+ });
678
852
  }
679
- [Symbol.dispose]() {
680
- if (this.disposed) return;
681
- this.disposed = true;
682
- this.rejectAll(new HandleClosedError());
683
- this.emitter.removeAllListeners();
853
+ async addStableRecruitOrder(req) {
854
+ return this.queue.request((requestId) => {
855
+ this.functions.nil_add_stable_recruit_order(requestId, JSON.stringify(req));
856
+ });
684
857
  }
685
- request(start) {
686
- if (this.disposed) return Promise.reject(new HandleClosedError());
687
- const requestId = this.requestId.next();
688
- return new Promise((resolve, reject) => {
689
- this.pendingRequests.set(requestId, {
690
- resolve,
691
- reject
692
- });
693
- try {
694
- start(requestId);
695
- } catch (err) {
696
- this.pendingRequests.delete(requestId);
697
- reject(err);
698
- }
858
+ async addWorkshopRecruitOrder(req) {
859
+ return this.queue.request((requestId) => {
860
+ this.functions.nil_add_workshop_recruit_order(requestId, JSON.stringify(req));
699
861
  });
700
862
  }
701
- drain() {
702
- if (this.disposed) return;
703
- this.clearTimeout();
704
- try {
705
- for (let i = 0; i < Queue.LIMIT_PER_TICK; i++) if (!this.poll()) break;
706
- } catch (err) {
707
- this.emitter.emit("error", err);
708
- }
709
- this.timer = setTimeout(() => this.drain(), Queue.POLL_INTERVAL);
863
+ async authorize(req) {
864
+ return this.queue.request((requestId) => {
865
+ this.functions.nil_authorize(requestId, JSON.stringify(req));
866
+ });
710
867
  }
711
- poll() {
712
- const out = allocBuffer();
713
- const status = this.functions.nil_ffi_poll(out);
714
- if (status === ffi_Status.ERR_NOTHING_TO_POLL) return false;
715
- if (status !== ffi_Status.OK) throw NilError.fromStatus(status);
716
- const ptr = readBufferPtr(out);
717
- if (ptr === 0n) throw new Error("failed to poll: unexpected null pointer");
718
- try {
719
- const json = ffi.toString(ptr) ?? "";
720
- const entry = JSON.parse(json);
721
- this.dispatch(entry);
722
- } finally {
723
- this.functions.nil_ffi_free_str(ptr);
724
- }
725
- return true;
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
+ });
726
1127
  }
727
- dispatch(entry) {
728
- switch (entry.kind) {
729
- case "response": {
730
- const response = JSON.parse(entry.jsonStr);
731
- this.emitter.emit("response", response);
732
- break;
733
- }
734
- }
1128
+ async forwardReport(req) {
1129
+ return this.queue.request((requestId) => {
1130
+ this.functions.nil_forward_report(requestId, JSON.stringify(req));
1131
+ });
735
1132
  }
736
- rejectAll(error) {
737
- this.clearTimeout();
738
- this.pendingRequests.values().forEach(({ reject }) => reject(error));
739
- 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
+ });
740
1137
  }
741
- clearTimeout() {
742
- if (!isNil(this.timer)) {
743
- clearTimeout(this.timer);
744
- this.timer = null;
745
- }
1138
+ async getArmies(req) {
1139
+ return this.queue.request((requestId) => {
1140
+ this.functions.nil_get_armies(requestId, JSON.stringify(req));
1141
+ });
746
1142
  }
747
- onResponse(response) {
748
- const pending = this.pendingRequests.get(response.id);
749
- if (pending) {
750
- this.pendingRequests.delete(response.id);
751
- if (response.kind === "ok") pending.resolve(response.data);
752
- else {
753
- const { status, error } = response;
754
- pending.reject(new NilError(error, { status }));
755
- }
756
- } 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
+ });
757
1147
  }
758
- };
759
- //#endregion
760
- //#region package.json
761
- var version = "0.7.11";
762
- //#endregion
763
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
764
- function __decorate(decorators, target, key, desc) {
765
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
766
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
767
- 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;
768
- return c > 3 && r && Object.defineProperty(target, key, r), r;
769
- }
770
- //#endregion
771
- //#region src/index.ts
772
- //! Copyright (C) Call of Nil contributors
773
- //! SPDX-License-Identifier: AGPL-3.0-only
774
- var VERSION = version;
775
- var USER_AGENT = `nil-ffi-node/${VERSION}`;
776
- var Nil = class Nil {
777
- constructor(dll, options) {
778
- this.closed = false;
779
- if (!dll.endsWith(ffi.suffix)) dll = `${dll}.${ffi.suffix}`;
780
- this.path = path.resolve(dll);
781
- this.handle = ffi.dlopen(dll, definitions);
782
- this.functions = this.handle.functions;
783
- 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
+ });
784
1152
  }
785
- async [Symbol.asyncDispose]() {
786
- 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
+ });
787
1157
  }
788
- async #close() {
789
- if (this.closed) return;
790
- this.closed = true;
791
- await attemptAsync(this.stopClient.bind(this));
792
- await attemptAsync(this.stopServer.bind(this));
793
- this.queue[Symbol.dispose]();
794
- this.functions.nil_ffi_shutdown();
795
- 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
+ });
796
1162
  }
797
- async close() {
798
- this.closePromise ??= this.#close();
799
- return this.closePromise;
1163
+ async getCities(req) {
1164
+ return this.queue.request((requestId) => {
1165
+ this.functions.nil_get_cities(requestId, JSON.stringify(req));
1166
+ });
800
1167
  }
801
- isClosed() {
802
- return this.closed;
1168
+ async getCity(req) {
1169
+ return this.queue.request((requestId) => {
1170
+ this.functions.nil_get_city(requestId, JSON.stringify(req));
1171
+ });
803
1172
  }
804
- async authorize(req) {
1173
+ async getCityScore(req) {
805
1174
  return this.queue.request((requestId) => {
806
- this.functions.nil_authorize(requestId, JSON.stringify(req));
1175
+ this.functions.nil_get_city_score(requestId, JSON.stringify(req));
807
1176
  });
808
1177
  }
809
1178
  async getClientVersion() {
@@ -811,26 +1180,156 @@ var Nil = class Nil {
811
1180
  this.functions.nil_client_version(requestId);
812
1181
  });
813
1182
  }
1183
+ async getContinentSize(req) {
1184
+ return this.queue.request((requestId) => {
1185
+ this.functions.nil_get_continent_size(requestId, JSON.stringify(req));
1186
+ });
1187
+ }
814
1188
  async getFfiVersion() {
815
1189
  return this.queue.request((requestId) => {
816
1190
  this.functions.nil_ffi_version(requestId);
817
1191
  });
818
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
+ }
819
1218
  async getPlayer(req) {
820
1219
  return this.queue.request((requestId) => {
821
1220
  this.functions.nil_get_player(requestId, JSON.stringify(req));
822
1221
  });
823
1222
  }
1223
+ async getPlayerCoords(req) {
1224
+ return this.queue.request((requestId) => {
1225
+ this.functions.nil_get_player_coords(requestId, JSON.stringify(req));
1226
+ });
1227
+ }
824
1228
  async getPlayerIds(req) {
825
1229
  return this.queue.request((requestId) => {
826
1230
  this.functions.nil_get_player_ids(requestId, JSON.stringify(req));
827
1231
  });
828
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
+ }
829
1243
  async getPlayerStatus(req) {
830
1244
  return this.queue.request((requestId) => {
831
1245
  this.functions.nil_get_player_status(requestId, JSON.stringify(req));
832
1246
  });
833
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
+ }
834
1333
  async getRemoteWorldLimit() {
835
1334
  return this.queue.request((requestId) => {
836
1335
  this.functions.nil_get_remote_world_limit(requestId);
@@ -846,6 +1345,16 @@ var Nil = class Nil {
846
1345
  this.functions.nil_get_remote_worlds(requestId);
847
1346
  });
848
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
+ }
849
1358
  async getRuntimeNumAliveTasks() {
850
1359
  return this.queue.request((requestId) => {
851
1360
  this.functions.nil_runtime_num_alive_tasks(requestId);
@@ -866,16 +1375,66 @@ var Nil = class Nil {
866
1375
  this.functions.nil_get_server_kind(requestId);
867
1376
  });
868
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
+ }
869
1388
  async getUserAgent() {
870
1389
  return this.queue.request((requestId) => {
871
1390
  this.functions.nil_user_agent(requestId);
872
1391
  });
873
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
+ }
874
1408
  async getWorldId() {
875
1409
  return this.queue.request((requestId) => {
876
1410
  this.functions.nil_world(requestId);
877
1411
  });
878
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
+ }
879
1438
  async isHost() {
880
1439
  return this.queue.request((requestId) => {
881
1440
  this.functions.nil_is_host(requestId);
@@ -901,6 +1460,46 @@ var Nil = class Nil {
901
1460
  this.functions.nil_player_exists(requestId, JSON.stringify(req));
902
1461
  });
903
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
+ }
904
1503
  async setPlayerStatus(req) {
905
1504
  return this.queue.request((requestId) => {
906
1505
  this.functions.nil_set_player_status(requestId, JSON.stringify(req));
@@ -911,11 +1510,21 @@ var Nil = class Nil {
911
1510
  this.functions.nil_set_user_agent(requestId, JSON.stringify(userAgent));
912
1511
  });
913
1512
  }
1513
+ async simulateBattle(req) {
1514
+ return this.queue.request((requestId) => {
1515
+ this.functions.nil_simulate_battle(requestId, JSON.stringify(req));
1516
+ });
1517
+ }
914
1518
  async spawnPlayer(req) {
915
1519
  return this.queue.request((requestId) => {
916
1520
  this.functions.nil_spawn_player(requestId, JSON.stringify(req));
917
1521
  });
918
1522
  }
1523
+ async startRound(req) {
1524
+ return this.queue.request((requestId) => {
1525
+ this.functions.nil_start_round(requestId, JSON.stringify(req));
1526
+ });
1527
+ }
919
1528
  async startServer(options) {
920
1529
  return this.queue.request((requestId) => {
921
1530
  this.functions.nil_start_server(requestId, JSON.stringify(options));
@@ -936,64 +1545,171 @@ var Nil = class Nil {
936
1545
  this.functions.nil_stop_server(requestId);
937
1546
  });
938
1547
  }
1548
+ async toggleBuilding(req) {
1549
+ return this.queue.request((requestId) => {
1550
+ this.functions.nil_toggle_building(requestId, JSON.stringify(req));
1551
+ });
1552
+ }
939
1553
  async updateClient(options) {
940
1554
  return this.queue.request((requestId) => {
941
1555
  this.functions.nil_update_client(requestId, JSON.stringify(options));
942
1556
  });
943
1557
  }
1558
+ async userExists(req) {
1559
+ return this.queue.request((requestId) => {
1560
+ this.functions.nil_user_exists(requestId, JSON.stringify(req));
1561
+ });
1562
+ }
944
1563
  async validateToken(req) {
945
1564
  return this.queue.request((requestId) => {
946
1565
  this.functions.nil_validate_token(requestId, JSON.stringify(req));
947
1566
  });
948
1567
  }
949
- static async init(dll, options) {
950
- const nil = new Nil(dll, options);
951
- await nil.setUserAgent(USER_AGENT);
952
- return nil;
953
- }
954
- static async initLatest(options) {
955
- const dll = await this.downloadLatest(options);
956
- return this.init(dll, options);
957
- }
958
- static async downloadLatest(options) {
959
- const file = `libnil.${ffi.suffix}`;
960
- const filePath = path.resolve(options?.outDir ?? cwd(), file);
961
- if (!(options?.overwrite ?? true) && existsSync(filePath)) return filePath;
962
- const response = await fetch(`https://tsukilabs.dev.br/download/nil/${file}`, { headers: { "User-Agent": USER_AGENT } });
963
- if (!response.ok) throw new Error(`failed to download ${file}: ${response.status} ${response.statusText}`);
964
- const bytes = await response.bytes();
965
- await fs.writeFile(filePath, bytes);
966
- return filePath;
967
- }
968
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);
969
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);
970
1636
  __decorate([ThrowIfClosed], Nil.prototype, "getClientVersion", null);
1637
+ __decorate([ThrowIfClosed], Nil.prototype, "getContinentSize", null);
971
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);
972
1644
  __decorate([ThrowIfClosed], Nil.prototype, "getPlayer", null);
1645
+ __decorate([ThrowIfClosed], Nil.prototype, "getPlayerCoords", null);
973
1646
  __decorate([ThrowIfClosed], Nil.prototype, "getPlayerIds", null);
1647
+ __decorate([ThrowIfClosed], Nil.prototype, "getPlayerMaintenance", null);
1648
+ __decorate([ThrowIfClosed], Nil.prototype, "getPlayerMilitary", null);
974
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);
975
1667
  __decorate([ThrowIfClosed], Nil.prototype, "getRemoteWorldLimit", null);
976
1668
  __decorate([ThrowIfClosed], Nil.prototype, "getRemoteWorldLimitPerUser", null);
977
1669
  __decorate([ThrowIfClosed], Nil.prototype, "getRemoteWorlds", null);
1670
+ __decorate([ThrowIfClosed], Nil.prototype, "getRound", null);
1671
+ __decorate([ThrowIfClosed], Nil.prototype, "getRuntimeGlobalQueueDepth", null);
978
1672
  __decorate([ThrowIfClosed], Nil.prototype, "getRuntimeNumAliveTasks", null);
979
1673
  __decorate([ThrowIfClosed], Nil.prototype, "getRuntimeNumWorkers", null);
980
1674
  __decorate([ThrowIfClosed], Nil.prototype, "getServerAddr", null);
981
1675
  __decorate([ThrowIfClosed], Nil.prototype, "getServerKind", null);
1676
+ __decorate([ThrowIfClosed], Nil.prototype, "getServerVersion", null);
1677
+ __decorate([ThrowIfClosed], Nil.prototype, "getStableRecruitCatalog", null);
982
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);
983
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);
984
1688
  __decorate([ThrowIfClosed], Nil.prototype, "isHost", null);
985
1689
  __decorate([ThrowIfClosed], Nil.prototype, "isLocal", null);
986
1690
  __decorate([ThrowIfClosed], Nil.prototype, "isReady", null);
987
1691
  __decorate([ThrowIfClosed], Nil.prototype, "isRemote", null);
988
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);
989
1701
  __decorate([ThrowIfClosed], Nil.prototype, "setPlayerStatus", null);
990
1702
  __decorate([ThrowIfClosed], Nil.prototype, "setUserAgent", null);
1703
+ __decorate([ThrowIfClosed], Nil.prototype, "simulateBattle", null);
991
1704
  __decorate([ThrowIfClosed], Nil.prototype, "spawnPlayer", null);
1705
+ __decorate([ThrowIfClosed], Nil.prototype, "startRound", null);
992
1706
  __decorate([ThrowIfClosed], Nil.prototype, "startServer", null);
993
1707
  __decorate([ThrowIfClosed], Nil.prototype, "startServerWithSavedata", null);
994
1708
  __decorate([ThrowIfClosed], Nil.prototype, "stopClient", null);
995
1709
  __decorate([ThrowIfClosed], Nil.prototype, "stopServer", null);
1710
+ __decorate([ThrowIfClosed], Nil.prototype, "toggleBuilding", null);
996
1711
  __decorate([ThrowIfClosed], Nil.prototype, "updateClient", null);
1712
+ __decorate([ThrowIfClosed], Nil.prototype, "userExists", null);
997
1713
  __decorate([ThrowIfClosed], Nil.prototype, "validateToken", null);
998
1714
  function ThrowIfClosed(_target, _key, descriptor) {
999
1715
  const method = descriptor.value;