Updated gdc-psyfork with current (NPOTB).
Updated gdc-psyfork with current (NPOTB).
- Added support for custom symbols.txt path (-s <path>).
- Added support for dlsym symbol lookup in linux bins (-n).
- Updated gdc_core.sh example script to account for new options above.
- Updated symbols.txt.
1.1 --- a/tools/gdc-psyfork/example-scripts/gdc_core.sh Sun Jan 06 09:35:22 2013 -0500
1.2 +++ b/tools/gdc-psyfork/example-scripts/gdc_core.sh Mon Jan 07 09:09:14 2013 -0500
1.3 @@ -8,6 +8,9 @@
1.4 GAME_BIN=${ENGINE_PATH}/${GAME_DIR}/bin/server
1.5 STEAMINF=${ENGINE_PATH}/${GAME_DIR}/steam.inf
1.6
1.7 +GDC_PATH=${SM_PATH}/tools/gdc-psyfork
1.8 +GDC_BIN=${GDC_PATH}/Release/gdc
1.9 +
1.10 if [ "${GAMEDATA_DIR}" == "" ] ; then
1.11 GAMEDATA_DIR=${GAME_DIR}
1.12 fi
1.13 @@ -107,16 +110,34 @@
1.14 hg pull -u
1.15
1.16 echo -e "\n"
1.17 +
1.18 +cd ${ENGINE_PATH}
1.19 +
1.20 for i in "${gamedata_files[@]}"
1.21 do
1.22 - ./Release/gdc \
1.23 - -g ${GAME_DIR} \
1.24 - -e ${ENGINE_NAME} \
1.25 - -f ${SM_PATH}/gamedata/$i \
1.26 - -b ${GAME_BIN}${BIN_EXT}.so \
1.27 - -x ${ENGINE_BIN}${BIN_EXT}.so \
1.28 - -w ${GAME_BIN}.dll \
1.29 - -y ${ENGINE_BIN}.dll
1.30 + NO_SYMTABLE=
1.31 +
1.32 + readelf --sections ${GAME_BIN}${BIN_EXT}.so | grep --quiet .symtab
1.33 + if [ "${PIPESTATUS[1]}" != "0" ] ; then
1.34 + NO_SYMTABLE=" -n"
1.35 + fi
1.36 +
1.37 + readelf --sections ${GAME_BIN}${BIN_EXT}.so | grep --quiet .strtab
1.38 + if [ "${PIPESTATUS[1]}" != "0" ] ; then
1.39 + NO_SYMTABLE=" -n"
1.40 + fi
1.41 +
1.42 + # having an issue upon exit after loading some source2007 server bins, invalid free in sendtable dtor, idk. suppress.
1.43 + MALLOC_CHECK_=0 ${GDC_BIN} \
1.44 + -g ${GAMEDATA_DIR} \
1.45 + -e ${ENGINE_NAME} \
1.46 + -f ${SM_PATH}/gamedata/$i \
1.47 + -b ${GAME_BIN}${BIN_EXT}.so \
1.48 + -x ${ENGINE_BIN}${BIN_EXT}.so \
1.49 + -w ${GAME_BIN}.dll \
1.50 + -y ${ENGINE_BIN}.dll \
1.51 + -s ${GDC_PATH}/symbols.txt \
1.52 + ${NO_SYMTABLE}
1.53 echo -e "------------------------------------------------------\n"
1.54 done
1.55
2.1 --- a/tools/gdc-psyfork/gdc.cpp Sun Jan 06 09:35:22 2013 -0500
2.2 +++ b/tools/gdc-psyfork/gdc.cpp Mon Jan 07 09:09:14 2013 -0500
2.3 @@ -16,12 +16,23 @@
2.4 char *engine_binary = NULL;
2.5 char *wgame_binary = NULL;
2.6 char *wengine_binary = NULL;
2.7 +char *symbols_file = NULL;
2.8 +
2.9 +bool use_symtab = true;
2.10
2.11 inline bool IsDigit( char c )
2.12 {
2.13 return c < 58 && c > 47;
2.14 }
2.15
2.16 +void PrintUsage()
2.17 +{
2.18 + printf("Usage: ./gdc -g <game> -e <engine name> -f <gamedata file> -b <game binary> -x <engine binary> -w <win game binary> -y <win engine binary> [-s <symbols.txt file>]\n");
2.19 + printf("Other options:\n");
2.20 + printf(" -d\tAdd debug output\n");
2.21 + printf(" -n\tDon't use symbol table for lookups (falls back to dlsym)\n");
2.22 +}
2.23 +
2.24 int main(int argc, char **argv)
2.25 {
2.26 char *gamedata = NULL;
2.27 @@ -29,12 +40,18 @@
2.28
2.29 opterr = 0;
2.30 int opt;
2.31 - while ((opt = getopt(argc, argv, "b:de:f:g:x:w:y:")) != -1)
2.32 + while ((opt = getopt(argc, argv, "b:nde:f:g:x:w:y:s:")) != -1)
2.33 + {
2.34 switch (opt)
2.35 {
2.36 case 'd':
2.37 debug = true;
2.38 break;
2.39 +
2.40 + case 'n':
2.41 + use_symtab = false;
2.42 + break;
2.43 +
2.44 case 'g':
2.45 game = optarg;
2.46 break;
2.47 @@ -63,18 +80,23 @@
2.48 wengine_binary = optarg;
2.49 break;
2.50
2.51 + case 's':
2.52 + symbols_file = optarg;
2.53 + break;
2.54 +
2.55 case '?':
2.56 - printf("Usage: ./gdc -g <game> -e <engine name> -f <gamedata file> -b <game binary> -x <engine binary> -w <win game binary> -y <win engine binary>\n");
2.57 + PrintUsage();
2.58 return 0;
2.59
2.60 default:
2.61 printf("WHAT\n");
2.62 return 0;
2.63 }
2.64 + }
2.65
2.66 if (!game || !engine || !gamedata || !game_binary || !engine_binary || !wgame_binary || !wengine_binary)
2.67 {
2.68 - printf("Usage: ./gdc -g <game> -e <engine name> -f <gamedata file> -b <game binary> -x <engine binary> -w <win game binary> -y <win engine binary>\n");
2.69 + PrintUsage();
2.70 return 0;
2.71 }
2.72
2.73 @@ -125,7 +147,7 @@
2.74 }
2.75
2.76 CGameConfig symbols;
2.77 - if (!symbols.EnterFile("symbols.txt", err, sizeof(err)))
2.78 + if (!symbols.EnterFile(symbols_file ? symbols_file : "symbols.txt", err, sizeof(err)))
2.79 {
2.80 printf("symbols.txt: %s\n", err);
2.81 return 0;
2.82 @@ -178,8 +200,17 @@
2.83 int newOffset;
2.84 if (symvt[0])
2.85 {
2.86 - void **newvt = (void**) mu.ResolveSymbol(ghandle, symvt);
2.87 - if (!newvt)
2.88 + void **newvt = NULL;
2.89 + if( use_symtab )
2.90 + {
2.91 + newvt = (void**)mu.ResolveSymbol(ghandle, symvt);
2.92 + }
2.93 + else
2.94 + {
2.95 + newvt = (void **)dlsym(ghandle, symvt);
2.96 + }
2.97 +
2.98 + if (!newvt)
2.99 {
2.100 printf("? O: %-22s - can't find, skipping\n", symvt);
2.101 continue;
2.102 @@ -362,13 +393,15 @@
2.103
2.104 int checkSigStringL(void *handle, const char* symbol)
2.105 {
2.106 - bool isAt = (symbol[0] == '@');
2.107 + bool isAt = (symbol[0] == '@' && symbol[1] != '\0');
2.108 int matches = 0;
2.109 bool dummy;
2.110
2.111 if (isAt)
2.112 {
2.113 - if( mu.ResolveSymbol(handle, symbol + 1) )
2.114 + if( use_symtab && mu.ResolveSymbol(handle, &symbol[1]) )
2.115 + matches = 1;
2.116 + else if( !use_symtab && dlsym(handle, &symbol[1]) )
2.117 matches = 1;
2.118 }
2.119 else
2.120 @@ -403,15 +436,30 @@
2.121
2.122 int findVFunc(void *handle, void **vt, const char *symbol)
2.123 {
2.124 - int offset = 1;
2.125 + if( !use_symtab )
2.126 + {
2.127 + for (int i = 0; i < 1000; i++ )
2.128 + {
2.129 + void *pFunc = vt[i];
2.130 + if( !pFunc )
2.131 + continue;
2.132 +
2.133 + if( pFunc == dlsym(handle, symbol ) )
2.134 + return i - 2;
2.135 + }
2.136 +
2.137 + return -1;
2.138 + }
2.139 +
2.140 int funcPos, paramPos;
2.141 findFuncPos(symbol, funcPos, paramPos);
2.142
2.143 -
2.144 -
2.145 for (int i = 0; i < 1000; i++)
2.146 {
2.147 void *pFunc = vt[i];
2.148 + if( !pFunc )
2.149 + continue;
2.150 +
2.151 const char *s;
2.152
2.153 if (!(s = mu.ResolveAddr(handle, pFunc)))
2.154 @@ -426,12 +474,11 @@
2.155
2.156 if (strcmp(s + tempFuncPos, symbol + funcPos) == 0)
2.157 {
2.158 - offset = i;
2.159 - break;
2.160 + return i - 2;
2.161 }
2.162 }
2.163
2.164 - return offset - 2;
2.165 + return -1;
2.166 }
2.167
2.168 unsigned int strncopy(char *dest, const char *src, size_t count)
3.1 --- a/tools/gdc-psyfork/symbols.txt Sun Jan 06 09:35:22 2013 -0500
3.2 +++ b/tools/gdc-psyfork/symbols.txt Mon Jan 07 09:09:14 2013 -0500
3.3 @@ -76,6 +76,7 @@
3.4 "ShouldGib" "_ZN9CTFPlayer9ShouldGibERK15CTakeDamageInfob"
3.5 "GetRadius" "_ZN13CTFBaseRocket9GetRadiusEv"
3.6 "DeflectPlayer" "_ZN13CTFWeaponBase13DeflectPlayerEP9CTFPlayerS1_R6VectorS3_S3_"
3.7 + "GetDataDescMap" "_ZN11CBaseEntity14GetDataDescMapEv"
3.8
3.9 // CSSDM
3.10 "IPointsForKill" "_ZN14CTeamplayRules14IPointsForKillEP11CBasePlayerS1_"
3.11 @@ -84,6 +85,12 @@
3.12
3.13 // NapalmLagFix
3.14 "RadiusDamage" "_ZN10CGameRules12RadiusDamageERK15CTakeDamageInfoRK6VectorfiP11CBaseEntity"
3.15 +
3.16 + // V
3.17 + "CTFFlameThrower::FireProjectile" "_ZN16CTFWeaponBaseGun14FireProjectileEP9CTFPlayer"
3.18 + "CTFFlameThrower::FireFlameRocket" "_ZN16CTFWeaponBaseGun15FireFlameRocketEP9CTFPlayer"
3.19 + "CTFPlayer::GetMaxHealth" "_ZNK11CBaseEntity12GetMaxHealthEv"
3.20 + "CBaseEntity::GetBaseEntity" "_ZN11CBaseEntity13GetBaseEntityEv"
3.21 }
3.22
3.23 "Options"
3.24 @@ -180,4 +187,17 @@
3.25 "GiveNamedItem" "_ZN11CBasePlayer13GiveNamedItemEPKcib"
3.26 }
3.27 }
3.28 +
3.29 + "#default"
3.30 + {
3.31 + "#supported"
3.32 + {
3.33 + "game" "synergy"
3.34 + }
3.35 +
3.36 + "Keys"
3.37 + {
3.38 + "GiveNamedItem" "_ZN11CBasePlayer13GiveNamedItemEPKcib"
3.39 + }
3.40 + }
3.41 }