1. I'm trying to make my mod easy to remove from game (set a flag which will be checked in `ModPlugin.beforeGameSave` and remove custom commodity if set, so it can be loaded without the mod), looking at other mods how they do it, but I can't find it so far.
How I go about it? Currently I'm looking at `Global.getSector().getEconomy().getCommoditySpec`, `getAllLocations()` and `getAllFactions()` with assumption that I have to iterate over them and find markets/fleets with the commodity to remove, am I on the right track?
[edit]
Actually, one of the saves I can't load, doesn't seem to have that commodity anywhere on market or fleet, it's like there is some meta data saved somewhere but not sure what, where, and how to remove it.
I'm gettting "Commodity with id not found" from `com.fs.starfarer.campaign.econ.CommodityOnMarket.readResolve()` when trying to load game after disabling the mod.
Added removal but it still errors:
Global.getSector().getAllLocations().forEach->.getAllEntities().forEach->.getMarket().getSubmarketsCopy().forEach->.getCargo().removeCommodity(id, quantity);
Not sure why I didn't do that earlier, but I went through save's xml file to figure out what's still left, I have added "make my illegal commodities legal before saving" with `faction.makeCommodityLegal` which removed some of occurrences of my commodity ID in the save. Still remaining (yet, while I'm trying to figure it out) in the xml:
/CampaignEngine/uiData/abilitySlots/slots/AbilitySlot-array[1]/AbilitySlot[9]/abilityId
/CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/submarketTradeData/e[32]/PlayerTradeDataForSubmarket/pS/s/CIStack/d
/CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/submarketTradeData/e[33]/PlayerTradeDataForSubmarket/pS/s/CIStack/d
/CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/submarketTradeData/e[35]/PlayerTradeDataForSubmarket/pS/s/CIStack/d
/CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/submarketTradeData/e[36]/PlayerTradeDataForSubmarket/pS/s/CIStack/d
/CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/profitabilityData/dataBought/e/st
/CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/profitabilityData/dataBought/e/CommodityData/commodityId
I have added this:
SharedData.getData().getPlayerActivityTracker().getSubmarketTradeData().get(submarket).getRecentPlayerBought().removeCommodity(id, bought.getCommodityQuantity(id));
SharedData.getData().getPlayerActivityTracker().getSubmarketTradeData().get(submarket).getRecentPlayerSold() .removeCommodity(id, sold .getCommodityQuantity(id));
Now I'm left with the below:
/CampaignEngine/uiData/abilitySlots/slots/AbilitySlot-array[1]/AbilitySlot[9]/abilityId
/CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/profitabilityData/dataBought/e/st
/CampaignEngine/modAndPluginData/persistentData/e[8]/SharedData/playerActivityTracker/profitabilityData/dataBought/e/CommodityData/commodityId
error
ERROR com.fs.starfarer.campaign.save.CampaignGameManager - Failed calling method
---- Debugging information ----
message : Failed calling method
cause-exception : java.lang.RuntimeException
cause-message : Commodity with id cpr_commodity not found
method : com.fs.starfarer.campaign.econ.MarketDemand.readResolve()
class : com.fs.starfarer.campaign.econ.MarketDemand
required-type : com.fs.starfarer.campaign.econ.MarketDemand
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number : 3978
class[1] : com.fs.starfarer.campaign.econ.MarketDemandData
class[2] : com.fs.starfarer.campaign.econ.Market
class[3] : com.fs.starfarer.campaign.CampaignPlanet
class[4] : java.util.ArrayList
converter-type[1] : com.thoughtworks.xstream.converters.collections.CollectionConverter
class[5] : com.fs.util.container.repo.ObjectRepository
class[6] : com.fs.starfarer.campaign.StarSystem
class[7] : com.fs.starfarer.campaign.CircularOrbit
class[8] : com.fs.starfarer.rpg.Person
class[9] : com.fs.starfarer.api.impl.campaign.events.OfficerManagerEvent$AvailableOfficer
class[10] : com.fs.starfarer.api.impl.campaign.events.OfficerManagerEvent
class[11] : java.util.LinkedHashMap
converter-type[2] : com.thoughtworks.xstream.converters.collections.MapConverter
class[12] : com.fs.starfarer.campaign.rules.Memory
class[13] : com.fs.starfarer.campaign.CommDirectoryEntry
class[14] : com.fs.starfarer.campaign.CommDirectory
class[15] : com.fs.starfarer.campaign.econ.reach.ReachEconomy
class[16] : com.fs.starfarer.campaign.econ.reach.ReachEconomyStepper
class[17] : com.fs.starfarer.campaign.econ.Economy
class[18] : com.fs.starfarer.campaign.StarSystem$UpdateFromHyperspaceLocation
class[19] : com.fs.starfarer.campaign.BaseLocation$LocationToken
class[20] : com.fs.starfarer.campaign.Hyperspace
class[21] : com.fs.starfarer.campaign.CampaignEngine
converter-type[3] : com.fs.starfarer.campaign.save.public
To access it I tried SharedData.getData().getPlayerActivityTracker().getProfitabilityData(), but not sure how to get to the `dataBought`, it's a private variable so I cannot extend `PlayerTradeProfitabilityData` and alias it in `configureXStream`, it would need to not be private, or that class needs to have something like `getDataBought() -> dataBought` or `deleteBoughtDataFor(String commodityId) -> dataBought.remove(commodityId)` method on it. Is there any other way removing mod commodity from it?
Another progress:
PlayerTradeProfitabilityData profitabilityData = SharedData.getData().getPlayerActivityTracker().getProfitabilityData();
profitabilityData.getBoughtDataFor(id).setQuantity(0);
profitabilityData.advance(365); // A year, arbitrarily chosen number > 1 (because it wasn't working with 1

)
and with above in the save file I see only two entries left for now:
/CampaignEngine/uiData/abilitySlots/slots/AbilitySlot-array[1]/AbilitySlot[9]/abilityId
/CampaignEngine/memory/d/e[49]/st
which seems to be safe in save

as I was able to load the game with mod disabled. Probably I will hit more edge cases once I spend more time testing but for now it works?...