Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/build
/.xmake
/.vscode/compile_commands.json
/.vscode/compile_commands.json
/generated
/vsxmake2022
/.importer
4 changes: 2 additions & 2 deletions data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
Expand Down
13 changes: 11 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"meta": {
"uuid": "00000000-0000-0000-0000-000000000000",
"namespace": "fx_template",
"name": "Amethyst-Template",
"version": "1.0.0",
"author": "FrederoxDev"
"version": "0.0.0-dev",
"author": "FrederoxDev",
"dependencies": [
{
"dependency_uuid": "e56c3987-fd4a-4590-9923-a07fc4be7250",
"dependency_namespace": "amethyst",
"version_range": ">=2.0.0 <2.1.0"
}
]
}
}
109 changes: 107 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -54,6 +54,68 @@ set_toolchains("msvc", {asm = "nasm"})

set_project(mod_name)

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")

on_load(function (package)
import("net.http")
import("core.base.json")
import("utils.archive")

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(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("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 Runtime-Importer...")

http.download(url, zipfile)
archive.extract(zipfile, bin_dir)
io.writefile(installed_version_file, latest_tag)
end

package:addenv("PATH", bin_dir)

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

if should_regenerate_pch then
print("Generating precompiled header of STL...")
os.mkdir(generated_dir)

local clang_args = {
path.join(bin_dir, "clang++.exe"),
"-x", "c++-header",
path.join(path.join(bin_dir, "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("Runtime-Importer", {system = false})

target(mod_name)
set_kind("shared")
add_deps("AmethystAPI", "libhat")
Expand Down Expand Up @@ -87,17 +149,60 @@ target(mod_name)
)

-- Deps
add_packages("Runtime-Importer")
add_packages("AmethystAPI", "libhat")
add_links("user32", "oleaut32", "windowsapp")
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)
local input_dir = path.join(amethystApiPath, "src"):gsub("\\", "/")
local include_dir = path.join(amethystApiPath, "include"):gsub("\\", "/")

local gen_sym_args = {
".importer/bin/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 = {
".importer/bin/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 importer_dir = path.join(os.curdir(), ".importer");
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
os.mkdir(modFolder)
end
os.cp(src_json, dst_json)

local tweaker_args = {
".importer/bin/Amethyst.ModuleTweaker.exe",
"--module", target:targetfile(),
"--symbols", string.format("%s/symbols", generated_dir)
}
print('Tweaking output file...')
os.exec(table.concat(tweaker_args, " "))
end)