package com.bugsnag.android.unity;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.bugsnag.android.Error;
import com.bugsnag.android.Event;
import com.bugsnag.android.OnErrorCallback;

public class BugsnagUnity {
    static {
        System.loadLibrary("bugsnag-unity");
    }

    public static native boolean isJNIAttached();

    public static OnErrorCallback getNativeCallback() {
        String discardedEventErrorClass = "java.lang.Error";
        Pattern pattern = Pattern.compile("signal \\d+ \\(SIG\\w+\\)", Pattern.CASE_INSENSITIVE);
        return new OnErrorCallback() {
            @Override
            // Discard any messages matching native Android events as they are captured (and more
            // accurate) via bugsnag-android. For Unity 2018.3+
            public boolean onError(Event event) {
                Error error = event.getErrors().get(0);
                String errorClass = error.getErrorClass();
                String message = error.getErrorMessage();
                return discardedEventErrorClass.equals(errorClass) &&
                    (message == null || !pattern.matcher(message).find());
            }
        };
    }
}

@@ -1028,23 +1028,19 @@
         
-return 
+if(
 discarde
@@ -1078,11 +1078,27 @@
 ass)
- &&
+)%0A                %7B
 %0A   
@@ -1114,16 +1114,18 @@
         
+if
 (message
@@ -1169,16 +1169,144 @@
 .find())
+%0A                    %7B%0A                        return false;%0A                    %7D%0A                %7D%0A                return true
 ;%0A      

allow other error classes to be reported