-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
119 lines (103 loc) · 3.64 KB
/
Copy pathinit.lua
File metadata and controls
119 lines (103 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--[[
SmartFrameRedirect - a Cyber Engine Tweaks mod for Cyberpunk 2077
---------------------------------------------------------------
Lets you type a custom folder path in an in-game window. Since CET's
mod sandbox cannot spawn external processes (io.popen / os.execute
are both unavailable to mods), this talks to a small separate
PowerShell watcher (watcher.ps1, started via StartWatcher.bat) which
must be running in the background. This mod just writes a small
request.json file; the watcher does the actual folder-junction work
and writes a response.txt back, which this HUD reads and displays.
Requirements: CET, and watcher.ps1 running (via StartWatcher.bat).
--]]
local destPath = "C:\\Users\\marwa\\OneDrive\\Desktop\\redirectcybermod\\images"
local statusMsg = "(watcher.ps1 must be running for buttons to do anything)"
local configFile = "smartframe_redirect_config.json"
local requestFile = "request.json"
local responseFile = "response.txt"
local runtimeData = {
cetOpen = false,
waitingForResponse = false
}
local function loadConfig()
local f = io.open(configFile, "r")
if f then
local content = f:read("*a")
f:close()
local ok, data = pcall(json.decode, content)
if ok and data and data.destPath and data.destPath ~= "" then
destPath = data.destPath
end
end
end
local function saveConfig()
local f = io.open(configFile, "w")
if f then
f:write(json.encode({ destPath = destPath }))
f:close()
end
end
local function sendRequest(action, path)
local f = io.open(requestFile, "w")
if not f then
statusMsg = "Could not write request file. Is the mod folder writable?"
return
end
f:write(json.encode({ action = action, destPath = path or "" }))
f:close()
runtimeData.waitingForResponse = true
statusMsg = "Request sent (" .. action .. ") - waiting for watcher.ps1..."
end
local function pollResponse()
if not runtimeData.waitingForResponse then return end
local f = io.open(responseFile, "r")
if f then
local content = f:read("*a")
f:close()
if os and os.remove then
pcall(os.remove, responseFile)
else
-- Fall back to truncating it instead, so we don't reprocess it forever.
local wf = io.open(responseFile, "w")
if wf then wf:close() end
end
statusMsg = content
runtimeData.waitingForResponse = false
end
end
registerForEvent("onInit", function()
loadConfig()
end)
registerForEvent("onOverlayOpen", function()
runtimeData.cetOpen = true
end)
registerForEvent("onOverlayClose", function()
runtimeData.cetOpen = false
end)
registerForEvent("onUpdate", function(_)
pollResponse()
end)
registerForEvent("onDraw", function()
if not runtimeData.cetOpen then return end
if ImGui.Begin("Smart Frame Redirect") then
ImGui.TextWrapped(
"Folder the in-game Gallery / SmartFrames will read images from:"
)
local newPath, _selected = ImGui.InputText("##sfdestpath", destPath, 260)
destPath = newPath
if ImGui.Button("Redirect Gallery to this folder") then
print("[SmartFrameRedirect] Redirect clicked, destPath = '" .. tostring(destPath) .. "' (type: " .. type(destPath) .. ")")
saveConfig()
sendRequest("redirect", destPath)
end
ImGui.SameLine()
if ImGui.Button("Restore original folder") then
sendRequest("restore", nil)
end
if statusMsg ~= "" then
ImGui.Separator()
ImGui.TextWrapped(statusMsg)
end
end
ImGui.End()
end)