private void DoInit(LiveSplitState state, DeltaOutput d) { Debug("Initializing"); RunMethod(Methods.init, state, d); InitCompleted = true; Debug("Init completed, running main methods"); }
internal void RunScript(object sender, DeltaOutput d) { try { Script.Update(State, d); } catch (Exception e) { Log.Error(e, "VASL Script failed to process frame."); } }
private static extern bool CreateDeltaB( DeltaFileType fileTypeSet, // File type set. DeltaFlag setFlags, // Set these flags. DeltaFlag resetFlags, // Reset (suppress) these flags. DeltaInput source, // Source memory block. DeltaInput target, // Target memory block. DeltaInput sourceOptions, // Memory block with source-specific options. DeltaInput targetOptions, // Memory block with target-specific options. DeltaInput globalOptions, // Memory block with global options. IntPtr targetFileTime, // Target file time to use, null to use current time. (need this overload because the compiler can't convert from "null" to "ref FILETIME") AlgId hashAlgId, out DeltaOutput delta);
private static extern bool CreateDeltaB( DeltaFileType fileTypeSet, // File type set. DeltaFlag setFlags, // Set these flags. DeltaFlag resetFlags, // Reset (suppress) these flags. DeltaInput source, // Source memory block. DeltaInput target, // Target memory block. DeltaInput sourceOptions, // Memory block with source-specific options. DeltaInput targetOptions, // Memory block with target-specific options. DeltaInput globalOptions, // Memory block with global options. ref System.Runtime.InteropServices.ComTypes.FILETIME targetFileTime, // Target file time to use, null to use current time. AlgId hashAlgId, out DeltaOutput delta);
private void UpdateRowsAsync(DeltaOutput d, int rowCount) { // It might be a bad idea to assume it's in the correct order, // but this might be a bit CPU intensive, and we're trying to // save as much of that as possible. var deltas = (double[])d.History[d.FrameIndex].Deltas.Clone(); var frameRate = (int)Math.Ceiling(d.FrameRate); var textBlocks = new TextBlock[rowCount - 2]; var deltaCount = deltas.Length; for (int i = 1; i < deltaCount + 1; i++) { var value = deltas[i - 1]; var varState = !double.IsNaN(value); textBlocks[i - 1] = GetLabels(value, i - 1, frameRate, varState); } var vars = (IDictionary <string, object>)_Component.Script.Vars; for (int i = deltaCount + 1; i < rowCount - 1; i++) { var varsKey = _VarsNames.ElementAt(i - deltaCount - 1); if (vars.ContainsKey(varsKey)) { var value = vars[varsKey]; textBlocks[i - 1] = GetLabels(value, i - 1, frameRate); } } if (!_Updating && !tlpFeatures.IsDisposed) { tlpFeatures.Invoke((MethodInvoker) delegate { for (int i = 1; i < tlpFeatures.RowCount - 1; i++) { var variableRow = (VariableRow)tlpFeatures.Controls[i]; variableRow.Update(textBlocks[i - 1]); } }); } _Updating = false; }
// Update the script public void Update(LiveSplitState state, DeltaOutput d) { if (Timer == null) { Timer = new TimerModel() { CurrentState = state }; PreviousPhase = state.CurrentPhase; Timer.OnUndoSplit += Timer_OnUndoSplit; } if (!InitCompleted) { DoInit(state, d); } else { DoUpdate(state, d); } ScriptUpdateFinished?.Invoke(this, d); }
private static extern bool ApplyDeltaB( DeltaApplyFlag applyFlags, DeltaInput source, DeltaInput delta, out DeltaOutput target);
private void UpdateRows(object sender, DeltaOutput d) { Task.Run(() => UpdateRowsAsync(d, tlpFeatures.RowCount)); }
private static extern bool ApplyDeltaB( DeltaApplyFlag applyFlags, DeltaInput source, DeltaInput delta, out DeltaOutput target );
private dynamic RunMethod(VASLMethod method, LiveSplitState state, DeltaOutput d) { var result = method.Call(state, Vars, GameVersion, Settings.Reader, d); return(result); }
private void DoUpdate(LiveSplitState state, DeltaOutput d) { var updateState = RunMethod(Methods.update, state, d); // If Update explicitly returns false, don't run anything else if (updateState is bool && updateState == false) { return; } var offsetTime = TimeStamp.CurrentDateTime.Time - d.History[d.FrameIndex].FrameEnd; // Enable regardless to keep track of offseting for now. if (!state.IsGameTimeInitialized) { Timer.InitializeGameTime(); } if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused) { if (UsesGameTime) { if (UsesIsLoading) { var isPausedState = RunMethod(Methods.isLoading, state, d); if (isPausedState is bool) { var prevPauseState = state.IsGameTimePaused; state.IsGameTimePaused = isPausedState; if (prevPauseState != isPausedState) { if (isPausedState) { state.GameTimePauseTime -= offsetTime; } else { state.GameTimePauseTime += offsetTime; } } } } if (UsesGameTime) { var gameTimeState = RunMethod(Methods.gameTime, state, d); if (gameTimeState is TimeSpan) { state.SetGameTime(gameTimeState); } } } if (Settings.GetBasicSettingValue("reset")) { var resetState = RunMethod(Methods.reset, state, d); if (resetState is bool && resetState == true) { Timer.Reset(); } } if (Settings.GetBasicSettingValue("split")) { var splitState = RunMethod(Methods.split, state, d); if (splitState is bool && splitState == true) { splitState = TimeSpan.Zero; } if (splitState is TimeSpan) { AdjustGameTime(state, splitState.Negate()); if (!UsesCustomGameTime) { AdjustGameTime(state, offsetTime.Negate()); } Timer.Split(); if (state.CurrentPhase != TimerPhase.Ended) { AdjustGameTime(state, splitState); if (!UsesCustomGameTime) { AdjustGameTime(state, offsetTime); } } else { LastSplitOffset = splitState; if (!UsesCustomGameTime) { LastSplitOffset += offsetTime; } } } } // @TODO: Add undo and skip; } else if (state.CurrentPhase == TimerPhase.NotRunning && Settings.GetBasicSettingValue("start")) { var startState = RunMethod(Methods.start, state, d); if ((startState is bool && startState == true) || startState is TimeSpan) { Timer.Start(); if (!state.IsGameTimeInitialized) { Timer.InitializeGameTime(); } LastSplitOffset = TimeSpan.Zero; TimeSpan startOffset = (startState is TimeSpan) ? startState : TimeSpan.Zero; AdjustGameTime(state, startOffset); if (!UsesCustomGameTime) { AdjustGameTime(state, offsetTime); } } } PreviousPhase = state.CurrentPhase; }
public dynamic Call(LiveSplitState timer, ExpandoObject vars, string gameVersion, dynamic settings, DeltaOutput d) { dynamic ret = null; var frameIndex = d.IsBlank ? -1 : d.FrameIndex; try { ret = CompiledCode.Execute(timer, vars, d, settings, frameIndex); } catch (Exception ex) { // Ignore NullReferenceExceptions until the history is filled. if (!(ex is NullReferenceException) || d.OriginalIndex > d.HistorySize) { Log.Error(new VASLRuntimeException(this, ex), "VASL Script Error"); } } return(ret); }