Raised This Month: $ Target: $400
 0% 

Solved Orpheu & WeaponBox


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-15-2018 , 04:00   Re: Orpheu & WeaponBox
Reply With Quote #1

Here you have a working code(you weren't far from the truth, just some small mistakes)
PHP Code:
#include < amxmodx > 
#include < fakemeta > 
#include < engine > 
#include < cstrike > 
#include < hamsandwich > 
#include < orpheu > 
#include <orpheu_advanced>

#define XO_CWEAPONBOX 4  

const m_iId 43;
const 
m_pfnThink 4

new const WeaponBoxModels[ ][ ] = 

    
"""models/w_p228.mdl",  ""
    
"models/w_scout.mdl",  """models/w_xm1014.mdl"
    
"models/w_c4.mdl""models/w_mac10.mdl""models/w_aug.mdl"""
    
"models/w_elite.mdl""models/w_fiveseven.mdl",  "models/w_ump45.mdl",  
    
"models/w_sg550.mdl""models/w_galil.mdl",  "models/w_famas.mdl",  
    
"models/w_usp.mdl""models/w_glock18.mdl""models/w_awp.mdl",  
    
"models/w_mp5.mdl""models/w_m249.mdl",  "models/w_m3.mdl"
    
"models/w_m4a1.mdl""models/w_tmp.mdl""models/w_g3sg1.mdl",  
    
"""models/w_deagle.mdl""models/w_sg552.mdl""models/w_ak47.mdl"
    
"""models/w_p90.mdl",  """" 


new 
IntClassNameString
new OrpheuFunction:HandleCreateNamedEntityFunc
new OrpheuFunction:HandlePackWeaponFunc
new CWeaponBoxKill_Address

public plugin_init( ) 

    
register_clcmd("say /create""OnCreate")
    
register_clcmd("say /think""OnThink")
    
    
IntClassNameString engfunc(EngFunc_AllocString"weaponbox")
    
    
HandleCreateNamedEntityFunc OrpheuGetFunction("CREATE_NAMED_ENTITY")
    
HandlePackWeaponFunc        OrpheuGetFunction("PackWeapon""CWeaponBox")
    
    
CWeaponBoxKill_Address OrpheuGetFunctionAddress(OrpheuGetFunction("Kill""CWeaponBox"))


public 
OnCreateid 

    new 
Float:WeaponBoxOrigin[3
    new 
Origin[3]
    
get_user_origin(idOrigin3)
    
IVecFVec(OriginWeaponBoxOrigin)

    new 
WeaponBoxEntity  OrpheuCall(HandleCreateNamedEntityFuncIntClassNameString
    if(!
pev_valid(WeaponBoxEntity))
    {
        return 
0
    
}
    
    
engfunc(EngFunc_SetOriginWeaponBoxEntityWeaponBoxOrigin)
    
ExecuteHam(Ham_SpawnWeaponBoxEntity)
    
    new 
WeaponEntity create_entity("weapon_ak47")
    if(!
pev_valid(WeaponEntity))
    {
        
remove_entity(WeaponBoxEntity)
    }

    
ExecuteHam(Ham_SpawnWeaponEntity)
    new 
WeaponID cs_get_weapon_id(WeaponEntity)
    
    
OrpheuCall(HandlePackWeaponFuncWeaponBoxEntityWeaponEntity)
    if(
WeaponBoxModels[WeaponID][ ] != EOS 
    { 
        
engfuncEngFunc_SetModelWeaponBoxEntityWeaponBoxModels[WeaponID])
    } 
    
    
set_pdata_int(WeaponBoxEntitym_pfnThinkCWeaponBoxKill_Address0)
    
    return 
0

Note: you will see an extra step:
PHP Code:
CWeaponBoxKill_Address OrpheuGetFunctionAddress(OrpheuGetFunction("Kill""CWeaponBox"))
set_pdata_int(WeaponBoxEntitym_pfnThinkCWeaponBoxKill_Address0
The proper way to remove a weaponbox is to force it to think(by using call_think for example). This removes both the weaponbox and the weapon that's linked to it. If you use only remove_entity then you will remove the box but the weapon will remain, causing a memory leak.
call_think works because m_pfnThink is set by the game with the address of CWeaponBox::Kill functions.
If you remove the set_pdata_int and use call_think you will see it does nothing. So if you want to be able to properly remove the box you need to set m_pfnThink to the correct value.

Now, what was wrong with your code?
When you create the weapon_ak47 entity you never spawned it meaning this offsets were never set: https://github.com/s1lentq/ReGameDLL...pn_ak47.cpp#L5

You tried to do something, but it's wrong:
PHP Code:
 set_pdata_intiWeaponEntitym_iIdcs_get_weapon_idiWeaponEntity ), XO_CWEAPONBOX ); 
cs_get_weapon_id is using m_iId. So basically you were doing m_iId = m_iId and the offset had no value at that point. After executing spawn the offset has a valid value.

Now here:
PHP Code:
engfuncEngFunc_SetModeliWeaponEntityWeaponBoxModelsiWeaponId ] ); 
         
        
ExecuteHamHam_SpawniWeaponEntity ); 
        
set_peviWeaponEntitypev_originfOrigin ); 
You need to do this on the weaponbox entity, not on the weapon entity. The weaponbox is a box and the weapon is inside it. What you see on the ground is the weaponbox not the weapon.
__________________

Last edited by HamletEagle; 07-15-2018 at 04:10.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-15-2018 , 05:12   Re: Orpheu & WeaponBox
Reply With Quote #2

Quote:
Originally Posted by HamletEagle View Post
Here you have a working code(you weren't far from the truth, just some small mistakes)
PHP Code:
#include < amxmodx > 
#include < fakemeta > 
#include < engine > 
#include < cstrike > 
#include < hamsandwich > 
#include < orpheu > 
#include <orpheu_advanced>

#define XO_CWEAPONBOX 4  

const m_iId 43;
const 
m_pfnThink 4

new const WeaponBoxModels[ ][ ] = 

    
"""models/w_p228.mdl",  ""
    
"models/w_scout.mdl",  """models/w_xm1014.mdl"
    
"models/w_c4.mdl""models/w_mac10.mdl""models/w_aug.mdl"""
    
"models/w_elite.mdl""models/w_fiveseven.mdl",  "models/w_ump45.mdl",  
    
"models/w_sg550.mdl""models/w_galil.mdl",  "models/w_famas.mdl",  
    
"models/w_usp.mdl""models/w_glock18.mdl""models/w_awp.mdl",  
    
"models/w_mp5.mdl""models/w_m249.mdl",  "models/w_m3.mdl"
    
"models/w_m4a1.mdl""models/w_tmp.mdl""models/w_g3sg1.mdl",  
    
"""models/w_deagle.mdl""models/w_sg552.mdl""models/w_ak47.mdl"
    
"""models/w_p90.mdl",  """" 


new 
IntClassNameString
new OrpheuFunction:HandleCreateNamedEntityFunc
new OrpheuFunction:HandlePackWeaponFunc
new CWeaponBoxKill_Address

public plugin_init( ) 

    
register_clcmd("say /create""OnCreate")
    
register_clcmd("say /think""OnThink")
    
    
IntClassNameString engfunc(EngFunc_AllocString"weaponbox")
    
    
HandleCreateNamedEntityFunc OrpheuGetFunction("CREATE_NAMED_ENTITY")
    
HandlePackWeaponFunc        OrpheuGetFunction("PackWeapon""CWeaponBox")
    
    
CWeaponBoxKill_Address OrpheuGetFunctionAddress(OrpheuGetFunction("Kill""CWeaponBox"))


public 
OnCreateid 

    new 
Float:WeaponBoxOrigin[3
    new 
Origin[3]
    
get_user_origin(idOrigin3)
    
IVecFVec(OriginWeaponBoxOrigin)

    new 
WeaponBoxEntity  OrpheuCall(HandleCreateNamedEntityFuncIntClassNameString
    if(!
pev_valid(WeaponBoxEntity))
    {
        return 
0
    
}
    
    
engfunc(EngFunc_SetOriginWeaponBoxEntityWeaponBoxOrigin)
    
ExecuteHam(Ham_SpawnWeaponBoxEntity)
    
    new 
WeaponEntity create_entity("weapon_ak47")
    if(!
pev_valid(WeaponEntity))
    {
        
remove_entity(WeaponBoxEntity)
    }

    
ExecuteHam(Ham_SpawnWeaponEntity)
    new 
WeaponID cs_get_weapon_id(WeaponEntity)
    
    
OrpheuCall(HandlePackWeaponFuncWeaponBoxEntityWeaponEntity)
    if(
WeaponBoxModels[WeaponID][ ] != EOS 
    { 
        
engfuncEngFunc_SetModelWeaponBoxEntityWeaponBoxModels[WeaponID])
    } 
    
    
set_pdata_int(WeaponBoxEntitym_pfnThinkCWeaponBoxKill_Address0)
    
    return 
0

Note: you will see an extra step:
PHP Code:
CWeaponBoxKill_Address OrpheuGetFunctionAddress(OrpheuGetFunction("Kill""CWeaponBox"))
set_pdata_int(WeaponBoxEntitym_pfnThinkCWeaponBoxKill_Address0
The proper way to remove a weaponbox is to force it to think(by using call_think for example). This removes both the weaponbox and the weapon that's linked to it. If you use only remove_entity then you will remove the box but the weapon will remain, causing a memory leak.
call_think works because m_pfnThink is set by the game with the address of CWeaponBox::Kill functions.
If you remove the set_pdata_int and use call_think you will see it does nothing. So if you want to be able to properly remove the box you need to set m_pfnThink to the correct value.

Now, what was wrong with your code?
When you create the weapon_ak47 entity you never spawned it meaning this offsets were never set: https://github.com/s1lentq/ReGameDLL...pn_ak47.cpp#L5

You tried to do something, but it's wrong:
PHP Code:
 set_pdata_intiWeaponEntitym_iIdcs_get_weapon_idiWeaponEntity ), XO_CWEAPONBOX ); 
cs_get_weapon_id is using m_iId. So basically you were doing m_iId = m_iId and the offset had no value at that point. After executing spawn the offset has a valid value.

Now here:
PHP Code:
engfuncEngFunc_SetModeliWeaponEntityWeaponBoxModelsiWeaponId ] ); 
         
        
ExecuteHamHam_SpawniWeaponEntity ); 
        
set_peviWeaponEntitypev_originfOrigin ); 
You need to do this on the weaponbox entity, not on the weapon entity. The weaponbox is a box and the weapon is inside it. What you see on the ground is the weaponbox not the weapon.
Thanks a lot !

Basically I need to start using other sources such as ReGameDLL to see what actually happens with the entities that I work with.

All is left for me to do now is add ammo for the weapons that I create by using PackAmmo function from Orpheu.

All I'm struggling with is knowing signature's location, I'm still confused about whether a signature should go in functions, virtualFunctions, types, or memory. Is there any way without using the IDA? It's such a messy app. You mentioned to me Asherkin's vtable dumper but that's just for SourceMod files.
__________________
edon1337 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode