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,20 +1,24 @@
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)
folder = get_running_game_title()
end
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
local path = get_replay_buffer_output()
local folder = get_game_capture_window_name()
if path ~= nil and folder ~= nil then
print("Moving " .. path .. " to " .. folder)
move(path, folder)
end
end
@ -31,22 +35,27 @@ function get_replay_buffer_output()
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)
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

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.