-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunner.java
More file actions
87 lines (71 loc) · 2.54 KB
/
Copy pathRunner.java
File metadata and controls
87 lines (71 loc) · 2.54 KB
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
package com.dd;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.dd.darkest.DarkestEncoder;
import com.dd.darkest.DarkestFile;
import com.dd.darkest.DarkestParser;
public class Runner {
// /////////////////EDIT ME//////////////////////////////
public static void main(String[] args) throws IOException {
List<GameplayChange> gameplayChanges = new ArrayList<GameplayChange>();
gameplayChanges.add(new MultiplyAllDamageAndHealth());
Runner runner = new Runner();
runner.run("E:/steam/steamapps/common/DarkestDungeon/",
gameplayChanges, false);
}
// //////////////////////////////////////////////////////
public void run(String installationDirectory,
List<GameplayChange> gameplayChanges, boolean dryrun)
throws IOException {
List<Backup> backups = Backup.createBackups(new File(
installationDirectory), ".darkest");
process(backups, gameplayChanges, dryrun);
}
public void process(List<Backup> backups,
List<GameplayChange> gameplayChanges, boolean dryrun)
throws IOException {
Map<File, DarkestFile> files = readDarkestFiles(backups);
makeGameplayChanges(files, gameplayChanges);
writeDarkestFiles(files, dryrun);
}
protected static Map<File, DarkestFile> readDarkestFiles(
List<Backup> backups) throws IOException {
Map<File, DarkestFile> darkestFiles = new HashMap<File, DarkestFile>();
for (Backup backup : backups) {
byte[] oldBytes = Files.readAllBytes(backup.getBackupFile()
.toPath());
DarkestParser parser = new DarkestParser();
DarkestFile darkestFile = parser
.parse(new String(oldBytes, "UTF-8"));
darkestFiles.put(backup.getGameFile(), darkestFile);
}
return darkestFiles;
}
protected static void writeDarkestFiles(
Map<File, DarkestFile> darkestFiles, boolean dryrun)
throws FileNotFoundException {
if (dryrun)
return;
for (File darkestFile : darkestFiles.keySet()) {
System.out.println("Writing: " + darkestFile);
DarkestEncoder encoder = new DarkestEncoder();
String result = encoder.marshall(darkestFiles.get(darkestFile));
PrintWriter newWriter = new PrintWriter(darkestFile);
newWriter.write(result);
newWriter.flush();
newWriter.close();
}
}
protected void makeGameplayChanges(Map<File, DarkestFile> files,
List<GameplayChange> gameplayChanges) {
for (GameplayChange change : gameplayChanges)
change.makeGameplayChanges(files);
}
}