public void Save() { try { Persistent persistent; persistent.HarvestMultiplier = SyncHarvestEfficiency.Get(); string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent)); MyAPIGateway.Utilities.SetVariable($"settings_{Drill.EntityId}", Raw); Drill.Storage?.AddOrUpdate(SessionCore.StorageGuid, Raw); } catch (Exception Scrap) { SessionCore.LogError($"{Drill.CustomName}.Save()", Scrap); } }
public void Save() { try { Persistent persistent; persistent.BeamLength = SyncBeamLength.Get(); persistent.DistanceBased = SyncDistanceMode.Get(); string Raw = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(persistent)); MyAPIGateway.Utilities.SetVariable($"settings_{Tool.EntityId}", Raw); SessionCore.DebugWrite($"{Tool.CustomName}.Load()", "Set settings to storage."); } catch (Exception Scrap) { SessionCore.LogError($"{Tool.CustomName}.Save()", Scrap); } }
public void Load() { try { if (MyAPIGateway.Multiplayer.MultiplayerActive && !MyAPIGateway.Multiplayer.IsServer) { SyncBeamLength.Ask(); SyncDistanceMode.Ask(); SyncSpeedMultiplier.Ask(); return; } string Storage = ""; //if (Tool.Storage.ContainsKey(SessionCore.StorageGuid)) if (Tool.Storage?.TryGetValue(SessionCore.StorageGuid, out Storage) == true || MyAPIGateway.Utilities.GetVariable($"settings_{Tool.EntityId}", out Storage)) { try { Persistent persistent = MyAPIGateway.Utilities.SerializeFromBinary <Persistent>(Convert.FromBase64String(Storage)); SyncBeamLength.Set(persistent.BeamLength); SyncDistanceMode.Set(persistent.DistanceBased); SyncSpeedMultiplier.Set(persistent.SpeedMultiplier); SessionCore.DebugWrite($"{Tool.CustomName}.Load()", $"Loaded from storage. Persistent Beamlength: {persistent.BeamLength}; Sync Beamlength: {SyncBeamLength.Get()}"); } catch (Exception Scrap) { SessionCore.LogError($"{Tool.CustomName}.Load()", Scrap); } } else { SessionCore.DebugWrite($"{Tool.CustomName}.Load()", "Storage access failed."); } } catch (Exception Scrap) { SessionCore.LogError($"{Tool.CustomName}.Load().AccessStorage", Scrap); } }