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
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ add_executable(bbhost
src/core/legacy_cpu.cpp
src/core/legacy_cpu_code.cpp
src/core/config.cpp
src/core/trophies.cpp
src/core/play_history.cpp
src/core/chalice_history.cpp
src/core/config_move.cpp
src/engine/image_text.cpp
src/core/sha256.cpp
Expand All @@ -118,6 +121,7 @@ add_executable(bbhost
src/engine/paramdef.cpp
src/engine/lua_events.cpp
src/engine/event_flags.cpp
src/engine/play_history.cpp
src/engine/player_data.cpp
src/engine/world_chr.cpp
src/engine/playlog.cpp
Expand Down Expand Up @@ -227,6 +231,7 @@ add_executable(bbhost
src/hle/net.cpp
src/hle/http.cpp
src/hle/ajm.cpp
src/hle/trophy.cpp
src/hle/system.cpp
src/host/label_landing.cpp
)
Expand Down Expand Up @@ -1641,3 +1646,15 @@ else()
DEPENDS bbhost
USES_TERMINAL)
endif()

# Local trophies and campaign/chalice histories; no game files required.
foreach(history_test trophies play_history chalice_history)
add_executable(${history_test}_test tests/${history_test}_test.cpp src/core/${history_test}.cpp)
target_include_directories(${history_test}_test PRIVATE src include)
target_link_libraries(${history_test}_test PRIVATE Threads::Threads)
add_test(NAME ${history_test}_test COMMAND ${history_test}_test)
endforeach()
target_sources(trophies_test PRIVATE src/hle/trophy.cpp)
target_sources(chalice_history_test PRIVATE src/core/play_history.cpp)

target_sources(bbhost PRIVATE src/host/trophy_ui.cpp src/host/play_history_ui.cpp)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,5 @@ game's code or data.
- Thanks to the many contributors and testers, incomplete and in no
particular order: Metr1k, Kyo, Schorched Knight, ancat, Nox-, Astrelle,
BlitzWOLF, CrunchyCheese, foxyhooligans, gkberk, sen, Ultra, droogie

Local progress: [trophies](docs/trophies.md) and [play and chalice history](docs/play-history.md), available in setup and the F10 menu.
37 changes: 37 additions & 0 deletions docs/play-history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Play history

bbhost records each character's NG/NG+ playtime, attempts, and kills for 17 base-game bosses, five DLC bosses, and chalice bosses. Campaign and chalice records have separate lists and totals.

Open **Play history** in setup or the in-game F10 menu. Select a character and a cycle, or enable **Show totals across all cycles**. Switch between **Base game and DLC** and **Chalice dungeons**.

## Counting fights

An attempt starts when the fight's start event enables its AI and health bar. Standing outside the fog does not count. Deaths, retreats, interrupted fights, and the winning fight count as attempts: two losses followed by a win give three attempts and one kill. Resuming an active fight does not count it twice. A kill takes precedence if the player dies at the same time.

Recording pauses during boss rush/practice and visits to another player's world. Practice results remain in the boss-rush plugin's own records. Plugin API 30 appends `campaign_tracking_pause(name, paused)` after the API 29 fields; practice plugins can hold and release their own pause on the main thread. Older API field offsets are unchanged.

## Time and incomplete records

Time follows the save's play clock. A rising NG+ counter ends the previous cycle. At the game's clock limit, 999:59:59, measurement continues using elapsed time in the world, excluding title screens and loading. Time while bbhost is closed is never added.

When first observing an NG save, its saved total time belongs to cycle one. For a save already in NG+, earlier cycle boundaries cannot be reconstructed: the current cycle starts with a partial time record. Unobserved cycles are not invented. Missing a cycle boundary, for example after playing in another build, also makes the adjacent times partial.

Previously defeated campaign bosses can be marked defeated, but earlier attempts cannot be recovered. **Unknown**, **+**, and **partial record** identify missing information. New cycles are recorded separately.

## Storage

`play-history.txt` in the data folder persists across sessions. Records are associated with save slots; renaming a character updates its display name. A decrease in cycle number, a fresh NG character, or a clock rollback greater than five minutes creates a separate record while retaining the previous one. Its totals do not mix with the old record. Smaller rollbacks, such as the gap since the last autosave, retain attempts and resume timing.

The record is saved on attempts, kills, cycle changes, loading, and normal exit, and roughly every ten seconds during play. A forced exit may lose time since the last write. Writes use a temporary file and replacement. Unreadable, malformed, or future-version records are reported without being overwritten.

Back up history files together with the game save. Tracking does not write game saves or event flags, or upload records.

## Chalice dungeons

Fixed and root chalice encounters are identified by dungeon, altar, layer, and boss. Encounters with the same boss in different dungeons keep separate active/cleared state. The multi-enemy Watchers encounter counts as one boss fight.

Chalice progress survives NG+. Attempts and kills belong to the cycle in which they were observed; an existing clear is not counted again in the next cycle. Replaying a cleared dungeon starts a separate encounter and retains the prior clear. Totals combine matching boss types only within the selected character and cycles.

An encounter already cleared when recording begins is shown as a prior clear, without assigning its kill to the current cycle. Initial attempts are lower bounds because earlier attempts are unknown.

Chalice records live in `chalice-history.txt`; the campaign file's format is unchanged. Keep the save and both history files together when backing up or moving to another PC so character identifiers remain associated.
24 changes: 24 additions & 0 deletions docs/trophies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Local trophies

bbhost records 40 trophies: 34 for the base game, including platinum, and six for The Old Hunters. When the game awards a trophy, bbhost saves it and shows a notification for six seconds. Notifications queue; repeated awards do not change the original timestamp. Platinum unlocks after all 33 other base-game trophies. DLC trophies are not required.

Open **Trophies** in the setup window or the in-game F10 menu. The list shows names, requirements, grades, progress, and unlock times in UTC. Filter by All, Unlocked, or Locked. Hidden trophies conceal their name and requirements until unlocked unless you select **Reveal hidden trophies**.

## Records and compatibility

Records live in `trophies.txt` in your configured data folder and are shared by characters using that folder. Existing bbhost records work unchanged. Choosing another data folder in setup changes the displayed record.

Before the first update to an existing file, bbhost makes `trophies.txt.pre-trophies.bak` without overwriting an earlier backup. New contents are flushed to a temporary file and replace the record only after the write succeeds. A failed write does not award or announce the trophy; check free space and permissions.

If an existing record already contains all 33 base-game trophies, trophy registration at the next game start reconciles platinum. Earlier trophies cannot be reconstructed from a game save alone.

These are local records, with no PlayStation Network or Steam achievement sync. Importing other ports' trophy formats is outside this change. Game files and saves are not modified.

## Implementation references

The factual catalog and API layout references were [ayozetr/bloodborne_linux](https://github.com/ayozetr/bloodborne_linux) at `804651e418dc1e80b1dafdc83402106bbea954cd`:

- `scripts/trophies.py` and `src/runtime_services.c`: IDs, grades, hidden flags, DLC grouping, and platinum conditions.
- Its shadPS4-derived `np_trophy.h` and `np_error.h`: structure layouts and error values (GPL-2.0-or-later, shadPS4 Emulator Project).

Persistence, HLE handling, UI, and descriptive text are implemented for bbhost. No game images or keys are included; the notification cup is drawn with overlay primitives.
8 changes: 6 additions & 2 deletions include/bbhost_plugin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* bbhost plugin API, version 29.
/* bbhost plugin API, version 30.
*
* A plugin is a shared library (.so on Linux, .dll on Windows) in
* <exe dir>/plugins or <data>/plugins. The host loads every one at start and
Expand Down Expand Up @@ -38,7 +38,7 @@
extern "C" {
#endif

#define BB_PLUGIN_API_VERSION 29
#define BB_PLUGIN_API_VERSION 30

#if defined(_WIN32)
#define BB_PLUGIN_EXPORT __declspec(dllexport)
Expand Down Expand Up @@ -1196,6 +1196,10 @@ typedef struct BbHostApi {
* on_view is not called while it is 1 (on_camera still is, so a plugin
* can see it begin and end). Any thread. */
int (*cutscene)(void);
/* Version 30: main thread only. Pause campaign and chalice history while
* a practice plugin changes world state. Each plugin owns its pause;
* pass 0 to release it. Does not alter the game's save or play clock. */
int (*campaign_tracking_pause)(const char* plugin, int paused);
} BbHostApi;

#define BB_SNAP_PIXELS 0xffffffffu /* version 18: scene_snap's grid the 3D's own pixels */
Expand Down
3 changes: 3 additions & 0 deletions plugins/boss_rush/boss_rush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,9 @@ void tick() {
if (g_test_practice) practice();
else begin();
}
if (g.api->version >= 30 && g.api->size >= offsetof(BbHostApi, campaign_tracking_pause) + sizeof(g.api->campaign_tracking_pause) &&
g.api->campaign_tracking_pause)
g.api->campaign_tracking_pause("boss_rush", g_state != State::Waiting && g_state != State::Done);
if (g_in_world && !g_banner.empty()) {
g.message(g_banner, g_banner_s);
g_banner.clear();
Expand Down
167 changes: 167 additions & 0 deletions src/core/chalice_history.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include "core/chalice_history.h"
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <map>
#include <set>
#include <sstream>

namespace chalice_history {
namespace {
constexpr std::uint64_t kMaxCounter = 1ull << 50;
bool end(std::istringstream& in) { in >> std::ws; return in.eof(); }
int summary_id(int id) {
// Different dungeon templates use separate health-bar IDs for the same
// displayed boss. Keep encounter IDs exact; combine their boss totals.
if (id == 209010) return 209000;
if (id == 509010) return 509000;
return id;
}
Stats& stats(Encounter& e, int cycle) {
for (auto& s : e.stats) if (s.cycle == cycle) return s;
e.stats.push_back({cycle, {}}); return e.stats.back();
}
}
std::string boss_name(int id) {
// Health-bar name IDs, including the multi-character Watchers event;
// NpcParam.nameId is different for several of these fights.
static const std::pair<int, const char*> names[] = {
{1010, "Forgotten Madman"}, {106000, "Brainsucker"}, {127000, "Maneater Boar"},
{209000, "Blood-starved Beast"}, {209010, "Blood-starved Beast"}, {216000, "Keeper of the Old Lords"},
{218000, "Loran Silverbeast"}, {251010, "Ebrietas, Daughter of the Cosmos"}, {257010, "Celestial Emissary"},
{304001, "Merciless Watchers"}, {305001, "Pthumerian Descendant"}, {305002, "Pthumerian Elder"},
{306000, "Pthumerian Bride"}, {306001, "Yharnam, Pthumerian Queen"}, {313000, "Undead Giant"},
{501000, "Watchdog of the Old Lords"}, {504010, "Abhorrent Beast"}, {508010, "Loran Darkbeast"},
{509000, "Bloodletting Beast"}, {509010, "Bloodletting Beast"}, {510010, "Rom, the Vacuous Spider"},
{512010, "Amygdala"}, {750000, "Beast-possessed Soul"},
};
for (const auto& [key, name] : names) if (key == id) return name;
return "Chalice boss #" + std::to_string(id);
}
Snapshot read(const std::filesystem::path& file) {
Snapshot out;
const auto bad = [&] { out.error = "Cannot read chalice history. The original file has not been changed."; return out; };
std::error_code ec;
const bool exists = std::filesystem::exists(file, ec);
if (ec) return bad();
if (!exists) return out;
if (!std::filesystem::is_regular_file(file, ec) || ec || std::filesystem::file_size(file, ec) > 8 * 1024 * 1024 || ec) return bad();
std::ifstream in(file, std::ios::binary); std::string line;
if (!in || !std::getline(in, line) || line != "BBHOST_CHALICE_HISTORY 1") return bad();
std::set<std::uint64_t> ids;
Encounter* current = nullptr;
bool finished = false;
while (std::getline(in, line)) {
std::istringstream row(line); std::string kind;
if (!(row >> kind)) continue;
if (kind == "end") { if (!end(row)) return bad(); finished = true; break; }
if (kind == "encounter") {
Encounter e; int cleared, prior, active, blocked;
if (!(row >> e.id >> e.character >> e.altar >> e.layer >> e.name_id >> e.last_deaths >> cleared >> prior >> active >> blocked >> std::quoted(e.dungeon)) ||
!end(row) || !e.id || e.id > kMaxCounter || !ids.insert(e.id).second || !e.character || e.character > kMaxCounter ||
e.altar < 0 || e.altar > 6 || e.layer < 1 || e.layer > 4 || e.name_id <= 0 || e.name_id > 10000000 ||
e.last_deaths > UINT32_MAX || cleared < 0 || cleared > 1 || prior < 0 || prior > 1 ||
active < 0 || active > 1 || blocked < 0 || blocked > 1 || e.dungeon.empty() || e.dungeon.size() > 128 ||
out.encounters.size() >= 10000 || (active && (cleared || blocked)) || (prior && !cleared)) return bad();
e.cleared = cleared; e.prior_clear = prior; e.active = active; e.blocked = blocked;
out.encounters.push_back(std::move(e)); current = &out.encounters.back();
} else if (kind == "stats") {
Stats s; int partial;
if (!current || !(row >> s.cycle >> s.count.attempts >> s.count.kills >> partial) || !end(row) ||
s.cycle < 0 || s.cycle > 1000000 || s.count.attempts > kMaxCounter || s.count.kills > 1 ||
partial < 0 || partial > 1 || (s.count.kills > s.count.attempts && !partial) ||
current->stats.size() >= 10000 || (!current->stats.empty() && s.cycle <= current->stats.back().cycle)) return bad();
s.count.partial = partial; current->stats.push_back(s);
} else return bad();
}
while (std::getline(in, line)) if (line.find_first_not_of(" \r\t") != std::string::npos) return bad();
if (in.bad() || !finished) return bad();
for (const auto& e : out.encounters) {
std::uint64_t kills = 0, attempts = 0;
for (const auto& s : e.stats) { kills += s.count.kills; attempts += s.count.attempts; }
if (kills > 1 || (kills && !e.cleared) || (e.prior_clear && (kills || attempts)) || (e.active && !attempts) ||
(!e.prior_clear && e.stats.empty())) return bad();
}
return out;
}
std::vector<Total> totals(const Snapshot& state, std::uint64_t character, int cycle) {
std::map<int, play_history::BossRecord> sums;
for (const auto& e : state.encounters) if (e.character == character) {
if (cycle < 0 && e.prior_clear) sums[summary_id(e.name_id)].partial = true;
for (const auto& s : e.stats) if (cycle < 0 || s.cycle == cycle) {
auto& t = sums[summary_id(e.name_id)]; t.attempts += s.count.attempts; t.kills += s.count.kills;
t.partial = t.partial || s.count.partial;
}
}
std::vector<Total> out;
for (const auto& [id, count] : sums) out.push_back({id, count});
return out;
}
void Store::open(const std::filesystem::path& file) {
std::lock_guard lock(mutex_); file_ = file; state_ = read(file); readable_ = state_.error.empty(); dirty_ = false;
}
Snapshot Store::snapshot() const { std::lock_guard lock(mutex_); return state_; }
bool Store::save() {
if (!readable_) return false;
if (!dirty_) return true;
std::ostringstream out; out << "BBHOST_CHALICE_HISTORY 1\n";
for (const auto& e : state_.encounters) {
out << "encounter " << e.id << ' ' << e.character << ' ' << e.altar << ' ' << e.layer << ' ' << e.name_id << ' ' << e.last_deaths
<< ' ' << e.cleared << ' ' << e.prior_clear << ' ' << e.active << ' ' << e.blocked << ' ' << std::quoted(e.dungeon) << '\n';
for (const auto& s : e.stats) out << "stats " << s.cycle << ' ' << s.count.attempts << ' ' << s.count.kills << ' ' << s.count.partial << '\n';
}
out << "end\n";
if (!play_history::write_history_file(file_, out.str())) {
state_.error = "Cannot save chalice history. Check free space and write permissions."; return false;
}
state_.error.clear(); dirty_ = false; return true;
}
bool Store::flush() { std::lock_guard lock(mutex_); return save(); }
void Store::observe(const Observation& o) {
std::lock_guard lock(mutex_);
if (!readable_) return;
if (!o.character || !o.in_world) { save(); return; }
if (o.character > kMaxCounter || o.cycle < 0 || o.cycle > 1000000 || o.deaths > UINT32_MAX || o.altar < 0 || o.altar > 6 || o.dungeon.size() > 128) return;
if (o.suspended) {
for (auto& e : state_.encounters) if (e.character == o.character && e.active) { e.active = false; dirty_ = true; }
save(); return;
}
for (const auto& boss : o.bosses) {
if (!boss.flags.valid || o.dungeon.empty() || boss.layer < 1 || boss.layer > 4 || boss.name_id <= 0 || boss.name_id > 10000000) continue;
Encounter* e = nullptr;
for (auto i = state_.encounters.rbegin(); i != state_.encounters.rend(); ++i) {
if (i->character == o.character && i->dungeon == o.dungeon && i->layer == boss.layer && i->name_id == boss.name_id) { e = &*i; break; }
}
// An observed cleared dungeon becoming uncleared is a new ritual or
// a replay of restored progress. Keep the previous clear intact.
const bool replay = e && e->cleared && !boss.flags.defeated;
if (!e || replay) {
Encounter next;
for (const auto& old : state_.encounters) next.id = std::max(next.id, old.id);
++next.id; next.character = o.character; next.dungeon = o.dungeon; next.altar = o.altar;
next.layer = boss.layer; next.name_id = boss.name_id; next.last_deaths = o.deaths;
next.cleared = next.prior_clear = boss.flags.defeated;
if (!next.prior_clear) stats(next, o.cycle).count.partial = !replay;
state_.encounters.push_back(std::move(next)); e = &state_.encounters.back(); dirty_ = true;
}
if (e->cleared) continue; // no inherited clear when NG+ changes
const bool died = !o.alive || (e->active && o.deaths > e->last_deaths);
if (!boss.flags.begun) e->blocked = false;
if (boss.flags.defeated) {
auto& s = stats(*e, o.cycle).count;
if (!e->active || !s.attempts) s.partial = true;
++s.kills; e->cleared = true; e->active = e->blocked = false; dirty_ = true;
} else if (e->active && (died || !boss.flags.begun)) {
e->active = false; e->blocked = boss.flags.begun; dirty_ = true;
} else if (!e->active && !e->blocked && boss.flags.begun && !died) {
++stats(*e, o.cycle).count.attempts; e->active = true; dirty_ = true;
}
e->last_deaths = o.deaths;
}
for (auto& e : state_.encounters) if (e.character == o.character && e.active) {
if (o.dungeon != e.dungeon || !o.alive || o.deaths > e.last_deaths) { e.active = false; e.blocked = true; dirty_ = true; }
}
save();
}
Store& runtime() { static Store store; return store; }
}
Loading