Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ games and popular romhacks:
- **Generation I:** Red, Blue, Green (JP), Yellow
- **Generation II:** Gold, Silver, Crystal
- **Generation III:** Ruby, Sapphire, Emerald, FireRed, LeafGreen, Pokémon Box: Ruby & Sapphire, Colosseum, XD: Gale of Darkness
- **My Pokémon Ranch:** read-only extraction from the original Diamond/Pearl format (verified with USA saves). Copy to Bank or export native RK4 files; conversion to another game's format explains the loss of Ranch ownership metadata. Deposits, edits and withdrawals are disabled. The Platinum revision is not yet verified.
- **Generation IV:** Diamond, Pearl, Platinum, HeartGold, SoulSilver
- **Generation V:** Black, White, Black 2, White 2
- **Generation VI:** X, Y, Omega Ruby, Alpha Sapphire
Expand All @@ -154,6 +155,7 @@ Link a storage unit and PKForge finds your saves automatically:
- **Game Boy Advance:** RetroArch, Linkboy, Pizza Boy A
- **Nintendo DS:** melonDS, DraStic, RetroArch
- **GameCube:** Dolphin
- **Wii storage:** Dolphin discovery of the USA My Pokémon Ranch main save (`savedata.bin`); automatic backups are excluded from discovery and can be opened explicitly.
- **Nintendo 3DS:** Azahar, Lime3DS, Citra MMJ
- **Nintendo Switch:** Eden

Expand Down
36 changes: 27 additions & 9 deletions src/PKForge.App/Platforms/Android/AndroidEmulatorScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void OnFile(ChildDocument child)
state.Trace($"RAW MEMORY CARD {child.Name}: individual GCI export required");
return;
}
if (!EmulatorSaveHeuristics.IsCandidateFileName(child.Name, kind)) return;
if (!EmulatorSaveHeuristics.IsCandidateFileName(child.Name, kind, child.ScanPath ?? child.DocId)) return;
if (TryDetect(treeUri, child, kind, gameLabel: child.Name, state: state) is { } save)
{
results.Add(save);
Expand All @@ -152,9 +152,12 @@ void OnFile(ChildDocument child)
}

var rootChildren = ListChildren(treeUri, rootDocId);
// SAF providers may use opaque ids (e.g. msd:123). Walk display names for
// the Ranch title filter rather than assuming every document id is a path.
var rootPath = kind == EmulatorKind.Dolphin ? rootDocId + "/" + DocumentName(treeUri, rootDocId) : null;
string[] preferredFolders = kind switch
{
EmulatorKind.Dolphin => ["GC"],
EmulatorKind.Dolphin => ["GC", "Wii"],
EmulatorKind.DraStic => ["backup"],
EmulatorKind.PizzaBoyGba or EmulatorKind.PizzaBoyGbc => ["save", "saves"],
_ => ["saves"],
Expand All @@ -164,13 +167,14 @@ void OnFile(ChildDocument child)
{
state.Siblings = rootChildren.Where(x => !x.IsDirectory).Select(x => x.Name).ToArray();
foreach (var file in rootChildren.Where(x => !x.IsDirectory))
OnFile(file);
OnFile(rootPath is null ? file : file with { ScanPath = rootPath + "/" + file.Name });
foreach (var savesDir in savesDirs)
FindFilesRecursive(treeUri, savesDir.DocId, maxDepth, cancellationToken, OnFile, state);
FindFilesRecursive(treeUri, savesDir.DocId, maxDepth, cancellationToken, OnFile, state,
scanPath: rootPath is null ? null : rootPath + "/" + savesDir.Name);
}
else
{
FindFilesRecursive(treeUri, rootDocId, maxDepth, cancellationToken, OnFile, state);
FindFilesRecursive(treeUri, rootDocId, maxDepth, cancellationToken, OnFile, state, scanPath: rootPath);
}
return results;
}
Expand Down Expand Up @@ -346,7 +350,7 @@ IEnumerable<TreeEntry<ChildDocument>> List(ChildDocument doc) =>
}
}

private sealed record ChildDocument(string DocId, string Name, bool IsDirectory, DateTimeOffset? LastModified);
private sealed record ChildDocument(string DocId, string Name, bool IsDirectory, DateTimeOffset? LastModified, string? ScanPath = null);

/// <summary>Android's last package update time: zero-once per install, stable after.</summary>
private static long _installEpoch = -1;
Expand Down Expand Up @@ -442,7 +446,7 @@ private static void Load()

private void FindFilesRecursive(AndroidUri treeUri, string parentDocId, int maxDepth,
CancellationToken cancellationToken, Action<ChildDocument> onFile, ScanState state,
bool diagnostic = false)
bool diagnostic = false, string? scanPath = null)
{
if (maxDepth <= 0)
{
Expand All @@ -463,16 +467,30 @@ private void FindFilesRecursive(AndroidUri treeUri, string parentDocId, int maxD
if (diagnostic) state.Trace($"PRUNED directory {child.Name}");
continue;
}
FindFilesRecursive(treeUri, child.DocId, maxDepth - 1, cancellationToken, onFile, state, diagnostic);
FindFilesRecursive(treeUri, child.DocId, maxDepth - 1, cancellationToken, onFile, state, diagnostic,
scanPath is null ? null : scanPath + "/" + child.Name);
}
else
{
state.Siblings = siblings;
onFile(child);
onFile(scanPath is null ? child : child with { ScanPath = scanPath + "/" + child.Name });
}
}
}

private static string? DocumentName(AndroidUri treeUri, string documentId)
{
try
{
var uri = DocumentsContract.BuildDocumentUriUsingTree(treeUri, documentId);
if (uri is null) return null;
using var cursor = Android.App.Application.Context.ContentResolver?.Query(uri,
[DocumentsContract.Document.ColumnDisplayName], null, null, null);
return cursor is not null && cursor.MoveToFirst() ? cursor.GetString(0) : null;
}
catch (Java.Lang.RuntimeException) { return null; } // optional hint; retain the document id
}

private static string? NavigatePath(AndroidUri treeUri, string fromDocId, string[] segments, Action<string>? trace = null)
{
var current = fromDocId;
Expand Down
12 changes: 10 additions & 2 deletions src/PKForge.App/ViewModels/BoxBrowserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ public async Task<bool> RunMutationAsync(Func<ISaveEngineSession, GenerationOutc
return false;
}

if (engineSession.ReadOnlyReason is { } readOnlyReason)
{
Status = readOnlyReason;
return false;
}

try
{
IsBusy = true;
Expand Down Expand Up @@ -932,6 +938,7 @@ public bool MoveCursor(FocusDirection direction)
public void JumpTo(int box, int slot)
{
if (Save is null || box < -1 || box >= BoxCount) return;
if (box == -1 && _sessions.CurrentSession?.HasParty == false) return;
PendingRectangle = null;
BoxIndex = box;
SelectedSlot = -1;
Expand All @@ -945,9 +952,10 @@ public void ChangeBox(int delta)
{
if (Save is null || BoxCount == 0) return;
// The party wraps around the boxes: last box, then PARTY, then box 1 again.
var first = _sessions.CurrentSession?.HasParty == false ? 0 : -1;
var next = BoxIndex + delta;
if (next > BoxCount - 1) next = -1;
else if (next < -1) next = BoxCount - 1;
if (next > BoxCount - 1) next = first;
else if (next < first) next = BoxCount - 1;
PendingRectangle = null; // a rectangle belongs to one page
BoxIndex = next;
SelectedSlot = -1;
Expand Down
43 changes: 23 additions & 20 deletions src/PKForge.App/Views/BoxBrowserPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public BoxBrowserPage(BoxBrowserViewModel viewModel, ISpriteService sprites, The
var root = new Grid
{
RowDefinitions = [new(GridLength.Auto), new(GridLength.Auto), new(GridLength.Star), new(GridLength.Auto)],
Children = { DsChrome.TitleBar(), DsChrome.StatusStrip(title, "Connected"), bodyHost, _footerHost },
Children = { DsChrome.TitleBar(), DsChrome.StatusStrip(title, _sessionsFor()?.ReadOnlyReason is null ? "Connected" : "Read-only"), bodyHost, _footerHost },
};
Grid.SetRow((View)root.Children[1], 1);
Grid.SetRow(bodyHost, 2);
Expand Down Expand Up @@ -359,8 +359,9 @@ private void SetBoxManageFooter() => _footerHost.Content = DsChrome.Footer(
private static SaveGuard Guard => HardcoreMode.Guard;

/// <summary>A menu entry that exists only while Hardcore mode allows its action; null hides it.</summary>
private static PadOption? Allowed(SaveAction action, PadOption option) =>
Guard.Allows(action) ? option : null;
private PadOption? Allowed(SaveAction action, PadOption option, bool changesSource = true) =>
Guard.Allows(action) && (_sessionsFor()?.ReadOnlyReason is null ||
!changesSource || action is SaveAction.ExportFile or SaveAction.Backup) ? option : null;

/// <summary>The menu's options without the entries Hardcore mode refuses.</summary>
private static PadOption[] Menu(params PadOption?[] options) =>
Expand Down Expand Up @@ -389,7 +390,9 @@ private async Task<bool> DeniedAsync(SaveAction action)
}

/// <summary>The idle status line, carrying the marker so the mode is visible on the screen it gates.</summary>
private void ShowReady() => _viewModel.Status = HardcoreMode.IsOn
private void ShowReady() => _viewModel.Status = _sessionsFor()?.ReadOnlyReason is not null
? "Read-only · export available"
: HardcoreMode.IsOn
? $"Ready · {HardcoreMode.StatusLine}"
: LayoutMarker ?? "Ready";

Expand Down Expand Up @@ -495,7 +498,7 @@ private View BuildSidePanel()
{
PksmIcons.Icon("storage", 44),
new Label { Text = "Select a Pokémon", TextColor = UiTokens.Ink1, FontFamily = DsChrome.PixelFont, FontSize = 15 },
new Label { Text = "Tap an empty slot to add one", TextColor = UiTokens.Ink1, FontSize = UiTokens.TextSmall, HorizontalTextAlignment = TextAlignment.Center },
new Label { Text = _sessionsFor()?.ReadOnlyReason is null ? "Tap an empty slot to add one" : "Inspect, copy or export Pokémon", TextColor = UiTokens.Ink1, FontSize = UiTokens.TextSmall, HorizontalTextAlignment = TextAlignment.Center },
},
};

Expand Down Expand Up @@ -1178,14 +1181,14 @@ private async Task ShowOrganizerMenuAsync()
{
options.Add(new("Clear marks", IconPath: "deselect"));
options.AddRange(Menu(
new PadOption("Move to box…", IconPath: "move"),
new PadOption("Move to Bank", IconPath: "bank", Detail: "They leave this save and are stored in the Bank."),
Allowed(SaveAction.Duplicate, new("Copy to Bank", IconPath: "bank", Detail: "Copies go to the Bank; the originals stay here.")),
new PadOption("Move to another game…", IconPath: "send", Detail: "They leave this save and join another linked game."),
Allowed(SaveAction.Duplicate, new("Copy to another game…", IconPath: "copy", Detail: "Copies join another linked game; the originals stay here.")),
Allowed(SaveAction.Move, new("Move to box…", IconPath: "move")),
Allowed(SaveAction.Move, new("Move to Bank", IconPath: "bank", Detail: "They leave this save and are stored in the Bank.")),
Allowed(SaveAction.Duplicate, new("Copy to Bank", IconPath: "bank", Detail: "Copies go to the Bank; the originals stay here."), changesSource: false),
Allowed(SaveAction.Move, new("Move to another game…", IconPath: "send", Detail: "They leave this save and join another linked game.")),
Allowed(SaveAction.Duplicate, new("Copy to another game…", IconPath: "copy", Detail: "Copies join another linked game; the originals stay here."), changesSource: false),
Allowed(SaveAction.Duplicate, new("Duplicate", IconPath: "copy", Detail: "Clone the marked Pokémon into the first free box slots.")),
new PadOption("Export (.pk files)", IconPath: "export", Detail: "Share each marked Pokémon as its own file."),
new PadOption("Release", IconPath: "release")));
Allowed(SaveAction.Release, new("Release", IconPath: "release"))));
options.AddRange(BulkOptions());
}
options.Add(new("Mark Pokémon holding…", IconPath: "item", Detail: "Find Pokémon holding an item, then mark them or go to one."));
Expand Down Expand Up @@ -3807,22 +3810,22 @@ private async Task ShowMonActionsAsync(int slot)
}
options.AddRange(Menu(
new PadOption("Summary", IconPath: "info"),
new PadOption("Edit", IconPath: "editor"),
_sessionsFor()?.ReadOnlyReason is null ? new PadOption("Edit", IconPath: "editor") : null,
Allowed(SaveAction.EditMon, new("Evolve…", IconPath: "evolve")),
new PadOption("Send to Poképark", IconPath: "park", Detail: "Adds it to the Poképark visitors. The save is not changed."),
new PadOption("Move", IconPath: "move", Detail: "Pick it up and carry it to another slot."),
Allowed(SaveAction.Move, new("Move", IconPath: "move", Detail: "Pick it up and carry it to another slot.")),
Allowed(SaveAction.Duplicate, new("Duplicate", IconPath: "copy", Detail: "Clone it into the next empty slot here.")),
new PadOption("Send to Bank", IconPath: "bank", Detail: "It leaves this save and is stored in the Bank."),
Allowed(SaveAction.Duplicate, new("Copy to Bank", IconPath: "copy", Detail: "A copy goes to the Bank; the original stays here.")),
new PadOption("Send to another game…", IconPath: "send", Detail: "It leaves this save and joins another linked game."),
Allowed(SaveAction.Duplicate, new("Copy to another game…", IconPath: "copy", Detail: "A copy joins another linked game; the original stays here.")),
Allowed(SaveAction.Move, new("Send to Bank", IconPath: "bank", Detail: "It leaves this save and is stored in the Bank.")),
Allowed(SaveAction.Duplicate, new("Copy to Bank", IconPath: "copy", Detail: "A copy goes to the Bank; the original stays here."), changesSource: false),
Allowed(SaveAction.Move, new("Send to another game…", IconPath: "send", Detail: "It leaves this save and joins another linked game.")),
Allowed(SaveAction.Duplicate, new("Copy to another game…", IconPath: "copy", Detail: "A copy joins another linked game; the original stays here."), changesSource: false),
new PadOption("Export .pk file", IconPath: "export", Detail: "Share this Pokémon as a file."),
new PadOption("Show as Showdown set", IconPath: "script", Detail: "Its set as Showdown text you can copy."),
new PadOption("Show as QR code", IconPath: "qr", Detail: "Its Showdown set as a QR code."),
new PadOption("Show as .pk QR", IconPath: "qr", Detail: "The whole Pokémon as a QR code that PKForge can scan into the Bank."),
new PadOption("RNG / IVs", IconPath: "dice", Detail: "See its PID and IVs, and change its nature without losing shininess."),
new PadOption("Lock / Unlock release", IconPath: "padlock", Detail: "A locked Pokémon cannot be released."),
new PadOption("Release", IconPath: "release")));
Allowed(SaveAction.Release, new("Release", IconPath: "release"))));
var choice = await PadMenu.ShowAsync(_hostGrid, nickname,
Note(verdict is { Valid: false } ? verdict.Problem : null), options.ToArray());
switch (choice)
Expand Down Expand Up @@ -4190,9 +4193,9 @@ private async Task SendSlotToAnotherGameAsync(int slot, string nickname, bool co
var export = session.ExportSlot(_viewModel.BoxIndex, slot);
// Cross-generation conversions change things; the diff preview is the trust
// step before the write. Same-generation sends show an empty diff.
var preview = await transfer.PreviewAsync(export.Data, nickname, target);
var preview = await transfer.PreviewAsync(export.Data, nickname, target, format: export.Format);
if (!await Services.TransferPreviewPrompt.ConfirmAsync(_hostGrid, preview, nickname, target.GameLabel)) return;
var outcome = await transfer.SendToGameAsync(export.Data, nickname, target);
var outcome = await transfer.SendToGameAsync(export.Data, nickname, target, format: export.Format);
_viewModel.Status = outcome.Message;
if (!outcome.Success || copyInsteadOfMove) return;

Expand Down
8 changes: 8 additions & 0 deletions src/PKForge.App/Views/BoxGridRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ internal static void PaintScene(SKCanvas canvas, SKImageInfo info, StorageScene
for (var index = 0; index < Columns * Rows; index++)
{
var cell = layout.Cell(index);
// A capacity-limited storage save can end partway through a grid page.
if (index >= slots.Count)
{
using var unavailable = new SKPaint { Color = SKColors.Gray.WithAlpha(45), Style = SKPaintStyle.Stroke, StrokeWidth = 1 };
canvas.DrawLine(cell.Left, cell.Top, cell.Right, cell.Bottom, unavailable);
canvas.DrawLine(cell.Right, cell.Top, cell.Left, cell.Bottom, unavailable);
continue;
}
// Badges keep the square tile they were designed for, centered in the wide cell.
var tile = SKRect.Create(cell.MidX - layout.CellHeight / 2, cell.Top, layout.CellHeight, layout.CellHeight);

Expand Down
6 changes: 3 additions & 3 deletions src/PKForge.App/Views/HomePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private async Task ShowLinkMenuAsync()
new PadOption("Game Boy / Game Boy Color", IconPath: "platform-gb"),
new PadOption("Game Boy Advance", IconPath: "platform-gba"),
new PadOption("Nintendo DS", IconPath: "platform-ds"),
new PadOption("GameCube", IconPath: "platform-gc"),
new PadOption("GameCube / Wii", IconPath: "platform-gc"),
new PadOption("Nintendo 3DS", IconPath: "azahar"),
new PadOption("Nintendo Switch", IconPath: "eden"),
new PadOption("Single save file", IconPath: "file"));
Expand All @@ -545,7 +545,7 @@ private async Task ShowLinkMenuAsync()
new PadOption("DraStic", IconPath: "drastic"),
new PadOption("RetroArch", IconPath: "retroarch"),
},
"GameCube" => new[] { new PadOption("Dolphin", IconPath: "dolphin") },
"GameCube / Wii" => new[] { new PadOption("Dolphin", IconPath: "dolphin") },
"Nintendo 3DS" => new[]
{
new PadOption("Azahar / Lime3DS", IconPath: "azahar"),
Expand All @@ -557,7 +557,7 @@ private async Task ShowLinkMenuAsync()
if (choice is null) continue;
var guidance = choice switch
{
"Dolphin" => "Save in game and stop emulation before editing Colosseum or XD. Select Dolphin's GC folder, a region folder, or Card A / Card B containing .gci saves. For .raw memory cards, export the game as GCI with Dolphin's Memory Card Manager, or configure that card slot as GCI Folder. After editing, start the game normally; loading an old save state can undo your edits.",
"Dolphin" => "Select Dolphin's user folder, GC, or Wii. GameCube saves use .gci files; My Pokémon Ranch uses savedata.bin and supports copy/export only. Save in game and stop emulation before editing GameCube saves. For .raw memory cards, export the game as GCI with Dolphin's Memory Card Manager, or configure that card slot as GCI Folder. After editing, start the game normally; loading an old save state can undo your edits.",
"DraStic" => "Save in game and close DraStic. Select its backup folder containing .dsv battery saves, or the DraStic data folder. Save states are not supported. Restart the game normally after editing.",
"Pizza Boy A (GBA)" or "Pizza Boy C (GB/GBC)" => "Save in game and close Pizza Boy. Select the folder containing its battery saves (.sav), not save states. If Android hides the folder, export the battery save in Pizza Boy and link that export. Import the edited export back into Pizza Boy, then restart the game normally.",
"Azahar / Lime3DS" => "Save in game and close the emulator. Select the user folder you chose in its setup (the one containing sdmc); sdmc, Nintendo 3DS or a folder above the user folder also work. Restart the game normally after editing.",
Expand Down
Loading