2023-01-24 13:02:50 +01:00
|
|
|
obs = obslua
|
|
|
|
|
|
|
|
function script_description()
|
2023-08-04 06:33:23 +02:00
|
|
|
return [[Saves replays to sub-folders using the current fullscreen video game executable name.
|
2024-08-21 20:58:06 +02:00
|
|
|
|
2023-01-24 13:02:50 +01:00
|
|
|
Author: redraskal]]
|
|
|
|
end
|
|
|
|
|
|
|
|
function script_load()
|
2023-08-04 06:33:23 +02:00
|
|
|
ffi = require("ffi")
|
|
|
|
ffi.cdef[[
|
|
|
|
int get_running_fullscreen_game_path(char* buffer, int bufferSize)
|
|
|
|
]]
|
|
|
|
detect_game = ffi.load(script_path() .. "detect_game.dll")
|
2023-08-04 02:50:37 +02:00
|
|
|
obs.obs_frontend_add_event_callback(obs_frontend_callback)
|
2023-01-24 13:02:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function obs_frontend_callback(event)
|
2023-08-04 02:50:37 +02:00
|
|
|
if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED then
|
2023-08-04 06:33:23 +02:00
|
|
|
local folder = get_running_game_title()
|
2024-08-21 20:58:15 +02:00
|
|
|
local path = get_replay_buffer_output()
|
2023-08-04 02:50:37 +02:00
|
|
|
if path ~= nil and folder ~= nil then
|
|
|
|
print("Moving " .. path .. " to " .. folder)
|
|
|
|
move(path, folder)
|
|
|
|
end
|
|
|
|
end
|
2023-01-24 13:02:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function get_replay_buffer_output()
|
2023-08-04 02:50:37 +02:00
|
|
|
local replay_buffer = obs.obs_frontend_get_replay_buffer_output()
|
|
|
|
local cd = obs.calldata_create()
|
|
|
|
local ph = obs.obs_output_get_proc_handler(replay_buffer)
|
|
|
|
obs.proc_handler_call(ph, "get_last_replay", cd)
|
|
|
|
local path = obs.calldata_string(cd, "path")
|
|
|
|
obs.calldata_destroy(cd)
|
|
|
|
obs.obs_output_release(replay_buffer)
|
|
|
|
return path
|
2023-01-24 13:02:50 +01:00
|
|
|
end
|
|
|
|
|
2023-08-04 02:50:37 +02:00
|
|
|
function get_running_game_title()
|
2023-08-04 06:33:23 +02:00
|
|
|
local path = ffi.new("char[?]", 260)
|
|
|
|
local result = detect_game.get_running_fullscreen_game_path(path, 260)
|
|
|
|
if result ~= 0 then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
result = ffi.string(path)
|
2023-08-04 02:50:37 +02:00
|
|
|
local len = #result
|
|
|
|
if len == 0 then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
local max = len - 4
|
2023-09-02 21:49:51 +02:00
|
|
|
local i = max
|
|
|
|
while i > 1 do
|
2023-08-04 02:50:37 +02:00
|
|
|
local char = result:sub(i, i)
|
|
|
|
if char == "\\" then
|
2023-09-02 21:49:51 +02:00
|
|
|
break
|
2023-08-04 02:50:37 +02:00
|
|
|
end
|
2023-09-02 21:49:51 +02:00
|
|
|
i = i - 1
|
2023-08-04 02:50:37 +02:00
|
|
|
end
|
2024-09-17 14:31:13 +02:00
|
|
|
local title = result:sub(i + 1, max)
|
|
|
|
|
|
|
|
-- Trim "-Win64-Shipping" if it exists
|
|
|
|
local trimmed_title = title:gsub("-Win64%-Shipping$", "")
|
|
|
|
|
|
|
|
return trimmed_title
|
2023-01-24 13:02:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function move(path, folder)
|
2023-08-04 02:50:37 +02:00
|
|
|
local sep = string.match(path, "^.*()/")
|
|
|
|
local root = string.sub(path, 1, sep) .. folder
|
|
|
|
local file_name = string.sub(path, sep, string.len(path))
|
|
|
|
local adjusted_path = root .. file_name
|
|
|
|
if obs.os_file_exists(root) == false then
|
|
|
|
obs.os_mkdir(root)
|
|
|
|
end
|
|
|
|
obs.os_rename(path, adjusted_path)
|
2023-01-24 13:02:50 +01:00
|
|
|
end
|