kitgit

tirbofish/dropbear · diff

1eeec37 · tk

jarvis, run github actions. i made some more changes... nothing works i hate this so fucking much

Unverified

diff --git a/.github/workflows/create_executable.yaml b/.github/workflows/create_executable.yaml
index 4ebcb46..7d407fe 100644
--- a/.github/workflows/create_executable.yaml
+++ b/.github/workflows/create_executable.yaml
@@ -100,16 +100,20 @@ jobs:
 
       - name: Prepare artifact
         run: |
-          mkdir dist
+          mkdir -p dist/libs
           cp target/${{ matrix.target }}/release/eucalyptus-editor${{ matrix.ext }} dist/
-          
-          # Copy any library files from target/release
+
           if [ "${{ matrix.os }}" = "windows-latest" ]; then
-            cp target/${{ matrix.target }}/release/*.dll dist/ 2>/dev/null || true
+            # Copy Windows native libs and import library
+            cp target/${{ matrix.target }}/release/eucalyptus_core.dll dist/ 2>/dev/null || true
+            cp target/${{ matrix.target }}/release/eucalyptus_core.dll dist/libs/ 2>/dev/null || true
+            cp target/${{ matrix.target }}/release/eucalyptus_core.dll.lib dist/libs/ 2>/dev/null || true
           elif [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
-            cp target/${{ matrix.target }}/release/*.so* dist/ 2>/dev/null || true
+            cp target/${{ matrix.target }}/release/libeucalyptus_core.so dist/ 2>/dev/null || true
+            cp target/${{ matrix.target }}/release/libeucalyptus_core.so dist/libs/ 2>/dev/null || true
           elif [ "${{ matrix.os }}" = "macos-latest" ]; then
-            cp target/${{ matrix.target }}/release/*.dylib dist/ 2>/dev/null || true
+            cp target/${{ matrix.target }}/release/libeucalyptus_core.dylib dist/ 2>/dev/null || true
+            cp target/${{ matrix.target }}/release/libeucalyptus_core.dylib dist/libs/ 2>/dev/null || true
             cp README.md dist/
           fi
         shell: bash
diff --git a/.run/Build eucalyptus_core cdylib.run.xml b/.run/Build eucalyptus_core cdylib.run.xml
index cdc5a07..03d23c4 100644
--- a/.run/Build eucalyptus_core cdylib.run.xml
+++ b/.run/Build eucalyptus_core cdylib.run.xml
@@ -1,5 +1,6 @@
 <component name="ProjectRunConfigurationManager">
   <configuration default="false" name="Build eucalyptus_core cdylib" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
+    <option name="buildProfileId" value="release" />
     <option name="command" value="build -p eucalyptus-core --features &quot;editor&quot;" />
     <option name="workingDirectory" value="file://$PROJECT_DIR$" />
     <envs />
diff --git a/dropbear-engine/src/lib.rs b/dropbear-engine/src/lib.rs
index d7809b1..bb19291 100644
--- a/dropbear-engine/src/lib.rs
+++ b/dropbear-engine/src/lib.rs
@@ -469,7 +469,7 @@ impl App {
 
         #[cfg(not(target_os = "android"))]
         {
-            Builder::new()
+            let _ = Builder::new()
                 .format(move |buf, record| {
                     let ts = Local::now().format("%Y-%m-%dT%H:%M:%S");
 
@@ -520,7 +520,7 @@ impl App {
                     LevelFilter::Debug,
                 )
                 .filter(Some("eucalyptus_core"), LevelFilter::Debug)
-                .init();
+                .try_init();
 
             // setup panic
             panic::set_hook();
diff --git a/eucalyptus-core/Cargo.toml b/eucalyptus-core/Cargo.toml
index eed6834..2cc4c86 100644
--- a/eucalyptus-core/Cargo.toml
+++ b/eucalyptus-core/Cargo.toml
@@ -37,8 +37,11 @@ rfd = { workspace = true, optional = true }
 
 [features]
 # editor only stuff
-editor = ["jvm", "rfd"]
+editor = ["jvm", "rfd", "jvm_debug"]
+# enabled scripttarget::jvm as an option 
 jvm = []
+# enables jdb
+jvm_debug = ["jvm"]
 
 [build-dependencies]
 anyhow = "1.0"
diff --git a/eucalyptus-core/README.md b/eucalyptus-core/README.md
index e00bcec..93da694 100644
--- a/eucalyptus-core/README.md
+++ b/eucalyptus-core/README.md
@@ -4,4 +4,11 @@ The core libraries of the eucalyptus editor. Great for embedding into `redback-r
 
 This is a library, so if tools are wished to be made, this is the perfect library for you.
 
-it also produces a shared library for Kotlin/Native and the JVM :)
\ No newline at end of file
+it also produces a shared library for Kotlin/Native and the JVM :)
+
+## Features
+
+- `editor` - Enables editor only features that the redback-runtime would not be able to access
+- `jvm` - Enables the JVM as a ScriptTarget and running the Java Virtual Machine (not possible with non-desktop targets)
+- `jvm_debug` - Enables debugging of the JVM through the java debugger. Can pose a risk to tampering, so is disabled by default unless
+    want to be enabled by developer or enabled by default by the `editor` feature. 
\ No newline at end of file
diff --git a/eucalyptus-core/src/scripting/jni.rs b/eucalyptus-core/src/scripting/jni.rs
index 23d60ae..85f45f1 100644
--- a/eucalyptus-core/src/scripting/jni.rs
+++ b/eucalyptus-core/src/scripting/jni.rs
@@ -81,14 +81,36 @@ impl JavaContext {
             .version(JNIVersion::V8)
             .option(format!("-Djava.class.path={}", host_jar_path.display()));
 
-        #[cfg(feature = "editor")]
+        #[cfg(feature = "jvm_debug")]
         let jvm_args =
             jvm_args.option("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:6741");
 
+        #[cfg(all(feature = "jvm", not(feature = "editor")))]
+        let jvm_args = {
+            #[allow(unused)]
+            let pathbuf = std::env::current_exe()?;
+            #[allow(unused)]
+            let path = pathbuf
+                .parent()
+                .ok_or_else(|| anyhow::anyhow!("Unable to locate parent"))?;
+
+            println!("Libs folder at {}", path.display());
+
+            if !path.exists() {
+                log::warn!(
+                    "Libs folder ({}) does not exist; native libraries may fail to load",
+                    path.display()
+                );
+            }
+
+            let path_str = path.to_string_lossy();
+            jvm_args.option(format!("-Djava.library.path={}", path_str))
+        };
+        
         let jvm_args = jvm_args.build()?;
         let jvm = JavaVM::new(jvm_args)?;
 
-        #[cfg(feature = "editor")]
+        #[cfg(feature = "jvm_debug")]
         crate::success!("JDB debugger enabled on localhost:6741");
 
         log::info!("Created JVM instance");
diff --git a/eucalyptus-core/src/scripting/jni/exports.rs b/eucalyptus-core/src/scripting/jni/exports.rs
index 05f9824..6386ddd 100644
--- a/eucalyptus-core/src/scripting/jni/exports.rs
+++ b/eucalyptus-core/src/scripting/jni/exports.rs
@@ -72,7 +72,7 @@ pub fn Java_com_dropbear_ffi_JNINative_getEntity(
             return id.id() as jlong;
         }
     }
-    -1
+    0
 }
 
 /// `JNIEXPORT jobject JNICALL Java_com_dropbear_ffi_JNINative_getTransform
diff --git a/eucalyptus-editor/Cargo.toml b/eucalyptus-editor/Cargo.toml
index c9c8958..1c1a5b2 100644
--- a/eucalyptus-editor/Cargo.toml
+++ b/eucalyptus-editor/Cargo.toml
@@ -41,6 +41,9 @@ open.workspace = true
 rustc_version_runtime.workspace = true
 egui_plot.workspace = true
 memory-stats.workspace = true
+env_logger.workspace = true
+colored.workspace = true
+chrono.workspace = true
 
 [target.'cfg(not(target_os = "android"))'.dependencies]
 rfd.workspace = true
diff --git a/eucalyptus-editor/src/main.rs b/eucalyptus-editor/src/main.rs
index 0d499d6..a31cfe5 100644
--- a/eucalyptus-editor/src/main.rs
+++ b/eucalyptus-editor/src/main.rs
@@ -18,6 +18,89 @@ async fn main() -> anyhow::Result<()> {
  to use with dependencies or create your own game on Desktop. Sorry :("
     );
 
+    #[cfg(not(target_os = "android"))]
+    {
+        use std::fs::OpenOptions;
+        use colored::Colorize;
+        use env_logger::Builder;
+        use log::LevelFilter;
+
+        let log_dir = app_dirs2::app_root(app_dirs2::AppDataType::UserData, &eucalyptus_core::APP_INFO)
+            .expect("Failed to get app data directory")
+            .join("logs");
+        std::fs::create_dir_all(&log_dir).expect("Failed to create log dir");
+
+        let datetime_str = chrono::offset::Local::now().format("%Y-%m-%d_%H-%M-%S");
+        let log_filename = format!("{}.{}.log", "eucalyptus-editor", datetime_str);
+        let log_path = log_dir.join(log_filename);
+
+        let file = OpenOptions::new()
+            .create(true)
+            .append(true)
+            .open(&log_path)
+            .expect("Failed to open log file");
+        let file = parking_lot::Mutex::new(file);
+
+        let app_target = "eucalyptus-editor".replace('-', "_");
+        let log_config = format!("dropbear_engine=trace,{}=debug,warn", app_target);
+        unsafe { std::env::set_var("RUST_LOG", log_config) };
+
+        Builder::new()
+        .format(move |buf, record| {
+            use std::io::Write;
+
+            let ts = chrono::offset::Local::now().format("%Y-%m-%dT%H:%M:%S");
+
+            let colored_level = match record.level() {
+                log::Level::Error => record.level().to_string().red().bold(),
+                log::Level::Warn => record.level().to_string().yellow().bold(),
+                log::Level::Info => record.level().to_string().green().bold(),
+                log::Level::Debug => record.level().to_string().blue().bold(),
+                log::Level::Trace => record.level().to_string().cyan().bold(),
+            };
+
+            let colored_timestamp = ts.to_string().bright_black();
+
+            let file_info = format!(
+                "{}:{}",
+                record.file().unwrap_or("unknown"),
+                record.line().unwrap_or(0)
+            )
+            .bright_black();
+
+            let console_line = format!(
+                "{} {} [{}] - {}\n",
+                file_info,
+                colored_timestamp,
+                colored_level,
+                record.args()
+            );
+
+            let file_line = format!(
+                "{}:{} {} [{}] - {}\n",
+                record.file().unwrap_or("unknown"),
+                record.line().unwrap_or(0),
+                ts,
+                record.level(),
+                record.args()
+            );
+
+            write!(buf, "{}", console_line)?;
+
+            let mut fh = file.lock();
+            let _ = fh.write_all(file_line.as_bytes());
+
+            Ok(())
+        })
+        .filter(Some("dropbear_engine"), LevelFilter::Trace)
+        .filter(
+            Some("eucalyptus-editor".replace('-', "_").as_str()),
+            LevelFilter::Debug,
+        )
+        .filter(Some("eucalyptus_core"), LevelFilter::Debug)
+        .init();
+    }
+
     dropbear_engine::panic::set_hook();
     let matches = Command::new("eucalyptus-editor")
         .about("A visual game editor")
diff --git a/src/jvmMain/kotlin/com/dropbear/ffi/NativeEngine.jvm.kt b/src/jvmMain/kotlin/com/dropbear/ffi/NativeEngine.jvm.kt
index 55e91f6..65da21f 100644
--- a/src/jvmMain/kotlin/com/dropbear/ffi/NativeEngine.jvm.kt
+++ b/src/jvmMain/kotlin/com/dropbear/ffi/NativeEngine.jvm.kt
@@ -68,6 +68,8 @@ actual class NativeEngine {
             } else {
                 null
             }
+        } else if (result == 0L) {
+            null
         } else {
             result
         }