Skip to content

Commit

Permalink
Add scandir(dirname) to CoDScript
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfooman committed Mar 22, 2014
1 parent 944a589 commit 530dcc2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions gsc.cpp
Expand Up @@ -152,6 +152,7 @@ Scr_Function scriptFunctions[] = {
{"stringToFloat" , gsc_utils_stringToFloat , 0},
{"rundll" , gsc_utils_rundll , 0},
{"Cmd_ExecuteString" , gsc_utils_ExecuteString , 0},
{"scandir" , gsc_utils_scandir , 0},
#endif

#if COMPILE_TCC == 1
Expand Down
7 changes: 4 additions & 3 deletions gsc.hpp
Expand Up @@ -187,14 +187,15 @@ int stackPushVector(float *ret);
int stackPushFloat(float ret);
int stackPushString(char *toPush);
int stackPushEntity(int arg);
int stackPushArray();
int stackPushArrayLast();

int stackCallScriptFunction(int self, int scriptFunction, int numberOfArgs);
int alloc_object_and_push_to_array();
int alloc_object_and_push_to_array(); // obsolete, use stackPushArray
int stackSetKeyInArray(int precachedStringOffset);
int push_previous_var_in_array_sub();
int push_previous_var_in_array_sub(); // obsolete, use stackPushArrayLast
int cdecl_injected_closer();


int sub_8101B40(int self, int eInflictor, int eAttacker, float *vDir, float *vPoint, int iDamage, int iDFlags, int iMeansOfDeath, int iHitLoc, int psOffsetTime);
int cdecl_cod2_player_damage_new(int self, int eInflictor, int eAttacker, float *vDir, float *vPoint, int iDamage, int iDFlags, int iMeansOfDeath, int iHitLoc, int psOffsetTime);

Expand Down
Empty file modified gsc_math.cpp 100644 → 100755
Empty file.
Empty file modified gsc_math.hpp 100644 → 100755
Empty file.
22 changes: 22 additions & 0 deletions gsc_utils.cpp
Expand Up @@ -2,6 +2,7 @@

#if COMPILE_UTILS == 1

#include <dirent.h> // dir stuff

// 1.2 0x080F6D5A
int utils_hook_player_eject(int player) { // player 0 = 0x08679380 + 0x11c = 0x0867949c
Expand Down Expand Up @@ -169,4 +170,25 @@ void gsc_utils_ExecuteString() {
stackPushInt(1);
}

void gsc_utils_scandir() {
char *dirname;
if ( ! stackGetParams((char *)"s", &dirname)) {
stackPushUndefined();
return;
}
DIR *dir;
struct dirent *dir_ent;
dir = opendir(dirname);
if ( ! dir) {
stackPushUndefined();
return;
}
stackPushArray();
while (dir_ent = readdir(dir)) {
stackPushString(dir_ent->d_name);
stackPushArrayLast();
}
closedir(dir);
}

#endif
1 change: 1 addition & 0 deletions gsc_utils.hpp
Expand Up @@ -27,6 +27,7 @@ void gsc_utils_getType();
void gsc_utils_stringToFloat();
void gsc_utils_rundll();
void gsc_utils_ExecuteString();
void gsc_utils_scandir();

#ifdef __cplusplus
}
Expand Down

0 comments on commit 530dcc2

Please sign in to comment.