AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question about read_argv / read_args (https://forums.alliedmods.net/showthread.php?t=272442)

Max3 09-30-2015 13:28

Question about read_argv / read_args
 
Hi.

Can read_argv or read_args values be changed? I want to replace the value provided by read_argv/read_args with another value (string).

Let's have this as an example:
PHP Code:

public func_a_b_c(id)
{
    new 
some_data[32], some_info[32];
    
    
read_argv(0some_datacharsmax(some_data)); // => some_data = "example"
    
read_argv(1some_infocharsmax(some_info)); // => some_info = "98765"
    
    
new new_data[] = "whatever"
    
new new_info[] = "123456"
    
    
// Patch arguments
    // There is no set_argv or set_args, this is just an example!
    
set_argv(0new_datacharsmax(new_data));
    
set_argv(1new_infocharsmax(new_info));
    
    
// Now read_argv 0 or 1 should provide the new data/info
    
read_argv(0some_datacharsmax(some_data)); // some_data = "whatever"
    
read_argv(1some_infocharsmax(some_info)); // some_info = "123456"


Is this possible? If yes, how?

Thank you.

jimaway 09-30-2015 13:55

Re: Question about read_argv / read_args
 
xy problem

please explain what are you trying to do

Max3 09-30-2015 14:44

Re: Question about read_argv / read_args
 
As I said, I only want to replace a string, provided by read_argv or read_args, with another string. So, next time when read_argv or read_args it's called it will provide the new string and not the old one.
Like get_arg and set_arg (Dynamic number of arguments in functions) but for read_argv or read_args.

fysiks 09-30-2015 20:56

Re: Question about read_argv / read_args
 
Simply edit the code to use your string instead.

If that's not the answer then:
Quote:

Originally Posted by jimaway (Post 2348440)
please explain what are you trying to do


Max3 09-30-2015 23:54

Re: Question about read_argv / read_args
 
No, I can not modify the string directly because the string I needed is provided by read_argv or read_args and if the string matches with one string pattern I need to replace this string with another.

Another explanation:
Do you know get_arg? I think you know. You can set the value from get_arg using set_arg. So, I need a function (like set_arg) that do the same but for read_argv or read_args. I hope it's clearly now. Pay attention to the first code please and you will understant .

Thank you.

fysiks 10-01-2015 00:29

Re: Question about read_argv / read_args
 
Quote:

Originally Posted by Max3 (Post 2348551)
I hope it's clearly now. Pay attention to the first code please and you will understant.

No, your examples makes no sense. Explain what you actually want to do.

Max3 10-01-2015 02:58

Re: Question about read_argv / read_args
 
WHAT THE HELL!!!

Let's say we have 2 function that hook client_command.

First plugin:
PHP Code:

#include<amxmodx>

new new_laser_cmd[] = "+set_my_laser";

public 
plugin_init()
{
    
register_plugin("Plugin1 - Patch""1.0""");
}

public 
client_command(id)
{
    new 
command[32],

    
read_argv(0commandcharsmax(command));
    
    if (
equali(command"+setlaser"))
    {
        
// Patch that read_argv(0, _, _)
      // This function doesn't exists or I am not awared of it
      // This will set the first argument into new_laser_cmd ("+set_my_laser")
        
set_argv(0new_laser_cmdcharsmax(new_laser_cmd))
    }
    return 
PLUGIN_CONTINUE;


Second plugin:
PHP Code:

#include<amxmodx>

new new_laser_cmd[] = "+set_my_laser";

public 
plugin_init()
{
    
register_plugin("Plugin2 - The actual plugin""1.0""");
}

public 
client_command(id)
{
    new 
command[32],

    
read_argv(0commandcharsmax(command)); // now command is not +setlaser, it's +set_my_laser because we patched it in the first plugin
    
    
if (equali(commandnew_laser_cmd))
    {
        
set_laser(idcommand);
    }
    return 
PLUGIN_CONTINUE;


The first plugin replace "+setlaser" with "+set_my_laser" because that's why I wanted! The second one, the actual plugin, will not read "+setlaser" anymore, but instead of it will read "+set_my_laser" (because we replaced/patched it in first plugin).

This is just an example! So don't ask me to use client_cmd instead of patching!

I hope this time you will understand what I want!

So, there is such method or no? Doens't matter if I need to use orpheu to patch that. I really need a method to do that.

Max3 10-02-2015 12:57

Re: Question about read_argv / read_args
 
Nobody?

Ok. Let's take another approach. Do you know a method like "engclient_cmd" for server (which I don't need to use id)? Because engclient_cmd(0, "command") don't work.

native engclient_cmd(index, const command[], const arg1[] = "", const arg2[] = "");
-> something like this:
native engsrv_cmd(const command[], const arg1[] = "", const arg2[] = "");
?

HamletEagle 10-02-2015 13:29

Re: Question about read_argv / read_args
 
If you want to change the command just edit the plugin. If you do not have the source code, don't use the plugin.

Edit: read_argv uses pfnCmd_Argv, which is an engine exported function. With orpheu you may be able to hook the function and alter it's value when it is called. Look at this example(note that I am not sure what you want to do, so I don't know what snippet to give you, look at the example and try to make what you need to).

PHP Code:

#include <amxmodx>
#include <orpheu>
#include <orpheu_stocks>

new OrpheuHook:HandleCmd_ArgvHook

public plugin_init()
{
    
register_clcmd("test""ClientCommand_Test")
}

public 
ClientCommand_Test(id)
{
    new 
Argument[32]
    
HandleCmd_ArgvHook OrpheuRegisterHook(OrpheuGetEngineFunction("pfnCmd_Argv""ReadArgv"), "pfnCmd_Argv")
    
read_argv(1Argumentcharsmax(Argument))
    
server_print("Got: %s"Argument)
}

public 
OrpheuHookReturn:pfnCmd_Argv(Argc)
{
    
OrpheuSetReturn("SomeRandomReturnHere")
    
OrpheuUnregisterHook(HandleCmd_ArgvHook)
    return 
OrpheuOverride


Signature:
Code:

{
    "name" : "ReadArgv",
    "library" : "engine",
    "arguments" :
    [
        {
            "type" : "int"
        }
    ],
    "return" :
    {
        "type" : "char *"
    }
}

So let's say you write test 123, and the value returned by read_argv should be 123. Well, the snippet change it to SomeRandomReturnHere and that is what you will get.

Max3 10-02-2015 13:40

Re: Question about read_argv / read_args
 
I said I can't, the command is provided by read_argv / read_args. You can change the client command using engclient_cmd (I forgot to say in #7 I can't use engclient_cmd), but how to change it when there is no id?


All times are GMT -4. The time now is 22:15.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.