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 


Some TImage & TPIcture support function

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

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Sat Feb 16, 2019 9:24 pm    Post subject: Some TImage & TPIcture support function Reply with quote

Sharing some of my own TImage support functions, these functions allow me easily manipulate TImage in thus creating animation or resizing objects on screen.
There some pros and some cons.
You shouldn't resize the same image over and over.
Since we cannot implement (yet) a AA method to smooth out the image, it's really not recommended to upscale and image , or downscale large image to small one, well atleast without anti-aliasing, however you might be able to do something if you play corp & resize function (corp a little bit, let's say 10-15 % and downscale).
The script also relays on temporary picture object (for each time you create an object, so it uses double object),shouldn't worry about it so much, it deletes the temp object when destroy is called.

Currently it does not support bitmap, as I created it to control many TImage objects at once, and picture class was my bitmap alternative for manipulating easily PNG images.

Functions it adds
Code:
-- each function should return true if everything went straight;
-- Case is optinal and can be one of the follow;
-- TopLeft
-- TopRight
-- BottomLeft
-- BottomRight
function cropImageByValue(TImage, nWidth, nHeight, sCase) -- Cuts nWidth&nHeight out of the picture and resize canvas; boolean;
function trimImageByValue(TImage, nWidth, nHeight, sCase) -- Cuts nWidth&nHeight out of the picture and resizing image according to canvas; boolean;
function cropImageByPercentage(TImage, nWidth, nHeight, sCase) -- Same but with percentage; boolean;
function trimImageByPercentage(TImage, nWidth, nHeight, sCase) -- Same but with percentage; boolean;
function scaleByValue(TImage, nWidth, nHeight) -- Scales image (negative for upscale); boolean;
function scaleByPercentage(TImage, nWidth, nHeight) -- Same but with percentage; boolean;
function flipVert(TImage) -- Flips image vertically;
function flipHorz(TImage) -- Flips image horizontally;
isVertFlip -- Variable : telling us if image is vertically flipped; boolean;
isHorzFlip -- Variable : telling us if image is horizontally flipped; boolean;

-- some easy drawning method;
-- Draws in the given cords, bitmap/canvas object(forgiving function), copyclip tells it to copy from source image based the given cords
function drawImage(TImage,nX1,nY1,nX2,nY2,source,copyclip)

Add the file to autorun folder.

Now here's some 'smart' cache class, this will allow us to easily load images from path or from table itself (it will try both).
Then we will have the option to duplicate our objects TImage objects easily, let's say we have a trainer with 100 balls as buttons, we could load 100 times the image from disk, or we could class this class which will load it from the path, and then when ever we call duplicate it will duplicate the calling TImage, making it quite easier to load 100 times the same image.
It also allows us to delete ALL duplicates except, access all duplicates, get unique ID (0x799 is reserved so avoid using it).
Another note, if you try to load the very same image, unless you specify its duplicate it will return you the original object (the first object that was created with this image);

It adds to us the following
Code:
function destroyDuplicates()-- Only original object has this method, and this method can be called to destroy any duplicate object;
function duplicate()       -- duplicates the current picture object, returns a new TPicture object;
function getCache()         -- returns current cache table with all objects for the current image (based on path name or table file name);
id                      -- returns current object id (increases by 1 each time an object is duplicated)
totalcachedobjects          -- some long variable name that returns you total amount of objects in cache;



I've attached an C.T with an example for you guys.



PopinOut Example (change from .lua to .ct).lua
 Description:
Image pop in and pop out example

Download
Filename: PopinOut Example (change from .lua to .ct).lua

Download
 Filename:  PopinOut Example (change from .lua to .ct).lua
 Filesize:  16.64 KB
 Downloaded:  275 Time(s)


Example (change from .lua to .ct).lua
 Description:
Example CT, everything is included inside this cheat table, including how to load lua script from memory stream and how to use these 2 scripts

Download
 Filename:  Example (change from .lua to .ct).lua
 Filesize:  16.11 KB
 Downloaded:  349 Time(s)


customImagePicture.lua
 Description:
creates several functions for TImage and TPicture objects

Download
 Filename:  customImagePicture.lua
 Filesize:  20.12 KB
 Downloaded:  249 Time(s)


assetsCache.lua
 Description:
Simple image loading, with ability to duplicate and delete duplicates easily, (builds on top of customImagePicture file).

Download
 Filename:  assetsCache.lua
 Filesize:  4.98 KB
 Downloaded:  240 Time(s)


_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919


Last edited by DaSpamer on Sat Mar 09, 2019 12:55 pm; edited 7 times in total
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1260

PostPosted: Sun Feb 17, 2019 7:44 am    Post subject: Reply with quote

Great work, thanks for your labor.
I think they are my favorite subjects. Smile
I get the error for "assetsCache".
I opened a file called "Slider."
I wrote the path of the file, I wrote the picture names.
But he still writes errors.
Is it possible to get an example .CT?

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website MSN Messenger
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Sun Feb 17, 2019 11:59 pm    Post subject: Reply with quote

