예제 #1
0
        public async Task ExampleUsage2()
        {
            var t = Log.MethodEntered("DataStoreExample2.ExampleUsage2");

            // Add a thunk middleware to allow dispatching async actions:
            var thunkMiddleware = Middlewares.NewThunkMiddleware <MyAppState1>();

            // aDD A logging middleware to log all dispatched actions:
            var loggingMiddleware = Middlewares.NewLoggingMiddleware <MyAppState1>();

            // Add a recorder middleware to enable hot reload by replaying previously recorded actions:
            var recorder      = new ReplayRecorder <MyAppState1>();
            var recMiddleware = recorder.CreateMiddleware();

            var undoable = new UndoRedoReducer <MyAppState1>();
            // To allow undo redo on the full store wrap the main reducer with the undo reducer:
            var undoReducer = undoable.Wrap(MyReducers1.ReduceMyAppState1);

            var data  = new MyAppState1(null, null, 0); // the initial immutable state
            var store = new DataStore <MyAppState1>(undoReducer, data, loggingMiddleware, recMiddleware, thunkMiddleware);

            store.storeName = "Store 1";

            TestNormalDispatchOfActions(store);

            TestUndoAndRedo(store);

            await TestAsyncActions(store);

            await TestReplayRecorder(recorder, store);

            TestSkippableUndoActions(store);

            Log.MethodDone(t);
        }
예제 #2
0
 public void SendToReplayRecorder(BinaryWriter packet)
 {
     if (ReplayRecorder != null)
     {
         ReplayRecorder.Send(packet);
     }
 }
예제 #3
0
        internal static void LaunchGame()
        {
            string GameDirectory = Location;

            var p = new System.Diagnostics.Process();

            p.StartInfo.WorkingDirectory = GameDirectory;
            p.StartInfo.FileName         = Path.Combine(GameDirectory, "League of Legends.exe");
            p.Exited += p_Exited;
            p.StartInfo.Arguments = "\"8394\" \"" + RootLocation + "LoLLauncher.exe" + "\" \"" + "\" \"" +
                                    CurrentGame.ServerIp + " " +
                                    CurrentGame.ServerPort + " " +
                                    CurrentGame.EncryptionKey + " " +
                                    CurrentGame.SummonerId + "\"";
            p.Start();
            MainWin.Visibility = Visibility.Hidden;
            MainWin.Hide();
            string ObserverServerIp;
            double GameId;
            string InternalName;
            string ObserverEncryptionKey;

            PlayerCredentialsDto replaydata = CurrentGame;

            ObserverServerIp      = replaydata.ObserverServerIp;
            GameId                = replaydata.GameId;
            InternalName          = Region.InternalName;
            ObserverEncryptionKey = replaydata.ObserverEncryptionKey;
            Autorecorder          = new JustUltedProj.Logic.Replays.ReplayRecorder(ObserverServerIp, (Int32)GameId, InternalName, ObserverEncryptionKey);
        }
