This repository has been archived by the owner on May 11, 2024. It is now read-only.
Added support for file preprocessing using lua scripts #83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added support for file preprocessing using lua scripts
Mainly Change
In
AssetsManager.cs
:Users can write their own simple lua scripts to do simple pre-processing of files without modifying the c# code to recompile it.
In the case of crosscore, for example, the header of the asset file for this game has an extra piece of duplicate information
prefabs_spine_badlands.zip
Although users can write their own simple Python scripts to remove the extra headers, processing a large number of files can take up extra hard disk space or lose the original files.
Now they can write the following lua script to load the corrected file in memory:
Interaction between Lua and C#
It provides three ways to call C# methods in lua scripts.
First Way
The file
AssetStudio/Lua/LuaMethods.cs
defines some functions in lua that call c# methods.The
CreateFileStream
function helps to generate a newFileStream
object:After this, you can call the FileStream class methods directly via
tmp:CopyTo(fs)
GetAnyMethod()
GetAnyMethod function can get any class method
use luanet
One problem with this approach is that functions with the same name in c# will be overwritten
Interactivity
GUI
Click
Load Lua Template
to open the file browser and select the lua script to import.And click
Enable Lua Scripts
to enable lua script preprocessing.CLI
Importing lua scripts with the
--lua_script
parameter.Lua Template
The lua environment provides two default variables,
filepath
andfilename
, which represent the absolute path to a file and its name, respectively.In addition, the constructors for
FileStream
,MemoryStream
andEndianBinaryReader
are pre-registered in this version.fs = CreateFileStream(filepath)
<==>FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
ms = CreateMemoryStream()
<==>MemoryStream ms = new MemoryStream();
reader = CreateEndianBinaryReader(stream)
<==>EndianBinaryReader reader = new EndianBinaryReader(stream);
After this you can use
fs:method_name(arg1,arg2...)
to call FileStream's class methodIf these interfaces don't meet your needs, you can try
GetAnyMethod()
andluanet
mentioned above