User:Blocco/VideoBypass

From Legacy Roblox Wiki
Jump to navigationJump to search
local lookupTable={};
for i = 0, 25 do
	lookupTable[i] = string.char(i+65);
end
for i = 26, 51 do
	lookupTable[i] = string.char(i+71);
end
for i = 52, 61 do
	lookupTable[i] = string.char(i-4);
end
lookupTable[62] = "+";
lookupTable[63] = "/";
lookupTable[64] = "="; -- for padding

local enhancedLookup=function(val)
	local rVal = lookupTable[val];
	if rVal then return rVal end
	for i, v in pairs(lookupTable) do
		if v == val then return (i == 64 and 0 or i) end
	end
	return nil;
end

local isValidChar=function(mode, char)
	if mode == "Encode" then return string.byte(char) < 256;
	elseif mode == "Decode" then return enhancedLookup(char) ~= nil;
	end
end

local octetToNumber = function(str)
	assert(type(str) == "string", "String expected in octetToNumber (got type " .. type(str) .. ")");
	assert(#str == 3, "octet expected, got length of " .. #str);
	for char in str:gmatch(".") do assert(isValidChar("Encode", char), "invalid character") end
	return string.byte(str:sub(1, 1))*2^16 + string.byte(str:sub(2, 2))*2^8 + string.byte(str:sub(3, 3))*2^0
end

local Base64={};
Base64.Encode=function(str)
	-- get each octet and convert it into four characters via lookup table
	local b64Str="";
	local it=0;
	for octet in str:gmatch("...") do
		it=it+1;
		local octet=octetToNumber(octet);
		local chars={};
		chars[1] = math.floor(octet/2^(6*3));
		chars[2] = math.floor(octet/2^(6*2)) - chars[1]*2^(6*1);
		chars[3] = math.floor(octet/2^(6*1)) - (chars[1]*2^(6*2) + chars[2]*2^(6*1));
		chars[4] = math.floor(octet/2^(6*0)) - (chars[1]*2^(6*3) + chars[2]*2^(6*2) + chars[3]*2^(6*1));
		table.foreachi(chars, function(i, v) chars[i] = enhancedLookup(v) end)
		b64Str = b64Str .. table.concat(chars, "");
	end
	local leftOver=str:sub(it*3+1);
	if #leftOver > 0 then
		leftOver = leftOver .. string.rep("\0", 3-#leftOver)
		local octet = octetToNumber(leftOver);
		local chars={};
		chars[1] = math.floor(octet/2^(6*3));
		chars[2] = math.floor(octet/2^(6*2)) - chars[1]*2^(6*1);
		chars[3] = math.floor(octet/2^(6*1)) - (chars[1]*2^(6*2) + chars[2]*2^(6*1));
		chars[4] = math.floor(octet/2^(6*0)) - (chars[1]*2^(6*3) + chars[2]*2^(6*2) + chars[3]*2^(6*1));
		table.foreachi(chars, function(i, v) chars[i] = ((v == 0 and i > 2) and enhancedLookup(64) or enhancedLookup(v)) end)
		b64Str = b64Str .. table.concat(chars, "");
	end
	local fixedStr="";
	local it2=0;
	for longSection in b64Str:gmatch(string.rep(".", 64)) do
		it2 = it2+1;
		fixedStr = fixedStr .. longSection .. "\r\n";
	end
	fixedStr = fixedStr:sub(1, -2);
	fixedStr = fixedStr .. b64Str:sub(it2*64+1);
	return fixedStr;
end

local videoWidth = 213;
local videoHeight = 150;

local sourceTemp = "data:text/html;base64,%s";
local embedUrlTemp = "http://www.youtube.com/embed/%s";
local embedCodeTemp = "<iframe width=\"%d\" height=\"%d\" src=\"%s\" frameborder=\"0\" allowfullscreen></iframe>";
local redirectTemp = '<script>window.location.replace("%s")</script>';

function GetEmbeddedVideo(videoId)
	return embedCodeTemp:format(videoWidth, videoHeight, sourceTemp:format(Base64.Encode(redirectTemp:format(embedUrlTemp:format(videoId))):gsub("[\r\n]", "")));
end

local copyValue=Instance.new("StringValue");
copyValue.Name = "Copy Value";

function _G.GetBypassVideo(videoId)
	copyValue.Value = GetEmbeddedVideo(videoId);
	game.Selection:Set({copyValue})
end

print("ChatToWatch.lua loaded, to use do:  _G.GetBypassVideo(string videoId);")