steamutils 1.4.40 → 1.4.42

Sign up to get free protection for your applications and to get access to all the features.
package/_steamproto.js CHANGED
@@ -1,29 +1,29 @@
1
- import path from "path";
2
- import { loadProfos } from "./helpers/protos.js";
3
- import { fileURLToPath } from "url";
4
- const __filename = fileURLToPath(import.meta.url);
5
- const __dirname = path.dirname(__filename);
6
-
7
- export class SteamProto {
8
- constructor(proto) {
9
- this._proto = proto;
10
- }
11
-
12
- toProto() {
13
- const file = loadProfos(path.join(`${__dirname}/protos/`, this._proto.filename));
14
- const root = root.loadSync(file, {
15
- keepCase: true,
16
- });
17
- return root[this._proto.name];
18
- }
19
-
20
- protoEncode(obj) {
21
- const protobuf = this.toProto();
22
- return protobuf.encode(protobuf.create(obj)).finish();
23
- }
24
-
25
- protoDecode(obj) {
26
- const protobuf = this.toProto();
27
- return protobuf.toObject(protobuf.decode(obj), { defaults: true });
28
- }
29
- }
1
+ import path from "path";
2
+ import { fileURLToPath } from "url";
3
+ import Protobuf from "protobufjs";
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ export class SteamProto {
9
+ constructor(proto) {
10
+ this._proto = proto;
11
+ }
12
+
13
+ toProto() {
14
+ const root = new Protobuf.Root().loadSync(path.join(`${__dirname}/protos/`, this._proto.filename), {
15
+ keepCase: true,
16
+ });
17
+ return root[this._proto.name];
18
+ }
19
+
20
+ protoEncode(obj) {
21
+ const protobuf = this.toProto();
22
+ return protobuf.encode(protobuf.create(obj)).finish();
23
+ }
24
+
25
+ protoDecode(obj) {
26
+ const protobuf = this.toProto();
27
+ return protobuf.toObject(protobuf.decode(obj), { defaults: true });
28
+ }
29
+ }
package/create_proto.js CHANGED
@@ -1,47 +1,96 @@
1
- import helpers, { loadProfos } from "./helpers/protos.js";
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
- import Protobuf from "protobufjs";
5
- import fs from "fs";
6
-
7
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
-
9
- function main() {
10
- const rootDir = `${__dirname}/protos/`;
11
- const Protos = helpers([
12
- {
13
- name: "csgo",
14
- protos: loadProfos(rootDir),
15
- },
16
- ]);
17
-
18
- const fileName = "steamproto.js";
19
- const content = fs.readFileSync("_steamproto.js", { encoding: "utf8", flag: "r" });
20
-
21
- fs.writeFileSync(fileName, `${content}\nexport const SteamProtoType = {};export const ESteamProto = {};`);
22
-
23
- for (const key in Protos.csgo) {
24
- let csgo = Protos.csgo[key];
25
- if (typeof csgo === "function" || typeof csgo === "boolean" || typeof csgo === "string" || Array.isArray(csgo) || csgo === null) {
26
- continue;
27
- }
28
-
29
- if (csgo instanceof Protobuf.Type) {
30
- const fields = {};
31
- for (const fieldsKey in csgo.fields) {
32
- fields[fieldsKey] = fieldsKey;
33
- }
34
-
35
- const filename = path.relative(rootDir, csgo.filename);
36
- fs.appendFileSync(fileName, `SteamProtoType.${key} = ${JSON.stringify({ name: csgo.name, filename })};`);
37
- } else {
38
- for (const csgoKey in csgo) {
39
- if (csgo[csgoKey] instanceof Protobuf.Enum) {
40
- fs.appendFileSync(fileName, `ESteamProto.${csgoKey} = ${JSON.stringify(csgo[csgoKey].values)};`);
41
- }
42
- }
43
- }
44
- }
45
- }
46
-
47
- main();
1
+ import helpers, { loadProfos } from "./helpers/protos.js";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ import Protobuf from "protobufjs";
5
+ import fs from "fs";
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const shortfileName = "steamproto.js";
9
+ const fullfileName = "full_steamproto.js";
10
+
11
+ function main() {
12
+ const rootDir = `${__dirname}/protos/`;
13
+ const Protos = helpers([
14
+ {
15
+ name: "csgo",
16
+ protos: loadProfos(rootDir),
17
+ },
18
+ ]);
19
+
20
+ const content = fs.readFileSync("_steamproto.js", { encoding: "utf8", flag: "r" });
21
+
22
+ fs.writeFileSync(shortfileName, `${content}\nexport const SteamProtoType = {};export const ESteamProto = {};`);
23
+ fs.writeFileSync(fullfileName, `${content}\nexport const SteamProtoType = {};export const ESteamProto = {};`);
24
+
25
+ for (const key in Protos.csgo) {
26
+ let csgo = Protos.csgo[key];
27
+ if (typeof csgo === "function" || typeof csgo === "boolean" || typeof csgo === "string" || Array.isArray(csgo) || csgo === null) {
28
+ continue;
29
+ }
30
+
31
+ if (csgo instanceof Protobuf.Type) {
32
+ const fields = {};
33
+ for (const fieldsKey in csgo.fields) {
34
+ fields[fieldsKey] = fieldsKey;
35
+ }
36
+
37
+ const filename = path.relative(rootDir, csgo.filename);
38
+ const text = `SteamProtoType.${key} = ${JSON.stringify({ name: csgo.name, filename })};`;
39
+ fs.appendFileSync(fullfileName, text);
40
+ if (hasKeyDir(key, __dirname)) {
41
+ fs.appendFileSync(shortfileName, text);
42
+ }
43
+ } else {
44
+ for (const csgoKey in csgo) {
45
+ if (csgo[csgoKey] instanceof Protobuf.Enum) {
46
+ const values = csgo[csgoKey].values;
47
+ fs.appendFileSync(fullfileName, `ESteamProto.${csgoKey} = ${JSON.stringify(values)};`);
48
+
49
+ for (const valuesKey in values) {
50
+ if (!hasKeyDir(`${csgoKey}.${valuesKey}`, __dirname)) {
51
+ delete values[valuesKey];
52
+ }
53
+ }
54
+ if (Object.keys(values).length) {
55
+ fs.appendFileSync(shortfileName, `ESteamProto.${csgoKey} = ${JSON.stringify(values)};`);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ const ignoreFiles = ["create_remote_file.js", shortfileName, fullfileName];
64
+
65
+ export function hasKeyDir(key, dir) {
66
+ const currentDir = fs.readdirSync(dir);
67
+ for (const currentFile of currentDir) {
68
+ if (!["SteamClient.js", "index.js"].includes(currentFile)) {
69
+ continue;
70
+ }
71
+
72
+ const _dir = path.join(dir, currentFile);
73
+ const isDirectory = fs.lstatSync(_dir).isDirectory();
74
+ if (isDirectory) {
75
+ if (currentFile !== "node_modules") {
76
+ if (hasKeyDir(key, _dir)) {
77
+ return true;
78
+ }
79
+ }
80
+ } else {
81
+ if (currentFile.endsWith(".js") && !ignoreFiles.includes(currentFile)) {
82
+ if (hasKeyFile(key, _dir)) {
83
+ return true;
84
+ }
85
+ }
86
+ }
87
+ }
88
+ return false;
89
+ }
90
+
91
+ export function hasKeyFile(key, file) {
92
+ const content = fs.readFileSync(file);
93
+ return content.includes(key);
94
+ }
95
+
96
+ main();