forked from KaBooMa/S1API
-
-
Notifications
You must be signed in to change notification settings - Fork 21
v0.4.4f10 Game Update #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2a6b7ab
v0.4.4f6 compatibility
HazDS e366925
Merge branch 'beta' into haz/v0.4.4f6-compat
ifBars e7ef1ba
chore: Address CodeRabbit Comments
ifBars 5179859
Merge pull request #57 from HazDS/haz/v0.4.4f6-compat
ifBars a3c0ea2
Update docs.yml
ifBars a23a58e
Merge branch 'beta' of https://github.com/ifBars/S1API into beta
ifBars d1bd975
Fixed v0.4.4f10 BuildableItems access change
HazDS 658b635
feat: Add UnityExceptionTraceHook
ifBars 682e711
Update UnityExceptionTraceHook.cs
ifBars 8d6169a
chore: address coderabbit & codex findings
ifBars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| using System; | ||
| using S1API.Logging; | ||
| using UnityEngine; | ||
| #if IL2CPPMELON | ||
| using Il2CppInterop.Runtime; | ||
| #endif | ||
|
|
||
| namespace S1API.Internal.Diagnostics | ||
| { | ||
| /// <summary> | ||
| /// INTERNAL: Hooks Unity's threaded log callback to emit detailed stack traces for NullReferenceException logs. | ||
| /// </summary> | ||
| internal static class UnityExceptionTraceHook | ||
| { | ||
| private static readonly Log Logger = new Log("UnityExceptionTrace"); | ||
| private static readonly object Sync = new object(); | ||
| #if IL2CPPMELON | ||
| private static readonly System.Action<string, string, LogType> ManagedCallback = OnUnityLogMessageReceived; | ||
| private static readonly Application.LogCallback Callback = DelegateSupport.ConvertDelegate<Application.LogCallback>(ManagedCallback); | ||
| #endif | ||
|
|
||
| private static string _lastExceptionSignature; | ||
| private static DateTime _lastExceptionAtUtc; | ||
| private static bool _installed; | ||
|
|
||
| internal static void Install() | ||
| { | ||
| if (_installed) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| #if IL2CPPMELON | ||
| Application.add_logMessageReceivedThreaded(Callback); | ||
| #else | ||
| Application.logMessageReceivedThreaded += OnUnityLogMessageReceived; | ||
| #endif | ||
| _installed = true; | ||
| } | ||
|
|
||
| internal static void Remove() | ||
| { | ||
| if (!_installed) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| #if IL2CPPMELON | ||
| _installed = false; | ||
| return; | ||
| #else | ||
| try | ||
| { | ||
| Application.logMessageReceivedThreaded -= OnUnityLogMessageReceived; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Logger.Warning($"[Unity] Failed to remove threaded log callback during shutdown: {ex.Message}"); | ||
| } | ||
|
|
||
| _installed = false; | ||
| #endif | ||
| } | ||
|
|
||
| private static void OnUnityLogMessageReceived(string condition, string stackTrace, LogType type) | ||
| { | ||
| if (type != LogType.Exception) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (!LooksLikeNullReference(condition, stackTrace)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| string signature = string.Concat(condition ?? string.Empty, "\n", stackTrace ?? string.Empty); | ||
| if (ShouldSuppressDuplicate(signature)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| Logger.Error($"[Unity] {condition}"); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(stackTrace)) | ||
| { | ||
| Logger.Error($"[Unity] stack trace:\n{stackTrace}"); | ||
| } | ||
| } | ||
|
|
||
| private static bool LooksLikeNullReference(string condition, string stackTrace) | ||
| { | ||
| string haystack = string.Concat(condition ?? string.Empty, "\n", stackTrace ?? string.Empty); | ||
| return haystack.Contains("NullReferenceException", StringComparison.Ordinal); | ||
| } | ||
|
|
||
| private static bool ShouldSuppressDuplicate(string signature) | ||
| { | ||
| lock (Sync) | ||
| { | ||
| DateTime now = DateTime.UtcNow; | ||
| if (signature == _lastExceptionSignature && (now - _lastExceptionAtUtc).TotalSeconds < 1) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| _lastExceptionSignature = signature; | ||
| _lastExceptionAtUtc = now; | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.