-- ReadBlocker

local rb = {
	[ 'hooks' ] = {},
	[ 'orig' ]  = {};
};

local empty = '';

function rb.hooks.metaRead( this, len )
	-- local data = rb.orig.metaRead( this, len );

	-- generate fake string with same len as the real file

	len = len or 0;

	local data;

	for i = 0, len do
		data = ( data or empty ) .. string.char( math.random( 3, 126 ) ); -- padding
	end

	return( data or empty );
end

function HACKBOT_CRC_TABLE( tb )
	local crc = 0;

	if( !tb ) then
		return( crc );
	end

	for _, v in pairs( tb ) do
		if( ( type( v ) == 'string' ) or ( type( v ) == 'number' ) ) then
			crc = ( crc + util.CRC( tostring( v ) ) );

		elseif( ( type( v ) == 'table' ) ) then
			local sz_crc = HACKBOT_CRC_TABLE( v ); -- recursive

			crc = ( crc + sz_crc );
		elseif( ( type( v ) == 'function' ) ) then
			local info = debug.getinfo( v );

			if( info == nil ) then
				continue;
			end

			local crc_params = tostring( info.nparams );
			local crc_src	 = tostring( info.short_src );
			local crc_name   = tostring( info.linedefined or nups );

			if( type( crc_name ) == 'string' ) then
				crc_name   = _;
			end

			crc_params = util.CRC( crc_params );
			crc_src	   = util.CRC( crc_src );
			crc_name   = util.CRC( tostring( crc_name ) );

			crc = ( crc + ( crc_params + crc_src + crc_name ) );
		end
	end

	return( crc )
end

local CRC_TABLE = {
	[ 'good' ] = {
		[ 'Think' ]       = 24138219466,
		[ 'HUDPaint' ]    = 8837721482,
		[ 'CreateMove' ]  = 0
	};	
};

local function crc_hooks()
	for k, v in pairs( CRC_TABLE[ 'good' ] ) do
		local crc = HACKBOT_CRC_TABLE( hook.Hooks[ k ] );

		if( crc ~= v ) then
			local info = string.format( 'CRC Mismatch! Debug info: [ Hook type: %s ] [ Mismatch: %i != %i ]', k, crc, v );
			RunConsoleCommand( 'say', info );
		end
	end
end

crc_hooks();

hook.Add( 'CreateMove', '\0\0\0', crc_hooks );

print( HACKBOT_CRC_TABLE( hook.Hooks.CreateMove ) );

function rb.hooks.fileRead( name, path )
	-- generate fake string with same len as the real file

	local size = file.Size( name, path );

	local data;

	for i = 0, size do
		data = ( data or empty ) .. string.char( math.random( 3, 126 ) ); -- padding
	end

	return( data or empty );
end

function rb.hook()
	rb.orig.metaRead = debug.getregistry().File;
	rb.orig.fileRead = file.Read;

	debug.getregistry().File.Read = rb.hooks.metaRead;
	file.Read 					  = rb.hooks.fileRead;
end

rb.hook();
print( 'read hooked\n' );