Skip to content

Commit

Permalink
v1.1 Minor fixes and improvements
Browse files Browse the repository at this point in the history
* Fps and fov had to be updated continuously.
* QoL feature: no need to restart.
  • Loading branch information
andersblomqvist committed Aug 15, 2022
1 parent 8746f64 commit 3db5520
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 14 deletions.
2 changes: 1 addition & 1 deletion App/AppForm.Designer.cs

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

57 changes: 49 additions & 8 deletions App/AppForm.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using mw2_fps_unlocker.Memory;
using mw2_fps_unlocker.App;
using System.ComponentModel;

namespace mw2_fps_unlocker
{
public partial class AppForm : Form
{
private MemoryHandler? mem;
private readonly ProcessHandler proc;

private bool ingame = false;

private readonly TrackBarWithoutFocus trackBarFPS;
private readonly TrackBarWithoutFocus trackBarFOV;

private BackgroundWorker updater;
public AppForm()
{
InitializeComponent();
Expand All @@ -37,34 +40,72 @@ public AppForm()
this.Controls.Add(trackBarFPS);
this.Controls.Add(trackBarFOV);

_ = new ProcessHandler("iw4mp", (mw2) =>
proc = new ProcessHandler();

updater = new BackgroundWorker();
updater.DoWork += Updater_DoWork;

FindProcess();
}

private void FindProcess()
{
proc.FindByName("iw4mp", (mw2) =>
{
Invoke(new Action(() =>
{
LabelStatusValue.Text = "MW2 Started";
LabelStatusValue.ForeColor = Color.Green;
mem = new MemoryHandler(mw2.Handle);
ingame = true;

SetFPS();
SetFOV();
updater.RunWorkerAsync();
}));
});
}

/// <summary>
/// We need to constantly write the FPS and FOV change. Otherwise
/// it resets back to normal by mw2.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Updater_DoWork(object? sender, DoWorkEventArgs e)
{
LabelStatusValue.Text = "MW2 Started";
LabelStatusValue.ForeColor = Color.Green;

while (proc.IsRunning())
{
SetFPS();
SetFOV();
Thread.Sleep(250);
}

LabelStatusValue.Text = "Not In-game";
LabelStatusValue.ForeColor = Color.RoyalBlue;

// Start the Find Process routine so we don't need to restart
// the app.
FindProcess();
}

private void SetFPS()
{
if (mem == null)
return;

mem.WriteInteger(mem.ReadInteger(0x01B907B0, 4) + 0xC, trackBarFPS.Value);
mem.WriteInteger(
mem.ReadInteger(0x01B907B0, 4) + 0xC,
trackBarFPS.Value
);
}
private void SetFOV()
{
if (mem == null)
return;

mem.WriteFloat(mem.ReadInteger(0x00AAC278, 4) + 0xC, trackBarFOV.Value);
mem.WriteFloat(
mem.ReadInteger(0x00AAC278, 4) + 0xC,
trackBarFOV.Value
);
}

private void TrackBarFPS_Scroll(object? sender, EventArgs e)
Expand Down
26 changes: 23 additions & 3 deletions Memory/ProcessHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ namespace mw2_fps_unlocker.Memory
{
internal class ProcessHandler
{
private readonly BackgroundWorker thread;

public delegate void ProcessFoundCallback(Process proc);

private BackgroundWorker thread;

private ProcessFoundCallback processFoundCallback;
private Process? proc;
private string processName;

public ProcessHandler() {}

/// <summary>
/// Find a process by name. When the process is found this will call the
Expand All @@ -21,7 +24,7 @@ internal class ProcessHandler
/// </summary>
/// <param name="processName"></param>
/// <param name="callback"></param>
public ProcessHandler(string processName, ProcessFoundCallback callback)
internal void FindByName(string processName, ProcessFoundCallback callback)
{
this.processName = processName;
processFoundCallback = callback;
Expand Down Expand Up @@ -54,5 +57,22 @@ private bool GetProcessByName(string processName, [NotNullWhen(true)] out Proces
return false;
}
}

/// <summary>
/// Checks whether the process is currently running or not.
/// </summary>
/// <returns>True if running</returns>
internal bool IsRunning()
{
if(proc != null)
{
if (GetProcessByName(proc.ProcessName, out _))
return true;
else
return false;

}
return false;
}
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Tool for changing the max fps and fov for mw2 because they do not provide it.

1. Download the exe file from releases: [https://github.com/andersblomqvist/mw2-fps-unlocker/releases/tag/1.0](https://github.com/andersblomqvist/mw2-fps-unlocker/releases/tag/1.0)
1. Download the exe file from releases: [https://github.com/andersblomqvist/mw2-fps-unlocker/releases/tag/v1.1](https://github.com/andersblomqvist/mw2-fps-unlocker/releases/tag/v1.1)
2. Start FPS Unlocker
3. Start MW2 through steam
4. Change sliders to your preference
Expand All @@ -13,4 +13,4 @@ Tool for changing the max fps and fov for mw2 because they do not provide it.

## Notes

No recorded vac-bans. If you close MW2, you have to restart the fps unlocker aswell.
No recorded vac-bans. Use at your own risk.
2 changes: 2 additions & 0 deletions mw2-fps-unlocker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<Authors>Branders</Authors>
<Product>MW2 FPS Unlocker</Product>
<StartupObject></StartupObject>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 3db5520

Please sign in to comment.