Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
- Add main menu
- Add level switcher
- Fix locks in TextureViewer and Menu
  • Loading branch information
spitfirex86 committed Jan 7, 2020
1 parent a7c2b32 commit 9f0b7fc
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 55 deletions.
3 changes: 3 additions & 0 deletions OverRay.Hook/GameFunctions/InputFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
77 changes: 52 additions & 25 deletions OverRay.Hook/Mod/GameManager.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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<MenuItem> items = new List<MenuItem>();

private Hud Hud { get; }
foreach (KeyValuePair<string, Dictionary<string, string>> level in OtherUtils.Levels)
{
List<MenuItem> subItems = new List<MenuItem>();

private Menu TestMenu { get; }
foreach (KeyValuePair<string, string> 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());
}
}
}
21 changes: 11 additions & 10 deletions OverRay.Hook/Mod/Hud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,17 @@ private void DrawTarget()
EngineObject engineObject = Marshal.PtrToStructure<EngineObject>(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()

Expand Down
33 changes: 21 additions & 12 deletions OverRay.Hook/Mod/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ public Menu(GameManager manager, params MenuItem[] items)
Manager = manager;
Items = new List<MenuItem>(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)
Expand All @@ -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<MenuItem> Items { get; }

Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
}
8 changes: 4 additions & 4 deletions OverRay.Hook/Mod/TextureViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions OverRay.Hook/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Loading

0 comments on commit 9f0b7fc

Please sign in to comment.