xboxscene.org forums

Author Topic: Get Xbeid In Hex...  (Read 86 times)

Kthulu

  • Archived User
  • Hero Member
  • *
  • Posts: 787
Get Xbeid In Hex...
« on: January 08, 2004, 08:59:00 PM »

here's a little something i just whipped up cause i'm thinking about making a context script that backs-up or restores or deletes game saves.  it uses SETFUNC ... XBEID ... to get the xbeID in decimal and then converts and returns it in hex notation.

Edit: oh, btw, no WIP necessary...

CODE

;Purpose: Get an xbe ID in HEX instead of decimal
;This script recursively calls itself to simulate 'function' calls.

;Usage:
;CallFile .xas ".xbe"
;  OR to simulate 'function call'...
;CallFile .xas "DECtoHEX" ""
;--------------------------------------------------------------------

SET arg1 %1%
;Check the first argument for a 'function call'...
IF %arg1% == "DECtoHEX" GOTO DECtoHEX

;Assuming first argument was a pathfilename.xbe...
;-- Main Proceedure --
;Get decimal value of xbeID...
SETFUNC gameID XBEID %1%

;Set some constants...
;These are powers of 16 to be used for decimal to hex conversion...
SET pow7 268435456
SET pow6 16777216
SET pow5 1048576
SET pow4 65536
SET pow3 4096
SET pow2 256
SET pow1 16
SET pow0 1

;Initialize the hex digits...
SET digit7 %gameID%
SET digit6 %gameID%
SET digit5 %gameID%
SET digit4 %gameID%
SET digit3 %gameID%
SET digit2 %gameID%
SET digit1 %gameID%
SET digit0 %gameID%

;Get most significant hex digit value...
;(Digits are numbered in descending order from left to right)
DIV digit7 %pow7%

;Get next significant hex digit value...
SET temp7 %pow7%
MULT temp7 %digit7%
SUB digit6 %temp7%
DIV digit6 %pow6%

;Get next significant hex digit value...
SUB digit5 %temp7%
SET temp6 %pow6%
MULT temp6 %digit6%
SUB digit5 %temp6%
DIV digit5 %pow5%

;Get next significant hex digit value...
SUB digit4 %temp7%
SUB digit4 %temp6%
SET temp5 %pow5%
MULT temp5 %digit5%
SUB digit4 %temp5%
DIV digit4 %pow4%

;Get next significant hex digit value...
SUB digit3 %temp7%
SUB digit3 %temp6%
SUB digit3 %temp5%
SET temp4 %pow4%
MULT temp4 %digit4%
SUB digit3 %temp4%
DIV digit3 %pow3%

;Get next significant hex digit value...
SUB digit2 %temp7%
SUB digit2 %temp6%
SUB digit2 %temp5%
SUB digit2 %temp4%
SET temp3 %pow3%
MULT temp3 %digit3%
SUB digit2 %temp3%
DIV digit2 %pow2%

;Get next significant hex digit value...
SUB digit1 %temp7%
SUB digit1 %temp6%
SUB digit1 %temp5%
SUB digit1 %temp4%
SUB digit1 %temp3%
SET temp2 %pow2%
MULT temp2 %digit2%
SUB digit1 %temp2%
DIV digit1 %pow1%

;Get next significant hex digit value...
SUB digit0 %temp7%
SUB digit0 %temp6%
SUB digit0 %temp5%
SUB digit0 %temp4%
SUB digit0 %temp3%
SUB digit0 %temp2%
SET temp1 %pow1%
MULT temp1 %digit1%
SUB digit0 %temp1%
DIV digit0 %pow0%

;Now call this script recursively with 'function call' name
;to convert hex digit values to hex characters...
CallFile %0% "DECtoHEX" "%digit7%"
SET digit7 %_RetVal%
CallFile %0% "DECtoHEX" "%digit6%"
SET digit6 %_RetVal%
CallFile %0% "DECtoHEX" "%digit5%"
SET digit5 %_RetVal%
CallFile %0% "DECtoHEX" "%digit4%"
SET digit4 %_RetVal%
CallFile %0% "DECtoHEX" "%digit3%"
SET digit3 %_RetVal%
CallFile %0% "DECtoHEX" "%digit2%"
SET digit2 %_RetVal%
CallFile %0% "DECtoHEX" "%digit1%"
SET digit1 %_RetVal%
CallFile %0% "DECtoHEX" "%digit0%"
SET digit0 %_RetVal%

;Set debug to any value other than zero
;to output results to the screen...
SET debug 0
IF# %debug% == "0" GOTO NODEBUG
BeginDraw UseCurrent
 MessageBox "%digit7%-%digit6%-%digit5%-%digit4%-%digit3%-%digit2%-%digit1%-%digit0%"
EndDraw
Input

;Just return the hex values...
:NODEBUG
SET _RetVal "%digit7%%digit6%%digit5%%digit4%%digit3%%digit2%%digit1%%digit0%"
Quit
;-- End Main Proceedure --


;-----------------------------------
;Here's the 'function' that converts
;decimal values to hex characters...
------------------------------------
;To access this function when calling...
;CallFile