예제 #4
0
        public void Record()
        {
            try
            {
                recorder = new ReplayRecorder(Server, GameID, Platform, Key, ReplayRecording);



                //DateTime st = recorder.GetGameStartTime();
                //RecordGui.SetGameStartTime(st);
                recorder.API = Program.MainFormInstance.API;
                recorder.OnReplayRecorded    += recorder_OnReplayRecorded;
                recorder.OnGotData           += recorder_OnGotChunk;
                recorder.OnAttemptToDownload += recorder_OnAttemptToDownload;
                recorder.OnFailedToRecord    += recorder_OnFailedToRecord;
                recorder.OnFailedToSave      += recorder_OnFailedToSave;
                recorder.OnDownloadProgress  += recorder_OnDownloadProgress;
                recorder.OnProblemOccured    += recorder_OnProblemOccured;
                recorder.CancelRecordOnFail   = true;
                if (!recorder.Recording)
                {
                    recorder_OnFailedToRecord(new Exception("The game has ended a long time ago or never existed"));
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Log.Error("Failed to init record", ex);
            }
        }
예제 #5
0
        private void RecordButton_Click(object sender, RoutedEventArgs e)
        {
            var objectGame = gameList[SelectedGame];
            Dictionary <string, object> SpectatorGame = objectGame as Dictionary <string, object>;
            string key        = "";
            int    gameId     = 0;
            string platformId = "";

            foreach (KeyValuePair <string, object> pair in SpectatorGame)
            {
                if (pair.Key == "gameId")
                {
                    gameId = (int)pair.Value;
                }
                if (pair.Key == "observers")
                {
                    Dictionary <string, object> keyArray = pair.Value as Dictionary <string, object>;
                    foreach (KeyValuePair <string, object> keyArrayPair in keyArray)
                    {
                        if (keyArrayPair.Key == "encryptionKey")
                        {
                            key = keyArrayPair.Value as string;
                        }
                    }
                }
                if (pair.Key == "platformId")
                {
                    platformId = pair.Value as string;
                }
            }

            BaseRegion region = BaseRegion.GetRegion((string)SpectatorComboBox.SelectedValue);
            //region.SpectatorIpAddress, key, gameId, platformId
            var recorder = new ReplayRecorder(region.SpectatorIpAddress + ":8088", gameId, platformId, key);
        }
예제 #6
0
    public void Fall(HumanBase humanBase, bool drown = false)
    {
        Human human = humanBase as Human;

        if (ReplayRecorder.isPlaying || NetGame.isClient)
        {
            return;
        }
        if (passedLevel && ((currentLevelNumber >= 0 && currentLevelNumber < levels.Length) || workshopLevel != null || currentLevelType == WorkshopItemSource.EditorPick))
        {
            if (ReplayRecorder.isRecording)
            {
                ReplayRecorder.Stop();
            }
            else if (workshopLevel != null)
            {
                passedLevel = false;
                PlayerManager.SetSingle();
                App.instance.PauseLeave();
                GameSave.PassCheckpointWorkshop(workshopLevel.hash, 0);
            }
            else if (currentLevelType == WorkshopItemSource.EditorPick)
            {
                passedLevel = false;
                PlayerManager.SetSingle();
                App.instance.PauseLeave();
                if (NetGame.isLocal)
                {
                    GameSave.StartFromBeginning();
                }
                for (int i = 0; i < Human.all.Count; i++)
                {
                    Human.all[i].ReleaseGrab();
                }
            }
            else
            {
                StatsAndAchievements.PassLevel(levels[currentLevelNumber], human);
                for (int j = 0; j < Human.all.Count; j++)
                {
                    Human.all[j].ReleaseGrab();
                }
                StartCoroutine(PassLevel());
            }
        }
        else
        {
            if (drown)
            {
                StatsAndAchievements.IncreaseDrownCount(human);
            }
            else
            {
                StatsAndAchievements.IncreaseFallCount(human);
            }
            Respawn(human, Vector3.zero);
            CheckpointRespawned(currentCheckpointNumber);
        }
    }
예제 #7
0
        public int?Turn(int turnnum)
        {
            foreach (var player in Players)
            {
                player.Cost += 3;
            }

            ReplayRecorder recorder = new ReplayRecorder();

            recorder.RecordStartFrame(this);
            var x = PlayerMoveHelper(0, 1);

            if (x is int propagResult)
            {
                return(propagResult);
            }
            x = PlayerMoveHelper(1, 0);
            if (x is int propagResult2)
            {
                return(propagResult2);
            }
            recorder.RecordEndFrame(this);
            ReplayOrganizer.AddFrame(recorder, true);

            MeleeAct();
            RangedAct();
            MapAct();

            if (Players[0].Base <= 0 && Players[1].Base > 0)
            {
                return(1);
            }
            if (Players[1].Base <= 0 && Players[0].Base > 0)
            {
                return(0);
            }
            if (Players[1].Base <= 0 && Players[0].Base <= 0)
            {
                return(-1);
            }

            if (turnnum >= 200)
            {
                if (Players[0].Base > Players[1].Base)
                {
                    return(0);
                }
                else if (Players[0].Base < Players[1].Base)
                {
                    return(1);
                }
                else
                {
                    return(-1);
                }
            }
            return(null);
        }
예제 #8
0
        private async void Download_Click(object sender, RoutedEventArgs e)
        {
            if (User)
            {
                PublicSummoner summoner = await RiotCalls.GetSummonerByName(Command.Text);

                if (string.IsNullOrWhiteSpace(summoner.Name))
                {
                    var overlay = new MessageOverlay
                    {
                        MessageTitle   = { Content = "No Summoner Found" },
                        MessageTextBox = { Text = "The summoner \"" + Command.Text + "\" does not exist." }
                    };
                    Client.OverlayContainer.Content    = overlay.Content;
                    Client.OverlayContainer.Visibility = Visibility.Visible;

                    return;
                }
                HintLabel.Content    = "retrieving replay";
                HintLabel.Visibility = Visibility.Visible;
                var fadeLabelInAnimationx = new DoubleAnimation(1, TimeSpan.FromSeconds(0.1));
                HintLabel.BeginAnimation(OpacityProperty, fadeLabelInAnimationx);
                PlatformGameLifecycleDTO n = await RiotCalls.RetrieveInProgressSpectatorGameInfo(Command.Text);

                if (n == null)
                {
                    var overlay = new MessageOverlay
                    {
                        MessageTitle   = { Content = "No Game Found" },
                        MessageTextBox = { Text = "The summoner \"" + Command.Text + "\" is not currently in game." }
                    };
                    Client.OverlayContainer.Content    = overlay.Content;
                    Client.OverlayContainer.Visibility = Visibility.Visible;

                    return;
                }
                if (n.GameName != null)
                {
                    string ip     = n.PlayerCredentials.ObserverServerIp + ":" + n.PlayerCredentials.ObserverServerPort;
                    string key    = n.PlayerCredentials.ObserverEncryptionKey;
                    var    gameId = (int)n.PlayerCredentials.GameId;
                    recorder = new ReplayRecorder(ip, gameId, Client.Region.InternalName, key);
                    recorder.OnReplayRecorded += recorder_OnReplayRecorded;
                    recorder.OnGotChunk       += recorder_OnGotChunk;

                    var fadeGridOutAnimation = new DoubleAnimation(0, TimeSpan.FromSeconds(0.1));
                    Command.Visibility   = Visibility.Hidden;
                    Download.Visibility  = Visibility.Hidden;
                    HintLabel.Visibility = Visibility.Visible;
                    HintLabel.Content    = "Starting replay download";
                }
                HintLabel.Content    = "That player is not in a game";
                HintLabel.Visibility = Visibility.Visible;
            }
        }
예제 #9
0
        private async void Download_Click(object sender, RoutedEventArgs e)
        {
            if (User == true)
            {
                PublicSummoner Summoner = await Client.PVPNet.GetSummonerByName(Command.Text);

                if (String.IsNullOrWhiteSpace(Summoner.Name))
                {
                    MessageOverlay overlay = new MessageOverlay();
                    overlay.MessageTitle.Content       = "No Summoner Found";
                    overlay.MessageTextBox.Text        = "The summoner \"" + Command.Text + "\" does not exist.";
                    Client.OverlayContainer.Content    = overlay.Content;
                    Client.OverlayContainer.Visibility = Visibility.Visible;
                    return;
                }
                HintLabel.Content    = "retrieving replay";
                HintLabel.Visibility = Visibility.Visible;
                var fadeLabelInAnimationx = new DoubleAnimation(1, TimeSpan.FromSeconds(0.1));
                HintLabel.BeginAnimation(Label.OpacityProperty, fadeLabelInAnimationx);
                PlatformGameLifecycleDTO n = await Client.PVPNet.RetrieveInProgressSpectatorGameInfo(Command.Text);

                if (n.GameName != null)
                {
                    int    port = n.PlayerCredentials.ServerPort;
                    string IP;
                    if (port == 0)
                    {
                        IP = n.PlayerCredentials.ObserverServerIp + ":8088";
                    }
                    else
                    {
                        IP = n.PlayerCredentials.ObserverServerIp + ":" + port;
                    }
                    string Key    = n.PlayerCredentials.ObserverEncryptionKey;
                    int    GameID = (Int32)n.PlayerCredentials.GameId;
                    recorder = new ReplayRecorder(IP, GameID, Client.Region.InternalName, Key);
                    recorder.OnReplayRecorded += recorder_OnReplayRecorded;
                    recorder.OnGotChunk       += recorder_OnGotChunk;

                    var fadeGridOutAnimation = new DoubleAnimation(0, TimeSpan.FromSeconds(0.1));
                    Command.Visibility   = Visibility.Hidden;
                    Download.Visibility  = Visibility.Hidden;
                    HintLabel.Visibility = Visibility.Visible;
                    HintLabel.Content    = "Starting replay download";
                    return;
                }
                else
                {
                    HintLabel.Content    = "That player is not in a game";
                    HintLabel.Visibility = Visibility.Visible;
                    return;
                }
            }
        }
예제 #10
0
 private void OnRecordStarted(ReplayRecorder replayRecorder)
 {
     Debug.Log("OnRecordStarted");
     _replayRecorder       = replayRecorder;
     playBtn.interactable  = false;
     pauseBtn.interactable = false;
     stopBtn.gameObject.SetActive(true);
     recordBtn.gameObject.SetActive(false);
     backBtn.interactable    = false;
     forwardBtn.interactable = false;
     liveBtn.interactable    = false;
     status.SetActive(true);
     statusIconRecord.gameObject.SetActive(true);
     statusIconPlay.gameObject.SetActive(false);
     statusIconPause.gameObject.SetActive(false);
     fileStatus.text = $"Record File to: {ReplayFileHandler.CurrentReplayFileName} with Compressionmethod: {ReplayManager.Instance.replayDeltaMode} at every {ReplayManager.Instance.snapshotAtFrame} Frame.";
 }
예제 #11
0
        public void MeleeAct()
        {
            ReplayRecorder recorder = new ReplayRecorder();

            recorder.RecordStartFrame(this);
            foreach (var item in Map.Army.ToArray())
            {
                if (item.HP <= 0)
                {
                    continue;
                }
                if (item is MeleeArmyBase melee)
                {
                    melee.MeleeMove(Map);
                }
            }
            recorder.RecordEndFrame(this);
            ReplayOrganizer.AddFrame(recorder);
        }
예제 #12
0
        private void Download_Click(object sender, RoutedEventArgs e)
        {
            HintLabel.Content    = "retrieving replay";
            HintLabel.Visibility = Visibility.Visible;
            var fadeLabelInAnimation = new DoubleAnimation(1, TimeSpan.FromSeconds(0.1));

            HintLabel.BeginAnimation(Label.OpacityProperty, fadeLabelInAnimation);

            string SpectatorCommand = Command.Text;

            string[] RemoveExcessInfo = SpectatorCommand.Split(new string[1] {
                "spectator "
            }, StringSplitOptions.None);

            if (RemoveExcessInfo.Length != 2)
            {
                HintLabel.Content    = "invalid command";
                HintLabel.Visibility = Visibility.Visible;
                return;
            }

            string[] Info = RemoveExcessInfo[1].Replace("\"", "").Split(' ');

            if (Info.Length != 4)
            {
                HintLabel.Content    = "invalid command";
                HintLabel.Visibility = Visibility.Visible;
                return;
            }

            Command.Text = "";

            int GameId = Convert.ToInt32(Info[2]);

            recorder = new ReplayRecorder(Info[0], GameId, Info[3], Info[1]);
            recorder.OnReplayRecorded += recorder_OnReplayRecorded;
            recorder.OnGotChunk       += recorder_OnGotChunk;

            var fadeGridOutAnimation = new DoubleAnimation(0, TimeSpan.FromSeconds(0.1));

            Command.Visibility  = Visibility.Hidden;
            Download.Visibility = Visibility.Hidden;
        }
예제 #13
0
        public static async Task <int> ReplayMain(Program.ReplayOptions options)
        {
            if (options.WorkDir == null || options.Archive == null || options.Output == null)
            {
                return(1);
            }

            var launcher = Launcher.DetectLauncher();

            return(await BuildManager.RunBuild(
                       launcher,
                       createRecorder : () => ReplayRecorder.Create(
                           archiveFile: options.Archive,
                           workDir: options.WorkDir
                           ),
                       outputDir : options.Output,
                       workDir : options.WorkDir
                       ));
        }
예제 #14
0
        public void MapAct()
        {
            ReplayRecorder recorder = new ReplayRecorder();

            recorder.RecordStartFrame(this);
            foreach (var item in Map.Army)
            {
                item.BreakMove(Map);
                if (item.PosY == Players[0].BasePosY && item.Owner == Players[1])
                {
                    Players[0].Base -= item.BreakingPower;
                }
                if (item.PosY == Players[1].BasePosY && item.Owner == Players[0])
                {
                    Players[1].Base -= item.BreakingPower;
                }
            }
            recorder.RecordEndFrame(this);
            ReplayOrganizer.AddFrame(recorder);
        }
예제 #15
0
 public void SendToAllBut(BinaryWriter packet, Player except, Player except2)
 {
     foreach (Player player in Players)
     {
         if (player != null && !player.Equals(except) && !player.Equals(except2))
         {
             player.Send(packet);
         }
     }
     foreach (Player player in Observers)
     {
         if (!player.Equals(except) && !player.Equals(except2))
         {
             player.Send(packet);
         }
     }
     if (ReplayRecorder != null && !ReplayRecorder.Equals(except) && !ReplayRecorder.Equals(except2))
     {
         SendToReplayRecorder(packet);
     }
 }
예제 #16
0
        private async Task TestReplayRecorderOnNewStore(ReplayRecorder <MyAppState1> recorder, MyAppState1 finalStateOfFirstStore)
        {
            var t = Log.MethodEntered("TestReplayRecorderOnNewStore");

            // Connect the recorder to the new store:
            var recMiddleware = recorder.CreateMiddleware();
            var undoable      = new UndoRedoReducer <MyAppState1>();
            var logging       = Middlewares.NewLoggingMiddleware <MyAppState1>();

            var data2  = new MyAppState1(null, null, 0);
            var store2 = new DataStore <MyAppState1>(undoable.Wrap(MyReducers1.ReduceMyAppState1), data2, logging, recMiddleware);

            store2.storeName = "Store 2";

            // Replaying the recorder will now fill the second store with the same actions:
            await recorder.ReplayStore();

            AssertEqualJson(finalStateOfFirstStore, store2.GetState());

            Log.MethodDone(t);
        }
예제 #17
0
        private void RecordButton_Click(object sender, RoutedEventArgs e)
        {
            object objectGame    = gameList[SelectedGame];
            var    SpectatorGame = objectGame as Dictionary <string, object>;
            string key           = "";
            int    gameId        = 0;
            string platformId    = "";

            foreach (var pair in SpectatorGame)
            {
                if (pair.Key == "gameId")
                {
                    gameId = (int)pair.Value;
                }
                if (pair.Key == "observers")
                {
                    var keyArray = pair.Value as Dictionary <string, object>;
                    foreach (var keyArrayPair in keyArray)
                    {
                        if (keyArrayPair.Key == "encryptionKey")
                        {
                            key = keyArrayPair.Value as string;
                        }
                    }
                }
                if (pair.Key == "platformId")
                {
                    platformId = pair.Value as string;
                }
            }

            BaseRegion region = BaseRegion.GetRegion((string)SpectatorComboBox.SelectedValue);
            //region.SpectatorIpAddress, key, gameId, platformId
            var recorder = new ReplayRecorder(region.SpectatorIpAddress, gameId, platformId, key);

            recorder.OnReplayRecorded += () => { curentlyRecording.Remove(gameId); };
            curentlyRecording.Add(gameId);
            RecordButton.IsEnabled = false;
            RecordButton.Content   = "Recording...";
        }
예제 #18
0
        public ReplayController(GameFixedUpdate gameFixedUpdate, ChecksumProvider checksumProvider, ReplayView recorderView, Commands commands, Replay replay)
        {
            _recording = true;

            _checksumProvider = checksumProvider;

            _replay = replay;

//			_replay = new ReplayBase (checksumProvider);

            _gameFixedUpdate = gameFixedUpdate;
            _recorderView    = recorderView;
            _commands        = commands;

            if (_recorderView != null)
            {
                _recorderView.SetReplay(this);
            }

            _replayRecorder = new ReplayRecorder(_replay, _commands);
            _replayPlayer   = new ReplayPlayer(_replay, _commands);
        }
예제 #19
0
        private async Task TestReplayRecorder(ReplayRecorder <MyAppState1> recorder, IDataStore <MyAppState1> store)
        {
            var t = Log.MethodEntered("TestReplayRecorder");

            // First remember the final state of the store:
            var finalState = store.GetState();

            // Then reset the store so that it is in its initial state again:
            recorder.ResetStore();
            Assert.Null(store.GetState().user);
            Assert.Null(store.GetState().currentWeather);

            // Calling ReplayStore will replay all actions stored by the recorder so that the final state is restored:
            await recorder.ReplayStore();

            Assert.NotEqual(0, recorder.recordedActionsCount);
            AssertEqualJson(finalState, store.GetState());

            // The recorder middleware can also replay the actions into a second store:
            await TestReplayRecorderOnNewStore(recorder, finalState);

            Log.MethodDone(t);
        }
예제 #20
0
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                recorder.Dispose();
                recorder = null;
                ReplayRecording.Dispose();
                ReplayRecording = null;
                RecordGui.Dispose();
                RecordGui = null;

                // Free any other managed objects here.
                //
            }

            // Free any unmanaged objects here.
            //
            disposed = true;
        }
