home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / IKLOWNS / CGCHRINT.CPP < prev    next >
C/C++ Source or Header  |  1996-08-28  |  4KB  |  142 lines

  1. /*===========================================================================*\
  2. |
  3. |  File:        cgchrint.cpp
  4. |
  5. |  Description: 
  6. |       
  7. |-----------------------------------------------------------------------------
  8. |
  9. |  Copyright (C) 1995-1996 Microsoft Corporation.  All Rights Reserved.
  10. |
  11. |  Written by Moss Bay Engineering, Inc. under contract to Microsoft Corporation
  12. |
  13. \*===========================================================================*/
  14.  
  15. /**************************************************************************
  16.  
  17.     (C) Copyright 1995-1996 Microsoft Corp.  All rights reserved.
  18.  
  19.     You have a royalty-free right to use, modify, reproduce and 
  20.     distribute the Sample Files (and/or any modified version) in 
  21.     any way you find useful, provided that you agree that 
  22.     Microsoft has no warranty obligations or liability for any 
  23.     Sample Application Files which are modified. 
  24.  
  25.     we do not recomend you base your game on IKlowns, start with one of
  26.     the other simpler sample apps in the GDK
  27.  
  28.  **************************************************************************/
  29.  
  30. #include <windows.h>
  31. #ifdef __WATCOMC__
  32. #include "mem.h"
  33. #else
  34. #include "memory.h"
  35. #endif
  36. #include "cgchdll.h"
  37. #include "cglevel.h"
  38. #include "cgchar.h"
  39. #include "cgchrint.h"
  40. #include "cginput.h"
  41.  
  42. // for now, only allow up to 9 DLLs (plus the internal list)
  43. #define GAME_INFO_MAX 10
  44. static int gameInfoCount = 0;       // none loaded yet
  45. static CGameInfo gameInfo[GAME_INFO_MAX];
  46.  
  47. static CGameInfo gInternalCharInfo = 
  48. {
  49.     0, 
  50.     NULL
  51. };
  52.  
  53. void    LoadCharInfo( CGameInfo * info )
  54. {
  55.     if ( gameInfoCount == GAME_INFO_MAX )
  56.         return;
  57.  
  58.     // scans 'info' for chars; adds them to our internal list of love
  59.     if ( info == NULL ) {
  60.         // NULL means load internal characters
  61.         info = &gInternalCharInfo;
  62.     }
  63.     // add the info ptr to our internal table
  64.     gameInfo[gameInfoCount] = *info;
  65.     ++gameInfoCount;
  66. }
  67.  
  68. CGameCharInfo *FindCharInfo( char *name )
  69. {
  70.     static CGameCharInfo *lastFound = NULL;
  71.  
  72.     CGameCharInfo *result = NULL;
  73.     int     x,
  74.             y;
  75.     int     found = 0;
  76.  
  77.     // first off - is this the same as the last one?
  78.         if (lastFound && (lstrcmpi(name, lastFound->name)==0))
  79.     {
  80.         result = lastFound;
  81.         ++found;
  82.     }
  83.     else
  84.     {
  85.         // scan to find a character in the list(s)
  86.         for ( x = 0; x < gameInfoCount; x++ ) {
  87.             for ( y = 0; y < gameInfo[x].numcharacters; y++ ) {
  88.                 result = gameInfo[x].characters[y];
  89.                                 if ( lstrcmpi( result->name, name ) == 0)
  90.                 {
  91.                     ++ found;
  92.                     lastFound = result;
  93.                     break;
  94.                 }
  95.             }
  96.             if (found) break;
  97.         }
  98.     }
  99.  
  100.     if ( !found )
  101.         result = NULL;
  102.  
  103.     return ( result );
  104. }
  105.  
  106. void    LoadMyDLL( char *path, char *name )
  107. {
  108.     char   *p;
  109.     char    thename[260];
  110.     CGameVersionIdent ident;
  111.     CGameInfo info;
  112.     int     (CALLBACK *fpIdent ) ( CGameVersionIdent * );
  113.     int     (CALLBACK *fpInfo ) ( CGameInfo * );
  114.  
  115.     lstrcpy( thename, path );
  116.     p = strrchr( thename, '/' );
  117.     if ( p == NULL )
  118.         p = strrchr( thename, '\\' );
  119.     if ( p == NULL )
  120.         lstrcat( thename, "\\" );
  121.     else
  122.         *( p + 1 ) = 0;
  123.  
  124.     lstrcat( thename, name );
  125.  
  126.         HINSTANCE  hlib = LoadLibrary( thename );
  127.  
  128.     if ( hlib != NULL ) {
  129.         fpIdent = ( int (CALLBACK * ) ( CGameVersionIdent * ) ) GetProcAddress( hlib, MAKEINTRESOURCE( EXPORTED_IDENT ) );
  130.         if ( fpIdent != NULL ) {
  131.             ( *fpIdent ) ( &ident );
  132.             if ( ( ident.version == RELEASE1_0 ) && ( ident.id == GAMEID ) ) {
  133.                 fpInfo = ( int ( CALLBACK * ) ( CGameInfo * ) ) GetProcAddress( hlib, MAKEINTRESOURCE( EXPORTED_INFO ) );
  134.                 if ( fpInfo != NULL ) {
  135.                     ( *fpInfo ) ( &info );
  136.                     LoadCharInfo( &info );
  137.                 }
  138.             }
  139.         }
  140.     }
  141. }
  142.