Dynamically Changing Water Settings

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
SleepKiller
Corporal
Corporal
Posts: 143
Joined: Thu Mar 03, 2011 5:08 pm
xbox live or psn: N/A

Dynamically Changing Water Settings

Post by SleepKiller »

In a spare half hour or so I took the time to test out some things I had been wondering about with water in SWBF. The most interesting (and successful) of which was editing the water's settings like height and what not while a map was running. I'm not sure how useful this information will be, but SWBFII does have the scripting capabilities to take advantage of it so I'll post it here.

So the theory is quite simple. Inside a terrain chunk there is a WATR chunk, inside that is all the information about water for the terrain. That chunk has multiple chunks in it, one of which is LAYR. It has the following layout.

Code: Select all

char[] water texture // null terminated variable length string. There will always be at least one null character even if the texture is unset.
int32 unknown // I don't know what it is, maybe it's what keeps the Earth from exploding.
float height // The height of all water in the map.
float u velocity // The U vel value of the water.
float v velocity // The V vel value of the water.
float u repeat // The U rept value of the water.
float v repeat // The V rept value of the water.
uint[4] colour // rgba colour of the water.
The total size of the chunk with an empty water texture is 29 bytes. Now what's interesting here is that we can strip away all the other nonsense from a terrain chunk and leave only the WATR chunk with only the LAYR chunk in it and the game will still load it and apply the water settings accordingly. This works even when ingame, leading to the distinct possibility of creating a map that floods or something.

In order to exploit this you can grab this premade ucfb file that is all setup for this. After that using it is as simple as putting the file in your map's _LVL_PC folder (of course I would personally organize it a bit more). And the wherever you wish to change the water settings in your script put.

Code: Select all

ReadDataFile("dc:settings.water")
-- Or for Lua hipsters 
ReadDataFile "dc:settings.water"
After that you're new water settings will take effect. Of course you'll probably want to edit the "settings.water" file in your favourite hexeditor to have the settings you want. (See the layout earlier in the post for how to do this.) If someone was wanting to get really fancy you could probably even create this file dynamically from within Lua; only thing is you would have a lot of fun encoding floats without access to integers or bit shifting.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Dynamically Changing Water Settings

Post by Marth8880 »

Very interesting! This could probably even be used in tandem with OnEnterRegion to have multiple bodies of water at varying heights, provided potential problems are occluded by the environment and whatnot.

Also,

Code: Select all

ReadDataFile "dc:settings.water"
User avatar
Lorul1
Rebel Colonel
Rebel Colonel
Posts: 562
Joined: Wed Apr 24, 2013 10:34 pm
Projects :: Assault on Theed
Games I'm Playing :: Battlegrounds
xbox live or psn: No gamertag set
Location: Your House

Re: Dynamically Changing Water Settings

Post by Lorul1 »

YES very good sleepkiller now it is possible to have water at separate heights I guess !

Offtopic: where do u find these memes Marth ?
Last edited by Lorul1 on Sun Oct 22, 2017 6:41 pm, edited 1 time in total.
thelegend
Sith
Sith
Posts: 1433
Joined: Thu Jan 23, 2014 6:01 am
Projects :: Star Wars - Battlefront III Legacy
Games I'm Playing :: Swbf GTA CoD LoL KH
xbox live or psn: El_Fabricio#
Location: Right behind you :)

Re: Dynamically Changing Water Settings

Post by thelegend »

But doesn't the game only support one layer of water and then moving it up (In case you have "2" layers of water set), the other layer would go up too as well? I am kinda confused. It's like replacing the skydome texture through ReadDataFile(Texture Name of sky) and then to expect two different sky domes in the end or sort of.
But still very nice find.
ARCTroopaNate
Jedi
Jedi
Posts: 1161
Joined: Mon Mar 21, 2011 8:12 pm
Projects :: Star Wars Battlefront - Tides of War
Games I'm Playing :: SWBF2 RC EAW
xbox live or psn: I have ps4
Location: STALKER!
Contact:

Re: Dynamically Changing Water Settings

Post by ARCTroopaNate »

Could be useful for a linear style campaign map.
SleepKiller
Corporal
Corporal
Posts: 143
Joined: Thu Mar 03, 2011 5:08 pm
xbox live or psn: N/A

Re: Dynamically Changing Water Settings

Post by SleepKiller »

thelegend wrote:But doesn't the game only support one layer of water and then moving it up (In case you have "2" layers of water set), the other layer would go up too as well? I am kinda confused. It's like replacing the skydome texture through ReadDataFile(Texture Name of sky) and then to expect two different sky domes in the end or sort of.
But still very nice find.
I think you have misread what's been posted slightly. I myself didn't say this let you have multiple distinct water layers and Marth8880 was suggesting it enabled it situationally through clever OnEnterRegion use. What you say is absolutely correct you can only have one water layer both in Zero Editor and in SWBF itself and we are all (I believe) on the same page about that :).
Post Reply