Ai MainGame class and hooks for AIAPI #23

Merged
thojmr merged 15 commits from AI-MainGame into master 2021-02-25 16:19:08 +00:00
thojmr commented 2021-02-16 21:27:13 +00:00 (Migrated from github.com)

Wanted to go ahead and open a pull request so I can get some feedback as I progress with this. None of this is in a finished state just yet, but it is close. Ill add comments where I have questions. Let me know if something looks off, since some of this conversions is "best guess".

  • Added MainGame API for AI
  • Converted into AI equavilent types/methods
    • Hooks
    • GameExtensions
    • GameCustFunCtrl
  • Removed some methods/hooks that do not apply in AI
  • Added package sources for AI

Thanks!

Wanted to go ahead and open a pull request so I can get some feedback as I progress with this. None of this is in a finished state just yet, but it is close. Ill add comments where I have questions. Let me know if something looks off, since some of this conversions is "best guess". - Added MainGame API for AI - Converted into AI equavilent types/methods - Hooks - GameExtensions - GameCustFunCtrl - Removed some methods/hooks that do not apply in AI - Added package sources for AI - Thanks!
thojmr (Migrated from github.com) reviewed 2021-02-16 21:30:12 +00:00
@ -0,0 +1,86 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:30:12 +00:00

Unlike KK, AI doesn't use path and filename together to save card data. Its either one or the other. Need to test this out. You can compare with KK/GameAPI.Hooks.cs to see what I mean

Unlike KK, AI doesn't use path and filename together to save card data. Its either one or the other. Need to test this out. You can compare with KK/GameAPI.Hooks.cs to see what I mean
thojmr (Migrated from github.com) reviewed 2021-02-16 21:31:10 +00:00
@ -0,0 +1,86 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:31:10 +00:00

This Hook is not working just yet. Can't seem to find a good HScene.Start hook.

This Hook is not working just yet. Can't seem to find a good HScene.Start hook.
thojmr (Migrated from github.com) reviewed 2021-02-16 21:31:52 +00:00
@ -0,0 +1,86 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:31:52 +00:00

KK Cycle is gone. AI seems to be using EnviroSky to keep track of time and days.

KK Cycle is gone. AI seems to be using EnviroSky to keep track of time and days.
thojmr (Migrated from github.com) reviewed 2021-02-16 21:32:57 +00:00
@ -0,0 +1,270 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:32:57 +00:00

These scene names may need to change for AI. They have not caused issues yet.

These scene names may need to change for AI. They have not caused issues yet.
thojmr (Migrated from github.com) reviewed 2021-02-16 21:33:56 +00:00
@ -0,0 +1,270 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:33:56 +00:00

Not sure this applies to AI?

Not sure this applies to AI?
thojmr (Migrated from github.com) reviewed 2021-02-16 21:34:57 +00:00
@ -0,0 +1,105 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:34:57 +00:00

I'm trying to keep the original property/field names when changing types, to make it easier to see what was converted.

I'm trying to keep the original property/field names when changing types, to make it easier to see what was converted.
thojmr (Migrated from github.com) reviewed 2021-02-16 21:36:18 +00:00
@ -0,0 +1,146 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:36:18 +00:00

Here's where the uncertinty comes into play. Is the Actor class really the replacement for SaveData.Heroine in KK? It seems like it, based on its structure.

Here's where the uncertinty comes into play. Is the Actor class really the replacement for SaveData.Heroine in KK? It seems like it, based on its structure.
thojmr (Migrated from github.com) reviewed 2021-02-16 21:37:39 +00:00
@ -0,0 +1,146 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:37:39 +00:00

So SaveData.Heroine and NPC from KK was combined into Actor in AI?

So SaveData.Heroine and NPC from KK was combined into Actor in AI?
thojmr (Migrated from github.com) reviewed 2021-02-16 21:38:39 +00:00
@ -0,0 +1,146 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:38:39 +00:00

Is AgentActor the correct type to be used here to fetch the ChaFileControl? Or should it just be the Actor?

Is AgentActor the correct type to be used here to fetch the ChaFileControl? Or should it just be the Actor?
thojmr (Migrated from github.com) reviewed 2021-02-16 21:39:08 +00:00
@ -0,0 +106,4 @@
/// Get the persisting player object that describes this character.
/// Returns null if the player could not be found. Works only in the main game.
/// </summary>
public static PlayerActor GetPlayer(this ChaControl chaControl)
thojmr (Migrated from github.com) commented 2021-02-16 21:39:08 +00:00

PlayerActor seems to be the replacement for KK SaveData.Player.

