mirror of
https://github.com/hykilpikonna/AquaDX.git
synced 2026-08-27 03:34:52 -05:00
[F] CustomCameraId crash when no camera
This commit is contained in:
9
AquaMai.Core/Resources/Locale.Designer.cs
generated
9
AquaMai.Core/Resources/Locale.Designer.cs
generated
@@ -151,6 +151,15 @@ namespace AquaMai.Core.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No camera detected.
|
||||
/// </summary>
|
||||
public static string NoCamera {
|
||||
get {
|
||||
return ResourceManager.GetString("NoCamera", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Pause.
|
||||
/// </summary>
|
||||
|
||||
@@ -122,4 +122,7 @@
|
||||
<data name="UserGhostAchievement" xml:space="preserve">
|
||||
<value>Battle Target: {0}</value>
|
||||
</data>
|
||||
<data name="NoCamera" xml:space="preserve">
|
||||
<value>No camera detected</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -115,4 +115,7 @@
|
||||
<data name="UserGhostAchievement" xml:space="preserve">
|
||||
<value>友人对战目标: {0}</value>
|
||||
</data>
|
||||
<data name="NoCamera" xml:space="preserve">
|
||||
<value>没有找到任何摄像头</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -7,6 +7,8 @@ using Manager;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
using AquaMai.Config.Attributes;
|
||||
using AquaMai.Core.Helpers;
|
||||
using AquaMai.Core.Resources;
|
||||
|
||||
namespace AquaMai.Mods.GameSystem;
|
||||
|
||||
@@ -45,7 +47,7 @@ public class CustomCameraId
|
||||
en: "WeChat QRCode Camera.",
|
||||
zh: "二维码扫描摄像头")]
|
||||
public static int chimeCamera;
|
||||
|
||||
|
||||
private static readonly Dictionary<string, string> cameraTypeMap = new()
|
||||
{
|
||||
["LeftQrCamera"] = "QRLeft",
|
||||
@@ -64,6 +66,14 @@ public class CustomCameraId
|
||||
|
||||
private static IEnumerator CameraInitialize(CameraManager __instance)
|
||||
{
|
||||
if (WebCamTexture.devices.Length == 0)
|
||||
{
|
||||
MelonLogger.Warning("[CustomCameraId] No camera detected, camera initialization failed.");
|
||||
MessageHelper.ShowMessage(Locale.NoCamera, title: "CustomCameraId");
|
||||
CameraManager.IsReady = true;
|
||||
yield break;
|
||||
}
|
||||
|
||||
var textureCache = new WebCamTexture[WebCamTexture.devices.Length];
|
||||
SortedDictionary<CameraManager.CameraTypeEnum, WebCamTexture> webCamTextures = [];
|
||||
foreach (var (configEntry, cameraTypeName) in cameraTypeMap)
|
||||
@@ -105,6 +115,7 @@ public class CustomCameraId
|
||||
CameraManager.DeviceId[(int)cameraType] = textureIndex;
|
||||
textureIndex++;
|
||||
}
|
||||
|
||||
Traverse.Create(__instance).Field("_webcamtex").SetValue(webCamTextures.Values.ToArray());
|
||||
|
||||
CameraManager.IsReady = true;
|
||||
@@ -132,11 +143,12 @@ public class CustomCameraId
|
||||
cameraList += $"FPS: {webCamTexture.requestedFPS}\n";
|
||||
webCamTexture.Stop();
|
||||
}
|
||||
|
||||
cameraList += "==================================================";
|
||||
|
||||
|
||||
foreach (var line in cameraList.Split('\n'))
|
||||
{
|
||||
MelonLogger.Msg($"[CustomCameraId] {line}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user