-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.lua
1778 lines (1364 loc) · 49.1 KB
/
init.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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--------- STATIC VARIABLES ---------
game_id = 881100
-- load version numbers
dofile("mods/evaisa.mp/version.lua")
noita_online_download = "https://github.com/EvaisaDev/noita-online/releases"
exceptions_in_logger = true
dev_mode = false
debugging = false
disable_print = false
trailer_mode = false
disable_error_catching = false
-----------------------------------
popup = dofile("mods/evaisa.mp/files/scripts/popup.lua")
try = dofile("mods/evaisa.mp/lib/try_catch.lua")
local ffi = require"ffi"
----- check if thingy is installed ------
local failed_to_load = false
try(function()
local _ = ffi.load("msvcp140.dll")
end).catch(function(ex)
print("Failed to load msvcp140.dll")
failed_to_load = true
end)
------ TRANSLATIONS -------
dofile("mods/evaisa.mp/lib/translations.lua")
register_localizations("mods/evaisa.mp/translations.csv", 2)
---------------------------
------ Path definitions -------
package.path = package.path .. ";./mods/evaisa.mp/lib/?.lua"
package.path = package.path .. ";./mods/evaisa.mp/lib/?/init.lua"
package.cpath = package.cpath .. ";./mods/evaisa.mp/bin/?.dll"
package.cpath = package.cpath .. ";./mods/evaisa.mp/bin/?.exe"
local function load(modulename)
local errmsg = ""
for path in string.gmatch(package.path, "([^;]+)") do
local filename = string.gsub(path, "%?", modulename)
local file = io.open(filename, "rb")
if file then
-- Compile and return the module
return assert(loadstring(assert(file:read("*a")), filename))
end
errmsg = errmsg .. "\n\tno file '" .. filename .. "' (checked with custom loader)"
end
return errmsg
end
---------------------------
string.bytes = function(str)
local bytes = 0
for i = 1, #str do
bytes = bytes + str:byte(i)
end
return bytes
end
get_content = ModTextFileGetContent
set_content = ModTextFileSetContent
dofile("mods/evaisa.mp/lib/ffi_extensions.lua")
-- do not apply any callbacks or anything because this is fucked up and evil
if(not failed_to_load)then
----------------- Gui Option Jankery ----------------
local gui_option_cache = {}
local gui_option_add = GuiOptionsAdd
local gui_option_remove = GuiOptionsRemove
function GuiOptionsAdd(gui, option)
gui_option_cache[gui] = gui_option_cache[gui] or {}
gui_option_cache[gui][option] = true
gui_option_add(gui, option)
end
function GuiOptionsRemove(gui, option)
if(gui_option_cache[gui] and gui_option_cache[gui][option])then
gui_option_remove(gui, option)
gui_option_cache[gui][option] = nil
end
end
-- epic new function truly
function GuiOptionsHas(gui, option)
return gui_option_cache[gui] and gui_option_cache[gui][option]
end
function GuiOptionsList(gui)
local options = {}
if(gui_option_cache[gui])then
for k, v in pairs(gui_option_cache[gui])do
table.insert(options, k)
end
end
return options
end
local gamemode_path = nil
-- Old function, doesn't work properly if multiple installs of mod exists and i do not know how to solve this.
function GetGamemodeFilePath()
if(gamemode_path)then
return gamemode_path
end
debug_log:print("GetGamemodeFilePath")
local save_folder = os.getenv('APPDATA'):gsub("\\Roaming", "") ..
"\\LocalLow\\Nolla_Games_Noita\\save00\\mod_config.xml"
local file_path = nil
local file, err = io.open(save_folder, 'rb')
if file then
debug_log:print("Found mod_config.xml")
local content = file:read("*all")
local subscribed_items = steam.UGC.getSubscribedItems()
local item_infos = {}
for _, v in ipairs(subscribed_items) do
local success, size, folder, timestamp = steam.UGC.getItemInstallInfo(v)
if (success) then
item_infos[tostring(v)] = {size = size, folder = folder, timestamp = timestamp}
end
end
local parsedModData = nxml.parse(content)
for elem in parsedModData:each_child() do
if (elem.name == "Mod") then
local modID = elem.attr.name
local steamID = elem.attr.workshop_item_id
local infoFile = "mods/" .. modID .. "/mod.xml"
if (steamID ~= "0") then
if(item_infos[steamID])then
infoFile = item_infos[steamID].folder .. "/mod.xml"
else
debug_log:print("Failed to find item info for: " .. steamID)
infoFile = nil
end
end
if(infoFile)then
local file2, err = io.open(infoFile, 'rb')
if file2 then
local content2 = file2:read("*all")
if(content2 ~= nil and content2 ~= "")then
local parsedModInfo = nxml.parse(content2)
local is_game_mode = parsedModInfo.attr.is_game_mode == "1"
if (ModIsEnabled(modID) and is_game_mode) then
if steamID == "0" then
file_path = "mods/" .. modID
else
file_path = item_infos[steamID].folder
end
break
end
end
else
debug_log:print("Failed to open mod.xml: " .. infoFile)
debug_log:print("Error: " .. tostring(err))
end
end
end
end
file:close()
end
debug_log:print("Gamemode path: " .. tostring(file_path))
gamemode_path = file_path
return file_path
end
function GetModFilePath(mod_id, steam_id)
local file_path = nil
if(not steam_id or steam_id == "" or steam_id == "0")then
file_path = "mods/" .. mod_id
else
local subscribed_items = steam.UGC.getSubscribedItems()
local item_infos = {}
for _, v in ipairs(subscribed_items) do
local success, size, folder, timestamp = steam.UGC.getItemInstallInfo(v)
if (success) then
item_infos[tostring(v)] = {size = size, folder = folder, timestamp = timestamp}
end
end
if(item_infos[steam_id])then
file_path = item_infos[steam_id].folder
end
end
return file_path
end
if(trailer_mode)then
ModMagicNumbersFileAdd("mods/evaisa.mp/magic_numbers_trailer.xml")
end
if(ModIsEnabled("NoitaDearImGui"))then
imgui = load_imgui({mod="noita-online", version="1.20"})
implot = imgui.implot
end
local inspect = dofile("mods/evaisa.mp/lib/inspect.lua")
zstandard = require("zstd")
zstd = zstandard:new()
table.insert(package.loaders, 2, load)
logger = require("logger")("noita_online_logs")
mp_log = logger.init("noita-online.log")
networking_log = logger.init("networking.log")
debug_log = logger.init("debugging.log")
exception_log = logger.init(os.date("%Y-%m-%d_%H-%M-%S")..".log", false, nil, "noita_online_logs/exceptions")
debug_info = logger.init("debug_info.log", nil, true, nil, true)
if(not debugging)then
networking_log.enabled = false
end
--fontbuilder = dofile("mods/evaisa.mp/lib/fontbuilder.lua")
game_config = dofile("mods/evaisa.mp/lib/game_config.lua")
local function readWord(file)
local byte1, byte2 = file:read(1), file:read(1)
if not byte1 or not byte2 then
return nil
end
return byte1:byte() + byte2:byte() * 256
end
local function readDword(file)
local word1, word2 = readWord(file), readWord(file)
if not word1 or not word2 then
return nil
end
return word1 + word2 * 65536
end
local function checkLAA(filename)
local file, err = io.open(filename, "rb")
if not file then
print("Error opening file: " .. err)
return false
end
file:seek("set", 0x3C)
local peOffset = readDword(file)
file:seek("set", peOffset + 4) -- Go to IMAGE_FILE_HEADER
local characteristicsOffset = peOffset + 22 -- Offset of "Characteristics" field
file:seek("set", characteristicsOffset)
local characteristics = readWord(file)
file:close()
return bit.band(characteristics, 0x20) == 0x20 -- Properly check the IMAGE_FILE_LARGE_ADDRESS_AWARE flag
end
lobby_data_last_frame = {}
lobby_data_updated_this_frame = {}
ModRegisterAudioEventMappings("mods/evaisa.mp/GUIDs.txt")
dofile_once("mods/evaisa.mp/files/scripts/gui_utils.lua")
dofile("data/scripts/lib/coroutines.lua")
nxml = dofile("mods/evaisa.mp/lib/nxml.lua")
try(function()
require 'lua-utf8'
end).catch(function(ex)
exception_log:print(tostring(ex))
if(exceptions_in_logger)then
old_print(tostring(ex))
end
end)
pngencoder = require("pngencoder")
dofile_once("mods/evaisa.mp/bin/NoitaPatcher/load.lua")
np = require("noitapatcher")
bitser = require("bitser")
smallfolk = require("smallfolk")
binser = require("binser")
--zstandard = require("zstd")
--zstd = zstandard:new()
delay = dofile("mods/evaisa.mp/lib/delay.lua")
streaming = dofile("mods/evaisa.mp/lib/streaming.lua")
local profiler_ui = dofile("mods/evaisa.mp/lib/profiler_ui.lua")
debug_info:print("Build: " .. tostring(MP_VERSION))
rng = dofile("mods/evaisa.mp/lib/rng.lua")
rand = nil
in_game = false
Spawned = false
Starting = nil
cached_lobby_data = {}
lobby_gamemode = nil
debug_info:print("Dev mode: " .. tostring(dev_mode))
local fs = require("fs")
local sha1 = require "sha1"
function GetNoitaVersionHash()
local file = "_version_hash.txt"
local f = io.open(file, "r")
if f then
local hash = f:read("*all")
f:close()
return hash
end
return nil
end
local function sleep(ms)
-- loop for n ms
local t0 = os.clock()
while os.clock() - t0 <= ms / 1000 do
end
end
noita_version = np.GetVersionString()
if(GameIsBetaBuild())then
noita_version = noita_version .. " (beta)"
end
function GetContentHash()
local file = "data\\data.wak"
-- try to run certutil
local handle = io.popen("certutil -hashfile " .. file .. " SHA1")
if not handle then
return "Unknown"
end
local result = handle:read("*a")
handle:close()
local hash = string.match(result, "SHA1 hash of " .. file .. ":\n([%w]+)\n")
if hash then
return hash
end
-- try to run hasher.exe instead
debug_log:print("Used hasher.exe to get the data.wak hash")
local handle = io.popen("mods\\evaisa.mp\\bin\\hasher.exe \"" .. file .. "\"")
if not handle then
return "Unknown"
end
local result = handle:read("*a")
handle:close()
if not result then
return "Unknown"
end
-- remove surrounding newlines
result = result:gsub("^%s*(.-)%s*$", "%1")
return result
end
noita_version_hash = GetContentHash()
print("Noita version hash: " .. noita_version_hash)
debug_info:print("Noita hash: " .. tostring(noita_version_hash))
--[[last_noita_version = ModSettingGet("evaisa.mp.last_noita_version_hash") or ""
laa_check_done = true
if(noita_version_hash ~= nil)then
mp_log:print("Noita version hash: " .. noita_version_hash)
if(last_noita_version ~= noita_version_hash)then
ModSettingSet("evaisa.mp.last_noita_version_hash", noita_version_hash)
--laa_check_done = false
else
--laa_check_done = true
end
end]]
base64 = require("base64")
msg = require("msg")
pretty = require("pretty_print")
debug_info:print("Beta build: " .. tostring(GameIsBetaBuild()))
debug_info:print("Using controller: " .. tostring(GameGetIsGamepadConnected()))
function RepairDataFolder()
local data_folder_name = os.getenv('APPDATA'):gsub("\\Roaming", "") ..
"\\LocalLow\\Nolla_Games_Noita\\save00\\evaisa.mp_data"
-- remove the folder
os.execute('del /q "' .. data_folder_name .. '\\*.*"')
print("Repaired data folder.")
GamePrint("Repairing data folder")
end
local serialization_version = "3"
if ((ModSettingGet("last_serialization_version") or "1") ~= serialization_version) then
RepairDataFolder()
ModSettingSet("last_serialization_version", serialization_version)
end
np.InstallShootProjectileFiredCallbacks()
np.EnableGameSimulatePausing(false)
np.InstallDamageDetailsPatch()
np.SilenceLogs("Warning - streaming didn\'t find any chunks it could stream away...\n")
--[[np.EnableExtendedLogging(true)
np.EnableLogFiltering(true)
function FilterLog(source, function_name, line, ...)
debug_log:print(source .. " " .. function_name .. " " .. line .. " " .. table.concat({...}, " "))
return false
end]]
np.EnableLogFiltering(true)
function FilterLog(source, function_name, line, ...)
debug_log:print(source .. " " .. function_name .. " " .. line .. " " .. table.concat({...}, " "))
-- if contains "Lua error" or "Stack traceback"
if (string.find(table.concat({...}, " "), "Lua error") or string.find(table.concat({...}, " "), "Stack traceback")) then
exception_log:print(source .. " " .. function_name .. " " .. line .. " " .. table.concat({...}, " "))
return true
end
return false
end
--GameSDK = require("game_sdk")
steam = require("luasteam")
--GameSDK = nil
--discord_sdk = nil
--require("physics")
steamutils = dofile_once("mods/evaisa.mp/lib/steamutils.lua")
clear_avatar_cache()
json = dofile_once("mods/evaisa.mp/lib/json.lua")
pretty = require("pretty_print")
local is_invalid_version = (PhysicsBodyIDGetBodyAABB == nil)
--GamePrint("Making api call")
dofile("mods/evaisa.mp/files/scripts/debugging.lua")
dofile("mods/evaisa.mp/lib/character_support.lua")
local old_print = print
print = function(...)
if not disable_print then
local content = ...
local source = debug.getinfo(2).source
local line = debug.getinfo(2).currentline
old_print(table.concat({"[" .. source .. ":" .. tostring(line) .. "]", ... }, " "))
end
end
function OnPausedChanged(paused, is_wand_pickup)
local players = EntityGetWithTag("player_unit") or {}
if(not is_wand_pickup)then
if(imgui)then
profiler_ui.apply_profiler_rate()
end
end
if (players[1]) then
np.RegisterPlayerEntityId(players[1])
local inventory_gui = EntityGetFirstComponentIncludingDisabled(players[1], "InventoryGuiComponent")
local controls_component = EntityGetFirstComponentIncludingDisabled(players[1], "ControlsComponent")
if (paused) then
--EntitySetComponentIsEnabled(players[1], inventory_gui, false)
np.EnableInventoryGuiUpdate(false)
np.EnablePlayerItemPickUpper(false)
ComponentSetValue2(controls_component, "enabled", false)
else
--EntitySetComponentIsEnabled(players[1], inventory_gui, true)
np.EnableInventoryGuiUpdate(true)
np.EnablePlayerItemPickUpper(true)
ComponentSetValue2(controls_component, "enabled", true)
end
end
if (paused) then
GameAddFlagRun("game_paused")
--GamePrint("paused")
else
GameRemoveFlagRun("game_paused")
--GamePrint("unpaused")
end
end
function IsPaused()
return steam_overlay_open or GameHasFlagRun("game_paused")
end
if type(Steam) == 'boolean' then Steam = nil end
activity = activity or nil
game_in_progress = false
gamemode_settings = gamemode_settings or {}
dofile("mods/evaisa.mp/files/scripts/lobby_handler.lua")
dofile_once("mods/evaisa.mp/files/scripts/utils.lua")
dofile_once("data/scripts/lib/utilities.lua")
input = nil
bindings = nil
bytes_sent = 0
last_bytes_sent = 0
bytes_received = 0
last_bytes_received = 0
bytes_sent_per_type = {}
bytes_received_per_type = {}
active_members = {}
member_message_frames = {}
gamemode_index = 1
gamemodes = {}
function FindGamemode(id)
for k, v in pairs(gamemodes) do
if (v.id == id) then
return v, k
end
end
return nil
end
function TryHandleMessage(lobby_code, event, message, user, ignore)
try(function()
if (lobby_gamemode ~= nil) then
local owner = steam.matchmaking.getLobbyOwner(lobby_code)
local from_owner = user == owner
if (from_owner and event == "start" or event == "restart") then
print("Starting game")
if(lobby_gamemode.apply_start_data)then
lobby_gamemode.apply_start_data(lobby_code, message)
end
if(event == "restart")then
StopGame()
end
if(owner == steam_utils.getSteamID())then
Starting = 5
else
Starting = 30
end
elseif (from_owner and event == "refresh") then
print("Refreshing lobby data")
if handleVersionCheck() and handleModCheck() then
if handleGamemodeVersionCheck(lobby_code) then
if (lobby_gamemode) then
--game_in_progress = false
--print("Refreshing lobby data in 30 frames")
delay.new(30, function()
for k, setting in ipairs(lobby_gamemode.settings or {}) do
gamemode_settings[setting.id] = steam.matchmaking.getLobbyData(lobby_code, "setting_" ..
setting.id)
end
if (lobby_gamemode.refresh) then
lobby_gamemode.refresh(lobby_code)
end
end, function(frames) end)
else
disconnect({
lobbyID = lobby_code,
message = string.format(GameTextGetTranslatedOrNot("$mp_gamemode_missing"), tostring(lobby_gamemode.id))--"Gamemode missing: " .. tostring(lobby_gamemode.id)
})
end
end
end
elseif (owner == steam_utils.getSteamID() and event == "spectate") then
print("Toggling spectator for " .. tostring(steamutils.getTranslatedPersonaName(user)))
local spectating = steamutils.IsSpectator(lobby_code, user)
steam_utils.TrySetLobbyData(lobby_code, tostring(user) .. "_spectator", spectating and "false" or "true")
end
--print("ignore? "..tostring(ignore))
if (lobby_gamemode.received and not ignore) then
lobby_gamemode.received(lobby_code, event, message, user)
end
end
end).catch(function(ex)
exception_log:print(tostring(ex))
if(exceptions_in_logger)then
old_print(tostring(ex))
end
end)
end
function HandleMessage(v, ignore)
if(is_awaiting_spectate)then
return
end
local data = steamutils.parseData(v.data)
bytes_received = bytes_received + v.msg_size
if (lobby_gamemode == nil) then
return
end
-- old api
if (lobby_gamemode.message and not ignore) then
lobby_gamemode.message(lobby_code, data, v.user)
end
if (data[1] and type(data[1]) == "string") then
if(bytes_received_per_type[data[1]] == nil)then
bytes_received_per_type[data[1]] = 0
end
bytes_received_per_type[data[1]] = bytes_received_per_type[data[1]] + v.msg_size
local event = data[1]
local message = data[2]
local frame = data[3]
if (data[3]) then
if (not member_message_frames[tostring(v.user)] or member_message_frames[tostring(v.user)] <= frame) then
member_message_frames[tostring(v.user)] = frame
TryHandleMessage(lobby_code, event, message, v.user, ignore)
end
else
TryHandleMessage(lobby_code, event, message, v.user, ignore)
end
else
print("Invalid message: "..tostring(data))
print(inspect(data))
end
end
local function ReceiveMessages(ignore)
-- 10 available channels should be enough
--for i = 0, 10 do
--print("Polling messages on channel " .. tostring(i))
if(is_awaiting_spectate)then
return
end
local messages = steam.networking.pollMessages(0) or {}
if(#messages > 0)then
--print("Received " .. tostring(#messages) .. " messages")
for k, v in ipairs(messages) do
HandleMessage(v, ignore)
end
end
--end
end
----- debugging spell stuff ------
--ModTextFileSetContent("mods/gun_flag.lua", [[
--for i, action in ipairs(actions)do
-- if(i > 4)then
-- action.spawn_requires_flag = action.id
-- end
--end
--]])
--ModLuaFileAppend("data/scripts/gun/gun_actions.lua", "mods/gun_flag.lua")
----------------------------------
local spawned_popup = false
local init_cleanup = false
local connection_popup_open = false
local connection_popup_was_open_timer = 0
local laa_check_busy = false
local invalid_version_popup_open = false
function OnWorldPreUpdate()
try(function()
if(GameHasFlagRun("mp_blocked_load"))then
return
end
-- this code handles unpausing the mod after closing steam overlay
--[[if(steam_overlay_closed and GameGetFrameNum() > steam_overlay_closed_frame + 60)then
steam_overlay_closed = false
steam_overlay_open = false
end]]
if(imgui)then
profiler_ui.pre_update()
else
if (input ~= nil and input:WasKeyPressed("f8")) then
GamePrint("Cannot use profiler without dear imgui installed.")
end
end
--input:Update()
wake_up_waiting_threads(1)
--math.randomseed( os.time() )
if (not IsPaused()) then
popup.update()
end
if (not failed_to_load) and steam and GameGetFrameNum() >= 60 then
--[[if(not laa_check_done)then
laa_enabled = checkLAA("noita.exe")
print("LAA: " .. tostring(laa_enabled))
if(not laa_enabled)then
laa_check_busy = true
popup.create("laa_message", GameTextGetTranslatedOrNot("$mp_laa_message"), {
GameTextGetTranslatedOrNot("$mp_laa_description"),
{
text = GameTextGetTranslatedOrNot("$mp_laa_warning"),
color = {217 / 255,52 / 255,52 / 255, 1}
}
}, {
{
text = GameTextGetTranslatedOrNot("$mp_laa_patch"),
callback = function()
LAAPatch("noita.exe", "noita")
laa_check_busy = false
end
},
{
text = GameTextGetTranslatedOrNot("$mp_close_popup"),
callback = function()
laa_check_busy = false
end
},
}, -6000)
end
laa_check_done = true
end]]
if(is_invalid_version)then
if(not invalid_version_popup_open)then
invalid_version_popup_open = true
popup.create("invalid_version_message", GameTextGetTranslatedOrNot("$mp_invalid_version"),
GameTextGetTranslatedOrNot("$mp_invalid_version_description"), {
{
text = GameTextGetTranslatedOrNot("$mp_close_popup"),
callback = function()
invalid_version_popup_open = false
end
}
}, -6000)
end
return
end
if(not laa_check_busy)then
if(not steam.user.loggedOn())then
if(GameGetFrameNum() % (300) == 0)then
GamePrint("Failed to connect to steam servers, are you logged into steam friends list?")
end
if(connection_popup_was_open_timer > 0)then
connection_popup_was_open_timer = connection_popup_was_open_timer - 1
end
if(not connection_popup_open and connection_popup_was_open_timer <= 0)then
connection_popup_open = true
connection_popup_was_open_timer = 60 * 60 * 2
popup.create("connection_message", GameTextGetTranslatedOrNot("$mp_steam_connection_failed_title"),
GameTextGetTranslatedOrNot("$mp_steam_connection_failed_description"), {
{
text = GameTextGetTranslatedOrNot("$mp_close_popup"),
callback = function()
if(lobby_code ~= nil)then
connection_popup_open = false
end
end
}
}, -6000)
end
end
--[[if(GameSDK ~= nil and discord_sdk ~= nil)then
GameSDK.runCallbacks(discord_sdk.corePtr)
end]]
if(input == nil)then
input = dofile_once("mods/evaisa.mp/lib/input.lua")
end
if(bindings == nil)then
bindings = dofile_once("mods/evaisa.mp/lib/keybinds.lua")
-- keyboards bindings
bindings:RegisterBinding("chat_submit", "Noita Online [keyboard]", "Chat Send", "Key_RETURN", "key", false, true, false, false)
bindings:RegisterBinding("chat_submit2", "Noita Online [keyboard]", "Chat Send Alt", "Key_KP_ENTER", "key", false, true, false, false)
bindings:RegisterBinding("chat_open_kb", "Noita Online [keyboard]", "Open Chat", "", "key", false, true, false, false)
bindings:RegisterBinding("lobby_menu_open_kb", "Noita Online [keyboard]", "Open Lobby Menu", "", "key", false, true, false, false)
-- gamepad bindings
bindings:RegisterBinding("chat_submit_gp", "Noita Online [gamepad]", "Chat Send", "", "button", false, false, true, false, true)
bindings:RegisterBinding("chat_open_gp", "Noita Online [gamepad]", "Open Chat", "", "button", false, false, true, false, true)
bindings:RegisterBinding("lobby_menu_open_gp", "Noita Online [gamepad]", "Open Lobby Menu", "", "button", false, false, true, false, true)
-- loop through gamemodes
for k, v in ipairs(gamemodes) do
if(v.binding_register ~= nil)then
v.binding_register(bindings)
end
end
end
if(init_cleanup == false)then
local lastCode = ModSettingGet("last_lobby_code")
--print("Code: "..tostring(lastCode))
if (steam) then
if (lastCode ~= nil and lastCode ~= "") then
local lobCode = steam.extra.parseUint64(lastCode)
if (tostring(lobCode) ~= "0") then
if (steam.extra.isSteamIDValid(lobCode)) then
gamemode_settings = {}
steam_utils.Leave(lobCode)
end
end
ModSettingRemove("last_lobby_code")
lobby_code = nil
end
end
init_cleanup = true
end
--pretty.table(steam.networking)
lobby_code = lobby_code or nil
ResetIDs()
ResetWindowStack()
--print(fs.cd())
dofile("mods/evaisa.mp/files/scripts/lobby_ui.lua")
dofile("mods/evaisa.mp/files/scripts/chat_ui.lua")
if (GameGetFrameNum() % (600) == 0) then
steamutils.CheckLocalLobbyData()
end
if (lobby_code ~= nil) then
if (lobby_gamemode == nil) then
return
end
delay.update()
if(Starting ~= nil)then
Starting = Starting - 1
if(Starting < 0)then
Starting = 0
end
end
if(Starting == 0)then
StartGame()
Starting = nil
end
--game_in_progress = steam.matchmaking.getLobbyData(lobby_code, "in_progress") == "true"
--print("a")
--print("b")
if (GameGetFrameNum() % Random(59,61) == 0) then
steam_utils.updateCacheSpectators(lobby_code)
last_bytes_sent = bytes_sent
last_bytes_received = bytes_received
bytes_sent = 0
bytes_received = 0
local function format_bytes(bytes)
return bytes < 1024 and tostring(bytes) .. " B/s" or tostring(math.floor(bytes / 1024)) .. " KB/s"
end
local output_string = last_bytes_sent < 1024 and tostring(last_bytes_sent) .. " B/s" or tostring(math.floor(last_bytes_sent / 1024)) .. " KB/s"
local input_string = last_bytes_received < 1024 and tostring(last_bytes_received) .. " B/s" or tostring(math.floor(last_bytes_received / 1024)) .. " KB/s"
local network_string = "Data throughput: ".."in: " .. input_string .. " | out: " .. output_string
for k, v in pairs(bytes_sent_per_type) do
if(bytes_received_per_type[k] == nil)then
bytes_received_per_type[k] = 0
end
local sent = v
local received = bytes_received_per_type[k]
network_string = network_string .. "\n["..k.."]: out: "..format_bytes(sent).." | in: "..format_bytes(received)
end
bytes_sent_per_type = {}
bytes_received_per_type = {}
networking_log:print(network_string.."\n")