PlayerActor seems to be the replacement for KK SaveData.Player.
thojmr (Migrated from github.com) reviewed 2021-02-16 21:40:01 +00:00
@ -0,0 +123,4 @@
if (chaFile == null) throw new ArgumentNullException(nameof(chaFile));
if (!Manager.Map.IsInstance() || Manager.Map.Instance.Player == null) return null;
return Manager.Map.Instance.Player.GetRelatedChaFiles().Contains(chaFile)
thojmr (Migrated from github.com) commented 2021-02-16 21:40:01 +00:00

Manager.Map.Instance.Player seems to be the replacement for Manager.Game.Instance.Player in KK.

Manager.Map.Instance.Player seems to be the replacement for Manager.Game.Instance.Player in KK.
thojmr (Migrated from github.com) reviewed 2021-02-16 21:40:30 +00:00
@ -0,0 +1,105 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-16 21:40:30 +00:00

Singleton.Instance.defChaCtrl seems to be the replacement for Manager.Game.Instance.HeroineList in KK.

Singleton<CustomBase>.Instance.defChaCtrl seems to be the replacement for Manager.Game.Instance.HeroineList in KK.
ManlyMarco (Migrated from github.com) reviewed 2021-02-18 14:26:11 +00:00
@ -0,0 +1,270 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-18 14:26:11 +00:00

This should be possible to be replaced with a hook, assuming it's needed at all. In KK this is used to ensure that controllers get a chance to run code because otherwise they can only catch savegame load and onnight events which don't fire when starting a new game.

This should be possible to be replaced with a hook, assuming it's needed at all. In KK this is used to ensure that controllers get a chance to run code because otherwise they can only catch savegame load and onnight events which don't fire when starting a new game.
ManlyMarco (Migrated from github.com) reviewed 2021-02-18 14:27:04 +00:00
@ -0,0 +1,270 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-18 14:27:03 +00:00

These names are almost definitely all different. They might not even be needed depending on how you hook things.

These names are almost definitely all different. They might not even be needed depending on how you hook things.
ManlyMarco (Migrated from github.com) reviewed 2021-02-18 14:28:34 +00:00
@ -0,0 +1,86 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-18 14:28:34 +00:00

You don't have to follow the KK API so closely if it doesn't make sense in context of AI. Plugins will need to have major differences in their gameplay code anyways so it might be better to have different event names to make things clearer, or have a different set of events.

You don't have to follow the KK API so closely if it doesn't make sense in context of AI. Plugins will need to have major differences in their gameplay code anyways so it might be better to have different event names to make things clearer, or have a different set of events.
ManlyMarco (Migrated from github.com) reviewed 2021-02-18 14:31:20 +00:00
@ -0,0 +1,105 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-18 14:31:20 +00:00

The only members that matter are the public ones, the guts could be completely replaced, so you could look at it in terms of which public members got implemented or not. It depends on how you want to go about porting it though.

The only members that matter are the public ones, the guts could be completely replaced, so you could look at it in terms of which public members got implemented or not. It depends on how you want to go about porting it though.
ManlyMarco (Migrated from github.com) reviewed 2021-02-18 14:34:19 +00:00
@ -0,0 +1,105 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-18 14:34:18 +00:00

In KK HeroineList is not null anywhere in the main game, it's created at the very start of the app. defChaCtrl might be different, also I remember there were multiple different character lists in different classes, so yeah.
This is what I'm using in CheatTools, and I think this list is the most useful one ManlyMarco/IllusionCheatTools@ae58184eac/AI_CheatTools/CheatToolsWindow.cs (L389)

In KK HeroineList is not null anywhere in the main game, it's created at the very start of the app. defChaCtrl might be different, also I remember there were multiple different character lists in different classes, so yeah. This is what I'm using in CheatTools, and I think this list is the most useful one https://github.com/ManlyMarco/IllusionCheatTools/blob/ae58184eacb0e52155a7a5b0d79de59f99561c3a/AI_CheatTools/CheatToolsWindow.cs#L389
ManlyMarco (Migrated from github.com) reviewed 2021-02-18 14:37:21 +00:00
@ -0,0 +1,146 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-18 14:37:21 +00:00

AgentActor is more or less equal to NPC in KK, AgentActor.ActorData is more or less equal to Heroine. Look at it from the angle of a plugin wanting to do x to the character, which class does it need to access in these games?

AgentActor is more or less equal to NPC in KK, AgentActor.ActorData is more or less equal to Heroine. Look at it from the angle of a plugin wanting to do x to the character, which class does it need to access in these games?
GeBo1 (Migrated from github.com) reviewed 2021-02-18 16:19:02 +00:00
@ -0,0 +1,270 @@
using System;
GeBo1 (Migrated from github.com) commented 2021-02-18 16:19:02 +00:00

I took a quick look, and I think this would work:

Postfix on TitleSceneLoad.SetWorldData, set a flag:

