// I'm unsure if this is necessary, but it works fine, and so better safe than sorry. private static void Prefix(GearItem __instance) { if (FoodRebalanceSettings.Instance.adjustCalories && __instance.m_FoodItem && __instance.m_FoodWeight) { __instance.m_FoodWeight.m_CaloriesPerKG = FoodRebalanceMod.ChangedCaloriesForItem(__instance.name, __instance); } }
// Restore the calorie changes that were removed in Prefix. private static void Postfix(GearItem __instance) { if (FoodRebalanceSettings.Instance.adjustCalories && __instance.m_FoodItem && !__instance.m_FoodWeight) { float changedCal = FoodRebalanceMod.ChangedCaloriesForItem(__instance.name, __instance); __instance.m_FoodItem.m_CaloriesRemaining += changedCal; __instance.m_FoodItem.m_CaloriesTotal += changedCal; } }
// Changes the calorie amount before the rest of the item's Awake call runs. // Items with a FoodWeight have their cal/KG changed, and the game's internal logic handles the rest. // Items without it have calories directly added to their value. private static void Prefix(GearItem __instance) { if (FoodRebalanceSettings.Instance.adjustCalories && __instance.m_FoodItem) { if (__instance.m_FoodWeight != null) { __instance.m_FoodWeight.m_CaloriesPerKG = FoodRebalanceMod.ChangedCaloriesForItem(__instance.name, __instance); } else { float changedCal = FoodRebalanceMod.ChangedCaloriesForItem(__instance.name, __instance); __instance.m_FoodItem.m_CaloriesRemaining += changedCal; __instance.m_FoodItem.m_CaloriesTotal += changedCal; } } }