Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GHXX committed Jun 27, 2021
1 parent 729fd47 commit 1adce62
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DataInterfaceConsole/Actions/BaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void AbortIfDiInvalid()
protected void WaitForIngame()
{
bool shown = false;
while (!this.di.IsGameRunning())
while (!this.di.IsMatchRunning())
{
if (!shown)
{
Expand Down
2 changes: 1 addition & 1 deletion DataInterfaceConsole/Actions/BaseLoadPredefinedVariant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected override void Run()
int safeBoardLimit = -1;
try
{
if (!this.di.IsGameRunning()) // if the match isnt running, then use the trap mode to inject it
if (!this.di.IsMatchRunning()) // if the match isnt running, then use the trap mode to inject it
{
at = this.di.asmHelper.PlaceAssemblyTrap(IntPtr.Add(this.di.GameProcess.MainModule.BaseAddress, 0x289C2));
Console.WriteLine("Main thread trapped. Please start a game, and then check back here.");
Expand Down
5 changes: 2 additions & 3 deletions DataInterfaceConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ private void Run()
}
catch (DataInterfaceClosedException ex)
{
Util.WriteColored($"Execution of the current action '{a.Name}' was aborted because the game closed or crashed: \n{ex}\n" +
$"To continue, please press ENTER.", ConsoleColor.Red);
Util.WriteColored($"Execution of the current action '{a.Name}' was aborted because the game closed or crashed: \n{ex}", ConsoleColor.Red);
ConsoleNonBlocking.ClearInputLines();
}
break;
Expand All @@ -80,7 +79,7 @@ private void Run()
}
catch (DataInterfaceClosedException ex)
{
Util.WriteColored($"Execution of the current action selection was aborted because the game closed or crashed: \n{ex}\nTo continue, please press ENTER.", ConsoleColor.Red);
Util.WriteColored($"Execution of the current action selection was aborted because the game closed or crashed: \n{ex}", ConsoleColor.Red);
ConsoleNonBlocking.ClearInputLines();
}
}
Expand Down
16 changes: 13 additions & 3 deletions FiveDChessDataInterface/DataInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private void SetChessBoardArrayInternal(ChessBoard[] newBoards)
this.asmHelper.EnsureArrayCapacity(this.MemLocChessArrayPointer.WithOffset(0x60), szGlobalBitboards, newBoards.Length); // 90*
// one hanging ref ["5dchesswithmultiversetimetravel.exe"+0014BC10]+0x990
this.asmHelper.EnsureArrayCapacity(this.MemLocChessArrayPointer.WithOffset(0x70), szGlobalBitboards, newBoards.Length); // a0*
this.asmHelper.EnsureArrayCapacity(this.MemLocChessArrayPointer.WithOffset(0x70), szGlobalBitboards, newBoards.Length); // a0*
this.asmHelper.EnsureArrayCapacity(this.MemLocChessArrayPointer.WithOffset(0x80), szGlobalBitboards, newBoards.Length); // b0*
this.asmHelper.EnsureArrayCapacity(this.MemLocChessArrayPointer.WithOffset(0x90), szGlobalBitboards, newBoards.Length); // c0*
this.asmHelper.EnsureArrayCapacity(this.MemLocChessArrayPointer.WithOffset(0xa0), szGlobalBitboards, newBoards.Length); // d0*
Expand Down Expand Up @@ -497,11 +497,21 @@ private void SetChessBoardArrayInternal(ChessBoard[] newBoards)
/// <returns>Returns 0 if it's WHITE's turn, and 1 if it's BLACK's turn.</returns>
public int GetCurrentPlayersTurn() => this.MemLocCurrentPlayersTurn.GetValue();

public bool IsGameRunning() => this.MemLocChessArrayPointer.GetValue() != IntPtr.Zero;
public bool IsMatchRunning()
{
try
{
return this.MemLocChessArrayPointer.GetValue() != IntPtr.Zero;
}
catch (Exception)
{
return false;
}
}

public GameState GetCurrentGameState()
{
if (!IsGameRunning())
if (!IsMatchRunning())
{
return GameState.NotStarted;
}
Expand Down
7 changes: 4 additions & 3 deletions FiveDChessDataInterface/MemoryHelpers/AssemblyTrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ private void PlaceTrap(bool throwOnExistingLock)

public void ReleaseTrap()
{
this.ah.di.ExecuteWhileGameSuspendedLocked(() =>
KernelMethods.WriteMemory(this.ah.gameHandle, this.originalLocation, this.originalCode)
); // restore original code
if (this.ah.di.IsValid())
this.ah.di.ExecuteWhileGameSuspendedLocked(() =>
KernelMethods.WriteMemory(this.ah.gameHandle, this.originalLocation, this.originalCode)
); // restore original code
}

public static AssemblyTrap TrapLocation(IntPtr ptr, AssemblyHelper ah, bool throwOnExistingLock = false)
Expand Down

0 comments on commit 1adce62

Please sign in to comment.