public override void Entry(IModHelper helper) { Instance = this; config = helper.Data.ReadJsonFile <ModConfig>("config.json") ?? ModConfigDefaultConfig.CreateDefaultConfig("config.json"); config = ModConfigDefaultConfig.UpdateConfigToLatest(config, "config.json"); if (config.enableMod) { helper.Events.Input.ButtonReleased += Input_ButtonReleased; helper.Events.GameLoop.DayStarted += GameLoop_DayStarted; helper.Events.GameLoop.TimeChanged += GameLoop_TimeChanged; helper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded; harmony = HarmonyInstance.Create("com.aairthegreat.mod.trainloot"); harmony.Patch(typeof(TrainCar).GetMethod("draw"), null, new HarmonyMethod(typeof(TrainCarOverrider).GetMethod("postfix_getTrainTreasure"))); harmony.Patch(typeof(Railroad).GetMethod("PlayTrainApproach"), new HarmonyMethod(typeof(RailroadOverrider).GetMethod("prefix_playTrainApproach"))); string trainCarFile = Path.Combine("DataFiles", "trains.json"); trainCars = helper.Data.ReadJsonFile <Dictionary <TRAINS, TrainData> >(trainCarFile) ?? TrainDefaultConfig.CreateTrainCarData(trainCarFile); SetupMultiplayerObject(); } }
public override void Entry(IModHelper helper) { Instance = this; modHelper = helper; config = helper.Data.ReadJsonFile <ModConfig>("config.json") ?? ModConfigDefaultConfig.CreateDefaultConfig("config.json"); config = ModConfigDefaultConfig.UpdateConfigToLatest(config, "config.json"); if (config.enableMod) { helper.Events.Input.ButtonReleased += Input_ButtonReleased; helper.Events.GameLoop.DayStarted += GameLoop_DayStarted; helper.Events.GameLoop.TimeChanged += GameLoop_TimeChanged; helper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded; //helper.Events.GameLoop.GameLaunched += GameLoop_GameLaunched; harmony = HarmonyInstance.Create("com.aairthegreat.mod.trainloot"); harmony.Patch(typeof(TrainCar).GetMethod("draw"), null, new HarmonyMethod(typeof(TrainCarOverrider).GetMethod("postfix_getTrainTreasure"))); harmony.Patch(typeof(Railroad).GetMethod("PlayTrainApproach"), new HarmonyMethod(typeof(RailroadOverrider).GetMethod("prefix_playTrainApproach"))); string trainCarFile = Path.Combine("DataFiles", "trains.json"); trainCars = helper.Data.ReadJsonFile <Dictionary <TRAINS, TrainData> >(trainCarFile) ?? TrainDefaultConfig.CreateTrainCarData(trainCarFile); bool updateLoot = false; foreach (var train in trainCars.Values) { //updated list to include new base game treasure if (!train.HasItem(806)) { train.treasureList.Add(new TrainTreasure(806, "Leprechaun Shoes", 0.01, LOOT_RARITY.RARE, true)); updateLoot = true; } } if (updateLoot) { helper.Data.WriteJsonFile(trainCarFile, trainCars); } SetupMultiplayerObject(); } }