Compare commits

..

7 Commits

Author SHA1 Message Date
Kenix3 674bc4cc3e Fixes crash handler. (#1446)
We need to include the PDB with the distributable.
2022-09-08 22:51:56 -04:00
Kenix3 3223331e76 Increment version 2022-09-08 19:08:22 -04:00
louist103 b85ac715eb Backport crash handler (#1401)
* backport crash handler

* backport crash handler

* Fix windows.
2022-09-08 19:05:09 -04:00
Baoulettes 100ab4cbf6 Rando: Fix Fast File Select seed loading (#1252)
* FixRandoLoading

* better methode
2022-08-21 22:19:02 -04:00
Kenix3 b0c10d710a Merge pull request #1239 from GreatArgorath/ToTFogFix2
FIX: Fog bug outside of Temple of Time
2022-08-17 17:54:43 -04:00
Ada 32c10ac885 Update libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp
Co-authored-by: David Chavez <david@dcvz.io>
2022-08-17 14:47:43 +01:00
Ada 4a2d9d8a4c Fixes ToT Fog 2022-08-17 13:20:15 +01:00
1253 changed files with 114961 additions and 67750 deletions
+1 -40
View File
@@ -9,7 +9,6 @@ __pycache__/
.idea/
cmake-build-debug
venv/
.cache/
# Project-specific ignores
build/
@@ -25,10 +24,6 @@ docs/doxygen/
*.map
*.dump
out.txt
*.sln
*.vcxproj
*.vcxproj.user
*.vcxproj.filters
# Tool artifacts
tools/mipspro7.2_compiler/
@@ -410,38 +405,4 @@ tags
oot.otr
*.sav
shipofharkinian.ini
shipofharkinian.json
imgui.ini
# Switch Stuff
*.nro
*.nacp
ZAPDTR/ZAPDUtils/lib/*
!/soh/icon.jpg
# Xcode
xcuserdata/
*.xcconfig
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
**/xcshareddata/WorkspaceSettings.xcsettings
# cmake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
*/extract_assets_cmake*
/build*
build.c
shipofharkinian.json
+43 -168
View File
@@ -2,84 +2,22 @@
## Windows
Requires:
* At least 8GB of RAM (machines with 4GB have seen complier failures)
* Visual Studio 2022 Community Edition with the C++ feature set
* One of the Windows SDKs that comes with Visual Studio, for example the current Windows 10 version 10.0.19041.0
* The `MSVC v142 - VS 2019 C++ build tools` component of Visual Studio
* Python 3 (can be installed manually or as part of Visual Studio)
* Git (can be installed manually or as part of Visual Studio)
* Cmake (can be installed via chocolatey or manually)
During installation, check the "Desktop development with C++" feature set:
![image](https://user-images.githubusercontent.com/30329717/183511274-d11aceea-7900-46ec-acb6-3f2cc110021a.png)
Doing so should also check one of the Windows SDKs by default. Then, in the installation details in the right-hand column, make sure you also check the v142 toolset.
You can also find the v142 toolset by searching through the individual components tab:
![image](https://user-images.githubusercontent.com/30329717/183521169-ead6a73b-a1bf-4e99-aab8-441746d8f08e.png)
While you're there, you can also install Python 3 and Git if needed.
1. Clone the Ship of Harkinian repository
2. Place one or more [compatible](#compatible-roms) roms in the `OTRExporter` directory with namings of your choice
_Note: Instructions assume using powershell_
```powershell
# Navigate to the Shipwright repo within powershell. ie: cd "C:\yourpath\Shipwright"
cd Shipwright
# Setup cmake project
& 'C:\Program Files\CMake\bin\cmake' -S . -B "build/x64" -G "Visual Studio 17 2022" -T v142 -A x64 # -DCMAKE_BUILD_TYPE:STRING=Release (if you're packaging)
# or for VS2019
& 'C:\Program Files\CMake\bin\cmake' -S . -B "build/x64" -G "Visual Studio 16 2019" -T v142 -A x64
# Extract assets & generate OTR (run this anytime you need to regenerate OTR)
& 'C:\Program Files\CMake\bin\cmake.exe' --build .\build\x64 --target ExtractAssets # --config Release (if you're packaging)
# Compile project
& 'C:\Program Files\CMake\bin\cmake.exe' --build .\build\x64 # --config Release (if you're packaging)
# Now you can run the executable in .\build\x64
# If you need to clean the project you can run
& 'C:\Program Files\CMake\bin\cmake.exe' --build .\build\x64 --target clean
```
### Developing SoH
With the cmake build system you have two options for working on the project:
#### Visual Studio
To develop using Visual Studio you only need to use cmake to generate the solution file:
```powershell
# Generates Ship.sln at `build/x64` for Visual Studio 2022
& 'C:\Program Files\CMake\bin\cmake' -S . -B "build/x64" -G "Visual Studio 17 2022" -T v142 -A x64
# or for Visual Studio 2019
& 'C:\Program Files\CMake\bin\cmake' -S . -B "build/x64" -G "Visual Studio 16 2019" -T v142 -A x64
```
#### Visual Studio Code or another editor
To develop using Visual Studio Code or another editor you only need to open the repository in it.
To build you'll need to follow the instructions from the building section.
_Note: If you're using Visual Studio Code, the [cpack plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) makes it very easy to just press run and debug._
_Experimental: You can also use another build system entirely rather than MSVC like [Ninja](https://ninja-build.org/) for possibly better performance._
### Generating the distributable
After compiling the project you can generate the distributable by running:
```powershell
# Go to build folder
cd "build/x64"
# Generate
& 'C:\Program Files\CMake\bin\cpack.exe' -G ZIP
```
1. Requires [Python](https://www.python.org/downloads/) >= 3.6.
2. Install [Visual Studio 2022 Community Edition](https://visualstudio.microsoft.com/vs/community/)
3. In the Visual Studio Installer, install `MSVC v142 - VS 2019 C++`.
4. Clone the Ship of Harkinian repository.
5. Place one or more [compatible](#compatible-roms) roms in the `OTRExporter` directory with namings of your choice.
6. Run `OTRExporter/OTRExporter.sln`.
7. Switch the solution to `Release x64`.
8. Build the solution.
9. Launching `OTRExporter/extract_assets.py` will generate an `oot.otr` archive file in `OTRExporter/oot.otr`.
10. Run `soh/soh.sln`
11. Switch the solution to `Release x86` or `Release x64`.
12. Build the solution.
13. Copy the `OTRExporter/oot.otr` archive file to `soh/Release`.
14. Launch `soh.exe`.
## Linux
Requires `gcc >= 10, x11, curl, python3, sdl2 >= 2.0.22, libpng, glew >= 2.2, ninja, cmake, lld`
**Important: For maximum performance make sure you have ninja build tools installed!**
_Note: If you're using Visual Studio Code, the [cpack plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) makes it very easy to just press run and debug._
```bash
# Clone the repo
@@ -87,112 +25,48 @@ git clone https://github.com/HarbourMasters/Shipwright.git
cd Shipwright
# Copy the baserom to the OTRExporter folder
cp <path to your ROM> OTRExporter
# Generate Ninja project
cmake -H. -Bbuild-cmake -GNinja # -DCMAKE_BUILD_TYPE:STRING=Release (if you're packaging)
# Extract assets & generate OTR (run this anytime you need to regenerate OTR)
cmake --build build-cmake --target ExtractAssets
# Compile the project
cmake --build build-cmake # --config Release (if you're packaging)
# Now you can run the executable in ./build-cmake/soh/soh.elf
# To develop the project open the repository in VSCode (or your preferred editor)
# If you need to clean the project you can run
cmake --build build-cmake --target clean
# Build the docker image
sudo docker build . -t soh
# Run the docker image with the working directory mounted to /soh
sudo docker run --rm -it -v $(pwd):/soh soh /bin/bash
```
### Generating a distributable
After compiling the project you can generate a distributable by running of the following:
Inside the Docker container:
```bash
# Go to build folder
cd build-cmake
# Generate
cpack -G DEB
cpack -G ZIP
cpack -G External (creates appimage)
# Clone and build StormLib
git clone https://github.com/ladislav-zezula/StormLib external/StormLib
cmake -B external/StormLib/build -S external/StormLib
cmake --build external/StormLib/build
cp external/StormLib/build/libstorm.a external
cp /usr/local/lib/libGLEW.a external
cd soh
# Extract the assets/Compile the exporter/Run the exporter
make setup -j$(nproc) OPTFLAGS=-O2 DEBUG=0
# Compile the code
make -j $(nproc) OPTFLAGS=-O2 DEBUG=0
```
## macOS
Requires Xcode (or xcode-tools) && `sdl2, libpng, glew, ninja, cmake` (can be installed via homebrew, macports, etc)
**Important: For maximum performance make sure you have ninja build tools installed!**
_Note: If you're using Visual Studio Code, the [cpack plugin](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) makes it very easy to just press run and debug._
1. Requires Xcode (or xcode-tools) && `sdl2, libpng, glew, dylibbundler` (can be installed via brew, etc)
```bash
# Clone the repo
git clone https://github.com/HarbourMasters/Shipwright.git
cd ShipWright
# Copy the baserom to the OTRExporter folder
cp <path to your ROM> OTRExporter
# Generate Ninja project
cmake -H. -Bbuild-cmake -GNinja # -DCMAKE_BUILD_TYPE:STRING=Release (if you're packaging)
# Extract assets & generate OTR (run this anytime you need to regenerate OTR)
cmake --build build-cmake --target ExtractAssets
# Compile the project
cmake --build build-cmake # --config Release (if you're packaging)
# Copy oot.otr into the Application Support directory
cp build-cmake/soh/oot.otr ~/Library/Application\ Support/com.shipofharkinian.soh/
# Now you can run the executable file:
./build-cmake/soh/soh-macos
# To develop the project open the repository in VSCode (or your preferred editor)
# If you need to clean the project you can run
cmake --build build-cmake --target clean
```
### Generating a distributable
After compiling the project you can generate a distributable by running of the following:
```bash
# Go to build folder
cd build-cmake
# Generate
cpack
```
## Switch
1. Requires that your build machine is setup with the tools necessary for your platform above
2. Requires that you have the switch build tools installed
3. Clone the Ship of Harkinian repository
4. Place one or more [compatible](#compatible-roms) roms in the `OTRExporter` directory with namings of your choice
```bash
cd Shipwright
# Setup cmake project for your host machine
cmake -H. -Bbuild-cmake -GNinja
# Extract assets & generate OTR (run this anytime you need to regenerate OTR)
cmake --build build-cmake --target ExtractAssets
# Setup cmake project for building for Switch
cmake -H. -Bbuild-switch -GNinja -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake
# Build project and generate nro
cmake --build build-switch --target soh_nro
# Now you can run the executable in ./build-switch/soh/soh.nro
# To develop the project open the repository in VSCode (or your preferred editor)
```
## Wii U
1. Requires that your build machine is setup with the tools necessary for your platform above
2. Requires that you have the Wii U build tools installed
3. Clone the Ship of Harkinian repository
4. Place one or more [compatible](#compatible-roms) roms in the `OTRExporter` directory with namings of your choice
```bash
cd Shipwright
# Setup cmake project for your host machine
cmake -H. -Bbuild-cmake -GNinja
# Extract assets & generate OTR (run this anytime you need to regenerate OTR)
cmake --build build-cmake --target ExtractAssets
# Setup cmake project for building for Wii U
cmake -H. -Bbuild-wiiu -GNinja -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/WiiU.cmake # -DCMAKE_BUILD_TYPE:STRING=Release (if you're packaging)
# Build project and generate rpx
cmake --build build-wiiu --target soh # --target soh_wuhb (for building .wuhb)
# Now you can run the executable in ./build-wiiu/soh/soh.rpx or the Wii U Homebrew Bundle in ./build-wiiu/soh/soh.wuhb
# To develop the project open the repository in VSCode (or your preferred editor)
cd soh
# Extract the assets/Compile the exporter/Run the exporter
# -jX defines number of cores to use for compilation - lower or remove entirely if having issues
make setup -j8 DEBUG=0
# Compile the code (watch the -j parameter as above)
make -j8 DEBUG=0
# Create macOS app bundle
make appbundle
```
9. Copy your OTR file to ~/Library/Application\ Support/com.shipofharkinian.soh
10. Launch soh app in the soh folder!
# Compatible Roms
```
@@ -211,3 +85,4 @@ Use the `extract_assets.py` script file to run the exporter using any of the fol
4) In a terminal run `python3 extract_assets.py <path_to_rom>`
If the script finds multiple roms the user is prompted which to use. Selection is done using the number keys and then pressing the carriage return key.
-65
View File
@@ -1,65 +0,0 @@
################################################################################
# Command for variable_watch. This command issues error message, if a variable
# is changed. If variable PROPERTY_READER_GUARD_DISABLED is TRUE nothing happens
# variable_watch(<variable> property_reader_guard)
################################################################################
function(property_reader_guard VARIABLE ACCESS VALUE CURRENT_LIST_FILE STACK)
if("${PROPERTY_READER_GUARD_DISABLED}")
return()
endif()
if("${ACCESS}" STREQUAL "MODIFIED_ACCESS")
message(FATAL_ERROR
" Variable ${VARIABLE} is not supposed to be changed.\n"
" It is used only for reading target property ${VARIABLE}.\n"
" Use\n"
" set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}\" \"<value>\")\n"
" or\n"
" set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}_<CONFIG>\" \"<value>\")\n"
" instead.\n")
endif()
endfunction()
################################################################################
# Create variable <name> with generator expression that expands to value of
# target property <name>_<CONFIG>. If property is empty or not set then property
# <name> is used instead. Variable <name> has watcher property_reader_guard that
# doesn't allow to edit it.
# create_property_reader(<name>)
# Input:
# name - Name of watched property and output variable
################################################################################
function(create_property_reader NAME)
set(PROPERTY_READER_GUARD_DISABLED TRUE)
set(CONFIG_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}_$<UPPER_CASE:$<CONFIG>>>>")
set(IS_CONFIG_VALUE_EMPTY "$<STREQUAL:${CONFIG_VALUE},>")
set(GENERAL_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}>>")
set("${NAME}" "$<IF:${IS_CONFIG_VALUE_EMPTY},${GENERAL_VALUE},${CONFIG_VALUE}>" PARENT_SCOPE)
variable_watch("${NAME}" property_reader_guard)
endfunction()
################################################################################
# Set property $<name>_${PROPS_CONFIG_U} of ${PROPS_TARGET} to <value>
# set_config_specific_property(<name> <value>)
# Input:
# name - Prefix of property name
# value - New value
################################################################################
function(set_config_specific_property NAME VALUE)
set_target_properties("${PROPS_TARGET}" PROPERTIES "${NAME}_${PROPS_CONFIG_U}" "${VALUE}")
endfunction()
################################################################################
create_property_reader("TARGET_NAME")
create_property_reader("OUTPUT_DIRECTORY")
set_config_specific_property("TARGET_NAME" "${PROPS_TARGET}")
set_config_specific_property("OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("ARCHIVE_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("LIBRARY_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("RUNTIME_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("ARCHIVE_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
set_config_specific_property("LIBRARY_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
set_config_specific_property("RUNTIME_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
-12
View File
@@ -1,12 +0,0 @@
include("${CMAKE_CURRENT_LIST_DIR}/Default.cmake")
set_config_specific_property("OUTPUT_DIRECTORY" "${CMAKE_SOURCE_DIR}$<$<NOT:$<STREQUAL:${CMAKE_VS_PLATFORM_NAME},Win32>>:/${CMAKE_VS_PLATFORM_NAME}>/${PROPS_CONFIG}")
if(MSVC)
create_property_reader("DEFAULT_CXX_EXCEPTION_HANDLING")
create_property_reader("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT")
set_target_properties("${PROPS_TARGET}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set_config_specific_property("DEFAULT_CXX_EXCEPTION_HANDLING" "/EHsc")
set_config_specific_property("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT" "/Zi")
endif()
-30
View File
@@ -1,30 +0,0 @@
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY 0)
set(CPACK_COMPONENTS_ALL "ship" "appimage")
if (NOT CPACK_GENERATOR STREQUAL "External")
list(REMOVE_ITEM CPACK_COMPONENTS_ALL "appimage")
endif()
if (CPACK_GENERATOR MATCHES "DEB|RPM")
# https://unix.stackexchange.com/a/11552/254512
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/ship/bin")#/${CMAKE_PROJECT_VERSION}")
set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY 0)
elseif (CPACK_GENERATOR MATCHES "ZIP")
set(CPACK_PACKAGING_INSTALL_PREFIX "")
endif()
if (CPACK_GENERATOR MATCHES "External")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
SET(CPACK_MONOLITHIC_INSTALL 1)
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/bin")
endif()
if (CPACK_GENERATOR MATCHES "Bundle")
set(CPACK_BUNDLE_NAME "soh")
set(CPACK_BUNDLE_PLIST "../soh/macosx/Info.plist")
set(CPACK_BUNDLE_ICON "macosx/soh.icns")
set(CPACK_BUNDLE_STARTUP_COMMAND "../soh/macosx/soh-macos.sh")
set(CPACK_BUNDLE_APPLE_CERT_APP "-")
endif()
-90
View File
@@ -1,90 +0,0 @@
# these are cache variables, so they could be overwritten with -D,
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}"
CACHE STRING "The resulting package name"
)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simple C++ application"
CACHE STRING "Package description for the package metadata"
)
set(CPACK_PACKAGE_VENDOR "Some Company")
set(CPACK_VERBATIM_VARIABLES YES)
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
SET(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_SOURCE_DIR}/_packages")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_CONTACT "YOUR@E-MAIL.net")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "YOUR NAME")
#set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CPACK_SYSTEM_NAME ${LSB_RELEASE_CODENAME_SHORT})
# package name for deb
# if set, then instead of some-application-0.9.2-Linux.deb
# you'll get some-application_0.9.2_amd64.deb (note the underscores too)
#set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
set( CPACK_DEBIAN_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}-${ARCHITECTURE}.deb )
# if you want every group to have its own package,
# although the same happens if this is not sent (so it defaults to ONE_PER_GROUP)
# and CPACK_DEB_COMPONENT_INSTALL is set to YES
set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)#ONE_PER_GROUP)
# without this you won't be able to pack only specified component
set(CPACK_DEB_COMPONENT_INSTALL YES)
set(CPACK_EXTERNAL_ENABLE_STAGING YES)
set(CPACK_EXTERNAL_PACKAGE_SCRIPT "${PROJECT_BINARY_DIR}/appimage-generate.cmake")
file(GENERATE
OUTPUT "${PROJECT_BINARY_DIR}/appimage-generate.cmake"
CONTENT [[
include(CMakePrintHelpers)
cmake_print_variables(CPACK_TEMPORARY_DIRECTORY)
cmake_print_variables(CPACK_TOPLEVEL_DIRECTORY)
cmake_print_variables(CPACK_PACKAGE_DIRECTORY)
cmake_print_variables(CPACK_PACKAGE_FILE_NAME)
find_program(LINUXDEPLOY_EXECUTABLE
NAMES linuxdeploy linuxdeploy-x86_64.AppImage
PATHS ${CPACK_PACKAGE_DIRECTORY}/linuxdeploy)
if (NOT LINUXDEPLOY_EXECUTABLE)
message(STATUS "Downloading linuxdeploy")
set(LINUXDEPLOY_EXECUTABLE ${CPACK_PACKAGE_DIRECTORY}/linuxdeploy/linuxdeploy)
file(DOWNLOAD
https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
${LINUXDEPLOY_EXECUTABLE}
INACTIVITY_TIMEOUT 10
LOG ${CPACK_PACKAGE_DIRECTORY}/linuxdeploy/download.log
STATUS LINUXDEPLOY_DOWNLOAD)
execute_process(COMMAND chmod +x ${LINUXDEPLOY_EXECUTABLE} COMMAND_ECHO STDOUT)
endif()
execute_process(
COMMAND
${CMAKE_COMMAND} -E env
OUTPUT=${CPACK_PACKAGE_FILE_NAME}.appimage
VERSION=$<IF:$<BOOL:${CPACK_PACKAGE_VERSION}>,${CPACK_PACKAGE_VERSION},0.1.0>
${LINUXDEPLOY_EXECUTABLE}
--appimage-extract-and-run
--appdir=${CPACK_TEMPORARY_DIRECTORY}
--executable=$<TARGET_FILE:soh>
$<$<BOOL:$<TARGET_PROPERTY:soh,APPIMAGE_DESKTOP_FILE>>:--desktop-file=$<TARGET_PROPERTY:soh,APPIMAGE_DESKTOP_FILE>>
$<$<BOOL:$<TARGET_PROPERTY:soh,APPIMAGE_ICON_FILE>>:--icon-file=$<TARGET_PROPERTY:soh,APPIMAGE_ICON_FILE>>
--output=appimage
# --verbosity=2
)
]])
endif()
include(CPack)
-248
View File
@@ -1,248 +0,0 @@
# utils file for projects came from visual studio solution with cmake-converter.
################################################################################
# Wrap each token of the command with condition
################################################################################
cmake_policy(PUSH)
cmake_policy(SET CMP0054 NEW)
macro(prepare_commands)
unset(TOKEN_ROLE)
unset(COMMANDS)
foreach(TOKEN ${ARG_COMMANDS})
if("${TOKEN}" STREQUAL "COMMAND")
set(TOKEN_ROLE "KEYWORD")
elseif("${TOKEN_ROLE}" STREQUAL "KEYWORD")
set(TOKEN_ROLE "CONDITION")
elseif("${TOKEN_ROLE}" STREQUAL "CONDITION")
set(TOKEN_ROLE "COMMAND")
elseif("${TOKEN_ROLE}" STREQUAL "COMMAND")
set(TOKEN_ROLE "ARG")
endif()
if("${TOKEN_ROLE}" STREQUAL "KEYWORD")
list(APPEND COMMANDS "${TOKEN}")
elseif("${TOKEN_ROLE}" STREQUAL "CONDITION")
set(CONDITION ${TOKEN})
elseif("${TOKEN_ROLE}" STREQUAL "COMMAND")
list(APPEND COMMANDS "$<$<NOT:${CONDITION}>:${DUMMY}>$<${CONDITION}:${TOKEN}>")
elseif("${TOKEN_ROLE}" STREQUAL "ARG")
list(APPEND COMMANDS "$<${CONDITION}:${TOKEN}>")
endif()
endforeach()
endmacro()
cmake_policy(POP)
################################################################################
# Transform all the tokens to absolute paths
################################################################################
macro(prepare_output)
unset(OUTPUT)
foreach(TOKEN ${ARG_OUTPUT})
if(IS_ABSOLUTE ${TOKEN})
list(APPEND OUTPUT "${TOKEN}")
else()
list(APPEND OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${TOKEN}")
endif()
endforeach()
endmacro()
################################################################################
# Parse add_custom_command_if args.
#
# Input:
# PRE_BUILD - Pre build event option
# PRE_LINK - Pre link event option
# POST_BUILD - Post build event option
# TARGET - Target
# OUTPUT - List of output files
# DEPENDS - List of files on which the command depends
# COMMANDS - List of commands(COMMAND condition1 commannd1 args1 COMMAND
# condition2 commannd2 args2 ...)
# Output:
# OUTPUT - Output files
# DEPENDS - Files on which the command depends
# COMMENT - Comment
# PRE_BUILD - TRUE/FALSE
# PRE_LINK - TRUE/FALSE
# POST_BUILD - TRUE/FALSE
# TARGET - Target name
# COMMANDS - Prepared commands(every token is wrapped in CONDITION)
# NAME - Unique name for custom target
# STEP - PRE_BUILD/PRE_LINK/POST_BUILD
################################################################################
function(add_custom_command_if_parse_arguments)
cmake_parse_arguments("ARG" "PRE_BUILD;PRE_LINK;POST_BUILD" "TARGET;COMMENT" "DEPENDS;OUTPUT;COMMANDS" ${ARGN})
if(WIN32)
set(DUMMY "cd.")
elseif(UNIX)
set(DUMMY "true")
endif()
prepare_commands()
prepare_output()
set(DEPENDS "${ARG_DEPENDS}")
set(COMMENT "${ARG_COMMENT}")
set(PRE_BUILD "${ARG_PRE_BUILD}")
set(PRE_LINK "${ARG_PRE_LINK}")
set(POST_BUILD "${ARG_POST_BUILD}")
set(TARGET "${ARG_TARGET}")
if(PRE_BUILD)
set(STEP "PRE_BUILD")
elseif(PRE_LINK)
set(STEP "PRE_LINK")
elseif(POST_BUILD)
set(STEP "POST_BUILD")
endif()
set(NAME "${TARGET}_${STEP}")
set(OUTPUT "${OUTPUT}" PARENT_SCOPE)
set(DEPENDS "${DEPENDS}" PARENT_SCOPE)
set(COMMENT "${COMMENT}" PARENT_SCOPE)
set(PRE_BUILD "${PRE_BUILD}" PARENT_SCOPE)
set(PRE_LINK "${PRE_LINK}" PARENT_SCOPE)
set(POST_BUILD "${POST_BUILD}" PARENT_SCOPE)
set(TARGET "${TARGET}" PARENT_SCOPE)
set(COMMANDS "${COMMANDS}" PARENT_SCOPE)
set(STEP "${STEP}" PARENT_SCOPE)
set(NAME "${NAME}" PARENT_SCOPE)
endfunction()
################################################################################
# Add conditional custom command
#
# Generating Files
# The first signature is for adding a custom command to produce an output:
# add_custom_command_if(
# <OUTPUT output1 [output2 ...]>
# <COMMANDS>
# <COMMAND condition command1 [args1...]>
# [COMMAND condition command2 [args2...]]
# [DEPENDS [depends...]]
# [COMMENT comment]
#
# Build Events
# add_custom_command_if(
# <TARGET target>
# <PRE_BUILD | PRE_LINK | POST_BUILD>
# <COMMAND condition command1 [args1...]>
# [COMMAND condition command2 [args2...]]
# [COMMENT comment]
#
# Input:
# output - Output files the command is expected to produce
# condition - Generator expression for wrapping the command
# command - Command-line(s) to execute at build time.
# args - Command`s args
# depends - Files on which the command depends
# comment - Display the given message before the commands are executed at
# build time.
# PRE_BUILD - Run before any other rules are executed within the target
# PRE_LINK - Run after sources have been compiled but before linking the
# binary
# POST_BUILD - Run after all other rules within the target have been
# executed
################################################################################
function(add_custom_command_if)
add_custom_command_if_parse_arguments(${ARGN})
if(OUTPUT AND TARGET)
message(FATAL_ERROR "Wrong syntax. A TARGET and OUTPUT can not both be specified.")
endif()
if(OUTPUT)
add_custom_command(OUTPUT ${OUTPUT}
${COMMANDS}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
elseif(TARGET)
if(PRE_BUILD AND NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio")
add_custom_target(
${NAME}
${COMMANDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
add_dependencies(${TARGET} ${NAME})
else()
add_custom_command(
TARGET ${TARGET}
${STEP}
${COMMANDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
endif()
else()
message(FATAL_ERROR "Wrong syntax. A TARGET or OUTPUT must be specified.")
endif()
endfunction()
################################################################################
# Use props file for a target and configs
# use_props(<target> <configs...> <props_file>)
# Inside <props_file> there are following variables:
# PROPS_TARGET - <target>
# PROPS_CONFIG - One of <configs...>
# PROPS_CONFIG_U - Uppercase PROPS_CONFIG
# Input:
# target - Target to apply props file
# configs - Build configurations to apply props file
# props_file - CMake script
################################################################################
macro(use_props TARGET CONFIGS PROPS_FILE)
set(PROPS_TARGET "${TARGET}")
foreach(PROPS_CONFIG ${CONFIGS})
string(TOUPPER "${PROPS_CONFIG}" PROPS_CONFIG_U)
get_filename_component(ABSOLUTE_PROPS_FILE "${PROPS_FILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
if(EXISTS "${ABSOLUTE_PROPS_FILE}")
include("${ABSOLUTE_PROPS_FILE}")
else()
message(WARNING "Corresponding cmake file from props \"${ABSOLUTE_PROPS_FILE}\" doesn't exist")
endif()
endforeach()
endmacro()
################################################################################
# Add compile options to source file
# source_file_compile_options(<source_file> [compile_options...])
# Input:
# source_file - Source file
# compile_options - Options to add to COMPILE_FLAGS property
################################################################################
function(source_file_compile_options SOURCE_FILE)
if("${ARGC}" LESS_EQUAL "1")
return()
endif()
get_source_file_property(COMPILE_OPTIONS "${SOURCE_FILE}" COMPILE_OPTIONS)
if(COMPILE_OPTIONS)
list(APPEND COMPILE_OPTIONS ${ARGN})
else()
set(COMPILE_OPTIONS "${ARGN}")
endif()
set_source_files_properties("${SOURCE_FILE}" PROPERTIES COMPILE_OPTIONS "${COMPILE_OPTIONS}")
endfunction()
################################################################################
# Default properties of visual studio projects
################################################################################
set(DEFAULT_CXX_PROPS "${CMAKE_CURRENT_LIST_DIR}/DefaultCXX.cmake")
function(get_linux_lsb_release_information)
find_program(LSB_RELEASE_EXEC lsb_release)
if(NOT LSB_RELEASE_EXEC)
message(FATAL_ERROR "Could not detect lsb_release executable, can not gather required information")
endif()
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --id OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --release OUTPUT_VARIABLE LSB_RELEASE_VERSION_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --codename OUTPUT_VARIABLE LSB_RELEASE_CODENAME_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)
set(LSB_RELEASE_ID_SHORT "${LSB_RELEASE_ID_SHORT}" PARENT_SCOPE)
set(LSB_RELEASE_VERSION_SHORT "${LSB_RELEASE_VERSION_SHORT}" PARENT_SCOPE)
set(LSB_RELEASE_CODENAME_SHORT "${LSB_RELEASE_CODENAME_SHORT}" PARENT_SCOPE)
endfunction()
-191
View File
@@ -1,191 +0,0 @@
#------------------------------------------------------------------------------------------------------------
#
# Automate-VCPKG by Andre Taulien
# ===============================
#
# Project Repository: https://github.com/REGoth-project/Automate-VCPKG
# License ..........: MIT, see end of file.
#
# Based on: https://github.com/sutambe/cpptruths/blob/vcpkg_cmake_blog/cpp0x/vcpkg_test/CMakeLists.txt
#
#
# While [Vcpkg](https://github.com/microsoft/vcpkg) on it's own is awesome, it does add
# a little bit of complexity to getting a project to build. Even more if the one trying
# to compile your application is not too fond of the commandline. Additionally, CMake
# commands tend to get rather long with the toolchain path.
#
# To keep things simple for new users who just want to get the project to build, this
# script offers a solution.
#
# Lets assume your main `CMakelists.txt` looks something like this:
#
# cmake_minimum_required (VERSION 3.12.0)
# project (MyProject)
#
# add_executable(MyExecutable main.c)
#
# To integrate Vcpkg into that `CMakelists.txt`, simple put the following lines before the
# call to `project(MyProject)`:
#
# include(cmake/automate-vcpkg.cmake)
#
# vcpkg_bootstrap()
# vcpkg_install_packages(libsquish physfs)
#
# The call to `vcpkg_bootstrap()` will clone the official Vcpkg repository and bootstrap it.
# If it detected an existing environment variable defining a valid `VCPKG_ROOT`, it will
# update the existing installation of Vcpkg.
#
# Arguments to `vcpkg_install_packages()` are the packages you want to install using Vcpkg.
#
# If you want to keep the possibility for users to chose their own copy of Vcpkg, you can
# simply not run the code snippet mentioned above, something like this will work:
#
# option(SKIP_AUTOMATE_VCPKG "When ON, you will need to built the packages
# required by MyProject on your own or supply your own vcpkg toolchain.")
#
# if (NOT SKIP_AUTOMATE_VCPKG)
# include(cmake/automate-vcpkg.cmake)
#
# vcpkg_bootstrap()
# vcpkg_install_packages(libsquish physfs)
# endif()
#
# Then, the user has to supply the packages on their own, be it through Vcpkg or manually
# specifying their locations.
#------------------------------------------------------------------------------------------------------------
cmake_minimum_required (VERSION 3.12)
if(WIN32)
set(VCPKG_FALLBACK_ROOT ${CMAKE_CURRENT_BINARY_DIR}/vcpkg CACHE STRING "vcpkg configuration directory to use if vcpkg was not installed on the system before")
else()
set(VCPKG_FALLBACK_ROOT ${CMAKE_CURRENT_BINARY_DIR}/.vcpkg CACHE STRING "vcpkg configuration directory to use if vcpkg was not installed on the system before")
endif()
# On Windows, Vcpkg defaults to x86, even on x64 systems. If we're
# doing a 64-bit build, we need to fix that.
if (WIN32)
# Since the compiler checks haven't run yet, we need to figure
# out the value of CMAKE_SIZEOF_VOID_P ourselfs
include(CheckTypeSize)
enable_language(C)
check_type_size("void*" SIZEOF_VOID_P BUILTIN_TYPES_ONLY)
if (SIZEOF_VOID_P EQUAL 8)
message(STATUS "Using Vcpkg triplet 'x64-windows'")
set(VCPKG_TRIPLET x64-windows)
endif()
endif()
if(NOT DEFINED VCPKG_ROOT)
if(NOT DEFINED ENV{VCPKG_ROOT})
set(VCPKG_ROOT ${VCPKG_FALLBACK_ROOT})
else()
set(VCPKG_ROOT $ENV{VCPKG_ROOT})
endif()
endif()
# Installs a new copy of Vcpkg or updates an existing one
macro(vcpkg_bootstrap)
_install_or_update_vcpkg()
# Find out whether the user supplied their own VCPKG toolchain file
if(NOT DEFINED ${CMAKE_TOOLCHAIN_FILE})
# We know this wasn't set before so we need point the toolchain file to the newly found VCPKG_ROOT
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake CACHE STRING "")
# Just setting vcpkg.cmake as toolchain file does not seem to actually pull in the code
include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
set(AUTOMATE_VCPKG_USE_SYSTEM_VCPKG OFF)
else()
# VCPKG_ROOT has been defined by the toolchain file already
set(AUTOMATE_VCPKG_USE_SYSTEM_VCPKG ON)
endif()
message(STATUS "Automate VCPKG status:")
message(STATUS " VCPKG_ROOT.....: ${VCPKG_ROOT}")
message(STATUS " VCPKG_EXEC.....: ${VCPKG_EXEC}")
message(STATUS " VCPKG_BOOTSTRAP: ${VCPKG_BOOTSTRAP}")
endmacro()
macro(_install_or_update_vcpkg)
if(NOT EXISTS ${VCPKG_ROOT})
message(STATUS "Cloning vcpkg in ${VCPKG_ROOT}")
execute_process(COMMAND git clone https://github.com/Microsoft/vcpkg.git ${VCPKG_ROOT})
# If a reproducible build is desired (and potentially old libraries are # ok), uncomment the
# following line and pin the vcpkg repository to a specific githash.
# execute_process(COMMAND git checkout 745a0aea597771a580d0b0f4886ea1e3a94dbca6 WORKING_DIRECTORY ${VCPKG_ROOT})
else()
# The following command has no effect if the vcpkg repository is in a detached head state.
message(STATUS "Auto-updating vcpkg in ${VCPKG_ROOT}")
execute_process(COMMAND git pull WORKING_DIRECTORY ${VCPKG_ROOT})
endif()
if(NOT EXISTS ${VCPKG_ROOT}/README.md)
message(FATAL_ERROR "***** FATAL ERROR: Could not clone vcpkg *****")
endif()
if(WIN32)
set(VCPKG_EXEC ${VCPKG_ROOT}/vcpkg.exe)
set(VCPKG_BOOTSTRAP ${VCPKG_ROOT}/bootstrap-vcpkg.bat)
else()
set(VCPKG_EXEC ${VCPKG_ROOT}/vcpkg)
set(VCPKG_BOOTSTRAP ${VCPKG_ROOT}/bootstrap-vcpkg.sh)
endif()
if(NOT EXISTS ${VCPKG_EXEC})
message("Bootstrapping vcpkg in ${VCPKG_ROOT}")
execute_process(COMMAND ${VCPKG_BOOTSTRAP} WORKING_DIRECTORY ${VCPKG_ROOT})
endif()
if(NOT EXISTS ${VCPKG_EXEC})
message(FATAL_ERROR "***** FATAL ERROR: Could not bootstrap vcpkg *****")
endif()
endmacro()
# Installs the list of packages given as parameters using Vcpkg
macro(vcpkg_install_packages)
# Need the given list to be space-separated
#string (REPLACE ";" " " PACKAGES_LIST_STR "${ARGN}")
message(STATUS "Installing/Updating the following vcpkg-packages: ${PACKAGES_LIST_STR}")
if (VCPKG_TRIPLET)
set(ENV{VCPKG_DEFAULT_TRIPLET} "${VCPKG_TRIPLET}")
endif()
execute_process(
COMMAND ${VCPKG_EXEC} install ${ARGN}
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endmacro()
# MIT License
#
# Copyright (c) 2019 REGoth-project
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-216
View File
@@ -1,216 +0,0 @@
cmake_minimum_required(VERSION 3.16.0 FATAL_ERROR)
set(CMAKE_SYSTEM_VERSION 10.0 CACHE STRING "" FORCE)
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
#set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard to use") - issue with soh compile with MSVC
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version" FORCE)
project(Ship C CXX)
set(PROJECT_VERSION_MAJOR "4")
set(PROJECT_VERSION_MINOR "0")
set(PROJECT_VERSION_PATCH "0")
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT soh)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
include(CMake/automate-vcpkg.cmake)
set(VCPKG_TRIPLET x64-windows-static)
set(VCPKG_TARGET_TRIPLET x64-windows-static)
vcpkg_bootstrap()
vcpkg_install_packages(zlib bzip2 libpng SDL2 SDL2-net GLEW glfw3)
endif()
################################################################################
# Set target arch type if empty. Visual studio solution generator provides it.
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(NOT CMAKE_VS_PLATFORM_NAME)
set(CMAKE_VS_PLATFORM_NAME "x64")
endif()
message("${CMAKE_VS_PLATFORM_NAME} architecture in use")
if(NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64"
OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32"))
message(FATAL_ERROR "${CMAKE_VS_PLATFORM_NAME} arch is not supported!")
endif()
endif()
################################################################################
# Global configuration types
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
set(CMAKE_C_FLAGS_DEBUG "-O3 -ffast-math")
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -ffast-math")
set(CMAKE_C_FLAGS_RELEASE "-O3 -ffast-math -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math -DNDEBUG")
else()
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_OBJCXX_FLAGS_RELEASE "-O2 -DNDEBUG")
endif()
if(NOT CMAKE_BUILD_TYPE )
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
endif()
################################################################################
# Global compiler options
################################################################################
if(MSVC)
# remove default flags provided with CMake for MSVC
set(CMAKE_C_FLAGS "")
set(CMAKE_C_FLAGS_DEBUG "")
set(CMAKE_C_FLAGS_RELEASE "")
set(CMAKE_CXX_FLAGS "")
set(CMAKE_CXX_FLAGS_DEBUG "")
set(CMAKE_CXX_FLAGS_RELEASE "")
endif()
################################################################################
# Global linker options
################################################################################
if(MSVC)
# remove default flags provided with CMake for MSVC
set(CMAKE_EXE_LINKER_FLAGS "")
set(CMAKE_MODULE_LINKER_FLAGS "")
set(CMAKE_SHARED_LINKER_FLAGS "")
set(CMAKE_STATIC_LINKER_FLAGS "")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS}")
endif()
################################################################################
# Common utils
################################################################################
include(CMake/Utils.cmake)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
get_linux_lsb_release_information()
message(STATUS "Linux ${LSB_RELEASE_ID_SHORT} ${LSB_RELEASE_VERSION_SHORT} ${LSB_RELEASE_CODENAME_SHORT}")
else()
message(STATUS ${CMAKE_SYSTEM_NAME})
endif()
################################################################################
# Additional Global Settings(add specific info there)
################################################################################
include(CMake/GlobalSettingsInclude.cmake OPTIONAL)
################################################################################
# Use solution folders feature
################################################################################
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
################################################################################
# Sub-projects
################################################################################
add_subdirectory(libultraship/libultraship ${CMAKE_BINARY_DIR}/libultraship)
add_subdirectory(ZAPDTR/ZAPD ${CMAKE_BINARY_DIR}/ZAPD)
add_subdirectory(ZAPDTR/ZAPDUtils ${CMAKE_BINARY_DIR}/ZAPDUtils)
add_subdirectory(OTRExporter)
add_subdirectory(soh)
if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|NintendoSwitch|CafeOS")
add_subdirectory(OTRGui)
endif()
set_property(TARGET soh PROPERTY APPIMAGE_DESKTOP_FILE_TERMINAL YES)
set_property(TARGET soh PROPERTY APPIMAGE_DESKTOP_FILE "${CMAKE_SOURCE_DIR}/scripts/linux/appimage/soh.desktop")
set_property(TARGET soh PROPERTY APPIMAGE_ICON_FILE "${CMAKE_BINARY_DIR}/sohIcon.png")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
install(PROGRAMS "${CMAKE_SOURCE_DIR}/scripts/linux/appimage/soh.sh" DESTINATION . COMPONENT appimage)
endif()
find_package(Python3 COMPONENTS Interpreter)
add_custom_target(
ExtractAssets
# CMake versions prior to 3.17 do not have the rm command, use remove instead for older versions
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:${CMAKE_VERSION},3.17>,remove,rm> -f oot.otr
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$<TARGET_FILE:ZAPD>"
COMMAND ${CMAKE_COMMAND} -E copy oot.otr ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E copy oot.otr ${CMAKE_BINARY_DIR}/soh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter
COMMENT "Running asset extraction..."
DEPENDS ZAPD
BYPRODUCTS oot.otr ${CMAKE_SOURCE_DIR}/oot.otr
)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
find_package(ImageMagick COMPONENTS convert)
if (ImageMagick_FOUND)
execute_process (
COMMAND ${ImageMagick_convert_EXECUTABLE} soh/macosx/sohIcon.png -resize 512x512 ${CMAKE_BINARY_DIR}/sohIcon.png
OUTPUT_VARIABLE outVar
)
endif()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_custom_target(CreateOSXIcons
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/macosx/soh.iconset
COMMAND sips -z 16 16 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_16x16.png
COMMAND sips -z 32 32 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_16x16@2x.png
COMMAND sips -z 32 32 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_32x32.png
COMMAND sips -z 64 64 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_32x32@2x.png
COMMAND sips -z 128 128 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_128x128.png
COMMAND sips -z 256 256 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_128x128@2x.png
COMMAND sips -z 256 256 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_256x256.png
COMMAND sips -z 512 512 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_256x256@2x.png
COMMAND sips -z 512 512 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_512x512.png
COMMAND cp soh/macosx/sohIcon.png ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_512x512@2x.png
COMMAND iconutil -c icns -o ${CMAKE_BINARY_DIR}/macosx/soh.icns ${CMAKE_BINARY_DIR}/macosx/soh.iconset
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Creating OSX icons ..."
)
add_dependencies(soh CreateOSXIcons)
add_custom_target(Assets ALL
COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_SOURCE_DIR}/OTRGui/assets/extractor" -Ddst_dir="${CMAKE_BINARY_DIR}/assets/extractor" -P "${CMAKE_SOURCE_DIR}/OTRGui/Overwrite.cmake"
COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_SOURCE_DIR}/OTRExporter/assets" -Ddst_dir="${CMAKE_BINARY_DIR}/assets/game" -P "${CMAKE_SOURCE_DIR}/OTRGui/Overwrite.cmake"
COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_SOURCE_DIR}/soh/assets/xml" -Ddst_dir="${CMAKE_BINARY_DIR}/assets/extractor/xmls" -P "${CMAKE_SOURCE_DIR}/OTRGui/Overwrite.cmake"
)
add_dependencies(soh Assets)
install(TARGETS ZAPD DESTINATION ${CMAKE_BINARY_DIR}/assets/extractor)
set(PROGRAM_PERMISSIONS_EXECUTE OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
install(DIRECTORY ${CMAKE_BINARY_DIR}/assets
DESTINATION .
PATTERN ZAPD.out
PERMISSIONS ${PROGRAM_PERMISSIONS_EXECUTE}
)
install(CODE "
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/soh-macos\" \"\" \"${dirs}\")
")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Windows|NintendoSwitch|CafeOS")
install(FILES ${CMAKE_SOURCE_DIR}/README.md DESTINATION . COMPONENT ship RENAME readme.txt )
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CPACK_GENERATOR "External")
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows|NintendoSwitch|CafeOS")
set(CPACK_GENERATOR "ZIP")
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CPACK_GENERATOR "Bundle")
endif()
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/CMake/Packaging-2.cmake)
include(CMake/Packaging.cmake)
+15 -36
View File
@@ -3,18 +3,17 @@ FROM ubuntu:20.04 as build
ENV LANG C.UTF-8
ARG DEBIAN_FRONTEND=noninteractive
ENV GCCVER=10
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
binutils \
gcc-${GCCVER} \
g++-${GCCVER} \
gcc-10 \
g++-10 \
patchelf \
p7zip-full \
python3 \
cmake \
python3.9 \
make \
cmake \
curl \
git \
lld \
@@ -22,47 +21,27 @@ RUN apt-get update && \
zlib1g-dev \
libbz2-dev \
libpng-dev \
libgles2-mesa-dev \
wget \
gpg \
imagemagick \
ninja-build && \
apt-get install -y software-properties-common && \
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
apt-add-repository "deb https://apt.kitware.com/ubuntu/ focal main" && \
apt-get update && \
apt-get upgrade -y && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCCVER} 10 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${GCCVER} 10
libgles2-mesa-dev && \
ln -s /usr/bin/g++-10 /usr/bin/g++ && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 && \
gcc --version && \
g++ --version
RUN apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/apt /var/lib/cache /var/lib/log
RUN git clone https://github.com/Perlmint/glew-cmake.git && \
cmake glew-cmake && \
make -j$(nproc) && \
make install
ENV SDL2VER=2.0.22
RUN curl -sLO https://libsdl.org/release/SDL2-${SDL2VER}.tar.gz && \
tar -xzf SDL2-${SDL2VER}.tar.gz && \
cd SDL2-${SDL2VER} && \
./configure --build=x86_64-linux-gnu && \
make -j$(nproc) && make install && \
./configure --prefix=/usr && \
make && make install && \
rm ../SDL2-${SDL2VER}.tar.gz && \
cp -av /usr/local/lib/libSDL* /lib/x86_64-linux-gnu/
RUN \
ln -sf /proc/self/mounts /etc/mtab && \
mkdir -p /usr/local/share/keyring/ && \
wget -O /usr/local/share/keyring/devkitpro-pub.gpg https://apt.devkitpro.org/devkitpro-pub.gpg && \
echo "deb [signed-by=/usr/local/share/keyring/devkitpro-pub.gpg] https://apt.devkitpro.org stable main" > /etc/apt/sources.list.d/devkitpro.list && \
apt-get update -y && \
apt-get install -y devkitpro-pacman && \
yes | dkp-pacman -Syu switch-dev switch-portlibs wiiu-dev wiiu-portlibs --noconfirm
ENV DEVKITPRO=/opt/devkitpro
ENV DEVKITARM=/opt/devkitpro/devkitARM
ENV DEVKITPPC=/opt/devkitpro/devkitPPC
ENV PATH=$PATH:/opt/devkitpro/portlibs/switch/bin/:$DEVKITPPC/bin
ENV WUT_ROOT=$DEVKITPRO/wut
cp -av /lib/libSDL* /lib/x86_64-linux-gnu/
RUN mkdir /soh
WORKDIR /soh
Vendored
+69 -132
View File
@@ -8,41 +8,20 @@ pipeline {
}
stages {
stage('Generate Assets') {
agent {
label "SoH-Asset-Builders"
}
steps {
timeout(time: 10) {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions,
userRemoteConfigs: scm.userRemoteConfigs
])
sh '''
cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
cmake --build build-cmake --target ExtractAssets --config Release
'''
stash includes: 'soh/assets/**/*', name: 'assets'
}
}
post {
unsuccessful {
step([$class: 'WsCleanup']) // Clean workspace
}
}
}
stage('Build SoH') {
parallel {
stage ('Build Windows') {
options {
timeout(time: 20)
}
environment {
MSBUILD='C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Msbuild\\Current\\Bin\\msbuild.exe'
CONFIG='Release'
OTRPLATFORM='x64'
PLATFORM='x64'
ZIP='C:\\Program Files\\7-Zip\\7z.exe'
PYTHON='C:\\Users\\jenkins\\AppData\\Local\\Programs\\Python\\Python310\\python.exe'
CMAKE='C:\\Program Files\\CMake\\bin\\cmake.exe'
CPACK='C:\\Program Files\\CMake\\bin\\cpack.exe'
TOOLSET='v142'
}
agent {
@@ -58,19 +37,41 @@ pipeline {
])
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
unstash 'assets'
bat """
"${env.CMAKE}" -S . -B "build\\${env.PLATFORM}" -G "Visual Studio 17 2022" -T ${env.TOOLSET} -A ${env.PLATFORM} -D Python_EXECUTABLE=${env.PYTHON} -D CMAKE_BUILD_TYPE:STRING=Release
"${env.CMAKE}" --build ".\\build\\${env.PLATFORM}" --target OTRGui --config Release
"${env.CMAKE}" --build ".\\build\\${env.PLATFORM}" --config Release
cd ".\\build\\${env.PLATFORM}"
"${env.CPACK}" -G ZIP
bat """
"${env.MSBUILD}" ".\\OTRExporter\\OTRExporter.sln" -t:build -p:Configuration=${env.CONFIG};Platform=${env.OTRPLATFORM};PlatformToolset=${env.TOOLSET};RestorePackagesConfig=true /restore /nodeReuse:false /m
xcopy "..\\..\\ZELOOTD.z64" "OTRExporter\\"
cd "OTRExporter"
"${env.PYTHON}" ".\\extract_assets.py"
cd "..\\"
"${env.MSBUILD}" ".\\soh\\soh.sln" -t:build -p:Configuration=${env.CONFIG};Platform=${env.PLATFORM};PlatformToolset=${env.TOOLSET} /nodeReuse:false /m
cd OTRGui
mkdir build
cd build
"${env.CMAKE}" ..
"${env.CMAKE}" --build . --config Release
cd "..\\..\\"
move "_packages\\*.zip" "soh.zip"
mkdir debug
move "soh\\x64\\Release\\soh.exe" ".\\"
move "soh\\x64\\Release\\soh.pdb" ".\\debug\\"
move "OTRGui\\build\\assets" ".\\"
move ".\\OTRExporter\\x64\\Release\\ZAPD.exe" ".\\assets\\extractor\\"
move ".\\OTRGui\\build\\Release\\OTRGui.exe" ".\\"
rename README.md readme.txt
"${env.ZIP}" a soh.7z soh.exe OTRGui.exe assets debug readme.txt
"""
archiveArtifacts artifacts: 'soh.7z', followSymlinks: false, onlyIfSuccessful: true
}
archiveArtifacts artifacts: 'soh.zip', followSymlinks: false, onlyIfSuccessful: true
}
post {
always {
@@ -79,6 +80,9 @@ pipeline {
}
}
stage ('Build Linux') {
options {
timeout(time: 20)
}
agent {
label "SoH-Linux-Builders"
}
@@ -91,26 +95,32 @@ pipeline {
userRemoteConfigs: scm.userRemoteConfigs
])
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
unstash 'assets'
sh '''
if docker ps -aq --filter "name=sohcont" | grep -q .; then docker rm -f sohcont; fi
cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64
docker build . -t soh
docker run --name sohcont -dit --rm -v $(pwd):/soh soh /bin/bash
docker exec sohcont scripts/linux/appimage/build.sh
cp ../../buildsoh.bash soh
docker exec sohcont soh/buildsoh.bash
mkdir build
mv soh/soh.elf build/
mv OTRGui/build/OTRGui build/
mv OTRGui/build/assets build/
mv ZAPDTR/ZAPD.out build/assets/extractor/
mv README.md readme.txt
mv build-cmake/*.appimage soh.appimage
7z a soh-linux.7z soh.appimage readme.txt
docker exec sohcont appimage/appimage.sh
7z a soh-linux.7z SOH-Linux.AppImage readme.txt
'''
}
sh 'sudo docker container stop sohcont'
archiveArtifacts artifacts: 'soh-linux.7z', followSymlinks: false, onlyIfSuccessful: true
}
post {
always {
sh 'sudo docker container stop sohcont'
sh 'docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi' // Clean dangling docker images
step([$class: 'WsCleanup']) // Clean workspace
}
}
@@ -119,6 +129,11 @@ pipeline {
agent {
label "SoH-Mac-Builders"
}
environment {
CC = 'clang -arch arm64 -arch x86_64'
CXX = 'clang++ -arch arm64 -arch x86_64'
MACOSX_DEPLOYMENT_TARGET = 10.15
}
steps {
checkout([
$class: 'GitSCM',
@@ -128,19 +143,17 @@ pipeline {
userRemoteConfigs: scm.userRemoteConfigs
])
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
unstash 'assets'
sh '''
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
cmake --build build-cmake --config Release --
(cd build-cmake && cpack)
mv README.md readme.txt
mv _packages/*.dmg SoH.dmg
7z a soh-mac.7z SoH.dmg readme.txt
cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64
cd soh
make setup -j4 OPTFLAGS=-O2 DEBUG=0 LD="ld"
make -j4 DEBUG=0 OPTFLAGS=-O2 LD="ld"
make -j4 appbundle
mv ../README.md readme.txt
7z a soh-mac.7z soh.app readme.txt
'''
}
archiveArtifacts artifacts: 'soh-mac.7z', followSymlinks: false, onlyIfSuccessful: true
archiveArtifacts artifacts: 'soh/soh-mac.7z', followSymlinks: false, onlyIfSuccessful: true
}
post {
always {
@@ -148,83 +161,7 @@ pipeline {
}
}
}
stage ('Build Switch') {
agent {
label "SoH-Linux-Builders"
}
steps {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions,
userRemoteConfigs: scm.userRemoteConfigs
])
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
unstash 'assets'
sh '''
if docker ps -aq --filter "name=sohswitchcont" | grep -q .; then docker rm -f sohswitchcont; fi
docker build . -t sohswitch
docker run --name sohswitchcont -dit --rm -v $(pwd):/soh sohswitch /bin/bash
docker exec sohswitchcont scripts/switch/build.sh
mv build-switch/soh/*.nro soh.nro
mv README.md readme.txt
7z a soh-switch.7z soh.nro readme.txt
'''
}
archiveArtifacts artifacts: 'soh-switch.7z', followSymlinks: false, onlyIfSuccessful: true
}
post {
always {
sh 'sudo docker container stop sohswitchcont'
sh 'docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi' // Clean dangling docker images
step([$class: 'WsCleanup']) // Clean workspace
}
}
}
stage ('Build Wii U') {
agent {
label "SoH-Linux-Builders"
}
steps {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions,
userRemoteConfigs: scm.userRemoteConfigs
])
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
unstash 'assets'
sh '''
if docker ps -aq --filter "name=sohwiiucont" | grep -q .; then docker rm -f sohwiiucont; fi
docker build . -t sohwiiu
docker run --name sohwiiucont -dit --rm -v $(pwd):/soh sohwiiu /bin/bash
docker exec sohwiiucont scripts/wiiu/build.sh
mv build-wiiu/soh/*.rpx soh.rpx
mv build-wiiu/soh/*.wuhb soh.wuhb
mv README.md readme.txt
7z a soh-wiiu.7z soh.rpx soh.wuhb readme.txt
'''
}
archiveArtifacts artifacts: 'soh-wiiu.7z', followSymlinks: false, onlyIfSuccessful: true
}
post {
always {
sh 'sudo docker container stop sohwiiucont'
sh 'docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi' // Clean dangling docker images
step([$class: 'WsCleanup']) // Clean workspace
}
}
}
}
}
}
}
-65
View File
@@ -1,65 +0,0 @@
################################################################################
# Command for variable_watch. This command issues error message, if a variable
# is changed. If variable PROPERTY_READER_GUARD_DISABLED is TRUE nothing happens
# variable_watch(<variable> property_reader_guard)
################################################################################
function(property_reader_guard VARIABLE ACCESS VALUE CURRENT_LIST_FILE STACK)
if("${PROPERTY_READER_GUARD_DISABLED}")
return()
endif()
if("${ACCESS}" STREQUAL "MODIFIED_ACCESS")
message(FATAL_ERROR
" Variable ${VARIABLE} is not supposed to be changed.\n"
" It is used only for reading target property ${VARIABLE}.\n"
" Use\n"
" set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}\" \"<value>\")\n"
" or\n"
" set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}_<CONFIG>\" \"<value>\")\n"
" instead.\n")
endif()
endfunction()
################################################################################
# Create variable <name> with generator expression that expands to value of
# target property <name>_<CONFIG>. If property is empty or not set then property
# <name> is used instead. Variable <name> has watcher property_reader_guard that
# doesn't allow to edit it.
# create_property_reader(<name>)
# Input:
# name - Name of watched property and output variable
################################################################################
function(create_property_reader NAME)
set(PROPERTY_READER_GUARD_DISABLED TRUE)
set(CONFIG_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}_$<UPPER_CASE:$<CONFIG>>>>")
set(IS_CONFIG_VALUE_EMPTY "$<STREQUAL:${CONFIG_VALUE},>")
set(GENERAL_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}>>")
set("${NAME}" "$<IF:${IS_CONFIG_VALUE_EMPTY},${GENERAL_VALUE},${CONFIG_VALUE}>" PARENT_SCOPE)
variable_watch("${NAME}" property_reader_guard)
endfunction()
################################################################################
# Set property $<name>_${PROPS_CONFIG_U} of ${PROPS_TARGET} to <value>
# set_config_specific_property(<name> <value>)
# Input:
# name - Prefix of property name
# value - New value
################################################################################
function(set_config_specific_property NAME VALUE)
set_target_properties("${PROPS_TARGET}" PROPERTIES "${NAME}_${PROPS_CONFIG_U}" "${VALUE}")
endfunction()
################################################################################
create_property_reader("TARGET_NAME")
create_property_reader("OUTPUT_DIRECTORY")
set_config_specific_property("TARGET_NAME" "${PROPS_TARGET}")
set_config_specific_property("OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("ARCHIVE_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("LIBRARY_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("RUNTIME_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("ARCHIVE_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
set_config_specific_property("LIBRARY_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
set_config_specific_property("RUNTIME_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
-12
View File
@@ -1,12 +0,0 @@
include("${CMAKE_CURRENT_LIST_DIR}/Default.cmake")
set_config_specific_property("OUTPUT_DIRECTORY" "${CMAKE_SOURCE_DIR}$<$<NOT:$<STREQUAL:${CMAKE_VS_PLATFORM_NAME},Win32>>:/${CMAKE_VS_PLATFORM_NAME}>/${PROPS_CONFIG}")
if(MSVC)
create_property_reader("DEFAULT_CXX_EXCEPTION_HANDLING")
create_property_reader("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT")
set_target_properties("${PROPS_TARGET}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set_config_specific_property("DEFAULT_CXX_EXCEPTION_HANDLING" "/EHsc")
set_config_specific_property("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT" "/Zi")
endif()
-233
View File
@@ -1,233 +0,0 @@
# utils file for projects came from visual studio solution with cmake-converter.
################################################################################
# Wrap each token of the command with condition
################################################################################
cmake_policy(PUSH)
cmake_policy(SET CMP0054 NEW)
macro(prepare_commands)
unset(TOKEN_ROLE)
unset(COMMANDS)
foreach(TOKEN ${ARG_COMMANDS})
if("${TOKEN}" STREQUAL "COMMAND")
set(TOKEN_ROLE "KEYWORD")
elseif("${TOKEN_ROLE}" STREQUAL "KEYWORD")
set(TOKEN_ROLE "CONDITION")
elseif("${TOKEN_ROLE}" STREQUAL "CONDITION")
set(TOKEN_ROLE "COMMAND")
elseif("${TOKEN_ROLE}" STREQUAL "COMMAND")
set(TOKEN_ROLE "ARG")
endif()
if("${TOKEN_ROLE}" STREQUAL "KEYWORD")
list(APPEND COMMANDS "${TOKEN}")
elseif("${TOKEN_ROLE}" STREQUAL "CONDITION")
set(CONDITION ${TOKEN})
elseif("${TOKEN_ROLE}" STREQUAL "COMMAND")
list(APPEND COMMANDS "$<$<NOT:${CONDITION}>:${DUMMY}>$<${CONDITION}:${TOKEN}>")
elseif("${TOKEN_ROLE}" STREQUAL "ARG")
list(APPEND COMMANDS "$<${CONDITION}:${TOKEN}>")
endif()
endforeach()
endmacro()
cmake_policy(POP)
################################################################################
# Transform all the tokens to absolute paths
################################################################################
macro(prepare_output)
unset(OUTPUT)
foreach(TOKEN ${ARG_OUTPUT})
if(IS_ABSOLUTE ${TOKEN})
list(APPEND OUTPUT "${TOKEN}")
else()
list(APPEND OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${TOKEN}")
endif()
endforeach()
endmacro()
################################################################################
# Parse add_custom_command_if args.
#
# Input:
# PRE_BUILD - Pre build event option
# PRE_LINK - Pre link event option
# POST_BUILD - Post build event option
# TARGET - Target
# OUTPUT - List of output files
# DEPENDS - List of files on which the command depends
# COMMANDS - List of commands(COMMAND condition1 commannd1 args1 COMMAND
# condition2 commannd2 args2 ...)
# Output:
# OUTPUT - Output files
# DEPENDS - Files on which the command depends
# COMMENT - Comment
# PRE_BUILD - TRUE/FALSE
# PRE_LINK - TRUE/FALSE
# POST_BUILD - TRUE/FALSE
# TARGET - Target name
# COMMANDS - Prepared commands(every token is wrapped in CONDITION)
# NAME - Unique name for custom target
# STEP - PRE_BUILD/PRE_LINK/POST_BUILD
################################################################################
function(add_custom_command_if_parse_arguments)
cmake_parse_arguments("ARG" "PRE_BUILD;PRE_LINK;POST_BUILD" "TARGET;COMMENT" "DEPENDS;OUTPUT;COMMANDS" ${ARGN})
if(WIN32)
set(DUMMY "cd.")
elseif(UNIX)
set(DUMMY "true")
endif()
prepare_commands()
prepare_output()
set(DEPENDS "${ARG_DEPENDS}")
set(COMMENT "${ARG_COMMENT}")
set(PRE_BUILD "${ARG_PRE_BUILD}")
set(PRE_LINK "${ARG_PRE_LINK}")
set(POST_BUILD "${ARG_POST_BUILD}")
set(TARGET "${ARG_TARGET}")
if(PRE_BUILD)
set(STEP "PRE_BUILD")
elseif(PRE_LINK)
set(STEP "PRE_LINK")
elseif(POST_BUILD)
set(STEP "POST_BUILD")
endif()
set(NAME "${TARGET}_${STEP}")
set(OUTPUT "${OUTPUT}" PARENT_SCOPE)
set(DEPENDS "${DEPENDS}" PARENT_SCOPE)
set(COMMENT "${COMMENT}" PARENT_SCOPE)
set(PRE_BUILD "${PRE_BUILD}" PARENT_SCOPE)
set(PRE_LINK "${PRE_LINK}" PARENT_SCOPE)
set(POST_BUILD "${POST_BUILD}" PARENT_SCOPE)
set(TARGET "${TARGET}" PARENT_SCOPE)
set(COMMANDS "${COMMANDS}" PARENT_SCOPE)
set(STEP "${STEP}" PARENT_SCOPE)
set(NAME "${NAME}" PARENT_SCOPE)
endfunction()
################################################################################
# Add conditional custom command
#
# Generating Files
# The first signature is for adding a custom command to produce an output:
# add_custom_command_if(
# <OUTPUT output1 [output2 ...]>
# <COMMANDS>
# <COMMAND condition command1 [args1...]>
# [COMMAND condition command2 [args2...]]
# [DEPENDS [depends...]]
# [COMMENT comment]
#
# Build Events
# add_custom_command_if(
# <TARGET target>
# <PRE_BUILD | PRE_LINK | POST_BUILD>
# <COMMAND condition command1 [args1...]>
# [COMMAND condition command2 [args2...]]
# [COMMENT comment]
#
# Input:
# output - Output files the command is expected to produce
# condition - Generator expression for wrapping the command
# command - Command-line(s) to execute at build time.
# args - Command`s args
# depends - Files on which the command depends
# comment - Display the given message before the commands are executed at
# build time.
# PRE_BUILD - Run before any other rules are executed within the target
# PRE_LINK - Run after sources have been compiled but before linking the
# binary
# POST_BUILD - Run after all other rules within the target have been
# executed
################################################################################
function(add_custom_command_if)
add_custom_command_if_parse_arguments(${ARGN})
if(OUTPUT AND TARGET)
message(FATAL_ERROR "Wrong syntax. A TARGET and OUTPUT can not both be specified.")
endif()
if(OUTPUT)
add_custom_command(OUTPUT ${OUTPUT}
${COMMANDS}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
elseif(TARGET)
if(PRE_BUILD AND NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio")
add_custom_target(
${NAME}
${COMMANDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
add_dependencies(${TARGET} ${NAME})
else()
add_custom_command(
TARGET ${TARGET}
${STEP}
${COMMANDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
endif()
else()
message(FATAL_ERROR "Wrong syntax. A TARGET or OUTPUT must be specified.")
endif()
endfunction()
################################################################################
# Use props file for a target and configs
# use_props(<target> <configs...> <props_file>)
# Inside <props_file> there are following variables:
# PROPS_TARGET - <target>
# PROPS_CONFIG - One of <configs...>
# PROPS_CONFIG_U - Uppercase PROPS_CONFIG
# Input:
# target - Target to apply props file
# configs - Build configurations to apply props file
# props_file - CMake script
################################################################################
macro(use_props TARGET CONFIGS PROPS_FILE)
set(PROPS_TARGET "${TARGET}")
foreach(PROPS_CONFIG ${CONFIGS})
string(TOUPPER "${PROPS_CONFIG}" PROPS_CONFIG_U)
get_filename_component(ABSOLUTE_PROPS_FILE "${PROPS_FILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
if(EXISTS "${ABSOLUTE_PROPS_FILE}")
include("${ABSOLUTE_PROPS_FILE}")
else()
message(WARNING "Corresponding cmake file from props \"${ABSOLUTE_PROPS_FILE}\" doesn't exist")
endif()
endforeach()
endmacro()
################################################################################
# Add compile options to source file
# source_file_compile_options(<source_file> [compile_options...])
# Input:
# source_file - Source file
# compile_options - Options to add to COMPILE_FLAGS property
################################################################################
function(source_file_compile_options SOURCE_FILE)
if("${ARGC}" LESS_EQUAL "1")
return()
endif()
get_source_file_property(COMPILE_OPTIONS "${SOURCE_FILE}" COMPILE_OPTIONS)
if(COMPILE_OPTIONS)
list(APPEND COMPILE_OPTIONS ${ARGN})
else()
set(COMPILE_OPTIONS "${ARGN}")
endif()
set_source_files_properties("${SOURCE_FILE}" PROPERTIES COMPILE_OPTIONS "${COMPILE_OPTIONS}")
endfunction()
################################################################################
# Default properties of visual studio projects
################################################################################
set(DEFAULT_CXX_PROPS "${CMAKE_CURRENT_LIST_DIR}/DefaultCXX.cmake")
-96
View File
@@ -1,96 +0,0 @@
cmake_minimum_required(VERSION 3.16.0 FATAL_ERROR)
set(CMAKE_SYSTEM_VERSION 10.0 CACHE STRING "" FORCE)
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
#set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard to use")
set(CMAKE_C_STANDARD 11)
project(OTRExporter C CXX)
################################################################################
# Set target arch type if empty. Visual studio solution generator provides it.
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(NOT CMAKE_VS_PLATFORM_NAME)
set(CMAKE_VS_PLATFORM_NAME "x64")
endif()
message("${CMAKE_VS_PLATFORM_NAME} architecture in use")
if(NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64"
OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32"))
message(FATAL_ERROR "${CMAKE_VS_PLATFORM_NAME} arch is not supported!")
endif()
endif()
################################################################################
# Global configuration types
################################################################################
set(CMAKE_CONFIGURATION_TYPES
"Debug"
"Release"
CACHE STRING "" FORCE
)
################################################################################
# Global compiler options
################################################################################
if(MSVC)
# remove default flags provided with CMake for MSVC
set(CMAKE_C_FLAGS "")
set(CMAKE_C_FLAGS_DEBUG "")
set(CMAKE_C_FLAGS_RELEASE "")
set(CMAKE_CXX_FLAGS "")
set(CMAKE_CXX_FLAGS_DEBUG "")
set(CMAKE_CXX_FLAGS_RELEASE "")
endif()
################################################################################
# Global linker options
################################################################################
if(MSVC)
# remove default flags provided with CMake for MSVC
set(CMAKE_EXE_LINKER_FLAGS "")
set(CMAKE_MODULE_LINKER_FLAGS "")
set(CMAKE_SHARED_LINKER_FLAGS "")
set(CMAKE_STATIC_LINKER_FLAGS "")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS}")
endif()
################################################################################
# Common utils
################################################################################
include(CMake/Utils.cmake)
################################################################################
# Additional Global Settings(add specific info there)
################################################################################
include(CMake/GlobalSettingsInclude.cmake OPTIONAL)
################################################################################
# Use solution folders feature
################################################################################
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
################################################################################
# Sub-projects
################################################################################
if (NOT TARGET libultraship)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/libultraship ${CMAKE_BINARY_DIR}/libultraship)
endif()
if (NOT TARGET ZAPD)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../ZAPDTR/ZAPD ${CMAKE_BINARY_DIR}/ZAPD)
endif()
if (NOT TARGET ZAPDUtils)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../ZAPDTR/ZAPDUtils ${CMAKE_BINARY_DIR}/ZAPDUtils)
endif()
add_subdirectory(OTRExporter)
+79
View File
@@ -0,0 +1,79 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OTRExporter", "OTRExporter\OTRExporter.vcxproj", "{A6103FD3-0709-4FC7-B066-1A6E056D6306}"
ProjectSection(ProjectDependencies) = postProject
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8} = {6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libultraship", "..\libultraship\libultraship\libultraship.vcxproj", "{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPD", "..\ZAPDTR\ZAPD\ZAPD.vcxproj", "{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}"
ProjectSection(ProjectDependencies) = postProject
{78424708-1F6E-4D4B-920C-FB6D26847055} = {78424708-1F6E-4D4B-920C-FB6D26847055}
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8} = {6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}
{A2E01C3E-D647-45D1-9788-043DEBC1A908} = {A2E01C3E-D647-45D1-9788-043DEBC1A908}
{A6103FD3-0709-4FC7-B066-1A6E056D6306} = {A6103FD3-0709-4FC7-B066-1A6E056D6306}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPDUtils", "..\ZAPDTR\ZAPDUtils\ZAPDUtils.vcxproj", "{A2E01C3E-D647-45D1-9788-043DEBC1A908}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StormLib", "..\StormLib\StormLib_vs19.vcxproj", "{78424708-1F6E-4D4B-920C-FB6D26847055}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A6103FD3-0709-4FC7-B066-1A6E056D6306}.Debug|x64.ActiveCfg = Debug|x64
{A6103FD3-0709-4FC7-B066-1A6E056D6306}.Debug|x64.Build.0 = Debug|x64
{A6103FD3-0709-4FC7-B066-1A6E056D6306}.Debug|x86.ActiveCfg = Debug|Win32
{A6103FD3-0709-4FC7-B066-1A6E056D6306}.Debug|x86.Build.0 = Debug|Win32
{A6103FD3-0709-4FC7-B066-1A6E056D6306}.Release|x64.ActiveCfg = Release|x64
{A6103FD3-0709-4FC7-B066-1A6E056D6306}.Release|x64.Build.0 = Release|x64
{A6103FD3-0709-4FC7-B066-1A6E056D6306}.Release|x86.ActiveCfg = Release|Win32
{A6103FD3-0709-4FC7-B066-1A6E056D6306}.Release|x86.Build.0 = Release|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x64.ActiveCfg = Debug|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x64.Build.0 = Debug|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x86.ActiveCfg = Debug|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x86.Build.0 = Debug|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x64.ActiveCfg = Release|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x64.Build.0 = Release|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x86.ActiveCfg = Release|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x86.Build.0 = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.ActiveCfg = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.Build.0 = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.ActiveCfg = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.Build.0 = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.Build.0 = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.ActiveCfg = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.Build.0 = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.ActiveCfg = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.Build.0 = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.ActiveCfg = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.Build.0 = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.ActiveCfg = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.Build.0 = Release|Win32
{78424708-1F6E-4D4B-920C-FB6D26847055}.Debug|x64.ActiveCfg = DebugUS|x64
{78424708-1F6E-4D4B-920C-FB6D26847055}.Debug|x64.Build.0 = DebugUS|x64
{78424708-1F6E-4D4B-920C-FB6D26847055}.Debug|x86.ActiveCfg = DebugAD|Win32
{78424708-1F6E-4D4B-920C-FB6D26847055}.Debug|x86.Build.0 = DebugAD|Win32
{78424708-1F6E-4D4B-920C-FB6D26847055}.Release|x64.ActiveCfg = ReleaseUS|x64
{78424708-1F6E-4D4B-920C-FB6D26847055}.Release|x64.Build.0 = ReleaseUS|x64
{78424708-1F6E-4D4B-920C-FB6D26847055}.Release|x86.ActiveCfg = ReleaseAS|Win32
{78424708-1F6E-4D4B-920C-FB6D26847055}.Release|x86.Build.0 = ReleaseAS|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DCE19FF1-37C0-49CD-915A-DD695E15F00B}
EndGlobalSection
EndGlobal
-249
View File
@@ -1,249 +0,0 @@
set(PROJECT_NAME OTRExporter)
################################################################################
# Source groups
################################################################################
set(Header_Files
"AnimationExporter.h"
"ArrayExporter.h"
"AudioExporter.h"
"BackgroundExporter.h"
"BlobExporter.h"
"CollisionExporter.h"
"command_macros_base.h"
"CutsceneExporter.h"
"DisplayListExporter.h"
"Exporter.h"
"Main.h"
"MtxExporter.h"
"PathExporter.h"
"PlayerAnimationExporter.h"
"RoomExporter.h"
"SkeletonExporter.h"
"SkeletonLimbExporter.h"
"TextExporter.h"
"TextureExporter.h"
"VersionInfo.h"
"VtxExporter.h"
"z64cutscene.h"
"z64cutscene_commands.h"
)
source_group("Header Files" FILES ${Header_Files})
set(Source_Files
"AnimationExporter.cpp"
"ArrayExporter.cpp"
"AudioExporter.cpp"
"BackgroundExporter.cpp"
"BlobExporter.cpp"
"CollisionExporter.cpp"
"CutsceneExporter.cpp"
"DisplayListExporter.cpp"
"Exporter.cpp"
"Main.cpp"
"MtxExporter.cpp"
"PathExporter.cpp"
"PlayerAnimationExporter.cpp"
"RoomExporter.cpp"
"SkeletonExporter.cpp"
"SkeletonLimbExporter.cpp"
"TextExporter.cpp"
"TextureExporter.cpp"
"VersionInfo.cpp"
"VtxExporter.cpp"
)
source_group("Source Files" FILES ${Source_Files})
set(ALL_FILES
${Header_Files}
${Source_Files}
)
################################################################################
# Target
################################################################################
add_library(${PROJECT_NAME} STATIC ${ALL_FILES})
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
endif()
set(ROOT_NAMESPACE OTRExporter)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_GLOBAL_KEYWORD "Win32Proj"
)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86")
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
endif()
endif()
################################################################################
# MSVC runtime library
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
$<$<CONFIG:Debug>:
MultiThreadedDebug
>
$<$<CONFIG:Release>:
MultiThreaded
>
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
endif()
################################################################################
# Compile definitions
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"_CONSOLE;"
"_CRT_SECURE_NO_WARNINGS;"
"UNICODE;"
"_UNICODE"
STORMLIB_NO_AUTO_LINK
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG;"
"_CRT_SECURE_NO_WARNINGS"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"WIN32;"
"_CONSOLE;"
"UNICODE;"
"_UNICODE"
STORMLIB_NO_AUTO_LINK
)
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"_CONSOLE;"
"_CRT_SECURE_NO_WARNINGS;"
"UNICODE;"
"_UNICODE"
)
endif()
################################################################################
# Compile and link options
################################################################################
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/ZAPD/
${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/ZAPDUtils
${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/lib/tinyxml2
${CMAKE_CURRENT_SOURCE_DIR}/../../libultraship/libultraship
${CMAKE_CURRENT_SOURCE_DIR}/../../libultraship/libultraship/Lib/spdlog/include
${CMAKE_CURRENT_SOURCE_DIR}/../../libultraship/libultraship/Lib/Fast3D/U64
${CMAKE_CURRENT_SOURCE_DIR}/../../StormLib/src
.
)
if(MSVC)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/Oi;
/Gy
>
/permissive-;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/Oi;
/Gy
>
/permissive-;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
endif()
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/OPT:REF;
/OPT:ICF
>
/SUBSYSTEM:CONSOLE
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86")
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/DEBUG;
/OPT:REF;
/OPT:ICF;
/INCREMENTAL:NO
>
/SUBSYSTEM:CONSOLE
)
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall -Wextra -Wno-error
-Wno-unused-parameter
-Wno-unused-function
-Wno-unused-variable
-Wno-missing-field-initializers
-Wno-parentheses
-Wno-narrowing
$<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-enum-enum-conversion>
)
endif()
################################################################################
# Dependencies
################################################################################
add_dependencies(${PROJECT_NAME}
libultraship
)
# Link with other targets.
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
set(ADDITIONAL_LIBRARY_DEPENDENCIES
"$<$<CONFIG:Debug>:"
"ZAPDUtils;"
"OTRLib"
">"
)
endif()
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
@@ -653,13 +653,8 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina
uint32_t seg = data & 0xFFFFFFFF;
int32_t texAddress = Seg2Filespace(data, dList->parent->baseAddress);
if (!Globals::Instance->HasSegment(GETSEGNUM(seg), res->parent->workerID) || (res->GetName() == "sShadowMaterialDL"))
if (!Globals::Instance->HasSegment(GETSEGNUM(seg), res->parent->workerID))
{
if (res->GetName() == "sShadowMaterialDL") {
// sShadowMaterialDL (In ovl_En_Jsjutan) has a texture in bss. This is a hack to override the reference to one
// to segment C. The actor has been modified to load the texture into segment C.
seg = 0x0C000000;
}
int32_t __ = (data & 0x00FF000000000000) >> 48;
int32_t www = (data & 0x00000FFF00000000) >> 32;
+1 -1
View File
@@ -3,7 +3,7 @@
void OTRExporter::WriteHeader(ZResource* res, const fs::path& outPath, BinaryWriter* writer, Ship::ResourceType resType, Ship::Version resVersion)
{
writer->Write((uint8_t)Endianness::Little); // 0x00
writer->Write((uint8_t)Endianess::Little); // 0x00
writer->Write((uint8_t)0); // 0x01
writer->Write((uint8_t)0); // 0x02
writer->Write((uint8_t)0); // 0x03
+3 -19
View File
@@ -63,29 +63,13 @@ static void ExporterProgramEnd()
{
if (Globals::Instance->fileMode == ZFileMode::ExtractDirectory)
{
printf("Creating version file...\n");
// Get crc from rom
std::string romPath = Globals::Instance->baseRomPath.string();
std::vector<uint8_t> romData = File::ReadAllBytes(romPath);
uint32_t crc = BitConverter::ToUInt32BE(romData, 0x10);
// Write crc to version file
fs::path versionPath("Extract/version");
std::ofstream versionFile(versionPath.c_str(), std::ios::out | std::ios::binary);
versionFile.write((char*)&crc, sizeof(crc));
versionFile.flush();
versionFile.close();
printf("Created version file.\n");
printf("Generating OTR Archive...\n");
otrArchive = Ship::Archive::CreateArchive(otrFileName, 40000);
for (auto item : files) {
for (auto item : files)
{
auto fileData = item.second;
otrArchive->AddFile(item.first, (uintptr_t)fileData.data(),
fileData.size());
otrArchive->AddFile(item.first, (uintptr_t)fileData.data(), fileData.size());
}
// Add any additional files that need to be manually copied...
+72
View File
@@ -0,0 +1,72 @@
# Only used for standalone compilation, usually inherits these from the main makefile
CXX ?= g++
AR := ar
FORMAT := clang-format-11
ASAN ?= 0
DEBUG ?= 1
OPTFLAGS ?= -O0
LTO ?= 0
WARN := -Wall -Wextra -Werror \
-Wno-unused-parameter \
-Wno-unused-function \
-Wno-unused-variable \
-Wno-error=multichar
CXXFLAGS := $(WARN) -std=c++17
CPPFLAGS := -MMD
ifneq ($(DEBUG),0)
CXXFLAGS += -g
endif
ifneq ($(ASAN),0)
CXXFLAGS += -fsanitize=address
endif
ifneq ($(LTO),0)
CXXFLAGS += -flto
endif
SRC_DIRS := $(shell find . -type d -not -path "*build*")
CXX_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
O_FILES := $(CXX_FILES:%.cpp=build/%.o)
D_FILES := $(O_FILES:%.o=%.d)
LIB := OTRExporter.a
INC_DIRS := $(addprefix -I, \
../../ZAPDTR/ZAPD \
../../ZAPDTR/lib/tinyxml2 \
../../ZAPDTR/lib/libgfxd \
../../ZAPDTR/ZAPDUtils \
../../libultraship/libultraship \
../../libultraship/libultraship/Lib/spdlog/include \
../../libultraship/libultraship/Lib/Fast3D/U64 \
../../StormLib/src \
)
# create build directories
$(shell mkdir -p $(SRC_DIRS:%=build/%))
all: $(LIB)
clean:
rm -rf build $(LIB)
format:
$(FORMAT) -i $(CXX_FILES) $(H_FILES)
.PHONY: all clean format
build/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) -c $< -o $@
$(LIB): $(O_FILES)
$(AR) rcs $@ $^
-include $(D_FILES)
+222
View File
@@ -0,0 +1,222 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ArrayExporter.h" />
<ClInclude Include="AudioExporter.h" />
<ClInclude Include="BackgroundExporter.h" />
<ClInclude Include="BlobExporter.h" />
<ClInclude Include="CollisionExporter.h" />
<ClInclude Include="command_macros_base.h" />
<ClInclude Include="CutsceneExporter.h" />
<ClInclude Include="DisplayListExporter.h" />
<ClInclude Include="AnimationExporter.h" />
<ClInclude Include="Main.h" />
<ClInclude Include="Exporter.h" />
<ClInclude Include="MtxExporter.h" />
<ClInclude Include="SkeletonExporter.h" />
<ClInclude Include="SkeletonLimbExporter.h" />
<ClInclude Include="PathExporter.h" />
<ClInclude Include="PlayerAnimationExporter.h" />
<ClInclude Include="RoomExporter.h" />
<ClInclude Include="TextExporter.h" />
<ClInclude Include="TextureExporter.h" />
<ClInclude Include="VersionInfo.h" />
<ClInclude Include="VtxExporter.h" />
<ClInclude Include="z64cutscene.h" />
<ClInclude Include="z64cutscene_commands.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ArrayExporter.cpp" />
<ClCompile Include="AudioExporter.cpp" />
<ClCompile Include="BackgroundExporter.cpp" />
<ClCompile Include="BlobExporter.cpp" />
<ClCompile Include="CollisionExporter.cpp" />
<ClCompile Include="CutsceneExporter.cpp" />
<ClCompile Include="DisplayListExporter.cpp" />
<ClCompile Include="AnimationExporter.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Exporter.cpp" />
<ClCompile Include="MtxExporter.cpp" />
<ClCompile Include="SkeletonExporter.cpp" />
<ClCompile Include="SkeletonLimbExporter.cpp" />
<ClCompile Include="PathExporter.cpp" />
<ClCompile Include="PlayerAnimationExporter.cpp" />
<ClCompile Include="RoomExporter.cpp" />
<ClCompile Include="TextExporter.cpp" />
<ClCompile Include="TextureExporter.cpp" />
<ClCompile Include="VersionInfo.cpp" />
<ClCompile Include="VtxExporter.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\OTRGui\build\ZERO_CHECK.vcxproj">
<Project>{02d10590-9542-3f55-aaf8-6055677e2a2a}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a6103fd3-0709-4fc7-b066-1a6e056d6306}</ProjectGuid>
<RootNamespace>OTRExporter</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)otrlib;$(SolutionDir)\ZAPD\ZAPD\;$(SolutionDir)\ZAPD\lib\tinyxml2;$(SolutionDir)\ZAPD\lib\libgfxd;$(SolutionDir)\ZAPD\lib\elfio;$(SolutionDir)\ZAPD\lib\assimp\include;$(SolutionDir)\ZAPD\lib\stb;$(ProjectDir);$(IncludePath)</IncludePath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules />
<CodeAnalysisRuleAssemblies />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules />
<CodeAnalysisRuleAssemblies />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)..\..\ZAPDTR\ZAPD;$(ProjectDir)..\..\ZAPDTR\lib\tinyxml2;$(ProjectDir)..\..\ZAPDTR\lib\libgfxd;$(ProjectDir)..\..\ZAPDTR\ZAPDUtils;$(ProjectDir)..\..\libultraship\libultraship;$(ProjectDir)..\..\libultraship\libultraship\lib\spdlog\include;$(ProjectDir)..\..\libultraship\libultraship\Lib\Fast3D\U64;$(ProjectDir)..\..\StormLib\src\;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)..\..\libultraship\libultraship;$(LibraryPath)</LibraryPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules />
<CodeAnalysisRuleAssemblies />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)..\..\ZAPDTR\ZAPD;$(ProjectDir)..\..\ZAPDTR\lib\tinyxml2;$(ProjectDir)..\..\ZAPDTR\lib\libgfxd;$(ProjectDir)..\..\ZAPDTR\ZAPDUtils;$(ProjectDir)..\..\libultraship\libultraship;$(ProjectDir)..\..\libultraship\libultraship\lib\spdlog\include;$(ProjectDir)..\..\libultraship\libultraship\Lib\Fast3D\U64;$(ProjectDir)..\..\StormLib\src\;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)..\..\libultraship\libultraship;$(LibraryPath)</LibraryPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules />
<CodeAnalysisRuleAssemblies />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ZAPDUtils.lib;OTRLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CollisionExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RoomExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TextureExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DisplayListExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Main.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PlayerAnimationExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BackgroundExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="VtxExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ArrayExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Exporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AnimationExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CutsceneExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="z64cutscene.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="z64cutscene_commands.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="command_macros_base.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PathExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SkeletonExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SkeletonLimbExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TextExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BlobExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MtxExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="VersionInfo.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AudioExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CollisionExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RoomExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TextureExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DisplayListExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PlayerAnimationExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SkeletonExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SkeletonLimbExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BackgroundExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="VtxExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ArrayExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Exporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AnimationExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CutsceneExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PathExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TextExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BlobExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MtxExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="VersionInfo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AudioExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
+10 -18
View File
@@ -5,21 +5,19 @@ import shutil
from rom_info import Z64Rom
import rom_chooser
import struct
import subprocess
import argparse
def BuildOTR(xmlPath, rom, zapd_exe=None):
def BuildOTR(xmlPath, rom):
shutil.copytree("assets", "Extract/assets")
if not zapd_exe:
zapd_exe = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPDTR/ZAPD.out"
checksum = int(Z64Rom(rom).checksum.value, 16)
with open("Extract/version", "wb") as f:
f.write(struct.pack('<L', checksum))
exec_cmd = [zapd_exe, "ed", "-i", xmlPath, "-b", rom, "-fl", "CFG/filelists",
"-o", "placeholder", "-osf", "placeholder", "-gsf", "1",
"-rconf", "CFG/Config.xml", "-se", "OTR"]
execStr = "x64\\Release\\ZAPD.exe" if sys.platform == "win32" else "../ZAPDTR/ZAPD.out"
execStr += " ed -i %s -b %s -fl CFG/filelists -o placeholder -osf placeholder -gsf 1 -rconf CFG/Config.xml -se OTR" % (xmlPath, rom)
print(exec_cmd)
exitValue = subprocess.call(exec_cmd)
print(execStr)
exitValue = os.system(execStr)
if exitValue != 0:
print("\n")
print("Error when building the OTR file...", file=os.sys.stderr)
@@ -27,19 +25,13 @@ def BuildOTR(xmlPath, rom, zapd_exe=None):
print("\n")
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-z", "--zapd", help="Path to ZAPD executable", dest="zapd_exe", type=str)
parser.add_argument("rom", help="Path to the rom", type=str, nargs="?")
args = parser.parse_args()
rom_path = args.rom if args.rom else rom_chooser.chooseROM()
rom_path = rom_chooser.chooseROM()
rom = Z64Rom(rom_path)
if (os.path.exists("Extract")):
shutil.rmtree("Extract")
BuildOTR("../soh/assets/xml/" + rom.version.xml_ver + "/", rom_path, zapd_exe=args.zapd_exe)
BuildOTR("../soh/assets/xml/" + rom.version.xml_ver + "/", rom_path)
if __name__ == "__main__":
main()
-1
View File
@@ -36,7 +36,6 @@ class RomVersion:
ROM_INFO_TABLE = dict()
ROM_INFO_TABLE[Checksums.OOT_PAL_GC] = RomVersion("CFG/filelists/gamecube_pal.txt", 0x7170, "GC_NMQ_PAL_F")
ROM_INFO_TABLE[Checksums.OOT_PAL_GC_DBG1] = RomVersion("CFG/filelists/dbg.txt", 0x12F70, "GC_NMQ_D")
ROM_INFO_TABLE[Checksums.OOT_PAL_GC_MQ_DBG] = RomVersion("CFG/filelists/dbg.txt", 0x12F70, "GC_MQ_D")
class RomDmaEntry:
def __init__(self, rom, i):
-65
View File
@@ -1,65 +0,0 @@
################################################################################
# Command for variable_watch. This command issues error message, if a variable
# is changed. If variable PROPERTY_READER_GUARD_DISABLED is TRUE nothing happens
# variable_watch(<variable> property_reader_guard)
################################################################################
function(property_reader_guard VARIABLE ACCESS VALUE CURRENT_LIST_FILE STACK)
if("${PROPERTY_READER_GUARD_DISABLED}")
return()
endif()
if("${ACCESS}" STREQUAL "MODIFIED_ACCESS")
message(FATAL_ERROR
" Variable ${VARIABLE} is not supposed to be changed.\n"
" It is used only for reading target property ${VARIABLE}.\n"
" Use\n"
" set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}\" \"<value>\")\n"
" or\n"
" set_target_properties(\"<target>\" PROPERTIES \"${VARIABLE}_<CONFIG>\" \"<value>\")\n"
" instead.\n")
endif()
endfunction()
################################################################################
# Create variable <name> with generator expression that expands to value of
# target property <name>_<CONFIG>. If property is empty or not set then property
# <name> is used instead. Variable <name> has watcher property_reader_guard that
# doesn't allow to edit it.
# create_property_reader(<name>)
# Input:
# name - Name of watched property and output variable
################################################################################
function(create_property_reader NAME)
set(PROPERTY_READER_GUARD_DISABLED TRUE)
set(CONFIG_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}_$<UPPER_CASE:$<CONFIG>>>>")
set(IS_CONFIG_VALUE_EMPTY "$<STREQUAL:${CONFIG_VALUE},>")
set(GENERAL_VALUE "$<TARGET_GENEX_EVAL:${PROPS_TARGET},$<TARGET_PROPERTY:${PROPS_TARGET},${NAME}>>")
set("${NAME}" "$<IF:${IS_CONFIG_VALUE_EMPTY},${GENERAL_VALUE},${CONFIG_VALUE}>" PARENT_SCOPE)
variable_watch("${NAME}" property_reader_guard)
endfunction()
################################################################################
# Set property $<name>_${PROPS_CONFIG_U} of ${PROPS_TARGET} to <value>
# set_config_specific_property(<name> <value>)
# Input:
# name - Prefix of property name
# value - New value
################################################################################
function(set_config_specific_property NAME VALUE)
set_target_properties("${PROPS_TARGET}" PROPERTIES "${NAME}_${PROPS_CONFIG_U}" "${VALUE}")
endfunction()
################################################################################
create_property_reader("TARGET_NAME")
create_property_reader("OUTPUT_DIRECTORY")
set_config_specific_property("TARGET_NAME" "${PROPS_TARGET}")
set_config_specific_property("OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("ARCHIVE_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("LIBRARY_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("RUNTIME_OUTPUT_NAME" "${TARGET_NAME}")
set_config_specific_property("ARCHIVE_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
set_config_specific_property("LIBRARY_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
set_config_specific_property("RUNTIME_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}")
-12
View File
@@ -1,12 +0,0 @@
include("${CMAKE_CURRENT_LIST_DIR}/Default.cmake")
set_config_specific_property("OUTPUT_DIRECTORY" "${CMAKE_SOURCE_DIR}$<$<NOT:$<STREQUAL:${CMAKE_VS_PLATFORM_NAME},Win32>>:/${CMAKE_VS_PLATFORM_NAME}>/${PROPS_CONFIG}")
if(MSVC)
create_property_reader("DEFAULT_CXX_EXCEPTION_HANDLING")
create_property_reader("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT")
set_target_properties("${PROPS_TARGET}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set_config_specific_property("DEFAULT_CXX_EXCEPTION_HANDLING" "/EHsc")
set_config_specific_property("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT" "/Zi")
endif()
-234
View File
@@ -1,234 +0,0 @@
# utils file for projects came from visual studio solution with cmake-converter.
################################################################################
# Wrap each token of the command with condition
################################################################################
cmake_policy(PUSH)
cmake_policy(SET CMP0054 NEW)
macro(prepare_commands)
unset(TOKEN_ROLE)
unset(COMMANDS)
foreach(TOKEN ${ARG_COMMANDS})
if("${TOKEN}" STREQUAL "COMMAND")
set(TOKEN_ROLE "KEYWORD")
elseif("${TOKEN_ROLE}" STREQUAL "KEYWORD")
set(TOKEN_ROLE "CONDITION")
elseif("${TOKEN_ROLE}" STREQUAL "CONDITION")
set(TOKEN_ROLE "COMMAND")
elseif("${TOKEN_ROLE}" STREQUAL "COMMAND")
set(TOKEN_ROLE "ARG")
endif()
if("${TOKEN_ROLE}" STREQUAL "KEYWORD")
list(APPEND COMMANDS "${TOKEN}")
elseif("${TOKEN_ROLE}" STREQUAL "CONDITION")
set(CONDITION ${TOKEN})
elseif("${TOKEN_ROLE}" STREQUAL "COMMAND")
list(APPEND COMMANDS "$<$<NOT:${CONDITION}>:${DUMMY}>$<${CONDITION}:${TOKEN}>")
elseif("${TOKEN_ROLE}" STREQUAL "ARG")
list(APPEND COMMANDS "$<${CONDITION}:${TOKEN}>")
endif()
endforeach()
endmacro()
cmake_policy(POP)
################################################################################
# Transform all the tokens to absolute paths
################################################################################
macro(prepare_output)
unset(OUTPUT)
foreach(TOKEN ${ARG_OUTPUT})
if(IS_ABSOLUTE ${TOKEN})
list(APPEND OUTPUT "${TOKEN}")
else()
list(APPEND OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${TOKEN}")
endif()
endforeach()
endmacro()
################################################################################
# Parse add_custom_command_if args.
#
# Input:
# PRE_BUILD - Pre build event option
# PRE_LINK - Pre link event option
# POST_BUILD - Post build event option
# TARGET - Target
# OUTPUT - List of output files
# DEPENDS - List of files on which the command depends
# COMMANDS - List of commands(COMMAND condition1 commannd1 args1 COMMAND
# condition2 commannd2 args2 ...)
# Output:
# OUTPUT - Output files
# DEPENDS - Files on which the command depends
# COMMENT - Comment
# PRE_BUILD - TRUE/FALSE
# PRE_LINK - TRUE/FALSE
# POST_BUILD - TRUE/FALSE
# TARGET - Target name
# COMMANDS - Prepared commands(every token is wrapped in CONDITION)
# NAME - Unique name for custom target
# STEP - PRE_BUILD/PRE_LINK/POST_BUILD
################################################################################
function(add_custom_command_if_parse_arguments)
cmake_parse_arguments("ARG" "PRE_BUILD;PRE_LINK;POST_BUILD" "TARGET;COMMENT" "DEPENDS;OUTPUT;COMMANDS" ${ARGN})
if(WIN32)
set(DUMMY "cd.")
elseif(UNIX)
set(DUMMY "true")
endif()
prepare_commands()
prepare_output()
set(DEPENDS "${ARG_DEPENDS}")
set(COMMENT "${ARG_COMMENT}")
set(PRE_BUILD "${ARG_PRE_BUILD}")
set(PRE_LINK "${ARG_PRE_LINK}")
set(POST_BUILD "${ARG_POST_BUILD}")
set(TARGET "${ARG_TARGET}")
if(PRE_BUILD)
set(STEP "PRE_BUILD")
elseif(PRE_LINK)
set(STEP "PRE_LINK")
elseif(POST_BUILD)
set(STEP "POST_BUILD")
endif()
set(NAME "${TARGET}_${STEP}")
set(OUTPUT "${OUTPUT}" PARENT_SCOPE)
set(DEPENDS "${DEPENDS}" PARENT_SCOPE)
set(COMMENT "${COMMENT}" PARENT_SCOPE)
set(PRE_BUILD "${PRE_BUILD}" PARENT_SCOPE)
set(PRE_LINK "${PRE_LINK}" PARENT_SCOPE)
set(POST_BUILD "${POST_BUILD}" PARENT_SCOPE)
set(TARGET "${TARGET}" PARENT_SCOPE)
set(COMMANDS "${COMMANDS}" PARENT_SCOPE)
set(STEP "${STEP}" PARENT_SCOPE)
set(NAME "${NAME}" PARENT_SCOPE)
endfunction()
################################################################################
# Add conditional custom command
#
# Generating Files
# The first signature is for adding a custom command to produce an output:
# add_custom_command_if(
# <OUTPUT output1 [output2 ...]>
# <COMMANDS>
# <COMMAND condition command1 [args1...]>
# [COMMAND condition command2 [args2...]]
# [DEPENDS [depends...]]
# [COMMENT comment]
#
# Build Events
# add_custom_command_if(
# <TARGET target>
# <PRE_BUILD | PRE_LINK | POST_BUILD>
# <COMMAND condition command1 [args1...]>
# [COMMAND condition command2 [args2...]]
# [COMMENT comment]
#
# Input:
# output - Output files the command is expected to produce
# condition - Generator expression for wrapping the command
# command - Command-line(s) to execute at build time.
# args - Command`s args
# depends - Files on which the command depends
# comment - Display the given message before the commands are executed at
# build time.
# PRE_BUILD - Run before any other rules are executed within the target
# PRE_LINK - Run after sources have been compiled but before linking the
# binary
# POST_BUILD - Run after all other rules within the target have been
# executed
################################################################################
function(add_custom_command_if)
add_custom_command_if_parse_arguments(${ARGN})
if(OUTPUT AND TARGET)
message(FATAL_ERROR "Wrong syntax. A TARGET and OUTPUT can not both be specified.")
endif()
if(OUTPUT)
add_custom_command(OUTPUT ${OUTPUT}
${COMMANDS}
DEPENDS ${DEPENDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
elseif(TARGET)
if(PRE_BUILD AND NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio")
add_custom_target(
${NAME}
${COMMANDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
add_dependencies(${TARGET} ${NAME})
else()
add_custom_command(
TARGET ${TARGET}
${STEP}
${COMMANDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT ${COMMENT})
endif()
else()
message(FATAL_ERROR "Wrong syntax. A TARGET or OUTPUT must be specified.")
endif()
endfunction()
################################################################################
# Use props file for a target and configs
# use_props(<target> <configs...> <props_file>)
# Inside <props_file> there are following variables:
# PROPS_TARGET - <target>
# PROPS_CONFIG - One of <configs...>
# PROPS_CONFIG_U - Uppercase PROPS_CONFIG
# Input:
# target - Target to apply props file
# configs - Build configurations to apply props file
# props_file - CMake script
################################################################################
macro(use_props TARGET CONFIGS PROPS_FILE)
set(PROPS_TARGET "${TARGET}")
foreach(PROPS_CONFIG ${CONFIGS})
string(TOUPPER "${PROPS_CONFIG}" PROPS_CONFIG_U)
get_filename_component(ABSOLUTE_PROPS_FILE "${PROPS_FILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
if(EXISTS "${ABSOLUTE_PROPS_FILE}")
include("${ABSOLUTE_PROPS_FILE}")
else()
message(WARNING "Corresponding cmake file from props \"${ABSOLUTE_PROPS_FILE}\" doesn't exist")
endif()
endforeach()
endmacro()
################################################################################
# Add compile options to source file
# source_file_compile_options(<source_file> [compile_options...])
# Input:
# source_file - Source file
# compile_options - Options to add to COMPILE_FLAGS property
################################################################################
function(source_file_compile_options SOURCE_FILE)
if("${ARGC}" LESS_EQUAL "1")
return()
endif()
get_source_file_property(COMPILE_OPTIONS "${SOURCE_FILE}" COMPILE_OPTIONS)
if(COMPILE_OPTIONS)
list(APPEND COMPILE_OPTIONS ${ARGN})
else()
set(COMPILE_OPTIONS "${ARGN}")
endif()
set_source_files_properties("${SOURCE_FILE}" PROPERTIES COMPILE_OPTIONS "${COMPILE_OPTIONS}")
endfunction()
################################################################################
# Default properties of visual studio projects
################################################################################
set(DEFAULT_CXX_PROPS "${CMAKE_CURRENT_LIST_DIR}/DefaultCXX.cmake")
set(DEFAULT_Fortran_PROPS "${CMAKE_CURRENT_LIST_DIR}/DefaultFortran.cmake")
+10 -44
View File
@@ -3,61 +3,27 @@ project(OTRGui)
set(PLATFORM "Desktop")
set(CMAKE_CXX_STANDARD 20)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(APP_ICON_RESOURCE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/appicon.rc)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(OpenGL_GL_PREFERENCE "GLVND")
endif()
include(CMake/Utils.cmake)
add_subdirectory(libs/raylib EXCLUDE_FROM_ALL)
add_subdirectory(libs/raylib)
include_directories(src)
include_directories(src/game)
include_directories(include)
if (NOT TARGET libultraship)
add_subdirectory(../libultraship/libultraship ${CMAKE_BINARY_DIR}/libultraship)
endif()
if (NOT TARGET ZAPD)
add_subdirectory(../ZAPDTR/ZAPD ${CMAKE_BINARY_DIR}/ZAPD)
endif()
if (NOT TARGET ZAPDUtils)
add_subdirectory(../ZAPDTR/ZAPDUtils ${CMAKE_BINARY_DIR}/ZAPDUtils)
endif()
if (NOT TARGET OTRExporter)
add_subdirectory(../OTRExporter/OTRExporter ${CMAKE_BINARY_DIR}/OTRExporter)
endif()
if (NOT TARGET storm)
add_subdirectory(../StormLib ${CMAKE_BINARY_DIR}/StormLib)
endif()
include_external_msproject(ZAPD ../../ZAPDTR/ZAPD/ZAPD.vcproj)
include_external_msproject(ZAPDUtils ../../ZAPDTR/ZAPDUtils/ZAPDUtils.vcproj)
include_external_msproject(libultraship ../../libultraship/libultraship/libultraship.vcproj)
include_external_msproject(OTRExporter ../../OTRExporter/OTRExporter/OTRExporter.vcproj)
file(GLOB_RECURSE HEADERS src/*.h)
file(GLOB_RECURSE SOURCES src/*.cpp)
file(GLOB_RECURSE C_SOURCES src/*.c)
add_executable(${PROJECT_NAME} EXCLUDE_FROM_ALL ${SOURCES} ${C_SOURCES} ${HEADERS} ${APP_ICON_RESOURCE_WINDOWS})
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
endif()
add_custom_target(Assets ALL
COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_CURRENT_SOURCE_DIR}/assets" -Ddst_dir="${CMAKE_CURRENT_BINARY_DIR}/assets" -P "${CMAKE_CURRENT_SOURCE_DIR}/Overwrite.cmake"
COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_CURRENT_SOURCE_DIR}/../OTRExporter/assets" -Ddst_dir="${CMAKE_CURRENT_BINARY_DIR}/assets/game" -P "${CMAKE_CURRENT_SOURCE_DIR}/Overwrite.cmake"
COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_CURRENT_SOURCE_DIR}/../soh/assets/xml" -Ddst_dir="${CMAKE_CURRENT_BINARY_DIR}/assets/extractor/xmls" -P "${CMAKE_CURRENT_SOURCE_DIR}/Overwrite.cmake"
)
add_dependencies(OTRGui Assets)
add_executable(${PROJECT_NAME} ${SOURCES} ${C_SOURCES} ${HEADERS} ${APP_ICON_RESOURCE_WINDOWS})
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_SOURCE_DIR}/assets" -Ddst_dir="${CMAKE_CURRENT_BINARY_DIR}/assets" -P "${CMAKE_CURRENT_SOURCE_DIR}/Overwrite.cmake")
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_SOURCE_DIR}/../OTRExporter/assets" -Ddst_dir="${CMAKE_CURRENT_BINARY_DIR}/assets/game" -P "${CMAKE_CURRENT_SOURCE_DIR}/Overwrite.cmake")
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -Dsrc_dir="${CMAKE_SOURCE_DIR}/../soh/assets/xml" -Ddst_dir="${CMAKE_CURRENT_BINARY_DIR}/assets/extractor/xmls" -P "${CMAKE_CURRENT_SOURCE_DIR}/Overwrite.cmake")
target_link_libraries(${PROJECT_NAME} PUBLIC raylib)
INSTALL(TARGETS OTRGui DESTINATION . COMPONENT ship)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets
DESTINATION .
COMPONENT ship
)
INSTALL(TARGETS ZAPD DESTINATION assets/extractor COMPONENT ship)
+4 -9
View File
@@ -1,15 +1,10 @@
include(CMakePrintHelpers)
string(REPLACE "\\ " " " sources_dir "${src_dir}")
string(REPLACE "\\ " " " destination_dir "${dst_dir}")
file(GLOB_RECURSE _file_list RELATIVE "${sources_dir}" "${sources_dir}/*")
file(GLOB_RECURSE _file_list RELATIVE "${src_dir}" "${src_dir}/*")
foreach( each_file ${_file_list} )
set(destinationfile "${destination_dir}/${each_file}")
set(sourcefile "${sources_dir}/${each_file}")
set(destinationfile "${dst_dir}/${each_file}")
set(sourcefile "${src_dir}/${each_file}")
if(NOT EXISTS ${destinationfile} OR ${sourcefile} IS_NEWER_THAN ${destinationfile})
get_filename_component(destinationdir ${destinationfile} DIRECTORY)
file(COPY ${sourcefile} DESTINATION ${destinationdir})
endif()
endforeach(each_file)
endforeach(each_file)
+1
View File
@@ -91,6 +91,7 @@ void ExtractRom()
//MoonUtils::copy("tmp/baserom/Audioseq", "Extract/Audioseq");
//MoonUtils::copy("tmp/baserom/Audiotable", "Extract/Audiotable");
//MoonUtils::copy("tmp/baserom/version", "Extract/version");
MoonUtils::write("Extract/version", (char*)&version.crc, sizeof(version.crc));
MoonUtils::copy("assets/game/", "Extract/assets/");
+3 -3
View File
@@ -29,7 +29,7 @@ std::string GetXMLVersion(RomVersion version)
switch (version.crc)
{
case OOT_PAL_GC_DBG1: return "GC_NMQ_D";
case OOT_PAL_GC_MQ_DBG: return "GC_MQ_D";
case OOT_PAL_GC_DBG2: return "GC_MQ_D";
case OOT_PAL_GC: return "GC_NMQ_PAL_F";
}
@@ -81,7 +81,7 @@ void startWorker(RomVersion version) {
path += GetXMLVersion(version);
// Util::write("tmp/baserom/version", (char*)&version.crc, sizeof(version.crc));
Util::write("tmp/baserom/version", (char*)&version.crc, sizeof(version.crc));
if (oldExtractMode)
{
@@ -144,4 +144,4 @@ void updateWorker(const std::string& output) {
std::thread otr(BuildOTR, output);
otr.detach();
}
}
}
+6 -45
View File
@@ -12,7 +12,7 @@ The Ship does not include assets and as such requires a prior copy of the game t
4) Launch `soh.exe`
### Supported Games
#### Ocarina of Time Debug PAL GC (not Master Quest)
#### Ocarina of Time Debug (not Master Quest)
> Currently the recommended option
```
Build team: `zelda@srd022j`
@@ -24,13 +24,6 @@ sha1: cee6bc3c2a634b41728f2af8da54d9bf8cc14099
```
sha1: 0227d7c0074f2d0ac935631990da8ec5914597b4
```
#### Ocarina of Time Debug PAL GC MQ (Dungeons will be Master Quest)
```
Build team: `zelda@srd022j`
Build date: `03-02-21 00:16:31` (year-month-day)
sha1: 079b855b943d6ad8bd1eb026c0ed169ecbdac7da (Produced by decomp)
sha1: 50bebedad9e0f10746a52b07239e47fa6c284d03 (Alternate)
```
Congratulations, you are now sailing with the Ship of Harkinian! Have fun!
@@ -38,10 +31,10 @@ Congratulations, you are now sailing with the Ship of Harkinian! Have fun!
The Ship of Harkinian uses a proprietary versioning system consisting of a sci-fi film character followed by a phonetic alphabet code word. The film character represents a major release version which increments with the addition of many new features and bug fixes. The code word represents a minor release version which increments with small updates mainly comprised of bug fixes. For example, `DECKARD ALFA`.
### Windows Rom Extraction
### The Extraction Tool
* Open OTRGui.exe, and select one of the supported roms listed above, to generate the `oot.otr` archive file.
* If a second button already exits then `oot.otr` already exists. To prevent overwriting the old `oot.otr` use this button to choose a new game directory. The new directory must not already contain an `oot.otr` to prevent an error.
* Open a rom to initiate generating the `oot.otr` archive file.
* If a second button exists then `oot.otr` already exists. To prevent overwriting the old `oot.otr` use this button to choose a new game directory. The new directory must not already contain an `oot.otr` to prevent an error.
* When the process completes, place `oot.otr` beside `soh.exe` if it is not already.
This packaging process can take up to **5 minutes**.
@@ -49,37 +42,6 @@ This packaging process can take up to **5 minutes**.
Close the OTRGui when the `Done!` message appears.
If you get another message, then you might have selected the wrong rom. Make sure to use a rom consistent with the above checksum.
### Linux Rom Extraction
* Place one of the supported roms in the same folder as the appimage.
* When you run the soh appimage, it should begin generating the `oot.otr` archive file.
* When the process completes, place `oot.otr` in the same folder as the appimage, if it is not already, then run the appimage.
The packaging process can take up to **5 minutes**.
If you get any errors, then you might have selected the wrong rom. Make sure to use a rom consistent with the above checksum.
### MacOS Rom Extraction
* Run `soh.app`, and when prompted, select one of the supported roms listed above.
* You should see a notification saying `Processing OTR`, then, once the process is complete, you should get a notification saying `OTR Successfully Generated`, then the game should start.
The packing process can take up to **5 minutes**.
If you get an error saying `Incompatible ROM hash`, you have selected the wrong rom, make sure the checksum matches one of the ones listed above.
### Nintendo Switch Rom Extraction
* Download the latest PC release of the Ship of Harkinian, and follow the instructions above for generating the `oot.otr` archive on that platform.
* Place the `.nro` and the `oot.otr` archive into a folder called `soh` in your Switch folder on your Switch
### Nintendo Wii U Rom Extraction
* Download the latest PC release of the Ship of Harkinian, and follow the instructions above for generating the `oot.otr` archive on that platform.
* Copy the `.rpx` and the `oot.otr` archive to `wiiu/apps/soh`
---
If you still cannot get the tool to work, join our [Discord Server](https://discord.com/invite/BtBmd55HVH) and ask for help in the `#support` text channel. Keep-in-mind that we do not condone piracy in any way.
### Running The Ship of Harkinian
@@ -121,7 +83,7 @@ Refer to the [building instructions](BUILDING.md) to compile SoH.
- Confirm that `zapd.exe` exists in the `/assets/extractor` folder
## Nightly Builds
Nightly builds of Ship of Harkinian are available [here](https://builds.shipofharkinian.com/)
Nightly builds of Ship of Harkinian are available [here](https://builds.shipofharkinian.com/job/SoH_Multibranch/job/develop)
## The Harbour Masters Are...
@@ -161,8 +123,7 @@ Nightly builds of Ship of Harkinian are available [here](https://builds.shipofha
## Video Credits
Kenix | Producer / Writer
briaguya | Writer
rainbow_fash | Executive Producer
rainbow_fash | Executive Producer
ReveriePass | Editor
MicTheMicrophone | Gwonam / The King
Amphibibro | Link
-1
View File
@@ -140,7 +140,6 @@ Desktop.ini
*.egg-info
dist
build
nxbuild
eggs
parts
bin
+2 -86
View File
@@ -1,9 +1,8 @@
set(PROJECT_NAME StormLib)
#project(StormLib)
project(StormLib)
cmake_minimum_required(VERSION 3.10)
set(LIBRARY_NAME storm)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -16,13 +15,6 @@ option(STORM_BUILD_TESTS
# "BUILD_TESTING" OFF # Stay coherent with CTest variables
)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(Source_Files__Windows
src/lzma/C/LzFindMt.c
src/lzma/C/Threads.c
)
endif()
set(SRC_FILES
src/adpcm/adpcm.cpp
src/huffman/huff.cpp
@@ -54,7 +46,6 @@ set(SRC_FILES
src/SFileVerify.cpp
src/libtomcrypt/src/pk/rsa/rsa_verify_simple.c
src/libtomcrypt/src/misc/crypt_libc.c
${Source_Files__Windows}
)
if(MSVC)
@@ -332,86 +323,11 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DO_LARGEFILE=0 -Dstat64=stat -Dlstat64=lstat -Dlseek64=lseek -Doff64_t=off_t -Dfstat64=fstat -Dftruncate64=ftruncate")
endif()
if(NOT WIN32 AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
# Enable POSIX extensions such as `readlink` and `ftruncate`.
add_definitions(-D_POSIX_C_SOURCE=200809L)
endif()
add_library(${LIBRARY_NAME} ${LIB_TYPE} ${SRC_FILES} ${SRC_ADDITIONAL_FILES} ${STORM_DEF_FILES})
if(WIN32)
set_target_properties(${LIBRARY_NAME} PROPERTIES OUTPUT_NAME "StormLib")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
use_props(${LIBRARY_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
endif()
################################################################################
# Compile definitions
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_definitions(${LIBRARY_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG;"
"_CRT_SECURE_NO_WARNINGS;"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
WIN32
_LIB
"UNICODE;"
"_UNICODE"
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
target_compile_definitions(${LIBRARY_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG;"
"_CRT_SECURE_NO_WARNINGS;"
">"
"$<$<CONFIG:Release>:"
"NDEBUG;"
">"
"WIN32;"
_LIB
"UNICODE;"
"_UNICODE"
)
endif()
endif()
################################################################################
# MSVC runtime library
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${LIBRARY_NAME} PROPERTY MSVC_RUNTIME_LIBRARY)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
$<$<CONFIG:Debug>:
MultiThreadedDebug
>
$<$<CONFIG:Release>:
MultiThreaded
>
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
$<$<CONFIG:Debug>:
MultiThreadedDebug
>
$<$<CONFIG:Release>:
MultiThreaded
>
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
)
endif()
set_target_properties(${LIBRARY_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
endif()
target_link_libraries(${LIBRARY_NAME} ${LINK_LIBS})
target_compile_definitions(${LIBRARY_NAME} INTERFACE STORMLIB_NO_AUTO_LINK) #CMake will take care of the linking
target_include_directories(${LIBRARY_NAME} PUBLIC src/)
-5
View File
@@ -34,12 +34,7 @@
// Local functions - platform-specific functions
#ifndef STORMLIB_WINDOWS
#ifndef STORMLIB_WIIU // WIIU doesn't support thread_local
static thread_local DWORD dwLastError = ERROR_SUCCESS;
#else
static DWORD dwLastError = ERROR_SUCCESS;
#endif
DWORD GetLastError()
{
+4 -4
View File
@@ -2005,7 +2005,7 @@ void ConvertTMPQHeader(void *header, uint16_t version)
TMPQHeader * theHeader = (TMPQHeader *)header;
// Swap header part version 1
if(version >= MPQ_FORMAT_VERSION_1)
if(version == MPQ_FORMAT_VERSION_1)
{
theHeader->dwID = SwapUInt32(theHeader->dwID);
theHeader->dwHeaderSize = SwapUInt32(theHeader->dwHeaderSize);
@@ -2018,21 +2018,21 @@ void ConvertTMPQHeader(void *header, uint16_t version)
theHeader->dwBlockTableSize = SwapUInt32(theHeader->dwBlockTableSize);
}
if(version >= MPQ_FORMAT_VERSION_2)
if(version == MPQ_FORMAT_VERSION_2)
{
theHeader->HiBlockTablePos64 = SwapUInt64(theHeader->HiBlockTablePos64);
theHeader->wHashTablePosHi = SwapUInt16(theHeader->wHashTablePosHi);
theHeader->wBlockTablePosHi = SwapUInt16(theHeader->wBlockTablePosHi);
}
if(version >= MPQ_FORMAT_VERSION_3)
if(version == MPQ_FORMAT_VERSION_3)
{
theHeader->ArchiveSize64 = SwapUInt64(theHeader->ArchiveSize64);
theHeader->BetTablePos64 = SwapUInt64(theHeader->BetTablePos64);
theHeader->HetTablePos64 = SwapUInt64(theHeader->HetTablePos64);
}
if(version >= MPQ_FORMAT_VERSION_4)
if(version == MPQ_FORMAT_VERSION_4)
{
theHeader->HashTableSize64 = SwapUInt64(theHeader->HashTableSize64);
theHeader->BlockTableSize64 = SwapUInt64(theHeader->BlockTableSize64);
+2 -2
View File
@@ -180,7 +180,7 @@ static DWORD LoadAttributesFile(TMPQArchive * ha, LPBYTE pbAttrFile, DWORD cbAtt
if((pbAttrPtr + cbArraySize) > pbAttrFileEnd)
return ERROR_FILE_CORRUPT;
BSWAP_ARRAY32_UNSIGNED(ArrayCRC32, cbArraySize);
BSWAP_ARRAY32_UNSIGNED(ArrayCRC32, cbCRC32Size);
for(i = 0; i < dwAttributesEntries; i++)
ha->pFileTable[i].dwCrc32 = ArrayCRC32[i];
pbAttrPtr += cbArraySize;
@@ -196,7 +196,7 @@ static DWORD LoadAttributesFile(TMPQArchive * ha, LPBYTE pbAttrFile, DWORD cbAtt
if((pbAttrPtr + cbArraySize) > pbAttrFileEnd)
return ERROR_FILE_CORRUPT;
BSWAP_ARRAY64_UNSIGNED(ArrayFileTime, cbArraySize);
BSWAP_ARRAY64_UNSIGNED(ArrayFileTime, cbFileTimeSize);
for(i = 0; i < dwAttributesEntries; i++)
ha->pFileTable[i].FileTime = ArrayFileTime[i];
pbAttrPtr += cbArraySize;
+1 -1
View File
@@ -480,7 +480,7 @@ static bool IsMatchingPatchFile(
{
// Load the patch header
SFileReadFile(hFile, &PatchHeader, sizeof(MPQ_PATCH_HEADER), &dwTransferred, NULL);
BSWAP_ARRAY32_UNSIGNED(&PatchHeader, sizeof(DWORD) * 6);
BSWAP_ARRAY32_UNSIGNED(pPatchHeader, sizeof(DWORD) * 6);
// If the file contains an incremental patch,
// compare the "MD5 before patching" with the base file MD5
+1 -1
View File
@@ -631,8 +631,8 @@ typedef struct _TMPQHash
#else
BYTE Reserved;
BYTE Platform;
BYTE Reserved;
USHORT lcLocale;
#endif
+1 -29
View File
@@ -95,7 +95,7 @@
#define PKEXPORT
#ifndef __SYS_ZLIB
#ifndef __SYS_ZLIB
#define __SYS_ZLIB
#endif
@@ -254,34 +254,6 @@
#endif
//-----------------------------------------------------------------------------
// Defines for Wii U platform
#if !defined(STORMLIB_PLATFORM_DEFINED) && defined(__WIIU__)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#include <malloc.h>
#undef STORMLIB_LITTLE_ENDIAN // Wii U is always big endian
#define STORMLIB_MAC // Use Mac compatible code
#define STORMLIB_WIIU
#define STORMLIB_PLATFORM_DEFINED
#endif
//-----------------------------------------------------------------------------
// Assumption: If the platform is not defined, assume a Linux-like platform
+140
View File
@@ -0,0 +1,140 @@
# use variables in submakes
export
OPTIMIZATION_ON ?= 1
ASAN ?= 0
DEPRECATION_ON ?= 1
DEBUG ?= 0
COPYCHECK_ARGS ?=
LLD ?= 0
WERROR ?= 0
UNAME := $(shell uname)
# Use clang++ if available, else use g++
ifeq ($(shell command -v clang++ >/dev/null 2>&1; echo $$?),0)
CXX ?= clang++
else
CXX ?= g++
endif
INC := -I ZAPD -I lib/elfio -I lib/libgfxd -I lib/tinyxml2 -I ZAPDUtils
CXXFLAGS := -fpic -std=c++17 -Wall -Wextra -fno-omit-frame-pointer
OPTFLAGS :=
ifneq ($(DEBUG),0)
OPTIMIZATION_ON = 0
CXXFLAGS += -g3 -DDEVELOPMENT -D_DEBUG
COPYCHECK_ARGS += --devel
DEPRECATION_ON = 0
endif
ifneq ($(WERROR),0)
CXXFLAGS += -Werror
endif
ifeq ($(OPTIMIZATION_ON),0)
OPTFLAGS := -O0
else
OPTFLAGS := -O2
endif
ifneq ($(ASAN),0)
CXXFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined
endif
ifneq ($(DEPRECATION_ON),0)
CXXFLAGS += -DDEPRECATION_ON
endif
# CXXFLAGS += -DTEXTURE_DEBUG
LDFLAGS := -Llib/libgfxd -L../libultraship -L../StormLib/build \
-pthread -lgfxd -lultraship ZAPDUtils/ZAPDUtils.a -lstorm -lbz2 -lm -ldl
ifeq ($(UNAME), Darwin)
LDFLAGS += $(shell pkg-config --libs glew libpng zlib) $(shell sdl2-config --libs) -framework OpenGL -framework Foundation
INC += $(shell pkg-config --cflags libpng)
else
LDFLAGS += -lpng -lGL -lGLEW -lX11 -lz -lSDL2 -lpulse
endif
# Use LLD if available. Set LLD=0 to not use it
ifeq ($(shell command -v ld.lld >/dev/null 2>&1; echo $$?),0)
LLD := 1
endif
ifneq ($(LLD),0)
LDFLAGS += -fuse-ld=lld
endif
UNAMEM := $(shell uname -m)
ifneq ($(UNAME), Darwin)
LDFLAGS += -Wl,-export-dynamic -lstdc++fs
EXPORTERS := -Wl,--whole-archive ../OTRExporter/OTRExporter/OTRExporter.a -Wl,--no-whole-archive
else
EXPORTERS := -Wl,-force_load ../OTRExporter/OTRExporter/OTRExporter.a
endif
ZAPD_SRC_DIRS := $(shell find ZAPD -type d)
SRC_DIRS = $(ZAPD_SRC_DIRS) lib/tinyxml2
ZAPD_CPP_FILES := $(foreach dir,$(ZAPD_SRC_DIRS),$(wildcard $(dir)/*.cpp))
ZAPD_H_FILES := $(foreach dir,$(ZAPD_SRC_DIRS),$(wildcard $(dir)/*.h))
CPP_FILES += $(ZAPD_CPP_FILES) lib/tinyxml2/tinyxml2.cpp
O_FILES := $(foreach f,$(CPP_FILES:.cpp=.o),build/$f)
O_FILES += build/ZAPD/BuildInfo.o
# create build directories
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))
# Main targets
all: ZAPD.out copycheck
build/ZAPD/BuildInfo.o:
python3 ZAPD/genbuildinfo.py $(COPYCHECK_ARGS)
$(CXX) $(CXXFLAGS) $(OPTFLAGS) $(INC) -c $(OUTPUT_OPTION) build/ZAPD/BuildInfo.cpp
copycheck: ZAPD.out
python3 copycheck.py
clean:
rm -rf build ZAPD.out
$(MAKE) -C lib/libgfxd clean
$(MAKE) -C ZAPDUtils clean
$(MAKE) -C ExporterTest clean
rm -rf ../StormLib/build
rebuild: clean all
format:
clang-format-11 -i $(ZAPD_CPP_FILES) $(ZAPD_H_FILES)
$(MAKE) -C ZAPDUtils format
$(MAKE) -C ExporterTest format
.PHONY: all build/ZAPD/BuildInfo.o copycheck clean rebuild format
build/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(OPTFLAGS) $(INC) -c $(OUTPUT_OPTION) $<
# Submakes
lib/libgfxd/libgfxd.a:
$(MAKE) -C lib/libgfxd
.PHONY: StormLib
StormLib:
LDFLAGS="" cmake -B ../StormLib/build -S ../StormLib
$(MAKE) -C ../StormLib/build
.PHONY: ExporterTest
ExporterTest:
$(MAKE) -C ExporterTest
.PHONY: ZAPDUtils
ZAPDUtils:
$(MAKE) -C ZAPDUtils
# Linking
ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a ExporterTest ZAPDUtils StormLib
$(CXX) $(CXXFLAGS) $(O_FILES) $(EXPORTERS) $(LDFLAGS) $(OUTPUT_OPTION)
-492
View File
@@ -1,492 +0,0 @@
set(PROJECT_NAME ZAPD)
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
#set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard to use")
set(CMAKE_C_STANDARD 11)
################################################################################
# Source groups
################################################################################
set(Header_Files
"../lib/tinyxml2/tinyxml2.h"
"CRC32.h"
"Declaration.h"
"FileWorker.h"
"GameConfig.h"
"Globals.h"
"ImageBackend.h"
"OutputFormatter.h"
"WarningHandler.h"
)
source_group("Header Files" FILES ${Header_Files})
set(Header_Files__Libraries
"../../libultraship/libultraship/Lib/stb/stb_image.h"
"../../libultraship/libultraship/Lib/stb/stb_image_write.h"
"ctpl_stl.h"
)
source_group("Header Files\\Libraries" FILES ${Header_Files__Libraries})
set(Header_Files__Libraries__elfio
"../lib/elfio/elfio/elf_types.hpp"
"../lib/elfio/elfio/elfio.hpp"
"../lib/elfio/elfio/elfio_dump.hpp"
"../lib/elfio/elfio/elfio_dynamic.hpp"
"../lib/elfio/elfio/elfio_header.hpp"
"../lib/elfio/elfio/elfio_note.hpp"
"../lib/elfio/elfio/elfio_relocation.hpp"
"../lib/elfio/elfio/elfio_section.hpp"
"../lib/elfio/elfio/elfio_segment.hpp"
"../lib/elfio/elfio/elfio_strings.hpp"
"../lib/elfio/elfio/elfio_symbols.hpp"
"../lib/elfio/elfio/elfio_utils.hpp"
)
source_group("Header Files\\Libraries\\elfio" FILES ${Header_Files__Libraries__elfio})
set(Header_Files__Libraries__libgfxd
"../lib/libgfxd/gbi.h"
"../lib/libgfxd/gfxd.h"
"../lib/libgfxd/priv.h"
)
source_group("Header Files\\Libraries\\libgfxd" FILES ${Header_Files__Libraries__libgfxd})
set(Header_Files__Yaz0
"yaz0/readwrite.h"
"yaz0/yaz0.h"
)
source_group("Header Files\\Yaz0" FILES ${Header_Files__Yaz0})
set(Header_Files__Z64
"OtherStructs/SkinLimbStructs.h"
"Overlays/ZOverlay.h"
"ZAnimation.h"
"ZArray.h"
"ZAudio.h"
"ZBackground.h"
"ZBlob.h"
"ZCollision.h"
"ZCutscene.h"
"ZCutsceneMM.h"
"ZDisplayList.h"
"ZFile.h"
"ZLimb.h"
"ZMtx.h"
"ZPath.h"
"ZPlayerAnimationData.h"
"ZResource.h"
"ZRom.h"
"ZScalar.h"
"ZSkeleton.h"
"ZString.h"
"ZSymbol.h"
"ZText.h"
"ZTexture.h"
"ZTextureAnimation.h"
"ZVector.h"
"ZVtx.h"
)
source_group("Header Files\\Z64" FILES ${Header_Files__Z64})
set(Header_Files__Z64__ZRoom
"ZRoom/ZRoom.h"
"ZRoom/ZRoomCommand.h"
)
source_group("Header Files\\Z64\\ZRoom" FILES ${Header_Files__Z64__ZRoom})
set(Header_Files__Z64__ZRoom__Commands
"ZRoom/Commands/EndMarker.h"
"ZRoom/Commands/SetActorCutsceneList.h"
"ZRoom/Commands/SetActorList.h"
"ZRoom/Commands/SetAlternateHeaders.h"
"ZRoom/Commands/SetAnimatedMaterialList.h"
"ZRoom/Commands/SetCameraSettings.h"
"ZRoom/Commands/SetCollisionHeader.h"
"ZRoom/Commands/SetCsCamera.h"
"ZRoom/Commands/SetCutscenes.h"
"ZRoom/Commands/SetEchoSettings.h"
"ZRoom/Commands/SetEntranceList.h"
"ZRoom/Commands/SetExitList.h"
"ZRoom/Commands/SetLightingSettings.h"
"ZRoom/Commands/SetLightList.h"
"ZRoom/Commands/SetMesh.h"
"ZRoom/Commands/SetMinimapChests.h"
"ZRoom/Commands/SetMinimapList.h"
"ZRoom/Commands/SetObjectList.h"
"ZRoom/Commands/SetPathways.h"
"ZRoom/Commands/SetRoomBehavior.h"
"ZRoom/Commands/SetRoomList.h"
"ZRoom/Commands/SetSkyboxModifier.h"
"ZRoom/Commands/SetSkyboxSettings.h"
"ZRoom/Commands/SetSoundSettings.h"
"ZRoom/Commands/SetSpecialObjects.h"
"ZRoom/Commands/SetStartPositionList.h"
"ZRoom/Commands/SetTimeSettings.h"
"ZRoom/Commands/SetTransitionActorList.h"
"ZRoom/Commands/SetWind.h"
"ZRoom/Commands/SetWorldMapVisited.h"
"ZRoom/Commands/Unused09.h"
"ZRoom/Commands/Unused1D.h"
"ZRoom/Commands/ZRoomCommandUnk.h"
)
source_group("Header Files\\Z64\\ZRoom\\Commands" FILES ${Header_Files__Z64__ZRoom__Commands})
set(Resource_Files
"../../OTRExporter/CFG/SymbolMap_OoTMqDbg.txt"
)
source_group("Resource Files" FILES ${Resource_Files})
set(Source_Files
"Declaration.cpp"
"FileWorker.cpp"
"GameConfig.cpp"
"Globals.cpp"
"ImageBackend.cpp"
"Main.cpp"
"OutputFormatter.cpp"
"WarningHandler.cpp"
)
source_group("Source Files" FILES ${Source_Files})
set(Source_Files__Libraries__libgfxd
"../lib/libgfxd/gfxd.c"
"../lib/libgfxd/uc.c"
"../lib/libgfxd/uc_f3d.c"
"../lib/libgfxd/uc_f3db.c"
"../lib/libgfxd/uc_f3dex.c"
"../lib/libgfxd/uc_f3dex2.c"
"../lib/libgfxd/uc_f3dexb.c"
)
source_group("Source Files\\Libraries\\libgfxd" FILES ${Source_Files__Libraries__libgfxd})
set(Source_Files__Yaz0
"yaz0/yaz0.cpp"
)
source_group("Source Files\\Yaz0" FILES ${Source_Files__Yaz0})
set(Source_Files__Z64
"OtherStructs/SkinLimbStructs.cpp"
"Overlays/ZOverlay.cpp"
"ZAnimation.cpp"
"ZArray.cpp"
"ZAudio.cpp"
"ZAudioDecode.cpp"
"ZBackground.cpp"
"ZBlob.cpp"
"ZCollision.cpp"
"ZCutscene.cpp"
"ZCutsceneMM.cpp"
"ZDisplayList.cpp"
"ZFile.cpp"
"ZLimb.cpp"
"ZMtx.cpp"
"ZPath.cpp"
"ZPlayerAnimationData.cpp"
"ZResource.cpp"
"ZRom.cpp"
"ZScalar.cpp"
"ZSkeleton.cpp"
"ZString.cpp"
"ZSymbol.cpp"
"ZText.cpp"
"ZTexture.cpp"
"ZTextureAnimation.cpp"
"ZVector.cpp"
"ZVtx.cpp"
)
source_group("Source Files\\Z64" FILES ${Source_Files__Z64})
set(Source_Files__Z64__ZRoom
"ZRoom/ZRoom.cpp"
"ZRoom/ZRoomCommand.cpp"
)
source_group("Source Files\\Z64\\ZRoom" FILES ${Source_Files__Z64__ZRoom})
set(Source_Files__Z64__ZRoom__Commands
"ZRoom/Commands/EndMarker.cpp"
"ZRoom/Commands/SetActorCutsceneList.cpp"
"ZRoom/Commands/SetActorList.cpp"
"ZRoom/Commands/SetAlternateHeaders.cpp"
"ZRoom/Commands/SetAnimatedMaterialList.cpp"
"ZRoom/Commands/SetCameraSettings.cpp"
"ZRoom/Commands/SetCollisionHeader.cpp"
"ZRoom/Commands/SetCsCamera.cpp"
"ZRoom/Commands/SetCutscenes.cpp"
"ZRoom/Commands/SetEchoSettings.cpp"
"ZRoom/Commands/SetEntranceList.cpp"
"ZRoom/Commands/SetExitList.cpp"
"ZRoom/Commands/SetLightingSettings.cpp"
"ZRoom/Commands/SetLightList.cpp"
"ZRoom/Commands/SetMesh.cpp"
"ZRoom/Commands/SetMinimapChests.cpp"
"ZRoom/Commands/SetMinimapList.cpp"
"ZRoom/Commands/SetObjectList.cpp"
"ZRoom/Commands/SetPathways.cpp"
"ZRoom/Commands/SetRoomBehavior.cpp"
"ZRoom/Commands/SetRoomList.cpp"
"ZRoom/Commands/SetSkyboxModifier.cpp"
"ZRoom/Commands/SetSkyboxSettings.cpp"
"ZRoom/Commands/SetSoundSettings.cpp"
"ZRoom/Commands/SetSpecialObjects.cpp"
"ZRoom/Commands/SetStartPositionList.cpp"
"ZRoom/Commands/SetTimeSettings.cpp"
"ZRoom/Commands/SetTransitionActorList.cpp"
"ZRoom/Commands/SetWind.cpp"
"ZRoom/Commands/SetWorldMapVisited.cpp"
"ZRoom/Commands/Unused09.cpp"
"ZRoom/Commands/Unused1D.cpp"
"ZRoom/Commands/ZRoomCommandUnk.cpp"
)
source_group("Source Files\\Z64\\ZRoom\\Commands" FILES ${Source_Files__Z64__ZRoom__Commands})
set(ALL_FILES
${Header_Files}
${Header_Files__Libraries}
${Header_Files__Libraries__elfio}
${Header_Files__Libraries__libgfxd}
${Header_Files__Yaz0}
${Header_Files__Z64}
${Header_Files__Z64__ZRoom}
${Header_Files__Z64__ZRoom__Commands}
${Resource_Files}
${Source_Files}
${Source_Files__Libraries__libgfxd}
${Source_Files__Yaz0}
${Source_Files__Z64}
${Source_Files__Z64__ZRoom}
${Source_Files__Z64__ZRoom__Commands}
${any__any}
)
################################################################################
# Target
################################################################################
add_executable(${PROJECT_NAME} ${ALL_FILES})
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
endif()
################################################################################
# Includes for CMake from *.props
################################################################################
set(ROOT_NAMESPACE ZAPD)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86")
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
endif()
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME "ZAPD.out"
)
endif()
################################################################################
# MSVC runtime library
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
$<$<CONFIG:Debug>:
MultiThreadedDebug
>
$<$<CONFIG:Release>:
MultiThreaded
>
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
endif()
################################################################################
# Compile definitions
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"_CRT_SECURE_NO_WARNINGS;"
"_MBCS"
STORMLIB_NO_AUTO_LINK
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_CRT_SECURE_NO_WARNINGS"
">"
"_MBCS"
STORMLIB_NO_AUTO_LINK
)
endif()
endif()
################################################################################
# Compile and link options
################################################################################
find_package(PNG REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/ZAPDUtils
${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/lib/tinyxml2
${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/lib/libgfxd
${PNG_PNG_INCLUDE_DIR}/
.
)
if(MSVC)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/Od;
/RTC1
>
$<$<CONFIG:Release>:
/Oi;
/Gy
>
/permissive-;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/Od
>
$<$<CONFIG:Release>:
/O2;
/Oi;
/Gy
>
/permissive-;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
endif()
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/PROFILE
>
$<$<CONFIG:Release>:
/OPT:REF;
/OPT:ICF
>
/DEBUG:FULL
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86")
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/PROFILE
>
$<$<CONFIG:Release>:
/OPT:REF;
/OPT:ICF
>
/DEBUG:FULL
)
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall -Wextra -Wno-error
-Wno-unused-parameter
-Wno-unused-function
-Wno-unused-variable
-Wno-missing-field-initializers
-Wno-parentheses
-Wno-narrowing
$<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-enum-enum-conversion>
-pthread
)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_options(${PROJECT_NAME} PRIVATE
-pthread
)
else()
target_link_options(${PROJECT_NAME} PRIVATE
-pthread
-Wl,-export-dynamic
)
endif()
endif()
################################################################################
# Dependencies
################################################################################
add_dependencies(${PROJECT_NAME}
OTRExporter
ZAPDUtils
libultraship
)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(ADDITIONAL_LIBRARY_DEPENDENCIES
"ZAPDUtils;"
"-WHOLEARCHIVE:$<TARGET_LINKER_FILE_DIR:OTRExporter>/$<TARGET_LINKER_FILE_NAME:OTRExporter>"
"libultraship;"
storm
PNG::PNG
)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(ADDITIONAL_LIBRARY_DEPENDENCIES
"ZAPDUtils;"
-Wl,-force_load $<TARGET_LINKER_FILE_DIR:OTRExporter>/$<TARGET_LINKER_FILE_NAME:OTRExporter>
"libultraship;"
PNG::PNG
${CMAKE_DL_LIBS}
Threads::Threads
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(ADDITIONAL_LIBRARY_DEPENDENCIES
"ZAPDUtils;"
-Wl,--whole-archive $<TARGET_LINKER_FILE_DIR:OTRExporter>/$<TARGET_LINKER_FILE_NAME:OTRExporter> -Wl,--no-whole-archive
"libultraship;"
PNG::PNG
Threads::Threads
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
set(ADDITIONAL_LIBRARY_DEPENDENCIES
"ZAPDUtils;"
"libultraship;"
PNG::PNG
)
else()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(ADDITIONAL_LIBRARY_DEPENDENCIES
"ZAPDUtils;"
-Wl,--whole-archive $<TARGET_LINKER_FILE_DIR:OTRExporter>/$<TARGET_LINKER_FILE_NAME:OTRExporter> -Wl,--no-whole-archive
"libultraship;"
PNG::PNG
${CMAKE_DL_LIBS}
Threads::Threads
)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS")
add_library(pathconf OBJECT pathconf.c)
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}" $<TARGET_OBJECTS:pathconf> )
else()
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
endif()
+6
View File
@@ -359,6 +359,12 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\OTRGui\build\ZERO_CHECK.vcxproj">
<Project>{02d10590-9542-3f55-aaf8-6055677e2a2a}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\OTRExporter\packages\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.targets" Condition="Exists('..\..\OTRExporter\packages\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.targets')" />
+2 -5
View File
@@ -348,14 +348,11 @@ std::string ZResource::GetSourceOutputHeader([[maybe_unused]] const std::string&
str += StringHelper::Sprintf("#define d%s \"__OTR__%s/%s\"", name.c_str(), outName.c_str(), nameStr.c_str());
if (nameSet && nameSet->find(name) == nameSet->end()) {
str += StringHelper::Sprintf(R"(
#ifdef _WIN32
static const __declspec(align(2)) char %s[] = d%s;
str += StringHelper::Sprintf("\nstatic const __declspec(align(2)) char %s[] = d%s;", name.c_str(), name.c_str());
#else
static const char %s[] __attribute__((aligned (2))) = d%s;
str += StringHelper::Sprintf("\nstatic const char %s[] __attribute__((aligned (2))) = d%s;", name.c_str(), name.c_str());
#endif
)", name.c_str(), name.c_str(), name.c_str(), name.c_str());
if (nameSet) {
nameSet->insert(name);
}
-6
View File
@@ -1,6 +0,0 @@
#include <unistd.h>
long pathconf(const char *path, int name) {
return -1;
}
+82
View File
@@ -0,0 +1,82 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPD", "ZAPD\ZAPD.vcxproj", "{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExporterExample", "ExporterTest\ExporterTest.vcxproj", "{65608EB0-1A47-45AD-AB66-192FB64C762C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPDUtils", "ZAPDUtils\ZAPDUtils.vcxproj", "{A2E01C3E-D647-45D1-9788-043DEBC1A908}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
MinSizeRel|x64 = MinSizeRel|x64
MinSizeRel|x86 = MinSizeRel|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
RelWithDebInfo|x64 = RelWithDebInfo|x64
RelWithDebInfo|x86 = RelWithDebInfo|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.ActiveCfg = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.Build.0 = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.ActiveCfg = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.Build.0 = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.MinSizeRel|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.MinSizeRel|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.MinSizeRel|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.MinSizeRel|x86.Build.0 = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.Build.0 = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x86.Build.0 = Release|Win32
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Debug|x64.ActiveCfg = Debug|x64
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Debug|x64.Build.0 = Debug|x64
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Debug|x86.ActiveCfg = Debug|Win32
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Debug|x86.Build.0 = Debug|Win32
{65608EB0-1A47-45AD-AB66-192FB64C762C}.MinSizeRel|x64.ActiveCfg = Debug|x64
{65608EB0-1A47-45AD-AB66-192FB64C762C}.MinSizeRel|x64.Build.0 = Debug|x64
{65608EB0-1A47-45AD-AB66-192FB64C762C}.MinSizeRel|x86.ActiveCfg = Debug|Win32
{65608EB0-1A47-45AD-AB66-192FB64C762C}.MinSizeRel|x86.Build.0 = Debug|Win32
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Release|x64.ActiveCfg = Release|x64
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Release|x64.Build.0 = Release|x64
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Release|x86.ActiveCfg = Release|Win32
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Release|x86.Build.0 = Release|Win32
{65608EB0-1A47-45AD-AB66-192FB64C762C}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{65608EB0-1A47-45AD-AB66-192FB64C762C}.RelWithDebInfo|x64.Build.0 = Release|x64
{65608EB0-1A47-45AD-AB66-192FB64C762C}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{65608EB0-1A47-45AD-AB66-192FB64C762C}.RelWithDebInfo|x86.Build.0 = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.ActiveCfg = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.Build.0 = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.ActiveCfg = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.Build.0 = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.MinSizeRel|x64.ActiveCfg = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.MinSizeRel|x64.Build.0 = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.MinSizeRel|x86.ActiveCfg = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.MinSizeRel|x86.Build.0 = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.ActiveCfg = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.Build.0 = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.ActiveCfg = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.Build.0 = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.RelWithDebInfo|x64.Build.0 = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.RelWithDebInfo|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C2E1CC72-7A50-3249-AFD5-DFF6FE25CDCA}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
-218
View File
@@ -1,218 +0,0 @@
set(PROJECT_NAME ZAPDUtils)
################################################################################
# Source groups
################################################################################
set(Header_Files
"Color3b.h"
"StrHash.h"
"Vec2f.h"
"Vec3f.h"
"Vec3s.h"
)
source_group("Header Files" FILES ${Header_Files})
set(Header_Files__Utils
"Utils/BinaryReader.h"
"Utils/BinaryWriter.h"
"Utils/BitConverter.h"
"Utils/Directory.h"
"Utils/File.h"
"Utils/MemoryStream.h"
"Utils/Path.h"
"Utils/Stream.h"
"Utils/StringHelper.h"
)
source_group("Header Files\\Utils" FILES ${Header_Files__Utils})
set(Source_Files__Libraries
"../lib/tinyxml2/tinyxml2.cpp"
)
source_group("Source Files\\Libraries" FILES ${Source_Files__Libraries})
set(Source_Files__Utils
"Utils/BinaryReader.cpp"
"Utils/BinaryWriter.cpp"
"Utils/MemoryStream.cpp"
"Utils/StringHelper.cpp"
)
source_group("Source Files\\Utils" FILES ${Source_Files__Utils})
set(ALL_FILES
${Header_Files}
${Header_Files__Utils}
${Source_Files__Libraries}
${Source_Files__Utils}
)
################################################################################
# Target
################################################################################
add_library(${PROJECT_NAME} STATIC ${ALL_FILES})
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
endif()
set(ROOT_NAMESPACE ZAPDUtils)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_GLOBAL_KEYWORD "Win32Proj"
)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
endif()
endif()
################################################################################
# MSVC runtime library
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
$<$<CONFIG:Debug>:
MultiThreadedDebug
>
$<$<CONFIG:Release>:
MultiThreaded
>
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
MultiThreaded
)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
endif()
################################################################################
# Compile definitions
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG;"
"_MBCS"
">"
"$<$<CONFIG:Release>:"
"NDEBUG;"
"UNICODE;"
"_UNICODE"
">"
"_CONSOLE;"
"_CRT_SECURE_NO_WARNINGS"
STORMLIB_NO_AUTO_LINK
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"WIN32;"
"_CONSOLE;"
"_CRT_SECURE_NO_WARNINGS;"
"UNICODE;"
"_UNICODE"
STORMLIB_NO_AUTO_LINK
)
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"_CONSOLE;"
"_CRT_SECURE_NO_WARNINGS;"
"UNICODE;"
"_UNICODE"
)
endif()
################################################################################
# Compile and link options
################################################################################
if(MSVC)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/Oi;
/Gy
>
/permissive-;
/MP;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/O2;
/Ot
>
$<$<CONFIG:Release>:
/Gy
>
/permissive-;
/MP;
/Oi;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
endif()
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/OPT:REF;
/OPT:ICF
>
/SUBSYSTEM:CONSOLE
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/OPT:REF;
/OPT:ICF
>
/SUBSYSTEM:CONSOLE
)
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall -Wextra -Wno-error
-Wno-unused-parameter
-Wno-unused-function
-Wno-unused-variable
-Wno-missing-field-initializers
-Wno-parentheses
-Wno-narrowing
$<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-enum-enum-conversion>
)
endif()
################################################################################
# Dependencies
################################################################################
# Link with other targets.
+29
View File
@@ -0,0 +1,29 @@
# Only used for standalone compilation, usually inherits these from the main makefile
CXX ?= g++
CXXFLAGS ?= -Wall -Wextra -O2 -g -std=c++17
SRC_DIRS := $(shell find . -type d -not -path "*build*")
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
O_FILES := $(foreach f,$(CPP_FILES:.cpp=.o),build/$f)
LIB := ZAPDUtils.a
# create build directories
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))
all: $(LIB)
clean:
rm -rf build $(LIB)
format:
clang-format-11 -i $(CPP_FILES) $(H_FILES)
.PHONY: all clean format
build/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(OPTFLAGS) -c $(OUTPUT_OPTION) $<
$(LIB): $(O_FILES)
$(AR) rcs $@ $^
+1 -56
View File
@@ -18,16 +18,6 @@ void BinaryReader::Close()
stream->Close();
}
void BinaryReader::SetEndianness(Endianness endianness)
{
this->endianness = endianness;
}
Endianness BinaryReader::GetEndianness() const
{
return endianness;
}
void BinaryReader::Seek(uint32_t offset, SeekOffsetType seekType)
{
stream->Seek(offset, seekType);
@@ -38,16 +28,11 @@ uint32_t BinaryReader::GetBaseAddress()
return stream->GetBaseAddress();
}
void BinaryReader::Read(int32_t length)
void BinaryReader::Read([[maybe_unused]] char* buffer, int32_t length)
{
stream->Read(length);
}
void BinaryReader::Read(char* buffer, int32_t length)
{
stream->Read(buffer, length);
}
char BinaryReader::ReadChar()
{
return (char)stream->ReadByte();
@@ -68,10 +53,6 @@ int16_t BinaryReader::ReadInt16()
int16_t result = 0;
stream->Read((char*)&result, sizeof(int16_t));
if (endianness != Endianness::Native)
result = BSWAP16(result);
return result;
}
@@ -80,10 +61,6 @@ int32_t BinaryReader::ReadInt32()
int32_t result = 0;
stream->Read((char*)&result, sizeof(int32_t));
if (endianness != Endianness::Native)
result = BSWAP32(result);
return result;
}
@@ -92,10 +69,6 @@ uint16_t BinaryReader::ReadUInt16()
uint16_t result = 0;
stream->Read((char*)&result, sizeof(uint16_t));
if (endianness != Endianness::Native)
result = BSWAP16(result);
return result;
}
@@ -104,10 +77,6 @@ uint32_t BinaryReader::ReadUInt32()
uint32_t result = 0;
stream->Read((char*)&result, sizeof(uint32_t));
if (endianness != Endianness::Native)
result = BSWAP32(result);
return result;
}
@@ -116,10 +85,6 @@ uint64_t BinaryReader::ReadUInt64()
uint64_t result = 0;
stream->Read((char*)&result, sizeof(uint64_t));
if (endianness != Endianness::Native)
result = BSWAP64(result);
return result;
}
@@ -129,15 +94,6 @@ float BinaryReader::ReadSingle()
stream->Read((char*)&result, sizeof(float));
if (endianness != Endianness::Native)
{
float tmp;
char* dst = (char*)&tmp;
char* src = (char*)&result;
dst[3] = src[0]; dst[2] = src[1]; dst[1] = src[2]; dst[0] = src[3];
result = tmp;
}
if (std::isnan(result))
throw std::runtime_error("BinaryReader::ReadSingle(): Error reading stream");
@@ -149,17 +105,6 @@ double BinaryReader::ReadDouble()
double result = NAN;
stream->Read((char*)&result, sizeof(double));
if (endianness != Endianness::Native)
{
double tmp;
char* dst = (char*)&tmp;
char* src = (char*)&result;
dst[7] = src[0]; dst[6] = src[1]; dst[5] = src[2]; dst[4] = src[3];
dst[3] = src[4]; dst[2] = src[5]; dst[1] = src[6]; dst[0] = src[7];
result = tmp;
}
if (std::isnan(result))
throw std::runtime_error("BinaryReader::ReadDouble(): Error reading stream");
-6
View File
@@ -8,7 +8,6 @@
#include "../Vec2f.h"
#include "../Vec3f.h"
#include "../Vec3s.h"
#include "BitConverter.h"
#include "Stream.h"
class BinaryReader
@@ -19,13 +18,9 @@ public:
void Close();
void SetEndianness(Endianness endianness);
Endianness GetEndianness() const;
void Seek(uint32_t offset, SeekOffsetType seekType);
uint32_t GetBaseAddress();
void Read(int32_t length);
void Read(char* buffer, int32_t length);
char ReadChar();
int8_t ReadByte();
@@ -46,5 +41,4 @@ public:
protected:
std::shared_ptr<Stream> stream;
Endianness endianness = Endianness::Native;
};
+1 -43
View File
@@ -10,11 +10,6 @@ BinaryWriter::BinaryWriter(std::shared_ptr<Stream> nStream)
stream = nStream;
}
void BinaryWriter::SetEndianness(Endianness endianness)
{
this->endianness = endianness;
}
void BinaryWriter::Close()
{
stream->Close();
@@ -52,25 +47,16 @@ void BinaryWriter::Write(uint8_t value)
void BinaryWriter::Write(int16_t value)
{
if (endianness != Endianness::Native)
value = BSWAP16(value);
stream->Write((char*)&value, sizeof(int16_t));
}
void BinaryWriter::Write(uint16_t value)
{
if (endianness != Endianness::Native)
value = BSWAP16(value);
stream->Write((char*)&value, sizeof(uint16_t));
}
void BinaryWriter::Write(int32_t value)
{
if (endianness != Endianness::Native)
value = BSWAP32(value);
stream->Write((char*)&value, sizeof(int32_t));
}
@@ -82,61 +68,33 @@ void BinaryWriter::Write(int32_t valueA, int32_t valueB)
void BinaryWriter::Write(uint32_t value)
{
if (endianness != Endianness::Native)
value = BSWAP32(value);
stream->Write((char*)&value, sizeof(uint32_t));
}
void BinaryWriter::Write(int64_t value)
{
if (endianness != Endianness::Native)
value = BSWAP64(value);
stream->Write((char*)&value, sizeof(int64_t));
}
void BinaryWriter::Write(uint64_t value)
{
if (endianness != Endianness::Native)
value = BSWAP64(value);
stream->Write((char*)&value, sizeof(uint64_t));
}
void BinaryWriter::Write(float value)
{
if (endianness != Endianness::Native)
{
float tmp;
char* dst = (char*)&tmp;
char* src = (char*)&value;
dst[3] = src[0]; dst[2] = src[1]; dst[1] = src[2]; dst[0] = src[3];
value = tmp;
}
stream->Write((char*)&value, sizeof(float));
}
void BinaryWriter::Write(double value)
{
if (endianness != Endianness::Native)
{
double tmp;
char* dst = (char*)&tmp;
char* src = (char*)&value;
dst[7] = src[0]; dst[6] = src[1]; dst[5] = src[2]; dst[4] = src[3];
dst[3] = src[4]; dst[2] = src[5]; dst[1] = src[6]; dst[0] = src[7];
value = tmp;
}
stream->Write((char*)&value, sizeof(double));
}
void BinaryWriter::Write(const std::string& str)
{
int strLen = str.size();
Write(strLen);
stream->Write((char*)&strLen, sizeof(int));
for (char c : str)
stream->WriteByte(c);
-4
View File
@@ -4,7 +4,6 @@
#include <memory>
#include <string>
#include <vector>
#include "BitConverter.h"
#include "Stream.h"
class BinaryWriter
@@ -13,8 +12,6 @@ public:
BinaryWriter(Stream* nStream);
BinaryWriter(std::shared_ptr<Stream> nStream);
void SetEndianness(Endianness endianness);
std::shared_ptr<Stream> GetStream();
uint64_t GetBaseAddress();
uint64_t GetLength();
@@ -37,5 +34,4 @@ public:
protected:
std::shared_ptr<Stream> stream;
Endianness endianness = Endianness::Native;
};
-22
View File
@@ -5,28 +5,6 @@
#include <vector>
#include <cstring>
#ifdef _MSC_VER
#define BSWAP16 _byteswap_ushort
#define BSWAP32 _byteswap_ulong
#define BSWAP64 _byteswap_uint64
#else
#define BSWAP16 __builtin_bswap16
#define BSWAP32 __builtin_bswap32
#define BSWAP64 __builtin_bswap64
#endif
enum class Endianness
{
Little = 0,
Big = 1,
#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || defined(__BIG_ENDIAN__)
Native = Big,
#else
Native = Little,
#endif
};
class BitConverter
{
public:
+4 -3
View File
@@ -1,9 +1,8 @@
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include "StringHelper.h"
#include <iostream>
#if __has_include(<filesystem>)
#include <filesystem>
@@ -13,6 +12,8 @@ namespace fs = std::filesystem;
namespace fs = std::experimental::filesystem;
#endif
#include "StringHelper.h"
#undef GetCurrentDirectory
#undef CreateDirectory
@@ -20,7 +21,7 @@ class Directory
{
public:
#ifndef PATH_HACK
static std::string GetCurrentDirectory() { return fs::current_path().string(); }
static std::string GetCurrentDirectory() { return fs::current_path().u8string().c_str(); }
#endif
static bool Exists(const fs::path& path) { return fs::exists(path); }
+7
View File
@@ -10,6 +10,13 @@ enum class SeekOffsetType
End
};
// TODO: Eventually account for endianess in binaryreader and binarywriter
enum class Endianess
{
Little = 0,
Big = 1,
};
class Stream
{
public:
+15 -15
View File
@@ -9,18 +9,22 @@
std::vector<std::string> StringHelper::Split(std::string s, const std::string& delimiter)
{
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
std::string token;
std::vector<std::string> res;
std::vector<std::string> result;
while ((pos_end = s.find(delimiter, pos_start)) != std::string::npos) {
token = s.substr(pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
res.push_back(token);
}
size_t pos = 0;
std::string token;
res.push_back(s.substr(pos_start));
return res;
while ((pos = s.find(delimiter)) != std::string::npos)
{
token = s.substr(0, pos);
result.push_back(token);
s.erase(0, pos + delimiter.length());
}
if (s.length() != 0)
result.push_back(s);
return result;
}
std::string StringHelper::Strip(std::string s, const std::string& delimiter)
@@ -64,11 +68,7 @@ void StringHelper::ReplaceOriginal(std::string& str, const std::string& from, co
bool StringHelper::StartsWith(const std::string& s, const std::string& input)
{
#if __cplusplus >= 202002L
return s.starts_with(input.c_str());
#else
return s.rfind(input, 0) == 0;
#endif
}
bool StringHelper::Contains(const std::string& s, const std::string& input)
@@ -127,4 +127,4 @@ bool StringHelper::IEquals(const std::string& a, const std::string& b)
{
return std::equal(a.begin(), a.end(), b.begin(), b.end(),
[](char a, char b) { return tolower(a) == tolower(b); });
}
}
+2
View File
@@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
struct Vec3f
{
float x, y, z;
+6
View File
@@ -186,6 +186,12 @@
<ClCompile Include="Utils\MemoryStream.cpp" />
<ClCompile Include="Utils\StringHelper.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\OTRGui\build\ZERO_CHECK.vcxproj">
<Project>{02d10590-9542-3f55-aaf8-6055677e2a2a}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
+2 -2
View File
@@ -489,7 +489,7 @@ Current supported types are `Vec3s`, `Vec3i` or `Vec3f`.
- Example:
```xml
<Array Name="gLinkPauseChildDekuShieldJointTable" Count="24" Offset="0x2040">
<Array Name="D_04002040" Count="24" Offset="0x2040">
<Vector Type="s16" Dimensions="3" />
</Array>
```
@@ -497,7 +497,7 @@ Current supported types are `Vec3s`, `Vec3i` or `Vec3f`.
Will be extracted as:
```c
Vec3s gLinkPauseChildDekuShieldJointTable[24] = {
Vec3s D_04002040[24] = {
{ -37, 2346, 93 },
{ 0, 11995, 0 },
{ -16385, -305, -16333 },
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
curl -sSfLO "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
chmod a+x linuxdeploy*.AppImage
curl -sSfL https://github.com$(curl https://github.com/probonopd/go-appimage/releases | grep "mkappimage-.*-x86_64.AppImage" | head -n 1 | cut -d '"' -f 2) -o mkappimage.AppImage
chmod a+x mkappimage.AppImage
mkdir -p AppDir/usr/bin
cp appimage/{soh.desktop,soh.sh} AppDir/
cp soh/macosx/sohIcon.png AppDir/soh.png
curl -sSfL https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt -o AppDir/usr/bin/gamecontrollerdb.txt
mkdir -p AppDir/usr/share/applications
mkdir -p AppDir/usr/share/icons/hicolor/scalable/apps
mkdir -p AppDir/usr/lib
mv AppDir/soh.sh AppDir/usr/bin
cp -r build/* AppDir/usr/bin
chmod +x AppDir/usr/bin/{soh.elf,OTRGui,soh.sh}
cd AppDir && ln -s ./usr/bin/soh.sh ./AppRun && cd ..
export UPD_INFO="gh-releases-zsync|HarbourMasters|Shipwright-linux|develop|SOH-Linux.AppImage.zsync"
./linuxdeploy-x86_64.AppImage --appimage-extract-and-run \
--appdir=./AppDir/ \
-d ./AppDir/soh.desktop \
-i ./AppDir/soh.png \
-e ./AppDir/usr/bin/soh.elf
cd /soh
VERSION=Linux ./mkappimage.AppImage --appimage-extract-and-run ./AppDir # "SOH-Linux-x86_64.AppImage"
mv SOH-Linux-x86_64.AppImage SOH-Linux.AppImage # Keep Original Name
@@ -1,9 +1,9 @@
[Desktop Entry]
Version=1.0
Name=SOH
Exec=soh.sh
Exec=AppRun
Terminal=false
Icon=sohIcon
Icon=soh
Type=Application
Categories=Game;
X-AppImage-Integrate=false
Name[en_US]=
@@ -5,18 +5,14 @@ export PATH="$HERE"/bin:"$HERE"/usr/bin:"$PATH"
export LD_LIBRARY_PATH="$HERE"/usr/lib:"$LD_LIBRARY_PATH"
export ZENITY=$(command -v zenity)
if [ -z ${SHIP_HOME+x} ]; then
export SHIP_HOME=$PWD
fi
while [[ ! -e "$SHIP_HOME"/oot.otr ]]; do
while [[ ! -e "$PWD"/oot.otr ]]; do
export ASSETDIR="$(mktemp -d /tmp/assets-XXXXX)"
ln -s "$HERE"/usr/bin/{assets,soh.elf,OTRGui} "$ASSETDIR"
export OLDPWD="$PWD"
mkdir -p "$ASSETDIR"/tmp
mkdir -p "$ASSETDIR"/Extract/assets
if [ -e "$SHIP_HOME"/*.*64 ]; then
ln -s "$SHIP_HOME"/*.*64 "$ASSETDIR"/tmp/rom.z64
if [ -e "$PWD"/*.*64 ]; then
ln -s "$OLDPWD"/*.*64 "$ASSETDIR"/tmp/rom.z64
cp -r "$ASSETDIR"/assets/game/ship_of_harkinian "$ASSETDIR"/Extract/assets/
cd "$ASSETDIR"
ROMHASH=$(sha1sum -b "$ASSETDIR"/tmp/rom.z64 | awk '{ print $1 }')
@@ -40,19 +36,22 @@ while [[ ! -e "$SHIP_HOME"/oot.otr ]]; do
echo "Processing..."
fi
assets/extractor/ZAPD.out ed -eh -i assets/extractor/xmls/"${ROM}" -b tmp/rom.z64 -fl assets/extractor/filelists -o placeholder -osf placeholder -gsf 1 -rconf assets/extractor/Config_"${ROM}".xml -se OTR > /dev/null 2>&1
cp "$ASSETDIR"/oot.otr "$SHIP_HOME"
cp "$ASSETDIR"/oot.otr "$OLDPWD"
echo "Restart $APPIMAGE to play!"
sleep 3
rm -r "$ASSETDIR"
break
else
if [ -n "$ZENITY" ]; then
zenity --error --timeout=5 --text="Place ROM in $SHIP_HOME" --title="Missing ROM file" --width=500 --width=200
zenity --error --timeout=5 --text="Place ROM in $OWD" --title="Missing ROM file" --width=500 --width=200
else
echo -e "\nPlace ROM in this folder\n"
fi
exit
fi
done
(cd "$HERE/usr/bin"; ./soh.elf)
cd "$OWD"
ln -s "$HERE"/usr/bin/gamecontrollerdb.txt "$PWD"
"$HERE"/usr/bin/soh.elf
unlink "$PWD"/gamecontrollerdb.txt
exit
+148
View File
@@ -0,0 +1,148 @@
# Only used for standalone compilation, usually inherits these from the main makefile
CXX ?= g++
CC ?= gcc
AR := ar
FORMAT := clang-format-11
UNAME := $(shell uname)
ASAN ?= 0
DEBUG ?= 1
OPTFLAGS ?= -O0
LTO ?= 0
# flag to save whether the compiler being used is clang or gcc by checking CXX --version
CXX_IS_CLANG ?= $(shell $(CXX) --version | grep -c clang)
ifeq ($(CXX_IS_CLANG),1)
MXX := $(CXX)
else
MXX ?= clang++
endif
WARN := -Wall -Wextra -Werror \
-Wno-unused-variable \
-Wno-unused-parameter \
-Wno-unused-function \
-Wno-parentheses \
-Wno-narrowing \
-Wno-missing-field-initializers \
-Wno-error=multichar \
-Wno-unused-command-line-argument \
-Wno-delete-non-abstract-non-virtual-dtor \
-Wno-unused-private-field \
-Wno-deprecated-copy-with-user-provided-copy \
-Wno-deprecated-declarations \
-Wno-unknown-warning-option
CWARN :=
CXXWARN := -Wno-deprecated-enum-enum-conversion -Wno-deprecated-copy
ifneq ($(CXX_IS_CLANG),1)
WARN += -Wno-error=stringop-overflow
CXXWARN += -Wno-error=maybe-uninitialized
endif
CXXFLAGS := $(WARN) $(CXXWARN) -std=c++20 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0
CFLAGS := $(WARN) $(CWARN) -std=c99 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0
CPPFLAGS := -MMD
MMFLAGS := -Wno-deprecated-declarations -ObjC++ -fobjc-weak -fobjc-arc
# if not using clang, ask clang to use gcc standard library
ifneq ($(CXX_IS_CLANG),1)
STD_ISYSTEM=$(shell ${CXX} -xc++ -E -v - < /dev/null 2>&1 | grep "> search starts here" -A2 | tail -n 2 | head -n 1)
CXX_ISYSTEM=$(shell ${CXX} -xc++ -E -v - < /dev/null 2>&1 | grep "> search starts here" -A2 | tail -n 2 | tail -n 1)
MMFLAGS += -stdlib++-isystem ${STD_ISYSTEM} -cxx-isystem ${CXX_ISYSTEM}
endif
ifeq ($(UNAME), Darwin) #APPLE
CPPFLAGS += $(shell pkg-config --cflags sdl2 glew) -framework OpenGL -framework Foundation
endif
ifneq ($(DEBUG),0)
CXXFLAGS += -g -D_DEBUG
CFLAGS += -g -D_DEBUG
endif
ifneq ($(ASAN),0)
CXXFLAGS += -fsanitize=address
CFLAGS += -fsanitize=address
endif
ifneq ($(LTO),0)
CXXFLAGS += -flto
CFLAGS += -flto
endif
SRC_DIRS := $(shell find . -type d -not -path "*build*")
CXX_FILES := \
$(shell find libultraship/Factories -name "*.cpp") \
$(shell find libultraship/Lib/Fast3D -name "*.cpp") \
$(shell find libultraship -maxdepth 1 -name "*.cpp") \
$(shell find libultraship/Lib/ImGui -maxdepth 1 -name "*.cpp") \
$(shell find libultraship/Lib/Mercury -maxdepth 1 -name "*.cpp") \
libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp \
libultraship/Lib/ImGui/backends/imgui_impl_sdl.cpp \
libultraship/Lib/StrHash64.cpp \
libultraship/Lib/tinyxml2/tinyxml2.cpp
C_FILES := \
libultraship/mixer.c \
libultraship/Lib/stb/stb_impl.c
MM_FILES := \
libultraship/OSXFolderManager.mm
FMT_FILES := $(shell find libultraship/ -type f \( -name "*.cpp" -o -name "*.h" \) -a -not -path "libultraship/Lib/*")
O_FILES := \
$(CXX_FILES:%.cpp=build/%.o) \
$(C_FILES:%.c=build/%.o)
ifeq ($(UNAME), Darwin) #APPLE
O_FILES += $(MM_FILES:%.mm=build/%.o)
endif
D_FILES := $(O_FILES:%.o=%.d)
LIB := libultraship.a
INC_DIRS := $(addprefix -I, \
../ZAPDTR/ZAPDUtils \
libultraship/Lib/Fast3D/U64 \
libultraship/Lib/spdlog \
libultraship/Lib/spdlog/include \
libultraship/Lib/ImGui \
libultraship/Lib/Mercury \
libultraship \
../StormLib/src \
)
# create build directories
$(shell mkdir -p $(SRC_DIRS:%=build/%))
all: $(LIB)
clean:
rm -rf build $(LIB)
format:
$(FORMAT) -i $(FMT_FILES)
.PHONY: all clean format
build/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) -c $< -o $@
build/%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) -c $< -o $@
build/%.o: %.mm
$(MXX) $(MMFLAGS) $(CXXFLAGS) $(OPTFLAGS) $(INC_DIRS) -c $< -o $@
$(LIB): $(O_FILES)
$(AR) rcs $@ $^
-include $(D_FILES)
+29
View File
@@ -0,0 +1,29 @@
#include "OTRArchive.h"
void SaveTest()
{
auto archPtr = OtrLib::OTRArchive::CreateArchive("myarch.mpq");
auto arch = archPtr.get();
char data[] = "ABCDEFG!";
arch->AddFile("test.txt", (uintptr_t)data, sizeof(data));
}
void LoadTest()
{
std::shared_ptr<OtrLib::OTRArchive> archPtr(new OtrLib::OTRArchive("myarch.mpq"));
archPtr->LoadFile("(crcfile)");
int bp = 0;
}
int main()
{
LoadTest();
//SaveTest();
return 0;
}
Binary file not shown.
+152
View File
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{3c4a8151-48d1-4518-be1a-24016a5b800f}</ProjectGuid>
<RootNamespace>TestApp</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)..\otrlib;$(ProjectDir)..\..\ZAPD\ZAPDUtils;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)x64\Debug;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>otrlib.lib;ZAPDUtils.lib;StormLibDUS.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
+64
View File
@@ -0,0 +1,64 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libultraship", "libultraship\libultraship.vcxproj", "{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestApp", "TestApp\TestApp.vcxproj", "{3C4A8151-48D1-4518-BE1A-24016A5B800F}"
ProjectSection(ProjectDependencies) = postProject
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8} = {6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPD", "..\ZAPDTR\ZAPD\ZAPD.vcxproj", "{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPDUtils", "..\ZAPDTR\ZAPDUtils\ZAPDUtils.vcxproj", "{A2E01C3E-D647-45D1-9788-043DEBC1A908}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x64.ActiveCfg = Debug|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x64.Build.0 = Debug|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x86.ActiveCfg = Debug|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x86.Build.0 = Debug|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x64.ActiveCfg = Release|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x64.Build.0 = Release|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x86.ActiveCfg = Release|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x86.Build.0 = Release|Win32
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Debug|x64.ActiveCfg = Debug|x64
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Debug|x64.Build.0 = Debug|x64
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Debug|x86.ActiveCfg = Debug|Win32
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Debug|x86.Build.0 = Debug|Win32
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Release|x64.ActiveCfg = Release|x64
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Release|x64.Build.0 = Release|x64
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Release|x86.ActiveCfg = Release|Win32
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Release|x86.Build.0 = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.ActiveCfg = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.Build.0 = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.ActiveCfg = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.Build.0 = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.Build.0 = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.ActiveCfg = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.Build.0 = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.ActiveCfg = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.Build.0 = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.ActiveCfg = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.Build.0 = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.ActiveCfg = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DCE19FF1-37C0-49CD-915A-DD695E15F00B}
EndGlobalSection
EndGlobal
+9 -19
View File
@@ -6,10 +6,6 @@
#include "Lib/StrHash64.h"
#include <filesystem>
#ifdef __SWITCH__
#include "SwitchImpl.h"
#endif
namespace Ship {
Archive::Archive(const std::string& MainPath, bool enableWriting) : Archive(MainPath, "", enableWriting)
{
@@ -39,7 +35,7 @@ namespace Ship {
std::copy(archivePath.begin(), archivePath.end(), t_filename);
bool success = SFileCreateArchive(t_filename, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_CREATE_ARCHIVE_V2, fileCapacity, &archive->mainMPQ);
int32_t error = GetLastError();
int error = GetLastError();
delete[] t_filename;
@@ -50,7 +46,7 @@ namespace Ship {
}
else
{
SPDLOG_ERROR("({}) We tried to create an archive, but it has fallen and cannot get up.", error);
SPDLOG_ERROR("({}) We tried to create an archive, but it has fallen and cannot get up.");
return nullptr;
}
}
@@ -65,8 +61,14 @@ namespace Ship {
bool attempt = SFileOpenFileEx(mainMPQ, filePath.c_str(), 0, &fileHandle);
//if (!attempt)
//{
//std::string filePathAlt = StringHelper::Replace(filePath, "/", "\\");
//attempt |= SFileOpenFileEx(mainMPQ, filePathAlt.c_str(), 0, &fileHandle);
//}
if (!attempt) {
SPDLOG_ERROR("({}) Failed to open file {} from mpq archive {}.", GetLastError(), filePath.c_str(), MainPath.c_str());
printf("({%i}) Failed to open file {%s} from mpq archive {%s}", GetLastError(), filePath.c_str(), MainPath.c_str());
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
FileToLoad->bHasLoadError = true;
return FileToLoad;
@@ -325,21 +327,13 @@ namespace Ship {
#ifdef _WIN32
std::wstring wfullPath = std::filesystem::absolute(MainPath).wstring();
#endif
#if defined(__SWITCH__)
std::string fullPath = MainPath;
#else
std::string fullPath = std::filesystem::absolute(MainPath).string();
#endif
#ifdef _WIN32
if (!SFileOpenArchive(wfullPath.c_str(), 0, enableWriting ? 0 : MPQ_OPEN_READ_ONLY, &mpqHandle)) {
#else
if (!SFileOpenArchive(fullPath.c_str(), 0, enableWriting ? 0 : MPQ_OPEN_READ_ONLY, &mpqHandle)) {
#endif
#ifdef __SWITCH__
Switch::ThrowMissingOTR(fullPath);
#endif
SPDLOG_ERROR("({}) Failed to open main mpq file {}.", GetLastError(), fullPath.c_str());
return false;
}
@@ -368,11 +362,7 @@ namespace Ship {
bool Archive::LoadPatchMPQ(const std::string& path) {
HANDLE patchHandle = NULL;
#if defined(__SWITCH__)
std::string fullPath = path;
#else
std::string fullPath = std::filesystem::absolute(path).string();
#endif
if (mpqHandles.contains(fullPath)) {
return true;
}
+1
View File
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
#include "Resource.h"
//#include "Lib/StrHash64.h"
#include "StormLib.h"
-8
View File
@@ -14,11 +14,3 @@ namespace Ship {
constexpr int GetSampleRate() const { return 44100; }
};
}
#ifdef _WIN32
#include "WasapiAudioPlayer.h"
#elif defined(__linux)
#include "PulseAudioPlayer.h"
#endif
#include "SDLAudioPlayer.h"
-721
View File
@@ -1,721 +0,0 @@
set(PROJECT_NAME libultraship)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
enable_language(OBJCXX)
#set(CMAKE_OBJCXX_FLAGS "-Wno-deprecated-declarations -ObjC++")
endif()
################################################################################
# Source groups
################################################################################
set(Header_Files__Resources__Factories
"Factories/AnimationFactory.h"
"Factories/ArrayFactory.h"
"Factories/AudioFactory.h"
"Factories/BlobFactory.h"
"Factories/CollisionHeaderFactory.h"
"Factories/CutsceneFactory.h"
"Factories/DisplayListFactory.h"
"Factories/MaterialFactory.h"
"Factories/MtxFactory.h"
"Factories/PathFactory.h"
"Factories/PlayerAnimationFactory.h"
"Factories/ResourceLoader.h"
"Factories/SceneFactory.h"
"Factories/SkeletonFactory.h"
"Factories/SkeletonLimbFactory.h"
"Factories/TextFactory.h"
"Factories/TextureFactory.h"
"Factories/VtxFactory.h"
)
source_group("Header Files\\Resources\\Factories" FILES ${Header_Files__Resources__Factories})
set(Header_Files__Resources__Files
"Animation.h"
"Array.h"
"Audio.h"
"Blob.h"
"CollisionHeader.h"
"Cutscene.h"
"DisplayList.h"
"Material.h"
"Matrix.h"
"Model.h"
"Path.h"
"PlayerAnimation.h"
"Scene.h"
"Skeleton.h"
"SkeletonLimb.h"
"Text.h"
"Texture.h"
"Vertex.h"
)
source_group("Header Files\\Resources\\Files" FILES ${Header_Files__Resources__Files})
set(Source_Files__Audio
"abi.h"
"AudioPlayer.h"
"mixer.c"
"mixer.h"
"SDLAudioPlayer.cpp"
"SDLAudioPlayer.h"
)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(Source_Files__Audio__extra
"WasapiAudioPlayer.cpp"
"WasapiAudioPlayer.h"
)
endif ()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(Source_Files__Audio__extra
"PulseAudioPlayer.cpp"
"PulseAudioPlayer.h"
)
endif ()
source_group("Source Files\\Audio" FILES ${Source_Files__Audio} ${Source_Files__Audio__extra})
set(Source_Files__Controller
"ControlDeck.cpp"
"ControlDeck.h"
"Controller.cpp"
"Controller.h"
"ControllerAttachment.cpp"
"ControllerAttachment.h"
"InputEditor.cpp"
"InputEditor.h"
"KeyboardController.cpp"
"KeyboardController.h"
"UltraController.h"
"DummyController.cpp"
"DummyController.h"
)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
list(APPEND Source_Files__Controller
"SDLController.cpp"
"SDLController.h"
)
endif()
source_group("Source Files\\Controller" FILES ${Source_Files__Controller})
set(Source_Files__Controller__Attachment
"ControllerAttachment.cpp"
"ControllerAttachment.h"
"MemoryPack.cpp"
"MemoryPack.h"
"RumblePack.cpp"
"RumblePack.h"
)
source_group("Source Files\\Controller\\Attachment" FILES ${Source_Files__Controller__Attachment})
set(Source_Files__CustomImpl
"GameOverlay.cpp"
"GameOverlay.h"
"Console.cpp"
"Console.h"
"ImGuiImpl.cpp"
"ImGuiImpl.h"
)
source_group("Source Files\\CustomImpl" FILES ${Source_Files__CustomImpl})
set(Source_Files__CustomImpl__Hooks
"Hooks.cpp"
"Hooks.h"
)
source_group("Source Files\\CustomImpl\\Hooks" FILES ${Source_Files__CustomImpl__Hooks})
set(Source_Files__CustomImpl__Utils
"Utils.cpp"
"Utils.h"
)
source_group("Source Files\\CustomImpl\\Utils" FILES ${Source_Files__CustomImpl__Utils})
set(Source_Files__Globals
"Cvar.cpp"
"Cvar.h"
"LUSMacros.h"
"Window.cpp"
"Window.h"
)
source_group("Source Files\\Globals" FILES ${Source_Files__Globals})
set(Source_Files__Lib
"Lib/mINI/src/mini/ini.h"
"Lib/StrHash64.cpp"
"Lib/StrHash64.h"
"Lib/tinyxml2/tinyxml2.cpp"
"stox.cpp"
"stox.h"
)
source_group("Source Files\\Lib" FILES ${Source_Files__Lib})
set(Source_Files__Lib__Fast3D
"Lib/Fast3D/gfx_cc.cpp"
"Lib/Fast3D/gfx_cc.h"
"Lib/Fast3D/gfx_pc.cpp"
"Lib/Fast3D/gfx_pc.h"
"Lib/Fast3D/gfx_rendering_api.h"
"Lib/Fast3D/gfx_screen_config.h"
"Lib/Fast3D/gfx_window_manager_api.h"
)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
list(APPEND Source_Files__Lib__Fast3D
"Lib/Fast3D/gfx_opengl.cpp"
"Lib/Fast3D/gfx_opengl.h"
"Lib/Fast3D/gfx_sdl.h"
"Lib/Fast3D/gfx_sdl2.cpp"
)
endif()
source_group("Source Files\\Lib\\Fast3D" FILES ${Source_Files__Lib__Fast3D})
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(Source_Files__Lib__Fast3D__extra
"Lib/Fast3D/gfx_direct3d11.cpp"
"Lib/Fast3D/gfx_direct3d11.h"
"Lib/Fast3D/gfx_direct3d12.cpp"
"Lib/Fast3D/gfx_direct3d12.h"
"Lib/Fast3D/gfx_direct3d12_guids.h"
"Lib/Fast3D/gfx_direct3d_common.cpp"
"Lib/Fast3D/gfx_direct3d_common.h"
"Lib/Fast3D/gfx_dxgi.cpp"
"Lib/Fast3D/gfx_dxgi.h"
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(Source_Files__Lib__Fast3D__extra
"Lib/Fast3D/gfx_glx.cpp"
"Lib/Fast3D/gfx_glx.h"
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
set(Source_Files__Lib__Fast3D__extra
"Lib/Fast3D/gfx_wiiu.cpp"
"Lib/Fast3D/gfx_wiiu.h"
"Lib/Fast3D/gfx_gx2.cpp"
"Lib/Fast3D/gfx_gx2.h"
"Lib/Fast3D/gx2_shader_gen.c"
"Lib/Fast3D/gx2_shader_gen.h"
)
endif()
source_group("Source Files\\Lib\\Fast3D\\extra" FILES ${Source_Files__Lib__Fast3D__extra})
set(Source_Files__Lib__ImGui
"Lib/ImGui/imconfig.h"
"Lib/ImGui/imgui.cpp"
"Lib/ImGui/imgui.h"
"Lib/ImGui/imgui_demo.cpp"
"Lib/ImGui/imgui_draw.cpp"
"Lib/ImGui/imgui_internal.h"
"Lib/ImGui/imgui_tables.cpp"
"Lib/ImGui/imgui_widgets.cpp"
"Lib/ImGui/imstb_rectpack.h"
"Lib/ImGui/imstb_textedit.h"
"Lib/ImGui/imstb_truetype.h"
)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
list(APPEND Source_Files__Lib__ImGui
"Lib/ImGui/backends/imgui_impl_opengl3.cpp"
"Lib/ImGui/backends/imgui_impl_opengl3.h"
"Lib/ImGui/backends/imgui_impl_sdl.cpp"
"Lib/ImGui/backends/imgui_impl_sdl.h"
)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(Source_Files__Lib__ImGui__Windows
"Lib/ImGui/backends/imgui_impl_dx11.cpp"
"Lib/ImGui/backends/imgui_impl_dx11.h"
"Lib/ImGui/backends/imgui_impl_win32.cpp"
"Lib/ImGui/backends/imgui_impl_win32.h"
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
set(Source_Files__Lib__ImGui__WiiU
"Lib/ImGui/backends/wiiu/imgui_impl_wiiu.cpp"
"Lib/ImGui/backends/wiiu/imgui_impl_wiiu.h"
"Lib/ImGui/backends/wiiu/imgui_impl_gx2.cpp"
"Lib/ImGui/backends/wiiu/imgui_impl_gx2.h"
)
endif ()
source_group("Source Files\\Lib\\ImGui" FILES
${Source_Files__Lib__ImGui}
${Source_Files__Lib__ImGui__Windows}
${Source_Files__Lib__ImGui__WiiU}
)
set(Source_Files__Lib__Mercury
"Lib/Mercury/Mercury.cpp"
"Lib/Mercury/Mercury.h"
)
source_group("Source Files\\Lib\\Mercury" FILES ${Source_Files__Lib__Mercury})
set(Source_Files__Lib__stb
"Lib/stb/stb_image.h"
"Lib/stb/stb_image_write.h"
"Lib/stb/stb_impl.c"
)
source_group("Source Files\\Lib\\stb" FILES ${Source_Files__Lib__stb})
set(Source_Files__Lib__dr_libs
"Lib/dr_libs/mp3.h"
"Lib/dr_libs/wav.h"
)
source_group("Source Files\\Lib\\dr_libs" FILES ${Source_Files__Lib__dr_libs})
set(Source_Files__Lib__tinyxml2
"Lib/tinyxml2/tinyxml2.h"
)
source_group("Source Files\\Lib\\tinyxml2" FILES ${Source_Files__Lib__tinyxml2})
set(Source_Files__Logging
"luslog.cpp"
"luslog.h"
)
source_group("Source Files\\Logging" FILES ${Source_Files__Logging})
set(Source_Files__Resources
"GameVersions.h"
"Resource.cpp"
"Resource.h"
"ResourceMgr.cpp"
"ResourceMgr.h"
)
source_group("Source Files\\Resources" FILES ${Source_Files__Resources})
set(Source_Files__Resources__Factories
"Factories/AnimationFactory.cpp"
"Factories/ArrayFactory.cpp"
"Factories/AudioFactory.cpp"
"Factories/BlobFactory.cpp"
"Factories/CollisionHeaderFactory.cpp"
"Factories/CutsceneFactory.cpp"
"Factories/DisplayListFactory.cpp"
"Factories/MaterialFactory.cpp"
"Factories/MtxFactory.cpp"
"Factories/PathFactory.cpp"
"Factories/PlayerAnimationFactory.cpp"
"Factories/ResourceLoader.cpp"
"Factories/SceneFactory.cpp"
"Factories/SkeletonFactory.cpp"
"Factories/SkeletonLimbFactory.cpp"
"Factories/TextFactory.cpp"
"Factories/TextureFactory.cpp"
"Factories/VtxFactory.cpp"
)
source_group("Source Files\\Resources\\Factories" FILES ${Source_Files__Resources__Factories})
set(Source_Files__Resources__Files
"Animation.cpp"
"Array.cpp"
"Audio.cpp"
"Blob.cpp"
"CollisionHeader.cpp"
"Cutscene.cpp"
"DisplayList.cpp"
"Material.cpp"
"Matrix.cpp"
"Model.cpp"
"Path.cpp"
"PlayerAnimation.cpp"
"Scene.cpp"
"Skeleton.cpp"
"SkeletonLimb.cpp"
"Text.cpp"
"Texture.cpp"
"Vertex.cpp"
)
source_group("Source Files\\Resources\\Files" FILES ${Source_Files__Resources__Files})
set(Source_Files__Resources__mpq
"Archive.cpp"
"Archive.h"
"File.cpp"
"File.h"
)
source_group("Source Files\\Resources\\mpq" FILES ${Source_Files__Resources__mpq})
set(Source_Files__Crash_Handler
"CrashHandler.cpp"
"CrashHandler.h"
)
source_group("Source Files\\Crash Handler" FILES ${Source_Files__Crash_Handler})
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(Source_Files__Darwin
"OSXFolderManager.mm"
"OSXFolderManager.h"
)
source_group("Source Files\\Darwin" FILES ${Source_Files__Darwin})
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
set(Source_Files__NintendoSwitch
"SwitchImpl.cpp"
"SwitchImpl.h"
)
source_group("Source Files\\NintendoSwitch" FILES ${Source_Files__NintendoSwitch})
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
set(Source_Files__CafeOS
"WiiUController.cpp"
"WiiUController.h"
"WiiUGamepad.cpp"
"WiiUGamepad.h"
"WiiUImpl.cpp"
"WiiUImpl.h"
)
source_group("Source Files\\CafeOS" FILES ${Source_Files__CafeOS})
endif()
set(ALL_FILES
${Header_Files__Resources__Factories}
${Header_Files__Resources__Files}
${Source_Files__Audio}
${Source_Files__Audio__extra}
${Source_Files__Controller}
${Source_Files__Controller__Attachment}
${Source_Files__CustomImpl}
${Source_Files__CustomImpl__Hooks}
${Source_Files__CustomImpl__Utils}
${Source_Files__Globals}
${Source_Files__Lib}
${Source_Files__Lib__Fast3D}
${Source_Files__Lib__Fast3D__extra}
${Source_Files__Lib__ImGui}
${Source_Files__Lib__ImGui__Windows}
${Source_Files__Lib__ImGui__WiiU}
${Source_Files__Lib__Mercury}
${Source_Files__Lib__stb}
${Source_Files__Lib__dr_libs}
${Source_Files__Lib__tinyxml2}
${Source_Files__Logging}
${Source_Files__Resources}
${Source_Files__Resources__Factories}
${Source_Files__Resources__Files}
${Source_Files__Resources__mpq}
${Source_Files__Crash_Handler}
${Source_Files__Darwin}
${Source_Files__NintendoSwitch}
${Source_Files__CafeOS}
)
################################################################################
# Target
################################################################################
add_library(${PROJECT_NAME} STATIC ${ALL_FILES})
if (NOT TARGET storm)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../StormLib ${CMAKE_BINARY_DIR}/StormLib EXCLUDE_FROM_ALL)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}")
endif()
set(ROOT_NAMESPACE libultraship)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_GLOBAL_KEYWORD "Win32Proj"
)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
endif()
endif()
################################################################################
# MSVC runtime library
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
$<$<CONFIG:Debug>:
MultiThreadedDebug
>
$<$<CONFIG:Release>:
MultiThreaded
>
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
string(CONCAT "MSVC_RUNTIME_LIBRARY_STR"
$<$<CONFIG:Debug>:
MultiThreadedDebug
>
$<$<CONFIG:Release>:
MultiThreaded
>
$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:Release>>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}>
)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR})
endif()
################################################################################
# Compile definitions
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"SPDLOG_ACTIVE_LEVEL=0;"
"WIN32;"
"_CONSOLE;"
"_CRT_SECURE_NO_WARNINGS;"
"ENABLE_DX11;"
"ENABLE_OPENGL;"
"UNICODE;"
"_UNICODE"
STORMLIB_NO_AUTO_LINK
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"SPDLOG_ACTIVE_LEVEL=0;"
"WIN32;"
"_CONSOLE;"
"_CRT_SECURE_NO_WARNINGS;"
"ENABLE_OPENGL;"
"ENABLE_DX11;"
"UNICODE;"
"_UNICODE"
STORMLIB_NO_AUTO_LINK
)
endif()
elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"SPDLOG_ACTIVE_LEVEL=3;"
"SPDLOG_NO_THREAD_ID;"
"SPDLOG_NO_TLS;"
"STBI_NO_THREAD_LOCALS;"
)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang")
target_compile_definitions(${PROJECT_NAME} PRIVATE
"$<$<CONFIG:Debug>:"
"_DEBUG"
">"
"$<$<CONFIG:Release>:"
"NDEBUG"
">"
"ENABLE_OPENGL;"
"SPDLOG_ACTIVE_LEVEL=0;"
)
endif()
################################################################################
# Compile and link options
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(SDL2)
find_package(GLEW)
find_package(X11)
if (NOT GLEW_FOUND)
include (FetchContent)
FetchContent_Declare(
glew
GIT_REPOSITORY https://github.com/Perlmint/glew-cmake.git
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../external/glew
)
FetchContent_MakeAvailable(glew)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/glew/build/cmake ${CMAKE_BINARY_DIR}/glew EXCLUDE_FROM_ALL)
endif()
if (NOT GLEW_FOUND)
set(GLEW-INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/../../external/glew/include)
else()
set(GLEW-INCLUDE ${GLEW_INCLUDE_DIRS})
endif()
set(SDL2-INCLUDE ${SDL2_INCLUDE_DIRS})
elseif (CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS")
find_package(SDL2)
else()
find_package(SDL2)
find_package(GLEW)
set(GLEW-INCLUDE ${GLEW_INCLUDE_DIRS})
set(SDL2-INCLUDE ${SDL2_INCLUDE_DIRS})
endif()
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Lib/spdlog/include/
${CMAKE_CURRENT_SOURCE_DIR}/Lib/Fast3D/U64/
${CMAKE_CURRENT_SOURCE_DIR}/Lib/Fast3D/U64/PR
${SDL2-INCLUDE}
${GLEW-INCLUDE}
${SWITCH-INCLUDE}
${CMAKE_CURRENT_SOURCE_DIR}/Lib/ImGui/
${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/ZAPDUtils
${CMAKE_CURRENT_SOURCE_DIR}/../../StormLib/src
.
)
if(MSVC)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/Od;
/Oi-
>
$<$<CONFIG:Release>:
/std:c++latest;
/Oi;
/Gy
>
/permissive-;
/MP;
/sdl;
/W3;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:
/Od;
/Oi-;
/W2
>
$<$<CONFIG:Release>:
/Oi;
/Gy;
/W3
>
/permissive-;
/MP;
/sdl;
${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
${DEFAULT_CXX_EXCEPTION_HANDLING}
)
endif()
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/OPT:REF;
/OPT:ICF
>
/SUBSYSTEM:CONSOLE
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:
/OPT:REF;
/OPT:ICF
>
/SUBSYSTEM:CONSOLE
)
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wno-error
-Wno-unused-variable
-Wno-unused-parameter
-Wno-unused-function
-Wno-parentheses
-Wno-narrowing
-Wno-missing-field-initializers
)
endif()
################################################################################
# Dependencies
################################################################################
# Link with other targets.
find_package(OpenGL QUIET)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(X11)
find_package(PulseAudio)
endif()
if (NOT GLEW_FOUND)
set(GLEW-LIB glew_s)
else()
set(GLEW-LIB GLEW::GLEW)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_link_libraries(${PROJECT_NAME}
"GLEW::GLEW;"
"opengl32;"
"storm;"
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
target_link_libraries(${PROJECT_NAME}
"GLEW::GLEW;"
"opengl32;"
"storm;"
)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_package(SDL2)
find_package(GLEW)
find_package(OpenGL QUIET)
find_Library(OSX_FOUNDATION Foundation)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME}
"storm;"
SDL2::SDL2
GLEW::GLEW
${OPENGL_opengl_LIBRARY}
${CMAKE_DL_LIBS}
Threads::Threads
${OSX_FOUNDATION}
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME}
storm
SDL2::SDL2
Threads::Threads
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
find_package(SDL2 REQUIRED)
target_link_libraries(${PROJECT_NAME}
storm
SDL2::SDL2-static
)
target_include_directories(${PROJECT_NAME} PRIVATE
${DEVKITPRO}/portlibs/wiiu/include/
)
else()
target_link_libraries(${PROJECT_NAME}
SDL2::SDL2
${PULSEAUDIO_LIBRARY}
${GLEW-LIB}
${OPENGL_glx_LIBRARY}
${OPENGL_opengl_LIBRARY}
${X11_LIBRARIES}
storm
)
endif()
+216 -302
View File
@@ -1,133 +1,145 @@
#include "Console.h"
#include <iostream>
#include <sstream>
#include "Cvar.h"
#include "GlobalCtx2.h"
#include "ImGuiImpl.h"
#include "Lib/ImGui/imgui.h"
#include "Utils/StringHelper.h"
#include "Lib/ImGui/imgui_internal.h"
#include "Utils.h"
#include <sstream>
namespace Ship {
std::string BuildUsage(const CommandEntry& entry) {
std::string usage;
for (const auto& arg : entry.arguments)
usage += StringHelper::Sprintf(arg.optional ? "[%s] " : "<%s> ", arg.info.c_str());
return usage;
std::map<ImGuiKey, std::string> Bindings;
std::map<ImGuiKey, std::string> BindingToggle;
static bool HelpCommand(const std::vector<std::string>&) {
INFO("SoH Commands:");
for(const auto& cmd : SohImGui::console->Commands) {
INFO("%s", (" - " + cmd.first).c_str());
}
return CMD_SUCCESS;
}
bool Console::HelpCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args) {
Console->SendInfoMessage("SoH Commands:");
for (const auto& cmd : Console->Commands) {
Console->SendInfoMessage(" - " + cmd.first);
}
return CMD_SUCCESS;
}
static bool ClearCommand(const std::vector<std::string>&) {
SohImGui::console->Log[SohImGui::console->selected_channel].clear();
return CMD_SUCCESS;
}
bool Console::ClearCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args) {
Console->ClearLogs(Console->GetCurrentChannel());
return CMD_SUCCESS;
}
std::string toLowerCase(std::string in) {
std::string cpy(in);
std::transform(cpy.begin(), cpy.end(), cpy.begin(), ::tolower);
return cpy;
}
bool Console::BindCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args) {
if (args.size() > 2) {
const ImGuiIO* io = &ImGui::GetIO();;
for (size_t k = 0; k < std::size(io->KeysData); k++) {
std::string key(ImGui::GetKeyName(k));
static bool BindCommand(const std::vector<std::string>& args) {
if(args.size() > 2) {
const ImGuiIO* io = &ImGui::GetIO();;
for (size_t k = 0; k < std::size(io->KeysData); k++) {
std::string key(ImGui::GetKeyName(k));
if (toLowerCase(args[1]) == toLowerCase(key)) {
std::vector<std::string> tmp;
const char* const delim = " ";
std::ostringstream imploded;
std::copy(args.begin() + 2, args.end(), std::ostream_iterator<std::string>(imploded, delim));
Console->Bindings[k] = imploded.str();
Console->SendInfoMessage("Binding '%s' to %s", args[1].c_str(), Console->Bindings[k].c_str());
break;
}
}
}
return CMD_SUCCESS;
}
bool Console::BindToggleCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args) {
if (args.size() > 2) {
const ImGuiIO* io = &ImGui::GetIO();;
for (size_t k = 0; k < std::size(io->KeysData); k++) {
std::string key(ImGui::GetKeyName(k));
if (toLowerCase(args[1]) == toLowerCase(key)) {
Console->BindingToggle[k] = args[2];
Console->SendInfoMessage("Binding toggle '%s' to %s", args[1].c_str(), Console->BindingToggle[k].c_str());
break;
}
}
}
return CMD_SUCCESS;
}
void Console::Init() {
this->inputBuffer = new char[MAX_BUFFER_SIZE];
strcpy(this->inputBuffer, "");
this->filterBuffer = new char[MAX_BUFFER_SIZE];
strcpy(this->filterBuffer, "");
AddCommand("help", { HelpCommand, "Shows all the commands" });
AddCommand("clear", { ClearCommand, "Clear the console history" });
AddCommand("bind", { BindCommand, "Binds key to commands" });
AddCommand("bind-toggle", { BindToggleCommand, "Bind key as a bool toggle" });
}
void Console::Update() {
for (auto [key, cmd] : Bindings) {
if (ImGui::IsKeyPressed(key)) Dispatch(cmd);
}
for (auto [key, var] : BindingToggle) {
if (ImGui::IsKeyPressed(key)) {
CVar* cvar = CVar_Get(var.c_str());
Dispatch("set " + var + " " + std::to_string(cvar == nullptr ? 0 : !static_cast<bool>(cvar->value.valueS32)));
if(toLowerCase(args[1]) == toLowerCase(key)) {
std::vector<std::string> tmp;
const char* const delim = " ";
std::ostringstream imploded;
std::copy(args.begin() + 2, args.end(), std::ostream_iterator<std::string>(imploded, delim));
Bindings[k] = imploded.str();
INFO("Binding '%s' to %s", args[1].c_str(), Bindings[k].c_str());
break;
}
}
}
return CMD_SUCCESS;
}
void Console::Draw() {
if (!this->opened) {
CVar_SetS32("gConsoleEnabled", 0);
return;
static bool BindToggleCommand(const std::vector<std::string>& args) {
if (args.size() > 2) {
const ImGuiIO* io = &ImGui::GetIO();;
for (size_t k = 0; k < std::size(io->KeysData); k++) {
std::string key(ImGui::GetKeyName(k));
if (toLowerCase(args[1]) == toLowerCase(key)) {
BindingToggle[k] = args[2];
INFO("Binding toggle '%s' to %s", args[1].c_str(), BindingToggle[k].c_str());
break;
}
}
}
return CMD_SUCCESS;
}
bool input_focus = false;
std::string BuildUsage(const CommandEntry& entry) {
std::string usage;
for (const auto& arg : entry.arguments)
usage += StringHelper::Sprintf(arg.optional ? "[%s] " : "<%s> ", arg.info.c_str());
return usage;
}
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
ImGui::Begin("Console", &this->opened, ImGuiWindowFlags_NoFocusOnAppearing);
void Console::Init() {
this->InputBuffer = new char[MAX_BUFFER_SIZE];
strcpy(this->InputBuffer, "");
this->FilterBuffer = new char[MAX_BUFFER_SIZE];
strcpy(this->FilterBuffer, "");
this->Commands["help"] = { HelpCommand, "Shows all the commands" };
this->Commands["clear"] = { ClearCommand, "Clear the console history" };
this->Commands["bind"] = { BindCommand, "Binds key to commands" };
this->Commands["bind-toggle"] = { BindToggleCommand, "Bind key as a bool toggle" };
}
void Console::Update() {
for(auto [key, cmd] : Bindings) {
if (ImGui::IsKeyPressed(key)) Dispatch(cmd);
}
for (auto [key, var] : BindingToggle) {
if (ImGui::IsKeyPressed(key)) {
CVar* cvar = CVar_Get(var.c_str());
Dispatch("set " + var + " " + std::to_string(cvar == nullptr ? 0 : !static_cast<bool>(cvar->value.valueS32)));
}
}
}
extern "C" uint8_t __enableGameInput;
void Console::Draw() {
bool input_focus = false;
__enableGameInput = true;
if (!this->opened) return;
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
ImGui::Begin("Console", nullptr, ImGuiWindowFlags_NoFocusOnAppearing);
const ImVec2 pos = ImGui::GetWindowPos();
const ImVec2 size = ImGui::GetWindowSize();
__enableGameInput = !ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows);
// SohImGui::ShowCursor(ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_RectOnly), SohImGui::Dialogues::dConsole);
// Renders autocomplete window
if (this->openAutocomplete) {
if(this->OpenAutocomplete) {
ImGui::SetNextWindowSize(ImVec2(350, std::min(static_cast<int>(this->Autocomplete.size()), 3) * 20.f), ImGuiCond_Once);
ImGui::SetNextWindowPos(ImVec2(pos.x + 8, pos.y + size.y - 1));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(3, 3));
ImGui::Begin("##WndAutocomplete", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove);
ImGui::Begin("##WndAutocomplete", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove );
ImGui::BeginChild("AC_Child", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(.3f, .3f, .3f, 1.0f));
if (ImGui::BeginTable("AC_History", 1)) {
for (const auto& cmd : this->Autocomplete) {
std::string usage = BuildUsage(this->Commands[cmd]);
for (const auto &cmd : this->Autocomplete) {
std::string usage = BuildUsage(this->Commands[cmd]);
std::string preview = cmd + " - " + this->Commands[cmd].description;
std::string autocomplete = (usage == NULLSTR ? cmd : usage);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
if (ImGui::Selectable(preview.c_str())) {
memset(this->inputBuffer, 0, MAX_BUFFER_SIZE);
memcpy(this->inputBuffer, autocomplete.c_str(), sizeof(char) * autocomplete.size());
this->openAutocomplete = false;
memset(this->InputBuffer, 0, MAX_BUFFER_SIZE);
memcpy(this->InputBuffer, autocomplete.c_str(), sizeof(char) * autocomplete.size());
this->OpenAutocomplete = false;
input_focus = true;
}
}
ImGui::EndTable();
}
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
this->openAutocomplete = false;
this->OpenAutocomplete = false;
}
ImGui::PopStyleColor();
ImGui::EndChild();
@@ -137,7 +149,7 @@ namespace Ship {
if (ImGui::BeginPopupContextWindow("Context Menu")) {
if (ImGui::MenuItem("Copy Text")) {
ImGui::SetClipboardText(this->Log[this->currentChannel][this->selectedId].text.c_str());
ImGui::SetClipboardText(this->Log[this->selected_channel][this->selectedId].text.c_str());
this->selectedId = -1;
}
ImGui::EndPopup();
@@ -147,270 +159,172 @@ namespace Ship {
}
// Renders top bar filters
if (ImGui::Button("Clear")) this->Log[this->currentChannel].clear();
if (CVar_GetS32("gSinkEnabled", 0)) {
ImGui::SameLine();
ImGui::SetNextItemWidth(150);
if (ImGui::BeginCombo("##channel", this->currentChannel.c_str())) {
for (const auto& channel : LogChannels) {
const bool is_selected = (channel == std::string(this->currentChannel));
if (ImGui::Selectable(channel.c_str(), is_selected))
this->currentChannel = channel;
if (is_selected) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
if (ImGui::Button("Clear")) this->Log[this->selected_channel].clear();
ImGui::SameLine();
ImGui::SetNextItemWidth(150);
if (ImGui::BeginCombo("##channel", this->selected_channel.c_str())) {
for (const auto& channel : log_channels) {
const bool is_selected = (channel == std::string(this->selected_channel));
if (ImGui::Selectable(channel.c_str(), is_selected))
this->selected_channel = channel;
if (is_selected) ImGui::SetItemDefaultFocus();
}
} else {
this->currentChannel = "Console";
ImGui::EndCombo();
}
ImGui::SameLine();
ImGui::SetNextItemWidth(150);
if (this->currentChannel != "Console") {
if (ImGui::BeginCombo("##level", spdlog::level::to_string_view(this->levelFilter).data())) {
for (const auto& priority_filter : PriorityFilters) {
const bool is_selected = priority_filter == this->levelFilter;
if (ImGui::Selectable(spdlog::level::to_string_view(priority_filter).data(), is_selected))
{
this->levelFilter = priority_filter;
if (is_selected) ImGui::SetItemDefaultFocus();
}
if (ImGui::BeginCombo("##level", this->level_filter.c_str())) {
for (const auto& filter : priority_filters) {
const bool is_selected = (filter == std::string(this->level_filter));
if (ImGui::Selectable(filter.c_str(), is_selected))
{
this->level_filter = filter;
if (is_selected) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
} else {
this->levelFilter = spdlog::level::trace;
ImGui::EndCombo();
}
ImGui::SameLine();
ImGui::PushItemWidth(-1);
if (ImGui::InputTextWithHint("##input", "Filter", this->filterBuffer, MAX_BUFFER_SIZE))this->filter = std::string(this->filterBuffer);
if (ImGui::InputTextWithHint("##input", "Filter", this->FilterBuffer, MAX_BUFFER_SIZE))this->filter = std::string(this->FilterBuffer);
ImGui::PopItemWidth();
// Renders console history
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), false, ImGuiWindowFlags_HorizontalScrollbar);
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(.3f, .3f, .3f, 1.0f));
if (ImGui::BeginTable("History", 1)) {
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(.3f, .3f, .3f, 1.0f));
if (ImGui::BeginTable("History", 1)) {
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow)))
if (this->selectedId < (int)this->Log.size() - 1)++this->selectedId;
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow)))
if (this->selectedId > 0)--this->selectedId;
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow)))
if (this->selectedId < (int)this->Log.size() - 1) ++this->selectedId;
if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow)))
if (this->selectedId > 0) --this->selectedId;
const std::vector<ConsoleLine> channel = this->Log[this->currentChannel];
for (int i = 0; i < static_cast<int>(channel.size()); i++) {
ConsoleLine line = channel[i];
if (!this->filter.empty() && line.text.find(this->filter) == std::string::npos) continue;
if (this->levelFilter > line.priority) continue;
std::string id = line.text + "##" + std::to_string(i);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
const bool is_selected = (this->selectedId == i) || std::find(this->selectedEntries.begin(), this->selectedEntries.end(), i) != this->selectedEntries.end();
ImGui::PushStyleColor(ImGuiCol_Text, this->PriorityColours[line.priority]);
if (ImGui::Selectable(id.c_str(), is_selected)) {
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_LeftCtrl)) && !is_selected)
this->selectedEntries.push_back(i);
const std::vector<ConsoleLine> channel = this->Log[this->selected_channel];
for (int i = 0; i < static_cast<int>(channel.size()); i++) {
ConsoleLine line = channel[i];
if(!this->filter.empty() && line.text.find(this->filter) == std::string::npos) continue;
if(this->level_filter != NULLSTR && line.priority != (std::find(priority_filters.begin(), priority_filters.end(), this->level_filter) - priority_filters.begin()) - 1) continue;
std::string id = line.text + "##" + std::to_string(i);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
const bool is_selected = (this->selectedId == i) || std::find(this->selectedEntries.begin(), this->selectedEntries.end(), i) != this->selectedEntries.end();
ImGui::PushStyleColor(ImGuiCol_Text, this->priority_colors[line.priority]);
if (ImGui::Selectable(id.c_str(), is_selected)) {
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_LeftCtrl)) && !is_selected)
this->selectedEntries.push_back(i);
else this->selectedEntries.clear();
this->selectedId = is_selected ? -1 : i;
else this->selectedEntries.clear();
this->selectedId = is_selected ? -1 : i;
}
ImGui::PopStyleColor();
if (is_selected) ImGui::SetItemDefaultFocus();
}
ImGui::PopStyleColor();
if (is_selected) ImGui::SetItemDefaultFocus();
ImGui::EndTable();
}
ImGui::EndTable();
}
ImGui::PopStyleColor();
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);
ImGui::PopStyleColor();
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);
ImGui::EndChild();
if (this->currentChannel == "Console") {
// Renders input textfield
constexpr ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit |
ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
#ifdef __WIIU__
ImGui::PushItemWidth(-53.0f * 2.0f);
#else
ImGui::PushItemWidth(-53.0f);
#endif
if (ImGui::InputTextWithHint("##CMDInput", ">", this->inputBuffer, MAX_BUFFER_SIZE, flags, &Console::CallbackStub, this)) {
input_focus = true;
if (this->inputBuffer[0] != '\0' && this->inputBuffer[0] != ' ')
this->Dispatch(std::string(this->inputBuffer));
memset(this->inputBuffer, 0, MAX_BUFFER_SIZE);
}
if (this->cmdHint != NULLSTR) {
if (ImGui::IsItemFocused()) {
ImGui::SetNextWindowPos(ImVec2(pos.x, pos.y + size.y));
ImGui::SameLine();
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::TextUnformatted(this->cmdHint.c_str());
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
}
ImGui::SameLine();
#ifdef __WIIU__
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 50 * 2.0f);
#else
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 50);
#endif
if (ImGui::Button("Submit") && !input_focus && this->inputBuffer[0] != '\0' && this->inputBuffer[0] != ' ') {
this->Dispatch(std::string(this->inputBuffer));
memset(this->inputBuffer, 0, MAX_BUFFER_SIZE);
}
ImGui::SetItemDefaultFocus();
if (input_focus) ImGui::SetKeyboardFocusHere(-1);
ImGui::PopItemWidth();
// Renders input textfield
constexpr ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit |
ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
ImGui::PushItemWidth(-1);
if(ImGui::InputTextWithHint("CMDInput", ">", this->InputBuffer, MAX_BUFFER_SIZE, flags, &Console::CallbackStub, this)) {
input_focus = true;
if(this->InputBuffer[0] != '\0' && this->InputBuffer[0] != ' ')
this->Dispatch(std::string(this->InputBuffer));
memset(this->InputBuffer, 0, MAX_BUFFER_SIZE);
}
ImGui::End();
}
void Console::Dispatch(const std::string& line) {
this->cmdHint = NULLSTR;
this->History.push_back(line);
SendInfoMessage("> " + line);
const std::vector<std::string> cmd_args = StringHelper::Split(line, " ");
if (this->Commands.contains(cmd_args[0])) {
const CommandEntry entry = this->Commands[cmd_args[0]];
if (!entry.handler(shared_from_this(), cmd_args) && !entry.arguments.empty()) {
SendErrorMessage("[SOH] Usage: " + cmd_args[0] + " " + BuildUsage(entry));
if(this->CMDHint != NULLSTR) {
if (ImGui::IsItemFocused()) {
ImGui::SetNextWindowPos(ImVec2(pos.x, pos.y + size.y));
ImGui::SameLine();
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::TextUnformatted(this->CMDHint.c_str());
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
return;
}
SendErrorMessage("[SOH] Command not found");
ImGui::SetItemDefaultFocus();
if (input_focus) ImGui::SetKeyboardFocusHere(-1);
ImGui::PopItemWidth();
ImGui::End();
}
void Console::Dispatch(const std::string& line) {
this->CMDHint = NULLSTR;
this->History.push_back(line);
this->Log[this->selected_channel].push_back({ "> " + line } );
const std::vector<std::string> cmd_args = StringHelper::Split(line, " ");
if (this->Commands.contains(cmd_args[0])) {
const CommandEntry entry = this->Commands[cmd_args[0]];
if(!entry.handler(cmd_args) && !entry.arguments.empty())
this->Log[this->selected_channel].push_back({ "[SOH] Usage: " + cmd_args[0] + " " + BuildUsage(entry), ERROR_LVL});
return;
}
this->Log[this->selected_channel].push_back({ "[SOH] Command not found", ERROR_LVL });
}
int Console::CallbackStub(ImGuiInputTextCallbackData* data) {
const auto instance = static_cast<Console*>(data->UserData);
const bool empty_history = instance->History.empty();
const int history_index = instance->historyIndex;
std::string history;
int Console::CallbackStub(ImGuiInputTextCallbackData* data) {
const auto instance = static_cast<Console*>(data->UserData);
const bool empty_history = instance->History.empty();
const int history_index = instance->HistoryIndex;
std::string history;
switch (data->EventKey) {
switch(data->EventKey) {
case ImGuiKey_Tab:
instance->Autocomplete.clear();
for (auto& [cmd, entry] : instance->Commands)
if (cmd.find(std::string(data->Buf)) != std::string::npos) instance->Autocomplete.push_back(cmd);
instance->openAutocomplete = !instance->Autocomplete.empty();
instance->cmdHint = NULLSTR;
instance->OpenAutocomplete = !instance->Autocomplete.empty();
instance->CMDHint = NULLSTR;
break;
case ImGuiKey_UpArrow:
if (empty_history) break;
if (history_index < static_cast<int>(instance->History.size()) - 1) instance->historyIndex += 1;
if(history_index < static_cast<int>(instance->History.size()) - 1) instance->HistoryIndex += 1;
data->DeleteChars(0, data->BufTextLen);
data->InsertChars(0, instance->History[instance->historyIndex].c_str());
instance->cmdHint = NULLSTR;
data->InsertChars(0, instance->History[instance->HistoryIndex].c_str());
instance->CMDHint = NULLSTR;
break;
case ImGuiKey_DownArrow:
if (empty_history) break;
if (history_index > -1) instance->historyIndex -= 1;
if (history_index > -1) instance->HistoryIndex -= 1;
data->DeleteChars(0, data->BufTextLen);
if (history_index >= 0)
if(history_index >= 0)
data->InsertChars(0, instance->History[history_index].c_str());
instance->cmdHint = NULLSTR;
instance->CMDHint = NULLSTR;
break;
case ImGuiKey_Escape:
instance->historyIndex = -1;
instance->HistoryIndex = -1;
data->DeleteChars(0, data->BufTextLen);
instance->openAutocomplete = false;
instance->cmdHint = NULLSTR;
instance->OpenAutocomplete = false;
instance->CMDHint = NULLSTR;
break;
default:
instance->openAutocomplete = false;
instance->OpenAutocomplete = false;
for (auto& [cmd, entry] : instance->Commands) {
const std::vector<std::string> cmd_args = StringHelper::Split(std::string(data->Buf), " ");
if (data->BufTextLen > 2 && !cmd_args.empty() && cmd.find(cmd_args[0]) != std::string::npos) {
instance->cmdHint = cmd + " " + BuildUsage(entry);
instance->CMDHint = cmd + " " + BuildUsage(entry);
break;
}
instance->cmdHint = NULLSTR;
instance->CMDHint = NULLSTR;
}
}
return 0;
}
return 0;
}
void Console::Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, va_list args) {
char buf[2048];
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
this->Log[channel].push_back({ std::string(buf), priority });
}
void Console::Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
Append(channel, priority, fmt, args);
va_end(args);
}
void Console::SendInfoMessage(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
Append("Console", spdlog::level::info, fmt, args);
va_end(args);
}
void Console::SendErrorMessage(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
Append("Console", spdlog::level::err, fmt, args);
va_end(args);
}
void Console::SendInfoMessage(const std::string& str) {
Append("Console", spdlog::level::info, str.c_str());
}
void Console::SendErrorMessage(const std::string& str) {
Append("Console", spdlog::level::err, str.c_str());
}
void Console::ClearLogs(std::string channel) {
Log[channel].clear();
}
void Console::ClearLogs() {
for (auto [key, var] : Log) {
var.clear();
}
}
bool Console::HasCommand(const std::string& command) {
for (const auto& Command : Commands) {
if (Command.first == command) {
return true;
}
}
return false;
}
void Console::AddCommand(const std::string& command, CommandEntry entry) {
if (!HasCommand(command)) {
Commands[command] = entry;
}
}
std::string Console::GetCurrentChannel() {
return currentChannel;
}
bool Console::IsOpened() {
return opened;
}
void Console::Close() {
opened = false;
}
void Console::Open() {
opened = true;
}
}
void Console::Append(const std::string& channel, Priority priority, const char* fmt, ...) {
char buf[1024];
va_list args;
va_start(args, fmt);
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
va_end(args);
this->Log[channel].push_back({ std::string(buf), priority });
}
+69 -89
View File
@@ -6,96 +6,76 @@
#include <functional>
#include "Lib/ImGui/imgui.h"
#include "spdlog/spdlog.h"
namespace Ship {
#define CMD_SUCCESS true
#define CMD_FAILED false
#define MAX_BUFFER_SIZE 255
#define NULLSTR "None"
#define LOG(msg, ...) SohImGui::console->Append("Main", Priority::LOG_LVL, msg, ##__VA_ARGS__)
#define INFO(msg, ...) SohImGui::console->Append("Main", Priority::INFO_LVL, msg, ##__VA_ARGS__)
#define WARNING(msg, ...) SohImGui::console->Append("Main", Priority::WARNING_LVL, msg, ##__VA_ARGS__)
#define ERROR(msg, ...) SohImGui::console->Append("Main", Priority::ERROR_LVL, msg, ##__VA_ARGS__)
#define CMD_SUCCESS true
#define CMD_FAILED false
#define MAX_BUFFER_SIZE 255
#define NULLSTR "None"
class Console;
typedef std::function<bool(std::shared_ptr<Console> Console, std::vector<std::string> args)> CommandHandler;
typedef std::function<bool(std::vector<std::string> args)> CommandHandler;
enum class ArgumentType {
TEXT, NUMBER, PLAYER_POS, PLAYER_ROT
enum Priority {
INFO_LVL,
LOG_LVL,
WARNING_LVL,
ERROR_LVL
};
enum class ArgumentType {
TEXT, NUMBER, PLAYER_POS, PLAYER_ROT
};
struct CommandArgument {
std::string info;
ArgumentType type = ArgumentType::NUMBER;
bool optional = false;
};
struct CommandEntry {
CommandHandler handler;
std::string description;
std::vector<CommandArgument> arguments;
};
struct ConsoleLine {
std::string text;
Priority priority = Priority::INFO_LVL;
std::string channel = "Main";
};
class Console {
int selectedId = -1;
std::vector<int> selectedEntries;
std::string filter;
std::string level_filter = NULLSTR;
std::vector<std::string> log_channels = { "Main", "SoH Logging"};
std::vector<std::string> priority_filters = { "None", "Info", "Log", "Warning", "Error" };
std::vector<ImVec4> priority_colors = {
ImVec4(1.0f, 1.0f, 1.0f, 1.0f),
ImVec4(0.2f, 1.0f, 0.2f, 1.0f),
ImVec4(0.9f, 0.8f, 0.4f, 0.01f),
ImVec4(1.0f, 0.2f, 0.2f, 1.0f)
};
struct CommandArgument {
std::string info;
ArgumentType type = ArgumentType::NUMBER;
bool optional = false;
};
struct CommandEntry {
CommandHandler handler;
std::string description;
std::vector<CommandArgument> arguments;
};
struct ConsoleLine {
std::string text;
spdlog::level::level_enum priority = spdlog::level::info;
std::string channel = "Console";
};
class Console : public std::enable_shared_from_this<Console> {
private:
static int CallbackStub(ImGuiInputTextCallbackData* data);
static bool ClearCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args);
static bool HelpCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args);
static bool BindCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args);
static bool BindToggleCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args);
bool opened = false;
int selectedId = -1;
int historyIndex = -1;
std::vector<int> selectedEntries;
std::string filter;
std::string currentChannel = "Console";
bool openAutocomplete = false;
char* inputBuffer = nullptr;
char* filterBuffer = nullptr;
std::string cmdHint = NULLSTR;
spdlog::level::level_enum levelFilter = spdlog::level::trace;
std::vector<std::string> History;
std::vector<std::string> Autocomplete;
std::map<ImGuiKey, std::string> Bindings;
std::map<ImGuiKey, std::string> BindingToggle;
std::map<std::string, CommandEntry> Commands;
std::map<std::string, std::vector<ConsoleLine>> Log;
const std::vector<std::string> LogChannels = { "Console", "Logs" };
const std::vector<spdlog::level::level_enum> PriorityFilters = { spdlog::level::off, spdlog::level::critical, spdlog::level::err, spdlog::level::warn, spdlog::level::info, spdlog::level::debug, spdlog::level::trace };
const std::vector<ImVec4> PriorityColours = {
ImVec4(0.8f, 0.8f, 0.8f, 1.0f), // TRACE
ImVec4(0.9f, 0.9f, 0.9f, 1.0f), // DEBUG
ImVec4(1.0f, 1.0f, 1.0f, 1.0f), // INFO
ImVec4(1.0f, 0.875f, 0.125f, 1.0f), // WARN
ImVec4(0.65f, 0.18f, 0.25, 1.0f), // ERROR
ImVec4(0.95f, 0.11f, 0.25, 1.0f), // CRITICAL
ImVec4(0.0f, 0.0f, 0.0f, 0.0f) // OFF
};
protected:
void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, va_list args);
public:
void ClearLogs(std::string channel);
void ClearLogs();
void Init();
void Update();
void Draw();
void Dispatch(const std::string& line);
void SendInfoMessage(const char* fmt, ...);
void SendErrorMessage(const char* fmt, ...);
void SendInfoMessage(const std::string& str);
void SendErrorMessage(const std::string& str);
void Append(const std::string& channel, spdlog::level::level_enum priority, const char* fmt, ...);
bool HasCommand(const std::string& command);
void AddCommand(const std::string& command, CommandEntry entry);
std::string GetCurrentChannel();
bool IsOpened();
void Close();
void Open();
};
}
public:
std::map<std::string, std::vector<ConsoleLine>> Log;
std::map<std::string, CommandEntry> Commands;
std::vector<std::string> Autocomplete;
std::vector<std::string> History;
std::string CMDHint = NULLSTR;
char* FilterBuffer = nullptr;
char* InputBuffer = nullptr;
bool OpenAutocomplete = false;
int HistoryIndex = -1;
std::string selected_channel = "Main";
bool opened = false;
void Init();
void Update();
void Draw();
void Append(const std::string& channel, Priority priority, const char* fmt, ...) IM_FMTARGS(4);
void Dispatch(const std::string& line);
static int CallbackStub(ImGuiInputTextCallbackData* data);
};
+128 -269
View File
@@ -2,286 +2,145 @@
#include "Window.h"
#include "Controller.h"
#include "DummyController.h"
#include <Utils/StringHelper.h>
#include "Cvar.h"
#include "Lib/ImGui/imgui.h"
#ifndef __WIIU__
#include "DisconnectedController.h"
#include "KeyboardController.h"
#include "SDLController.h"
#else
#include "WiiUGamepad.h"
#include "WiiUController.h"
#endif
#include <Utils/StringHelper.h>
namespace Ship {
uint8_t* controllerBits;
void ControlDeck::Init(uint8_t* bits) {
ScanPhysicalDevices();
controllerBits = bits;
}
void Ship::ControlDeck::Init(uint8_t* bits) {
ScanPhysicalDevices();
controllerBits = bits;
}
void ControlDeck::ScanPhysicalDevices() {
void Ship::ControlDeck::ScanPhysicalDevices() {
virtualDevices.clear();
physicalDevices.clear();
virtualDevices.clear();
physicalDevices.clear();
#ifndef __WIIU__
for (int32_t i = 0; i < SDL_NumJoysticks(); i++) {
if (SDL_IsGameController(i)) {
auto sdl = std::make_shared<SDLController>(i);
sdl->Open();
physicalDevices.push_back(sdl);
}
}
physicalDevices.push_back(std::make_shared<DummyController>("Auto", "Auto", true));
physicalDevices.push_back(std::make_shared<KeyboardController>());
#else
physicalDevices.push_back(std::make_shared<DummyController>("Auto", "Auto", true));
auto gamepad = std::make_shared<Ship::WiiUGamepad>();
gamepad->Open();
physicalDevices.push_back(gamepad);
for (int32_t i = 0; i < 4; i++) {
auto controller = std::make_shared<Ship::WiiUController>((WPADChan) i);
controller->Open();
physicalDevices.push_back(controller);
}
#endif
physicalDevices.push_back(std::make_shared<DummyController>("Disconnected", "None", false));
for (const auto device : physicalDevices) {
for (int32_t i = 0; i < MAXCONTROLLERS; i++) {
device->CreateDefaultBinding(i);
}
}
for (int32_t i = 0; i < MAXCONTROLLERS; i++) {
virtualDevices.push_back(i == 0 ? 0 : static_cast<int>(physicalDevices.size()) - 1);
}
LoadControllerSettings();
}
void ControlDeck::SetPhysicalDevice(int32_t slot, int32_t deviceSlot) {
const std::shared_ptr<Controller> backend = physicalDevices[deviceSlot];
virtualDevices[slot] = deviceSlot;
*controllerBits |= (backend->Connected()) << slot;
}
void ControlDeck::WriteToPad(OSContPad* pad) const {
for (size_t i = 0; i < virtualDevices.size(); i++) {
const std::shared_ptr<Controller> backend = physicalDevices[virtualDevices[i]];
// If the controller backend is "Auto" we need to get the real device
// we search for the real device to read input from it
if (backend->GetGuid() == "Auto") {
for (const auto& device : physicalDevices) {
if(ShouldBlockGameInput(device->GetGuid())) {
device->Read(nullptr, i);
continue;
}
device->Read(&pad[i], i);
}
continue;
}
if(ShouldBlockGameInput(backend->GetGuid())) {
backend->Read(nullptr, i);
continue;
}
backend->Read(&pad[i], i);
for (int i = 0; i < SDL_NumJoysticks(); i++) {
if (SDL_IsGameController(i)) {
auto sdl = std::make_shared<SDLController>(i);
sdl->Open();
physicalDevices.push_back(sdl);
}
}
#define NESTED(key, ...) StringHelper::Sprintf("Controllers.%s.Slot_%d." key, device->GetGuid().c_str(), virtualSlot, __VA_ARGS__)
physicalDevices.push_back(std::make_shared<KeyboardController>());
physicalDevices.push_back(std::make_shared<DisconnectedController>());
void ControlDeck::LoadControllerSettings() {
std::shared_ptr<Mercury> Config = Window::GetInstance()->GetConfig();
for (const auto& device : physicalDevices) {
for (int i = 0; i < MAXCONTROLLERS; i++) {
device->CreateDefaultBinding(i);
}
}
for (auto const& val : Config->rjson["Controllers"]["Deck"].items()) {
int32_t slot = std::stoi(val.key().substr(5));
for (int i = 0; i < MAXCONTROLLERS; i++) {
virtualDevices.push_back(i == 0 ? 0 : static_cast<int>(physicalDevices.size()) - 1);
}
for (size_t dev = 0; dev < physicalDevices.size(); dev++) {
std::string guid = physicalDevices[dev]->GetGuid();
if (guid != val.value()) continue;
virtualDevices[slot] = dev;
}
}
for (size_t i = 0; i < virtualDevices.size(); i++) {
std::shared_ptr<Controller> backend = physicalDevices[virtualDevices[i]];
Config->setString(StringHelper::Sprintf("Controllers.Deck.Slot_%d", (int)i), backend->GetGuid());
}
for (const auto device : physicalDevices) {
std::string guid = device->GetGuid();
for (int32_t virtualSlot = 0; virtualSlot < MAXCONTROLLERS; virtualSlot++) {
if (!(Config->rjson["Controllers"].contains(guid) && Config->rjson["Controllers"][guid].contains(StringHelper::Sprintf("Slot_%d", virtualSlot)))) continue;
auto profile = device->getProfile(virtualSlot);
auto rawProfile = Config->rjson["Controllers"][guid][StringHelper::Sprintf("Slot_%d", virtualSlot)];
profile->Mappings.clear();
profile->AxisDeadzones.clear();
profile->AxisDeadzones.clear();
profile->GyroData.clear();
profile->Version = Config->getInt(NESTED("Version", ""), DEVICE_PROFILE_VERSION_V0);
switch (profile->Version) {
case DEVICE_PROFILE_VERSION_V0:
// Load up defaults for the things we can't load.
device->CreateDefaultBinding(virtualSlot);
profile->UseRumble = Config->getBool(NESTED("Rumble.Enabled", ""));
profile->RumbleStrength = Config->getFloat(NESTED("Rumble.Strength", ""));
profile->UseGyro = Config->getBool(NESTED("Gyro.Enabled", ""));
for (auto const& val : rawProfile["Mappings"].items()) {
device->SetButtonMapping(virtualSlot, std::stoi(val.key().substr(4)), val.value());
}
break;
case DEVICE_PROFILE_VERSION_V1:
profile->UseRumble = Config->getBool(NESTED("Rumble.Enabled", ""));
profile->RumbleStrength = Config->getFloat(NESTED("Rumble.Strength", ""));
profile->UseGyro = Config->getBool(NESTED("Gyro.Enabled", ""));
for (auto const& val : rawProfile["AxisDeadzones"].items()) {
profile->AxisDeadzones[std::stoi(val.key())] = val.value();
}
for (auto const& val : rawProfile["AxisMinimumPress"].items()) {
profile->AxisMinimumPress[std::stoi(val.key())] = val.value();
}
for (auto const& val : rawProfile["GyroData"].items()) {
profile->GyroData[std::stoi(val.key())] = val.value();
}
for (auto const& val : rawProfile["Mappings"].items()) {
device->SetButtonMapping(virtualSlot, std::stoi(val.key().substr(4)), val.value());
}
break;
// Version is invalid.
default:
device->CreateDefaultBinding(virtualSlot);
break;
}
}
}
}
void ControlDeck::SaveControllerSettings() {
std::shared_ptr<Mercury> Config = Window::GetInstance()->GetConfig();
for (size_t i = 0; i < virtualDevices.size(); i++) {
std::shared_ptr<Controller> backend = physicalDevices[virtualDevices[i]];
Config->setString(StringHelper::Sprintf("Controllers.Deck.Slot_%d", (int)i), backend->GetGuid());
}
for (const auto& device : physicalDevices) {
int32_t virtualSlot = 0;
std::string guid = device->GetGuid();
for (int32_t virtualSlot = 0; virtualSlot < MAXCONTROLLERS; virtualSlot++) {
auto profile = device->getProfile(virtualSlot);
if (!device->Connected()) continue;
auto rawProfile = Config->rjson["Controllers"][guid][StringHelper::Sprintf("Slot_%d", virtualSlot)];
Config->setInt(NESTED("Version", ""), profile->Version);
Config->setBool(NESTED("Rumble.Enabled", ""), profile->UseRumble);
Config->setFloat(NESTED("Rumble.Strength", ""), profile->RumbleStrength);
Config->setBool(NESTED("Gyro.Enabled", ""), profile->UseGyro);
for (auto const& val : rawProfile["Mappings"].items()) {
Config->setInt(NESTED("Mappings.%s", val.key().c_str()), -1);
}
for (auto const& [key, val] : profile->AxisDeadzones) {
Config->setFloat(NESTED("AxisDeadzones.%d", key), val);
}
for (auto const& [key, val] : profile->AxisMinimumPress) {
Config->setFloat(NESTED("AxisMinimumPress.%d", key), val);
}
for (auto const& [key, val] : profile->GyroData) {
Config->setFloat(NESTED("GyroData.%d", key), val);
}
for (auto const& [key, val] : profile->Mappings) {
Config->setInt(NESTED("Mappings.BTN_%d", val), key);
}
virtualSlot++;
}
}
Config->save();
}
std::shared_ptr<Controller> ControlDeck::GetPhysicalDevice(int32_t deviceSlot) {
return physicalDevices[deviceSlot];
}
size_t ControlDeck::GetNumPhysicalDevices() {
return physicalDevices.size();
}
int32_t ControlDeck::GetVirtualDevice(int32_t slot) {
return virtualDevices[slot];
}
size_t ControlDeck::GetNumVirtualDevices() {
return virtualDevices.size();
}
std::shared_ptr<Controller> ControlDeck::GetPhysicalDeviceFromVirtualSlot(int32_t slot) {
return GetPhysicalDevice(GetVirtualDevice(slot));
}
uint8_t* ControlDeck::GetControllerBits() {
return controllerBits;
}
void ControlDeck::BlockGameInput() {
shouldBlockGameInput = true;
}
void ControlDeck::UnblockGameInput() {
shouldBlockGameInput = false;
}
bool ControlDeck::ShouldBlockGameInput(std::string inputDeviceGuid) const {
// We block controller input if F1 menu is open and control navigation is on.
// This is because we don't want controller inputs to affect the game
bool shouldBlockControllerInput = CVar_GetS32("gOpenMenuBar", 0) && CVar_GetS32("gControlNav", 0);
// We block keyboard input if you're currently typing into a textfield.
// This is because we don't want your keyboard typing to affect the game.
ImGuiIO io = ImGui::GetIO();
bool shouldBlockKeyboardInput = io.WantCaptureKeyboard;
bool inputDeviceIsKeyboard = inputDeviceGuid == "Keyboard";
return shouldBlockGameInput || (inputDeviceIsKeyboard ? shouldBlockKeyboardInput : shouldBlockControllerInput);
}
LoadControllerSettings();
}
void Ship::ControlDeck::SetPhysicalDevice(int slot, int deviceSlot) {
const std::shared_ptr<Controller> backend = physicalDevices[deviceSlot];
virtualDevices[slot] = deviceSlot;
*controllerBits |= (backend->Connected()) << slot;
}
void Ship::ControlDeck::WriteToPad(OSContPad* pad) const {
for (size_t i = 0; i < virtualDevices.size(); i++) {
physicalDevices[virtualDevices[i]]->Read(&pad[i], i);
}
}
#define NESTED(key, ...) StringHelper::Sprintf("Controllers.%s.Slot_%d." key, device->GetGuid().c_str(), slot, __VA_ARGS__)
void Ship::ControlDeck::LoadControllerSettings() {
std::shared_ptr<Mercury> Config = GlobalCtx2::GetInstance()->GetConfig();
for (auto const& val : Config->rjson["Controllers"]["Deck"].items()) {
int slot = std::stoi(val.key().substr(5));
for (size_t dev = 0; dev < physicalDevices.size(); dev++) {
std::string guid = physicalDevices[dev]->GetGuid();
if(guid != val.value()) continue;
virtualDevices[slot] = dev;
}
}
for (size_t i = 0; i < virtualDevices.size(); i++) {
std::shared_ptr<Controller> backend = physicalDevices[virtualDevices[i]];
Config->setString(StringHelper::Sprintf("Controllers.Deck.Slot_%d", (int)i), backend->GetGuid());
}
for (const auto& device : physicalDevices) {
std::string guid = device->GetGuid();
for (int slot = 0; slot < MAXCONTROLLERS; slot++) {
if (!(Config->rjson["Controllers"].contains(guid) && Config->rjson["Controllers"][guid].contains(StringHelper::Sprintf("Slot_%d", slot)))) continue;
auto& profile = device->profiles[slot];
auto rawProfile = Config->rjson["Controllers"][guid][StringHelper::Sprintf("Slot_%d", slot)];
profile.Mappings.clear();
profile.Thresholds.clear();
profile.UseRumble = Config->getBool(NESTED("Rumble.Enabled", ""));
profile.RumbleStrength = Config->getFloat(NESTED("Rumble.Strength", ""));
profile.UseGyro = Config->getBool(NESTED("Gyro.Enabled", ""));
for (auto const& val : rawProfile["Thresholds"].items()) {
profile.Thresholds[static_cast<ControllerThresholds>(std::stoi(val.key()))] = val.value();
}
for (auto const& val : rawProfile["Mappings"].items()) {
device->SetButtonMapping(slot, std::stoi(val.key().substr(4)), val.value());
}
}
}
}
void Ship::ControlDeck::SaveControllerSettings() {
std::shared_ptr<Mercury> Config = GlobalCtx2::GetInstance()->GetConfig();
for (size_t i = 0; i < virtualDevices.size(); i++) {
std::shared_ptr<Controller> backend = physicalDevices[virtualDevices[i]];
Config->setString(StringHelper::Sprintf("Controllers.Deck.Slot_%d", (int)i), backend->GetGuid());
}
for (const auto& device : physicalDevices) {
int slot = 0;
std::string guid = device->GetGuid();
for (const auto& profile : device->profiles) {
if (!device->Connected()) continue;
auto rawProfile = Config->rjson["Controllers"][guid][StringHelper::Sprintf("Slot_%d", slot)];
Config->setBool(NESTED("Rumble.Enabled", ""), profile.UseRumble);
Config->setFloat(NESTED("Rumble.Strength", ""), profile.RumbleStrength);
Config->setBool(NESTED("Gyro.Enabled", ""), profile.UseGyro);
for (auto const& val : rawProfile["Mappings"].items()) {
Config->setInt(NESTED("Mappings.%s", val.key().c_str()), -1);
}
for (auto const& [key, val] : profile.Thresholds) {
Config->setFloat(NESTED("Thresholds.%d", key), val);
}
for (auto const& [key, val] : profile.Mappings) {
Config->setInt(NESTED("Mappings.BTN_%d", val), key);
}
slot++;
}
}
Config->save();
}
+4 -16
View File
@@ -2,31 +2,19 @@
#include "Controller.h"
#include <vector>
#include "Lib/Mercury/Mercury.h"
#include <string>
namespace Ship {
class ControlDeck {
public:
std::vector<int> virtualDevices;
std::vector<std::shared_ptr<Controller>> physicalDevices = {};
void Init(uint8_t* controllerBits);
void ScanPhysicalDevices();
void WriteToPad(OSContPad* pad) const;
void LoadControllerSettings();
void SaveControllerSettings();
void SetPhysicalDevice(int32_t slot, int32_t deviceSlot);
std::shared_ptr<Controller> GetPhysicalDevice(int32_t deviceSlot);
std::shared_ptr<Controller> GetPhysicalDeviceFromVirtualSlot(int32_t slot);
size_t GetNumPhysicalDevices();
int32_t GetVirtualDevice(int32_t slot);
size_t GetNumVirtualDevices();
uint8_t* GetControllerBits();
void BlockGameInput();
void UnblockGameInput();
bool ShouldBlockGameInput(std::string inputDeviceGuid) const;
private:
std::vector<int32_t> virtualDevices = {};
std::vector<std::shared_ptr<Controller>> physicalDevices = {};
uint8_t* controllerBits = nullptr;
bool shouldBlockGameInput = false;
void SetPhysicalDevice(int slot, int deviceSlot);
};
}
+35 -101
View File
@@ -1,7 +1,6 @@
#include "Controller.h"
#include <memory>
#include <algorithm>
#include "Cvar.h"
#if __APPLE__
#include <SDL_events.h>
#else
@@ -10,137 +9,72 @@
namespace Ship {
Controller::Controller() : isRumbling(false) {
Controller::Controller() : isRumbling(false), wStickX(0), wStickY(0), wGyroX(0), wGyroY(0), dwPressedButtons(0){
Attachment = nullptr;
for(int32_t virtualSlot = 0; virtualSlot < MAXCONTROLLERS; virtualSlot++) {
profiles[virtualSlot] = std::make_shared<DeviceProfile>();
ButtonData[virtualSlot] = std::make_shared<Buttons>();
profiles.resize(MAXCONTROLLERS);
for(int slot = 0; slot < MAXCONTROLLERS; slot++) {
dwPressedButtons.push_back(0);
}
}
void Controller::Read(OSContPad* pad, int32_t virtualSlot) {
ReadFromSource(virtualSlot);
void Controller::Read(OSContPad* pad, int32_t slot) {
ReadFromSource(slot);
OSContPad padToBuffer = { 0 };
#ifndef __WIIU__
SDL_PumpEvents();
#endif
// Button Inputs
padToBuffer.button |= getPressedButtons(virtualSlot) & 0xFFFF;
pad->button |= dwPressedButtons[slot] & 0xFFFF;
// Stick Inputs
if (getLeftStickX(virtualSlot) == 0) {
if (getPressedButtons(virtualSlot) & BTN_STICKLEFT) {
padToBuffer.stick_x = -128;
} else if (getPressedButtons(virtualSlot) & BTN_STICKRIGHT) {
padToBuffer.stick_x = 127;
if (wStickX == 0) {
if (dwPressedButtons[slot] & BTN_STICKLEFT) {
pad->stick_x = -128;
} else if (dwPressedButtons[slot] & BTN_STICKRIGHT) {
pad->stick_x = 127;
}
} else {
padToBuffer.stick_x = getLeftStickX(virtualSlot);
pad->stick_x = wStickX;
}
if (getLeftStickY(virtualSlot) == 0) {
if (getPressedButtons(virtualSlot) & BTN_STICKDOWN) {
padToBuffer.stick_y = -128;
} else if (getPressedButtons(virtualSlot) & BTN_STICKUP) {
padToBuffer.stick_y = 127;
if (wStickY == 0) {
if (dwPressedButtons[slot] & BTN_STICKDOWN) {
pad->stick_y = -128;
} else if (dwPressedButtons[slot] & BTN_STICKUP) {
pad->stick_y = 127;
}
} else {
padToBuffer.stick_y = getLeftStickY(virtualSlot);
pad->stick_y = wStickY;
}
// Stick Inputs
if (getRightStickX(virtualSlot) == 0) {
if (getPressedButtons(virtualSlot) & BTN_VSTICKLEFT) {
padToBuffer.right_stick_x = -128;
} else if (getPressedButtons(virtualSlot) & BTN_VSTICKRIGHT) {
padToBuffer.right_stick_x = 127;
if (wCamX == 0) {
if (dwPressedButtons[slot] & BTN_VSTICKLEFT) {
pad->cam_x = -128 * 10.0f;
} else if (dwPressedButtons[slot] & BTN_VSTICKRIGHT) {
pad->cam_x = 127 * 10.0f;
}
} else {
padToBuffer.right_stick_x = getRightStickX(virtualSlot);
pad->cam_x = wCamX;
}
if (getRightStickY(virtualSlot) == 0) {
if (getPressedButtons(virtualSlot) & BTN_VSTICKDOWN) {
padToBuffer.right_stick_y = -128;
} else if (getPressedButtons(virtualSlot) & BTN_VSTICKUP) {
padToBuffer.right_stick_y = 127;
if (wCamY == 0) {
if (dwPressedButtons[slot] & BTN_VSTICKDOWN) {
pad->cam_y = -128 * 10.0f;
} else if (dwPressedButtons[slot] & BTN_VSTICKUP) {
pad->cam_y = 127 * 10.0f;
}
} else {
padToBuffer.right_stick_y = getRightStickY(virtualSlot);
pad->cam_y = wCamY;
}
// Gyro
padToBuffer.gyro_x = getGyroX(virtualSlot);
padToBuffer.gyro_y = getGyroY(virtualSlot);
padBuffer.push_front(padToBuffer);
if (pad != nullptr) {
auto &padFromBuffer = padBuffer[std::min(padBuffer.size() - 1, (size_t)CVar_GetS32("gSimulatedInputLag", 0))];
pad->button |= padFromBuffer.button;
if (pad->stick_x == 0) pad->stick_x = padFromBuffer.stick_x;
if (pad->stick_y == 0) pad->stick_y = padFromBuffer.stick_y;
if (pad->gyro_x == 0) pad->gyro_x = padFromBuffer.gyro_x;
if (pad->gyro_y == 0) pad->gyro_y = padFromBuffer.gyro_y;
if (pad->right_stick_x == 0) pad->right_stick_x = padFromBuffer.right_stick_x;
if (pad->right_stick_y == 0) pad->right_stick_y = padFromBuffer.right_stick_y;
}
while (padBuffer.size() > 6) {
padBuffer.pop_back();
}
pad->gyro_x = wGyroX;
pad->gyro_y = wGyroY;
}
void Controller::SetButtonMapping(int32_t virtualSlot, int32_t n64Button, int32_t dwScancode) {
std::map<int32_t, int32_t>& Mappings = getProfile(virtualSlot)->Mappings;
void Controller::SetButtonMapping(int slot, int32_t n64Button, int32_t dwScancode) {
std::map<int32_t, int32_t>& Mappings = profiles[slot].Mappings;
std::erase_if(Mappings, [n64Button](const std::pair<int32_t, int32_t>& bin) { return bin.second == n64Button; });
Mappings[dwScancode] = n64Button;
}
int8_t& Controller::getLeftStickX(int32_t virtualSlot) {
return ButtonData[virtualSlot]->leftStickX;
}
int8_t& Controller::getLeftStickY(int32_t virtualSlot) {
return ButtonData[virtualSlot]->leftStickY;
}
int8_t& Controller::getRightStickX(int32_t virtualSlot) {
return ButtonData[virtualSlot]->rightStickX;
}
int8_t& Controller::getRightStickY(int32_t virtualSlot) {
return ButtonData[virtualSlot]->rightStickY;
}
int32_t& Controller::getPressedButtons(int32_t virtualSlot) {
return ButtonData[virtualSlot]->pressedButtons;
}
float& Controller::getGyroX(int32_t virtualSlot) {
return ButtonData[virtualSlot]->gyroX;
}
float& Controller::getGyroY(int32_t virtualSlot) {
return ButtonData[virtualSlot]->gyroY;
}
std::shared_ptr<DeviceProfile> Controller::getProfile(int32_t virtualSlot) {
return profiles[virtualSlot];
}
std::shared_ptr<ControllerAttachment> Controller::GetAttachment() {
return Attachment;
}
bool Controller::IsRumbling() {
return isRumbling;
}
std::string Controller::GetGuid() {
return GUID;
}
}
+49 -58
View File
@@ -3,88 +3,79 @@
#include <map>
#include <memory>
#include <string>
#include <cstdint>
#include <queue>
#include "stdint.h"
#include "UltraController.h"
#include "ControllerAttachment.h"
#include <vector>
#include <unordered_map>
#define EXTENDED_SCANCODE_BIT (1 << 8)
#define AXIS_SCANCODE_BIT (1 << 9)
namespace Ship {
enum GyroData {
DRIFT_X,
DRIFT_Y,
GYRO_SENSITIVITY
};
enum DeviceProfileVersion {
DEVICE_PROFILE_VERSION_V0 = 0,
DEVICE_PROFILE_VERSION_V1 = 1
enum ControllerThresholds {
LEFT_STICK = 1,
RIGHT_STICK = 2,
LEFT_TRIGGER = 3,
RIGHT_TRIGGER = 4,
DRIFT_X = 5,
DRIFT_Y = 6,
SENSITIVITY = 7,
GYRO_SENSITIVITY = 8
};
#define DEVICE_PROFILE_CURRENT_VERSION DEVICE_PROFILE_VERSION_V1
struct DeviceProfile {
int32_t Version = 0;
bool UseRumble = false;
bool UseGyro = false;
float RumbleStrength = 1.0f;
std::unordered_map<int32_t, float> AxisDeadzones;
std::unordered_map<int32_t, float> AxisMinimumPress;
std::unordered_map<int32_t, float> GyroData;
std::unordered_map<ControllerThresholds, float> Thresholds;
std::map<int32_t, int32_t> Mappings;
};
class Controller {
public:
virtual ~Controller() = default;
Controller();
virtual void ReadFromSource(int32_t virtualSlot) = 0;
virtual void WriteToSource(int32_t virtualSlot, ControllerCallback* controller) = 0;
virtual bool Connected() const = 0;
virtual bool CanRumble() const = 0;
virtual bool CanGyro() const = 0;
virtual void CreateDefaultBinding(int32_t virtualSlot) = 0;
virtual void ClearRawPress() = 0;
virtual int32_t ReadRawPress() = 0;
virtual const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) = 0;
virtual const std::string GetControllerName() = 0;
void Read(OSContPad* pad, int32_t virtualSlot);
void SetButtonMapping(int32_t virtualSlot, int32_t n64Button, int32_t dwScancode);
std::shared_ptr<ControllerAttachment> GetAttachment();
std::shared_ptr<DeviceProfile> getProfile(int32_t virtualSlot);
int8_t& getLeftStickX(int32_t virtualSlot);
int8_t& getLeftStickY(int32_t virtualSlot);
int8_t& getRightStickX(int32_t virtualSlot);
int8_t& getRightStickY(int32_t virtualSlot);
int32_t& getPressedButtons(int32_t virtualSlot);
float& getGyroX(int32_t virtualSlot);
float& getGyroY(int32_t virtualSlot);
bool IsRumbling();
std::string GetGuid();
public:
virtual ~Controller() = default;
Controller();
void Read(OSContPad* pad, int32_t slot);
virtual void ReadFromSource(int32_t slot) = 0;
virtual void WriteToSource(int32_t slot, ControllerCallback* controller) = 0;
virtual bool Connected() const = 0;
virtual bool CanRumble() const = 0;
virtual bool CanGyro() const = 0;
virtual void CreateDefaultBinding(int32_t slot) = 0;
bool isRumbling;
std::vector<DeviceProfile> profiles;
virtual void ClearRawPress() = 0;
virtual int32_t ReadRawPress() = 0;
void SetButtonMapping(int slot, int32_t n64Button, int32_t dwScancode);
std::shared_ptr<ControllerAttachment> GetAttachment() { return Attachment; }
std::string GetGuid() { return GUID; }
virtual const char* GetButtonName(int slot, int n64Button) = 0;
virtual const char* GetControllerName() = 0;
int8_t wStickX;
int8_t wStickY;
float wGyroX;
float wGyroY;
float wCamX;
float wCamY;
protected:
std::shared_ptr<ControllerAttachment> Attachment;
std::vector<int32_t> dwPressedButtons;
std::string GUID;
bool isRumbling;
void LoadBinding();
private:
struct Buttons {
int32_t pressedButtons = 0;
int8_t leftStickX = 0;
int8_t leftStickY = 0;
int8_t rightStickX = 0;
int8_t rightStickY = 0;
float gyroX = 0.0f;
float gyroY = 0.0f;
};
std::unordered_map<int32_t, std::shared_ptr<DeviceProfile>> profiles;
std::unordered_map<int32_t, std::shared_ptr<Buttons>> ButtonData = {};
std::deque<OSContPad> padBuffer;
std::shared_ptr<ControllerAttachment> Attachment;
};
struct ControllerEntry {
uint8_t* controllerBits;
Controller* entryIO;
};
}
+159 -278
View File
@@ -2,94 +2,6 @@
#include "Utils/StringHelper.h"
#include "CrashHandler.h"
#include "Window.h"
#include "ResourceMgr.h"
#include "GameVersions.h"
#include "Cvar.h"
#define WRITE_VAR_LINE(buff, len, varName, varValue) \
append_str(buff, len, varName); \
append_line(buff, len, varValue);
#define WRITE_VAR(buff, len, varName, varValue) \
append_str(buff, len, varName); \
append_str(buff, len, varValue);
extern "C" void DeinitOTR(void);
static CrashHandlerCallback sCallbackFunc = nullptr;
static const char* GetGameVersionString() {
if(Ship::Window::GetInstance()->GetResourceManager()->IsRunning()) {
uint32_t version = Ship::Window::GetInstance()->GetResourceManager()->GetGameVersion();
switch (version) {
case OOT_NTSC_10:
return "NTSC 1.0";
case OOT_NTSC_11:
return "NTSC 1.1";
case OOT_NTSC_12:
return "NTSC 1.2";
case OOT_PAL_10:
return "PAL 1.0";
case OOT_PAL_11:
return "PAL 1.1";
case OOT_NTSC_JP_GC_CE:
return "NTSC JP_GC_CE";
case OOT_NTSC_JP_GC:
return "NTSC_JP_GC";
case OOT_NTSC_US_GC:
return "NTSC_US_GC";
case OOT_PAL_GC:
return "PAL_GC";
case OOT_NTSC_JP_MQ:
return "NTSC_JP_MQ";
case OOT_NTSC_US_MQ:
return "NTSC_US_MQ";
case OOT_PAL_MQ:
return "PAL_MQ";
case OOT_PAL_GC_DBG1:
return "DBG_1";
case OOT_PAL_GC_DBG2:
return "DBG_2";
case OOT_PAL_GC_MQ_DBG:
return "MQ_DBG";
case OOT_IQUE_TW:
return "IQUE_TW";
case OOT_IQUE_CN:
return "IQUE_CN";
case OOT_UNKNOWN:
return "UNKNOWN";
}
}
return "ResourceMGR not ready";
}
static void append_str(char* buf, size_t* len, const char* str) {
while (*str != '\0')
buf[(*len)++] = *str++;
}
static void append_line(char* buf, size_t* len, const char* str) {
while (*str != '\0')
buf[(*len)++] = *str++;
buf[(*len)++] = '\n';
}
/**
* @brief Prints common data relevant to the crash
*
* @param buffer
*/
static void CrashHandler_PrintCommon(char* buffer, size_t* curBufferPos) {
WRITE_VAR_LINE(buffer, curBufferPos, "OTR Generated with: ", GetGameVersionString());
if (sCallbackFunc != nullptr) {
sCallbackFunc(buffer, curBufferPos);
}
SPDLOG_CRITICAL(buffer);
}
#if defined(__linux__)
#include <csignal>
@@ -98,106 +10,100 @@ static void CrashHandler_PrintCommon(char* buffer, size_t* curBufferPos) {
#include <dlfcn.h> // for dladdr
#include <execinfo.h>
#include <unistd.h>
#include <SDL.h>
static void PrintRegisters(ucontext_t* ctx, char* buffer, size_t* pos) {
char regbuffer[128];
append_line(buffer, pos, "Registers:");
static void PrintRegisters(ucontext_t* ctx) {
char regbuffer[1024];
SPDLOG_CRITICAL("Registers:");
#if defined(__x86_64__)
snprintf(regbuffer, std::size(regbuffer), "RAX: 0x%016llX", ctx->uc_mcontext.gregs[REG_RAX]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "RDI: 0x%016llX", ctx->uc_mcontext.gregs[REG_RDI]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "RSI: 0x%016llX", ctx->uc_mcontext.gregs[REG_RSI]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "RDX: 0x%016llX", ctx->uc_mcontext.gregs[REG_RDX]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "RCX: 0x%016llX", ctx->uc_mcontext.gregs[REG_RCX]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "R8: 0x%016llX", ctx->uc_mcontext.gregs[REG_R8]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "R9: 0x%016llX", ctx->uc_mcontext.gregs[REG_R9]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "R10: 0x%016llX", ctx->uc_mcontext.gregs[REG_R10]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "R11: 0x%016llX", ctx->uc_mcontext.gregs[REG_R11]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "RSP: 0x%016llX", ctx->uc_mcontext.gregs[REG_RSP]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "RBX: 0x%016llX", ctx->uc_mcontext.gregs[REG_RBX]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "RBP: 0x%016llX", ctx->uc_mcontext.gregs[REG_RBP]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "R12: 0x%016llX", ctx->uc_mcontext.gregs[REG_R12]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "R13: 0x%016llX", ctx->uc_mcontext.gregs[REG_R13]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "R14: 0x%016llX", ctx->uc_mcontext.gregs[REG_R14]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "R15: 0x%016llX", ctx->uc_mcontext.gregs[REG_R15]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "RIP: 0x%016llX", ctx->uc_mcontext.gregs[REG_RIP]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "EFL: 0x%016llX", ctx->uc_mcontext.gregs[REG_EFL]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RAX]);
SPDLOG_CRITICAL("RAX: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RDI]);
SPDLOG_CRITICAL("RDI: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RSI]);
SPDLOG_CRITICAL("RSI: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RDX]);
SPDLOG_CRITICAL("RDX: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RCX]);
SPDLOG_CRITICAL("RCX: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_R8]);
SPDLOG_CRITICAL("R8 : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_R9]);
SPDLOG_CRITICAL("R9 : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_R10]);
SPDLOG_CRITICAL("R10: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_R11]);
SPDLOG_CRITICAL("R11: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RSP]);
SPDLOG_CRITICAL("RSP: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RBX]);
SPDLOG_CRITICAL("RBX: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RBP]);
SPDLOG_CRITICAL("RBP: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_R12]);
SPDLOG_CRITICAL("R12: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_R13]);
SPDLOG_CRITICAL("R13: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_R14]);
SPDLOG_CRITICAL("R14: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_R15]);
SPDLOG_CRITICAL("R15: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_RIP]);
SPDLOG_CRITICAL("RIP: {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer), "0x%016llX", ctx->uc_mcontext.gregs[REG_EFL]);
SPDLOG_CRITICAL("EFLAGS: {} ", regbuffer);
#else
snprintf(regbuffer, std::size(regbuffer),"EDI: 0x%08lX", ctx->uc_mcontext.gregs[REG_EDI]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"ESI: 0x%08lX", ctx->uc_mcontext.gregs[REG_ESI]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"EBP: 0x%08lX", ctx->uc_mcontext.gregs[REG_EBP]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"ESP: 0x%08lX", ctx->uc_mcontext.gregs[REG_ESP]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"EBX: 0x%08lX", ctx->uc_mcontext.gregs[REG_EBX]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"EDX: 0x%08lX", ctx->uc_mcontext.gregs[REG_EDX]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"ECX: 0x%08lX", ctx->uc_mcontext.gregs[REG_ECX]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"EAX: 0x%08lX", ctx->uc_mcontext.gregs[REG_EAX]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"EIP: 0x%08lX", ctx->uc_mcontext.gregs[REG_EIP]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"EFL: 0x%08lX", ctx->uc_mcontext.gregs[REG_EFL]);
append_line(buffer, pos, regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_EDI]);
SPDLOG_CRITICAL("EDI : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_ESI]);
SPDLOG_CRITICAL("ESI : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_EBP]);
SPDLOG_CRITICAL("EBP : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_ESP]);
SPDLOG_CRITICAL("ESP : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_EBX]);
SPDLOG_CRITICAL("EBX : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_EDX]);
SPDLOG_CRITICAL("EDX : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_ECX]);
SPDLOG_CRITICAL("ECX : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_EAX]);
SPDLOG_CRITICAL("EAX : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_EIP]);
SPDLOG_CRITICAL("EIP : {} ", regbuffer);
snprintf(regbuffer, std::size(regbuffer),"0x%08lX", ctx->uc_mcontext.gregs[REG_EFL]);
SPDLOG_CRITICAL("EFL : {} ", regbuffer);
#endif
}
static void ErrorHandler(int sig, siginfo_t* sigInfo, void* data) {
constexpr size_t MAX_BUFF_SIZE = 32768;
size_t curBufferPos = 0;
char buffer[MAX_BUFF_SIZE];
char intToCharBuffer[16];
std::array<void*, 4096> arr;
ucontext_t* ctx = static_cast<ucontext_t*>(data);
constexpr size_t nMaxFrames = arr.size();
size_t size = backtrace(arr.data(), nMaxFrames);
char** symbols = backtrace_symbols(arr.data(), nMaxFrames);
snprintf(intToCharBuffer, sizeof(intToCharBuffer), "Signal: %i", sig);
append_line(buffer, &curBufferPos, intToCharBuffer);
SPDLOG_CRITICAL("(Signal: {})", sig);
switch (sig) {
case SIGILL:
append_line(buffer, &curBufferPos, "ILLEGAL INSTRUCTION");
SPDLOG_CRITICAL("ILLEGAL INSTRUCTION");
break;
case SIGABRT:
append_line(buffer, &curBufferPos, "ABORT");
SPDLOG_CRITICAL("ABORT");
break;
case SIGFPE:
append_line(buffer, &curBufferPos, "ERRONEUS ARITHEMETIC OPERATION");
SPDLOG_CRITICAL("ERRONEUS ARITHEMETIC OPERATION");
break;
case SIGSEGV:
append_line(buffer, &curBufferPos, "INVALID ACCESS TO STORAGE");
SPDLOG_CRITICAL("INVALID ACCESS TO STORAGE");
break;
}
PrintRegisters(ctx, buffer, &curBufferPos);
PrintRegisters(ctx);
append_line(buffer, &curBufferPos, "Traceback:");
SPDLOG_CRITICAL("Traceback:");
for (size_t i = 1; i < size; i++) {
Dl_info info;
int gotAddress = dladdr(arr[i], &info);
@@ -224,115 +130,130 @@ static void ErrorHandler(int sig, siginfo_t* sigInfo, void* data) {
(char*)arr[i] - (char*)info.dli_saddr);
free(demangled);
}
snprintf(intToCharBuffer, sizeof(intToCharBuffer), "%i ", (int)i);
WRITE_VAR_LINE(buffer, &curBufferPos, intToCharBuffer, functionName.c_str());
}
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "SoH has crashed", "SoH Has crashed. Please upload the logs to the support channel in discord.", nullptr);
free(symbols);
CrashHandler_PrintCommon(buffer, &curBufferPos);
DeinitOTR();
Ship::Window::GetInstance()->GetLogger()->flush();
spdlog::shutdown();
SPDLOG_CRITICAL("{} {}", i, functionName.c_str());
}
free(symbols);
//DeinitOTR();
exit(1);
}
static void ShutdownHandler(int sig, siginfo_t* sigInfo, void* data) {
DeinitOTR();
//DeinitOTR();
exit(1);
}
extern "C" void SetupHandlerLinux() {
struct sigaction action;
struct sigaction shutdownAction;
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = ErrorHandler;
sigaction(SIGILL, &action, nullptr);
sigaction(SIGABRT, &action, nullptr);
sigaction(SIGFPE, &action, nullptr);
sigaction(SIGSEGV, &action, nullptr);
shutdownAction.sa_flags = SA_SIGINFO;
shutdownAction.sa_sigaction = ShutdownHandler;
sigaction(SIGINT, &shutdownAction, nullptr);
sigaction(SIGTERM, &shutdownAction, nullptr);
sigaction(SIGQUIT, &shutdownAction, nullptr);
sigaction(SIGKILL, &shutdownAction, nullptr);
}
#elif _WIN32
#if defined(_WIN32) && !defined(_WIN64)
#define WINDOWS_32_BIT
#endif
static void PrintRegisters(CONTEXT* ctx, char* buffer, size_t* pos) {
append_line(buffer, pos, "Registers: ");
char regBuff[25];
static void PrintRegisters(CONTEXT* ctx) {
SPDLOG_CRITICAL("Register dump");
char regBuff[50];
#if defined(_M_AMD64)
sprintf_s(regBuff, std::size(regBuff), "RAX: 0x%016llX", ctx->Rax);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rax);
SPDLOG_CRITICAL("RAX: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "RCX: 0x%016llX", ctx->Rcx);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rcx);
SPDLOG_CRITICAL("RCX: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "RDX: 0x%016llX", ctx->Rdx);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rdx);
SPDLOG_CRITICAL("RDX: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "RBX: 0x%016llX", ctx->Rbx);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rbx);
SPDLOG_CRITICAL("RBX: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "RSP: 0x%016llX", ctx->Rsp);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rsp);
SPDLOG_CRITICAL("RSP: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "RBP: 0x%016llX", ctx->Rbp);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rbp);
SPDLOG_CRITICAL("RBP: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "RSI: 0x%016llX", ctx->Rsi);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rsi);
SPDLOG_CRITICAL("RSI: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "RDI: 0x%016llX", ctx->Rdi);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rdi);
SPDLOG_CRITICAL("RDI: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "R9: 0x%016llX", ctx->R9);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->R9);
SPDLOG_CRITICAL("R9: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "R10: 0x%016llX", ctx->R10);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->R10);
SPDLOG_CRITICAL("R10: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "R11: 0x%016llX", ctx->R11);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->R11);
SPDLOG_CRITICAL("R11: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "R12: 0x%016llX", ctx->R12);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->R12);
SPDLOG_CRITICAL("R12: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "R13: 0x%016llX", ctx->R13);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->R13);
SPDLOG_CRITICAL("R13: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "R14: 0x%016llX", ctx->R14);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->R14);
SPDLOG_CRITICAL("R14: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "R15: 0x%016llX", ctx->R15);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->R15);
SPDLOG_CRITICAL("R15: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "RIP: 0x%016llX", ctx->Rip);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%016llX", ctx->Rip);
SPDLOG_CRITICAL("RIP: {}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "EFLAGS: 0x%08lX", ctx->EFlags);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->EFlags);
SPDLOG_CRITICAL("EFLAGS: {}", regBuff);
#elif WINDOWS_32_BIT
sprintf_s(regBuff, std::size(regBuff), "EDI: 0x%08lX", ctx->Edi);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->Edi);
SPDLOG_CRITICAL("EDI: 0x{}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "ESI: 0x%08lX", ctx->Esi);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->Esi);
SPDLOG_CRITICAL("ESI: 0x{}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "EBX: 0x%08lX", ctx->Ebx);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->Ebx);
SPDLOG_CRITICAL("EBX: 0x{}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "ECX: 0x%08lX", ctx->Ecx);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->Ecx);
SPDLOG_CRITICAL("ECX: 0x{}", ctx->Ecx);
sprintf_s(regBuff, std::size(regBuff), "EAX: 0x%08lX", ctx->Eax);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->Eax);
SPDLOG_CRITICAL("EAX: 0x{}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "EBP: 0x%08lX", ctx->Ebp);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->Ebp);
SPDLOG_CRITICAL("EBP: 0x{}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "ESP: 0x%08lX", ctx->Esp);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->Esp);
SPDLOG_CRITICAL("ESP: 0x{}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "EFLAGS: 0x%08lX", ctx->EFlags);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->EFlags);
SPDLOG_CRITICAL("EFLAGS: 0x{}", regBuff);
sprintf_s(regBuff, std::size(regBuff), "EIP: 0x%08lX", ctx->Eip);
append_line(buffer, pos, regBuff);
snprintf(regBuff, std::size(regBuff), "0x%08lX", ctx->Eip);
SPDLOG_CRITICAL("EIP: 0x{}", regBuff);
#endif
}
static void printStack(CONTEXT* ctx, char* logBuffer, size_t* pos) {
static void printStack(CONTEXT* ctx) {
BOOL result;
HANDLE process;
HANDLE thread;
@@ -363,7 +284,7 @@ static void printStack(CONTEXT* ctx, char* logBuffer, size_t* pos) {
CONTEXT ctx2;
memcpy(&ctx2, ctx, sizeof(CONTEXT));
PrintRegisters(&ctx2, logBuffer, pos);
PrintRegisters(&ctx2);
process = GetCurrentProcess();
thread = GetCurrentThread();
@@ -371,7 +292,6 @@ static void printStack(CONTEXT* ctx, char* logBuffer, size_t* pos) {
SymSetOptions(SYMOPT_NO_IMAGE_SEARCH | SYMOPT_IGNORE_IMAGEDIR);
SymInitialize(process, "debug", true);
constexpr DWORD machineType =
#if defined(_M_AMD64)
IMAGE_FILE_MACHINE_AMD64;
@@ -397,16 +317,12 @@ static void printStack(CONTEXT* ctx, char* logBuffer, size_t* pos) {
line.SizeOfStruct = sizeof(IMAGEHLP_LINE);
#endif
if (SymGetLineFromAddr(process, stack.AddrPC.Offset, &disp, &line)) {
char lineNumberStr[16];
sprintf_s(lineNumberStr, sizeof(lineNumberStr), "Line: %d", line.LineNumber);
append_str(logBuffer, pos, symbol->Name); append_str(logBuffer, pos, " in "); append_str(logBuffer, pos, line.FileName); append_line(logBuffer, pos, lineNumberStr);
//SPDLOG_CRITICAL("{} in {}: line: {}: ", symbol->Name, line.FileName, line.LineNumber);
SPDLOG_CRITICAL("{} in {}: line: {}: ", symbol->Name, line.FileName, line.LineNumber);
}
else {
char addrString[20];
sprintf_s(addrString, std::size(addrString), "0x%016llX", symbol->Address);
WRITE_VAR(logBuffer, pos, "At ", symbol->Name); WRITE_VAR_LINE(logBuffer, pos, "Addr: ", addrString);
//SPDLOG_CRITICAL("at {}, addr 0x{}", symbol->Name, addrString);
char addrString[25];
snprintf(addrString, std::size(addrString), "0x%016llX", symbol->Address);
SPDLOG_CRITICAL("at {}, addr 0x{}", symbol->Name, addrString);
hModule = nullptr;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCTSTR)(stack.AddrPC.Offset), &hModule);
@@ -414,59 +330,24 @@ static void printStack(CONTEXT* ctx, char* logBuffer, size_t* pos) {
if (hModule != nullptr) {
GetModuleFileNameA(hModule, module, sizeof(module));
}
WRITE_VAR_LINE(logBuffer, pos, "In: ", module);
// SPDLOG_CRITICAL("In {}", module);
SPDLOG_CRITICAL("In {}", module);
}
}
CrashHandler_PrintCommon(logBuffer, pos);
Ship::Window::GetInstance()->GetLogger()->flush();
Ship::GlobalCtx2::GetInstance()->GetLogger()->flush();
spdlog::shutdown();
DeinitOTR();
}
extern "C" LONG seh_filter(struct _EXCEPTION_POINTERS* ex) {
char exceptionString[20];
constexpr size_t MAX_BUFF_SIZE = 32768;
size_t curBufferPos = 0;
char buffer[MAX_BUFF_SIZE];
snprintf(exceptionString, std::size(exceptionString), "0x%x", ex->ExceptionRecord->ExceptionCode);
WRITE_VAR_LINE(buffer, &curBufferPos, "Exception: ", exceptionString);
printStack(ex->ContextRecord, buffer, &curBufferPos);
MessageBoxA(nullptr, "SoH Has crashed. Please upload the logs to the support channel in discord.", "Crash", MB_OK | MB_ICONERROR);
CrashHandler_PrintCommon(buffer, &curBufferPos);
SPDLOG_CRITICAL("EXCEPTION {} occurred", exceptionString);
printStack(ex->ContextRecord);
MessageBox(nullptr, L"SoH Has crashed. Please upload the logs to the support channel in discord.", L"Crash", MB_OK | MB_ICONERROR);
return EXCEPTION_EXECUTE_HANDLER;
}
#endif
extern "C" void CrashHandler_Init(CrashHandlerCallback callback) {
#if defined(__linux__)
struct sigaction action;
struct sigaction shutdownAction;
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = ErrorHandler;
sigaction(SIGILL, &action, nullptr);
sigaction(SIGABRT, &action, nullptr);
sigaction(SIGFPE, &action, nullptr);
sigaction(SIGSEGV, &action, nullptr);
shutdownAction.sa_flags = SA_SIGINFO;
shutdownAction.sa_sigaction = ShutdownHandler;
sigaction(SIGINT, &shutdownAction, nullptr);
sigaction(SIGTERM, &shutdownAction, nullptr);
sigaction(SIGQUIT, &shutdownAction, nullptr);
sigaction(SIGKILL, &shutdownAction, nullptr);
#elif _WIN32
SetUnhandledExceptionFilter(seh_filter);
#endif
sCallbackFunc = callback;
}
+10 -5
View File
@@ -1,21 +1,26 @@
#ifndef CRASH_HANDLER_H
#define CRASH_HANDLER_H
#include <stddef.h>
typedef void(*CrashHandlerCallback)(char*, size_t*);
#ifdef __linux__
#ifdef __cplusplus
extern "C" {
#endif
void CrashHandler_Init(CrashHandlerCallback callback);
void SetupHandlerLinux(void);
#ifdef __cplusplus
}
#endif
#ifdef _WIN32
#elif _WIN32 // __linux__ ^^^^ _WIN32 vvvvv
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOGDI
#define NOGDI
#endif
#include <windows.h>
#include <DbgHelp.h>
+4 -505
View File
@@ -1,103 +1,4 @@
#include "Cutscene.h"
#include "spdlog/spdlog.h"
enum class CutsceneCommands
{
Cmd00 = 0x0000,
SetCameraPos = 0x0001,
SetCameraFocus = 0x0002,
SpecialAction = 0x0003,
SetLighting = 0x0004,
SetCameraPosLink = 0x0005,
SetCameraFocusLink = 0x0006,
Cmd07 = 0x0007,
Cmd08 = 0x0008,
Cmd09 = 0x0009,
Unknown = 0x001A,
Textbox = 0x0013,
SetActorAction0 = 0x000A,
SetActorAction1 = 0x000F,
SetActorAction2 = 0x000E,
SetActorAction3 = 0x0019,
SetActorAction4 = 0x001D,
SetActorAction5 = 0x001E,
SetActorAction6 = 0x002C,
SetActorAction7 = 0x001F,
SetActorAction8 = 0x0031,
SetActorAction9 = 0x003E,
SetActorAction10 = 0x008F,
SetSceneTransFX = 0x002D,
Nop = 0x000B,
PlayBGM = 0x0056,
StopBGM = 0x0057,
FadeBGM = 0x007C,
SetTime = 0x008C,
Terminator = 0x03E8,
End = 0xFFFF,
Error = 0xFEAF,
};
static inline uint32_t read_CMD_BBBB(BinaryReader* reader)
{
uint32_t v;
reader->Read((char*)&v, sizeof(uint32_t));
return v;
}
static inline uint32_t read_CMD_BBH(BinaryReader* reader)
{
uint32_t v;
reader->Read((char*)&v, sizeof(uint32_t));
// swap the half word to match endianness
if (reader->GetEndianness() != Endianness::Native)
{
uint8_t* b = (uint8_t*)&v;
uint8_t tmp = b[2];
b[2] = b[3];
b[3] = tmp;
}
return v;
}
static inline uint32_t read_CMD_HBB(BinaryReader* reader)
{
uint32_t v;
reader->Read((char*)&v, sizeof(uint32_t));
// swap the half word to match endianness
if (reader->GetEndianness() != Endianness::Native)
{
uint8_t* b = (uint8_t*)&v;
uint8_t tmp = b[0];
b[0] = b[1];
b[1] = tmp;
}
return v;
}
static inline uint32_t read_CMD_HH(BinaryReader* reader)
{
uint32_t v;
reader->Read((char*)&v, sizeof(uint32_t));
// swap the half words to match endianness
if (reader->GetEndianness() != Endianness::Native)
{
uint8_t* b = (uint8_t*)&v;
uint8_t tmp = b[0];
b[0] = b[1];
b[1] = tmp;
tmp = b[2];
b[2] = b[3];
b[3] = tmp;
}
return v;
}
void Ship::CutsceneV0::ParseFileBinary(BinaryReader* reader, Resource* res)
{
@@ -108,413 +9,11 @@ void Ship::CutsceneV0::ParseFileBinary(BinaryReader* reader, Resource* res)
uint32_t numEntries = reader->ReadUInt32();
cs->commands.reserve(numEntries);
uint32_t numCommands = reader->ReadUInt32();
cs->commands.push_back(numCommands);
// endFrame
cs->commands.push_back(reader->ReadUInt32());
while (true)
for (uint32_t i = 0; i < numEntries; i++)
{
uint32_t commandId = reader->ReadUInt32();
cs->commands.push_back(commandId);
uint32_t data = reader->ReadUInt32();
uint16_t opcode = data >> 16;
switch (commandId)
{
case (uint32_t)CutsceneCommands::SetCameraPos:
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
while (true)
{
uint32_t val = read_CMD_BBH(reader);
int8_t continueFlag = ((int8_t*)&val)[0];
cs->commands.push_back(val);
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
if (continueFlag == -1)
break;
}
}
break;
case (uint32_t)CutsceneCommands::SetCameraFocus:
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
while (true)
{
uint32_t val = read_CMD_BBH(reader);
int8_t continueFlag = ((int8_t*)&val)[0];
cs->commands.push_back(val);
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
if (continueFlag == -1)
break;
}
break;
}
case (uint32_t)CutsceneCommands::SpecialAction:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
}
break;
}
case (uint32_t)CutsceneCommands::SetLighting:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
}
break;
}
case (uint32_t)CutsceneCommands::SetCameraPosLink:
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
while (true)
{
uint32_t val = read_CMD_BBH(reader);
int8_t continueFlag = ((int8_t*)&val)[0];
cs->commands.push_back(val);
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
if (continueFlag == -1)
break;
}
break;
}
case (uint32_t)CutsceneCommands::SetCameraFocusLink:
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
while (true)
{
uint32_t val = read_CMD_BBH(reader);
int8_t continueFlag = ((int8_t*)&val)[0];
cs->commands.push_back(val);
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
if (continueFlag == -1)
break;
}
break;
}
case (uint32_t)CutsceneCommands::Cmd09:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HBB(reader));
cs->commands.push_back(read_CMD_BBH(reader));
}
break;
}
case 0x15:
case (uint32_t)CutsceneCommands::Unknown:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
}
}
break;
case (uint32_t)CutsceneCommands::Textbox:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
}
break;
}
case (uint32_t)CutsceneCommands::SetActorAction0:
case (uint32_t)CutsceneCommands::SetActorAction1:
case 17:
case 18:
case 23:
case 34:
case 39:
case 46:
case 76:
case 85:
case 93:
case 105:
case 107:
case 110:
case 119:
case 123:
case 138:
case 139:
case 144:
case (uint32_t)CutsceneCommands::SetActorAction2:
case 16:
case 24:
case 35:
case 40:
case 48:
case 64:
case 68:
case 70:
case 78:
case 80:
case 94:
case 116:
case 118:
case 120:
case 125:
case 131:
case 141:
case (uint32_t)CutsceneCommands::SetActorAction3:
case 36:
case 41:
case 50:
case 67:
case 69:
case 72:
case 74:
case 81:
case 106:
case 117:
case 121:
case 126:
case 132:
case (uint32_t)CutsceneCommands::SetActorAction4:
case 37:
case 42:
case 51:
case 53:
case 63:
case 65:
case 66:
case 75:
case 82:
case 108:
case 127:
case 133:
case (uint32_t)CutsceneCommands::SetActorAction5:
case 38:
case 43:
case 47:
case 54:
case 79:
case 83:
case 128:
case 135:
case (uint32_t)CutsceneCommands::SetActorAction6:
case 55:
case 77:
case 84:
case 90:
case 129:
case 136:
case (uint32_t)CutsceneCommands::SetActorAction7:
case 52:
case 57:
case 58:
case 88:
case 115:
case 130:
case 137:
case (uint32_t)CutsceneCommands::SetActorAction8:
case 60:
case 89:
case 111:
case 114:
case 134:
case 142:
case (uint32_t)CutsceneCommands::SetActorAction9:
case (uint32_t)CutsceneCommands::SetActorAction10:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
}
break;
}
case (uint32_t)CutsceneCommands::SetSceneTransFX:
{
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
break;
}
case (uint32_t)CutsceneCommands::PlayBGM:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
}
break;
}
case (uint32_t)CutsceneCommands::StopBGM:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
}
break;
}
case (uint32_t)CutsceneCommands::FadeBGM:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(reader->ReadUInt32());
}
break;
}
case (uint32_t)CutsceneCommands::SetTime:
{
uint32_t size = reader->ReadUInt32();
cs->commands.push_back(size);
for (uint32_t i = 0; i < size; i++)
{
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HBB(reader));
cs->commands.push_back(reader->ReadUInt32());
}
break;
}
case (uint32_t)CutsceneCommands::Terminator:
{
cs->commands.push_back(reader->ReadUInt32());
cs->commands.push_back(read_CMD_HH(reader));
cs->commands.push_back(read_CMD_HH(reader));
break;
}
case 0xFFFFFFFF: // CS_END
{
cs->commands.push_back(reader->ReadUInt32());
return;
}
default:
SPDLOG_TRACE("CutsceneV0: Unknown command {}\n", commandId);
// error?
break;
}
cs->commands.push_back(data);
}
}
+15 -187
View File
@@ -1,24 +1,24 @@
#include "Cvar.h"
#include <map>
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <utility>
#include <Utils/File.h>
#include "Window.h"
#include <PR/ultra64/gbi.h>
#include "imgui_internal.h"
std::map<std::string, std::unique_ptr<CVar>, std::less<>> cvars;
CVar* CVar_Get(const char* name) {
extern "C" CVar* CVar_Get(const char* name) {
auto it = cvars.find(name);
return (it != cvars.end()) ? it->second.get() : nullptr;
}
extern "C" int32_t CVar_GetS32(const char* name, int32_t defaultValue) {
extern "C" s32 CVar_GetS32(const char* name, s32 defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar) {
if (cvar->type == CVarType::S32)
if (cvar->type == CVAR_TYPE_S32)
return cvar->value.valueS32;
}
@@ -29,7 +29,7 @@ extern "C" float CVar_GetFloat(const char* name, float defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar) {
if (cvar->type == CVarType::Float)
if (cvar->type == CVAR_TYPE_FLOAT)
return cvar->value.valueFloat;
}
@@ -40,68 +40,28 @@ extern "C" const char* CVar_GetString(const char* name, const char* defaultValue
CVar* cvar = CVar_Get(name);
if (cvar) {
if (cvar->type == CVarType::String)
if (cvar->type == CVAR_TYPE_STRING)
return cvar->value.valueStr;
}
return defaultValue;
}
extern "C" Color_RGB8 CVar_GetRGB(const char* name, Color_RGB8 defaultValue)
{
Color_RGBA8 defaultValueRGBA;
defaultValueRGBA.r = defaultValue.r;
defaultValueRGBA.g = defaultValue.g;
defaultValueRGBA.b = defaultValue.b;
defaultValueRGBA.a = 255;
Color_RGBA8 cvarGet = CVar_GetRGBA(name, defaultValueRGBA);
Color_RGB8 result;
result.r = cvarGet.r;
result.g = cvarGet.g;
result.b = cvarGet.b;
return result;
}
extern "C" Color_RGBA8 CVar_GetRGBA(const char* name, Color_RGBA8 defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar != nullptr) {
if (cvar->type == CVarType::RGBA)
return cvar->value.valueRGBA;
}
return defaultValue;
}
extern "C" void CVar_SetRGBA(const char* name, Color_RGBA8 value)
{
extern "C" void CVar_SetS32(const char* name, s32 value) {
auto& cvar = cvars[name];
if (!cvar) {
cvar = std::make_unique<CVar>();
}
cvar->type = CVarType::RGBA;
cvar->value.valueRGBA = value;
}
extern "C" void CVar_SetS32(const char* name, int32_t value) {
auto& cvar = cvars[name];
if (!cvar) {
cvar = std::make_unique<CVar>();
}
cvar->type = CVarType::S32;
cvar->type = CVAR_TYPE_S32;
cvar->value.valueS32 = value;
}
extern "C" void CVar_SetFloat(const char* name, float value) {
void CVar_SetFloat(const char* name, float value) {
auto& cvar = cvars[name];
if (!cvar) {
cvar = std::make_unique<CVar>();
}
cvar->type = CVarType::Float;
cvar->type = CVAR_TYPE_FLOAT;
cvar->value.valueFloat = value;
}
@@ -110,20 +70,11 @@ extern "C" void CVar_SetString(const char* name, const char* value) {
if (!cvar) {
cvar = std::make_unique<CVar>();
}
cvar->type = CVarType::String;
#ifdef _MSC_VER
cvar->value.valueStr = _strdup(value);
#else
cvar->value.valueStr = strdup(value);
#endif
cvar->type = CVAR_TYPE_STRING;
cvar->value.valueStr = ImStrdup(value);
}
extern "C" void CVar_RegisterRGBA(const char* name, Color_RGBA8 defaultValue) {
if (!CVar_Get(name))
CVar_SetRGBA(name, defaultValue);
}
extern "C" void CVar_RegisterS32(const char* name, int32_t defaultValue) {
extern "C" void CVar_RegisterS32(const char* name, s32 defaultValue) {
if (!CVar_Get(name))
CVar_SetS32(name, defaultValue);
}
@@ -137,126 +88,3 @@ extern "C" void CVar_RegisterString(const char* name, const char* defaultValue)
if (!CVar_Get(name))
CVar_SetString(name, defaultValue);
}
template <typename Numeric> bool is_number(const std::string& s) {
Numeric n;
return ((std::istringstream(s) >> n >> std::ws).eof());
}
void CVar_LoadLegacy() {
auto cvarsConfig = Ship::Window::GetPathRelativeToAppDirectory("cvars.cfg");
if (File::Exists(cvarsConfig)) {
const auto lines = File::ReadAllLines(cvarsConfig);
for (const std::string& line : lines) {
std::vector<std::string> cfg = StringHelper::Split(line, " = ");
if (line.empty()) continue;
if (cfg.size() < 2) continue;
if (cfg[1].find("\"") == std::string::npos && (cfg[1].find("#") != std::string::npos))
{
std::string value(cfg[1]);
value.erase(std::remove_if(value.begin(), value.end(), [](char c) { return c == '#'; }), value.end());
auto splitTest = StringHelper::Split(value, "\r")[0];
uint32_t val = std::stoul(splitTest, nullptr, 16);
Color_RGBA8 clr;
clr.r = val >> 24;
clr.g = val >> 16;
clr.b = val >> 8;
clr.a = val & 0xFF;
CVar_SetRGBA(cfg[0].c_str(), clr);
}
if (cfg[1].find("\"") != std::string::npos) {
std::string value(cfg[1]);
value.erase(std::remove(value.begin(), value.end(), '\"'), value.end());
#ifdef _MSC_VER
CVar_SetString(cfg[0].c_str(), _strdup(value.c_str()));
#else
CVar_SetString(cfg[0].c_str(), strdup(value.c_str()));
#endif
}
if (is_number<float>(cfg[1])) {
CVar_SetFloat(cfg[0].c_str(), std::stof(cfg[1]));
}
if (is_number<int>(cfg[1])) {
CVar_SetS32(cfg[0].c_str(), std::stoi(cfg[1]));
}
}
fs::remove(cvarsConfig);
}
}
extern "C" void CVar_Load() {
std::shared_ptr<Mercury> pConf = Ship::Window::GetInstance()->GetConfig();
pConf->reload();
for (const auto& item : pConf->rjson["CVars"].items()) {
auto value = item.value();
switch (value.type()) {
case nlohmann::detail::value_t::array:
break;
case nlohmann::detail::value_t::object:
if (value["Type"].get<std::string>() == mercuryRGBAObjectType) {
Color_RGBA8 clr;
clr.r = value["R"].get<uint8_t>();
clr.g = value["G"].get<uint8_t>();
clr.b = value["B"].get<uint8_t>();
clr.a = value["A"].get<uint8_t>();
CVar_SetRGBA(item.key().c_str(), clr);
}
break;
case nlohmann::detail::value_t::string:
CVar_SetString(item.key().c_str(), value.get<std::string>().c_str());
break;
case nlohmann::detail::value_t::boolean:
CVar_SetS32(item.key().c_str(), value.get<bool>());
break;
case nlohmann::detail::value_t::number_unsigned:
case nlohmann::detail::value_t::number_integer:
CVar_SetS32(item.key().c_str(), value.get<int>());
break;
case nlohmann::detail::value_t::number_float:
CVar_SetFloat(item.key().c_str(), value.get<float>());
break;
default:;
}
if (item.key() == "gOpenMenuBar") {
int bp = 0;
}
}
CVar_LoadLegacy();
}
extern "C" void CVar_Save()
{
std::shared_ptr<Mercury> pConf = Ship::Window::GetInstance()->GetConfig();
for (const auto& cvar : cvars) {
const std::string key = StringHelper::Sprintf("CVars.%s", cvar.first.c_str());
if (cvar.second->type == CVarType::String && cvar.second->value.valueStr != nullptr)
pConf->setString(key, std::string(cvar.second->value.valueStr));
else if (cvar.second->type == CVarType::S32)
pConf->setInt(key, cvar.second->value.valueS32);
else if (cvar.second->type == CVarType::Float)
pConf->setFloat(key, cvar.second->value.valueFloat);
else if (cvar.second->type == CVarType::RGBA)
{
auto keyStr = key.c_str();
Color_RGBA8 clr = cvar.second->value.valueRGBA;
pConf->setUInt(StringHelper::Sprintf("%s.R", keyStr), clr.r);
pConf->setUInt(StringHelper::Sprintf("%s.G", keyStr), clr.g);
pConf->setUInt(StringHelper::Sprintf("%s.B", keyStr), clr.b);
pConf->setUInt(StringHelper::Sprintf("%s.A", keyStr), clr.a);
pConf->setString(StringHelper::Sprintf("%s.Type", keyStr), mercuryRGBAObjectType);
}
}
pConf->save();
}
+15 -31
View File
@@ -1,55 +1,37 @@
#ifndef _CVAR_H
#define _CVAR_H
#include "color.h"
#include <stdint.h>
#include <PR/ultra64/gbi.h>
#ifdef __cplusplus
typedef enum class CVarType
{
S32,
Float,
String,
RGBA
} CVarType;
typedef enum CVarType { CVAR_TYPE_S32, CVAR_TYPE_FLOAT, CVAR_TYPE_STRING } CVarType;
typedef struct CVar {
const char* name;
CVarType type;
union {
int32_t valueS32;
s32 valueS32;
float valueFloat;
const char* valueStr;
Color_RGBA8 valueRGBA;
} value;
} CVar;
extern "C" CVar * CVar_Get(const char* name);
#endif
#ifdef __cplusplus
extern "C"
{
#endif
//#include <ultra64.h>
float CVar_GetFloat(const char* name, float defaultValue);
void CVar_SetFloat(const char* name, float value);
int32_t CVar_GetS32(const char* name, int32_t defaultValue);
void CVar_SetS32(const char* name, int32_t value);
const char* CVar_GetString(const char* name, const char* defaultValue);
void CVar_SetString(const char* name, const char* value);
Color_RGB8 CVar_GetRGB(const char* name, Color_RGB8 defaultValue);
Color_RGBA8 CVar_GetRGBA(const char* name, Color_RGBA8 defaultValue);
void CVar_SetRGBA(const char* name, Color_RGBA8 value);
CVar* CVar_Get(const char* name);
s32 CVar_GetS32(const char* name, s32 defaultValue);
float CVar_GetFloat(const char* name, float defaultValue);
const char* CVar_GetString(const char* name, const char* defaultValue);
void CVar_SetS32(const char* name, s32 value);
void CVar_SetString(const char* name, const char* value);
void CVar_RegisterS32(const char* name, int32_t defaultValue);
void CVar_RegisterFloat(const char* name, float defaultValue);
void CVar_RegisterString(const char* name, const char* defaultValue);
void CVar_RegisterRGBA(const char* name, Color_RGBA8 defaultValue);
void CVar_Load();
void CVar_Save();
void CVar_RegisterS32(const char* name, s32 defaultValue);
void CVar_RegisterFloat(const char* name, float defaultValue);
void CVar_RegisterString(const char* name, const char* defaultValue);
#ifdef __cplusplus
};
@@ -58,8 +40,10 @@ extern "C"
#ifdef __cplusplus
#include <map>
#include <string>
#include <functional>
#include <memory>
extern std::map<std::string, std::unique_ptr<CVar>, std::less<>> cvars;
void CVar_SetFloat(const char* name, float value);
#endif
#endif
@@ -0,0 +1,31 @@
#pragma once
#include <vector>
#include <optional>
#include "Controller.h"
class DisconnectedController final : public Ship::Controller {
public:
DisconnectedController() {
GUID = "Disconnected";
}
std::map<std::vector<std::string>, int32_t> ReadButtonPress();
void ReadFromSource(int32_t slot) override {}
const char* GetControllerName() override { return "Disconnected"; }
const char* GetButtonName(int slot, int n64Button) override { return "None"; }
void WriteToSource(int32_t slot, ControllerCallback* controller) override { }
bool Connected() const override { return false; }
bool CanRumble() const override { return false; }
bool CanGyro() const override { return false; }
void ClearRawPress() override {}
int32_t ReadRawPress() override { return -1; }
bool HasPadConf() const { return true; }
std::optional<std::string> GetPadConfSection() { return "Unk"; }
void CreateDefaultBinding(int32_t slot) override {}
protected:
std::string GetControllerType() { return "Unk"; }
std::string GetConfSection() { return "Unk"; }
std::string GetBindingConfSection() { return "Unk"; }
};
+12 -12
View File
@@ -14,25 +14,23 @@ namespace Ship
while (true)
{
uint32_t w0 = reader->ReadUInt32();
uint32_t w1 = reader->ReadUInt32();
uint64_t data = reader->ReadUInt64();
if (sizeof(uintptr_t) < 8){
dl->instructions.push_back(((uint64_t) w0 << 32) | w1);
dl->instructions.push_back(data);
uint8_t opcode = w0 >> 24;
uint8_t opcode = data >> 24;
// These are 128-bit commands, so read an extra 64 bits...
if (opcode == G_SETTIMG_OTR || opcode == G_DL_OTR || opcode == G_VTX_OTR || opcode == G_BRANCH_Z_OTR || opcode == G_MARKER || opcode == G_MTX_OTR) {
w0 = reader->ReadUInt32();
w1 = reader->ReadUInt32();
dl->instructions.push_back(((uint64_t) w0 << 32) | w1);
}
if (opcode == G_SETTIMG_OTR || opcode == G_DL_OTR || opcode == G_VTX_OTR || opcode == G_BRANCH_Z_OTR || opcode == G_MARKER || opcode == G_MTX_OTR)
dl->instructions.push_back(reader->ReadUInt64());
if (opcode == G_ENDDL)
break;
} else {
uint32_t w0 = (uint32_t)data;
uint32_t w1 = (uint32_t)(data >> 32);
dl->instructions.push_back(w0);
dl->instructions.push_back(w1);
@@ -40,8 +38,10 @@ namespace Ship
if (opcode == G_SETTIMG_OTR || opcode == G_DL_OTR || opcode == G_VTX_OTR || opcode == G_BRANCH_Z_OTR || opcode == G_MARKER || opcode == G_MTX_OTR)
{
w0 = reader->ReadUInt32();
w1 = reader->ReadUInt32();
data = reader->ReadUInt64();
w0 = (uint32_t)data;
w1 = (uint32_t)(data >> 32);
dl->instructions.push_back(w0);
dl->instructions.push_back(w1);
@@ -1,61 +0,0 @@
#include "DummyController.h"
namespace Ship {
DummyController::DummyController(const std::string& CUID, const std::string& KeyName, bool Connected) {
GUID = CUID;
isConnected = Connected;
ButtonName = KeyName;
}
void DummyController::ReadFromSource(int32_t virtualSlot) {
}
const std::string DummyController::GetControllerName() {
return GUID;
}
const std::string DummyController::GetButtonName(int32_t virtualSlot, int32_t n64Button) {
return ButtonName;
}
void DummyController::WriteToSource(int32_t virtualSlot, ControllerCallback* controller){
}
bool DummyController::Connected() const {
return isConnected;
}
bool DummyController::CanRumble() const {
return false;
}
bool DummyController::CanGyro() const {
return false;
}
void DummyController::CreateDefaultBinding(int32_t slot) {
}
std::string DummyController::GetControllerType() {
return "Unk";
}
std::string DummyController::GetConfSection() {
return "Unk";
}
std::string DummyController::GetBindingConfSection() {
return "Unk";
}
void DummyController::ClearRawPress() {
}
int32_t DummyController::ReadRawPress() {
return -1;
}
}
@@ -1,31 +0,0 @@
#pragma once
#include <vector>
#include <optional>
#include "Controller.h"
namespace Ship {
class DummyController final : public Controller {
public:
DummyController(const std::string& CUID, const std::string& KeyName, bool Connected);
std::map<std::vector<std::string>, int32_t> ReadButtonPress();
void ReadFromSource(int32_t virtualSlot) override;
const std::string GetControllerName() override;
const std::string GetButtonName(int32_t virtualSlot, int32_t n64Button) override;
void WriteToSource(int32_t slot, ControllerCallback* controller) override;
bool Connected() const override;
bool CanRumble() const override;
bool CanGyro() const override;
void ClearRawPress() override;
int32_t ReadRawPress() override;
bool HasPadConf() const;
std::optional<std::string> GetPadConfSection();
void CreateDefaultBinding(int32_t virtualSlot) override;
protected:
std::string ButtonName;
bool isConnected = false;
std::string GetControllerType();
std::string GetConfSection();
std::string GetBindingConfSection();
};
}
+15
View File
@@ -0,0 +1,15 @@
#include "Environment.h"
#include <map>
#include <string>
std::map<std::string, std::string> environmentVars;
namespace SohUtils {
void saveEnvironmentVar(const std::string& key, const std::string& value) {
environmentVars[key] = value;
}
std::string getEnvironmentVar(const std::string& key) {
return environmentVars[key];
}
}
+8
View File
@@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace SohUtils {
void saveEnvironmentVar(const std::string& key, const std::string& value);
std::string getEnvironmentVar(const std::string& key);
}
@@ -25,12 +25,12 @@ namespace Ship
auto memStream = std::make_shared<MemoryStream>(FileToLoad->buffer.get(), FileToLoad->dwBufferSize);
auto reader = std::make_shared<BinaryReader>(memStream);
Endianness endianness = (Endianness)reader->ReadByte();
Endianess endianess = (Endianess)reader->ReadByte();
for (int i = 0; i < 3; i++)
reader->ReadByte();
reader->SetEndianness(endianness);
// OTRTODO: Setup the binaryreader to use the resource's endianess
ResourceType resourceType = (ResourceType)reader->ReadUInt32();
Resource* result = nullptr;
+1 -2
View File
@@ -2,8 +2,7 @@
#include <string>
#include <memory>
#include <mutex>
#include <condition_variable>
#include "GlobalCtx2.h"
namespace Ship {
class Archive;
+213 -227
View File
@@ -4,236 +4,222 @@
#include "File.h"
#include "Archive.h"
#include "ResourceMgr.h"
#include "Console.h"
#include "ImGuiImpl.h"
#include "TextureMod.h"
#include "Lib/ImGui/imgui_internal.h"
#include "Utils/StringHelper.h"
namespace Ship {
bool GameOverlay::OverlayCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args) {
if (args.size() < 3) {
return CMD_FAILED;
}
if (CVar_Get(args[2].c_str()) != nullptr) {
const char* key = args[2].c_str();
GameOverlay* overlay = SohImGui::GetGameOverlay();
if (args[1] == "add") {
if (!overlay->RegisteredOverlays.contains(key)) {
overlay->RegisteredOverlays[key] = new Overlay({ OverlayType::TEXT, ImStrdup(key), -1.0f });
SohImGui::GetConsole()->SendInfoMessage("Added overlay: %s", key);
}
else {
SohImGui::GetConsole()->SendErrorMessage("Overlay already exists: %s", key);
}
}
else if (args[1] == "remove") {
if (overlay->RegisteredOverlays.contains(key)) {
overlay->RegisteredOverlays.erase(key);
SohImGui::GetConsole()->SendInfoMessage("Removed overlay: %s", key);
}
else {
SohImGui::GetConsole()->SendErrorMessage("Overlay not found: %s", key);
}
}
}
else {
SohImGui::GetConsole()->SendErrorMessage("CVar {} does not exist", args[2].c_str());
}
return CMD_SUCCESS;
}
void GameOverlay::LoadFont(const std::string& name, const std::string& path, float fontSize) {
ImGuiIO& io = ImGui::GetIO();
std::shared_ptr<Archive> base = Window::GetInstance()->GetResourceManager()->GetArchive();
std::shared_ptr<File> font = std::make_shared<File>();
base->LoadFile(path, false, font);
if (font->bIsLoaded) {
char* font_data = new char[font->dwBufferSize];
memcpy(font_data, font->buffer.get(), font->dwBufferSize);
Fonts[name] = io.Fonts->AddFontFromMemoryTTF(font_data, font->dwBufferSize, fontSize);
}
}
void GameOverlay::TextDraw(float x, float y, bool shadow, ImVec4 color, const char* fmt, ...) {
char buf[1024];
va_list args;
va_start(args, fmt);
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
va_end(args);
ImGui::PushStyleColor(ImGuiCol_Text, color);
ImGui::PushFont(Fonts[this->CurrentFont]);
if (shadow) {
ImGui::SetCursorPos(ImVec2(x + 1, y + 1));
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(.0f, .0f, .0f, color.w));
ImGui::Text(buf, args);
}
ImGui::PopStyleColor();
ImGui::SetCursorPos(ImVec2(x, y));
ImGui::Text(buf, args);
ImGui::PopFont();
ImGui::PopStyleColor();
}
void GameOverlay::TextDrawNotification(float duration, bool shadow, const char* fmt, ...) {
char buf[1024];
va_list args;
va_start(args, fmt);
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
va_end(args);
this->RegisteredOverlays[StringHelper::Sprintf("NotificationID:%d%d", rand(), this->RegisteredOverlays.size())] = new Overlay({ OverlayType::NOTIFICATION, ImStrdup(buf), duration, duration });
NeedsCleanup = true;
}
void GameOverlay::CleanupNotifications() {
if (!NeedsCleanup) return;
for (auto it = this->RegisteredOverlays.begin(); it != this->RegisteredOverlays.end(); ) {
if (it->second->type == OverlayType::NOTIFICATION && it->second->duration <= 0.0f) {
it = this->RegisteredOverlays.erase(it);
}
else {
++it;
}
}
NeedsCleanup = false;
}
float GameOverlay::GetScreenWidth() {
const ImGuiViewport* viewport = ImGui::GetMainViewport();
return viewport->Size.x;
}
float GameOverlay::GetScreenHeight() {
const ImGuiViewport* viewport = ImGui::GetMainViewport();
return viewport->Size.y;
}
float GameOverlay::GetStringWidth(const char* text) {
return CalculateTextSize(text).x;
}
ImVec2 GameOverlay::CalculateTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) {
ImGuiContext& g = *GImGui;
const char* text_display_end;
if (hide_text_after_double_hash)
text_display_end = ImGui::FindRenderedTextEnd(text, text_end); // Hide anything after a '##' string
else
text_display_end = text_end;
GameOverlay* overlay = SohImGui::GetGameOverlay();
ImFont* font = overlay->CurrentFont == "Default" ? g.Font : overlay->Fonts[overlay->CurrentFont];
const float font_size = font->FontSize;
if (text == text_display_end)
return ImVec2(0.0f, font_size);
ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
// Round
// FIXME: This has been here since Dec 2015 (7b0bf230) but down the line we want this out.
// FIXME: Investigate using ceilf or e.g.
// - https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
// - https://embarkstudios.github.io/rust-gpu/api/src/libm/math/ceilf.rs.html
text_size.x = IM_FLOOR(text_size.x + 0.99999f);
return text_size;
}
void GameOverlay::Init() {
this->LoadFont("Press Start 2P", "assets/ship_of_harkinian/fonts/PressStart2P-Regular.ttf", 12.0f);
this->LoadFont("Fipps", "assets/ship_of_harkinian/fonts/Fipps-Regular.otf", 32.0f);
const std::string DefaultFont = this->Fonts.begin()->first;
if (!this->Fonts.empty()) {
const std::string font = CVar_GetString("gOverlayFont", ImStrdup(DefaultFont.c_str()));
for (auto& [name, _] : this->Fonts) {
if (font.starts_with(name)) {
this->CurrentFont = name;
break;
}
this->CurrentFont = DefaultFont;
}
}
SohImGui::GetConsole()->AddCommand("overlay", { OverlayCommand, "Draw an overlay using a cvar value" });
}
void GameOverlay::DrawSettings() {
ImGui::Text("Overlays Text Font");
if (ImGui::BeginCombo("##TextFont", this->CurrentFont.c_str())) {
for (auto& [name, font] : this->Fonts) {
if (ImGui::Selectable(name.c_str(), name == this->CurrentFont)) {
this->CurrentFont = name;
CVar_SetString("gOverlayFont", ImStrdup(name.c_str()));
SohImGui::RequestCvarSaveOnNextTick();
}
}
ImGui::EndCombo();
}
}
void GameOverlay::Draw() {
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos, ImGuiCond_Always);
ImGui::SetNextWindowSize(viewport->Size, ImGuiCond_Always);
ImGui::Begin("SoHOverlay", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoInputs);
this->CleanupNotifications();
float textY = 50;
float notY = 0;
for (auto& [key, overlay] : this->RegisteredOverlays) {
if (overlay->type == OverlayType::TEXT) {
const char* text = ImStrdup(overlay->value);
const CVar* var = CVar_Get(text);
ImVec4 color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
switch (var->type) {
case CVarType::Float:
this->TextDraw(30, textY, true, color, "%s %.2f", text, var->value.valueFloat);
break;
case CVarType::S32:
this->TextDraw(30, textY, true, color, "%s %d", text, var->value.valueS32);
break;
case CVarType::String:
this->TextDraw(30, textY, true, color, "%s %s", text, var->value.valueStr);
break;
case CVarType::RGBA:
this->TextDraw(30, textY, true, color, "#%08X", text, var->value.valueRGBA);
break;
}
free((void*)text);
textY += 30;
}
if (overlay->type == OverlayType::NOTIFICATION && overlay->duration > 0) {
const char* text = overlay->value;
const float duration = overlay->duration / overlay->fadeTime;
const ImVec4 color = ImVec4(1.0f, 1.0f, 1.0f, duration);
#ifdef __WIIU__
const float textWidth = this->GetStringWidth(overlay->value) * 2.0f;
const float textOffset = 40.0f * 2.0f;
#else
const float textWidth = this->GetStringWidth(overlay->value);
const float textOffset = 40.0f;
#endif
this->TextDraw(GetScreenWidth() - textWidth - textOffset, GetScreenHeight() - textOffset - notY, true, color, text);
notY += 30;
overlay->duration -= .05f;
}
}
ImGui::End();
void Ship::GameOverlay::LoadFont(const std::string& name, const std::string& path, float fontSize) {
ImGuiIO& io = ImGui::GetIO();
std::shared_ptr<Archive> base = GlobalCtx2::GetInstance()->GetResourceManager()->GetArchive();
std::shared_ptr<File> font = std::make_shared<File>();
base->LoadFile(path, false, font);
if (font->bIsLoaded) {
char* font_data = new char[font->dwBufferSize];
memcpy(font_data, font->buffer.get(), font->dwBufferSize);
Fonts[name] = io.Fonts->AddFontFromMemoryTTF(font_data, font->dwBufferSize, fontSize);
}
}
void Ship::GameOverlay::TextDraw(float x, float y, bool shadow, ImVec4 color, const char* fmt, ...) {
char buf[1024];
va_list args;
va_start(args, fmt);
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
va_end(args);
ImGui::PushStyleColor(ImGuiCol_Text, color);
ImGui::PushFont(Fonts[this->CurrentFont]);
if (shadow) {
ImGui::SetCursorPos(ImVec2(x + 1, y + 1));
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(.0f, .0f, .0f, color.w));
ImGui::Text(buf, args);
}
ImGui::PopStyleColor();
ImGui::SetCursorPos(ImVec2(x, y));
ImGui::Text(buf, args);
ImGui::PopFont();
ImGui::PopStyleColor();
}
void Ship::GameOverlay::TextDrawNotification(float duration, bool shadow, const char* fmt, ...) {
char buf[1024];
va_list args;
va_start(args, fmt);
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
va_end(args);
this->RegisteredOverlays[StringHelper::Sprintf("NotificationID:%d%d", rand(), this->RegisteredOverlays.size())] = new Overlay({ OverlayType::NOTIFICATION, ImStrdup(buf), duration, duration });
NeedsCleanup = true;
}
void Ship::GameOverlay::CleanupNotifications() {
if(!NeedsCleanup) return;
for (auto it = this->RegisteredOverlays.begin(); it != this->RegisteredOverlays.end(); ) {
if (it->second->type == OverlayType::NOTIFICATION && it->second->duration <= 0.0f) {
it = this->RegisteredOverlays.erase(it);
} else {
++it;
}
}
NeedsCleanup = false;
}
float Ship::GameOverlay::GetScreenWidth() {
const ImGuiViewport* viewport = ImGui::GetMainViewport();
return viewport->Size.x;
}
float Ship::GameOverlay::GetScreenHeight() {
const ImGuiViewport* viewport = ImGui::GetMainViewport();
return viewport->Size.y;
}
float Ship::GameOverlay::GetStringWidth(const char* text) {
return CalculateTextSize(text).x;
}
ImVec2 Ship::GameOverlay::CalculateTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width) {
ImGuiContext& g = *GImGui;
const char* text_display_end;
if (hide_text_after_double_hash)
text_display_end = ImGui::FindRenderedTextEnd(text, text_end); // Hide anything after a '##' string
else
text_display_end = text_end;
GameOverlay* overlay = SohImGui::overlay;
ImFont* font = overlay->CurrentFont == "Default" ? g.Font : overlay->Fonts[overlay->CurrentFont];
const float font_size = font->FontSize;
if (text == text_display_end)
return ImVec2(0.0f, font_size);
ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
// Round
// FIXME: This has been here since Dec 2015 (7b0bf230) but down the line we want this out.
// FIXME: Investigate using ceilf or e.g.
// - https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
// - https://embarkstudios.github.io/rust-gpu/api/src/libm/math/ceilf.rs.html
text_size.x = IM_FLOOR(text_size.x + 0.99999f);
return text_size;
}
void Ship::GameOverlay::Init() {
this->LoadFont("Press Start 2P", "assets/ship_of_harkinian/fonts/PressStart2P-Regular.ttf", 12.0f);
this->LoadFont("Fipps", "assets/ship_of_harkinian/fonts/Fipps-Regular.otf", 32.0f);
const std::string DefaultFont = this->Fonts.begin()->first;
if(!this->Fonts.empty()) {
const std::string font = CVar_GetString("gOverlayFont", ImStrdup(DefaultFont.c_str()));
for (auto& [name, _] : this->Fonts) {
if (font.starts_with(name)) {
this->CurrentFont = name;
break;
}
this->CurrentFont = DefaultFont;
}
}
SohImGui::console->Commands["overlay"] = { OverlayCommand, "Draw an overlay using a cvar value" };
}
void Ship::GameOverlay::DrawSettings() {
ImGui::Text("Overlays Text Font");
if (ImGui::BeginCombo("##TextFont", this->CurrentFont.c_str())) {
for (auto& [name, font] : this->Fonts) {
if (ImGui::Selectable(name.c_str(), name == this->CurrentFont)) {
this->CurrentFont = name;
CVar_SetString("gOverlayFont", ImStrdup(name.c_str()));
SohImGui::needs_save = true;
}
}
ImGui::EndCombo();
}
}
void Ship::GameOverlay::Draw() {
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos, ImGuiCond_Always);
ImGui::SetNextWindowSize(viewport->Size, ImGuiCond_Always);
ImGui::Begin("SoHOverlay", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoInputs);
this->CleanupNotifications();
float textY = 50;
float notY = 0;
for (auto &[key, overlay] : this->RegisteredOverlays) {
if (overlay->type == OverlayType::TEXT) {
const char* text = ImStrdup(overlay->value);
const CVar* var = CVar_Get(text);
ImVec4 color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
switch (var->type) {
case CVAR_TYPE_FLOAT:
this->TextDraw(30, textY, true, color, "%s %.2f", text, var->value.valueFloat);
break;
case CVAR_TYPE_S32:
this->TextDraw(30, textY, true, color, "%s %d", text, var->value.valueS32);
break;
case CVAR_TYPE_STRING:
this->TextDraw(30, textY, true, color, "%s %s", text, var->value.valueStr);
break;
}
free((void*) text);
textY += 30;
}
if (overlay->type == OverlayType::NOTIFICATION && overlay->duration > 0) {
const char* text = overlay->value;
const float duration = overlay->duration / overlay->fadeTime;
const ImVec4 color = ImVec4(1.0f, 1.0f, 1.0f, duration);
const float textWidth = this->GetStringWidth(overlay->value);
this->TextDraw(GetScreenWidth() - textWidth - 40, GetScreenHeight() - 40 - notY, true, color, text);
notY += 30;
overlay->duration -= .05f;
}
}
ImGui::End();
}
bool Ship::OverlayCommand(const std::vector<std::string>& args) {
if (args.size() < 3) {
return CMD_FAILED;
}
if (CVar_Get(args[2].c_str()) != nullptr) {
const char* key = args[2].c_str();
GameOverlay* overlay = SohImGui::overlay;
if (args[1] == "add") {
if (!overlay->RegisteredOverlays.contains(key)) {
overlay->RegisteredOverlays[key] = new Overlay({ OverlayType::TEXT, ImStrdup(key), -1.0f });
INFO("Added overlay: %s ", key);
} else {
ERROR("Overlay already exists: %s", key);
}
} else if (args[1] == "remove") {
if (overlay->RegisteredOverlays.contains(key)) {
overlay->RegisteredOverlays.erase(key);
INFO("Removed overlay: %s ", key);
} else {
ERROR("Overlay not found: %s ", key);
}
}
} else {
ERROR("CVar %s does not exist", args[2].c_str());
}
return CMD_SUCCESS;
}
+17 -20
View File
@@ -1,29 +1,28 @@
#pragma once
#include <string>
#include <vector>
#include <memory>
#include "Console.h"
#include "Lib/ImGui/imgui.h"
#include <map>
#include <unordered_map>
enum class OverlayType {
TEXT, IMAGE, NOTIFICATION
};
struct Overlay {
OverlayType type;
const char* value;
float fadeTime;
float duration;
};
namespace Ship {
enum class OverlayType {
TEXT, IMAGE, NOTIFICATION
};
struct Overlay {
OverlayType type;
const char* value;
float fadeTime;
float duration;
};
class GameOverlay {
public:
static bool OverlayCommand(std::shared_ptr<Console> Console, const std::vector<std::string>& args);
std::unordered_map<std::string, Overlay*> RegisteredOverlays;
std::unordered_map<std::string, ImFont*> Fonts;
std::string CurrentFont = "Default";
void Init();
void Draw();
void DrawSettings();
@@ -34,12 +33,10 @@ namespace Ship {
void TextDraw(float x, float y, bool shadow, ImVec4 color, const char* text, ...);
void TextDrawNotification(float duration, bool shadow, const char* fmt, ...);
private:
std::unordered_map<std::string, ImFont*> Fonts;
std::unordered_map<std::string, Overlay*> RegisteredOverlays;
std::string CurrentFont = "Default";
bool NeedsCleanup = false;
void CleanupNotifications();
void LoadFont(const std::string& name, const std::string& path, float fontSize);
};
static bool OverlayCommand(const std::vector<std::string>& args);
}
@@ -0,0 +1,56 @@
#include "GameSettings.h"
// Audio
#include <cstddef>
#include <PR/ultra64/types.h>
#include <PR/ultra64/sptask.h>
#include <PR/ultra64/pi.h>
#include <PR/ultra64/message.h>
#include "Cvar.h"
#include "GlobalCtx2.h"
#include "ImGuiImpl.h"
#include "../../soh/include/z64audio.h"
#include "Hooks.h"
#include "../../soh/soh/Enhancements/debugconsole.h"
#include "Window.h"
#include "Lib/Fast3D/gfx_rendering_api.h"
#define ABS(var) var < 0 ? -(var) : var
using namespace Ship;
namespace Game {
bool DeSyncAudio = false;
void UpdateAudio() {
Audio_SetGameVolume(SEQ_BGM_MAIN, CVar_GetFloat("gMainMusicVolume", 1));
Audio_SetGameVolume(SEQ_BGM_SUB, CVar_GetFloat("gSubMusicVolume", 1));
Audio_SetGameVolume(SEQ_FANFARE, CVar_GetFloat("gSFXMusicVolume", 1));
Audio_SetGameVolume(SEQ_SFX, CVar_GetFloat("gFanfareVolume", 1));
}
void LoadSettings() {
DebugConsole_LoadCVars();
}
void SaveSettings() {
DebugConsole_SaveCVars();
}
void InitSettings() {
ModInternal::RegisterHook<ModInternal::AudioInit>(UpdateAudio);
ModInternal::RegisterHook<ModInternal::GfxInit>([] {
gfx_get_current_rendering_api()->set_texture_filter((FilteringMode) CVar_GetS32("gTextureFilter", FILTER_THREE_POINT));
SohImGui::console->opened = CVar_GetS32("gConsoleEnabled", 0);
SohImGui::controller->Opened = CVar_GetS32("gControllerConfigurationEnabled", 0);
UpdateAudio();
});
}
void SetSeqPlayerVolume(SeqPlayers playerId, float volume) {
Audio_SetGameVolume(playerId, volume);
}
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
enum SeqPlayers {
/* 0 */ SEQ_BGM_MAIN,
/* 1 */ SEQ_FANFARE,
/* 2 */ SEQ_SFX,
/* 3 */ SEQ_BGM_SUB,
/* 4 */ SEQ_MAX
};
namespace Game {
void InitSettings();
void LoadSettings();
void LoadPadSettings();
void SaveSettings();
void SetSeqPlayerVolume(SeqPlayers playerId, float volume);
}
+128
View File
@@ -0,0 +1,128 @@
#include "GlobalCtx2.h"
#include <iostream>
#include <vector>
#include "ResourceMgr.h"
#include "Window.h"
#include "spdlog/async.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/sohconsole_sink.h"
#include "ModManager.h"
#ifdef __APPLE__
#include "OSXFolderManager.h"
#endif
namespace Ship {
std::weak_ptr<GlobalCtx2> GlobalCtx2::Context;
ModManager* INSTANCE;
std::shared_ptr<GlobalCtx2> GlobalCtx2::GetInstance() {
return Context.lock();
}
std::shared_ptr<GlobalCtx2> GlobalCtx2::CreateInstance(const std::string& Name) {
if (Context.expired()) {
auto Shared = std::make_shared<GlobalCtx2>(Name);
Context = Shared;
Shared->InitWindow();
return Shared;
} else {
SPDLOG_DEBUG("Trying to create a context when it already exists.");
}
return GetInstance();
}
std::string GlobalCtx2::GetAppDirectoryPath() {
#ifdef __APPLE__
FolderManager folderManager;
std::string fpath = std::string(folderManager.pathForDirectory(NSApplicationSupportDirectory, NSUserDomainMask));
fpath.append("/com.shipofharkinian.soh");
return fpath;
#endif
return ".";
}
std::string GlobalCtx2::GetPathRelativeToAppDirectory(const char* path) {
return GlobalCtx2::GetAppDirectoryPath() + "/" + path;
}
GlobalCtx2::GlobalCtx2(std::string Name) : Name(std::move(Name)) {
}
GlobalCtx2::~GlobalCtx2() {
SPDLOG_INFO("destruct GlobalCtx2");
INSTANCE->Exit();
}
void GlobalCtx2::InitWindow() {
InitLogging();
Config = std::make_shared<Mercury>(GetPathRelativeToAppDirectory("shipofharkinian.json"));
Config->reload();
MainPath = Config->getString("Game.Main Archive", GetPathRelativeToAppDirectory("oot.otr"));
PatchesPath = Config->getString("Game.Patches Archive", GetAppDirectoryPath() + "/mods");
ResMan = std::make_shared<ResourceMgr>(GetInstance(), MainPath, PatchesPath);
Win = std::make_shared<Window>(GetInstance());
if (!ResMan->DidLoadSuccessfully())
{
#ifdef _WIN32
MessageBox(nullptr, L"Main OTR file not found!", L"Uh oh", MB_OK);
#else
SPDLOG_ERROR("Main OTR file not found!");
#endif
exit(1);
}
INSTANCE = new ModManager(ResMan);
INSTANCE->Init();
}
void GlobalCtx2::InitLogging() {
try {
auto logPath = GetPathRelativeToAppDirectory(("logs/" + GetName() + ".log").c_str());
// Setup Logging
spdlog::init_thread_pool(8192, 1);
auto SohConsoleSink = std::make_shared<spdlog::sinks::soh_sink_mt>();
auto ConsoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
auto FileSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(logPath, 1024 * 1024 * 10, 10);
SohConsoleSink->set_level(spdlog::level::trace);
ConsoleSink->set_level(spdlog::level::trace);
FileSink->set_level(spdlog::level::trace);
std::vector<spdlog::sink_ptr> Sinks{ ConsoleSink, FileSink, SohConsoleSink };
Logger = std::make_shared<spdlog::async_logger>(GetName(), Sinks.begin(), Sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
GetLogger()->set_level(spdlog::level::trace);
GetLogger()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%@] [%l] %v");
spdlog::register_logger(GetLogger());
spdlog::set_default_logger(GetLogger());
}
catch (const spdlog::spdlog_ex& ex) {
std::cout << "Log initialization failed: " << ex.what() << std::endl;
}
}
void GlobalCtx2::WriteSaveFile(const std::filesystem::path& savePath, const uintptr_t addr, void* dramAddr, const size_t size) {
std::ofstream saveFile = std::ofstream(savePath, std::fstream::in | std::fstream::out | std::fstream::binary);
saveFile.seekp(addr);
saveFile.write((char*)dramAddr, size);
saveFile.close();
}
void GlobalCtx2::ReadSaveFile(std::filesystem::path savePath, uintptr_t addr, void* dramAddr, size_t size) {
std::ifstream saveFile = std::ifstream(savePath, std::fstream::in | std::fstream::out | std::fstream::binary);
// If the file doesn't exist, initialize DRAM
if (saveFile.good()) {
saveFile.seekg(addr);
saveFile.read((char*)dramAddr, size);
} else {
memset(dramAddr, 0, size);
}
saveFile.close();
}
}
+54
View File
@@ -0,0 +1,54 @@
#ifndef GLOBAL_CTX_2
#define GLOBAL_CTX_2
#pragma once
#ifdef __cplusplus
#include <filesystem>
#include <memory>
#include <fstream>
#include "spdlog/spdlog.h"
#include "Lib/Mercury/Mercury.h"
namespace Ship {
class ResourceMgr;
class Window;
class GlobalCtx2 {
public:
static std::shared_ptr<GlobalCtx2> GetInstance();
static std::shared_ptr<GlobalCtx2> CreateInstance(const std::string& Name);
std::string GetName() { return Name; }
std::shared_ptr<Window> GetWindow() { return Win; }
std::shared_ptr<ResourceMgr> GetResourceManager() { return ResMan; }
std::shared_ptr<spdlog::logger> GetLogger() { return Logger; }
std::shared_ptr<Mercury> GetConfig() { return Config; }
static std::string GetAppDirectoryPath();
static std::string GetPathRelativeToAppDirectory(const char* path);
void WriteSaveFile(const std::filesystem::path& savePath, uintptr_t addr, void* dramAddr, size_t size);
void ReadSaveFile(std::filesystem::path savePath, uintptr_t addr, void* dramAddr, size_t size);
GlobalCtx2(std::string Name);
~GlobalCtx2();
protected:
void InitWindow();
void InitLogging();
private:
static std::weak_ptr <GlobalCtx2> Context;
std::shared_ptr<spdlog::logger> Logger;
std::shared_ptr<Window> Win;
std::shared_ptr<Mercury> Config; // Config needs to be after the Window because we call the Window during it's destructor.
std::shared_ptr<ResourceMgr> ResMan;
std::string Name;
std::string MainPath;
std::string PatchesPath;
};
}
#endif
#endif
+7 -2
View File
@@ -1,5 +1,10 @@
#include "Hooks.h"
#include <map>
#include <string>
#include <vector>
#include <stdarg.h>
#include <iostream>
namespace Ship {
void ModInternal_ExecuteAudioInitHooks() {
ModInternal::ExecuteHooks<ModInternal::AudioInit>();
}
+19 -5
View File
@@ -1,12 +1,15 @@
#pragma once
#ifdef __cplusplus
#include <functional>
#include "UltraController.h"
#include "Controller.h"
#define DEFINE_HOOK(name, type) struct name { typedef std::function<type> fn; }
namespace Ship {
class Controller;
namespace ModInternal {
template <typename H>
struct RegisteredHooks {
@@ -26,11 +29,22 @@ namespace Ship {
}
DEFINE_HOOK(ControllerRead, void(OSContPad* cont_pad));
DEFINE_HOOK(ControllerRawInput, void(Controller* backend, uint32_t raw));
DEFINE_HOOK(ControllerRawInput, void(Ship::Controller* backend, uint32_t raw));
DEFINE_HOOK(AudioInit, void());
DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture));
DEFINE_HOOK(GfxInit, void());
DEFINE_HOOK(ExitGame, void());
DEFINE_HOOK(LoadFile, void(uint32_t fileNum));
DEFINE_HOOK(DeleteFile, void(uint32_t fileNum));
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
void ModInternal_ExecuteAudioInitHooks();
#ifdef __cplusplus
}
#endif

Some files were not shown because too many files have changed in this diff Show More