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

Commit

Permalink
Added --No-Titlebar and --Always-On-Top command-line arguments.
Browse files Browse the repository at this point in the history
Potentially fixed a bug with Inventory display.
  • Loading branch information
Squirrelies committed Feb 7, 2019
1 parent a682317 commit 3e47684
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 19 deletions.
6 changes: 5 additions & 1 deletion RE2REmakeSRT/GameMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ public void Refresh()

// Inventory
for (int i = 0; i < PointerInventoryEntries.Length; ++i)
PlayerInventory[i] = new InventoryEntry(PointerInventoryEntries[i].DerefByteArray(0x00, 0xF0));
{
long invDataPointer = PointerInventoryEntries[i].DerefLong(0x10);
long invDataOffset = invDataPointer - PointerInventoryEntries[i].Addresses[PointerInventoryEntries[i].Addresses.Count - 1];
PlayerInventory[i] = new InventoryEntry(PointerInventoryEntries[i].DerefInt(0x28), PointerInventoryEntries[i].DerefByteArray(invDataOffset + 0x10, 0x14));
}

// Rank
Rank = PointerRank.DerefInt(0x58);
Expand Down
29 changes: 15 additions & 14 deletions RE2REmakeSRT/InventoryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@ public string _DebuggerDisplay
}
}

// Private storage variable.
private readonly byte[] data; // 240 (0xF0) bytes.
// Storage variable.
public readonly int SlotPosition;
public readonly byte[] Data;

// Public accessor properties.
public int SlotPosition => ProcessMemory.HighPerfBitConverter.ToInt32(data, 0x28);
public ItemEnumeration ItemID => (ItemEnumeration)ProcessMemory.HighPerfBitConverter.ToInt32(data, 0x70);
public WeaponEnumeration WeaponID => (WeaponEnumeration)ProcessMemory.HighPerfBitConverter.ToInt32(data, 0x74);
public AttachmentsFlag Attachments => (AttachmentsFlag)ProcessMemory.HighPerfBitConverter.ToInt32(data, 0x78);
public int Quantity => ProcessMemory.HighPerfBitConverter.ToInt32(data, 0x80);

public bool IsEmptySlot => ItemID == ItemEnumeration.None && (WeaponID == WeaponEnumeration.None || WeaponID == 0);
// Accessor properties.
public ItemEnumeration ItemID => (ItemEnumeration)ProcessMemory.HighPerfBitConverter.ToInt32(Data, 0x00);
public WeaponEnumeration WeaponID => (WeaponEnumeration)ProcessMemory.HighPerfBitConverter.ToInt32(Data, 0x04);
public AttachmentsFlag Attachments => (AttachmentsFlag)ProcessMemory.HighPerfBitConverter.ToInt32(Data, 0x08);
public int Quantity => ProcessMemory.HighPerfBitConverter.ToInt32(Data, 0x10);

public bool IsItem => ItemID != ItemEnumeration.None && (WeaponID == WeaponEnumeration.None || WeaponID == 0);
public bool IsWeapon => ItemID == ItemEnumeration.None && WeaponID != WeaponEnumeration.None && WeaponID != 0;
public bool IsEmptySlot => !IsItem && !IsWeapon;

public InventoryEntry(byte[] data)
public InventoryEntry(int slotPosition, byte[] data)
{
this.data = data;
this.SlotPosition = slotPosition;
this.Data = data;
}

public bool Equals(InventoryEntry other)
{
return data.ByteArrayEquals(other.data);
return Data.ByteArrayEquals(other.Data);
}

public override bool Equals(object obj)
Expand Down Expand Up @@ -78,7 +79,7 @@ public override string ToString()
if (ReferenceEquals(obj2, null))
return false;

return obj1.data.ByteArrayEquals(obj2.data);
return obj1.Data.ByteArrayEquals(obj2.Data);
}

public static bool operator !=(InventoryEntry obj1, InventoryEntry obj2)
Expand Down
4 changes: 4 additions & 0 deletions RE2REmakeSRT/MainUI.Designer.cs

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

