增加Lua导出和FileList

This commit is contained in:
2025-09-02 20:39:30 +08:00
parent 1fb319f0e8
commit 6788128cc3
18 changed files with 682 additions and 56 deletions
+113 -1
View File
@@ -11,9 +11,100 @@
#include "sgu_mode_npk_dump_list.h"
#include "sgu_mode_npk_extract_files.h"
#include "sgu_mode_download.h"
#include "sgu_mode_run_lua_file.h"
#include "libEncrypt_AES.h"
//int TestFunc(lua_State* L)
//{
// printf("# TestFunc\n");
// return lua_yield(L, 0);
//}
//
//int TestFunc2(lua_State* L, float a)
//{
// printf("# TestFunc2(L,%f)\n", a);
// return lua_yield(L, 0);
//}
//
//class TestClass
//{
//public:
//
// int TestFunc(lua_State* L, int a)
// {
// m_data = a;
// printf("# TestClass::TestFunc\n");
// return lua_yield(L, 0);
// }
//
// int TestFunc2(lua_State* L, float a)
// {
// printf("# TestClass::TestFunc2(L,%d, %f)\n", m_data, a);
// return lua_yield(L, 0);
// }
//
//private:
// int m_data;
//};
//
//int foo()
//{
// lua_State* L = lua_open();
// luaopen_base(L);
// luaopen_string(L);
//
// lua_tinker::def(L, "TestFunc", &TestFunc);
// lua_tinker::def(L, "TestFunc2", &TestFunc2);
//
// lua_tinker::class_add<TestClass>(L, "TestClass");
// lua_tinker::class_def<TestClass>(L, "TestFunc", &TestClass::TestFunc);
// lua_tinker::class_def<TestClass>(L, "TestFunc2", &TestClass::TestFunc2);
//
// TestClass g_test;
// lua_tinker::set(L, "g_test", &g_test);
//
//
//
// lua_tinker::dostring(L,
// "function ThreadTest()\n"
// " print(\"ThreadTest\")\n"
//
// " print(\"TestFunc Begin\")"
// " TestFunc()\n"
// " TestFunc2(1.2)\n"
// " print(\"TestFunc End\")\n"
//
// " print(\"g_test::TestFunc()\")\n"
// " g_test:TestFunc(123)\n"
// " g_test:TestFunc2(2.3)\n"
// " print(\"g_test::TestFunc()\")\n"
// "end\n"
// );
//
// lua_newthread(L);
// lua_pushstring(L, "ThreadTest");
// lua_gettable(L, LUA_GLOBALSINDEX);
//
// printf("* lua_resume() 1\n");
// lua_resume(L, 0);
//
// printf("* lua_resume() 2\n");
// lua_resume(L, 0);
//
// printf("* lua_resume() 3\n");
// lua_resume(L, 0);
//
// printf("* lua_resume() 4\n");
// lua_resume(L, 0);
//
// printf("* lua_resume() 5\n");
// lua_resume(L, 0);
//
// lua_close(L);
//
// return 0;
//}
////////////////////////////////////////////////////////////////////////////////////////////
enum { OPT_MODE,
OPT_INPUT, OPT_INPUT2, OPT_OUTPUT,
@@ -65,6 +156,7 @@ static void printUsage(const char* moduleName)
printf(" NPKDumpList\tDumps the file list from an NPK archive to a text file.\n");
printf(" NPKExtractFiles\tExtracts all files from an NPK archive to a specified output directory.\n");
printf(" HttpDownload\tDownloads a file from a specified URL and saves it to a local file.\n");
printf(" RunLuaFile\t xxxx \n");
printf("\nSample:\n");
printf(" -m GenRandFile -min 500 -max 1k -o rand.bin\n");
printf(" -m RandModifyFile -i ver01.bin -min 100 -max 1k -c 3 -o ver02.bin\n");
@@ -77,6 +169,7 @@ static void printUsage(const char* moduleName)
printf(" -m NPKDumpList -i abc.npk -o abc_file_list.txt\n");
printf(" -m NPKExtractFiles -i abc.npk -o output\n");
printf(" -m HttpDownload -i http://download.com/file.txt -o file.txt\n");
printf(" -m RunLuaFile -i script.lua\n");
}
enum WorkMode {
@@ -92,6 +185,7 @@ enum WorkMode {
WM_HTTP_DOWNLOAD,
WM_NPK_DUMPLIST,
WM_NPK_EXTRACT_FILES,
WM_RUN_LUA_FILE,
};
enum HashType {
@@ -138,6 +232,9 @@ WorkMode parserWorkMode(const char* modeStr)
else if (_stricmp(modeStr, "NPKExtractFiles") == 0) {
return WM_NPK_EXTRACT_FILES;
}
else if (_stricmp(modeStr, "RunLuaFile") == 0) {
return WM_RUN_LUA_FILE;
}
return WM_NONE;
}
@@ -418,7 +515,22 @@ int main(int argc, char* argv[])
}
}
break;
case WM_RUN_LUA_FILE:
{
if (inputFilename == nullptr)
{
printf("Error: For 'RunLuaFile' mode, you must specify input Lua script file.\n");
printUsage(::PathFindFileNameA(argv[0]));
return 1;
}
printf("Running Lua script file: %s\n", inputFilename);
if (!run_lua_file(inputFilename))
{
printf("Error: Failed to run Lua script file.\n");
return 1;
}
}
break;
case WM_NONE:
default:
{