Ai MainGame class and hooks for AIAPI #23
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
IllusionMods/IllusionModdingAPI!23
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "AI-MainGame"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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".
Thanks!
@ -0,0 +1,86 @@using System;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
@ -0,0 +1,86 @@using System;This Hook is not working just yet. Can't seem to find a good HScene.Start hook.
@ -0,0 +1,86 @@using System;KK Cycle is gone. AI seems to be using EnviroSky to keep track of time and days.
@ -0,0 +1,270 @@using System;These scene names may need to change for AI. They have not caused issues yet.
@ -0,0 +1,270 @@using System;Not sure this applies to AI?
@ -0,0 +1,105 @@using System;I'm trying to keep the original property/field names when changing types, to make it easier to see what was converted.
@ -0,0 +1,146 @@using System;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.
@ -0,0 +1,146 @@using System;So SaveData.Heroine and NPC from KK was combined into Actor in AI?
@ -0,0 +1,146 @@using System;Is AgentActor the correct type to be used here to fetch the ChaFileControl? Or should it just be the Actor?
@ -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)PlayerActor seems to be the replacement for KK SaveData.Player.
@ -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)Manager.Map.Instance.Player seems to be the replacement for Manager.Game.Instance.Player in KK.
@ -0,0 +1,105 @@using System;Singleton.Instance.defChaCtrl seems to be the replacement for Manager.Game.Instance.HeroineList in KK.
@ -0,0 +1,270 @@using System;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.
@ -0,0 +1,270 @@using System;These names are almost definitely all different. They might not even be needed depending on how you hook things.
@ -0,0 +1,86 @@using System;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.
@ -0,0 +1,105 @@using System;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.
@ -0,0 +1,105 @@using System;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)@ -0,0 +1,146 @@using System;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?
@ -0,0 +1,270 @@using System;I took a quick look, and I think this would work:
Postfix on
TitleSceneLoad.SetWorldData, set a flag:Then check flag in postfix on
AIProjectScene.MapScene.OnLoaded:@ -0,0 +1,270 @@using System;That was helpful. Ended up going with
_worldData?.SaveTime.Millisecond == 0;to detect new game using your hooks@ -0,0 +1,105 @@using System;Oops this was a replacement for
Manager.Game.Instance.saveDataSo ill just swap it out withSingleton<Map>.Instance.Player.ChaControl.chaFilesince I assume it's supposed to be saved to the players card@ -0,0 +1,86 @@using System;I don't think this is right because it could be true of any save (since it's true once per second).
Maybe
Alternately, maybe prefix
MapScene.Updateand check:You'd probably not really want it to run every Update though. Maybe there's somewhere else that's safe to check that.
@ -0,0 +1,86 @@using System;BetterHScenes uses SetStartVoice... It gets called near the end of HScene Start... A little wonky but it seems to work
@ -0,0 +1,86 @@using System;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!
@ -0,0 +1,86 @@using System;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.
@ -0,0 +1,86 @@using System;isNewGame = _worldData?.SaveTime == new DateTime(0);
Seems to do the trick.
@ -0,0 +138,4 @@var results = new HashSet<ChaFileControl>();if (player.ChaControl?.chaFile != null)results.Add(player.ChaControl.chaFile);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.
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.
@ -0,0 +138,4 @@var results = new HashSet<ChaFileControl>();if (player.ChaControl?.chaFile != null)results.Add(player.ChaControl.chaFile);This is a quirk of how KK main game copies characters around, it's a hack to keep all different copies up to date.
@ -0,0 +1,86 @@using System;That should be fine, yeah.
Let me know when you finish testing and I'll give it a final look over and merge it.
Alright, I think that's everything now. Give it a final look over when you have time.
@ -0,0 +1,105 @@using System;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.
@ -0,0 +1,105 @@using System;Huh for KK the first param is of type SaveData saveData, but for AI its ChaFile. Maybe ExtensibleSaveFormat needs to be updated for AI?
@ -0,0 +1,105 @@using System;KK_ExtensibleSaveFormat has a set of extra methods for main game saves. I think these need to be added for AI to support this.
@ -0,0 +1,105 @@using System;These methods can be stubbed for the time being (if you don't need them) with
throw new NotImplementedException()and anObsoleteattribute with an explanation.@ -0,0 +1,105 @@using System;Yea, I don't need them for now. Ill Obsolete them. If someone needs them later we can upgrade ExtensibleSaveFormat.
Done merging it, thank you for the good work!