Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.69 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading;
  5.  
  6. namespace DynamicGravityModHost
  7. {
  8. class Program
  9. {
  10. private static string execFile;
  11. private static string keybindKey = "O";
  12. private static double gravityTimeMax = 5; //seconds
  13. private static double gravityTimeMin = 1.5; //seconds
  14. private static double maxDownGravity = -10000;
  15. private static double maxUpGravity = 10000;
  16. private static double minDownGravity = -100;
  17. private static double minUpGravity = 100;
  18. private static double gravityUpRatio = 0.7; //70% up, 100% down for time ratio
  19. private static bool useRandomInterval = true;
  20. private static bool sayToAll = true;
  21.  
  22. static void Main(string[] args)
  23. {
  24. Console.WriteLine("Dynamic Gravity Mod 1.0");
  25. Console.WriteLine("By FemShep");
  26. Console.WriteLine("========================");
  27. if (args.Length != 1)
  28. {
  29. Console.WriteLine("Argument must be a path to the Mass Effect 3 directory.");
  30. endProgram(1);
  31. }
  32. string me3dir = args[0];
  33. if (!me3dir.EndsWith(@"\"))
  34. {
  35. me3dir += @"\";
  36. }
  37. verifyDirectory(me3dir);
  38. showConfigMenu();
  39. Console.WriteLine("Open the console and type this command in game: 'setbind " + keybindKey + " \"EXEC dynamicgravity.txt\"'");
  40. Console.WriteLine("Press any key to begin gravity session");
  41. Console.ReadKey();
  42. startGravityLoop();
  43. //unreachable
  44. }
  45.  
  46. private static void showConfigMenu()
  47. {
  48. showMainConfigMenu();
  49. }
  50.  
  51. private static void showMainConfigMenu()
  52. {
  53. bool breakLoop = false;
  54. while (true)
  55. {
  56. Console.WriteLine("Select an option to configure this session.");
  57. Console.WriteLine(" 1 - Set Min/Max gravity values");
  58. Console.WriteLine(" 2 - Set gravity switching timers");
  59. Console.WriteLine(" 3 - Set keybind key (Currently: " + keybindKey + ")");
  60. Console.WriteLine(" 4 - Set state change notification on/off (Currently: " + (sayToAll ? "On" : "Off")+ ")");
  61. Console.WriteLine(" S - Start dynamic gravity mod");
  62. Console.Write("Input: ");
  63. ConsoleKeyInfo input = Console.ReadKey();
  64. Console.WriteLine();
  65. switch (input.Key.ToString().ToLower())
  66. {
  67. case "d1":
  68. case "1":
  69. showGravityValuesMenu();
  70. break;
  71. case "d2":
  72. case "2":
  73. showSwitchingMenu();
  74. break;
  75. case "d3":
  76. case "3":
  77. showKeybindingMenu();
  78. break;
  79. case "d4":
  80. case "4":
  81. while (true)
  82. {
  83. bool breakPeriodicLoop = false;
  84. Console.WriteLine("Send players a message for each state change (Y) or don't send (N):");
  85. ConsoleKeyInfo periodicInput = Console.ReadKey();
  86. switch (periodicInput.Key.ToString().ToLower())
  87. {
  88. case "n":
  89. breakPeriodicLoop = true;
  90. sayToAll = false;
  91. break;
  92. case "y":
  93. breakPeriodicLoop = true;
  94. sayToAll = true;
  95. break;
  96. default:
  97. Console.WriteLine();
  98. Console.WriteLine("Invalid choice.");
  99. break;
  100. }
  101. if (breakPeriodicLoop)
  102. {
  103. Console.Clear();
  104. break;
  105. }
  106. }
  107.  
  108. break;
  109. case "s":
  110. breakLoop = true;
  111. break;
  112. default:
  113. Console.WriteLine("Invalid option.");
  114. continue;
  115. }
  116. if (breakLoop)
  117. {
  118. break;
  119. }
  120. }
  121. }
  122.  
  123. private static void showKeybindingMenu()
  124. {
  125. Console.Clear();
  126. Console.WriteLine("Press a key to send to the game to trigger the in-game keybinding:");
  127. ConsoleKeyInfo input = Console.ReadKey();
  128. keybindKey = input.Key.ToString();
  129. }
  130.  
  131. private static void showSwitchingMenu()
  132. {
  133. bool breakLoop = false;
  134. while (true)
  135. {
  136. Console.Clear();
  137. Console.WriteLine("Select an option to configure gravity timers:");
  138. Console.WriteLine(" 1 - Set periodic or random switching timers (Currently: " + (useRandomInterval ? "Random" : "Periodic") + ")");
  139. Console.WriteLine(" 2 - Set max time for gravity state (Currently: " + gravityTimeMax + "s)");
  140. Console.WriteLine(" 2 - Set min time for gravity state (Currently: " + gravityTimeMin + "s)");
  141. Console.WriteLine(" 3 - Set gravity up time ratio (Currently: " + gravityUpRatio + " : 1)");
  142. Console.WriteLine(" R - Return to previous menu");
  143. Console.Write("Input: ");
  144. ConsoleKeyInfo input = Console.ReadKey();
  145. Console.WriteLine();
  146.  
  147. switch (input.Key.ToString().ToLower())
  148. {
  149. case "d1":
  150. case "1":
  151. while (true)
  152. {
  153. bool breakPeriodicLoop = false;
  154. Console.WriteLine("Use Periodic (P) or Random (R) gravity timers:");
  155. ConsoleKeyInfo periodicInput = Console.ReadKey();
  156. switch (periodicInput.Key.ToString().ToLower())
  157. {
  158. case "p":
  159. breakPeriodicLoop = true;
  160. useRandomInterval = false;
  161. break;
  162. case "r":
  163. breakPeriodicLoop = true;
  164. useRandomInterval = true;
  165. break;
  166. default:
  167. Console.WriteLine("Invalid choice.");
  168. break;
  169. }
  170. if (breakPeriodicLoop)
  171. {
  172. break;
  173. }
  174. }
  175.  
  176. break;
  177. case "d2":
  178. case "2":
  179. while (true)
  180. {
  181. Console.WriteLine("Set a maximum time (in seconds) for a gravity state. Periodic will use this interval, random will use this as a maximum value:");
  182. String timeInput = Console.ReadLine();
  183. float switchingTime = 0;
  184. if (!float.TryParse(timeInput, out switchingTime) || switchingTime < 1)
  185. {
  186. Console.WriteLine("Invalid input. Must be greater than or equal to 1 second.");
  187. continue;
  188. }
  189. else if (switchingTime < gravityTimeMin)
  190. {
  191. Console.WriteLine("Gravity state max time can't be less than the gravity state min time (" + gravityTimeMin + "s)");
  192. continue;
  193. }
  194. else
  195. {
  196. gravityTimeMax = switchingTime;
  197. break;
  198. }
  199. }
  200. break;
  201. case "d3":
  202. case "3":
  203. while (true)
  204. {
  205. Console.WriteLine("Set a minimum time (in seconds) for a gravity state. Gravity up time will use this value multiplied by it's ratio value.");
  206. String timeInput = Console.ReadLine();
  207. float switchingTime = 0;
  208. if (!float.TryParse(timeInput, out switchingTime) || switchingTime < .1)
  209. {
  210. Console.WriteLine("Invalid input. Must be greater than or equal to .1 seconds.");
  211. continue;
  212. }
  213. else if (switchingTime > gravityTimeMax)
  214. {
  215. Console.WriteLine("Gravity state min time can't be greater than the gravity state max time (" + gravityTimeMax + "s)");
  216. continue;
  217. }
  218. else
  219. {
  220. gravityTimeMin = switchingTime;
  221. break;
  222. }
  223. }
  224. break;
  225. case "d4":
  226. case "4":
  227. while (true)
  228. {
  229. Console.WriteLine("Set a ratio for the time gravity is up compared to down. 1 implies they are equal. The value should ideally be less than 1 or you will float up more than down, leading players to be unable to do anything. This will be applied after all other timing calculations are done: ");
  230. String timeInput = Console.ReadLine();
  231. float uptime = 0;
  232.  
  233. if (!float.TryParse(timeInput, out uptime) || uptime < 0.01)
  234. {
  235. Console.WriteLine("Invalid input. Must be greater than or equal to 0.01");
  236. continue;
  237. }
  238. else
  239. {
  240. gravityUpRatio = uptime;
  241. break;
  242. }
  243. }
  244. break;
  245. case "r":
  246. breakLoop = true;
  247. break;
  248. }
  249. if (breakLoop)
  250. {
  251. break;
  252. }
  253. }
  254. }
  255.  
  256. private static void showGravityValuesMenu()
  257. {
  258. bool breakLoop = false;
  259. while (true)
  260. {
  261. Console.Clear();
  262. Console.WriteLine("The game's default gravity is -981.");
  263. Console.WriteLine("Select an option to configure gravity values:");
  264. Console.WriteLine(" 1 - Set minimum up gravity (Currently: " + minUpGravity + ")");
  265. Console.WriteLine(" 2 - Set maximum up gravity (Currently: " + maxUpGravity + ")");
  266. Console.WriteLine(" 3 - Set minimum down gravity (Currently: " + minDownGravity + ")");
  267. Console.WriteLine(" 4 - Set maximum down gravity (Currently: " + maxDownGravity + ")");
  268. Console.WriteLine(" R - Return to previous menu");
  269. Console.Write("Input: ");
  270. ConsoleKeyInfo input = Console.ReadKey();
  271. Console.WriteLine();
  272.  
  273. switch (input.Key.ToString().ToLower())
  274. {
  275. case "d1":
  276. case "1":
  277. while (true)
  278. {
  279. Console.WriteLine("Set maximum UP gravity (positive values):");
  280. String timeInput = Console.ReadLine();
  281. double maxUp = 0;
  282.  
  283. if (!double.TryParse(timeInput, out maxUp) || maxUp < 0)
  284. {
  285. Console.WriteLine("Invalid input. Must be greater than or equal to 0.01");
  286. continue;
  287. }
  288. else if (maxUp < minUpGravity)
  289. {
  290. Console.WriteLine("Maximum up gravity must be greater than or equal to minimum up (" + minUpGravity + ")");
  291. continue;
  292. }
  293. else
  294. {
  295. maxUpGravity = maxUp;
  296. break;
  297. }
  298. }
  299. break;
  300. case "d2":
  301. case "2":
  302. while (true)
  303. {
  304. Console.WriteLine("Set minimum UP gravity (positive values):");
  305. String timeInput = Console.ReadLine();
  306. double minUp = 0;
  307.  
  308. if (!double.TryParse(timeInput, out minUp) || minUp < 0)
  309. {
  310. Console.WriteLine("Invalid input. Must be greater than or equal to 0.01");
  311. continue;
  312. }
  313. else if (minUp > maxUpGravity)
  314. {
  315. Console.WriteLine("Minimum up gravity must be less than or equal to minimum up (" + maxUpGravity + ")");
  316. continue;
  317. }
  318. else
  319. {
  320. minUpGravity = minUp;
  321. break;
  322. }
  323. }
  324. break;
  325. case "d4":
  326. case "4":
  327. while (true)
  328. {
  329. Console.WriteLine("Set maximum DOWN gravity (negative values):");
  330. String timeInput = Console.ReadLine();
  331. double maxDown = 0;
  332.  
  333. if (!double.TryParse(timeInput, out maxDown) || maxDown > 0)
  334. {
  335. Console.WriteLine("Invalid input. Must be less than 0.");
  336. continue;
  337. }
  338. else if (maxDown > minDownGravity)
  339. {
  340. Console.WriteLine("Maximum down gravity must be less than or equal to minimum down (" + minDownGravity + ")");
  341. continue;
  342. }
  343. else
  344. {
  345. maxDownGravity = maxDown;
  346. break;
  347. }
  348. }
  349. break;
  350. case "d3": //MIN DOWN
  351. case "3":
  352. while (true)
  353. {
  354. Console.WriteLine("Set minimum DOWN gravity (negative values):");
  355. String timeInput = Console.ReadLine();
  356. double minDown = 0;
  357.  
  358. if (!double.TryParse(timeInput, out minDown) || minDown > 0)
  359. {
  360. Console.WriteLine("Invalid input. Must be less than 0.");
  361. continue;
  362. }
  363. else if (minDown < maxDownGravity)
  364. {
  365. Console.WriteLine("Minimum down gravity must be greater than or equal to maximium down (" + maxDownGravity + ")");
  366. continue;
  367. }
  368. else
  369. {
  370. minDownGravity = minDown;
  371. break;
  372. }
  373. }
  374. break;
  375. case "r":
  376. breakLoop = true;
  377. break;
  378. default:
  379. Console.WriteLine("Invalid choice.");
  380. continue;
  381. }
  382. }
  383. }
  384.  
  385. private static void startGravityLoop()
  386. {
  387. Random random = new Random();
  388. gravityTimeMax *= 1000; //s to ms
  389. bool gravityUp = false;
  390. while (true)
  391. {
  392. gravityUp = !gravityUp;
  393. int sleepTime = (int)gravityTimeMax;
  394. if (useRandomInterval)
  395. {
  396. sleepTime = random.Next(sleepTime) + 100;
  397. }
  398.  
  399. double scalar = random.NextDouble(); //picks next random value
  400. double gravityWindow = (gravityUp ? maxUpGravity - minUpGravity : Math.Abs(maxDownGravity) - Math.Abs(minDownGravity));
  401. gravityWindow *= scalar;
  402. if (gravityUp)
  403. {
  404. gravityWindow *= gravityUpRatio;
  405. }
  406.  
  407. double gravityValue = (gravityUp ? minUpGravity + gravityWindow : minDownGravity - gravityWindow);
  408. String command = "SetGravity " + gravityValue;
  409.  
  410. if (sayToAll)
  411. {
  412. command += "\bSay GRAVITY: " + gravityValue + " for " + sleepTime + "ms";
  413. }
  414. File.WriteAllText(execFile, command);
  415. Console.WriteLine("Gravity: " + (gravityUp ? "Up" : "Down") + " for " + sleepTime + " ms");
  416. Thread.Sleep(sleepTime);
  417. }
  418. }
  419.  
  420. private static void verifyDirectory(string me3dir)
  421. {
  422. if (!Directory.Exists(me3dir))
  423. {
  424. Console.WriteLine("Directory does not exist: " + me3dir);
  425. endProgram(1);
  426. }
  427. me3dir += "Binaries\\";
  428. string masseffect3exe = me3dir + "win32\\MassEffect3.exe";
  429. if (!File.Exists(masseffect3exe))
  430. {
  431. Console.WriteLine("Directory specified is not the Mass Effect 3 directory:");
  432. Console.WriteLine("EXE would be at: " + masseffect3exe);
  433. endProgram(1);
  434. }
  435. execFile = me3dir + "dynamicgravity.txt";
  436. }
  437.  
  438. private static void endProgram(int v)
  439. {
  440. DebugPause();
  441. Environment.Exit(v);
  442. }
  443.  
  444. [Conditional("DEBUG")]
  445. public static void DebugPause()
  446. {
  447. Console.WriteLine("Press any key to exit");
  448. Console.ReadKey();
  449. }
  450. }
  451. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement