Skip to content

Commit ae7f503

Browse files
committed
- input blocking scripts state
- other scripts stuff
1 parent d6308c3 commit ae7f503

File tree

4 files changed

+341
-1
lines changed

4 files changed

+341
-1
lines changed

data/scripts/_old/docs_dump.lua

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
2+
local luaDocs = {}
3+
4+
function LuaDocumentation_Initialise()
5+
print("$luadoc$:init")
6+
luaDocs = {}
7+
end
8+
function LuaDocumentation_Shutdown()
9+
print("$luadoc$:shutdown")
10+
addUserUpdateFunction("LuaDocs", function()
11+
local blacklist = {
12+
["_M"] = true,
13+
["_NAME"] = true,
14+
["_PACKAGE"] = true,
15+
}
16+
17+
print("**** sorting docs")
18+
local docs = {}
19+
for k,v in pairs(luaDocs) do
20+
if k ~= "_G" then
21+
table.insert(docs, k)
22+
end
23+
end
24+
table.sort(docs)
25+
26+
if luaDocs["_G"] ~= nil then
27+
table.insert(docs, 1, "_G")
28+
end
29+
30+
local docfile = io.open("temp:luadocs.txt", "w+")
31+
32+
print("**** writing docs")
33+
for i,libraryName in ipairs(docs) do
34+
local library = rawget(luaDocs, libraryName)
35+
local t = "table"
36+
if library._M and library._NAME and library._PACKAGE then
37+
t = "module"
38+
end
39+
docfile:write(string.format("[%s] : %s\n", libraryName, t))
40+
local sorted = {}
41+
for name,_ in pairs(library) do
42+
if not blacklist[name] then
43+
table.insert(sorted, name)
44+
end
45+
end
46+
table.sort(sorted)
47+
local typeMap = {
48+
"CFunction",
49+
"function",
50+
"property",
51+
"userdata",
52+
"table",
53+
"boolean",
54+
"number",
55+
"string",
56+
"nil",
57+
}
58+
local typeSorted = {}
59+
for _,t in ipairs(typeMap) do
60+
typeSorted[t] = {}
61+
end
62+
for _,name in ipairs(sorted) do
63+
local info = library[name]
64+
local m = ""
65+
local t = type(name)
66+
if t == "string" then
67+
if name:find(" ") ~= nil then
68+
m = string.format("[\"%s\"]", name)
69+
else
70+
m = name
71+
end
72+
else
73+
m = string.format("[%s]", tostring(name))
74+
end
75+
if string.len(info.docs) > 0 then
76+
m = m .." : ".. info.docs
77+
end
78+
table.insert(typeSorted[info.type], m)
79+
end
80+
for _,t in ipairs(typeMap) do
81+
local v = typeSorted[t]
82+
for _,m in ipairs(v) do
83+
local l = string.format("\t%s %s\n", t, m)
84+
docfile:write(l)
85+
end
86+
end
87+
end
88+
docfile:close()
89+
90+
removeUserUpdateFunction("LuaDocs")
91+
end, 0.01 * updates.stepRate, true)
92+
end
93+
function LuaDocumentation_AddLuaLibrary(libraryName)
94+
if luaDocs[libraryName] == nil then
95+
luaDocs[libraryName] = {}
96+
end
97+
end
98+
function LuaDocumentation_AddLuaDocumentation(libraryName, docType, docName, docText)
99+
if luaDocs[libraryName] == nil then
100+
luaDocs[libraryName] = {}
101+
end
102+
if luaDocs[libraryName][docName] == nil then
103+
luaDocs[libraryName][docName] = { type = docType, docs = docText or "" }
104+
end
105+
end
106+
function LuaDocumentation_AddLuaDataDocumentation(libraryName, value, name, docs)
107+
local printTypes = {
108+
["string"] = true,
109+
["number"] = true,
110+
["boolean"] = true,
111+
}
112+
local dataType = type(value)
113+
if printTypes[dataType] then
114+
local v = tostring(value)
115+
if dataType == "string" then
116+
v = '"'..v..'"'
117+
end
118+
if string.len(docs) > 0 then
119+
docs = v .." : ".. docs
120+
else
121+
docs = v
122+
end
123+
end
124+
LuaDocumentation_AddLuaDocumentation(libraryName, dataType, name, docs)
125+
end
126+
function LuaDocumentation_AddLuaFunctionDocumentation(libraryName, functionName, functionDocs)
127+
LuaDocumentation_AddLuaDocumentation(libraryName, "function", functionName, functionDocs)
128+
end
129+
function LuaDocumentation_AddLuaPropertyDocumentation(libraryName, propertyName, propertyDocs)
130+
LuaDocumentation_AddLuaDocumentation(libraryName, "property", propertyName, propertyDocs)
131+
end
132+
function LuaDocumentation_RemoveLuaLibrary(libraryName)
133+
if luaDocs[libraryName] then
134+
table.remove(luaDocs, libraryName)
135+
end
136+
end
137+
function LuaDocumentation_ParseTable(name, values)
138+
local function parseTable(name, key, value)
139+
if key ~= name then
140+
LuaDocumentation_AddLuaDataDocumentation(name, value, key, "")
141+
end
142+
end
143+
local function parseGlobals(name, key, value)
144+
if type(value) == "table" then
145+
if key ~= "_G" then
146+
LuaDocumentation_ParseTable(key, value)
147+
end
148+
else
149+
LuaDocumentation_AddLuaDataDocumentation("_G", value, key, "")
150+
end
151+
end
152+
153+
local parseIt = parseGlobals
154+
if string.len(name) > 0 then
155+
parseIt = parseTable
156+
end
157+
158+
for key, value in next, values do
159+
parseIt(name, key, value)
160+
end
161+
end

data/scripts/_old/user.lua

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
function spawnVehicleEx(modelID, vehicleParams, characters)
2+
local function spawn()
3+
vehicleParams = vehicleParams or {}
4+
5+
local params = {
6+
heading = 0,
7+
modelID = modelID or 0,
8+
snapToTerrain = vehicleParams.snapToTerrain or true,
9+
panelSet = mods.panelSetOverride or vehicleParams.panelSet or nil,
10+
shader = {
11+
[0] = vehicleParams.chosenShader or framework.random(0,8)
12+
},
13+
}
14+
local mt = {__index = vehicleParams, __newindex = function(t, k, v) rawset(vehicleParams, k, v) end}
15+
setmetatable(params, mt)
16+
if localPlayer.currentVehicle then
17+
params.position = localPlayer.position + -localPlayer.currentVehicle.matrix[0] * 5
18+
params.heading = localPlayer.heading
19+
else
20+
params.position = player.position + vec.vector(5, 0, 0, 1)
21+
end
22+
local vehicle = vehicleManager.spawnVehicle(params)
23+
vehicle.owner = "Script"
24+
if characters then
25+
for i = 1, #characters do
26+
GameVehicleResource.setCharacterSpoolingEntityIndex(vehicle.gameVehicle, i - 1, characters[i])
27+
end
28+
else
29+
-- clear passengers
30+
for i = 1, 3 do
31+
GameVehicleResource.setCharacterSpoolingEntityIndex(vehicle.gameVehicle, i, "-1")
32+
end
33+
end
34+
35+
local rigID = 285
36+
local bigRigID = 286
37+
local trailerID = 123
38+
39+
local trailerIDs = {
40+
123,
41+
131,
42+
289,
43+
}
44+
45+
if modelID == bigRigID or modelID == rigID then
46+
local selTrailerId = trailerIDs[framework.random(1, 3)]
47+
48+
-- make sure special trailers are spooled in
49+
if selTrailerId ~= trailerID then
50+
local trailerLoaded = TrafficSpooler.IsMissionVehicleLoaded(selTrailerId)
51+
local tries = 1
52+
53+
while not trailerLoaded do
54+
if tries > 3 then
55+
print("**** COULD NOT SPAWN TRAILER WITH ID ".. selTrailerId .." - USING DEFAULT! ****")
56+
selTrailerId = trailerID
57+
break
58+
end
59+
60+
TrafficSpooler.RequestMissionVehicle(selTrailerId)
61+
trailerLoaded = TrafficSpooler.IsMissionVehicleLoaded(selTrailerId)
62+
tries = tries + 1
63+
end
64+
end
65+
66+
GameVehicleResource.createTrailerAndHookup({
67+
gameVehicle = vehicle.gameVehicle,
68+
trailerId = selTrailerId,
69+
panelSet = framework.random(0,8)
70+
})
71+
end
72+
73+
return vehicle
74+
end
75+
local function waitForSpooling(modelID)
76+
TrafficSpooler.SetAsPlayerVehicle(modelID)
77+
return function()
78+
if TrafficSpooler.IsPlayerVehicleLoaded() then
79+
removeUserUpdateFunction("spawnVehicleEx")
80+
spawn()
81+
end
82+
end
83+
end
84+
if TrafficSpooler.IsMissionVehicleLoaded(modelID) then
85+
return spawn()
86+
elseif not spooling.requestToSpoolVehicle(modelID, spawn) then
87+
addUserUpdateFunction("spawnVehicleEx", waitForSpooling(modelID), 1)
88+
end
89+
end
90+
91+
local function safeRun()
92+
if localPlayer.currentVehicle then
93+
local status = controlHandler:getStatus("Zap_ActiveVehicle_Two")
94+
if status == "JustPressed" then
95+
local vehicle = localPlayer.currentVehicle
96+
97+
local newVehicle = spawnVehicleEx(vehicle.model_id)
98+
99+
OneShotSound.PlayMenuSound("HUD_Garage_Vehicle_Repair")
100+
101+
localPlayer:setPreviousVehicle()
102+
localPlayer:zapToAgent(newVehicle, {playerInstigated = true, disableZapFlash = true})
103+
end
104+
local status = controlHandler:getStatus("Zap_ActiveVehicle_One")
105+
if status == "JustPressed" then
106+
spawnVehicleEx(269)
107+
end
108+
end
109+
end
110+
111+
local function waitForSimulation()
112+
-- wait for the pause menu to go away
113+
if simulation.getSpeed() ~= 0 then
114+
removeUserUpdateFunction("safeRunWait")
115+
addUserUpdateFunction("safeRunDelay", safeRun, 1)
116+
end
117+
end
118+
119+
addUserUpdateFunction("safeRunWait", waitForSimulation, 0.1 * updates.stepRate)

data/scripts/driverNGHookMenu.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
local menuShown = false
2+
3+
local function dngHookMenu()
4+
local toggle = ImGui.IsKeyPressed(0x71) -- VK_F2
5+
6+
if toggle then
7+
menuShown = not menuShown
8+
end
9+
10+
if menuShown and ImGui.BeginMainMenuBar() then
11+
if ImGui.BeginMenu("File") then
12+
13+
ImGui.EndMenu()
14+
end
15+
16+
if ImGui.BeginMenu("View") then
17+
18+
ImGui.EndMenu();
19+
end
20+
21+
if ImGui.BeginMenu("World") then
22+
23+
ImGui.EndMenu();
24+
end
25+
26+
if ImGui.BeginMenu("Game") then
27+
28+
ImGui.EndMenu()
29+
end
30+
31+
if ImGui.BeginMenu("Utilities") then
32+
33+
ImGui.EndMenu()
34+
end
35+
36+
if ImGui.BeginMenu("Help") then
37+
if ImGui.MenuItem("API documentation") then
38+
documentationWindowShown = not documentationWindowShown
39+
end
40+
ImGui.EndMenu()
41+
end
42+
43+
ImGui.EndMainMenuBar();
44+
end
45+
46+
return menuShown
47+
end
48+
49+
ImGui_AddUpdateFunction("Menu", dngHookMenu, true)

data/scripts/game_autoexec.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,20 @@ end
122122

123123
-- called from C++
124124
local function hookImGui_Update()
125+
local needsInputBlocking = false
125126
for k,upd in pairs(driverNGHook.imGuiFuncs) do
126127
if upd.displayAlways or driverNGHook.gamePaused then
127-
xpcall(upd.func, hookImGui_errorHandler)
128+
local ret = nil
129+
xpcall(function()
130+
ret = upd.func()
131+
end, hookImGui_errorHandler)
132+
133+
if type(ret) == "boolean" and ret == true then
134+
needsInputBlocking = true
135+
end
128136
end
129137
end
138+
return needsInputBlocking
130139
end
131140

132141
-------------------------------------------------------------------------------------------
@@ -212,3 +221,5 @@ local function check(tab, name, value)
212221
end
213222

214223
setmetatable(_G, {__index=ReadOnly, __newindex=check})
224+
225+
dofile(DNGHookScriptPath.. "driverNGHookMenu.lua")

0 commit comments

Comments
 (0)