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

Commit

Permalink
Fixed issue #12 where users would experience Win32 Error Code 299 rel…
Browse files Browse the repository at this point in the history
…ating to WoW64 weirdness and ArgumentException relating to scalingFactor being set somehow to 0.
  • Loading branch information
Squirrelies committed Feb 15, 2019
1 parent c54e57f commit c6c563c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 20 deletions.
40 changes: 32 additions & 8 deletions RE2REmakeSRT/GameMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public TimeSpan IGTTimeSpan
///
/// </summary>
/// <param name="proc"></param>
public GameMemory(Process proc)
public GameMemory(int pid)
{
gameVersion = REmake2VersionDetector.GetVersion(proc);
memoryAccess = new ProcessMemory.ProcessMemory(proc.Id);
BaseAddress = NativeWrappers.GetProcessBaseAddress(proc.Id, ProcessMemory.PInvoke.ListModules.LIST_MODULES_64BIT).ToInt64(); // Bypass .NET's managed solution for getting this and attempt to get this info ourselves via PInvoke since some users are getting 299 PARTIAL COPY when they seemingly shouldn't. This is built as x64 only and RE2 is x64 only to my knowledge.
gameVersion = REmake2VersionDetector.GetVersion(pid);
memoryAccess = new ProcessMemory.ProcessMemory(pid);
BaseAddress = NativeWrappers.GetProcessBaseAddress(pid, ProcessMemory.PInvoke.ListModules.LIST_MODULES_64BIT).ToInt64(); // Bypass .NET's managed solution for getting this and attempt to get this info ourselves via PInvoke since some users are getting 299 PARTIAL COPY when they seemingly shouldn't. This is built as x64 only and RE2 is x64 only to my knowledge.
//BaseAddress = proc.MainModule.BaseAddress.ToInt64();

// Setup the pointers.
Expand Down Expand Up @@ -180,14 +180,38 @@ public void Refresh()
public static void GenerateImages()
{
// Transform the image into a 32-bit PARGB Bitmap.
inventoryImage = Properties.Resources.ui0100_iam_texout.Clone(new Rectangle(0, 0, Properties.Resources.ui0100_iam_texout.Width, Properties.Resources.ui0100_iam_texout.Height), PixelFormat.Format32bppPArgb);
try
{
inventoryImage = Properties.Resources.ui0100_iam_texout.Clone(new Rectangle(0, 0, Properties.Resources.ui0100_iam_texout.Width, Properties.Resources.ui0100_iam_texout.Height), PixelFormat.Format32bppPArgb);
}
catch (Exception ex)
{
Program.FailFast(string.Format("[{0}] An unhandled exception has occurred. Please see below for details.\r\n\r\n[{1}] {2}\r\n{3}.\r\n\r\nPARGB Transform.", Program.srtVersion, ex.GetType().ToString(), ex.Message, ex.StackTrace), ex);
}

// Rescales the image down if the scaling factor is not 1.
if (Program.programSpecialOptions.ScalingFactor != 1d)
{
int sheetWidth = (int)Math.Round(inventoryImage.Width * Program.programSpecialOptions.ScalingFactor, MidpointRounding.AwayFromZero);
int sheetHeight = (int)Math.Round(inventoryImage.Height * Program.programSpecialOptions.ScalingFactor, MidpointRounding.AwayFromZero);
inventoryImage = new Bitmap(inventoryImage, sheetWidth, sheetHeight);
double sheetWidth = Math.Round(inventoryImage.Width * Program.programSpecialOptions.ScalingFactor, MidpointRounding.AwayFromZero);
double sheetHeight = Math.Round(inventoryImage.Height * Program.programSpecialOptions.ScalingFactor, MidpointRounding.AwayFromZero);
try
{
inventoryImage = new Bitmap(inventoryImage, (int)sheetWidth, (int)sheetHeight);
}
catch (Exception ex)
{
Program.FailFast(string.Format(@"[{0}] An unhandled exception has occurred. Please see below for details.
---
[{1}] {2}
{3}
---
Resizing section.
sheetWidth: {4} ({7} * {6})
sheetHeight: {5} ({8} * {6})
scalingFactor: {6}
inventoryImage.Width: {7}
inventoryImage.Height: {8}", Program.srtVersion, ex.GetType().ToString(), ex.Message, ex.StackTrace, sheetWidth.ToString(), sheetHeight.ToString(), Program.programSpecialOptions.ScalingFactor.ToString(), inventoryImage.Width.ToString(), inventoryImage.Height.ToString()), ex);
}
}

int itemColumnInc = -1;
Expand Down
4 changes: 4 additions & 0 deletions RE2REmakeSRT/MainUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public MainUI()

// Adjust main form width as well.
this.Width = this.statisticsPanel.Width + 24 + this.inventoryPanel.Width;

// Only adjust form height if its greater than 461. We don't want it to go below this size.
if (41 + this.inventoryPanel.Height > 461)
this.Height = 41 + this.inventoryPanel.Height;
}
else
{
Expand Down
10 changes: 9 additions & 1 deletion RE2REmakeSRT/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void GetOptions()
Flags &= ~ProgramFlags.NoInventory;

double.TryParse(RegistryHelper.GetValue(optionsKey, "ScalingFactor", "0.75"), out ScalingFactor);

// Do not permit ScalingFactor values less than or equal to 0% and greater than 400%.
if (ScalingFactor <= 0 || ScalingFactor > 4)
ScalingFactor = 0.75d;
}

public void SetOptions()
Expand Down Expand Up @@ -81,7 +85,11 @@ public void SetOptions()
else
optionsKey.SetValue("NoInventory", 0, RegistryValueKind.DWord);

optionsKey.SetValue("ScalingFactor", ScalingFactor.ToString(), RegistryValueKind.String);
// Do not permit ScalingFactor values less than or equal to 0% and greater than 400%.
if (ScalingFactor <= 0 || ScalingFactor > 4)
optionsKey.SetValue("ScalingFactor", "0.75", RegistryValueKind.String);
else
optionsKey.SetValue("ScalingFactor", ScalingFactor.ToString(), RegistryValueKind.String);
}
}
}
21 changes: 16 additions & 5 deletions RE2REmakeSRT/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class Program
public static GameMemory gameMem;

