diff --git a/Core/Callbacks/ModCallbacks.cs b/Core/Callbacks/ModCallbacks.cs index 1de767f5..bc30dcd2 100644 --- a/Core/Callbacks/ModCallbacks.cs +++ b/Core/Callbacks/ModCallbacks.cs @@ -43,7 +43,7 @@ public class ModCallbacks : OnLoad // if (ProgramStatics.MODS) { // await this.postSptModLoader.load(); // } TODO: needs to be implemented - throw new NotImplementedException(); + return; } public string GetRoute() diff --git a/Core/Callbacks/SaveCallbacks.cs b/Core/Callbacks/SaveCallbacks.cs index 17b41ce6..103ac844 100644 --- a/Core/Callbacks/SaveCallbacks.cs +++ b/Core/Callbacks/SaveCallbacks.cs @@ -26,12 +26,10 @@ public class SaveCallbacks : OnLoad, OnUpdate _backupService = backupService; } - public Task OnLoad() + public async Task OnLoad() { _backupService.InitAsync(); _saveServer.Load(); - - return Task.CompletedTask; } public async Task OnUpdate(long SecondsSinceLastRun) diff --git a/Core/Controllers/GameController.cs b/Core/Controllers/GameController.cs index d3bf02b8..59d81ebc 100644 --- a/Core/Controllers/GameController.cs +++ b/Core/Controllers/GameController.cs @@ -187,6 +187,6 @@ public class GameController public void Load() { - throw new NotImplementedException(); + return; // TODO: actually implement } } diff --git a/Core/Controllers/PresetController.cs b/Core/Controllers/PresetController.cs index 72d1d89e..dfe9e26b 100644 --- a/Core/Controllers/PresetController.cs +++ b/Core/Controllers/PresetController.cs @@ -10,6 +10,6 @@ public class PresetController /// public void Initialize() { - throw new NotImplementedException(); + return; // TODO: actually implement } } diff --git a/Core/Controllers/TraderController.cs b/Core/Controllers/TraderController.cs index d6e1bdad..46290be5 100644 --- a/Core/Controllers/TraderController.cs +++ b/Core/Controllers/TraderController.cs @@ -14,7 +14,7 @@ public class TraderController /// public void Load() { - throw new NotImplementedException(); + return; // TODO: actually implement } /// diff --git a/Core/DI/OnLoadOrder.cs b/Core/DI/OnLoadOrder.cs index 9e9b75d7..82ba878c 100644 --- a/Core/DI/OnLoadOrder.cs +++ b/Core/DI/OnLoadOrder.cs @@ -5,12 +5,12 @@ public static class OnLoadOrder public const int Database = 0; public const int PostDBModLoader = 1; public const int HandbookCallbacks = 2; - public const int HttpCallbacks = 3; - public const int PresetCallbacks = 4; - public const int SaveCallbacks = 5; - public const int TraderCallbacks = 6; - public const int RagfairPriceService = 7; - public const int RagfairCallbacks = 8; - public const int ModCallbacks = 9; - public const int GameCallbacks = 10; + public const int PresetCallbacks = 3; + public const int SaveCallbacks = 4; + public const int TraderCallbacks = 5; + public const int RagfairPriceService = 6; + public const int RagfairCallbacks = 7; + public const int ModCallbacks = 8; + public const int GameCallbacks = 9; + public const int HttpCallbacks = 10; } diff --git a/Core/Routers/SaveLoad/HealthSaveLoadRouter.cs b/Core/Routers/SaveLoad/HealthSaveLoadRouter.cs new file mode 100644 index 00000000..4ef2852d --- /dev/null +++ b/Core/Routers/SaveLoad/HealthSaveLoadRouter.cs @@ -0,0 +1,47 @@ +using Core.Annotations; +using Core.DI; +using Core.Models.Eft.Profile; + +namespace Core.Routers.SaveLoad; + +[Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))] +public class HealthSaveLoadRouter : SaveLoadRouter +{ + protected override List GetHandledRoutes() + { + return new List() { new HandledRoute("spt-health", false) }; + } + + public override SptProfile HandleLoad(SptProfile profile) + { + if (profile?.VitalityData == null) + profile.VitalityData = new() { Health = null, Effects = null }; + + profile.VitalityData.Health = new() + { + Hydration = 0, + Energy = 0, + Temperature = 0, + Head = 0, + Chest = 0, + Stomach = 0, + LeftArm = 0, + RightArm = 0, + LeftLeg = 0, + RightLeg = 0 + }; + + profile.VitalityData.Effects = new() + { + Head = new(), + Chest = new(), + Stomach = new(), + LeftArm = new(), + RightArm = new(), + LeftLeg = new(), + RightLeg = new() + }; + + return profile; + } +} diff --git a/Core/Routers/SaveLoad/InraidSaveLoadRouter.cs b/Core/Routers/SaveLoad/InraidSaveLoadRouter.cs new file mode 100644 index 00000000..bae4b0bf --- /dev/null +++ b/Core/Routers/SaveLoad/InraidSaveLoadRouter.cs @@ -0,0 +1,22 @@ +using Core.Annotations; +using Core.DI; +using Core.Models.Eft.Profile; + +namespace Core.Routers.SaveLoad; + +[Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))] +public class InraidSaveLoadRouter : SaveLoadRouter +{ + protected override List GetHandledRoutes() + { + return new List() { new HandledRoute("spt-inraid", false) }; + } + + public override SptProfile HandleLoad(SptProfile profile) + { + if (profile.InraidData == null) + profile.InraidData = new Inraid { Location = "none", Character = "none" }; + + return profile; + } +} diff --git a/Core/Routers/SaveLoad/InsuranceSaveLoadRouter.cs b/Core/Routers/SaveLoad/InsuranceSaveLoadRouter.cs new file mode 100644 index 00000000..08f122de --- /dev/null +++ b/Core/Routers/SaveLoad/InsuranceSaveLoadRouter.cs @@ -0,0 +1,22 @@ +using Core.Annotations; +using Core.DI; +using Core.Models.Eft.Profile; + +namespace Core.Routers.SaveLoad; + +[Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))] +public class InsuranceSaveLoadRouter : SaveLoadRouter +{ + protected override List GetHandledRoutes() + { + return new List() { new HandledRoute("spt-insurance", false) }; + } + + public override SptProfile HandleLoad(SptProfile profile) + { + if (profile.InsuranceList == null) + profile.InsuranceList = new List(); + + return profile; + } +} diff --git a/Core/Routers/SaveLoad/ProfileSaveLoadRouter.cs b/Core/Routers/SaveLoad/ProfileSaveLoadRouter.cs new file mode 100644 index 00000000..f8615124 --- /dev/null +++ b/Core/Routers/SaveLoad/ProfileSaveLoadRouter.cs @@ -0,0 +1,22 @@ +using Core.Annotations; +using Core.DI; +using Core.Models.Eft.Profile; + +namespace Core.Routers.SaveLoad; + +[Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))] +public class ProfileSaveLoadRouter : SaveLoadRouter +{ + protected override List GetHandledRoutes() + { + return new List() { new HandledRoute("spt-profile", false) }; + } + + public override SptProfile HandleLoad(SptProfile profile) + { + if (profile.CharacterData == null) + profile.CharacterData = new Characters { PmcData = new(), ScavData = new() }; + + return profile; + } +} diff --git a/Core/Servers/SaveServer.cs b/Core/Servers/SaveServer.cs index fa7db3c2..62f4a171 100644 --- a/Core/Servers/SaveServer.cs +++ b/Core/Servers/SaveServer.cs @@ -85,9 +85,11 @@ public class SaveServer // load profiles var stopwatch = Stopwatch.StartNew(); - foreach (var file in files) { + foreach (var file in files) + { LoadProfile(_vfs.StripExtension(file)); } + stopwatch.Stop(); _logger.Debug($"{files.Count()} Profiles took: {stopwatch.ElapsedMilliseconds}ms to load."); } @@ -99,7 +101,8 @@ public class SaveServer { // Save every profile var totalTime = 0L; - foreach ( var sessionID in profiles) { + foreach (var sessionID in profiles) + { totalTime += SaveProfile(sessionID.Key); } @@ -139,7 +142,7 @@ public class SaveServer * @returns Dictionary of ISptProfile */ public Dictionary GetProfiles() => profiles; - + /** * Delete a profile by id * @param sessionID Id of profile to remove @@ -171,7 +174,7 @@ public class SaveServer new SptProfile() { ProfileInfo = profileInfo, - CharacterData = new Characters() { PmcData = new PmcData(), ScavData = new PmcData() } + CharacterData = new Characters() { PmcData = new(), ScavData = new() } }); } @@ -191,8 +194,8 @@ public class SaveServer */ public void LoadProfile(string sessionID) { - var filename = $"{sessionID}.json"; - var filePath = $"{profileFilepath}{filename}"; + var filename = $"{sessionID}.json"; + var filePath = $"{profileFilepath}{filename}"; if (_vfs.FileExists(filePath)) { // File found, store in profiles[] @@ -200,7 +203,8 @@ public class SaveServer } // Run callbacks - foreach (var callback in _saveLoadRouters) { + foreach (var callback in _saveLoadRouters) // HealthSaveLoadRouter, InraidSaveLoadRouter, InsuranceSaveLoadRouter, ProfileSaveLoadRouter. THESE SHOULD EXIST IN HERE + { profiles[sessionID] = callback.HandleLoad(GetProfile(sessionID)); } } @@ -216,9 +220,9 @@ public class SaveServer var filePath = $"{profileFilepath}{sessionID}.json"; // Run pre-save callbacks before we save into json - foreach ( var callback in onBeforeSaveCallbacks) + foreach (var callback in onBeforeSaveCallbacks) { - var previous = profiles[sessionID]; + var previous = profiles[sessionID]; try { profiles[sessionID] = onBeforeSaveCallbacks[callback.Key](profiles[sessionID]); @@ -231,9 +235,10 @@ public class SaveServer } var start = Stopwatch.StartNew(); - var jsonProfile = _jsonUtil.Serialize(profiles[sessionID], !_configServer.GetConfig(ConfigTypes.CORE).Features.CompressProfile); - var fmd5 = _hashUtil.GenerateMd5ForData(jsonProfile); - if (!saveMd5.TryGetValue(sessionID, out var currentMd5) || currentMd5 != fmd5) { + var jsonProfile = _jsonUtil.Serialize(profiles[sessionID], !_configServer.GetConfig(ConfigTypes.CORE).Features.CompressProfile); + var fmd5 = _hashUtil.GenerateMd5ForData(jsonProfile); + if (!saveMd5.TryGetValue(sessionID, out var currentMd5) || currentMd5 != fmd5) + { saveMd5[sessionID] = fmd5; // save profile to disk _vfs.WriteFile(filePath, jsonProfile); @@ -256,6 +261,7 @@ public class SaveServer profiles.Remove(sessionID); _vfs.DeleteFile(file); } + return !_vfs.FileExists(file); } } diff --git a/Core/Utils/App.cs b/Core/Utils/App.cs index 6824f5ec..9635b0ad 100644 --- a/Core/Utils/App.cs +++ b/Core/Utils/App.cs @@ -79,9 +79,23 @@ public class App _logger.Debug("Commit: ${ProgramStatics.COMMIT}"); } */ - foreach (var onLoad in _onLoad) await onLoad.OnLoad(); + foreach (var onLoad in _onLoad) + { + Console.WriteLine($"Start Onload: {onLoad.GetRoute()}"); + await onLoad.OnLoad(); + Console.WriteLine($"finish Onload: {onLoad.GetRoute()}"); + } - var timer = new Timer(_ => { update(_onUpdate); }, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(5000)); + var timer = new Timer(_ => + { + Console.WriteLine($"Start OnUpdate"); + update(_onUpdate); + Console.WriteLine($"Finish OnUpdate"); + + }, + null, + TimeSpan.Zero, + TimeSpan.FromMilliseconds(5000)); } protected async Task update(IEnumerable onUpdateComponents) @@ -124,4 +138,4 @@ public class App _logger.Error(_localisationService.GetText("scheduled_event_failed_to_run", updateable.GetRoute())); _logger.Error(err.ToString()); } -} \ No newline at end of file +} diff --git a/Core/Utils/Watermark.cs b/Core/Utils/Watermark.cs index 882303ed..2622a1b1 100644 --- a/Core/Utils/Watermark.cs +++ b/Core/Utils/Watermark.cs @@ -110,7 +110,7 @@ public class Watermark { var versionTag = /*ProgramStatics.DEBUG&*/ $"{sptVersion} - {_localisationService.GetText("bleeding_edge_build")}"; if (withEftVersion) { - var tarkovVersion = sptConfig.CompatibleTarkovVersion.Split(".").First(); + var tarkovVersion = sptConfig.CompatibleTarkovVersion.Split(".").Last(); return $"{versionTag} ({tarkovVersion})"; }