// // /*=============================================================================== // // Copyright (C) 2022 PhantomsXR Ltd. All Rights Reserved. // // // // This file is part of the UnityFusion.Runtime.CodeHook. // // // // The ARMOD-SDK cannot be copied, distributed, or made available to // // third-parties for commercial purposes without written permission of PhantomsXR Ltd. // // // // Contact nswell@phantomsxr.com for licensing requests. // // ===============================================================================*/ using System; using System.Collections.Generic; using UnityFusion.CLR.Method; using UnityFusion.CLR.Utils; using UnityFusion.Runtime.Intepreter; using UnityFusion.Runtime.Stack; using UnityEngine; using AppDomain = UnityFusion.Runtime.Enviorment.AppDomain; #if DEBUG && !DISABLE_UNITYFUSION_DEBUG using AutoList = System.Collections.Generic.List; #else using AutoList = UnityFusion.Other.UncheckedList; #endif namespace Phantom.XRMOD.UnityFusion.Runtime { public class DebugClrMethodRegister : AbstractRegister { public override unsafe void Register(AppDomain _appDomain) { base.Register(_appDomain); Type tmp_DebugType = typeof(Debug); var tmp_LOGMethod = tmp_DebugType.GetMethod("Log", new[] {typeof(object)}); _appDomain.RegisterCLRMethodRedirection(tmp_LOGMethod, Log); var tmp_LOGWarningMethod = tmp_DebugType.GetMethod("LogWarning", new[] {typeof(object)}); _appDomain.RegisterCLRMethodRedirection(tmp_LOGWarningMethod, LogWarning); var tmp_LOGErrorMethod = tmp_DebugType.GetMethod("LogError", new[] {typeof(object)}); _appDomain.RegisterCLRMethodRedirection(tmp_LOGErrorMethod, LogError); } /// /// Debug.Log /// /// /// /// /// /// /// private unsafe StackObject* Log(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); object tmp_Message = typeof(object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var tmp_Stacktrace = __domain.DebugService.GetStackTrace(__intp); Debug.Log($"{tmp_Message}\r\nUnityFusion StackTrace\n{tmp_Stacktrace}"); return __ret; } /// /// Debug.LogError /// /// /// /// /// /// /// private unsafe StackObject* LogError(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); object @message = typeof(object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var tmp_Stacktrace = __domain.DebugService.GetStackTrace(__intp); Debug.LogError($"{message}\r\nUnityFusion StackTrace\n{tmp_Stacktrace}"); return __ret; } /// /// Debug.LogWarning /// /// /// /// /// /// /// private unsafe StackObject* LogWarning(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); object tmp_Message = typeof(object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var tmp_Stacktrace = __domain.DebugService.GetStackTrace(__intp); Debug.LogWarning($"{tmp_Message}\r\nUnityFusion StackTrace\n{tmp_Stacktrace}"); return __ret; } } }