diff --git a/src/main/java/emu/grasscutter/tools/Dumpers.java b/src/main/java/emu/grasscutter/tools/Dumpers.java index deaf5e757..c7e3bf752 100644 --- a/src/main/java/emu/grasscutter/tools/Dumpers.java +++ b/src/main/java/emu/grasscutter/tools/Dumpers.java @@ -204,6 +204,42 @@ public interface Dumpers { } } + /** + * Dumps all entities to a JSON file. + * + * @param locale The language to dump the entities in. + */ + static void dumpEntities(String locale) { + // Reload resources. + ResourceLoader.loadAll(); + Language.loadTextMaps(); + + // Convert all known avatars to an avatar map. + var dump = new HashMap(); + GameData.getMonsterDataMap().forEach((id, monster) -> { + var langHash = monster.getNameTextMapHash(); + dump.put(id, new EntityInfo( + langHash == 0 ? monster.getMonsterName() : + Language.getTextMapKey(langHash).get(locale), + monster.getMonsterName() + )); + }); + + try { + // Create a file for the dump. + var file = new File("entities.csv"); + if (file.exists() && !file.delete()) + throw new RuntimeException("Failed to delete file."); + if (!file.exists() && !file.createNewFile()) + throw new RuntimeException("Failed to create file."); + + // Write the dump to the file. + Files.writeString(file.toPath(), Dumpers.miniEncode(dump)); + } catch (IOException ignored) { + throw new RuntimeException("Failed to write to file."); + } + } + @AllArgsConstructor class CommandInfo { public List name; @@ -254,6 +290,18 @@ public interface Dumpers { } } + @AllArgsConstructor + class EntityInfo { + public String name; + public String internal; + + @Override + public String toString() { + return this.name + "," + + this.internal; + } + } + enum Quality { LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN; diff --git a/src/main/java/emu/grasscutter/utils/StartupArguments.java b/src/main/java/emu/grasscutter/utils/StartupArguments.java index 8c06d25fd..dfae34b2c 100644 --- a/src/main/java/emu/grasscutter/utils/StartupArguments.java +++ b/src/main/java/emu/grasscutter/utils/StartupArguments.java @@ -153,6 +153,7 @@ public final class StartupArguments { case "avatars" -> Dumpers.dumpAvatars(language); case "items" -> Dumpers.dumpItems(language); case "scenes" -> Dumpers.dumpScenes(); + case "entities" -> Dumpers.dumpEntities(language); } Grasscutter.getLogger().info("Finished dumping.");