<commit_before>using System;
using System.IO;
using System.Threading;
using Mod;
using UnityEngine;

public class UIMainReferences : MonoBehaviour
{
    public const string Version = "01042015";
    private static bool _done;
    
    private void Start()
    {
        if (!_done)
        {
            _done = true;
            
            float aspectRatio = (float) Screen.currentResolution.width / Screen.currentResolution.height;
            if (Mathf.Abs((float) Screen.width / Screen.height - aspectRatio) > float.Epsilon)
                Screen.SetResolution((int)(Screen.height * aspectRatio), Screen.height, Screen.fullScreen);
            
            GameObject go = new GameObject("Shelter");
            Shelter shelter = go.AddComponent<Shelter>();
            DontDestroyOnLoad(go);
            shelter.InitComponents();


            new Thread(() =>
            {
                LoadAssets("RCAssets");
            }).Start();
        }

        Shelter.OnMainMenu();
    }

    private static void LoadAssets(string asset)
    {
        using (var stream = Shelter.Assembly.GetManifestResourceStream($@"Mod.Resources.Assets.{asset}.unity3d"))
        {
            if (stream == null)
                throw new NullReferenceException("Cannot find resource"); // TODO: Log
            using (var ms = new MemoryStream())
            {
                byte[] buffer = new byte[8192];

                int bytesRead;
                while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                    ms.Write(buffer, 0, bytesRead);
                
                ms.Flush();

                FengGameManagerMKII.RCassets = AssetBundle.CreateFromMemoryImmediate(ms.ToArray());
            }
        }
    }
}<commit_msg>Added LogCallbacks and went back to single threaded assets loading.<commit_after>using System;
using System.Collections;
using System.IO;
using Mod;
using Mod.Interface;
using Mod.Logging;
using UnityEngine;

public class UIMainReferences : MonoBehaviour
{
    public const string Version = "01042015";
    private static bool _done;
    
    private void Start()
    {
        if (!_done)
        {
            _done = true;
            
            float aspectRatio = (float) Screen.currentResolution.width / Screen.currentResolution.height;
            if (Mathf.Abs((float) Screen.width / Screen.height - aspectRatio) > float.Epsilon)
                Screen.SetResolution((int)(Screen.height * aspectRatio), Screen.height, Screen.fullScreen);
            
            GameObject go = new GameObject("Shelter");
            Shelter shelter = go.AddComponent<Shelter>();
            DontDestroyOnLoad(go);
            shelter.InitComponents();

            Application.RegisterLogCallback(UnityLogHandle);
            
            StartCoroutine(LoadRCAssets());
        }

        Shelter.OnMainMenu();
    }
    
    private void UnityLogHandle(string log, string stacktrace, LogType type)
    {
        switch (type)
        {
            case LogType.Error:
                Shelter.Log(log, LogLevel.Error);
                break;
            case LogType.Assert:
                Shelter.Log(log, LogLevel.Error);
                break;
            case LogType.Warning:
                if (!log.Contains("Behaviour is missing!"))
                    Shelter.Log(log, LogLevel.Warning);
                break;
            case LogType.Log:
                Shelter.Log(log);
                break;
            case LogType.Exception:
                Shelter.Log($"{log} {stacktrace}", LogLevel.Error);
                break;
            default:
                Shelter.Log($"LogLevel {type} does not exist.", LogLevel.Error);
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
        }
    }

    private static IEnumerator LoadRCAssets()
    {
        var url = "http://iishawk.it/AoTTG/RCAssets.unity3d";
        var file = Application.dataPath + "/RCAssets.unity3d";
        if (File.Exists(file))
            url = "file://" + file;
        
        while (!Caching.ready)
            yield return null;
        using (WWW www = WWW.LoadFromCacheOrDownload(url, 1))
        {
            yield return www;
            if (www.error != null)
                throw new Exception("Error on WWW request (RCAssets):" + www.error);
            FengGameManagerMKII.RCassets = www.assetBundle;
        }
    }
}
{'fraction_non_alphanumeric': 0.10177192185370286, 'fraction_numerical': 0.006133575647432985, 'mean_word_length': 1.7744171392564587, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 5, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6230694', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1174, 'n_words': 264}