diff --git a/.gitmodules b/.gitmodules index e4b076c..9e921cd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "minparse"] path = minparse url = https://github.com/Josh194/ArgParse +[submodule "zydis"] + path = zydis + url = https://github.com/zyantific/zydis.git diff --git a/CMakeLists.txt b/CMakeLists.txt index a8671b9..fe0770c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.19) +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "Do not build in source") +endif() + project(FMCB) include(CheckIPOSupported) @@ -8,9 +12,14 @@ check_ipo_supported() # maybe error check to insure version was found file(READ info.json INFO_JSON) string(JSON VERSION GET "${INFO_JSON}" version) - message("Server version is ${VERSION}") +set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install) # Should this be in /bin? +message("Install location is \"${CMAKE_INSTALL_PREFIX}\"") + +set(GRAPHVIZ_GENERATE_PER_TARGET false) +set(GRAPHVIZ_GENERATE_DEPENDERS false) + set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo" CACHE STRING "") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/Factorio/FMCB/control.lua b/Factorio/FMCB/control.lua new file mode 100644 index 0000000..9e4ee25 --- /dev/null +++ b/Factorio/FMCB/control.lua @@ -0,0 +1,15 @@ +script.on_event({defines.events.on_tick}, + function (e) + if e.tick == 0 then + game.print("FMCB has been correctly loaded") + game.print(fmcb.int_cube(4)) + + -- local chest_inventory = entity.get_inventory(1) + -- local item = "coal" + + -- for s = 1, 2 do + -- chest_inventory[s].set_stack{name = item, count = game.item_prototypes[item].stack_size} + -- end + end + end +) \ No newline at end of file diff --git a/Factorio/FMCB/data.lua b/Factorio/FMCB/data.lua new file mode 100644 index 0000000..350fff9 --- /dev/null +++ b/Factorio/FMCB/data.lua @@ -0,0 +1,4 @@ +fmcb = require("libFMCBLua") + +require("prototypes.genericSend") +require("prototypes.genericSend") \ No newline at end of file diff --git a/Factorio/FMCB_0.0.1/info.json b/Factorio/FMCB/info.json similarity index 68% rename from Factorio/FMCB_0.0.1/info.json rename to Factorio/FMCB/info.json index 40a74e9..8a68134 100644 --- a/Factorio/FMCB_0.0.1/info.json +++ b/Factorio/FMCB/info.json @@ -1,11 +1,11 @@ { "name": "FMCB", - "version": "0.0.1", + "version": "0.1.0", "title": "FMCB", "author": "MegaGlub & the4naves", "contact": "", "homepage": "https://github.com/Josh194/FMCB", - "factorio_version": "0.17", - "dependencies": [ "base >= 0.17" ], + "factorio_version": "1.1", + "dependencies": [], "description": "Adds the factorio FMCB subsystem." } \ No newline at end of file diff --git a/Factorio/FMCB_0.0.1/prototypes/genericReceive.lua b/Factorio/FMCB/prototypes/genericReceive.lua similarity index 100% rename from Factorio/FMCB_0.0.1/prototypes/genericReceive.lua rename to Factorio/FMCB/prototypes/genericReceive.lua diff --git a/Factorio/FMCB/prototypes/genericSend.lua b/Factorio/FMCB/prototypes/genericSend.lua new file mode 100644 index 0000000..e69de29 diff --git a/Factorio/FMCB_0.0.1/Bridge.cpp b/Factorio/FMCB_0.0.1/Bridge.cpp deleted file mode 100644 index 5ea81cd..0000000 --- a/Factorio/FMCB_0.0.1/Bridge.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - #include "lauxlib.h" - - /* Pop-up a Windows message box with your choice of message and caption */ - int lua_msgbox(lua_State* L) - { - const char* message = luaL_checkstring(L, 1); - const char* caption = luaL_optstring(L, 2, ""); - int result = MessageBox(NULL, message, caption, MB_OK); - lua_pushnumber(L, result); - return 1; - } - - int __declspec(dllexport) libinit (lua_State* L) - { - lua_register(L, "msgbox", lua_msgbox); - return 0; - } \ No newline at end of file diff --git a/Factorio/FMCB_0.0.1/control.lua b/Factorio/FMCB_0.0.1/control.lua deleted file mode 100644 index 371198c..0000000 --- a/Factorio/FMCB_0.0.1/control.lua +++ /dev/null @@ -1,14 +0,0 @@ -script.on_event({defines.events.on_tick}, - function (e) - if e.tick == 0 then - game.print("FMCB has been correctly loaded") - - local chest_inventory = entity.get_inventory(1) - local item = "coal" - - for s = 1, 2 do - chest_inventory[s].set_stack{name = item, count = game.item_prototypes[item].stack_size} - end - end - end -) \ No newline at end of file diff --git a/Factorio/FMCB_0.0.1/data.lua b/Factorio/FMCB_0.0.1/data.lua deleted file mode 100644 index b96be56..0000000 --- a/Factorio/FMCB_0.0.1/data.lua +++ /dev/null @@ -1,2 +0,0 @@ -require("prototypes.portalSend") -require("prototypes.portalReceive") \ No newline at end of file diff --git a/Factorio/FMCB_0.0.1/prototypes/genericSend.lua b/Factorio/FMCB_0.0.1/prototypes/genericSend.lua deleted file mode 100644 index 3a64f55..0000000 --- a/Factorio/FMCB_0.0.1/prototypes/genericSend.lua +++ /dev/null @@ -1,15 +0,0 @@ -local genSend = table.deepcopy(data.raw.container) - -script.onPlaced({defines.events.on_built_entity}, - function (e) - --External Function - registerSend(e.created_entity) - end -) - -script.onDestroyed({defines.events.on_pre_player_mined_item}, - function (e) - --External Function - unregisterSend(e.entity) - end -) \ No newline at end of file diff --git a/client/wrapper/Lua/CMakeLists.txt b/client/wrapper/Lua/CMakeLists.txt index e69de29..0b01295 100644 --- a/client/wrapper/Lua/CMakeLists.txt +++ b/client/wrapper/Lua/CMakeLists.txt @@ -0,0 +1,12 @@ +find_package(Lua) +include_directories(${LUA_INCLUDE_DIR}) + +add_library(LuaWrapperDef SHARED Memory.c) + +target_link_libraries(LuaWrapperDef ClientCore ${LUA_LIBRARIES}) + +set_target_properties(LuaWrapperDef PROPERTIES OUTPUT_NAME "FMCBLua") # Can this be placed in add_library? + +install(TARGETS LuaWrapperDef) + +# Should we create some kind of lua archive? \ No newline at end of file diff --git a/client/wrapper/Lua/FMCB.lua b/client/wrapper/Lua/FMCB.lua new file mode 100644 index 0000000..3fb9c2f --- /dev/null +++ b/client/wrapper/Lua/FMCB.lua @@ -0,0 +1,11 @@ +arr = {2, 5, 6} + +function printAll() + for i = 1, 3 do + print(arr[i]) + end +end + +test = require("libFMCBLua") +print(test.int_cube(3)) +printAll() \ No newline at end of file diff --git a/client/wrapper/Lua/Memory.c b/client/wrapper/Lua/Memory.c new file mode 100644 index 0000000..e5691da --- /dev/null +++ b/client/wrapper/Lua/Memory.c @@ -0,0 +1,21 @@ +#include "Memory.h" +#include "lauxlib.h" + +static int iCube(lua_State *L) { + int x = luaL_checknumber(L, 1); + + lua_pushnumber(L, x * x * x); + + return 1; // Number of return values +} + +static const luaL_Reg fmcbReg[] = { + {"int_cube", iCube}, + {NULL, NULL} +}; + +LUALIB_API int luaopen_libFMCBLua(lua_State *L) { + luaL_newlib(L, fmcbReg); // ? Is this correct? + + return 1; // ? What does Lua expect here? +} \ No newline at end of file diff --git a/client/wrapper/Lua/Memory.h b/client/wrapper/Lua/Memory.h new file mode 100644 index 0000000..cd60a28 --- /dev/null +++ b/client/wrapper/Lua/Memory.h @@ -0,0 +1,4 @@ +// ? (C++) Could we just use C instead? The API is designed for it after all. +#include "lua.h" + +LUALIB_API int luaopen_libFMCBLua(lua_State *L); // ? (C++) Should this be in a namespace? \ No newline at end of file diff --git a/zydis b/zydis new file mode 160000 index 0000000..25193db --- /dev/null +++ b/zydis @@ -0,0 +1 @@ +Subproject commit 25193db008e8799ff59fd655c2a26b2ffd79d40d