Skip to content

Commit

Permalink
Save using a Task to prevent freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jun 12, 2024
1 parent 13ad39d commit 8ce8802
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,10 +1620,19 @@ private void HealthController_DiedEvent(EDamageType obj)

if (FikaPlugin.Instance.ForceSaveOnDeath)
{
SavePlayer((CoopPlayer)gparam_0.Player, MyExitStatus, null, true);
StartCoroutine(SaveOnDeathRoutine());
}
}

private IEnumerator SaveOnDeathRoutine()
{
Task saveTask = SavePlayer((CoopPlayer)gparam_0.Player, MyExitStatus, null, true);
while (!saveTask.IsCompleted)
{
yield return null;
}
}

public override void Stop(string profileId, ExitStatus exitStatus, string exitName, float delay = 0f)
{
Logger.LogInfo("CoopGame::Stop");
Expand Down Expand Up @@ -1739,11 +1748,11 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa
GClass548.Config.UseSpiritPlayer = false;
}

private void SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitName, bool fromDeath)
private Task SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitName, bool fromDeath)
{
if (hasSaved)
{
return;
return Task.CompletedTask;
}

if (fromDeath)
Expand Down Expand Up @@ -1771,6 +1780,7 @@ private void SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitNam
RequestHandler.PutJson("/raid/profile/save", SaveRequest.ToJson(Converters.AddItem(new NotesJsonConverter()).ToArray()));

hasSaved = true;
return Task.CompletedTask;
}

private void StopFromError(string profileId, ExitStatus exitStatus)
Expand Down Expand Up @@ -1984,12 +1994,8 @@ public void HandleExit()
MonoBehaviourSingleton<BetterAudio>.Instance.FadeOutVolumeAfterRaid();
StaticManager staticManager = StaticManager.Instance;
float num = delay;
Action action;
if ((action = EndAction) == null)
{
action = (EndAction = new Action(FireCallback));
}
staticManager.WaitSeconds(num, action);
EndAction = new Action(FireCallback);
staticManager.WaitSeconds(num, EndAction);
}

private void FireCallback()
Expand Down Expand Up @@ -2023,12 +2029,8 @@ public void ExitOverride()
}
MonoBehaviour instance2 = StaticManager.Instance;
float num = delay;
Action action;
if ((action = action_0) == null)
{
action = action_0 = new Action(method_1);
}
instance2.WaitSeconds(num, action);
action_0 = new Action(method_1);
instance2.WaitSeconds(num, action_0);
}
}

Expand Down

0 comments on commit 8ce8802

Please sign in to comment.