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

Patch gpGlobals data


Post New Thread Reply   
 
Thread Tools Display Modes
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 09-24-2012 , 20:02   Re: Patch gpGlobals data
Reply With Quote #11

Quote:
Originally Posted by K.K.Lv View Post
More clear claudiuhks

edited:
native are unnecessary, use a file system is enough
I think you have to free the memory claudiuhks !
I don't know how, unfortunately. May you explain, please?

Edited: Today I learnt how to use pointers. Thanks for that observation you did.

By the way, more simple code here:

PHP Code:
#include <stdlib.h> /* malloc, free */

void PatchMapnamechar pName ) {
    
int Address reinterpret_cast int > ( gpGlobals -> pStringBase gpGlobals -> mapname );

    for( 
int i 0<= ( int ) strlenpName ); i++ )
        *( 
unsigned char * ) ( Address ) = pName];
}

void ServerActivate_Postedict_t *, intint ) {
    
char pName = ( char * ) malloc128 /* 128 characters is a good size to set */ );

    
sprintfpName"%s Bombardier"STRINGgpGlobals -> mapname ) );

    
PatchMapnamepName );

    
freepName );

    
RETURN_METAMRES_IGNORED );

__________________

Last edited by claudiuhks; 09-25-2012 at 00:30.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 09-25-2012 , 01:42   Re: Patch gpGlobals data
Reply With Quote #12

AFAIK, the max size of the map name is 32
so you needn't create a pointer, just a char var is nice
Code:
void ServerActivate_Post( edict_t *, int, int ) {     char szName[32];     _snprintf(szName, 31, "%s Bombardier", STRING( gpGlobals -> mapname ) );     PatchMapname(szName);     RETURN_META( MRES_IGNORED ); }
__________________
QQ:116268742

Last edited by K.K.Lv; 09-25-2012 at 01:43.
K.K.Lv is offline
Send a message via MSN to K.K.Lv
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 09-25-2012 , 09:55   Re: Patch gpGlobals data
Reply With Quote #13

Better to use pfnAllocString and set globals->mapname to the returned pointer .
This will avoid any problem with memory leaks and you don't need the PatchMapname function.

EDIT:

In HLSDK you can see an example at triggers.cpp (void NextLevel)

Code:
gpGlobals->mapname = ALLOC_STRING("start");
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.

Last edited by joropito; 09-25-2012 at 10:20.
joropito is offline
Send a message via MSN to joropito
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 09-25-2012 , 10:32   Re: Patch gpGlobals data
Reply With Quote #14

What's the difference between g_engfuncs.pfnAllocString( const char * ) and MAKE_STRING( const char * ) macro?
__________________

Last edited by claudiuhks; 09-25-2012 at 10:32.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 09-25-2012 , 10:40   Re: Patch gpGlobals data
Reply With Quote #15

Quote:
Originally Posted by claudiuhks View Post
What's the difference between g_engfuncs.pfnAllocString( const char * ) and MAKE_STRING( const char * ) macro?
Code:
#define STRING(offset)             (const char *)(gpGlobals->pStringBase + (int)offset)
#define MAKE_STRING(str)      ((int)str - (int)STRING(0))
Maybe similar but AllocString does a new alloc.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 09-26-2012 , 07:01   Re: Patch gpGlobals data
Reply With Quote #16

Quote:
Originally Posted by joropito View Post
Better to use pfnAllocString and set globals->mapname to the returned pointer .
This will avoid any problem with memory leaks and you don't need the PatchMapname function.

EDIT:

In HLSDK you can see an example at triggers.cpp (void NextLevel)

Code:
gpGlobals->mapname = ALLOC_STRING("start");
It doesn't work properly.
Or, it works maybe but not even like K.K.Lv's explanation.
__________________

Last edited by claudiuhks; 09-26-2012 at 07:01.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 09-26-2012 , 11:53   Re: Patch gpGlobals data
Reply With Quote #17

I have test joropito's before I post.
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 09-27-2012 , 10:20   Re: Patch gpGlobals data
Reply With Quote #18

Please post all gpGlobals datas
__________________
kiki33hun is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 09-27-2012 , 10:31   Re: Patch gpGlobals data
Reply With Quote #19

progdefs.h

PHP Code:
typedef struct {
    
float        time;
    
float        frametime;
    
float        force_retouch;
    
string_t    mapname;
    
string_t    startspot;
    
float        deathmatch;
    
float        coop;
    
float        teamplay;
    
float        serverflags;
    
float        found_secrets;
    
vec3_t        v_forward;
    
vec3_t        v_up;
    
vec3_t        v_right;
    
float        trace_allsolid;
    
float        trace_startsolid;
    
float        trace_fraction;
    
vec3_t        trace_endpos;
    
vec3_t        trace_plane_normal;
    
float        trace_plane_dist;
    
edict_t        *trace_ent;
    
float        trace_inopen;
    
float        trace_inwater;
    
int            trace_hitgroup;
    
int            trace_flags;
    
int            msg_entity;
    
int            cdAudioTrack;
    
int            maxClients;
    
int            maxEntities;
    const 
char    *pStringBase;
    
void        *pSaveData;
    
vec3_t        vecLandmarkOffset;
globalvars_t
__________________

Last edited by claudiuhks; 09-27-2012 at 10:33.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
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:29.


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