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 


Can I Run A Script And Then Kill It?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Gear2ndGandalf
Cheater
Reputation: 0

Joined: 22 Jan 2018
Posts: 36
Location: USA

PostPosted: Sun Apr 02, 2023 1:15 pm    Post subject: Can I Run A Script And Then Kill It? Reply with quote

I'm creating a large life bar script for Metal Gear Solid which extends the life gauge across the screen, but Actual Life doesn't fill it up within the bar automatically like I want. I created another script for your Actual Life to match your Max Life and placed it inside the High Life Bar script.

The issue is this match life script makes me invincible. Is there a way to only run it once in the script so that I get the HP to match without becoming invincible?

I'm aware there may be a way to kill it, but after searching around I just can't seem to find the tutorial required to help me get my syntax right. Also, if there is an alternative way to make this happen in CE please let me know.



CaptureB.PNG
 Description:
Need To Only Run This Once
 Filesize:  87.26 KB
 Viewed:  1222 Time(s)

CaptureB.PNG



CaptureA.PNG
 Description:
Match Life Script Issue
 Filesize:  2.85 KB
 Viewed:  1221 Time(s)

CaptureA.PNG


Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Sun Apr 02, 2023 2:27 pm    Post subject: Reply with quote

You can create a trigger inside of the script that gets set anytime you press the hotkey for it (boolean), then it resets itself when the action is tiggered. This can be repeated as much as you want.

example:
Code:
newmem:
cmp byte ptr [trigger],1
je set_health_to_max
jmp originalcode

set_health_to_max:
mov byte ptr [trigger],0
//code for setting health value to max
jmp originalcode


You will need to perform a few extra steps in order for this script to work properly. If you paste your script in text format, I can fix it for you so that you can see how to set everything up and study it.

Otherwise, there are ways to do this with Lua.
Back to top
View user's profile Send private message
Gear2ndGandalf
Cheater
Reputation: 0

Joined: 22 Jan 2018
Posts: 36
Location: USA

PostPosted: Sun Apr 02, 2023 7:39 pm    Post subject: Reply with quote

Wow thanks I'll post it below!

Code:
{ Game   : mgsi.exe
  Version: 1.0
  Date   : 2023-04-02
  Author : Gear2

  Match max life.
}

define(address,"mgsi.exe"+E1D05)
define(bytes,0F BF 15 F6 E7 78 00)

[ENABLE]

assert(address,bytes)
alloc(newmem,$1000)

label(code)
label(return)

newmem:

code:
  push ecx
  mov ecx,[mgsi.exe+38E7F8] //MAX HEALTH
  mov [mgsi.exe+38E7F6],ecx
  mov edx,[mgsi.exe+38E7F6] //ACTUAL HEALTH
  pop ecx
  jmp return

address:
  jmp newmem
  nop 2
return:

[DISABLE]

address:
  db bytes
  // movsx edx,word ptr [mgsi.exe+38E7F6]

dealloc(newmem)

{
// ORIGINAL CODE - INJECTION POINT: mgsi.exe+E1D05

mgsi.exe+E1CD5: 66 89 41 28           - mov [ecx+28],ax
mgsi.exe+E1CD9: 8B 86 9C 08 00 00     - mov eax,[esi+0000089C]
mgsi.exe+E1CDF: 66 8B 48 28           - mov cx,[eax+28]
mgsi.exe+E1CE3: 66 01 48 26           - add [eax+26],cx
mgsi.exe+E1CE7: 8B 86 9C 08 00 00     - mov eax,[esi+0000089C]
mgsi.exe+E1CED: 66 83 60 28 00        - and word ptr [eax+28],00
mgsi.exe+E1CF2: 8B 8E 9C 08 00 00     - mov ecx,[esi+0000089C]
mgsi.exe+E1CF8: 0F BF 96 22 0A 00 00  - movsx edx,word ptr [esi+00000A22]
mgsi.exe+E1CFF: 0F BF 41 26           - movsx eax,word ptr [ecx+26]
mgsi.exe+E1D03: 2B C2                 - sub eax,edx
// ---------- INJECTING HERE ----------
mgsi.exe+E1D05: 0F BF 15 F6 E7 78 00  - movsx edx,word ptr [mgsi.exe+38E7F6]
// ---------- DONE INJECTING  ----------
mgsi.exe+E1D0C: 03 C2                 - add eax,edx
mgsi.exe+E1D0E: 0F BF 15 F8 E7 78 00  - movsx edx,word ptr [mgsi.exe+38E7F8]
mgsi.exe+E1D15: 3B C2                 - cmp eax,edx
mgsi.exe+E1D17: 7E 02                 - jle mgsi.exe+E1D1B
mgsi.exe+E1D19: 8B C2                 - mov eax,edx
mgsi.exe+E1D1B: 85 C0                 - test eax,eax
mgsi.exe+E1D1D: 7D 02                 - jnl mgsi.exe+E1D21
mgsi.exe+E1D1F: 33 C0                 - xor eax,eax
mgsi.exe+E1D21: 83 79 44 0A           - cmp dword ptr [ecx+44],0A
mgsi.exe+E1D25: 74 10                 - je mgsi.exe+E1D37
}


I am interested in learning LUA for CE and how this would look like for that.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4654

PostPosted: Sun Apr 02, 2023 8:01 pm    Post subject: Reply with quote

I'm surprised that code works. You should probably be treating those as 2-byte values instead of 4-byte values...
Regardless, this is how to read and write a 4-byte value in Lua:
Code:
local maxHealth = readInteger('mgsi.exe+38E7F8')
writeInteger('mgsi.exe+38E7F6', maxHealth)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon Apr 03, 2023 8:27 am    Post subject: Reply with quote

I just woke up, so you will want to test this before studying it.

https://ufile.io/3n3alg2r

Once the script is activated, you should be able to set the 'Heal' entry value to 1 in order to trigger the effect. You can set up a hotkey for this that can trigger the effect using the keyboard or controller etc..
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 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