Example #1
0
 private bool InputManager_GetControlStatus(On.InputManager.orig_GetControlStatus orig, InputManager self, Control control, ControlStatus controlStatus)
 {
     if (HasFlag(State.Playing) && !HasFlag(State.Pausing))
     {
         return(TASInputPlayer.GetControlStatus(control, controlStatus));
     }
     return(orig(self, control, controlStatus));
 }
 public static void Update_MouseEvents(InputManager self)
 {
     DynData<InputManager> d = new DynData<InputManager>(self);
     List<ClickDownInfo> leftClickInfos = d.Get<List<ClickDownInfo>>("leftClickInfos");
     List<ClickDownInfo> rightClickInfos = d.Get<List<ClickDownInfo>>("rightClickInfos");
     List<ClickDownInfo> middleClickInfos = d.Get<List<ClickDownInfo>>("middleClickInfos");
     if (!AgeManager.IsMouseCovered)
     {
         if (TASInputPlayer.GetMouseButtonDown(0))
         {
             TriggerClickDownEvent(self, "OnLeftClickDown", ref leftClickInfos);
         }
         if (TASInputPlayer.GetMouseButtonDown(1))
         {
             TriggerClickDownEvent(self, "OnRightClickDown", ref rightClickInfos);
         }
         if (TASInputPlayer.GetMouseButtonDown(2))
         {
             TriggerClickDownEvent(self, "OnMiddleClickDown", ref middleClickInfos);
         }
         // TODO MAYBE ADD MOUSEWHEEL?
     }
     if (TASInputPlayer.GetMouseButtonUp(0) && leftClickInfos != null)
     {
         TriggerClickUpEvent(self, "OnLeftClickUp", ref leftClickInfos);
     }
     if (TASInputPlayer.GetMouseButtonUp(1) && rightClickInfos != null)
     {
         TriggerClickUpEvent(self, "OnRightClickUp", ref rightClickInfos);
     }
     if (TASInputPlayer.GetMouseButtonUp(2) && middleClickInfos != null)
     {
         TriggerClickUpEvent(self, "OnMiddleClickUp", ref middleClickInfos);
     }
     d.Set("leftClickInfos", leftClickInfos);
     d.Set("rightClickInfos", rightClickInfos);
     d.Set("middleClickInfos", middleClickInfos);
 }
 public static void TriggerClickDownEvent(InputManager self, string eventName, ref List<ClickDownInfo> clickInfosContainer)
 {
     DynData<InputManager> d = new DynData<InputManager>(self);
     d.Set<bool>("stopClickEventPropagation", false);
     LayerMask mask = (!d.Get<IGameCameraService>("gameCameraManager").IsTacticalMapActive()) ? d.Get<LayerMask>("gameMouseClickLayerMask") : d.Get<LayerMask>("tacticalMapClickLayerMask");
     RaycastHit[] array = Physics.RaycastAll(d.Get<IGameCameraService>("gameCameraManager").ScreenPointToRay(TASInputPlayer.GetMousePos()), float.PositiveInfinity, mask);
     Array.Sort<RaycastHit>(array, (RaycastHit hitInfo1, RaycastHit hitInfo2) => hitInfo1.distance.CompareTo(hitInfo2.distance));
     if (d.Get<bool>("debug"))
     {
         Diagnostics.LogWarning(string.Concat(new object[]
         {
         eventName,
         " > ",
         array.Length,
         " hits"
         }), new object[0]);
     }
     clickInfosContainer = new List<ClickDownInfo>();
     int num = 0;
     foreach (RaycastHit raycastHit in array)
     {
         ClickDownInfo item = new ClickDownInfo(raycastHit.collider, raycastHit.point, num, array.Length);
         clickInfosContainer.Add(item);
     }
     foreach (ClickDownInfo clickDownInfo in clickInfosContainer)
     {
         if (d.Get<bool>("debug"))
         {
             Diagnostics.Log(string.Concat(new object[]
             {
             eventName,
             "@",
             num,
             "=",
             clickDownInfo.HitCollider.name,
             " @",
             clickDownInfo.WorldPosition
             }), new object[0]);
         }
         clickDownInfo.HitCollider.SendMessage(eventName, clickDownInfo, SendMessageOptions.DontRequireReceiver);
         num++;
         if (d.Get<bool>("stopClickEventPropagation"))
         {
             break;
         }
     }
 }
