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 sub project: CE AutoAssembler Engine ---- [May 23, 2013]
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Source
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Tue Apr 16, 2013 8:43 am    Post subject: This post has 1 review(s) Reply with quote

it also works with dx10, dx10.1 and dx11 yes (not dx11.1 though, but who wants to use w8 for 3d gaming anyhow)
no opengl yet

Perhaps I should try making a default 3doverlay script generator based on the cheat table like I do with the trainer maker

Quote:

but I hear openGL hooking is alot trickier than DX

There's probably more to hook, but I don't see much problems (Besides not too many games that use it right now)

Of course, if you are hooking d3d by modifying the function table of the d3ddevice then it will be trickier yes. (and not to mention that windows vista and later royally screw that up if you hook more than just present/endscene)


-
Also, next ce version has simplified lua scripting a lot
Code:

d3dhook_sprite_setHeight(bgsprite, d3dhook_texture_getHeight(statusbartexture))

can then be written as:
Code:

bgsprite.Height=statusbartexture.Height

_________________
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
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Tue Apr 16, 2013 10:04 am    Post subject: Reply with quote

Yes I modify the function table like this: Hooking either present or endscene seem to work equally effective so Im not sure which is better to use... maybe depends on the game...

And of course got to hook reset and properly release what you've created... Very Happy

And yes that second lua code looks nicer! I should probably start learning it! it is quite useful if you know how to write it!

Code:

OutputDebugStringA("Got Direct3D Device! SUCCESS!");

   DWORD *d3dMethods = (DWORD*)*(DWORD*)DXDev;

   BeginSceneAddress = (LPVOID)d3dMethods[41];
   EndSceneAddress = (LPVOID)d3dMethods[42];
   ResetAddress = (LPVOID)d3dMethods[16];
   PresentAddress = (LPVOID)d3dMethods[17];

   sprintf(dbg, "BeginSceneAddress: %p EndSceneAddress: %p; ResetAddress: %p; PresentAddress: %p \n", BeginSceneAddress, EndSceneAddress, ResetAddress, PresentAddress);
   OutputDebugStringA(dbg);
   
   //HookClass *BeginSceneHook = new HookClass((DWORD)BeginSceneAddress, (DWORD)&myBeginScene);
   //HookClass *EndSceneHook = new HookClass((DWORD)EndSceneAddress, (DWORD)&myEndScene);
   HookClass *PresentHook = new HookClass((DWORD)PresentAddress, (DWORD)&myPresent);
   HookClass *ResetHook = new HookClass((DWORD)ResetAddress, (DWORD)&myReset);

   //RealBeginScene = (BEGINSCENE)EndSceneHook->DetouredFunction;
   //RealEndScene = (ENDSCENE)EndSceneHook->DetouredFunction;
   RealPresent = (PRESENT)PresentHook->DetouredFunction;
   RealReset = (RESET)ResetHook->DetouredFunction;

   sprintf(dbg, "Hooked EndScene/Present + Reset! Of D3D9! RealEndScene: %p; RealPresent: %p RealReset: %p\n", RealEndScene, RealPresent, RealReset);
   OutputDebugStringA(dbg);


Dark Byte, there's no way to attach videos is there? I thought I saw someone do it, but might have been a mod...

Anyway I know you probably don't watch peoples videos but I whipped this up real quick after making a quick mod on my work in progress to show you how I'm able to dynamically load CT's and generate a direct X gui based on them! I think that's what you were talking about... (and thanks to Alice, they'll actually be able to enable and disable as well Very Happy)


Watch it please, it's only two minutes Very Happy


Link


Since fraps doesn't coincide with my DX hook (or at least I haven't cared to make them coincide I had to use windowed mode to demonstrate...)

After loading a CT, it doesn't immediately dynamically create the new cheats list... so I had to alt + enter to enter + exit full screen mode to cause reset to be called so it would re-initialize my DXTrainerMenu object and everything else with it!

Any idea how it could be instant, without having to have reset to be called?

Thanks this project of mine is turning out to be a quite fun one to piece together!

OH and I almost forgot, see how some of the check boxes are randomly not being drawn? I can't seem to figure out what's causing that.... (I don't create a check box checked and check box unchecked texture for each 'DXHack' object, I just pass the created one from DXTrainerMenu as a pointer... I thought that is okay... Should I instead have the DXHack object create its own two checkbox textures instead? It would be more calls to D3DXCreateTextureFromFileInMemory but if that solves the problem I wouldn't mind it!

Very Happy

_________________
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Tue Apr 16, 2013 10:44 am    Post subject: Reply with quote

I find it the easiest to just create what you need when present is called and you're about to draw
Is the object you need still NULL? Then create and initialize it.

Sure, the first frame render after the hook will be slightly slower, but all subsequent frames will have a normal render speed

Then when reset is called free everything (that isn't NULL) and NULL the pointers so the next time the gui is rendered repeat it again

As for the checkboxes not being rendered not sure. This looks a lot of using uninitialized variables where every so often a variable in the stack is not 0 so a certain variable has a value that's not 0 either

_________________
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
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Tue Apr 16, 2013 11:24 am    Post subject: Reply with quote

Dark Byte wrote:
I find it the easiest to just create what you need when present is called and you're about to draw
Is the object you need still NULL? Then create and initialize it.

Sure, the first frame render after the hook will be slightly slower, but all subsequent frames will have a normal render speed

Then when reset is called free everything (that isn't NULL) and NULL the pointers so the next time the gui is rendered repeat it again

As for the checkboxes not being rendered not sure. This looks a lot of using uninitialized variables where every so often a variable in the stack is not 0 so a certain variable has a value that's not 0 either


OMG!!! THANKS DARK BYTE!!

I solved the checkbox problem!! Okay what I was doing wrong was trying to initialize after the call to reset! as well as at the start of present! Looking back that was silly of me, as it only needs to be initialized once! and the begginning of present or endscene is the best place to do it!

I was properly releasing / freeing / setting back to NULL though so that's why I wasn't crashing...

This was my reset hook previously:

Code:

HRESULT WINAPI myReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS *pParams)
{
   _asm pushad

   if(DXTrainer) delete DXTrainer;
   DXTrainer = 0;

   saferelease(pSprite);
   pSprite = 0;

   OutputDebugStringA("Reset! Called, hook is working :D");
   HRESULT Result = RealReset(pDevice, pParams);

   if(Show) InitializeTextures(pDevice);

   _asm popad
   return Result;
}


I removed the line "if(Show) InitializeTextures(pDevice);" And now MY CHECK BOXES ALWAYS APPEAR Very Happy

Show is my variable which toggles showing or hiding the GUI and everything on it (F12 currently toggles drawing of it)

This is how my present hook was and still is: (It's the same in endscene too, so I can just switch to whatever one I want to use)
Code:

HRESULT WINAPI myPresent(LPDIRECT3DDEVICE9 pDevice, RECT* pSourceRect, RECT* pDestRect, HWND hDestWindowOverride, RGNDATA* pDirtyRegion)
{
   _asm pushad
   if(Show)
   {
      InitializeTextures(pDevice);

      if(pSprite && DXTrainer)
      {
         pSprite->Begin(D3DXSPRITE_ALPHABLEND);
         DXTrainer->Draw(pSprite);
         pSprite->End();
      }
   }
   _asm popad
   return RealPresent(pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
}


However I'm unsure if I should keep the IntializeTextures() function under the if of 'Show' Or just initialize them anyway even if not showing the gui yet? I suppose it doesn't matter since it wont initialize them unless they aren't initialized...

This is my initialize textures function
Code:

void InitializeTextures(LPDIRECT3DDEVICE9 pDevice)
{
   if(!pSprite)
      D3DXCreateSprite(pDevice, &pSprite);

   if(!DXTrainer)
   {
      DXTrainer = new DXTrainerMenu(pDevice);
      DXTrainer->AddCheatsToMenu(Assembler->CT);
   }
}


The AddCheatsToMenu method of DXTrainerMenu class is what dynamically creates the cheat list as I demonstrated in that video you saw Very Happy Thanks for embedding it by the way Very Happy

Well now that my check box issue is all cleared up, I can continue work on making it movable (which I've already done, just now have to make sure everything moves with it) making the checkboxes get checked, and calling Assembler->AutoAssemble(); on the clicked cheat!


I noticed something though, I think some scaling is going on because the sizes of my trainer window and other drawn images doesn't seem to reflect their actual image size... How can I accurately programmatically calculate these sizes of textures?


I've used: DXTrainerTexture->GetLevelDesc(0, &DXTrainerWindowDesc);
And the DXTrainerWindowDesc.Width + Height fields but they for example returned 512 x 512 and the image was actually 378w x 478h ? I'm thinking it's because power of two... but even manually forcing 378 and 478 as the dimensions it still was not the right size...

So I suppose the question is, regardless of how DX is scaling the image, how can I know it's true dimensions?

lol this is my last question I promise! But thanks for making me realize how to fix my checkbox problem! ONLY initialize your stuff in present/endscene... don't mess around trying to do that after reset!!

Very Happy

_________________
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Tue Apr 16, 2013 11:34 am    Post subject: Reply with quote

Two solutions:
1: When rendering get the real size of the texture and the wanted size of the picture and just render with a specified scale matrix.

2: use D3DXCreateTextureFromFileInMemoryEx instead and for Filter specify D3DX_FILTER_NONE so it will not scale and the pixels that don't make up the texture are made transparent (So in fact the texture when drawn as a sprite is the size of the original picture)

here's an example of me using D3DXCreateTextureFileInMemoryEx:
http://code.google.com/p/cheat-engine/source/browse/trunk/Cheat%20Engine/Direct%20x%20mess/CED3D9Hook/CED3D9Hook.cpp#347 (It's a stupid solution to a specific problem and I should probably just query what kind of device it is first)

_________________
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
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Tue Apr 16, 2013 12:41 pm    Post subject: Reply with quote

Dark Byte wrote:
Two solutions:
1: When rendering get the real size of the texture and the wanted size of the picture and just render with a specified scale matrix.

2: use D3DXCreateTextureFromFileInMemoryEx instead and for Filter specify D3DX_FILTER_NONE so it will not scale and the pixels that don't make up the texture are made transparent (So in fact the texture when drawn as a sprite is the size of the original picture)

here's an example of me using D3DXCreateTextureFileInMemoryEx:
http://code.google.com/p/cheat-engine/source/browse/trunk/Cheat%20Engine/Direct%20x%20mess/CED3D9Hook/CED3D9Hook.cpp#347 (It's a stupid solution to a specific problem and I should probably just query what kind of device it is first)



I tried the second solution first, and IT WORKS Very Happy

As you can see the image is in it's true size, there were a lot of extra parameters in that Ex call though, they weren't kidding about the Ex! lol Can for sure tell because the text is now going off the side! Smile


Code:

//This line:
D3DXCreateTextureFromFileInMemory(DXDevice, &DXTrainerImageData, sizeof(DXTrainerImageData), &TrainerTexture);

//Became:
D3DXIMAGE_INFO imageinfo;
ZeroMemory(&imageinfo, sizeof(imageinfo));

D3DXCreateTextureFromFileInMemoryEx(DXDevice, &DXTrainerImageData, sizeof(DXTrainerImageData), D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, &imageinfo, 0, &TrainerTexture);



So thanks for that! Now my gui looks much nicer and not distored a bit due to stretching! Very Happy


I also tried the first method just to learn how to do it that way as well, in case maybe I did want to scale or perhaps rotate something... (so I switched back to the 'D3DXCreateTextureFromFileInMemory' call and tried this:

I tried this by putting it between pSprite->Begin() and pSprite->End() (in my present hook)

Code:

pSprite->Begin(D3DXSPRITE_ALPHABLEND);

         D3DXMATRIX ScaleMe;
         D3DXMatrixScaling(&ScaleMe, 10.0f, 10.0f, 0.0f);
         pDevice->SetTransform(D3DTS_TEXTURE0, &ScaleMe);

         DXTrainer->Draw(pSprite);
         
         pSprite->End();


According to what I was thinking it should have applied that scale matrix so anything drawn after it would be scaled X + Y by 10.0 so it should've basically filled the whole screen! perhaps that isn't the right code... and if I set a transform don't I have to unset it? I don't see a call for unset transform... Or I know perhaps you just call settransform again with the original matrix... Very Happy Also I was confused about D3DTS_TEXTURE0 it was some example code I found online, perhaps that's not right either...

I'll keep playing around maybe I'll have better luck with trying to rotate it Very Happy


EDIT: I GOT IT! I wasn't applying the matrix to the world! only to whatever D3DTS_TEXTURE0 is!

Thanks to this way more informative page then where I got that example code from, I substituted it for: 'D3DTS_WORLD' instead and bingo! scaled by ten fold Very Happy (http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-5)



Okay now I'm just having fun! It's back to work for me Smile

_________________
Back to top
View user's profile Send private message
Alice0725
Expert Cheater
Reputation: 11

Joined: 24 Jul 2012
Posts: 145

PostPosted: Thu Apr 18, 2013 7:00 am    Post subject: Reply with quote

@SteveAndrew Surprised Good job! Congratulations!

Ok!I've upload an example about loading CETack.dll from memory. It's a vs2012.C++ project.

Confused But, I think it's too complicated to write a trainer with c++ for me. I prefer using pascal or CE's Lua. Arrow And it's very easy to make an ingame menu trainer with CE's lua engine.
Back to top
View user's profile Send private message
SteveAndrew
Master Cheater
Reputation: 30

Joined: 02 Sep 2012
Posts: 323

PostPosted: Sun Apr 21, 2013 2:11 am    Post subject: Reply with quote

Alice0725 wrote:
@SteveAndrew Surprised Good job! Congratulations!

Ok!I've upload an example about loading CETack.dll from memory. It's a vs2012.C++ project.

Confused But, I think it's too complicated to write a trainer with c++ for me. I prefer using pascal or CE's Lua. Arrow And it's very easy to make an ingame menu trainer with CE's lua engine.



Well you don't have to write any C++ code! In order to have a C++ directx GUI trainer Wink That's what my DX Trainer Kit does! It automatically creates it for you Very Happy The code is already laid out!

Check it out if you get the chance Alice!: http://forum.cheatengine.org/viewtopic.php?t=564408

I'll have to include that loading the CETack DLL from memory in my next update though!

But it's finally complete! Very Happy And working like I wanted it too! Now to just support more than directx9 only!!!

_________________
Back to top
View user's profile Send private message
Alice0725
Expert Cheater
Reputation: 11

Joined: 24 Jul 2012
Posts: 145

PostPosted: Thu May 23, 2013 6:08 am    Post subject: Reply with quote

Steve, I've made a static library. You can download it now.

click here: http://sdrv.ms/Z2ebVM


Code:
/*
 *
 * CETack Static Library(Cheat Engine Auto Assembler module)
 * Version: 1.0.1.21
 * Author: Alice0725
 *
 * This is not an official library of Cheat Engine. But, placed in CE forum by Alice0725.
 * The URL is http://forum.cheatengine.org/viewtopic.php?t=560099
 *
 *
 * THIS SOFTWARE AND THE ACCOMPANYING FILES (IF ANY) ARE PROVIDED AS IS WITHOUT WARRANTY OF
 *  ANY KIND, EITHER EXPRESS OR IMPLIED.
 *
 * CETack is a standalone auto assembler module. So, rapidly and easily for you to
 * make a trainer if you use it in your project. The whole CETack package has 3 parts:
 *
 * (1)CETackLCL:It's a visual component library for use in Lazarus.If you know a little pascal,
 *  using Lazarus to write a standalone trainer will be your best choice. The simple the best one,
 *  your best choice it's a table of Cheat Engine .
 *
 * (2)CETackDLL:It's a dynamic library. The easist way to load CETack in your project.
 *
 * (3)CETackLib:It's static library. For those who want to make a single file trainer.
 *
 *
 * The original library is a dynamic library programmed in pascal(Yesh,that's the CETackDLL).
 * So thanks for Joachim Bauch([email protected])'s Memory DLL loading code.We can have
 * this static library. His website is http://www.joachim-bauch.de.
 *
 * Thanks Dark Byte, the author of Cheat Engine.Yeah, CETack is just a tack of cheat engine.
 * Cheat engine can do more than this,no matter you're a trainer maker or professional programmer...
 * Try it, you'll love it. Cheat Engine's Offical website: Http://www.CheatEngine.org
 *
 * Thanks Steve Andrew! Without his encouragement, this project would have never been finished.
 *
 */

#pragma once
#include <Windows.h>


/*
  @return:
     CETack version: e.g.: "1.0.1.21"
*/
PCHAR    WINAPI  GetCETackVersion();



/*
  @params:
  (1)HANDLE processHandle;
  (2)CHAR *symbolName. The symbol name can be a :
    a. User defined symbol in aascript.
   b. Symbol in a module of the process. You can use this to call the API.
   c. CE's address expression. e.g.: "[[hero.exe+0987]+7FE8]+0B".
*/
UINT_PTR WINAPI  GetAddress(HANDLE processHandle, CHAR *symbolName);



/*
  @params:
  (1)HANDLE processHandle
  (2)CHAR *aascript. AutoAssembler script. See CE's help file for more help.
  (3)BOOL bEnable. Since CE's aascript has tow sections, one is enable ,the other one is disable.
      bEnable=true, execute the script in [enable] section.
     bEnable=false,execute the script in [disable] section.
  (4)DWORD dwFlag, This param is for showing message.
      dwFlag=0, show nothing;
     dwFlag=1, only popup errors;
     dwFlag=2, popup messages and errors.
*/
BOOL     WINAPI  AutoAssemble(HANDLE processHandle, CHAR *aascript, BOOL bEnable, DWORD dwFlag);



/*
 @param:
   (1)CHAR *imageName: the image name of the process. e.g.:"hero.exe" .
 @notes:
   (1)If the imageName is not a pure ASCII str, use UTF-8 encoding.
   (2)If there are 2 or more processes have the same imageName, will only return the 1st one.
*/
DWORD    WINAPI  GetProcessIdByName(CHAR *imageName);



/*
  @params:
  (1)CHAR *wndClass: The class name of the process window.(Use Spy++ or other tool to get it.)
  (2)CHAR *wndName:  The Window name of the process window.(Use spy++ or other tool to get it.)
  @Notes:
   (1)If the wndClass or wndName is not a pure ASCII str, use UTF-8 encoding.
   (2)If there are 2 or more processes have the same class and Name, will only return the 1st one.
  @Tip:
   Window's system process: "explorer.exe" 's window caption is always the current folder.So, you
   should always set the wndClass.

*/
DWORD    WINAPI  GetProcessIdByWindow(CHAR *wndClass, CHAR *wndName);

_________________
Back to top
View user's profile Send private message
Corruptor
Advanced Cheater
Reputation: 3

Joined: 10 Aug 2011
Posts: 82

PostPosted: Tue Jun 11, 2013 4:28 pm    Post subject: Reply with quote

It's been 3 months since the last update, but just in case that this one is still maintained, i have a question:

So far, i simply downloaded the source files from the link and added them to my project.

Calling the AutoAssemble function with a little test code that creates a popup window works perfectly so far.

However, when i want to inject more complex code, i run into trouble. Mainly, the AutoAssemble has problems with expressions like "msvcr80.strcat", telling me he could not compile that line. If i replace it by "strcat", it compiles; however, the process i'm currently injecting the code into seems to have two different c libraries loaded, and "strcat" is resolved to "ntdll.strcat"; and calling this one crashes the process.

The same problem occurs with any address which is built through the Modulename.functionname syntax (user32.MessageBoxA). When i inject the very same code through cheat engine itself, if works fine. The GetAddress function returns 0 when given such an expression, so i can not use it to get around that problem either.

So, does anybody have an idea what i am doing wrong before i end up enumerating the modules myself and replacing them manually?
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 Source All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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