using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
private static Dictionary<CSWeaponType, List<Weapon>> weaponDictionary;
public static void Main(string[] args)
var weaponName = "weapon_awp";
Stopwatch stopwatch = Stopwatch.StartNew();
var weapon1 = FindWeaponOriginal(weaponName);
Console.WriteLine($"Original: {stopwatch.ElapsedTicks} ticks");
var weapon2 = FindWeaponWithSpan(weaponName);
Console.WriteLine($"With Span: {stopwatch.ElapsedTicks} ticks");
public static void InitializeWeapons()
weaponDictionary = new Dictionary<CSWeaponType, List<Weapon>>();
AddWeapon(new("weapon_cz75a", "CZ75", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_CZ75A, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_deagle", "Desert Eagle", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_DEAGLE, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_elite", "Berety", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_ELITE, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_fiveseven", "Five-Seven", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_FIVESEVEN, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_glock", "Glock", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_GLOCK, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_hkp2000", "P2000", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_HKP2000, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_p250", "P250", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_P250, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_revolver", "Revolver", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_REVOLVER, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_tec9", "Tec-9", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_TEC9, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_usp_silencer", "USP-S", CSWeaponType.WEAPONTYPE_PISTOL, (ushort)WeaponDefIndex.WEAPON_USP_SILENCER, gear_slot_t.GEAR_SLOT_PISTOL));
AddWeapon(new("weapon_mac10", "MAC-10", CSWeaponType.WEAPONTYPE_SUBMACHINEGUN, (ushort)WeaponDefIndex.WEAPON_MAC10, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_mp5sd", "MP5-SD", CSWeaponType.WEAPONTYPE_SUBMACHINEGUN, (ushort)WeaponDefIndex.WEAPON_MP5SD, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_mp7", "MP7", CSWeaponType.WEAPONTYPE_SUBMACHINEGUN, (ushort)WeaponDefIndex.WEAPON_MP7, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_mp9", "MP9", CSWeaponType.WEAPONTYPE_SUBMACHINEGUN, (ushort)WeaponDefIndex.WEAPON_MP9, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_bizon", "PP-Bizon", CSWeaponType.WEAPONTYPE_SUBMACHINEGUN, (ushort)WeaponDefIndex.WEAPON_BIZON, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_p90", "P90", CSWeaponType.WEAPONTYPE_SUBMACHINEGUN, (ushort)WeaponDefIndex.WEAPON_P90, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_ump45", "UMP-45", CSWeaponType.WEAPONTYPE_SUBMACHINEGUN, (ushort)WeaponDefIndex.WEAPON_UMP45, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_ak47", "AK-47", CSWeaponType.WEAPONTYPE_RIFLE, (ushort)WeaponDefIndex.WEAPON_AK47, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_aug", "AUG", CSWeaponType.WEAPONTYPE_RIFLE, (ushort)WeaponDefIndex.WEAPON_AUG, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_famas", "Famas", CSWeaponType.WEAPONTYPE_RIFLE, (ushort)WeaponDefIndex.WEAPON_FAMAS, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_galilar", "Galil AR", CSWeaponType.WEAPONTYPE_RIFLE, (ushort)WeaponDefIndex.WEAPON_GALILAR, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_m4a1_silencer", "M4A1-S", CSWeaponType.WEAPONTYPE_RIFLE, (ushort)WeaponDefIndex.WEAPON_M4A1_SILENCER, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_m4a1", "M4A4", CSWeaponType.WEAPONTYPE_RIFLE, (ushort)WeaponDefIndex.WEAPON_M4A1, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_sg556", "SSG 553", CSWeaponType.WEAPONTYPE_RIFLE, (ushort)WeaponDefIndex.WEAPON_SG556, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_awp", "AWP", CSWeaponType.WEAPONTYPE_SNIPER_RIFLE, (ushort)WeaponDefIndex.WEAPON_AWP, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_g3sg1", "G3SG1", CSWeaponType.WEAPONTYPE_SNIPER_RIFLE, (ushort)WeaponDefIndex.WEAPON_G3SG1, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_scar20", "SCAR-20", CSWeaponType.WEAPONTYPE_SNIPER_RIFLE, (ushort)WeaponDefIndex.WEAPON_SCAR20, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_ssg08", "SSG 08", CSWeaponType.WEAPONTYPE_SNIPER_RIFLE, (ushort)WeaponDefIndex.WEAPON_SSG08, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_mag7", "MAG-7", CSWeaponType.WEAPONTYPE_SHOTGUN, (ushort)WeaponDefIndex.WEAPON_MAG7, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_nova", "Nova", CSWeaponType.WEAPONTYPE_SHOTGUN, (ushort)WeaponDefIndex.WEAPON_NOVA, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_sawedoff", "Obrzyn", CSWeaponType.WEAPONTYPE_SHOTGUN, (ushort)WeaponDefIndex.WEAPON_SAWEDOFF, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_xm1014", "XM1014", CSWeaponType.WEAPONTYPE_SHOTGUN, (ushort)WeaponDefIndex.WEAPON_XM1014, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_m249", "M249", CSWeaponType.WEAPONTYPE_MACHINEGUN, (ushort)WeaponDefIndex.WEAPON_M249, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_negev", "Negev", CSWeaponType.WEAPONTYPE_MACHINEGUN, (ushort)WeaponDefIndex.WEAPON_NEGEV, gear_slot_t.GEAR_SLOT_RIFLE));
AddWeapon(new("weapon_hegrenade", "HE", CSWeaponType.WEAPONTYPE_GRENADE, (ushort)WeaponDefIndex.WEAPON_HEGRENADE, gear_slot_t.GEAR_SLOT_GRENADES));
AddWeapon(new("weapon_flashbang", "Flashbang", CSWeaponType.WEAPONTYPE_GRENADE, (ushort)WeaponDefIndex.WEAPON_FLASHBANG, gear_slot_t.GEAR_SLOT_GRENADES));
AddWeapon(new("weapon_smokegrenade", "Smoke", CSWeaponType.WEAPONTYPE_GRENADE, (ushort)WeaponDefIndex.WEAPON_SMOKEGRENADE, gear_slot_t.GEAR_SLOT_GRENADES));
AddWeapon(new("weapon_decoy", "Decoy", CSWeaponType.WEAPONTYPE_GRENADE, (ushort)WeaponDefIndex.WEAPON_DECOY, gear_slot_t.GEAR_SLOT_GRENADES));
AddWeapon(new("weapon_molotov", "Molotov", CSWeaponType.WEAPONTYPE_GRENADE, (ushort)WeaponDefIndex.WEAPON_MOLOTOV, gear_slot_t.GEAR_SLOT_GRENADES));
AddWeapon(new("weapon_incgrenade", "Incgrenade", CSWeaponType.WEAPONTYPE_GRENADE, (ushort)WeaponDefIndex.WEAPON_INCGRENADE, gear_slot_t.GEAR_SLOT_GRENADES));
AddWeapon(new("weapon_knife", "CT Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_CT, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife", "TT Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_TT, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_css", "Clasic Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_CSS, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_flip", "Flip Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_FLIP, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_gut", "Gut Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_GUT, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_karambit", "Karambit", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_KARAMBIT, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_m9_bayonet", "M9 Bayonet", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_M9_BAYONET, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_tactical", "Tactical Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_TACTICAL, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_falchion", "Falchion Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_FALCHION, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_survival_bowie", "Survival Bowie", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_SURVIVAL_BOWIE, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_butterfly", "Butterfly Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_BUTTERFLY, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_push", "Push Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_PUSH, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_cord", "Cord Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_CORD, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_canis", "Canis Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_CANIS, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_ursus", "Ursus Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_URSUS, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_gypsy_jackknife", "Gypsy Jackknife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_GYPSY_JACKKNIFE, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_outdoor", "Outdoor Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_OUTDOOR, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_stiletto", "Stiletto Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_STILETTO, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_widowmaker", "Widowmaker Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_WIDOWMAKER, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_skeleton", "Skeleton Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_SKELETON, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_knife_kukri", "Kukri Knife", CSWeaponType.WEAPONTYPE_KNIFE, (ushort)WeaponDefIndex.WEAPON_KNIFE_KUKRI, gear_slot_t.GEAR_SLOT_KNIFE));
AddWeapon(new("weapon_taser", "Zeus", CSWeaponType.WEAPONTYPE_TASER, (ushort)WeaponDefIndex.WEAPON_TASER, gear_slot_t.GEAR_SLOT_BOOSTS));
AddWeapon(new("weapon_healthshot", "Healthshot", CSWeaponType.WEAPONTYPE_STACKABLEITEM, (ushort)WeaponDefIndex.WEAPON_HEALTHSHOT, gear_slot_t.GEAR_SLOT_UTILITY));
AddWeapon(new("weapon_c4", "C4", CSWeaponType.WEAPONTYPE_C4, (ushort)WeaponDefIndex.WEAPON_C4, gear_slot_t.GEAR_SLOT_C4));
private static void AddWeapon(Weapon weapon)
if (!weaponDictionary.ContainsKey(weapon.Type))
weaponDictionary[weapon.Type] = new List<Weapon>();
weaponDictionary[weapon.Type].Add(weapon);
public static Weapon FindWeaponOriginal(string weaponName)
foreach (var weaponList in weaponDictionary.Values)
var weapon = weaponList.FirstOrDefault(w => w.WeaponEntityName == weaponName);
public static Weapon FindWeaponWithSpan(string weaponName)
var weaponValuesSpan = CollectionsMarshal.AsSpan(weaponDictionary.Values.ToList());
for (int i = 0; i < weaponValuesSpan.Length; i++)
var weaponListSpan = CollectionsMarshal.AsSpan(weaponValuesSpan[i]);
for (int j = 0; j < weaponListSpan.Length; j++)
if (weaponListSpan[j].WeaponEntityName == weaponName)
return weaponListSpan[j];
WEAPONTYPE_SUBMACHINEGUN,
WEAPONTYPE_STACKABLEITEM,
public enum WeaponDefIndex : ushort
WEAPON_KNIFE_SURVIVAL_BOWIE,
WEAPON_KNIFE_GYPSY_JACKKNIFE,
public string WeaponEntityName { get; set; }
public string DisplayName { get; set; }
public CSWeaponType Type { get; set; }
public ushort DefIndex { get; set; }
public gear_slot_t GearSlot { get; set; }
public Weapon(string weaponEntityName, string displayName, CSWeaponType type, ushort defIndex, gear_slot_t gearSlot)
WeaponEntityName = weaponEntityName;
DisplayName = displayName;