2020-12-02 16:19:16 -05:00
# include "pch.h"
# include "Weapon.h"
2021-01-03 06:48:07 -05:00
# include "Ui.h"
# include "Util.h"
2021-03-02 14:18:37 -05:00
# include "Ped.h"
2021-08-14 20:36:11 -04:00
# include "CWeaponInfo.h"
2020-12-02 16:19:16 -05:00
Weapon : : Weapon ( )
{
Events : : processScriptsEvent + = [ ]
{
2021-06-18 12:49:11 -04:00
CPlayerPed * player = FindPlayerPed ( ) ;
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2021-06-18 12:49:11 -04:00
if ( m_bAutoAim )
2020-12-02 16:19:16 -05:00
{
2020-12-28 15:12:40 -05:00
if ( CPad : : NewMouseControllerState . X = = 0 & & CPad : : NewMouseControllerState . Y = = 0 )
2020-12-02 16:19:16 -05:00
{
if ( KeyPressed ( 2 ) )
2021-07-30 18:01:17 -04:00
{
2020-12-02 16:19:16 -05:00
CCamera : : m_bUseMouse3rdPerson = false ;
2021-07-30 18:01:17 -04:00
}
2020-12-02 16:19:16 -05:00
}
else
2021-07-30 18:01:17 -04:00
{
2020-12-02 16:19:16 -05:00
CCamera : : m_bUseMouse3rdPerson = true ;
2021-07-30 18:01:17 -04:00
}
2020-12-02 16:19:16 -05:00
}
2021-08-14 20:36:11 -04:00
# endif
2020-12-02 16:19:16 -05:00
uchar slot = player - > m_nActiveWeaponSlot ;
2021-06-18 12:49:11 -04:00
if ( m_nCurrentWeaponSlot ! = slot )
2020-12-02 16:19:16 -05:00
{
2021-07-30 18:01:17 -04:00
eWeaponType weaponType = player - > m_aWeapons [ slot ] . m_nType ;
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2021-07-30 18:01:17 -04:00
CWeaponInfo * pWeaponInfo = CWeaponInfo : : GetWeaponInfo ( weaponType , player - > GetWeaponSkill ( weaponType ) ) ;
2021-08-14 20:36:11 -04:00
# elif GTAVC
CWeaponInfo * pWeaponInfo = CWeaponInfo : : GetWeaponInfo ( weaponType ) ;
if ( m_bInfiniteAmmo )
{
Command < Commands : : SET_PLAYER_AMMO > ( 0 , weaponType , 999999 ) ;
}
# endif
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
if ( m_bHugeDamage )
2021-07-30 18:01:17 -04:00
{
pWeaponInfo - > m_nDamage = 1000 ;
}
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
if ( m_bLongRange )
2020-12-02 16:19:16 -05:00
{
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2021-07-30 18:01:17 -04:00
pWeaponInfo - > m_fTargetRange = 1000.0f ;
pWeaponInfo - > m_fWeaponRange = 1000.0f ;
pWeaponInfo - > m_fAccuracy = 1.0f ;
pWeaponInfo - > m_nFlags . bReload2Start = true ;
2021-08-14 20:36:11 -04:00
# elif GTAVC
pWeaponInfo - > m_fRange = 1000.0f ;
# endif
2020-12-02 16:19:16 -05:00
}
2021-08-14 20:36:11 -04:00
# ifdef GTASA
if ( m_bRapidFire & & weaponType ! = BY_GAME ( WEAPON_MINIGUN , WEAPONTYPE_MINIGUN ) ) // mingun doesn't work with rapidfire
2021-07-30 18:01:17 -04:00
{
pWeaponInfo - > m_nFlags . bContinuosFire = true ;
2021-08-14 20:36:11 -04:00
2021-07-30 18:01:17 -04:00
}
2020-12-28 15:12:40 -05:00
2021-07-30 18:01:17 -04:00
if ( m_bDualWeild & & ( weaponType = = WEAPON_PISTOL | | weaponType = = WEAPON_MICRO_UZI | | weaponType = =
WEAPON_TEC9 | | weaponType = = WEAPON_SAWNOFF ) )
{
pWeaponInfo - > m_nFlags . bTwinPistol = true ;
}
2020-12-28 15:12:40 -05:00
2021-06-18 12:49:11 -04:00
if ( m_bMoveAim )
2021-07-30 18:01:17 -04:00
{
pWeaponInfo - > m_nFlags . bMoveAim = true ;
}
2021-06-18 12:49:11 -04:00
if ( m_bMoveFire )
2021-07-30 18:01:17 -04:00
{
pWeaponInfo - > m_nFlags . bMoveFire = true ;
}
2021-08-14 20:36:11 -04:00
# endif
2021-06-18 12:49:11 -04:00
m_nCurrentWeaponSlot = slot ;
2020-12-02 16:19:16 -05:00
}
} ;
}
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2020-12-02 16:19:16 -05:00
void Weapon : : SetGangWeapon ( std : : string & weapon_type )
{
2021-06-18 12:49:11 -04:00
m_nGangWeaponList [ m_nSelectedGang ] [ m_nSelectedWeapon ] = std : : stoi ( weapon_type ) ;
CGangs : : SetGangWeapons ( m_nSelectedGang , m_nGangWeaponList [ m_nSelectedGang ] [ 0 ] , m_nGangWeaponList [ m_nSelectedGang ] [ 1 ] ,
2021-08-06 11:53:18 -04:00
m_nGangWeaponList [ m_nSelectedGang ] [ 2 ] ) ;
2020-12-02 16:19:16 -05:00
}
2021-08-14 20:36:11 -04:00
# elif GTAVC
// Implementation of SA opcode 0x555
static void ClearPlayerWeapon ( eWeaponType weaponType )
{
int weaponSlot = CWeaponInfo : : GetWeaponInfo ( weaponType ) - > m_WeaponSlot ;
CPlayerPed * pPlayer = FindPlayerPed ( ) ;
if ( weaponSlot ! = - 1 )
{
CWeapon * pWeapon = & pPlayer - > m_aWeapons [ weaponSlot ] ;
if ( pWeapon - > m_nType = = weaponType )
{
if ( pPlayer - > m_nActiveWeaponSlot = = weaponSlot )
{
CWeaponInfo * pWeaponInfo = CWeaponInfo : : GetWeaponInfo ( WEAPONTYPE_UNARMED ) ;
pPlayer - > SetCurrentWeapon ( pWeaponInfo - > m_WeaponSlot ) ;
}
pWeapon - > Shutdown ( ) ;
}
}
}
2020-12-02 16:19:16 -05:00
2021-08-14 20:36:11 -04:00
// Implementation of opcode 0x605 (CLEO)
static eWeaponType GetWeaponTypeFromModel ( int model )
{
eWeaponType weaponType = WEAPONTYPE_UNARMED ;
for ( size_t i = 0 ; i < 37 ; i + + )
{
int temp = CallAndReturn < int , 0x4418B0 > ( i ) ; // int __cdecl CPickups::ModelForWeapon(int a1)
if ( temp = = model )
{
weaponType = ( eWeaponType ) i ;
break ;
}
}
return weaponType ;
}
# endif
# ifdef GTASA
2020-12-02 16:19:16 -05:00
void Weapon : : GiveWeaponToPlayer ( std : : string & weapon_type )
{
CPlayerPed * player = FindPlayerPed ( ) ;
int hplayer = CPools : : GetPedRef ( player ) ;
if ( weapon_type = = " -1 " ) // Jetpack
2021-07-30 18:01:17 -04:00
{
2020-12-02 16:19:16 -05:00
Command < Commands : : TASK_JETPACK > ( hplayer ) ;
2021-07-30 18:01:17 -04:00
}
2020-12-02 16:19:16 -05:00
else
{
int iweapon_type = std : : stoi ( weapon_type ) ;
int model = NULL ;
Command < Commands : : GET_WEAPONTYPE_MODEL > ( iweapon_type , & model ) ;
2021-06-18 12:49:11 -04:00
CStreaming : : RequestModel ( model , PRIORITY_REQUEST ) ;
2021-01-03 06:48:07 -05:00
if ( model = = 363 ) // remote bomb
2021-07-30 18:01:17 -04:00
{
2021-06-18 12:49:11 -04:00
CStreaming : : RequestModel ( 364 , PRIORITY_REQUEST ) ; // detonator
2021-07-30 18:01:17 -04:00
}
2021-01-03 06:48:07 -05:00
2020-12-02 16:19:16 -05:00
CStreaming : : LoadAllRequestedModels ( false ) ;
2021-06-18 12:49:11 -04:00
Command < Commands : : GIVE_WEAPON_TO_CHAR > ( hplayer , iweapon_type , m_nAmmoCount ) ;
2021-01-03 06:48:07 -05:00
if ( model = = 363 ) // remote bomb
2021-07-30 18:01:17 -04:00
{
2021-01-03 06:48:07 -05:00
Command < Commands : : MARK_MODEL_AS_NO_LONGER_NEEDED > ( 364 ) ; // detonator
2021-07-30 18:01:17 -04:00
}
2021-01-03 06:48:07 -05:00
2020-12-02 16:19:16 -05:00
Command < Commands : : MARK_MODEL_AS_NO_LONGER_NEEDED > ( model ) ;
2021-06-18 12:49:11 -04:00
}
2020-12-02 16:19:16 -05:00
}
2021-08-14 20:36:11 -04:00
# elif GTAVC
void Weapon : : GiveWeaponToPlayer ( std : : string & rootkey , std : : string & name , std : : string & model )
{
CPlayerPed * player = FindPlayerPed ( ) ;
int hplayer = CPools : : GetPedRef ( player ) ;
int iModel = std : : stoi ( model ) ;
CStreaming : : RequestModel ( iModel , PRIORITY_REQUEST ) ;
CStreaming : : LoadAllRequestedModels ( false ) ;
eWeaponType weaponType = GetWeaponTypeFromModel ( iModel ) ;
Command < Commands : : GIVE_WEAPON_TO_CHAR > ( hplayer , weaponType , m_nAmmoCount ) ;
Command < Commands : : MARK_MODEL_AS_NO_LONGER_NEEDED > ( iModel ) ;
}
# endif
2020-12-02 16:19:16 -05:00
2021-02-24 16:54:45 -05:00
void Weapon : : Draw ( )
2020-12-02 16:19:16 -05:00
{
2021-07-30 18:01:17 -04:00
CPlayerPed * pPlayer = FindPlayerPed ( ) ;
uint hplayer = CPools : : GetPedRef ( pPlayer ) ;
2020-12-02 16:19:16 -05:00
ImGui : : Spacing ( ) ;
if ( ImGui : : Button ( " Drop weapon " , Ui : : GetSize ( 3 ) ) )
{
float x , y , z ;
Command < Commands : : GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS > ( hplayer , 0.0 , 3.0 , 0.0 , & x , & y , & z ) ;
2021-07-30 18:01:17 -04:00
eWeaponType weaponType = pPlayer - > m_aWeapons [ pPlayer - > m_nActiveWeaponSlot ] . m_nType ;
2021-06-18 12:49:11 -04:00
2021-07-30 18:01:17 -04:00
if ( weaponType )
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
int model = 0 , pickup = 0 ;
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2021-07-30 18:01:17 -04:00
Command < Commands : : GET_WEAPONTYPE_MODEL > ( weaponType , & model ) ;
2021-08-14 20:36:11 -04:00
# elif GTAVC
model = CallAndReturn < int , 0x4418B0 > ( weaponType ) ; // int __cdecl CPickups::ModelForWeapon(int a1)
# endif
2020-12-02 16:19:16 -05:00
Command < Commands : : CREATE_PICKUP_WITH_AMMO > ( model , 3 , 999 , x , y , z , & pickup ) ;
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2021-07-30 18:01:17 -04:00
Command < Commands : : REMOVE_WEAPON_FROM_CHAR > ( hplayer , weaponType ) ;
2021-08-14 20:36:11 -04:00
# elif GTAVC
ClearPlayerWeapon ( weaponType ) ;
# endif
2020-12-02 16:19:16 -05:00
}
}
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Remove all " , Ui : : GetSize ( 3 ) ) )
2021-07-30 18:01:17 -04:00
{
2020-12-02 16:19:16 -05:00
Command < Commands : : REMOVE_ALL_CHAR_WEAPONS > ( hplayer ) ;
2021-07-30 18:01:17 -04:00
}
2020-12-02 16:19:16 -05:00
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Remove current " , Ui : : GetSize ( 3 ) ) )
2021-07-30 18:01:17 -04:00
{
2021-08-14 20:36:11 -04:00
# ifdef GTASA
Command < Commands : : REMOVE_WEAPON_FROM_CHAR > ( hplayer , pPlayer - > m_aWeapons [ pPlayer - > m_nActiveWeaponSlot ] . m_nType ) ;
# elif GTAVC
ClearPlayerWeapon ( pPlayer - > m_aWeapons [ pPlayer - > m_nActiveWeaponSlot ] . m_nType ) ;
# endif
2021-07-30 18:01:17 -04:00
}
2020-12-02 16:19:16 -05:00
ImGui : : Spacing ( ) ;
2021-08-06 11:53:18 -04:00
2020-12-02 16:19:16 -05:00
if ( ImGui : : BeginTabBar ( " Ped " , ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll ) )
{
if ( ImGui : : BeginTabItem ( " Checkboxes " ) )
{
ImGui : : Spacing ( ) ;
ImGui : : BeginChild ( " CheckboxesChild " ) ;
2021-08-14 20:36:11 -04:00
ImGui : : Spacing ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : Text ( " Info " ) ;
Ui : : ShowTooltip ( " Weapon tweaks apply globally \n to every ped weapon type " ) ;
2020-12-02 16:19:16 -05:00
ImGui : : Columns ( 2 , 0 , false ) ;
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2021-07-15 07:08:21 -04:00
Ui : : CheckboxWithHint ( " Fast aim " , & m_bAutoAim , " Enables aim assist on keyboard \n \n Q = left E = right \n \n Press Q and E to switch targets. \n Moving mouse removes the target! " ) ;
if ( Ui : : CheckboxWithHint ( " Dual wield " , & m_bDualWeild ,
2021-08-06 11:53:18 -04:00
" Dual wield pistol, shawoff, uzi, tec9 \n (Other weapons don't work) " ) )
2020-12-28 15:12:40 -05:00
{
2021-06-18 12:49:11 -04:00
if ( ! m_bDualWeild )
2021-07-30 18:01:17 -04:00
{
2020-12-28 15:12:40 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
2021-07-30 18:01:17 -04:00
}
2020-12-28 15:12:40 -05:00
}
2021-08-14 20:36:11 -04:00
# endif
2021-06-18 12:49:11 -04:00
if ( Ui : : CheckboxWithHint ( " Huge damage " , & m_bHugeDamage ) )
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
if ( ! m_bHugeDamage )
2021-07-30 18:01:17 -04:00
{
2020-12-02 16:19:16 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
2021-07-30 18:01:17 -04:00
}
2020-12-02 16:19:16 -05:00
}
2021-06-18 12:49:11 -04:00
if ( Ui : : CheckboxWithHint ( " Fast reload " , & m_bFastReload ) )
2021-08-14 20:36:11 -04:00
{
2021-06-18 12:49:11 -04:00
Command < Commands : : SET_PLAYER_FAST_RELOAD > ( hplayer , m_bFastReload ) ;
2021-08-14 20:36:11 -04:00
}
2020-12-02 16:19:16 -05:00
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2020-12-02 16:19:16 -05:00
Ui : : CheckboxAddress ( " Infinite ammo " , 0x969178 ) ;
2021-08-14 20:36:11 -04:00
# endif
2020-12-28 15:12:40 -05:00
ImGui : : NextColumn ( ) ;
2021-08-14 20:36:11 -04:00
# ifdef GTAVC
Ui : : CheckboxWithHint ( " Infinite ammo " , & m_bInfiniteAmmo ) ;
# endif
2021-06-18 12:49:11 -04:00
if ( Ui : : CheckboxWithHint ( " Long range " , & m_bLongRange ) )
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
if ( ! m_bLongRange )
2021-07-30 18:01:17 -04:00
{
2020-12-02 16:19:16 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
2021-07-30 18:01:17 -04:00
}
2020-12-02 16:19:16 -05:00
}
2021-08-14 20:36:11 -04:00
# ifdef GTASA
2021-06-18 12:49:11 -04:00
if ( Ui : : CheckboxWithHint ( " Move when aiming " , & m_bMoveAim ) )
2020-12-28 15:12:40 -05:00
{
2021-06-18 12:49:11 -04:00
if ( ! m_bMoveAim )
2021-07-30 18:01:17 -04:00
{
2020-12-28 15:12:40 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
2021-07-30 18:01:17 -04:00
}
2020-12-28 15:12:40 -05:00
}
2021-06-18 12:49:11 -04:00
if ( Ui : : CheckboxWithHint ( " Move when firing " , & m_bMoveFire ) )
2020-12-28 15:12:40 -05:00
{
2021-06-18 12:49:11 -04:00
if ( ! m_bMoveFire )
2021-07-30 18:01:17 -04:00
{
2020-12-28 15:12:40 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
2021-07-30 18:01:17 -04:00
}
2020-12-28 15:12:40 -05:00
}
2021-06-18 12:49:11 -04:00
if ( Ui : : CheckboxWithHint ( " Rapid fire " , & m_bRapidFire ) )
2020-12-28 15:12:40 -05:00
{
2021-06-18 12:49:11 -04:00
if ( ! m_bRapidFire )
2021-07-30 18:01:17 -04:00
{
2020-12-28 15:12:40 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
2021-07-30 18:01:17 -04:00
}
2020-12-28 15:12:40 -05:00
}
2021-08-14 20:36:11 -04:00
# endif
2020-12-02 16:19:16 -05:00
ImGui : : Columns ( 1 , 0 , false ) ;
ImGui : : EndChild ( ) ;
ImGui : : EndTabItem ( ) ;
}
2021-08-14 20:36:11 -04:00
if ( ImGui : : BeginTabItem ( " Spawn " ) )
{
ImGui : : Spacing ( ) ;
if ( ImGui : : InputInt ( " Ammo " , & m_nAmmoCount ) )
{
m_nAmmoCount = ( m_nAmmoCount < 0 ) ? 0 : m_nAmmoCount ;
m_nAmmoCount = ( m_nAmmoCount > 99999 ) ? 99999 : m_nAmmoCount ;
}
# ifdef GTASA
Ui : : DrawImages ( m_WesaponData , GiveWeaponToPlayer , nullptr ,
[ ] ( std : : string str ) { return m_WeaponData . m_pJson - > m_Data [ str ] . get < std : : string > ( ) ; } ,
[ ] ( std : : string str ) { return str ! = " 0 " ; /*Unarmed*/ }
) ;
# elif GTAVC
Ui : : DrawJSON ( m_WeaponData , GiveWeaponToPlayer , nullptr ) ;
# endif
ImGui : : EndTabItem ( ) ;
}
# ifdef GTASA
2020-12-02 16:19:16 -05:00
if ( ImGui : : BeginTabItem ( " Gang weapon editor " ) )
{
ImGui : : Spacing ( ) ;
2021-06-18 12:49:11 -04:00
Ui : : ListBox ( " Select gang " , Ped : : m_GangNames , m_nSelectedGang ) ;
2020-12-02 16:19:16 -05:00
ImGui : : Columns ( 3 , 0 , false ) ;
2021-06-18 12:49:11 -04:00
ImGui : : RadioButton ( " Weap 1 " , & m_nSelectedWeapon , 0 ) ;
2020-12-02 16:19:16 -05:00
ImGui : : NextColumn ( ) ;
2021-06-18 12:49:11 -04:00
ImGui : : RadioButton ( " Weap 2 " , & m_nSelectedWeapon , 1 ) ;
2020-12-02 16:19:16 -05:00
ImGui : : NextColumn ( ) ;
2021-06-18 12:49:11 -04:00
ImGui : : RadioButton ( " Weap 3 " , & m_nSelectedWeapon , 2 ) ;
2020-12-02 16:19:16 -05:00
ImGui : : Columns ( 1 ) ;
ImGui : : Spacing ( ) ;
2021-06-18 12:49:11 -04:00
ImGui : : Text ( " Current weapon: %s " ,
2021-08-12 23:28:19 -04:00
m_WeaponData . m_pJson - > m_Data [ std : : to_string ( m_nGangWeaponList [ m_nSelectedGang ] [ m_nSelectedWeapon ] ) ] . get <
2021-08-06 11:53:18 -04:00
std : : string > ( ) . c_str ( ) ) ;
2020-12-02 16:19:16 -05:00
ImGui : : Spacing ( ) ;
2021-08-13 13:45:56 -04:00
Ui : : DrawImages ( m_WeaponData , SetGangWeapon , nullptr ,
2021-08-12 23:28:19 -04:00
[ ] ( std : : string str ) { return m_WeaponData . m_pJson - > m_Data [ str ] . get < std : : string > ( ) ; } ,
2021-08-06 11:53:18 -04:00
[ ] ( std : : string str ) { return str ! = " -1 " ; /*Jetpack*/ }
2020-12-02 16:19:16 -05:00
) ;
ImGui : : EndTabItem ( ) ;
}
2021-08-14 20:36:11 -04:00
# endif
2020-12-02 16:19:16 -05:00
ImGui : : EndTabBar ( ) ;
}
}