Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Trying creating a WebView. CE faild to load libraries.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Apr 25, 2020 9:58 am    Post subject: Trying creating a WebView. CE faild to load libraries. Reply with quote

I am trying to make Web Page Viewer adapted to CE Lua scripting environments.
I made ones using Lua 5.3.5 scripting and using WebView.dll + Cjson.dll from Lua JLS 5.3.5 as framework libraries. It's work fine when execute using Lua 5.3.5

Code:
-- test.lua (webview script Lua 5.3.5 example)

local webviewLib = require('webview')

-- Default web content
local url = [[data:text/html,<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="top" href="./index.php?sid=ab3b4da2ec9bef9773a781137cad6616" title="Cheat Engine Forum Index" />

--- some HTML code until...

</html>
]]


local requestFunctionMap = {
  fullscreen = function(value, _, _, _, webview)
   webviewLib.fullscreen(webview, value == 'true')
  end,

  title = function(value, _, _, _, webview)
    webviewLib.title(webview, value)
  end,

  terminate = function(_, _, _, _, webview)
    webviewLib.terminate(webview, true)
  end,

  evalLua = function(value, evalJs, callJs, context, webview)
    local f, err = load('local evalJs, callJs, context, webview = ...; '..value)
    if f then
      return f(evalJs, callJs, context, webview)
    else
      print('Error', err, 'while loading', value)
    end
  end,

  evalJs = function(value, _, _, _, webview)
    webviewLib.eval(webview, value, true)
  end,
}

-- Parse command line arguments
local urlArg = arg[1]
if urlArg and urlArg ~= '' then
  if urlArg == '-h' or urlArg == '/?' or urlArg == '--help' then
    print('Launchs a WebView using the specified URL')
    print('Optional arguments: url title width height resizable')
    os.exit(0)
  end
  local protocol = string.match(urlArg, '^([^:]+):.+$')
  if protocol == 'http' or protocol == 'https' or protocol == 'file' or protocol == 'data' then
    url = urlArg
  elseif string.match(urlArg, '^.:\\.+$') or string.match(urlArg, '^/.+$') then
    url = 'file://'..tostring(urlArg)
  else
    print('Invalid URL, to launch a file please use an absolute path')
    os.exit(22)
  end
end
local title = arg[2] or 'Web View'
local width = arg[3] or 800
local height = arg[4] or 600
local resizable = arg[5] ~= 'false'
local verbose = arg[6] == 'true'

-- Creates the web view
local webview = webviewLib.new(url, title, width, height, resizable)

-- Defines a context that will be shared across Lua calls
local context = {}

-- Setup a Lua function to evaluates JS code
local function evalJs(value)
  webviewLib.eval(webview, value, true)
end

-- Setup a Lua function to call JS function,
-- the Lua function arguments are JSON encoded then passed to the JS function
local callJs, jsonLibLoaded, jsonLib
jsonLibLoaded, jsonLib = pcall(require, 'cjson')
if not jsonLibLoaded then
  jsonLibLoaded, jsonLib = pcall(require, 'dkjson')
end
if not jsonLibLoaded then
  print('Fail to find suitable JSON Lua module')
  jsonLib = nil
end
if jsonLib then
  callJs = function(functionName, ...)
    local args = {...}
    local jsArgs = {}
    for _, arg in ipairs(args) do
      table.insert(jsArgs, jsonLib.encode(arg))
    end
    local jsString = functionName..'('..table.concat(jsArgs, ',')..')'
    webviewLib.eval(webview, jsString, true)
  end
end

-- Registers the web view callback that handles the JS requests coming from window.external.invoke()
webviewLib.callback(webview, function(request)
  local flag, name, value = string.match(request, '^([%+%-%*]?)([^:]+):(.*)$')
  if name then
    if flag == '' then
      -- Look for the specified request
      local fn = requestFunctionMap[name]
      if fn then
        if verbose then
          print('Calling '..name..' with', value)
        end
        local s, r = pcall(fn, value, evalJs, callJs, context, webview, jsonLib)
        if not s then
          print('Fail to execute '..name..' due to', r)
        end
      else
        print('Unknown function', name)
      end
    elseif flag == '-' then
      requestFunctionMap[name] = nil
    elseif flag == '+' or flag == '*' then
      -- Registering the new request using the specified Lua code
      local injected = 'local value, evalJs, callJs, context, webview = ...; '
      if flag == '*' then
        injected = 'local jsonValue, evalJs, callJs, context, webview, jsonLib = ...; local value = jsonLib.decode(jsonValue); '
      end
      local fn, err = load(injected..value)
      requestFunctionMap[name] = fn
      if fn then
        if verbose then
          print('Loaded '..name..' as', value)
        end
      else
        print('Error', err, 'while loading', value)
      end
    else
      print('Invalid flag', flag)
    end
  else
    print('Invalid request', request)
  end
end)

-- Runs the web view event loop
webviewLib.loop(webview)


-- result as attached image

Problem:

Can not use in CE 7.1 : event webview.dll has placed on CE clibs32 or clibs64 folder (I am on windows 7 64bit)

Code:
local webviewLib = require('webview')   -- failed to load or not found

-- or maybe use: (?)

package.loadlib('E:\\ webview.dll','luaopen_webview')


Any solutions?



Capture.JPG
 Description:
 Filesize:  78.05 KB
 Viewed:  2058 Time(s)

Capture.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 472

Joined: 09 May 2003
Posts: 25874
Location: The netherlands

PostPosted: Sat Apr 25, 2020 10:07 am    Post subject: Reply with quote

compile webview with the help of ce lua's .lib files
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Apr 26, 2020 1:55 am    Post subject: Reply with quote

Thanks, DB for the solution. In case when trying compile webview source + CE lua53-64.lib using MSVC Compiler, I got many warnings and errors (maybe because I don't know how to do that properly), then I made an HTML renderer to an image app using C#, it works just fine.

Considering this topic: https://forum.cheatengine.org/viewtopic.php?p=5760315#5760315
Also able to use third-party app names IECapt for an easier solution.

Regards

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites