Skip to content

Instantly share code, notes, and snippets.

@gesslar
Last active June 21, 2024 03:23
Show Gist options
  • Save gesslar/c8ad4e3c52ba3df592e99b5388abf029 to your computer and use it in GitHub Desktop.
Save gesslar/c8ad4e3c52ba3df592e99b5388abf029 to your computer and use it in GitHub Desktop.
Script for managing Muddler automatic uninstall/re-install
-- After making changes to the items table, you will need to run: lua resetProfile()
-- So that it will reload.
MuddleHelper = MuddleHelper or {
items = {
{ name = "ThreshBuff", path = "D:/git/threshbuff", active = true, helper = nil },
{ name = "ThreshKeepalive", path = "D:/git/ThreshKeepalive", active = true, helper = nil },
{ name = "ThreshColorPercent", path = "D:/git/ThreshColorPercent", active = true, helper = nil },
}
}
function MuddleHelper:KillIt(pkg)
debugc(f"Killing {pkg}")
-- Check package.loaded
for pkgName, _ in pairs(package.loaded) do
if pkgName:find(pkg) then
debugc(f"Uncaching lua package {pkgName}")
package.loaded[pkgName] = nil
end
end
-- Check _G in package.loaded
if package.loaded._G and type(package.loaded._G) == "table" then
for globalName, _ in pairs(package.loaded._G) do
if globalName:find(pkg) then
debugc(f"Uncaching lua package {globalName}")
package.loaded._G[globalName] = nil
end
end
end
end
-- Helper function to create a new Muddler instance with a string callback
function MuddleHelper:createMuddler(item)
local postremoveString = f"MuddleHelper:KillIt('{item.name}')"
return Muddler:new({
path = item.path,
postremove = postremoveString,
})
end
function MuddleHelper:setup()
if Muddler then
for _, item in ipairs(self.items) do
-- Check if the item is active and doesn't have a helper, then create one
if item.active and not item.helper then
item.helper = self:createMuddler(item)
debugc(f"Added Muddler helper for {item.name}")
end
end
end
end
MuddleHelper:setup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment