#include "weapon_knife"
//#include "weapon_fiveseven"
#include "weapon_p228sil"
#include "weapon_colt"
#include "weapon_dualglock"
#include "weapon_sawedoff_io"
#include "BulletEjection"

namespace CLASSICWEAPONS2
{

array<ItemMapping@> CLASSIC_WEAPONS_LIST = 
{
	ItemMapping( "weapon_knife", "weapon_csknife" ),
	ItemMapping( "weapon_p228sil", "weapon_usp" ),
	ItemMapping( "weapon_colt", "weapon_csdeagle" ),
	ItemMapping( "weapon_dualglock", "weapon_dualelites" ),
	ItemMapping( "weapon_sawedoff_io", "weapon_m3" )
};

void Enable()
{
	RegisterWeapon_KNIFE();
	//RegisterFIVESEVEN();
	RegisterCOLT();
	RegisterELITES();
	RegisterUSP();
	RegisterSAWEDOFF();

	g_ClassicMode.SetItemMappings( @CLASSIC_WEAPONS_LIST );
	g_ClassicMode.ForceItemRemap( true );
    
	g_Hooks.RegisterHook( Hooks::PickupObject::Materialize, ItemSpawned2 );
}

// World weapon swapper routine (credit to KernCore)
HookReturnCode ItemSpawned2(CBaseEntity@ pOldItem) 
{
	if( pOldItem is null ) 
		return HOOK_CONTINUE;

	for( uint w = 0; w < CLASSIC_WEAPONS_LIST.length(); ++w )
	{
		if( pOldItem.GetClassname() != CLASSIC_WEAPONS_LIST[w].get_From() )
			continue;

		CBaseEntity@ pNewItem = g_EntityFuncs.Create( CLASSIC_WEAPONS_LIST[w].get_To(), pOldItem.GetOrigin(), pOldItem.pev.angles, false );

		if( pNewItem is null ) 
			continue;

		pNewItem.pev.movetype = pOldItem.pev.movetype;

		if( pOldItem.pev.netname != "" )
			pNewItem.pev.netname = pOldItem.pev.netname;

		g_EntityFuncs.Remove( pOldItem );
        
	}
    
	return HOOK_CONTINUE;
}

}

void MapInit()
{
	CLASSICWEAPONS2::Enable();
}