38 changes: 37 additions & 1 deletion RE2REmakeSRT/MainUI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using DoubleBuffered;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
Expand Down Expand Up @@ -32,6 +33,9 @@ public MainUI()
{
InitializeComponent();

if (Program.programSpecialOptions.HasFlag(ProgramFlags.NoTitleBar))
this.FormBorderStyle = FormBorderStyle.None;

// Set titlebar.
this.Text += string.Format(" v{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());

Expand All @@ -50,6 +54,14 @@ private void MemoryPollingTimer_Elapsed(object sender, System.Timers.ElapsedEven
// Suspend UI layout logic to perform redrawing.
MainUI uiForm = (MainUI)Program.mainContext.MainForm;

if (Program.programSpecialOptions.HasFlag(ProgramFlags.AlwaysOnTop))
{
if (uiForm.InvokeRequired)
uiForm.Invoke(new Action(() => uiForm.TopMost = true));
else
uiForm.TopMost = true;
}

// Only perform a pointer update occasionally.
if (DateTime.UtcNow.Ticks - lastPtrUpdate >= PTR_UPDATE_TICKS)
{
Expand Down Expand Up @@ -204,5 +216,29 @@ private void statisticsPanel_Paint(object sender, PaintEventArgs e)
e.Graphics.DrawText(0, heightOffset + (heightGap * ++i), string.Format("{0} {1:P1}", Program.gameMem.EnemyCurrentHealth[ehi], (decimal)Program.gameMem.EnemyCurrentHealth[ehi] / (decimal)Program.gameMem.EnemyMaxHealth[ehi]), Brushes.Red, new Font("Consolas", 10, FontStyle.Bold));
}
}

private void inventoryPanel_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
PInvoke.DragControl(((DoubleBufferedPanel)sender).Parent.Handle);
}

private void statisticsPanel_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
PInvoke.DragControl(((DoubleBufferedPanel)sender).Parent.Handle);
}

private void playerHealthStatus_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
PInvoke.DragControl(((PictureBox)sender).Parent.Handle);
}

private void MainUI_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
PInvoke.DragControl(((Form)sender).Handle);
}
}
}
23 changes: 23 additions & 0 deletions RE2REmakeSRT/PInvoke.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Runtime.InteropServices;

namespace RE2REmakeSRT
{
public static class PInvoke
{
private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HT_CAPTION = 0x2;

[DllImportAttribute("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

[DllImportAttribute("user32.dll")]
private static extern bool ReleaseCapture();

public static void DragControl(IntPtr controlHandle)
{
ReleaseCapture();
SendMessage(controlHandle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
15 changes: 14 additions & 1 deletion RE2REmakeSRT/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;

namespace RE2REmakeSRT
Expand Down Expand Up @@ -30,13 +31,25 @@ public static void Main(string[] args)
{
if (string.Equals(arg, "--Help", StringComparison.InvariantCultureIgnoreCase))
{
MessageBox.Show(null, "Command-line arguments:\r\n\r\n--Skip-Checksum\t\tSkips the checksum file validation step.\r\n--Debug\t\tDebug mode.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
StringBuilder message = new StringBuilder("Command-line arguments:\r\n\r\n");
message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Skip-Checksum", "Skip the checksum file validation step.");
message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--No-Titlebar", "Hide the titlebar and window frame.");
message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Always-On-Top", "Always appear on top of other windows.");
message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Debug", "Debug mode.");

MessageBox.Show(null, message.ToString().Trim(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
Environment.Exit(0);
}

if (string.Equals(arg, "--Skip-Checksum", StringComparison.InvariantCultureIgnoreCase))
programSpecialOptions |= ProgramFlags.SkipChecksumCheck;

if (string.Equals(arg, "--No-Titlebar", StringComparison.InvariantCultureIgnoreCase))
programSpecialOptions |= ProgramFlags.NoTitleBar;

if (string.Equals(arg, "--Always-On-Top", StringComparison.InvariantCultureIgnoreCase))
programSpecialOptions |= ProgramFlags.AlwaysOnTop;

// Assigning here because debug will always be the sum of all of the options being on.
if (string.Equals(arg, "--Debug", StringComparison.InvariantCultureIgnoreCase))
programSpecialOptions = ProgramFlags.Debug;
Expand Down
2 changes: 2 additions & 0 deletions RE2REmakeSRT/ProgramFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public enum ProgramFlags : byte
{
None = 0x00,
SkipChecksumCheck = 0x01,
NoTitleBar = 0x02,
AlwaysOnTop = 0x04,
Debug = SkipChecksumCheck
}
}
4 changes: 2 additions & 2 deletions RE2REmakeSRT/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,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("1.1.4.2")]
[assembly: AssemblyFileVersion("1.1.4.2")]
[assembly: AssemblyVersion("1.1.4.3")]
[assembly: AssemblyFileVersion("1.1.4.3")]
1 change: 1 addition & 0 deletions RE2REmakeSRT/RE2REmakeSRT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Compile Include="Extensions.cs" />
<Compile Include="ItemEnumeration.cs" />
<Compile Include="ItemPositionEnumeration.cs" />
<Compile Include="PInvoke.cs" />
<Compile Include="Program.cs" />
<Compile Include="ProgramFlags.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit 3e47684

Please sign in to comment.