Files
Assembly-CSharp/Assembly-CSharp/Mai2/LogCallback.cs
2026-06-12 12:58:31 +08:00

261 lines
7.1 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace MAI2
{
// Token: 0x02000710 RID: 1808
public static class LogCallback
{
// Token: 0x060041EB RID: 16875 RVA: 0x00172031 File Offset: 0x00171231
public static void initialize(string logSendAddress, int logSendLevel, string logLocalAddress)
{
LogCallback.LogSendAddress = logSendAddress;
LogCallback.LogSendLevel = Mathf.Clamp(logSendLevel, 0, 4);
LogCallback.LogLocalIP = logLocalAddress;
Application.logMessageReceived += new Application.LogCallback(LogCallback.logCallback);
}
// Token: 0x060041EC RID: 16876 RVA: 0x00172060 File Offset: 0x00171260
private static void logCallback(string logString, string stackTrace, LogType type)
{
if (string.IsNullOrEmpty(LogCallback.LogSendAddress))
{
return;
}
switch (type)
{
case 0:
if (LogCallback.LogSendLevel <= 3)
{
LogCallback.LogSender.create(logString, stackTrace, 3, LogCallback.LogLocalIP);
return;
}
break;
case 1:
if (LogCallback.LogSendLevel <= 2)
{
LogCallback.LogSender.create(logString, stackTrace, 2, LogCallback.LogLocalIP);
return;
}
break;
case 2:
if (LogCallback.LogSendLevel <= 1)
{
LogCallback.LogSender.create(logString, stackTrace, 1, LogCallback.LogLocalIP);
return;
}
break;
case 3:
if (LogCallback.LogSendLevel <= 0)
{
LogCallback.LogSender.create(logString, stackTrace, 0, LogCallback.LogLocalIP);
return;
}
break;
case 4:
if (LogCallback.LogSendLevel <= 4)
{
LogCallback.LogSender.create(logString, stackTrace, 4, LogCallback.LogLocalIP);
}
break;
default:
return;
}
}
// Token: 0x04004D06 RID: 19718
public const int LogLevel_Log = 0;
// Token: 0x04004D07 RID: 19719
public const int LogLevel_Warning = 1;
// Token: 0x04004D08 RID: 19720
public const int LogLevel_Assert = 2;
// Token: 0x04004D09 RID: 19721
public const int LogLevel_Error = 3;
// Token: 0x04004D0A RID: 19722
public const int LogLevel_Exception = 4;
// Token: 0x04004D0B RID: 19723
private static string LogSendAddress = string.Empty;
// Token: 0x04004D0C RID: 19724
private static int LogSendLevel = 2;
// Token: 0x04004D0D RID: 19725
private static string LogLocalIP = string.Empty;
// Token: 0x02000D8C RID: 3468
private class LogSender : MonoBehaviour
{
// Token: 0x060058EE RID: 22766 RVA: 0x001BAFE4 File Offset: 0x001BA1E4
public static void create(string message, string stackTrace, int level, string ip)
{
GameObject gameObject = GameObject.Find("/LogSender");
LogCallback.LogSender logSender;
if (null != gameObject)
{
logSender = gameObject.GetComponent<LogCallback.LogSender>();
}
else
{
gameObject = new GameObject("LogSender");
logSender = gameObject.AddComponent<LogCallback.LogSender>();
}
logSender.push(message, stackTrace, level, ip);
}
// Token: 0x060058EF RID: 22767 RVA: 0x001BB02C File Offset: 0x001BA22C
private void push(string message, string stackTrace, int level, string ip)
{
DateTime dateTime = DateTime.UtcNow.ToLocalTime();
while (8 < this.checkSame_.Count)
{
this.checkSame_.RemoveAt(0);
}
for (int i = 0; i < this.checkSame_.Count; i++)
{
double totalSeconds = (dateTime - this.checkSame_[i].localTime_).TotalSeconds;
if (this.checkSame_[i].message_ == message && totalSeconds <= 60.0)
{
return;
}
}
base.StartCoroutine(this.pushImpl(dateTime, message, stackTrace, level, ip));
}
// Token: 0x060058F0 RID: 22768 RVA: 0x001BB0D3 File Offset: 0x001BA2D3
private IEnumerator pushImpl(DateTime localTime, string message, string stackTrace, int level, string ip)
{
yield return new WaitForEndOfFrame();
Texture2D texture2D = new Texture2D(Screen.width, Screen.height);
texture2D.ReadPixels(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), 0, 0);
texture2D.Apply();
Texture2D texture2D2 = new Texture2D(Screen.width >> 1, Screen.height >> 1);
for (int i = 0; i < texture2D2.height; i++)
{
float num = Mathf.Clamp01((float)i / (float)texture2D2.height);
for (int j = 0; j < texture2D2.width; j++)
{
float num2 = Mathf.Clamp01((float)j / (float)texture2D2.width);
texture2D2.SetPixel(j, i, texture2D.GetPixelBilinear(num2, num));
}
}
texture2D2.Apply();
byte[] array = ImageConversion.EncodeToJPG(texture2D2);
LogCallback.LogSender.Log log = default(LogCallback.LogSender.Log);
log.localTime_ = localTime;
log.message_ = message;
log.stackTrace_ = stackTrace;
log.level_ = level;
log.ip_ = ip;
log.bytes_ = array;
this.checkSame_.Add(log);
this.logs_.Add(log);
yield break;
}
// Token: 0x060058F1 RID: 22769 RVA: 0x001BB107 File Offset: 0x001BA307
private void Awake()
{
Object.DontDestroyOnLoad(base.gameObject);
}
// Token: 0x060058F2 RID: 22770 RVA: 0x001BB114 File Offset: 0x001BA314
private void Update()
{
int num = this.state_;
if (num != 0)
{
if (num != 1)
{
return;
}
if (this.uwr_ == null || this.uwr_.isDone)
{
if (this.uwr_ != null)
{
this.uwr_.Dispose();
this.uwr_ = null;
}
this.state_ = 0;
}
}
else
{
if (0 < this.logs_.Count)
{
this.time_ = 0f;
LogCallback.LogSender.Log log = this.logs_[0];
this.logs_.RemoveAt(0);
WWWForm wwwform = new WWWForm();
wwwform.AddField("date", log.localTime_.ToString());
wwwform.AddField("message", log.message_);
wwwform.AddField("stack", log.stackTrace_);
wwwform.AddField("level", log.level_);
wwwform.AddField("ip", log.ip_);
wwwform.AddBinaryData("image", log.bytes_, "ss.jpg");
this.uwr_ = UnityWebRequest.Post(LogCallback.LogSendAddress, wwwform);
this.state_ = 1;
return;
}
this.time_ += Time.deltaTime;
if (20f < this.time_)
{
Object.Destroy(base.gameObject);
return;
}
}
}
// Token: 0x04007588 RID: 30088
public const int State_Init = 0;
// Token: 0x04007589 RID: 30089
public const int State_Proc = 1;
// Token: 0x0400758A RID: 30090
private int state_;
// Token: 0x0400758B RID: 30091
private float time_;
// Token: 0x0400758C RID: 30092
private List<LogCallback.LogSender.Log> checkSame_ = new List<LogCallback.LogSender.Log>(8);
// Token: 0x0400758D RID: 30093
private List<LogCallback.LogSender.Log> logs_ = new List<LogCallback.LogSender.Log>();
// Token: 0x0400758E RID: 30094
private UnityWebRequest uwr_;
// Token: 0x02000DBD RID: 3517
public struct Log
{
// Token: 0x040075E9 RID: 30185
public DateTime localTime_;
// Token: 0x040075EA RID: 30186
public string message_;
// Token: 0x040075EB RID: 30187
public string stackTrace_;
// Token: 0x040075EC RID: 30188
public int level_;
// Token: 0x040075ED RID: 30189
public string ip_;
// Token: 0x040075EE RID: 30190
public byte[] bytes_;
}
}
}
}