| View previous topic :: View next topic |
| Author |
Message |
Stregum Advanced Cheater
Reputation: 0
Joined: 17 Jun 2014 Posts: 56 Location: We make baguettes there !
|
Posted: Sun Jul 10, 2016 1:57 pm Post subject: Accessing a table address using a variable (eg index array) |
|
|
Hello CEF, it's been a while
I was doing a table and came accross one issue.
The game in question uses a lot of arrays accessed by player ID's as indexes, such as
| Code: |
DWORD ore[MAX_PLAYERS];
DWORD gas[MAX_PLAYERS];
BYTE colorID[MAX_PLAYERS];
//... you got it
|
instead of using arrays of data structures, why not.. (I don't get this, could that be an optimization because of... cache ?) anyways.
What I want to acheive is to have one CE-allocated address that can be modified by the CE user to provide the id manually. That way CE fetches the corresponding value using the player id using the format BASE + INDEX*SIZE
The thing is where I access my value, eg:
0xDEADBABE+[player_id]*4
It seems that the parser doesn't like it :p (Could that be a possible request ?)
(See attachment)
"Enable" script
| Code: |
[ENABLE]
alloc(data,64)
registersymbol(data)
data:
label(player_id)
registersymbol(player_id)
player_id:
db 00 00 00 00
[DISABLE]
unregistersymbol(player_id)
dealloc(data)
unregistersymbol(data)
|
So I thought doing multiple intermediate symbols such as player_ore_ptr, player_gas_ptr, player_color_ptr, etc... and compute them in a script, something along
| Code: |
;push'es / frame
mov edi,[player_id]
mov eax,0xDEADBABE
mov lea eax,[eax+edi*4]
mov [player_ore_ptr],eax
mov eax,0xDEADBEEF
mov lea eax,[eax+edi*4]
mov [player_gas_ptr],eax
mov eax,0xDEADF00D
mov lea eax,[eax+edi*4]
mov [player_crew_ptr],eax
;more stuff
;pop'es / ret
|
and then access the values in the table using the correct player_xxx_ptr symbol.
This method seems a bit heavy
Plus I don't know how to do that, would I need to create a thread that loops infinitely and sleeps for a bit, or use lua timers (again I don't know, just ideas) ?
This is just for quick-test some of the values, I'm not crazy or anything ^^
Do you have any suggestions or hacks on this method ? Thanks !
| Description: |
|
| Filesize: |
5.75 KB |
| Viewed: |
6503 Time(s) |

|
_________________
Rhaa Stregum Vitae 
Last edited by Stregum on Sun Jul 10, 2016 3:11 pm; edited 1 time in total |
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Jul 10, 2016 2:22 pm Post subject: |
|
|
Add this to your "Enable" script, in addition to the "player_id" symbol you already have.
| Code: | [ENABLE]
label(player_index)
registersymbol(player_index)
[DISABLE]
unregistersymbol(player_index) |
Create a new "Set Player" script. Let the user type in the "player_id" value then enable this.
| Code: | [ENABLE]
[player_id]:
player_index:
[DISABLE]
[player_id]:
player_index: |
Update the entry address.
| Code: | | Mission.dll+80BFC+player_index*4 |
|
|
| Back to top |
|
 |
Stregum Advanced Cheater
Reputation: 0
Joined: 17 Jun 2014 Posts: 56 Location: We make baguettes there !
|
Posted: Sun Jul 10, 2016 3:34 pm Post subject: |
|
|
Thank you, that's really clever, if I understand it correctly, the SetPlayer scripts does (kinda) this player_index = [player_id] right ?
The problem now is that CE doesn't let me compile the Enable script because the player_index symbol is not used anywhere.
So I added this (in the enable script)
| Code: |
[ENABLE]
label(player_index)
registersymbol(player_index)
0: //<here
player_index: //<here
///......
|
to initialize player_index to zero. Is it right ? Apparently not because nothing is changing even though I changed the addresses in the table
I'm out of ideas , thank you for your time.
_________________
Rhaa Stregum Vitae  |
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Jul 10, 2016 3:39 pm Post subject: |
|
|
Your table entries weren't even showing player 1 (index 0)?
After you change the "player_id" value, you need to re-activate this script.
| Code: | [ENABLE]
[player_id]:
player_index:
[DISABLE]
[player_id]:
player_index: |
|
|
| Back to top |
|
 |
Stregum Advanced Cheater
Reputation: 0
Joined: 17 Jun 2014 Posts: 56 Location: We make baguettes there !
|
Posted: Sun Jul 10, 2016 3:49 pm Post subject: |
|
|
I know, I reactivated the script and nope, no changes :/ , that seems very odd, it should work, I'm going to work on this one, it's strange...
EDIT:
I found the problem; it seems like the player_index symbol cannot change after being initialized (which is logic in some sense)
I just modified the script; it registers & unregisters the symbol on the fly
| Code: |
[ENABLE]
label(player_index)
registersymbol(player_index)
[io_player]:
player_index:
[DISABLE]
unregistersymbol(player_index)
|
By the way, initializing it to zero won't work too, so if [io_player] == 0 then CE will not do anything about it.
Thanks Zanzer for the neat trick
_________________
Rhaa Stregum Vitae 
Last edited by Stregum on Sun Jul 10, 2016 5:05 pm; edited 3 times in total |
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Jul 10, 2016 5:00 pm Post subject: |
|
|
Apparently it just doesn't work for the address of 0.
"Enable" script:
| Code: | [ENABLE]
label(player_index)
alloc(player_id,4)
player_id:
dd 1
registersymbol(player_id)
registersymbol(player_index)
1:
player_index:
[DISABLE]
unregistersymbol(player_id)
unregistersymbol(player_index)
dealloc(player_id) |
"Set Player" script:
| Code: | [ENABLE]
unregistersymbol(player_index)
label(player_index)
[player_id]:
player_index:
registersymbol(player_index)
[DISABLE]
unregistersymbol(player_index)
label(player_index)
[player_id]:
player_index:
registersymbol(player_index) |
Table entry address:
| Code: | | Mission.dll+80BFC+player_index*4-4 |
|
|
| Back to top |
|
 |
Stregum Advanced Cheater
Reputation: 0
Joined: 17 Jun 2014 Posts: 56 Location: We make baguettes there !
|
Posted: Sun Jul 10, 2016 5:04 pm Post subject: |
|
|
I just edited my post aswell ahah, your method is better, that way I don't have to toggle the script twice
Thanks for the tips & for your time I love this community, I learn so much from y'all !
_________________
Rhaa Stregum Vitae  |
|
| Back to top |
|
 |
|