Jump to content

Recommended Posts

i'm trying to get SEASON_DANGER_MUSIC and SEASON_EPICFIGHT_MUSIC, for a way to future-proof and sort of add compatiblity to my music mod, but i just can't upvalue hack it. it's called in the StartDanger() function at line 525 in dynamicmusic.lua, and from what i understand, the reference path should be something like OnPlayerActivated() (ln 775) -> StartPlayerListeners() (ln 667) -> OnAttacked() (ln 627) -> StartDanger()

i've managed to get and replace SEASON_BUSY_MUSIC from StartBusy() at line 235, and the work music seems to work fine, but the others simply just return nil in the debug print

here's the snippet of code that i'm using to get and replace them:

Spoiler

local SEASON_BUSY_MUSIC_ANALOG =
{
    autumn = "music_mod/music/music_work",
    winter = "music_mod/music/music_work_winter",
    spring = "music_mod/music/music_work_spring",
    summer = "music_mod/music/music_work_summer",
}

local SEASON_DANGER_MUSIC_ANALOG =
{
    autumn = "music_mod/music/music_danger",
    winter = "music_mod/music/music_danger_winter",
    spring = "music_mod/music/music_danger_spring",
    summer = "music_mod/music/music_danger_summer",
}

local SEASON_EPICFIGHT_MUSIC_ANALOG =
{
    autumn = "music_mod/music/music_epicfight",
    winter = "music_mod/music/music_epicfight_winter",
    spring = "music_mod/music/music_epicfight_spring",
    summer = "music_mod/music/music_epicfight_summer",
}

AddComponentPostInit("dynamicmusic", function(self, inst)
    local OnEnabledDynamicMusic, OnPlayerActivated, StartPlayerListeners, StartBusy, OnAttacked, StartDanger, SEASON_BUSY_MUSIC, SEASON_DANGER_MUSIC, SEASON_EPICFIGHT_MUSIC
    local function _SetupUpvalues()
        OnEnabledDynamicMusic = inst:GetEventCallback("enabledynamicmusic", TheWorld)
        OnPlayerActivated = inst:GetEventCallBack("playeractivated", inst, "scripts/components/dynamicmusic.lua")

        StartPlayerListeners = UpvalueHacker.GetUpvalue(OnPlayerActivated, "StartPlayerListeners")

        StartBusy = UpvalueHacker.GetUpvalue(StartPlayerListeners, "StartBusy")
        OnAttacked = UpvalueHacker.GetUpvalue(StartPlayerListeners, "OnAttacked")
        StartDanger = UpvalueHacker.GetUpvalue(OnAttacked, "StartDanger")
        SEASON_BUSY_MUSIC = UpvalueHacker.GetUpvalue(StartBusy, "SEASON_BUSY_MUSIC")
        SEASON_EPICFIGHT_MUSIC = UpvalueHacker.GetUpvalue(StartDanger, "SEASON_EPICFIGHT_MUSIC")
        SEASON_DANGER_MUSIC = UpvalueHacker.GetUpvalue(StartDanger, "SEASON_DANGER_MUSIC")
    end

 

    local function ReplaceAnalog(original, analog)
        if original and analog then
            for k, v in pairs(original) do
                print("K:", k, "V:", v, "FULL VALUE:", analog[k])
                original[k] = analog[k]
            end
        end
    end

    ReplaceAnalog(SEASON_BUSY_MUSIC, SEASON_BUSY_MUSIC_ANALOG)
    ReplaceAnalog(SEASON_DANGER_MUSIC, SEASON_DANGER_MUSIC_ANALOG)
    ReplaceAnalog(SEASON_EPICFIGHT_MUSIC, SEASON_BUSY_MUSIC_ANALOG)
end)

anyone know why this doesn't work? i don't know if upvalue hacking it is the best way to approach it, but it was the one i could wrap my head around the most

Edited by fabin

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...