Beispiel #1
0
        public override void Entry(IModHelper helper)
        {
            //Setup Montior
            new SplitScreen.Monitor(Monitor);

            //Get player index if it is set in launch options, e.g. StardewModdingAPI.exe --log-path "third.txt" --player-index 3
            this.playerIndexController = new PlayerIndexController(Environment.GetCommandLineArgs());

            //Stardew Valley uses this as the target controller for rumble(and nothing else it seems)
            Game1.playerOneIndex = PlayerIndexController._PlayerIndex.GetValueOrDefault();

            //Removes FPS throttle when window inactive
            Game1.game1.InactiveSleepTime = new TimeSpan(0);

            var harmony = HarmonyInstance.Create("me.ilyaki.splitscreen");

            harmony.PatchAll(Assembly.GetExecutingAssembly());


            Helper.Events.Input.ButtonPressed += InputEvents_ButtonPressed;


            Helper.Events.GameLoop.UpdateTicked += delegate { Game1.game1.SetPrivateFieldValue("isActive", true); };            //only do when in-game?

            //Keyboards/Mice Managers
            kbManager = new Keyboards.MultipleKeyboardManager(harmony);
            Helper.Events.GameLoop.UpdateTicked += kbManager.OnUpdate;

            Helper.Events.GameLoop.ReturnedToTitle += kbManager.OnAfterReturnToTitle;

            miceManager = new Mice.MultipleMiceManager();

            Helper.Events.Specialized.UnvalidatedUpdateTicked += miceManager.OnUpdateTick;
            Helper.Events.GameLoop.ReturnedToTitle            += miceManager.OnAfterReturnToTitle;

            //Set the affinity for all SMAPI processes. Adjustments are handled by AffinityButtonMenu
            var processes      = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
            int processorCount = Environment.ProcessorCount;

            for (int i = 0; i < processes.Count(); i++)
            {
                int designatedCPU = i % processorCount;
                designatedCPU = processorCount - designatedCPU - 1;                //Start backwards (Use the last core for the first instance)
                try { processes[i].ProcessorAffinity = (IntPtr)(1 << designatedCPU); }
                catch (Exception e) { Monitor.Log($"Could not set affinity for {i}: {e.ToString()}", LogLevel.Debug); }
            }

            //Load the config
            this.config = Helper.ReadConfig <ModConfig>();
            if (!Enum.TryParse(this.config.MenuKey, out menuKey))
            {
                menuKey = Keys.N;
            }
        }
Beispiel #2
0
 public static GamePadState Postfix(GamePadState g, PlayerIndex playerIndex, GamePadState __result)
 {
     if (playerIndex.Equals(PlayerIndex.One) && PlayerIndexController.Index != PlayerIndex.One)
     {
         return(PlayerIndexController.GetGamepadState());
     }
     else
     {
         return(__result);
     }
 }
Beispiel #3
0
 private void ChangedButtonClicked(UIMouseEvent evt, UIElement listeningElement)
 {
     Terraria.Main.PlaySound(10);
     PlayerIndexController.IncrementPlayerIndex();
     Monitor.Log($"Switched player index to {PlayerIndexController.Index?.ToString() ?? "NONE"}");
 }