mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-25 14:05:57 +00:00
Merge task/plugstale: a mod plugin whose start-up writes a value into the game's data that redirects nothing (Zonai Fieldworks' Self Recall and its memory pool size) no longer goes stale when render_scale grows the pool, and a plugin the game found stale makes the rebuild lift and compile again instead of looping (#1437, #1388)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ed8fa04034
8 files changed
+193
-26
No files matched your search
+8
-13
@@ -62,6 +62,7 @@
|
||||
#include "kernel.h"
|
||||
#include "mods.h"
|
||||
#include "platform/platform.h"
|
||||
#include "plugin_writes.h"
|
||||
|
||||
#if __has_include("patches.h")
|
||||
#include "patches.h"
|
||||
@@ -523,11 +524,7 @@ static const struct { const char *module; int set; const char *sha256; } plugin_
|
||||
RT_PLUGINS(X)
|
||||
#undef X
|
||||
};
|
||||
static const struct { int plugin; const char *module; uint64_t off; uint32_t old, now; } write_tab[] = {
|
||||
#define X(p, mod, off, old, now) {p, mod, off, old, now},
|
||||
RT_PLUGIN_WRITES(X)
|
||||
#undef X
|
||||
};
|
||||
static const PluginWrite write_tab[] = {RT_PLUGIN_WRITES(PLUGIN_WRITE)};
|
||||
#define NWRITES ((int)(sizeof write_tab / sizeof *write_tab))
|
||||
#ifdef RT_PLUGIN_ROOTS
|
||||
static const struct { const char *module; uint64_t off; } root_tab[] = {
|
||||
@@ -590,7 +587,9 @@ static void restore_page(const RtLoaded *m, uint64_t off, const uint8_t *was) {
|
||||
}
|
||||
|
||||
// After plugin i's init: what it wrote into the game modules, word by word, against the record of the build (its
|
||||
// entries of RT_PLUGIN_WRITES). The first difference goes into why (unless a reason is there already). Then the game
|
||||
// entries of RT_PLUGIN_WRITES, plugin_writes.h plugin_write_find). A recorded word the init did not change counts as
|
||||
// missing, unless the record takes any value there (the init may have written the value the word held). The first
|
||||
// difference goes into why (unless a reason is there already). Then the game
|
||||
// modules are made what they were before the init: the sealed part (.text, .rodata) gets the game's bytes back, a
|
||||
// write elsewhere stays and goes into pre, so the next plugin's init is compared only with what it writes itself.
|
||||
// The aliases this init mapped (from first_alias on) are flushed first; an earlier init's were flushed after it.
|
||||
@@ -612,12 +611,8 @@ static void check_writes(int plugin, int first_alias, char *why, size_t cap) {
|
||||
memcpy(&a, pre[i] + w, 4);
|
||||
memcpy(&b, now + w, 4);
|
||||
if (a == b) continue;
|
||||
int k = 0;
|
||||
while (k < NWRITES && !(write_tab[k].plugin == plugin && write_tab[k].off == w &&
|
||||
!strcmp(write_tab[k].module, m->name) && write_tab[k].old == a &&
|
||||
write_tab[k].now == b))
|
||||
k++;
|
||||
if (k < NWRITES) {
|
||||
int k = plugin_write_find(write_tab, NWRITES, plugin, m->name, w, a, b);
|
||||
if (k >= 0) {
|
||||
seen[k] = 1;
|
||||
} else if (!unexpected++) {
|
||||
snprintf(first, sizeof first, "%s+%#llx %08x -> %08x", m->name, (unsigned long long)w, a, b);
|
||||
@@ -627,7 +622,7 @@ static void check_writes(int plugin, int first_alias, char *why, size_t cap) {
|
||||
else memcpy(pre[i] + off, now + off, PAGE);
|
||||
}
|
||||
}
|
||||
for (int k = 0; k < NWRITES; k++) missing += write_tab[k].plugin == plugin && !seen[k];
|
||||
for (int k = 0; k < NWRITES; k++) missing += write_tab[k].plugin == plugin && !seen[k] && !write_tab[k].any;
|
||||
if (why[0]) return;
|
||||
if (unexpected)
|
||||
snprintf(why, cap, "its init wrote %d words the build did not record (first %s)", unexpected, first);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// The build's record of what a mod plugin's init writes into the game modules (patches.h RT_PLUGIN_WRITES, from the
|
||||
// `expect` lines of recomp/patches.py), and the lookup plugin_init.c check_writes makes for every word an init changed
|
||||
// at the start of the game.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// any: the expect line said `* *`, a word of main's .data or .bss that shapes no lifted code (tools/exefs_plugins.py
|
||||
// plugin_lines). The game may hold another value there at play than in the service run (Zonai Fieldworks' Self Recall
|
||||
// takes its storage off a pool size that grows with the resolution's texture heap), so it matches by place only. A
|
||||
// hook branch in .text and a pointer into a plugin's .text match by place and both words.
|
||||
typedef struct {
|
||||
int plugin;
|
||||
const char *module;
|
||||
uint64_t off;
|
||||
uint32_t old, now;
|
||||
int any;
|
||||
} PluginWrite;
|
||||
|
||||
// The X of RT_PLUGIN_WRITES for a table of PluginWrite.
|
||||
#define PLUGIN_WRITE(p, mod, off, old, now, any) {p, mod, off, old, now, any},
|
||||
|
||||
// The index of the entry of plugin that records the write of module+off from old to now, or -1.
|
||||
static inline int plugin_write_find(const PluginWrite *tab, int n, int plugin, const char *module, uint64_t off,
|
||||
uint32_t old, uint32_t now) {
|
||||
for (int k = 0; k < n; k++)
|
||||
if (tab[k].plugin == plugin && tab[k].off == off && !strcmp(tab[k].module, module) &&
|
||||
(tab[k].any || (tab[k].old == old && tab[k].now == now)))
|
||||
return k;
|
||||
return -1;
|
||||
}
|
||||
Reference in new issue
Block a user