Skip to content

Commit 51b3776

Browse files
committed
Handling to prevent exceptions from occurring during Auto Refresh.
1 parent ee175d6 commit 51b3776

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

PS4CheaterNeo/Main.cs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ private void ToolStripRefreshCheat_Click(object sender, EventArgs e)
10661066

10671067
refreshCheatSource = new CancellationTokenSource();
10681068
refreshCheatTask = RefreshCheatTask(true);
1069-
refreshCheatTask.ContinueWith(t => {
1069+
refreshCheatTask?.ContinueWith(t => {
10701070
refreshCheatSource?.Dispose();
10711071
refreshCheatSource = null;
10721072
refreshCheatTask?.Dispose();
@@ -1148,7 +1148,7 @@ private void AutoRefreshTimer_Tick(object sender, EventArgs e)
11481148

11491149
refreshCheatSource = new CancellationTokenSource();
11501150
refreshCheatTask = RefreshCheatTask();
1151-
refreshCheatTask.ContinueWith(t => {
1151+
refreshCheatTask?.ContinueWith(t => {
11521152
refreshCheatSource?.Dispose();
11531153
refreshCheatSource = null;
11541154
refreshCheatTask?.Dispose();
@@ -1438,47 +1438,51 @@ private void CheatBatchReadMemory(int processID, Dictionary<uint, (Section Secti
14381438
int count = 0;
14391439
int firstDisplayedScrollingRowIndex = CheatGridView.FirstDisplayedScrollingRowIndex;
14401440
bool isRefreshFinish = false;
1441-
foreach ((Section Section_, uint MinOffset, uint MaxOffset, List<(uint OffsetAddr, int Length, int CIDX, ScanType ScanType, bool IsSign)> CheatList) cheat in cheatsDict.Values)
1441+
try
14421442
{
1443-
refreshCheatSource.Token.ThrowIfCancellationRequested();
1444-
byte[] newDatas = PS4Tool.ReadMemory(processID, cheat.Section_.Start + cheat.MinOffset, (int)cheat.MaxOffset - (int)cheat.MinOffset);
1445-
for (int idx = 0; idx < cheat.CheatList.Count; idx++)
1443+
foreach ((Section Section_, uint MinOffset, uint MaxOffset, List<(uint OffsetAddr, int Length, int CIDX, ScanType ScanType, bool IsSign)> CheatList) cheat in cheatsDict.Values)
14461444
{
1447-
count++;
14481445
refreshCheatSource.Token.ThrowIfCancellationRequested();
1449-
(uint OffsetAddr, int Length, int CIDX, ScanType ScanType, bool IsSign) = cheat.CheatList[idx];
1450-
Byte[] newData = new byte[Length];
1451-
Buffer.BlockCopy(newDatas, (int)OffsetAddr - (int)cheat.MinOffset, newData, 0, Length);
1452-
Invoke(new MethodInvoker(() =>
1446+
byte[] newDatas = PS4Tool.ReadMemory(processID, cheat.Section_.Start + cheat.MinOffset, (int)cheat.MaxOffset - (int)cheat.MinOffset);
1447+
for (int idx = 0; idx < cheat.CheatList.Count; idx++)
14531448
{
1454-
cheatGridRowList[CIDX].Cells[(int)ChertCol.CheatListValue] = ScanTool.BytesToString(ScanType, newData, false, IsSign);
1455-
if (idx % 1000 == 0 && (CheatAutoRefreshShowStatus || isShowStatus))
1449+
count++;
1450+
refreshCheatSource.Token.ThrowIfCancellationRequested();
1451+
(uint OffsetAddr, int Length, int CIDX, ScanType ScanType, bool IsSign) = cheat.CheatList[idx];
1452+
Byte[] newData = new byte[Length];
1453+
Buffer.BlockCopy(newDatas, (int)OffsetAddr - (int)cheat.MinOffset, newData, 0, Length);
1454+
Invoke(new MethodInvoker(() =>
14561455
{
1457-
if (idx % 50000 == 0)
1456+
cheatGridRowList[CIDX].Cells[(int)ChertCol.CheatListValue] = ScanTool.BytesToString(ScanType, newData, false, IsSign);
1457+
if (idx % 1000 == 0 && (CheatAutoRefreshShowStatus || isShowStatus))
14581458
{
1459-
if (firstDisplayedScrollingRowIndex != CheatGridView.FirstDisplayedScrollingRowIndex) isRefreshFinish = false;
1460-
if (!isRefreshFinish && CIDX > CheatGridView.FirstDisplayedScrollingRowIndex)
1459+
if (idx % 50000 == 0)
14611460
{
1462-
CheatGridView.Refresh();
1463-
isRefreshFinish = true;
1461+
if (firstDisplayedScrollingRowIndex != CheatGridView.FirstDisplayedScrollingRowIndex) isRefreshFinish = false;
1462+
if (!isRefreshFinish && CIDX > CheatGridView.FirstDisplayedScrollingRowIndex)
1463+
{
1464+
CheatGridView.Refresh();
1465+
isRefreshFinish = true;
1466+
}
1467+
firstDisplayedScrollingRowIndex = CheatGridView.FirstDisplayedScrollingRowIndex;
14641468
}
1465-
firstDisplayedScrollingRowIndex = CheatGridView.FirstDisplayedScrollingRowIndex;
1469+
ToolStripMsg.Text = string.Format("{0:000}%, Refresh Cheat elapsed:{1:0.00}s. {2}/{3}",
1470+
(int)(((float)count / cheatGridRowList.Count) * 100), tickerMajor.Elapsed.TotalSeconds, count, cheatGridRowList.Count);
14661471
}
1472+
}));
1473+
}
1474+
Invoke(new MethodInvoker(() =>
1475+
{
1476+
if (CheatAutoRefreshShowStatus || isShowStatus)
1477+
{
1478+
CheatGridView.Refresh();
14671479
ToolStripMsg.Text = string.Format("{0:000}%, Refresh Cheat elapsed:{1:0.00}s. {2}/{3}",
14681480
(int)(((float)count / cheatGridRowList.Count) * 100), tickerMajor.Elapsed.TotalSeconds, count, cheatGridRowList.Count);
14691481
}
14701482
}));
14711483
}
1472-
Invoke(new MethodInvoker(() =>
1473-
{
1474-
if (CheatAutoRefreshShowStatus || isShowStatus)
1475-
{
1476-
CheatGridView.Refresh();
1477-
ToolStripMsg.Text = string.Format("{0:000}%, Refresh Cheat elapsed:{1:0.00}s. {2}/{3}",
1478-
(int)(((float)count / cheatGridRowList.Count) * 100), tickerMajor.Elapsed.TotalSeconds, count, cheatGridRowList.Count);
1479-
}
1480-
}));
14811484
}
1485+
catch (Exception ex) { InputBox.MsgBox("CheatBatchReadMemory", ex.Message, "Cheat Batch Read Memory error occurred"); }
14821486
}
14831487

14841488
/// <summary>

PS4CheaterNeo/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.2.7")]
36-
[assembly: AssemblyFileVersion("1.0.2.7")]
35+
[assembly: AssemblyVersion("1.0.2.8")]
36+
[assembly: AssemblyFileVersion("1.0.2.8")]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PS4CheaterNeo is a program to find game cheat codes, and it is based on [`ps4debug`](https://github.com/jogolden/ps4debug) and [`.Net Framework 4.8`](https://support.microsoft.com/en-us/topic/microsoft-net-framework-4-8-offline-installer-for-windows-9d23f658-3b97-68ab-d013-aa3c3e7495e0).
44

5-
Currently in `version 1.0.2.7`
5+
Currently in `version 1.0.2.8`
66

77

88
## Table of Contents

0 commit comments

Comments
 (0)