Skip to content

Commit

Permalink
Added hotkey for quick toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Daylonz committed Oct 8, 2020
1 parent 09b63d8 commit 5cab488
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 24 deletions.
15 changes: 12 additions & 3 deletions MCCBounceEnable/src/UIForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 87 additions & 21 deletions MCCBounceEnable/src/UIForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -17,7 +18,15 @@ namespace MCCBounceEnable
{
public partial class UIForm : Form
{
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(int vKey);

private static readonly int VK_MENU = 0x12; //Alt key.
private static readonly int VK_O = 0x4F; //O key.
private DateTime lastHotkeyPress = DateTime.Now;

public readonly IMemoryPattern test = new DwordPattern("48 8B 0D ?? ?? ?? ?? F3 0F 10 49 10");
private IntPtr lastAddr = IntPtr.Zero;

byte[] value30 = { 0x1E, 0x00, 0x89, 0x88, 0x08, 0x3D };
byte[] value60 = { 0x3C, 0x00, 0x89, 0x88, 0x88, 0x3C };
Expand All @@ -44,30 +53,60 @@ private static ProcessSharp getProcess()

public void setTickrate(int desired)
{
var process = getProcess();
process.Memory = new ExternalProcessMemory(process.Handle);

PatternScanner scanner = new PatternScanner(process["halo2.dll"]);
PatternScanResult result = scanner.Find(test);
if (!result.Found)
try
{
MessageBox.Show("Could not find tick rate in memory. Make sure you're in a game!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
byte[] offset = process.Memory.Read(result.ReadAddress + 3, 4);
IntPtr addressLocation = (result.ReadAddress + 7 + BitConverter.ToInt32(offset, 0));
byte[] addressValue = process.Memory.Read(addressLocation, 8);
IntPtr tickAddress = new IntPtr(BitConverter.ToInt64(addressValue, 0) + 2);
if (desired == 30)
{
process.Memory.Write(tickAddress, value30);
MessageBox.Show("Tick rate set to 30.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
var process = getProcess();
process.Memory = new ExternalProcessMemory(process.Handle);
byte[] addressValue;
if (lastAddr != IntPtr.Zero)
{
addressValue = process.Memory.Read(lastAddr, 6);
if (!addressValue.SequenceEqual(value30) && !addressValue.SequenceEqual(value60))
{
PatternScanner scanner = new PatternScanner(process["halo2.dll"]);
PatternScanResult result = scanner.Find(test);
if (!result.Found)
{
MessageBox.Show("Could not find tick rate in memory. Make sure you're in a game!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
byte[] offset = process.Memory.Read(result.ReadAddress + 3, 4);
IntPtr addressLocation = (result.ReadAddress + 7 + BitConverter.ToInt32(offset, 0));
addressValue = process.Memory.Read(addressLocation, 8);
IntPtr tickAddress = new IntPtr(BitConverter.ToInt64(addressValue, 0) + 2);
lastAddr = tickAddress;
}
}
else
{
PatternScanner scanner = new PatternScanner(process["halo2.dll"]);
PatternScanResult result = scanner.Find(test);
if (!result.Found)
{
MessageBox.Show("Could not find tick rate in memory. Make sure you're in a game!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
byte[] offset = process.Memory.Read(result.ReadAddress + 3, 4);
IntPtr addressLocation = (result.ReadAddress + 7 + BitConverter.ToInt32(offset, 0));
addressValue = process.Memory.Read(addressLocation, 8);
IntPtr tickAddress = new IntPtr(BitConverter.ToInt64(addressValue, 0) + 2);
lastAddr = tickAddress;
}

if (desired == 30)
{
process.Memory.Write(lastAddr, value30);
}

if (desired == 60)
if (desired == 60)
{
process.Memory.Write(lastAddr, value60);
}
}
catch (Win32Exception e)
{
process.Memory.Write(tickAddress, value60);
MessageBox.Show("Tick rate set to 60.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
lastAddr = IntPtr.Zero;
setTickrate(desired);
}
}

Expand Down Expand Up @@ -97,5 +136,32 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)
setTickrate(60);
}
}

private void timer1_Tick(object sender, EventArgs e)
{
short keyState1 = GetAsyncKeyState(VK_MENU);
short keyState2 = GetAsyncKeyState(VK_O);

bool altIsPressed = ((keyState1 >> 15) & 0x0001) == 0x0001;
bool oIsPressed = ((keyState2 >> 15) & 0x0001) == 0x0001;

if (altIsPressed && oIsPressed)
{
if (DateTime.Now.Subtract(lastHotkeyPress).TotalSeconds > 1)
{
if (checkBox1.Checked)
{
setTickrate(30);
}
else
{
setTickrate(60);
}
checkBox1.Checked = !checkBox1.Checked;
System.Media.SystemSounds.Asterisk.Play();
lastHotkeyPress = DateTime.Now;
}
}
}
}
}
3 changes: 3 additions & 0 deletions MCCBounceEnable/src/UIForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down

0 comments on commit 5cab488

Please sign in to comment.