steamutils 1.4.35 → 1.4.37
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/SteamClient.js +160 -169
- package/_steamproto.js +29 -0
- package/create_proto.js +47 -0
- package/helpers/protos.js +52 -54
- package/package.json +1 -1
- package/protos/csgo/engine_gcmessages.proto +1 -1
- package/protos/csgo/network_connection.proto +1 -1
- package/protos/csgo/steammessages.proto +1 -1
- package/protos/csgo/steammessages_base.proto +1 -1
- package/protos/csgo/steammessages_unified_base.steamworkssdk.proto +1 -1
- package/protos/csgo/valveextensions.proto +1 -1
- package/protos/steam/steammessages_base.proto +1 -1
- package/protos/steam/steammessages_clientsettings.proto +1 -1
- package/protos/steam/steammessages_unified_base.steamclient.proto +1 -1
- package/protos/steam/webuimessages_base.proto +1 -1
- package/protos/webui/common_base.proto +1 -1
- package/steamproto.js +6159 -0
package/_steamproto.js
ADDED
@@ -0,0 +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
|
+
}
|
package/create_proto.js
ADDED
@@ -0,0 +1,47 @@
|
|
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();
|
package/helpers/protos.js
CHANGED
@@ -1,54 +1,52 @@
|
|
1
|
-
import Protobuf from "protobufjs";
|
2
|
-
import fs from "fs";
|
3
|
-
import path from "path";
|
4
|
-
import {fileURLToPath} from "url";
|
5
|
-
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
7
|
-
const __dirname = path.dirname(__filename);
|
8
|
-
|
9
|
-
export default function Protos(protos, ignoreErrors = true) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
const
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
return protos
|
54
|
-
}
|
1
|
+
import Protobuf from "protobufjs";
|
2
|
+
import fs from "fs";
|
3
|
+
import path from "path";
|
4
|
+
import { fileURLToPath } from "url";
|
5
|
+
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
7
|
+
const __dirname = path.dirname(__filename);
|
8
|
+
|
9
|
+
export default function Protos(protos, ignoreErrors = true) {
|
10
|
+
const protobufs = {};
|
11
|
+
|
12
|
+
for (let proto of protos) {
|
13
|
+
let root = new Protobuf.Root();
|
14
|
+
let files = Array.isArray(proto.protos) ? proto.protos : fs.readdirSync(proto.protos).map((file) => path.join(proto.protos, file));
|
15
|
+
|
16
|
+
for (let file of files) {
|
17
|
+
if (!file.endsWith(".proto") || !fs.existsSync(file)) {
|
18
|
+
continue;
|
19
|
+
}
|
20
|
+
|
21
|
+
try {
|
22
|
+
root = root.loadSync(file, {
|
23
|
+
keepCase: true,
|
24
|
+
});
|
25
|
+
} catch (err) {
|
26
|
+
if (!ignoreErrors) {
|
27
|
+
throw err;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
protobufs[proto.name] = root;
|
33
|
+
}
|
34
|
+
|
35
|
+
return protobufs;
|
36
|
+
}
|
37
|
+
|
38
|
+
export function loadProfos(dir, protos = []) {
|
39
|
+
const currentDir = fs.readdirSync(dir);
|
40
|
+
for (const currentFile of currentDir) {
|
41
|
+
const _dir = path.join(dir, currentFile);
|
42
|
+
const isDirectory = fs.lstatSync(_dir).isDirectory();
|
43
|
+
if (isDirectory) {
|
44
|
+
loadProfos(_dir, protos);
|
45
|
+
} else {
|
46
|
+
if (currentFile.endsWith(".proto")) {
|
47
|
+
protos.push(_dir);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
return protos;
|
52
|
+
}
|
package/package.json
CHANGED