Skip to content

Commit

Permalink
Bunch of non-functional WIP linux stuff from 1.5 years ago
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Dec 11, 2023
1 parent bf1eadf commit 29ea7d8
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 73 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ src/out/
src/vc140.pdb

src/vc140.idb

src/CMakeSettings.json
5 changes: 5 additions & 0 deletions misc/linuxLaunchScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

export LD_PRELOAD=InterceptHost.so

./ArmaReforgerServer $@
3 changes: 3 additions & 0 deletions misc/nixShellCMakeWrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/nix/store/3af6g226v4hsv6x7xzh23d6wqyq0nzjp-nix-2.10.3/bin/nix-shell -p gcc --run "cmake $@"
43 changes: 38 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,47 @@
cmake_minimum_required (VERSION 3.12)
project (Intercept2 CXX ASM)

find_package (Threads)

if(MSVC)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest" )
#elseif(MSVC)
# message(FATAL_ERROR "ERROR: You need a C++17 compatible compiler")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest" )
else()

# https://www.reddit.com/r/debian/comments/mmure2/comment/hwcffeo/?utm_source=share&utm_medium=web2x&context=3
# https://stackoverflow.com/questions/17275348/how-to-specify-new-gcc-path-for-cmake
# install clang

# /nix/store/grd724gvgblkvklrmbdyqm5jp8phyb7r-cmake-3.23.2/bin/cmake -G "Ninja" -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE:STRING="Debug" /home/wolf/projects/interceptar/src/src/CMakeLists.txt
# and also do this https://stackoverflow.com/a/58338868
# export CC=/nix/store/0vyacyskar330fsp3bnmk75brl1vlg6d-clang-wrapper-14.0.6/bin/clang
# export CXX=/nix/store/0vyacyskar330fsp3bnmk75brl1vlg6d-clang-wrapper-14.0.6/bin/clang++
# export CPLUS_INCLUDE_PATH=/nix/store/567idnfsci29qkwvpmy0yal96wy1qib3-gcc-12.1.0/include/c++/12.1.0/:/nix/store/567idnfsci29qkwvpmy0yal96wy1qib3-gcc-12.1.0/include/c++/12.1.0/x86_64-unknown-linux-gnu
# export TMPDIR=$PREFIX/tmp

if(EXISTS "/nix/store/0vyacyskar330fsp3bnmk75brl1vlg6d-clang-wrapper-14.0.6/bin/clang") # Dedmen hack to use my correct cland version
set(CMAKE_C_COMPILER "/nix/store/0vyacyskar330fsp3bnmk75brl1vlg6d-clang-wrapper-14.0.6/bin/clang" CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER "/nix/store/0vyacyskar330fsp3bnmk75brl1vlg6d-clang-wrapper-14.0.6/bin/clang++" CACHE PATH "" FORCE)
message("##################################################################################")
endif()


if(CMAKE_COMPILER_IS_GNUCXX)
# https://www.reddit.com/r/debian/comments/mmure2/comment/hwcffeo/?utm_source=share&utm_medium=web2x&context=3
# https://stackoverflow.com/questions/17275348/how-to-specify-new-gcc-path-for-cmake
# install gcc12
# then inside shell run `whereis gcc` to find path to gcc 12 install, and insert that below. Or just run a modern linux distribution that has gcc12 already
# run cmake inside nix shell, I tried to get it working with visual studio remote linux compiling, but nothing really works to let it run inside the nix environemtn
# cmake -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" ../CMakeLists.txt

if(EXISTS "/nix/store/567idnfsci29qkwvpmy0yal96wy1qib3-gcc-12.1.0/bin/gcc") # Dedmen hack to use my correct GCC version
set(CMAKE_C_COMPILER "/nix/store/567idnfsci29qkwvpmy0yal96wy1qib3-gcc-12.1.0/bin/gcc" CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER "/nix/store/567idnfsci29qkwvpmy0yal96wy1qib3-gcc-12.1.0/bin/g++" CACHE PATH "" FORCE)
message("##################################################################################")
endif()
endif()
endif()


find_package (Threads)

message("GENERATOR USED: '${CMAKE_GENERATOR}'")
message("COMPILER USED: '${CMAKE_CXX_COMPILER_ID}'")

Expand Down
27 changes: 0 additions & 27 deletions src/CMakeSettings.json

This file was deleted.

115 changes: 114 additions & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,121 @@
cmake_minimum_required (VERSION 3.13)

file(GLOB_RECURSE CommonSources *.ixx)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

file(GLOB_RECURSE CommonSources *.nothing)
SOURCE_GROUP("common" FILES ${CommonSources})

SET(CommonSources "${CommonSources}" CACHE INTERNAL "CommonSources")



function(add_module name)
message("Module target ${CMAKE_CURRENT_SOURCE_DIR}/${ARGN}")

