Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Threading;
- namespace DynamicGravityModHost
- {
- class Program
- {
- private static string execFile;
- private static string keybindKey = "O";
- private static double gravityTimeMax = 5; //seconds
- private static double gravityTimeMin = 1.5; //seconds
- private static double maxDownGravity = -10000;
- private static double maxUpGravity = 10000;
- private static double minDownGravity = -100;
- private static double minUpGravity = 100;
- private static double gravityUpRatio = 0.7; //70% up, 100% down for time ratio
- private static bool useRandomInterval = true;
- private static bool sayToAll = true;
- static void Main(string[] args)
- {
- Console.WriteLine("Dynamic Gravity Mod 1.0");
- Console.WriteLine("By FemShep");
- Console.WriteLine("========================");
- if (args.Length != 1)
- {
- Console.WriteLine("Argument must be a path to the Mass Effect 3 directory.");
- endProgram(1);
- }
- string me3dir = args[0];
- if (!me3dir.EndsWith(@"\"))
- {
- me3dir += @"\";
- }
- verifyDirectory(me3dir);
- showConfigMenu();
- Console.WriteLine("Open the console and type this command in game: 'setbind " + keybindKey + " \"EXEC dynamicgravity.txt\"'");
- Console.WriteLine("Press any key to begin gravity session");
- Console.ReadKey();
- startGravityLoop();
- //unreachable
- }
- private static void showConfigMenu()
- {
- showMainConfigMenu();
- }
- private static void showMainConfigMenu()
- {
- bool breakLoop = false;
- while (true)
- {
- Console.WriteLine("Select an option to configure this session.");
- Console.WriteLine(" 1 - Set Min/Max gravity values");
- Console.WriteLine(" 2 - Set gravity switching timers");
- Console.WriteLine(" 3 - Set keybind key (Currently: " + keybindKey + ")");
- Console.WriteLine(" 4 - Set state change notification on/off (Currently: " + (sayToAll ? "On" : "Off")+ ")");
- Console.WriteLine(" S - Start dynamic gravity mod");
- Console.Write("Input: ");
- ConsoleKeyInfo input = Console.ReadKey();
- Console.WriteLine();
- switch (input.Key.ToString().ToLower())
- {
- case "d1":
- case "1":
- showGravityValuesMenu();
- break;
- case "d2":
- case "2":
- showSwitchingMenu();
- break;
- case "d3":
- case "3":
- showKeybindingMenu();
- break;
- case "d4":
- case "4":
- while (true)
- {
- bool breakPeriodicLoop = false;
- Console.WriteLine("Send players a message for each state change (Y) or don't send (N):");
- ConsoleKeyInfo periodicInput = Console.ReadKey();
- switch (periodicInput.Key.ToString().ToLower())
- {
- case "n":
- breakPeriodicLoop = true;
- sayToAll = false;
- break;
- case "y":
- breakPeriodicLoop = true;
- sayToAll = true;
- break;
- default:
- Console.WriteLine();
- Console.WriteLine("Invalid choice.");
- break;
- }
- if (breakPeriodicLoop)
- {
- Console.Clear();
- break;
- }
- }
- break;
- case "s":
- breakLoop = true;
- break;
- default:
- Console.WriteLine("Invalid option.");
- continue;
- }
- if (breakLoop)
- {
- break;
- }
- }
- }
- private static void showKeybindingMenu()
- {
- Console.Clear();
- Console.WriteLine("Press a key to send to the game to trigger the in-game keybinding:");
- ConsoleKeyInfo input = Console.ReadKey();
- keybindKey = input.Key.ToString();
- }
- private static void showSwitchingMenu()
- {
- bool breakLoop = false;
- while (true)
- {
- Console.Clear();
- Console.WriteLine("Select an option to configure gravity timers:");
- Console.WriteLine(" 1 - Set periodic or random switching timers (Currently: " + (useRandomInterval ? "Random" : "Periodic") + ")");
- Console.WriteLine(" 2 - Set max time for gravity state (Currently: " + gravityTimeMax + "s)");
- Console.WriteLine(" 2 - Set min time for gravity state (Currently: " + gravityTimeMin + "s)");
- Console.WriteLine(" 3 - Set gravity up time ratio (Currently: " + gravityUpRatio + " : 1)");
- Console.WriteLine(" R - Return to previous menu");
- Console.Write("Input: ");
- ConsoleKeyInfo input = Console.ReadKey();
- Console.WriteLine();
- switch (input.Key.ToString().ToLower())
- {
- case "d1":
- case "1":
- while (true)
- {
- bool breakPeriodicLoop = false;
- Console.WriteLine("Use Periodic (P) or Random (R) gravity timers:");
- ConsoleKeyInfo periodicInput = Console.ReadKey();
- switch (periodicInput.Key.ToString().ToLower())
- {
- case "p":
- breakPeriodicLoop = true;
- useRandomInterval = false;
- break;
- case "r":
- breakPeriodicLoop = true;
- useRandomInterval = true;
- break;
- default:
- Console.WriteLine("Invalid choice.");
- break;
- }
- if (breakPeriodicLoop)
- {
- break;
- }
- }
- break;
- case "d2":
- case "2":
- while (true)
- {
- 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:");
- String timeInput = Console.ReadLine();
- float switchingTime = 0;
- if (!float.TryParse(timeInput, out switchingTime) || switchingTime < 1)
- {
- Console.WriteLine("Invalid input. Must be greater than or equal to 1 second.");
- continue;
- }
- else if (switchingTime < gravityTimeMin)
- {
- Console.WriteLine("Gravity state max time can't be less than the gravity state min time (" + gravityTimeMin + "s)");
- continue;
- }
- else
- {
- gravityTimeMax = switchingTime;
- break;
- }
- }
- break;
- case "d3":
- case "3":
- while (true)
- {
- 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.");
- String timeInput = Console.ReadLine();
- float switchingTime = 0;
- if (!float.TryParse(timeInput, out switchingTime) || switchingTime < .1)
- {
- Console.WriteLine("Invalid input. Must be greater than or equal to .1 seconds.");
- continue;
- }
- else if (switchingTime > gravityTimeMax)
- {
- Console.WriteLine("Gravity state min time can't be greater than the gravity state max time (" + gravityTimeMax + "s)");
- continue;
- }
- else
- {
- gravityTimeMin = switchingTime;
- break;
- }
- }
- break;
- case "d4":
- case "4":
- while (true)
- {
- 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: ");
- String timeInput = Console.ReadLine();
- float uptime = 0;
- if (!float.TryParse(timeInput, out uptime) || uptime < 0.01)
- {
- Console.WriteLine("Invalid input. Must be greater than or equal to 0.01");
- continue;
- }
- else
- {
- gravityUpRatio = uptime;
- break;
- }
- }
- break;
- case "r":
- breakLoop = true;
- break;
- }
- if (breakLoop)
- {
- break;
- }
- }
- }
- private static void showGravityValuesMenu()
- {
- bool breakLoop = false;
- while (true)
- {
- Console.Clear();
- Console.WriteLine("The game's default gravity is -981.");
- Console.WriteLine("Select an option to configure gravity values:");
- Console.WriteLine(" 1 - Set minimum up gravity (Currently: " + minUpGravity + ")");
- Console.WriteLine(" 2 - Set maximum up gravity (Currently: " + maxUpGravity + ")");
- Console.WriteLine(" 3 - Set minimum down gravity (Currently: " + minDownGravity + ")");
- Console.WriteLine(" 4 - Set maximum down gravity (Currently: " + maxDownGravity + ")");
- Console.WriteLine(" R - Return to previous menu");
- Console.Write("Input: ");
- ConsoleKeyInfo input = Console.ReadKey();
- Console.WriteLine();
- switch (input.Key.ToString().ToLower())
- {
- case "d1":
- case "1":
- while (true)
- {
- Console.WriteLine("Set maximum UP gravity (positive values):");
- String timeInput = Console.ReadLine();
- double maxUp = 0;
- if (!double.TryParse(timeInput, out maxUp) || maxUp < 0)
- {
- Console.WriteLine("Invalid input. Must be greater than or equal to 0.01");
- continue;
- }
- else if (maxUp < minUpGravity)
- {
- Console.WriteLine("Maximum up gravity must be greater than or equal to minimum up (" + minUpGravity + ")");
- continue;
- }
- else
- {
- maxUpGravity = maxUp;
- break;
- }
- }
- break;
- case "d2":
- case "2":
- while (true)
- {
- Console.WriteLine("Set minimum UP gravity (positive values):");
- String timeInput = Console.ReadLine();
- double minUp = 0;
- if (!double.TryParse(timeInput, out minUp) || minUp < 0)
- {
- Console.WriteLine("Invalid input. Must be greater than or equal to 0.01");
- continue;
- }
- else if (minUp > maxUpGravity)
- {
- Console.WriteLine("Minimum up gravity must be less than or equal to minimum up (" + maxUpGravity + ")");
- continue;
- }
- else
- {
- minUpGravity = minUp;
- break;
- }
- }
- break;
- case "d4":
- case "4":
- while (true)
- {
- Console.WriteLine("Set maximum DOWN gravity (negative values):");
- String timeInput = Console.ReadLine();
- double maxDown = 0;
- if (!double.TryParse(timeInput, out maxDown) || maxDown > 0)
- {
- Console.WriteLine("Invalid input. Must be less than 0.");
- continue;
- }
- else if (maxDown > minDownGravity)
- {
- Console.WriteLine("Maximum down gravity must be less than or equal to minimum down (" + minDownGravity + ")");
- continue;
- }
- else
- {
- maxDownGravity = maxDown;
- break;
- }
- }
- break;
- case "d3": //MIN DOWN
- case "3":
- while (true)
- {
- Console.WriteLine("Set minimum DOWN gravity (negative values):");
- String timeInput = Console.ReadLine();
- double minDown = 0;
- if (!double.TryParse(timeInput, out minDown) || minDown > 0)
- {
- Console.WriteLine("Invalid input. Must be less than 0.");
- continue;
- }
- else if (minDown < maxDownGravity)
- {
- Console.WriteLine("Minimum down gravity must be greater than or equal to maximium down (" + maxDownGravity + ")");
- continue;
- }
- else
- {
- minDownGravity = minDown;
- break;
- }
- }
- break;
- case "r":
- breakLoop = true;
- break;
- default:
- Console.WriteLine("Invalid choice.");
- continue;
- }
- }
- }
- private static void startGravityLoop()
- {
- Random random = new Random();
- gravityTimeMax *= 1000; //s to ms
- bool gravityUp = false;
- while (true)
- {
- gravityUp = !gravityUp;
- int sleepTime = (int)gravityTimeMax;
- if (useRandomInterval)
- {
- sleepTime = random.Next(sleepTime) + 100;
- }
- double scalar = random.NextDouble(); //picks next random value
- double gravityWindow = (gravityUp ? maxUpGravity - minUpGravity : Math.Abs(maxDownGravity) - Math.Abs(minDownGravity));
- gravityWindow *= scalar;
- if (gravityUp)
- {
- gravityWindow *= gravityUpRatio;
- }
- double gravityValue = (gravityUp ? minUpGravity + gravityWindow : minDownGravity - gravityWindow);
- String command = "SetGravity " + gravityValue;
- if (sayToAll)
- {
- command += "\bSay GRAVITY: " + gravityValue + " for " + sleepTime + "ms";
- }
- File.WriteAllText(execFile, command);
- Console.WriteLine("Gravity: " + (gravityUp ? "Up" : "Down") + " for " + sleepTime + " ms");
- Thread.Sleep(sleepTime);
- }
- }
- private static void verifyDirectory(string me3dir)
- {
- if (!Directory.Exists(me3dir))
- {
- Console.WriteLine("Directory does not exist: " + me3dir);
- endProgram(1);
- }
- me3dir += "Binaries\\";
- string masseffect3exe = me3dir + "win32\\MassEffect3.exe";
- if (!File.Exists(masseffect3exe))
- {
- Console.WriteLine("Directory specified is not the Mass Effect 3 directory:");
- Console.WriteLine("EXE would be at: " + masseffect3exe);
- endProgram(1);
- }
- execFile = me3dir + "dynamicgravity.txt";
- }
- private static void endProgram(int v)
- {
- DebugPause();
- Environment.Exit(v);
- }
- [Conditional("DEBUG")]
- public static void DebugPause()
- {
- Console.WriteLine("Press any key to exit");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement