forked from Nexus-Mods/vortex-games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
143 lines (127 loc) · 4.08 KB
/
index.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const { app, remote } = require('electron');
const path = require('path');
const { fs, selectors, util } = require('vortex-api');
const winapi = require('winapi-bindings');
const GAME_ID = 'divinityoriginalsin2';
const GAME_ID_DE = 'divinityoriginalsin2definitiveedition';
const appUni = app || remote.app;
function modPath() {
return path.join(appUni.getPath('documents'), 'Larian Studios', 'Divinity Original Sin 2', 'Mods');
}
function modPathDE() {
return path.join(appUni.getPath('documents'), 'Larian Studios', 'Divinity Original Sin 2 Definitive Edition', 'Mods');
}
function findGame() {
try {
const instPath = winapi.RegGetValue(
'HKEY_LOCAL_MACHINE',
'SOFTWARE\\WOW6432Node\\GOG.com\\Games\\1584823040',
'path');
if (!instPath) {
throw new Error('empty registry key');
}
return Promise.resolve(instPath.value);
} catch (err) {
return util.steam.findByName('Divinity: Original Sin 2')
.then(game => game.gamePath);
}
}
function isPak(file) {
return path.extname(file.relPath).toLowerCase() === '.pak';
}
function prepareForModding(discovery, isDefinitiveEdition) {
const modsPath = (isDefinitiveEdition) ? modPathDE() : modPath();
return fs.ensureDirWritableAsync(modsPath,() => Promise.resolve());
}
function versionOrigEd(gamePath, exePath) {
const exeVersion = require('exe-version');
try {
return exeVersion.default(path.join(gamePath, 'bin', 'EoCApp.exe'));
} catch (err) {
// classic version as shipped with the definive edition
return exeVersion.default(path.join(gamePath, 'Classic', 'EoCApp.exe'));
}
}
function versionDefEd(gamePath, exePath) {
const exeVersion = require('exe-version');
return exeVersion.default(path.join(gamePath, 'DefEd', 'bin', 'EoCApp.exe'));
}
function main(context) {
context.registerGame({
id: GAME_ID,
name: 'Divinity: Original Sin 2\tOriginal Edition',
mergeMods: true,
queryPath: findGame,
supportedTools: [],
queryModPath: modPath,
logo: 'gameart.jpg',
executable: () => 'bin/SupportTool.exe',
getGameVersion: versionOrigEd,
setup: (discovery) => prepareForModding(discovery, false),
requiredFiles: [
'bin/SupportTool.exe',
],
environment: {
SteamAPPId: '435150',
},
details: {
steamAppId: 435150,
}
});
context.registerGame({
id: GAME_ID_DE,
name: 'Divinity: Original Sin 2\tDefinitive Edition',
mergeMods: true,
queryPath: findGame,
supportedTools: [],
queryModPath: modPathDE,
logo: 'gameartDE.png',
executable: () => 'DefEd/bin/SupportTool.exe',
getGameVersion: versionDefEd,
setup: (discovery) => prepareForModding(discovery, true),
requiredFiles: [
'DefEd/bin/SupportTool.exe',
],
environment: {
SteamAPPId: '435150',
},
details: {
steamAppId: 435150,
}
});
context.once(() => {
let previouslyDeployed;
context.api.onAsync('will-deploy', (profileId, deployment) => {
const state = context.api.store.getState();
const profile = selectors.profileById(state, profileId);
if ([GAME_ID, GAME_ID_DE].indexOf(profile?.gameId) === -1) {
return Promise.resolve();
}
previouslyDeployed = new Set(deployment[''].filter(isPak).map(iter => iter.relPath));
return Promise.resolve();
})
context.api.onAsync('did-deploy', (profileId, deployment) => {
const state = context.api.store.getState();
const profile = selectors.profileById(state, profileId);
if ([GAME_ID, GAME_ID_DE].indexOf(profile?.gameId) === -1) {
return Promise.resolve();
}
const paks = deployment[''].filter(isPak).map(iter => iter.relPath);
const added = paks.filter(iter => !previouslyDeployed.has(iter));
if (added.length > 0) {
context.api.sendNotification({
type: 'info',
id: 'dos2-enable-mods',
icon: 'attention-required',
message: 'Please remember to enable mods in-game',
displayMS: 5000,
});
}
return Promise.resolve();
});
});
return true;
}
module.exports = {
default: main
};