Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

Commit

Permalink
Fixed OverflowException with the enemy HP bars.
Browse files Browse the repository at this point in the history
Added initial code for DirectX overlay.
  • Loading branch information
Squirrelies committed Feb 25, 2019
1 parent 0ebc416 commit d5004d8
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 26 deletions.
2 changes: 1 addition & 1 deletion RE2REmakeSRT/AttachUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private void ProcessPollingTimer_Elapsed(object sender, System.Timers.ElapsedEve
{
try
{
Program.GetProcessPid();
Program.GetProcessInfo();
}
finally
{
Expand Down
101 changes: 101 additions & 0 deletions RE2REmakeSRT/DXOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using GameOverlay.Drawing;
using GameOverlay.Windows;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace RE2REmakeSRT
{
public class DXOverlay : IDXOverlay
{
private IntPtr windowHook;
private OverlayWindow _window;
private Graphics _graphics;

public DXOverlay(IntPtr windowHook)
{
this.windowHook = windowHook;

// it is important to set the window to visible (and topmost) if you want to see it!
_window = new OverlayWindow()
{
IsVisible = true,
IsTopmost = true
};

// initialize a new Graphics object
// set everything before you call _graphics.Setup()
_graphics = new Graphics()
{
MeasureFPS = false,
PerPrimitiveAntiAliasing = false,
TextAntiAliasing = true,
UseMultiThreadedFactories = false,
VSync = false
};
}

~DXOverlay()
{
// dont forget to free resources
_graphics.Dispose();
_window.Dispose();
}

public void Initialize(Action<OverlayWindow, Graphics> initMethod)
{
_window.CreateWindow();
_window.FitToWindow(windowHook, true);

_graphics.Width = _window.Width;
_graphics.Height = _window.Height;
_graphics.WindowHandle = _window.Handle; // set the target handle before calling Setup()
_graphics.Setup();

initMethod.Invoke(_window, _graphics);
}

public Task Run(Action<OverlayWindow, Graphics> drawMethod, CancellationToken cToken)
{
return Task.Run(() =>
{
using (System.Timers.Timer t = new System.Timers.Timer()
{
AutoReset = false,
Interval = 16.6d
})
{
t.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) =>
{
try
{
// Ensure this is on top of the game.
_window.PlaceAboveWindow(windowHook);

// Begin a new scene/frame.
_graphics.BeginScene();

// Clear the previous scene/frame.
_graphics.ClearScene();

drawMethod.Invoke(_window, _graphics);

// End the scene/frame rendering.
_graphics.EndScene();
}
finally
{
try { ((System.Timers.Timer)sender).Start(); }
catch { }
}
};
t.Start();

try { Task.WaitAll(Task.Delay(-1, cToken)); }
catch { }
}
}, cToken);
}
}
}
4 changes: 2 additions & 2 deletions RE2REmakeSRT/EnemyHP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public readonly struct EnemyHP
public EnemyHP(int maximumHP, int currentHP)
{
MaximumHP = maximumHP;
CurrentHP = currentHP;
IsAlive = MaximumHP > 0 && CurrentHP > 0;
CurrentHP = (currentHP <= maximumHP) ? currentHP : 0;
IsAlive = MaximumHP > 0 && CurrentHP > 0 && CurrentHP <= MaximumHP;
Percentage = (IsAlive) ? (float)CurrentHP / (float)MaximumHP : 0f;
}
}
Expand Down
10 changes: 4 additions & 6 deletions RE2REmakeSRT/GameMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public GameMemory(int pid)
public void UpdatePointers()
{
PointerIGT.UpdatePointers();
PointerRank.UpdatePointers();
PointerPlayerHP.UpdatePointers();
PointerPlayerPoison.UpdatePointers();
PointerRank.UpdatePointers();

for (int i = 0; i < PointerEnemyEntries.Length; ++i)
PointerEnemyEntries[i].UpdatePointers();
Expand Down Expand Up @@ -143,6 +143,8 @@ public void Refresh()
PlayerMaxHealth = PointerPlayerHP.DerefInt(0x54);
PlayerCurrentHealth = PointerPlayerHP.DerefInt(0x58);
PlayerPoisoned = PointerPlayerPoison.DerefByte(0x258) == 0x01;
Rank = PointerRank.DerefInt(0x58);
RankScore = PointerRank.DerefFloat(0x5C);

// Enemy HP
for (int i = 0; i < PointerEnemyEntries.Length; ++i)
Expand All @@ -154,14 +156,10 @@ public void Refresh()
for (int i = 0; i < PointerInventoryEntries.Length; ++i)
{
long invDataPointer = PointerInventoryEntries[i].DerefLong(0x10);
long invDataOffset = invDataPointer - PointerInventoryEntries[i].Addresses[PointerInventoryEntries[i].Addresses.Count - 1];
long invDataOffset = invDataPointer - PointerInventoryEntries[i].Address;
PlayerInventory[i] = new InventoryEntry(PointerInventoryEntries[i].DerefInt(0x28), PointerInventoryEntries[i].DerefByteArray(invDataOffset + 0x10, 0x14));
}
}

// Rank
Rank = PointerRank.DerefInt(0x58);
RankScore = PointerRank.DerefFloat(0x5C);
}

public static Bitmap inventoryImage;
Expand Down
14 changes: 14 additions & 0 deletions RE2REmakeSRT/IDXOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using GameOverlay.Drawing;
using GameOverlay.Windows;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace RE2REmakeSRT
{
public interface IDXOverlay
{
void Initialize(Action<OverlayWindow, Graphics> initMethod);
Task Run(Action<OverlayWindow, Graphics> drawMethod, CancellationToken cToken);
}
}
3 changes: 0 additions & 3 deletions RE2REmakeSRT/MainUI.Designer.cs

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

Loading

0 comments on commit d5004d8

Please sign in to comment.