// Copyright 2026 Code Philosophy // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using System; using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; using UnityEngine.Scripting; namespace HybridCLR { [Preserve] public static class RuntimeApi { /// /// load supplementary metadata assembly /// /// /// /// #if UNITY_EDITOR public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode) { return LoadImageErrorCode.OK; } #else [MethodImpl(MethodImplOptions.InternalCall)] public static extern LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode); #endif /// /// prejit method to avoid the jit cost of first time running /// /// /// return true if method is jited, return false if method can't be jited /// #if UNITY_EDITOR public static bool PreJitMethod(MethodInfo method) { return false; } #else [MethodImpl(MethodImplOptions.InternalCall)] public static extern bool PreJitMethod(MethodInfo method); #endif /// /// prejit all methods of class to avoid the jit cost of first time running /// /// /// return true if class is jited, return false if class can't be jited #if UNITY_EDITOR public static bool PreJitClass(Type type) { return false; } #else [MethodImpl(MethodImplOptions.InternalCall)] public static extern bool PreJitClass(Type type); #endif /// /// get the maximum number of StackObjects in the interpreter thread stack (size*8 represents the final memory size occupied /// /// public static int GetInterpreterThreadObjectStackSize() { return GetRuntimeOption(RuntimeOptionId.InterpreterThreadObjectStackSize); } /// /// set the maximum number of StackObjects for the interpreter thread stack (size*8 represents the final memory size occupied) /// /// public static void SetInterpreterThreadObjectStackSize(int size) { SetRuntimeOption(RuntimeOptionId.InterpreterThreadObjectStackSize, size); } /// /// get the number of interpreter thread function frames (sizeof(InterpreterFrame)*size represents the final memory size occupied) /// /// public static int GetInterpreterThreadFrameStackSize() { return GetRuntimeOption(RuntimeOptionId.InterpreterThreadFrameStackSize); } /// /// set the number of interpreter thread function frames (sizeof(InterpreterFrame)*size represents the final memory size occupied) /// /// public static void SetInterpreterThreadFrameStackSize(int size) { SetRuntimeOption(RuntimeOptionId.InterpreterThreadFrameStackSize, size); } #if UNITY_EDITOR private static readonly Dictionary s_runtimeOptions = new Dictionary(); /// /// set runtime option value /// /// /// public static void SetRuntimeOption(RuntimeOptionId optionId, int value) { s_runtimeOptions[optionId] = value; } #else [MethodImpl(MethodImplOptions.InternalCall)] public static extern void SetRuntimeOption(RuntimeOptionId optionId, int value); #endif /// /// get runtime option value /// /// /// #if UNITY_EDITOR public static int GetRuntimeOption(RuntimeOptionId optionId) { if (s_runtimeOptions.TryGetValue(optionId, out var value)) { return value; } return 0; } #else [MethodImpl(MethodImplOptions.InternalCall)] public static extern int GetRuntimeOption(RuntimeOptionId optionId); #endif } }