Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.nio.charset.StandardCharsets;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.Arrays;
- import java.util.List;
- import java.util.function.Function;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- public class Main {
- public final static String eu4HistoryPath = "C:\\Program Files\\Steam\\steamapps\\common\\Europa Universalis IV\\history\\";
- public final static String pgvd4HistoryPath = "C:\\Program Files\\Steam\\steamapps\\workshop\\content\\236850\\1872558755\\history\\";
- public static void main(String[] args) throws Exception {
- File folder = new File(pgvd4HistoryPath + "provinces\\");
- List<Integer> ids = List.of(2768
- ).stream().distinct().collect(Collectors.toList());
- moveFiles(ids);
- List<File> files = Arrays.stream(folder.listFiles()).collect(Collectors.toList());
- files.stream().filter(e -> idMatcher(e.getName(), ids)).forEach(f -> doActionOnFile(f, s -> "", s -> s.startsWith("owner") || s.startsWith("add_core ") || s.startsWith("controller")));
- /*moveFiles(List.of(286, 379, 1026, 206, 333, 4306, 303, 298, 184, 208, 87, 345,344,2470,1110,347,348,2464,2466,2460,346));
- addCore(files, List.of(1751), "MOR", true);
- addCore(files, List.of(232, 231, 4558, 4555, 4548), "POR", true);
- addCore(files, List.of(4554, 206), "GAL", true);
- addCore(files, List.of(207, 1745, 209, 2989, 1746, 4552, 215, 4553, 208), "ASU", true);
- addCore(files, List.of(207), "ASU", true);
- addCore(files, List.of(224, 1749, 225, 1748, 4547, 221), "GRA", true);
- addCore(files, List.of(174, 175, 176, 173), "GUY", true);
- addCore(files, List.of(197, 196, 2753, 198, 199, 203, 4391, 200, 204, 2991, 4112, 190), "TOU", true);
- addCore(files, List.of(179, 195, 194, 4387, 180, 4386, 4111), "BER", true);
- addCore(files, List.of(89, 167, 168, 4385, 1879, 177, 178, 172, 4384, 169, 171, 170), "NRM", true);
- addCore(files, List.of(95, 98, 99, 4381, 4382, 100), "HOL", false);
- addCore(files, List.of(373), "MTH", true);
- addCore(files, List.of(4365), "KOI", true);
- addCore(files, List.of(242, 4366, 241, 4369), "WLS", true);
- addCore(files, List.of(4389), "ORL", true);
- addCore(files, List.of(78, 79, 66, 71, 70, 74, 72, 75, 1880), "PAL", false);
- addCore(files, List.of(2966, 4238, 264, 263), "BOH", false);
- addCore(files, List.of(73, 110, 1768), "TIR", true);
- addCore(files, List.of(1775, 13), "DAN", false);
- addCore(files, List.of(27, 28, 30, 31, 29, 4123, 19, 4152, 4113, 4151), "FIN", true);
- addCore(files, List.of(39, 1935, 273, 4241, 37, 1834, 271), "TEU", false);
- addCore(files, List.of(127, 2986), "SAR", true);
- addCore(files, List.of(124, 125, 2982), "SIC", true);
- addCore(files, List.of(275, 4242, 292, 4246, 771, 4243), "PLT", true);
- addCore(files, List.of(4245, 293, 297, 4244), "SMO", true);
- addCore(files, List.of(4254, 306, 2423), "NZH", true);
- addCore(files, List.of(1752), "TVE", true);
- addCore(files, List.of(4117), "YAR", true);
- addCore(files, List.of(289, 2407, 4542, 280, 1944, 1943, 4540, 1942, 4247, 281, 4539, 2962, 279, 1940, 2961, 261, 4541, 2424, 1940, 4115), "KIE", true);
- addCore(files, List.of(1773, 145, 146), "ATH", true);
- addCore(files, List.of(149, 1764, 2750, 1765, 2746, 148, 3001, 1853, 147, 144, 143, 4175), "BYZ", true);
- addCore(files, List.of(150, 159), "BUL", true);
- addCore(files, List.of(2313, 377, 407, 1849, 405, 4271, 4270, 382, 4297, 378, 1855, 381, 1854, 364), "SYR", true);
- addCore(files, List.of(4269, 383, 4268, 2327, 380, 379, 365, 2315), "ANZ", true);
- addCore(files, List.of(2461, 337, 2459, 126, 4559), "TUN", false);
- addCore(files, List.of(1755, 4262, 4263, 314), "NOV", true);
- addCore(files, List.of(1945, 4543, 298, 291, 290), "CHR", true);
- addCore(files, List.of(283, 2406, 282), "ZAZ", true);
- addCore(files, List.of(355), "TUN", true);
- addCore(files, List.of(88), "PIC", true);
- addCore(files, List.of(247, 246, 4368), "NOL", true);
- addCore(files, List.of(2314), "QAR", true);
- addCore(files, List.of(1826,131,152,1767), "CRO", true);
- addCore(files, List.of(162,1952,157,4127,158,4128,1951), "TRA", true);
- //addCore(files, List.of(), "", true);
- //removeCores(files, List.of(), "", "");
- addDev();*/
- }
- private static void addCots(List<File> files, List<Integer> ids) {
- files.stream()
- .filter(f -> idMatcher(f.getName(), ids))
- .forEach(file -> {
- List<String> strings;
- try {
- strings = Files.readAllLines(Paths.get(file.getPath()), StandardCharsets.ISO_8859_1);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- if (strings.stream().anyMatch(s -> s.startsWith("center_of_trade "))) {
- return;
- }
- for (int i = 0; i < strings.size(); i++) {
- String s = strings.get(i);
- if (s.startsWith("add_core")) {
- strings.add(i, "center_of_trade = 1");
- break;
- }
- }
- try {
- FileWriter fw = new FileWriter(file, false);
- fw.write(String.join("\n", strings));
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
- }
- private static void addDev() throws Exception {
- File folder = new File(pgvd4HistoryPath + "provinces\\");
- List<File> files = Arrays.stream(folder.listFiles()).collect(Collectors.toList());
- addDev(files, List.of(289, 2407, 4542, 1944, 280, 1942, 4247), 1, 1, 2); //kiev
- addDev(files, List.of(2961, 289, 1945, 4545, 4242, 2409), 1, 2, 0); //kijów i okolice
- addDev(files, List.of(2456, 2450, 2453, 339, 354), 1, 2, 0); //tunis okolice
- //addDev(files, List.of(), );
- // ` addCore(files, List.of(), "", false);
- addCore(files, List.of(1024, 1837, 1023, 1835, 4359, 1030, 4360, 1839, 1029, 4189, 1020, 1832, 4187, 1021, 4185), "TKG", false);
- addCore(files, List.of(1818, 4182, 1014, 4181, 4180, 1012), "OUC", false);
- addCore(files, List.of(1830, 1019, 4184, 1018, 1825, 4183, 1017, 4186, 1819, 1820), "YMN", false);
- addCore(files, List.of(1026, 1025, 4131, 4192, 4193, 1847, 1031, 1852), "DTE", false);
- addCots(files, List.of(1847, 286, 379, 4131, 1026, 206, 333, 4306, 303, 298, 184));
- removeCots(files, List.of(208, 214));
- removeCores(files, List.of(345,344,2470,1110,347,348,2464,2466,2460,346), "MOR");
- //removeCores(files, List.of(), "", "");
- //files.forEach(Main::changeReligionInjapan);
- //changeJapanCountriesReligion();
- removeFort(files, List.of(87, 2753,246));
- }
- private static void removeCores(List<File> files, List<Integer> ids, String whose) {
- files.stream().filter(f -> idMatcher(f.getName(), ids))
- .forEach(f -> doActionOnFile(f, (String s) -> null, s -> s.startsWith("add_core") && s.contains(whose)));
- }
- private static void removeFort(List<File> files, List<Integer> ids) {
- files.stream().filter(f -> idMatcher(f.getName(), ids))
- .forEach(f -> doActionOnFile(f, (String s) -> null, s -> s.startsWith("fort_15th")));
- }
- private static void removeCots(List<File> files, List<Integer> provinces) {
- files.stream()
- .filter(f -> idMatcher(f.getName(), provinces))
- .forEach(f -> doActionOnFile(f, (String s) -> null, (String s) -> s.startsWith("center_of_trade")));
- }
- private static void doActionOnFile(File file, Function<String, String> action, Function<String, Boolean> checker) {
- List<String> strings;
- try {
- strings = Files.readAllLines(Paths.get(file.getPath()), StandardCharsets.ISO_8859_1);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- for (int i = 0; i < strings.size(); i++) {
- String s = strings.get(i);
- if (checker.apply(s)) {
- String ret = action.apply(s);
- if (s != null) {
- strings.set(i, ret);
- } else {
- strings.set(i, "");
- }
- break;
- }
- }
- try {
- FileWriter fw = new FileWriter(file, false);
- fw.write(String.join("\n", strings));
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static void moveFiles(List<Integer> integers) {
- File from = new File(eu4HistoryPath + "provinces\\");
- Arrays.stream(from.listFiles()).filter(f -> idMatcher(f.getName(), integers)).forEach(f -> {
- try {
- File to = new File(pgvd4HistoryPath + "provinces\\" + f.getName());
- if (to.exists()) {
- return;
- }
- FileWriter fw = new FileWriter(pgvd4HistoryPath + "provinces\\" + f.getName());
- fw.write(String.join("\n", Files.readAllLines(Paths.get(f.getPath()), StandardCharsets.ISO_8859_1)));
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
- }
- private static void changeJapanCountriesReligion() throws Exception {
- File folder = new File(pgvd4HistoryPath + "countries\\");
- List<File> files = Arrays.stream(folder.listFiles()).collect(Collectors.toList());
- files.forEach(file -> {
- List<String> strings;
- try {
- strings = Files.readAllLines(Paths.get(file.getPath()), StandardCharsets.ISO_8859_1);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- for (int i = 0; i < strings.size(); i++) {
- String s = strings.get(i);
- if (s.startsWith("religion")) {
- strings.set(i, "religion = sunni");
- }
- if (s.startsWith("add_government_reform")) {
- strings.set(i, "add_government_reform = feudalism_reform");
- }
- }
- try {
- FileWriter fw = new FileWriter(file, false);
- fw.write(String.join("\n", strings));
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
- }
- private static void changeReligionInjapan(File file) {
- List<String> strings;
- try {
- strings = Files.readAllLines(Paths.get(file.getPath()), StandardCharsets.ISO_8859_1);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- for (int i = 0; i < strings.size(); i++) {
- String s = strings.get(i);
- if (s.startsWith("religion = shinto")) {
- strings.set(i, "religion = sunni #japan");
- }
- }
- try {
- FileWriter fw = new FileWriter(file, false);
- fw.write(String.join("\n", strings));
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static void addDev(List<File> files, List<Integer> provinces, int adm, int dip, int mil) {
- files.stream()
- .filter(i -> idMatcher(i.getName(), provinces))
- .forEach(i -> addDev(i, adm, dip, mil));
- }
- private static void addDev(File file, int adm, int dip, int mil) {
- List<String> strings;
- Pattern pattern = Pattern.compile("[a-z_ =]*([0-9]+ *)");
- try {
- strings = Files.readAllLines(Paths.get(file.getPath()), StandardCharsets.ISO_8859_1);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- for (int i = 0; i < strings.size(); i++) {
- String s = strings.get(i);
- if (s.matches("base_[a-z]* = [0-9]+ *")) {
- Matcher matcher = pattern.matcher(s);
- if (!matcher.matches()) {
- System.console().writer().println("Didn't found dev!");
- break;
- }
- int dev = Integer.valueOf(matcher.group(1).trim());
- if (s.contains("base_tax")) {
- strings.set(i, "base_tax = " + (adm + dev));
- } else if (s.contains("base_production")) {
- strings.set(i, "base_production = " + (dip + dev));
- } else if (s.contains("base_manpower")) {
- strings.set(i, "base_manpower = " + (mil + dev));
- }
- }
- }
- try {
- FileWriter fw = new FileWriter(file, false);
- fw.write(String.join("\n", strings));
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static void addCore(List<File> files, List<Integer> provinces, String tag, boolean removeOther) throws Exception {
- files.stream()
- .filter(i -> idMatcher(i.getName(), provinces))
- .forEach(f -> modify(f, tag, removeOther));
- }
- private static void modify(File file, String tag, boolean removeOther) {
- List<String> strings;
- try {
- strings = Files.readAllLines(Paths.get(file.getPath()), StandardCharsets.ISO_8859_1);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- int lastIndex = -1;
- int ownerIndex = 8;
- for (int i = 0; i < strings.size(); i++) {
- String s = strings.get(i);
- if (removeOther && s.startsWith("add_core")) {
- strings.set(i, "#" + s);
- }
- if (s.startsWith("owner =")) {
- strings.set(i, "owner = " + tag);
- ownerIndex = i;
- }
- if (s.startsWith("controller =")) {
- strings.set(i, "controller = " + tag);
- }
- if (s.matches("[0-9]{4}\\.[0-9]{1,2}.*")) {
- lastIndex = i;
- break;
- }
- }
- strings.add(ownerIndex, "add_core = " + tag);
- if (lastIndex != -1) {
- strings = strings.subList(0, lastIndex);
- }
- String finalContent = String.join("\n", strings);
- try {
- FileWriter fw = new FileWriter(new File(pgvd4HistoryPath + "provinces\\" + file.getName()), false);
- fw.write(finalContent);
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- static boolean idMatcher(String filename, List<Integer> ids) {
- return ids.stream().anyMatch(i -> idMatcher(filename, i));
- }
- static boolean idMatcher(String filename, Integer id) {
- Pattern pattern = Pattern.compile(id + " ?-.*");
- int tmp = filename.lastIndexOf("\\");
- return pattern.matcher(filename).matches();
- }
- private static boolean filter(File file) {
- try {
- List<String> strings = Files.readAllLines(Paths.get(file.getPath()), StandardCharsets.ISO_8859_1);
- for (String s : strings) {
- if (s.startsWith("discovered_by")) {
- return false;
- }
- if (s.startsWith("hre = yes")) {
- return true;
- }
- String[] france = new String[]{"FRA", "PRO", "BRE", "BUR", "NEV"};
- for (String token : france) {
- if (s.startsWith("controller = " + token)) {
- return true;
- }
- }
- if (s.startsWith("#118 - Roma")) {
- return true;
- }
- }
- return false;
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement