4using System.Runtime.Versioning;
8using System.Diagnostics;
11using System.Security.Cryptography;
13using System.Reflection;
16using System.Globalization;
21[assembly: SupportedOSPlatform(
"browser")]
29 public static Mutex m_mutex;
30 public static bool m_mutexHandled;
39 public static bool m_firstFramePrepared;
45 public static async Task Main2(
string[] args) {
54 public static int Counter;
55 [System.Runtime.InteropServices.UnmanagedCallersOnly]
56 public static int Frame(
double time, nint userData)
64 primitivesRenderer2D.
Flush();
65 if (++Counter >= size.
X) {
71 public static async Task
Main(
string[] args) {
73 static void Main(
string[] args) {
79 switch (args.Length) {
81 string path = args[0];
84 && File.Exists(path)) {
85 using (FileStream fileStream = File.OpenRead(path)) {
89 Window.MessageBox(IntPtr.Zero, $
"Successfully imported {fileName}.\n导入 {fileName} 成功",
"Success 成功", 0x40u);
92 Window.MessageBox(IntPtr.Zero, $
"Failed to import {fileName}, reason:\n导入 {fileName} 失败,原因:\n{e}",
null, 0x10u);
99 if (args[0] !=
"--wait") {
102 if (
int.TryParse(args[1], out
int pid)) {
104 Process.GetProcessById(pid)?.WaitForExit();
114 using (SHA256 sha256 = SHA256.Create()) {
115 byte[] hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(Assembly.GetEntryAssembly()?.Location ??
"SurvivalcraftApi"));
116 mutexName = $
"Global\\{BitConverter.ToString(hash).Replace("-
", "").ToLowerInvariant()}";
118 m_mutex =
new Mutex(
true, mutexName, out m_mutexHandled);
119 if (!m_mutexHandled) {
122 "This game is already running! If you cannot find the window, please stop it from the Task Manager, and check the log file in Bugs directory.\n游戏已经在运行!如果找不到游戏窗口,请从任务管理器终止它,并检查 Bugs 目录中的日志文件。";
123 Window.MessageBox(IntPtr.Zero, str,
null, 0x10u);
131 InputMethod.Initialize(Process.GetCurrentProcess().MainWindowHandle);
132 InputMethod.Enabled =
false;
137 m_mutex.ReleaseMutex();
162 SystemLanguage = RegionInfo.CurrentRegion.DisplayName !=
"United States" ?
"zh-CN" :
"en-US";
172 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
173 CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
174 string title = $
"Survivalcraft {ModsManager.ShortGameVersion} - API {ModsManager.APIVersionString}";
177 title = $
"[DEBUG]{title}";
209 $
"Survivalcraft starting up at {DateTime.Now}, GameVersion={VersionsManager.Version}, BuildConfiguration={VersionsManager.BuildConfiguration}, Platform={VersionsManager.PlatformString}, Storage.AvailableFreeSpace={Storage.FreeSpace / 1024 / 1024}MB, ApproximateScreenDpi={ScreenResolutionManager.ApproximateScreenDpi:0.0}, ApproxScreenInches={ScreenResolutionManager.ApproximateScreenInches:0.0}, ScreenResolution={Window.Size}, ProcessorsCount={Environment.ProcessorCount}, APIVersion={ModsManager.APIVersionString}, 64bit={Environment.Is64BitProcess}"
219 catch (Exception e) {
224 public static void Run() {
228#if !MOBILE && !BROWSER
253 catch (Exception e) {
264 catch (Exception e3) {
270 Display.RenderTarget =
null;
285 catch (Exception e2) {
296 m_firstFramePrepared =
true;
300 m_firstFramePrepared =
true;
309#pragma warning disable CA1416
310 Intent intent =
new Intent(
Window.Activity,
Window.Activity.Class);
311 Window.Activity.StartActivity(intent);
313 Process current = Process.GetCurrentProcess();
314 Process.Start(
new ProcessStartInfo
316 FileName = current.MainModule!.FileName!,
317 Arguments = $
"--wait {current.Id}",
318 UseShellExecute =
false
static partial void FirstFramePrepared()
static partial string GetLanguage()
static partial void Initialize(IntPtr sharedInputMemoryPtr)
static unsafe void RequestAnimationFrameLoop(void *f, nint userDataPtr)
static void Clear(Vector4? color, float? depth=null, int? stencil=null)
static Point2 BackbufferSize
void QueueLine(Vector2 p1, Vector2 p2, float depth, Color color)
FlatBatch2D FlatBatch(int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null)
void Flush(bool clearAfterFlush=true, int maxLayer=int.MaxValue)
static void Error(object message)
static void Information(object message)
static void AddLogSink(ILogSink logSink)
static string GetExtension(string path)
static string GetFileName(string path)
readonly Exception Exception
static void Run(int width=0, int height=0, WindowMode windowMode=WindowMode.Resizable, string title="")
static Action Deactivated
static Action< UnhandledExceptionInfo > UnhandledException
static Action< Uri > HandleUri
static Action< List<(Stream stream, string fileName)> > FileDropped
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static void UpdateExceptionScreen()
static void DrawExceptionScreen()
static void ReportExceptionToUser(string additionalMessage, Exception e)
static bool IsEntryTypeDownloadSupported(ExternalContentType type)
static async Task ImportExternalContentsAsync(List<(Stream stream, string fileName)> files, bool showResultDialog)
static ExternalContentType ExtensionToType(string extension)
static string ImportExternalContentSync(Stream stream, ExternalContentType type, string name)
static void DisposeProject()
static bool m_isContentLoaded
static void FileDropHandler(List<(Stream stream, string fileName)> files)
static float LastFrameTime
static Action< Uri > HandleUri
static float LastCpuFrameTime
static void Main(string[] args)
static void FrameHandler()
static void ToRestartHandler()
static double m_frameBeginTime
static void HandleUriHandler(Uri uri)
static string SystemLanguage
static double m_cpuEndTime
static List< Uri > m_urisToHandle
static void DeactivatedHandler()
static void SwitchScreen(string name, params object[] parameters)
static Screen CurrentScreen
static WindowMode WindowMode
void SetErrorHead(int headLangIndex, int adviceLangIndex)