jcnils / protonhax

Run programs inside your game proton's environment.
BSD 3-Clause "New" or "Revised" License
118 stars 7 forks source link

envload vs declare: removing dependency on C code/compiler #11

Closed vincent-hugot closed 7 months ago

vincent-hugot commented 11 months ago

Hello,

Thanks for protonhax. It's neat.

Couldn't envload.c be entirely replaced by two lines of pure bash using declare?

declare -px > dump ... source dump

This handles special characters, such as line feeds, correctly: e.g. output:

export a='1\n2'

vincent-hugot commented 11 months ago

Actually, I see in the history that there used to be another C program called envsave, which was replaced by a simple call to env -0... so this is just the drop of the other shoe :)

https://github.com/jcnils/protonhax/commit/3f62d41048fd9944f994f6fc99b2b57c97c17a17

jcnils commented 7 months ago

Hi @vincent-hugot thanks for the report, sorry it took so long to reply.

Bash only would be great and make things so simple. - it also helps me close another issue. https://github.com/jcnils/protonhax/issues/12

I will give it a try this week, but if you already have a fork working, feel free to open a PR.

Thank you!

vincent-hugot commented 7 months ago

Hi!

No, I don't have a PR ready for you, but here is a proof-of-concept:

env_save () {
    export x="test test\nline\nin subshell"
    declare -px > dump
}

env_load () {
    export x="erased in current shell"
    (source dump && echo -e $x > outsub)
    cat outsub
    echo -e $x
}

source envload.sh ; env_save ; env_load

restores x in the subshell (and only there) as expected.

Cheers, V

jcnils commented 7 months ago

That is beautiful! Thank you so much.

I will try to get it working this week.

jcnils commented 7 months ago

Thank you very much for the suggestion. It worked with just a few small changes.