Skip to content

Different Directory Pak File Managment/Loading#1548

Merged
praydog merged 7 commits intopraydog:masterfrom
hcdd0304:custom_dir_pak
Feb 24, 2026
Merged

Different Directory Pak File Managment/Loading#1548
praydog merged 7 commits intopraydog:masterfrom
hcdd0304:custom_dir_pak

Conversation

@hcdd0304
Copy link
Copy Markdown
Contributor

@hcdd0304 hcdd0304 commented Feb 21, 2026

Fix #1544

Purpose

  • Load PAKs from reframework/paks. PAKs dont need to follow re_chunk_000.xyzabc format, can be of any name.
  • This is in short to avoid a black screen caused by mod manager not cleaning up PAK file properly, by opening an option to put modded PAKs to its separate directory with their own name
  • This feature can be disabled
  • If there is a need for PAK load order, it will be done when the need arise

Code changes

  • Wrapped new changes for TDB 81 upper only
  • Hooking before three calls to change the path before creating a file handle:
    • Two CreateFileW calls in the supposed via.File.open used by the PAK loading function
    • One call by DirectStorage used to open the PAK
image

#define ENABLE_PAK_DIRECTORY_LOAD (TDB_VER >= 81)

static utility::ExhaustionResult do_exhaustion_scan_create_file_refs(utility::ExhaustionContext &ctx, uintptr_t target_search_func, std::vector<uintptr_t> &before_create_file_ptrs) {
if (ctx.instrux.Instruction == ND_INS_CALLNI || ctx.instrux.Instruction == ND_INS_CALLNR || ctx.instrux.Instruction == ND_INS_CALLFD || ctx.instrux.Instruction == ND_INS_CALLFI) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use if (ctx.instrux.Category == ND_CAT_CALL)

}

// Try decode next instruction and see if it calls CreateFileW
auto next_instr_opt = utility::decode_one((std::uint8_t*)(ctx.addr + ctx.instrux.Length));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant decode can likely be folded into the if statement above and checking the current ctx.instrux rather than decoding again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I have adjusted it

@hcdd0304
Copy link
Copy Markdown
Contributor Author

People on Discord (Haven) suggested to change the directory path to pak_mods so I changed it

}
if (ctx.instrux.Category == ND_CAT_CALL) {
auto displacement_opt = utility::resolve_displacement(ctx.addr);
if (displacement_opt && *(uintptr_t*)(*displacement_opt) == target_search_func) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ND_CAT_CALL isn't guaranteed to always be indirect CALL instructions like you're looking for here. Use an inner if statement looking for if (ctx.instrux.Instruction == ND_INS_CALLNI)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted that, thanks!

@praydog praydog merged commit 4285afc into praydog:master Feb 24, 2026
15 checks passed
@Yashirow
Copy link
Copy Markdown

Is it intented that the new folder is ./pak_mods and not ./reframework/pak_mods?

@hcdd0304
Copy link
Copy Markdown
Contributor Author

Yeah, the path is suggested by modders and users on the modding discord (Havens Night)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Different Directory Pak File Managment/Loading

3 participants