Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //By Kryo4lex
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using GTA;
- using GTA.Native;
- using GTA.Math;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using NativeUI;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Linq;
- using XInputDotNetPure;
- public class Selective_Fire : Script
- {
- public const string version_num = "1.2";
- public const string version = "Selective Fire" + " " + version_num;
- public const string settingsFilePath = @"scripts//Selective_Fire//Selective_Fire_settings.bin";
- private UIMenu mainMenu;
- private MenuPool _menuPool;
- private UIMenuItem UIMI_FIREMODE_KEY;
- private UIMenuItem UIMI_FIREMODE_CGP;
- private UIMenuCheckboxItem UIMCBI_MOD_ENABLED;
- private UIMenuCheckboxItem UIMCBI_SafetyLock;
- private UIMenuCheckboxItem UIMCBI_FullAutoDefault;
- private UIMenuCheckboxItem UIMCBI_Semi;
- private UIMenuCheckboxItem UIMCBI_BurstRelease;
- private UIMenuCheckboxItem UIMCBI_BurstDelay;
- private UIMenuListItem UIMLI_BurstCount;
- private UIMenuListItem UIMLI_NotficationType;
- private UIMenuItem savesettings;
- [Serializable]
- public struct SF_Settings
- {
- public bool MOD_ENABLED;
- public bool SAFETY_LOCK_ENABLED;
- public bool FULL_AUTO_DEFAULT_ENABLED;
- public bool SEMI_ENABLED;
- public bool BURST_RELEASE_ENABLED;
- public bool BURST_DELAY_ENABLED;
- public int N_BURST;
- public List<Keys> KEYS_FIRING_MODE_SWITCH;
- public int CGP_FIRING_MODE_SWITCH;
- public int NOTIFICATION_TYPE;
- }
- private SF_Settings settings = new SF_Settings();
- private List<dynamic> burstShots
- {
- get; set;
- }
- private List<dynamic> notificationTypes
- {
- get; set;
- }
- public Selective_Fire()
- {
- if (!File.Exists(settingsFilePath))
- {
- settings.MOD_ENABLED = true;
- settings.SAFETY_LOCK_ENABLED = true;
- settings.FULL_AUTO_DEFAULT_ENABLED = true;
- settings.SEMI_ENABLED = true;
- settings.BURST_RELEASE_ENABLED = true;
- settings.BURST_DELAY_ENABLED = true;
- settings.N_BURST = 3;
- settings.KEYS_FIRING_MODE_SWITCH = new List<Keys>();
- settings.KEYS_FIRING_MODE_SWITCH.Add(Keys.CapsLock);
- settings.CGP_FIRING_MODE_SWITCH = 528;
- settings.NOTIFICATION_TYPE = 0;
- }
- else
- {
- loadSettings();
- }
- this.Tick += this.OnTick;
- this.KeyDown += this.OnKeyDown;
- this.KeyUp += this.OnKeyUp;
- ControllerGamepadNames = new List<dynamic>
- {
- "A",
- "B",
- "X",
- "Y",
- "Left Shoulder",
- "Right Shoulder",
- "Left Stick",
- "Right Stick",
- "DPad Up",
- "DPad Down",
- "DPad Left",
- "DPad Right",
- "LS Up",
- "LS Down",
- "LS Right",
- "LS Left",
- "RS Up",
- "RS Down",
- "RS Right",
- "RS Left",
- };
- setupUIMenu();
- }
- private void setupUIMenu()
- {
- burstShots = new List<dynamic>
- {
- 1,
- 2,
- 3,
- 4,
- 5
- };
- notificationTypes = new List<dynamic>
- {
- "Subtitle",
- "Map Notification",
- "Help text",
- "None"
- };
- _menuPool = new MenuPool();
- mainMenu = new UIMenu(version, "~b~By Kryo4lex");
- //mainMenu.SetBannerType("scripts\\Selective_Fire\\customBanner.png");
- _menuPool.Add(mainMenu);
- UIMI_FIREMODE_KEY = new UIMenuItem("Firing mode switch keyboard: " + getStringKeys(settings.KEYS_FIRING_MODE_SWITCH), "Select the key for the firing mode switch.");
- UIMI_FIREMODE_CGP = new UIMenuItem("Firing mode switch controller: " + stringControlPattern(settings.CGP_FIRING_MODE_SWITCH), "Select the controller/gamepad controls for the firing mode switch.");
- mainMenu.AddItem(UIMCBI_MOD_ENABLED = new UIMenuCheckboxItem("Mod enabled", settings.MOD_ENABLED, "Use this to toggle the Selective Fire mod."));
- mainMenu.AddItem(UIMI_FIREMODE_KEY);
- mainMenu.AddItem(UIMI_FIREMODE_CGP);
- mainMenu.AddItem(UIMCBI_SafetyLock = new UIMenuCheckboxItem("Safety/Lock", settings.SAFETY_LOCK_ENABLED, "Check this option if you want to have the Safety/Lock firing mode available."));
- mainMenu.AddItem(UIMCBI_FullAutoDefault = new UIMenuCheckboxItem("Full auto/Default", settings.FULL_AUTO_DEFAULT_ENABLED, "Check this option if you want to have the Full auto/Default firing mode available."));
- mainMenu.AddItem(UIMCBI_Semi = new UIMenuCheckboxItem("Single fire/Semi", settings.SEMI_ENABLED, "Check this option if you want to have the Single fire/Semi firing mode available."));
- mainMenu.AddItem(UIMCBI_BurstRelease = new UIMenuCheckboxItem(settings.N_BURST.ToString() + "-Burst-release", settings.BURST_RELEASE_ENABLED, "Check this option if you want to have the Burst-release firing mode available. Release means, that you have to release the trigger to fire again."));
- mainMenu.AddItem(UIMCBI_BurstDelay = new UIMenuCheckboxItem(settings.N_BURST.ToString() + "-Burst-delay", settings.BURST_DELAY_ENABLED, "Check this option if you want to have the Burst-delay firing mode available. Delay means, that yo will shoot a burst and then it will fire again with a delay, if you keep holding the trigger."));
- mainMenu.AddItem(UIMLI_BurstCount = new UIMenuListItem("Burst-shot count:", burstShots, (settings.N_BURST-1) , "Change the count of the shots of a burst."));
- mainMenu.AddItem(UIMLI_NotficationType = new UIMenuListItem("Notification type:", notificationTypes, settings.NOTIFICATION_TYPE, "Change the way the change of the firing mode is indicated."));
- savesettings = new UIMenuItem("Save settings", "Save your settings, to play with the same settings on the next startup of the game.");
- mainMenu.AddItem(savesettings);
- mainMenu.RefreshIndex();
- mainMenu.OnItemSelect += OnItemSelect;
- mainMenu.OnCheckboxChange += OnCheckboxChange;
- mainMenu.OnListChange += OnListChange;
- }
- public void OnListChange(UIMenu sender, UIMenuListItem list, int index)
- {
- if (list == UIMLI_BurstCount)
- {
- settings.N_BURST = UIMLI_BurstCount.Index + 1;
- UIMCBI_BurstRelease.Text = settings.N_BURST.ToString() + "-Burst-release";
- UIMCBI_BurstDelay.Text = settings.N_BURST.ToString() + "-Burst-delay";
- }
- if (list == UIMLI_NotficationType)
- {
- settings.NOTIFICATION_TYPE = UIMLI_NotficationType.Index;
- }
- }
- public void OnItemSelect(UIMenu sender, UIMenuItem selectedItem, int index)
- {
- if (selectedItem == savesettings)
- {
- saveSettings();
- UI.Notify("~b~Selective Fire settings saved!");
- }
- else if (selectedItem == UIMI_FIREMODE_KEY)
- {
- ChangeKeyAssignment_active = true;
- }
- else if(selectedItem == UIMI_FIREMODE_CGP)
- {
- ChangeControllerAssignment = true;
- }
- }
- public void OnCheckboxChange(UIMenu sender, UIMenuCheckboxItem checkbox, bool Checked)
- {
- if (checkbox == UIMCBI_SafetyLock)
- {
- settings.SAFETY_LOCK_ENABLED = UIMCBI_SafetyLock.Checked;
- }
- else if(checkbox == UIMCBI_FullAutoDefault)
- {
- settings.FULL_AUTO_DEFAULT_ENABLED = UIMCBI_FullAutoDefault.Checked;
- }
- else if (checkbox == UIMCBI_Semi)
- {
- settings.SEMI_ENABLED = UIMCBI_Semi.Checked;
- }
- else if (checkbox == UIMCBI_BurstRelease)
- {
- settings.BURST_RELEASE_ENABLED = UIMCBI_BurstRelease.Checked;
- }
- else if (checkbox == UIMCBI_BurstDelay)
- {
- settings.BURST_DELAY_ENABLED = UIMCBI_BurstDelay.Checked;
- }
- else if (checkbox == UIMCBI_MOD_ENABLED)
- {
- settings.MOD_ENABLED = UIMCBI_MOD_ENABLED.Checked;
- }
- //Protect from selecting no firing mode at all
- /*
- if (!(settings.SAFETY_LOCK_ENABLED || settings.FULL_AUTO_DEFAULT_ENABLED || settings.SEMI_ENABLED || settings.BURST_RELEASE_ENABLED || settings.BURST_DELAY_ENABLED))
- {
- checkbox.
- }
- */
- }
- private string getStringKeys(List<Keys> listkeys)
- {
- string str = "";
- int i = 0;
- foreach (var key in listkeys)
- {
- str += key.ToString();
- if (i != (listkeys.Count - 1))
- {
- str += " + ";
- }
- i++;
- }
- return str;
- }
- private void saveSettings()
- {
- FileStream fs = new FileStream(settingsFilePath, FileMode.Create);
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize(fs, settings);
- fs.Close();
- }
- private void loadSettings()
- {
- FileStream fs = new FileStream(settingsFilePath, FileMode.Open);
- BinaryFormatter formatter = new BinaryFormatter();
- settings = (SF_Settings)formatter.Deserialize(fs);
- fs.Close();
- }
- private List<Keys> newKeys = new List<Keys>();
- bool ChangeKeyAssignment_active = false;
- int KeyAssignmentStepIndex = 0;
- bool s1_started = false;
- long t_s1 = 0;
- bool s2_started = false;
- long t_s2 = 0;
- private List<Keys> pressedKeys = new List<Keys>();
- bool switchBef = false;
- bool switchNow = false;
- void OnTick(object sender, EventArgs e)
- {
- if (settings.MOD_ENABLED)
- {
- processKeyboardInput();
- processControllerInput();
- featureSelectiveFire();
- if(displayHelpTextThisFrameActive)
- {
- if(displayHelpTextThisFrameActiveStartTime + 2500 >= Environment.TickCount)
- {
- DisplayHelpTextThisFrame(displayHelpTextThisFrameMessage);
- }
- else
- {
- displayHelpTextThisFrameActive = false;
- }
- }
- }
- _menuPool.ProcessMenus();
- }
- private void processKeyboardInput()
- {
- if (ChangeKeyAssignment_active)
- {
- switch (KeyAssignmentStepIndex)
- {
- case 0:
- mainMenu.Visible = false;
- UI.ShowSubtitle("~b~In 3 seconds, you have 4 seconds, to hold the new key(s), for the firing mode switch.", 3000);
- if (!s1_started)
- {
- s1_started = true;
- t_s1 = Environment.TickCount + 3000;
- }
- if (Environment.TickCount >= t_s1)
- KeyAssignmentStepIndex++;
- break;
- case 1:
- newKeys.Clear();
- newKeys = new List<Keys>(pressedKeys);
- UI.ShowSubtitle("~b~Key(s):\n" + getStringKeys(newKeys), 4000);
- if (!s2_started)
- {
- s2_started = true;
- t_s2 = Environment.TickCount + 4000;
- }
- if (Environment.TickCount >= t_s2)
- KeyAssignmentStepIndex++;
- break;
- case 2:
- s1_started = false;
- s2_started = false;
- ChangeKeyAssignment_active = false;
- KeyAssignmentStepIndex = 0;
- if (newKeys.Count != 0)
- {
- settings.KEYS_FIRING_MODE_SWITCH.Clear();
- settings.KEYS_FIRING_MODE_SWITCH = new List<Keys>(newKeys);
- UIMI_FIREMODE_KEY.Text = "Firing mode switch key: " + getStringKeys(settings.KEYS_FIRING_MODE_SWITCH);
- UI.ShowSubtitle("~b~Successfully assinged firing mode switch key to " + getStringKeys(pressedKeys), 3000);
- }
- else
- {
- UI.ShowSubtitle("~b~No key(s) have been changed!", 3000);
- }
- break;
- }
- }
- else
- {
- switchNow = LinqHelper.ContainsAll(pressedKeys, settings.KEYS_FIRING_MODE_SWITCH);
- if (switchNow && !switchBef)
- {
- if (!Game.Player.Character.IsInVehicle())
- {
- changeFiringMode();
- }
- }
- switchBef = switchNow;
- }
- }
- //used to count the shots for bursts
- int shotCounter = 0;
- //number of desired shots fired with a burst
- //int n_burst = 3;
- //used to count shots --> edge detection
- bool shots_bef = false;
- //fire delay in ms for 4th firing mode (n-burst delay)
- long fireDelay = 500;
- long lastFire = 0;
- private void featureSelectiveFire()
- {
- if (!Game.Player.Character.IsInVehicle())
- {
- //edge detection to count shots
- if (Game.Player.Character.IsShooting && shots_bef == false)
- {
- shotCounter++;
- }
- shots_bef = Game.Player.Character.IsShooting;
- bugfixes();
- switch (firingMode)
- {
- case 0://lock weapon
- disableAttack();
- break;
- case 1://everything is enabled, like default
- break;
- case 2://single fire
- //if 1 shot has been fired, suppress (disable) the fire key
- if (shotCounter >= 1)
- {
- disableAttack();
- }
- //if the suppressed fire key (=disabled control) is pressed, re-enable it and reset the shot counter
- if (Game.IsDisabledControlJustPressed(0, GTA.Control.Attack))
- {
- Game.EnableControlThisFrame(0, GTA.Control.Attack);
- shotCounter = 0;
- }
- break;
- case 3://burst fire release
- //same as case 1, but only effective if it counts 3 shotCounter = burst
- //necesssary to release the fire key
- if (shotCounter >= settings.N_BURST)
- {
- disableAttack();
- }
- //this code branch part simulates the trigger,
- //even if the player did bot hit the key.
- //Without that code, the weapon would only fire while the player pressed the trigger,
- //but not automatically 3 times (with n_burst = 3), if he only pressed it once
- else
- {
- if (Game.IsControlPressed(0, GTA.Control.Attack))
- {
- Game.SetControlNormal(0, GTA.Control.Attack, 1.0f);
- }
- }
- if (Game.IsDisabledControlJustPressed(0, GTA.Control.Attack))
- {
- Game.EnableControlThisFrame(0, GTA.Control.Attack);
- shotCounter = 0;
- }
- break;
- case 4://burst fire delay
- //same as case 3, but no need to release the fire key
- if (shotCounter >= settings.N_BURST)
- {
- lastFire = Environment.TickCount;
- shotCounter = 0;
- }
- //this code branch part simulates the trigger,
- //even if the player did bot hit the key.
- //Without that code, the weapon would only fire while the player pressed the trigger,
- //but not automatically 3 times (with n_burst = 3), if he only pressed it once
- else
- {
- if(lastFire + fireDelay >= Environment.TickCount)
- {
- disableAttack();
- break;
- }
- if (Game.IsControlPressed(0, GTA.Control.Attack))
- {
- Game.SetControlNormal(0, GTA.Control.Attack, 1.0f);
- }
- }
- break;
- default:
- break;
- }
- }
- }
- //suppress fire key
- void disableAttack()
- {
- Game.DisableControlThisFrame(0, GTA.Control.Attack);
- Game.DisableControlThisFrame(0, GTA.Control.Attack2);
- }
- Weapon playerWeapon;
- void bugfixes()
- {
- //shooting after weapon switch
- if (Game.Player.Character.Weapons.Current != playerWeapon)
- {
- shotCounter = settings.N_BURST;
- }
- playerWeapon = Game.Player.Character.Weapons.Current;
- //Check if the wepaon itself exists, for example when you climb and etc., there would be this bug where it continues shooting after interrupted
- //Don't use Game.Player.Character.Weapons.CurrentWeaponObject.Exists() --> Null Reference Exception, and try catch is inefficient
- if (Game.Player.Character.Weapons.CurrentWeaponObject == null)
- {
- //no weapon object in the memory (=not existing in game) --> reset shotCounter
- shotCounter = settings.N_BURST;
- //UI.ShowSubtitle("WEAP NO MEM",100);
- }
- else
- {
- if (Game.Player.Character.Weapons.CurrentWeaponObject.Exists())
- {
- //the weapon object exists in the game so do nothing --> player isn't climbing etc. ...
- //UI.ShowSubtitle("WEAP USED",100);
- }
- else
- {
- //the weapon object exists in the memory, but not in the game --> weapon put away --> reset shotCounter
- shotCounter = settings.N_BURST;
- //UI.ShowSubtitle("WEAP PUT AWAY",100);
- }
- }
- //shooting when ragdoll --> ragdoll occurs when shooting is interrupted
- if (Game.Player.Character.IsRagdoll)
- {
- shotCounter = settings.N_BURST;
- }
- //is in air, like jumping
- if (Game.Player.Character.IsInAir)
- {
- shotCounter = settings.N_BURST;
- }
- //if the player pressed the cover control, imagine that you shoot with burst, then go into cover, and and then it continus firing
- if (Game.IsControlJustPressed(0, GTA.Control.Cover))
- {
- shotCounter = settings.N_BURST;
- }
- //shooting after reloading
- if (Game.Player.Character.IsReloading)
- {
- shotCounter = settings.N_BURST;
- }
- }
- int firingMode = 1;
- int MenuToggleStep = 0;
- private void OnKeyDown(object sender, KeyEventArgs e)
- {
- if (!(pressedKeys.Contains(e.KeyCode)))
- pressedKeys.Add(e.KeyCode);
- /*
- //change fire mode with x key
- if (e.KeyCode == Keys.CapsLock)
- {
- if (!Game.Player.Character.IsInVehicle())
- {
- changeFiringMode();
- Audio.PlaySoundFrontend("TOGGLE_ON", "HUD_FRONTEND_DEFAULT_SOUNDSET");
- }
- }
- */
- /*
- if (e.KeyCode == Keys.X)
- {
- mainMenu.Visible = !mainMenu.Visible;
- }
- */
- if (e.KeyCode == Keys.F && MenuToggleStep == 0)
- {
- MenuToggleStep++;
- }
- else if (e.KeyCode == Keys.I && MenuToggleStep == 1)
- {
- MenuToggleStep++;
- }
- else if (e.KeyCode == Keys.R && MenuToggleStep == 2)
- {
- MenuToggleStep++;
- }
- else if (e.KeyCode == Keys.E && MenuToggleStep == 3)
- {
- MenuToggleStep++;
- }
- else if (e.KeyCode == Keys.M && MenuToggleStep == 4)
- {
- mainMenu.Visible = !mainMenu.Visible;
- MenuToggleStep = 0;
- }
- else
- {
- MenuToggleStep = 0;
- }
- }
- private void OnKeyUp(object sender, KeyEventArgs e)
- {
- pressedKeys.Remove(e.KeyCode);
- //printPressedKeys(pressedKeys);
- }
- //change fire mode and show current fire mode
- void changeFiringMode()
- {
- //firingMode++;
- bool[] boolFiringModes = { settings.SAFETY_LOCK_ENABLED, settings.FULL_AUTO_DEFAULT_ENABLED, settings.SEMI_ENABLED, settings.BURST_RELEASE_ENABLED, settings.BURST_DELAY_ENABLED };
- int i = firingMode;
- int j = 0;
- while(j<=5)
- {
- i++;
- j++;
- if (i >= 5)
- {
- i = 0;
- }
- if(boolFiringModes[i]==true)
- {
- firingMode = i;
- break;
- }
- }
- /*
- if (firingMode >= 5)
- {
- firingMode = 0;
- }
- */
- switch (firingMode)
- {
- case 0:
- changeFiringModeMessage("Safety/Lock");
- break;
- case 1:
- changeFiringModeMessage("Firing mode: Full Auto (Default)");
- break;
- case 2:
- changeFiringModeMessage("Firing mode: Semi (Single Fire)");
- break;
- case 3:
- changeFiringModeMessage("Firing mode: " + settings.N_BURST.ToString() + "-Burst Release");
- break;
- case 4:
- changeFiringModeMessage("Firing mode: " + settings.N_BURST.ToString() + "-Burst Delay");
- break;
- default:
- break;
- }
- Audio.PlaySoundFrontend("TOGGLE_ON", "HUD_FRONTEND_DEFAULT_SOUNDSET");
- }
- int notificationHandle;
- bool displayHelpTextThisFrameActive = false;
- long displayHelpTextThisFrameActiveStartTime = 0;
- string displayHelpTextThisFrameMessage;
- void changeFiringModeMessage(string message)
- {
- if(settings.NOTIFICATION_TYPE == 0)//Subtitle
- {
- UI.ShowSubtitle(message);
- }
- else if(settings.NOTIFICATION_TYPE == 1)// Map notification
- {
- Function.Call(Hash._REMOVE_NOTIFICATION, new InputArgument[] { notificationHandle });
- notificationHandle = ShowNotification(message);
- }
- else if (settings.NOTIFICATION_TYPE == 2)//Help text
- {
- displayHelpTextThisFrameActive = true;
- displayHelpTextThisFrameActiveStartTime = Environment.TickCount;
- displayHelpTextThisFrameMessage = message;
- }
- else if (settings.NOTIFICATION_TYPE == 3)//None
- {
- }
- }
- public int ShowNotification(string message)
- {
- Function.Call(Hash._SET_NOTIFICATION_TEXT_ENTRY, new InputArgument[] { "STRING" });
- Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, new InputArgument[] { message });
- int haNotificationDeletitionLastTimee = Function.Call<int>(Hash._DRAW_NOTIFICATION, new InputArgument[] { false, false });
- return haNotificationDeletitionLastTimee;
- }
- void DisplayHelpTextThisFrame(string text)
- {
- Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
- Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
- Function.Call(Hash._0x238FFE5C7B0498A6, 0, 0, 1, -1);
- }
- #region Controller/GamePad Input
- public void setBit(ref int value, int index)
- {
- value = (value | (1 << index));
- }
- bool isBitSet(int value, int index)
- {
- return (value & (1 << index)) != 0;
- }
- int createControlPattern()
- {
- int controlpattern = 0;
- GamePadState state = GamePad.GetState(PlayerIndex.One);
- //A
- if (state.Buttons.A == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 0);
- }
- //B
- if (state.Buttons.B == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 1);
- }
- //X
- if (state.Buttons.X == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 2);
- }
- //Y
- if (state.Buttons.Y == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 3);
- }
- //Left Shoulder
- if (state.Buttons.LeftShoulder == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 4);
- }
- //Right Shoulder
- if (state.Buttons.RightShoulder == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 5);
- }
- //Left Stick
- if (state.Buttons.LeftStick == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 6);
- }
- //Right Stick
- if (state.Buttons.RightStick == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 7);
- }
- //DPad Up
- if (state.DPad.Up == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 8);
- }
- //DPad Down
- if (state.DPad.Down == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 9);
- }
- //DPad Left
- if (state.DPad.Left == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 10);
- }
- //DPad Right
- if (state.DPad.Right == XInputDotNetPure.ButtonState.Pressed)
- {
- setBit(ref controlpattern, 11);
- }
- //LS Up
- if (state.ThumbSticks.Left.Y >= 0.5)
- {
- setBit(ref controlpattern, 12);
- }
- //LS Down
- if (state.ThumbSticks.Left.Y <= -0.5)
- {
- setBit(ref controlpattern, 13);
- }
- //LS Right
- if (state.ThumbSticks.Left.X >= 0.5)
- {
- setBit(ref controlpattern, 14);
- }
- //LS Left
- if (state.ThumbSticks.Left.X <= -0.5)
- {
- setBit(ref controlpattern, 15);
- }
- //RS Up
- if (state.ThumbSticks.Right.Y >= 0.5)
- {
- setBit(ref controlpattern, 16);
- }
- //RS Down
- if (state.ThumbSticks.Right.Y <= -0.5)
- {
- setBit(ref controlpattern, 17);
- }
- //RS Right
- if (state.ThumbSticks.Right.X >= 0.5)
- {
- setBit(ref controlpattern, 18);
- }
- //RS Left
- if (state.ThumbSticks.Right.X <= -0.5)
- {
- setBit(ref controlpattern, 19);
- }
- return controlpattern;
- }
- private List<dynamic> ControllerGamepadNames
- {
- get; set;
- }
- string stringControlPattern(int value)
- {
- string s = "";
- for (int i = 0; i < ControllerGamepadNames.Count; i++)
- {
- if (isBitSet(value, i))
- s += ControllerGamepadNames[i] + "+";
- }
- if (s.Length > 1)
- s = s.Remove(s.Length - 1);
- return s;
- }
- int change_cgp_control_idx = 0;
- int newcontrols = 0;
- bool state_CGP_FIRING_MODE_SWITCH = false;
- bool state_CGP_FIRING_MODE_SWITCH_bef = false;
- bool ChangeControllerAssignment = false;
- void processControllerInput()
- {
- int currentcontrolpattern = createControlPattern();
- state_CGP_FIRING_MODE_SWITCH = (currentcontrolpattern & settings.CGP_FIRING_MODE_SWITCH) == settings.CGP_FIRING_MODE_SWITCH;
- if (ChangeControllerAssignment)
- {
- switch (change_cgp_control_idx)
- {
- case 0:
- UI.ShowSubtitle("~b~In 3 seconds, you have 4 seconds, to hold the control(s), for the firing mode switch.", 3000);
- if (!s1_started)
- {
- s1_started = true;
- t_s1 = Environment.TickCount + 3000;
- }
- if (Environment.TickCount >= t_s1)
- change_cgp_control_idx++;
- break;
- case 1:
- newcontrols = createControlPattern();
- UI.ShowSubtitle("~b~Controls:\n" + stringControlPattern(newcontrols), 4000);
- if (!s2_started)
- {
- s2_started = true;
- t_s2 = Environment.TickCount + 4000;
- }
- if (Environment.TickCount >= t_s2)
- change_cgp_control_idx++;
- break;
- case 2:
- s1_started = false;
- s2_started = false;
- ChangeControllerAssignment = false;
- change_cgp_control_idx = 0;
- if (newcontrols != 0)
- {
- settings.CGP_FIRING_MODE_SWITCH = newcontrols;
- UIMI_FIREMODE_CGP.Text = "Firing mode switch controller: " + stringControlPattern(settings.CGP_FIRING_MODE_SWITCH);
- UI.ShowSubtitle("~b~Successfully assinged firing mode switch key to " + stringControlPattern(settings.CGP_FIRING_MODE_SWITCH), 3000);
- }
- else
- {
- UI.ShowSubtitle("~b~No control(s) have been changed!", 3000);
- }
- break;
- }
- }
- else
- {
- if(state_CGP_FIRING_MODE_SWITCH && !state_CGP_FIRING_MODE_SWITCH_bef)
- {
- changeFiringMode();
- }
- state_CGP_FIRING_MODE_SWITCH_bef = state_CGP_FIRING_MODE_SWITCH;
- }
- }
- #endregion
- }
- public static class LinqHelper
- {
- public static bool ContainsAll<T>(this IEnumerable<T> containingList, IEnumerable<T> lookupList)
- {
- return !lookupList.Except(containingList).Any();
- }
- public static IList<T> Clone<T>(this IList<T> listToClone) where T : ICloneable
- {
- return listToClone.Select(item => (T)item.Clone()).ToList();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement