Skip to content
Merged
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
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,19 @@ add_executable(test_ge_renderer tests/test_ge_renderer.cpp)
target_link_libraries(test_ge_renderer PRIVATE p3p3ds_core)
add_test(NAME p3p_ge_renderer COMMAND test_ge_renderer)
# Builder (ISO -> .3dsx) pieces that run on the host and are unit-tested here.
add_library(p3p3ds_builder_core STATIC platform/pc/builder/psp_eboot.cpp platform/pc/builder/game_prep.cpp)
add_library(p3p3ds_builder_core STATIC platform/pc/builder/psp_eboot.cpp platform/pc/builder/game_prep.cpp
platform/pc/builder/update_check.cpp)
target_include_directories(p3p3ds_builder_core PUBLIC platform/pc/builder)
target_link_libraries(p3p3ds_builder_core PUBLIC p3p3ds_core)
# The Builder's version lives in one place, builder.rc (release.yml checks
# release tags against it); the update check (#67) reads it from there.
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/platform/pc/builder/builder.rc" _builder_version_line REGEX "VALUE \"FileVersion\"")
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" P3P3DS_BUILDER_VERSION "${_builder_version_line}")
if(NOT P3P3DS_BUILDER_VERSION)
message(FATAL_ERROR "no FileVersion in platform/pc/builder/builder.rc")
endif()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/platform/pc/builder/builder.rc")
target_compile_definitions(p3p3ds_builder_core PRIVATE P3P3DS_BUILDER_VERSION="${P3P3DS_BUILDER_VERSION}")
# ISO -> eboot.elf for the developer setup (tools/prepare_game.py delegates to it).
# Built without game files, so a fresh checkout can prepare the ELF first.
add_executable(p3p_prepare_elf platform/pc/builder/prepare_elf_main.cpp)
Expand All @@ -367,7 +377,7 @@ endif()
if(WIN32)
enable_language(RC)
add_executable(p3p3ds_builder WIN32 platform/pc/builder/builder_main.cpp platform/pc/builder/pipeline.cpp platform/pc/builder/builder.rc)
target_link_libraries(p3p3ds_builder PRIVATE p3p3ds_builder_core p3p3ds_core comctl32 comdlg32 shell32 ole32)
target_link_libraries(p3p3ds_builder PRIVATE p3p3ds_builder_core p3p3ds_core comctl32 comdlg32 shell32 ole32 winhttp)
target_compile_definitions(p3p3ds_builder PRIVATE UNICODE _UNICODE)
if(MINGW)
target_link_options(p3p3ds_builder PRIVATE -municode -static)
Expand All @@ -380,6 +390,9 @@ endif()
set_target_properties(p3p3ds_builder PROPERTIES OUTPUT_NAME "P3P3DS-Builder")
configure_file(profiles/p3p/config/aot_layout.hpp.in generated/aot_layout.hpp @ONLY)
target_include_directories(p3p3ds_builder PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/generated")
add_executable(test_update_check tests/test_update_check.cpp)
target_link_libraries(test_update_check PRIVATE p3p3ds_builder_core)
add_test(NAME p3p_update_check COMMAND test_update_check "${P3P3DS_BUILDER_VERSION}")
add_executable(test_psp_eboot tests/test_psp_eboot.cpp)
target_link_libraries(test_psp_eboot PRIVATE p3p3ds_builder_core p3p3ds_core)
file(GLOB P3P_LOCAL_ISOS "${CMAKE_CURRENT_SOURCE_DIR}/*.iso")
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ You need:
3. Wait about 5-15 minutes: the game's code is translated to C++ and compiled for the 3DS on all CPU cores, with a progress bar, a time estimate and Persona 3 trivia. An interrupted build continues where it stopped.
4. The builder can copy everything to your SD card itself; otherwise copy as shown below.

When a newer Builder is released, the window shows **Update: Builder X.Y.Z is available** in its bottom left corner; the button opens the release page. The Windows wizard only asks GitHub for the latest release tag when it starts (nothing is downloaded or installed, no identifiers are sent); `--no-update-check` or the environment variable `P3P3DS_NO_UPDATE_CHECK=1` turns that off, and `--cli` builds never check. `P3P3DS-Builder.exe --check-update` prints the result in a console, `--version` shows the version.

On Linux the builder is a console program (`P3P3DS-Builder-<version>-linux.tar.gz`): `./P3P3DS-Builder --iso <iso> [--devkitpro <dir>] [--out <file>] [--jobs <n>]`; devkitPro is looked up in `$DEVKITPRO`, then `/opt/devkitpro`. On NixOS run it inside `p3p-3ds` from `shell.nix`, where devkitPro's prebuilt binaries work.

The builder package (about 2 MB zipped) contains no game data: only the prebuilt P3P3DS runtime for the 3DS, the code generator and the community CWCheat patch list; everything made from the game is generated on your PC. Measured clean builds on a 12-thread CPU: 4 min 23 s with 12 compiler jobs, 4 min 55 s with 7 (the builder picks the number from CPU cores and free memory).
Expand Down
5 changes: 5 additions & 0 deletions docs/CURRENT_STATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This is the current source of truth, newest entries first. Evidence concerns ULUS-10512; each section says whether it was measured on the PC runner, in Azahar or on a real New 3DS.

## Builder shows when a newer release exists (#67, 2026-11-05)

- `platform/pc/builder/update_check.cpp` (version parsing, top-level `tag_name` of a GitHub releases/latest response, comparison; no network code) and the wizard (`builder_main.cpp`): on start a detached thread GETs `https://api.github.com/repos/endercodezz/P3P3DS/releases/latest` with WinHTTP (5 s timeouts, `User-Agent: P3P3DS-Builder/<version>`), and a newer tag shows a bottom-left button that opens `https://github.com/endercodezz/P3P3DS/releases/tag/<tag>`. The page URL is built from the validated tag, never taken from the response. Off with `--no-update-check` or `P3P3DS_NO_UPDATE_CHECK`; `--cli` never checks; `--check-update` prints the result; `P3P3DS_UPDATE_URL` overrides the URL for tests. The version comes from `builder.rc` FileVersion through CMake, so a release still bumps one place.
- [VERIFIED] Windows: real API: "latest release: v0.3.2; no update" in about 1 s. Local test server returning `v9.9.9` (with a foreign `html_url` and a nested `tag_name`): banner "Update: Builder 9.9.9 is available" (window capture `.tmp/upd/banner.png`), page built from the tag. Unreachable server: no banner, `--check-update` returns after about 2 s. Server log: 0 requests from `--cli`, `--no-update-check` and `P3P3DS_NO_UPDATE_CHECK=1`. Imports: system DLLs and UCRT only, plus `WINHTTP.dll`. `test_update_check` and CTest 32/32. [UNVERIFIED] Linux console Builder: only `--version`, no check.

## Texture pack format: Rust writer and C++ reader tested together (#63, 2026-11-05)

- CTest `p3p_texpack_build_rgba8` / `p3p_texpack_build_auto` run `p3p-texpack build` on `tools/texpack/tests/fixtures` (`textures.ini` there), `p3p_texpack_roundtrip` (`tests/test_texture_pack_roundtrip.cpp`) reads both packs with the runtime's `TexturePack` and compares every texel with the fixture formulas after the format's rules (header, entry order, alignment, row order, tiling, format codes, channel packing, keep-original entry). Registered only when CMake finds `cargo` (Linux CI and local builds; not the MSYS2 Windows job).
Expand Down
115 changes: 111 additions & 4 deletions platform/pc/builder/builder_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// [--jobs <n>] [--work <dir>]` runs the same build in a console.
// Linux and other POSIX hosts: console only, same options (`--cli` optional).
#include "pipeline.hpp"
#include "update_check.hpp"

#ifdef _WIN32
#include "fun_facts.hpp"
Expand All @@ -16,6 +17,7 @@
#include <commdlg.h>
#include <shellapi.h>
#include <shlobj.h>
#include <winhttp.h>
#endif

#include <chrono>
Expand Down Expand Up @@ -67,12 +69,12 @@ int run_console(const Settings &s) {
namespace {

constexpr int kWidth = 620, kHeight = 470, kHeader = 64;
constexpr UINT WM_BUILD_PROGRESS = WM_APP + 1, WM_BUILD_LOG = WM_APP + 2, WM_BUILD_DONE = WM_APP + 3;
constexpr UINT WM_BUILD_PROGRESS = WM_APP + 1, WM_BUILD_LOG = WM_APP + 2, WM_BUILD_DONE = WM_APP + 3, WM_UPDATE_FOUND = WM_APP + 4;
constexpr UINT_PTR kFactTimer = 1;
enum Id : int {
IdBack = 100, IdNext, IdCancel,
IdIso, IdIsoBrowse, IdIsoStatus, IdDkp, IdDkpBrowse, IdDkpStatus, IdDkpLink, IdOut, IdOutBrowse, IdSdCheck, IdSdDrive,
IdStep, IdBar, IdTime, IdFact, IdNextFact, IdLog, IdOpenFolder,
IdStep, IdBar, IdTime, IdFact, IdNextFact, IdLog, IdOpenFolder, IdUpdate, IdUpdateClose,
};
enum Page { Welcome, Setup, Build, Finish };

Expand All @@ -85,6 +87,8 @@ struct App {
HWND back{}, next{}, cancel{};
HWND iso{}, iso_status{}, dkp{}, dkp_status{}, out{}, sd_check{}, sd_drive{};
HWND step{}, bar{}, time{}, fact{}, log{}, finish_text{}, open_folder{};
HWND update{}, update_close{};
std::wstring update_page;
fs::path exe_dir;
std::unique_ptr<Pipeline> pipeline;
std::thread worker;
Expand Down Expand Up @@ -242,7 +246,8 @@ void create_controls() {
L"This wizard builds P3P3DS - Persona 3 Portable running natively on the New Nintendo 3DS - "
L"from your own copy of the game (ULUS-10512).\n\n"
L"It reads the game's executable from your ISO, translates it to native 3DS code and packages "
L"p3p3ds.3dsx for the Homebrew Launcher. Nothing is downloaded.\n\n"
L"p3p3ds.3dsx for the Homebrew Launcher. Nothing is downloaded; the Builder only asks GitHub whether a newer "
L"version exists (start it with --no-update-check to turn that off).\n\n"
L"You need: your Persona 3 Portable ISO, and devkitPro with the 3DS development tools installed. "
L"The build takes about 5-15 minutes depending on your CPU.\n\n"
L"The result contains code made from your game: it is for you only. Please do not share it.\n\n"
Expand Down Expand Up @@ -290,7 +295,13 @@ void create_controls() {
reinterpret_cast<HMENU>(IdNext), app.inst, nullptr);
app.cancel = CreateWindowExW(0, L"BUTTON", L"Exit", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, kWidth - 108, kHeight - 44, 86, 28, app.wnd,
reinterpret_cast<HMENU>(IdCancel), app.inst, nullptr);
for (HWND b : {app.back, app.next, app.cancel}) SendMessageW(b, WM_SETFONT, reinterpret_cast<WPARAM>(app.font), TRUE);
// Update banner (#67), hidden until a newer release is found.
app.update = CreateWindowExW(0, L"BUTTON", L"", WS_CHILD | BS_PUSHBUTTON, left, kHeight - 44, 230, 28, app.wnd,
reinterpret_cast<HMENU>(IdUpdate), app.inst, nullptr);
app.update_close = CreateWindowExW(0, L"BUTTON", L"x", WS_CHILD | BS_PUSHBUTTON, left + 234, kHeight - 44, 28, 28, app.wnd,
reinterpret_cast<HMENU>(IdUpdateClose), app.inst, nullptr);
for (HWND b : {app.back, app.next, app.cancel, app.update, app.update_close})
SendMessageW(b, WM_SETFONT, reinterpret_cast<WPARAM>(app.font), TRUE);

// Defaults: the single ISO next to the builder, devkitPro guess, output folder next to the builder.
for (const auto &e : fs::directory_iterator(app.exe_dir))
Expand Down Expand Up @@ -367,6 +378,11 @@ LRESULT CALLBACK wnd_proc(HWND h, UINT msg, WPARAM wp, LPARAM lp) {
if (!f.empty()) SetWindowTextW(app.out, f.c_str());
} else if (id == IdDkpLink) {
ShellExecuteW(h, L"open", L"https://devkitpro.org/wiki/Getting_Started", nullptr, nullptr, SW_SHOWNORMAL);
} else if (id == IdUpdate) {
ShellExecuteW(h, L"open", app.update_page.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
} else if (id == IdUpdateClose) {
ShowWindow(app.update, SW_HIDE);
ShowWindow(app.update_close, SW_HIDE);
} else if (id == IdNextFact) {
next_fact();
} else if (id == IdOpenFolder) {
Expand Down Expand Up @@ -400,6 +416,15 @@ LRESULT CALLBACK wnd_proc(HWND h, UINT msg, WPARAM wp, LPARAM lp) {
SendMessageW(app.log, EM_REPLACESEL, FALSE, reinterpret_cast<LPARAM>(w.c_str()));
return 0;
}
case WM_UPDATE_FOUND: {
std::unique_ptr<Update> update(reinterpret_cast<Update *>(lp));
app.update_page = widen(update->page);
const std::wstring label = L"Update: Builder " + widen(version_string(update->version)) + L" is available";
SetWindowTextW(app.update, label.c_str());
ShowWindow(app.update, SW_SHOW);
ShowWindow(app.update_close, SW_SHOW);
return 0;
}
case WM_BUILD_DONE: {
std::unique_ptr<std::string> err(reinterpret_cast<std::string *>(lp));
if (app.worker.joinable()) app.worker.join();
Expand Down Expand Up @@ -435,6 +460,62 @@ LRESULT CALLBACK wnd_proc(HWND h, UINT msg, WPARAM wp, LPARAM lp) {
}
}

// GET `url` with WinHTTP (system DLL; the Builder stays statically linked
// against system DLLs only). Empty on any failure; 5 s timeouts; at most 1 MiB.
std::string http_get(const std::wstring &url) {
wchar_t host[256], path[2048];
URL_COMPONENTS parts{};
parts.dwStructSize = sizeof parts;
parts.lpszHostName = host;
parts.dwHostNameLength = 256;
parts.lpszUrlPath = path;
parts.dwUrlPathLength = 2048;
if (!WinHttpCrackUrl(url.c_str(), 0, 0, &parts)) return {};
const std::wstring agent = L"P3P3DS-Builder/" + widen(version_string(builder_version()));
std::string body;
HINTERNET session = WinHttpOpen(agent.c_str(), WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
HINTERNET connection = session ? WinHttpConnect(session, host, parts.nPort, 0) : nullptr;
HINTERNET request = connection ? WinHttpOpenRequest(connection, L"GET", path, nullptr, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES,
parts.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0)
: nullptr;
if (session) WinHttpSetTimeouts(session, 5000, 5000, 5000, 5000);
DWORD status = 0, size = sizeof status;
if (request && WinHttpSendRequest(request, L"Accept: application/vnd.github+json\r\n", static_cast<DWORD>(-1), WINHTTP_NO_REQUEST_DATA, 0, 0, 0) &&
WinHttpReceiveResponse(request, nullptr) &&
WinHttpQueryHeaders(request, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, WINHTTP_HEADER_NAME_BY_INDEX, &status, &size,
WINHTTP_NO_HEADER_INDEX) &&
status == 200) {
char buffer[8192];
DWORD read = 0;
while (body.size() < (1u << 20) && WinHttpReadData(request, buffer, sizeof buffer, &read) && read > 0) body.append(buffer, read);
}
if (request) WinHttpCloseHandle(request);
if (connection) WinHttpCloseHandle(connection);
if (session) WinHttpCloseHandle(session);
return body;
}

bool update_check_enabled(int argc, wchar_t **argv) {
for (int i = 1; i < argc; ++i)
if (std::wstring(argv[i]) == L"--no-update-check") return false;
const char *off = std::getenv(kNoUpdateCheckEnv);
return off == nullptr || off[0] == '\0' || std::string(off) == "0";
}

// Asks GitHub for the latest release on a detached thread (a slow network
// must not hold up closing the window) and posts WM_UPDATE_FOUND if it is newer.
void start_update_check(HWND wnd) {
const char *override_url = std::getenv(kUpdateUrlEnv);
const std::wstring url = widen(override_url && override_url[0] ? override_url : kLatestReleaseUrl);
std::thread([wnd, url] {
const std::string body = http_get(url);
if (auto update = newer_release(body, builder_version())) {
auto *message = new Update(std::move(*update));
if (!PostMessageW(wnd, WM_UPDATE_FOUND, 0, reinterpret_cast<LPARAM>(message))) delete message; // window already gone
}
}).detach();
}

int run_cli(int argc, wchar_t **argv) {
// Keep a redirected stdout (file/pipe); otherwise write to the parent console.
const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
Expand Down Expand Up @@ -465,6 +546,27 @@ int WINAPI wWinMain(HINSTANCE inst, HINSTANCE, PWSTR, int show) {
wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc);
for (int i = 1; i < argc; ++i)
if (std::wstring(argv[i]) == L"--cli") return run_cli(argc, argv);
for (int i = 1; i < argc; ++i)
if (std::wstring(argv[i]) == L"--check-update") { // console: the wizard's check, printed
const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
if (out == nullptr || out == INVALID_HANDLE_VALUE || GetFileType(out) == FILE_TYPE_UNKNOWN) {
if (!AttachConsole(ATTACH_PARENT_PROCESS)) AllocConsole();
std::freopen("CONOUT$", "w", stdout);
}
const char *override_url = std::getenv(kUpdateUrlEnv);
const std::string body = http_get(widen(override_url && override_url[0] ? override_url : kLatestReleaseUrl));
const auto tag = latest_release_tag(body);
const auto update = newer_release(body, builder_version());
std::printf("P3P3DS Builder %s; latest release: %s; %s\n", version_string(builder_version()).c_str(),
tag ? tag->c_str() : "unknown (no answer)", update ? ("update available: " + update->page).c_str() : "no update");
return 0;
}
for (int i = 1; i < argc; ++i)
if (std::wstring(argv[i]) == L"--version") {
const std::wstring text = L"P3P3DS Builder " + widen(version_string(builder_version()));
MessageBoxW(nullptr, text.c_str(), L"P3P3DS Builder", MB_OK | MB_ICONINFORMATION);
return 0;
}

SetProcessDPIAware();
INITCOMMONCONTROLSEX icc{sizeof icc, ICC_PROGRESS_CLASS | ICC_STANDARD_CLASSES};
Expand Down Expand Up @@ -496,6 +598,7 @@ int WINAPI wWinMain(HINSTANCE inst, HINSTANCE, PWSTR, int show) {
create_controls();
show_page(Welcome);
ShowWindow(app.wnd, show);
if (update_check_enabled(argc, argv)) start_update_check(app.wnd);
MSG msg;
while (GetMessageW(&msg, nullptr, 0, 0)) {
if (!IsDialogMessageW(app.wnd, &msg)) {
Expand All @@ -518,6 +621,10 @@ int main(int argc, char **argv) {
const std::string a = argv[i];
const bool has_value = i + 1 < argc;
if (a == "--cli") continue;
if (a == "--version") {
std::printf("P3P3DS Builder %s\n", version_string(builder_version()).c_str());
return 0;
}
if (a == "--help" || a == "-h") {
std::printf("usage: %s --iso <ULUS-10512.iso> [--devkitpro <dir>] [--out <file.3dsx>] [--jobs <n>] [--work <dir>]\n", argv[0]);
return 0;
Expand Down
Loading