I'm trying to make a very "simple" mod which colors the Nameplates(specifically SettlementNameplates) to a color for each faction, unlike originally where the color is selected based on the current relation with the player(Neutral, Ally, Enemy). My understanding is that the color is set by selecting a style for the brush of the widget via Widget.SetState(string) using a string corresponding to a brush-style in the Nameplates.xml("NeutralTown" etc).
My line of thinking have been to add styles to the brushes in Nameplate.xml("aseraiTown" etc) then changing SetNameplateRelationType(int type) to call SetSate not with a string based on the relation but rather the faction name. To do this I need to figure out what faction the current Nameplates settlement belongs to. The Widget have no direct access to the settlement its representing but it has the name of it stored in SettlementNameplateWidget.(Big, Normal, Small)NameplateWidget.SettlementNameWidget.Text.
So finding a Settlement from its name now becomes the next task. The Settlement.Find(string) dont seem to work with the name, as it is using the idString which I think is semi randomly generated(no real clue tho?). So to get around this I have tried to make a Dictionary that uses the name as the key and a Settlement/idString, building it by iterating over Campaign.Currnet.Settlements during the loading of a campaign(tried DoLoading, OnGameLoaded, OnGameInitializationFinished) but as soon as I try to access Settlement.StringId or adding the Settlement to the dictionary the game crashes with no error messages.
Clearly I am doing something wrong, but I don't understand what. Very possible that there is a easier/more correct way of doing it but I'm very new to modding games so I'm not really used to the flow of execution/listener structur/interface system(Gauntlet) that bannerlord has. Any help is much appreciated