diff --git a/scripts/after_build.lua b/scripts/after_build.lua deleted file mode 100644 index 8c3f345..0000000 --- a/scripts/after_build.lua +++ /dev/null @@ -1,127 +0,0 @@ -function beautify_json(value, indent) - import("core.base.json") - local json_text = "" - local stack = {} - - local function escape_str(s) - return string.gsub(s, '[%c\\"]', function(c) - local replacements = {['\b'] = '\\b', ['\f'] = '\\f', ['\n'] = '\\n', ['\r'] = '\\r', ['\t'] = '\\t', ['"'] = '\\"', ['\\'] = '\\\\'} - return replacements[c] or string.format('\\u%04x', c:byte()) - end) - end - - local function is_null(v) - return v == json.null - end - - local function is_empty_table(t) - if type(t) ~= 'table' then return false end - for _ in pairs(t) do - return false - end - return true - end - - local function is_array(t) - return type(t) == 'table' and json.is_marked_as_array(t) or #t > 0 - end - - local function serialize(val, level) - local spaces = string.rep(" ", level * indent) - - if type(val) == "table" and not stack[val] then - if is_empty_table(val) then - json_text = json_text .. (is_array(val) and "[]" or "{}") - return - end - - stack[val] = true - local isArray = is_array(val) - json_text = json_text .. (isArray and "[\n" or "{\n") - - local keys = isArray and {} or {} - for k in pairs(val) do - table.insert(keys, k) - end - if not isArray then - table.sort(keys) - end - - for _, k in ipairs(keys) do - local v = val[k] - json_text = json_text .. spaces .. (isArray and "" or '"' .. escape_str(tostring(k)) .. '": ') - serialize(v, level + 1) - json_text = json_text .. ",\n" - end - - json_text = string.sub(json_text, 1, -3) .. "\n" .. string.rep(" ", (level - 1) * indent) .. (isArray and "]" or "}") - stack[val] = nil - elseif type(val) == "string" then - json_text = json_text .. '"' .. escape_str(val) .. '"' - elseif type(val) == "number" then - if val % 1 == 0 then - json_text = json_text .. tostring(math.floor(val)) - else - json_text = json_text .. tostring(val) - end - elseif type(val) == "boolean" then - json_text = json_text .. tostring(val) - elseif is_null(val) then - json_text = json_text .. "null" - else - error("Invalid value type: " .. type(val)) - end - end - serialize(value, 1) - return json_text -end - -function string_formatter(str, variables) - return str:gsub("%${(.-)}", function(var) - return variables[var] or "${" .. var .. "}" - end) -end - -function pack_plugin(target,plugin_define) - import("lib.detect.find_file") - - local manifest_path = find_file("manifest.json", os.projectdir()) - if manifest_path then - local manifest = io.readfile(manifest_path) - local bindir = path.join(os.projectdir(), "bin") - local outputdir = path.join(bindir, plugin_define.pluginName) - local targetfile = path.join(outputdir, plugin_define.pluginFile) - local pdbfile = path.join(outputdir, path.basename(plugin_define.pluginFile) .. ".pdb") - local manifestfile = path.join(outputdir, "manifest.json") - local oritargetfile = target:targetfile() - local oripdbfile = path.join(path.directory(oritargetfile), path.basename(oritargetfile) .. ".pdb") - - os.mkdir(outputdir) - os.cp(oritargetfile, targetfile) - if os.isfile(oripdbfile) then - os.cp(oripdbfile, pdbfile) - end - - formattedmanifest = string_formatter(manifest, plugin_define) - io.writefile(manifestfile,formattedmanifest) - - -- Copy i18n files. - local langfile = path.join(os.projectdir(), "src", "lang") - os.cp(langfile, path.join(outputdir, "lang")) - - -- Copy base library files. - local baselib_file = path.join(os.projectdir(), "src", "baselib") - os.cp(baselib_file, outputdir) - - cprint("${bright green}[Plugin Packer]: ${reset}plugin already generated to " .. outputdir) - else - cprint("${bright yellow}warn: ${reset}not found manifest.json in root dir!") - end -end - - -return { - pack_plugin = pack_plugin, - beautify_json = beautify_json, - string_formatter = string_formatter -} diff --git a/xmake.lua b/xmake.lua index 381f075..115ad56 100644 --- a/xmake.lua +++ b/xmake.lua @@ -2,6 +2,14 @@ add_rules("mode.debug", "mode.release") add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git") +if is_config("target_type", "server") then + add_requires("levilamina develop", {configs = {target_type = "server"}}) +else + add_requires("levilamina develop", {configs = {target_type = "client"}}) +end + +add_requires("levibuildscript") + add_requires( "demangler", "dyncall", @@ -9,7 +17,6 @@ add_requires( "legacymoney 0.8.3", "legacyparticleapi 0.8.3", "legacyremotecall 0.8.3", - "levilamina 0.13.5", "lightwebsocketclient", "magic_enum", "nlohmann_json", @@ -38,29 +45,25 @@ if not has_config("vs_runtime") then set_runtimes("MD") end +option("target_type") + set_default("server") + set_showmenu(true) + set_values("server", "client") +option_end() + option("backend") set_default("lua") set_values("lua", "quickjs", "python", "nodejs") target("legacy-script-engine") - add_cxflags( - "/EHa", - "/utf-8", - "/sdl", - "/W4" - ) + add_rules("@levibuildscript/linkrule") + add_rules("@levibuildscript/modpacker") + add_cxflags("/EHa", "/utf-8", "/W4", "/w44265", "/w44289", "/w44296", "/w45263", "/w44738", "/w45204") add_defines( "NOMINMAX", "UNICODE", "_AMD64_" ) - add_files( - "src/**.cpp" - ) - add_includedirs( - "src", - "src/legacy" - ) add_packages( "cpp-httplib", "demangler", @@ -78,9 +81,6 @@ target("legacy-script-engine") "sqlite3", "toml++" ) - add_shflags( - "/DELAYLOAD:bedrock_server.dll" - ) set_exceptions("none") set_kind("shared") set_languages("cxx20") @@ -112,14 +112,11 @@ target("legacy-script-engine") end - after_build(function (target) - local plugin_packer = import("scripts.after_build") - - local plugin_define = { - pluginName = target:basename(), - pluginFile = path.filename(target:targetfile()), - } - - plugin_packer.pack_plugin(target,plugin_define) - end) + add_files( + "src/**.cpp" + ) + add_includedirs( + "src", + "src/legacy" + )