From 6769ca815e835775602d87bf223691bb95670c3b Mon Sep 17 00:00:00 2001 From: Rich Dunne Date: Sun, 6 Dec 2020 07:35:53 -0700 Subject: [PATCH] Organizational refactoring --- SceneManager/ConsoleCommands.cs | 36 ------- SceneManager/GetUserInput.cs | 67 ------------- SceneManager/MousePositionInWorld.cs | 42 --------- SceneManager/PNWUserInput.cs | 28 ------ SceneManager/RNUIMouseInputHandler.cs | 130 -------------------------- SceneManager/SceneManager.csproj | 46 ++++++--- SceneManager/SceneManager.obproj | 18 ++++ SceneManager/app.config | 23 +++++ SceneManager/packages.config | 4 + SceneManager/smprotected.crproj | 3 + 10 files changed, 81 insertions(+), 316 deletions(-) delete mode 100644 SceneManager/ConsoleCommands.cs delete mode 100644 SceneManager/GetUserInput.cs delete mode 100644 SceneManager/MousePositionInWorld.cs delete mode 100644 SceneManager/PNWUserInput.cs delete mode 100644 SceneManager/RNUIMouseInputHandler.cs create mode 100644 SceneManager/SceneManager.obproj create mode 100644 SceneManager/app.config create mode 100644 SceneManager/packages.config create mode 100644 SceneManager/smprotected.crproj diff --git a/SceneManager/ConsoleCommands.cs b/SceneManager/ConsoleCommands.cs deleted file mode 100644 index 973a978..0000000 --- a/SceneManager/ConsoleCommands.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Rage; -using Rage.Attributes; -using Rage.ConsoleCommands.AutoCompleters; -using System.Linq; - -namespace SceneManager -{ - internal static class ConsoleCommands - { - [ConsoleCommand] - internal static void Command_ShowCollectedVehicleInfo([ConsoleCommandParameter(AutoCompleterType = typeof(ConsoleCommandAutoCompleterVehicle))] Vehicle vehicle) - { - foreach(Path path in PathMainMenu.paths) - { - var collectedVehicle = path.CollectedVehicles.Where(v => v.Vehicle == vehicle).FirstOrDefault(); - if(collectedVehicle != null) - { - Game.LogTrivial($"Vehicle: {collectedVehicle.Vehicle.Model.Name} [{collectedVehicle.Vehicle.Handle}]"); - Rage.Native.NativeFunction.Natives.xA6E9C38DB51D7748(collectedVehicle.Vehicle, out uint script); - Game.LogTrivial($"Vehicle spawned by: {script}"); - Game.LogTrivial($"Driver handle: {collectedVehicle.Driver.Handle}"); - Game.LogTrivial($"Path: {collectedVehicle.Path.Number}"); - Game.LogTrivial($"Current waypoint: {collectedVehicle.CurrentWaypoint.Number}"); - Game.LogTrivial($"StoppedAtWaypoint: {collectedVehicle.StoppedAtWaypoint}"); - Game.LogTrivial($"SkipWaypoint: {collectedVehicle.SkipWaypoint}"); - Game.LogTrivial($"ReadyForDirectTasks: {collectedVehicle.ReadyForDirectTasks}"); - Game.LogTrivial($"Directed: {collectedVehicle.Directed}"); - Game.LogTrivial($"Dismissed: {collectedVehicle.Dismissed}"); - Game.LogTrivial($"Task status: {collectedVehicle.Driver.Tasks.CurrentTaskStatus}"); - return; - } - } - Game.LogTrivial($"{vehicle.Model.Name} [{vehicle.Handle}] was not found collected by any path."); - } - } -} diff --git a/SceneManager/GetUserInput.cs b/SceneManager/GetUserInput.cs deleted file mode 100644 index 3cfb264..0000000 --- a/SceneManager/GetUserInput.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Rage; - -namespace SceneManager -{ - class GetUserInput - { - internal static void LoopForUserInput() - { - while (true) - { - GetKeyboardInput(); - GetControllerInput(); - -#if DEBUG - if (MenuManager.menuPool.IsAnyMenuOpen()) - { - Game.DisplaySubtitle($"You are using a test build of Scene Manager. Please report any bugs/crashes in the Discord server."); - } -#endif - MenuManager.menuPool.ProcessMenus(); - GameFiber.Yield(); - } - } - - private static void GetControllerInput() - { - if (Settings.ModifierButton == ControllerButtons.None) - { - if (Game.IsControllerButtonDown(Settings.ToggleButton) && AreMenusClosed()) - { - MainMenu.mainMenu.Visible = !MainMenu.mainMenu.Visible; - } - } - else if (Game.IsControllerButtonDownRightNow(Settings.ModifierButton) && Game.IsControllerButtonDown(Settings.ToggleButton) && AreMenusClosed()) - { - MainMenu.mainMenu.Visible = !MainMenu.mainMenu.Visible; - } - } - - private static void GetKeyboardInput() - { - if (Settings.ModifierKey == System.Windows.Forms.Keys.None) - { - if (Game.IsKeyDown(Settings.ToggleKey) && AreMenusClosed()) - { - MainMenu.mainMenu.Visible = !MainMenu.mainMenu.Visible; - } - } - else if (Game.IsKeyDownRightNow(Settings.ModifierKey) && Game.IsKeyDown(Settings.ToggleKey) && AreMenusClosed()) - { - MainMenu.mainMenu.Visible = !MainMenu.mainMenu.Visible; - } - } - - private static bool AreMenusClosed() - { - if(!BarrierMenu.barrierMenu.Visible && !PathMainMenu.pathMainMenu.Visible && !PathCreationMenu.pathCreationMenu.Visible && !EditPathMenu.editPathMenu.Visible && !EditWaypointMenu.editWaypointMenu.Visible && !SettingsMenu.settingsMenu.Visible) - { - return true; - } - else - { - return false; - } - } - } -} diff --git a/SceneManager/MousePositionInWorld.cs b/SceneManager/MousePositionInWorld.cs deleted file mode 100644 index 5d1b9e5..0000000 --- a/SceneManager/MousePositionInWorld.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Rage; -using RAGENativeUI.Elements; - -namespace SceneManager -{ - internal static class MousePositionInWorld - { - internal static Vector3 GetPosition { get { return GetMousePositionInWorld(); } } - internal static Vector3 GetPositionForBarrier { get { return GetMousePositionInWorld(Settings.BarrierPlacementDistance); } } - - private static Vector3 GetMousePositionInWorld(float maxDistance = 100f) - { - HitResult TracePlayerView(float maxTraceDistance = 100f, TraceFlags flags = TraceFlags.IntersectWorld) => TracePlayerView2(out Vector3 v1, out Vector3 v2, maxTraceDistance, flags); - - HitResult TracePlayerView2(out Vector3 start, out Vector3 end, float maxTraceDistance, TraceFlags flags) - { - Vector3 direction = GetPlayerLookingDirection(out start); - end = start + (maxTraceDistance * direction); - return World.TraceLine(start, end, flags); - } - - Vector3 GetPlayerLookingDirection(out Vector3 camPosition) - { - if (Camera.RenderingCamera) - { - camPosition = Camera.RenderingCamera.Position; - return Camera.RenderingCamera.Direction; - } - else - { - float pitch = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_PITCH(); - float heading = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_RELATIVE_HEADING(); - - camPosition = Rage.Native.NativeFunction.Natives.GET_GAMEPLAY_CAM_COORD(); - return (Game.LocalPlayer.Character.Rotation + new Rotator(pitch, 0, heading)).ToVector().ToNormalized(); - } - } - - return TracePlayerView(maxDistance, TraceFlags.IntersectWorld).HitPosition; - } - } -} diff --git a/SceneManager/PNWUserInput.cs b/SceneManager/PNWUserInput.cs deleted file mode 100644 index 92268e1..0000000 --- a/SceneManager/PNWUserInput.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Rage; -using Rage.Native; - -namespace SceneManager -{ - internal static class PNWUserInput - { - public static string GetUserInput(string windowTitle, string defaultText, int maxLength) - { - NativeFunction.Natives.DISABLE_ALL_CONTROL_ACTIONS(2); - - NativeFunction.Natives.DISPLAY_ONSCREEN_KEYBOARD(true, windowTitle, 0, defaultText, 0, 0, 0, maxLength); - Game.DisplayHelp("Enter the filename you would like to save your path as\n~INPUT_FRONTEND_ACCEPT~ Export path\n~INPUT_FRONTEND_CANCEL~ Cancel", true); - Game.DisplaySubtitle(windowTitle, 100000); - - while (NativeFunction.Natives.UPDATE_ONSCREEN_KEYBOARD() == 0) - { - GameFiber.Yield(); - } - - NativeFunction.Natives.ENABLE_ALL_CONTROL_ACTIONS(2); - Game.DisplaySubtitle("", 5); - Game.HideHelp(); - - return NativeFunction.Natives.GET_ONSCREEN_KEYBOARD_RESULT(); - } - } -} \ No newline at end of file diff --git a/SceneManager/RNUIMouseInputHandler.cs b/SceneManager/RNUIMouseInputHandler.cs deleted file mode 100644 index 5fb2457..0000000 --- a/SceneManager/RNUIMouseInputHandler.cs +++ /dev/null @@ -1,130 +0,0 @@ -using InputManager; -using Rage; -using RAGENativeUI; -using RAGENativeUI.Elements; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Forms; - -namespace SceneManager -{ - internal class RNUIMouseInputHandler - { - internal delegate void Function(); - - internal static void Initialize(UIMenu menu, List scrollerItems) - { - GameFiber.StartNew(() => - { - while (menu.Visible) - { - var selectedScroller = menu.MenuItems.Where(x => scrollerItems.Contains(x) && x.Selected && x.Enabled).FirstOrDefault(); - if (selectedScroller != null) - { - OnWheelScroll(menu, selectedScroller, scrollerItems); - } - - if (Game.IsKeyDown(Keys.LButton) && Rage.Native.NativeFunction.Natives.UPDATE_ONSCREEN_KEYBOARD() != 0) - { - Keyboard.KeyDown(Keys.Enter); - GameFiber.Wait(1); - Keyboard.KeyUp(Keys.Enter); - } - - if (menu.SubtitleText.Contains("Path Creation Menu")) - { - DrawWaypointMarker(); - } - GameFiber.Yield(); - } - }); - } - - internal static void OnWheelScroll(UIMenu menu, UIMenuItem selectedScroller, List scrollerItems) - { - var menuScrollingDisabled = false; - var menuItems = menu.MenuItems.Where(x => x != selectedScroller); - - while (Game.IsShiftKeyDownRightNow) - { - menu.ResetKey(Common.MenuControls.Up); - menu.ResetKey(Common.MenuControls.Down); - menuScrollingDisabled = true; - ScrollMenuItem(); - if (menu.SubtitleText.Contains("Path Creation Menu") || menu.SubtitleText.Contains("Edit Waypoint")) - { - CompareScrollerValues(); - } - if(menu.SubtitleText.Contains("Path Creation Menu")) - { - DrawWaypointMarker(); - } - GameFiber.Yield(); - } - - if (menuScrollingDisabled) - { - menuScrollingDisabled = false; - menu.SetKey(Common.MenuControls.Up, GameControl.CursorScrollUp); - menu.SetKey(Common.MenuControls.Up, GameControl.CellphoneUp); - menu.SetKey(Common.MenuControls.Down, GameControl.CursorScrollDown); - menu.SetKey(Common.MenuControls.Down, GameControl.CellphoneDown); - } - - void ScrollMenuItem() - { - if (Game.GetMouseWheelDelta() > 0) - { - Keyboard.KeyDown(Keys.Right); - GameFiber.Wait(1); - Keyboard.KeyUp(Keys.Right); - } - else if (Game.GetMouseWheelDelta() < 0) - { - Keyboard.KeyDown(Keys.Left); - GameFiber.Wait(1); - Keyboard.KeyUp(Keys.Left); - } - } - - void CompareScrollerValues() - { - var collectorRadius = (UIMenuNumericScrollerItem)scrollerItems.Where(x => x.Text == "Collection Radius").FirstOrDefault(); - var speedZoneRadius = (UIMenuNumericScrollerItem)scrollerItems.Where(x => x.Text == "Speed Zone Radius").FirstOrDefault(); - - if (selectedScroller.Text == "Collection Radius" || selectedScroller.Text == "Speed Zone Radius") - { - if (selectedScroller == collectorRadius && collectorRadius.Value > speedZoneRadius.Value) - { - while (collectorRadius.Value > speedZoneRadius.Value) - { - speedZoneRadius.ScrollToNextOption(); - } - } - if (selectedScroller == speedZoneRadius && speedZoneRadius.Value < collectorRadius.Value) - { - collectorRadius.Value = speedZoneRadius.Value; - } - } - } - } - - private static void DrawWaypointMarker() - { - var waypointPosition = MousePositionInWorld.GetPosition; - if (SettingsMenu.threeDWaypoints.Checked && PathCreationMenu.collectorWaypoint.Checked) - { - Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, waypointPosition, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.collectorRadius.Value * 2, (float)PathCreationMenu.collectorRadius.Value * 2, 1f, 80, 130, 255, 80, false, false, 2, false, 0, 0, false); - Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, waypointPosition, 0, 0, 0, 0, 0, 0, (float)PathCreationMenu.speedZoneRadius.Value * 2, (float)PathCreationMenu.speedZoneRadius.Value * 2, 1f, 255, 185, 80, 80, false, false, 2, false, 0, 0, false); - } - else if (PathCreationMenu.stopWaypointType.Checked) - { - Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, waypointPosition, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 255, 65, 65, 80, false, false, 2, false, 0, 0, false); - } - else - { - Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, waypointPosition, 0, 0, 0, 0, 0, 0, 1f, 1f, 1f, 65, 255, 65, 80, false, false, 2, false, 0, 0, false); - } - } - } -} diff --git a/SceneManager/SceneManager.csproj b/SceneManager/SceneManager.csproj index 8b24f01..8181199 100644 --- a/SceneManager/SceneManager.csproj +++ b/SceneManager/SceneManager.csproj @@ -12,6 +12,8 @@ v4.8 512 true + + true @@ -32,20 +34,28 @@ - False - bin\Debug\InputManager.dll + ..\packages\InputManager.1.0.0\lib\InputManager.dll D:\Program Files\Rockstar Games\Grand Theft Auto V\RAGENativeUI.dll + False - - D:\Program Files\Rockstar Games\Grand Theft Auto V\plugins\LSPDFR\RagePluginHookSDK.dll + + ..\..\Modding Resources\References\RagePluginHook.dll + False + + + + + + + @@ -54,27 +64,37 @@ - - - - + + + + + + - + - + - + + - + - + + + + + + + + \ No newline at end of file diff --git a/SceneManager/SceneManager.obproj b/SceneManager/SceneManager.obproj new file mode 100644 index 0000000..3bb39c5 --- /dev/null +++ b/SceneManager/SceneManager.obproj @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SceneManager/app.config b/SceneManager/app.config new file mode 100644 index 0000000..fbfff6f --- /dev/null +++ b/SceneManager/app.config @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SceneManager/packages.config b/SceneManager/packages.config new file mode 100644 index 0000000..9eb48c7 --- /dev/null +++ b/SceneManager/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/SceneManager/smprotected.crproj b/SceneManager/smprotected.crproj new file mode 100644 index 0000000..5982c27 --- /dev/null +++ b/SceneManager/smprotected.crproj @@ -0,0 +1,3 @@ + + + \ No newline at end of file