public static readonly string srtVersion = string.Format("v{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
public static readonly string srtTitle = string.Format("RE2(2019) SRT - {0}", srtVersion);

public static int INV_SLOT_WIDTH;
public static int INV_SLOT_HEIGHT;
Expand Down Expand Up @@ -99,17 +100,27 @@ public static void Main(string[] args)
Application.Run(mainContext);

// Attach to the re2.exe process now that we've found it and show the UI.
using (gameMem = new GameMemory(gameProc))
using (gameMem = new GameMemory(gameProc.Id))
using (mainContext = new ApplicationContext(new MainUI()))
Application.Run(mainContext);
}
catch (Exception ex)
{
string title = "RE2 (2019) SRT - " + srtVersion;
string exception = string.Format("[{0}] An unhandled exception has occurred. Please see below for details.\r\n\r\n[{1}] {2}\r\n{3}.", srtVersion, ex.GetType().ToString(), ex.Message, ex.StackTrace);
MessageBox.Show(exception, title, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
Environment.FailFast(exception, ex);
FailFast(string.Format("[{0}] An unhandled exception has occurred. Please see below for details.\r\n\r\n[{1}] {2}\r\n{3}.", srtVersion, ex.GetType().ToString(), ex.Message, ex.StackTrace), ex);
}
}

public static void FailFast(string message, Exception ex)
{
ShowError(message);
Environment.FailFast(message, ex);
}

public static void ShowError(string message)
{
MessageBox.Show(message, srtTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}

public static string GetExceptionMessage(Exception ex) => string.Format("[{0}] An unhandled exception has occurred. Please see below for details.\r\n\r\n[{1}] {2}\r\n{3}.", srtVersion, ex.GetType().ToString(), ex.Message, ex.StackTrace);
}
}
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.8.3")]
[assembly: AssemblyFileVersion("1.1.8.3")]
[assembly: AssemblyVersion("1.1.8.4")]
[assembly: AssemblyFileVersion("1.1.8.4")]
7 changes: 4 additions & 3 deletions RE2REmakeSRT/REmake2VersionDetector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using ProcessMemory;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
Expand All @@ -17,13 +18,13 @@ private static byte[] GetSHA256Checksum(string filePath)
}
}

public static REmake2VersionEnumeration GetVersion(Process remake2Proc)
public static REmake2VersionEnumeration GetVersion(int pid)
{
// If we're skipping the checksum version check, return the latest version we kow about.
if (Program.programSpecialOptions.Flags.HasFlag(ProgramFlags.SkipChecksumCheck))
return REmake2VersionEnumeration.Stock_1p01;

byte[] processHash = GetSHA256Checksum(remake2Proc.MainModule.FileName);
byte[] processHash = GetSHA256Checksum(NativeWrappers.GetProcessPath(pid));

if (processHash.SequenceEqual(GameHashes.Stock_1ShotDemo))
{
Expand Down
14 changes: 13 additions & 1 deletion RE2REmakeSRT/RegistryHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
using Microsoft.Win32;
using System;

namespace RE2REmakeSRT
{
public static class RegistryHelper
{
public static T GetValue<T>(RegistryKey baseKey, string valueKey, T defaultValue) => (T)baseKey.GetValue(valueKey, defaultValue);
public static T GetValue<T>(RegistryKey baseKey, string valueKey, T defaultValue)
{
try
{
return (T)baseKey.GetValue(valueKey, defaultValue);
}
catch (Exception ex)
{
Program.ShowError(Program.GetExceptionMessage(ex));
return defaultValue;
}
}

public static bool GetBoolValue(RegistryKey baseKey, string valueKey, bool defaultValue)
{
Expand Down

0 comments on commit c6c563c

Please sign in to comment.