Example #4
0
        private void InputManager_Update(On.InputManager.orig_Update orig, InputManager self)
        {
            // Do the recording, pausing, resetting, and playing here.
            // Updates the state
            UpdateState();
            // Performs an action depending on the state
            if (SingletonManager.Get <Dungeon>(false) == null)
            {
                // We don't have a Dungeon to work with yet!
                // This should be removed soon and instead of having levels, have time stamps or something else.
                // That would allow for TAS in menus (without a Dungeon)
                orig(self);
                return;
            }
            int level = SingletonManager.Get <Dungeon>(false).Level;

            if (HasFlag(State.Pausing))
            {
                // Need to find some way of doing standard processing except for actually updating the game
            }
            if (HasFlag(State.Playing) && !HasFlag(State.Pausing))
            {
                // Read Inputs from file/RAM and perform them
                if (TASInput.HasNext(level))
                {
                    TASInputPlayer.Update(TASInput.GetNext(level));
                    mod.Log("Playing input: " + TASInputPlayer.Current);
                }
                else
                {
                    mod.Log("Completed input playback!");
                    ToggleState(State.Playing);
                }
            }
            if (HasFlag(State.Recording))
            {
                // Read Inputs from real action into file/RAM
                // Assumes the current level exists.
                TASInput.CreateAndAdd(level);
                // Also make sure that the seed is correctly set
                mod.Log("Recording input: " + TASInput.inputs[level][TASInput.inputs[level].Count - 1].ToString());
                // TODO: REMOVE LINE BELOW
                ToggleState(State.Recording);
            }
            if (HasFlag(State.Saving))
            {
                // Save the current floor as a start point (somehow)
                // Probably just save the SeedData and do a "generateForLevel" or something
                SaveKey = GameSave.GenerateSaveKey();
                SingletonManager.Get <Dungeon>(false).SaveGameData(SaveKey);
                mod.Log("Saved Key: " + SaveKey + " saved successfully!");
                ToggleState(State.Saving);
            }
            if (HasFlag(State.SavingToFile))
            {
                // Assume the Dungeon exists, use it to determine the level to write the TAS for.
                mod.Log("Writing files with *" + tasFileExtensionWrapper.Value);
                TASIO.WriteTAS(TASInput.inputs, tasFileExtensionWrapper.Value);
                ToggleState(State.SavingToFile);
            }
            if (HasFlag(State.ReadingFromFiles))
            {
                // Don't assume that the Dungeon exists, but read the many information things from the TAS file.
                // The trick with this is that the seed also needs to be read.
                TASInput.Clear();
                mod.Log("Reading from *" + tasFileExtensionWrapper.Value + " files...");
                foreach (string file in System.IO.Directory.GetFiles(".", "*" + tasFileExtensionWrapper.Value))
                {
                    // Let's just load all of the info into the TASInput RAM
                    mod.Log("Reading file: " + file);
                    TASIO.ReadTAS(file);
                }
                ToggleState(State.ReadingFromFiles);
            }
            if (HasFlag(State.Resetting))
            {
                // Reset to the current save point (whatever floor it is)
                // Probably just do a "generateForLevel" or something (make the game think the data was saved in a certain way)
                mod.Log("Attempting to load SaveKey: " + SaveKey);
                if (SaveKey.Length > 0)
                {
                    // Only now can we load valid data.
                    mod.Log("Preparing Dungeon for SaveKey!");
                    Dungeon.PrepareForSavedGame(SaveKey, false);
                }
                ToggleState(State.Resetting);
            }
            if (HasFlag(State.Clearing))
            {
                // Clear the data for this level
                TASInput.ClearForLevel(level);
                mod.Log("Cleared all TAS data for level: " + level);
                ToggleState(State.Clearing);
            }
            orig(self);
        }