maximegmd / CyberEngineTweaks

Cyberpunk 2077 tweaks, hacks and scripting framework
MIT License
4.51k stars 287 forks source link

uvfs support for CET with MO2 #877

Closed rfuzzo closed 1 year ago

rfuzzo commented 1 year ago

The problem

When launching the game through Mod Organizer 2, CET mods don't work That is because

Any mod that creates files at runtime (that is ALL CET mods since the sandbox db gets created at runtime) will fail since the "overwrite" directory escapes the mod sandbox.

This PR

This PR does two things:

  1. It delays the luaVM init slightly so that CET mods get detected after UVFS did its thing
  2. More problematically, it allows lua paths outside the mod sandbox under certain conditions:
    • when the game is launched through MO2 (we detect usvfs_x64.dll)
    • and when the lua path originates from MO2s "overwrite" directory (we detect this by comparing relative paths)

Since GetLuaPath does more checks now, I needed to move it out of utils into sandbox. This also incurred pulling the sandbox into more lambdas.

Pros and Cons

Pros:

Cons:

rfuzzo commented 1 year ago

Thinking about the checks a bit more. One simple alternative to the rather complicated path checking in the PR could also be just to get the lexically_relative path between the filePath and the currentDir if uvfs is detected - and for safety we could check the input lua path for "..//".

WSSDude commented 1 year ago

Eh, checking for .. is sketchy, they may be valid cases (like when mod from some of its subfolder does something with parent)

Dont think that is a good solution.

WSSDude commented 1 year ago

And on top, it may appear in the middle of the path potentially and you could still escape

sth/../../yey

WSSDude commented 1 year ago

I think this looks good apart from the few commented out stuff at least on first glance... I'd rather have a more proper look in like an hour though cause cant discern changes to the GetLuaPath as you moved + changed it in same commit.