Skip to content

Commit

Permalink
Bonk
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Dec 26, 2023
1 parent 0ab7bf3 commit 4f83ddc
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 339 deletions.
7 changes: 4 additions & 3 deletions include/jni_driver.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <vector>

#include "helpers.hpp"

class Pandroid {
public:
static void onSmdhLoaded(const std::vector<u8> &smdh);

namespace Pandroid {
static void onSmdhLoaded(const std::vector<u8>& smdh);
};
9 changes: 4 additions & 5 deletions src/core/loader/ncch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,13 @@ bool NCCH::parseSMDH(const std::vector<u8>& smdh) {
return false;
}


#ifdef __ANDROID__
Pandroid::onSmdhLoaded(smdh);
#endif
#ifdef __ANDROID__
Pandroid::onSmdhLoaded(smdh);
#endif

// Bitmask showing which regions are allowed.
// https://www.3dbrew.org/wiki/SMDH#Region_Lockout
const u32 regionMasks = *(u32*)&smdh[0x2018];
const u32 regionMasks = *(u32 *)&smdh[0x2018];
// Detect when games are region free (ie all regions are allowed) for future use
[[maybe_unused]] const bool isRegionFree = (regionMasks & 0x7f) == 0x7f;

Expand Down
50 changes: 22 additions & 28 deletions src/jni_driver.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "jni_driver.hpp"

#include <EGL/egl.h>
#include <android/log.h>
#include <jni.h>
Expand All @@ -8,8 +10,6 @@
#include "renderer_gl/renderer_gl.hpp"
#include "services/hid.hpp"

#include "jni_driver.hpp"

std::unique_ptr<Emulator> emulator = nullptr;
HIDService* hidService = nullptr;
RendererGL* renderer = nullptr;
Expand All @@ -24,41 +24,35 @@ void throwException(JNIEnv* env, const char* message) {
env->ThrowNew(exceptionClass, message);
}

JNIEnv* jniEnv(){
JNIEnv* env;
auto status = jvm->GetEnv((void **)&env, JNI_VERSION_1_6);
if(status == JNI_EDETACHED){
jvm->AttachCurrentThread(&env, nullptr);
} else if(status != JNI_OK){
throw std::runtime_error("Failed to obtain JNIEnv from JVM!!");
}
return env;
}
JNIEnv* jniEnv() {
JNIEnv* env;
auto status = jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
if (status == JNI_EDETACHED) {
jvm->AttachCurrentThread(&env, nullptr);
} else if (status != JNI_OK) {
throw std::runtime_error("Failed to obtain JNIEnv from JVM!!");
}

return env;
}

void Pandroid::onSmdhLoaded(const std::vector<u8> &smdh){
JNIEnv* env = jniEnv();
int size = smdh.size();

jbyteArray result = env->NewByteArray(size);

env->SetByteArrayRegion(result, 0, size, (jbyte*)smdh.data());
void Pandroid::onSmdhLoaded(const std::vector<u8>& smdh) {
JNIEnv* env = jniEnv();
int size = smdh.size();


auto clazz = env->FindClass(alberClass);
auto method = env->GetStaticMethodID(clazz, "OnSmdhLoaded", "([B)V");
jbyteArray result = env->NewByteArray(size);
env->SetByteArrayRegion(result, 0, size, (jbyte*)smdh.data());

env->CallStaticVoidMethod(clazz, method, result);
auto classLoader = env->FindClass(alberClass);
auto method = env->GetStaticMethodID(classLoader, "OnSmdhLoaded", "([B)V");

env->DeleteLocalRef(result);
env->CallStaticVoidMethod(classLoader, method, result);
env->DeleteLocalRef(result);
}


extern "C" {

AlberFunction(void, Setup)(JNIEnv* env, jobject obj) {
env->GetJavaVM(&jvm);
}
AlberFunction(void, Setup)(JNIEnv* env, jobject obj) { env->GetJavaVM(&jvm); }

AlberFunction(void, Initialize)(JNIEnv* env, jobject obj) {
emulator = std::make_unique<Emulator>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
package com.panda3ds.pandroid.app;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.data.config.GlobalConfig;


public class BaseActivity extends AppCompatActivity {
private int currentTheme = GlobalConfig.get(GlobalConfig.KEY_APP_THEME);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
applyTheme();
super.onCreate(savedInstanceState);
}

@Override
protected void onResume() {
super.onResume();
if (GlobalConfig.get(GlobalConfig.KEY_APP_THEME) != currentTheme){
recreate();
}
}

private void applyTheme(){
switch (GlobalConfig.get(GlobalConfig.KEY_APP_THEME)){
case GlobalConfig.THEME_ANDROID:
setTheme(R.style.Theme_Pandroid);
break;
case GlobalConfig.THEME_LIGHT:
setTheme(R.style.Theme_Pandroid_Light);
break;
case GlobalConfig.THEME_DARK:
setTheme(R.style.Theme_Pandroid_Dark);
break;
case GlobalConfig.THEME_BLACK:
setTheme(R.style.Theme_Pandroid_Black);
break;
}
currentTheme = GlobalConfig.get(GlobalConfig.KEY_APP_THEME);
}
private int currentTheme = GlobalConfig.get(GlobalConfig.KEY_APP_THEME);

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
applyTheme();
super.onCreate(savedInstanceState);
}

@Override
protected void onResume() {
super.onResume();

if (GlobalConfig.get(GlobalConfig.KEY_APP_THEME) != currentTheme) {
recreate();
}
}

private void applyTheme() {
switch (GlobalConfig.get(GlobalConfig.KEY_APP_THEME)) {
case GlobalConfig.THEME_ANDROID: setTheme(R.style.Theme_Pandroid); break;
case GlobalConfig.THEME_LIGHT: setTheme(R.style.Theme_Pandroid_Light); break;
case GlobalConfig.THEME_DARK: setTheme(R.style.Theme_Pandroid_Dark); break;
case GlobalConfig.THEME_BLACK: setTheme(R.style.Theme_Pandroid_Black); break;
}

currentTheme = GlobalConfig.get(GlobalConfig.KEY_APP_THEME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.game.AlberInputListener;
Expand All @@ -24,7 +22,6 @@
import com.panda3ds.pandroid.view.PandaLayoutController;

public class GameActivity extends BaseActivity {

private final AlberInputListener inputListener = new AlberInputListener(this);

@Override
Expand All @@ -43,7 +40,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.game_activity);

((FrameLayout) findViewById(R.id.panda_gl_frame))
.addView(pandaSurface, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
.addView(pandaSurface, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

PandaLayoutController controllerLayout = findViewById(R.id.controller_layout);
controllerLayout.initialize();
Expand Down Expand Up @@ -75,25 +72,28 @@ protected void onPause() {

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (InputHandler.processKeyEvent(event))
if (InputHandler.processKeyEvent(event)) {
return true;
}

return super.dispatchKeyEvent(event);
}

@Override
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
if (InputHandler.processMotionEvent(ev))
if (InputHandler.processMotionEvent(ev)) {
return true;
}

return super.dispatchGenericMotionEvent(ev);
}

@Override
protected void onDestroy() {
if(AlberDriver.HasRomLoaded()){
if (AlberDriver.HasRomLoaded()) {
AlberDriver.Finalize();
}

super.onDestroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
import android.os.Bundle;
import android.os.Environment;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.google.android.material.navigation.NavigationBarView;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.main.GamesFragment;
import com.panda3ds.pandroid.app.main.SearchFragment;
import com.panda3ds.pandroid.app.main.SettingsFragment;


public class MainActivity extends BaseActivity implements NavigationBarView.OnItemSelectedListener {
private static final int PICK_ROM = 2;
private static final int PERMISSION_REQUEST_CODE = 3;
Expand All @@ -45,8 +44,8 @@ protected void onCreate(Bundle savedInstanceState) {
startActivity(intent);
}
} else {
ActivityCompat.requestPermissions(this, new String[]{READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
ActivityCompat.requestPermissions(this, new String[] {READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
ActivityCompat.requestPermissions(this, new String[] {WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
}

setContentView(R.layout.activity_main);
Expand All @@ -71,9 +70,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return false;
}

manager.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commitNow();
manager.beginTransaction().replace(R.id.fragment_container, fragment).commitNow();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@

import android.app.Application;
import android.content.Context;

import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.data.config.GlobalConfig;
import com.panda3ds.pandroid.input.InputMap;
import com.panda3ds.pandroid.utils.GameUtils;


public class PandroidApplication extends Application {
private static Context appContext;
private static Context appContext;

@Override
public void onCreate() {
super.onCreate();
appContext = this;

@Override
public void onCreate() {
super.onCreate();
appContext = this;
GlobalConfig.initialize();
GameUtils.initialize();
InputMap.initialize();
AlberDriver.Setup();
}
GlobalConfig.initialize();
GameUtils.initialize();
InputMap.initialize();
AlberDriver.Setup();
}

public static Context getAppContext() {
return appContext;
}
public static Context getAppContext() { return appContext; }
}
Loading

0 comments on commit 4f83ddc

Please sign in to comment.