smilz0 / Left4Bots

Improvements for the L4D2 survivor bots
https://steamcommunity.com/sharedfiles/filedetails/?id=3022416274
34 stars 4 forks source link

[fix] Hooks not work sometimes after last update #96

Open 4512369781 opened 3 months ago

4512369781 commented 3 months ago

I suggested moving the loading method to director_base_addon.nut before, but it still has some bugs to work out. After the update people reported not being able to use chat commands after map transition, and I never had that issue. but I found out what the problem was though.

Scriptedmode.nut After enable script mode, there is a "ScriptMode_OnActivate" function that will be executed before the game starts. set hooks before this will work. When the map is first loaded, the "round_start" event will be triggered before the "OnActivate" function, so everything works great. However, when the map restarted or transitioned, the "round_start" event will be later than the "OnActivate" function, and set hooks will not work at this time.

Normally, Left4Bots should be loaded before Left4Lib, so "HooksHub.Init()" will be executed twice before the "round_start" event. But the people who had the problem for some reason had Left4Lib loaded before Left4Bots, and HooksHub.Init() was only executed once, thus causing hooks not work when the map was restarted or transitioned.

There are two solutions:

  1. Delete director_base_addon.nut from Left4Lib, add HooksHub.Init() after IncludeScript("left4bots") to ensure it is executed twice.
  2. Or modify the "ScriptMode_OnActivate" function just like what we did for "ScriptMode_Init". Left4Lib_fix_hook.zip
smilz0 commented 3 months ago

How do you reproduce the issue? I've never had this issue with L4B2, no matter what.

4512369781 commented 3 months ago

So am I, also never had this problem either l4b1 or l4b2. but my mod had this problem before, it took me a lot of time to figure out.

according to report, I thought it might be the same bug, so I manually make HooksHub.Init() only run once when director_base_addon.nut loading. The first map works well, and after transition to next, chat commands not work.

smilz0 commented 3 months ago

director_base_addon is called 2 times per map so, even if for some reason L4L is called before L4B, the second time HooksHub is surely loaded and HooksHub.Init will run. Plus it's called again in the round_start event which, in my logs, it's always called after everything else. Most reports were for L4B1 which had a vscript error on a Log line into its director_base_addon.nut, the error prevented the hooks to init correctly after a map transition/restart but after commenting the log line there error is gone and now it's always working like L4B2 (at least for me). We'll see if other people still report the problem or not.

4512369781 commented 3 months ago

after map transition or round restart, every hooks change not applied because round_start event fired too late. there is a test way: only call HooksHub.Init() in round_startevent twice, if the map is first load, hooks should be work. then transition to next level, and hooks will break, also chat command.

Infact, even has that "Log line error", l4b1 still work fine for me, I really don't know why the loading sort is reversed.

smilz0 commented 3 months ago

Ok got it. Sounds like a typical case of "not worth bother, better rollback" to me. Well... RIP Dark Messiah.

4512369781 commented 3 months ago

That's a good way too. RIP Dark Messiah.

RB490 commented 3 months ago

Yay! Appreciate the rollback, i was having this issue since the recent updates a few days back. Looking forward to it

smilz0 commented 3 months ago

After seeing how to replicate the issue i realized that the fix was easier than rolling back the change to all my addons, so here we go: https://github.com/smilz0/Left4Lib/commit/7c4044abb087ea13a0710421fc94506a0ccff74f Hopefully it works for everyone this time. Let me know.

RB490 commented 3 months ago

After seeing how to replicate the issue i realized that the fix was easier than rolling back the change to all my addons, so here we go: smilz0/Left4Lib@7c4044a Hopefully it works for everyone this time. Let me know.

It's working again :-)

noahsamaX commented 3 months ago

I tested the parish. In chapter 1, bots warp worked correctly but in chapter 2, it didn't work correctly at all. Here is console log. console log.txt

smilz0 commented 3 months ago

@LilLovebird @noahsamaX it's likely another vscript addon overwriting the hooks. Can you disable all the vscript addons (excluding l4b1/2 and l4l) and enable one by one to find which ones are doing it?

4512369781 commented 3 months ago

