public static PantyFairySaveData Deserialize(PluginData data) { var result = new PantyFairySaveData(); if (data != null) { foreach (var fieldInfo in _serializedFields) { if (data.data.TryGetValue(fieldInfo.Name, out var val)) { try { if (fieldInfo.FieldType.IsEnum) { val = (int)val; } fieldInfo.SetValue(result, val); } catch (Exception ex) { PantyFairyPlugin.Logger.LogError($"Could not deserialize field {fieldInfo.Name} because of error: {ex.Message}"); } } } if (result.Progress == StoryProgress.Unknown || !Enum.IsDefined(typeof(StoryProgress), result.Progress)) { result.Progress = StoryProgress.E1_Initial; PantyFairyPlugin.Logger.LogInfo("Resetting Story Progress to E1_Initial from " + result.Progress); } } else { result.Progress = StoryProgress.E1_Initial; } return(result); }
protected override void OnGameLoad(GameSaveLoadEventArgs args) { var data = GetExtendedData(); CustomEvents.SaveData = PantyFairySaveData.Deserialize(data); }