From dc58bf328a6e234c40473e9c8b41815e164a70fd Mon Sep 17 00:00:00 2001 From: ineed bots Date: Fri, 1 Dec 2023 14:27:20 -0600 Subject: [PATCH] add cod4x io builtins --- maps/mp/bots/_bot_utility.gsc | 48 +++++++++++++++++++++++++++++++++++ scripts/bots_adapter.gsc | 28 +++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/maps/mp/bots/_bot_utility.gsc b/maps/mp/bots/_bot_utility.gsc index cc8225f..5baca93 100644 --- a/maps/mp/bots/_bot_utility.gsc +++ b/maps/mp/bots/_bot_utility.gsc @@ -129,6 +129,54 @@ BotBuiltinIsBot() return false; } +/* + Opens the file +*/ +BotBuiltinFileOpen( file, mode ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fs_fopen"] ) ) + { + return [[ level.bot_builtins["fs_fopen" ]]]( file, mode ); + } + + return 0; +} + +/* + Closes the file +*/ +BotBuiltinFileClose( fh ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fs_fclose"] ) ) + { + [[ level.bot_builtins["fs_fclose" ]]]( fh ); + } +} + +/* + Closes the file +*/ +BotBuiltinReadLine( fh ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fs_readline"] ) ) + { + return [[ level.bot_builtins["fs_readline" ]]]( fh ); + } + + return undefined; +} + +/* + Closes the file +*/ +BotBuiltinWriteLine( fh, contents ) +{ + if ( isDefined( level.bot_builtins ) && isDefined( level.bot_builtins["fs_writeline"] ) ) + { + [[ level.bot_builtins["fs_writeline" ]]]( fh, contents ); + } +} + /* Returns if player is the host */ diff --git a/scripts/bots_adapter.gsc b/scripts/bots_adapter.gsc index 961338d..a5f2508 100644 --- a/scripts/bots_adapter.gsc +++ b/scripts/bots_adapter.gsc @@ -9,6 +9,10 @@ init() level.bot_builtins["botmovement"] = ::do_botmovement; level.bot_builtins["botmoveto"] = ::do_botmoveto; level.bot_builtins["isbot"] = ::do_isbot; + level.bot_builtins["fs_fopen"] = ::do_fs_fopen; + level.bot_builtins["fs_fclose"] = ::do_fs_fclose; + level.bot_builtins["fs_readline"] = ::do_fs_readline; + level.bot_builtins["fs_writeline"] = ::do_fs_writeline; } do_printconsole( s ) @@ -24,7 +28,7 @@ do_filewrite( file, contents, mode ) // always adds newline, strip from contents if ( contents[contents.size - 1] == "\n" ) { - contents = getsubstr(contents, 0, contents.size - 1); + contents = getsubstr( contents, 0, contents.size - 1 ); } FS_WriteLine( f, contents ); @@ -79,3 +83,25 @@ do_isbot() { return self.isbot; } + +do_fs_fopen( file, mode ) +{ + file = "scriptdata/" + file; + return FS_FOpen( file, mode ); +} + +do_fs_fclose( file ) +{ + file = "scriptdata/" + file; + FS_FClose( file ); +} + +do_fs_readline( fh ) +{ + return FS_ReadLine( fh ); +} + +do_fs_writeline( fh, contents ) +{ + FS_WriteLine( fh, contents ); +}