add_custom_target(${name}.gcm
COMMAND
${CMAKE_CXX_COMPILER}
"-std=c++20"
"-fmodules-ts"
"-xc++"
-c
${CMAKE_CURRENT_SOURCE_DIR}/${ARGN}
)
endfunction()

function(add_system_header_unit name)
add_custom_target(${name}.gcm
COMMAND
${CMAKE_CXX_COMPILER}
"-std=c++20"
"-fmodules-ts"
"-xc++-system-header"
"-nostartfiles" #???? shouldn't be here?!
${name}
)
endfunction()


file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/gcm.cache)

# GCC Bug?! https://stackoverflow.com/questions/67030839/how-to-use-modules-in-c-20-using-g
#add_module(interceptCommon interceptCommon.ixx)

#file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/interceptCommon.ixx DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/GCCBugFix.cpp)
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/interceptCommon.ixx ${CMAKE_CURRENT_SOURCE_DIR}/GCCBugFix.cpp COPYONLY)
add_module(interceptCommon interceptCommon.cpp)
add_custom_target(gccBugFixFile ALL COMMAND ${CMAKE_COMMAND} -E create_symlink "interceptCommon.ixx" "${CMAKE_CURRENT_SOURCE_DIR}/interceptCommon.cpp")
add_dependencies(interceptCommon.gcm gccBugFixFile)


#add_dependencies(interceptCommon.gcm gccBugFixFile)



#add_system_header_unit(string_view)
#add_system_header_unit(filesystem)
#add_system_header_unit(vector)
#add_system_header_unit(array)
#add_system_header_unit(charconv)
#add_system_header_unit(span)
#add_system_header_unit(cstdint)
#add_system_header_unit(functional)
#add_system_header_unit(typeinfo)
#add_system_header_unit(optional)
#add_dependencies(interceptCommon.gcm filesystem.gcm string_view.gcm vector.gcm array.gcm charconv.gcm span.gcm cstdint.gcm functional.gcm typeinfo.gcm optional.gcm)


add_custom_target(gcmLinkCommon ALL COMMAND ${CMAKE_COMMAND} -E create_symlink "../gcm.cache" "gcm.cache") # #TODO custom for plugin template
add_dependencies(interceptCommon.gcm gcmLinkCommon)

# g++ -std=c++20 -fmodules-ts -xc++-system-header iostream
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

function(add_module name)
message("Module target ${CMAKE_CURRENT_SOURCE_DIR}/${ARGN}")

file(MAKE_DIRECTORY ${PREBUILT_MODULE_PATH})
add_custom_target(${name}.pcm
COMMAND
${CMAKE_CXX_COMPILER}
-std=c++20
-stdlib=libc++
-fmodules-ts


#-fbuiltin-module-map
-fno-implicit-module-maps
-fno-implicit-modules
#-fimplicit-module-maps
-fprebuilt-module-path=${PREBUILT_MODULE_PATH}

-c
#-x c++-module
${CMAKE_CURRENT_SOURCE_DIR}/${ARGN}
-Xclang -emit-module-interface
-o ${PREBUILT_MODULE_PATH}/${name}.pcm

)
endfunction()




add_module(InterceptCommon interceptCommon.cpp)
# clang bug, doesn't handle .ixx even though it says it should, prints obscure error message about how -std=c++20 nor -fmodules-ts parameters are passed, even though they are!
add_custom_target(gccBugFixFile ALL COMMAND ${CMAKE_COMMAND} -E create_symlink "interceptCommon.ixx" "${CMAKE_CURRENT_SOURCE_DIR}/interceptCommon.cpp")
add_dependencies(InterceptCommon.pcm gccBugFixFile)

message("CXX ${CMAKE_CXX_COMPILER}")


else()

file(GLOB_RECURSE CommonSources *.ixx *.cxx)
SOURCE_GROUP("common" FILES ${CommonSources})

SET(CommonSources "${CommonSources}" CACHE INTERNAL "CommonSources")


endif()
14 changes: 6 additions & 8 deletions src/common/dllInterface.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

class VariableDataHolder;
class FunctionArgumentsHandler;
class FunctionResultHandler;
class ENF_Variable;
export class VariableDataHolder;
export class FunctionArgumentsHandler;
export class FunctionResultHandler;
export class ENF_Variable;


export typedef void (*ScriptFunc)(FunctionArgumentsHandler& args, FunctionResultHandler& result);
class IScriptClassBaseSimple;
export class IScriptClassBaseSimple;
export typedef void (*registerClassT)(IScriptClassBaseSimple* self, std::string_view name, bool doReg);

// Same as Enforce Script
Expand Down Expand Up @@ -73,8 +73,6 @@ inline uint8_t PtrHash(uintptr_t input) { //#TODO move to Util?
return res;
}

#include <Windows.h>

