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 


CE Video Player

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

Joined: 10 Apr 2015
Posts: 1348

PostPosted: Thu Apr 23, 2020 8:17 am    Post subject: CE Video Player Reply with quote

Base on this topic: https://forum.cheatengine.org/viewtopic.php?t=613951

This is about how to make a video player using cheat engine 7.1 + Lua scripting.

I made this video player without any video player app. which binds to this CE project.

The project is pure using CE Lua scripting and calls winmm.dll mciSendString function as the library to control video player.

The video will play inside CE Panel boundaries.

This is a simple CE video player, which means by ignoring video aspect ratio in connection to fit the video frame inside the panel size or when change bound of the main form or the panel size.

Components used in this video form project are:
1. The main form (1)
2. Panel (1)
3. Buttons (4) for PLAY, STOP, PAUSE, and RESUME

Note:
By default the video player able to play media with format WMV, OGG, WMA, WAV (all media format support by windows). If you want to play Mpeg, mp4 format then you need to install windows codec pack.

Codec pack for windows 7 -- I am using Windows 7 enterprise.
https://www.windows7codecs.com/

K-Lite Codec pack
https://codecguide.com/download_k-lite_codec_pack_mega.htm

Download code CT file (5kb)
https://mega.nz/file/PlUVlSzR#eAnR5j7WPHJmfdfCUgzhQngQu_V2TC9i2wY87sK0pKc

Demo video:
https://youtu.be/mIGQ9_Bub8A


Full code example:

Code:
function ceVideoPlayer()
 if ceVideoPlayer_Loaded then
    return true
 end

local script64bit=[[loadlibrary(C:\Windows\System32\winmm.dll)
alloc(ce_VideoPlayer,4096)
registersymbol(ce_VideoPlayer)

ce_VideoPlayer:
lea rsp,[rsp-28]
lea rsi,[rcx+400]

lea rdx,[rcx+300]
mov r8d,80
xor r9d,r9d
call mciSendStringW
mov rcx,rax
mov rdx,rsi
mov r8,200
call mciGetErrorStringW

lea rsp,[rsp+28]
ret]]

local script32bit=[[loadlibrary(C:\Windows\System32\winmm.dll)
alloc(ce_VideoPlayer,4096)
registersymbol(ce_VideoPlayer)

ce_VideoPlayer:
push ebp
mov ebp,esp
push ebx

mov ebx,[ebp+8]

sub esp,10
mov [esp],ebx
lea ebx,[ebx+300]
mov [esp+4],ebx
mov [esp+8],80
mov [esp+c],0
call mciSendStringW

mov ebx,[ebp+8]
lea ebx,[ebx+400]

sub esp,0c
mov [esp],eax
mov [esp+0x4],ebx
mov [esp+0x8],200
call mciGetErrorStringW

pop ebx
leave
ret 004]]

if cheatEngineIs64Bit() then script = script64bit else script = script32bit end
 if autoAssemble(script,true) then
    ceVideoPlayer_Loaded=true
    msPlayerCommand=createMemoryStream()
    msPlayerCommand.Size=2048
    return true
  else
    return false
  end
end

