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
13 changes: 9 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ jobs:
- name: Run GUI theme smoke test (light/dark, offscreen Qt)
run: ./build/gui_theme_smoke

- name: Run GUI Help Markdown smoke test (offscreen Qt)
run: ./build/gui_help_smoke

- name: Run GUI guest-scan and code-finder smoke tests
env:
QT_QPA_PLATFORM: offscreen
Expand Down Expand Up @@ -397,8 +400,9 @@ jobs:
# without ASan in ubuntu-build).
- name: Build the GUI tests (instrumented)
run: |
cmake --build build-asan -j"$(nproc)" --target gui_debugger_smoke gui_theme_smoke gui_structdissect_smoke \
gui_hexview_smoke gui_disasm_smoke gui_changeaddr_smoke gui_luaconsole_smoke gui_codefinder_smoke
cmake --build build-asan -j"$(nproc)" --target gui_debugger_smoke gui_theme_smoke gui_help_smoke \
gui_structdissect_smoke gui_hexview_smoke gui_disasm_smoke gui_changeaddr_smoke \
gui_luaconsole_smoke gui_codefinder_smoke

- name: Run the GUI tests under ASan + UBSan
timeout-minutes: 15
Expand All @@ -407,8 +411,9 @@ jobs:
UBSAN_OPTIONS: halt_on_error=1:print_stacktrace=1
QT_QPA_PLATFORM: offscreen
run: |
for test in gui_debugger_smoke gui_theme_smoke gui_structdissect_smoke gui_hexview_smoke \
gui_disasm_smoke gui_changeaddr_smoke gui_luaconsole_smoke gui_codefinder_smoke; do
for test in gui_debugger_smoke gui_theme_smoke gui_help_smoke gui_structdissect_smoke \
gui_hexview_smoke gui_disasm_smoke gui_changeaddr_smoke gui_luaconsole_smoke \
gui_codefinder_smoke; do
"./build-asan/$test"
done

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ jobs:
python3 test/mono_compatibility_gate.py build --report build/compatibility-evidence/mono-runtime.json
python3 test/mono_compatibility_gate.py build --embedded --report build/compatibility-evidence/mono-embedded.json
python3 test/gui_runtime_gate.py build --report build/compatibility-evidence/native-frontends.json
for test in gui_debugger_smoke gui_theme_smoke gui_guest_scan_smoke \
for test in gui_debugger_smoke gui_theme_smoke gui_help_smoke \
gui_guest_scan_smoke \
gui_structdissect_smoke gui_hexview_smoke gui_disasm_smoke \
gui_search_smoke gui_changeaddr_smoke gui_luaconsole_smoke \
gui_codefinder_smoke gui_lifecycle_smoke; do
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ reimplementation of Cheat Engine).

## Unreleased

- The Help window renders the whole README again and follows GitHub's Markdown
design. Qt's own Markdown importer drops every block after a raw HTML block,
and README.md opens with an `<img>`, so only the introduction and headings
used to show. The Help windows now parse the docs with the vendored md4c
(MIT) and render the result as HTML: GitHub light/dark colours, typographic
headings, bordered code cards, accent links, dim quotes, the README
screenshot (installed next to the docs), and a copy button on every code
block that copies exactly that block. The Lua documentation goes through the
same renderer. Links to help pages that ship offline (the Lua reference)
open inside the Help window; links to pages that are not installed point at
the "Open on GitHub" button instead of opening a browser or a blank page, so
that button stays the only way to the online docs. Back and Forward buttons
remember the docs opened in the window. `gui_help_smoke` renders both docs
offscreen, checks the text on both sides of the image, that clicking a code
block's copy button puts the block on the clipboard, and that in-app link
navigation works without blanking the page and Back/Forward return to the
open docs.
- Fedora and openSUSE packages are now built from
`packaging/rpm/cheat-engine-linux.spec` and attached to releases next to the
`.deb` and the AppImage. The RPM grants `cap_sys_ptrace` at install like the
Expand Down
43 changes: 40 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ add_library(cecore_tinyxml2 STATIC third_party/tinyxml2/tinyxml2.cpp)
target_include_directories(cecore_tinyxml2 PUBLIC ${CMAKE_SOURCE_DIR}/third_party/tinyxml2)
set_target_properties(cecore_tinyxml2 PROPERTIES POSITION_INDEPENDENT_CODE ON AUTOMOC OFF)

# Markdown parser for the Help windows (MIT). Qt's own Markdown importer drops
# the blocks after raw HTML and styles code blocks poorly, so the docs go
# through md4c and reach QTextBrowser as HTML.
add_library(md4c STATIC
third_party/md4c/md4c.c
third_party/md4c/entity.c
third_party/md4c/md4c-html.c)
target_include_directories(md4c PUBLIC ${CMAKE_SOURCE_DIR}/third_party/md4c)
target_compile_definitions(md4c PRIVATE MD4C_USE_UTF8)
set_target_properties(md4c PROPERTIES POSITION_INDEPENDENT_CODE ON AUTOMOC OFF)

# Capstone and Keystone declare older cmake_minimum_required values that fail
# to configure with CMake >= 3.27 unless this is set. Applies to nested
# FetchContent CMakeLists too.
Expand Down Expand Up @@ -427,6 +438,9 @@ if(Qt6_FOUND)
gui/i18n.cpp
gui/mainwindow.cpp
gui/mainwindow_menus.cpp
gui/helpmarkdown.cpp
gui/helpview.cpp
gui/helpview.hpp
gui/aboutdialog.cpp
gui/mainwindow_process.cpp
gui/mainwindow_scan.cpp
Expand Down Expand Up @@ -482,7 +496,7 @@ if(Qt6_FOUND)
scripting/lua_bitmap.cpp
)
target_include_directories(cheatengine PRIVATE ${LUA_DIR})
target_link_libraries(cheatengine PRIVATE cecore Qt6::Widgets Qt6::Network Qt6::DBus)
target_link_libraries(cheatengine PRIVATE cecore md4c Qt6::Widgets Qt6::Network Qt6::DBus)
# Global hotkeys need X11 (XGrabKey). Optional: without it, hotkeys fall back
# to Qt::ApplicationShortcut (only active when a cheatengine window is focused).
find_package(X11)
Expand Down Expand Up @@ -536,7 +550,8 @@ if(Qt6_FOUND)
list(REMOVE_ITEM CE_GUI_TEST_SOURCES gui/main.cpp gui/resources.qrc)
qt_add_executable(gui_lifecycle_smoke test/gui_lifecycle_smoke.cpp ${CE_GUI_TEST_SOURCES})
target_include_directories(gui_lifecycle_smoke PRIVATE ${CMAKE_SOURCE_DIR} ${LUA_DIR})
target_link_libraries(gui_lifecycle_smoke PRIVATE cecore Qt6::Widgets Qt6::Network Qt6::DBus)
# It compiles the whole GUI, including the md4c-based Help renderer.
target_link_libraries(gui_lifecycle_smoke PRIVATE cecore md4c Qt6::Widgets Qt6::Network Qt6::DBus)

