void onTimeWarpRateChanged() { if (TimeWarp.fetch != null) { //Log.Info("TimeWarp.fetch.current_rate_index: " + TimeWarp.fetch.current_rate_index.ToString() + " New time warp: " + TimeWarp.fetch.warpRates[TimeWarp.fetch.current_rate_index].ToString() + " lastWarpRate: " + lastWarpRate.ToString()); if (lastWarpRateIdx > 0 && TimeWarp.fetch.warpRates[TimeWarp.fetch.current_rate_index] > 1) { foreach (var v in FlightGlobals.fetch.vesselsLoaded) { foreach (var p in v.Parts) { foreach (PartModule tmpPM in p.Modules) { // Find all modules of type BaseConvertor which are inactive switch (tmpPM.moduleName) { case "FissionReactor": case "KFAPUController": case "ModuleResourceConverter": ModuleResourceConverter tmpGen = (ModuleResourceConverter)tmpPM; Log.Info("Module: " + tmpGen.moduleName + " IsActivated: " + tmpGen.IsActivated.ToString()); if (!tmpGen.IsActivated) { if (!resourceConverterParts.Contains(p)) { resourceConverterParts.Add(p); } } else { if (resourceConverterParts.Contains(p)) { resourceConverterParts.Remove(p); FieldInfo fi = tmpGen.GetType().GetField("lastUpdateTime", BindingFlags.NonPublic | BindingFlags.Instance); if (fi != null) { Log.Info("Updating lastUpdateTime"); fi.SetValue(tmpGen, Planetarium.GetUniversalTime()); } else { Log.Info("Unable to get pointer to lastUpdateTime"); } } } break; } } } } } lastWarpRateIdx = TimeWarp.fetch.current_rate_index; } }
private void CorrectLastUpdateTime(ModuleResourceConverter mrc) { if (mrc is null) { throw new ArgumentNullException(nameof(mrc)); } FieldInfo fi = mrc.GetType().GetField("lastUpdateTime", BindingFlags.NonPublic | BindingFlags.Instance); if (fi != null) { fi.SetValue(mrc, Planetarium.GetUniversalTime()); } else { throw new InvalidOperationException("Unable to get a lastUpdateTime field on module " + mrc.moduleName); } }
// When coming out of warp, fix issue with ResourceConverter void onPartUnpack(Part p) { Log.Info("Unpacking part: " + p.partInfo.name); if (resourceConverterParts.Contains(p)) { resourceConverterParts.Remove(p); foreach (PartModule tmpPM in p.Modules) { // Find all modules of type BaseConvertor // If !IsActivated, then // set lastUpdateTime = Planetarium.GetUniversalTime(); // lastUpdateTime is a protected field, so Reflection was needed to fix this switch (tmpPM.moduleName) { case "FissionReactor": case "KFAPUController": case "ModuleResourceConverter": ModuleResourceConverter tmpGen = (ModuleResourceConverter)tmpPM; Log.Info("Module: " + tmpGen.moduleName + " IsActivated: " + tmpGen.IsActivated.ToString()); // if (!tmpGen.IsActivated) { FieldInfo fi = tmpGen.GetType().GetField("lastUpdateTime", BindingFlags.NonPublic | BindingFlags.Instance); if (fi != null) { Log.Info("Updating lastUpdateTime"); fi.SetValue(tmpGen, Planetarium.GetUniversalTime()); } else { Log.Info("Unable to get pointer to lastUpdateTime"); } } break; } } } }