From 9f0b7fcfb6c63070049f9ce5e86305c4fae4eb69 Mon Sep 17 00:00:00 2001 From: Spitfire_x86 Date: Tue, 7 Jan 2020 01:03:45 +0100 Subject: [PATCH] v0.3.0 - Add main menu - Add level switcher - Fix locks in TextureViewer and Menu --- OverRay.Hook/GameFunctions/InputFunctions.cs | 3 + OverRay.Hook/Mod/GameManager.cs | 77 +++++++--- OverRay.Hook/Mod/Hud.cs | 21 +-- OverRay.Hook/Mod/Menu.cs | 33 ++-- OverRay.Hook/Mod/TextureViewer.cs | 8 +- OverRay.Hook/Properties/AssemblyInfo.cs | 4 +- OverRay.Hook/Utils/OtherUtils.cs | 153 +++++++++++++++++++ OverRay.UI/Properties/AssemblyInfo.cs | 4 +- 8 files changed, 248 insertions(+), 55 deletions(-) diff --git a/OverRay.Hook/GameFunctions/InputFunctions.cs b/OverRay.Hook/GameFunctions/InputFunctions.cs index 74eb07a..dedabee 100644 --- a/OverRay.Hook/GameFunctions/InputFunctions.cs +++ b/OverRay.Hook/GameFunctions/InputFunctions.cs @@ -35,6 +35,9 @@ private short HVirtualKeyToAscii(byte ch, int a2) Detour.Interface.WriteLog($"VirtualKeyToAscii result: {(char)result}, char: {ch}, a2: {a2}"); + // Prevent custom binds from activating on pause screen + if (Marshal.ReadByte((IntPtr) 0x500faa) != 0) return result; + if (ExclusiveInput == null) { lock (InputActions) diff --git a/OverRay.Hook/Mod/GameManager.cs b/OverRay.Hook/Mod/GameManager.cs index 4335d77..a012e4a 100644 --- a/OverRay.Hook/Mod/GameManager.cs +++ b/OverRay.Hook/Mod/GameManager.cs @@ -1,9 +1,8 @@ -using System; +using OverRay.Hook.GameFunctions; +using OverRay.Hook.Utils; +using System; using System.Collections.Generic; using System.Runtime.InteropServices; -using OverRay.Hook.GameFunctions; -using OverRay.Hook.Types; -using OverRay.Hook.Utils; namespace OverRay.Hook.Mod { @@ -16,46 +15,74 @@ public GameManager() Hud = new Hud(this); Hud.InitializeHud(); - // menu test - do not delete until menu system is finished + InitMainMenu(); + } + + public EngineFunctions Engine { get; } = new EngineFunctions(); + public GfxFunctions Graphics { get; } = new GfxFunctions(); + public TextFunctions Text { get; } = new TextFunctions(); + public InputFunctions Input { get; } = new InputFunctions(); + + private Hud Hud { get; } + + private Menu MainMenu { get; set; } + private Menu LevelMenu { get; set; } + + private void InitHooks() + { + // Create all hooks here + Engine.VEngine.CreateHook(); + Text.DrawsTexts.CreateHook(); + Input.VirtualKeyToAscii.CreateHook(); + } + + private void InitMainMenu() + { + IntPtr purpleFistPtr = Memory.GetPointerAtOffset((IntPtr)0x4B730C, 0x274, 0x790, 0x0, 0x4, 0x574); + IntPtr glowFistPtr = Memory.GetPointerAtOffset((IntPtr)0x4B730C, 0x274, 0x790, 0x0, 0x4, 0x578); - IntPtr purpleFistPtr = Memory.GetPointerAtOffset((IntPtr) 0x4B730C, 0x274, 0x790, 0x0, 0x4, 0x574); - IntPtr glowFistPtr = Memory.GetPointerAtOffset((IntPtr) 0x4B730C, 0x274, 0x790, 0x0, 0x4, 0x578); + InitLevelMenu(); - TestMenu = new Menu(this, - new MenuItem("go to learn30", () => Engine.AskToChangeLevel.Call("learn_30", 0)), - new MenuItem("purple lum power", new Menu(this, + MainMenu = new Menu(this, + new MenuItem("Change Level", LevelMenu), + new MenuItem("Purple Lum Power", new Menu(this, new MenuItem("on", () => Marshal.WriteByte(purpleFistPtr, 0x40)), new MenuItem("off", () => Marshal.WriteByte(purpleFistPtr, 0)) )), - new MenuItem("glowfist power", new Menu(this, + new MenuItem("Glowfist Power", new Menu(this, new MenuItem("on", () => Marshal.WriteInt32(glowFistPtr, 0x400000)), new MenuItem("off", () => Marshal.WriteInt32(glowFistPtr, 0)) )), - new MenuItem("texture viewer", () => + new MenuItem("Texture Viewer", () => { TextureViewer viewer = new TextureViewer(this); viewer.Show(); }) ); - Input.InputActions['m'] = () => TestMenu.Show(); + lock (Input.InputActions) Input.InputActions['m'] = () => MainMenu.Show(); + lock (Text.TextActions) Text.TextActions["menutip"] = () => Text.CustomText("M".Yellow() + " - menu", 9, 850, 970); } - public EngineFunctions Engine { get; } = new EngineFunctions(); - public GfxFunctions Graphics { get; } = new GfxFunctions(); - public TextFunctions Text { get; } = new TextFunctions(); - public InputFunctions Input { get; } = new InputFunctions(); + private void InitLevelMenu() + { + List items = new List(); - private Hud Hud { get; } + foreach (KeyValuePair> level in OtherUtils.Levels) + { + List subItems = new List(); - private Menu TestMenu { get; } + foreach (KeyValuePair section in level.Value) + subItems.Add(new MenuItem(section.Key, () => Engine.AskToChangeLevel.Call(section.Value, 0))); - private void InitHooks() - { - // Create all hooks here - Engine.VEngine.CreateHook(); - Text.DrawsTexts.CreateHook(); - Input.VirtualKeyToAscii.CreateHook(); + items.Add( + subItems.Count == 1 + ? new MenuItem(level.Key, subItems[0].Action) + : new MenuItem(level.Key, new Menu(this, subItems.ToArray())) + ); + } + + LevelMenu = new Menu(this, items.ToArray()); } } } \ No newline at end of file diff --git a/OverRay.Hook/Mod/Hud.cs b/OverRay.Hook/Mod/Hud.cs index 20a9ec4..4600801 100644 --- a/OverRay.Hook/Mod/Hud.cs +++ b/OverRay.Hook/Mod/Hud.cs @@ -92,16 +92,17 @@ private void DrawTarget() EngineObject engineObject = Marshal.PtrToStructure(raymanSPO.engineObjectPtr); int stdGame = (int)engineObject.stdGamePtr; - int[] interp = new int[] {0x00000071, 0x03020000, // Func_CibleLaPlusProcheavecAngles(, 1, 1, 10, Func_GetPersoSighting(), 160f, 40f); - 0x00000020, 0x0C030000, // 32, - 0x00000014, 0x0C030000, // 20, - 0x00000002, 0x0C030000, // 2, - 0x00000001, 0x0C030000, // 1, - 0x000000A3, 0x03030000, // Func_GetPersoSighting(), - 0x420C0000, 0x0D030000, // 35f - 0x420C0000, 0x0D030000, // 35f - 0x00000000, 0x00010000, - }; + int[] interp = { + 0x00000071, 0x03020000, // Func_CibleLaPlusProcheavecAngles(, 1, 1, 10, Func_GetPersoSighting(), 160f, 40f); + 0x00000020, 0x0C030000, // 32, + 0x00000014, 0x0C030000, // 20, + 0x00000002, 0x0C030000, // 2, + 0x00000001, 0x0C030000, // 1, + 0x000000A3, 0x03030000, // Func_GetPersoSighting(), + 0x420C0000, 0x0D030000, // 35f + 0x420C0000, 0x0D030000, // 35f + 0x00000000, 0x00010000, + }; // TODO: use ArrayPtr() diff --git a/OverRay.Hook/Mod/Menu.cs b/OverRay.Hook/Mod/Menu.cs index a894b2c..241094a 100644 --- a/OverRay.Hook/Mod/Menu.cs +++ b/OverRay.Hook/Mod/Menu.cs @@ -13,12 +13,7 @@ public Menu(GameManager manager, params MenuItem[] items) Manager = manager; Items = new List(items); - foreach (MenuItem item in items) - { - int itemWidth = item.Name.Length * 2; - if (itemWidth > Width) - Width = itemWidth; - } + Width = CalculateWidth(); } public Menu(GameManager manager, Vector3 position, float width, params MenuItem[] items) : this(manager, items) @@ -27,11 +22,12 @@ public Menu(GameManager manager, Vector3 position, float width, params MenuItem[ Width = width; } - private string Id { get; } = Guid.NewGuid().ToString(); private GameManager Manager { get; } - private Menu ParentMenu { get; set; } + private string Id { get; } = Guid.NewGuid().ToString(); + private Vector3 Position { get; } = new Vector3 { X=3, Y=10, Z=0 }; private float Width { get; } + private Menu ParentMenu { get; set; } public List Items { get; } @@ -54,14 +50,14 @@ public void Show(Menu parentMenu = null) Manager.Input.DisableGameInput(); Manager.Input.ExclusiveInput = ProcessInput; - Manager.Engine.EngineActions[Id] = DrawGraphics; - Manager.Text.TextActions[Id] = DrawText; + lock (Manager.Engine.EngineActions) Manager.Engine.EngineActions[Id] = DrawGraphics; + lock (Manager.Text.TextActions) Manager.Text.TextActions[Id] = DrawText; } public void Hide() { - Manager.Engine.EngineActions.Remove(Id); - Manager.Text.TextActions.Remove(Id); + lock (Manager.Engine.EngineActions) Manager.Engine.EngineActions.Remove(Id); + lock (Manager.Text.TextActions) Manager.Text.TextActions.Remove(Id); Manager.Input.ExclusiveInput = null; Manager.Input.EnableGameInput(); @@ -106,5 +102,18 @@ private void DrawText() Manager.Text.CustomText(i == Selected ? Items[i].Name.Yellow(): Items[i].Name, 9, (Position.X + 1) * 10, (Position.Y + 2 + i * 4) * 10); } } + + private int CalculateWidth() + { + int newWidth = 0; + foreach (MenuItem item in Items) + { + int itemWidth = item.Name.Length * 2; + if (itemWidth > newWidth) + newWidth = itemWidth; + } + + return newWidth; + } } } \ No newline at end of file diff --git a/OverRay.Hook/Mod/TextureViewer.cs b/OverRay.Hook/Mod/TextureViewer.cs index 61b094d..eec73c0 100644 --- a/OverRay.Hook/Mod/TextureViewer.cs +++ b/OverRay.Hook/Mod/TextureViewer.cs @@ -40,18 +40,18 @@ public void Show() Manager.Input.DisableGameInput(); Manager.Input.ExclusiveInput = ProcessInput; - Manager.Engine.EngineActions[Id] = DrawGraphics; - Manager.Text.TextActions[Id] = DrawText; + lock (Manager.Engine.EngineActions) Manager.Engine.EngineActions[Id] = DrawGraphics; + lock (Manager.Text.TextActions) Manager.Text.TextActions[Id] = DrawText; } public void Hide() { - Manager.Engine.EngineActions[Id] = () => + lock (Manager.Engine.EngineActions) Manager.Engine.EngineActions[Id] = () => { DrawEmptyParticle(); Manager.Engine.EngineActions.Remove(Id); }; - Manager.Text.TextActions.Remove(Id); + lock (Manager.Text.TextActions) Manager.Text.TextActions.Remove(Id); Manager.Input.ExclusiveInput = null; Manager.Input.EnableGameInput(); diff --git a/OverRay.Hook/Properties/AssemblyInfo.cs b/OverRay.Hook/Properties/AssemblyInfo.cs index 1da8a8b..09b4523 100644 --- a/OverRay.Hook/Properties/AssemblyInfo.cs +++ b/OverRay.Hook/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.1.0")] -[assembly: AssemblyFileVersion("0.2.1.0")] +[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyFileVersion("0.3.0.0")] diff --git a/OverRay.Hook/Utils/OtherUtils.cs b/OverRay.Hook/Utils/OtherUtils.cs index 1181aef..dd60ad3 100644 --- a/OverRay.Hook/Utils/OtherUtils.cs +++ b/OverRay.Hook/Utils/OtherUtils.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace OverRay.Hook.Utils { @@ -7,5 +8,157 @@ public static class OtherUtils public static Version Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; public static string GetVersion = $"{Version.Major}.{Version.Minor}.{Version.Build}"; + + public static Dictionary> Levels = new Dictionary> + { + { + "Woods of Light", new Dictionary + { + { "Jail", "jail_20" }, + { "Woods of Light", "learn_10" } + } + }, + { + "Fairy Glade", new Dictionary + { + { "Section 1", "learn_30" }, + { "Section 2", "learn_31" }, + { "Section 3", "bast_20" }, + { "Section 4", "bast_22" }, + { "Section 5", "learn_60" }, + } + }, + { + "Marshes of Awakening", new Dictionary + { + { "Section 1", "ski_10" }, + { "Section 2", "ski_60" }, + } + }, + { + "Bayou", new Dictionary + { + { "Section 1", "chase_10" }, + { "Section 2", "chase_22" }, + } + }, + { + "Sanctuary of Water and Ice", new Dictionary + { + { "Section 1", "water_10" }, + { "Section 2", "water_20" }, + } + }, + { + "Menhir Hills", new Dictionary + { + { "Section 1", "rodeo_10" }, + { "Section 2", "rodeo_40" }, + { "Section 3", "rodeo_60" }, + } + }, + { + "Cave of Bad Dreams", new Dictionary + { + { "Section 1", "vulca_10" }, + { "Section 2", "vulca_20" }, + } + }, + { + "Canopy", new Dictionary + { + { "Section 1", "glob_30" }, + { "Section 2", "glob_10" }, + { "Section 3", "glob_20" }, + } + }, + { + "Whale Bay", new Dictionary + { + { "Section 1", "whale_00" }, + { "Section 2", "whale_05" }, + { "Section 3", "whale_10" }, + } + }, + { + "Sanctuary of Stone and Fire", new Dictionary + { + { "Section 1", "plum_00" }, + { "Section 2", "plum_20" }, + { "Section 3", "plum_10" }, + } + }, + { + "Echoing Caves", new Dictionary + { + { "Section 1", "bast_10" }, + { "Section 2", "cask_10" }, + { "Section 3", "cask_30" }, + } + }, + { + "Precipice", new Dictionary + { + { "Section 1", "nave_10" }, + { "Section 2", "nave_15" }, + { "Section 3", "nave_20" }, + } + }, + { + "Top of the World", new Dictionary + { + { "Section 1", "seat_10" }, + { "Section 2", "seat_11" }, + } + }, + { + "Sanctuary of Rock and Lava", new Dictionary + { + { "Section 1", "earth_10" }, + { "Section 2", "earth_20" }, + { "Section 3", "earth_30" }, + } + }, + { + "Beneath the Sanctuary of RnL", new Dictionary + { + { "Section 1", "helic_10" }, + { "Section 2", "helic_20" }, + { "Section 3", "helic_30" }, + } + }, + { + "Tomb of the Ancients", new Dictionary + { + { "Section 1", "morb_00" }, + { "Section 2", "morb_10" }, + { "Section 3", "morb_20" }, + } + }, + { + "Iron Mountains", new Dictionary + { + { "Section 1", "learn_40" }, + { "Section 2", "ile_10" }, + { "Section 3", "mine_10" }, + } + }, + { + "Prison Ship", new Dictionary + { + { "Section 1", "boat01" }, + { "Section 2", "boat02" }, + { "Section 3", "astro_00" }, + { "Section 4", "astro_10" }, + } + }, + { + "The Crow's Nest", new Dictionary + { + { "Section 1", "rhop_10" }, + } + }, + + }; } } \ No newline at end of file diff --git a/OverRay.UI/Properties/AssemblyInfo.cs b/OverRay.UI/Properties/AssemblyInfo.cs index aaecba7..9da0816 100644 --- a/OverRay.UI/Properties/AssemblyInfo.cs +++ b/OverRay.UI/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.1.0")] -[assembly: AssemblyFileVersion("0.1.1.0")] +[assembly: AssemblyVersion("0.2.0.0")] +[assembly: AssemblyFileVersion("0.2.0.0")]