1212using VRC . SDKBase ;
1313
1414namespace DesktopCamera {
15-
1615 public static class ModBuildInfo {
1716 public const string Name = "DesktopCamera" ;
1817 public const string Author = "nitro." ;
@@ -29,10 +28,29 @@ public class VersionCheckResponse {
2928 }
3029
3130 public class Main : MelonMod {
32-
33- public override void OnApplicationStart ( ) {
34- MelonLogger . Log ( "Mod loaded." ) ;
31+ private const string ModCategory = "DesktopCamera" ;
32+ private const string CameraSpeedPref = "CameraSpeed" ;
33+ private const string CameraSpeedAltPref = "CameraSpeedAlt" ;
34+ private static float CameraSpeed = 0.005f ;
35+ private static float CameraSpeedAlt = 0.020f ;
36+
37+ public override void OnApplicationStart ( )
38+ {
39+ MelonModLogger . Log ( "Mod loaded." ) ;
40+ ModPrefs . RegisterCategory ( ModCategory , "Desktop Camera" ) ;
41+ ModPrefs . RegisterPrefInt ( ModCategory , CameraSpeedPref , 5 , "Basic camera speed" ) ;
42+ ModPrefs . RegisterPrefInt ( ModCategory , CameraSpeedAltPref , 20 , "Alt camera speed (ALT pressed)" ) ;
43+ OnModSettingsApplied ( ) ;
3544 }
45+
46+
47+ public override void OnModSettingsApplied ( )
48+ {
49+ CameraSpeed = ModPrefs . GetInt ( ModCategory , CameraSpeedPref ) ;
50+ CameraSpeedAlt = ModPrefs . GetInt ( ModCategory , CameraSpeedAltPref ) ;
51+
52+ CameraSpeed /= 1000 ;
53+ CameraSpeedAlt /= 1000 ;
3654
3755 public override void VRChat_OnUiManagerInit ( ) {
3856 MelonCoroutines . Start ( Setup ( ) ) ;
@@ -335,62 +353,79 @@ public override void OnUpdate() {
335353 // VRCUtils.ShowQuickMenuPage(quickMenu, cameraMenu);
336354 //}
337355 if ( Settings . cameraEnabled && Settings . arrowKeysEnabled ) {
338- if ( Input . GetKey ( KeyCode . LeftArrow ) ) {
356+ var cameraRotation = CameraUtils . worldCameraQuaternion . ToEuler ( ) ;
357+ var actualCameraSpeed = ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) )
358+ ? CameraSpeedAlt
359+ : CameraSpeed ;
360+ if ( Input . GetKey ( KeyCode . DownArrow ) ) {
339361 if ( Settings . moveCamera ) {
340- if ( Settings . allowCameraMovement ) {
341- if ( Settings . rotateAroundUserCamera ) CameraUtils . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . up , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 2f : - 1f ) ;
342- else CameraUtils . worldCameraVector += new Vector3 ( 0f , 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 0.01f : 0.005f ) ;
362+ if ( Settings . allowCameraMovement )
363+ {
364+ if ( Settings . rotateAroundUserCamera )
365+ CameraUtils . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position ,
366+ VRCUtils . GetMainCamera ( ) . transform . up ,
367+ ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 2f : - 1f ) ;
368+ else
369+ CameraUtils . worldCameraVector -= new Vector3 (
370+ ( float ) Math . Sin ( cameraRotation . y ) * actualCameraSpeed , 0f ,
371+ ( float ) Math . Cos ( cameraRotation . y ) * actualCameraSpeed ) ;
343372 }
344373 } else {
345- if ( Settings . rotateAroundUserCamera ) VRCUtils . GetUserCameraController ( ) . viewFinder . transform . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . up , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 2f : - 1f ) ;
346- else VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 0.01f : - 0.005f , 0f , 0f ) ;
374+ VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( 0f , 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 0.01f : - 0.005f ) ;
347375 }
348376 }
349- if ( Input . GetKey ( KeyCode . RightArrow ) ) {
377+ if ( Input . GetKey ( KeyCode . UpArrow ) ) {
350378 if ( Settings . moveCamera ) {
351379 if ( Settings . allowCameraMovement ) {
352380 if ( Settings . rotateAroundUserCamera ) CameraUtils . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . up , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 2f : 1f ) ;
353- else CameraUtils . worldCameraVector += new Vector3 ( 0f , 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 0.01f : - 0.005f ) ;
381+ else CameraUtils . worldCameraVector += new Vector3 (
382+ ( float ) Math . Sin ( cameraRotation . y ) * actualCameraSpeed , 0f ,
383+ ( float ) Math . Cos ( cameraRotation . y ) * actualCameraSpeed ) ;
354384 }
355385 } else {
356- if ( Settings . rotateAroundUserCamera ) VRCUtils . GetUserCameraController ( ) . viewFinder . transform . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . up , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 2f : 1f ) ;
357- else VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 0.01f : 0.005f , 0f , 0f ) ;
386+ VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( 0f , 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 0.01f : 0.005f ) ;
358387 }
359388 }
360- if ( Input . GetKey ( KeyCode . UpArrow ) ) {
389+ if ( Input . GetKey ( KeyCode . PageUp ) ) {
361390 if ( Settings . moveCamera ) {
362391 if ( Settings . allowCameraMovement ) {
363392 if ( Settings . rotateAroundUserCamera ) CameraUtils . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . right , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 2f : - 1f ) ;
364- else CameraUtils . worldCameraVector += new Vector3 ( 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 0.01f : 0.005f , 0f ) ;
393+ else CameraUtils . worldCameraVector += new Vector3 ( 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? CameraSpeedAlt : CameraSpeed , 0f ) ;
365394 }
366395 } else {
367396 if ( Settings . rotateAroundUserCamera ) VRCUtils . GetUserCameraController ( ) . viewFinder . transform . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . right , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 2f : - 1f ) ;
368397 else VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 0.01f : 0.005f , 0f ) ;
369398 }
370399 }
371- if ( Input . GetKey ( KeyCode . DownArrow ) ) {
400+ if ( Input . GetKey ( KeyCode . PageDown ) ) {
372401 if ( Settings . moveCamera ) {
373402 if ( Settings . allowCameraMovement ) {
374403 if ( Settings . rotateAroundUserCamera ) CameraUtils . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . right , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 2f : 1f ) ;
375- else CameraUtils . worldCameraVector += new Vector3 ( 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 0.01f : - 0.005f , 0f ) ;
404+ else CameraUtils . worldCameraVector += new Vector3 ( 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - CameraSpeedAlt : - CameraSpeed , 0f ) ;
376405 }
377406 } else {
378407 if ( Settings . rotateAroundUserCamera ) VRCUtils . GetUserCameraController ( ) . viewFinder . transform . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . right , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 2f : 1f ) ;
379408 else VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 0.01f : - 0.005f , 0f ) ;
380409 }
381410 }
382- if ( Input . GetKey ( KeyCode . PageUp ) ) {
411+ if ( Input . GetKey ( KeyCode . LeftArrow ) ) {
383412 if ( Settings . moveCamera ) {
384- if ( Settings . allowCameraMovement ) CameraUtils . worldCameraVector += new Vector3 ( ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 0.01f : 0.005f , 0f , 0f ) ;
413+ if ( Settings . allowCameraMovement ) CameraUtils . worldCameraVector -= new Vector3 (
414+ ( float ) Math . Cos ( cameraRotation . y ) * actualCameraSpeed , 0f ,
415+ ( float ) - Math . Sin ( cameraRotation . y ) * actualCameraSpeed ) ;
385416 } else {
386- VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( 0f , 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 0.01f : 0.005f ) ;
417+ if ( Settings . rotateAroundUserCamera ) VRCUtils . GetUserCameraController ( ) . viewFinder . transform . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . up , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 2f : - 1f ) ;
418+ else VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 0.01f : - 0.005f , 0f , 0f ) ;
387419 }
388420 }
389- if ( Input . GetKey ( KeyCode . PageDown ) ) {
421+ if ( Input . GetKey ( KeyCode . RightArrow ) ) {
390422 if ( Settings . moveCamera ) {
391- if ( Settings . allowCameraMovement ) CameraUtils . worldCameraVector += new Vector3 ( ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 0.01f : - 0.005f , 0f , 0f ) ;
423+ if ( Settings . allowCameraMovement ) CameraUtils . worldCameraVector += new Vector3 (
424+ ( float ) Math . Cos ( cameraRotation . y ) * actualCameraSpeed , 0f ,
425+ ( float ) - Math . Sin ( cameraRotation . y ) * actualCameraSpeed ) ;
392426 } else {
393- VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( 0f , 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 0.01f : - 0.005f ) ;
427+ if ( Settings . rotateAroundUserCamera ) VRCUtils . GetUserCameraController ( ) . viewFinder . transform . RotateAround ( VRCUtils . GetMainCamera ( ) . transform . position , VRCUtils . GetMainCamera ( ) . transform . up , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 2f : 1f ) ;
428+ else VRCUtils . GetUserCameraController ( ) . viewFinder . transform . localPosition += new Vector3 ( ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 0.01f : 0.005f , 0f , 0f ) ;
394429 }
395430 }
396431
@@ -411,14 +446,14 @@ public override void OnUpdate() {
411446 }
412447 if ( Input . GetKey ( KeyCode . Keypad4 ) ) {
413448 if ( Settings . moveCamera ) {
414- if ( Settings . allowCameraMovement ) CameraUtils . worldCameraQuaternion *= Quaternion . Euler ( 0f , Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ? 2f : 1f , 0f ) ;
449+ if ( Settings . allowCameraMovement ) CameraUtils . worldCameraQuaternion *= Quaternion . Euler ( 0f , Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ? - 2f : - 1f , 0f ) ;
415450 } else {
416451 VRCUtils . GetUserCameraController ( ) . viewFinder . transform . Rotate ( new Vector3 ( 0f , 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? - 2f : - 1f ) ) ;
417452 }
418453 }
419454 if ( Input . GetKey ( KeyCode . Keypad6 ) ) {
420455 if ( Settings . moveCamera ) {
421- if ( Settings . allowCameraMovement ) CameraUtils . worldCameraQuaternion *= Quaternion . Euler ( 0f , Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ? - 2f : - 1f , 0f ) ;
456+ if ( Settings . allowCameraMovement ) CameraUtils . worldCameraQuaternion *= Quaternion . Euler ( 0f , Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ? 2f : 1f , 0f ) ;
422457 } else {
423458 VRCUtils . GetUserCameraController ( ) . viewFinder . transform . Rotate ( new Vector3 ( 0f , 0f , ( Input . GetKey ( KeyCode . LeftAlt ) || Input . GetKey ( KeyCode . RightAlt ) ) ? 2f : 1f ) ) ;
424459 }
@@ -467,6 +502,6 @@ public override void OnUpdate() {
467502 }
468503 }
469504 }
470- }
471- }
505+ }
506+ }
472507}
0 commit comments