Difference between revisions of "Help File:Money type"
Jump to navigation
Jump to search
(Created page with '<hr><div align="left"><font face="Arial" color="#010101" class="Arial2"> The following custom type script will handle values that need to be divided by 100 to get to the corre…') |
|||
Line 1: | Line 1: | ||
− | + | == Money type (divided by 100) == | |
− | The following custom type script will handle values that need to be divided by 100 to get to the | + | |
− | correct value | + | The following custom type script will handle values that need to be divided by 100 to get to the correct value |
− | This type is used by some games like civilization 5 where the money and research technology is | + | This type is used by some games like civilization 5 where the money and research technology is stored using this floating point type. |
− | stored using this floating point type. | + | |
− | + | ||
− | 100.35 gold would be stored in memory as 10013 | + | Example: |
− | 103.89 gold would be stored in memory as 10389 | + | |
− | with this script you'd be able to scan for 100 and 103 respectively, and if you wanted to change | + | 100.35 gold would be stored in memory as 10013 |
− | the value to 700 you'd just change the value to 700 instead of 70000 | + | |
− | alloc(TypeName,256) | + | 103.89 gold would be stored in memory as 10389 |
− | alloc(ByteSize,4) | + | |
− | alloc(ConvertRoutine,1024) | + | |
− | alloc(ConvertBackRoutine,1024) | + | with this script you'd be able to scan for 100 and 103 respectively, and if you wanted to change the value to 700 you'd just change the value to 700 instead of 70000 |
− | TypeName: | + | |
− | db 'Civ 5 Float',0 | + | |
− | ByteSize: | + | alloc(TypeName,256) |
− | dd 4 | + | alloc(ByteSize,4) |
− | //The convert routine should hold a routine that converts the data to an | + | alloc(ConvertRoutine,1024) |
− | nteger (in eax) | + | alloc(ConvertBackRoutine,1024) |
− | //function declared as: stdcall int ConvertRoutine(unsigned char | + | |
− | *input); | + | TypeName: |
− | //Note: Keep in mind that this routine can be called by multiple threads | + | db 'Civ 5 Float',0 |
− | at the same time. | + | |
− | ConvertRoutine: | + | ByteSize: |
− | [32-bit] | + | dd 4 |
− | push ebp | + | |
− | mov ebp,esp | + | // The convert routine should hold a routine that converts the data to an nteger (in eax) |
− | push ecx | + | // function declared as: stdcall int ConvertRoutine(unsigned char *input); |
− | mov ecx,[ebp+8] | + | |
− | [/32-bit] | + | // Note: Keep in mind that this routine can be called by multiple threads at the same time. |
− | //at this point ecx contains the address where the bytes are stored | + | |
− | //save the used registers | + | ConvertRoutine: |
− | push edx //fun fact about ce's assembler, because push ebx does not | + | [32-bit] |
− | exist in 64-bit it becomes the 64-bit push rdx automatically | + | push ebp |
− | push ebx | + | mov ebp,esp |
− | //put the bytes into the eax register | + | push ecx |
− | mov eax,[ecx] //second fun fact, addressing with 32-bit registers | + | mov ecx,[ebp+8] |
− | doesn't work in 64-bit, it becomes a 64-bit automatically (most of the | + | [/32-bit] |
− | time) | + | |
− | xor edx,edx | + | // at this point ecx contains the address where the bytes are stored |
− | mov ebx,#100 | + | // save the used registers |
− | div ebx //divide eax by 100 and put the result in eax (and leftover in | + | push edx // fun fact about ce's assembler, because push ebx does not exist in 64-bit it becomes the 64-bit push rdx automatically |
− | edx) | + | push ebx |
− | pop ebx | + | |
− | pop edx | + | // put the bytes into the eax register |
− | //and now exit the routine | + | mov eax,[ecx] // second fun fact, addressing with 32-bit registers doesn't work in 64-bit, it becomes a 64-bit automatically (most of the time) |
− | [64-bit] | + | |
− | ret | + | xor edx,edx |
− | [/64-bit] | + | mov ebx,#100 |
− | [32-bit] | + | div ebx // divide eax by 100 and put the result in eax (and leftover in edx) |
− | pop ecx | + | |
− | pop ebp | + | pop ebx |
− | ret 4 | + | pop edx |
− | [/32-bit] | + | // and now exit the routine |
− | //The convert back routine should hold a routine that converts the given | + | [64-bit] |
− | integer back to a row of bytes (e.g when the user wats to write a new | + | ret |
− | value) | + | [/64-bit] |
− | //function declared as: stdcall void ConvertBackRoutine(int i, unsigned | + | [32-bit] |
− | char *output); | + | pop ecx |
− | ConvertBackRoutine: | + | pop ebp |
− | [32-bit] | + | ret 4 |
− | push ebp | + | [/32-bit] |
− | mov ebp,esp | + | |
− | push edx //save the registers | + | // The convert back routine should hold a routine that converts the given integer back to a row of bytes (e.g when the user wats to write a new value) |
− | push ecx | + | // function declared as: stdcall void ConvertBackRoutine(int i, unsigned char *output); |
− | mov edx,[ebp+0c] | + | ConvertBackRoutine: |
− | mov ecx,[ebp+08] | + | [32-bit] |
− | [/32-bit] | + | push ebp |
− | //at this point edx contains the address to write the value to | + | mov ebp,esp |
− | //and ecx contains the value | + | push edx // save the registers |
− | push eax | + | push ecx |
− | push edx | + | mov edx,[ebp+0c] |
− | push ecx | + | mov ecx,[ebp+08] |
− | mov eax,ecx //eax gets the given value | + | [/32-bit] |
− | xor edx,edx //clear edx | + | |
− | mov ecx,#100 | + | // at this point edx contains the address to write the value to |
− | mul ecx //multiply eax and put the results into edx:eax (edx is ignored | + | // and ecx contains the value |
− | for this routine) | + | push eax |
− | pop ecx | + | push edx |
− | pop edx | + | push ecx |
− | mov [edx],eax | + | |
− | pop eax | + | mov eax,ecx // eax gets the given value |
− | [64-bit] | + | xor edx,edx // clear edx |
− | //everything is back to what it was, so exit | + | mov ecx,#100 |
− | ret | + | mul ecx // multiply eax and put the results into edx:eax (edx is ignored for this routine) |
− | [/64-bit] | + | |
− | [32-bit] | + | pop ecx |
− | //cleanup first | + | pop edx |
− | pop ecx | + | mov [edx],eax |
− | pop edx | + | pop eax |
− | pop ebp | + | |
− | ret 8 | + | [64-bit] |
− | [/32-bit] | + | // everything is back to what it was, so exit |
+ | ret | ||
+ | [/64-bit] | ||
+ | |||
+ | [32-bit] | ||
+ | // cleanup first | ||
+ | pop ecx | ||
+ | pop edx | ||
+ | pop ebp | ||
+ | ret 8 | ||
+ | [/32-bit] |
Revision as of 00:10, 7 March 2017
Money type (divided by 100)
The following custom type script will handle values that need to be divided by 100 to get to the correct value This type is used by some games like civilization 5 where the money and research technology is stored using this floating point type.
Example:
100.35 gold would be stored in memory as 10013
103.89 gold would be stored in memory as 10389
with this script you'd be able to scan for 100 and 103 respectively, and if you wanted to change the value to 700 you'd just change the value to 700 instead of 70000
alloc(TypeName,256) alloc(ByteSize,4) alloc(ConvertRoutine,1024) alloc(ConvertBackRoutine,1024) TypeName: db 'Civ 5 Float',0 ByteSize: dd 4 // The convert routine should hold a routine that converts the data to an nteger (in eax) // function declared as: stdcall int ConvertRoutine(unsigned char *input); // Note: Keep in mind that this routine can be called by multiple threads at the same time. ConvertRoutine: [32-bit] push ebp mov ebp,esp push ecx mov ecx,[ebp+8] [/32-bit] // at this point ecx contains the address where the bytes are stored // save the used registers push edx // fun fact about ce's assembler, because push ebx does not exist in 64-bit it becomes the 64-bit push rdx automatically push ebx // put the bytes into the eax register mov eax,[ecx] // second fun fact, addressing with 32-bit registers doesn't work in 64-bit, it becomes a 64-bit automatically (most of the time) xor edx,edx mov ebx,#100 div ebx // divide eax by 100 and put the result in eax (and leftover in edx) pop ebx pop edx // and now exit the routine [64-bit] ret [/64-bit] [32-bit] pop ecx pop ebp ret 4 [/32-bit] // The convert back routine should hold a routine that converts the given integer back to a row of bytes (e.g when the user wats to write a new value) // function declared as: stdcall void ConvertBackRoutine(int i, unsigned char *output); ConvertBackRoutine: [32-bit] push ebp mov ebp,esp push edx // save the registers push ecx mov edx,[ebp+0c] mov ecx,[ebp+08] [/32-bit] // at this point edx contains the address to write the value to // and ecx contains the value push eax push edx push ecx mov eax,ecx // eax gets the given value xor edx,edx // clear edx mov ecx,#100 mul ecx // multiply eax and put the results into edx:eax (edx is ignored for this routine) pop ecx pop edx mov [edx],eax pop eax [64-bit] // everything is back to what it was, so exit ret [/64-bit] [32-bit] // cleanup first pop ecx pop edx pop ebp ret 8 [/32-bit]