mirror of
https://github.com/izzy2lost/WeeU.git
synced 2026-07-06 00:19:59 -07:00
Refactored native library
This commit is contained in:
@@ -27,7 +27,7 @@ class AndroidFilesystemCallbacks : public FilesystemAndroid::FilesystemCallbacks
|
||||
AndroidFilesystemCallbacks()
|
||||
{
|
||||
JNIUtils::ScopedJNIENV env;
|
||||
m_fileUtilClass = JNIUtils::Scopedjclass("info/cemu/Cemu/utils/FileUtil");
|
||||
m_fileUtilClass = JNIUtils::Scopedjclass("info/cemu/Cemu/nativeinterface/FileCallbacks");
|
||||
m_openContentUriMid = env->GetStaticMethodID(*m_fileUtilClass, "openContentUri", "(Ljava/lang/String;)I");
|
||||
m_listFilesMid = env->GetStaticMethodID(*m_fileUtilClass, "listFiles", "(Ljava/lang/String;)[Ljava/lang/String;");
|
||||
m_isDirectoryMid = env->GetStaticMethodID(*m_fileUtilClass, "isDirectory", "(Ljava/lang/String;)Z");
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
add_library(CemuAndroid SHARED
|
||||
AndroidAudio.cpp
|
||||
AndroidAudio.h
|
||||
AndroidEmulatedController.cpp
|
||||
AndroidEmulatedController.h
|
||||
AndroidFilesystemCallbacks.h
|
||||
AndroidGameTitleLoadedCallback.h
|
||||
CMakeLists.txt
|
||||
CafeSystemUtils.cpp
|
||||
CafeSystemUtils.h
|
||||
EmulationState.h
|
||||
GameTitleLoader.cpp
|
||||
GameTitleLoader.h
|
||||
Image.cpp
|
||||
Image.h
|
||||
JNIUtils.cpp
|
||||
JNIUtils.h
|
||||
Utils.cpp
|
||||
Utils.h
|
||||
native-lib.cpp
|
||||
stb_image.h
|
||||
NativeEmulation.cpp
|
||||
NativeGameTitles.cpp
|
||||
NativeGraphicPacks.cpp
|
||||
NativeInput.cpp
|
||||
NativeLib.cpp
|
||||
NativeSettings.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(CemuAndroid PRIVATE
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#include "CafeSystemUtils.h"
|
||||
|
||||
#include "Cafe/CafeSystem.h"
|
||||
#include "Cafe/TitleList/TitleList.h"
|
||||
|
||||
namespace CafeSystemUtils
|
||||
{
|
||||
void startGame(const fs::path& launchPath)
|
||||
{
|
||||
TitleInfo launchTitle{launchPath};
|
||||
if (launchTitle.IsValid())
|
||||
{
|
||||
// the title might not be in the TitleList, so we add it as a temporary entry
|
||||
CafeTitleList::AddTitleFromPath(launchPath);
|
||||
// title is valid, launch from TitleId
|
||||
TitleId baseTitleId;
|
||||
if (!CafeTitleList::FindBaseTitleId(launchTitle.GetAppTitleId(), baseTitleId))
|
||||
{
|
||||
throw GameBaseFilesNotFoundException();
|
||||
}
|
||||
CafeSystem::STATUS_CODE r = CafeSystem::PrepareForegroundTitle(baseTitleId);
|
||||
if (r != CafeSystem::STATUS_CODE::SUCCESS)
|
||||
{
|
||||
throw UnknownGameFilesException();
|
||||
}
|
||||
}
|
||||
else // if (launchTitle.GetFormat() == TitleInfo::TitleDataFormat::INVALID_STRUCTURE )
|
||||
{
|
||||
// title is invalid, if it's an RPX/ELF we can launch it directly
|
||||
// otherwise it's an error
|
||||
CafeTitleFileType fileType = DetermineCafeSystemFileType(launchPath);
|
||||
if (fileType == CafeTitleFileType::RPX || fileType == CafeTitleFileType::ELF)
|
||||
{
|
||||
CafeSystem::STATUS_CODE r = CafeSystem::PrepareForegroundTitleFromStandaloneRPX(launchPath);
|
||||
if (r != CafeSystem::STATUS_CODE::SUCCESS)
|
||||
{
|
||||
throw UnknownGameFilesException();
|
||||
}
|
||||
}
|
||||
else if (launchTitle.GetInvalidReason() == TitleInfo::InvalidReason::NO_DISC_KEY)
|
||||
{
|
||||
throw NoDiscKeyException();
|
||||
}
|
||||
else if (launchTitle.GetInvalidReason() == TitleInfo::InvalidReason::NO_TITLE_TIK)
|
||||
{
|
||||
throw NoTitleTikException();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw UnknownGameFilesException();
|
||||
}
|
||||
}
|
||||
CafeSystem::LaunchForegroundTitle();
|
||||
}
|
||||
}; // namespace CafeSystemUtils
|
||||
@@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cafe/TitleList/TitleId.h"
|
||||
|
||||
namespace CafeSystemUtils
|
||||
{
|
||||
class GameFilesException : public std::exception
|
||||
{
|
||||
public:
|
||||
explicit GameFilesException(const std::string& message)
|
||||
: m_message(message) {}
|
||||
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return m_message.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_message;
|
||||
};
|
||||
|
||||
class GameBaseFilesNotFoundException : public GameFilesException
|
||||
{
|
||||
public:
|
||||
GameBaseFilesNotFoundException()
|
||||
: GameFilesException("Game base files not found.") {}
|
||||
};
|
||||
|
||||
class NoDiscKeyException : public GameFilesException
|
||||
{
|
||||
public:
|
||||
NoDiscKeyException()
|
||||
: GameFilesException("No disc key found.") {}
|
||||
};
|
||||
|
||||
class NoTitleTikException : public GameFilesException
|
||||
{
|
||||
public:
|
||||
NoTitleTikException()
|
||||
: GameFilesException("No title ticket found.") {}
|
||||
};
|
||||
|
||||
class UnknownGameFilesException : public GameFilesException
|
||||
{
|
||||
public:
|
||||
UnknownGameFilesException()
|
||||
: GameFilesException("Unknown error occurred during game launch.") {}
|
||||
};
|
||||
|
||||
void startGame(const fs::path& launchPath);
|
||||
}; // namespace CafeSystemUtils
|
||||
@@ -1,360 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "AndroidAudio.h"
|
||||
#include "AndroidEmulatedController.h"
|
||||
#include "AndroidFilesystemCallbacks.h"
|
||||
#include "Cafe/HW/Latte/Core/LatteOverlay.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h"
|
||||
#include "CafeSystemUtils.h"
|
||||
#include "Cafe/CafeSystem.h"
|
||||
#include "Cemu/GuiSystem/GuiSystem.h"
|
||||
#include "GameTitleLoader.h"
|
||||
#include "Utils.h"
|
||||
#include "input/ControllerFactory.h"
|
||||
#include "input/InputManager.h"
|
||||
#include "input/api/Android/AndroidController.h"
|
||||
#include "input/api/Android/AndroidControllerProvider.h"
|
||||
|
||||
void CemuCommonInit();
|
||||
|
||||
class EmulationState
|
||||
{
|
||||
GameTitleLoader m_gameTitleLoader;
|
||||
std::unordered_map<int64_t, GraphicPackPtr> m_graphicPacks;
|
||||
void fillGraphicPacks()
|
||||
{
|
||||
m_graphicPacks.clear();
|
||||
auto graphicPacks = GraphicPack2::GetGraphicPacks();
|
||||
for (auto&& graphicPack : graphicPacks)
|
||||
{
|
||||
m_graphicPacks[reinterpret_cast<int64_t>(graphicPack.get())] = graphicPack;
|
||||
}
|
||||
}
|
||||
void onTouchEvent(sint32 x, sint32 y, bool isTV, std::optional<bool> status = {})
|
||||
{
|
||||
auto& instance = InputManager::instance();
|
||||
auto& touchInfo = isTV ? instance.m_main_mouse : instance.m_pad_mouse;
|
||||
std::scoped_lock lock(touchInfo.m_mutex);
|
||||
touchInfo.position = {x, y};
|
||||
if (status.has_value())
|
||||
touchInfo.left_down = touchInfo.left_down_toggle = status.value();
|
||||
}
|
||||
WiiUMotionHandler m_wiiUMotionHandler{};
|
||||
long m_lastMotionTimestamp;
|
||||
|
||||
public:
|
||||
void initializeEmulation()
|
||||
{
|
||||
g_config.SetFilename(ActiveSettings::GetConfigPath("settings.xml").generic_wstring());
|
||||
g_config.Load();
|
||||
FilesystemAndroid::setFilesystemCallbacks(std::make_shared<AndroidFilesystemCallbacks>());
|
||||
NetworkConfig::LoadOnce();
|
||||
InputManager::instance().load();
|
||||
auto& instance = InputManager::instance();
|
||||
InitializeGlobalVulkan();
|
||||
createCemuDirectories();
|
||||
LatteOverlay_init();
|
||||
CemuCommonInit();
|
||||
fillGraphicPacks();
|
||||
}
|
||||
|
||||
void initializeActiveSettings(const fs::path& dataPath, const fs::path& cachePath)
|
||||
{
|
||||
std::set<fs::path> failedWriteAccess;
|
||||
ActiveSettings::SetPaths(false, {}, dataPath, dataPath, cachePath, dataPath, failedWriteAccess);
|
||||
}
|
||||
|
||||
void clearSurface(bool isMainCanvas)
|
||||
{
|
||||
if (!isMainCanvas)
|
||||
{
|
||||
auto renderer = static_cast<VulkanRenderer*>(g_renderer.get());
|
||||
if (renderer)
|
||||
renderer->StopUsingPadAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
void notifySurfaceChanged(bool isMainCanvas)
|
||||
{
|
||||
}
|
||||
|
||||
void setSurface(JNIEnv* env, jobject surface, bool isMainCanvas)
|
||||
{
|
||||
cemu_assert_debug(surface != nullptr);
|
||||
auto& windowHandleInfo = isMainCanvas ? GuiSystem::getWindowInfo().canvas_main : GuiSystem::getWindowInfo().canvas_pad;
|
||||
if (windowHandleInfo.surface)
|
||||
{
|
||||
ANativeWindow_release(static_cast<ANativeWindow*>(windowHandleInfo.surface));
|
||||
windowHandleInfo.surface = nullptr;
|
||||
}
|
||||
windowHandleInfo.surface = ANativeWindow_fromSurface(env, surface);
|
||||
int width, height;
|
||||
if (isMainCanvas)
|
||||
GuiSystem::getWindowPhysSize(width, height);
|
||||
else
|
||||
GuiSystem::getPadWindowPhysSize(width, height);
|
||||
VulkanRenderer::GetInstance()->InitializeSurface({width, height}, isMainCanvas);
|
||||
}
|
||||
|
||||
void setSurfaceSize(int width, int height, bool isMainCanvas)
|
||||
{
|
||||
auto& windowInfo = GuiSystem::getWindowInfo();
|
||||
if (isMainCanvas)
|
||||
{
|
||||
windowInfo.width = windowInfo.phys_width = width;
|
||||
windowInfo.height = windowInfo.phys_height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
windowInfo.pad_width = windowInfo.phys_pad_width = width;
|
||||
windowInfo.pad_height = windowInfo.phys_pad_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
void onKeyEvent(const std::string& deviceDescriptor, const std::string& deviceName, int keyCode, bool isPressed)
|
||||
{
|
||||
auto apiProvider = InputManager::instance().get_api_provider(InputAPI::Android);
|
||||
auto androidControllerProvider = dynamic_cast<AndroidControllerProvider*>(apiProvider.get());
|
||||
androidControllerProvider->on_key_event(deviceDescriptor, deviceName, keyCode, isPressed);
|
||||
}
|
||||
|
||||
void onAxisEvent(const std::string& deviceDescriptor, const std::string& deviceName, int axisCode, float value)
|
||||
{
|
||||
auto apiProvider = InputManager::instance().get_api_provider(InputAPI::Android);
|
||||
auto androidControllerProvider = dynamic_cast<AndroidControllerProvider*>(apiProvider.get());
|
||||
androidControllerProvider->on_axis_event(deviceDescriptor, deviceName, axisCode, value);
|
||||
}
|
||||
|
||||
std::optional<std::string> getEmulatedControllerMapping(size_t index, uint64 mappingId)
|
||||
{
|
||||
return AndroidEmulatedController::getAndroidEmulatedController(index).getMapping(mappingId);
|
||||
}
|
||||
|
||||
AndroidEmulatedController& getEmulatedController(size_t index)
|
||||
{
|
||||
return AndroidEmulatedController::getAndroidEmulatedController(index);
|
||||
}
|
||||
|
||||
int getVPADControllersCount()
|
||||
{
|
||||
int vpadCount = 0;
|
||||
for (int i = 0; i < InputManager::kMaxController; i++)
|
||||
{
|
||||
auto emulatedController = AndroidEmulatedController::getAndroidEmulatedController(i).getEmulatedController();
|
||||
if (!emulatedController)
|
||||
continue;
|
||||
if (emulatedController->type() == EmulatedController::Type::VPAD)
|
||||
++vpadCount;
|
||||
}
|
||||
return vpadCount;
|
||||
}
|
||||
|
||||
int getWPADControllersCount()
|
||||
{
|
||||
int wpadCount = 0;
|
||||
for (int i = 0; i < InputManager::kMaxController; i++)
|
||||
{
|
||||
auto emulatedController = AndroidEmulatedController::getAndroidEmulatedController(
|
||||
i)
|
||||
.getEmulatedController();
|
||||
if (!emulatedController)
|
||||
continue;
|
||||
if (emulatedController->type() != EmulatedController::Type::VPAD)
|
||||
++wpadCount;
|
||||
}
|
||||
return wpadCount;
|
||||
}
|
||||
|
||||
EmulatedController::Type getEmulatedControllerType(size_t index)
|
||||
{
|
||||
auto emulatedController = AndroidEmulatedController::getAndroidEmulatedController(index).getEmulatedController();
|
||||
if (emulatedController)
|
||||
return emulatedController->type();
|
||||
throw std::runtime_error(fmt::format("can't get type for emulated controller {}", index));
|
||||
}
|
||||
|
||||
void clearEmulatedControllerMapping(size_t index, uint64 mapping)
|
||||
{
|
||||
AndroidEmulatedController::getAndroidEmulatedController(index).clearMapping(mapping);
|
||||
}
|
||||
|
||||
void setEmulatedControllerType(size_t index, EmulatedController::Type type)
|
||||
{
|
||||
auto& androidEmulatedController = AndroidEmulatedController::getAndroidEmulatedController(index);
|
||||
if (EmulatedController::Type::VPAD <= type && type < EmulatedController::Type::MAX)
|
||||
androidEmulatedController.setType(type);
|
||||
else
|
||||
androidEmulatedController.setDisabled();
|
||||
}
|
||||
|
||||
void initializeRenderer(JNIEnv* env, jobject testSurface)
|
||||
{
|
||||
cemu_assert_debug(testSurface != nullptr);
|
||||
// TODO: cleanup surface
|
||||
GuiSystem::getWindowInfo().window_main.surface = ANativeWindow_fromSurface(env, testSurface);
|
||||
g_renderer = std::make_unique<VulkanRenderer>();
|
||||
}
|
||||
void setReplaceTVWithPadView(bool showDRC)
|
||||
{
|
||||
// Emulate pressing the TAB key for showing DRC instead of TV
|
||||
GuiSystem::getWindowInfo().set_keystate(GuiSystem::PlatformKeyCodes::TAB, showDRC);
|
||||
}
|
||||
void setDPI(float dpi)
|
||||
{
|
||||
auto& windowInfo = GuiSystem::getWindowInfo();
|
||||
windowInfo.dpi_scale = windowInfo.pad_dpi_scale = dpi;
|
||||
}
|
||||
|
||||
bool isEmulatedControllerDisabled(size_t index)
|
||||
{
|
||||
return AndroidEmulatedController::getAndroidEmulatedController(index).getEmulatedController() == nullptr;
|
||||
}
|
||||
|
||||
std::map<uint64, std::string> getEmulatedControllerMappings(size_t index)
|
||||
{
|
||||
return AndroidEmulatedController::getAndroidEmulatedController(index).getMappings();
|
||||
}
|
||||
|
||||
void setControllerMapping(const std::string& deviceDescriptor, const std::string& deviceName, size_t index, uint64 mappingId, uint64 buttonId)
|
||||
{
|
||||
auto apiProvider = InputManager::instance().get_api_provider(InputAPI::Android);
|
||||
auto controller = ControllerFactory::CreateController(InputAPI::Android, deviceDescriptor, deviceName);
|
||||
AndroidEmulatedController::getAndroidEmulatedController(index).setMapping(mappingId, controller, buttonId);
|
||||
}
|
||||
void initializeAudioDevices()
|
||||
{
|
||||
auto& config = g_config.data();
|
||||
if (!config.tv_device.empty())
|
||||
AndroidAudio::createAudioDevice(IAudioAPI::AudioAPI::Cubeb, config.tv_channels, config.tv_volume, true);
|
||||
|
||||
if (!config.pad_device.empty())
|
||||
AndroidAudio::createAudioDevice(IAudioAPI::AudioAPI::Cubeb, config.pad_channels, config.pad_volume, false);
|
||||
}
|
||||
|
||||
void setOnGameTitleLoaded(const std::shared_ptr<GameTitleLoadedCallback>& onGameTitleLoaded)
|
||||
{
|
||||
m_gameTitleLoader.setOnTitleLoaded(onGameTitleLoaded);
|
||||
}
|
||||
|
||||
void addGamesPath(const std::string& gamePath)
|
||||
{
|
||||
auto& gamePaths = g_config.data().game_paths;
|
||||
if (std::any_of(gamePaths.begin(), gamePaths.end(), [&](auto path) { return path == gamePath; }))
|
||||
return;
|
||||
gamePaths.push_back(gamePath);
|
||||
g_config.Save();
|
||||
CafeTitleList::ClearScanPaths();
|
||||
for (auto& it : gamePaths)
|
||||
CafeTitleList::AddScanPath(it);
|
||||
CafeTitleList::Refresh();
|
||||
}
|
||||
|
||||
void removeGamesPath(const std::string& gamePath)
|
||||
{
|
||||
auto& gamePaths = g_config.data().game_paths;
|
||||
std::erase_if(gamePaths, [&](auto path) { return path == gamePath; });
|
||||
g_config.Save();
|
||||
CafeTitleList::ClearScanPaths();
|
||||
for (auto& it : gamePaths)
|
||||
CafeTitleList::AddScanPath(it);
|
||||
CafeTitleList::Refresh();
|
||||
}
|
||||
|
||||
void reloadGameTitles()
|
||||
{
|
||||
m_gameTitleLoader.reloadGameTitles();
|
||||
}
|
||||
|
||||
void startGame(const fs::path& gamePath)
|
||||
{
|
||||
GuiSystem::getWindowInfo().set_keystates_up();
|
||||
initializeAudioDevices();
|
||||
CafeSystemUtils::startGame(gamePath);
|
||||
}
|
||||
|
||||
void refreshGraphicPacks()
|
||||
{
|
||||
if (!CafeSystem::IsTitleRunning())
|
||||
{
|
||||
GraphicPack2::ClearGraphicPacks();
|
||||
GraphicPack2::LoadAll();
|
||||
fillGraphicPacks();
|
||||
}
|
||||
}
|
||||
|
||||
const std::unordered_map<int64_t, GraphicPackPtr>& getGraphicPacks() const
|
||||
{
|
||||
return m_graphicPacks;
|
||||
}
|
||||
|
||||
void setEnabledStateForGraphicPack(int64_t id, bool state)
|
||||
{
|
||||
auto graphicPack = m_graphicPacks.at(id);
|
||||
graphicPack->SetEnabled(state);
|
||||
saveGraphicPackStateToConfig(graphicPack);
|
||||
}
|
||||
|
||||
GraphicPackPtr getGraphicPack(int64_t id) const
|
||||
{
|
||||
return m_graphicPacks.at(id);
|
||||
}
|
||||
void setGraphicPackActivePreset(int64_t id, const std::string& presetCategory, const std::string& preset) const
|
||||
{
|
||||
auto graphicPack = m_graphicPacks.at(id);
|
||||
graphicPack->SetActivePreset(presetCategory, preset);
|
||||
saveGraphicPackStateToConfig(graphicPack);
|
||||
}
|
||||
void saveGraphicPackStateToConfig(GraphicPackPtr graphicPack) const
|
||||
{
|
||||
auto& data = g_config.data();
|
||||
auto filename = _utf8ToPath(graphicPack->GetNormalizedPathString());
|
||||
if (data.graphic_pack_entries.contains(filename))
|
||||
data.graphic_pack_entries.erase(filename);
|
||||
if (graphicPack->IsEnabled())
|
||||
{
|
||||
data.graphic_pack_entries.try_emplace(filename);
|
||||
auto& it = data.graphic_pack_entries[filename];
|
||||
// otherwise store all selected presets
|
||||
for (const auto& preset : graphicPack->GetActivePresets())
|
||||
it.try_emplace(preset->category, preset->name);
|
||||
}
|
||||
else if (graphicPack->IsDefaultEnabled())
|
||||
{
|
||||
// save that its disabled
|
||||
data.graphic_pack_entries.try_emplace(filename);
|
||||
auto& it = data.graphic_pack_entries[filename];
|
||||
it.try_emplace("_disabled", "false");
|
||||
}
|
||||
g_config.Save();
|
||||
}
|
||||
void onTouchMove(sint32 x, sint32 y, bool isTV)
|
||||
{
|
||||
onTouchEvent(x, y, isTV);
|
||||
}
|
||||
void onTouchUp(sint32 x, sint32 y, bool isTV)
|
||||
{
|
||||
onTouchEvent(x, y, isTV, false);
|
||||
}
|
||||
void onTouchDown(sint32 x, sint32 y, bool isTV)
|
||||
{
|
||||
onTouchEvent(x, y, isTV, true);
|
||||
}
|
||||
void onMotion(long timestamp, float gyroX, float gyroY, float gyroZ, float accelX, float accelY, float accelZ)
|
||||
{
|
||||
float deltaTime = (timestamp - m_lastMotionTimestamp) * 1e-9f;
|
||||
m_wiiUMotionHandler.processMotionSample(deltaTime, gyroX, gyroY, gyroZ, accelX * 0.098066f, -accelY * 0.098066f, -accelZ * 0.098066f);
|
||||
m_lastMotionTimestamp = timestamp;
|
||||
auto& deviceMotion = InputManager::instance().m_device_motion;
|
||||
std::scoped_lock lock{deviceMotion.m_mutex};
|
||||
deviceMotion.m_motion_sample = m_wiiUMotionHandler.getMotionSample();
|
||||
}
|
||||
void setMotionEnabled(bool enabled)
|
||||
{
|
||||
auto& deviceMotion = InputManager::instance().m_device_motion;
|
||||
std::scoped_lock lock{deviceMotion.m_mutex};
|
||||
deviceMotion.m_device_motion_enabled = enabled;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,261 @@
|
||||
#include "JNIUtils.h"
|
||||
#include "AndroidAudio.h"
|
||||
#include "AndroidEmulatedController.h"
|
||||
#include "AndroidFilesystemCallbacks.h"
|
||||
#include "Cafe/HW/Latte/Core/LatteOverlay.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h"
|
||||
#include "Cafe/CafeSystem.h"
|
||||
#include "Cemu/GuiSystem/GuiSystem.h"
|
||||
#include "GameTitleLoader.h"
|
||||
#include "input/ControllerFactory.h"
|
||||
#include "input/InputManager.h"
|
||||
#include "input/api/Android/AndroidController.h"
|
||||
#include "input/api/Android/AndroidControllerProvider.h"
|
||||
#include "config/ActiveSettings.h"
|
||||
#include "Cemu/ncrypto/ncrypto.h"
|
||||
|
||||
// forward declaration from main.cpp
|
||||
void CemuCommonInit();
|
||||
|
||||
namespace NativeEmulation
|
||||
{
|
||||
void initializeAudioDevices()
|
||||
{
|
||||
auto& config = g_config.data();
|
||||
if (!config.tv_device.empty())
|
||||
AndroidAudio::createAudioDevice(IAudioAPI::AudioAPI::Cubeb, config.tv_channels, config.tv_volume, true);
|
||||
|
||||
if (!config.pad_device.empty())
|
||||
AndroidAudio::createAudioDevice(IAudioAPI::AudioAPI::Cubeb, config.pad_channels, config.pad_volume, false);
|
||||
}
|
||||
|
||||
void createCemuDirectories()
|
||||
{
|
||||
std::wstring mlc = ActiveSettings::GetMlcPath().generic_wstring();
|
||||
|
||||
// create sys/usr folder in mlc01
|
||||
const auto sysFolder = fs::path(mlc).append(L"sys");
|
||||
fs::create_directories(sysFolder);
|
||||
|
||||
const auto usrFolder = fs::path(mlc).append(L"usr");
|
||||
fs::create_directories(usrFolder);
|
||||
fs::create_directories(fs::path(usrFolder).append("title/00050000")); // base
|
||||
fs::create_directories(fs::path(usrFolder).append("title/0005000c")); // dlc
|
||||
fs::create_directories(fs::path(usrFolder).append("title/0005000e")); // update
|
||||
|
||||
// Mii Maker save folders {0x500101004A000, 0x500101004A100, 0x500101004A200},
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a000/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a100/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a200/user/common/db"));
|
||||
|
||||
// lang files
|
||||
auto langDir = fs::path(mlc).append(L"sys/title/0005001b/1005c000/content");
|
||||
fs::create_directories(langDir);
|
||||
|
||||
auto langFile = fs::path(langDir).append("language.txt");
|
||||
if (!fs::exists(langFile))
|
||||
{
|
||||
std::ofstream file(langFile);
|
||||
if (file.is_open())
|
||||
{
|
||||
const char* langStrings[] = {"ja", "en", "fr", "de", "it", "es", "zh", "ko", "nl", "pt", "ru", "zh"};
|
||||
for (const char* lang : langStrings)
|
||||
file << fmt::format(R"("{}",)", lang) << std::endl;
|
||||
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
auto countryFile = fs::path(langDir).append("country.txt");
|
||||
if (!fs::exists(countryFile))
|
||||
{
|
||||
std::ofstream file(countryFile);
|
||||
for (sint32 i = 0; i < 201; i++)
|
||||
{
|
||||
const char* countryCode = NCrypto::GetCountryAsString(i);
|
||||
if (boost::iequals(countryCode, "NN"))
|
||||
file << "NULL," << std::endl;
|
||||
else
|
||||
file << fmt::format(R"("{}",)", countryCode) << std::endl;
|
||||
}
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
|
||||
// cemu directories
|
||||
const auto controllerProfileFolder = ActiveSettings::GetConfigPath(L"controllerProfiles").generic_wstring();
|
||||
if (!fs::exists(controllerProfileFolder))
|
||||
fs::create_directories(controllerProfileFolder);
|
||||
|
||||
const auto memorySearcherFolder = ActiveSettings::GetUserDataPath(L"memorySearcher").generic_wstring();
|
||||
if (!fs::exists(memorySearcherFolder))
|
||||
fs::create_directories(memorySearcherFolder);
|
||||
}
|
||||
enum StartGameResult : sint32
|
||||
{
|
||||
SUCCESSFUL = 0,
|
||||
ERROR_GAME_BASE_FILES_NOT_FOUND = 1,
|
||||
ERROR_NO_DISC_KEY = 2,
|
||||
ERROR_NO_TITLE_TIK = 3,
|
||||
ERROR_UNKNOWN = 4,
|
||||
};
|
||||
StartGameResult startGame(const fs::path& launchPath)
|
||||
{
|
||||
TitleInfo launchTitle{launchPath};
|
||||
if (launchTitle.IsValid())
|
||||
{
|
||||
// the title might not be in the TitleList, so we add it as a temporary entry
|
||||
CafeTitleList::AddTitleFromPath(launchPath);
|
||||
// title is valid, launch from TitleId
|
||||
TitleId baseTitleId;
|
||||
if (!CafeTitleList::FindBaseTitleId(launchTitle.GetAppTitleId(), baseTitleId))
|
||||
{
|
||||
return ERROR_GAME_BASE_FILES_NOT_FOUND;
|
||||
}
|
||||
CafeSystem::STATUS_CODE r = CafeSystem::PrepareForegroundTitle(baseTitleId);
|
||||
if (r != CafeSystem::STATUS_CODE::SUCCESS)
|
||||
{
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
else // if (launchTitle.GetFormat() == TitleInfo::TitleDataFormat::INVALID_STRUCTURE )
|
||||
{
|
||||
// title is invalid, if it's an RPX/ELF we can launch it directly
|
||||
// otherwise it's an error
|
||||
CafeTitleFileType fileType = DetermineCafeSystemFileType(launchPath);
|
||||
if (fileType == CafeTitleFileType::RPX || fileType == CafeTitleFileType::ELF)
|
||||
{
|
||||
CafeSystem::STATUS_CODE r = CafeSystem::PrepareForegroundTitleFromStandaloneRPX(launchPath);
|
||||
if (r != CafeSystem::STATUS_CODE::SUCCESS)
|
||||
{
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
else if (launchTitle.GetInvalidReason() == TitleInfo::InvalidReason::NO_DISC_KEY)
|
||||
{
|
||||
return ERROR_NO_DISC_KEY;
|
||||
}
|
||||
else if (launchTitle.GetInvalidReason() == TitleInfo::InvalidReason::NO_TITLE_TIK)
|
||||
{
|
||||
return ERROR_NO_TITLE_TIK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
CafeSystem::LaunchForegroundTitle();
|
||||
return SUCCESSFUL;
|
||||
}
|
||||
} // namespace NativeEmulation
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_setReplaceTVWithPadView([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean swapped)
|
||||
{
|
||||
// Emulate pressing the TAB key for showing DRC instead of TV
|
||||
GuiSystem::getWindowInfo().set_keystate(GuiSystem::PlatformKeyCodes::TAB, swapped);
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_initializeActiveSettings(JNIEnv* env, [[maybe_unused]] jclass clazz, jstring data_path, jstring cache_path)
|
||||
{
|
||||
std::string dataPath = JNIUtils::JStringToString(env, data_path);
|
||||
std::string cachePath = JNIUtils::JStringToString(env, cache_path);
|
||||
std::set<fs::path> failedWriteAccess;
|
||||
ActiveSettings::SetPaths(false, {}, dataPath, dataPath, cachePath, dataPath, failedWriteAccess);
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_initializeEmulation([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
FilesystemAndroid::setFilesystemCallbacks(std::make_shared<AndroidFilesystemCallbacks>());
|
||||
g_config.SetFilename(ActiveSettings::GetConfigPath("settings.xml").generic_wstring());
|
||||
NativeEmulation::createCemuDirectories();
|
||||
NetworkConfig::LoadOnce();
|
||||
ActiveSettings::Init();
|
||||
LatteOverlay_init();
|
||||
CemuCommonInit();
|
||||
InitializeGlobalVulkan();
|
||||
// TODO: move this
|
||||
// fillGraphicPacks();
|
||||
}
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_initializerRenderer(JNIEnv* env, [[maybe_unused]] jclass clazz, jobject testSurface)
|
||||
{
|
||||
JNIUtils::handleNativeException(env, [&]() {
|
||||
cemu_assert_debug(testSurface != nullptr);
|
||||
// TODO: cleanup surface
|
||||
GuiSystem::getWindowInfo().window_main.surface = ANativeWindow_fromSurface(env, testSurface);
|
||||
g_renderer = std::make_unique<VulkanRenderer>();
|
||||
});
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_setDPI([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jfloat dpi)
|
||||
{
|
||||
auto& windowInfo = GuiSystem::getWindowInfo();
|
||||
windowInfo.dpi_scale = windowInfo.pad_dpi_scale = dpi;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_clearSurface([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean is_main_canvas)
|
||||
{
|
||||
if (!is_main_canvas)
|
||||
{
|
||||
auto renderer = static_cast<VulkanRenderer*>(g_renderer.get());
|
||||
if (renderer)
|
||||
renderer->StopUsingPadAndWait();
|
||||
}
|
||||
}
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_recreateRenderSurface([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean is_main_canvas)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_setSurface(JNIEnv* env, [[maybe_unused]] jclass clazz, jobject surface, jboolean is_main_canvas)
|
||||
{
|
||||
JNIUtils::handleNativeException(env, [&]() {
|
||||
cemu_assert_debug(surface != nullptr);
|
||||
auto& windowHandleInfo = is_main_canvas ? GuiSystem::getWindowInfo().canvas_main : GuiSystem::getWindowInfo().canvas_pad;
|
||||
if (windowHandleInfo.surface)
|
||||
{
|
||||
ANativeWindow_release(static_cast<ANativeWindow*>(windowHandleInfo.surface));
|
||||
windowHandleInfo.surface = nullptr;
|
||||
}
|
||||
windowHandleInfo.surface = ANativeWindow_fromSurface(env, surface);
|
||||
int width, height;
|
||||
if (is_main_canvas)
|
||||
GuiSystem::getWindowPhysSize(width, height);
|
||||
else
|
||||
GuiSystem::getPadWindowPhysSize(width, height);
|
||||
VulkanRenderer::GetInstance()->InitializeSurface({width, height}, is_main_canvas);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_setSurfaceSize([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint width, jint height, jboolean is_main_canvas)
|
||||
{
|
||||
auto& windowInfo = GuiSystem::getWindowInfo();
|
||||
if (is_main_canvas)
|
||||
{
|
||||
windowInfo.width = windowInfo.phys_width = width;
|
||||
windowInfo.height = windowInfo.phys_height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
windowInfo.pad_width = windowInfo.phys_pad_width = width;
|
||||
windowInfo.pad_height = windowInfo.phys_pad_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeEmulation_startGame([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jstring launchPath)
|
||||
{
|
||||
GuiSystem::getWindowInfo().set_keystates_up();
|
||||
NativeEmulation::initializeAudioDevices();
|
||||
return NativeEmulation::startGame(JNIUtils::JStringToString(env, launchPath));
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "JNIUtils.h"
|
||||
#include "GameTitleLoader.h"
|
||||
#include "AndroidGameTitleLoadedCallback.h"
|
||||
|
||||
namespace NativeGameTitles
|
||||
{
|
||||
GameTitleLoader s_gameTitleLoader;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGameTitles_setGameTitleLoadedCallback(JNIEnv* env, [[maybe_unused]] jclass clazz, jobject game_title_loaded_callback)
|
||||
{
|
||||
if (game_title_loaded_callback == nullptr)
|
||||
{
|
||||
NativeGameTitles::s_gameTitleLoader.setOnTitleLoaded(nullptr);
|
||||
return;
|
||||
}
|
||||
jclass gameTitleLoadedCallbackClass = env->GetObjectClass(game_title_loaded_callback);
|
||||
jmethodID onGameTitleLoadedMID = env->GetMethodID(gameTitleLoadedCallbackClass, "onGameTitleLoaded", "(Ljava/lang/String;Ljava/lang/String;[III)V");
|
||||
env->DeleteLocalRef(gameTitleLoadedCallbackClass);
|
||||
NativeGameTitles::s_gameTitleLoader.setOnTitleLoaded(std::make_shared<AndroidGameTitleLoadedCallback>(onGameTitleLoadedMID, game_title_loaded_callback));
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGameTitles_reloadGameTitles([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
NativeGameTitles::s_gameTitleLoader.reloadGameTitles();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jobject JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGameTitles_getInstalledGamesTitleIds(JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return JNIUtils::createJavaLongArrayList(env, CafeTitleList::GetAllTitleIds());
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
#include "Cafe/CafeSystem.h"
|
||||
#include "config/CemuConfig.h"
|
||||
#include "Cafe/GraphicPack/GraphicPack2.h"
|
||||
#include "JNIUtils.h"
|
||||
|
||||
namespace NativeGraphicPacks
|
||||
{
|
||||
std::unordered_map<sint64, GraphicPackPtr> s_graphicPacks;
|
||||
|
||||
void fillGraphicPacks()
|
||||
{
|
||||
s_graphicPacks.clear();
|
||||
auto graphicPacks = GraphicPack2::GetGraphicPacks();
|
||||
for (auto&& graphicPack : graphicPacks)
|
||||
{
|
||||
s_graphicPacks[reinterpret_cast<sint64>(graphicPack.get())] = graphicPack;
|
||||
}
|
||||
}
|
||||
|
||||
void saveGraphicPackStateToConfig(GraphicPackPtr graphicPack)
|
||||
{
|
||||
auto& data = g_config.data();
|
||||
auto filename = _utf8ToPath(graphicPack->GetNormalizedPathString());
|
||||
if (data.graphic_pack_entries.contains(filename))
|
||||
data.graphic_pack_entries.erase(filename);
|
||||
if (graphicPack->IsEnabled())
|
||||
{
|
||||
data.graphic_pack_entries.try_emplace(filename);
|
||||
auto& it = data.graphic_pack_entries[filename];
|
||||
// otherwise store all selected presets
|
||||
for (const auto& preset : graphicPack->GetActivePresets())
|
||||
it.try_emplace(preset->category, preset->name);
|
||||
}
|
||||
else if (graphicPack->IsDefaultEnabled())
|
||||
{
|
||||
// save that its disabled
|
||||
data.graphic_pack_entries.try_emplace(filename);
|
||||
auto& it = data.graphic_pack_entries[filename];
|
||||
it.try_emplace("_disabled", "false");
|
||||
}
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
jobject getGraphicPresets(JNIEnv* env, GraphicPackPtr graphicPack, sint64 id)
|
||||
{
|
||||
auto graphicPackPresetClass = env->FindClass("info/cemu/Cemu/nativeinterface/NativeGraphicPacks$GraphicPackPreset");
|
||||
auto graphicPackPresetCtorId = env->GetMethodID(graphicPackPresetClass, "<init>", "(JLjava/lang/String;Ljava/util/ArrayList;Ljava/lang/String;)V");
|
||||
|
||||
std::vector<std::string> order;
|
||||
auto presets = graphicPack->GetCategorizedPresets(order);
|
||||
|
||||
std::vector<jobject> presetsJobjects;
|
||||
for (const auto& category : order)
|
||||
{
|
||||
const auto& entry = presets[category];
|
||||
// test if any preset is visible and update its status
|
||||
if (std::none_of(entry.cbegin(), entry.cend(), [graphicPack](const auto& p) { return p->visible; }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
jstring categoryJStr = category.empty() ? nullptr : env->NewStringUTF(category.c_str());
|
||||
std::vector<std::string> presetSelections;
|
||||
std::optional<std::string> activePreset;
|
||||
for (auto& pentry : entry)
|
||||
{
|
||||
if (!pentry->visible)
|
||||
continue;
|
||||
|
||||
presetSelections.push_back(pentry->name);
|
||||
|
||||
if (pentry->active)
|
||||
activePreset = pentry->name;
|
||||
}
|
||||
|
||||
jstring activePresetJstr = nullptr;
|
||||
if (activePreset)
|
||||
activePresetJstr = env->NewStringUTF(activePreset->c_str());
|
||||
else if (!presetSelections.empty())
|
||||
activePresetJstr = env->NewStringUTF(presetSelections.front().c_str());
|
||||
auto presetJObject = env->NewObject(graphicPackPresetClass, graphicPackPresetCtorId, id, categoryJStr, JNIUtils::createJavaStringArrayList(env, presetSelections), activePresetJstr);
|
||||
presetsJobjects.push_back(presetJObject);
|
||||
}
|
||||
return JNIUtils::createArrayList(env, presetsJobjects);
|
||||
}
|
||||
} // namespace NativeGraphicPacks
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGraphicPacks_refreshGraphicPacks([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
if (!CafeSystem::IsTitleRunning())
|
||||
{
|
||||
GraphicPack2::ClearGraphicPacks();
|
||||
GraphicPack2::LoadAll();
|
||||
NativeGraphicPacks::fillGraphicPacks();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jobject JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGraphicPacks_getGraphicPackBasicInfos(JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
auto graphicPackInfoClass = env->FindClass("info/cemu/Cemu/nativeinterface/NativeGraphicPacks$GraphicPackBasicInfo");
|
||||
auto graphicPackInfoCtorId = env->GetMethodID(graphicPackInfoClass, "<init>", "(JLjava/lang/String;Ljava/util/ArrayList;)V");
|
||||
|
||||
std::vector<jobject> graphicPackInfoJObjects;
|
||||
for (auto&& graphicPack : NativeGraphicPacks::s_graphicPacks)
|
||||
{
|
||||
jstring virtualPath = env->NewStringUTF(graphicPack.second->GetVirtualPath().c_str());
|
||||
jlong id = graphicPack.first;
|
||||
jobject titleIds = JNIUtils::createJavaLongArrayList(env, graphicPack.second->GetTitleIds());
|
||||
jobject jGraphicPack = env->NewObject(graphicPackInfoClass, graphicPackInfoCtorId, id, virtualPath, titleIds);
|
||||
graphicPackInfoJObjects.push_back(jGraphicPack);
|
||||
}
|
||||
return JNIUtils::createArrayList(env, graphicPackInfoJObjects);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jobject JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGraphicPacks_getGraphicPack(JNIEnv* env, [[maybe_unused]] jclass clazz, jlong id)
|
||||
{
|
||||
auto graphicPackClass = env->FindClass("info/cemu/Cemu/nativeinterface/NativeGraphicPacks$GraphicPack");
|
||||
auto graphicPackCtorId = env->GetMethodID(graphicPackClass, "<init>", "(JZLjava/lang/String;Ljava/lang/String;Ljava/util/ArrayList;)V");
|
||||
auto graphicPack = NativeGraphicPacks::s_graphicPacks.at(id);
|
||||
|
||||
jstring graphicPackName = env->NewStringUTF(graphicPack->GetName().c_str());
|
||||
jstring graphicPackDescription = env->NewStringUTF(graphicPack->GetDescription().c_str());
|
||||
return env->NewObject(
|
||||
graphicPackClass,
|
||||
graphicPackCtorId,
|
||||
id,
|
||||
graphicPack->IsEnabled(),
|
||||
graphicPackName,
|
||||
graphicPackDescription,
|
||||
NativeGraphicPacks::getGraphicPresets(env, graphicPack, id));
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGraphicPacks_setGraphicPackActive([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jlong id, jboolean active)
|
||||
{
|
||||
auto graphicPack = NativeGraphicPacks::s_graphicPacks.at(id);
|
||||
graphicPack->SetEnabled(active);
|
||||
NativeGraphicPacks::saveGraphicPackStateToConfig(graphicPack);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGraphicPacks_setGraphicPackActivePreset([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jlong id, jstring category, jstring preset)
|
||||
{
|
||||
std::string presetCategory = category == nullptr ? "" : JNIUtils::JStringToString(env, category);
|
||||
auto graphicPack = NativeGraphicPacks::s_graphicPacks.at(id);
|
||||
graphicPack->SetActivePreset(presetCategory, JNIUtils::JStringToString(env, preset));
|
||||
NativeGraphicPacks::saveGraphicPackStateToConfig(graphicPack);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jobject JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeGraphicPacks_getGraphicPackPresets(JNIEnv* env, [[maybe_unused]] jclass clazz, jlong id)
|
||||
{
|
||||
return NativeGraphicPacks::getGraphicPresets(env, NativeGraphicPacks::s_graphicPacks.at(id), id);
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
#include "JNIUtils.h"
|
||||
#include "input/ControllerFactory.h"
|
||||
#include "input/InputManager.h"
|
||||
#include "input/api/Android/AndroidController.h"
|
||||
#include "input/api/Android/AndroidControllerProvider.h"
|
||||
#include "AndroidEmulatedController.h"
|
||||
|
||||
namespace NativeInput
|
||||
{
|
||||
WiiUMotionHandler s_wiiUMotionHandler{};
|
||||
long s_lastMotionTimestamp = 0;
|
||||
|
||||
void onTouchEvent(sint32 x, sint32 y, bool isTV, std::optional<bool> status = {})
|
||||
{
|
||||
auto& instance = InputManager::instance();
|
||||
auto& touchInfo = isTV ? instance.m_main_mouse : instance.m_pad_mouse;
|
||||
std::scoped_lock lock(touchInfo.m_mutex);
|
||||
touchInfo.position = {x, y};
|
||||
if (status.has_value())
|
||||
touchInfo.left_down = touchInfo.left_down_toggle = status.value();
|
||||
}
|
||||
} // namespace NativeInput
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_onNativeKey(JNIEnv* env, [[maybe_unused]] jclass clazz, jstring device_descriptor, jstring device_name, jint key, jboolean is_pressed)
|
||||
{
|
||||
auto deviceDescriptor = JNIUtils::JStringToString(env, device_descriptor);
|
||||
auto deviceName = JNIUtils::JStringToString(env, device_name);
|
||||
auto apiProvider = InputManager::instance().get_api_provider(InputAPI::Android);
|
||||
auto androidControllerProvider = dynamic_cast<AndroidControllerProvider*>(apiProvider.get());
|
||||
androidControllerProvider->on_key_event(deviceDescriptor, deviceName, key, is_pressed);
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_onNativeAxis(JNIEnv* env, [[maybe_unused]] jclass clazz, jstring device_descriptor, jstring device_name, jint axis, jfloat value)
|
||||
{
|
||||
auto deviceDescriptor = JNIUtils::JStringToString(env, device_descriptor);
|
||||
auto deviceName = JNIUtils::JStringToString(env, device_name);
|
||||
auto apiProvider = InputManager::instance().get_api_provider(InputAPI::Android);
|
||||
auto androidControllerProvider = dynamic_cast<AndroidControllerProvider*>(apiProvider.get());
|
||||
androidControllerProvider->on_axis_event(deviceDescriptor, deviceName, axis, value);
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_setControllerType([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint index, jint emulated_controller_type)
|
||||
{
|
||||
auto type = static_cast<EmulatedController::Type>(emulated_controller_type);
|
||||
auto& androidEmulatedController = AndroidEmulatedController::getAndroidEmulatedController(index);
|
||||
if (EmulatedController::Type::VPAD <= type && type < EmulatedController::Type::MAX)
|
||||
androidEmulatedController.setType(type);
|
||||
else
|
||||
androidEmulatedController.setDisabled();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_getControllerType([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint index)
|
||||
{
|
||||
auto emulatedController = AndroidEmulatedController::getAndroidEmulatedController(index).getEmulatedController();
|
||||
if (emulatedController)
|
||||
return emulatedController->type();
|
||||
throw std::runtime_error(fmt::format("can't get type for emulated controller {}", index));
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_getWPADControllersCount([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
int wpadCount = 0;
|
||||
for (size_t i = 0; i < InputManager::kMaxController; i++)
|
||||
{
|
||||
auto emulatedController = AndroidEmulatedController::getAndroidEmulatedController(i).getEmulatedController();
|
||||
if (!emulatedController)
|
||||
continue;
|
||||
if (emulatedController->type() != EmulatedController::Type::VPAD)
|
||||
++wpadCount;
|
||||
}
|
||||
return wpadCount;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_getVPADControllersCount([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
int vpadCount = 0;
|
||||
for (size_t i = 0; i < InputManager::kMaxController; i++)
|
||||
{
|
||||
auto emulatedController = AndroidEmulatedController::getAndroidEmulatedController(i).getEmulatedController();
|
||||
if (!emulatedController)
|
||||
continue;
|
||||
if (emulatedController->type() == EmulatedController::Type::VPAD)
|
||||
++vpadCount;
|
||||
}
|
||||
return vpadCount;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_isControllerDisabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint index)
|
||||
{
|
||||
return AndroidEmulatedController::getAndroidEmulatedController(index).getEmulatedController() == nullptr;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_setControllerMapping(JNIEnv* env, [[maybe_unused]] jclass clazz, jstring device_descriptor, jstring device_name, jint index, jint mapping_id, jint button_id)
|
||||
{
|
||||
auto deviceName = JNIUtils::JStringToString(env, device_name);
|
||||
auto deviceDescriptor = JNIUtils::JStringToString(env, device_descriptor);
|
||||
auto apiProvider = InputManager::instance().get_api_provider(InputAPI::Android);
|
||||
auto controller = ControllerFactory::CreateController(InputAPI::Android, deviceDescriptor, deviceName);
|
||||
AndroidEmulatedController::getAndroidEmulatedController(index).setMapping(mapping_id, controller, button_id);
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jstring JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_getControllerMapping(JNIEnv* env, [[maybe_unused]] jclass clazz, jint index, jint mapping_id)
|
||||
{
|
||||
auto mapping = AndroidEmulatedController::getAndroidEmulatedController(index).getMapping(mapping_id);
|
||||
return env->NewStringUTF(mapping.value_or("").c_str());
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_clearControllerMapping([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint index, jint mapping_id)
|
||||
{
|
||||
AndroidEmulatedController::getAndroidEmulatedController(index).clearMapping(mapping_id);
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jobject JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_getControllerMappings(JNIEnv* env, [[maybe_unused]] jclass clazz, jint index)
|
||||
{
|
||||
jclass hashMapClass = env->FindClass("java/util/HashMap");
|
||||
jmethodID hashMapConstructor = env->GetMethodID(hashMapClass, "<init>", "()V");
|
||||
jmethodID hashMapPut = env->GetMethodID(hashMapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
jclass integerClass = env->FindClass("java/lang/Integer");
|
||||
jmethodID integerConstructor = env->GetMethodID(integerClass, "<init>", "(I)V");
|
||||
jobject hashMapObj = env->NewObject(hashMapClass, hashMapConstructor);
|
||||
auto mappings = AndroidEmulatedController::getAndroidEmulatedController(index).getMappings();
|
||||
for (const auto& pair : mappings)
|
||||
{
|
||||
jint key = pair.first;
|
||||
jstring buttonName = env->NewStringUTF(pair.second.c_str());
|
||||
jobject mappingId = env->NewObject(integerClass, integerConstructor, key);
|
||||
env->CallObjectMethod(hashMapObj, hashMapPut, mappingId, buttonName);
|
||||
}
|
||||
return hashMapObj;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_onTouchDown([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint x, jint y, jboolean isTV)
|
||||
{
|
||||
NativeInput::onTouchEvent(x, y, isTV, true);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_onTouchUp([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint x, jint y, jboolean isTV)
|
||||
{
|
||||
NativeInput::onTouchEvent(x, y, isTV, false);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_onTouchMove([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint x, jint y, jboolean isTV)
|
||||
{
|
||||
NativeInput::onTouchEvent(x, y, isTV);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_onMotion([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jlong timestamp, jfloat gyroX, jfloat gyroY, jfloat gyroZ, jfloat accelX, jfloat accelY, jfloat accelZ)
|
||||
{
|
||||
float deltaTime = (timestamp - NativeInput::s_lastMotionTimestamp) * 1e-9f;
|
||||
NativeInput::s_wiiUMotionHandler.processMotionSample(deltaTime, gyroX, gyroY, gyroZ, accelX * 0.098066f, -accelY * 0.098066f, -accelZ * 0.098066f);
|
||||
NativeInput::s_lastMotionTimestamp = timestamp;
|
||||
auto& deviceMotion = InputManager::instance().m_device_motion;
|
||||
std::scoped_lock lock{deviceMotion.m_mutex};
|
||||
deviceMotion.m_motion_sample = NativeInput::s_wiiUMotionHandler.getMotionSample();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_setMotionEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean motionEnabled)
|
||||
{
|
||||
auto& deviceMotion = InputManager::instance().m_device_motion;
|
||||
std::scoped_lock lock{deviceMotion.m_mutex};
|
||||
deviceMotion.m_device_motion_enabled = motionEnabled;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_onOverlayButton([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint controllerIndex, jint mappingId, jboolean state)
|
||||
{
|
||||
AndroidEmulatedController::getAndroidEmulatedController(controllerIndex).setButtonValue(mappingId, state);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeInput_onOverlayAxis([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint controllerIndex, jint mappingId, jfloat value)
|
||||
{
|
||||
AndroidEmulatedController::getAndroidEmulatedController(controllerIndex).setAxisValue(mappingId, value);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "JNIUtils.h"
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, [[maybe_unused]] void* reserved)
|
||||
{
|
||||
JNIUtils::g_jvm = vm;
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
#include "JNIUtils.h"
|
||||
#include "config/CemuConfig.h"
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getOverlayPosition([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return static_cast<jint>(g_config.data().overlay.position);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setOverlayPosition([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint position)
|
||||
{
|
||||
g_config.data().overlay.position = static_cast<ScreenPosition>(position);
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isOverlayFPSEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().overlay.fps;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setOverlayFPSEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().overlay.fps = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isOverlayDrawCallsPerFrameEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().overlay.drawcalls;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setOverlayDrawCallsPerFrameEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().overlay.drawcalls = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isOverlayCPUUsageEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().overlay.cpu_usage;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setOverlayCPUUsageEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().overlay.cpu_usage = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isOverlayCPUPerCoreUsageEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().overlay.cpu_per_core_usage;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setOverlayCPUPerCoreUsageEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().overlay.cpu_per_core_usage = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isOverlayRAMUsageEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().overlay.ram_usage;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setOverlayRAMUsageEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().overlay.ram_usage = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isOverlayVRAMUsageEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().overlay.vram_usage;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setOverlayVRAMUsageEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().overlay.vram_usage = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isOverlayDebugEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().overlay.debug;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setOverlayDebugEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().overlay.debug = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getNotificationsPosition([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return static_cast<jint>(g_config.data().notification.position);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setNotificationsPosition([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint position)
|
||||
{
|
||||
g_config.data().notification.position = static_cast<ScreenPosition>(position);
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isNotificationControllerProfilesEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().notification.controller_profiles;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setNotificationControllerProfilesEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().notification.controller_profiles = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isNotificationShaderCompilerEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().notification.shader_compiling;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setNotificationShaderCompilerEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().notification.shader_compiling = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_isNotificationFriendListEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().notification.friends;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setNotificationFriendListEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().notification.friends = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_addGamesPath(JNIEnv* env, [[maybe_unused]] jclass clazz, jstring uri)
|
||||
{
|
||||
auto& gamePaths = g_config.data().game_paths;
|
||||
auto gamePath = JNIUtils::JStringToString(env, uri);
|
||||
if (std::any_of(gamePaths.begin(), gamePaths.end(), [&](auto path) { return path == gamePath; }))
|
||||
return;
|
||||
gamePaths.push_back(gamePath);
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_removeGamesPath(JNIEnv* env, [[maybe_unused]] jclass clazz, jstring uri)
|
||||
{
|
||||
auto gamePath = JNIUtils::JStringToString(env, uri);
|
||||
auto& gamePaths = g_config.data().game_paths;
|
||||
std::erase_if(gamePaths, [&](auto path) { return path == gamePath; });
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jobject JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getGamesPaths(JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return JNIUtils::createJavaStringArrayList(env, g_config.data().game_paths);
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getAsyncShaderCompile([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().async_compile;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setAsyncShaderCompile([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().async_compile = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getVSyncMode([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().vsync;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setVSyncMode([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint vsync_mode)
|
||||
{
|
||||
g_config.data().vsync = vsync_mode;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getAccurateBarriers([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz)
|
||||
{
|
||||
return g_config.data().vk_accurate_barriers;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setAccurateBarriers([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled)
|
||||
{
|
||||
g_config.data().vk_accurate_barriers = enabled;
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jboolean JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getAudioDeviceEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean tv)
|
||||
{
|
||||
const auto& device = tv ? g_config.data().tv_device : g_config.data().pad_device;
|
||||
return !device.empty();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setAudioDeviceEnabled([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean enabled, jboolean tv)
|
||||
{
|
||||
auto& device = tv ? g_config.data().tv_device : g_config.data().pad_device;
|
||||
if (enabled)
|
||||
device = L"Default";
|
||||
else
|
||||
device.clear();
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getAudioDeviceChannels([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean tv)
|
||||
{
|
||||
const auto& deviceChannels = tv ? g_config.data().tv_channels : g_config.data().pad_channels;
|
||||
return deviceChannels;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setAudioDeviceChannels([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint channels, jboolean tv)
|
||||
{
|
||||
auto& deviceChannels = tv ? g_config.data().tv_channels : g_config.data().pad_channels;
|
||||
deviceChannels = static_cast<AudioChannels>(channels);
|
||||
g_config.Save();
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT jint JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_getAudioDeviceVolume([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jboolean tv)
|
||||
{
|
||||
const auto& deviceVolume = tv ? g_config.data().tv_volume : g_config.data().pad_volume;
|
||||
return deviceVolume;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] JNIEXPORT void JNICALL
|
||||
Java_info_cemu_Cemu_nativeinterface_NativeSettings_setAudioDeviceVolume([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, jint volume, jboolean tv)
|
||||
{
|
||||
auto& deviceVolume = tv ? g_config.data().tv_volume : g_config.data().pad_volume;
|
||||
deviceVolume = volume;
|
||||
g_config.Save();
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
#include "Utils.h"
|
||||
|
||||
#include "Cemu/ncrypto/ncrypto.h"
|
||||
#include "config/ActiveSettings.h"
|
||||
|
||||
void createCemuDirectories()
|
||||
{
|
||||
std::wstring mlc = ActiveSettings::GetMlcPath().generic_wstring();
|
||||
|
||||
// create sys/usr folder in mlc01
|
||||
try
|
||||
{
|
||||
const auto sysFolder = fs::path(mlc).append(L"sys");
|
||||
fs::create_directories(sysFolder);
|
||||
|
||||
const auto usrFolder = fs::path(mlc).append(L"usr");
|
||||
fs::create_directories(usrFolder);
|
||||
fs::create_directories(fs::path(usrFolder).append("title/00050000")); // base
|
||||
fs::create_directories(fs::path(usrFolder).append("title/0005000c")); // dlc
|
||||
fs::create_directories(fs::path(usrFolder).append("title/0005000e")); // update
|
||||
|
||||
// Mii Maker save folders {0x500101004A000, 0x500101004A100, 0x500101004A200},
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a000/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a100/user/common/db"));
|
||||
fs::create_directories(fs::path(mlc).append(L"usr/save/00050010/1004a200/user/common/db"));
|
||||
|
||||
// lang files
|
||||
auto langDir = fs::path(mlc).append(L"sys/title/0005001b/1005c000/content");
|
||||
fs::create_directories(langDir);
|
||||
|
||||
auto langFile = fs::path(langDir).append("language.txt");
|
||||
if (!fs::exists(langFile))
|
||||
{
|
||||
std::ofstream file(langFile);
|
||||
if (file.is_open())
|
||||
{
|
||||
const char* langStrings[] = {"ja", "en", "fr", "de", "it", "es", "zh", "ko", "nl", "pt", "ru", "zh"};
|
||||
for (const char* lang : langStrings)
|
||||
file << fmt::format(R"("{}",)", lang) << std::endl;
|
||||
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
auto countryFile = fs::path(langDir).append("country.txt");
|
||||
if (!fs::exists(countryFile))
|
||||
{
|
||||
std::ofstream file(countryFile);
|
||||
for (sint32 i = 0; i < 201; i++)
|
||||
{
|
||||
const char* countryCode = NCrypto::GetCountryAsString(i);
|
||||
if (boost::iequals(countryCode, "NN"))
|
||||
file << "NULL," << std::endl;
|
||||
else
|
||||
file << fmt::format(R"("{}",)", countryCode) << std::endl;
|
||||
}
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
} catch (const std::exception& ex)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// cemu directories
|
||||
try
|
||||
{
|
||||
const auto controllerProfileFolder = ActiveSettings::GetConfigPath(L"controllerProfiles").generic_wstring();
|
||||
if (!fs::exists(controllerProfileFolder))
|
||||
fs::create_directories(controllerProfileFolder);
|
||||
|
||||
const auto memorySearcherFolder = ActiveSettings::GetUserDataPath(L"memorySearcher").generic_wstring();
|
||||
if (!fs::exists(memorySearcherFolder))
|
||||
fs::create_directories(memorySearcherFolder);
|
||||
} catch (const std::exception& ex)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "config/ActiveSettings.h"
|
||||
#include "Cemu/ncrypto/ncrypto.h"
|
||||
|
||||
void createCemuDirectories();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,12 +4,15 @@ import android.app.Application;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
import info.cemu.Cemu.NativeLibrary;
|
||||
import info.cemu.Cemu.utils.FileUtil;
|
||||
import info.cemu.Cemu.nativeinterface.NativeEmulation;
|
||||
import info.cemu.Cemu.nativeinterface.NativeGraphicPacks;
|
||||
|
||||
public class CemuApplication extends Application {
|
||||
static {
|
||||
System.loadLibrary("CemuAndroid");
|
||||
}
|
||||
|
||||
private static CemuApplication application;
|
||||
|
||||
public CemuApplication() {
|
||||
@@ -31,8 +34,9 @@ public class CemuApplication extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
||||
NativeLibrary.setDPI(displayMetrics.density);
|
||||
NativeLibrary.initializeActiveSettings(getInternalFolder().toString(), getInternalFolder().toString());
|
||||
NativeLibrary.initializeEmulation();
|
||||
NativeEmulation.setDPI(displayMetrics.density);
|
||||
NativeEmulation.initializeActiveSettings(getInternalFolder().toString(), getInternalFolder().toString());
|
||||
NativeEmulation.initializeEmulation();
|
||||
NativeGraphicPacks.refreshGraphicPacks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,412 +0,0 @@
|
||||
package info.cemu.Cemu;
|
||||
|
||||
import android.view.Surface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class NativeLibrary {
|
||||
static {
|
||||
System.loadLibrary("CemuAndroid");
|
||||
}
|
||||
|
||||
public static native void setDPI(float dpi);
|
||||
|
||||
public static native void setSurface(Surface surface, boolean isMainCanvas);
|
||||
|
||||
public static native void clearSurface(boolean isMainCanvas);
|
||||
|
||||
public static native void setSurfaceSize(int width, int height, boolean isMainCanvas);
|
||||
|
||||
public static native void initializerRenderer(Surface surface);
|
||||
|
||||
public static class GameFilesException extends RuntimeException {
|
||||
}
|
||||
|
||||
public static class GameBaseFilesNotFoundException extends GameFilesException {
|
||||
}
|
||||
|
||||
public static class NoDiscKeyException extends GameFilesException {
|
||||
}
|
||||
|
||||
public static class NoTitleTikException extends GameFilesException {
|
||||
}
|
||||
|
||||
public static class UnknownGameFilesException extends GameFilesException {
|
||||
}
|
||||
|
||||
public static native void startGame(String launchPath);
|
||||
|
||||
public static native void setReplaceTVWithPadView(boolean swapped);
|
||||
|
||||
public static native void recreateRenderSurface(boolean isMainCanvas);
|
||||
|
||||
public interface GameTitleLoadedCallback {
|
||||
void onGameTitleLoaded(String path, String title, int[] colors, int width, int height);
|
||||
}
|
||||
|
||||
public static native void setGameTitleLoadedCallback(GameTitleLoadedCallback gameTitleLoadedCallback);
|
||||
|
||||
public static native void reloadGameTitles();
|
||||
|
||||
public static native void initializeActiveSettings(String dataPath, String cachePath);
|
||||
|
||||
public static native void initializeEmulation();
|
||||
|
||||
public static native void addGamesPath(String uri);
|
||||
|
||||
public static native void removeGamesPath(String uri);
|
||||
|
||||
public static native ArrayList<String> getGamesPaths();
|
||||
|
||||
public static native void onNativeKey(String deviceDescriptor, String deviceName, int key, boolean isPressed);
|
||||
|
||||
public static native void onNativeAxis(String deviceDescriptor, String deviceName, int axis, float value);
|
||||
|
||||
public static final int VPAD_BUTTON_NONE = 0;
|
||||
public static final int VPAD_BUTTON_A = 1;
|
||||
public static final int VPAD_BUTTON_B = 2;
|
||||
public static final int VPAD_BUTTON_X = 3;
|
||||
public static final int VPAD_BUTTON_Y = 4;
|
||||
public static final int VPAD_BUTTON_L = 5;
|
||||
public static final int VPAD_BUTTON_R = 6;
|
||||
public static final int VPAD_BUTTON_ZL = 7;
|
||||
public static final int VPAD_BUTTON_ZR = 8;
|
||||
public static final int VPAD_BUTTON_PLUS = 9;
|
||||
public static final int VPAD_BUTTON_MINUS = 10;
|
||||
public static final int VPAD_BUTTON_UP = 11;
|
||||
public static final int VPAD_BUTTON_DOWN = 12;
|
||||
public static final int VPAD_BUTTON_LEFT = 13;
|
||||
public static final int VPAD_BUTTON_RIGHT = 14;
|
||||
public static final int VPAD_BUTTON_STICKL = 15;
|
||||
public static final int VPAD_BUTTON_STICKR = 16;
|
||||
public static final int VPAD_BUTTON_STICKL_UP = 17;
|
||||
public static final int VPAD_BUTTON_STICKL_DOWN = 18;
|
||||
public static final int VPAD_BUTTON_STICKL_LEFT = 19;
|
||||
public static final int VPAD_BUTTON_STICKL_RIGHT = 20;
|
||||
public static final int VPAD_BUTTON_STICKR_UP = 21;
|
||||
public static final int VPAD_BUTTON_STICKR_DOWN = 22;
|
||||
public static final int VPAD_BUTTON_STICKR_LEFT = 23;
|
||||
public static final int VPAD_BUTTON_STICKR_RIGHT = 24;
|
||||
public static final int VPAD_BUTTON_MIC = 25;
|
||||
public static final int VPAD_BUTTON_SCREEN = 26;
|
||||
public static final int VPAD_BUTTON_HOME = 27;
|
||||
public static final int VPAD_BUTTON_MAX = 28;
|
||||
|
||||
public static final int PRO_BUTTON_NONE = 0;
|
||||
public static final int PRO_BUTTON_A = 1;
|
||||
public static final int PRO_BUTTON_B = 2;
|
||||
public static final int PRO_BUTTON_X = 3;
|
||||
public static final int PRO_BUTTON_Y = 4;
|
||||
public static final int PRO_BUTTON_L = 5;
|
||||
public static final int PRO_BUTTON_R = 6;
|
||||
public static final int PRO_BUTTON_ZL = 7;
|
||||
public static final int PRO_BUTTON_ZR = 8;
|
||||
public static final int PRO_BUTTON_PLUS = 9;
|
||||
public static final int PRO_BUTTON_MINUS = 10;
|
||||
public static final int PRO_BUTTON_HOME = 11;
|
||||
public static final int PRO_BUTTON_UP = 12;
|
||||
public static final int PRO_BUTTON_DOWN = 13;
|
||||
public static final int PRO_BUTTON_LEFT = 14;
|
||||
public static final int PRO_BUTTON_RIGHT = 15;
|
||||
public static final int PRO_BUTTON_STICKL = 16;
|
||||
public static final int PRO_BUTTON_STICKR = 17;
|
||||
public static final int PRO_BUTTON_STICKL_UP = 18;
|
||||
public static final int PRO_BUTTON_STICKL_DOWN = 19;
|
||||
public static final int PRO_BUTTON_STICKL_LEFT = 20;
|
||||
public static final int PRO_BUTTON_STICKL_RIGHT = 21;
|
||||
public static final int PRO_BUTTON_STICKR_UP = 22;
|
||||
public static final int PRO_BUTTON_STICKR_DOWN = 23;
|
||||
public static final int PRO_BUTTON_STICKR_LEFT = 24;
|
||||
public static final int PRO_BUTTON_STICKR_RIGHT = 25;
|
||||
public static final int PRO_BUTTON_MAX = 26;
|
||||
|
||||
public static final int CLASSIC_BUTTON_NONE = 0;
|
||||
public static final int CLASSIC_BUTTON_A = 1;
|
||||
public static final int CLASSIC_BUTTON_B = 2;
|
||||
public static final int CLASSIC_BUTTON_X = 3;
|
||||
public static final int CLASSIC_BUTTON_Y = 4;
|
||||
public static final int CLASSIC_BUTTON_L = 5;
|
||||
public static final int CLASSIC_BUTTON_R = 6;
|
||||
public static final int CLASSIC_BUTTON_ZL = 7;
|
||||
public static final int CLASSIC_BUTTON_ZR = 8;
|
||||
public static final int CLASSIC_BUTTON_PLUS = 9;
|
||||
public static final int CLASSIC_BUTTON_MINUS = 10;
|
||||
public static final int CLASSIC_BUTTON_HOME = 11;
|
||||
public static final int CLASSIC_BUTTON_UP = 12;
|
||||
public static final int CLASSIC_BUTTON_DOWN = 13;
|
||||
public static final int CLASSIC_BUTTON_LEFT = 14;
|
||||
public static final int CLASSIC_BUTTON_RIGHT = 15;
|
||||
public static final int CLASSIC_BUTTON_STICKL_UP = 16;
|
||||
public static final int CLASSIC_BUTTON_STICKL_DOWN = 17;
|
||||
public static final int CLASSIC_BUTTON_STICKL_LEFT = 18;
|
||||
public static final int CLASSIC_BUTTON_STICKL_RIGHT = 19;
|
||||
public static final int CLASSIC_BUTTON_STICKR_UP = 20;
|
||||
public static final int CLASSIC_BUTTON_STICKR_DOWN = 21;
|
||||
public static final int CLASSIC_BUTTON_STICKR_LEFT = 22;
|
||||
public static final int CLASSIC_BUTTON_STICKR_RIGHT = 23;
|
||||
public static final int CLASSIC_BUTTON_MAX = 24;
|
||||
|
||||
public static final int WIIMOTE_BUTTON_NONE = 0;
|
||||
public static final int WIIMOTE_BUTTON_A = 1;
|
||||
public static final int WIIMOTE_BUTTON_B = 2;
|
||||
public static final int WIIMOTE_BUTTON_1 = 3;
|
||||
public static final int WIIMOTE_BUTTON_2 = 4;
|
||||
public static final int WIIMOTE_BUTTON_NUNCHUCK_Z = 5;
|
||||
public static final int WIIMOTE_BUTTON_NUNCHUCK_C = 6;
|
||||
public static final int WIIMOTE_BUTTON_PLUS = 7;
|
||||
public static final int WIIMOTE_BUTTON_MINUS = 8;
|
||||
public static final int WIIMOTE_BUTTON_UP = 9;
|
||||
public static final int WIIMOTE_BUTTON_DOWN = 10;
|
||||
public static final int WIIMOTE_BUTTON_LEFT = 11;
|
||||
public static final int WIIMOTE_BUTTON_RIGHT = 12;
|
||||
public static final int WIIMOTE_BUTTON_NUNCHUCK_UP = 13;
|
||||
public static final int WIIMOTE_BUTTON_NUNCHUCK_DOWN = 14;
|
||||
public static final int WIIMOTE_BUTTON_NUNCHUCK_LEFT = 15;
|
||||
public static final int WIIMOTE_BUTTON_NUNCHUCK_RIGHT = 16;
|
||||
public static final int WIIMOTE_BUTTON_HOME = 17;
|
||||
public static final int WIIMOTE_BUTTON_MAX = 18;
|
||||
|
||||
public static final int EMULATED_CONTROLLER_TYPE_VPAD = 0;
|
||||
public static final int EMULATED_CONTROLLER_TYPE_PRO = 1;
|
||||
public static final int EMULATED_CONTROLLER_TYPE_CLASSIC = 2;
|
||||
public static final int EMULATED_CONTROLLER_TYPE_WIIMOTE = 3;
|
||||
public static final int EMULATED_CONTROLLER_TYPE_DISABLED = -1;
|
||||
|
||||
public static final int DPAD_UP = 34;
|
||||
public static final int DPAD_DOWN = 35;
|
||||
public static final int DPAD_LEFT = 36;
|
||||
public static final int DPAD_RIGHT = 37;
|
||||
public static final int AXIS_X_POS = 38;
|
||||
public static final int AXIS_Y_POS = 39;
|
||||
public static final int ROTATION_X_POS = 40;
|
||||
public static final int ROTATION_Y_POS = 41;
|
||||
public static final int TRIGGER_X_POS = 42;
|
||||
public static final int TRIGGER_Y_POS = 43;
|
||||
public static final int AXIS_X_NEG = 44;
|
||||
public static final int AXIS_Y_NEG = 45;
|
||||
public static final int ROTATION_X_NEG = 46;
|
||||
public static final int ROTATION_Y_NEG = 47;
|
||||
|
||||
public static final int MAX_CONTROLLERS = 8;
|
||||
public static final int MAX_VPAD_CONTROLLERS = 2;
|
||||
public static final int MAX_WPAD_CONTROLLERS = 7;
|
||||
|
||||
public static native void setControllerType(int index, int emulatedControllerType);
|
||||
|
||||
public static native boolean isControllerDisabled(int index);
|
||||
|
||||
public static native int getControllerType(int index);
|
||||
|
||||
public static native int getWPADControllersCount();
|
||||
|
||||
public static native int getVPADControllersCount();
|
||||
|
||||
public static native void setControllerMapping(String deviceDescriptor, String deviceName, int index, int mappingId, int buttonId);
|
||||
|
||||
public static native void clearControllerMapping(int index, int mappingId);
|
||||
|
||||
public static native String getControllerMapping(int index, int mappingId);
|
||||
|
||||
public static native Map<Integer, String> getControllerMappings(int index);
|
||||
|
||||
public static native void onKeyEvent(String deviceDescriptor, String deviceName, int keyCode, boolean isPressed);
|
||||
|
||||
public static native void onAxisEvent(String deviceDescriptor, String deviceName, int axisCode, float value);
|
||||
|
||||
public static native boolean getAsyncShaderCompile();
|
||||
|
||||
public static native void setAsyncShaderCompile(boolean enabled);
|
||||
|
||||
public static final int VSYNC_MODE_OFF = 0;
|
||||
public static final int VSYNC_MODE_DOUBLE_BUFFERING = 1;
|
||||
public static final int VSYNC_MODE_TRIPLE_BUFFERING = 2;
|
||||
|
||||
public static native int getVSyncMode();
|
||||
|
||||
public static native void setVSyncMode(int vsyncMode);
|
||||
|
||||
public static native boolean getAccurateBarriers();
|
||||
|
||||
public static native void setAccurateBarriers(boolean enabled);
|
||||
|
||||
public static native boolean getAudioDeviceEnabled(boolean tv);
|
||||
|
||||
public static native void setAudioDeviceEnabled(boolean enabled, boolean tv);
|
||||
|
||||
public static final int AUDIO_CHANNELS_MONO = 0;
|
||||
public static final int AUDIO_CHANNELS_STEREO = 1;
|
||||
public static final int AUDIO_CHANNELS_SURROUND = 2;
|
||||
|
||||
public static native void setAudioDeviceChannels(int channels, boolean tv);
|
||||
|
||||
public static native int getAudioDeviceChannels(boolean tv);
|
||||
|
||||
public static final int AUDIO_MIN_VOLUME = 0;
|
||||
public static final int AUDIO_MAX_VOLUME = 100;
|
||||
|
||||
public static native void setAudioDeviceVolume(int volume, boolean tv);
|
||||
|
||||
public static native int getAudioDeviceVolume(boolean tv);
|
||||
|
||||
public record GraphicPackBasicInfo(long id, String virtualPath, ArrayList<Long> titleIds) {
|
||||
}
|
||||
|
||||
public static native ArrayList<Long> getInstalledGamesTitleIds();
|
||||
|
||||
public static native ArrayList<GraphicPackBasicInfo> getGraphicPackBasicInfos();
|
||||
|
||||
public static class GraphicPackPreset {
|
||||
private final long graphicPackId;
|
||||
private final String category;
|
||||
private final ArrayList<String> presets;
|
||||
private String activePreset;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(graphicPackId, category, presets, activePreset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object == null) return false;
|
||||
if (object == this) return true;
|
||||
if (object instanceof GraphicPackPreset preset)
|
||||
return this.hashCode() == preset.hashCode();
|
||||
return false;
|
||||
}
|
||||
|
||||
public GraphicPackPreset(long graphicPackId, String category, ArrayList<String> presets, String activePreset) {
|
||||
this.graphicPackId = graphicPackId;
|
||||
this.category = category;
|
||||
this.presets = presets;
|
||||
this.activePreset = activePreset;
|
||||
}
|
||||
|
||||
public String getActivePreset() {
|
||||
return activePreset;
|
||||
}
|
||||
|
||||
public void setActivePreset(String activePreset) {
|
||||
if (presets.stream().noneMatch(s -> s.equals(activePreset)))
|
||||
throw new IllegalArgumentException("Trying to set an invalid preset: " + activePreset);
|
||||
setGraphicPackActivePreset(graphicPackId, category, activePreset);
|
||||
this.activePreset = activePreset;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public ArrayList<String> getPresets() {
|
||||
return presets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class GraphicPack {
|
||||
public final long id;
|
||||
protected boolean active;
|
||||
public final String name;
|
||||
public final String description;
|
||||
public List<GraphicPackPreset> presets;
|
||||
|
||||
public GraphicPack(long id, boolean active, String name, String description, ArrayList<GraphicPackPreset> presets) {
|
||||
this.id = id;
|
||||
this.active = active;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.presets = presets;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void reloadPresets() {
|
||||
presets = NativeLibrary.getGraphicPackPresets(id);
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
setGraphicPackActive(id, active);
|
||||
}
|
||||
}
|
||||
|
||||
public static native void refreshGraphicPacks();
|
||||
|
||||
public static native GraphicPack getGraphicPack(long id);
|
||||
|
||||
public static native void setGraphicPackActive(long id, boolean active);
|
||||
|
||||
public static native void setGraphicPackActivePreset(long id, String category, String preset);
|
||||
|
||||
public static native ArrayList<GraphicPackPreset> getGraphicPackPresets(long id);
|
||||
|
||||
public static native void onOverlayButton(int controllerIndex, int mappingId, boolean value);
|
||||
|
||||
public static native void onOverlayAxis(int controllerIndex, int mappingId, float value);
|
||||
|
||||
public static final int OVERLAY_SCREEN_POSITION_DISABLED = 0;
|
||||
public static final int OVERLAY_SCREEN_POSITION_TOP_LEFT = 1;
|
||||
public static final int OVERLAY_SCREEN_POSITION_TOP_CENTER = 2;
|
||||
public static final int OVERLAY_SCREEN_POSITION_TOP_RIGHT = 3;
|
||||
public static final int OVERLAY_SCREEN_POSITION_BOTTOM_LEFT = 4;
|
||||
public static final int OVERLAY_SCREEN_POSITION_BOTTOM_CENTER = 5;
|
||||
public static final int OVERLAY_SCREEN_POSITION_BOTTOM_RIGHT = 6;
|
||||
|
||||
public static native int getOverlayPosition();
|
||||
|
||||
public static native void setOverlayPosition(int position);
|
||||
|
||||
public static native boolean isOverlayFPSEnabled();
|
||||
|
||||
public static native void setOverlayFPSEnabled(boolean enabled);
|
||||
|
||||
public static native boolean isOverlayDrawCallsPerFrameEnabled();
|
||||
|
||||
public static native void setOverlayDrawCallsPerFrameEnabled(boolean enabled);
|
||||
|
||||
public static native boolean isOverlayCPUUsageEnabled();
|
||||
|
||||
public static native void setOverlayCPUUsageEnabled(boolean enabled);
|
||||
|
||||
public static native boolean isOverlayCPUPerCoreUsageEnabled();
|
||||
|
||||
public static native void setOverlayCPUPerCoreUsageEnabled(boolean enabled);
|
||||
|
||||
public static native boolean isOverlayRAMUsageEnabled();
|
||||
|
||||
public static native void setOverlayRAMUsageEnabled(boolean enabled);
|
||||
|
||||
public static native boolean isOverlayDebugEnabled();
|
||||
|
||||
public static native void setOverlayDebugEnabled(boolean enabled);
|
||||
|
||||
public static native int getNotificationsPosition();
|
||||
|
||||
public static native void setNotificationsPosition(int position);
|
||||
|
||||
public static native boolean isNotificationControllerProfilesEnabled();
|
||||
|
||||
public static native void setNotificationControllerProfilesEnabled(boolean enabled);
|
||||
|
||||
public static native boolean isNotificationShaderCompilerEnabled();
|
||||
|
||||
public static native void setNotificationShaderCompilerEnabled(boolean enabled);
|
||||
|
||||
public static native boolean isNotificationFriendListEnabled();
|
||||
|
||||
public static native void setNotificationFriendListEnabled(boolean enabled);
|
||||
|
||||
public static native void onTouchDown(int x, int y, boolean isTV);
|
||||
|
||||
public static native void onTouchMove(int x, int y, boolean isTV);
|
||||
|
||||
public static native void onTouchUp(int x, int y, boolean isTV);
|
||||
|
||||
public static native void onMotion(long timestamp, float gyroX, float gyroY, float gyroZ, float accelX, float accelY, float accelZ);
|
||||
|
||||
public static native void setMotionEnabled(boolean motionEnabled);
|
||||
}
|
||||
@@ -22,13 +22,14 @@ import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import info.cemu.Cemu.NativeLibrary;
|
||||
import info.cemu.Cemu.nativeinterface.NativeEmulation;
|
||||
import info.cemu.Cemu.R;
|
||||
import info.cemu.Cemu.databinding.FragmentEmulationBinding;
|
||||
import info.cemu.Cemu.input.SensorManager;
|
||||
import info.cemu.Cemu.inputoverlay.InputOverlaySettingsProvider;
|
||||
import info.cemu.Cemu.inputoverlay.InputOverlaySurfaceView;
|
||||
import info.cemu.Cemu.nativeinterface.NativeException;
|
||||
import info.cemu.Cemu.nativeinterface.NativeInput;
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
public class EmulationFragment extends Fragment implements PopupMenu.OnMenuItemClickListener {
|
||||
@@ -51,16 +52,16 @@ public class EmulationFragment extends Fragment implements PopupMenu.OnMenuItemC
|
||||
int y = (int) event.getY(pointerIndex);
|
||||
switch (event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> {
|
||||
NativeLibrary.onTouchDown(x, y, isTV);
|
||||
NativeInput.onTouchDown(x, y, isTV);
|
||||
return true;
|
||||
}
|
||||
case MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> {
|
||||
currentPointerId = -1;
|
||||
NativeLibrary.onTouchUp(x, y, isTV);
|
||||
NativeInput.onTouchUp(x, y, isTV);
|
||||
return true;
|
||||
}
|
||||
case MotionEvent.ACTION_MOVE -> {
|
||||
NativeLibrary.onTouchMove(x, y, isTV);
|
||||
NativeInput.onTouchMove(x, y, isTV);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -83,11 +84,11 @@ public class EmulationFragment extends Fragment implements PopupMenu.OnMenuItemC
|
||||
@Override
|
||||
public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int format, int width, int height) {
|
||||
try {
|
||||
NativeLibrary.setSurfaceSize(width, height, isMainCanvas);
|
||||
NativeEmulation.setSurfaceSize(width, height, isMainCanvas);
|
||||
if (surfaceSet) {
|
||||
return;
|
||||
}
|
||||
NativeLibrary.setSurface(surfaceHolder.getSurface(), isMainCanvas);
|
||||
NativeEmulation.setSurface(surfaceHolder.getSurface(), isMainCanvas);
|
||||
surfaceSet = true;
|
||||
} catch (NativeException exception) {
|
||||
onEmulationError(getString(R.string.failed_create_surface_error, exception.getMessage()));
|
||||
@@ -96,7 +97,7 @@ public class EmulationFragment extends Fragment implements PopupMenu.OnMenuItemC
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {
|
||||
NativeLibrary.clearSurface(isMainCanvas);
|
||||
NativeEmulation.clearSurface(isMainCanvas);
|
||||
surfaceSet = false;
|
||||
}
|
||||
}
|
||||
@@ -212,7 +213,7 @@ public class EmulationFragment extends Fragment implements PopupMenu.OnMenuItemC
|
||||
}
|
||||
if (itemId == R.id.replace_tv_with_pad) {
|
||||
boolean replaceTVWithPad = !item.isChecked();
|
||||
NativeLibrary.setReplaceTVWithPadView(replaceTVWithPad);
|
||||
NativeEmulation.setReplaceTVWithPadView(replaceTVWithPad);
|
||||
item.setChecked(replaceTVWithPad);
|
||||
return true;
|
||||
}
|
||||
@@ -270,7 +271,7 @@ public class EmulationFragment extends Fragment implements PopupMenu.OnMenuItemC
|
||||
}
|
||||
SurfaceView mainCanvas = binding.mainCanvas;
|
||||
try {
|
||||
NativeLibrary.initializerRenderer(testSurface);
|
||||
NativeEmulation.initializerRenderer(testSurface);
|
||||
} catch (NativeException exception) {
|
||||
onEmulationError(getString(R.string.failed_initialize_renderer_error, exception.getMessage()));
|
||||
return binding.getRoot();
|
||||
@@ -302,17 +303,17 @@ public class EmulationFragment extends Fragment implements PopupMenu.OnMenuItemC
|
||||
}
|
||||
|
||||
private void startGame() {
|
||||
try {
|
||||
NativeLibrary.startGame(launchPath);
|
||||
} catch (NativeLibrary.GameBaseFilesNotFoundException exception) {
|
||||
onEmulationError(getString(R.string.game_not_found));
|
||||
} catch (NativeLibrary.NoDiscKeyException exception) {
|
||||
onEmulationError(getString(R.string.no_disk_key));
|
||||
} catch (NativeLibrary.NoTitleTikException exception) {
|
||||
onEmulationError(getString(R.string.no_title_tik));
|
||||
} catch (NativeLibrary.GameFilesException exception) {
|
||||
onEmulationError(getString(R.string.game_files_unknown_error, launchPath));
|
||||
}
|
||||
int result = NativeEmulation.startGame(launchPath);
|
||||
if (result == NativeEmulation.START_GAME_SUCCESSFUL)
|
||||
return;
|
||||
int errorMessageId = switch (result) {
|
||||
case NativeEmulation.START_GAME_ERROR_GAME_BASE_FILES_NOT_FOUND ->
|
||||
R.string.game_not_found;
|
||||
case NativeEmulation.START_GAME_ERROR_NO_DISC_KEY -> R.string.no_disk_key;
|
||||
case NativeEmulation.START_GAME_ERROR_NO_TITLE_TIK -> R.string.no_title_tik;
|
||||
default -> R.string.game_files_unknown_error;
|
||||
};
|
||||
onEmulationError(getString(errorMessageId));
|
||||
}
|
||||
|
||||
private void onEmulationError(String errorMessage) {
|
||||
|
||||
@@ -34,7 +34,6 @@ public class DocumentsProvider extends android.provider.DocumentsProvider {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final String[] DEFAULT_ROOT_PROJECTION = {
|
||||
DocumentsContract.Root.COLUMN_ROOT_ID,
|
||||
DocumentsContract.Root.COLUMN_MIME_TYPES,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package info.cemu.Cemu.gameview;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
@@ -9,10 +8,8 @@ import androidx.lifecycle.ViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import info.cemu.Cemu.NativeLibrary;
|
||||
import info.cemu.Cemu.nativeinterface.NativeGameTitles;
|
||||
|
||||
public class GameViewModel extends ViewModel {
|
||||
private final MutableLiveData<List<Game>> gamesData;
|
||||
@@ -25,7 +22,7 @@ public class GameViewModel extends ViewModel {
|
||||
|
||||
public GameViewModel() {
|
||||
this.gamesData = new MutableLiveData<>();
|
||||
NativeLibrary.setGameTitleLoadedCallback((path, title, colors, width, height) -> {
|
||||
NativeGameTitles.setGameTitleLoadedCallback((path, title, colors, width, height) -> {
|
||||
Bitmap icon = null;
|
||||
if (colors != null)
|
||||
icon = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
|
||||
@@ -39,12 +36,12 @@ public class GameViewModel extends ViewModel {
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
NativeLibrary.setGameTitleLoadedCallback(null);
|
||||
NativeGameTitles.setGameTitleLoadedCallback(null);
|
||||
}
|
||||
|
||||
public void refreshGames() {
|
||||
games.clear();
|
||||
gamesData.setValue(null);
|
||||
NativeLibrary.reloadGameTitles();
|
||||
NativeGameTitles.reloadGameTitles();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package info.cemu.Cemu.input;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import info.cemu.Cemu.NativeLibrary;
|
||||
import info.cemu.Cemu.nativeinterface.NativeInput;
|
||||
|
||||
public class InputManager {
|
||||
private static class InvalidAxisException extends Exception {
|
||||
@@ -17,59 +16,60 @@ public class InputManager {
|
||||
private int getNativeAxisKey(int axis, boolean isPositive) throws InvalidAxisException {
|
||||
if (isPositive) {
|
||||
return switch (axis) {
|
||||
case MotionEvent.AXIS_X -> NativeLibrary.AXIS_X_POS;
|
||||
case MotionEvent.AXIS_Y -> NativeLibrary.AXIS_Y_POS;
|
||||
case MotionEvent.AXIS_RX, MotionEvent.AXIS_Z -> NativeLibrary.ROTATION_X_POS;
|
||||
case MotionEvent.AXIS_RY, MotionEvent.AXIS_RZ -> NativeLibrary.ROTATION_Y_POS;
|
||||
case MotionEvent.AXIS_LTRIGGER -> NativeLibrary.TRIGGER_X_POS;
|
||||
case MotionEvent.AXIS_RTRIGGER -> NativeLibrary.TRIGGER_Y_POS;
|
||||
case MotionEvent.AXIS_HAT_X -> NativeLibrary.DPAD_RIGHT;
|
||||
case MotionEvent.AXIS_HAT_Y -> NativeLibrary.DPAD_DOWN;
|
||||
case MotionEvent.AXIS_X -> NativeInput.AXIS_X_POS;
|
||||
case MotionEvent.AXIS_Y -> NativeInput.AXIS_Y_POS;
|
||||
case MotionEvent.AXIS_RX, MotionEvent.AXIS_Z -> NativeInput.ROTATION_X_POS;
|
||||
case MotionEvent.AXIS_RY, MotionEvent.AXIS_RZ -> NativeInput.ROTATION_Y_POS;
|
||||
case MotionEvent.AXIS_LTRIGGER -> NativeInput.TRIGGER_X_POS;
|
||||
case MotionEvent.AXIS_RTRIGGER -> NativeInput.TRIGGER_Y_POS;
|
||||
case MotionEvent.AXIS_HAT_X -> NativeInput.DPAD_RIGHT;
|
||||
case MotionEvent.AXIS_HAT_Y -> NativeInput.DPAD_DOWN;
|
||||
default -> throw new InvalidAxisException(axis);
|
||||
};
|
||||
} else {
|
||||
return switch (axis) {
|
||||
case MotionEvent.AXIS_X -> NativeLibrary.AXIS_X_NEG;
|
||||
case MotionEvent.AXIS_Y -> NativeLibrary.AXIS_Y_NEG;
|
||||
case MotionEvent.AXIS_RX, MotionEvent.AXIS_Z -> NativeLibrary.ROTATION_X_NEG;
|
||||
case MotionEvent.AXIS_RY, MotionEvent.AXIS_RZ -> NativeLibrary.ROTATION_Y_NEG;
|
||||
case MotionEvent.AXIS_HAT_X -> NativeLibrary.DPAD_LEFT;
|
||||
case MotionEvent.AXIS_HAT_Y -> NativeLibrary.DPAD_UP;
|
||||
case MotionEvent.AXIS_X -> NativeInput.AXIS_X_NEG;
|
||||
case MotionEvent.AXIS_Y -> NativeInput.AXIS_Y_NEG;
|
||||
case MotionEvent.AXIS_RX, MotionEvent.AXIS_Z -> NativeInput.ROTATION_X_NEG;
|
||||
case MotionEvent.AXIS_RY, MotionEvent.AXIS_RZ -> NativeInput.ROTATION_Y_NEG;
|
||||
case MotionEvent.AXIS_HAT_X -> NativeInput.DPAD_LEFT;
|
||||
case MotionEvent.AXIS_HAT_Y -> NativeInput.DPAD_UP;
|
||||
default -> throw new InvalidAxisException(axis);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMotionEventFromJoystick(MotionEvent event) {
|
||||
return (event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE;
|
||||
private boolean isMotionEventFromJoystickOrGamepad(MotionEvent event) {
|
||||
return (event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK || (event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD;
|
||||
}
|
||||
|
||||
private static final float MIN_ABS_AXIS_VALUE = 0.33f;
|
||||
|
||||
public boolean mapMotionEventToMappingId(int controllerIndex, int mappingId, MotionEvent event) {
|
||||
if (isMotionEventFromJoystick(event)) {
|
||||
InputDevice device = event.getDevice();
|
||||
float maxAbsAxisValue = 0.0f;
|
||||
int maxAxis = -1;
|
||||
int actionPointerIndex = event.getActionIndex();
|
||||
for (InputDevice.MotionRange motionRange : device.getMotionRanges()) {
|
||||
float axisValue = event.getAxisValue(motionRange.getAxis(), actionPointerIndex);
|
||||
int axis;
|
||||
try {
|
||||
axis = getNativeAxisKey(motionRange.getAxis(), axisValue > 0);
|
||||
} catch (InvalidAxisException e) {
|
||||
continue;
|
||||
}
|
||||
if (Math.abs(axisValue) > maxAbsAxisValue) {
|
||||
maxAxis = axis;
|
||||
maxAbsAxisValue = Math.abs(axisValue);
|
||||
}
|
||||
if (!isMotionEventFromJoystickOrGamepad(event)) {
|
||||
return false;
|
||||
}
|
||||
InputDevice device = event.getDevice();
|
||||
float maxAbsAxisValue = 0.0f;
|
||||
int maxAxis = -1;
|
||||
int actionPointerIndex = event.getActionIndex();
|
||||
for (InputDevice.MotionRange motionRange : device.getMotionRanges()) {
|
||||
float axisValue = event.getAxisValue(motionRange.getAxis(), actionPointerIndex);
|
||||
int axis;
|
||||
try {
|
||||
axis = getNativeAxisKey(motionRange.getAxis(), axisValue > 0);
|
||||
} catch (InvalidAxisException e) {
|
||||
continue;
|
||||
}
|
||||
if (maxAbsAxisValue > MIN_ABS_AXIS_VALUE) {
|
||||
NativeLibrary.setControllerMapping(device.getDescriptor(), device.getName(), controllerIndex, mappingId, maxAxis);
|
||||
return true;
|
||||
if (Math.abs(axisValue) > maxAbsAxisValue) {
|
||||
maxAxis = axis;
|
||||
maxAbsAxisValue = Math.abs(axisValue);
|
||||
}
|
||||
}
|
||||
if (maxAbsAxisValue > MIN_ABS_AXIS_VALUE) {
|
||||
NativeInput.setControllerMapping(device.getDescriptor(), device.getName(), controllerIndex, mappingId, maxAxis);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -98,26 +98,26 @@ public class InputManager {
|
||||
InputDevice device = event.getDevice();
|
||||
if (!isController(device))
|
||||
return false;
|
||||
NativeLibrary.onNativeKey(device.getDescriptor(), device.getName(), event.getKeyCode(), event.getAction() == KeyEvent.ACTION_DOWN);
|
||||
NativeInput.onNativeKey(device.getDescriptor(), device.getName(), event.getKeyCode(), event.getAction() == KeyEvent.ACTION_DOWN);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onMotionEvent(MotionEvent event) {
|
||||
if (!isMotionEventFromJoystick(event))
|
||||
if (!isMotionEventFromJoystickOrGamepad(event))
|
||||
return false;
|
||||
InputDevice device = event.getDevice();
|
||||
int actionPointerIndex = event.getActionIndex();
|
||||
for (InputDevice.MotionRange motionRange : device.getMotionRanges()) {
|
||||
float axisValue = event.getAxisValue(motionRange.getAxis(), actionPointerIndex);
|
||||
int axis = motionRange.getAxis();
|
||||
NativeLibrary.onNativeAxis(device.getDescriptor(), device.getName(), axis, axisValue);
|
||||
NativeInput.onNativeAxis(device.getDescriptor(), device.getName(), axis, axisValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean mapKeyEventToMappingId(int controllerIndex, int mappingId, KeyEvent event) {
|
||||
InputDevice device = event.getDevice();
|
||||
NativeLibrary.setControllerMapping(device.getDescriptor(), device.getName(), controllerIndex, mappingId, event.getKeyCode());
|
||||
NativeInput.setControllerMapping(device.getDescriptor(), device.getName(), controllerIndex, mappingId, event.getKeyCode());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user