Open tommai78101 opened 2 years ago
Can this be solved the same way core settings/syncsettings was @nattthebear?
On quick glance, it seems like it could be, yes.
After consulting with adelikat and YoshiRulz on Discord, I followed their suggestions to use [ConfigPersist]
attribute on multiple data types that are supported by C# language and BizHawk. And it worked! Thanks to both.
Leaving the ticket open because it's still a legitimate issue.
Custom class types are stored into the config.ini file as fully qualified class names. They are typically stored in the following format:
"$type": "GeneticAlgorithmBot.GeneticAlgorithmBotSettings, GeneticAlgorithmBot",
This qualified class type name is created from the [ConfigPersist]
applied to the GeneticAlgorithmBotSettings
class itself:
[ConfigPersist]
public GeneticAlgorithmBotSettings Settings { get; set; }
BizHawk doesn't know what GeneticAlgorithmBot.GeneticAlgorithmBotSettings
class type this is, so it encounters a crash that cleans the config.ini back to its default state.
We need to set the [ConfigPersist]
attribute only to class types that BizHawk recognizes. I split off my custom bot settings into multiple properties, each tagged with [ConfigPersist]
attribute, like so:
#region Settings
[ConfigPersist]
public RecentFiles recentFiles {
get => this.Settings.RecentBotFiles;
set => this.Settings.RecentBotFiles = value;
}
[ConfigPersist]
public bool TurboWhenBotting {
get => this.Settings.TurboWhenBotting;
set => this.Settings.TurboWhenBotting = value;
}
[ConfigPersist]
public bool InvisibleEmulation {
get => this.Settings.InvisibleEmulation;
set => this.Settings.InvisibleEmulation = value;
}
public GeneticAlgorithmBotSettings Settings { get; set; }
#endregion
Then, Bizhawk will store the fully qualified name for the known class type RecentFiles
as such in the config.ini file:
"$type": "BizHawk.Client.Common.RecentFiles, BizHawk.Client.Common",
While all other types are stored in their primitive types handled by the JSON parser/writer.
The next time BizHawk loads the config.ini file, it will then know what to do with them.
Summary
If the external tool is opened at least once, and the external tool uses the following C# codes below, in theory, the configuration file
config.ini
will include information of the external tool.Below is the snippet of the
config.ini
:I suspect that the formatting of the JSON object for
CustomToolSettings
andCommonToolSettings
both didn't expect there to be an external tool reference if the external tool is using[ConfigPersist]
attribute in the code.Repro
[ConfigPersist]
attribute and create a class type with any properties (int
,float
, or evenRecentFiles
class type).Output
Full stack trace below:
Host env.