Skip to content

Commit

Permalink
Tools: Add a utility script to dump RSM files as JSON
Browse files Browse the repository at this point in the history
This doesn't currently work due to a bug in the JSON encoder; it will throw when encountering FFI metatypes and other unexpected value types. After the next runtime update, this problem should no longer exist.
  • Loading branch information
rdw-software committed Feb 18, 2024
1 parent cafefab commit 3d81a6e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Core/FileFormats/RagnarokRSM.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local assertions = require("assertions")
local iconv = require("iconv")
local json = require("json")
local uv = require("uv")

local assert = assert
Expand Down Expand Up @@ -426,4 +427,15 @@ function RagnarokRSM:DecodeOptionalBoundingBoxes()
end
end

function RagnarokRSM:ToJSON()
local rsmInfo = {
signature = self.signature,
version = self.version,
meshes = self.meshes,
scaleKeyframes = self.scaleKeyframes,
boundingBoxes = self.boundingBoxes,
}
return json.prettier(rsmInfo)
end

return RagnarokRSM
18 changes: 18 additions & 0 deletions Tools/rsm-to-json.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local RagnarokGRF = require("Core.FileFormats.RagnarokGRF")
local RagnarokRSM = require("Core.FileFormats.RagnarokRSM")

local grf = RagnarokGRF()
grf:Open("data.grf")
local rsmFileName = arg[1] or "data/model/프론테라/민가04.rsm"

local rsmFileContents = grf:ExtractFileInMemory(rsmFileName)
grf:Close()

local rsm = RagnarokRSM()
rsm:DecodeFileContents(rsmFileContents)

local jsonFileContents = rsm:ToJSON()

local jsonFilePath = path.join("Exports", path.basename(rsmFileName) .. ".json")
printf("Exporting decoded file contents to %s", jsonFilePath)
C_FileSystem.WriteFile(jsonFilePath, jsonFileContents)

0 comments on commit 3d81a6e

Please sign in to comment.