-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
394 lines (356 loc) · 11.6 KB
/
main.lua
File metadata and controls
394 lines (356 loc) · 11.6 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
local debug = RegisterMod("Debug Tool", 1)
DebugTool = debug
--TODO:
-- Entity whitelist/blacklist
-- Support for mods to render arbitrary data for debugging
-- MCM support
-- DebugLevelState
-- DebugGameState
DebugTool.enums = {}
DebugTool.data = {
sfxThisRoom = {}
}
DebugTool.save = {
config = {}
}
local game = Game()
local sfx = SFXManager()
local cursor = Sprite()
cursor:Load("gfx/ui/cursor.anm2", true)
cursor:Play("Idle")
--cursor.Scale = Vector(0.5, 0.5)
local f = Font() -- init font object
f:Load("font/pftempestasevencondensed.fnt") -- load a font into the font object
include("scripts.the-everything-function-rev1") --provides "dump" function
include("scripts.enums")
include("scripts.data")
include("scripts.command")
--include("scripts.mcm")
if Isaac.GetFrameCount() <= 1 then
DebugTool.data = {
sfxThisRoom = {}
}
end
DebugTool.LoadGame()
-- Helpers --------------------------------------------------------
function DebugTool.getStringWidth(value)
return (string.len(tostring(value))) - .5
end
function DebugTool.UpdateSfxsPlaying()
for i = 1, SoundEffect.NUM_SOUND_EFFECTS do
if sfx:IsPlaying(i) then
local shouldAddIt = true
for j = 1, #DebugTool.data.sfxThisRoom do
if DebugTool.data.sfxThisRoom[j] == i then
shouldAddIt = false
break
end
end
if shouldAddIt then
DebugTool.data.sfxThisRoom[#DebugTool.data.sfxThisRoom + 1] = i
end
end
end
end
function DebugTool.StringList(number, stringTable) -- it's easier to iterate on bit values this way than doing bitwise comparisons
local bitTab = DebugTool.ToBitTab(number)
local returnString = ""
for i = 1, #stringTable do
if bitTab[i]==1 then
if (returnString == "") then
returnString = returnString .. stringTable[i]
else
returnString = returnString .. ", " .. stringTable[i]
end
end
end
if (returnString == "") then
return "none"
end
return returnString
end
function DebugTool.ToBitTab(num)
local t={}
local rest = 0
while num>0 do
rest=math.fmod(num,2)
t[#t+1]=rest
num=(num-rest)/2
end
return t
end
local function GetDimension()
local level = game:GetLevel()
local curDec = level:GetCurrentRoomDesc()
local curIndex = level:GetCurrentRoomIndex()
if GetPtrHash(curDec) == GetPtrHash(level:GetRoomByIdx(curIndex, 0)) then
return 0
elseif GetPtrHash(curDec) == GetPtrHash(level:GetRoomByIdx(curIndex, 2)) then
return 2
else
return 1
end
end
local widthDefault = 30 -- i'll clean this later.
local function DrawText(text, x, y, sx, sy, r, g, b, a, w, c)
f:DrawStringScaled(text, x-w/2, y, sx, sy, KColor(r, g, b, a), w, c)
end
-- Processors --------------------------------------------------------
local function DebugSFX()
if DebugTool.config.debugSfxs then
DebugTool.UpdateSfxsPlaying()
if DebugTool.config.toggle then
local buffer = ""
local x = 400 - 23*Options.HUDOffset
DrawText("SFXs this room:", x, 5, 0.5, 0.5, 255, 255, 255, 255, widthDefault, false)
for i=1, #DebugTool.data.sfxThisRoom do
buffer = DebugTool.enums.sfxList[DebugTool.data.sfxThisRoom[i]]
if type(buffer) == "nil" then buffer = tostring(i) end
DrawText(buffer, x, 5 + 7*i, 0.5, 0.5, 255, 255, 255, 255, widthDefault, false)
end
end
end
end
local function DebugGameValues(player)
if DebugTool.config.debugGameValues then
local x = 35 + 20*Options.HUDOffset
local y = 30 + 11.8*Options.HUDOffset
DrawText("Character: " .. player:GetName(), x, y, 0.5, 0.5, 255, 255, 255, 255, 0, false)
local source = player:GetLastDamageSource()
if source ~= nil then
DrawText("Last damage source: " .. source.Type .. "." .. source.Variant, x, y+7, 0.5, 0.5, 255, 255, 255, 255, 0, false)
end
local text = DebugTool.StringList(player:GetLastDamageFlags(), DebugTool.enums.damageFlagList)
DrawText("Last damage flags: " .. text, x, y+14, 0.5, 0.5, 255, 255, 255, 255, 0, false)
DrawText("Current room index: " .. game:GetLevel():GetCurrentRoomIndex() .. ", ".. GetDimension(), x, y+28, 0.5, 0.5, 255, 255, 255, 255, 0, false)
text = DebugTool.StringList(game:GetLevel():GetCurses(), DebugTool.enums.curseList)
DrawText("Curses: " .. text, x, y+35, 0.5, 0.5, 255, 255, 255, 255, 0, false)
end
end
--[[
local function DebugLevelState()
if debugLevelState then
end
end
local function DebugGameState()
if debugGameState then
end
end
]]--
local function DebugAnything(entity, pos)
if entity.Type ~= EntityType.ENTITY_TEXT then -- if it's neither a text nor an effect
local text = "" .. entity.Type .. "." .. entity.Variant .. "." .. entity.SubType
DrawText(text, pos.X, pos.Y-47, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
text = "spawner: " .. entity.SpawnerType .. "." .. entity.SpawnerVariant
if (text ~= "spawner: 0.0") then
DrawText(text, pos.X, pos.Y-42, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
end
end
end
local rY = 0
local foo = {
[1] = function(enemy, x)
local text = "" .. math.floor(enemy.HitPoints*10)/10 .. "/" .. math.floor(enemy.MaxHitPoints*10)/10 ..
string.format(" (%.2f%%)", (math.max(enemy.HitPoints,0)/math.max(enemy.MaxHitPoints, 0.001))*100)
DrawText(text, x, rY, 0.5, 0.5, 255, 255, 0, 255, widthDefault, true)
return true
end,
[2] = function(enemy, x)
local text = DebugTool.enums.stateList[enemy:ToNPC().State+1]
if type(text) == "nil" then text = "unenumed" end
text = text.." ("..enemy:ToNPC().State..")"
DrawText(text, x, rY, 0.5, 0.5, 0, 255, 255, 255, widthDefault, true)
return true
end,
[3] = function(enemy, x)
local buffer = ""
local text = ""
--[[
if frame ~= nil then
if enemy.StateFrame > frame then
buffer = "+"..enemy.StateFrame - frame
else
buffer = "-"..math.abs(enemy.StateFrame - frame)
end
text = "frame: "..enemy.StateFrame.." ("..buffer..")"
else
text = "frame: "..enemy.StateFrame
end
]]--
text = "frame: "..enemy.StateFrame
DrawText(text, x, rY, 0.5, 0.5, 0, 255, 255, 255, widthDefault, true)
return true
end,
[4] = function(enemy, x)
local text = "" .. enemy.Type .. "." .. enemy.Variant .. "." .. enemy.SubType
DrawText(text, x, rY, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
return true
end,
[5] = function(enemy, x)
local text = "spawner: " .. enemy.SpawnerType .. "." .. enemy.SpawnerVariant
if (text ~= "spawner: 0.0") then
DrawText(text, x, rY, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
return true
end
return false
end,
[6] = function(enemy, x)
if DebugTool.config.testIVars then
local text = "I1: " .. dump(enemy.I1) .. " I2: " .. dump(enemy.I2)
DrawText(text, x, rY, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
return true
end
return false
end,
[7] = function(enemy, x)
if DebugTool.config.testVectors then
local text = "V1: " .. dump(enemy.V1)
DrawText(text, x, y, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
if text ~= "V1: Vector(0.00, 0.00)" and text ~= "V1: Vector(0.00, -0.00)" and text ~= "V1: Vector(-0.00, 0.00)" and text ~= "V1: Vector(-0.00, -0.00)" then
cursor.Color = Color(1, .5, 0, 1, 0, 0, 0)
cursor:Render(enemy.V1)
end
rY = rY + 5
text = "V2: " .. dump(enemy.V2)
DrawText(text, x, y, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
if text ~= "V2: Vector(0.00, 0.00)" and text ~= "V2: Vector(0.00, -0.00)" and text ~= "V2: Vector(-0.00, 0.00)" and text ~= "V2: Vector(-0.00, -0.00)" then
cursor.Color = Color(0, .5, 1, 1, 0, 0, 0)
cursor:Render(enemy.V2)
end
return true
end
return false
end,
--[[
[8] = function(enemy, x, y)
local text = "mass: "..enemy.Mass
DrawText(text, x, rY, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
return true
end,
[9] = function(enemy, x, y)
local text = "friction: "..enemy.Friction
DrawText(text, x, rY, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
return true
end
]]--
}
local function DebugEnemy(enemy, pos)
local yOffset = 5
rY = pos.Y - 57
for _,v in pairs(foo) do
if v(enemy, pos.X) then
rY = rY + yOffset
end
end
end
local function DebugPickup(pickup, pos)
-- render type.variant.subtype
local text = "" .. pickup.Type .. "." .. pickup.Variant .. "." .. pickup.SubType
DrawText(text, pos.X, pos.Y-27, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
-- render spawner
text = "spawner: " .. pickup.SpawnerType .. "." .. pickup.SpawnerVariant
if (text ~= "spawner: 0.0") then
DrawText(text, pos.X, pos.Y-22, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
end
end
local function DebugEffect(effect, pos)
local sprite = effect:GetSprite()
local buffer = ""
local text = "" .. effect.Type .. "." .. effect.Variant .. "." .. effect.SubType
DrawText(text, pos.X, pos.Y-47, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
buffer = "" .. sprite:GetFilename()
text = string.sub(buffer, 5, string.len(buffer)-5)
DrawText(text, pos.X, pos.Y-42, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
text = "spawner: " .. effect.SpawnerType .. "." .. effect.SpawnerVariant
if (text ~= "spawner: 0.0") then
DrawText(text, pos.X, pos.Y-37, 0.5, 0.5, 255, 255, 255, 255, widthDefault, true)
end
end
local function DebugEntities(entities, room)
for i = 1, #entities do
local pos = room:WorldToScreenPosition(entities[i].Position, false) -- get its position
if entities[i]:ToNPC() ~= nil then
if entities[i]:IsBoss() and DebugTool.config.debugBoss
or DebugTool.config.debugEnemies and not entities[i]:IsBoss() then
DebugEnemy(entities[i]:ToNPC(), pos)
end
elseif entities[i]:ToPickup() ~= nil then
if entities[i].Variant == PickupVariant.PICKUP_COLLECTIBLE then
if DebugTool.config.debugCollectibles then
DebugPickup(entities[i]:ToPickup(), pos)
end
elseif DebugTool.config.debugPickups then
DebugPickup(entities[i]:ToPickup(), pos)
end
elseif entities[i]:ToEffect() ~= nil then
if DebugTool.config.debugEffects then
DebugEffect(entities[i]:ToEffect(), pos)
end
elseif DebugTool.config.tryDebugAll then
DebugAnything(entities[i], pos)
end
end
end
-- Callbacks --------------------------------------------------------
debug:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, function(_, fromsave)
if not fromsave then
if DebugTool.config.spawnModItems then
local id = CollectibleType.NUM_COLLECTIBLES
while Isaac.GetItemConfig():GetCollectible(id) ~= nil do
Isaac.ExecuteCommand("spawn 5.100." .. id)
id = id+1
end
end
if DebugTool.config.spawnModTrinkets then
local id = TrinketType.NUM_TRINKETS
while Isaac.GetItemConfig():GetTrinket(id) ~= nil do
Isaac.ExecuteCommand("spawn 5.350." .. id)
id = id+1
end
end
end
end)
debug:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, function() DebugTool.data.sfxThisRoom = {} end)
debug:AddCallback(ModCallbacks.MC_POST_RENDER, function()
--TODO move as needed once other functions are done
local entities = Isaac.GetRoomEntities()
local room = game:GetRoom()
local player = Isaac.GetPlayer()
DebugSFX()
if DebugTool.config.toggle then
DebugGameValues(player)
--DebugLevelState()
--DebugGameState()
DebugEntities(entities, room)
end
end)
--Not officially used at this point, but here's a system to directly control some of an entity's params
--[[
local frame = nil
local hp = nil
local state = nil
debug:AddCallback(ModCallbacks.MC_PRE_NPC_UPDATE, function(_, entity)
if type(frame) == "number" then
entity.StateFrame = frame
end
if type(hp) == "number" then
entity.HitPoints = hp
hp = nil
end
if state ~= nil then
entity.State = state
end
end, EntityType.ENTITY_HUSH)
debug:AddCallback(ModCallbacks.MC_EXECUTE_CMD, function(_, cmd, params)
cmd = string.lower(cmd)
if (string.match(cmd,"hush")) then
if cmd == "hush_frame" then
frame = tonumber(params)
elseif cmd == "hush_hp" then
hp = tonumber(params)
elseif cmd == "hush_state" then
state = params
end
end
end)
]]--