Skip to content
Closed
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
9 changes: 8 additions & 1 deletion games/totk/runtime/romfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ void runtime_fs_init(void) {
}
static int path_ok(const char *p) {return romfs_path_valid_relative(p);}
static const char *rom_path(const char *path) {
const char *m=mount_of(path);return romfs_path_relative(m?m:mount_name,path);
static _Thread_local char norm[4096];
const char *m=mount_of(path);
const char *p=romfs_path_relative(m?m:mount_name,path);
return p?romfs_path_collapse(p,norm,sizeof norm):NULL;
}
static uint64_t lower(const char *name) {uint64_t lo=0,hi=file_count;while(lo<hi){uint64_t m=lo+(hi-lo)/2;if(strcmp(entry_name(entry(m)),name)<0)lo=m+1;else hi=m;}return lo;}
static unsigned mount_rom(const char *name,void *cache,uint64_t size) {
Expand Down Expand Up @@ -436,6 +439,10 @@ void runtime_fs_probe(void) {
need(!runtime_romfs_read(&n,h,0,actual,sizeof actual)&&n==sizeof actual&&!memcmp(actual,expected,sizeof actual),"normalized audio stream bytes");runtime_romfs_close(h);
}
need(runtime_romfs_open(&h,"rom://../Sound/Resource/Stream/Dm_OP_0001.bwav",1)!=0,"reject traversal after repeated root separator");
/* Voice stream requests join "Resource" and "Stream" with an extra slash (Voice/Resource//Stream). */
snprintf(path,sizeof path,"rom:/Sound/Resource//Stream/Dm_OP_0001.bwav");
need(!runtime_romfs_open(&h,path,1),"open interior double-slash audio stream");
need(!runtime_romfs_read(&n,h,0,actual,sizeof actual)&&n==sizeof actual&&!memcmp(actual,expected,sizeof actual),"interior double-slash audio bytes");runtime_romfs_close(h);
}
for(uint64_t i=0;i<file_count;i+=file_count/64){Entry e=entry(i);char p[4096];need(snprintf(p,sizeof(p),"rom:/%s",entry_name(e))<(int)sizeof(p),"probe path");uint64_t h=0,n=0;int64_t size;uint32_t ov=overlay_slot(i);uint64_t expected_size=ov?overlays[ov-1].size:e.size;need(!runtime_romfs_open(&h,p,1)&&!runtime_romfs_size(&size,h)&&(uint64_t)size==expected_size,"probe open/size");need(!runtime_romfs_read(&n,h,0,buffer,sizeof(buffer)),"probe partial read");for(uint64_t j=0;j<n;j++)sum=sum*131+buffer[j];need(!runtime_romfs_read(&n,h,size,buffer,1)&&n==0,"probe EOF");runtime_romfs_close(h);count++;}
for(size_t k=0;k<noverlay;k++){char p[4096];need(snprintf(p,sizeof(p),"rom:/%s",overlays[k].name)<(int)sizeof(p),"probe overlay path");
Expand Down
19 changes: 17 additions & 2 deletions games/totk/runtime/romfs_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ static inline int romfs_path_valid_relative(const char *path) {
for (const char *part = path; *part;) {
const char *end = strchr(part, '/');
size_t size = end ? (size_t)(end - part) : strlen(part);
if (!size || (size == 1 && part[0] == '.') ||
(size == 2 && part[0] == '.' && part[1] == '.')) return 0;
if (size == 0) { /* the game joins voice paths with "Resource//Stream" */ }
else if ((size == 1 && part[0] == '.') ||
(size == 2 && part[0] == '.' && part[1] == '.')) return 0;
if (!end) break;
part = end + 1;
}
return 1;
}

/* Collapse repeated separators (including interior ones) into out; the RomFS
index uses the same single-separator names the game's other paths use. */
static inline const char *romfs_path_collapse(const char *in, char *out, size_t cap) {
size_t n = 0;
if (!in || !cap) return NULL;
for (; *in; in++) {
if (*in == '/' && n && out[n - 1] == '/') continue;
if (n + 1 >= cap) return NULL;
out[n++] = *in;
}
out[n] = 0;
return out;
}

static inline const char *romfs_path_relative(const char *mount, const char *path) {
if (!mount || !*mount || !path) return NULL;
size_t size = strlen(mount);
Expand Down
9 changes: 7 additions & 2 deletions games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m
Original file line number Diff line number Diff line change
Expand Up @@ -6188,6 +6188,10 @@ static int drv_fillable(int stage, int bank, unsigned off) {
case 0: return (off >= 0x110 && off < 0x210) || off == 0x610;
#endif
case 1: return off >= 0x510 && off < 0x610;
#ifdef GAME_NS2
case 3: return off >= 0x670 && off < 0x770; /* task storage-buffer table */
case 4: return off >= 0x770 && off < 0x870; /* mesh storage-buffer table */
#endif
#ifdef GAME_NS2
case 5: return off < 0x10 || (off >= 0x200 && off < 0x410); /* NVN2: the workgroup counts at c0 + 4 */
#else
Expand Down Expand Up @@ -15196,11 +15200,12 @@ static void mesh_tasks_draw(const p_mesh_tasks *mesh) {
rp_end(); cg_flush(); defer_fallback(); rp_flush(); upd_flush();
g_mesh_pre_n = 0;
for (int r = 0; r < nrun; r++) { void *source; uint64_t so;
if (!mtl_addr(run[r]->ind, 8, &source, &so)) { if (!r) { RED_ONCE(163, "DrawMeshTasksIndirect record at %#llx is in no memory pool: draw skipped", (unsigned long long)run[r]->ind); return; } continue; }
if (!mtl_addr(run[r]->ind, 16, &source, &so)) { if (!r) { RED_ONCE(163, "DrawMeshTasksIndirect record at %#llx is in no memory pool: draw skipped", (unsigned long long)run[r]->ind); return; } continue; }
__strong id<MTLBuffer> ab; size_t ao = arena_alloc(32, &ab); uint32_t *w = (uint32_t *)((uint8_t *)ab.contents + ao); memset(w, 0, 32); w[1] = w[2] = 1;
id<MTLBuffer> src = (__bridge id<MTLBuffer>)source;
id<MTL4ComputeCommandEncoder> ce = blit_buffer(src, so, ab, ao, 4);
enc_b_copy_buffer(ce, src, so, ab, ao, 4); enc_b_copy_buffer(ce, src, so + 4, ab, ao + 16, 4);
static int first_old = -1; if (first_old < 0) { const char *e = getenv("TOTK_MESH_FIRST_OLD"); first_old = e && *e && strcmp(e, "0"); }
enc_b_copy_buffer(ce, src, so, ab, ao, 4); enc_b_copy_buffer(ce, src, so + (first_old ? 4 : 12), ab, ao + 16, 4);
if (!r) { g_mesh_ind_args = ab.gpuAddress + ao; g_mesh_ind_first = ab.gpuAddress + ao + 16; }
else { g_mesh_pre[g_mesh_pre_n].op = run[r]; g_mesh_pre[g_mesh_pre_n].sub = g_sub_serial; g_mesh_pre[g_mesh_pre_n].args = ab.gpuAddress + ao; g_mesh_pre[g_mesh_pre_n].first = ab.gpuAddress + ao + 16; g_mesh_pre_n++; } }
enc_b_end(g_blit); g_blit = nil; } }
Expand Down
Loading