# The AI Assistant panel with a scripted model, and its keyring client
# against a mock Secret Service (test/secret_store_gate.py).
Expand Down Expand Up @@ -658,6 +673,21 @@ if(Qt6_FOUND)
target_include_directories(gui_theme_smoke PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(gui_theme_smoke PRIVATE Qt6::Widgets)

# Offscreen smoke test for the Help windows: renders the shipped
# Markdown and checks that Qt's importer no longer drops the blocks
# after README.md's <img>. `gui_help_smoke --shot out.png` also saves
# the page for UI review.
qt_add_executable(gui_help_smoke
test/gui_help_smoke.cpp
gui/helpview.cpp
gui/helpview.hpp
gui/helpmarkdown.cpp
gui/theme.cpp # applyTheme() for the --shot render
)
target_include_directories(gui_help_smoke PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(gui_help_smoke PRIVATE md4c Qt6::Widgets)
target_compile_definitions(gui_help_smoke PRIVATE CE_SOURCE_DIR="${CMAKE_SOURCE_DIR}")

# Offscreen render harness: grabs the real Memory Viewer to a PNG so its
# layout + light/dark theming can be verified without a window manager.
# Not run in CI; used for UI review. `gui_browser_shot <out.png> [dark]`.
Expand Down Expand Up @@ -937,6 +967,8 @@ install(FILES third_party/tinyxml2/LICENSE.txt
DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses/cheat-engine-linux/tinyxml2)
install(FILES third_party/lua/LICENSE
DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses/cheat-engine-linux/lua)
install(FILES third_party/md4c/LICENSE.md
DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses/cheat-engine-linux/md4c)
install(FILES LICENSE
DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses/cheat-engine-linux)
set_target_properties(cecore PROPERTIES
Expand Down Expand Up @@ -967,8 +999,13 @@ if(TARGET cheatengine)
install(FILES packaging/cheat-engine-linux.mime.xml
DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)
# Help > Cheat Engine Help / Lua documentation open these offline.
install(FILES README.md docs/SCRIPTING.md
# Keep the repository-relative paths in the installed tree, so the links
# inside README.md ("docs/SCRIPTING.md", "docs/screenshot.png") resolve
# both in the Help window and in a dev build.
install(FILES README.md
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/cheat-engine-linux)
install(FILES docs/SCRIPTING.md docs/screenshot.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/cheat-engine-linux/docs)
endif()
# Relocatable: the prefix is found from the .pc file's own directory, so an
# install with --prefix other than the configured one still points at itself.
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ build/cescan --help # CLI scanner
debugger lifecycle regressions. Included in both release and sanitizer CI.
- `build/scan_test` — cross-process scan/write against its own child process.
- `build/gui_debugger_smoke` — offscreen Qt smoke test for the debugger window.
- `build/gui_help_smoke` — renders the shipped README/SCRIPTING docs the way the
Help windows do (md4c to HTML) and checks the text on both sides of README's
`<img>`, each code block's copy button and the Back/Forward history.
`--shot out.png [light]` saves the page for UI review.
- **Sanitizers:** `cmake -B build-asan -DCECORE_SANITIZE=ON && cmake --build
build-asan --target cecore_test && ./build-asan/cecore_test`. CI runs this too.
Tests that deliberately fault or inject code are guarded by
Expand Down
100 changes: 100 additions & 0 deletions gui/helpmarkdown.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include "gui/helpmarkdown.hpp"

#include <md4c-html.h>
#include <md4c.h>

#include <QDir>
#include <QFileInfo>
#include <QRegularExpression>
#include <QUrl>

#include <string>

namespace {

/// Value of a single attribute in the text between "<img" and ">".
QString attributeValue(const QString& attributes, const QString& name) {
const QRegularExpression re(
QStringLiteral(R"attr((?<![-\w])%1\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>/]+)))attr")
.arg(QRegularExpression::escape(name)),
QRegularExpression::CaseInsensitiveOption);
const auto match = re.match(attributes);
if (!match.hasMatch()) return {};
for (int group = 1; group <= 3; ++group) {
if (match.capturedStart(group) >= 0) return match.captured(group);
}
return {};
}

QString escapeAltText(QString text) {
text.replace(QLatin1Char('\\'), QStringLiteral("\\\\"));
text.replace(QLatin1Char('['), QStringLiteral("\\["));
text.replace(QLatin1Char(']'), QStringLiteral("\\]"));
return text;
}

/// One Markdown image for an <img ...> tag.
QString imageMarkdown(const QString& attributes, const QString& baseDir) {
const QString src = attributeValue(attributes, QStringLiteral("src")).trimmed();
QString alt = attributeValue(attributes, QStringLiteral("alt")).trimmed();
if (alt.isEmpty()) alt = QFileInfo(src).fileName();
alt = escapeAltText(alt);
if (src.isEmpty()) return alt;

const QUrl url(src);
if (!url.scheme().isEmpty()) // http(s):, data:, ...
return QStringLiteral("![%1](%2)").arg(alt, src);

const QString path = QDir(baseDir).absoluteFilePath(src);
if (QFileInfo::exists(path))
return QStringLiteral("![%1](%2)").arg(alt, QUrl::fromLocalFile(path).toString());

return alt; // not shipped with this build: show the caption, not a broken image
}

void appendHtml(const MD_CHAR* text, MD_SIZE size, void* userdata) {
static_cast<std::string*>(userdata)->append(text, size);
}

} // namespace

namespace ce::gui {

QString prepareHelpMarkdown(const QString& markdown, const QString& baseDir) {
// Only <img> is block-level HTML in the shipped docs. A single pass
// replaces every tag regardless of whether it starts its own block, which
// is also correct inline.
static const QRegularExpression imgTag(QStringLiteral(R"(<img\b[^>]*>)"),
QRegularExpression::CaseInsensitiveOption);

QString prepared;
prepared.reserve(markdown.size());
qsizetype copied = 0;
auto it = imgTag.globalMatch(markdown);
while (it.hasNext()) {
const auto match = it.next();
prepared += markdown.mid(copied, match.capturedStart() - copied);
QString attributes = match.captured();
attributes.remove(0, 4); // "<img"
attributes.chop(1); // ">"
prepared += imageMarkdown(attributes, baseDir);
copied = match.capturedEnd();
}
prepared += markdown.mid(copied);
return prepared;
}

QString helpHtmlFromMarkdown(const QString& markdown, const QString& baseDir) {
const QByteArray utf8 = prepareHelpMarkdown(markdown, baseDir).toUtf8();
std::string html;
// The docs are Markdown only: raw HTML blocks are escaped, and the images
// were converted above, so md4c never needs to pass HTML through.
const unsigned flags = MD_DIALECT_GITHUB | MD_FLAG_TABLES | MD_FLAG_STRIKETHROUGH
| MD_FLAG_TASKLISTS | MD_FLAG_PERMISSIVEATXHEADERS
| MD_FLAG_NOHTMLBLOCKS | MD_FLAG_NOHTMLSPANS;
if (md_html(utf8.constData(), MD_SIZE(utf8.size()), &appendHtml, &html, flags, 0) != 0)
return {};
return QString::fromUtf8(html.data(), qsizetype(html.size()));
}

} // namespace ce::gui
22 changes: 22 additions & 0 deletions gui/helpmarkdown.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
/// Markdown rendering for the Help windows. Qt's own Markdown importer is
/// md4c-based but drops every block after a raw HTML block (README.md opens
/// with an <img>) and gives code blocks no styling. The docs are therefore
/// parsed with the vendored md4c and handed to QTextBrowser as HTML, which
/// also allows the GitHub-style code cards and their copy buttons.

#include <QString>

namespace ce::gui {

/// Converts the block-level HTML the shipped docs use to Markdown: an <img>
/// becomes a Markdown image with an absolute file: URL when it ships next to
/// the doc (`baseDir` is the doc's directory), or its alt text when it does
/// not. Everything else is passed through unchanged.
QString prepareHelpMarkdown(const QString& markdown, const QString& baseDir);

/// Renders the Markdown to an HTML fragment for QTextBrowser (md4c, GitHub
/// dialect, raw HTML escaped: the docs are Markdown, not HTML).
QString helpHtmlFromMarkdown(const QString& markdown, const QString& baseDir);

} // namespace ce::gui
Loading
Loading