Skip to content

Commit

Permalink
autosave tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Aug 26, 2023
1 parent 547ef79 commit a76e907
Showing 1 changed file with 58 additions and 13 deletions.
71 changes: 58 additions & 13 deletions DXRModules/DeusEx/Classes/DXRAutosave.uc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class DXRAutosave extends DXRActorsBase transient;

var transient bool bNeedSave;
var config float save_delay;
var transient float save_timer;

const Disabled = 0;
const FirstEntry = 1;
Expand All @@ -11,18 +12,19 @@ const ExtraSafe = 4;

function CheckConfig()
{
if( ConfigOlderThan(2,5,0,9) ) {
save_delay = 0.7;
if( ConfigOlderThan(2,5,2,7) ) {
save_delay = 0.5;
}
Super.CheckConfig();
Disable('Tick');
}

function PostFirstEntry()
function PreFirstEntry()
{
Super.PostFirstEntry();
l("PostFirstEntry() " $ dxr.dxInfo.MissionNumber);
Super.PreFirstEntry();
l("PreFirstEntry() " $ dxr.dxInfo.MissionNumber);
if( dxr.dxInfo != None && dxr.dxInfo.MissionNumber > 0 && dxr.dxInfo.MissionNumber < 98 && dxr.flags.autosave > 0 ) {
bNeedSave=true;
NeedSave();
}
}

Expand All @@ -31,20 +33,59 @@ function ReEntry(bool IsTravel)
Super.ReEntry(IsTravel);
l("ReEntry() " $ dxr.dxInfo.MissionNumber);
if( dxr.dxInfo != None && dxr.dxInfo.MissionNumber > 0 && dxr.dxInfo.MissionNumber < 98 && dxr.flags.autosave>=EveryEntry && dxr.flags.autosave != Hardcore && IsTravel ) {
bNeedSave=true;
NeedSave();
}
}

function PostAnyEntry()
{
if( bNeedSave )
SetTimer(save_delay, True);
if(bNeedSave)
NeedSave();
}

function Timer()
function NeedSave()
{
if( bNeedSave )
doAutosave();
bNeedSave = true;
save_timer = save_delay;
Enable('Tick');
if(!PawnIsInCombat(player()))
SetGameSpeed(0);
}

function SetGameSpeed(float s)
{
local MissionScript mission;

s = FMax(s, 0.01);// ServerSetSloMo only goes down to 0.1
if(s == Level.Game.GameSpeed) return;
Level.Game.GameSpeed = s;
Level.TimeDilation = s;
Level.Game.SetTimer(s, true);
Level.Game.SaveConfig();
Level.Game.GameReplicationInfo.SaveConfig();

// we need the mission script to clear PlayerTraveling
if(s < 0.5) s /= 2;// might as well run the timer faster?
foreach AllActors(class'MissionScript', mission) {
mission.SetTimer(mission.checkTime * s, true);
}
}

function Tick(float delta)
{
if(bNeedSave) {
save_timer -= delta / Level.Game.GameSpeed;
if(save_timer <= 0) {
doAutosave();
}
}
else if(save_timer <= 0) {
SetGameSpeed(1);
Disable('Tick');
} else {
save_timer -= delta / Level.Game.GameSpeed;
SetGameSpeed(0.2);
}
}

static function bool AllowManualSaves(DeusExPlayer player)
Expand All @@ -66,6 +107,8 @@ function doAutosave()
local int lastMission;
local bool isDifferentMission;

save_timer = save_delay;

if( dxr == None ) {
info("dxr == None, doAutosave() not saving yet");
return;
Expand All @@ -84,6 +127,7 @@ function doAutosave()

if(PawnIsInCombat(p)) {
info("waiting for Player to be out of combat, not saving yet");
SetGameSpeed(1);
return;
}

Expand Down Expand Up @@ -115,10 +159,11 @@ function doAutosave()
dxr.flags.f.SetInt('Rando_lastmission', dxr.dxInfo.MissionNumber,, 999);

info("doAutosave() " $ lastMission @ dxr.dxInfo.MissionNumber @ saveSlot @ saveName @ p.GetStateName() @ save_delay);
SetTimer(0, False);
bNeedSave = false;
SetGameSpeed(1);
class'DXRStats'.static.IncDataStorageStat(p, "DXRStats_autosaves");
p.SaveGame(saveSlot, saveName);
SetGameSpeed(0);

if( interruptedDL != None ) {
p.dataLinkPlay = interruptedDL;
Expand Down

0 comments on commit a76e907

Please sign in to comment.