Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Renaming all variables within a script? (Via code)

Asked by 7 years ago

Basically, I am creating a Lua script obfuscator for a client of mine, who wants his game to break if the place ID is wrong, which will be checked at random points within every script (and every script will be heavily obfuscated).

Now, I have successfully done many, many things such as fluff code, comments and whitespace stripping, and even renaming local variables and a somewhat-sorta- custom virtual machine to execute the code. However, I'm stumped as to how to do this with globals, as to not cause it to mess up changing properties? I.e. Humanoid.jfrdkwfkdf = 100; instead of Humanoid.Health by accident, if you get what I mean. There must be a simple way to do this and I must just be having a brainfart. Any ideas?

function Utilities:RenameVariables(Type)
    if (Type == "Locals") then
        for String in Script:gmatch("local%s+(%w+)") do
            local CurrentStringToReplace = String;
            Script = Script:gsub(String, SecondaryUtilities:GenerateRandomVariableName(math.random(5, 20)));
        end;
    elseif (Type == "Globals") then

    end;
end;

That is the relevant function. I tried string patterns to make sure you weren't setting a property, etc, and it failed horribly.

Answer this question