IsNewGame = !Manager.Game.Instance.Data.WorldList.Values.Contains(_worldData)

Then check flag in postfix on AIProjectScene.MapScene.OnLoaded:

if (IsNewGame) OnNewGame();
IsNewGame = false;
I took a quick look, and I think this would work: Postfix on `TitleSceneLoad.SetWorldData`, set a flag: ``` IsNewGame = !Manager.Game.Instance.Data.WorldList.Values.Contains(_worldData) ``` Then check flag in postfix on `AIProjectScene.MapScene.OnLoaded`: ``` if (IsNewGame) OnNewGame(); IsNewGame = false; ```
thojmr (Migrated from github.com) reviewed 2021-02-19 01:36:07 +00:00
@ -0,0 +1,270 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-19 01:36:06 +00:00

That was helpful. Ended up going with _worldData?.SaveTime.Millisecond == 0; to detect new game using your hooks

That was helpful. Ended up going with `_worldData?.SaveTime.Millisecond == 0;` to detect new game using your hooks
thojmr (Migrated from github.com) reviewed 2021-02-19 01:44:23 +00:00
@ -0,0 +1,105 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-19 01:44:23 +00:00

Oops this was a replacement for Manager.Game.Instance.saveData So ill just swap it out with Singleton<Map>.Instance.Player.ChaControl.chaFile since I assume it's supposed to be saved to the players card

Oops this was a replacement for `Manager.Game.Instance.saveData` So ill just swap it out with `Singleton<Map>.Instance.Player.ChaControl.chaFile` since I assume it's supposed to be saved to the players card
GeBo1 (Migrated from github.com) reviewed 2021-02-19 17:01:16 +00:00
@ -0,0 +1,86 @@
using System;
GeBo1 (Migrated from github.com) commented 2021-02-19 17:01:16 +00:00

I don't think this is right because it could be true of any save (since it's true once per second).

Maybe

isNewGame = _wordData?.SaveTime = Game.Instance.Data.AutoData.SaveTime;

Alternately, maybe prefix MapScene.Update and check:

if (Game.Instance != null && Game.Instance.Environment != null) 
{
     isNewGame = Game.Instance.Environment.TotalPlayTime.TimeSpan == TimeSpan.Zero;
}

You'd probably not really want it to run every Update though. Maybe there's somewhere else that's safe to check that.

I don't think this is right because it could be true of any save (since it's true once per second). Maybe ``` isNewGame = _wordData?.SaveTime = Game.Instance.Data.AutoData.SaveTime; ``` Alternately, maybe prefix `MapScene.Update` and check: ``` if (Game.Instance != null && Game.Instance.Environment != null) { isNewGame = Game.Instance.Environment.TotalPlayTime.TimeSpan == TimeSpan.Zero; } ``` You'd probably not really want it to run every Update though. Maybe there's somewhere else that's safe to check that.
Animal42069 (Migrated from github.com) reviewed 2021-02-21 02:23:29 +00:00
@ -0,0 +1,86 @@
using System;
Animal42069 (Migrated from github.com) commented 2021-02-21 02:23:28 +00:00

BetterHScenes uses SetStartVoice... It gets called near the end of HScene Start... A little wonky but it seems to work

BetterHScenes uses SetStartVoice... It gets called near the end of HScene Start... A little wonky but it seems to work
thojmr (Migrated from github.com) reviewed 2021-02-21 04:57:26 +00:00
@ -0,0 +1,86 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-21 04:57:25 +00:00

This worked great once I realised the KK OnHScene copied method was an IEnumerator... I had even tried SetStartVoice earlier and thought it didn't work. Thanks for the reminder!

This worked great once I realised the KK OnHScene copied method was an IEnumerator... I had even tried SetStartVoice earlier and thought it didn't work. Thanks for the reminder!
thojmr (Migrated from github.com) reviewed 2021-02-21 05:01:28 +00:00
@ -0,0 +1,86 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-21 05:01:28 +00:00

Ah, I assumed it was Total milliseconds. So yea there would be a 1/1000 chance that it might be incorrectly fired :) Ill take another stab at it.

Ah, I assumed it was Total milliseconds. So yea there would be a 1/1000 chance that it might be incorrectly fired :) Ill take another stab at it.
thojmr (Migrated from github.com) reviewed 2021-02-21 05:19:10 +00:00
@ -0,0 +1,86 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-21 05:19:10 +00:00

isNewGame = _worldData?.SaveTime == new DateTime(0);
Seems to do the trick.

isNewGame = _worldData?.SaveTime == new DateTime(0); Seems to do the trick.
thojmr (Migrated from github.com) reviewed 2021-02-21 06:08:13 +00:00
@ -0,0 +138,4 @@
var results = new HashSet<ChaFileControl>();
if (player.ChaControl?.chaFile != null)
results.Add(player.ChaControl.chaFile);
thojmr (Migrated from github.com) commented 2021-02-21 06:08:13 +00:00

