-
Notifications
You must be signed in to change notification settings - Fork 33
Questpatches #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Questpatches #86
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e68f0a8
quest patches fix
omar-akermi 7cdce5c
Merge branch 'bleeding-edge' into questpatches
omar-akermi 78bec8b
fix for mono
omar-akermi 79b610d
Merge remote-tracking branch 'origin/questpatches' into questpatches
omar-akermi 41d3b05
changes for max
omar-akermi fd280c4
fix: using logger
omar-akermi e7df9c0
change exception handling
omar-akermi f115cdd
fix: save under Modded/Quests
omar-akermi 25daf94
fix: load path
omar-akermi eaeb339
fix: no singleton usage savemanager.instance
omar-akermi e84c658
fix: singelton in load
omar-akermi 84bd747
fix: directory creation instead of log
omar-akermi a608613
Merge branch 'bleeding-edge' into questpatches
omar-akermi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,14 @@ | |
| using S1Loaders = Il2CppScheduleOne.Persistence.Loaders; | ||
| using S1Datas = Il2CppScheduleOne.Persistence.Datas; | ||
| using S1Quests = Il2CppScheduleOne.Quests; | ||
| using S1Persistence = Il2CppScheduleOne.Persistence; | ||
| #elif (MONOMELON || MONOBEPINEX || IL2CPPBEPINEX) | ||
| using S1Loaders = ScheduleOne.Persistence.Loaders; | ||
| using S1Datas = ScheduleOne.Persistence.Datas; | ||
| using S1Quests = ScheduleOne.Quests; | ||
| #endif | ||
| using S1Persistence = ScheduleOne.Persistence; | ||
|
|
||
| #endif | ||
| #if (IL2CPPMELON || IL2CPPBEPINEX) | ||
| using Il2CppSystem.Collections.Generic; | ||
| #elif (MONOMELON || MONOBEPINEX) | ||
|
|
@@ -19,63 +21,80 @@ | |
| using System.Linq; | ||
| using HarmonyLib; | ||
| using Newtonsoft.Json; | ||
| using S1API.Internal.Abstraction; | ||
| using S1API.Internal.Utils; | ||
| using S1API.Quests; | ||
| using UnityEngine; | ||
| using ISaveable = S1API.Internal.Abstraction.ISaveable; | ||
|
|
||
| namespace S1API.Internal.Patches | ||
| { | ||
| /// <summary> | ||
| /// INTERNAL: All patches related to quests. | ||
| /// INTERNAL: Contains patches specific to quest handling and modification. | ||
| /// </summary> | ||
| [HarmonyPatch] | ||
| internal class QuestPatches | ||
| { | ||
| protected static readonly Logging.Log Logger = new Logging.Log("QuestPatches"); | ||
|
|
||
| /// <summary> | ||
| /// Patching performed when all quests are saved. | ||
| /// Invoked after all quests are saved. | ||
| /// Ensures that modded quest data is correctly saved to a designated folder. | ||
| /// </summary> | ||
| /// <param name="__instance">Instance of the quest manager.</param> | ||
| /// <param name="parentFolderPath">Path to the base Quest folder.</param> | ||
| /// <param name="__result">List of extra saveable data. The game uses this for cleanup later.</param> | ||
| [HarmonyPatch(typeof(S1Quests.QuestManager), "WriteData")] | ||
| /// <param name="saveFolderPath">The path to the primary save folder where quest data will be stored.</param> | ||
| [HarmonyPatch(typeof(S1Persistence.SaveManager), nameof(S1Persistence.SaveManager.Save), typeof(string))] | ||
| [HarmonyPostfix] | ||
| private static void QuestManagerWriteData(S1Quests.QuestManager __instance, string parentFolderPath, ref List<string> __result) | ||
| private static void SaveManager_Save_Postfix(string saveFolderPath) | ||
| { | ||
| string questsPath = Path.Combine(parentFolderPath, "Quests"); | ||
| try | ||
| { | ||
| string moddedQuestsPath = Path.Combine(saveFolderPath, "..\\Players\\ModdedQuests"); | ||
|
|
||
| if (!Directory.Exists(moddedQuestsPath)) | ||
| Directory.CreateDirectory(moddedQuestsPath); | ||
|
|
||
| foreach (Quest quest in QuestManager.Quests) | ||
| { | ||
|
|
||
| foreach (Quest quest in QuestManager.Quests) | ||
| quest.SaveInternal(questsPath, ref __result); | ||
| List<string> dummy = new List<string>(); | ||
|
|
||
| quest.SaveInternal(moddedQuestsPath, ref dummy); | ||
|
|
||
| } | ||
|
|
||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Logger.Error("Failed during SaveManager_Save_Postfix execution.\n" + ex); | ||
|
||
| throw; | ||
| } | ||
MaxtorCoder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Patching performed for when all quests are loaded. | ||
| /// Patching performed for when all quests are loaded from the modded quests directory. | ||
| /// </summary> | ||
| /// <param name="__instance">Instance of the quest loader.</param> | ||
| /// <param name="mainPath">Path to the base Quest folder.</param> | ||
| /// <param name="__instance">Instance of the quest loader responsible for loading quests.</param> | ||
| /// <param name="mainPath">Path to the base Quest folder where quests are located.</param> | ||
| [HarmonyPatch(typeof(S1Loaders.QuestsLoader), "Load")] | ||
| [HarmonyPostfix] | ||
| private static void QuestsLoaderLoad(S1Loaders.QuestsLoader __instance, string mainPath) | ||
| { | ||
| // Make sure we have a quests directory (fresh saves don't at this point in runtime) | ||
| if (!Directory.Exists(mainPath)) | ||
| return; | ||
| string moddedQuestsPath = Path.Combine(mainPath, "..\\Players\\ModdedQuests"); | ||
omar-akermi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| string[] questDirectories = Directory.GetDirectories(mainPath) | ||
| string[] questDirectories = Directory.GetDirectories(moddedQuestsPath) | ||
| .Select(Path.GetFileName) | ||
| .Where(directory => directory != null && directory.StartsWith("Quest_")) | ||
| .ToArray()!; | ||
|
|
||
| foreach (string questDirectory in questDirectories) | ||
| { | ||
| string baseQuestPath = Path.Combine(mainPath, questDirectory); | ||
| string baseQuestPath = Path.Combine(moddedQuestsPath, questDirectory); | ||
| __instance.TryLoadFile(baseQuestPath, out string questDataText); | ||
| if (questDataText == null) | ||
| continue; | ||
|
|
||
| S1Datas.QuestData baseQuestData = JsonUtility.FromJson<S1Datas.QuestData>(questDataText); | ||
|
|
||
| string questDirectoryPath = Path.Combine(mainPath, questDirectory); | ||
| string questDirectoryPath = Path.Combine(moddedQuestsPath, questDirectory); | ||
| string questDataPath = Path.Combine(questDirectoryPath, "QuestData"); | ||
| if (!__instance.TryLoadFile(questDataPath, out string questText)) | ||
| continue; | ||
|
|
@@ -93,26 +112,11 @@ private static void QuestsLoaderLoad(S1Loaders.QuestsLoader __instance, string m | |
| } | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Patching performed for when stale files are deleted. | ||
| /// Executes custom initialization logic whenever a quest starts. | ||
| /// </summary> | ||
| /// <param name="__instance">Instance of the quest manager.</param> | ||
| /// <param name="parentFolderPath">Path to the base Quest folder.</param> | ||
| [HarmonyPatch(typeof(S1Quests.QuestManager), "DeleteUnapprovedFiles")] | ||
| [HarmonyPostfix] | ||
| private static void QuestManagerDeleteUnapprovedFiles(S1Quests.QuestManager __instance, string parentFolderPath) | ||
| { | ||
| string questFolder = Path.Combine(parentFolderPath, "Quests"); | ||
| string?[] existingQuests = QuestManager.Quests.Select(quest => quest.SaveFolder).ToArray(); | ||
|
|
||
| string[] unapprovedQuestDirectories = Directory.GetDirectories(questFolder) | ||
| .Where(directory => directory.StartsWith("Quest_") && !existingQuests.Contains(directory)) | ||
| .ToArray(); | ||
|
|
||
| foreach (string unapprovedQuestDirectory in unapprovedQuestDirectories) | ||
| Directory.Delete(unapprovedQuestDirectory, true); | ||
| } | ||
|
|
||
| /// <param name="__instance">The instance of the quest that is starting.</param> | ||
| [HarmonyPatch(typeof(S1Quests.Quest), "Start")] | ||
| [HarmonyPrefix] | ||
| private static void QuestStart(S1Quests.Quest __instance) => | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.