forcedreg

Untitled

Apr 20th, 2024
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.48 KB | None | 0 0
  1. /*
  2. Hawken v2.0.1 Controls for Steel Battalion
  3. Created by Flame Soulis
  4.  
  5. NOTE: DO NOT USE 2.1 RC! These settings are for 2.0.1 of the program that
  6. handles the controller! The value ranges are different and this
  7. makes it difficult to include a setting to allow different maths
  8. to be applied. Until this is managed or is upgraded to handle that,
  9. please use Steel-Battalion-64_2.0.1 instead.
  10. */
  11. /*
  12. From GameEngine.ini
  13.  
  14. .Bindings=(Name="XboxTypeS_Back",Command="GBA_ShowScores")
  15. .Bindings=(Name="XboxTypeS_Start",Command="GBA_ShowMenu")
  16.  
  17. .Bindings=(Name="XboxTypeS_LeftX",Command="GBA_StrafeLeft_Gamepad")
  18. .Bindings=(Name="XboxTypeS_LeftY",Command="GBA_MoveForward_Gamepad")
  19. .Bindings=(Name="XboxTypeS_RightX",Command="GBA_TurnLeft_Gamepad")
  20. .Bindings=(Name="XboxTypeS_RightY",Command="GBA_Look_Gamepad")
  21.  
  22. .Bindings=(Name="XboxTypeS_LeftTrigger",Command="GBA_Fire")
  23. .Bindings=(Name="XboxTypeS_RightTrigger",Command="GBA_AltFire")
  24.  
  25. .Bindings=(Name="XboxTypeS_LeftShoulder",Command="GBA_Jump_Gamepad")
  26. .Bindings=(Name="XboxTypeS_RightShoulder",Command="GBA_Boost")
  27.  
  28. .Bindings=(Name="XboxTypeS_A",Command="GBA_Ability")
  29. .Bindings=(Name="XboxTypeS_B",Command="GBA_Heal | Back")
  30. .Bindings=(Name="XboxTypeS_Y",Command="GBA_Action")
  31. .Bindings=(Name="XboxTypeS_X",Command="GBA_Use | Confirm")
  32. .Bindings=(Name="XboxTypeS_LeftThumbstick",Command="GBA_EnemySpotted")
  33. .Bindings=(Name="XboxTypeS_RightThumbstick",Command="GBA_AltFire2")
  34.  
  35. .Bindings=(Name="XboxTypeS_DPad_Up",Command="GBA_NeedAssistance")
  36. .Bindings=(Name="XboxTypeS_DPad_Down",Command="GBA_ToggleMap")
  37. .Bindings=(Name="XboxTypeS_DPad_Left",Command="GBA_PrevItem")
  38. .Bindings=(Name="XboxTypeS_DPad_Right",Command="GBA_NextItem")
  39. ;.Bindings=(Name="SIXAXIS_AccelX",Command="GBA_TurnLeft_Gamepad")
  40. ;.Bindings=(Name="SIXAXIS_AccelZ",Command="GBA_Look_Gamepad")
  41. */
  42.  
  43. /*
  44. Aiming Lever Y = Xbox Right Y
  45. Aiming Lever X = Xbox Right X
  46. Rotation Lever = Shift + Xbox Left X
  47. Sight Change Pressed= B01
  48. Sight Change X = Xbox Left X
  49. Sight Change Y =
  50. Lock On = B06
  51. Main Weapon = B10
  52. Sub Weapon = B09
  53. Gas Pedal = Xbox Left Y (Pos)
  54. Brake Pedal = Xbox Left Y (Neg)
  55. Clutch Pedal = B07
  56. Main Weapon Ctrl = 1
  57. Sub Weapon Ctrl = 2
  58. Magazine Change = 3
  59. Oxygen Toggle = B02
  60. Filtration Toggle = B11
  61.  
  62.  
  63. Buttons
  64. 01 = A
  65. 02 = B
  66. 03 = X
  67. 04 = Y
  68. 05 = Left Stick
  69. 06 = Right Stick
  70. 07 = Left Shoulder
  71. 08 = Right Shoulder
  72. 09 = Left Trigger
  73. 10 = Right Trigger
  74. 11 = Back Button
  75. 12 = Start Button
  76. 13 = D-PAD UP
  77. 14 = D-PAD RIGHT
  78. 15 = D-PAD DOWN
  79. 16 = D-PAD LEFT
  80. */
  81.  
  82. using SBC;
  83. using System;
  84. namespace SBC {
  85. public class DynamicClass {
  86. SteelBattalionController controller;
  87. vJoy joystick;
  88. bool acquired;
  89. const int refreshRate = 30;//number of milliseconds between call to mainLoop
  90.  
  91. const int iRotationLeverDead = 32;
  92. const int iLeftPedalDead = 32;
  93. const int iMovementPedalBoost = 196;
  94. const int iReversePedalBoost = 212;
  95.  
  96. const int iGlowyGoodnessMin = 0; //0-15 for glow effect
  97. const int iGlowyGoodnessMax = 15;
  98. const double dGlowySpeed = 5;
  99.  
  100. //MOSTLY system stuff, no touchy beyond this point
  101. //Unless you know what you are doing
  102.  
  103. double dGlowyGoodness;
  104.  
  105. //Keyboard stuff - Because we have more buttons than a standard XBOX Controller
  106. const Microsoft.DirectX.DirectInput.Key ITEM1 = Microsoft.DirectX.DirectInput.Key.D1;
  107. const Microsoft.DirectX.DirectInput.Key ITEM2 = Microsoft.DirectX.DirectInput.Key.D2;
  108. const Microsoft.DirectX.DirectInput.Key ITEM3 = Microsoft.DirectX.DirectInput.Key.D3;
  109.  
  110. const Microsoft.DirectX.DirectInput.Key HOLOTAUNT = Microsoft.DirectX.DirectInput.Key.H;
  111. const Microsoft.DirectX.DirectInput.Key NORMALTAUNT = Microsoft.DirectX.DirectInput.Key.G;
  112. const Microsoft.DirectX.DirectInput.Key SHOWSCORES = Microsoft.DirectX.DirectInput.Key.Tab;
  113. const Microsoft.DirectX.DirectInput.Key TOGGLEMAP = Microsoft.DirectX.DirectInput.Key.V;
  114. const Microsoft.DirectX.DirectInput.Key ACTION = Microsoft.DirectX.DirectInput.Key.E;
  115.  
  116. public void Initialize() {
  117. controller = new SteelBattalionController();
  118. controller.Init(refreshRate);
  119. dGlowyGoodness=iGlowyGoodnessMin;
  120. int baseLineIntensity = 10;//just an average value for LED intensity
  121. int emergencyLightIntensity = 15;//for stuff like eject,cockpit Hatch,Ignition, and Start
  122.  
  123. for(int i=4;i<4+30;i++) {
  124. if (i != (int)ButtonEnum.Eject)//excluding eject since we are going to flash that one
  125. controller.AddButtonLightMapping((ButtonEnum)(i-1),(ControllerLEDEnum)(i),true,baseLineIntensity);
  126. }
  127.  
  128. controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMain, true,baseLineIntensity,ITEM1,true);
  129. controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConSub, true,baseLineIntensity,ITEM2,true);
  130. controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMagazine, true,baseLineIntensity,ITEM3,true);
  131.  
  132. controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomIn, true,baseLineIntensity,HOLOTAUNT,true);
  133. controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomOut, true,baseLineIntensity,NORMALTAUNT,true);
  134. controller.AddButtonKeyLightMapping(ButtonEnum.ToggleFilterControl, true,baseLineIntensity,SHOWSCORES,true);
  135. controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonOpenClose, true,baseLineIntensity,TOGGLEMAP,true);
  136. controller.AddButtonKeyLightMapping(ButtonEnum.Start, true,baseLineIntensity,ACTION,true);
  137.  
  138. joystick = new vJoy();
  139. acquired = joystick.acquireVJD(1);
  140. joystick.resetAll();//have to reset before we use it
  141. }
  142.  
  143. public int getRefreshRate() {
  144. return refreshRate;
  145. }
  146.  
  147. public void updatePOVhat() {
  148. controller.POVhat = SBC.POVdirection.CENTER;
  149. }
  150.  
  151. //this gets called once every refreshRate milliseconds by main program
  152. public void mainLoop() {
  153. updatePOVhat();
  154. handleComms();
  155. //Update the glowiness
  156. dGlowyGoodness = (dGlowyGoodness + dGlowySpeed) % 360;
  157. //Handle all Axis based stuff222
  158. if(!controller.GetButtonState(ButtonEnum.ToggleVTLocation)) {
  159. joystick.setAxis(1,32+(int)((double)controller.AimingX*0.75),HID_USAGES.HID_USAGE_RX);
  160. joystick.setAxis(1,32+(int)((double)controller.AimingY*0.75),HID_USAGES.HID_USAGE_RY);
  161. } else {
  162. joystick.setAxis(1,64+(controller.AimingX/2),HID_USAGES.HID_USAGE_RX);
  163. joystick.setAxis(1,64+(controller.AimingY/2),HID_USAGES.HID_USAGE_RY);
  164. }
  165. joystick.setAxis(1,controller.RightPedal-controller.MiddlePedal,HID_USAGES.HID_USAGE_Y);
  166. joystick.setAxis(1,controller.SightChangeX,HID_USAGES.HID_USAGE_X);
  167.  
  168. //Handle Special Stuff
  169. //Determine if the Rotation Lever was used (aka Side Dash of Justice)
  170. bool bBoost = false;
  171. if(System.Math.Abs(controller.RotationLever) > iRotationLeverDead) {
  172. bBoost=true;
  173. if(controller.RotationLever > iRotationLeverDead)
  174. joystick.setAxis(1,128,HID_USAGES.HID_USAGE_X);
  175. else
  176. joystick.setAxis(1,-128,HID_USAGES.HID_USAGE_X);
  177. }
  178. //Are we trying to jump?
  179. if(controller.LeftPedal > iLeftPedalDead)
  180. joystick.setButton(true,1,07);
  181. else
  182. joystick.setButton(false,1,07);
  183.  
  184. //Should we boost?
  185. if(controller.RightPedal > iMovementPedalBoost ||
  186. controller.MiddlePedal > iReversePedalBoost)
  187. bBoost=true;
  188.  
  189. //Handle Buttons
  190. joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire),1,
  191. controller.GetButtonState(ButtonEnum.ToggleBufferMaterial) ? 09 : 10); //Right Trigger
  192. joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyMainWeapon),1,
  193. controller.GetButtonState(ButtonEnum.ToggleBufferMaterial) ? 10 : 09); //Left Trigger
  194. joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyLockOn),1,06); //Right Analog Stick
  195. joystick.setButton(controller.GetButtonState(ButtonEnum.ToggleOxygenSupply),1,02); //B Button
  196. //joystick.setButton(controller.GetButtonState(ButtonEnum.ToggleFilterControl),1,11); //Back Button
  197. joystick.setButton(controller.GetButtonState(ButtonEnum.LeftJoySightChange),1,01); //A Button
  198. //joystick.setButton(controller.GetButtonState(ButtonEnum.MultiMonOpenClose),1,15); //D-PAD DOWN
  199.  
  200. //Handle the Lights
  201. controller.SetLEDState((ControllerLEDEnum)ButtonLights.WeaponConMain,getGlowy(0));
  202. controller.SetLEDState((ControllerLEDEnum)ButtonLights.WeaponConSub,getGlowy(30));
  203. controller.SetLEDState((ControllerLEDEnum)ButtonLights.WeaponConMagazine,getGlowy(60));
  204. controller.SetLEDState((ControllerLEDEnum)ButtonLights.MainMonZoomOut,getGlowy(90));
  205. controller.SetLEDState((ControllerLEDEnum)ButtonLights.FunctionFSS,getGlowy(120)); //Dunno why, but the values are swapped for the LEDs...
  206.  
  207. controller.SetLEDState((ControllerLEDEnum)ButtonLights.Comm1,getGlowy(0));
  208. controller.SetLEDState((ControllerLEDEnum)ButtonLights.Comm2,getGlowy(18));
  209. controller.SetLEDState((ControllerLEDEnum)ButtonLights.Comm3,getGlowy(36));
  210. controller.SetLEDState((ControllerLEDEnum)ButtonLights.Comm4,getGlowy(54));
  211. controller.SetLEDState((ControllerLEDEnum)ButtonLights.Comm5,getGlowy(72));
  212.  
  213. //Handle boost (because it's special)
  214. joystick.setButton(bBoost,1,08);
  215. joystick.sendUpdate(1);
  216. }
  217.  
  218. public int getGlowy(int iOffset) {
  219. double angle = ((dGlowyGoodness + iOffset) % 360)*System.Math.PI/180.0;
  220. double dSin = System.Math.Sin(angle);
  221. return (int)System.Math.Abs(dSin*(double)(iGlowyGoodnessMax-iGlowyGoodnessMin)) + iGlowyGoodnessMin;
  222. }
  223.  
  224. bool bComm1=false;
  225. bool bComm2=false;
  226. bool bComm5=false;
  227. public void handleComms() {
  228. if(controller.GetButtonState(ButtonEnum.Comm1) && !bComm1) {
  229. bComm1=true;
  230. Microsoft.DirectX.DirectInput.Key[] Message = {
  231. Microsoft.DirectX.DirectInput.Key.T,
  232. Microsoft.DirectX.DirectInput.Key.G,
  233. Microsoft.DirectX.DirectInput.Key.O,
  234. Microsoft.DirectX.DirectInput.Key.Space,
  235. Microsoft.DirectX.DirectInput.Key.T,
  236. Microsoft.DirectX.DirectInput.Key.O,
  237. Microsoft.DirectX.DirectInput.Key.Space,
  238. Microsoft.DirectX.DirectInput.Key.A,
  239. Microsoft.DirectX.DirectInput.Key.A,
  240. Microsoft.DirectX.DirectInput.Key.Return};
  241. foreach (Microsoft.DirectX.DirectInput.Key msg in Message)
  242. controller.sendKeyPress(msg);
  243. } else if(!controller.GetButtonState(ButtonEnum.Comm1)) bComm1=false;
  244.  
  245. if(controller.GetButtonState(ButtonEnum.Comm2) && !bComm2) {
  246. bComm2=true;
  247. Microsoft.DirectX.DirectInput.Key[] Message = {
  248. Microsoft.DirectX.DirectInput.Key.T,
  249. Microsoft.DirectX.DirectInput.Key.G,
  250. Microsoft.DirectX.DirectInput.Key.O,
  251. Microsoft.DirectX.DirectInput.Key.Space,
  252. Microsoft.DirectX.DirectInput.Key.C,
  253. Microsoft.DirectX.DirectInput.Key.O,
  254. Microsoft.DirectX.DirectInput.Key.L,
  255. Microsoft.DirectX.DirectInput.Key.L,
  256. Microsoft.DirectX.DirectInput.Key.E,
  257. Microsoft.DirectX.DirectInput.Key.C,
  258. Microsoft.DirectX.DirectInput.Key.T,
  259. Microsoft.DirectX.DirectInput.Key.Space,
  260. Microsoft.DirectX.DirectInput.Key.E,
  261. Microsoft.DirectX.DirectInput.Key.U,
  262. Microsoft.DirectX.DirectInput.Key.Return};
  263. foreach (Microsoft.DirectX.DirectInput.Key msg in Message)
  264. controller.sendKeyPress(msg);
  265. } else if(!controller.GetButtonState(ButtonEnum.Comm2)) bComm2=false;
  266.  
  267. if(controller.GetButtonState(ButtonEnum.Comm5) && !bComm5) {
  268. bComm5=true;
  269. Microsoft.DirectX.DirectInput.Key[] Message = {
  270. Microsoft.DirectX.DirectInput.Key.Y,
  271. Microsoft.DirectX.DirectInput.Key.T,
  272. Microsoft.DirectX.DirectInput.Key.H,
  273. Microsoft.DirectX.DirectInput.Key.A,
  274. Microsoft.DirectX.DirectInput.Key.T,
  275. Microsoft.DirectX.DirectInput.Key.Space,
  276. Microsoft.DirectX.DirectInput.Key.W,
  277. Microsoft.DirectX.DirectInput.Key.A,
  278. Microsoft.DirectX.DirectInput.Key.S,
  279. Microsoft.DirectX.DirectInput.Key.Space,
  280. Microsoft.DirectX.DirectInput.Key.A,
  281. Microsoft.DirectX.DirectInput.Key.Space,
  282. Microsoft.DirectX.DirectInput.Key.G,
  283. Microsoft.DirectX.DirectInput.Key.O,
  284. Microsoft.DirectX.DirectInput.Key.O,
  285. Microsoft.DirectX.DirectInput.Key.D,
  286. Microsoft.DirectX.DirectInput.Key.Space,
  287. Microsoft.DirectX.DirectInput.Key.G,
  288. Microsoft.DirectX.DirectInput.Key.A,
  289. Microsoft.DirectX.DirectInput.Key.M,
  290. Microsoft.DirectX.DirectInput.Key.E,
  291. Microsoft.DirectX.DirectInput.Key.Return};
  292. foreach (Microsoft.DirectX.DirectInput.Key msg in Message)
  293. controller.sendKeyPress(msg);
  294. } else if(!controller.GetButtonState(ButtonEnum.Comm5)) bComm5=false;
  295. }
  296.  
  297. public void shutDown() {
  298. controller.UnInit();
  299. joystick.Release(1);
  300. }
  301. }
  302. }
Advertisement
Add Comment
Please, Sign In to add comment