• What exactly is "detouring" something? and how to properly size/position VGUI.
    7 replies, posted
What exactly is detouring a string/function and how can it be used efficiently?
Elaborate, and give examples. So far this is what I see about what you've so far explained. [url]http://puu.sh/pJDNI/3d89e8a687.png[/url]
[QUOTE=RedXVIII;50613188]Elaborate, and give examples.[/QUOTE] For example. I see posts about watching out for someone detouring RunString.
I mean In my perspective I see no reason why to use [url=https://wiki.garrysmod.com/page/Global/RunString]RunString[/url].
when you want to control a certain piece of code or situation in the game, you often use a hook for example, whenever a player tries to freeze something with his physgun, you might want to add code that happens, so you would [url=https://wiki.garrysmod.com/page/GM/OnPhysgunFreeze]use the hook for that[/url] to intercept that action to insert custom code some things you find yourself wanting to do will not have a hook already made for you to do so with but there is some function somewhere in the game code that manages the action detouring (or overriding) a function means to replace a function of the game's code with your own replacement so for example: if you wanted to change the displayed name of a certain user in the server, how would you go about it? you don't simply have control over their steam name you might try using the chat box hooks, but that would only take care of the chat, and not the name you see on-screen when aiming at a player instead of trying to change each of these areas of code one by one, you might instead realize that all code involving a player's name finds that name by going ply:Nick() the player entity class has what is called a metatable, which is in this case something that every newly created player entity uses to call player-based functions if you call ply:Nick(), the truth is that the function doesn't really exist as a part of the ply, but rather the ply metatable that every ply object in the server is tied to so, to override all code involving player names, you simply overwrite the player metatable's Nick function: [code] local plyMeta = FindMetaTable("Player") local oldNick = plyMeta.Nick function plyMeta:Nick() if self:SteamID() == "STEAM_blahblahblah" then return "butts" end return oldNick(self) end [/code] the oldNick was created storing the original ply.Nick function, because ply.Nick is defined in the game engine; the lua environment we use to mod the game has no access to the steam player name, only the original Nick function can do that (so it is backed up first that way players can still be seen as their steam names if their steamID isn't STEAM_blahblahblah)
[QUOTE=Matsumoto;50613201]For example. I see posts about watching out for someone detouring RunString.[/QUOTE] Detouring means backing up the function in some local variable [code] local _RunString = RunString [/code] and replacing with your own implementation [code] function RunString(a, b, c) return _RunString(a, b, c) end [/code]
[QUOTE=bitches;50613230]-snip-[/QUOTE] Thank you, that just cleared up so much. So pretty much if you just want to take out something or add something before the function is ran? If so then my previous post asking why my code wasn't working was pretty much detouring? [lua]local o_cc_run = concommand.Run function concommand.Run(...) PrintTable({...}) return o_cc_run(...) end[/lua]
Ah I get it.
Sorry, you need to Log In to post a reply to this thread.