Advertisement
awilliams17

Bad.cs

Sep 8th, 2018
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.84 KB | None | 0 0
  1. using System;
  2. using Microsoft.Win32;
  3.  
  4. namespace Halo_Mouse_Tool
  5. {
  6.     public class Settings
  7.     {
  8.         //CombatEvolved == 1, CustomEdition == 0 in registry
  9.         public enum Game { CombatEvolved, CustomEdition };
  10.  
  11.         private Game _current_game = Game.CustomEdition;
  12.         private float _sensX = 1.0F;
  13.         private float _sensY = 1.0F;
  14.         private int _hotKeyApplication = 0x70; //F1
  15.         private int _hotKeyDll = 0x71; //F2
  16.         private bool _hotKeyEnabled = true;
  17.         private bool _patchAccel = true;
  18.  
  19.         private bool _checkForUpdates = true;
  20.         private int _updateTimeout = 5000;
  21.         private bool _soundsEnabled = true;
  22.         private bool _soundsEnabledDll = true;
  23.         private bool _successMessages = true;
  24.  
  25.         private float _incrementAmount = 0.1F;
  26.         private bool _incrementKeysEnabled = true;
  27.  
  28.         public Game Current_Game
  29.         {
  30.             get => _current_game;
  31.             set => _current_game = value;
  32.         }
  33.  
  34.         public float SensX
  35.         {
  36.             get => _sensX;
  37.             set => _sensX = Validators.BelowZero(value);
  38.         }
  39.  
  40.         public float SensY
  41.         {
  42.             get => _sensY;
  43.             set => _sensY = Validators.BelowZero(value);
  44.         }
  45.  
  46.         public bool PatchAcceleration
  47.         {
  48.             get => _patchAccel;
  49.             set => _patchAccel = value;
  50.         }
  51.  
  52.         public int HotKeyApplication
  53.         {
  54.             get => _hotKeyApplication;
  55.             set => _hotKeyApplication = value;
  56.         }
  57.  
  58.         public bool HotKeyEnabled
  59.         {
  60.             get => _hotKeyEnabled;
  61.             set => _hotKeyEnabled = value;
  62.         }
  63.  
  64.         public int HotKeyDll
  65.         {
  66.             get => _hotKeyDll;
  67.             set => _hotKeyDll = value;
  68.         }
  69.  
  70.         public bool CheckForUpdates
  71.         {
  72.             get => _checkForUpdates;
  73.             set => _checkForUpdates = value;
  74.         }
  75.  
  76.         public int UpdateTimeout
  77.         {
  78.             get => _updateTimeout;
  79.             set => _updateTimeout = Validators.UpdateTimeout(value);
  80.         }
  81.  
  82.         public bool SoundsEnabled
  83.         {
  84.             get => _soundsEnabled;
  85.             set => _soundsEnabled = value;
  86.         }
  87.  
  88.         public bool SoundsEnabledDll
  89.         {
  90.             get => _soundsEnabledDll;
  91.             set => _soundsEnabledDll = value;
  92.         }
  93.  
  94.         public bool SuccessMessages
  95.         {
  96.             get => _successMessages;
  97.             set => _successMessages = value;
  98.         }
  99.  
  100.         public float IncrementAmount
  101.         {
  102.             get => _incrementAmount;
  103.             set => _incrementAmount = Validators.IncrementAmount(value);
  104.         }
  105.  
  106.         public bool IncrementKeysEnabled
  107.         {
  108.             get => _incrementKeysEnabled;
  109.             set => _incrementKeysEnabled = value;
  110.         }
  111.  
  112.         public void SaveSettings()
  113.         {
  114.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "SensX", SensX, RegistryValueKind.String);
  115.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "SensY", SensY, RegistryValueKind.String);
  116.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "PatchMouseAcceleration", Convert.ToInt32(PatchAcceleration), RegistryValueKind.DWord);
  117.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "HotkeyApplication", HotKeyApplication, RegistryValueKind.DWord);
  118.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "HotkeyDll", HotKeyDll, RegistryValueKind.DWord);
  119.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "CheckForUpdates", CheckForUpdates, RegistryValueKind.DWord);
  120.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "UpdateTimeout", UpdateTimeout, RegistryValueKind.DWord);
  121.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "HotKeyEnabled", Convert.ToInt32(HotKeyEnabled), RegistryValueKind.DWord);
  122.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "SoundsEnabled", Convert.ToInt32(SoundsEnabled), RegistryValueKind.DWord);
  123.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "SoundsEnabledDll", Convert.ToInt32(SoundsEnabledDll), RegistryValueKind.DWord);
  124.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "SuccessMessages", Convert.ToInt32(SuccessMessages), RegistryValueKind.DWord);
  125.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "CurrentGame", (int)Current_Game, RegistryValueKind.DWord);
  126.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "IncrementKeysEnabled", Convert.ToInt32(IncrementKeysEnabled), RegistryValueKind.DWord);
  127.             Registry.SetValue("HKEY_CURRENT_USER\\Software\\HaloMouseTool", "IncrementAmount", IncrementAmount, RegistryValueKind.String);
  128.         }
  129.  
  130.         public void LoadSettings() //This is bad, but it works.
  131.         {
  132.             RegistryKey HaloMouseToolRegistry = Registry.CurrentUser.OpenSubKey("Software\\HaloMouseTool", false);
  133.             if (HaloMouseToolRegistry == null)
  134.             {
  135.                 SaveSettings();
  136.             }
  137.             else
  138.             {
  139.                 SensX = float.Parse(HaloMouseToolRegistry.GetValue("SensX").ToString());
  140.                 SensY = float.Parse(HaloMouseToolRegistry.GetValue("SensY").ToString());
  141.                 PatchAcceleration = Convert.ToInt32(HaloMouseToolRegistry.GetValue("PatchMouseAcceleration")) == 1;
  142.                 SoundsEnabled = Convert.ToInt32(HaloMouseToolRegistry.GetValue("SoundsEnabled")) == 1;
  143.                 SoundsEnabledDll = Convert.ToInt32(HaloMouseToolRegistry.GetValue("SoundsEnabledDll")) == 1;
  144.                 SuccessMessages = Convert.ToInt32(HaloMouseToolRegistry.GetValue("SuccessMessages")) == 1;
  145.                 IncrementKeysEnabled = Convert.ToInt32(HaloMouseToolRegistry.GetValue("IncrementKeysEnabled")) == 1;
  146.                 CheckForUpdates = Convert.ToInt32(HaloMouseToolRegistry.GetValue("CheckForUpdates")) == 1;
  147.                 HotKeyEnabled = Convert.ToInt32(HaloMouseToolRegistry.GetValue("HotKeyEnabled")) == 1;
  148.                 HotKeyApplication = int.Parse(HaloMouseToolRegistry.GetValue("HotkeyApplication").ToString());
  149.                 HotKeyDll = int.Parse(HaloMouseToolRegistry.GetValue("HotkeyDll").ToString());
  150.                 UpdateTimeout = int.Parse(HaloMouseToolRegistry.GetValue("UpdateTimeout").ToString());
  151.                 IncrementAmount = float.Parse(HaloMouseToolRegistry.GetValue("IncrementAmount").ToString());
  152.                 if (int.Parse(HaloMouseToolRegistry.GetValue("CurrentGame").ToString()) == 0)
  153.                 {
  154.                     Current_Game = Game.CombatEvolved;
  155.                 }
  156.             }
  157.         }
  158.     }
  159.     class Validators
  160.     {
  161.         public static float BelowZero(float arg)
  162.         {
  163.             if (arg < 0)
  164.             {
  165.                 throw new ArgumentOutOfRangeException("This cannot be below 0.");
  166.             }
  167.             return arg;
  168.         }
  169.  
  170.         public static int UpdateTimeout(int arg)
  171.         {
  172.             if (arg < 1000)
  173.             {
  174.                 throw new ArgumentOutOfRangeException("This can not be less than 1 second.");
  175.             }
  176.             if (arg > 15000)
  177.             {
  178.                 throw new ArgumentOutOfRangeException("This can not be greater than 15 seconds.");
  179.             }
  180.             return arg;
  181.         }
  182.  
  183.         public static float IncrementAmount(float arg)
  184.         {
  185.             if (arg < 0.0F)
  186.             {
  187.                 throw new ArgumentOutOfRangeException("Increment amount can not be below 0.");
  188.             }
  189.             if (arg > 25.0F)
  190.             {
  191.                 throw new ArgumentOutOfRangeException("Increment amount can not be above 25.");
  192.             }
  193.             return arg;
  194.         }
  195.     }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement