L-Sherry / Localize-me

CCLoader mod to add locales
MIT License
5 stars 3 forks source link

Await deadlock caused by calling `$.ajax` in prestart #13

Open krypciak opened 7 months ago

krypciak commented 7 months ago

Consider the example plugin.js:

export default class Example {
    async prestart() {
        await new Promise(resolve => {
            $.ajax({
                dataType: 'json',
                url: 'data/changelog.json',
                success: data => {
                    console.log('data!', data)
                    resolve()
                },
                error: () => console.log('error!'),
            })
        })
    }
}

The code above causes a deadlock. It is caused by the following stack: https://github.com/L-Sherry/Localize-me/blob/master/mod.js#L832 https://github.com/L-Sherry/Localize-me/blob/master/mod.js#L857 https://github.com/L-Sherry/Localize-me/blob/master/mod.js#L817 https://github.com/L-Sherry/Localize-me/blob/master/mod.js#L596 https://github.com/L-Sherry/Localize-me/blob/master/mod.js#L386 https://github.com/L-Sherry/Localize-me/blob/master/mod.js#L351 https://github.com/L-Sherry/Localize-me/blob/master/mod.js#L162 It ends up on

await this.final_locale

this.final_locale is not resolved until ig.Lang#init is executed, which happens after prestart

L-Sherry commented 6 months ago

This can't really be fixed.

If I don't patch the game files, the langlabels will be stuffed everywhere, including in inaccessible places like local variables and it will be too late to patch them. To patch the game files, Localize-Me need to know which language the game will use, otherwise it would have to load every language mod's files and it will be slow (and break the API, because the current API documents that methods are not called if your language is not selected). Some files will still block anyway, like fonts, because only one language mod can patch fonts.

One possible workaround is to not block loading game files if they do not contain lang labels, but that will only partially fix the issue. It turns out the v1.x branch does this, but that branch is like, going to die because ccloader v3 never took on. Maybe this specific patch can be cherry-picked.