-
Notifications
You must be signed in to change notification settings - Fork 5
/
gamestateIntegration.js
113 lines (107 loc) · 3.05 KB
/
gamestateIntegration.js
1
2
3
4
5
6
7
8
9
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const VDF = require('@node-steam/vdf')
const Registry = require('winreg')
const fs = require('fs-extra')
const path = require('path')
const os = require('os')
const ipc = require('electron').ipcRenderer
const REG = 'SteamPath'
const WINSTEAMLIB = path.join('steamapps', 'libraryfolders.vdf')
const GSIFILENAME = 'gamestate_integration_kitten.cfg'
const HOMEDIR = (process.env.SNAP) ? path.join('/home', process.env.USER) : os.homedir()
function saveConfig(config) {
let cfg = VDF.stringify({
'Kitten State API Config': {
'uri': config.url,
'timeout': 5.0,
'buffer': 0.1,
'throttle': 0.1,
'heartbeat': config.heartbeat,
'auth': {
'token': config.token
},
'data': {
'provider': 1, 'map': 1, 'round': 1, 'player_id': 1, 'allplayers_id': 1,
'player_state': 1, 'player_match_stats': 1, 'map_round_wins': 1
}
}
})
getCSGOPath(function (pth) {
fs.writeFile(path.join(pth, GSIFILENAME), cfg)
if (os.platform() === 'win32') {
ipc.send('csgoicon', path.resolve(pth, '..', '..', 'csgo.exe'))
}
})
}
function getCSGOPath(cb) {
getLibraryFoldersVDFPath(function (vdfPath) {
getLibraryFolders(vdfPath, function (libraries) {
libraries.push(path.join(path.dirname(vdfPath), 'common'))
libraries.forEach(function (pth, index) {
let cfgPath = path.join(pth, 'Counter-Strike Global Offensive', 'csgo', 'cfg')
fs.pathExists(cfgPath, function (err, exists) {
if (!err && exists) {
cb(cfgPath)
}
})
})
})
})
}
function getLibraryFoldersVDFPath(cb = function () { }) {
if (os.platform() === 'win32') {
//look at HKEY_CURRENT_USER\Software\Valve\Steam
let regKey = new Registry({
hive: Registry.HKCU, // open registry hive HKEY_CURRENT_USER
key: '\\Software\\Valve\\Steam'
})
regKey.values(function (err, items) {
let r = false
if (err) {
console.log('ERROR: ' + err)
}
else {
for (var i = 0; i < items.length && !r; i++) {
if (items[i].name === REG) {
r = path.join(items[i].value, WINSTEAMLIB)
}
}
}
cb(r)
})
}
else {
let vdfpath
if (os.platform() === 'darwin') {
vdfpath = path.join(HOMEDIR, 'Library/Application Support/Steam/steamapps/libraryfolders.vdf')
}
else {
vdfpath = path.join(HOMEDIR, '.local/share/Steam/steamapps/libraryfolders.vdf')
}
cb(vdfpath)
return vdfpath
}
}
function getLibraryFolders(vdfPath, cb) {
let folders = []
try {
fs.readFile(vdfPath, { encoding: 'utf8' }, function (err, data) {
if (!err) {
let vdfdata = VDF.parse(data)
if ('LibraryFolders' in vdfdata) {
vdfdata = vdfdata['LibraryFolders']
let key
for (key in vdfdata) {
if (!isNaN(key)) {
folders.push(path.join(vdfdata[key], 'steamapps', 'common'))
}
}
}
}
cb(folders)
})
}
catch (err) {
cb(folders)
}
}
exports.saveConfig = saveConfig