Skip to content
This repository was archived by the owner on May 25, 2026. It is now read-only.

Commit 9ecfc05

Browse files
committed
v1.1.22
- Actualizar ALM - Corregir la apariencia de la imagen de Stream TradeBlock para SV - Correcciones de fugas de memoria - Envolver EnterLinkTradeAndCode en try/finally para una limpieza adecuada
1 parent 7e527f0 commit 9ecfc05

6 files changed

Lines changed: 46 additions & 20 deletions

File tree

SysBot.Pokemon.WinForms/Main.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
6060

6161
private SearchManager _searchManager = null!;
6262
private LogViewerForwarder _logViewerForwarder = null!;
63+
private TextBoxForwarder _textBoxForwarder = null!;
6364

6465
internal bool hasUpdate = false;
6566
private bool _isRestoringFromTray = false;
@@ -457,7 +458,8 @@ private void LoadControls()
457458
// Apply enhanced styling to the game selector
458459
ConfigureGameSelector();
459460

460-
LogUtil.Forwarders.Add(new TextBoxForwarder(RTB_Logs));
461+
_textBoxForwarder = new TextBoxForwarder(RTB_Logs);
462+
LogUtil.Forwarders.Add(_textBoxForwarder);
461463
LogUtil.Forwarders.Add(_logViewerForwarder);
462464
}
463465

