// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ // ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ // ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ // Magicbane Emulator Project © 2013 - 2024 // www.magicbane.com package engine.wpak; import engine.gameManager.ConfigManager; import org.pmw.tinylog.Logger; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PowersParser { public static String powersPath = ConfigManager.DEFAULT_DATA_DIR + "wpak/Powers.cfg"; private static final Pattern POWER_REGEX = Pattern.compile("(?<=POWERBEGIN)(.+?)(?=POWEREND)", Pattern.DOTALL); private static final Pattern STRSPLIT_REGEX = Pattern.compile("([^\"]\\S*|\"[^\"]*\")\\s*"); public static void parseWpakFile() throws IOException { // Read .wpak file from disk byte[] fileData = Files.readAllBytes(Paths.get(powersPath)); String fileContents = new String(fileData); // Iterate over power entries from .wpak data Matcher matcher = POWER_REGEX.matcher(fileContents); while (matcher.find()) { PowerEntry powerEntry = parsePowerEntry(matcher.group().trim()); } } private static PowerEntry parsePowerEntry(String powerData) { PowerEntry powerEntry = new PowerEntry(); try { String[] powerEntries = powerData.trim().split("\n"); ArrayList powerHeader = new ArrayList<>(); // Parse header String headerString = powerEntries[0]; headerString = headerString.replace("\n", " "); Matcher matcher = STRSPLIT_REGEX.matcher(headerString); while (matcher.find()) powerHeader.add(matcher.group().trim()); powerEntry.power_id = powerHeader.get(0); if (powerHeader.size() != 22) Logger.error(powerEntry.power_id); PowerData power = new PowerData(); power.power = powerHeader.get(1).replaceAll("\"", ""); power.power_type = powerHeader.get(2); power.icon = Integer.parseInt(powerHeader.get(3)); powerEntry.powers.add(power); powerEntry.powerbase = powerHeader.get(4).replaceAll("\"", ""); powerEntry.target_type = powerHeader.get(5); powerEntry.range = Integer.parseInt(powerHeader.get(6)); powerEntry.areaType = powerHeader.get(7); powerEntry.areaRange = Integer.parseInt(powerHeader.get(8)); powerEntry.excludeType = powerHeader.get(9); powerEntry.costType = powerHeader.get(10); powerEntry.cost = Float.parseFloat(powerHeader.get(11)); powerEntry.difficulty = Integer.parseInt(powerHeader.get(12)); powerEntry.precision = Integer.parseInt(powerHeader.get(13)); powerEntry.init_time = Float.parseFloat(powerHeader.get(14)); powerEntry.release_time = Float.parseFloat(powerHeader.get(15)); powerEntry.recycle_time = Float.parseFloat(powerHeader.get(16)); powerEntry.hitRollYN = Integer.parseInt(powerHeader.get(17)); powerEntry.castingMode = powerHeader.get(18); powerEntry.initAmin = Integer.parseInt(powerHeader.get(19)); powerEntry.releaseAnim = Integer.parseInt(powerHeader.get(20)); powerEntry.targetSelect = powerHeader.get(21); for (int x = 2; x < powerEntries.length; x++) { // Parse key/pair values // via switch } } catch (Exception e) { Logger.error(powerEntry.power_id); } return powerEntry; } }