Skip to content

Commit

Permalink
refactor gun menu
Browse files Browse the repository at this point in the history
  • Loading branch information
destoer committed Jan 20, 2024
1 parent 0829584 commit b4e82e2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
9 changes: 9 additions & 0 deletions gamedata/Cs2Jailbreak.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"CBasePlayerController_SetPawn": {
"signatures": {
"library": "server",
"windows": "\\x44\\x88\\x4C\\x24\\x2A\\x55\\x57",
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x57\\x41\\x56\\x41\\x55\\x41\\x54\\x49\\x89\\xFC\\x53\\x48\\x89\\xF3\\x48\\x81\\xEC\\xC8\\x00\\x00\\x00"
}
}
}
2 changes: 1 addition & 1 deletion src/LastRequest/Rebel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void rebel_guns(CCSPlayerController player, ChatMenuOption option)

player.strip_weapons();

player.GiveNamedItem("weapon_" + Lib.gun_give_name(option.Text));
player.GiveNamedItem(Lib.gun_give_name(option.Text));
player.GiveNamedItem("weapon_deagle");

player.GiveNamedItem("item_assaultsuit");
Expand Down
50 changes: 22 additions & 28 deletions src/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,10 @@ static void give_menu_weapon(CCSPlayerController player, ChatMenuOption option)
player.strip_weapons();

// give their desired guns with lots of reserve ammo
player.GiveNamedItem("weapon_" + gun_give_name(option.Text));
player.GiveNamedItem(gun_give_name(option.Text));
player.GiveNamedItem("weapon_deagle");

CBasePlayerWeapon? primary = Lib.find_weapon(player,gun_give_name(option.Text));
CBasePlayerWeapon? primary = Lib.find_weapon(player,GUN_LIST[option.Text]);
primary.set_ammo(-1,999);

CBasePlayerWeapon? secondary = Lib.find_weapon(player,"deagle");
Expand All @@ -699,35 +699,27 @@ static void give_menu_weapon(CCSPlayerController player, ChatMenuOption option)
player.GiveNamedItem("item_assaultsuit");
}

static String[] GUN_LIST =
{
"ak47", "m4a1_silencer","nova",
"p90", "m249", "mp5sd",
"galilar", "sg556","bizon", "aug",
"famas", "xm1014","ssg08","awp"

};

static String[] GUN_NAMES =
{
"AK47","M4","M3","P90","M249","MP5",
"FAL","SG556","BIZON","AUG",
"FAMAS","XM1014","SCOUT","AWP"
static Dictionary<String,String> GUN_LIST = new Dictionary<String,String>()
{
{"AK47","ak47"},
{"M4","m4a1_silencer"},
{"M3","nova"},
{"P90","p90"},
{"M249","m249"},
{"MP5","mp5sd"},
{"FAL","galilar"},
{"SG556","sg556"},
{"BIZON","bizon"},
{"AUG","aug"},
{"FAMAS","famas"},
{"XM1014","xm1014"},
{"SCOUT","ssg08"},
{"AWP", "awp"},
};


public static String gun_give_name(String name)
{
// TODO: a linear scan shouldn't matter on a list this small
for(int i = 0; i < GUN_NAMES.Count(); i++)
{
if(name == GUN_NAMES[i])
{
return GUN_LIST[i];
}
}

return "";
return "weapon_" + GUN_LIST[name];
}

static public void gun_menu_internal(this CCSPlayerController? player, bool no_awp, Action<CCSPlayerController, ChatMenuOption> callback)
Expand All @@ -741,8 +733,10 @@ static public void gun_menu_internal(this CCSPlayerController? player, bool no_a

var gun_menu = new ChatMenu("Gun Menu");

foreach(var weapon_name in GUN_NAMES)
foreach(var weapon_pair in GUN_LIST)
{
var weapon_name = weapon_pair.Key;

if(no_awp && weapon_name == "awp")
{
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/Warden/Warden.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public void setup_player_guns(CCSPlayerController? player)

if(jail_player != null)
{
player.GiveNamedItem("weapon_" + Lib.gun_give_name(jail_player.ct_gun));
player.GiveNamedItem(Lib.gun_give_name(jail_player.ct_gun));
}
}

Expand Down Expand Up @@ -541,7 +541,7 @@ public void ct_guns(CCSPlayerController player, ChatMenuOption option)
jail_player.ct_gun = option.Text;
}

player.GiveNamedItem("weapon_" + Lib.gun_give_name(option.Text));
player.GiveNamedItem(Lib.gun_give_name(option.Text));
player.GiveNamedItem("weapon_deagle");

if(config.ct_armour)
Expand Down

0 comments on commit b4e82e2

Please sign in to comment.