diff --git a/RE2REmakeSRT/GameMemory.cs b/RE2REmakeSRT/GameMemory.cs index f5a55ec..0ea57ec 100644 --- a/RE2REmakeSRT/GameMemory.cs +++ b/RE2REmakeSRT/GameMemory.cs @@ -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); diff --git a/RE2REmakeSRT/InventoryEntry.cs b/RE2REmakeSRT/InventoryEntry.cs index 7f49e0e..5cdbf7a 100644 --- a/RE2REmakeSRT/InventoryEntry.cs +++ b/RE2REmakeSRT/InventoryEntry.cs @@ -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) @@ -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) diff --git a/RE2REmakeSRT/MainUI.Designer.cs b/RE2REmakeSRT/MainUI.Designer.cs index c4d3e68..360c231 100644 --- a/RE2REmakeSRT/MainUI.Designer.cs +++ b/RE2REmakeSRT/MainUI.Designer.cs @@ -44,6 +44,7 @@ private void InitializeComponent() this.playerHealthStatus.TabIndex = 0; this.playerHealthStatus.TabStop = false; this.playerHealthStatus.Paint += new System.Windows.Forms.PaintEventHandler(this.playerHealthStatus_Paint); + this.playerHealthStatus.MouseDown += new System.Windows.Forms.MouseEventHandler(this.playerHealthStatus_MouseDown); // // statisticsPanel // @@ -52,6 +53,7 @@ private void InitializeComponent() this.statisticsPanel.Size = new System.Drawing.Size(150, 354); this.statisticsPanel.TabIndex = 2; this.statisticsPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.statisticsPanel_Paint); + this.statisticsPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.statisticsPanel_MouseDown); // // inventoryPanel // @@ -60,6 +62,7 @@ private void InitializeComponent() this.inventoryPanel.Size = new System.Drawing.Size(336, 420); this.inventoryPanel.TabIndex = 3; this.inventoryPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.inventoryPanel_Paint); + this.inventoryPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.inventoryPanel_MouseDown); // // MainUI // @@ -77,6 +80,7 @@ private void InitializeComponent() this.Name = "MainUI"; this.ShowIcon = false; this.Text = "RE2 (2019) SRT"; + this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainUI_MouseDown); ((System.ComponentModel.ISupportInitialize)(this.playerHealthStatus)).EndInit(); this.ResumeLayout(false); diff --git a/RE2REmakeSRT/MainUI.cs b/RE2REmakeSRT/MainUI.cs index 9f8bd29..fac6668 100644 --- a/RE2REmakeSRT/MainUI.cs +++ b/RE2REmakeSRT/MainUI.cs @@ -1,4 +1,5 @@ -using System; +using DoubleBuffered; +using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; @@ -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()); @@ -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) { @@ -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); + } } } diff --git a/RE2REmakeSRT/PInvoke.cs b/RE2REmakeSRT/PInvoke.cs new file mode 100644 index 0000000..0e0d070 --- /dev/null +++ b/RE2REmakeSRT/PInvoke.cs @@ -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); + } + } +} diff --git a/RE2REmakeSRT/Program.cs b/RE2REmakeSRT/Program.cs index e847ef2..f4e23aa 100644 --- a/RE2REmakeSRT/Program.cs +++ b/RE2REmakeSRT/Program.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; +using System.Text; using System.Windows.Forms; namespace RE2REmakeSRT @@ -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; diff --git a/RE2REmakeSRT/ProgramFlags.cs b/RE2REmakeSRT/ProgramFlags.cs index 184a43d..18b1382 100644 --- a/RE2REmakeSRT/ProgramFlags.cs +++ b/RE2REmakeSRT/ProgramFlags.cs @@ -7,6 +7,8 @@ public enum ProgramFlags : byte { None = 0x00, SkipChecksumCheck = 0x01, + NoTitleBar = 0x02, + AlwaysOnTop = 0x04, Debug = SkipChecksumCheck } } diff --git a/RE2REmakeSRT/Properties/AssemblyInfo.cs b/RE2REmakeSRT/Properties/AssemblyInfo.cs index 505693e..08c419b 100644 --- a/RE2REmakeSRT/Properties/AssemblyInfo.cs +++ b/RE2REmakeSRT/Properties/AssemblyInfo.cs @@ -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")] diff --git a/RE2REmakeSRT/RE2REmakeSRT.csproj b/RE2REmakeSRT/RE2REmakeSRT.csproj index 46ee50b..fba35d1 100644 --- a/RE2REmakeSRT/RE2REmakeSRT.csproj +++ b/RE2REmakeSRT/RE2REmakeSRT.csproj @@ -71,6 +71,7 @@ +