Raised This Month: $51 Target: $400
 12% 

Solved Orpheu & WeaponBox


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-14-2018 , 18:37   Orpheu & WeaponBox
Reply With Quote #1

Hi,

I'm trying to create a custom made entity, such as in fy_ maps, no, I'm not going with armoury_entity.
I decided to use Orpheu and learn in the meantime, but after all I'm still a beginner with it.
Why does this code give me an AK47? I'm trying to make it spawn an AK47 in my origin not give me it.. What am I missing?

PHP Code:
#include < amxmodx >
#include < fakemeta >
#include < engine >
#include < cstrike >
#include < hamsandwich >
#include < orpheu >

#define XO_CWEAPONBOX 4 

const m_iId 43;

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",  """"
}

public 
plugin_init( )
{
    
register_clcmd"say /create""OnCreate" );
}

public 
OnCreateid )
{
    new 
Float:fOrigin];
    
pevidpev_originfOrigin );

    new 
iClassString engfuncEngFunc_AllocString"weaponbox" );
    new 
iWeaponEntity create_entity"weapon_ak47" );

    new 
OrpheuFunction:HandleCreateNamedEntityFunc OrpheuGetFunction"CREATE_NAMED_ENTITY" );
    new 
iEntity OrpheuCallHandleCreateNamedEntityFunciClassString );

    new 
OrpheuFunction:HandlePackWeaponFunc;
    
HandlePackWeaponFunc OrpheuGetFunction"PackWeapon""CWeaponBox" );

    
OrpheuCallHandlePackWeaponFunciEntityiWeaponEntity );
    
set_pdata_intiWeaponEntitym_iIdcs_get_weapon_idiWeaponEntity ), XO_CWEAPONBOX );
    
    new 
iWeaponId cs_get_weapon_idiWeaponEntity );
    if( 
WeaponBoxModelsiWeaponId ][ ] != EOS )
    {
        
engfuncEngFunc_SetModeliWeaponEntityWeaponBoxModelsiWeaponId ] );
        
        
ExecuteHamHam_SpawniWeaponEntity );
        
set_peviWeaponEntitypev_originfOrigin );
    }

Thanks!
__________________

Last edited by edon1337; 07-15-2018 at 08:56.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-14-2018 , 18:48   Re: Orpheu & WeaponBox
Reply With Quote #2

I'm on phone so I can't properly check but maybe it's because you set it on player origin and touch is instantly triggered.
__________________

Last edited by HamletEagle; 07-14-2018 at 18:48.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-14-2018 , 19:14   Re: Orpheu & WeaponBox
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
I'm on phone so I can't properly check but maybe it's because you set it on player origin and touch is instantly triggered.
I'm using the same code and it's not doing anything now, lol..
I could swear it was giving me an AK47 before when I'd say /create now it does nothing, no errors I'll try again tomorrow, maybe I'm too tired
__________________

Last edited by edon1337; 07-14-2018 at 19:15.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-15-2018 , 04:00   Re: Orpheu & WeaponBox
Reply With Quote #4

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 #5

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
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-15-2018 , 05:21   Re: Orpheu & WeaponBox
Reply With Quote #6

Quote:
Basically I need to start using other sources such as ReGameDLL to see what actually happens with the entities that I work with.
For sure. Even if you don't use regamedll, it helps to see how the game does certain things.

Quote:
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.
https://asherkin.github.io/vtable/ this works for GoldSource too. Just drag and drop cs.so in that site.
Unfortunately you need to get used to working with IDA if you want to make signatures.
The vtable dumper will only provide you with the offsets for the virtual functions. If it's not virtual you need to use IDA and create a signature.

In virtualFunctions you put any function that's virtual. To properly understand what a virtual function is you would need knowledge of object oriented programming. Without that, what you can do is use the vtable dumper and see if you find a certain function. If you do, it's virtual. If you don't it's a regular function.
Another way is to check RegameDLL in *.h files. For example if you want to know the virtual functions for CBasePlayer you would look in player.h
https://github.com/s1lentq/ReGameDLL.../player.h#L329 inside CBasePlayer class. If it has "virtual" in front then it's virtual.
For example:
PHP Code:
virtual void TraceAttack(entvars_t *pevAttackerfloat flDamageVector vecDirTraceResult *ptrint bitsDamageType); 
is virtual.
PHP Code:
void AddAccount(int amountbool bTrackChange true); 
is not virtual and needs a signature.

Don't bother with types and memory folders for now.
__________________

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

Quote:
Originally Posted by HamletEagle View Post
For sure. Even if you don't use regamedll, it helps to see how the game does certain things.

https://asherkin.github.io/vtable/ this works for GoldSource too. Just drag and drop cs.so in that site.
Unfortunately you need to get used to working with IDA if you want to make signatures.
The vtable dumper will only provide you with the offsets for the virtual functions. If it's not virtual you need to use IDA and create a signature.

In virtualFunctions you put any function that's virtual. To properly understand what a virtual function is you would need knowledge of object oriented programming. Without that, what you can do is use the vtable dumper and see if you find a certain function. If you do, it's virtual. If you don't it's a regular function.
Another way is to check RegameDLL in *.h files. For example if you want to know the virtual functions for CBasePlayer you would look in player.h
https://github.com/s1lentq/ReGameDLL.../player.h#L329 inside CBasePlayer class. If it has "virtual" in front then it's virtual.
For example:
PHP Code:
virtual void TraceAttack(entvars_t *pevAttackerfloat flDamageVector vecDirTraceResult *ptrint bitsDamageType); 
is virtual.
PHP Code:
void AddAccount(int amountbool bTrackChange true); 
is not virtual and needs a signature.

Don't bother with types and memory folders for now.
It's giving me 'Failed to find all required ELF sections.' when I upload cs.so

And that's a lot easier, I'm not thinking of making signatures at this time, there's plenty in the forum. So basically I get to know that CWeaponBox:Kill is a non-virtual function and requires a signature from this https://github.com/s1lentq/ReGameDLL...pons.cpp#L1583

Is every single game function inside these files? Does it mean I can find any function that I'm using and see whether it's virtual or not by using ReGameDLL?
__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-15-2018 , 06:09   Re: Orpheu & WeaponBox
Reply With Quote #8

Quote:
And that's a lot easier, I'm not thinking of making signatures at this time, there's plenty in the forum. So basically I get to know that CWeaponBox:Kill is a non-virtual function and requires a signature from this https://github.com/s1lentq/ReGameDLL...pons.cpp#L1583
You should look in the *.h file, not *.cpp. https://github.com/s1lentq/ReGameDLL...weapons.h#L466

Quote:
Is every single game function inside these files? Does it mean I can find any function that I'm using and see whether it's virtual or not by using ReGameDLL?
In most cases yes. The RegameDLL guys did add a lot of things and the code will not mimic the original valve code 100% anymore. But it should be all under some #ifndef REGAMEDLL_API or #ifndef REGAMEDLL. Just ignore this parts of the code and you should be good.
__________________
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-15-2018 , 06:37   Re: Orpheu & WeaponBox
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
You should look in the *.h file, not *.cpp. https://github.com/s1lentq/ReGameDLL...weapons.h#L466



In most cases yes. The RegameDLL guys did add a lot of things and the code will not mimic the original valve code 100% anymore. But it should be all under some #ifndef REGAMEDLL_API or #ifndef REGAMEDLL. Just ignore this parts of the code and you should be good.
PHP Code:
virtual void Killed(entvars_t *pevAttackerint iGib); 
but I have it in orpheu/functions/CWeaponBox !?

Doesn't being a virtual function mean being in orpheu/virtualFunctions ?
__________________

Last edited by edon1337; 07-15-2018 at 06:38.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-15-2018 , 07:17   Re: Orpheu & WeaponBox
Reply With Quote #10

Quote:
Originally Posted by edon1337 View Post
PHP Code:
virtual void Killed(entvars_t *pevAttackerint iGib); 
but I have it in orpheu/functions/CWeaponBox !?

Doesn't being a virtual function mean being in orpheu/virtualFunctions ?
You are looking at the wrong class. This one is from class CGrenade, but you want CWeaponBox class.
__________________

Last edited by HamletEagle; 07-15-2018 at 07:18.
HamletEagle 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 08:21.


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