-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBaldursGate3.ts
333 lines (305 loc) · 11.9 KB
/
BaldursGate3.ts
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// 博德之门3 Mod支持
import { extname, basename, join } from 'path'
import { ElMessage } from "element-plus";
import { homedir, } from "os";
import { statSync } from "fs";
const xml2js = require('xml2js')
interface IAttribute {
$: {
id: string
type: string
value: string
}
}
//#region pack
let modsettings = {
get data() {
let file = join(FileHandler.GetAppData(), 'Local', 'Larian Studios', "Baldur's Gate 3", 'PlayerProfiles', 'Public', 'modsettings.lsx')
let data = FileHandler.readFile(file)
return xml2js.parseStringPromise(data)
},
set data(value) {
let file = join(FileHandler.GetAppData(), 'Local', 'Larian Studios', "Baldur's Gate 3", 'PlayerProfiles', 'Public', 'modsettings.lsx')
let data = new xml2js.Builder().buildObject(value)
if (data) FileHandler.writeFile(file, data)
}
}
async function LoadModDataFromPak(pakPath: string) {
const edge = require('electron-edge-js-v33-only')
const manager = useManager()
try {
let assemblyFile = join(manager.modStorage ?? "", manager.getModInfoByWebId(200783)?.id.toString() ?? "", 'BaldursGate3.dll')
// console.log(assemblyFile);
let Invoke = edge.func({
assemblyFile: assemblyFile,
typeName: 'BaldursGate3.Program',
methodName: 'LoadModDataFromPakAsync'
})
return new Promise<IAttribute[]>((resolve, reject) => {
Invoke(pakPath, async (error: any, result: any) => {
if (error) reject(error);
let attribute: IAttribute[] = []
if (result) {
let data = await xml2js.parseStringPromise(result)
data.save.region[0].node[0].children[0].node.forEach((item: any) => {
if (item.attribute) attribute.push(...item.attribute)
})
// if (data.save.region[0].node[0].children[0].node[0]?.attribute) {
// attribute.push(...data.save.region[0].node[0].children[0].node[0].attribute)
// }
// if (data.save.region[0].node[0].children[0].node[1]?.attribute) {
// attribute.push(...data.save.region[0].node[0].children[0].node[1].attribute)
// }
}
resolve(attribute);
})
})
} catch (error) {
console.log(error);
ElMessage.error(`错误: ${error}`)
}
}
async function handlePak(mod: IModInfo, installPath: string, isInstall: boolean) {
if (!Manager.checkInstalled("博德之门3 前置插件 For GMM", 200783)) return false
// if (isInstall) if (!Manager.checkInstalled("Patch 3 Mod Fixer", 200740)) return false
let res: IState[] = []
let manager = useManager()
let modsettings_data = await modsettings.data
let root = modsettings_data.save.region[0].node[0].children[0].node
// console.log(root);
if (!root[0].children || !root[0].children[0].node) {
// 如果用户是第一次装Mod
// console.log('第一次装Mod');
root[0] = {
$: {
id: 'ModOrder'
},
children: [
{
node: []
}
]
}
}
for (let index = 0; index < mod.modFiles.length; index++) {
const item = mod.modFiles[index];
let modStorage = join(manager.modStorage ?? "", mod.id.toString(), item)
if (statSync(modStorage).isFile()) {
if (extname(item) == '.pak') {
if (isInstall) FileHandler.copyFile(modStorage, join(installPath, basename(item)))
else FileHandler.deleteFile(join(installPath, basename(item)))
let meta = await LoadModDataFromPak(modStorage)
if (meta) {
// console.log(meta);
let ModuleShortDesc = meta.filter(item => (item.$.id == 'Folder' || item.$.id == 'MD5' || item.$.id == 'Name' || item.$.id == 'UUID' || item.$.id == 'Version64'))
if (ModuleShortDesc.length > 0) {
if (isInstall) {
// 安装
// ModOrder 中添加 UUID
root[0].children[0].node.push({
$: {
id: "Module"
},
attribute: [
{
$: {
id: "UUID",
type: "FixedString",
value: ModuleShortDesc.find(item => item.$.id == 'UUID')?.$.value,
}
}
]
})
// Mods 中添加 数据
root[1].children[0].node.push({
$: {
id: 'ModuleShortDesc'
},
attribute: [...ModuleShortDesc]
})
} else {
// 卸载
// ModOrder 中删除 UUID
root[0].children[0].node = root[0].children[0].node.filter((item: any) => item?.attribute[0].$.value != ModuleShortDesc.find(item => item.$.id == 'UUID')?.$.value)
// Mods 中删除 数据
root[1].children[0].node = root[1].children[0].node.filter((item: any) => {
let uuid = item?.attribute.find((item: any) => item.$.id == 'UUID')
if (uuid) return uuid.$.value != ModuleShortDesc.find(item => item.$.id == 'UUID')?.$.value
else return true
})
}
}
modsettings.data = modsettings_data
}
}
}
}
return true
}
//#endregion
export const supportedGames: ISupportedGames = {
GlossGameId: 240,
steamAppID: 1086940,
mod_io: 6715,
installdir: join("Baldurs Gate 3", "bin"),
gameName: "Baldurs Gate 3",
gameExe: [
{
name: 'bg3.exe',
rootPath: join('..')
},
{
name: 'bg3_dx11.exe',
rootPath: join('..')
}
],
startExe: [
{
name: 'Steam 启动',
cmd: 'steam://rungameid/1086940'
},
{
name: 'Vulkan',
exePath: join('bin', 'bg3.exe')
},
{
name: 'DirectX 11',
exePath: join('bin', 'bg3_dx11.exe')
},
],
archivePath: join(FileHandler.GetAppData(), 'Local', 'Larian Studios', "Baldur's Gate 3"),
gameCoverImg: "https://mod.3dmgame.com/static/upload/game/5f9fc80ea912c.png",
modType: [
{
id: 1,
name: 'pak',
installPath: join(homedir(), 'AppData', 'Local', 'Larian Studios', "Baldur's Gate 3", 'Mods'),
async install(mod) {
try {
return handlePak(mod, this.installPath ?? "", true)
} catch (error) {
ElMessage.error(`错误: ${error}`)
return false
}
},
async uninstall(mod) {
return handlePak(mod, this.installPath ?? "", false)
},
},
{
id: 2,
name: 'Data',
installPath: join('Data'),
async install(mod) {
return Manager.installByFolder(mod, this.installPath ?? "", "data", true, false, true)
},
async uninstall(mod) {
return Manager.installByFolder(mod, this.installPath ?? "", "data", false, false, true)
}
},
{
id: 3,
name: '插件',
installPath: '',
async install(mod) {
if (mod.webId == 201398) {
// 安装 Native Mod Loader
let manager = useManager()
mod.modFiles.forEach(item => {
let modStorage = join(manager.modStorage ?? "", mod.id.toString(), item)
if (statSync(modStorage).isFile()) {
let file = FileHandler.getFolderFromPath(item, 'bin')
let gameStorage = join(manager.gameStorage ?? "", file ?? "", item)
FileHandler.copyFile(modStorage, gameStorage)
}
})
}
return true
},
async uninstall(mod) {
if (mod.webId == 201398) {
// 卸载 Native Mod Loader
let manager = useManager()
mod.modFiles.forEach(item => {
let modStorage = join(manager.modStorage ?? "", mod.id.toString(), item)
if (statSync(modStorage).isFile()) {
let file = FileHandler.getFolderFromPath(item, 'bin')
let gameStorage = join(manager.gameStorage ?? "", file ?? "", item)
FileHandler.deleteFile(gameStorage)
}
})
}
return true
}
},
{
id: 4,
name: 'NativeMods',
installPath: join('bin', 'NativeMods'),
async install(mod) {
return Manager.installByFolder(mod, this.installPath ?? "", "NativeMods", true)
},
async uninstall(mod) {
return Manager.installByFolder(mod, this.installPath ?? "", "NativeMods", false)
}
},
{
id: 5,
name: 'bin',
installPath: join('bin'),
async install(mod) {
return Manager.installByFolder(mod, this.installPath ?? "", "bin", true)
},
async uninstall(mod) {
return Manager.installByFolder(mod, this.installPath ?? "", "bin", false)
}
},
{
id: 6,
name: "bg3se",
installPath: join('bin'),
async install(mod) {
return Manager.generalInstall(mod, this.installPath ?? "", true)
},
async uninstall(mod) {
return Manager.generalUninstall(mod, this.installPath ?? "", true)
}
},
{
id: 99,
name: '未知',
installPath: '',
async install(mod) {
ElMessage.warning("该mod类型未知, 无法自动安装, 请手动安装!")
return false
},
async uninstall(mod) {
return true
}
}
],
checkModType(mod) {
let plugins = [200783, 201398]
if (plugins.includes((mod.webId ?? 0) as number)) return 3
let pak = false
let data = false
let native = false
let bin = false
let bg3se = false
mod.modFiles.forEach(item => {
let exe = extname(item)
if (exe === '.pak') pak = true
if (item.toLowerCase().includes('public')) data = true
if (item.toLowerCase().includes('data')) data = true
if (item.toLowerCase().includes('bin')) bin = true
if (exe == '.dll') native = true
if (basename(item).toLowerCase() == 'DWrite.dll'.toLowerCase()) bg3se = true
})
if (bg3se) return 6
if (pak) return 1
if (data) return 2
if (bin) return 5
if (native) return 4
return 99
}
}