Skip to content

Jaliborc/C_Everywhere

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C_Everywhere 🌠

Patreon Paypal Discord

A JIT compiled emulation library that simplifies developing World of Wacraft addons which support multiple client versions. Code for latest expansion, run everywhere.

Overview

Since Blizzard started refactoring the game's API, but only on it's retail servers, supporting the multiple clients often results in a choice between duplicated or unneficient code (so much spaghetti 🍝!), even when using version-dependent code compilers.

Here is an implementation for printing link and quantity of the first 3 tracked currencies, running on both Dragonflight and Wrath of the Lich King:

for i = 0, 3 do
    local id, quantity
    if LE_EXPANSION_LEVEL_CURRENT >= LE_EXPANSION_DRAGONFLIGHT then
        local data = C_CurrencyInfo.GetBackpackCurrencyInfo(i)
        if data then
            id = data.currencyTypesID
            quantity = data.quantity
        end
    else
        local _, count, _, typeID = GetBackpackCurrencyInfo(i)
        id, quantity = typeID, count
    end

    local link = C_CurrencyInfo and C_CurrencyInfo.GetCurrencyLink and C_CurrencyInfo.GetCurrencyLink(id) or GetCurrencyLink(id)
    print(link, quantity)
end

C_Everywhere takes all that clutter away while ensuring efficient implementation:

local C = LibStub('C_Everywhere')

for i = 0, 3 do
    local data = C.CurrencyInfo.GetBackpackCurrencyInfo(i)
    if data then
        print(C.CurrencyInfo.GetCurrencyLink(data.currencyTypesID), data.quantity)
    end
end

It does so by lazily just-in-time building namespaces and compiling lua functions optimized for the current client.

Advanced

As shown, when a namesapce C.Some_Namespace is requested, C_Everywhere returns a virtual namespace that abstracts the process of finding and optimizing APIs. These virtual namespaces also provide some extra functions:

Function Description Input Return
.rawfind(api) Forces a search for the requested API, without using any of the other features or optimizations. string function
.locate(api) Returns the real namespace in which the API can be found. string table
.hooksecurefunc(api, call) Shorthand, equivalent to hooksecurefunc(.locate(api), api, call) string, function nil

💡 If I missed implementing output packing into structured code for a function you require, please submit a pull request. It only takes a single line of code to implement in the source code. Here is GetBackpackCurrencyInfo implementation:

pack(C.CurrencyInfo, 'GetBackpackCurrencyInfo', 'name, quantity, iconFileID, currencyTypesID')

Limitations

C_Everywhere is not a full virtual machine. While it is able to entirely automatically handle common refactoring patterns, for some APIs conversion has to be implemented manually, of which 100% coverage is not guaranteed.
Here are examples of conversions that it currently does:

  • API moving namespaces.
  • API moving from frame type to a namespace (ex: GameTooltip -> C_Tooltip).
  • Change of outputs from a variable list to single structured (table) variables.
  • Change in input arguments, or input argument order.
  • Functions from Retail that do not have a direct equivalent everywhere, and should return a static value in those situations (ex: bank is always type 0 in Classic).

⚠️ Reminder!

If you use this library, please list it as one of your dependencies in the CurseForge admin system. It's a big help! 👍

About

JIT converts WoW API depending on client version

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

Contributors

Languages