From ef1c2a59307ff4df500d38a88d5ac249daf31304 Mon Sep 17 00:00:00 2001 From: Alula <6276139+alula@users.noreply.github.com> Date: Wed, 25 Jan 2023 18:23:15 +0100 Subject: [PATCH] hotfix time --- .appveyor.yml | 23 +--- Cargo.toml | 6 +- app/app/src/main/AndroidManifest.xml | 37 ++++-- .../github/doukutsu_rs/DownloadActivity.java | 26 +++-- .../io/github/doukutsu_rs/GameActivity.java | 93 +++++++++++++++ .../io/github/doukutsu_rs/MainActivity.java | 106 +++--------------- app/app/src/main/res/layout/activity_main.xml | 9 ++ app/build.gradle | 2 +- build.rs | 1 + drsandroid/Cargo.toml | 2 + drsandroid/src/lib.rs | 4 + drshorizon/Cargo.toml | 6 +- src/data/vanilla.rs | 37 ++++-- src/menu/settings_menu.rs | 2 +- 14 files changed, 216 insertions(+), 138 deletions(-) create mode 100644 app/app/src/main/java/io/github/doukutsu_rs/GameActivity.java create mode 100644 app/app/src/main/res/layout/activity_main.xml diff --git a/.appveyor.yml b/.appveyor.yml index 65c196b..8af3731 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -43,13 +43,6 @@ for: only: - appveyor_build_worker_image: Visual Studio 2019 - init: - - ps: | - if ($env:APPVEYOR_REPO_TAG -eq "true") - { - Update-AppveyorBuild -Version "$env:APPVEYOR_REPO_TAG_NAME" - } - install: - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - rustup-init -yv --default-toolchain %channel% --default-host %target% @@ -69,7 +62,8 @@ for: - 'target -> Cargo.toml' build_script: - - set DRS_BUILD_VERSION_OVERRIDE=%APPVEYOR_BUILD_VERSION% + #- set DRS_BUILD_VERSION_OVERRIDE=%APPVEYOR_BUILD_VERSION% + - if "%APPVEYOR_REPO_TAG%" == "true" (set DRS_BUILD_VERSION_OVERRIDE=%APPVEYOR_REPO_TAG_NAME%) else (set DRS_BUILD_VERSION_OVERRIDE=%APPVEYOR_BUILD_VERSION%) - set CARGO_INCREMENTAL=1 - cargo build --release --bin doukutsu-rs - mkdir release @@ -111,7 +105,8 @@ for: - 'target -> Cargo.toml' build_script: - - export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_BUILD_VERSION + #- export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_BUILD_VERSION + - if [ "$APPVEYOR_REPO_TAG" = "true" ]; then export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_REPO_TAG_NAME; else export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_BUILD_VERSION; fi - CARGO_INCREMENTAL=1 cargo bundle --release --target $target - mkdir release - cp LICENSE ./release/LICENSE @@ -126,13 +121,6 @@ for: only: - appveyor_build_worker_image: Ubuntu - init: - - ps: | - if ($env:APPVEYOR_REPO_TAG -eq "true") - { - Update-AppveyorBuild -Version "$env:APPVEYOR_REPO_TAG_NAME" - } - install: - sudo apt-get update && sudo apt-get -y install libasound2-dev libudev-dev libgl1-mesa-dev pkg-config - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -yv --default-toolchain $channel --default-host $target @@ -152,7 +140,8 @@ for: - 'target -> Cargo.toml' build_script: - - export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_BUILD_VERSION + #- export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_BUILD_VERSION + - if [ "$APPVEYOR_REPO_TAG" = "true" ]; then export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_REPO_TAG_NAME; else export DRS_BUILD_VERSION_OVERRIDE=$APPVEYOR_BUILD_VERSION; fi - RUSTFLAGS="-C link-arg=-s" CARGO_INCREMENTAL=1 cargo build --release --bin doukutsu-rs - mkdir release - cp LICENSE ./release/LICENSE diff --git a/Cargo.toml b/Cargo.toml index fd9b443..c266cfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,12 +16,16 @@ bench = false required-features = ["exe"] [profile.release] -lto = "thin" +lto = "off" panic = "abort" +codegen-units = 256 +incremental = true +split-debuginfo = "packed" [profile.dev.package."*"] opt-level = 3 overflow-checks = false +codegen-units = 256 [package.metadata.bundle] name = "doukutsu-rs" diff --git a/app/app/src/main/AndroidManifest.xml b/app/app/src/main/AndroidManifest.xml index d5a5a13..d22316e 100644 --- a/app/app/src/main/AndroidManifest.xml +++ b/app/app/src/main/AndroidManifest.xml @@ -1,35 +1,52 @@ + - - - + android:theme="@style/Theme.Doukutsurs.NoActionBar"> - - - + + + + + + progressBar.setIndeterminate(true)); } byte[] zipFile; @@ -81,7 +83,7 @@ public class DownloadActivity extends AppCompatActivity { ? String.format(Locale.ENGLISH, "Downloading... %d%% (%d/%d KiB, %d KiB/s)", downloaded * 100 / fileLength, downloaded / 1024, fileLength / 1024, speed) : String.format(Locale.ENGLISH, "Downloading... --%% (%d KiB, %d KiB/s)", downloaded / 1024, speed); - txtProgress.setText(text); + handler.post(() -> txtProgress.setText(text)); downloadedLast = downloaded; last = now; @@ -105,7 +107,8 @@ public class DownloadActivity extends AppCompatActivity { entryName = entryName.substring("CaveStory/".length()); } - txtProgress.setText("Unpacking: " + entryName); + final String s = entryName; + handler.post(() -> txtProgress.setText("Unpacking: " + s)); if (entry.isDirectory()) { new File(basePath + entryName).mkdirs(); @@ -122,14 +125,19 @@ public class DownloadActivity extends AppCompatActivity { } } - txtProgress.setText("Done!"); + handler.post(() -> txtProgress.setText("Done!")); - Intent intent = new Intent(DownloadActivity.this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME); - startActivity(intent); - DownloadActivity.this.finish(); + handler.post(() -> { + Intent intent = new Intent(DownloadActivity.this, GameActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + DownloadActivity.this.finish(); + }); } catch (Exception e) { - if (txtProgress != null) txtProgress.setText(e.getMessage()); + handler.post(() -> { + if (txtProgress != null) + txtProgress.setText(e.getMessage()); + }); e.printStackTrace(); } finally { if (connection != null) connection.disconnect(); diff --git a/app/app/src/main/java/io/github/doukutsu_rs/GameActivity.java b/app/app/src/main/java/io/github/doukutsu_rs/GameActivity.java new file mode 100644 index 0000000..01347af --- /dev/null +++ b/app/app/src/main/java/io/github/doukutsu_rs/GameActivity.java @@ -0,0 +1,93 @@ +package io.github.doukutsu_rs; + +import android.app.AlertDialog; +import android.app.NativeActivity; +import android.content.Intent; +import android.content.res.Configuration; +import android.hardware.SensorManager; +import android.os.Build; +import android.os.Bundle; +import android.view.OrientationEventListener; +import android.view.WindowInsets; + +import java.io.File; + +import static android.os.Build.VERSION.SDK_INT; + +public class GameActivity extends NativeActivity { + private int[] displayInsets = new int[]{0, 0, 0, 0}; + private OrientationEventListener listener; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + listener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) { + @Override + public void onOrientationChanged(int orientation) { + GameActivity.this.updateCutouts(); + } + }; + + if (listener.canDetectOrientation()) { + listener.enable(); + } else { + listener = null; + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + if (listener != null) { + listener.disable(); + + listener = null; + } + } + + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + + this.updateCutouts(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + this.updateCutouts(); + } + + private void updateCutouts() { + this.displayInsets[0] = 0; + this.displayInsets[1] = 0; + this.displayInsets[2] = 0; + this.displayInsets[3] = 0; + + WindowInsets insets = getWindow().getDecorView().getRootWindowInsets(); + + if (insets != null) { + this.displayInsets[0] = Math.max(this.displayInsets[0], insets.getStableInsetLeft()); + this.displayInsets[1] = Math.max(this.displayInsets[1], insets.getStableInsetTop()); + this.displayInsets[2] = Math.max(this.displayInsets[2], insets.getStableInsetRight()); + this.displayInsets[3] = Math.max(this.displayInsets[3], insets.getStableInsetBottom()); + } else { + return; + } + + if (SDK_INT >= Build.VERSION_CODES.P) { + android.view.DisplayCutout cutout = insets.getDisplayCutout(); + + if (cutout != null) { + this.displayInsets[0] = Math.max(this.displayInsets[0], cutout.getSafeInsetLeft()); + this.displayInsets[1] = Math.max(this.displayInsets[0], cutout.getSafeInsetTop()); + this.displayInsets[2] = Math.max(this.displayInsets[0], cutout.getSafeInsetRight()); + this.displayInsets[3] = Math.max(this.displayInsets[0], cutout.getSafeInsetBottom()); + } + + } + } +} diff --git a/app/app/src/main/java/io/github/doukutsu_rs/MainActivity.java b/app/app/src/main/java/io/github/doukutsu_rs/MainActivity.java index df90929..e9bea3f 100644 --- a/app/app/src/main/java/io/github/doukutsu_rs/MainActivity.java +++ b/app/app/src/main/java/io/github/doukutsu_rs/MainActivity.java @@ -1,119 +1,49 @@ package io.github.doukutsu_rs; import android.app.AlertDialog; -import android.app.NativeActivity; import android.content.Intent; -import android.content.res.Configuration; -import android.hardware.SensorManager; -import android.os.Build; import android.os.Bundle; -import android.view.OrientationEventListener; -import android.view.WindowInsets; + +import androidx.appcompat.app.AppCompatActivity; import java.io.File; -import static android.os.Build.VERSION.SDK_INT; - -public class MainActivity extends NativeActivity { - private int[] displayInsets = new int[]{0, 0, 0, 0}; - private OrientationEventListener listener; +public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + File f = new File(getFilesDir().getAbsolutePath() + "/data/"); String[] list = f.list(); if (!f.exists() || (list != null && list.length == 0)) { messageBox("Missing data files", "No data files found, would you like to download them?", () -> { Intent intent = new Intent(this, DownloadActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); this.finish(); - }); - } - - super.onCreate(savedInstanceState); - - listener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) { - @Override - public void onOrientationChanged(int orientation) { - MainActivity.this.updateCutouts(); - } - }; - - if (listener.canDetectOrientation()) { - listener.enable(); + }, this::launchGame); } else { - listener = null; + launchGame(); } } - @Override - protected void onDestroy() { - super.onDestroy(); - - if (listener != null) { - listener.disable(); - - listener = null; - } + private void launchGame() { + Intent intent = new Intent(this, GameActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + this.finish(); } - @Override - public void onAttachedToWindow() { - super.onAttachedToWindow(); - - this.updateCutouts(); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - - this.updateCutouts(); - } - - private void updateCutouts() { - this.displayInsets[0] = 0; - this.displayInsets[1] = 0; - this.displayInsets[2] = 0; - this.displayInsets[3] = 0; - - WindowInsets insets = getWindow().getDecorView().getRootWindowInsets(); - - if (insets != null) { - this.displayInsets[0] = Math.max(this.displayInsets[0], insets.getStableInsetLeft()); - this.displayInsets[1] = Math.max(this.displayInsets[1], insets.getStableInsetTop()); - this.displayInsets[2] = Math.max(this.displayInsets[2], insets.getStableInsetRight()); - this.displayInsets[3] = Math.max(this.displayInsets[3], insets.getStableInsetBottom()); - } else { - return; - } - - if (SDK_INT >= Build.VERSION_CODES.P) { - android.view.DisplayCutout cutout = insets.getDisplayCutout(); - - if (cutout != null) { - this.displayInsets[0] = Math.max(this.displayInsets[0], cutout.getSafeInsetLeft()); - this.displayInsets[1] = Math.max(this.displayInsets[0], cutout.getSafeInsetTop()); - this.displayInsets[2] = Math.max(this.displayInsets[0], cutout.getSafeInsetRight()); - this.displayInsets[3] = Math.max(this.displayInsets[0], cutout.getSafeInsetBottom()); - } - - } - } - - private void messageBox(String title, String message, Runnable callback) { + private void messageBox(String title, String message, Runnable yesCallback, Runnable noCallback) { this.runOnUiThread(() -> { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(title); alert.setMessage(message); - alert.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> { - callback.run(); - }); - alert.setNegativeButton(android.R.string.no, (dialog, whichButton) -> { - // hide - }); + alert.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> yesCallback.run()); + alert.setNegativeButton(android.R.string.no, (dialog, whichButton) -> noCallback.run()); alert.show(); }); } -} +} \ No newline at end of file diff --git a/app/app/src/main/res/layout/activity_main.xml b/app/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..0b15a20 --- /dev/null +++ b/app/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 079dfea..67fa796 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ buildscript { } } dependencies { - classpath "com.android.tools.build:gradle:7.4.0" + classpath "com.android.tools.build:gradle:7.3.1" classpath "gradle.plugin.com.github.willir.rust:plugin:0.3.4" // NOTE: Do not place your application dependencies here; they belong diff --git a/build.rs b/build.rs index 3cc58ed..fda2906 100644 --- a/build.rs +++ b/build.rs @@ -19,6 +19,7 @@ fn main() { if target.contains("i686") { // yet another hack println!("cargo:rustc-link-arg=/FORCE:MULTIPLE"); + println!("cargo:rustc-link-lib=shlwapi"); } } diff --git a/drsandroid/Cargo.toml b/drsandroid/Cargo.toml index 7b8ad81..93c45b9 100644 --- a/drsandroid/Cargo.toml +++ b/drsandroid/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" [profile.release] opt-level = 3 +lto = "off" +codegen-units = 256 incremental = true [lib] diff --git a/drsandroid/src/lib.rs b/drsandroid/src/lib.rs index 095fc7a..a12cbd0 100644 --- a/drsandroid/src/lib.rs +++ b/drsandroid/src/lib.rs @@ -1,6 +1,10 @@ #[cfg(target_os = "android")] #[cfg_attr(target_os = "android", ndk_glue::main())] pub fn android_main() { + let resource_dir = std::path::PathBuf::from(ndk_glue::native_activity().internal_data_path().to_string_lossy().to_string()); + + std::env::set_current_dir(&resource_dir).unwrap(); + let options = doukutsu_rs::game::LaunchOptions { server_mode: false, editor: false }; doukutsu_rs::game::init(options).unwrap(); diff --git a/drshorizon/Cargo.toml b/drshorizon/Cargo.toml index 7c62b00..6497029 100644 --- a/drshorizon/Cargo.toml +++ b/drshorizon/Cargo.toml @@ -6,15 +6,19 @@ edition = "2021" [profile.release] opt-level = 3 -#incremental = true +codegen-units = 256 +incremental = true [profile.dev.package."*"] opt-level = 3 overflow-checks = false incremental = true + [profile.dev.package."doukutsu-rs"] opt-level = 3 +lto = "off" overflow-checks = false +codegen-units = 256 incremental = true [dependencies] diff --git a/src/data/vanilla.rs b/src/data/vanilla.rs index 5137283..fc58229 100644 --- a/src/data/vanilla.rs +++ b/src/data/vanilla.rs @@ -17,6 +17,7 @@ use crate::framework::{ pub struct VanillaExtractor { exe_buffer: Vec, data_base_dir: String, + root: PathBuf, } const VANILLA_STAGE_COUNT: u32 = 95; @@ -26,14 +27,33 @@ const VANILLA_STAGE_TABLE_SIZE: u32 = VANILLA_STAGE_COUNT * VANILLA_STAGE_ENTRY_ impl VanillaExtractor { pub fn from(ctx: &mut Context, exe_name: String, data_base_dir: String) -> Option { - let mut vanilla_exe_path = env::current_exe().unwrap(); - vanilla_exe_path.pop(); - vanilla_exe_path.push(exe_name); + #[cfg(not(any(target_os = "android", target_os = "horizon")))] + let mut vanilla_exe_path = env::current_dir().unwrap(); + + #[cfg(target_os = "android")] + let mut vanilla_exe_path = PathBuf::from(ndk_glue::native_activity().internal_data_path().to_string_lossy().to_string()); + + #[cfg(target_os = "horizon")] + let mut vanilla_exe_path = PathBuf::from("sdmc:/switch/doukutsu-rs/"); + + vanilla_exe_path.push(&exe_name); + + log::info!("Looking for vanilla game executable at {:?}", vanilla_exe_path); + + #[cfg(not(any(target_os = "android", target_os = "horizon")))] + if !vanilla_exe_path.is_file() { + vanilla_exe_path = env::current_exe().unwrap(); + vanilla_exe_path.pop(); + vanilla_exe_path.push(&exe_name); + } if !vanilla_exe_path.is_file() { return None; } + let mut root = vanilla_exe_path.clone(); + root.pop(); + log::info!("Found vanilla game executable, attempting to extract resources."); if filesystem::exists(ctx, format!("{}/stage.sect", data_base_dir.clone())) { @@ -54,7 +74,7 @@ impl VanillaExtractor { return None; } - Some(Self { exe_buffer, data_base_dir }) + Some(Self { exe_buffer, data_base_dir, root }) } pub fn extract_data(&self) -> GameResult { @@ -93,8 +113,7 @@ impl VanillaExtractor { } for org in orgs.unwrap().data_files { - let mut org_path = env::current_exe().unwrap(); - org_path.pop(); + let mut org_path = self.root.clone(); org_path.push(self.data_base_dir.clone()); org_path.push("Org/"); @@ -130,8 +149,7 @@ impl VanillaExtractor { } for bitmap in bitmaps.unwrap().data_files { - let mut data_path = env::current_exe().unwrap(); - data_path.pop(); + let mut data_path = self.root.clone(); data_path.push(self.data_base_dir.clone()); if self.deep_create_dir_if_not_exists(data_path.clone()).is_err() { @@ -180,8 +198,7 @@ impl VanillaExtractor { let byte_slice = &self.exe_buffer[start..end]; - let mut stage_tbl_path = env::current_exe().unwrap(); - stage_tbl_path.pop(); + let mut stage_tbl_path = self.root.clone(); stage_tbl_path.push(self.data_base_dir.clone()); if self.deep_create_dir_if_not_exists(stage_tbl_path.clone()).is_err() { diff --git a/src/menu/settings_menu.rs b/src/menu/settings_menu.rs index 5393e91..b213c2f 100644 --- a/src/menu/settings_menu.rs +++ b/src/menu/settings_menu.rs @@ -203,7 +203,7 @@ impl SettingsMenu { ], ), ); - #[cfg(not(all(target_os = "android", target_os = "horizon")))] + #[cfg(not(any(target_os = "android", target_os = "horizon")))] self.graphics.push_entry( GraphicsMenuEntry::WindowMode, MenuEntry::Options(