diff --git a/.gitignore b/.gitignore index 86e94c0..4fb8064 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,6 @@ luac.out *.exp # Shared objects (inc. Windows DLLs) -*.dll *.so *.so.* *.dylib diff --git a/OBSReplayFolders.lua b/OBSReplayFolders.lua index 4336d1e..35c3170 100644 --- a/OBSReplayFolders.lua +++ b/OBSReplayFolders.lua @@ -1,22 +1,25 @@ obs = obslua function script_description() - return [[Saves replays to sub-folders using the Game Capture executable name. + return [[Saves replays to sub-folders using the current fullscreen video game executable name. Author: redraskal]] end function script_load() + ffi = require("ffi") + ffi.cdef[[ + int get_running_fullscreen_game_path(char* buffer, int bufferSize) + ]] + detect_game = ffi.load(script_path() .. "detect_game.dll") + print(get_running_game_title()) 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_running_game_title() if path ~= nil and folder ~= nil then print("Moving " .. path .. " to " .. folder) move(path, folder) @@ -36,9 +39,12 @@ function get_replay_buffer_output() end function get_running_game_title() - local handle = assert(io.popen("detect_game")) - local result = handle:read("*all") - handle:close() + 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) local len = #result if len == 0 then return nil @@ -55,7 +61,6 @@ function get_running_game_title() end i = i + 1 end - print("Current running game: " .. title) return title end diff --git a/README.md b/README.md index d9a12c0..314df3f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,3 @@ # obs-replay-folders Saves replay buffer files to game-specific folders (like ShadowPlay). - -## Important: - -1. The script requires `detect_game.exe` to be added to PATH. -2. To update the replay folder, restart the Replay Buffer. - -There is no way to run an executable in Lua without breaking fullscreen application focus. So, the current running game will not automatically update. diff --git a/detect_game.dll b/detect_game.dll new file mode 100644 index 0000000..8fa1933 Binary files /dev/null and b/detect_game.dll differ diff --git a/detect_game.exe b/detect_game.exe deleted file mode 100644 index 79ad581..0000000 Binary files a/detect_game.exe and /dev/null differ