segabl / pd2-useful-bots

A lightweight bot overhaul
GNU General Public License v3.0
7 stars 5 forks source link

Possible Compatibility Issue - coplogicattack.lua crash #14

Closed ghost closed 1 year ago

ghost commented 1 year ago

As Useful Bots doesn't have a coplogicattack.lua, and I haven't encountered this crash before installing the upcoming version, I'm assuming it's a compatibility issue if it's not a base game crash. Only two mods I have contain this lua file, that being Deadlocke and The Fixes. I've been using Deadlocke again (the version from 24.11.20) for 10 days now, and The Fixes for exactly 13 months on this install.

Video of crash: https://youtu.be/cZ_OBHRDlX0

Crash log:

----------------------------------------------------------------------

Sat Jan 14 23:53:36 2023

Application has crashed: C++ exception
[string "lib/units/enemies/cop/logics/coplogicattack.lua"]:1193: attempt to call field 'chk_should_turn' (a nil value)

SCRIPT STACK

clbk() lib/units/player_team/logics/teamailogictravel.lua:233
_execute_queued_task() lib/managers/enemymanager.lua:600
_update_queued_tasks() lib/managers/enemymanager.lua:615
update() lib/managers/enemymanager.lua:52
update() lib/setups/gamesetup.lua:809
update() lib/setups/networkgamesetup.lua:21
original() core/lib/setups/coresetup.lua:559
@mods/base/req/core/Hooks.lua:288

-------------------------------

Callstack:

         payday2_win32_release  (???)     ???                                                 
         payday2_win32_release  (???)     ???                                                 
         payday2_win32_release  (???)     ???                                                 
         payday2_win32_release  (???)     zip_get_name                                        
                         ntdll  (???)     RtlDosSearchPath_Ustr                               
                         ntdll  (???)     RtlRestoreLastWin32Error                            
                         ntdll  (???)     ZwQueryVirtualMemory                                
                    KERNELBASE  (???)     VirtualQueryEx                                      
                    KERNELBASE  (???)     SetUnhandledExceptionFilter                         
                    KERNELBASE  (???)     SetUnhandledExceptionFilter                         
         payday2_win32_release  (???)     ???                                                 
         payday2_win32_release  (???)     zip_get_name                                        

-------------------------------

Current thread: Main

-------------------------------

System information:
    Application version : 1.134.167
    CPU : 12th Gen Intel(R) Core(TM) i7-12700K (10 cores); SSE; SSE2; SSE3; SSSE3; SSE4.1; SSE4.2
    DirectX : 12.0 
    GPU : NVIDIA GeForce RTX 3070 Ti / nvldumd.dll[31.0.15.2802]
    Language : english
    Memory :     32538MB 116KB
    OS : 6.2.9200 () 0x300-0x1 (64 bits)
    Physics : threaded
    Renderer : DX9 threaded
    Sound : Razer Inc. (Headphones (Razer Nari - Game))

Possible conflicting code:

Deadlocke

local _CopLogicAttack_update = CopLogicAttack.update
function CopLogicAttack.update(data)
    _CopLogicAttack_update(data)
    DeadLocke:inform_law_enforcements(data) 
end

The Fixes

TheFixesPreventer = TheFixesPreventer or {}
if not TheFixesPreventer.crash_upd_aim_coplogicattack then
    -- coplogicattack.lua:1080: attempt to index 'weapon_range' (a nil value)
    local origfunc =  CopLogicAttack._upd_aim
    function CopLogicAttack._upd_aim(data, my_data, ...)
        if data.attention_obj
            and AIAttentionObject.REACT_AIM <= data.attention_obj.reaction
            and (data.attention_obj.verified or data.attention_obj.nearly_visible)
            and not (my_data and my_data.weapon_range)
        then
            return
        end

        return origfunc(data, my_data, ...)
    end
end

if not TheFixesPreventer.crash_aim_allow_fire_coplogicattack then
    -- coplogicattack.lua:1259: attempt to index field 'chatter' (a nil value)
    local aim_allow_fire_orig = CopLogicAttack.aim_allow_fire
    function CopLogicAttack.aim_allow_fire(shoot, aim, data, ...)
        if shoot then
            data.char_tweak.chatter = data.char_tweak.chatter or {}
        end
        return aim_allow_fire_orig(shoot, aim, data, ...)
    end
end
segabl commented 1 year ago

I've been using The Fixes for ages and haven't encountered this, and Deadlocke doesn't really do anything weird here. If anything I suspect it's caused by something in teamailogictravel but not sure.

ghost commented 1 year ago

Well, if it ever comes up again, I'll send it here. It does seem to be an extremely rare one. I also don't have any mods besides Useful Bots that modify teamailogictravel.lua if that's of any help.

segabl commented 1 year ago

I can include a fix for this anyways since it's just a line of code (that should be there in vanilla to begin with) These might be rare cases of bots being forced to update their enemy detection due to tasers/cloakers while being in a logic that's missing some of the functions that are used in there.

segabl commented 1 year ago

Fix for this specific crash has been included in the latest version