Difference between revisions of "Loading Level Resources With Lua"

Jump to navigation Jump to search
Added info on Names table load order, stuff we don't know how to load with Lua yet, notes on sound/particle emitters, maybe a couple other things
(Added info on Names table load order, stuff we don't know how to load with Lua yet, notes on sound/particle emitters, maybe a couple other things)
Line 7: Line 7:
These methods do not actually edit how the game reads an embedded Level_''Somewhere''/''Something''Instances.lua , so these changes only last until the level is unloaded.
These methods do not actually edit how the game reads an embedded Level_''Somewhere''/''Something''Instances.lua , so these changes only last until the level is unloaded.


If you try to reference an object that isn't in the Names table (an object from another level, or one that just doesn't exist, etc) your game will crash. It is not yet known whether your companion's game will crash if you reference an object that only exists in ''your'' Names table; this seems unlikely for most objects, but might happen with networked Trigger types.
If you try to reference an object that isn't in the Names table, your game will crash. It is not yet known whether your companion's game will crash if you reference an object that only exists in ''your'' Names table; this seems unlikely for most objects, but might happen with networked Trigger types.


Although the ''Something''Instances.lua's all have each part of their table on its own line, it seems like the entire table needs to be on the same line to run properly in Lua.
Although the ''Something''Instances.lua's all have each part of their table on its own line, it seems like the entire table needs to be on the same line to run properly in Lua.


The ''Something''Instances/etc tables that you construct to load resources into the Names table are usually (but not always) cleared automatically after the functions run, to free up memory.
The ''Something''Instances/etc tables that you construct to load resources into the Names table are usually (but not always) cleared automatically after the functions run, to free up memory.
From tests done by inserting logging code into the resource-loading functions, this appears to always be the order that resources get loaded into the Names table, in all levels. You should probably use the same order when adding/modifying different types of resources at the same time, it is not yet known if doing them in a different order can break anything.
#Camera Key Frames
#Hulls
#Environment Nodes
#Markers
#Jets
#Signs
#Timelines
#Rails
#Clumps
#Creatures
#Triggers
#Decoration Mesh Instances
#PrintNameTableSize() from Helpers.lua is called - might be a safe and good function to edit to add/modify all the resources you want ready when the level actually "starts", not tested yet
#Environment Nodes (apparently gets loaded twice)
*Load order not yet known for Particle Emitters, Sound Emitters, Terrain Data, the SFX/Music Banks, or the DuneColorShadow texture.


==Triggers==
==Triggers==
Line 185: Line 202:
LoadEnvFXParticles( game:envFXBarn(), game:particleBarn() )  
LoadEnvFXParticles( game:envFXBarn(), game:particleBarn() )  
</code>
</code>
Based on tests where logging code was put in LoadEnvFXParticles() and ParticleEmitterInitialize() and nothing was logged, it seems this script doesn't actually run at level start, so Particle Emitters might be added to Names table by another Lua script or by inaccessible C code. But maybe this function could still add/modify Particle Emitters anyway.


==Sound Emitters==
==Sound Emitters==
Line 197: Line 216:
LoadSoundEmitters( game:soundBarn() )
LoadSoundEmitters( game:soundBarn() )
</code>
</code>
Based on tests where logging code was put in LoadSoundEmitters() and SoundEmitterInitialize() and nothing was logged, it seems this script doesn't actually run at level start, so Sound Emitters might be added to Names table by another Lua script or by inaccessible C code. But maybe this function could still add/modify Sound Emitters anyway.


==Environment Nodes==
==Environment Nodes==
Line 213: Line 234:
There is also an UpdateEnvNamesTableEntry() function in Environment.lua that might be for modifying existing Env Nodes somehow.
There is also an UpdateEnvNamesTableEntry() function in Environment.lua that might be for modifying existing Env Nodes somehow.


LoadEnvNodes does ''not'' clear the EnvNodeInstances table automatically upon completion, the code comments say this causes a crash.
LoadEnvNodes does ''not'' clear the EnvNodeInstances table automatically upon completion, and the code comments say this causes a crash, so might be a bad idea to do it yourself.


==Markers==
==Markers==
Line 279: Line 300:
</code>
</code>
( There doesn't seem to be a game:signBarn(), so maybe it's a different name in game:, or maybe it's used like SignBarn, SignBarn() or SignBarn(game). Also, signData/signInstances don't seem to actually be referenced inside InitializeSignBarn, so they might not be required, but if required then maybe signData is Credits and signInstances is SignInstances. )
( There doesn't seem to be a game:signBarn(), so maybe it's a different name in game:, or maybe it's used like SignBarn, SignBarn() or SignBarn(game). Also, signData/signInstances don't seem to actually be referenced inside InitializeSignBarn, so they might not be required, but if required then maybe signData is Credits and signInstances is SignInstances. )
==TBD / Other==
These are the remaining types of level resources. They can *maybe* be manipulated in real time with Lua code, but it's not yet known if/how it can be done.
===Hulls===
Hulls are regions of space that never move(?), which are used as physical collision geometry and/or a way for Triggers to determine "if ''this thing'' is touching/inside ''this region'', do ''this event''".
You can change the Hulls loaded at start of level by editing HullInstances.lua in the folder for that level under Data/Scripts.
===Decoration Meshes===
Decoration Meshes are any visible object other than terrain, fog, particle effects, Strands(?), and the basic "naked" player avatar. By themselves, they are not physical objects, their collision data comes from physical Hulls put in the same place.
You can change the Decoration Meshes loaded at start of level by editing DecorationMeshInstances.lua.bin in the folder for that level under Data/Scripts.
===Sound Banks===
SFX Banks contain sounds, and references/mixing data for longer sounds streamed from the audio files in Data/Sounds/Streams.
Music Banks just contain references/mixing data for music audio files streamed in from Data/Sounds/Streams.
These are LevelSfx''Somewhere''-SFX.bnk and LevelMus''Somewhere''-MUS.bnk in the Data/Sounds folder; not much is known yet about how to edit these at all, other than renaming files to swap one level for another.
===TerrainData===
Terrain Data determines the terrain's Height Map and Land Color (the color of sand/snow added to the sides and/or top of some Decoration Meshes, and that collects on the player avatars). It also determines Mask Data which seems to be unused.
You can change what is loaded at start of level by editing the TerrainData.bin inside TerrainData.bin.gz in the Data/Terrain/Level_''Somewhere'' folder.
===DuneColorShadow===
DuneColorShadow is a texture that determines the color of the terrain in a level, and which areas are in shadow.
You can change what is loaded at the start of a level by editing/replacing the DuneColorShadow.dds texture inside the DuneColorShadow.dds.D3D11x64 file in the Data/Textures/Level_''Somewhere''/Bin folder.

Navigation menu