Merge pull request #78 from truongdatnhan/master

Upgrade to to File NIO
This commit is contained in:
Ponk
2022-08-03 06:59:41 +02:00
committed by GitHub
41 changed files with 672 additions and 635 deletions

View File

@@ -76,44 +76,10 @@ public enum Stat {
}
public static Stat getByString(String type) {
if (type.equals("SKIN")) {
return SKIN;
} else if (type.equals("FACE")) {
return FACE;
} else if (type.equals("HAIR")) {
return HAIR;
} else if (type.equals("LEVEL")) {
return LEVEL;
} else if (type.equals("JOB")) {
return JOB;
} else if (type.equals("STR")) {
return STR;
} else if (type.equals("DEX")) {
return DEX;
} else if (type.equals("INT")) {
return INT;
} else if (type.equals("LUK")) {
return LUK;
} else if (type.equals("HP")) {
return HP;
} else if (type.equals("MAXHP")) {
return MAXHP;
} else if (type.equals("MP")) {
return MP;
} else if (type.equals("MAXMP")) {
return MAXMP;
} else if (type.equals("AVAILABLEAP")) {
return AVAILABLEAP;
} else if (type.equals("AVAILABLESP")) {
return AVAILABLESP;
} else if (type.equals("EXP")) {
return EXP;
} else if (type.equals("FAME")) {
return FAME;
} else if (type.equals("MESO")) {
return MESO;
} else if (type.equals("PET")) {
return PET;
for (Stat stat : Stat.values()) {
if (stat.name().equals(type)) {
return stat;
}
}
return null;
}

View File

@@ -50,7 +50,11 @@ import server.maps.*;
import tools.PacketCreator;
import tools.Pair;
import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture;
@@ -448,8 +452,14 @@ public final class Channel {
private static String[] getEvents() {
List<String> events = new ArrayList<>();
for (File file : new File("scripts/event").listFiles()) {
events.add(file.getName().substring(0, file.getName().length() - 3));
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get("scripts/event"))) {
for (Path path : stream) {
String fileName = path.getFileName().toString();
events.add(fileName.substring(0, fileName.length() - 3));
}
} catch (IOException e) {
log.warn("Unable to load events !");
e.printStackTrace();
}
return events.toArray(new String[0]);
}

View File

@@ -25,9 +25,10 @@ import provider.wz.WZFiles;
import provider.wz.XMLWZFile;
import java.io.File;
import java.nio.file.Path;
public class DataProviderFactory {
private static DataProvider getWZ(File in) {
private static DataProvider getWZ(Path in) {
return new XMLWZFile(in);
}

View File

@@ -1,6 +1,8 @@
package provider.wz;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
public enum WZFiles {
QUEST("Quest"),
@@ -25,17 +27,16 @@ public enum WZFiles {
this.fileName = name + ".wz";
}
public File getFile() {
return new File(DIRECTORY, fileName);
public Path getFile() {
return Paths.get(DIRECTORY).resolve(fileName);
}
public String getFilePath() {
return getFile().getPath();
return getFile().toString();
}
private static String getWzDirectory() {
// Either provide a custom directory path through the "wz-path" property when launching the .jar,
// or don't provide one to use the default "wz" directory
// Either provide a custom directory path through the "wz-path" property when launching the .jar, or don't provide one to use the default "wz" directory
String propertyPath = System.getProperty("wz-path");
if (propertyPath != null && new File(propertyPath).isDirectory()) {
return propertyPath;

View File

@@ -37,15 +37,16 @@ import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class XMLDomMapleData implements Data {
private final Node node;
private File imageDataDir;
private Path imageDataDir;
public XMLDomMapleData(FileInputStream fis, File imageDataDir) {
public XMLDomMapleData(FileInputStream fis, Path imageDataDir) {
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
@@ -79,7 +80,8 @@ public class XMLDomMapleData implements Data {
boolean foundChild = false;
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getAttributes().getNamedItem("name").getNodeValue().equals(s)) {
if (childNode.getNodeType() == Node.ELEMENT_NODE
&& childNode.getAttributes().getNamedItem("name").getNodeValue().equals(s)) {
myNode = childNode;
foundChild = true;
break;
@@ -91,7 +93,7 @@ public class XMLDomMapleData implements Data {
}
XMLDomMapleData ret = new XMLDomMapleData(myNode);
ret.imageDataDir = new File(imageDataDir, getName() + "/" + path).getParentFile();
ret.imageDataDir = imageDataDir.resolve(getName().trim()).resolve(path).getParent();
return ret;
}
@@ -104,7 +106,7 @@ public class XMLDomMapleData implements Data {
Node childNode = childNodes.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
XMLDomMapleData child = new XMLDomMapleData(childNode);
child.imageDataDir = new File(imageDataDir, getName());
child.imageDataDir = imageDataDir.resolve(getName().trim());
ret.add(child);
}
}
@@ -193,7 +195,7 @@ public class XMLDomMapleData implements Data {
return null;
}
XMLDomMapleData parentData = new XMLDomMapleData(parentNode);
parentData.imageDataDir = imageDataDir.getParentFile();
parentData.imageDataDir = imageDataDir.getParent();
return parentData;
}

View File

@@ -25,62 +25,66 @@ import provider.Data;
import provider.DataDirectoryEntry;
import provider.DataProvider;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class XMLWZFile implements DataProvider {
private final File root;
private static final Logger log = LoggerFactory.getLogger(DataProvider.class);
private final Path root;
private final WZDirectoryEntry rootForNavigation;
public XMLWZFile(File fileIn) {
public XMLWZFile(Path fileIn) {
root = fileIn;
rootForNavigation = new WZDirectoryEntry(fileIn.getName(), 0, 0, null);
rootForNavigation = new WZDirectoryEntry(fileIn.getFileName().toString(), 0, 0, null);
fillMapleDataEntitys(root, rootForNavigation);
}
private void fillMapleDataEntitys(File lroot, WZDirectoryEntry wzdir) {
for (File file : lroot.listFiles()) {
String fileName = file.getName();
if (file.isDirectory() && !fileName.endsWith(".img")) {
WZDirectoryEntry newDir = new WZDirectoryEntry(fileName, 0, 0, wzdir);
wzdir.addDirectory(newDir);
fillMapleDataEntitys(file, newDir);
} else if (fileName.endsWith(".xml")) {
wzdir.addFile(new WZFileEntry(fileName.substring(0, fileName.length() - 4), 0, 0, wzdir));
private void fillMapleDataEntitys(Path lroot, WZDirectoryEntry wzdir) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(lroot)) {
for (Path path : stream) {
String fileName = path.getFileName().toString();
if (Files.isDirectory(path) && !fileName.endsWith(".img")) {
WZDirectoryEntry newDir = new WZDirectoryEntry(fileName, 0, 0, wzdir);
wzdir.addDirectory(newDir);
fillMapleDataEntitys(path, newDir);
} else if (fileName.endsWith(".xml")) {
wzdir.addFile(new WZFileEntry(fileName.substring(0, fileName.length() - 4), 0, 0, wzdir));
}
}
} catch (IOException e) {
log.warn("Can not open file/directory at " + lroot);
}
}
@Override
public synchronized Data getData(String path) {
File dataFile = new File(root, path + ".xml");
File imageDataDir = new File(root, path);
if (!dataFile.exists()) {
return null;//bitches
}
FileInputStream fis;
try {
fis = new FileInputStream(dataFile);
} catch (FileNotFoundException e) {
throw new RuntimeException("Datafile " + path + " does not exist in " + root.getAbsolutePath());
Path dataFile = root.resolve(path + ".xml");
Path imageDataDir = root.resolve(path);
if (!Files.exists(dataFile)) {
return null;// bitches
}
final XMLDomMapleData domMapleData;
try {
domMapleData = new XMLDomMapleData(fis, imageDataDir.getParentFile());
} finally {
try {
fis.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try (FileInputStream fis = new FileInputStream(dataFile.toString())) {
domMapleData = new XMLDomMapleData(fis, imageDataDir.getParent());
} catch (FileNotFoundException e) {
throw new RuntimeException("Datafile " + path + " does not exist in " + root.toAbsolutePath());
} catch (IOException e) {
throw new RuntimeException(e);
}
return domMapleData;
}
@Override
public DataDirectoryEntry getRoot() {
return rootForNavigation;
}
}
@Override
public DataDirectoryEntry getRoot() {
return rootForNavigation;
}
}

View File

@@ -26,11 +26,17 @@ import provider.Data;
import provider.DataProvider;
import provider.DataProviderFactory;
import provider.DataTool;
import provider.wz.WZDirectoryEntry;
import provider.wz.WZFileEntry;
import provider.wz.WZFiles;
import tools.DatabaseConnection;
import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -185,26 +191,31 @@ public class SkillbookInformationProvider {
return loadedSkillbooks;
}
private static void listFiles(String directoryName, ArrayList<File> files) {
File directory = new File(directoryName);
private static void listFiles(String directoryName, ArrayList<Path> files) {
Path directory = Paths.get(directoryName);
// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
if (file.isFile()) {
files.add(file);
} else if (file.isDirectory()) {
listFiles(file.getAbsolutePath(), files);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
for (Path path : stream) {
if (Files.isRegularFile(path)) {
files.add(path);
} else if (Files.isDirectory(path)) {
listFiles(path.toAbsolutePath().toString(), files);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static List<File> listFilesFromDirectoryRecursively(String directory) {
ArrayList<File> files = new ArrayList<>();
listFiles(directory, files);
private static List<Path> listFilesFromDirectoryRecursively(String directory) {
ArrayList<Path> files = new ArrayList<>();
listFiles(directory, files);
return files;
}
return files;
}
private static Set<Integer> findMatchingSkillbookIdsOnFile(String fileContent) {
Set<Integer> skillbookIds = new HashSet<>(4);
@@ -219,22 +230,20 @@ public class SkillbookInformationProvider {
return skillbookIds;
}
private static String readFileToString(File file, String encoding) throws IOException {
private static String readFileToString(Path file, String encoding) throws IOException {
Scanner scanner = new Scanner(file, encoding);
String text = "";
try {
try {
text = scanner.useDelimiter("\\A").next();
} finally {
scanner.close();
}
try (scanner) {
text = scanner.useDelimiter("\\A").next();
} catch (NoSuchElementException e) {
}
return text;
}
private static Map<Integer, SkillBookEntry> fileSearchMatchingData(File file) {
private static Map<Integer, SkillBookEntry> fileSearchMatchingData(Path file) {
Map<Integer, SkillBookEntry> scriptFileSkillbooks = new HashMap<>();
try {
@@ -245,7 +254,7 @@ public class SkillbookInformationProvider {
scriptFileSkillbooks.put(skillbookId, SkillBookEntry.SCRIPT);
}
} catch (IOException ioe) {
log.error("Failed to read file:{}", file.getName(), ioe);
log.error("Failed to read file:{}", file.getFileName(), ioe);
}
return scriptFileSkillbooks;
@@ -254,8 +263,8 @@ public class SkillbookInformationProvider {
private static Map<Integer, SkillBookEntry> fetchSkillbooksFromScripts() {
Map<Integer, SkillBookEntry> scriptSkillbooks = new HashMap<>();
for (File file : listFilesFromDirectoryRecursively("./scripts")) {
if (file.getName().endsWith(".js")) {
for (Path file : listFilesFromDirectoryRecursively("./scripts")) {
if (file.getFileName().endsWith(".js")) {
scriptSkillbooks.putAll(fileSearchMatchingData(file));
}
}

View File

@@ -23,10 +23,12 @@ import server.life.MonsterStats;
import tools.Pair;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -171,7 +173,7 @@ public class ArrowFetcher {
if (!existingEntries.isEmpty()) {
List<int[]> entryValues = getArrowEntryValues(existingEntries);
printWriter = new PrintWriter(ToolConstants.getOutputFile(OUTPUT_FILE_NAME), StandardCharsets.UTF_8);
printWriter = new PrintWriter(Files.newOutputStream(ToolConstants.getOutputFile(OUTPUT_FILE_NAME)));
printSqlHeader();
for (int[] arrowEntry : entryValues) {
@@ -211,10 +213,15 @@ public class ArrowFetcher {
}
public static void main(String[] args) {
Instant instantStarted = Instant.now();
// load mob stats from WZ
mobStats = MonsterStatFetcher.getAllMonsterStats();
calcAllMobsArrowRange();
updateMobsArrowRange();
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -3,7 +3,11 @@ package tools.mapletools;
import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@@ -129,20 +133,18 @@ public class BossHpBarFetcher {
}
private static void readBossHpBarData() throws IOException {
String line;
final File mobDirectory = WZFiles.MOB.getFile();
for (File file : mobDirectory.listFiles()) {
if (file.isFile()) {
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
final Path mobDirectory = WZFiles.MOB.getFile();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(mobDirectory)) {
for (Path path : stream) {
if (Files.isRegularFile(path)) {
try (BufferedReader br = Files.newBufferedReader(path)) {
bufferedReader = br;
String line;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
}
}
bufferedReader.close();
fileReader.close();
}
}
}
@@ -162,17 +164,15 @@ public class BossHpBarFetcher {
private static void reportBossHpBarData() {
// This will reference one line at a time
try {
try (PrintWriter printWriter = new PrintWriter(Files.newOutputStream(ToolConstants.getOutputFile(OUTPUT_FILE_NAME)))) {
System.out.println("Reading WZs...");
readBossHpBarData();
System.out.println("Reporting results...");
final PrintWriter printWriter = new PrintWriter(ToolConstants.getOutputFile(OUTPUT_FILE_NAME), StandardCharsets.UTF_8);
printReportFileHeader(printWriter);
printReportFileResults(printWriter);
printWriter.close();
System.out.println("Done!");
} catch (FileNotFoundException ex) {
System.out.println("Unable to open mob file.");
@@ -184,7 +184,12 @@ public class BossHpBarFetcher {
}
public static void main(String[] args) {
Instant instantStarted = Instant.now();
reportBossHpBarData();
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -5,6 +5,8 @@ import tools.Pair;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/**
@@ -21,8 +23,8 @@ import java.util.*;
* Estimated parse time: 1 minute
*/
public class CashCosmeticsChecker {
private static final String INPUT_DIRECTORY_PATH = ToolConstants.getInputFile("care").getPath();
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("cash_cosmetics_result.txt");
private static final String INPUT_DIRECTORY_PATH = ToolConstants.getInputFile("care").toString();
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("cash_cosmetics_result.txt");
private static final boolean IGNORE_CURRENT_SCRIPT_COSMETICS = false; // Toggle to preference
private static final int INITIAL_STRING_LENGTH = 50;
@@ -614,50 +616,50 @@ public class CashCosmeticsChecker {
private static void reportCosmeticResults() throws IOException {
System.out.println("Reporting results ...");
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));) {
printWriter = pw;
printReportFileHeader();
printReportFileHeader();
if (!missingCosmeticsNpcTypes.isEmpty()) {
printWriter.println(
"Found " + missingCosmeticsNpcTypes.size() + " entries with missing cosmetic entries.");
if (!missingCosmeticsNpcTypes.isEmpty()) {
printWriter.println("Found " + missingCosmeticsNpcTypes.size() + " entries with missing cosmetic entries.");
for (Pair<Pair<Integer, String>, List<Integer>> mcn : getSortedMapEntries(missingCosmeticsNpcTypes)) {
printWriter.println(" NPC " + mcn.getLeft());
for (Pair<Pair<Integer, String>, List<Integer>> mcn : getSortedMapEntries(missingCosmeticsNpcTypes)) {
printWriter.println(" NPC " + mcn.getLeft());
Pair<List<Integer>, List<Integer>> genderItemids = getCosmeticReport(mcn.getRight());
reportNpcCosmetics(genderItemids.getLeft());
reportNpcCosmetics(genderItemids.getRight());
printWriter.println();
}
}
if (!unusedCosmetics.isEmpty()) {
printWriter.println("Unused cosmetics: " + unusedCosmetics.size());
List<Integer> list = new ArrayList<>(unusedCosmetics);
Collections.sort(list);
for (Integer i : list) {
printWriter.println(i + " " + cosmeticIdNames.get(i));
}
printWriter.println();
}
if (!missingCosmeticNames.isEmpty()) {
printWriter.println("Missing cosmetic itemids: " + missingCosmeticNames.size());
List<String> listString = new ArrayList<>(missingCosmeticNames);
Collections.sort(listString);
for (String c : listString) {
printWriter.println(c);
}
Pair<List<Integer>, List<Integer>> genderItemids = getCosmeticReport(mcn.getRight());
reportNpcCosmetics(genderItemids.getLeft());
reportNpcCosmetics(genderItemids.getRight());
printWriter.println();
}
}
if (!unusedCosmetics.isEmpty()) {
printWriter.println("Unused cosmetics: " + unusedCosmetics.size());
List<Integer> list = new ArrayList<>(unusedCosmetics);
Collections.sort(list);
for (Integer i : list) {
printWriter.println(i + " " + cosmeticIdNames.get(i));
}
printWriter.println();
}
if (!missingCosmeticNames.isEmpty()) {
printWriter.println("Missing cosmetic itemids: " + missingCosmeticNames.size());
List<String> listString = new ArrayList<>(missingCosmeticNames);
Collections.sort(listString);
for (String c : listString) {
printWriter.println(c);
}
printWriter.println();
}
printWriter.close();
}
public static void main(String[] args) {

View File

@@ -4,7 +4,9 @@ import provider.wz.WZFiles;
import tools.Pair;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -20,7 +22,7 @@ import java.util.*;
* Estimated parse time: 2 minutes
*/
public class CashDropFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("cash_drop_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("cash_drop_report.txt");
private static final Connection con = SimpleDatabaseConnection.getConnection();
private static final int INITIAL_STRING_LENGTH = 50;
private static final int ITEM_FILE_NAME_SIZE = 13;
@@ -175,17 +177,19 @@ public class CashDropFetcher {
printWriter.println();
}
private static void listFiles(String directoryName, ArrayList<File> files) {
File directory = new File(directoryName);
private static void listFiles(Path directoryName, ArrayList<Path> files) {
// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
if (file.isFile()) {
files.add(file);
} else if (file.isDirectory()) {
listFiles(file.getAbsolutePath(), files);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directoryName)) {
for (Path path : stream) {
if (Files.isRegularFile(path)) {
files.add(path);
} else if (Files.isDirectory(path)) {
listFiles(path, files);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@@ -260,42 +264,39 @@ public class CashDropFetcher {
}
private static void reportNxDropData() {
try {
try (con; PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
System.out.println("Reading Character.wz ...");
ArrayList<File> files = new ArrayList<>();
listFiles(WZFiles.CHARACTER.getFilePath(), files);
ArrayList<Path> files = new ArrayList<>();
listFiles(WZFiles.CHARACTER.getFile(), files);
InputStreamReader fileReader = null;
for (File f : files) {
//System.out.println("Parsing " + f.getAbsolutePath());
int itemid = getItemIdFromFilename(f.getName());
for (Path path : files) {
// System.out.println("Parsing " + f.getAbsolutePath());
int itemid = getItemIdFromFilename(path.getFileName().toString());
if (itemid < 0) {
continue;
}
fileReader = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
bufferedReader = Files.newBufferedReader(path);
currentItemid = itemid;
inspectEquipWzEntry();
bufferedReader.close();
fileReader.close();
}
System.out.println("Reading Item.wz ...");
files = new ArrayList<>();
listFiles(WZFiles.ITEM.getFilePath(), files);
listFiles(WZFiles.ITEM.getFile(), files);
for (File f : files) {
//System.out.println("Parsing " + f.getAbsolutePath());
fileReader = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
for (Path path : files) {
// System.out.println("Parsing " + f.getAbsolutePath());
bufferedReader = Files.newBufferedReader(path);
if (f.getName().length() <= ITEM_FILE_NAME_SIZE) {
if (path.getFileName().toString().length() <= ITEM_FILE_NAME_SIZE) {
inspectItemWzEntry();
} else { // pet file structure is similar to equips, maybe there are other item-types following this behaviour?
int itemid = getItemIdFromFilename(f.getName());
} else { // pet file structure is similar to equips, maybe there are other item-types
// following this behaviour?
int itemid = getItemIdFromFilename(path.getFileName().toString());
if (itemid < 0) {
continue;
}
@@ -305,27 +306,23 @@ public class CashDropFetcher {
}
bufferedReader.close();
fileReader.close();
}
System.out.println("Reporting results...");
// report suspects of missing quest drop data, as well as those drop data that may have incorrect questids.
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
// report suspects of missing quest drop data, as well as those drop data that
// may have incorrect questids.
printWriter = pw;
printReportFileHeader();
reportNxDropResults(true);
reportNxDropResults(false);
/*
printWriter.println("NX LIST"); // list of all cash items found
for(Integer nx : nxItems) {
printWriter.println(nx);
}
*/
* printWriter.println("NX LIST"); // list of all cash items found for(Integer
* nx : nxItems) { printWriter.println(nx); }
*/
con.close();
printWriter.close();
System.out.println("Done!");
} catch (SQLException e) {
System.out.println("Warning: Could not establish connection to database to report quest data.");

View File

@@ -4,6 +4,8 @@ import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
@@ -16,7 +18,7 @@ import java.util.Set;
* Estimated parse time: 10 seconds
*/
public class CashVegaChecker {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("vega_checker_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("vega_checker_report.txt");
private static final int INITIAL_STRING_LENGTH = 1000;
private static final Set<Integer> vegaItems = new HashSet<>();
@@ -156,16 +158,14 @@ public class CashVegaChecker {
private static void reportMissingVegaItems() {
System.out.println("Reporting results ...");
try {
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
printWriter = pw;
printReportFileHeader();
for (Integer itemid : vegaItems) {
printWriter.println(" " + itemid);
}
printWriter.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}

View File

@@ -3,7 +3,8 @@ package tools.mapletools;
import tools.Pair;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashSet;
@@ -22,7 +23,7 @@ import static java.util.concurrent.TimeUnit.HOURS;
* Estimated parse time: 2 minutes (for 100 code entries)
*/
public class CodeCouponGenerator {
private static final File INPUT_FILE = ToolConstants.getInputFile("CouponCodes.img.xml");
private static final Path INPUT_FILE = ToolConstants.getInputFile("CouponCodes.img.xml");
private static final int INITIAL_STRING_LENGTH = 250;
private static final Connection con = SimpleDatabaseConnection.getConnection();
@@ -312,24 +313,19 @@ public class CodeCouponGenerator {
ps.close();
}
private static void generateCodeCoupons(File file) throws IOException {
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
private static void generateCodeCoupons(Path file) throws IOException {
try (BufferedReader br = Files.newBufferedReader(file); con;) {
bufferedReader = br;
resetCouponPackage();
status = 0;
resetCouponPackage();
status = 0;
System.out.println("Reading XML coupon information...");
String line;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
System.out.println();
System.out.println("Reading XML coupon information...");
String line;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
bufferedReader.close();
fileReader.close();
System.out.println();
try {
System.out.println("Loading DB coupon codes...");
loadUsedCouponCodes();
System.out.println();
@@ -340,9 +336,8 @@ public class CodeCouponGenerator {
commitCodeCouponDescription(ccd);
}
System.out.println();
con.close();
System.out.println("Done.");
} catch (SQLException e) {
e.printStackTrace();
}
@@ -352,7 +347,7 @@ public class CodeCouponGenerator {
try {
generateCodeCoupons(INPUT_FILE);
} catch (IOException ex) {
System.out.println("Error reading file '" + INPUT_FILE.getAbsolutePath() + "'");
System.out.println("Error reading file '" + INPUT_FILE.toAbsolutePath() + "'");
}
}
}

View File

@@ -3,7 +3,8 @@ package tools.mapletools;
import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -16,8 +17,8 @@ import java.sql.SQLException;
* a SQL table that the server will make use.
*/
public class CouponInstaller {
private static final File COUPON_INPUT_FILE_1 = new File(WZFiles.ITEM.getFilePath(), "/Cash/0521.img.xml");
private static final File COUPON_INPUT_FILE_2 = new File(WZFiles.ITEM.getFilePath(), "/Cash/0536.img.xml");
private static final Path COUPON_INPUT_FILE_1 = WZFiles.ITEM.getFile().resolve("Cash/0521.img.xml");
private static final Path COUPON_INPUT_FILE_2 = WZFiles.ITEM.getFile().resolve("Cash/0536.img.xml");
private static final Connection con = SimpleDatabaseConnection.getConnection();
private static BufferedReader bufferedReader = null;
private static byte status = 0;
@@ -192,20 +193,17 @@ public class CouponInstaller {
}
}
private static void installRateCoupons(File file) {
private static void installRateCoupons(Path file) {
// This will reference one line at a time
String line = null;
try {
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
try (BufferedReader br = Files.newBufferedReader(file)) {
bufferedReader = br;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
bufferedReader.close();
fileReader.close();
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + file + "'");
} catch (IOException ex) {

View File

@@ -3,7 +3,12 @@ package tools.mapletools;
import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
/**
* @author RonanLana
@@ -16,8 +21,9 @@ import java.nio.charset.StandardCharsets;
* Estimated parse time: 10 seconds
*/
public class DojoUpdate {
private static final File INPUT_DIRECTORY = new File(WZFiles.MAP.getFile(), "/Map/Map9");
private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("dojo-maps");
private static final Path INPUT_DIRECTORY = WZFiles.MAP.getFile().resolve("Map").resolve("Map9");
private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("dojo-maps");
private static final Path WORKING_DIRECTORY = Paths.get("").toAbsolutePath();
private static final int DOJO_MIN_MAP_ID = 925_020_100;
private static final int DOJO_MAX_MAP_ID = 925_033_804;
private static final int INITIAL_STRING_LENGTH = 250;
@@ -114,30 +120,26 @@ public class DojoUpdate {
return Integer.parseInt(fileName.substring(0, 9));
}
private static void parseDojoData(File file, String curPath) throws IOException {
int mapId = getMapId(file.getName());
private static void parseDojoData(Path file, String curPath) throws IOException {
int mapId = getMapId(file.getFileName().toString());
isDojoMapid = isDojoMapId(mapId);
if (!isDojoMapid) {
return;
}
try (PrintWriter pw = new PrintWriter(
Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName())));
BufferedReader br = Files.newBufferedReader(file);) {
printWriter = pw;
bufferedReader = br;
status = 0;
printWriter = new PrintWriter(OUTPUT_DIRECTORY.getPath() + "/" + curPath + file.getName(), StandardCharsets.UTF_8);
String line;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
status = 0;
String line;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
printFileFooter();
}
bufferedReader.close();
fileReader.close();
printFileFooter();
printWriter.close();
}
private static boolean isDojoMapId(int mapId) {
@@ -152,31 +154,48 @@ public class DojoUpdate {
}
private static void parseDirectoryDojoData(String curPath) {
File folder = new File(OUTPUT_DIRECTORY, curPath);
if (!folder.exists()) {
folder.mkdir();
Path folder = OUTPUT_DIRECTORY.resolve(curPath);
if (!Files.exists(folder)) {
try {
Files.createDirectory(folder);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Unable to create folder " + folder.toAbsolutePath() + ".");
e.printStackTrace();
}
}
System.out.println("Parsing directory '" + curPath + "'");
folder = new File(INPUT_DIRECTORY, curPath);
for (File file : folder.listFiles()) {
if (file.isFile()) {
try {
parseDojoData(file, curPath);
} catch (FileNotFoundException ex) {
System.out.println("Unable to open dojo file " + file.getAbsolutePath() + ".");
} catch (IOException ex) {
System.out.println("Error reading dojo file " + file.getAbsolutePath() + ".");
} catch (Exception e) {
e.printStackTrace();
folder = INPUT_DIRECTORY.resolve(curPath);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(folder)) {
for (Path path : stream) {
if (Files.isRegularFile(path)) {
try {
parseDojoData(path, curPath);
} catch (FileNotFoundException ex) {
System.out.println("Unable to open dojo file " + path.toAbsolutePath() + ".");
} catch (IOException ex) {
System.out.println("Error reading dojo file " + path.toAbsolutePath() + ".");
} catch (Exception e) {
e.printStackTrace();
}
} else {
parseDirectoryDojoData(curPath + path.getFileName() + "/");
}
} else {
parseDirectoryDojoData(curPath + file.getName() + "/");
}
} catch (IOException e1) {
System.out.println("Unable to read folder " + folder.toAbsolutePath() + ".");
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public static void main(String[] args) {
Instant instantStarted = Instant.now();
parseDirectoryDojoData("");
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -4,6 +4,8 @@ import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/**
@@ -14,8 +16,8 @@ import java.util.*;
* And it removes from the String.wz XMLs all entries which misses properties on Item.wz.
*/
public class EmptyItemWzChecker {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("empty_item_wz_report.txt");
private static final String OUTPUT_PATH = ToolConstants.OUTPUT_DIRECTORY.getPath();
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("empty_item_wz_report.txt");
private static final String OUTPUT_PATH = ToolConstants.OUTPUT_DIRECTORY.toString();
private static final int INITIAL_STRING_LENGTH = 50;
private static final int ITEM_FILE_NAME_SIZE = 13;
@@ -338,12 +340,11 @@ public class EmptyItemWzChecker {
private static void reportItemNameDiff(Set<Integer> emptyItemNames, Set<Integer> emptyNameItems) throws IOException {
System.out.println("Reporting results...");
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
printReportFileHeader();
printReportFileResults(emptyItemNames, emptyNameItems);
printWriter.close();
try(PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
printWriter = pw;
printReportFileHeader();
printReportFileResults(emptyItemNames, emptyNameItems);
}
}
private static void locateItemStringWzDiff() throws IOException {
@@ -408,7 +409,7 @@ public class EmptyItemWzChecker {
private static void generateStringWz() throws IOException {
System.out.println("Generating clean String.wz ...");
String[][] stringWzFiles = {{"Cash", "Consume", "Ins", "Pet"}, {"Etc"}, {"Eqp"}};
String[][] stringWzFiles = { { "Cash", "Consume", "Ins", "Pet" }, { "Etc" }, { "Eqp" } };
String stringWzPath = "/String.wz/";
File folder = new File(OUTPUT_PATH + "/String.wz/");

View File

@@ -3,7 +3,11 @@ package tools.mapletools;
import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
/**
* @author RonanLana
@@ -16,14 +20,13 @@ import java.nio.charset.StandardCharsets;
* Estimated parse time: 7 minutes
*/
public class EquipmentOmniLeveller {
private static final File INPUT_DIRECTORY = WZFiles.CHARACTER.getFile();
private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("equips-with-levels");
private static final Path INPUT_DIRECTORY = WZFiles.CHARACTER.getFile();
private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("equips-with-levels");
private static final int INITIAL_STRING_LENGTH = 250;
private static final int FIXED_EXP = 10000;
private static final int MAX_EQP_LEVEL = 30;
private static PrintWriter printWriter = null;
private static InputStreamReader fileReader = null;
private static BufferedReader bufferedReader = null;
private static int infoTagState = -1;
@@ -353,30 +356,25 @@ public class EquipmentOmniLeveller {
return accessInfoTag;
}
private static void copyCashItemData(File file, String curPath) throws IOException {
printWriter = new PrintWriter(new File(OUTPUT_DIRECTORY, curPath + file.getName()), StandardCharsets.UTF_8);
fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
printWriter.println(line);
private static void copyCashItemData(Path file, String curPath) throws IOException {
try (PrintWriter pw = new PrintWriter(
Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName())));
BufferedReader br = Files.newBufferedReader(file);) {
printWriter = pw;
bufferedReader = br;
String line;
while ((line = bufferedReader.readLine()) != null) {
printWriter.println(line);
}
}
bufferedReader.close();
fileReader.close();
printWriter.close();
}
private static void parseEquipData(File file, String curPath) throws IOException {
printWriter = new PrintWriter(new File(OUTPUT_DIRECTORY, curPath + file.getName()), StandardCharsets.UTF_8);
fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
try {
private static void parseEquipData(Path file, String curPath) throws IOException {
try (PrintWriter pw = new PrintWriter(
Files.newOutputStream(OUTPUT_DIRECTORY.resolve(curPath).resolve(file.getFileName())));
BufferedReader br = Files.newBufferedReader(file);) {
printWriter = pw;
bufferedReader = br;
status = 0;
upgradeable = false;
cash = false;
@@ -384,23 +382,13 @@ public class EquipmentOmniLeveller {
String line;
while ((line = bufferedReader.readLine()) != null) {
if (translateToken(line)) {
infoTagState = status; // status: 2
infoTagState = status; // status: 2
translateInfoTag(status);
infoTagState = -1;
}
}
bufferedReader.close();
fileReader.close();
printFileFooter();
printWriter.close();
} catch (RuntimeException e) {
bufferedReader.close();
fileReader.close();
printWriter.close();
copyCashItemData(file, curPath);
}
}
@@ -413,31 +401,48 @@ public class EquipmentOmniLeveller {
}
private static void parseDirectoryEquipData(String curPath) {
File folder = new File(OUTPUT_DIRECTORY, curPath);
if (!folder.exists()) {
folder.mkdir();
Path folder = OUTPUT_DIRECTORY.resolve(curPath);
if (!Files.exists(folder)) {
try {
Files.createDirectory(folder);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Unable to create folder " + folder.toAbsolutePath() + ".");
e.printStackTrace();
}
}
System.out.println("Parsing directory '" + curPath + "'");
folder = new File(INPUT_DIRECTORY, curPath);
for (File file : folder.listFiles()) {
if (file.isFile()) {
try {
parseEquipData(file, curPath);
} catch (FileNotFoundException ex) {
System.out.println("Unable to open equip file " + file.getAbsolutePath() + ".");
} catch (IOException ex) {
System.out.println("Error reading equip file " + file.getAbsolutePath() + ".");
} catch (Exception e) {
e.printStackTrace();
folder = INPUT_DIRECTORY.resolve(curPath);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(folder)) {
for (Path path : stream) {
if (Files.isRegularFile(path)) {
try {
parseEquipData(path, curPath);
} catch (FileNotFoundException ex) {
System.out.println("Unable to open dojo file " + path.toAbsolutePath() + ".");
} catch (IOException ex) {
System.out.println("Error reading dojo file " + path.toAbsolutePath() + ".");
} catch (Exception e) {
e.printStackTrace();
}
} else {
parseDirectoryEquipData(curPath + path.getFileName() + "/");
}
} else {
parseDirectoryEquipData(curPath + file.getName() + "/");
}
} catch (IOException e1) {
System.out.println("Unable to read folder " + folder.toAbsolutePath() + ".");
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public static void main(String[] args) {
Instant instantStarted = Instant.now();
parseDirectoryEquipData("");
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -1,7 +1,8 @@
package tools.mapletools;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -22,8 +23,8 @@ import java.util.regex.Pattern;
* Estimated parse time: 1 minute
*/
public class GachaponItemIdRetriever {
private static final File INPUT_FILE = ToolConstants.getInputFile("gachapon_items.txt");
private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("gachapons");
private static final Path INPUT_FILE = ToolConstants.getInputFile("gachapon_items.txt");
private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("gachapons");
private static final Connection con = SimpleDatabaseConnection.getConnection();
private static final Pattern pattern = Pattern.compile("(\\d*)%");
private static final int[] scrollsChances = new int[]{10, 15, 30, 60, 65, 70, 100};
@@ -247,11 +248,7 @@ public class GachaponItemIdRetriever {
private static void fetchDataOnMapleHandbook() throws SQLException {
String line;
try {
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(fileReader);
try (BufferedReader bufferedReader = Files.newBufferedReader(INPUT_FILE)) {
int skip = 0;
boolean lineHeader = false;
while ((line = bufferedReader.readLine()) != null) {
@@ -276,10 +273,10 @@ public class GachaponItemIdRetriever {
if (printWriter != null) {
printWriter.close();
}
File outputFile = new File(OUTPUT_DIRECTORY, gachaponName + ".txt");
Path outputFile = OUTPUT_DIRECTORY.resolve(gachaponName + ".txt");
setupDirectories(outputFile);
printWriter = new PrintWriter(outputFile, StandardCharsets.UTF_8);
printWriter = new PrintWriter(Files.newOutputStream(outputFile));
skip = 2;
lineHeader = true;
@@ -297,30 +294,27 @@ public class GachaponItemIdRetriever {
}
}
}
if (printWriter != null) {
printWriter.close();
}
bufferedReader.close();
fileReader.close();
} catch (IOException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
private static void setupDirectories(File file) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
private static void setupDirectories(Path file) {
if (!Files.exists(file.getParent())) {
try {
Files.createDirectories(file.getParent());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
try {
try (con) {
loadHandbookUseNames();
fetchDataOnMapleHandbook();
con.close();
} catch (SQLException e) {
System.out.println("Error: invalid SQL syntax");
System.out.println(e.getMessage());

View File

@@ -2,10 +2,14 @@ package tools.mapletools;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
/**
@@ -26,8 +30,8 @@ import java.util.ArrayList;
*/
public class IdRetriever {
private static final boolean INSTALL_SQLTABLE = true;
private static final File INPUT_FILE = ToolConstants.getInputFile("fetch_ids.txt");
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("fetched_ids.txt");
private static final Path INPUT_FILE = ToolConstants.getInputFile("fetch_ids.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("fetched_ids.txt");
private static final Connection con = SimpleDatabaseConnection.getConnection();
private static InputStreamReader fileReader = null;
@@ -132,14 +136,10 @@ public class IdRetriever {
}
private static void fetchDataOnMapleHandbook() throws SQLException {
String line;
try {
fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
PrintWriter printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
try (BufferedReader br = Files.newBufferedReader(INPUT_FILE);
PrintWriter printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));) {
bufferedReader = br;
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.isEmpty()) {
printWriter.println("");
@@ -164,29 +164,27 @@ public class IdRetriever {
printWriter.println(str);
}
printWriter.close();
bufferedReader.close();
fileReader.close();
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
public static void main(String[] args) {
try {
Instant instantStarted = Instant.now();
try (con) {
if (INSTALL_SQLTABLE) {
parseMapleHandbook();
} else {
fetchDataOnMapleHandbook();
}
con.close();
} catch (SQLException e) {
System.out.println("Error: invalid SQL syntax");
e.printStackTrace();
}
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -3,7 +3,9 @@ package tools.mapletools;
import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
/**
@@ -72,17 +74,17 @@ public class MapFieldLimitChecker {
}
}
private static void listFiles(String directoryName, ArrayList<File> files) {
File directory = new File(directoryName);
// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
if (file.isFile()) {
files.add(file);
} else if (file.isDirectory()) {
listFiles(file.getAbsolutePath(), files);
private static void listFiles(Path directory, ArrayList<Path> files) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
for (Path path : stream) {
if (Files.isRegularFile(path)) {
files.add(path);
} else if (Files.isDirectory(path)) {
listFiles(path, files);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
@@ -134,18 +136,17 @@ public class MapFieldLimitChecker {
private static void loadMapWz() throws IOException {
System.out.println("Reading Map.wz ...");
ArrayList<File> files = new ArrayList<>();
listFiles(WZFiles.MAP.getFilePath() + "/Map", files);
ArrayList<Path> files = new ArrayList<>();
listFiles(WZFiles.MAP.getFile().resolve("Map"), files);
for (File f : files) {
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
for (Path f : files) {
try (BufferedReader br = Files.newBufferedReader(f)) {
bufferedReader = br;
mapid = getMapIdFromFilename(f.getName());
inspectMapEntry();
mapid = getMapIdFromFilename(f.getFileName().toString());
inspectMapEntry();
bufferedReader.close();
fileReader.close();
}
}
}

View File

@@ -5,6 +5,8 @@ import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -16,7 +18,7 @@ import java.util.List;
* the "info" node in their WZ node tree.
*/
public class MapInfoRetriever {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("map_info_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("map_info_report.txt");
private static final List<Integer> missingInfo = new ArrayList<>();
private static BufferedReader bufferedReader = null;
@@ -129,9 +131,7 @@ public class MapInfoRetriever {
}
private static void writeReport() {
try {
PrintWriter printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
try (PrintWriter printWriter = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
if (!missingInfo.isEmpty()) {
for (Integer i : missingInfo) {
printWriter.println(i);
@@ -139,8 +139,6 @@ public class MapInfoRetriever {
} else {
printWriter.println("All map files contain 'info' node.");
}
printWriter.close();
} catch (IOException e) {
e.printStackTrace();
}

View File

@@ -3,12 +3,14 @@ package tools.mapletools;
import server.life.MonsterStats;
import tools.Pair;
import java.io.File;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -27,7 +29,7 @@ import java.util.Map;
*/
public class MesoFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("meso_drop_data.sql");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("meso_drop_data.sql");
private static final boolean PERMIT_MESOS_ON_DOJO_BOSSES = false;
private static final int MESO_ID = 0;
private static final int MIN_ITEMS = 4;
@@ -119,13 +121,11 @@ public class MesoFetcher {
private static void generateMissingMobsMesoRange() {
System.out.print("Generating missing ranges... ");
Connection con = SimpleDatabaseConnection.getConnection();
List<Integer> existingMobs = new ArrayList<>(200);
try {
// select all mobs which doesn't drop mesos and have a fair amount of items dropping (meaning they are not an event mob)
PreparedStatement ps = con.prepareStatement("SELECT dropperid FROM drop_data WHERE dropperid NOT IN (SELECT DISTINCT dropperid FROM drop_data WHERE itemid = 0) GROUP BY dropperid HAVING count(*) >= " + MIN_ITEMS + ";");
ResultSet rs = ps.executeQuery();
try (Connection con = SimpleDatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT dropperid FROM drop_data WHERE dropperid NOT IN (SELECT DISTINCT dropperid FROM drop_data WHERE itemid = 0) GROUP BY dropperid HAVING count(*) >= " + MIN_ITEMS + ";");
ResultSet rs = ps.executeQuery();) {
List<Integer> existingMobs = new ArrayList<>(200);
if (rs.isBeforeFirst()) {
while (rs.next()) {
@@ -137,18 +137,19 @@ public class MesoFetcher {
}
if (!existingMobs.isEmpty()) {
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
printSqlHeader();
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
printWriter = pw;
for (int i = 0; i < existingMobs.size() - 1; i++) {
printSqlMobMesoRange(existingMobs.get(i));
printSqlHeader();
for (int i = 0; i < existingMobs.size() - 1; i++) {
printSqlMobMesoRange(existingMobs.get(i));
}
printSqlMobMesoRangeFinal(existingMobs.get(existingMobs.size() - 1));
printSqlExceptions();
}
printSqlMobMesoRangeFinal(existingMobs.get(existingMobs.size() - 1));
printSqlExceptions();
printWriter.close();
} else {
throw new Exception("ALREADY UPDATED");
}
@@ -157,10 +158,6 @@ public class MesoFetcher {
throw new Exception("ALREADY UPDATED");
}
rs.close();
ps.close();
con.close();
System.out.println("done!");
} catch (Exception e) {
@@ -173,11 +170,17 @@ public class MesoFetcher {
}
public static void main(String[] args) {
// load mob stats from WZ
Instant instantStarted = Instant.now();
// load mob stats from WZ
mobStats = MonsterStatFetcher.getAllMonsterStats();
calcAllMobsMesoRange();
generateMissingMobsMesoRange();
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -4,6 +4,8 @@ import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -16,7 +18,7 @@ import java.sql.SQLException;
* puts them on a SQL table with the correspondent mob cardid.
*/
public class MobBookIndexer {
private static final File INPUT_FILE = new File(WZFiles.STRING.getFile(), "MonsterBook.img.xml");
private static final Path INPUT_FILE = WZFiles.STRING.getFile().resolve("MonsterBook.img.xml");
private static final Connection con = SimpleDatabaseConnection.getConnection();
private static BufferedReader bufferedReader = null;
@@ -123,15 +125,13 @@ public class MobBookIndexer {
}
private static void indexFromDropData() {
// This will reference one line at a time
String line = null;
try {
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
try (con; BufferedReader br = Files.newBufferedReader(INPUT_FILE);) {
bufferedReader = br;
String line = null;
PreparedStatement ps = con.prepareStatement("DROP TABLE IF EXISTS monstercardwz;");
ps.execute();
PreparedStatement ps = con.prepareStatement("DROP TABLE IF EXISTS monstercardwz;");
ps.execute();
ps = con.prepareStatement("CREATE TABLE `monstercardwz` ("
+ "`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
@@ -141,25 +141,20 @@ public class MobBookIndexer {
+ ");");
ps.execute();
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
bufferedReader.close();
fileReader.close();
con.close();
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + INPUT_FILE + "'");
} catch (IOException ex) {
System.out.println("Error reading file '" + INPUT_FILE + "'");
} catch (SQLException e) {
System.out.println("Warning: Could not establish connection to database to change card chance rate.");
System.out.println(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + INPUT_FILE + "'");
} catch (IOException ex) {
System.out.println("Error reading file '" + INPUT_FILE + "'");
} catch (SQLException e) {
System.out.println("Warning: Could not establish connection to database to change card chance rate.");
System.out.println(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {

View File

@@ -3,7 +3,8 @@ package tools.mapletools;
import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -26,8 +27,8 @@ import java.sql.SQLException;
* remove the property 'MonsterBook.img' inside 'string.wz' and choose to import the xml generated with this software.
*/
public class MobBookUpdate {
private static final File INPUT_FILE = new File(WZFiles.STRING.getFile(), "MonsterBook.img.xml");
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("MonsterBook_updated.img.xml");
private static final Path INPUT_FILE = WZFiles.STRING.getFile().resolve("MonsterBook.img.xml");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("MonsterBook_updated.img.xml");
private static final Connection con = SimpleDatabaseConnection.getConnection();
private static PrintWriter printWriter = null;
@@ -143,23 +144,17 @@ public class MobBookUpdate {
}
private static void updateFromDropData() {
// This will reference one line at a time
String line = null;
try (con;
PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));
BufferedReader br = Files.newBufferedReader(INPUT_FILE);) {
printWriter = pw;
bufferedReader = br;
try {
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
printWriter.close();
bufferedReader.close();
fileReader.close();
con.close();
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + INPUT_FILE + "'");
} catch (IOException ex) {

View File

@@ -11,6 +11,8 @@ import server.life.LifeFactory.selfDestruction;
import server.life.MonsterStats;
import tools.Pair;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
public class MonsterStatFetcher {
@@ -140,4 +142,15 @@ public class MonsterStatFetcher {
}
}
public static void main(String[] args) {
Instant instantStarted = Instant.now();
// load mob stats from WZ
Map<Integer, MonsterStats> mobStats = MonsterStatFetcher.getAllMonsterStats();
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -4,6 +4,8 @@ import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -20,7 +22,7 @@ import java.util.*;
* A file is generated listing all the inexistent ids.
*/
public class NoItemIdFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("no_item_id_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("no_item_id_report.txt");
private static final Connection con = SimpleDatabaseConnection.getConnection();
private static final Set<Integer> existingIds = new HashSet<>();
@@ -174,7 +176,7 @@ public class NoItemIdFetcher {
}
private static void evaluateDropsFromDb() {
try {
try (con) {
System.out.println("Evaluating item data on DB...");
evaluateDropsFromTable("drop_data");
@@ -192,23 +194,19 @@ public class NoItemIdFetcher {
System.out.println("Inexistent itemid count: " + nonExistingIds.size());
System.out.println("Total itemid count: " + existingIds.size());
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
printWriter = pw;
existingIds.add(0); // meso itemid
readEquipDataDirectory(WZFiles.CHARACTER.getFilePath());
readItemDataDirectory(WZFiles.ITEM.getFilePath());
evaluateDropsFromDb();
printWriter.close();
} catch (Exception e) {
e.printStackTrace();
}

View File

@@ -3,9 +3,9 @@ package tools.mapletools;
import provider.*;
import provider.wz.WZFiles;
import java.io.File;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/**
@@ -19,8 +19,8 @@ import java.util.*;
* Estimated parse time: 2 minutes
*/
public class NoItemNameFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("no_item_name_result.txt");
private static final File OUTPUT_XML_FILE = ToolConstants.getOutputFile("no_item_name_xml.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("no_item_name_result.txt");
private static final Path OUTPUT_XML_FILE = ToolConstants.getOutputFile("no_item_name_xml.txt");
private static final Map<Integer, String> itemsWzPath = new HashMap<>();
private static final Map<Integer, EquipType> equipTypes = new HashMap<>();
@@ -435,32 +435,32 @@ public class NoItemNameFetcher {
private static void writeMissingStringWZNames(Map<String, List<Integer>> missingNames) throws Exception {
System.out.println("Writing remaining 'String.wz' names...");
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_XML_FILE))) {
printWriter = pw;
printWriter = new PrintWriter(OUTPUT_XML_FILE, StandardCharsets.UTF_8);
printOutputFileHeader();
printOutputFileHeader();
String[] nodePaths = { "Cash.img", "Consume.img", "Eqp.img", "Etc.img", "Ins.img", "Pet.img" };
for (int i = 0; i < nodePaths.length; i++) {
writeMissingStringWZNode(nodePaths[i], missingNames.get(nodePaths[i]), i == 2);
}
String[] nodePaths = {"Cash.img", "Consume.img", "Eqp.img", "Etc.img", "Ins.img", "Pet.img"};
for (int i = 0; i < nodePaths.length; i++) {
writeMissingStringWZNode(nodePaths[i], missingNames.get(nodePaths[i]), i == 2);
}
printWriter.close();
}
public static void main(String[] args) {
try {
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
printWriter = pw;
curType = ItemType.EQP;
readEquipWZData();
curType = ItemType.UNDEF;
readItemWZData();
readStringWZData(); // calculates the diff and effectively holds all items with no name property on the WZ
readStringWZData(); // calculates the diff and effectively holds all items with no name property on the WZ
System.out.println("Reporting results...");
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
printReportFileHeader();
printReportFileResults();
printWriter.close();
Map<String, List<Integer>> missingNames = filterMissingItemNames();
writeMissingStringWZNames(missingNames);

View File

@@ -5,6 +5,8 @@ import tools.Pair;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/**
@@ -17,7 +19,7 @@ import java.util.*;
* Running it should generate a report file under "output" folder with the search results.
*/
public class QuestItemCountFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_item_count_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_item_count_report.txt");
private static final String ACT_NAME = WZFiles.QUEST.getFilePath() + "/Act.img.xml";
private static final String CHECK_NAME = WZFiles.QUEST.getFilePath() + "/Check.img.xml";
private static final int INITIAL_STRING_LENGTH = 50;
@@ -241,17 +243,16 @@ public class QuestItemCountFetcher {
private static void reportQuestItemCountData() {
// This will reference one line at a time
try {
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
System.out.println("Reading WZs...");
readQuestItemCountData();
System.out.println("Reporting results...");
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
printWriter = pw;
printReportFileHeader();
printReportFileResults();
printWriter.close();
System.out.println("Done!");
} catch (FileNotFoundException ex) {
System.out.println("Unable to open quest file.");

View File

@@ -8,6 +8,8 @@ import tools.Pair;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -25,7 +27,7 @@ import java.util.*;
* Estimated parse time: 1 minute
*/
public class QuestItemFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_report.txt");
private static final int INITIAL_STRING_LENGTH = 50;
private static final int INITIAL_LENGTH = 200;
private static final boolean DISPLAY_EXTRA_INFO = true; // display items with zero quantity over the quest act WZ
@@ -409,32 +411,28 @@ public class QuestItemFetcher {
private static void reportQuestItemData() {
// This will reference one line at a time
String line = null;
String fileName = null;
Path file = null;
try {
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
System.out.println("Reading WZs...");
fileName = WZFiles.QUEST.getFilePath() + "/Check.img.xml";
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
file = WZFiles.QUEST.getFile().resolve("Check.img.xml");
bufferedReader = Files.newBufferedReader(file);
while ((line = bufferedReader.readLine()) != null) {
translateCheckToken(line); // fetch expired quests through here as well
translateCheckToken(line); // fetch expired quests through here as well
}
bufferedReader.close();
fileReader.close();
fileName = WZFiles.QUEST.getFilePath() + "/Act.img.xml";
fileReader = new InputStreamReader(new FileInputStream(fileName), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
file = WZFiles.QUEST.getFile().resolve("Act.img.xml");
bufferedReader = Files.newBufferedReader(file);
while ((line = bufferedReader.readLine()) != null) {
translateActToken(line);
}
bufferedReader.close();
fileReader.close();
System.out.println("Calculating table diffs...");
calculateQuestItemDiff();
@@ -452,8 +450,9 @@ public class QuestItemFetcher {
filterDirectorySearchMatchingData("src", itemsWithQuest);
System.out.println("Reporting results...");
// report suspects of missing quest drop data, as well as those drop data that may have incorrect questids.
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
// report suspects of missing quest drop data, as well as those drop data that
// may have incorrect questids.
printWriter = pw;
printReportFileHeader();
@@ -505,12 +504,11 @@ public class QuestItemFetcher {
}
}
printWriter.close();
System.out.println("Done!");
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + fileName + "'");
System.out.println("Unable to open file '" + file + "'");
} catch (IOException ex) {
System.out.println("Error reading file '" + fileName + "'");
System.out.println("Error reading file '" + file + "'");
} catch (SQLException e) {
System.out.println("Warning: Could not establish connection to database to report quest data.");
System.out.println(e.getMessage());

View File

@@ -3,7 +3,8 @@ package tools.mapletools;
import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/**
@@ -16,7 +17,7 @@ import java.util.*;
* Running it should generate a report file under "output" folder with the search results.
*/
public class QuestMesoFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("quest_meso_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("quest_meso_report.txt");
private static final boolean PRINT_FEES = true; // print missing values as additional info report
private static final int INITIAL_STRING_LENGTH = 50;
@@ -147,25 +148,21 @@ public class QuestMesoFetcher {
private static void readQuestMesoData() throws IOException {
String line;
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(WZFiles.QUEST.getFilePath() + "/Act.img.xml"), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
bufferedReader = Files.newBufferedReader(WZFiles.QUEST.getFile().resolve("Act.img.xml"));
while ((line = bufferedReader.readLine()) != null) {
translateTokenAct(line);
}
bufferedReader.close();
fileReader.close();
fileReader = new InputStreamReader(new FileInputStream(WZFiles.QUEST.getFilePath() + "/Check.img.xml"), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
bufferedReader = Files.newBufferedReader(WZFiles.QUEST.getFile().resolve("Check.img.xml"));
while ((line = bufferedReader.readLine()) != null) {
translateTokenCheck(line);
}
bufferedReader.close();
fileReader.close();
}
private static void printReportFileHeader() {
@@ -232,20 +229,19 @@ public class QuestMesoFetcher {
private static void reportQuestMesoData() {
// This will reference one line at a time
try {
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
System.out.println("Reading WZs...");
readQuestMesoData();
System.out.println("Reporting results...");
// report missing meso checks on quest completes
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
printWriter = pw;
printReportFileHeader();
printReportFileResults(checkedMesoQuests, appliedMesoQuests, true);
printReportFileResults(appliedMesoQuests, checkedMesoQuests, false);
printWriter.close();
System.out.println("Done!");
} catch (FileNotFoundException ex) {
System.out.println("Unable to open quest file.");

View File

@@ -4,6 +4,10 @@ import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
/**
@@ -18,7 +22,7 @@ import java.util.*;
* Running it should generate a report file under "output" folder with the search results.
*/
public class QuestlineFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("questline_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("questline_report.txt");
private static final String ACT_NAME = WZFiles.QUEST.getFilePath() + "/Act.img.xml";
private static final String CHECK_NAME = WZFiles.QUEST.getFilePath() + "/Check.img.xml";
private static final int INITIAL_STRING_LENGTH = 50;
@@ -289,7 +293,7 @@ public class QuestlineFetcher {
private static void reportQuestlineData() {
// This will reference one line at a time
try {
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
System.out.println("Reading quest scripts...");
instantiateQuestScriptFiles(ToolConstants.SCRIPTS_PATH + "/quest");
@@ -301,12 +305,11 @@ public class QuestlineFetcher {
calculateSkillRelatedMissingQuestScripts();
System.out.println("Reporting results...");
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
printWriter = pw;
printReportFileHeader();
printReportFileResults();
printWriter.close();
System.out.println("Done!");
} catch (FileNotFoundException ex) {
System.out.println("Unable to open quest file.");
@@ -356,7 +359,13 @@ public class QuestlineFetcher {
*/
public static void main(String[] args) {
Instant instantStarted = Instant.now();
reportQuestlineData();
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -1,8 +1,11 @@
package tools.mapletools;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -16,7 +19,7 @@ import java.util.*;
* not yet coded.
*/
public class ReactorDropFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("reactor_drop_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("reactor_drop_report.txt");
private static final String REACTOR_SCRIPT_PATH = ToolConstants.SCRIPTS_PATH + "/reactor";
private static final Connection con = SimpleDatabaseConnection.getConnection();
@@ -38,14 +41,14 @@ public class ReactorDropFetcher {
}
private static void removeScriptedReactorids(String directoryName) {
File directory = new File(directoryName);
// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
if (file.isFile()) {
reactors.remove(getReactorIdFromFilename(file.getName()));
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(directoryName))) {
for (Path path : stream) {
if (Files.isRegularFile(path)) {
reactors.remove(getReactorIdFromFilename(path.getFileName().toString()));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
@@ -84,19 +87,18 @@ public class ReactorDropFetcher {
}
private static void reportMissingReactors() {
try {
try (con; PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
System.out.println("Fetching reactors from DB...");
fetchMissingReactorDrops();
con.close();
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
printWriter = pw;
// report suspects of missing quest drop data, as well as those drop data that may have incorrect questids.
// report suspects of missing quest drop data, as well as those drop data that
// may have incorrect questids.
System.out.println("Reporting results...");
printReportFileHeader();
reportMissingReactorDrops();
printWriter.close();
System.out.println("Done!");
} catch (SQLException e) {
System.out.println("Warning: Could not establish connection to database to report quest data.");

View File

@@ -5,7 +5,8 @@ import server.ItemInformationProvider;
import tools.DatabaseConnection;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -20,8 +21,8 @@ import java.util.Map;
*/
public class SkillMakerFetcher {
private static final File INPUT_FILE = new File(WZFiles.ETC.getFile(), "ItemMake.img.xml");
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("maker-data.sql");
private static final Path INPUT_FILE = WZFiles.ETC.getFile().resolve("ItemMake.img.xml");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("maker-data.sql");
private static final int INITIAL_STRING_LENGTH = 50;
private static PrintWriter printWriter = null;
@@ -299,14 +300,14 @@ public class SkillMakerFetcher {
printWriter.println(sb_reward);
}
private static void writeMakerTableData() {
// This will reference one line at a time
private static void writeMakerTableData() {
// This will reference one line at a time
String line = null;
try {
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));
BufferedReader br = Files.newBufferedReader(INPUT_FILE);) {
printWriter = pw;
bufferedReader = br;
resetMakerDataFields();
@@ -316,9 +317,6 @@ public class SkillMakerFetcher {
WriteMakerTableFile();
printWriter.close();
bufferedReader.close();
fileReader.close();
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + INPUT_FILE + "'");
} catch (IOException ex) {
@@ -326,7 +324,7 @@ public class SkillMakerFetcher {
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
DatabaseConnection.initializeConnectionPool(); // Using ItemInformationProvider which loads som unrelated things from the db

View File

@@ -4,7 +4,8 @@ import provider.wz.WZFiles;
import tools.Pair;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@@ -16,8 +17,8 @@ import java.util.List;
* by the server source.
*/
public class SkillMakerReagentIndexer {
private static final File INPUT_FILE = new File(WZFiles.ITEM.getFile(), "Etc/0425.img.xml");
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("maker-reagent-data.sql");
private static final Path INPUT_FILE = WZFiles.ITEM.getFile().resolve("Etc/0425.img.xml");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("maker-reagent-data.sql");
private static final int INITIAL_STRING_LENGTH = 50;
private static final List<Pair<Integer, Pair<String, Integer>>> reagentList = new ArrayList<>();
@@ -147,26 +148,22 @@ public class SkillMakerReagentIndexer {
printWriter.println(sb);
}
private static void writeMakerReagentTableData() {
private static void writeMakerReagentTableData() {
// This will reference one line at a time
String line = null;
try {
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(INPUT_FILE), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE));
BufferedReader br = Files.newBufferedReader(INPUT_FILE);) {
bufferedReader = br;
while ((line = bufferedReader.readLine()) != null) {
translateToken(line);
}
bufferedReader.close();
fileReader.close();
SortReagentList();
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
printWriter = pw;
WriteMakerReagentTableFile();
printWriter.close();
} catch (FileNotFoundException ex) {
System.out.println("Unable to open file '" + OUTPUT_FILE + "'");
} catch (IOException ex) {

View File

@@ -3,10 +3,10 @@ package tools.mapletools;
import server.life.MonsterStats;
import tools.Pair;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -27,7 +27,7 @@ import java.util.Map;
* drops.
*/
public class SkillbookChanceFetcher {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("skillbook_drop_data.sql");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("skillbook_drop_data.sql");
private static final Map<Pair<Integer, Integer>, Integer> skillbookChances = new HashMap<>();
private static PrintWriter printWriter;
@@ -102,17 +102,17 @@ public class SkillbookChanceFetcher {
}
private static void generateSkillbookChanceUpdateFile() {
try {
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
printWriter = pw;
printSkillbookChanceUpdateSqlHeader();
List<Map.Entry<Pair<Integer, Integer>, Integer>> skillbookChancesList = sortedSkillbookChances();
for (Map.Entry<Pair<Integer, Integer>, Integer> e : skillbookChancesList) {
printWriter.println("(" + e.getKey().getLeft() + ", " + e.getKey().getRight() + ", 1, 1, 0, " + e.getValue() + "),");
printWriter.println("(" + e.getKey().getLeft() + ", " + e.getKey().getRight() + ", 1, 1, 0, "
+ e.getValue() + "),");
}
printWriter.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}

View File

@@ -3,7 +3,11 @@ package tools.mapletools;
import provider.wz.WZFiles;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
/**
* @author RonanLana
@@ -15,8 +19,8 @@ import java.nio.charset.StandardCharsets;
* Estimated parse time: 10 seconds
*/
public class SkillbookStackUpdate {
private static final File INPUT_DIRECTORY = new File(WZFiles.ITEM.getFile(), "Consume");
private static final File OUTPUT_DIRECTORY = ToolConstants.getOutputFile("skillbook-update");
private static final Path INPUT_DIRECTORY = WZFiles.ITEM.getFile().resolve("Consume");
private static final Path OUTPUT_DIRECTORY = ToolConstants.getOutputFile("skillbook-update");
private static final int INITIAL_STRING_LENGTH = 50;
private static PrintWriter printWriter = null;
@@ -65,7 +69,6 @@ public class SkillbookStackUpdate {
private static void forwardCursor(int st) {
String line = null;
try {
while (status >= st && (line = bufferedReader.readLine()) != null) {
simpleToken(line);
@@ -111,47 +114,55 @@ public class SkillbookStackUpdate {
printWriter.println(token);
}
private static void parseItemFile(File file, File outputFile) {
setupDirectories(outputFile);
// This will reference one line at a time
String line = null;
private static void parseItemFile(Path file, Path outputFile) {
setupDirectories(outputFile);
try {
printWriter = new PrintWriter(outputFile);
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(fileReader);
try (BufferedReader br = Files.newBufferedReader(file);
PrintWriter pw = new PrintWriter(Files.newOutputStream(outputFile))) {
bufferedReader = br;
printWriter = pw;
String line;
while ((line = bufferedReader.readLine()) != null) {
translateItemToken(line);
}
} catch (IOException ex) {
System.out.println("Error reading file '" + file.getFileName() + "'");
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
while ((line = bufferedReader.readLine()) != null) {
translateItemToken(line);
private static void setupDirectories(Path file) {
if (!Files.exists(file.getParent())) {
try {
Files.createDirectories(file.getParent());
} catch (IOException e) {
System.out.println("Error creating folder '" + file.getParent() + "'");
e.printStackTrace();
}
}
}
private static void parseItemDirectory(Path inputDirectory, Path outputDirectory) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(inputDirectory)) {
for (Path path : stream) {
parseItemFile(path, outputDirectory.resolve(path.getFileName()));
}
bufferedReader.close();
fileReader.close();
printWriter.close();
} catch (IOException ex) {
System.out.println("Error reading file '" + file.getName() + "'");
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void setupDirectories(File file) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
}
private static void parseItemDirectory(File inputDirectory, File outputDirectory) {
for (File f : inputDirectory.listFiles()) {
parseItemFile(f, new File(outputDirectory, f.getName()));
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Instant instantStarted = Instant.now();
System.out.println("Reading item files...");
parseItemDirectory(INPUT_DIRECTORY, OUTPUT_DIRECTORY);
System.out.println("Done!");
Instant instantStopped = Instant.now();
Duration durationBetween = Duration.between(instantStarted, instantStopped);
System.out.println("Get elapsed time in milliseconds: " + durationBetween.toMillis());
System.out.println("Get elapsed time in seconds: " + durationBetween.toSeconds());
}
}

View File

@@ -1,18 +1,19 @@
package tools.mapletools;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
class ToolConstants {
static final File INPUT_DIRECTORY = new File("tools/input");
static final File OUTPUT_DIRECTORY = new File("tools/output");
static final Path INPUT_DIRECTORY = Paths.get("tools/input");
static final Path OUTPUT_DIRECTORY = Paths.get("tools/output");
static final String SCRIPTS_PATH = "scripts";
static final String HANDBOOK_PATH = "handbook";
static File getInputFile(String fileName) {
return new File(INPUT_DIRECTORY, fileName);
static Path getInputFile(String fileName) {
return INPUT_DIRECTORY.resolve(fileName);
}
static File getOutputFile(String fileName) {
return new File(OUTPUT_DIRECTORY, fileName);
static Path getOutputFile(String fileName) {
return OUTPUT_DIRECTORY.resolve(fileName);
}
}

View File

@@ -5,6 +5,8 @@ import tools.Pair;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/**
@@ -14,7 +16,7 @@ import java.util.*;
* throughout the map tree (area map -> continent map -> world map) but are currently missing.
*/
public class WorldmapChecker {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("worldmap_report.txt");
private static final Path OUTPUT_FILE = ToolConstants.getOutputFile("worldmap_report.txt");
private static final int INITIAL_STRING_LENGTH = 50;
private static final Map<String, Set<Integer>> worldMapids = new HashMap<>();
private static final Map<String, String> parentWorldmaps = new HashMap<>();
@@ -186,8 +188,8 @@ public class WorldmapChecker {
}
private static void verifyWorldmapTreeMapids() {
try {
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(OUTPUT_FILE))) {
printWriter = pw;
printReportFileHeader();
if (rootWorldmaps.size() > 1) {
@@ -242,7 +244,6 @@ public class WorldmapChecker {
printReportFileResults(unreferencedEntries);
}
printWriter.close();
} catch (Exception e) {
e.printStackTrace();
}