mirror of
https://github.com/HarbourMasters/Starship.git
synced 2025-01-23 05:25:01 +03:00
Merge pull request #131 from HarbourMasters/otr-ig-gen
Reimplemented built-in generation
This commit is contained in:
commit
beee77da2a
@ -18,6 +18,8 @@ set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard to use")
|
||||
|
||||
# Add a custom module path to locate additional CMake modules
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
||||
set(YAML_CPP_STATIC_DEFINE ON)
|
||||
add_compile_definitions(YAML_CPP_STATIC_DEFINE)
|
||||
|
||||
if (WIN32)
|
||||
include(cmake/automate-vcpkg.cmake)
|
||||
@ -27,6 +29,11 @@ vcpkg_bootstrap()
|
||||
vcpkg_install_packages(zlib bzip2 libzip libpng sdl2 glew glfw3 nlohmann-json tinyxml2 spdlog)
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS ${CMAKE_BINARY_DIR}/config.yml)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config.yml" "${CMAKE_BINARY_DIR}/config.yml")
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/assets/" "${CMAKE_BINARY_DIR}/assets/")
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
set(CPP "${CMAKE_C_COMPILER}" "/EP")
|
||||
else()
|
||||
@ -221,7 +228,6 @@ add_dependencies(${PROJECT_NAME} libultraship)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE libultraship)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
"$<$<CONFIG:Debug>:"
|
||||
"_DEBUG;"
|
||||
@ -233,30 +239,12 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
">"
|
||||
"INCLUDE_GAME_PRINTF;"
|
||||
"UNICODE;"
|
||||
"_UNICODE"
|
||||
STORMLIB_NO_AUTO_LINK
|
||||
"_UNICODE;"
|
||||
"_CRT_SECURE_NO_WARNINGS;"
|
||||
"_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS;"
|
||||
)
|
||||
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
"$<$<CONFIG:Debug>:"
|
||||
"NOINCLUDE_GAME_PRINTF;"
|
||||
"_DEBUG;"
|
||||
"_CRT_SECURE_NO_WARNINGS;"
|
||||
"ENABLE_OPENGL"
|
||||
">"
|
||||
"$<$<CONFIG:Release>:"
|
||||
"NDEBUG;"
|
||||
">"
|
||||
"INCLUDE_GAME_PRINTF;"
|
||||
"WIN32;"
|
||||
"UNICODE;"
|
||||
"_UNICODE"
|
||||
STORMLIB_NO_AUTO_LINK
|
||||
"_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS;"
|
||||
)
|
||||
endif()
|
||||
add_compile_definitions(STORMLIB_NO_AUTO_LINK)
|
||||
set(STORMLIB_NO_AUTO_LINK ON)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
"$<$<CONFIG:Debug>:"
|
||||
@ -319,18 +307,25 @@ if(USE_NETWORKING)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_NETWORKING)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
|
||||
option(USE_STANDALONE "Build as a standalone executable" OFF)
|
||||
option(BUILD_STORMLIB "Build with StormLib support" OFF)
|
||||
|
||||
option(BUILD_SM64 "Build with Super Mario 64 support" OFF)
|
||||
option(BUILD_MK64 "Build with Mario Kart 64 support" OFF)
|
||||
option(BUILD_FZERO "Build with F-Zero X support" OFF)
|
||||
add_subdirectory(tools/Torch)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE torch "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch")
|
||||
|
||||
nx_generate_nacp(Lylat.nacp
|
||||
nx_generate_nacp(${PROJECT_NAME}.nacp
|
||||
NAME "${PROJECT_NAME}"
|
||||
AUTHOR "${PROJECT_TEAM}"
|
||||
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
|
||||
)
|
||||
|
||||
nx_create_nro(${PROJECT_NAME}
|
||||
NACP Lylat.nacp
|
||||
NACP ${PROJECT_NAME}.nacp
|
||||
)
|
||||
|
||||
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.nro DESTINATION . COMPONENT ${PROJECT_NAME})
|
||||
@ -530,20 +525,20 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
|
||||
endif()
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(torch
|
||||
PREFIX torch
|
||||
ExternalProject_Add(TorchExternal
|
||||
PREFIX TorchExternal
|
||||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/tools/Torch
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/Torch
|
||||
)
|
||||
ExternalProject_Get_Property(torch install_dir)
|
||||
ExternalProject_Get_Property(TorchExternal install_dir)
|
||||
if (MSVC)
|
||||
set(TORCH_EXECUTABLE ${install_dir}/src/torch-build/$<CONFIGURATION>/torch)
|
||||
set(TORCH_EXECUTABLE ${install_dir}/src/TorchExternal-build/$<CONFIGURATION>/torch)
|
||||
else()
|
||||
set(TORCH_EXECUTABLE ${install_dir}/src/torch-build/torch)
|
||||
set(TORCH_EXECUTABLE ${install_dir}/src/TorchExternal-build/torch)
|
||||
endif()
|
||||
add_custom_target(
|
||||
ExtractAssets
|
||||
DEPENDS torch
|
||||
DEPENDS TorchExternal
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${TORCH_EXECUTABLE} o2r baserom.z64
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/sf64.o2r" "${CMAKE_BINARY_DIR}/sf64.o2r"
|
||||
@ -551,7 +546,7 @@ add_custom_target(
|
||||
|
||||
add_custom_target(
|
||||
GeneratePortOTR
|
||||
DEPENDS torch
|
||||
DEPENDS TorchExternal
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${TORCH_EXECUTABLE} pack port starship.o2r o2r
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/starship.o2r" "${CMAKE_BINARY_DIR}/starship.o2r"
|
||||
|
1770
include/portable-file-dialogs.h
Normal file
1770
include/portable-file-dialogs.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@
|
||||
#include "ui/ImguiUI.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
#include "extractor/GameExtractor.h"
|
||||
#include "libultraship/src/Context.h"
|
||||
#include "resource/type/ResourceType.h"
|
||||
#include "resource/importers/AnimFactory.h"
|
||||
@ -40,14 +41,12 @@
|
||||
#include "port/mods/PortEnhancements.h"
|
||||
|
||||
#include <Fast3D/gfx_pc.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
extern "C" {
|
||||
bool prevAltAssets = false;
|
||||
float gInterpolationStep = 0.0f;
|
||||
#include <sf64thread.h>
|
||||
#include <macros.h>
|
||||
#include "sf64audio_provisional.h"
|
||||
@ -59,14 +58,32 @@ static GamePool MemoryPool = { .chunk = 1024 * 512, .cursor = 0, .length = 0, .m
|
||||
|
||||
GameEngine::GameEngine() {
|
||||
std::vector<std::string> archiveFiles;
|
||||
if (const std::string cube_path = Ship::Context::GetPathRelativeToAppDirectory("starship.o2r");
|
||||
std::filesystem::exists(cube_path)) {
|
||||
archiveFiles.push_back(cube_path);
|
||||
const std::string main_path = Ship::Context::GetPathRelativeToAppDirectory("sf64.o2r");
|
||||
const std::string assets_path = Ship::Context::GetPathRelativeToAppDirectory("starship.o2r");
|
||||
|
||||
#ifdef _WIN32
|
||||
AllocConsole();
|
||||
#endif
|
||||
|
||||
if (std::filesystem::exists(main_path)) {
|
||||
archiveFiles.push_back(main_path);
|
||||
} else {
|
||||
if (ShowYesNoBox("No O2R Files", "No O2R files found. Generate one now?") == IDYES) {
|
||||
if(!GenAssetFile()){
|
||||
ShowMessage("Error", "An error occured, no O2R file was generated.\n\nExiting...");
|
||||
exit(1);
|
||||
} else {
|
||||
archiveFiles.push_back(main_path);
|
||||
}
|
||||
if (const std::string sm64_otr_path = Ship::Context::GetPathRelativeToAppDirectory("sf64.o2r");
|
||||
std::filesystem::exists(sm64_otr_path)) {
|
||||
archiveFiles.push_back(sm64_otr_path);
|
||||
} else {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (std::filesystem::exists(assets_path)) {
|
||||
archiveFiles.push_back(assets_path);
|
||||
}
|
||||
|
||||
if (const std::string patches_path = Ship::Context::GetPathRelativeToAppDirectory("mods");
|
||||
!patches_path.empty() && std::filesystem::exists(patches_path)) {
|
||||
if (std::filesystem::is_directory(patches_path)) {
|
||||
@ -187,6 +204,25 @@ GameEngine::GameEngine() {
|
||||
context->GetResourceManager()->SetAltAssetsEnabled(prevAltAssets);
|
||||
}
|
||||
|
||||
bool GameEngine::GenAssetFile() {
|
||||
auto extractor = new GameExtractor();
|
||||
|
||||
if (!extractor->SelectGameFromUI()) {
|
||||
ShowMessage("Error", "No ROM selected.\n\nExiting...");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
auto game = extractor->ValidateChecksum();
|
||||
if (!game.has_value()) {
|
||||
ShowMessage("Unsupported ROM", "The provided ROM is not supported.\n\nCheck the readme for a list of supported versions.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ShowMessage(("Found " + game.value()).c_str(), "The extraction process will now begin.\n\nThis may take a few minutes.", SDL_MESSAGEBOX_INFORMATION);
|
||||
|
||||
return extractor->GenerateOTR();
|
||||
}
|
||||
|
||||
void GameEngine::Create() {
|
||||
const auto instance = Instance = new GameEngine();
|
||||
instance->AudioInit();
|
||||
@ -421,6 +457,39 @@ uint32_t GameEngine::GetInterpolationFPS() {
|
||||
CVarGetInteger("gInterpolationFPS", 60));
|
||||
}
|
||||
|
||||
void GameEngine::ShowMessage(const char* title, const char* message, SDL_MessageBoxFlags type) {
|
||||
#if defined(__SWITCH__)
|
||||
SPDLOG_ERROR(message);
|
||||
#else
|
||||
SDL_ShowSimpleMessageBox(type, title, message, nullptr);
|
||||
SPDLOG_ERROR(message);
|
||||
#endif
|
||||
}
|
||||
|
||||
int GameEngine::ShowYesNoBox(const char* title, const char* box) {
|
||||
int ret;
|
||||
#ifdef _WIN32
|
||||
ret = MessageBoxA(nullptr, box, title, MB_YESNO | MB_ICONQUESTION);
|
||||
#else
|
||||
SDL_MessageBoxData boxData = { 0 };
|
||||
SDL_MessageBoxButtonData buttons[2] = { { 0 } };
|
||||
|
||||
buttons[0].buttonid = IDYES;
|
||||
buttons[0].text = "Yes";
|
||||
buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
|
||||
buttons[1].buttonid = IDNO;
|
||||
buttons[1].text = "No";
|
||||
buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
|
||||
boxData.numbuttons = 2;
|
||||
boxData.flags = SDL_MESSAGEBOX_INFORMATION;
|
||||
boxData.message = box;
|
||||
boxData.title = title;
|
||||
boxData.buttons = buttons;
|
||||
SDL_ShowMessageBox(&boxData, &ret);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" uint32_t GameEngine_GetSampleRate() {
|
||||
auto player = Ship::Context::GetInstance()->GetAudio()->GetAudioPlayer();
|
||||
if (player == nullptr) {
|
||||
|
@ -12,10 +12,16 @@ struct GamePool {
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <vector>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <Fast3D/gfx_pc.h>
|
||||
#include "libultraship/src/Context.h"
|
||||
|
||||
|
||||
#ifndef IDYES
|
||||
#define IDYES 6
|
||||
#endif
|
||||
#ifndef IDNO
|
||||
#define IDNO 7
|
||||
#endif
|
||||
|
||||
class GameEngine {
|
||||
public:
|
||||
@ -24,6 +30,7 @@ class GameEngine {
|
||||
std::shared_ptr<Ship::Context> context;
|
||||
|
||||
GameEngine();
|
||||
static bool GenAssetFile();
|
||||
static void Create();
|
||||
void StartFrame() const;
|
||||
static void HandleAudioThread();
|
||||
@ -37,6 +44,9 @@ class GameEngine {
|
||||
static void Destroy();
|
||||
static void ProcessGfxCommands(Gfx* commands);
|
||||
static uint32_t GetInterpolationFPS();
|
||||
|
||||
static int ShowYesNoBox(const char* title, const char* box);
|
||||
static void ShowMessage(const char* title, const char* message, SDL_MessageBoxFlags type = SDL_MESSAGEBOX_ERROR);
|
||||
};
|
||||
|
||||
extern "C" void* GameEngine_Malloc(size_t size);
|
||||
|
58
src/port/extractor/GameExtractor.cpp
Normal file
58
src/port/extractor/GameExtractor.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "GameExtractor.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "Context.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "portable-file-dialogs.h"
|
||||
#include <port/Engine.h>
|
||||
|
||||
std::unordered_map<std::string, std::string> mGameList = {
|
||||
{ "d8b1088520f7c5f81433292a9258c1184afa1457", "Star Fox 64 (U) (V1.0)" },
|
||||
{ "63b69f0ef36306257481afc250f9bc304c7162b2", "Star Fox 64 (U) (V1.0) (Uncompressed)" },
|
||||
{ "09f0d105f476b00efa5303a3ebc42e60a7753b7a", "Star Fox 64 (U) (V1.1)" },
|
||||
{ "f7475fb11e7e6830f82883412638e8390791ab87", "Star Fox 64 (U) (V1.1) (Uncompressed)" },
|
||||
};
|
||||
|
||||
bool GameExtractor::SelectGameFromUI() {
|
||||
#if !defined(__IOS__) || !defined(__ANDROID__) || !defined(__SWITCH__)
|
||||
auto selection = pfd::open_file("Select a file", ".", { "N64 Roms", "*.z64 *.n64 *.v64" }).result();
|
||||
|
||||
if (selection.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->mGamePath = selection[0];
|
||||
#else
|
||||
this->mGamePath = Ship::Context::GetPathRelativeToAppDirectory("baserom.us.rev1.z64");
|
||||
#endif
|
||||
|
||||
std::ifstream file(this->mGamePath, std::ios::binary);
|
||||
this->mGameData = std::vector<uint8_t>( std::istreambuf_iterator( file ), {} );
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<std::string> GameExtractor::ValidateChecksum() const {
|
||||
const auto rom = new N64::Cartridge(this->mGameData);
|
||||
rom->Initialize();
|
||||
auto hash = rom->GetHash();
|
||||
|
||||
if (mGameList.find(hash) == mGameList.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return mGameList[hash];
|
||||
}
|
||||
|
||||
bool GameExtractor::GenerateOTR() const {
|
||||
Companion::Instance = new Companion(this->mGameData, ArchiveType::O2R, false);
|
||||
|
||||
try {
|
||||
Companion::Instance->Init(ExportType::Binary);
|
||||
} catch (const std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
17
src/port/extractor/GameExtractor.h
Normal file
17
src/port/extractor/GameExtractor.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Companion.h"
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
class GameExtractor {
|
||||
public:
|
||||
static bool GenAssetFile();
|
||||
std::optional<std::string> ValidateChecksum() const;
|
||||
bool SelectGameFromUI();
|
||||
bool GenerateOTR() const;
|
||||
private:
|
||||
fs::path mGamePath;
|
||||
std::vector<uint8_t> mGameData;
|
||||
};
|
@ -1,10 +1,3 @@
|
||||
//
|
||||
// UIWidgets.cpp
|
||||
// soh
|
||||
//
|
||||
// Created by David Chavez on 25.08.22.
|
||||
//
|
||||
|
||||
#include "UIWidgets.h"
|
||||
|
||||
#include "libultraship/src/Context.h"
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 82c4397160b42f0b2c9a51581335ee1a23907993
|
||||
Subproject commit 7da8ae8e25d6c1267792941bf9ac56c1acc384ae
|
Loading…
Reference in New Issue
Block a user