There was several typos and few minor bugs, fixed it.
Anyhow updated both scripts in the main post (removed the scripts as the post was too long).
Added a n example ct, just rename the extension from .lua to .ct
@DB it does not contain anything but these 2 scripts, CE logo taken from the forum and example script
Example result:

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1260

PostPosted: Mon Feb 18, 2019 2:31 am    Post subject: Reply with quote

I could not transparent background and scaling the copies.
Where there is error?

Note:(Please understand the questions globally.
Solutions left to comments: they will always show the way.)

Such works are always "Inspirational"
and thanks again for giving up these issues.

EDIT: Sorry.. İmage Url;
http://tinypic.com/r/28jeefp/9

EDIT2: When copying and distributing the image: En, Boy does not accept scaling.
Enlarge the image with the same size, and the image is cropped.
Please provide scaling options for distributed copies.


_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past


Last edited by AylinCE on Mon Feb 18, 2019 11:26 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Mon Feb 18, 2019 10:43 am    Post subject: Reply with quote

Couldn't quite understand what's the problem? and the picture has been deleted already.
Try upload to tinypic.co

Anyhow, it does not work with transparency? you mean like transparent background is not transparent when scaling and such?
This is due the fact that draw/copyRect methods do not accept transparency, a somewhat fix would force transparent property on the TImage object, and drawning using drawWithMask function.

Replace
Code:
i2.setPicture(obj2);

with
Code:
local bmp=i2.Picture.Bitmap
bmp.width,bmp.height = i2.width,i2.height; -- we gotta explicity update bitmap size;
bmp.TransparentColor = 0 -- transparent color;
i2.Transparent = true;
i2.canvas.drawWithMask(0,0,i2.width,i2.height,obj2.bitmap,0,0,obj2.bitmap.width,obj2.bitmap.height); -- draw image with transparency;


We cannot truely support PNG yet, only if db allowed to :/

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1260

PostPosted: Mon Feb 18, 2019 12:34 pm    Post subject: Reply with quote

DaSpamer wrote:

Replace
Code:
i2.setPicture(obj2);

with
Code:
local bmp=i2.Picture.Bitmap
bmp.width,bmp.height = i2.width,i2.height; -- we gotta explicity update bitmap size;
bmp.TransparentColor = 0 -- transparent color;
i2.Transparent = true;
i2.canvas.drawWithMask(0,0,i2.width,i2.height,obj2.bitmap,0,0,obj2.bitmap.width,obj2.bitmap.height); -- draw image with transparency;


We cannot truely support PNG yet, only if db allowed to :/



No, the code didn't work. Some ideas were used.
But: If the form limit is removed, the background is black.

Now only: Copies needs scaling.
In the code, the aspect ratios are not functional.

http://i64.tinypic.com/28st2yt.png
https://hizliresim.com/zjpp7j


_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website MSN Messenger
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Sat Mar 09, 2019 11:17 am    Post subject: PopinOut Example (change from .lua to .ct).lua Reply with quote

Actually when I think about it, it actually does work perfectly.
I have forgotten to allow the image transparency and I had yet again a small typo in the script itself.

See first post (updated the attachment file)

Works excellent!
Video demonstation:
https://www.youtube.com/watch?v=kNM8eH1dMC0



Now I have made another example for pop in and pop of an image (as I stated in the video above that I will make)
See this post attachment
Here's the video url
https://www.youtube.com/watch?v=zFFy88xXpWM

EDIT:
I would greatly appreciate if someone could move this to the lua extensions and plugins sub forum!

Another edit:
Added video examples
Added a 'pop in & out' effect for image; great for sliders and hightlight or what so ever



PopinOut Example (change from .lua to .ct).lua
 Description:
Image pop in and pop out example

Download
 Filename:  PopinOut Example (change from .lua to .ct).lua
 Filesize:  16.64 KB
 Downloaded:  280 Time(s)


_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Mar 10, 2019 10:13 am    Post subject: Re: PopinOut Example (change from .lua to .ct).lua Reply with quote

DaSpamer wrote:

EDIT:
I would greatly appreciate if someone could move this to the lua extensions and plugins sub forum!


How ?. Forum moderator should do that Smile

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

Joined: 16 Feb 2017
Posts: 1260

PostPosted: Sun Mar 10, 2019 1:38 pm    Post subject: Reply with quote

and Final..



İmageURL: https://i.hizliresim.com/r5DJP7.png

Transparent background with a few junk insertion.
(old codes sometimes work well Wink )

Code:
local a = findTableFile('customImagePicture.lua').stream; -- gets memory string
a = load(readStringLocal(a.memory,a.size))() -- loads it;
local b = findTableFile('assetsCache.lua').stream; -- gets memory string
b = load(readStringLocal(b.memory,b.size))()
f = createForm();

