-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ai MainGame class and hooks for AIAPI (#23)
* Basic MainGame hooks working with AI * fixed day counter hook * potential fix for ExtendedData methods * GameExtensions.cs AI conversion types * hook fixes * better method names to describe AI hooks * added hooks for OnNewGame * Use Map instance to get players char file * Fixed OnHStart * Fix for isNewGame hook, checking datetime * converted SaveData.Heroine to AgentData and NPC to AgentActor * Reverted test logging back to debug level * Made ExtendedData methids obsolete with compile error in AI API for now * Throw if trying to use unimplemented methods
- Loading branch information
Showing
10 changed files
with
702 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -334,3 +334,6 @@ ASALocalRun/ | |
/lib | ||
PostBuild.bat | ||
*.DotSettings | ||
|
||
#Ignore vscode config dir | ||
.vscode |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
|
||
namespace KKAPI.MainGame | ||
{ | ||
/// <summary> | ||
/// Arguments used with main game save/load events. | ||
/// </summary> | ||
public sealed class GameSaveLoadEventArgs : EventArgs | ||
{ | ||
/// <summary> | ||
/// Create a new instance | ||
/// </summary> | ||
public GameSaveLoadEventArgs(string path, string fileName) | ||
{ | ||
Path = path; | ||
FileName = fileName; | ||
} | ||
|
||
/// <summary> | ||
/// Name of the safe file. | ||
/// </summary> | ||
public string FileName { get; } | ||
|
||
/// <summary> | ||
/// Full filename of the save file. | ||
/// </summary> | ||
public string FullFilename => System.IO.Path.Combine(Path, FileName); | ||
|
||
/// <summary> | ||
/// Path to which the save file will be written. | ||
/// </summary> | ||
public string Path { get; } | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Collections; | ||
using HarmonyLib; | ||
using AIProject.SaveData; | ||
using AIProject; | ||
using Sirenix.Serialization; | ||
using AIProject.Scene; | ||
using Manager; | ||
|
||
namespace KKAPI.MainGame | ||
{ | ||
public static partial class GameAPI | ||
{ | ||
private class Hooks | ||
{ | ||
public static int lastCurrentDay = 1;//Always starts at 1 | ||
public static bool isNewGame = false; | ||
|
||
public static void SetupHooks() | ||
{ | ||
Harmony.CreateAndPatchAll(typeof(Hooks)); | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(SaveData), nameof(SaveData.Load), new[] { typeof(string) })] | ||
public static void LoadHook(string fileName) | ||
{ | ||
OnGameBeingLoaded("", fileName); | ||
} | ||
|
||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(SaveData), nameof(SaveData.SaveFile), new[] { typeof(string) })] | ||
public static void SaveHook(string path) | ||
{ | ||
OnGameBeingSaved(path, ""); | ||
} | ||
|
||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(TitleLoadScene), "SetWorldData", typeof(WorldData), typeof(bool))] | ||
public static void TitleLoadScene_SetWorldData(WorldData _worldData, bool isAuto) | ||
{ | ||
isNewGame = _worldData?.SaveTime == new DateTime(0); | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(MapScene), "OnLoaded")] | ||
public static void MapScene_OnLoaded(MapScene __instance) | ||
{ | ||
if (isNewGame) OnNewGame(); | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(HScene), "SetStartVoice")] | ||
public static void HScene_SetStartVoice(HScene __instance) | ||
{ | ||
OnHStart(__instance); | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(HScene), "EndProc")] | ||
public static void HScene_EndProc(HScene __instance) | ||
{ | ||
OnHEnd(__instance); | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(EnvironmentSimulator), nameof(EnvironmentSimulator.SetTimeZone), typeof(AIProject.TimeZone))] | ||
public static void EnvironmentChangeTypeHook(AIProject.TimeZone zone) | ||
{ | ||
OnPeriodChange(zone);//morning, day, evening | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(EnviroSky), "SetGameTime")] | ||
public static void EnvironmentChangeDayHook(EnviroSky __instance) | ||
{ | ||
var currentDay = (int)__instance.currentDay; | ||
if (lastCurrentDay < currentDay) | ||
{ | ||
lastCurrentDay = currentDay; | ||
OnDayChange(currentDay); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.