Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua API & REPL using luagenny #10

Merged
merged 8 commits into from
Aug 25, 2022
Merged

Lua API & REPL using luagenny #10

merged 8 commits into from
Aug 25, 2022

Conversation

praydog
Copy link
Collaborator

@praydog praydog commented Aug 25, 2022

As per the title, this adds a Lua API & REPL using my library, luagenny.

This adds three new dependencies, sol2, lua 5.4, and luagenny.

The top level luagenny API can be accessed through the sdkgenny global table.

ReGenny's implementation overrides luagenny's global sdkgenny_reader and sdkgenny_string_reader functions to read external memory instead.

In addition to the luagenny bindings, I've added bindings for some of the core regenny objects:

ReGenny class can be accessed by the Lua global regenny:

regenny:address() -- Returns the current top level structure address being inspected in the viewer/editor
regenny:type() -- Returns the current sdkgenny::Type* being inspected in the viewer/editor
regenny:sdk() -- Returns the current sdkgenny::Sdk* created as a result of parsing the editor text
regenny:process() -- Returns the current regenny Process* for the attached process, WindowsProcess* on Win32
regenny:overlay() -- Constructs and returns a new sdkgenny.StructOverlay with the current address() and type()

Process class: (read funcs only take (addr), write funcs are (addr, value))

  • read_uint8
  • read_uint16
  • read_uint32
  • read_uint64
  • read_int8
  • read_int16
  • read_int32
  • read_int64
  • read_float
  • read_double
  • write_uint8
  • write_uint1
  • write_uint3
  • write_uint6
  • write_int8
  • write_int16
  • write_int32
  • write_int64
  • write_float
  • write_double
  • read_string

WindowsProcess class (on Windows only):

  • get_typename(obj_addr) - Returns the RTTI name of the object

Example script to set the scale of a game object given the corret structure definitions:

if regenny:overlay:type():name() ~= "HeroLocal" then
    print("overlay is not a HeroLocal")
    return
end

function set_scale(x, y, z)
    local data = regenny:overlay().owner.data_at_0

    if data then
        data.scale.x = x
        data.scale.y = y
        data.scale.z = z
    end
end

Then just run set_scale(1, 2, 3) inside the REPL window.

Example script to dump component names for a given entity in that new game about the Arachnid Male (given the correct ReGenny structure definitions)

arachnid

local overlay = regenny:overlay()
if overlay == nil then
    print("no overlay, exiting")
    return
end

if overlay:type():name() ~= "HeroLocal" then
    print("overlay is not a HeroLocal")
    return
end

for i=0, 1000 do
    local elements = overlay.data[0].elements
    if elements == nil then
        print("elements is nil")
        break
    end

    local element = overlay.data[0].elements[i]
    if element == nil then
        print("element at " .. tostring(i) .. " is nil")
        break
    end
    
    local descriptor = element.descriptor
    local comp = element.component
    if comp == nil then
        print("Encountered nil component at index " .. tostring(i))
        break
    end

    if descriptor == nil then
        print("Encountered nil descriptor at index " .. tostring(i))
        break
    end

    local name = descriptor.component_name
    if name == nil then
        print("Encountered nil component name at index " .. tostring(i))
        break
    end

    local data = comp.data
    if data == nil then
        print("Encountered nil data at index " .. tostring(i))
        break
    end

    print(tostring(i) .. " [" .. tostring(data.component_name) .. "]: " .. name)
end

Copy link
Owner

@cursey cursey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@praydog praydog merged commit b00a791 into master Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants