@@ -352,19 +352,14 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
352352 private void hookCardboard (final LoadPackageParam lpparam ) {
353353 try {
354354 Class headTransformTMP = XposedHelpers .findClassIfExists ("com.google.vrtoolkit.cardboard.HeadTransform" , lpparam .classLoader );
355- Class eyeTMP = XposedHelpers .findClassIfExists ("com.google.vrtoolkit.cardboard.Eye" , lpparam .classLoader );
356355
357356 if (headTransformTMP == null ) {
358357 headTransformTMP = XposedHelpers .findClassIfExists ("com.google.vr.sdk.base.HeadTransform" , lpparam .classLoader );
359- if (headTransformTMP != null ) XposedBridge .log ("VirtualSensor: Did not find com.google.vrtoolkit.cardboard.HeadTransform but found com.google.vr.sdk.base.HeadTransform" );
360- }
361- if (eyeTMP == null ) {
362- eyeTMP = XposedHelpers .findClassIfExists ("com.google.vr.sdk.base.Eye" , lpparam .classLoader );
363- if (eyeTMP != null ) XposedBridge .log ("VirtualSensor: Did not find com.google.vrtoolkit.cardboard.Eye but found com.google.vr.sdk.base.Eye" );
358+ if (headTransformTMP != null )
359+ XposedBridge .log ("VirtualSensor: Did not find com.google.vrtoolkit.cardboard.HeadTransform but found com.google.vr.sdk.base.HeadTransform" );
364360 }
365361
366362 final Class headTransform = headTransformTMP ;
367- final Class eye = eyeTMP ;
368363 final int sensorToUse = Build .VERSION .SDK_INT >= 18 ? Sensor .TYPE_GAME_ROTATION_VECTOR : Sensor .TYPE_ROTATION_VECTOR ;
369364
370365 if (headTransform != null ) {
@@ -380,7 +375,7 @@ public void onSensorChanged(SensorEvent event) {
380375 if (event .values != null ) {
381376 try {
382377 Field htMatrix = XposedHelpers .findFirstFieldByExactType (headTransform , float [].class );
383- float [] rotationMatrix = (float [])htMatrix .get (param .thisObject );
378+ float [] rotationMatrix = (float []) htMatrix .get (param .thisObject );
384379 SensorManager .getRotationMatrixFromVector (rotationMatrix , event .values );
385380
386381 XposedHelpers .setObjectField (param .thisObject , htMatrix .getName (), rotationMatrix );
@@ -401,58 +396,6 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) {
401396 });
402397 }
403398
404- if (eye != null ) {
405- XposedBridge .log ("VirtualSensor: Found the Google Cardboard library in " + lpparam .packageName + ", hooking Eye" );
406-
407- XposedHelpers .findAndHookConstructor (eye , int .class , new XC_MethodHook () {
408- @ Override
409- protected void afterHookedMethod (final MethodHookParam param ) throws Throwable {
410- SensorManager mgr = (SensorManager ) AndroidAppHelper .currentApplication ().getSystemService (Context .SENSOR_SERVICE );
411-
412- Field matrixField = null ;
413- for (Field field : eye .getDeclaredFields ()) {
414- if (field .getType () == float [].class ) {
415- field .setAccessible (true );
416-
417- Object value = field .get (param .thisObject );
418- if (value != null && ((float [])value ).length == 16 ) {
419- matrixField = field ;
420- break ;
421- }
422- }
423- }
424-
425- final Field finalMatrixField = matrixField ;
426- if (matrixField == null ) {
427- XposedBridge .log ("VirtualSensor: Did not find the field containing the matrix, aborting hook" );
428- } else {
429- XposedBridge .log ("VirtualSensor: Found the field containing the eye matrix, name is " + matrixField .getName ());
430- SensorEventListener listener = new SensorEventListener () {
431- @ Override
432- public void onSensorChanged (SensorEvent event ) {
433- if (event .sensor .getType () == sensorToUse ) {
434- if (event .values != null ) {
435- try {
436- float [] rotationMatrix = new float [16 ];
437- SensorManager .getRotationMatrixFromVector (rotationMatrix , event .values );
438- XposedHelpers .setObjectField (param .thisObject , finalMatrixField .getName (), rotationMatrix );
439- } catch (Exception e ) {
440- e .printStackTrace ();
441- }
442- }
443- }
444- }
445-
446- @ Override
447- public void onAccuracyChanged (Sensor sensor , int accuracy ) {
448- }
449- };
450- mgr .registerListener (listener , mgr .getDefaultSensor (sensorToUse ), mgr .getDefaultSensor (sensorToUse ).getMinDelay ());
451- }
452- super .afterHookedMethod (param );
453- }
454- });
455- }
456399 } catch (Exception e ) {e .printStackTrace ();}
457400 }
458401}
0 commit comments