divided by a number

Programming related discussions related to game research
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

divided by a number

Post by Shokoniraya »

i need a little help with a script


get FILE-SIZE asize
get CRC long
math CRC += 1024
get OFFSET longlong

How can i do that: (If FILE-SIZE not was divided by 16, then do that: math OFFSET += 12)

divided by 16: like 16, 32, 48, 64, 80, 96, 112, 128, 144...
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: divided by a number

Post by aluigi »

math OFFSET x 16

It performs an automatic alignment to 16.
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: divided by a number

Post by Shokoniraya »

in LIS_BNK_Import.bms, Line 53

i need to set alignment all of files as (divided by 16), just like original, or if i dont, then game cant read files, if i do it with hex, game can read files
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: divided by a number

Post by aluigi »

That's a bit different than the original simpler question of how to align an offset :)
Basically you should first calculate the aligned offset, then use "append 1" that allows to move on any desired offset of MEMORY_FILE, then fix that OFFLEN... not exactly a one-line fix.

I did some edit on the fly, try it:

Code: Select all

open FDDE header_bnk 0
open FDDE footer_bnk 1
open FDDE bnk 2
get NAME basename
string BNK_NAME p "%s%s.bnk" NAME "_NEW"


get HEADER_SIZE asize 0
get FSB_SIZE asize 1
log MEMORY_FILE 0 HEADER_SIZE 0


get MEM_SIZE asize MEMORY_FILE



goto 0x0 0
findloc DATA binary "\x44\x41\x54\x41" 0
goto DATA 0
get DATA long 0
get CHUNK long #all extracted size 0
math ALL_SIZE = CHUNK 0
savepos SSSSA 0
math E_HEADING = DATA 0
goto 0x0 0
findloc HEADER_TWO_SCOUND binary "\x44\x49\x44\x58" 0
goto HEADER_TWO_SCOUND 0
get DIDX_HEADER long 0
get HEADER_TWO long 0
math HEADER_COUNT = HEADER_TWO 0
math HEADER_TWO /= 12 #12, (CRC, OFFSET, SIZE long) 0

math DUMMY_ADDER = 24 0
math HEADER_HEADING + HEADER_ONE 0
math HEADER_HEADING + DUMMY_ADDER 0


get MAHPE asize 0
for i = 0 < HEADER_TWO 0

get CRC long 0
savepos OFFSET_OFF 0
get OFFSET long 0
savepos SIZE_OFF 0
get SIZE long 0
math OFFSET == 0 0
math OFFSET + HEADER_HEADING 0
string CRC p "%s.wem" CRC 0

open FDSE CRC 4
get WEM_SIZE asize 4
savepos OFFLEN MEMORY_FILE
math OFFLEN x 16
append 1
goto OFFLEN MEMORY_FILE
log MEMORY_FILE 0 WEM_SIZE 4
append




putvarchr MEMORY_FILE OFFSET_OFF OFFLEN long
putvarchr MEMORY_FILE SIZE_OFF WEM_SIZE long



next i





append
log MEMORY_FILE 0 FSB_SIZE 1
append



get MEM_SIZE asize MEMORY_FILE
log BNK_NAME 0 MEM_SIZE MEMORY_FILE
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: divided by a number

Post by Shokoniraya »

Sorry, nut BKHD Header cant add!
alignment is works fine! but when you change (append) to (append 1), then header cant add on top of file!

math OFFLEN x 16
append 1


i upload a better sample
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: divided by a number

Post by aluigi »

You can use both, I mean "append 1" for moving to the aligned position, followed by "append" (for closing the previous mode) and another "append" for opening the classical append mode.

Otherwise just go directly to the end of the file in "append 1":

Code: Select all

get TMP asize MEMORY_FILE
goto TMP MEMORY_FILE
log MEMORY_FILE OFFSET SIZE

Many choices :)
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: divided by a number

Post by Shokoniraya »

aluigi wrote:You can use both, I mean "append 1" for moving to the aligned position, followed by "append" (for closing the previous mode) and another "append" for opening the classical append mode.

Otherwise just go directly to the end of the file in "append 1":

Code: Select all

get TMP asize MEMORY_FILE
goto TMP MEMORY_FILE
log MEMORY_FILE OFFSET SIZE

Many choices :)


infact, i cant understand why cant add header! because i did it before!

can you fix script? to make NEW .bnk Just like original?
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: divided by a number

Post by Shokoniraya »

Shokoniraya wrote:
aluigi wrote:You can use both, I mean "append 1" for moving to the aligned position, followed by "append" (for closing the previous mode) and another "append" for opening the classical append mode.

Otherwise just go directly to the end of the file in "append 1":

Code: Select all

get TMP asize MEMORY_FILE
goto TMP MEMORY_FILE
log MEMORY_FILE OFFSET SIZE

Many choices :)


infact, i cant understand why cant add header! because i did it before!

can you fix script? to make NEW .bnk Just like original?


aluigi, i dont unrestand why (append 1) will disable header log?
can you fix it yourself for test?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: divided by a number

Post by aluigi »

Sorry, currently I can't.
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: divided by a number

Post by GHOST DEAD »

aluigi wrote:Sorry, currently I can't.

hmmm... adding another append not working
do you think QuickBMS need a Update? because i think so
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: divided by a number

Post by aluigi »

No, everything works perfectly.
It's just that I can't spend time understanding what the script is meant to do and then fixing or rewriting it from scratch.
Sorry.
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: divided by a number

Post by GHOST DEAD »

Shoko, your script had some Problem, in this days, im working on audio modding to change music in game
i made a recreated script based on your script

You did something wrong and in this code, when i change (append) to (append 1), header still can be added in template

only problem is:

Code: Select all

append
math WEM_OFFSET x 16
log MEMORY_FILE WEM_OFFSET WEM_SIZE 4
append

not working, me too
and i don't think that just using (x 16) will works
aluigi, which code? can you tell me what can i do? (x 16) not working
for example, can you fix 16-alignment in LIS_BNK.bms? if it's solved, other problem will solve
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: divided by a number

Post by GHOST DEAD »

i forgot to say, but x can set a size a special number, not just put in OFFSET, got to use for set a size, not rewrite them!
i really need it, too
GHOST DEAD
Posts: 218
Joined: Wed Jul 19, 2017 5:04 am

Re: divided by a number

Post by GHOST DEAD »

i found problem now
Seems like quickbms can't set offset by 16 in reimport2 and just add file in -0x0. anyway, game can't read files without (math offset x 16) in new offset, a problem or not avable?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: divided by a number

Post by aluigi »

The 'x' command is a non-reversible since you can't calculate the old value to store back in the original field, but that should not be a problem.

I will check it anyway.
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: divided by a number

Post by Shokoniraya »

i want to reimport2 a file with x16 offset. but QuickBMS always adding file in end of file. that is right
solution?

For instance
i want to create a script for a simple file. And i can extract it as well with real size and hash and offset
And for reimporting i must use reimport2
But game juat can read offset as x16. Like 16 and 32 or more
Now Tool just can add file in end of archive
And if archive are 37 byte. Then my new offset is 38. But must be 64!
What we need for now: adding file by X16 offset.
Shokoniraya
Posts: 416
Joined: Sat Sep 15, 2018 5:22 am

Re: divided by a number

Post by Shokoniraya »

Sorry. here a edited part

if archive are 37 byte. Then my new offset is 38. But must be 48!