@@ -474,7 +476,11 @@ private ProgramConfig GetCurrentConfiguration()
474476
private void Main_FormClosing(object sender, FormClosingEventArgs e)
475477
{
476478
if (IsUpdating) return;
477-
479+
480+
// Remove log forwarders to prevent memory leaks
481+
LogUtil.Forwarders.Remove(_textBoxForwarder);
482+
LogUtil.Forwarders.Remove(_logViewerForwarder);
483+
478484
// Let the form close normally when X button is clicked
479485
// No longer minimizing to tray on close
480486
this.StopWebServer();

SysBot.Pokemon.WinForms/WebApi/WebApiExtensions.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public static void InitWebServer(this Main mainForm)
3333
{
3434
_main = mainForm;
3535

36+
_cts = new CancellationTokenSource(); // Initialize early for background tasks
37+
3638
// Get the configured port from settings
3739
if (mainForm.Config?.Hub?.WebServer != null)
3840
{
@@ -120,10 +122,17 @@ public static void InitWebServer(this Main mainForm)
120122
// Periodically clean up completed update sessions
121123
_ = Task.Run(async () =>
122124
{
123-
while (true)
125+
while (_cts != null && !_cts.Token.IsCancellationRequested)
124126
{
125-
await Task.Delay(TimeSpan.FromMinutes(30));
126-
UpdateManager.ClearState();
127+
try
128+
{
129+
await Task.Delay(TimeSpan.FromMinutes(30), _cts.Token);
130+
UpdateManager.ClearState();
131+
}
132+
catch (OperationCanceledException)
133+
{
134+
break; // Exit gracefully when cancelled
135+
}
127136
}
128137
});
129138
}
@@ -320,7 +329,7 @@ private static void StartFullServer()
320329

321330
private static void StartTcp()
322331
{
323-
_cts = new CancellationTokenSource();
332+
_cts ??= new CancellationTokenSource(); // Only create if not already created
324333
Task.Run(() => StartTcpListenerAsync(_cts.Token));
325334
}
326335

SysBot.Pokemon/Helpers/PokeNexo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ namespace SysBot.Pokemon.Helpers
22
{
33
public static class PokeNexo
44
{
5-
public const string Attribution = "https://github.com/hexbyt3/PokeBot";
5+
public const string Attribution = "https://github.com/Daiivr/PokeNexo";
66

77
public const string ConfigPath = "config.json";
88

9-
public const string Version = "v1.1.21";
9+
public const string Version = "v1.1.22";
1010
}
1111
}

SysBot.Pokemon/SV/BotTrade/PokeTradeBotSV.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,6 @@ void SendCollectedPokemonAndCleanup()
957957
return PokeTradeResult.NoTrainerFound;
958958
}
959959

960-
Hub.Config.Stream.EndEnterCode(this);
961-
962960
var cnt = 0;
963961
while (!await IsInBox(PortalOffset, token).ConfigureAwait(false))
964962
{
@@ -1214,7 +1212,6 @@ private async Task<PokeTradeResult> PerformLinkCodeTrade(SAV9SV sav, PokeTradeDe
12141212
// Update Barrier Settings
12151213
UpdateBarrier(poke.IsSynchronized);
12161214
poke.TradeInitialize(this);
1217-
Hub.Config.Stream.EndEnterCode(this);
12181215

12191216
// Handle connection and portal entry
12201217
if (!await EnsureConnectedAndInPortal(token).ConfigureAwait(false))
@@ -1223,7 +1220,7 @@ private async Task<PokeTradeResult> PerformLinkCodeTrade(SAV9SV sav, PokeTradeDe
12231220
}
12241221

12251222
// Enter Link Trade and code
1226-
if (!await EnterLinkTradeAndCode(poke.Code, token).ConfigureAwait(false))
1223+
if (!await EnterLinkTradeAndCode(poke, poke.Code, token).ConfigureAwait(false))
12271224
{
12281225
return PokeTradeResult.RecoverStart;
12291226
}
@@ -1260,7 +1257,7 @@ private async Task<bool> EnsureConnectedAndInPortal(CancellationToken token)
12601257
return true;
12611258
}
12621259

1263-
private async Task<bool> EnterLinkTradeAndCode(int code, CancellationToken token)
1260+
private async Task<bool> EnterLinkTradeAndCode(PokeTradeDetail<PK9> poke, int code, CancellationToken token)
12641261
{
12651262
// Assumes we're freshly in the Portal and the cursor is over Link Trade.
12661263
Log("Seleccionando Link Trade.");
@@ -1269,13 +1266,29 @@ private async Task<bool> EnterLinkTradeAndCode(int code, CancellationToken token
12691266
// Always clear Link Codes and enter a new one based on the current trade type
12701267
await Click(X, 1_000, token).ConfigureAwait(false);
12711268
await Click(PLUS, 1_000, token).ConfigureAwait(false);
1272-
await Task.Delay(Hub.Config.Timings.MiscellaneousSettings.ExtraTimeOpenCodeEntry, token).ConfigureAwait(false);
12731269

1274-
Log($"Ingresando el código de Link Trade: {code:0000 0000}...");
1275-
await EnterLinkCode(code, Hub.Config, token).ConfigureAwait(false);
1276-
await Click(PLUS, 3_000, token).ConfigureAwait(false);
1270+
// Loading code entry
1271+
bool startedEnterCode = false;
1272+
try
1273+
{
1274+
if (poke.Type != PokeTradeType.Random)
1275+
{
1276+
Hub.Config.Stream.StartEnterCode(this);
1277+
startedEnterCode = true;
1278+
}
1279+
await Task.Delay(Hub.Config.Timings.MiscellaneousSettings.ExtraTimeOpenCodeEntry, token).ConfigureAwait(false);
12771280

1278-
return true;
1281+
Log($"Ingresando el código de Link Trade: {code:0000 0000}...");
1282+
await EnterLinkCode(code, Hub.Config, token).ConfigureAwait(false);
1283+
await Click(PLUS, 3_000, token).ConfigureAwait(false);
1284+
1285+
return true;
1286+
}
1287+
finally
1288+
{
1289+
if (startedEnterCode)
1290+
Hub.Config.Stream.EndEnterCode(this);
1291+
}
12791292
}
12801293

12811294
private async Task<PokeTradeResult> PerformNonBatchTrade(SAV9SV sav, PokeTradeDetail<PK9> poke, CancellationToken token)
@@ -1320,8 +1333,6 @@ private async Task<PokeTradeResult> PerformNonBatchTrade(SAV9SV sav, PokeTradeDe
13201333
return PokeTradeResult.NoTrainerFound;
13211334
}
13221335

1323-
Hub.Config.Stream.EndEnterCode(this);
1324-
13251336
// Wait until we get into the box.
13261337
var cnt = 0;
13271338
while (!await IsInBox(PortalOffset, token).ConfigureAwait(false))
0 Bytes
Binary file not shown.

SysBot.Pokemon/deps/PKHeX.Core.dll

3 KB
Binary file not shown.

0 commit comments

Comments
 (0)