fix: game folders

This commit is contained in:
redraskal 2023-08-03 19:50:37 -05:00
parent 76d1660a05
commit 6d93ee7510
4 changed files with 60 additions and 48 deletions

5
.gitignore vendored
View file

@ -1,3 +1,6 @@
*.c
*.cmd
# Compiled Lua sources
luac.out
@ -32,10 +35,8 @@ luac.out
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

View file

@ -1,62 +1,71 @@
obs = obslua
function script_description()
return [[Saves replays to sub-folders using the Game Capture window name.
return [[Saves replays to sub-folders using the Game Capture executable name.
Author: redraskal]]
end
function script_load()
obs.obs_frontend_add_event_callback(obs_frontend_callback)
obs.obs_frontend_add_event_callback(obs_frontend_callback)
folder = get_running_game_title()
end
function obs_frontend_callback(event)
if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED then
local path = get_replay_buffer_output()
local folder = get_game_capture_window_name()
if path ~= nil and folder ~= nil then
move(path, folder)
end
end
if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED then
folder = get_running_game_title()
end
if event == obs.OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED then
local path = get_replay_buffer_output()
if path ~= nil and folder ~= nil then
print("Moving " .. path .. " to " .. folder)
move(path, folder)
end
end
end
function get_replay_buffer_output()
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
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
end
function get_game_capture_window_name()
-- TODO: Infer source
-- current_scene = obs.obs_frontend_get_current_scene()
-- game_capture = obs.obs_scene_find_source(current_scene, "Game Capture")
game_capture = obs.obs_get_source_by_name("Game Capture")
local properties = obs.obs_source_properties(game_capture)
local prop = obs.obs_properties_get(properties, "window")
local setting = obs.obs_property_name(prop)
local settings = obs.obs_source_get_settings(game_capture)
local value = obs.obs_data_get_string(settings, setting)
obs.obs_data_release(settings)
obs.obs_properties_destroy(properties)
obs.obs_source_release(game_capture)
-- obs.obs_source_release(current_scene)
local i, j = string.find(value, " :")
local title = string.sub(value, 1, j - 3)
return title
function get_running_game_title()
local handle = assert(io.popen("detect_game"))
local result = handle:read("*all")
handle:close()
local len = #result
if len == 0 then
return nil
end
local title = ""
local i = 1
local max = len - 4
while i <= max do
local char = result:sub(i, i)
if char == "\\" then
title = ""
else
title = title .. char
end
i = i + 1
end
print("Current running game: " .. title)
return title
end
function move(path, folder)
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)
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)
end

View file

@ -1,8 +1,10 @@
# obs-replay-folders
Saves replay buffer files to game-specific folders (like ShadowPlay).
## About
## Important:
Replay Buffer Folders moves replay buffer files to a sub-folder upon creation. The sub-folder is determined by the current window title in the Game Capture source. Tested on Windows.
1. The script requires `detect_game.exe` to be added to PATH.
2. To update the replay folder, restart the Replay Buffer.
### The script requires the Game Capture source to be called "Game Capture".
There is no way to run an executable in Lua without breaking fullscreen application focus. So, the current running game will not automatically update.

BIN
detect_game.exe Normal file

Binary file not shown.