diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index 7026c3962..a7e7a67cb 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -8,6 +8,7 @@ import java.util.Map; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.binout.*; +import emu.grasscutter.game.quest.QuestEncryptionKey; import emu.grasscutter.utils.Utils; import emu.grasscutter.data.excels.*; import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; @@ -25,6 +26,7 @@ public class GameData { private static final Map openConfigEntries = new HashMap<>(); private static final Map scenePointEntries = new HashMap<>(); private static final Int2ObjectMap mainQuestData = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap questsKeys = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap homeworldDefaultSaveData = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap npcBornData = new Int2ObjectOpenHashMap<>(); @@ -163,6 +165,10 @@ public class GameData { return mainQuestData; } + public static Int2ObjectMap getMainQuestEncryptionMap() { + return questsKeys; + } + public static Int2ObjectMap getHomeworldDefaultSaveData() { return homeworldDefaultSaveData; } diff --git a/src/main/java/emu/grasscutter/data/ResourceLoader.java b/src/main/java/emu/grasscutter/data/ResourceLoader.java index 61b329250..b2ddbe5d6 100644 --- a/src/main/java/emu/grasscutter/data/ResourceLoader.java +++ b/src/main/java/emu/grasscutter/data/ResourceLoader.java @@ -1,5 +1,25 @@ package emu.grasscutter.data; +import com.google.gson.JsonElement; +import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.binout.*; +import emu.grasscutter.data.binout.AbilityModifier.AbilityConfigData; +import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; +import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierActionType; +import emu.grasscutter.data.common.PointData; +import emu.grasscutter.data.common.ScenePointConfig; +import emu.grasscutter.game.quest.QuestEncryptionKey; +import emu.grasscutter.game.world.SpawnDataEntry; +import emu.grasscutter.game.world.SpawnDataEntry.GridBlockId; +import emu.grasscutter.game.world.SpawnDataEntry.SpawnGroupEntry; +import emu.grasscutter.scripts.SceneIndexManager; +import emu.grasscutter.utils.Utils; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import lombok.SneakyThrows; +import org.reflections.Reflections; + import java.io.*; import java.lang.reflect.Type; import java.nio.file.Files; @@ -9,27 +29,7 @@ import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; -import emu.grasscutter.data.binout.*; -import emu.grasscutter.game.world.SpawnDataEntry; -import emu.grasscutter.scripts.SceneIndexManager; -import emu.grasscutter.utils.Utils; -import lombok.SneakyThrows; -import org.reflections.Reflections; - -import com.google.gson.JsonElement; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.binout.AbilityModifier.AbilityConfigData; -import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction; -import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierActionType; -import emu.grasscutter.data.common.PointData; -import emu.grasscutter.data.common.ScenePointConfig; -import emu.grasscutter.game.world.SpawnDataEntry.*; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; - -import static emu.grasscutter.config.Configuration.*; +import static emu.grasscutter.config.Configuration.RESOURCE; import static emu.grasscutter.utils.Language.translate; public class ResourceLoader { @@ -417,6 +417,18 @@ public class ResourceLoader { GameData.getMainQuestDataMap().put(mainQuest.getId(), mainQuest); } + try (Reader reader = DataLoader.loadReader("QuestEncryptionKeys.json")) { + List keys = Grasscutter.getGsonFactory().fromJson( + reader, + TypeToken.getParameterized(List.class, QuestEncryptionKey.class).getType()); + + Int2ObjectMap questEncryptionMap = GameData.getMainQuestEncryptionMap(); + keys.forEach(key -> questEncryptionMap.put(key.getMainQuestId(), key)); + Grasscutter.getLogger().info("loaded {} quest keys.", questEncryptionMap.size()); + } catch (Exception e) { + Grasscutter.getLogger().error("Unable to load quest keys.", e); + } + Grasscutter.getLogger().debug("Loaded " + GameData.getMainQuestDataMap().size() + " MainQuestDatas."); } diff --git a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java index 9117be4c1..df2a7d826 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameMainQuest.java @@ -132,7 +132,8 @@ public class GameMainQuest { ParentQuest.Builder proto = ParentQuest.newBuilder() .setParentQuestId(getParentQuestId()) .setIsFinished(isFinished()) - .setParentQuestState(getState().getValue()); + .setParentQuestState(getState().getValue()) + .setCutsceneEncryptionKey(QuestManager.getQuestKey(parentQuestId)); for (GameQuest quest : this.getChildQuests().values()) { ChildQuest childQuest = ChildQuest.newBuilder() diff --git a/src/main/java/emu/grasscutter/game/quest/QuestEncryptionKey.java b/src/main/java/emu/grasscutter/game/quest/QuestEncryptionKey.java new file mode 100644 index 000000000..9d01bbb64 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/quest/QuestEncryptionKey.java @@ -0,0 +1,12 @@ +package emu.grasscutter.game.quest; + +import lombok.AccessLevel; +import lombok.Data; +import lombok.experimental.FieldDefaults; + +@Data +@FieldDefaults(level = AccessLevel.PRIVATE) +public class QuestEncryptionKey { + int mainQuestId; + long encryptionKey; +} diff --git a/src/main/java/emu/grasscutter/game/quest/QuestManager.java b/src/main/java/emu/grasscutter/game/quest/QuestManager.java index c8049f362..525231626 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestManager.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestManager.java @@ -2,8 +2,6 @@ package emu.grasscutter.game.quest; import java.util.*; import java.util.function.Consumer; -import java.util.stream.Collectors; - import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; import emu.grasscutter.data.binout.MainQuestData; @@ -23,6 +21,11 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; public class QuestManager extends BasePlayerManager { private final Int2ObjectMap quests; + public static long getQuestKey(int mainQuestId){ + QuestEncryptionKey questEncryptionKey = GameData.getMainQuestEncryptionMap().get(mainQuestId); + return questEncryptionKey != null ? questEncryptionKey.getEncryptionKey() : 0L; + } + public QuestManager(Player player) { super(player); this.quests = new Int2ObjectOpenHashMap<>();