.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > SDK Programming discussions > Half-Life 1 SDK
Half-Life 1 SDK For developments focused around Half-Life (and its mods) Half-Life

Reply
 
Thread Tools
Re: [CZ] Changing model directory "on the fly"?
Old
  (#21)
Rusty Le Cyborg
Complete Amateur
 
Rusty Le Cyborg's Avatar
 
Status: Offline
Posts: 52
Join Date: May 2005
Default Re: [CZ] Changing model directory "on the fly"? - 03-07-2005

Okay. Thanks for going to all this trouble, it's much appreciated
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#22)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: [CZ] Changing model directory "on the fly"? - 04-07-2005

Np, though hl is fighting me along the way though lol.
I have it at the point where it should work but then I get a "bad character in client command" error when I join my server.

That makes absolutely no sense at all, the path only gets the mapname added to the start :/

What goes in: weapons/emp_1.wav
What comes out: 2fort/weapons/emp_1.wav

All is good, no precache errors, the file was checked to exist and I even unhooked EmitSound to be sure.

Heres it so far, I did some re-designing so only the sound stuff is in right now.
The plugin framework is turning out nice too, so much easier now
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mplugin.h"

// Converts forward slashes to backslashes so the paths
// work under win32
void LinuxToWinPath( char* pszPath, int nCount ) {
#ifdef _WIN32
   register int _nCount = nCount;   // I wonder if "register" actually does anything these days

   // Chose to use _nCount so hopefully the compiler would choose to
   // compare to registers rather than a memory location on each iteration.
   for ( register int i = 0; i < _nCount; i++ ) {
	  // Convert forward slashes to backslashes so
	  // this will work under windows
	  if ( pszPath[ i ] == '/' )
		 pszPath[ i ] = '\\';
   }
#endif
}

// NOTE:
// Make SURE pszSearchdir is set! ( ie. "sound" or "models" )
// Otherwise, fopen will fail and so will this function!
int CheckFileExists( const char* pszFile, const char* pszSearchdir ) {
   char szGamedir[ _MAX_PATH ];  // Mod root directory
   char szNewpath[ _MAX_PATH ];  // Where to look
   FILE* pFile = NULL;		   // Temporary file handle

   // Get the mod directory and setup our filename string
   GET_GAME_DIR( szGamedir );
   _snprintf( szNewpath, sizeof( szNewpath ), "%s\\%s\\%s", szGamedir, pszSearchdir, pszFile );

   // Make sure the slashes are right if running under win32
   // Note:
   // Under linux, the LinuxToWinPath function will do nothing. 
   LinuxToWinPath( szNewpath, strlen( szNewpath ) );

   // Attempt to open the file, if it exists pFile should be a valid pointer.
   if ( ( pFile = fopen( szNewpath, "rb" ) ) != NULL ) {
	  fclose( pFile );
	  return 1;
   }

   // Not found
   return 0;
}

// Old : weapons/dbarrel1.wav
// New : 2fort/weapons/dbarrel1.wav
int ChangeSearchPath( const char* pszFile, const char* pszSearchdir, char* pszNewpathbuf, size_t lMaxbuflen ) {
   char szNewpath[ _MAX_PATH ];

   // Add the mapname to the beginning of the string
   _snprintf( szNewpath, sizeof( szNewpath ), "%s/%s", STRING( gpGlobals->mapname ), pszFile );

   // If the file exists, give the caller the new path and return success
   if ( CheckFileExists( szNewpath, pszSearchdir ) == 1 ) {
	  strncpy( pszNewpathbuf, szNewpath, lMaxbuflen );
	  return 1;
   }

   // No updated version of this file
   return 0;
}

int PrecacheModel( char* pszModel ) {
   RETURN_META_VALUE( MRES_IGNORED, 1 );   
}
   
int PrecacheSound( char* pszSound ) {
   char szNewpath[ _MAX_PATH ];

 RETURN_META_VALUE( MRES_SUPERCEDE, ChangeSearchPath( pszSound, "sound", szNewpath, sizeof( szNewpath ) ) == 0 ? PRECACHE_SOUND( pszSound ) : PRECACHE_SOUND( szNewpath ) );
}
   
void SetModel( edict_t* pEntity, const char* pszModel ) {
   RETURN_META( MRES_IGNORED );
}

void EmitSound( edict_t* pEntity, int nChan, const char* pszSample, float flVolume, float flAttenuation, int iFlags, int iPitch ) {
   char szNewpath[ _MAX_PATH ];

 RETURN_META_VALUE( MRES_SUPERCEDE, ChangeSearchPath( pszSample, "sound", szNewpath, sizeof( szNewpath ) ) == 0 ? g_engfuncs.pfnEmitSound( pEntity, nChan, pszSample, flVolume, flAttenuation, iFlags, iPitch ) : g_engfuncs.pfnEmitSound( pEntity, nChan, szNewpath, flVolume, flAttenuation, iFlags, iPitch ) );
}

BEGIN_GIVEFNPTRSTODLL( )
END_GIVEFNPTRSTODLL( )

BEGIN_META_ATTACH( )
END_META_ATTACH( )

BEGIN_META_QUERY( )
END_META_QUERY( )

BEGIN_META_DETACH( )
END_META_DETACH( )

BEGIN_GETENGINEFUNCTIONS( )
   //HOOK_ENGINE_FN( pfnPrecacheModel, PrecacheModel );
   HOOK_ENGINE_FN( pfnPrecacheSound, PrecacheSound );
   //HOOK_ENGINE_FN( pfnEmitSound, EmitSound );
   //HOOK_ENGINE_FN( pfnSetModel, SetModel );
END_GETENGINEFUNCTIONS( )
It's 3:32am here and I'm just not seeing it, maybe someone knows why this is happening?

I put a breakpoint just before PrecacheSound returns, the updated path is normal with no unusual characters of any kind.
That is whats bothering me so much.

Only a small delay though, this will get fixed.
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#23)
Rusty Le Cyborg
Complete Amateur
 
Rusty Le Cyborg's Avatar
 
Status: Offline
Posts: 52
Join Date: May 2005
Default Re: [CZ] Changing model directory "on the fly"? - 04-07-2005

Hmm.. not being knowledgable about these things I had a look at Steampowered about this...and there was a particular support query about this...

Does this help?

http://steampowered.custhelp.com/cgi...i=&p_topview=1
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#24)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: [CZ] Changing model directory "on the fly"? - 04-07-2005

Thanks but the server is running on the same machine I play/develop on and the problem goes away when my code is disabled.

I'm going to take another look at it now but I can't see anything wrong.
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#25)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: [CZ] Changing model directory "on the fly"? - 04-07-2005

Lazy, for the player models, you will certainly need to set them in the client's key/value data.

Another tip, don't bother converting forward slashes to backwards slashes, even on Windows. Always use forward slashes, everywhere.

And at least one big mistake: define your local character arrays as static if you return pointers to them, else they are deallocated when the function exits.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#26)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: [CZ] Changing model directory "on the fly"? - 04-07-2005

I never return pointers to local variables, what I did is make the caller pass a pointer to it's own local variable which gets the new string copied into it.

And the only time I convert to backslashes is when I use fopen to check if the file exists or not, but I still have no idea why I'm getting this error.

OR, is hl keeping a pointer to szNewpath when I call PRECACHE_SOUND?
That would explain a lot but I'd assume it makes a copy first.

[Added]
Well, it looks like HL needs a copy of the string.
The problem was solved by changing szNewpath to STRING( ALLOC_STRING( szNewpath ) ).
Bah, I would never keep a string pointer like that.

Thanks PMB, now I can get back to finishing this thing

Last edited by Lazy; 04-07-2005 at 22:41..
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#27)
CyKo74
Member
 
CyKo74's Avatar
 
Status: Offline
Posts: 20
Join Date: Jul 2004
Location: CHICKaginsk
Default Re: [CZ] Changing model directory "on the fly"? - 05-07-2005

...And dont worry about register thingy. c & cpp copilers are "smart" enough to do it automaticaly. Check youreself by compiling & re-engeneering the output code. Btw why dont make those lil func's inline or macros?


...yet another internal vodka combustion evil machine...
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#28)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: [CZ] Changing model directory "on the fly"? - 05-07-2005

The only time I read code output was when I was trying to make my function hooking class, took me a long time to get it right but I finally got that JMP instruction to work

Anyway, which functions are you talking about?
The BEGIN_xxx functions are just macros that handle setting up the dll automatically and hooking various APIs.
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#29)
Rusty Le Cyborg
Complete Amateur
 
Rusty Le Cyborg's Avatar
 
Status: Offline
Posts: 52
Join Date: May 2005
Default Re: [CZ] Changing model directory "on the fly"? - 06-07-2005

Quote:
Originally Posted by Lazy

What goes in: weapons/emp_1.wav
What comes out: 2fort/weapons/emp_1.wav
Just a quick question (again!)

Having the directory structure like this will mean that your mod root directory will be rather full of "extra" entries...

Would it be better to have a new directory to dump your map specific models/sounds into?

Something like "MOD ROOT / lazy / %s / weapons / ..." etc or is that a different kettle of fish entirely?

Cheers for now
  
Reply With Quote
Re: [CZ] Changing model directory "on the fly"?
Old
  (#30)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: [CZ] Changing model directory "on the fly"? - 10-07-2005

I don't think its possible for sounds since hl will only play whats inside the sound directory and its subdirectories.
It used to be possible under won, in tfc I would have it speak sounds from cs under tfc by using something like ../../../../cstrike/sound/terwin and it worked for those who had cs installed.
But since steam that sort of thing wont work, which is why I chose that layout.
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com