From f6de48315a500714cc314a2c076e6cb8516d1f9d Mon Sep 17 00:00:00 2001 From: d3m37r4 Date: Sun, 3 Dec 2023 16:50:04 +0700 Subject: [PATCH 1/2] Fix crash. Refactoring. Optimizations for current version of ReGameDLL. --- .../addons/amxmodx/scripting/include/regg.inc | 2 +- .../addons/amxmodx/scripting/regg/config.inl | 74 ++++++++++++++++++- .../amxmodx/scripting/regg/functions.inl | 65 +++++++++------- .../addons/amxmodx/scripting/regg/hooks.inl | 65 ++++++++-------- .../addons/amxmodx/scripting/regg_core.sma | 1 + .../amxmodx/scripting/regg_informer.sma | 1 + 6 files changed, 146 insertions(+), 62 deletions(-) diff --git a/cstrike/addons/amxmodx/scripting/include/regg.inc b/cstrike/addons/amxmodx/scripting/include/regg.inc index 3313075..78155ae 100644 --- a/cstrike/addons/amxmodx/scripting/include/regg.inc +++ b/cstrike/addons/amxmodx/scripting/include/regg.inc @@ -21,7 +21,7 @@ #define REGG_MAJOR_VERSION 0 #define REGG_MINOR_VERSION 3 -#define REGG_MAINTENANCE_VERSION 32 +#define REGG_MAINTENANCE_VERSION 34 #define REGG_VERSION str_to_num(fmt("%d%d%d", REGG_MAJOR_VERSION, REGG_MINOR_VERSION, REGG_MAINTENANCE_VERSION)) #define REGG_VERSION_STR fmt("%d.%d.%d-alpha", REGG_MAJOR_VERSION, REGG_MINOR_VERSION, REGG_MAINTENANCE_VERSION) diff --git a/cstrike/addons/amxmodx/scripting/regg/config.inl b/cstrike/addons/amxmodx/scripting/regg/config.inl index d2b0c28..0afd019 100644 --- a/cstrike/addons/amxmodx/scripting/regg/config.inl +++ b/cstrike/addons/amxmodx/scripting/regg/config.inl @@ -35,9 +35,18 @@ enum _:game_cvars_s { GCFriendlyFire, GCGivePlayerC4, GCWeaponsAllowMapPlaced, + GCFreeArmor, + GCTDefaultGrenades[32], + GCTGivePlayerKnife, + GCTDefaultWeaponsSecondary[32], + GCTDefaultWeaponsPrimary[32], + GCCTDefaultGrenades[32], + GCCTGivePlayerKnife, + GCCTDefaultWeaponsSecondary[32], + GCCTDefaultWeaponsPrimary[32], Float:GCBuyTime, GCItemStaytime, -} +}; new config_section_s:CfgSection = CfgSectionNone; new Config[config_s]; @@ -137,6 +146,42 @@ changeGameCvars() { GameCvars[GCWeaponsAllowMapPlaced] = get_pcvar_num(pcvar); set_pcvar_num(pcvar, 0); + pcvar = get_cvar_pointer("mp_t_default_grenades"); + get_pcvar_string(pcvar, GameCvars[GCTDefaultGrenades], charsmax(GameCvars[GCTDefaultGrenades])); + set_pcvar_string(pcvar, ""); + + pcvar = get_cvar_pointer("mp_t_give_player_knife"); + GameCvars[GCTGivePlayerKnife] = get_pcvar_num(pcvar); + set_pcvar_num(pcvar, 1); + + pcvar = get_cvar_pointer("mp_t_default_weapons_secondary"); + get_pcvar_string(pcvar, GameCvars[GCTDefaultWeaponsSecondary], charsmax(GameCvars[GCTDefaultWeaponsSecondary])); + set_pcvar_string(pcvar, ""); + + pcvar = get_cvar_pointer("mp_t_default_weapons_primary"); + get_pcvar_string(pcvar, GameCvars[GCTDefaultWeaponsPrimary], charsmax(GameCvars[GCTDefaultWeaponsPrimary])); + set_pcvar_string(pcvar, ""); + + pcvar = get_cvar_pointer("mp_ct_default_grenades"); + get_pcvar_string(pcvar, GameCvars[GCCTDefaultGrenades], charsmax(GameCvars[GCCTDefaultGrenades])); + set_pcvar_string(pcvar, ""); + + pcvar = get_cvar_pointer("mp_ct_give_player_knife"); + GameCvars[GCCTGivePlayerKnife] = get_pcvar_num(pcvar); + set_pcvar_num(pcvar, 1); + + pcvar = get_cvar_pointer("mp_ct_default_weapons_secondary"); + get_pcvar_string(pcvar, GameCvars[GCCTDefaultWeaponsSecondary], charsmax(GameCvars[GCCTDefaultWeaponsSecondary])); + set_pcvar_string(pcvar, ""); + + pcvar = get_cvar_pointer("mp_ct_default_weapons_primary"); + get_pcvar_string(pcvar, GameCvars[GCCTDefaultWeaponsPrimary], charsmax(GameCvars[GCCTDefaultWeaponsPrimary])); + set_pcvar_string(pcvar, ""); + + pcvar = get_cvar_pointer("mp_free_armor"); + GameCvars[GCFreeArmor] = get_pcvar_num(pcvar); + set_pcvar_num(pcvar, Config[CfgFreeArmor]); + pcvar = get_cvar_pointer("mp_buytime"); GameCvars[GCBuyTime] = get_pcvar_float(pcvar); set_pcvar_float(pcvar, 0.0); @@ -183,6 +228,33 @@ restoreGameCvars() { pcvar = get_cvar_pointer("mp_weapons_allow_map_placed"); set_pcvar_num(pcvar, GameCvars[GCWeaponsAllowMapPlaced]); + pcvar = get_cvar_pointer("mp_t_default_grenades"); + set_pcvar_string(pcvar, GameCvars[GCTDefaultGrenades]); + + pcvar = get_cvar_pointer("mp_t_give_player_knife"); + set_pcvar_num(pcvar, GameCvars[GCTGivePlayerKnife]); + + pcvar = get_cvar_pointer("mp_t_default_weapons_secondary"); + set_pcvar_string(pcvar, GameCvars[GCTDefaultWeaponsSecondary]); + + pcvar = get_cvar_pointer("mp_t_default_weapons_primary"); + set_pcvar_string(pcvar, GameCvars[GCTDefaultWeaponsPrimary]); + + pcvar = get_cvar_pointer("mp_ct_default_grenades"); + set_pcvar_string(pcvar, GameCvars[GCCTDefaultGrenades]); + + pcvar = get_cvar_pointer("mp_ct_give_player_knife"); + set_pcvar_num(pcvar, GameCvars[GCCTGivePlayerKnife]); + + pcvar = get_cvar_pointer("mp_ct_default_weapons_secondary"); + set_pcvar_string(pcvar, GameCvars[GCCTDefaultWeaponsSecondary]); + + pcvar = get_cvar_pointer("mp_ct_default_weapons_primary"); + set_pcvar_string(pcvar, GameCvars[GCCTDefaultWeaponsPrimary]); + + pcvar = get_cvar_pointer("mp_free_armor"); + set_pcvar_num(pcvar, GameCvars[GCFreeArmor]); + pcvar = get_cvar_pointer("mp_buytime"); set_pcvar_float(pcvar, GameCvars[GCBuyTime]); diff --git a/cstrike/addons/amxmodx/scripting/regg/functions.inl b/cstrike/addons/amxmodx/scripting/regg/functions.inl index 6406339..9d318d6 100644 --- a/cstrike/addons/amxmodx/scripting/regg/functions.inl +++ b/cstrike/addons/amxmodx/scripting/regg/functions.inl @@ -9,7 +9,7 @@ bool:start(const ReGG_Mode:mode) { EXECUTE_FORWARD_PRE_ARGS(FWD_Start, false, mode); - Mode = mode; + // Mode = mode; changeGameCvars(); @@ -23,18 +23,34 @@ bool:start(const ReGG_Mode:mode) { EXECUTE_FORWARD_POST_ARGS(FWD_Start, mode); + Mode = mode; set_member_game(m_bCompleteReset, true); - rg_restart_round(); + // rg_restart_round(); + + rg_round_end( + .tmDelay = 3.0, + .st = WINSTATUS_DRAW, + .event = ROUND_END_DRAW, + .message = "Message", + .sentence = "", + .trigger = true + ); + return true; } bool:finish(const killer, const victim) { + log_amx(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> finish"); EXECUTE_FORWARD_PRE_ARGS(FWD_Finish, false, killer, victim); restoreGameCvars(); disableHooks(); + resetPlayersStats(); + resetTeamsStats(); + EXECUTE_FORWARD_POST_ARGS(FWD_Finish, killer, victim); Mode = ReGG_ModeNone; + set_member_game(m_bCompleteReset, true); rg_restart_round(); return true; } @@ -137,18 +153,6 @@ ReGG_Result:killKnife(const killer, const victim) { return result; } -giveDefaultWeapons(const id) { - switch(ArmorType:Config[CfgFreeArmor]) { - case ARMOR_KEVLAR: { - rg_set_user_armor(id, 100, ARMOR_KEVLAR); - } - case ARMOR_VESTHELM: { - rg_set_user_armor(id, 100, ARMOR_VESTHELM); - } - } - rg_give_item(id, "weapon_knife"); -} - bool:giveWeapon(const id, const level) { EXECUTE_FORWARD_PRE_ARGS(FWD_GiveWeapon, false, id, Levels[level][LevelWeaponID]); switch (Levels[level][LevelWeaponID]) { @@ -561,12 +565,7 @@ bool:setPlayerLevel(const id, const value, const bool:forwards = true) { new oldValue = Players[id][PlayerLevel]; Players[id][PlayerLevel] = value; if(oldValue != Players[id][PlayerLevel]) { - if (Levels[value][LevelWeaponID] != WEAPON_KNIFE) { - removeWeapon(id, oldValue); - } else { - rg_remove_all_items(id); - giveDefaultWeapons(id); - } + Levels[value][LevelWeaponID] != WEAPON_KNIFE ? removeWeapon(id, oldValue) : rg_give_default_items(id); giveWeapon(id, Players[id][PlayerLevel]); } @@ -586,12 +585,7 @@ bool:setTeamLevel(const slot, const value, const bool:forwards = true) { playerSlot = getTeamSlot(player); if(playerSlot == slot) { if(oldValue != Teams[slot][TeamLevel]) { - if(Levels[value][LevelWeaponID] != WEAPON_KNIFE) { - removeWeapon(player, oldValue); - } else { - rg_remove_all_items(player); - giveDefaultWeapons(player); - } + Levels[value][LevelWeaponID] != WEAPON_KNIFE ? removeWeapon(player, oldValue) : rg_give_default_items(player); giveWeapon(player, Teams[slot][TeamLevel]); } } @@ -606,7 +600,6 @@ getTeamSlot(const id) { case TEAM_TERRORIST: { return ReGG_SlotT; } - case TEAM_CT: { return ReGG_SlotCT; } @@ -642,3 +635,21 @@ getTeamPlayers(const slot) { ? get_member_game(m_iNumTerrorist) : get_member_game(m_iNumCT); } + +resetPlayersStats() { + log_amx(">>> >>> >>> resetPlayersStats"); + for(new player = 1; player <= MaxClients; player++) { + log_amx("Players[%d][PlayerPoints] = %d | Players[%d][PlayerLevel] = %d", player, Players[player][PlayerPoints], player, Players[player][PlayerLevel]); + Players[player][PlayerPoints] = 0; + Players[player][PlayerLevel] = 0; + } +} + +resetTeamsStats() { + log_amx(">>> >>> >>> resetTeamssStats"); + for(new slot = ReGG_SlotT; slot <= ReGG_SlotCT; slot++) { + log_amx("Teams[%d][TeamPoints] = %d | Teams[%d][TeamLevel] = %d", slot, Teams[slot][TeamPoints], slot, Teams[slot][TeamLevel]); + Teams[slot][TeamPoints] = 0; + Teams[slot][TeamLevel] = 0; + } +} \ No newline at end of file diff --git a/cstrike/addons/amxmodx/scripting/regg/hooks.inl b/cstrike/addons/amxmodx/scripting/regg/hooks.inl index 973da0d..1acf554 100644 --- a/cstrike/addons/amxmodx/scripting/regg/hooks.inl +++ b/cstrike/addons/amxmodx/scripting/regg/hooks.inl @@ -15,32 +15,28 @@ enum _:hook_s { HookChain:HookKilled, }; -new Hooks[hook_s]; +new HookChain:Hooks[hook_s]; registerHooks() { Hooks[HookDropClient] = RegisterHookChain(RH_SV_DropClient, "SV_DropClient_Post", true); - Hooks[HookRestartRound] = RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound_Pre", false); + Hooks[HookRestartRound] = RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound_Post", false); Hooks[HookHasRestrictItem] = RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "CBasePlayer_HasRestrictItem_Pre", false); Hooks[HookDropPlayerItem] = RegisterHookChain(RG_CBasePlayer_DropPlayerItem, "CBasePlayer_DropPlayerItem_Pre", false); Hooks[HookFShouldSwitchWeapon] = RegisterHookChain(RG_CSGameRules_FShouldSwitchWeapon, "CSGameRules_FShouldSwitchWeapon_Pre", false); - - Hooks[HookOnSpawnEquip] = RegisterHookChain(RG_CBasePlayer_OnSpawnEquip, "CBasePlayer_OnSpawnEquip_Pre", false); + Hooks[HookOnSpawnEquip] = RegisterHookChain(RG_CBasePlayer_OnSpawnEquip, "CBasePlayer_OnSpawnEquip_Post", true); Hooks[HookThrowHeGrenade] = RegisterHookChain(RG_ThrowHeGrenade, "CBasePlayer_ThrowHeGrenade_Post", true); Hooks[HookKilled] = RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed_Post", true); } disableHooks() { for(new i = 0; i < sizeof(Hooks); i++) { - DisableHookChain(HookChain:Hooks[i]); + Hooks[i] && DisableHookChain(Hooks[i]); + // DisableHookChain(HookChain:Hooks[i]); } } toggleShouldSwitchWeapon(const bool:enable) { - if(enable) { - EnableHookChain(Hooks[HookFShouldSwitchWeapon]); - } else { - DisableHookChain(Hooks[HookFShouldSwitchWeapon]); - } + enable ? EnableHookChain(Hooks[HookFShouldSwitchWeapon]) : DisableHookChain(Hooks[HookFShouldSwitchWeapon]); } public SV_DropClient_Post(const id) { @@ -51,29 +47,34 @@ public SV_DropClient_Post(const id) { return HC_CONTINUE; } -public CSGameRules_RestartRound_Pre() { - if(get_member_game(m_bCompleteReset)) { - for(new player = 1; player <= MaxClients; player++) { - Players[player][PlayerPoints] = 0; - Players[player][PlayerLevel] = 0; - - if(is_user_connected(player) && (TEAM_TERRORIST <= TeamName:get_member(player, m_iTeam) <= TEAM_CT)) { - rg_remove_all_items(player, true); - giveDefaultWeapons(player); - giveWeapon(player, 0); - } - } - for(new slot = ReGG_SlotT; slot <= ReGG_SlotCT; slot++) { - Teams[slot][TeamPoints] = 0; - Teams[slot][TeamLevel] = 0; - } +public CSGameRules_RestartRound_Post() { + log_amx(">>>>>>>>>>>>>>>>>>>> CSGameRules_RestartRound_Post()"); + // if(!get_member_game(m_bCompleteReset)) { + // return HC_CONTINUE; + // } + + // for(new player = 1; player <= MaxClients; player++) { + // log_amx("Players[player][PlayerPoints] = %d | Players[player][PlayerLevel] = %d", Players[player][PlayerPoints], Players[player][PlayerLevel]); + // Players[player][PlayerPoints] = 0; + // Players[player][PlayerLevel] = 0; + // } + + // for(new slot = ReGG_SlotT; slot <= ReGG_SlotCT; slot++) { + // Teams[slot][TeamPoints] = 0; + // Teams[slot][TeamLevel] = 0; + // } + + if(get_member_game(m_bCompleteReset)) { + resetPlayersStats(); + resetTeamsStats(); } - return HC_CONTINUE; + + // return HC_CONTINUE; } public CBasePlayer_HasRestrictItem_Pre() { - SetHookChainReturn(ATYPE_BOOL, true); - return HC_SUPERCEDE; + // SetHookChainReturn(ATYPE_BOOL, true); + // return HC_SUPERCEDE; } public CBasePlayer_DropPlayerItem_Pre() { @@ -86,7 +87,7 @@ public CSGameRules_FShouldSwitchWeapon_Pre() { return HC_SUPERCEDE; } -public CBasePlayer_OnSpawnEquip_Pre(const id) { +public CBasePlayer_OnSpawnEquip_Post(const id) { if(!is_user_alive(id)) { return HC_CONTINUE; } @@ -96,7 +97,6 @@ public CBasePlayer_OnSpawnEquip_Pre(const id) { Players[id][PlayerJoined] = true; } - giveDefaultWeapons(id); if(Mode == ReGG_ModeTeam) { new slot = getTeamSlot(id); giveWeapon(id, Teams[slot][TeamLevel]); @@ -105,8 +105,7 @@ public CBasePlayer_OnSpawnEquip_Pre(const id) { } set_member(id, m_iHideHUD, get_member(id, m_iHideHUD) | HIDEHUD_MONEY); - - return HC_SUPERCEDE; + return HC_CONTINUE; } public CBasePlayer_ThrowHeGrenade_Post(const id) { diff --git a/cstrike/addons/amxmodx/scripting/regg_core.sma b/cstrike/addons/amxmodx/scripting/regg_core.sma index d8ff1d0..af5c1f3 100644 --- a/cstrike/addons/amxmodx/scripting/regg_core.sma +++ b/cstrike/addons/amxmodx/scripting/regg_core.sma @@ -102,6 +102,7 @@ public TaskGiveGrenade(id) { } else { level = Players[id][PlayerLevel]; } + if(Levels[level][LevelWeaponID] == WEAPON_HEGRENADE) { rg_give_item(id, "weapon_hegrenade"); } diff --git a/cstrike/addons/amxmodx/scripting/regg_informer.sma b/cstrike/addons/amxmodx/scripting/regg_informer.sma index 0b34e0b..e1ec4b9 100644 --- a/cstrike/addons/amxmodx/scripting/regg_informer.sma +++ b/cstrike/addons/amxmodx/scripting/regg_informer.sma @@ -28,6 +28,7 @@ public ReGG_FinishPost() { state disabled; remove_task(TASK_INFO_ID); ClearSyncHud(0, SyncHudStats); + arrayset(PlayerInfos[0][0], 0, sizeof(PlayerInfos) * sizeof(PlayerInfos[])); } public ReGG_PlayerJoinPost(const id) { From 37afb72200ebce4c4404827fd557b4ba42146135 Mon Sep 17 00:00:00 2001 From: d3m37r4 Date: Sun, 3 Dec 2023 17:12:51 +0700 Subject: [PATCH 2/2] Fixed a typo in name of the RestartRound hook function. --- cstrike/addons/amxmodx/scripting/regg/hooks.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cstrike/addons/amxmodx/scripting/regg/hooks.inl b/cstrike/addons/amxmodx/scripting/regg/hooks.inl index 1acf554..5e342e0 100644 --- a/cstrike/addons/amxmodx/scripting/regg/hooks.inl +++ b/cstrike/addons/amxmodx/scripting/regg/hooks.inl @@ -19,7 +19,7 @@ new HookChain:Hooks[hook_s]; registerHooks() { Hooks[HookDropClient] = RegisterHookChain(RH_SV_DropClient, "SV_DropClient_Post", true); - Hooks[HookRestartRound] = RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound_Post", false); + Hooks[HookRestartRound] = RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound_Pre", false); Hooks[HookHasRestrictItem] = RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "CBasePlayer_HasRestrictItem_Pre", false); Hooks[HookDropPlayerItem] = RegisterHookChain(RG_CBasePlayer_DropPlayerItem, "CBasePlayer_DropPlayerItem_Pre", false); Hooks[HookFShouldSwitchWeapon] = RegisterHookChain(RG_CSGameRules_FShouldSwitchWeapon, "CSGameRules_FShouldSwitchWeapon_Pre", false); @@ -47,8 +47,8 @@ public SV_DropClient_Post(const id) { return HC_CONTINUE; } -public CSGameRules_RestartRound_Post() { - log_amx(">>>>>>>>>>>>>>>>>>>> CSGameRules_RestartRound_Post()"); +public CSGameRules_RestartRound_Pre() { + log_amx(">>>>>>>>>>>>>>>>>>>> CSGameRules_RestartRound_Pre()"); // if(!get_member_game(m_bCompleteReset)) { // return HC_CONTINUE; // }