function mciSendString(Command)
    writeStringLocal(msPlayerCommand.Memory, Command, true);
    writeBytesLocal (msPlayerCommand.Memory+2*#Command, 0, 0);
    executeCodeLocal('ce_VideoPlayer',msPlayerCommand.Memory);
    return readStringLocal(msPlayerCommand.Memory+1024,512,true),
           readStringLocal(msPlayerCommand.Memory+768,128,true)
end
-----------------------------------------------------------------
---- DO NOT CHANGE THE CODE ABOVE WITHOUT KNOWLEDGE ABOUT AA ----
-----------------------------------------------------------------


----# FUNCTION HANDLERS AND VARIABLES

local retVal = 0
local playing = false


function button1_click(sender)  -- play
 if not ceVideoPlayer() then return end
 local filename = "E:\\ONE OK ROCK - Wasted Nights.mp4"  -- change video source path here
 retVal = mciSendString("close movie", "", 0, 0)
 filename = string.char(34)..filename..string.char(34)
 retVal = mciSendString("open "..filename.." type mpegvideo alias movie parent "..tonumber(panel1.handle).." style child", "", 0, 0)
 retVal = mciSendString("play movie", "", 0, 0)
 playing = true
 iLeft = 0
 iTop = 0
 newWidth = panel1.Width
 newHeight = panel1.Height
 mciSendString("put movie window at "..iLeft.." "..iTop.." "..newWidth.." "..newHeight, "", 0, 0)
 button1.Enabled = false
end


function button2_click(sender)  -- stop
 if not ceVideoPlayer() then return end
 retVal = mciSendString("stop movie", "", 0, 0)
 retVal = mciSendString("close movie", "", 0, 0)
 playing = false
 button1.Enabled = true
end


function button3_click(sender)  -- pause
 if not ceVideoPlayer() then return end
 retVal = mciSendString("pause movie", "", 0, 0)
 playing = false
 button3.Enabled = false
end


function button4_click(sender)  -- pause
 if not ceVideoPlayer() then return end
 retVal = mciSendString("resume movie", "", 0, 0)
 playing = true
 button3.Enabled = true
end


function panel1_sizeChange()
 if playing then
    --SizeVideoWindow(panel1.getSize())
    iLeft = 0
    iTop = 0
    newWidth = panel1.Width
    newHeight = panel1.Height
    mciSendString("put movie window at "..iLeft.." "..iTop.." "..newWidth.." "..newHeight, "", 0, 0)
 end
end


function form_FormClosed(sender)
  if not ceVideoPlayer() then return end
  retVal = mciSendString("stop movie", "", 0, 0)
  retVal = mciSendString("close movie", "", 0, 0)
  closeCE()
  return caFree
end


----# GUI (SIMPLE)
if form then form.destroy() end

form = createForm()
form.setSize(600,500)
form.BorderStyle = 'bsSizeable'
form.Position = 'poScreenCenter'
form.Caption = 'CE Video Player - By Corroder (2020)'

panel1 = createPanel(form)
panel1.Width = 600
panel1.Height = 450
panel1.BorderStyle = 'bsSingle'
panel1.Anchors = '[akTop,akLeft,akRight,akBottom]'

button1 = createButton(form)
button1.setPosition(10, 460)
button1.setSize(100,30)
button1.Caption = 'Play'
button1.Anchors = '[akLeft,akBottom]'

button2 = createButton(form)
button2.setPosition(110, 460)
button2.setSize(100,30)
button2.Caption = 'Stop'
button2.Anchors = '[akLeft,akBottom]'

button3 = createButton(form)
button3.setPosition(210, 460)
button3.setSize(100,30)
button3.Caption = 'Pause'
button3.Anchors = '[akLeft,akBottom]'

button4 = createButton(form)
button4.setPosition(310, 460)
button4.setSize(100,30)
button4.Caption = 'Resume'
button4.Anchors = '[akLeft,akBottom]'


---# CALL EVENTS HANDLERS
form.Show()
button1.OnCLick = button1_click
button2.OnCLick = button2_click
button3.OnCLick = button3_click
button4.OnCLick = button4_click
panel1.OnChangeBound = panel1_sizeChange
panel1.OnResize = panel1_sizeChange
form.OnClose = form_FormClosed



Capture.JPG
 Description:
CE Video Player by Corroder
 Filesize:  41.09 KB
 Viewed:  2768 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
Aylin
Grandmaster Cheater
Reputation: 9

Joined: 16 Feb 2017
Posts: 592

PostPosted: Thu Apr 23, 2020 10:05 pm    Post subject: Reply with quote

Congratulations. It works fine.
It loads and launches faster than the original.
While the video subject and CE are remote possibilities, you coded it.
Good job.

_________________
Hi Hitler Take control of your trainer
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 33

Joined: 10 Apr 2015
Posts: 1348

PostPosted: Fri Apr 24, 2020 12:09 am    Post subject: Reply with quote

Aylin wrote:
Congratulations. It works fine.
It loads and launches faster than the original.
While the video subject and CE are remote possibilities, you coded it.
Good job.


NVM, thank you

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Aylin
Grandmaster Cheater
Reputation: 9

Joined: 16 Feb 2017
Posts: 592

PostPosted: Fri Apr 24, 2020 1:09 pm    Post subject: Reply with quote

DB, must have a comment on this beautiful work.
And @mgr.inz.Player; The project has been completed.

_________________
Hi Hitler Take control of your trainer
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 165

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Apr 25, 2020 8:24 am    Post subject: Reply with quote

Nice. Few things.

Lua function mciSendString returns strings, not an integer. If you want integer value to be first (MCI error codes), here:
Code:
function ceVideoPlayer()
  if ceVideoPlayer_Loaded then return true end

  local script=[[loadlibrary(C:\Windows\System32\winmm.dll)
alloc(ce_VideoPlayer,4096)
registersymbol(ce_VideoPlayer)

define(returnString,300)
define(retErrorString,400)
define(mciErrorCode,F00)

[64-bit]
ce_VideoPlayer:
lea rsp,[rsp-28]
mov rsi,rcx

lea rdx,[rcx+returnString]
mov r8d,80
xor r9d,r9d
call mciSendStringW
mov [rsi+mciErrorCode],rax // retVal

mov rcx,rax
lea rdx,[rsi+retErrorString]
mov r8,200
call mciGetErrorStringW

lea rsp,[rsp+28]
ret
[/64-bit]

[32-bit]
ce_VideoPlayer:
push ebp
mov ebp,esp
push ebx

mov ebx,[ebp+8]

sub esp,10
mov [esp],ebx
lea ebx,[ebx+returnString]
mov [esp+4],ebx
mov [esp+8],80
mov [esp+c],0
call mciSendStringW

mov ebx,[ebp+8]
mov [ebx+mciErrorCode],eax // retVal
lea ebx,[ebx+retErrorString]

sub esp,0c
mov [esp],eax
mov [esp+0x4],ebx
mov [esp+0x8],200
call mciGetErrorStringW

pop ebx
leave
ret 004
[/32-bit]
]]

  if autoAssemble(script,true) then
    ceVideoPlayer_Loaded=true
    msPlayerCommand=createMemoryStream()
    msPlayerCommand.Size=2048
    return true
  else
    return false
  end

end

function mciSendString(Command)
    writeStringLocal(msPlayerCommand.Memory, Command, true);
    writeBytesLocal (msPlayerCommand.Memory+2*#Command, 0, 0);
    executeCodeLocal('ce_VideoPlayer',msPlayerCommand.Memory);
    return readIntegerLocal(msPlayerCommand.Memory+0xF00),
           readStringLocal(msPlayerCommand.Memory+0x400,512,true),
           readStringLocal(msPlayerCommand.Memory+0x300,128,true)
end



Code:
 mciErrorCode,retErrorString,returnString = mciSendString("open "..filename.." type mpegvideo alias movie parent "..tonumber(panel1.handle).." style child")
 print(mciErrorCode,retErrorString,returnString)

 mciErrorCode,retErrorString,returnString = mciSendString("play movie")
 print(mciErrorCode,retErrorString,returnString)

_________________
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 33

Joined: 10 Apr 2015
Posts: 1348

PostPosted: Sat Apr 25, 2020 9:33 am    Post subject: Reply with quote

Thanks, @mgr.inz.Player, for fixed and updated error handling.
Now, I am able to fix my main CE Video Player project.

EDIT:
@mgr.inz.Player, I try to implement your updated code, give an error: attempt to index a nil value (global 'msPlayerCommand)

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
JohnathanSweeney
Newbie cheater
Reputation: 1

Joined: 04 Apr 2016
Posts: 11

PostPosted: Thu Aug 06, 2020 8:46 pm    Post subject: Reply with quote

this is crazy, I never expected to see a CE video player haha nice work!
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 33

Joined: 10 Apr 2015
Posts: 1348

PostPosted: Fri Aug 07, 2020 2:34 pm    Post subject: Reply with quote

JohnathanSweeney wrote:
this is crazy, I never expected to see a CE video player haha nice work!


Crazy but it's real. Hehehe...!

_________________
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 Extensions 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