extern "C" {
extern BOOL WINAPI _DllMainCRTStartup(
HINSTANCE const instance,
Expand Down Expand Up @@ -151,7 +149,7 @@ export extern "C" BOOL InterceptEntryPoint(HINSTANCE const instance,

// Linux entry point

void __attribute__((constructor(0))) InterceptEntryPoint(void) {
inline void __attribute__((constructor(0))) InterceptEntryPoint(void) {

// find host
Util::BreakToDebuggerIfPresent();
Expand Down
4 changes: 2 additions & 2 deletions src/common/enfusionContainers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ENF_Array {
uint32_t size;


std::span<Type> AsSpan() const {
return std::span<Type>(data, size);
auto AsSpan() const {
return std::span(data, size);
}
};
52 changes: 43 additions & 9 deletions src/common/enfusionTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export enum class VariableSubType : uint32_t {
Pointer = 1 << 6
};

class VariableTypeInfo {
export class VariableTypeInfo {
uint32_t type{0}; // Type is only the first 4 bits, the rest is smth else
VariableSubType subtype{0};
public:
Expand Down Expand Up @@ -104,7 +104,7 @@ export class ENF_Variable : public VariableDataHolder {

// I would put the get templates into Variable Helper, but cannot use templates here, not supported in GCC https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85282

class VariableHelper;
export class VariableHelper;

namespace internal {
template<typename Type>
Expand Down Expand Up @@ -327,15 +327,15 @@ namespace internal {
} \
};

#ifndef __linux__ // GCC internal compiler error https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100583
//#ifndef __linux__ // GCC internal compiler error https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100583

ARRAYTYPE(Vector3)
ARRAYTYPE(const char*)
ARRAYTYPE(float)
ARRAYTYPE(int)
ARRAYTYPE(bool)

#endif
//#endif
#undef ARRAYTYPE


Expand Down Expand Up @@ -454,6 +454,14 @@ namespace internal {

template <class T, template <class> class U>
struct is_instance<U<T>, U> : public std::true_type {};


template <typename T>
struct is_span : public std::false_type {};

template <typename X>
struct is_span<std::span<X>> : public std::true_type {};

}

export class ClassInstanceVariable {
Expand All @@ -462,9 +470,8 @@ export class ClassInstanceVariable {


template <typename Type>
Type GetAs() const {

if constexpr (internal::is_instance<Type, std::span>::value) {
[[nodiscard]] Type GetAs() const {
if constexpr (internal::is_span<Type>::value) {
return std::span(getHelper()->GetAs<Type::pointer>(), variableTypeThing->GetSize());
} else
return getHelper()->GetAs<Type>();
Expand Down Expand Up @@ -536,15 +543,35 @@ export class ClassInstance {

uint32_t GetVariableIndex(std::string_view name) const {
auto& vars = *(ENF_Array<Variable*>*)((uintptr_t)classInfo + 0x58);
auto found = std::ranges::find_if(vars.AsSpan(), [name](const Variable* var) { return name.compare(var->GetName()) == 0; });
auto found = std::ranges::find_if(
#ifdef __linux__
vars.data, vars.data+vars.size // GCC internal compiler error, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100583
#else
vars.AsSpan()
#endif

, [name](const Variable* var) { return name.compare(var->GetName()) == 0; });
#ifdef __linux__
if (found == vars.data + vars.size) // GCC internal compiler error, span is broken??
#else
if (found == vars.AsSpan().end())
#endif
return -1;

#ifdef __linux__
return std::distance(vars.data, found); // GCC internal compiler error, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100583
#else
return std::distance(vars.AsSpan().begin(), found);
#endif
}

Variable* GetVariableRawAt(uint32_t index) const {
auto& vars = *(ENF_Array<Variable*>*)((uintptr_t)classInfo + 0x58);
#ifdef __linux__
auto var = vars.data[index]; // GCC internal compiler error, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100583
#else
auto var = vars.AsSpan()[index];
#endif
return var;
}

Expand Down Expand Up @@ -595,7 +622,7 @@ export class ClassInstance {
// P2


class IScriptClassBaseSimple {
export class IScriptClassBaseSimple {
uint64_t internalBuffer[8] {};
protected:

Expand All @@ -616,10 +643,17 @@ class IScriptClassBaseSimple {
virtual void DoSetup(RegisterFuncHandler) = 0;
};


//export template <template <unsigned> class classname>
#if !__cpp_nontype_template_parameter_class
export template <auto classname>
#else
export template <FixedString classname>
#endif
class ScriptClassBaseSimple : public IScriptClassBaseSimple {
public:
ScriptClassBaseSimple() : IScriptClassBaseSimple(std::string_view(classname)) {}
using RegisterFuncHandler = IScriptClassBaseSimple::RegisterFuncHandler;
};


Expand Down
Loading

0 comments on commit 29ea7d8

Please sign in to comment.