Skip to content
Closed
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
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function(file_dependent_read_list FILE LIST)
set(${LIST} "${TEMP_LIST}" PARENT_SCOPE)
endfunction()

project ("OpenSHC")
project ("OpenSHC" LANGUAGES C CXX ASM_MASM)

# Name of exe and dll should be the same
set(OPEN_SHC_NAME "OpenSHC")
Expand Down Expand Up @@ -158,9 +158,11 @@ target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/Mss32.dll" "
target_file_copy_if_different(OpenSHC.exe.runnable "${CRUSADER_DIR}/shfolder.dll" "$<TARGET_FILE_DIR:OpenSHC.exe>/shfolder.dll")


# Add the asm file containing the game symbols as reference
set(GAME_SYMBOLS_FILE ${CMAKE_SOURCE_DIR}/src/symbols/game.asm)

# Create the OpenSHC.dll target, should not require the game
add_library(OpenSHC.dll SHARED src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES})
add_library(OpenSHC.dll SHARED src/entry.cpp ${CORE_SOURCES} ${OPENSHC_SOURCES} ${GAME_SYMBOLS_FILE})
set_target_properties(OpenSHC.dll PROPERTIES OUTPUT_NAME ${OPEN_SHC_NAME})
set_target_properties(OpenSHC.dll PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/DLL")
target_compile_definitions(OpenSHC.dll PRIVATE OPEN_SHC_DLL REIMPLEMENTED_CRT=0)
Expand Down
14 changes: 13 additions & 1 deletion src/precomp/StructResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ struct StructResolver {
private:
template <typename T, int gameAddress> struct Instance;

template <typename T, int gameAddress> struct Extern {
static T instance;
};

template <typename T, bool implemented, int gameAddress> struct InternalResolver;
template <typename T, int gameAddress> struct InternalResolver<T, true, gameAddress> {
static T* const ptr;
Expand Down Expand Up @@ -39,7 +43,8 @@ struct StructResolver {
};

template <typename T, int gameAddress>
T* const StructResolver::InternalResolver<T, false, gameAddress>::ptr = reinterpret_cast<T*>(gameAddress);
T* const StructResolver::InternalResolver<T, false, gameAddress>::ptr
= &StructResolver::Extern<T, gameAddress>::instance;

template <typename T, int gameAddress>
T* const StructResolver::InternalResolver<T, true, gameAddress>::ptr
Expand All @@ -57,6 +62,13 @@ StructResolver::Resolver<T, implemented, gameAddress>::Initializer::Initializer(
initialize(AddressUsageKeeper<gameAddress>::initialized, isImplemented, gameAddress, Ptr::ptr, getTypeName<T>());
}

// TODO: rather then adding a template to hold the ref which would require a long mangled name,
// if we have a generatable name, we use a macro to define an extern C and use this instead.
// In this case, the asm file only needs to be touched if the general constract of the address changes
// and should we only ever use the addresses of the globals, this might be never.
// However, if filtered and generated names are required, maybe it could also be possible to create a generator for
// the more complicated mangled names? Any general type change would need to also adept the ASM file.

#define MACRO_STRUCT_RESOLVER(STRUCT_TYPE, IMPLEMENTED, GAME_ADDRESS) \
template struct StructResolver::Resolver<STRUCT_TYPE, IMPLEMENTED, GAME_ADDRESS>; \
typedef StructResolver::Resolver<STRUCT_TYPE, IMPLEMENTED, GAME_ADDRESS>::Ptr
Expand Down
10 changes: 10 additions & 0 deletions src/symbols/game.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.386
.model flat

PUBLIC ?instance@?$Extern@USoundEffectsHelperData1@Audio@OpenSHC@@$0NPDHPA@@StructResolver@@2USoundEffectsHelperData1@Audio@OpenSHC@@A

_TEXT SEGMENT
?instance@?$Extern@USoundEffectsHelperData1@Audio@OpenSHC@@$0NPDHPA@@StructResolver@@2USoundEffectsHelperData1@Audio@OpenSHC@@A EQU 00DF37F0h
_TEXT ENDS

END