Skip to content

Commit

Permalink
Building and packaging Win32 and Win64 builds of UModel
Browse files Browse the repository at this point in the history
- SDL2.dll is no longer copied next to umodel.exe, it is picked up from libs during development, using delay-loading tech
- package_win32.sh script builds Win32 and Win64 targets and packages executables alongside with SDL2 dlls
- Separated SDL2 logic from common.project to SDL2.project
- Replaced appMilliseconds implementation from SDL_GetTicks to GetTickCount, so running in command line mode will no longer require SDL2.dll
  • Loading branch information
gildor2 committed Jul 5, 2021
1 parent 912d691 commit 8bebb68
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 39 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ umodel.cfg
# Executable files and pdb
umodel[-_]*.exe
umodel*.pdb
SDL2.dll
Tools/**/*.exe
Tools/**/*.pdb
*todo.md
Expand Down
24 changes: 10 additions & 14 deletions Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,21 +637,17 @@ extern bool GUseDebugger;
#endif


#if RENDERING
# define appMilliseconds() SDL_GetTicks()
#else
# ifdef _WIN32
# if !defined(WINAPI) // detect <windows.h>
extern "C" {
__declspec(dllimport) unsigned long __stdcall GetTickCount();
}
# endif
# else
// Local implementation of GetTickCount() for non-Windows platforms
unsigned long GetTickCount();
#ifdef _WIN32
# if !defined(WINAPI) // detect <windows.h>
extern "C" {
__declspec(dllimport) unsigned long __stdcall GetTickCount();
}
# endif
# define appMilliseconds() GetTickCount()
#endif // RENDERING
#else
// Local implementation of GetTickCount() for non-Windows platforms
unsigned long GetTickCount();
#endif
#define appMilliseconds() GetTickCount()

// Allow operation of enum class as with regular integer
#define BITFIELD_ENUM(Enum) \
Expand Down
7 changes: 1 addition & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,8 @@ GenerateMakefile
# Perform a build
# if $target is empty, whole project will be built, otherwise a single file
case "$PLATFORM" in
"vc-win32")
"vc-win32"|"vc-win64")
Make $makefile $target || exit 1
[ $render -eq 1 ] && cp $root/libs/SDL2/x86/SDL2.dll .
;;
"vc-win64")
Make $makefile $target || exit 1
[ $render -eq 1 ] && cp $root/libs/SDL2/x64/SDL2.dll .
;;
"mingw32"|"cygwin")
PATH=/bin:/usr/bin:$PATH # configure paths for Cygwin
Expand Down
14 changes: 3 additions & 11 deletions common.project
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ sources(COMP_LIBS) = {
pop(INCLUDES)
pop(DEFINES)

# SDL2
!include $R/libs/SDL2/SDL2.project

# oodle SDK support
!include $R/libs/oodle/oodle.project

Expand All @@ -192,9 +195,6 @@ sources(UE4_LIBS) = {
#------------------------------------------------

OBJDIR = $R/obj/$PRJ-$PLATFORM
!if "$PLATFORM" ne "osx"
STDLIBS += SDL2 # disabled in macOS build
!endif
INCLUDES += . $R/Core $R/Unreal $LIBINCLUDES
OPTIONS += $WARNINGS

Expand All @@ -212,11 +212,3 @@ OPTIONS += $WARNINGS
libs/tracy/TracyClient.cpp
}
!endif

!if "$PLATFORM" eq "win32"
INCLUDES += $R/libs/includewin32
LIBRARIES += $R/libs/SDL2/x86
!elif "$PLATFORM" eq "win64"
INCLUDES += $R/libs/includewin32
LIBRARIES += $R/libs/SDL2/x64
!endif
21 changes: 21 additions & 0 deletions libs/SDL2/SDL2.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# perl highlighting

!if "$PLATFORM" ne "osx"
STDLIBS += SDL2 # disabled in macOS build
!endif

!if "$PLATFORM" eq "win32"
INCLUDES += $R/libs/includewin32
LIBRARIES += $R/libs/SDL2/x86
!elif "$PLATFORM" eq "win64"
INCLUDES += $R/libs/includewin32
LIBRARIES += $R/libs/SDL2/x64
!endif

!if "$COMPILER" eq "VisualC"
# Delay loading of SDL2.dll
LINKFLAGS += -DELAYLOAD:SDL2.dll
STDLIBS += delayimp
# Delay loader helper function
sources(MAIN) = $R/libs/SDL2/SDL2Loader.cpp
!endif
47 changes: 47 additions & 0 deletions libs/SDL2/SDL2Loader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <windows.h>
#include <delayimp.h>

// Reference:
// https://docs.microsoft.com/en-us/cpp/build/reference/understanding-the-helper-function

// Core external functions
void appPrintf(const char*, ...);
void appError(const char*, ...);

static const char* DllPaths[] =
{
#ifndef _WIN64
"SDL2.dll",
"libs\\SDL2\\x86\\SDL2.dll"
#else
"SDL2_64.dll",
"libs\\SDL2\\x64\\SDL2.dll"
#endif
};

static FARPROC WINAPI delayHook(unsigned dliNotify, PDelayLoadInfo pdli)
{
if (dliNotify == dliNotePreLoadLibrary)
{
if (stricmp(pdli->szDll, "SDL2.dll") == 0)
{
// Find SDL2.dll in local folder, then in libs. Use a different file name for Win64 builds.
for (const char* DllName : DllPaths)
{
HANDLE hDll = LoadLibrary(DllName);
if (hDll)
return (FARPROC) hDll;
}
appError("SDL2.dll was not found, terminating...");
}
else
{
// Actually can simply return NULL, and let CRT to find a DLL itself
appError("Unknown DelayLoad: %s", pdli->szDll);
}
}

return NULL;
}

ExternC const PfnDliHook __pfnDliNotifyHook2 = delayHook;
27 changes: 20 additions & 7 deletions package_win32.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/bin/bash
archive="umodel_win32.zip"
filelist="umodel.exe readme.txt SDL2.dll"
filelist="umodel.exe umodel_64.exe readme.txt SDL2.dll SDL2_64.dll"

for i in $filelist; do
if [ ! -f $i ]; then
echo "ERROR: unable to find \"$i\""
exit 1
fi
done
# Build 32 and 64 bit executables
./build.sh || exit 1
./build.sh --64 || exit 1

if grep -q -E "(PRIVATE BUILD)" umodel.exe; then
echo "ERROR: this is a private build"
Expand All @@ -19,5 +16,21 @@ if grep -q -E "(DEBUG BUILD)" umodel.exe; then
exit
fi

# Copy SDL2.dll locally
cp libs/SDL2/x86/SDL2.dll .
cp libs/SDL2/x64/SDL2.dll ./SDL2_64.dll

# Verify for presence of all files
for i in $filelist; do
if [ ! -f $i ]; then
echo "ERROR: unable to find \"$i\""
exit 1
fi
done

# Create an archive
rm -f $archive
pkzipc -add $archive -level=9 $filelist

# Remove SDL2.dll files, these are required only for packaging
rm -f SDL2.dll SDL2_64.dll
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ Oodle

Changes
~~~~~~~
05.07.2021
- providing Win32 and Win64 builds of UE Viewer

30.05.2021
- Mass Effect Legendary Edition support

Expand Down
Binary file modified umodel.exe
Binary file not shown.

0 comments on commit 8bebb68

Please sign in to comment.