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 # Compiled Lua sources
luac.out luac.out
@ -32,10 +35,8 @@ luac.out
*.dylib *.dylib
# Executables # Executables
*.exe
*.out *.out
*.app *.app
*.i*86 *.i*86
*.x86_64 *.x86_64
*.hex *.hex

View file

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

View file

@ -1,8 +1,10 @@
# obs-replay-folders # obs-replay-folders
Saves replay buffer files to game-specific folders (like ShadowPlay). 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.