Batfoxkid / Freak-Fortress-2-Rewrite

The gamemode that's now also a standalone boss maker.
https://forums.alliedmods.net/forumdisplay.php?f=154
GNU General Public License v3.0
17 stars 7 forks source link

[Bug] Fixing invalid handle error #199

Closed naydef closed 1 month ago

naydef commented 4 months ago

Basically if you make a boss call rage_cloneattack on itself (aka he gets converted to a boss from his own config), then FF2 will generate invalid handle error like this one:

L 04/22/2024 - 20:39:10: [SM] Exception reported: Invalid Handle 6e2023fb (error 3)
L 04/22/2024 - 20:39:10: [SM] Blaming: freak_fortress_2.smx
L 04/22/2024 - 20:39:10: [SM] Call stack trace:
L 04/22/2024 - 20:39:10: [SM]   [0] StringMap.Snapshot
L 04/22/2024 - 20:39:10: [SM]   [1] Line 879, /home/ndf/NecGaming/addons/sourcemod/scripting/include/cfgmap.inc::CloneConfigMap
L 04/22/2024 - 20:39:10: [SM]   [2] Line 516, /home/ndf/NecGaming/addons/sourcemod/scripting/include/cfgmap.inc::ConfigMap.Clone
L 04/22/2024 - 20:39:10: [SM]   [3] Line 1596, freak_fortress_2/bosses.sp::Bosses_CreateFromConfig
L 04/22/2024 - 20:39:10: [SM]   [4] Line 137, freak_fortress_2/natives.sp::Native_CreateBoss
L 04/22/2024 - 20:39:10: [SM]   [6] FF2R_CreateBoss
L 04/22/2024 - 20:39:10: [SM]   [7] Line 2702, freaks_new/ff2r_default_abilities.sp::SpawnCloneList
L 04/22/2024 - 20:39:10: [SM]   [8] Line 2597, freaks_new/ff2r_default_abilities.sp::Rage_CloneAttack
L 04/22/2024 - 20:39:10: [SM]   [9] Line 1496, freaks_new/ff2r_default_abilities.sp::FF2R_OnAbility
L 04/22/2024 - 20:39:10: [SM]   [11] Call_Finish
L 04/22/2024 - 20:39:10: [SM]   [12] Line 133, freak_fortress_2/forwards.sp::Forward_OnAbility
L 04/22/2024 - 20:39:10: [SM]   [13] Line 2591, freak_fortress_2/bosses.sp::UseAbility
L 04/22/2024 - 20:39:10: [SM]   [14] Line 2433, freak_fortress_2/bosses.sp::Bosses_UseSlot
L 04/22/2024 - 20:39:10: [SM]   [15] Line 117, freak_fortress_2/natives.sp::Native_DoBossSlot
L 04/22/2024 - 20:39:10: [SM]   [17] FF2R_DoBossSlot
L 04/22/2024 - 20:39:10: [SM]   [18] Line 235, freaks_new/ff2r_basics.sp::FF2R_OnAbility
L 04/22/2024 - 20:39:10: [SM]   [20] Call_Finish
L 04/22/2024 - 20:39:10: [SM]   [21] Line 115, freak_fortress_2/forwards.sp::Forward_OnAbility
L 04/22/2024 - 20:39:10: [SM]   [22] Line 2591, freak_fortress_2/bosses.sp::UseAbility
L 04/22/2024 - 20:39:10: [SM]   [23] Line 2429, freak_fortress_2/bosses.sp::Bosses_UseSlot
L 04/22/2024 - 20:39:10: [SM]   [24] Line 117, freak_fortress_2/natives.sp::Native_DoBossSlot
L 04/22/2024 - 20:39:10: [SM]   [26] FF2R_DoBossSlot
L 04/22/2024 - 20:39:10: [SM]   [27] Line 392, characters_new/david.sp::DDE_PlayerHurt
L 04/22/2024 - 20:39:10: [SM]   [28] Line 1164, optional/ffbat_nec_abilities.sp::OnPlayerHurt

Fix being in Bosses_CreateFromConfig:

+   ConfigMap cloneCg = cfg.Clone(ThisPlugin);

    if(Client(client).Cfg)
    {
        Forward_OnBossRemoved(client);
        DeleteCfg(Client(client).Cfg);
        Client(client).Cfg = null;
    }

    EnableSubplugins();

-   Client(client).Cfg = cfg.Clone(ThisPlugin);
+   Client(client).Cfg = cloneCg;

And yea, too lazy to keep my official FF2R fork updated with nec changes as well as doing PRs...

naydef commented 3 months ago

Instead of doing the changes above, I guess FF2R_MakeBoss should throw an error if it gets called for the caller boss inside FF2R_OnAbility. Basically this should throw meaningful error:

public void FF2R_OnAbility(int client, const char[] ability, AbilityData cfg)
{
    if(StrEqual(ability, "some_name"))
    {
        FF2R_MakeBoss(client, some_boss_cfg, 3);
    }
}