Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
PK9: Fix writing box bin of self-owned SV eggs clearing nickname trash, also clear any hint of trading completely
SAV1: ensure current box is index:0 if uninitialized
  • Loading branch information
kwsch committed Jun 6, 2024
1 parent d5e5eec commit de6c1ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions PKHeX.Core/PKM/PK9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ private void SetHandlerEggOT(ITrainerInfo tr)
HandlingTrainerGender = 0;
HandlingTrainerLanguage = 0;

MetDate = null;
MetLocation = 0;
Nickname = SpeciesName.GetSpeciesNameGeneration(Species, tr.Language, 9);
Nickname = SpeciesName.GetEggName(tr.Language, 9);
OriginalTrainerName = tr.OT;
CurrentHandler = 0;
Expand Down
4 changes: 3 additions & 1 deletion PKHeX.Core/Saves/SAV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ protected override byte[] GetFinalData()
bool newContent = AnyBoxSlotSpeciesPresent(current, boxSlotCount);
if (newContent)
BoxesInitialized = boxInitialized = true;
else
current = CurrentBox = 0; // No content, reset to box 1.
}

for (int i = 0; i < BoxCount; i++)
Expand All @@ -154,7 +156,7 @@ protected override byte[] GetFinalData()
var src = GetUnpackedBoxSpan(i);

bool written = PokeList1.MergeSingles(src, dest, StringLength, boxSlotCount, false, boxInitialized);
if (written && i == CurrentBox)
if (written && i == current) // Ensure the current box is mirrored in the box buffer; easier than having dest be CurrentBox.
dest.CopyTo(Data.AsSpan(Offsets.CurrentBox));
}

Expand Down
4 changes: 2 additions & 2 deletions PKHeX.WinForms/Misc/ErrorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public Exception Error
}
}

public void LoadException(Exception ex, string friendlyMessage, bool allowContinue) => Invoke(() =>
public void LoadException(Exception ex, string friendlyMessage, bool allowContinue)
{
ShowContinue = allowContinue;
Message = friendlyMessage;
Error = ex;
});
}

private void UpdateExceptionDetailsMessage()
{
Expand Down
14 changes: 10 additions & 4 deletions PKHeX.WinForms/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
try
{
var e = t.Exception;
string errorMessage = IsPluginError<IPlugin>(e, out var pluginName)
? $"An error occurred in a PKHeX plugin. Please report this error to the plugin author/maintainer.\n{pluginName}"
: "An error occurred in PKHeX. Please report this error to the PKHeX author.";
string errorMessage = GetErrorMessage(e);
result = ErrorWindow.ShowErrorDialog(errorMessage, e, true);
}
catch (Exception reportingException)
Expand All @@ -83,6 +81,13 @@ private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
Application.Exit();
}

private static string GetErrorMessage(Exception e)
{
return IsPluginError<IPlugin>(e, out var pluginName)
? $"An error occurred in a PKHeX plugin. Please report this error to the plugin author/maintainer.\n{pluginName}"
: "An error occurred in PKHeX. Please report this error to the PKHeX author.";
}

// Handle the UI exceptions by showing a dialog box, and asking the user if they wish to abort execution.
// NOTE: This exception cannot be kept from terminating the application - it can only
// log the event, and inform the user about it.
Expand All @@ -97,7 +102,8 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc
}
else if (ex != null)
{
ErrorWindow.ShowErrorDialog("An unhandled exception has occurred.\nPKHeX must now close.", ex, false);
var msg = GetErrorMessage(ex);
ErrorWindow.ShowErrorDialog($"{msg}\nPKHeX must now close.", ex, false);
}
else
{
Expand Down

0 comments on commit de6c1ba

Please sign in to comment.