ACF-Team / ACF-3

ACF
MIT License
67 stars 55 forks source link

Fix some Version Checking shortcomings #315

Closed brandonsturgeon closed 2 years ago

brandonsturgeon commented 2 years ago

Description 📜

The ACF Loader uses the given Addon Name as the Addon Path, which is not good for a number of reasons:

There's another issue, too: If you're using a branch that has a slashed-prefix (e.g. feature/whatever-thing), the Branch finder will fail because Git internally stores the branch names in sub-directories instead of flat files.

For example, if our branch name was feature/example-feature, ACF looks in the heads/ directory for a file named feature/example-feature. Instead, it should look in the heads/feature/ directory for a file named example-feature. (This is a bit of an oversimplification but it should get the point across)

Example of the error trace:

ACF has finished loading.

[acf-3] addons/acf-3/lua/acf/core/version/version_sh.lua:79: attempt to concatenate local 'Code' (a nil value)
  1. CheckLocalVersion - addons/acf-3/lua/acf/core/version/version_sh.lua:79
   2. AddRepository - addons/acf-3/lua/acf/core/version/version_sh.lua:142
    3. v - addons/acf-3-missiles/lua/acf/core/acfm_globals.lua:23
     4. Run - lua/includes/modules/hook.lua:96
      5. LoadAddon - addons/acf-3/lua/autorun/acf_loader.lua:187
       6. unknown - addons/acf-3/lua/autorun/acf_loader.lua:194

Impact ☄️

Okay, so before, this hasn't been that big of an issue, but recently, ACF-3-Missiles added their AddRepository call to the _OnAddonLoaded hook, which, among other things, loads the ACF Engine Performance data.

It's a weird whirldwind of an issue, but, this means if an addon uses _OnAddonLoaded to call AddRepository, it will break the _OnAddonLoaded hook chain and prevent Engine Data (and other things) from loading.

Which lines up with what we're seeing. ACF Engines just poop out when they spawn, erroring in UpdateOverlay because engine.PowerMax is nil.

The Fix 🛠️

This PR changes two important parts of the ACF Loader:

  1. The ACF Loader no longer tries to search for the addon that calls it. It uses the current stack to determine which addon called the function. This means it'll work regardless of the operating system, and regardless of the directory name
  2. The code that retrieves the branch information can now properly handle branch names with slashes in them