Skip to content

Commit

Permalink
Fix extra char on OT Terminator. Fix SetShiny in AutoOT
Browse files Browse the repository at this point in the history
  • Loading branch information
bdawg1989 committed Jun 6, 2024
1 parent d51a96c commit b518d7b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
4 changes: 2 additions & 2 deletions SysBot.Pokemon/BDSP/BotTrade/PokeTradeBotBS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ private static void UpdateTrainerDetails(PB8 pokemon, PB8 offered, string tradeP

if (actualLength < maxLength)
{
trash[actualLength * 2] = 0xFF;
trash[actualLength * 2 + 1] = 0xFF;
trash[actualLength * 2] = 0x00;
trash[actualLength * 2 + 1] = 0x00;
}
}

Expand Down
4 changes: 2 additions & 2 deletions SysBot.Pokemon/LA/BotTrade/PokeTradeBotLA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ private static void UpdateTrainerDetails(PA8 pokemon, TradePartnerLA tradePartne

if (actualLength < maxLength)
{
trash[actualLength * 2] = 0xFF;
trash[actualLength * 2 + 1] = 0xFF;
trash[actualLength * 2] = 0x00;
trash[actualLength * 2 + 1] = 0x00;
}
}
}
33 changes: 14 additions & 19 deletions SysBot.Pokemon/SV/BotTrade/PokeTradeBotSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,17 @@ private async Task<bool> SetBoxPkmWithSwappedIDDetailsSV(PK9 toSend, TradeMyStat
UpdateTrainerDetails(cln, tradePartner);
cln.Version = DetermineVersion(cln.Species, cln.Form, tradePartner);
ClearNicknameIfNeeded(cln);
UpdateShininess(cln);
if (toSend.MetLocation == Locations.TeraCavern9 && toSend.IsShiny)
{
uint id32 = (uint)((cln.TID16) | (cln.SID16 << 16));
uint pid = cln.PID;
ShinyUtil.ForceShinyState(true, ref pid, id32, 1u);
cln.PID = pid;
}
else if (toSend.IsShiny)
{
cln.SetShiny();
}
cln.RefreshChecksum();
var tradeSV = new LegalityAnalysis(cln);
if (tradeSV.Valid)
Expand All @@ -1369,25 +1379,21 @@ private static void UpdateTrainerDetails(PK9 pokemon, TradeMyStatus tradePartner
pokemon.TrainerTID7 = (uint)Math.Abs(tradePartner.DisplayTID);
pokemon.TrainerSID7 = (uint)Math.Abs(tradePartner.DisplaySID);
pokemon.Language = tradePartner.Language;

Span<byte> trash = pokemon.OriginalTrainerTrash;
trash.Clear();

string name = tradePartner.OT;
int maxLength = trash.Length / 2;
int maxLength = trash.Length / 2;
int actualLength = Math.Min(name.Length, maxLength);

for (int i = 0; i < actualLength; i++)
{
char value = name[i];
trash[i * 2] = (byte)value;
trash[i * 2 + 1] = (byte)(value >> 8);
}

if (actualLength < maxLength)
{
trash[actualLength * 2] = 0xFF;
trash[actualLength * 2 + 1] = 0xFF;
trash[actualLength * 2] = 0x00;
trash[actualLength * 2 + 1] = 0x00;
}
}

Expand Down Expand Up @@ -1470,15 +1476,4 @@ private static void ClearNicknameIfNeeded(PK9 pokemon)
if (!pokemon.IsNicknamed)
pokemon.ClearNickname();
}

private static void UpdateShininess(PK9 pokemon)
{
if (pokemon.IsShiny)
{
uint id32 = (uint)((pokemon.TID16) | (pokemon.SID16 << 16));
uint pid = pokemon.PID;
ShinyUtil.ForceShinyState(true, ref pid, id32, 1u);
pokemon.PID = pid;
}
}
}
4 changes: 2 additions & 2 deletions SysBot.Pokemon/SWSH/BotTrade/PokeTradeBotSWSH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,8 @@ private static void UpdateTrainerDetails(PK8 pokemon, byte[] data, string traine

if (actualLength < maxLength)
{
trash[actualLength * 2] = 0xFF;
trash[actualLength * 2 + 1] = 0xFF;
trash[actualLength * 2] = 0x00;
trash[actualLength * 2 + 1] = 0x00;
}
}
}

0 comments on commit b518d7b

Please sign in to comment.