@LilLovebird @noahsamaX it's likely another vscript addon overwriting the hooks. Can you disable all the vscript addons (excluding l4b1/2 and l4l) and enable one by one to find which ones are doing it?

with @LilLovebird 's log, he only use left 4 lib and left 4 bots 2, I can't find any error in the log. Basically it same as my log, not sure why this doesn't work.

4512369781 commented 3 months ago

@LilLovebird @noahsamaX try this test version, unzip to "\Left 4 Dead 2\left4dead2\addons\workshop\" folder, bakcup the same name file first. left4lib_tryfix.zip

If it still doesn't work, so... rollback.

noahsamaX commented 3 months ago

@LilLovebird @noahsamaX try this test version, unzip to "\Left 4 Dead 2\left4dead2\addons\workshop" folder, bakcup the same name file first. left4lib_tryfix.zip

If it still doesn't work, so... rollback.

In my game, it seems that test fix version works correctly. I was able to use bots warp after transition (I tested The Parish) without any turning off other addons.

4512369781 commented 3 months ago

@LilLovebird So before this update, everything was working fine, right?

@noahsamaX Good news.

4512369781 commented 3 months ago

@LilLovebird I tested your launch options, it does not cause problem for me. Try this two fix:

Tell me which one works.

smilz0 commented 3 months ago

@LilLovebird get the console log when you use the commands and post it here pls.

4512369781 commented 3 months ago

@4512369781 At this point I feel like it's just my L4D2 that's the issue, neither of those work

Are you using the sourcemod plugins? If so, try disabling it, also verify integrity of game files.

smilz0 commented 3 months ago

@LilLovebird i think i found the problem. Apperently there is a bug that only happens when you play in single player mode and you are not yet in the admins.txt file. I will fix it, in the meantime you can solve by starting a local host lobby (even private), that will add you to the admins.txt file and you will notice that the commands work. After loading the map you can even quit and start single player, that should work too.

smilz0 commented 3 months ago

@smilz0 There was some progress. I started a Play with Friends server hosted locally and I did get a response to the commands, but the bots didn't do anything. ` [L4L][DEBUG] HooksHub.InterceptChat - speaker: LilLovebird #FixTF2 - text: ellis lead

[L4L][DEBUG] HooksHub.InterceptChat - ret: true

LilLovebird #FixTF2 : ellis lead ` Edit: After leaving that server and starting Singleplayer like I was doing before, I got a message in chat saying I joined as an admin and everything works as intended.

Yep, in fact the bug wasn't restricted to singleplayer but it affected the first round of multiplayer too. Btw i think i fixed it, if you want to try it before i release it on workshop you can download this version: https://github.com/smilz0/Left4Lib/blob/main/out/Left4Lib.vpk

@4512369781 i also made a little change to the loading method. I moved the init back into director_base_addon but this time it will run only once in the second run waiting for other addons (like vslib) to set their hooks. Most addons won't overwrite the hooks if they already set so the loading order doesn't matter. In the case that you have an addon that does overwrite the hooks in the second run you just need to move it before L4L into addonlist.txt and everything should work. Let me know what you think.

4512369781 commented 3 months ago

Yep, in fact the bug wasn't restricted to singleplayer but it affected the first round of multiplayer too. Btw i think i fixed it, if you want to try it before i release it on workshop you can download this version:

that's why I does not has this problem, I always use "map xx" to test mod.

@4512369781 i also made a little change to the loading method. I moved the init back into director_base_addon but this time it will run only once in the second run waiting for other addons (like vslib) to set their hooks. Most addons won't overwrite the hooks if they already set so the loading order doesn't matter. In the case that you have an addon that does overwrite the hooks in the second run you just need to move it before L4L into addonlist.txt and everything should work. Let me know what you think.

yeah, this way seems like the old one, but more stable, it works pretty.

4512369781 commented 3 months ago

@smilz0 find one issue, should reset SecondRun to false after set hooks, otherwise if the round restart, "HooksHub.Init()" will run twice.

smilz0 commented 2 months ago

@smilz0 find one issue, should reset SecondRun to false after set hooks, otherwise if the round restart, "HooksHub.Init()" will run twice.

Done. I also added a check 5 seconds after round_start to see if hooks are ok.