In KK this returns multiple chaFiles. But PlayerActor only appears to have one chaFile, so it will only ever return one, unless I missed something.

In KK this returns multiple chaFiles. But PlayerActor only appears to have one chaFile, so it will only ever return one, unless I missed something.
thojmr commented 2021-02-21 06:11:04 +00:00 (Migrated from github.com)

At this point all of the KK => AI conversions have been made. Just need to find time to test out the GameExtension.cs changes.
All of the Hooks seem to be working now at least.

At this point all of the KK => AI conversions have been made. Just need to find time to test out the GameExtension.cs changes. All of the Hooks seem to be working now at least.
ManlyMarco (Migrated from github.com) reviewed 2021-02-22 17:34:00 +00:00
@ -0,0 +138,4 @@
var results = new HashSet<ChaFileControl>();
if (player.ChaControl?.chaFile != null)
results.Add(player.ChaControl.chaFile);
ManlyMarco (Migrated from github.com) commented 2021-02-22 17:34:00 +00:00

This is a quirk of how KK main game copies characters around, it's a hack to keep all different copies up to date.

This is a quirk of how KK main game copies characters around, it's a hack to keep all different copies up to date.
ManlyMarco (Migrated from github.com) reviewed 2021-02-22 17:34:46 +00:00
@ -0,0 +1,86 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-22 17:34:46 +00:00

That should be fine, yeah.

That should be fine, yeah.
ManlyMarco commented 2021-02-22 17:37:24 +00:00 (Migrated from github.com)

Let me know when you finish testing and I'll give it a final look over and merge it.

Let me know when you finish testing and I'll give it a final look over and merge it.
thojmr commented 2021-02-24 22:12:39 +00:00 (Migrated from github.com)

Alright, I think that's everything now. Give it a final look over when you have time.

Alright, I think that's everything now. Give it a final look over when you have time.
ManlyMarco (Migrated from github.com) reviewed 2021-02-25 01:44:07 +00:00
@ -0,0 +1,105 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-25 01:44:07 +00:00

Clever, but isn't this going to cause issues if player character is changed, or if the plugin uses same ID for character and game controllers?

The rest looks perfectly fine.

Clever, but isn't this going to cause issues if player character is changed, or if the plugin uses same ID for character and game controllers? The rest looks perfectly fine.
thojmr (Migrated from github.com) reviewed 2021-02-25 02:13:58 +00:00
@ -0,0 +1,105 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-25 02:13:58 +00:00

Huh for KK the first param is of type SaveData saveData, but for AI its ChaFile. Maybe ExtensibleSaveFormat needs to be updated for AI?

Huh for KK the first param is of type SaveData saveData, but for AI its ChaFile. Maybe ExtensibleSaveFormat needs to be updated for AI?
GeBo1 (Migrated from github.com) reviewed 2021-02-25 14:41:48 +00:00
@ -0,0 +1,105 @@
using System;
GeBo1 (Migrated from github.com) commented 2021-02-25 14:41:48 +00:00

KK_ExtensibleSaveFormat has a set of extra methods for main game saves. I think these need to be added for AI to support this.

KK_ExtensibleSaveFormat has a [set of extra methods for main game saves](https://github.com/IllusionMods/BepisPlugins/blob/master/src/KK_ExtensibleSaveFormat/KK.ExtendedSave.SaveData.cs). I think these need to be added for AI to support this.
ManlyMarco (Migrated from github.com) reviewed 2021-02-25 15:12:24 +00:00
@ -0,0 +1,105 @@
using System;
ManlyMarco (Migrated from github.com) commented 2021-02-25 15:12:24 +00:00

These methods can be stubbed for the time being (if you don't need them) with throw new NotImplementedException() and an Obsolete attribute with an explanation.

These methods can be stubbed for the time being (if you don't need them) with `throw new NotImplementedException()` and an `Obsolete` attribute with an explanation.
thojmr (Migrated from github.com) reviewed 2021-02-25 15:31:41 +00:00
@ -0,0 +1,105 @@
using System;
thojmr (Migrated from github.com) commented 2021-02-25 15:31:40 +00:00

Yea, I don't need them for now. Ill Obsolete them. If someone needs them later we can upgrade ExtensibleSaveFormat.

Yea, I don't need them for now. Ill Obsolete them. If someone needs them later we can upgrade ExtensibleSaveFormat.
ManlyMarco commented 2021-02-25 16:19:34 +00:00 (Migrated from github.com)

Done merging it, thank you for the good work!

Done merging it, thank you for the good work!
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
IllusionMods/IllusionModdingAPI!23
No description provided.