l = createLabel(f); -- some component under our image objects to show proof of transparency;
l.Caption = "Hello Wolrd!Hello Wolrd!Hello Wolrd!"
l.Font.Color = 0x00FFFF; -- Yellow World!
l.Font.Size = 40
l.top = 95
------------------- Close Button -----------
b1 = createButton(f)
b1.left = 700
b1.top = 120
b1.caption = "CLOSE"
b1.onClick = function()
f.close()
end
---------------------------------------------
i1 = createImage(f);
i2 = createImage(f);
i3 = createImage(f);
i1.transparent,i2.transparent,i3.transparent = true,true,true; -- allow transparency
--f.width,f.height = 675,225;
f.width,f.height = 875,275;
i1.width,i1.height = 225,225;
i2.width,i2.height = 235,225;
i1.top = 22
i2.top = 22
i3.top = 70
i3.width,i3.height = 235,225;
i2.left = 225;
i3.left = 500;

obj = assetsCache.loadImage('download.png'); -- load new image object;
obj2 = obj:duplicate(); -- duplicates, now we have a new picture object;
obj2:cropImageByPercentage(15); -- corps 25% of the image and rescale back;
obj3 = obj2:duplicate();
--obj3:cropImageByPercentage(35,0,"TopLeft"); -- deletes 0 to 35% of image width and resizes it back to original size from TopLeft of the image
obj3:flipHorz(); -- flip horizontally
obj3:flipVert(); -- flip vertically

i1.setPicture(obj); -- sets first image
i2.setPicture(obj2); -- set image;
obj3:scaleByPercentage(50); -- scale image by 50%
i3.setPicture(obj3);

i2.OnMouseDown = function() f.DragNow() end
-----------------------------------------------
------------------------------------------------- TRANSPARENT
function makeFormTransparent(form)

  if form==nil then return false end

  colorkey = colorkey or 0xFFFFFF
  alpha = alpha or 0xFF
  flag = flag or 1

  if cheatEngineIs64Bit()~=0 or cheatEngineIs32Bit() then

    handle = readQwordLocal(userDataToInteger(form)+0x538)

    script = [[
    alloc(thread,128)
    createthread(thread)
    thread:
    lea rsp,[rsp-40]
    mov rcx,handle
    mov edx,FFFFFFEC
    call user32.GetWindowLongA
    mov r8d,eax
    or r8d,00080000
    mov rcx,handle
    mov edx,FFFFFFEC
    call user32.SetWindowLongA
    mov rcx,handle
    mov edx,00FFFFFF  //color white
    mov r8d,000000FF
    mov r9d,00000001
    call user32.SetLayeredWindowAttributes
    lea rsp,[rsp+40]
    ret
    ]]

    script=script:gsub('handle', string.format('%X',handle))

    autoAssemble(script,true)
  else

    handle = bAnd( readQwordLocal(userDataToInteger(form)+0x330) , 0xFFFFFFFF)

    script = [[
    alloc(thread,128)
    createthread(thread)
    thread:

    push -14
    push handle
    call user32.GetWindowLongA
    or eax,80000
    push eax
    push -14
    push handle
    call user32.SetWindowLongA
    push 01
    push 000000FF
    push 00FFFFFF
    push handle
    call user32.SetLayeredWindowAttributes

    ret
    ]]

    script=script:gsub('handle', string.format('%X',handle)):gsub('colorkey', string.format('%X',colorkey))
    script=script:gsub('alpha', string.format('%X',alpha)):gsub('flag', string.format('%X',flag))
    autoAssemble(script,true)
  end
end

LWA_COLORKEY = 1
LWA_ALPHA = 2
-------------------------------------------------------------
f.Color = 0xFFFFFF
f.setLayeredAttributes (0x0000FF, 250, 3)
f.BorderStyle=bsNone
makeFormTransparent(f)


Note: It still seems to be working on.
You have to recreate the final version.
and final, as a new forum:
"Lua Extension" section, you should archive.
Also add the movements shown in the video. Wink

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1260

PostPosted: Sun Jul 26, 2020 4:18 am    Post subject: Reply with quote

@DaSpamer, I hope I don't ruin your holiday. Smile

I have to put this forum on top for a project.
My question;

Code:
obj3:flipHorz(); -- flip horizontally
obj3:flipVert(); -- flip vertically


Is it possible to rate "flipHorz" and "flipVert" between 1 and 100?

Code:
local _verticalFlipped = false;
   local _horizontalFlipped = false;
   local function flipVert(img)
      img = type(img) =='userdata' and img or self;
      if (img) then
         _verticalFlipped = not _verticalFlipped;
         rawset(mt,"isVertFlip",_verticalFlipped);
         img.canvas.copyRect(0,0,img.width,img.height,img.canvas,img.width,0,0,img.height)
      end
   end
   local function flipHorz(img)
      img = type(img) =='userdata' and img or self;
      if (img) then
         img.canvas.copyRect(0,0,img.width,img.height,img.canvas,0,img.height,img.width,0)
         _horizontalFlipped = not _horizontalFlipped;
         rawset(mt,"isHorzFlip",_horizontalFlipped);
      end
   end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website MSN Messenger
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