Aragas / Bannerlord.MBOptionScreen

Mod Configuration Menu. A Module for easy Setting integration. Documentation available.

Home Page:https://www.nexusmods.com/mountandblade2bannerlord/mods/612

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on preset load

Igor-Rakhmanov opened this issue · comments

Hi. my mod crashes when I try to load any preset. Issue was not present in version 5.0.3
https://report.butr.link/E3AC2E.html

My Setting groups

        public const string Smithing = "{=I34ardNfzvnvE}Smithing";
        public const string SmithingRarityChance = "{=WYDp2KtTRIWT7}Smithing/Rarity chance";
        public const string SmithingRarityBonus = "{=fiEcFzWSLZoVC}Smithing/Rarity bonus";

        public const string ExperienceFactors = "{=x63OTfGg3hkHt}Experience/Factors";
        public const string ExperienceLearning = "{=mV7FaNIGlMRSD}Experience/Learning rates and limits";
        public const string ExperienceTradeAdditionalXp = "{=5B5MjvBIQlO5B}Experience/Trade/Additional Trade XP from any deal";

        public const string CharacterDevelopment = "{=BX1VpXfkokzkE}Character Development";

Quick look at the code: shouldn't it be here like this

topGroup = new SettingsPropertyGroupDefinition(sp.GroupName).SetSubGroupDelimiter(subGroupDelimiter);

topGroup = new SettingsPropertyGroupDefinition(**topGroupName**).SetSubGroupDelimiter(subGroupDelimiter);

@Igor-Rakhmanov, not exactly related to the issue, but I'd suggest defining your group headers like this:

        public const string Smithing = "{=I34ardNfzvnvE}Smithing";
        public const string SmithingRarityChance = Smithing + "/{=WYDp2KtTRIWT7}Rarity chance";
        public const string SmithingRarityBonus = Smithing  + "/{=fiEcFzWSLZoVC}Rarity bonus";

That way if you ever want to change higher-level header, you won't have to change it in several constants and XML strings.

@Igor-Rakhmanov, not exactly related to the issue, but I'd suggest defining your group headers like this:

        public const string Smithing = "{=I34ardNfzvnvE}Smithing";
        public const string SmithingRarityChance = Smithing + "/{=WYDp2KtTRIWT7}Rarity chance";
        public const string SmithingRarityBonus = Smithing  + "/{=fiEcFzWSLZoVC}Rarity bonus";

That way if you ever want to change higher-level header, you won't have to change it in several constants and XML strings.

Thank you, didn't know that's possible until look at MCM sources. I'll definitely rearrange my code as you said once the issue is resolved.
I've flattened my settings structure as a temporary solution.

Can you confirm that this still happend on v5.2.0? I might have fixed that

Tried on 5.3.0 - same exception

Could you provide the full settings class?

I don't know why, but rearranging the whole thing as was suggested by @artifixer stopped crashes altogether.
I'm closing the issue then.
Also pushed my module code to github, with settings being here https://github.com/Igor-Rakhmanov/Bannerlord.XPTweaks/tree/master/Settings
Any comments would be appreciated as this is my first try at modding.

@Igor-Rakhmanov, replacing game models will work, but it's genereally considered bad practice by the modding community. It's because any other mod that changes any method from any of the models you have replaced will be incompaitable. If you're fine with that, it's ok, but if not, I'd suggest keeping default models and patch the methods you'd like to change with harmony patches.

@artifixer That's interesting. Well, when you first look into how everything is coded inside bannerlord, it definitely looks like those models and behaviours are made to be easily overriden for modding purposes, that's why I used them whenever I could.
But the problem of latest model completely overriding all the previous has come to my mind. I even thought of maybe getting the instance of existing model and passing it over to constructor of my model, and referencing it instead of base, so my models would act like kind of decorator. But that wouldn't solve the problem of other mods overriding my logic.
I don't like the idea of patching, and it feels like the problem partly remains, as other mods can disable original method call altogether (right?). But it looks like the lesser evil.
I guess replacing game models is fine for complete overhauls, but for lesser mods like this, harmony patching is preferable.
Looks like I have to rewrite the whole thing when I have the capacity to do so.
P.S. sorry for long post, I don't know people to share my thought on this really :) Do you know of any community guidelines for modding?

@Igor-Rakhmanov I was more or less following the same thought process two years ago while preparing to write Allegiance Overhaul. =) As for guidelines, there are none consistent ones that I am aware of. You could and probably should ask on official modding discord - lots of helpful and active people there.

@Igor-Rakhmanov Sorry for necroposting. There is a good way to replace models that I totally forgot about. Had to use it recently and it works perfect. For use example, see here and here.

@artifixer Thank you for the example.
That's basically what I meant in the post above

getting the instance of existing model and passing it over to constructor of my model, and referencing it instead of base, so my models would act like kind of decorator. But that wouldn't solve the problem of other mods overriding my logic.

I only had such idea in my head, interesting to see it up and running. I like it this way because if you patch a lot of stuff in the same model it starts looking too clunky and not really easy to follow.