Skip to content

Commit

Permalink
Continuous Batch Trading for SWSH
Browse files Browse the repository at this point in the history
Version Bump to v4.0
  • Loading branch information
bdawg1989 committed Oct 31, 2024
1 parent 41fa4c6 commit 97388d7
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 10 deletions.
3 changes: 2 additions & 1 deletion SysBot.Pokemon/Actions/PokeRoutineExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public abstract class PokeRoutineExecutor<T>(IConsoleBotManaged<IConsoleConnecti
: PokeRoutineExecutorBase(Config)
where T : PKM, new()
{
private const ulong dmntID = 0x010000000000000d;
public readonly BatchTradeTracker<T> _batchTracker = new();

private const ulong dmntID = 0x010000000000000d;
// Check if either Tesla or dmnt are active if the sanity check for Trainer Data fails, as these are common culprits.
private const ulong ovlloaderID = 0x420000000007e51a;

Expand Down
6 changes: 4 additions & 2 deletions SysBot.Pokemon/BDSP/BotTrade/PokeTradeBotBS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,8 @@ private async Task<PokeTradeResult> PerformLinkCodeTrade(SAV8BS sav, PokeTradeDe
var tradePartner = await GetTradePartnerInfo(token).ConfigureAwait(false);
var trainerNID = GetFakeNID(tradePartner.TrainerName, tradePartner.TrainerID);
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{tradePartner.TrainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: ({tradePartner.TrainerName}-{trainerNID})");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down Expand Up @@ -1094,7 +1095,8 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8BS sav, PokeTradeDetai

var tradePartner = await GetTradePartnerInfo(token).ConfigureAwait(false);
var trainerNID = GetFakeNID(tradePartner.TrainerName, tradePartner.TrainerID);
Log($"Found Link Trade partner: ({tradePartner.TrainerName}-{tradePartner.TID7})");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

// Handle trainer data
var tradeCodeStorage = new TradeCodeStorage();
Expand Down
6 changes: 3 additions & 3 deletions SysBot.Pokemon/Helpers/BatchTradeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SysBot.Pokemon.Helpers
private readonly TimeSpan _tradeTimeout = TimeSpan.FromMinutes(5);
private readonly ConcurrentDictionary<(ulong TrainerId, int UniqueTradeID), DateTime> _lastTradeTime = new();
private readonly ConcurrentDictionary<ulong, List<T>> _receivedPokemon = new();
private readonly object _claimLock = new(); // Add this line
private readonly object _claimLock = new();

public bool CanProcessBatchTrade(PokeTradeDetail<T> trade)
{
Expand All @@ -33,7 +33,7 @@ public bool TryClaimBatchTrade(PokeTradeDetail<T> trade, string botName)

var key = (trade.Trainer.ID, trade.UniqueTradeID);

lock (_claimLock) // Add this line
lock (_claimLock)
{
// If we already have this batch, make sure it's the same bot
if (_activeBatches.TryGetValue(key, out var existingBot))
Expand All @@ -50,7 +50,7 @@ public bool TryClaimBatchTrade(PokeTradeDetail<T> trade, string botName)
}

return false;
} // Add this line
}
}

public void CompleteBatchTrade(PokeTradeDetail<T> trade)
Expand Down
2 changes: 1 addition & 1 deletion SysBot.Pokemon/Helpers/TradeBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public static class TradeBot

public const string ConfigPath = "config.json";

public const string Version = "v3.7";
public const string Version = "v4.0";
}
}
2 changes: 2 additions & 0 deletions SysBot.Pokemon/LA/BotTrade/PokeTradeBotLA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV8LA sav, PokeTradeDetai
tradePartner.NID = trainerNID;
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{tradePartner.TrainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down Expand Up @@ -665,6 +666,7 @@ private async Task<PokeTradeResult> PerformLinkCodeTrade(SAV8LA sav, PokeTradeDe
tradePartner.NID = trainerNID;
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{tradePartner.TrainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down
2 changes: 2 additions & 0 deletions SysBot.Pokemon/SV/BotTrade/PokeTradeBotSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ private async Task<PokeTradeResult> PerformBatchTrade(SAV9SV sav, PokeTradeDetai
var trainerNID = await GetTradePartnerNID(TradePartnerNIDOffset, token).ConfigureAwait(false);
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{tradePartner.TrainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down Expand Up @@ -1168,6 +1169,7 @@ private async Task<PokeTradeResult> PerformNonBatchTrade(SAV9SV sav, PokeTradeDe
var trainerNID = await GetTradePartnerNID(TradePartnerNIDOffset, token).ConfigureAwait(false);
RecordUtil<PokeTradeBotSWSH>.Record($"Initiating\t{trainerNID:X16}\t{tradePartner.TrainerName}\t{poke.Trainer.TrainerName}\t{poke.Trainer.ID}\t{poke.ID}\t{toSend.EncryptionConstant:X8}");
Log($"Found Link Trade partner: {tradePartner.TrainerName}-{tradePartner.TID7} (ID: {trainerNID})");
poke.SendNotification(this, $"Found Link Trade partner: {tradePartner.TrainerName}. **TID**: {tradePartner.TID7} **SID**: {tradePartner.SID7}. Waiting for a Pokémon...");

var tradeCodeStorage = new TradeCodeStorage();
var existingTradeDetails = tradeCodeStorage.GetTradeDetails(poke.Trainer.ID);
Expand Down
Loading

0 comments on commit 97388d7

Please sign in to comment.