예제 #21
0
        public async Task TestReplayRecorder()
        {
            // Add a recorder middleware to enable hot reload by replaying previously recorded actions:
            var recorder      = new ReplayRecorder <string>();
            var recMiddleware = recorder.CreateMiddleware();
            // Test that exceptions are thrown if ReplayStore is not yet ready to use:
            await Assert.ThrowsAsync <NullReferenceException>(async() => { await recorder.ReplayStore(); });

            var store = new DataStore <string>(StateReducer, "", recMiddleware);
            await recorder.ReplayStore(); // Does nothing but does not throw an exception

            // Test that exceptions are thrown if an invalid nrOfActionsToReplay is passed into ReplayStore():
            await Assert.ThrowsAsync <ArgumentException>(async() => {
                await recorder.ReplayStore(delayBetweenStepsInMs: 0, nrOfActionsToReplay: 1);
            });

            // Test that Replay does not change the recorder.recordedActionsCount:
            Assert.Equal(0, recorder.recordedActionsCount);
            store.Dispatch("1");                            // Dispatch a first event
            Assert.Equal(1, recorder.recordedActionsCount); // Now the count must be 1
            await recorder.ReplayStore();

            Assert.Equal(1, recorder.recordedActionsCount); // Recorded actions still 1 after replay
        }
예제 #22
0
 private void Awake()
 {
     instance = this;
 }