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"
2020-12-02 16:19:16 -05:00
Weapon : : Weapon ( )
{
Events : : processScriptsEvent + = [ ]
{
2021-06-18 12:49:11 -04:00
if ( ! m_bImagesLoaded )
2021-02-24 16:54:45 -05:00
{
2021-06-18 12:49:11 -04:00
Util : : LoadTexturesInDirRecursive (
PLUGIN_PATH ( ( char * ) " CheatMenu \\ weapons \\ " ) , " .jpg " , Weapon : : m_WeaponData . m_Categories ,
Weapon : : m_WeaponData . m_ImagesList ) ;
m_bImagesLoaded = true ;
2021-02-24 16:54:45 -05:00
}
2021-06-18 12:49:11 -04:00
CPlayerPed * player = FindPlayerPed ( ) ;
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 ) )
CCamera : : m_bUseMouse3rdPerson = false ;
}
else
CCamera : : m_bUseMouse3rdPerson = true ;
}
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
{
auto weapon_type = player - > m_aWeapons [ slot ] . m_nType ;
2021-06-18 12:49:11 -04:00
CWeaponInfo * pweapon_info = CWeaponInfo : : GetWeaponInfo ( weapon_type , player - > GetWeaponSkill ( weapon_type ) ) ;
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
if ( m_bHugeDamage )
2021-01-07 16:07:45 -05:00
pweapon_info - > 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
{
pweapon_info - > m_fTargetRange = 1000.0f ;
pweapon_info - > m_fWeaponRange = 1000.0f ;
pweapon_info - > m_fAccuracy = 1.0f ;
2020-12-28 15:12:40 -05:00
pweapon_info - > m_nFlags . bReload2Start = true ;
2020-12-02 16:19:16 -05:00
}
2021-06-18 12:49:11 -04:00
if ( m_bRapidFire & & weapon_type ! = WEAPON_MINIGUN ) // mingun doesn't work with rapidfire
2020-12-28 15:12:40 -05:00
pweapon_info - > m_nFlags . bContinuosFire = true ;
2021-06-18 12:49:11 -04:00
if ( m_bDualWeild & & ( weapon_type = = WEAPON_PISTOL | | weapon_type = = WEAPON_MICRO_UZI | | weapon_type = =
WEAPON_TEC9 | | weapon_type = = WEAPON_SAWNOFF ) )
2020-12-28 15:12:40 -05:00
pweapon_info - > m_nFlags . bTwinPistol = true ;
2021-06-18 12:49:11 -04:00
if ( m_bMoveAim )
2020-12-28 15:12:40 -05:00
pweapon_info - > m_nFlags . bMoveAim = true ;
2021-06-18 12:49:11 -04:00
if ( m_bMoveFire )
2020-12-28 15:12:40 -05:00
pweapon_info - > m_nFlags . bMoveFire = true ;
2021-06-18 12:49:11 -04:00
m_nCurrentWeaponSlot = slot ;
2020-12-02 16:19:16 -05:00
}
} ;
}
Weapon : : ~ Weapon ( )
{
2021-06-18 12:49:11 -04:00
Util : : ReleaseTextures ( Weapon : : m_WeaponData . m_ImagesList ) ;
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 ] ,
m_nGangWeaponList [ m_nSelectedGang ] [ 2 ] ) ;
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
Command < Commands : : TASK_JETPACK > ( hplayer ) ;
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-06-18 12:49:11 -04:00
CStreaming : : RequestModel ( 364 , PRIORITY_REQUEST ) ; // detonator
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
Command < Commands : : MARK_MODEL_AS_NO_LONGER_NEEDED > ( 364 ) ; // detonator
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-02-24 16:54:45 -05:00
void Weapon : : Draw ( )
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
CPlayerPed * player = FindPlayerPed ( ) ;
2020-12-02 16:19:16 -05:00
uint hplayer = CPools : : GetPedRef ( player ) ;
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 ) ;
auto type = player - > m_aWeapons [ player - > m_nActiveWeaponSlot ] . m_nType ;
2021-06-18 12:49:11 -04:00
2020-12-02 16:19:16 -05:00
if ( type )
{
2021-06-18 12:49:11 -04:00
int model = 0 , pickup = 0 ;
2020-12-02 16:19:16 -05:00
Command < Commands : : GET_WEAPONTYPE_MODEL > ( type , & model ) ;
Command < Commands : : CREATE_PICKUP_WITH_AMMO > ( model , 3 , 999 , x , y , z , & pickup ) ;
Command < Commands : : REMOVE_WEAPON_FROM_CHAR > ( hplayer , type ) ;
}
}
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Remove all " , Ui : : GetSize ( 3 ) ) )
Command < Commands : : REMOVE_ALL_CHAR_WEAPONS > ( hplayer ) ;
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Remove current " , Ui : : GetSize ( 3 ) ) )
Command < Commands : : REMOVE_WEAPON_FROM_CHAR > ( hplayer , player - > m_aWeapons [ player - > m_nActiveWeaponSlot ] . m_nType ) ;
ImGui : : Spacing ( ) ;
if ( ImGui : : BeginTabBar ( " Ped " , ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll ) )
{
if ( ImGui : : BeginTabItem ( " Checkboxes " ) )
{
ImGui : : Spacing ( ) ;
ImGui : : BeginChild ( " CheckboxesChild " ) ;
ImGui : : Columns ( 2 , 0 , false ) ;
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 ,
" 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 )
2020-12-28 15:12:40 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
}
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 )
2020-12-02 16:19:16 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
}
2021-06-18 12:49:11 -04:00
if ( Ui : : CheckboxWithHint ( " Fast reload " , & m_bFastReload ) )
Command < Commands : : SET_PLAYER_FAST_RELOAD > ( hplayer , m_bFastReload ) ;
2020-12-02 16:19:16 -05:00
Ui : : CheckboxAddress ( " Infinite ammo " , 0x969178 ) ;
2020-12-28 15:12:40 -05:00
ImGui : : NextColumn ( ) ;
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 )
2020-12-02 16:19:16 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
}
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 )
2020-12-28 15:12:40 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
}
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 )
2020-12-28 15:12:40 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
}
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 )
2020-12-28 15:12:40 -05:00
CWeaponInfo : : LoadWeaponData ( ) ;
}
2020-12-02 16:19:16 -05:00
ImGui : : Columns ( 1 , 0 , false ) ;
ImGui : : EndChild ( ) ;
ImGui : : EndTabItem ( ) ;
}
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 " ,
m_WeaponData . m_Json . m_Data [ std : : to_string ( m_nGangWeaponList [ m_nSelectedGang ] [ m_nSelectedWeapon ] ) ] . get <
std : : string > ( ) . c_str ( ) ) ;
2020-12-02 16:19:16 -05:00
ImGui : : Spacing ( ) ;
2021-06-18 12:49:11 -04:00
Ui : : DrawImages ( m_WeaponData . m_ImagesList , ImVec2 ( 65 , 65 ) , m_WeaponData . m_Categories , m_WeaponData . m_Selected ,
m_WeaponData . m_Filter , SetGangWeapon , nullptr ,
[ ] ( std : : string str ) { return m_WeaponData . m_Json . m_Data [ str ] . get < std : : string > ( ) ; } ,
[ ] ( std : : string str ) { return str ! = " -1 " ; /*Jetpack*/ }
2020-12-02 16:19:16 -05:00
) ;
ImGui : : EndTabItem ( ) ;
}
if ( ImGui : : BeginTabItem ( " Spawn " ) )
{
ImGui : : Spacing ( ) ;
2021-06-18 12:49:11 -04:00
if ( ImGui : : InputInt ( " Ammo " , & m_nAmmoCount ) )
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
m_nAmmoCount = ( m_nAmmoCount < 0 ) ? 0 : m_nAmmoCount ;
m_nAmmoCount = ( m_nAmmoCount > 99999 ) ? 99999 : m_nAmmoCount ;
2020-12-02 16:19:16 -05:00
}
2021-06-18 12:49:11 -04:00
Ui : : DrawImages ( m_WeaponData . m_ImagesList , ImVec2 ( 65 , 65 ) , m_WeaponData . m_Categories , m_WeaponData . m_Selected ,
m_WeaponData . m_Filter , GiveWeaponToPlayer , nullptr ,
[ ] ( std : : string str ) { return m_WeaponData . m_Json . m_Data [ str ] . get < std : : string > ( ) ; } ,
[ ] ( std : : string str ) { return str ! = " 0 " ; /*Unarmed*/ }
2020-12-02 16:19:16 -05:00
) ;
ImGui : : EndTabItem ( ) ;
}
ImGui : : EndTabBar ( ) ;
}
}