Skip to content

prcScript

Ben Hall edited this page Apr 13, 2020 · 8 revisions

prcScript provides a custom Lua environment to edit files.

example code:

Lib.open_dir = "Path/To/Root/Folder/of/Game/Files"
Lib.save_dir = "mods" -- can specify absolute or relative paths

local start = clock()

do
    local root = assert(Lib:open("fighter/common/param/fighter_param.prc"))
    -- "t" here means a table containing each fighter param struct
    local t = assert(root:by_hash(hash("fighter_param_table"))):to_table()

    local mods = {
        mario = {
            scale = 2,
            jostle_weight = 0,
        },
        pikachu = {
            scale = 0.1,
            jump_count_max = 3,
            landing_attack_air_frame_n = 1
        }
    }

    do
        --convert the indeces of the table from strings to their hash
        local _mods = {}
        for name, t in pairs(mods) do
            _mods[hash("fighter_kind_"..name)] = t
        end
        mods = _mods
    end

    for _, p in ipairs(t) do
        local ft_kind_hash = assert(p:by_hash(hash("fighter_kind"))).value
        local mod_table = mods[ft_kind_hash]

        if mod_table then
            for param_name, value in pairs(mod_table) do
                assert(p:by_hash(hash(param_name))).value = value
            end
        end
    end

    Lib:save(root) -- saves to "mods/fighter/common/param/fighter_param.prc"
end

print("elapsed: "..clock() - start)
Clone this wiki locally