From 11ce9731ac440525dd68434cd36cfc35db9e8d62 Mon Sep 17 00:00:00 2001 From: Raony Fernandes dos Reis <75029692+raonygamer@users.noreply.github.com> Date: Thu, 11 Sep 2025 13:56:06 -0300 Subject: [PATCH 1/7] Integrate RuntimeImporter and automate code generation Added RuntimeImporter as a package and automated its installation and precompiled header generation. Updated build steps to generate symbol JSON files and Minecraft.Windows.lib before build, and to tweak the output module after build. Updated .gitignore to exclude generated and vsxmake2022 directories. --- .gitignore | 4 ++- xmake.lua | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 55dafad..ceb7b7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /build /.xmake -/.vscode/compile_commands.json \ No newline at end of file +/.vscode/compile_commands.json +/generated +/vsxmake2022 diff --git a/xmake.lua b/xmake.lua index e1a6a37..cd7bfe2 100644 --- a/xmake.lua +++ b/xmake.lua @@ -54,6 +54,63 @@ set_toolchains("msvc", {asm = "nasm"}) set_project(mod_name) +package("RuntimeImporter") + set_kind("binary") + set_homepage("https://github.com/AmethystAPI/Runtime-Importer") + set_description("The runtime importer enables importing functions and variables from the game just by defining annotations in header files") + + on_load(function (package) + import("net.http") + import("core.base.json") + import("utils.archive") + + local releases_file = path.join(os.tmpdir(), "runtimeimporter.releases.json") + http.download("https://api.github.com/repos/AmethystAPI/Runtime-Importer/releases/latest", releases_file) + + local release = json.loadfile(releases_file) + local latest_tag = release.tag_name + local installed_version_file = path.join(package:installdir(), "version.txt") + local installed_version = os.isfile(installed_version_file) and io.readfile(installed_version_file) or "0.0.0" + local should_reinstall = installed_version ~= latest_tag + + if should_reinstall then + print("RuntimeImporter is outdated, reinstalling...") + print("Latest version is " .. latest_tag) + local url = "https://github.com/AmethystAPI/Runtime-Importer/releases/latest/download/Runtime-Importer.zip" + local zipfile = path.join(os.tmpdir(), "Runtime-Importer.zip") + print("Installing RuntimeImporter...") + + http.download(url, zipfile) + archive.extract(zipfile, package:installdir("bin")) + io.writefile(installed_version_file, latest_tag) + end + + package:addenv("PATH", package:installdir("bin")) + + local generated_dir = path.join(os.curdir(), "generated") + local pch_file = path.join(generated_dir, "pch.hpp.pch") + local should_regenerate_pch = os.exists(pch_file) == false or should_reinstall + if should_regenerate_pch then + print("Generating precompiled header of STL...") + os.mkdir(generated_dir) + local clang_args = { + path.join(package:installdir("bin"), "clang++.exe"), + "-x", "c++-header", + path.join(package:installdir("bin/utils"), "pch.hpp"), + "-std=c++23", + "-fms-extensions", + "-fms-compatibility", + "-o", pch_file + } + os.exec(table.concat(clang_args, " ")) + end + end) + + on_install(function (package) + end) +package_end() + +add_requires("RuntimeImporter", {system = false}) target(mod_name) set_kind("shared") add_deps("AmethystAPI", "libhat") @@ -87,17 +144,58 @@ target(mod_name) ) -- Deps + add_packages("RuntimeImporter") add_packages("AmethystAPI", "libhat") - add_links("user32", "oleaut32", "windowsapp") + add_links("user32", "oleaut32", "windowsapp", path.join(os.curdir(), "generated/lib/Minecraft.Windows.lib")) add_includedirs("src", {public = true}) add_headerfiles("src/**.hpp") + before_build(function (target) + local generated_dir = path.join(os.curdir(), "generated") + local input_dir = path.join(amethystApiPath, "src"):gsub("\\", "/") + local include_dir = path.join(amethystApiPath, "include"):gsub("\\", "/") + + local gen_sym_args = { + "Amethyst.SymbolGenerator.exe", + "--input", string.format("%s", input_dir), + "--output", string.format("%s", generated_dir), + "--filters", "minecraft", + "--", + "-x c++", + "-include-pch", path.join(generated_dir, "pch.hpp.pch"), + "-std=c++23", + "-fms-extensions", + "-fms-compatibility", + string.format('-I%s', include_dir), + string.format('-I%s', input_dir) + } + print('Generating *.symbols.json files for headers...') + os.exec(table.concat(gen_sym_args, " ")) + + local gen_lib_args = { + "Amethyst.LibraryGenerator.exe", + "--input", string.format("%s/symbols", generated_dir), + "--output", string.format("%s/lib", generated_dir) + } + print('Generating Minecraft.Windows.lib file...') + os.exec(table.concat(gen_lib_args, " ")) + end) + after_build(function (target) + local generated_dir = path.join(os.curdir(), "generated") local src_json = path.join("mod.json") local dst_json = path.join(modFolder, "mod.json") if not os.isdir(modFolder) then os.mkdir(modFolder) end os.cp(src_json, dst_json) + + local tweaker_args = { + "Amethyst.ModuleTweaker.exe", + "--module", target:targetfile(), + "--symbols", string.format("%s/symbols", generated_dir) + } + print('Tweaking output file...') + os.exec(table.concat(tweaker_args, " ")) end) \ No newline at end of file From 89d89bdd47eff2b75a68b89a55a923fe5e44b29c Mon Sep 17 00:00:00 2001 From: Raony Fernandes dos Reis <75029692+raonygamer@users.noreply.github.com> Date: Thu, 11 Sep 2025 18:03:43 -0300 Subject: [PATCH 2/7] Stuff --- .gitignore | 1 + xmake.lua | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index ceb7b7e..1775d4c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.vscode/compile_commands.json /generated /vsxmake2022 +/.importer diff --git a/xmake.lua b/xmake.lua index cd7bfe2..4305539 100644 --- a/xmake.lua +++ b/xmake.lua @@ -64,39 +64,44 @@ package("RuntimeImporter") import("core.base.json") import("utils.archive") - local releases_file = path.join(os.tmpdir(), "runtimeimporter.releases.json") + local releases_file = path.join(os.tmpdir(), "runtime-importer.releases.json") http.download("https://api.github.com/repos/AmethystAPI/Runtime-Importer/releases/latest", releases_file) + local importer_dir = path.join(os.curdir(), ".importer"); + local bin_dir = path.join(importer_dir, "bin"); local release = json.loadfile(releases_file) local latest_tag = release.tag_name - local installed_version_file = path.join(package:installdir(), "version.txt") + local installed_version_file = path.join(importer_dir, "version.txt") local installed_version = os.isfile(installed_version_file) and io.readfile(installed_version_file) or "0.0.0" local should_reinstall = installed_version ~= latest_tag + if should_reinstall then - print("RuntimeImporter is outdated, reinstalling...") + print("Runtime-Importer is outdated, reinstalling...") print("Latest version is " .. latest_tag) local url = "https://github.com/AmethystAPI/Runtime-Importer/releases/latest/download/Runtime-Importer.zip" local zipfile = path.join(os.tmpdir(), "Runtime-Importer.zip") - print("Installing RuntimeImporter...") + print("Installing Runtime-Importer...") http.download(url, zipfile) - archive.extract(zipfile, package:installdir("bin")) + archive.extract(zipfile, bin_dir) io.writefile(installed_version_file, latest_tag) end - package:addenv("PATH", package:installdir("bin")) + package:addenv("PATH", bin_dir) - local generated_dir = path.join(os.curdir(), "generated") + local generated_dir = path.join(importer_dir, "generated") local pch_file = path.join(generated_dir, "pch.hpp.pch") local should_regenerate_pch = os.exists(pch_file) == false or should_reinstall + if should_regenerate_pch then print("Generating precompiled header of STL...") os.mkdir(generated_dir) + local clang_args = { - path.join(package:installdir("bin"), "clang++.exe"), + path.join(bin_dir, "clang++.exe"), "-x", "c++-header", - path.join(package:installdir("bin/utils"), "pch.hpp"), + path.join(path.join(bin_dir, "utils"), "pch.hpp"), "-std=c++23", "-fms-extensions", "-fms-compatibility", @@ -152,7 +157,8 @@ target(mod_name) add_headerfiles("src/**.hpp") before_build(function (target) - local generated_dir = path.join(os.curdir(), "generated") + local importer_dir = path.join(os.curdir(), ".importer"); + local generated_dir = path.join(importer_dir, "generated") local input_dir = path.join(amethystApiPath, "src"):gsub("\\", "/") local include_dir = path.join(amethystApiPath, "include"):gsub("\\", "/") @@ -183,7 +189,8 @@ target(mod_name) end) after_build(function (target) - local generated_dir = path.join(os.curdir(), "generated") + local importer_dir = path.join(os.curdir(), ".importer"); + local generated_dir = path.join(importer_dir, "generated") local src_json = path.join("mod.json") local dst_json = path.join(modFolder, "mod.json") if not os.isdir(modFolder) then From c96a59408c3cd794e699477c551a34b38c37c042 Mon Sep 17 00:00:00 2001 From: Raony Fernandes dos Reis <75029692+raonygamer@users.noreply.github.com> Date: Thu, 11 Sep 2025 18:18:37 -0300 Subject: [PATCH 3/7] Update xmake.lua --- xmake.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xmake.lua b/xmake.lua index 4305539..21eb2a3 100644 --- a/xmake.lua +++ b/xmake.lua @@ -90,7 +90,7 @@ package("RuntimeImporter") package:addenv("PATH", bin_dir) - local generated_dir = path.join(importer_dir, "generated") + local generated_dir = path.join(importer_dir) local pch_file = path.join(generated_dir, "pch.hpp.pch") local should_regenerate_pch = os.exists(pch_file) == false or should_reinstall @@ -151,14 +151,14 @@ target(mod_name) -- Deps add_packages("RuntimeImporter") add_packages("AmethystAPI", "libhat") - add_links("user32", "oleaut32", "windowsapp", path.join(os.curdir(), "generated/lib/Minecraft.Windows.lib")) + add_links("user32", "oleaut32", "windowsapp", path.join(os.curdir(), ".importer/lib/Minecraft.Windows.lib")) add_includedirs("src", {public = true}) add_headerfiles("src/**.hpp") before_build(function (target) local importer_dir = path.join(os.curdir(), ".importer"); - local generated_dir = path.join(importer_dir, "generated") + local generated_dir = path.join(importer_dir) local input_dir = path.join(amethystApiPath, "src"):gsub("\\", "/") local include_dir = path.join(amethystApiPath, "include"):gsub("\\", "/") @@ -190,7 +190,7 @@ target(mod_name) after_build(function (target) local importer_dir = path.join(os.curdir(), ".importer"); - local generated_dir = path.join(importer_dir, "generated") + local generated_dir = path.join(importer_dir) local src_json = path.join("mod.json") local dst_json = path.join(modFolder, "mod.json") if not os.isdir(modFolder) then From 3cc7aaa0704234d866355d5e392cbdb41795aff8 Mon Sep 17 00:00:00 2001 From: Freddie <69014593+FrederoxDev@users.noreply.github.com> Date: Thu, 11 Sep 2025 22:25:00 +0100 Subject: [PATCH 4/7] Fix name consistency --- xmake.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xmake.lua b/xmake.lua index 21eb2a3..4a8bd84 100644 --- a/xmake.lua +++ b/xmake.lua @@ -54,7 +54,7 @@ set_toolchains("msvc", {asm = "nasm"}) set_project(mod_name) -package("RuntimeImporter") +package("Runtime-Importer") set_kind("binary") set_homepage("https://github.com/AmethystAPI/Runtime-Importer") set_description("The runtime importer enables importing functions and variables from the game just by defining annotations in header files") @@ -75,7 +75,6 @@ package("RuntimeImporter") local installed_version = os.isfile(installed_version_file) and io.readfile(installed_version_file) or "0.0.0" local should_reinstall = installed_version ~= latest_tag - if should_reinstall then print("Runtime-Importer is outdated, reinstalling...") print("Latest version is " .. latest_tag) @@ -115,7 +114,8 @@ package("RuntimeImporter") end) package_end() -add_requires("RuntimeImporter", {system = false}) +add_requires("Runtime-Importer", {system = false}) + target(mod_name) set_kind("shared") add_deps("AmethystAPI", "libhat") @@ -149,7 +149,7 @@ target(mod_name) ) -- Deps - add_packages("RuntimeImporter") + add_packages("Runtime-Importer") add_packages("AmethystAPI", "libhat") add_links("user32", "oleaut32", "windowsapp", path.join(os.curdir(), ".importer/lib/Minecraft.Windows.lib")) From 2c18688a5299d39d94262b007c6e6f679c415e94 Mon Sep 17 00:00:00 2001 From: Raony Fernandes dos Reis Date: Sun, 28 Sep 2025 00:36:14 -0300 Subject: [PATCH 5/7] Add dependency info to mod.json Introduced a UUID field and a dependencies array to the mod.json file, specifying required Amethyst version range and dependency UUID. This enhances mod metadata and ensures proper dependency management. --- mod.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mod.json b/mod.json index 2c6d6bb..2b792da 100644 --- a/mod.json +++ b/mod.json @@ -1,7 +1,15 @@ { "meta": { + "uuid": "00000000-0000-0000-0000-000000000000", "name": "Amethyst-Template", "version": "1.0.0", - "author": "FrederoxDev" + "author": "FrederoxDev", + "dependencies": [ + { + "dependency_uuid": "e56c3987-fd4a-4590-9923-a07fc4be7250", + "dependency_namespace": "amethyst", + "version_range": ">=2.0.0 <2.1.0" + } + ] } } \ No newline at end of file From 6d6bc6e1c1895b1ebc5033c88d40b04e39c8a22c Mon Sep 17 00:00:00 2001 From: Raony Fernandes dos Reis Date: Sun, 28 Sep 2025 00:39:28 -0300 Subject: [PATCH 6/7] Update version to 0.0.0-dev and adjust paths Changed mod version to 0.0.0-dev in mod.json and updated related paths in config.json and xmake.lua to reflect the new version. Also updated executable paths in xmake.lua to use .importer/bin directory. --- data/config.json | 4 ++-- mod.json | 2 +- xmake.lua | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/data/config.json b/data/config.json index 06ae859..a75b15e 100644 --- a/data/config.json +++ b/data/config.json @@ -13,10 +13,10 @@ "profiles": { "default": { "export": { - "bpPath": "%localappdata%/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/amethyst/mods/Amethyst-Template@dev/behavior_packs/main_bp", + "bpPath": "%localappdata%/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/amethyst/mods/Amethyst-Template@0.0.0-dev/behavior_packs/main_bp", "build": "standard", "readOnly": false, - "rpPath": "%localappdata%/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/amethyst/mods/Amethyst-Template@dev/resource_packs/main_rp", + "rpPath": "%localappdata%/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/amethyst/mods/Amethyst-Template@0.0.0-dev/resource_packs/main_rp", "target": "exact" }, "filters": [] diff --git a/mod.json b/mod.json index 2b792da..300cb7f 100644 --- a/mod.json +++ b/mod.json @@ -2,7 +2,7 @@ "meta": { "uuid": "00000000-0000-0000-0000-000000000000", "name": "Amethyst-Template", - "version": "1.0.0", + "version": "0.0.0-dev", "author": "FrederoxDev", "dependencies": [ { diff --git a/xmake.lua b/xmake.lua index 4a8bd84..64296df 100644 --- a/xmake.lua +++ b/xmake.lua @@ -35,7 +35,7 @@ else modFolder = path.join( amethystFolder, "mods", - string.format("%s@dev", mod_name) + string.format("%s@0.0.0-dev", mod_name) ) end @@ -163,7 +163,7 @@ target(mod_name) local include_dir = path.join(amethystApiPath, "include"):gsub("\\", "/") local gen_sym_args = { - "Amethyst.SymbolGenerator.exe", + ".importer/bin/Amethyst.SymbolGenerator.exe", "--input", string.format("%s", input_dir), "--output", string.format("%s", generated_dir), "--filters", "minecraft", @@ -180,7 +180,7 @@ target(mod_name) os.exec(table.concat(gen_sym_args, " ")) local gen_lib_args = { - "Amethyst.LibraryGenerator.exe", + ".importer/bin/Amethyst.LibraryGenerator.exe", "--input", string.format("%s/symbols", generated_dir), "--output", string.format("%s/lib", generated_dir) } @@ -199,7 +199,7 @@ target(mod_name) os.cp(src_json, dst_json) local tweaker_args = { - "Amethyst.ModuleTweaker.exe", + ".importer/bin/Amethyst.ModuleTweaker.exe", "--module", target:targetfile(), "--symbols", string.format("%s/symbols", generated_dir) } From 533367813f03df7e2b25ad830d95d18bc9caf3e7 Mon Sep 17 00:00:00 2001 From: Raony Fernandes dos Reis Date: Sun, 28 Sep 2025 00:45:23 -0300 Subject: [PATCH 7/7] Update mod.json --- mod.json | 1 + 1 file changed, 1 insertion(+) diff --git a/mod.json b/mod.json index 300cb7f..e6fde37 100644 --- a/mod.json +++ b/mod.json @@ -1,6 +1,7 @@ { "meta": { "uuid": "00000000-0000-0000-0000-000000000000", + "namespace": "fx_template", "name": "Amethyst-Template", "version": "0.0.0-dev", "author": "FrederoxDev",