-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSILVER_FrameDebugger.lua
265 lines (234 loc) · 12.9 KB
/
SILVER_FrameDebugger.lua
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
--/////////////////////////////////////--
local modName = "Frame Debugger"
local modAuthor = "SilverEzredes"
local modUpdated = "02/11/2025"
local modVersion = "v1.0.01"
local modCredits = "alphaZomega; praydog"
local modNotes = "Required _ScriptCore version: 1.1.92+\nTested in:\n - MHWilds OBT1\n - RE4R"
local modChangeLog = "v1.0.01\n - Small UI changes\n\nTestedv1.0.00\n - Initial release"
--/////////////////////////////////////--
local func = require("_SharedCore/Functions")
local ui = require("_SharedCore/Imgui")
local hk = require("Hotkeys/Hotkeys")
local changed = false
local wc = false
local appSingelton = sdk.get_native_singleton("via.Application")
local appType = sdk.find_type_definition("via.Application")
local frameTimePeak = 0.0
local frameTimeRecord = {}
local debugToolDefaultSettings = {
maxFrameTime = 0.0,
currFrame = 0,
deltaTime = 0.0,
OS = "",
frameTimeCritical = 33.334,
frameTimeWarningThreshold = 0.75,
deltaTimeBaseLine = 2.0,
historyMaxSize = 50,
capturedFrameCount = 0,
recordMaxSize = 100000,
frameTimeHistory = {},
deltaTimeHistory = {},
isNewWindow = false,
showFrameTime = true,
showFrameRecord = true,
showDeltaTime = true,
["isRecFrameTime"] = false,
}
local debugToolSettings = hk.merge_tables({}, debugToolDefaultSettings) and hk.recurse_def_settings(json.load_file("SILVER/_Debug/FrameDebuggerSettings.json") or {}, debugToolDefaultSettings)
local function add_ToHistory(value, tbl, maxSize, key)
if key then
tbl[key] = value
else
table.insert(tbl, value)
end
if not key and #tbl > maxSize then
table.remove(tbl, 1)
elseif key then
local count = 0
for _ in pairs(tbl) do
count = count + 1
end
if count > maxSize then
local oldestKey = nil
for k in pairs(tbl) do
if not oldestKey or k < oldestKey then
oldestKey = k
end
end
tbl[oldestKey] = nil
end
end
end
local function lua_TableToCSV(tbl)
local csv = {}
local keys = {}
for key, _ in pairs(tbl) do
table.insert(keys, key)
end
table.insert(csv, table.concat(keys, ","))
local values = {}
for _, value in pairs(tbl) do
table.insert(values, value)
end
table.insert(csv, table.concat(values, ","))
return csv
end
local function get_AppData()
if appSingelton == nil then return end
debugToolSettings.maxFrameTime = sdk.call_native_func(appSingelton, appType, "get_FrameTimeMillisecond")
add_ToHistory(debugToolSettings.maxFrameTime, debugToolSettings.frameTimeHistory, debugToolSettings.historyMaxSize)
debugToolSettings.deltaTime = sdk.call_native_func(appSingelton, appType, "get_DeltaTime")
add_ToHistory(debugToolSettings.deltaTime, debugToolSettings.deltaTimeHistory, debugToolSettings.historyMaxSize)
debugToolSettings.currFrame = sdk.call_native_func(appSingelton, appType, "get_FrameCount")
debugToolSettings.OS = sdk.call_native_func(appSingelton, appType, "get_OperatingSystemDesc")
end
local function record_FrameTime()
if not debugToolSettings["isRecFrameTime"] then return end
debugToolSettings.maxFrameTime = sdk.call_native_func(appSingelton, appType, "get_FrameTimeMillisecond")
add_ToHistory(debugToolSettings.maxFrameTime, frameTimeRecord, debugToolSettings.recordMaxSize, debugToolSettings.currFrame)
end
local function setup_FrameDebugger()
ui.textButton_ColoredValue("OS:", debugToolSettings.OS, func.convert_rgba_to_ABGR(ui.colors.cerulean))
imgui.same_line()
ui.textButton_ColoredValue("Current Frame:", debugToolSettings.currFrame, func.convert_rgba_to_ABGR(ui.colors.gold))
changed, debugToolSettings.isNewWindow = imgui.checkbox("Use Separate Window", debugToolSettings.isNewWindow); wc = wc or changed
imgui.spacing()
if debugToolSettings.showFrameTime then
if debugToolSettings.maxFrameTime >= debugToolSettings.frameTimeCritical * debugToolSettings.frameTimeWarningThreshold then
ui.progressBar_DynamicColor(string.format("Frame Time: %.3fms", debugToolSettings.maxFrameTime), false, 0, func.convert_rgba_to_ABGR(ui.colors.white), func.convert_rgba_to_ABGR(ui.colors.red), func.convert_rgba_to_ABGR(ui.colors.orange), func.convert_rgba_to_ABGR(ui.colors.REFgray), debugToolSettings.frameTimeCritical, debugToolSettings.maxFrameTime, 100.0, 300.0, 5.0)
else
ui.progressBar_DynamicColor(string.format("Frame Time: %.3fms", debugToolSettings.maxFrameTime), false, 0, func.convert_rgba_to_ABGR(ui.colors.white), func.convert_rgba_to_ABGR(ui.colors.red), func.convert_rgba_to_ABGR(ui.colors.green), func.convert_rgba_to_ABGR(ui.colors.REFgray), debugToolSettings.frameTimeCritical, debugToolSettings.maxFrameTime, 100.0, 300.0, 5.0)
end
if debugToolSettings.maxFrameTime >= 100.0 then
frameTimePeak = debugToolSettings.maxFrameTime
end
imgui.text(string.format("Last Major Peak: %.3fms", frameTimePeak))
if debugToolSettings.showFrameRecord then
ui.button_CheckboxStyle("[ REC ]", debugToolSettings, "isRecFrameTime", func.convert_rgba_to_ABGR(ui.colors.REFgray), func.convert_rgba_to_ABGR(ui.colors.deepRed), func.convert_rgba_to_ABGR(ui.colors.deepRed))
imgui.same_line()
debugToolSettings.capturedFrameCount = func.get_table_size(frameTimeRecord)
ui.textButton_ColoredValue("Captured Frame Count: ", debugToolSettings.capturedFrameCount, func.convert_rgba_to_ABGR(ui.colors.deepRed))
if imgui.button("Clear Captured Frames") then
frameTimeRecord = {}
end
imgui.same_line()
if imgui.button("Save Recording") then
json.dump_file("SILVER/_Debug/FrameTime/frameTimeREC.json", lua_TableToCSV(frameTimeRecord))
end
end
if imgui.tree_node("Frame Time History") then
imgui.indent(-20)
for i = #debugToolSettings.frameTimeHistory, 1, -1 do
local frameTime = debugToolSettings.frameTimeHistory[i]
if frameTime >= debugToolSettings.frameTimeCritical * debugToolSettings.frameTimeWarningThreshold then
ui.progressBar_DynamicColor(string.format("%d Frame Time: %.3fms", i, frameTime), false, 0, func.convert_rgba_to_ABGR(ui.colors.white), func.convert_rgba_to_ABGR(ui.colors.red), func.convert_rgba_to_ABGR(ui.colors.orange), func.convert_rgba_to_ABGR(ui.colors.REFgray), debugToolSettings.frameTimeCritical, frameTime, 100.0, 300.0, 5.0, true)
else
ui.progressBar_DynamicColor(string.format("%d Frame Time: %.3fms", i, frameTime), false, 0, func.convert_rgba_to_ABGR(ui.colors.white), func.convert_rgba_to_ABGR(ui.colors.red), func.convert_rgba_to_ABGR(ui.colors.green), func.convert_rgba_to_ABGR(ui.colors.REFgray), debugToolSettings.frameTimeCritical, frameTime, 100.0, 300.0, 5.0, true)
end
end
imgui.indent(20)
imgui.spacing()
imgui.tree_pop()
end
end
if debugToolSettings.showDeltaTime then
ui.progressBar_DynamicColor(string.format("Delta Time: %.3fms", debugToolSettings.deltaTime), false, 0, func.convert_rgba_to_ABGR(ui.colors.safetyYellow), func.convert_rgba_to_ABGR(ui.colors.red), func.convert_rgba_to_ABGR(ui.colors.green), func.convert_rgba_to_ABGR(ui.colors.REFgray), debugToolSettings.deltaTimeBaseLine, debugToolSettings.deltaTime, 4.0, 300.0, 5.0)
if imgui.tree_node("Delta Time History") then
for i = #debugToolSettings.deltaTimeHistory, 1, -1 do
local deltaT = debugToolSettings.deltaTimeHistory[i]
ui.progressBar_DynamicColor(string.format("%d Delta Time: %.3fms", i, deltaT), false, 0, func.convert_rgba_to_ABGR(ui.colors.safetyYellow), func.convert_rgba_to_ABGR(ui.colors.red), func.convert_rgba_to_ABGR(ui.colors.green), func.convert_rgba_to_ABGR(ui.colors.REFgray), debugToolSettings.deltaTimeBaseLine, deltaT, 4.0, 300.0, 5.0, true)
end
imgui.spacing()
imgui.tree_pop()
end
end
if changed or wc then
json.dump_file("SILVER/_Debug/FrameDebuggerSettings.json", debugToolSettings)
changed = false
wc = false
end
end
local function draw_FrameDebugger()
if imgui.tree_node(modName) then
imgui.begin_rect()
imgui.spacing()
imgui.indent(10)
if not debugToolSettings.isNewWindow then
setup_FrameDebugger()
end
imgui.spacing()
if imgui.tree_node("Settings") then
imgui.begin_rect()
imgui.spacing()
imgui.indent(5)
if imgui.button("Reset to Defaults") then
wc = true
debugToolSettings = hk.recurse_def_settings({}, debugToolDefaultSettings)
end
imgui.push_item_width(250)
changed, debugToolSettings.showFrameTime = imgui.checkbox("Show Frame Time", debugToolSettings.showFrameTime); wc = wc or changed
changed, debugToolSettings.showFrameRecord = imgui.checkbox("Show Frame Recorder UI", debugToolSettings.showFrameRecord); wc = wc or changed
changed, debugToolSettings.frameTimeCritical = ui.imgui_safe_input(imgui.drag_float, debugToolSettings.frameTimeCritical, "Critical Frame Time", debugToolSettings.frameTimeCritical, {0.001, 0.0, 100.0, "%.3fms"}); wc = wc or changed
ui.tooltip("Frame Times higher than this value will be marked red.")
local displayThreshold = debugToolSettings.frameTimeWarningThreshold * 100
changed, displayThreshold = ui.imgui_safe_input(imgui.drag_float, debugToolSettings.frameTimeWarningThreshold, "Frame Time Warning Threshold", displayThreshold, {0.01, 0.0, 100.0, "%.1f%%"}); wc = wc or changed
ui.tooltip("Frame Times higher than this percentage of the 'Critical Frame Time' value will be marked orange.")
if changed then
debugToolSettings.frameTimeWarningThreshold = displayThreshold / 100
end
changed, debugToolSettings.showDeltaTime = imgui.checkbox("Show Delta Time", debugToolSettings.showDeltaTime); wc = wc or changed
changed, debugToolSettings.deltaTimeBaseLine = ui.imgui_safe_input(imgui.drag_float, debugToolSettings.deltaTimeBaseLine, "Delta Time Base Line", debugToolSettings.deltaTimeBaseLine, {0.001, 0.0, 100.0, "%.3fms"}); wc = wc or changed
changed, debugToolSettings.historyMaxSize = ui.imgui_safe_input(imgui.drag_int, debugToolSettings.historyMaxSize, "History Limit", debugToolSettings.historyMaxSize, {1, 0, 1000}); wc = wc or changed
changed, debugToolSettings.recordMaxSize = ui.imgui_safe_input(imgui.drag_int, debugToolSettings.recordMaxSize, "Recording Limit", debugToolSettings.recordMaxSize, {10, 0, 1000000}); wc = wc or changed
imgui.pop_item_width()
if changed then
debugToolSettings.deltaTimeHistory = {}
debugToolSettings.frameTimeHistory = {}
end
if imgui.tree_node("Change Log") then
imgui.text(modChangeLog)
imgui.tree_pop()
end
if imgui.tree_node("Credits and Notes") then
imgui.text("Credits: " .. modCredits)
imgui.text("Notes: " .. modNotes)
imgui.tree_pop()
end
imgui.indent(-5)
imgui.spacing()
imgui.end_rect()
imgui.tree_pop()
end
if changed or wc then
json.dump_file("SILVER/_Debug/FrameDebuggerSettings.json", debugToolSettings)
changed = false
wc = false
end
imgui.text_colored(modVersion .. " | " .. modUpdated, func.convert_rgba_to_ABGR(ui.colors.gold)); imgui.same_line(); imgui.text("(c) " .. modAuthor .. " ")
imgui.indent(-10)
imgui.spacing()
imgui.end_rect()
imgui.tree_pop()
end
end
--////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--
--MARK:On Frame
re.on_frame(function ()
get_AppData()
record_FrameTime()
if debugToolSettings.isNewWindow then
imgui.begin_window(modName)
imgui.begin_rect()
imgui.spacing()
imgui.indent(10)
setup_FrameDebugger()
imgui.indent(-10)
imgui.spacing()
imgui.end_rect()
imgui.end_window()
end
end)
re.on_draw_ui(function ()
draw_FrameDebugger()
end)