Skip to content

Commit

Permalink
Merge pull request #9 from d3m37r4/dev-branch
Browse files Browse the repository at this point in the history
Fix crash. Refactoring. Optimizations for current version of ReGameDLL.
  • Loading branch information
d3m37r4 authored Dec 6, 2023
2 parents 2bd22a0 + 37afb72 commit 833c281
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 60 deletions.
2 changes: 1 addition & 1 deletion cstrike/addons/amxmodx/scripting/include/regg.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
74 changes: 73 additions & 1 deletion cstrike/addons/amxmodx/scripting/regg/config.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]);

Expand Down
65 changes: 38 additions & 27 deletions cstrike/addons/amxmodx/scripting/regg/functions.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
bool:start(const ReGG_Mode:mode) {
EXECUTE_FORWARD_PRE_ARGS(FWD_Start, false, mode);

Mode = mode;
// Mode = mode;

changeGameCvars();

Expand All @@ -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;
}
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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]);
}

Expand All @@ -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]);
}
}
Expand All @@ -606,7 +600,6 @@ getTeamSlot(const id) {
case TEAM_TERRORIST: {
return ReGG_SlotT;
}

case TEAM_CT: {
return ReGG_SlotCT;
}
Expand Down Expand Up @@ -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;
}
}
61 changes: 30 additions & 31 deletions cstrike/addons/amxmodx/scripting/regg/hooks.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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[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) {
Expand All @@ -52,28 +48,33 @@ public SV_DropClient_Post(const id) {
}

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;
}
log_amx(">>>>>>>>>>>>>>>>>>>> CSGameRules_RestartRound_Pre()");
// 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() {
Expand All @@ -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;
}
Expand All @@ -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]);
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions cstrike/addons/amxmodx/scripting/regg_core.sma
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public TaskGiveGrenade(id) {
} else {
level = Players[id][PlayerLevel];
}

if(Levels[level][LevelWeaponID] == WEAPON_HEGRENADE) {
rg_give_item(id, "weapon_hegrenade");
}
Expand Down
1 change: 1 addition & 0 deletions cstrike/addons/amxmodx/scripting/regg_informer.sma
Original file line number Diff line number Diff line change
Expand Up @@ -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) <enabled> {
Expand Down

0 comments on commit 833c281

Please sign in to comment.