private void StartAtNearestFrameAndEmulate(int frame, bool fromLua, bool fromRewinding) { if (frame == Emulator.Frame) return; _shouldUnpauseFromRewind = fromRewinding && !Mainform.EmulatorPaused; TastudioPlayMode(); KeyValuePair<int, byte[]> closestState = CurrentTasMovie.TasStateManager.GetStateClosestToFrame(frame); if (closestState.Value != null && (frame < Emulator.Frame || closestState.Key > Emulator.Frame)) { LoadState(closestState); } if (fromLua) { bool wasPaused = Mainform.EmulatorPaused; // why not use this? because I'm not letting the form freely run. it all has to be under this loop. // i could use this and then poll StepRunLoop_Core() repeatedly, but.. that's basically what I'm doing // PauseOnFrame = frame; // can't re-enter lua while doing this Mainform.SuppressLua = true; while (Emulator.Frame != frame) { Mainform.SeekFrameAdvance(); } Mainform.SuppressLua = false; if (!wasPaused) { Mainform.UnpauseEmulator(); } // lua botting users will want to re-activate record mode automatically -- it should be like nothing ever happened if (WasRecording) { TastudioRecordMode(); } // now the next section won't happen since we're at the right spot } // frame == Emulator.Frame when frame == 0 if (frame > Emulator.Frame) { if (Mainform.EmulatorPaused || Mainform.IsSeeking || fromRewinding) // make seek frame keep up with emulation on fast scrolls { StartSeeking(frame); } else { // GUI users may want to be protected from clobbering their video when skipping around... // well, users who are rewinding arent. (that gets done through the seeking system in the call above) // users who are clicking around.. I dont know. } } }