Files
2026-05-26 16:15:54 +08:00

645 lines
23 KiB
C#

using System;
using System.Linq;
using asap.core;
using game;
using GameCore;
using IngameDebugConsole;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
public class DebugFunc
{
public static void Init()
{
var config = GContext.container.Resolve<IConfig>();
if (config != null && (config.Get("DEBUG", "0") == "1" || config.Get("GM", "0") == "1"))
{
DebugLogConsole.AddCommand<string, string>("Go.show", "Shows a GameObject", ShowGO);
DebugLogConsole.AddCommand<string, string>("Go.hide", "Shows a GameObject", HideGO);
DebugLogConsole.AddCommand<int, string>("Render.quality", "change quality", SetQuality);
DebugLogConsole.AddCommand<float, string>("Render.scale", "Set render scale [0.1-2]", SetRendererScale);
DebugLogConsole.AddCommand<int, string>("Render.aa", "anti aliasing", SetAntiAliasing);
DebugLogConsole.AddCommand<string>("Render.ShadowToggle", "Toggle Shadow", ToggleShadow);
DebugLogConsole.AddCommand<string, string>("Render.Pipline", "light num", SetRenderPipline);
DebugLogConsole.AddCommand<string>("info.GPU", "GPU Info", GpuInfo);
DebugLogConsole.AddCommand<string>("info.CPU", "CPU Info", CpuInfo);
DebugLogConsole.AddCommand<string>("info.Support", "Device Support", SupportInfo);
DebugLogConsole.AddCommand("FPS", "Toggle FPS", Fps);
DebugLogConsole.AddCommand<int>("Render.antiAliasing", "change antiAliasing", SetRTAntiAliasing);
DebugLogConsole.AddCommand<string>("T.hotupdate", "hot update test", HotUpdateTest);
DebugLogConsole.AddCommand<string, string>("UI.hide", "Hide UI", ToggleUI);
DebugLogConsole.AddCommand<int, string>("Misc.tg", "Hide misc", ToggleMisc);
DebugLogConsole.AddCommand("aihelp", "open aihelp", OpenAIHelp);
DebugLogConsole.AddCommand("review", "open review", OpenReview);
DebugLogConsole.AddCommand("Pay.sku", "sku list", GetSKUs);
DebugLogConsole.AddCommand("ad.debug", "Active Ad Debug", ActiveAdDebug);
DebugLogConsole.AddCommand("ad.media", "Active Ad Media Debug", ActiveAdMedia);
DebugLogConsole.AddCommand("notify.send", "Local Notify Test", NotifyTest);
DebugLogConsole.AddCommand("notify.setting", " Notify set", NotifySettingTest);
DebugLogConsole.AddCommand<string>("notify.status", " Notify Status", NotificationStatus);
DebugLogConsole.AddCommand<string>("notify.time", "Notify at certain time", NotifyAtTime);
DebugLogConsole.AddCommand("mail.status", "Print cache mail", PrintMail);
DebugLogConsole.AddCommand("mail.fetch", "fetch mail to cache", FetchMail);
DebugLogConsole.AddCommand("rt.test", "test realtime", RtTest);
DebugLogConsole.AddCommand("account.login1D", "login time - 1day", Login1D);
DebugLogConsole.AddCommand("account.info", "account info", AccoutInfo);
DebugLogConsole.AddCommand("account.authortest", "author test", AuthorTest);
DebugLogConsole.AddCommand("aihelp.test", "aihelp test", AIHelpTest);
DebugLogConsole.AddCommand("open.washing", "Open Washing Activity", OpenWashingActivity);
DebugLogConsole.AddCommand<int, int>("WashingGoTo", "Event Washing Go To Ship & Step", WashingGoTo);
DebugLogConsole.AddCommand("washing.clear", "Clear Washing Data", WashingDataClear);
DebugLogConsole.AddCommand("deeplink.test", "Test if deeplink connects. If so, returns pid and uid.", TestDeepLink);
DebugLogConsole.AddCommand<int>("PotionGoTo", "Potion Go To", PotionGoTo);
DebugLogConsole.AddCommand("potion.clear", "Potion Go To", PotionClear);
DebugLogConsole.AddCommand("pinball.clear", "Clear Pinball Data", PinballDataClear);
DebugLogConsole.AddCommand<float>("pinball.fire", "Launch Pinball Pellet", PinballFirePellet);
DebugLogConsole.AddCommand("scratch.clear", "Clear Scratch Ticket Data", ScratchTicketDataClear);
DebugLogConsole.AddCommand<int>("shooting.go", "Goto", ShootingRangeDebug);
DebugLogConsole.AddCommand("eventpartner.activate", "Activate a temp event", EventPartnerDebugActivate);
DebugLogConsole.AddCommand("bingo.ts", "OpenTestScene", ShowTestBingoPanel);
DebugLogConsole.AddCommand("bingo.seeds", "TestBingoSeedPickingRng", TestBingoSeedPickingRng);
DebugLogConsole.AddCommand("bingo.instant", "Instant Bingo.", TestBingoInstantBingo);
DebugLogConsole.AddCommand("srp.fswave", "toggle fullscreen wave", ToggleFSWave);
DebugLogConsole.AddCommand<int>("ib.lvl", "infinitebuilding level", SetInfiniteBuildLvl);
DebugLogConsole.AddCommand("srp.fsblur", "toggle fullscreen blur", ToggleFSBlur);
DebugLogConsole.AddCommand<string>("stash", "test reward stash service", TestRewardStashService);
DebugLogConsole.AddCommand("guide.clear", "clear guide data", ClearGuide);
}
}
private static void TestDeepLink()
{
var res = AFHelper.Instance.GetDLReferer(out var pid, out var uid);
Debug.Log($"DidReceiveDeepLink: {AFHelper.Instance.DidReceivedDeepLink}");
Debug.Log($"IsFirstLaunch: {AFHelper.Instance.IsFirstLaunch}");
if (AFHelper.Instance.DeepLinkParamsDictionary is not null)
{
Debug.Log($"DeepLinkParamsDic:");
foreach (var kvp in AFHelper.Instance.DeepLinkParamsDictionary)
{
Debug.Log($"{kvp.Key}: {kvp.Value}");
}
}
else
{
Debug.Log($"DeepLinkParamsDic: Empty.");
}
var message = res ? $"Deeplink success with pid: {pid}, uid: {uid}" : "Deeplink fail.";
Debug.Log(message);
}
private static void NotifyAtTime(string time)
{
var now = ZZTimeHelper.UtcNow();
var fireTime = DateTime.SpecifyKind(DateTime.Parse(time), DateTimeKind.Utc);
fireTime = fireTime.AddDays(now <= fireTime ? 0 : 1);
var service = GContext.container.Resolve<ILocalNotificationService>();
service.ScheduleOneTimeNotification(434200, fireTime.ToLocalTime(), "Test Note at Time",
$"Test Notification @ {fireTime}.");
}
private static void NotifyTest()
{
ILocalNotificationService service = GContext.container.Resolve<ILocalNotificationService>();
service.ScheduleOneTimeNotification(434200, DateTime.Now + TimeSpan.FromSeconds(3), "Notification",
"Test Notification ");
}
private static void NotifySettingTest()
{
ILocalNotificationService service = GContext.container.Resolve<ILocalNotificationService>();
service.OpenSettings();
}
private static string NotificationStatus()
{
#if UNITY_ANDROID
return Unity.Notifications.Android.AndroidNotificationCenter.UserPermissionToPost.ToString();
#else
return Unity.Notifications.iOS.iOSNotificationCenter.GetNotificationSettings().AuthorizationStatus.ToString();
#endif
}
private static string HotUpdateTest()
{
return "hot update test Ver 0.6 - 2024-03-26:1434";
}
private static string ToggleUI(string path)
{
GameObject homePanelGo = UIManager.Instance.gameObject.transform.Find("HomePanel").gameObject;
if (homePanelGo == null)
{
return "UI not found.";
}
GameObject go = homePanelGo.transform.Find(path).gameObject;
if (go == null)
{
return "path not found";
}
go.SetActive(!go.activeSelf);
return $"UI {go} toggled to {go.activeSelf}.";
}
private static string ToggleMisc(int idx)
{
GameObject go = GetGOFromPath("Env_101(Clone)/Misc");
int childCount = go.transform.childCount;
if (idx >= childCount)
return $"index {idx} exceeds children count{childCount}";
var child = go.transform.GetChild(idx).gameObject;
if (child == null)
return $"child {idx} not found";
child.SetActive(!child.activeSelf);
return $"{child} toggled to {child.activeSelf}.";
}
private static void OpenAIHelp()
{
AIHelp.AIHelpSupport.Show("E001");
}
private static void OpenReview()
{
var config = GContext.container.Resolve<IConfig>();
tysdk.AppRequestReview.RequestReview(config.Get(GConstant.K_APP_Store_URL, string.Empty));
}
private static string ShowGO(string path)
{
GameObject go = GetGOFromPath(path);
if (go != null)
{
go.SetActive(true);
}
return $"GameObject not found";
}
private static string HideGO(string path)
{
GameObject go = GetGOFromPath(path);
if (go != null)
{
go.SetActive(false);
return $"{go.name} has been hidden";
}
return $"GameObject not found";
}
private static string SetQuality(int level)
{
QualityManager.ChangeQuality(level);
zzwater.URPHelper.RendererFeatureSetActive(false, "FSBlur");
zzwater.URPHelper.RendererFeatureSetActive(false, "FSWave");
return $"quality set to {QualitySettings.names[QualitySettings.GetQualityLevel()]}";
}
private static void SetRTAntiAliasing(int level)
{
var rt = new RenderTexture((int)125, (int)125, 24, RenderTextureFormat.ARGB32);
rt.antiAliasing = level;
}
private static string SetRendererScale(float ratio)
{
if (ratio == 0)
{
return $"Render scale {CurrentRenderPipeline.renderScale}";
}
ratio = Mathf.Clamp(ratio, 0.1f, 2f);
var uprAsset = CurrentRenderPipeline;
if (uprAsset == null) return "No UniversalRenderPipelineAsset";
var preValue = uprAsset.renderScale;
uprAsset.renderScale = ratio;
return $"Render scale {preValue} set to {ratio}";
}
private static string SetAntiAliasing(int count)
{
var uprAsset = CurrentRenderPipeline;
if (uprAsset == null) return "No UniversalRenderPipelineAsset";
var preValue = uprAsset.msaaSampleCount;
uprAsset.msaaSampleCount = count;
return $"Render scale {preValue} set to {count}";
}
private static string SetRenderPipline(string name)
{
var currentPiplineName = GraphicsSettings.currentRenderPipeline.name;
if (name == "?")
{
return $"Pipline set to {currentPiplineName}";
}
else if (name == "-")
{
QualitySettings.renderPipeline = null;
}
else
{
var pipelineAsset = Addressables.LoadAssetAsync<RenderPipelineAsset>(name).WaitForCompletion();
QualitySettings.renderPipeline = pipelineAsset;
}
var newPipelineName = GraphicsSettings.currentRenderPipeline.name;
return $"{currentPiplineName} set to {newPipelineName}";
}
private static string ToggleShadow()
{
var cam = Camera.main;
if (cam != null)
{
var comp = cam.GetComponent<UniversalAdditionalCameraData>();
var preValue = comp.renderShadows;
comp.renderShadows = !preValue;
return $"Shadow {preValue} set to {comp.renderShadows}";
}
return "Camera not found";
}
private static string CpuInfo()
{
var props = typeof(SystemInfo).GetProperties()
.Where(x => x.Name.StartsWith("processor"));
var sb = new System.Text.StringBuilder();
sb.AppendLine();
foreach (var prop in props)
{
sb.AppendLine($"{prop.Name}: {prop.GetValue(null)}");
}
return sb.ToString();
}
private static string GpuInfo()
{
var props = typeof(SystemInfo).GetProperties()
.Where(x => x.Name.StartsWith("graphics"));
var sb = new System.Text.StringBuilder();
sb.AppendLine();
foreach (var prop in props)
{
sb.AppendLine($"{prop.Name}: {prop.GetValue(null)}");
}
return sb.ToString();
}
private static string SupportInfo()
{
var props = typeof(SystemInfo).GetProperties()
.Where(x => x.Name.StartsWith("support"));
var sb = new System.Text.StringBuilder();
sb.AppendLine();
foreach (var prop in props)
{
sb.AppendLine($"{prop.Name}: {prop.GetValue(null)}");
}
return sb.ToString();
}
private static void Fps()
{
game.RootCtx.showFPS = !game.RootCtx.showFPS;
}
private static UniversalRenderPipelineAsset CurrentRenderPipeline
{
get
{
return GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
//return (UniversalRenderPipelineAsset) QualitySettings.renderPipeline;
}
}
private static async void GetSKUs()
{
var iapService = GContext.container.Resolve<game.IIAPService>();
if (iapService == null)
{
UnityEngine.Debug.Log("iapService is null");
;
return;
}
var sb = new System.Text.StringBuilder();
sb.AppendLine();
var skus = await iapService.GetSKUs();
foreach (var sku in skus)
{
sb.AppendLine();
sb.Append($" {sku.price} code {sku.price_currency_code} ");
sb.AppendLine();
}
UnityEngine.Debug.Log(sb.ToString());
}
private static void ActiveAdDebug()
{
MaxSdk.SetVerboseLogging(true);
MaxSdk.ShowCreativeDebugger();
}
private static void ActiveAdMedia()
{
MaxSdk.ShowMediationDebugger();
}
private static GameObject GetGOFromPath(string path)
{
var root = SceneManager.GetActiveScene().GetRootGameObjects();
var splitPath = path.Split('/');
var rootName = splitPath[0];
var rootGo = root.FirstOrDefault(x => x.name == rootName);
if (rootGo == null) return null;
if (splitPath.Length == 1) return rootGo;
var childPath = string.Join("/", splitPath.Skip(1));
return rootGo.transform.Find(childPath)?.gameObject;
}
private static void PrintMail()
{
var mailService = GContext.container.Resolve<IInGameMailService>() as InGameMailService;
mailService.PrintCacheMail();
}
private static void FetchMail()
{
GContext.container.Resolve<IInGameMailService>().FetchMail();
}
private static void RtTest()
{
var rtService = GContext.container.Resolve<IRTService>() as SignalRService;
rtService.Test();
}
private static void Login1D()
{
var userService = GContext.container.Resolve<game.IUserService>() as game.PlayFabUserService;
if (userService == null) return;
var loginTime = userService.LoginTime;
var newLoginTime = loginTime.AddDays(-1.1);
var prop = userService.GetType().GetProperty("LoginTime");
prop.SetValue(userService, newLoginTime);
Debug.Log($"loginTime: {loginTime} newLoginTime: {newLoginTime} prop: {userService.LoginTime}");
}
private static void AccoutInfo()
{
var userService = GContext.container.Resolve<game.IUserService>() as game.PlayFabUserService;
if (userService == null) return;
Debug.Log($"pfid: {userService.UserId} tyid: {userService.CustomId} lastLogin: {userService.LoginTime}");
if (PlayerPrefs.HasKey("KEY_ACCOUNT_INFO"))
{
Debug.Log("Saved account info: " + PlayerPrefs.GetString("KEY_ACCOUNT_INFO"));
}
else
{
Debug.Log("No saved account info");
}
}
private static async void AuthorTest()
{
var svr = GContext.container.Resolve<ICustomServerMgr>();
var result = await svr.GetStringAsync("account/authortest");
Debug.Log($"AuthorTest {result}");
}
private static void AIHelpTest()
{
RedPointManager.Instance.SetRedPointState(RedPointName.AIHelp_Msg, true, 1);
}
private static void OpenWashingActivity()
{
ToggleUI("safearea/RightPanel/layout/btn_washing");
}
private static void WashingGoTo(int stageID, int stepID)
{
GContext.container.Resolve<EventWashingDataManager>().GoToStep(stageID, stepID);
Debug.Log("--- WashingGoTo stageID:" + stageID + ", stepID:" + stepID + ", ok");
}
private static void WashingDataClear()
{
GContext.container.Resolve<EventWashingDataManager>().ResetRefreshData();
Debug.Log("--- WashingDataClear ok");
}
private static void PotionClear()
{
GContext.container.Resolve<EventPotionDataManager>().ClearPotionData();
Debug.Log("--- Potion Clear ok");
}
private static void PotionGoTo(int levelID)
{
GContext.container.Resolve<EventPotionDataManager>().GoToPotionLevel(levelID);
Debug.Log("--- PotionGoTo levelID:" + levelID + ", ok");
}
private static void PinballDataClear()
{
GContext.container.Resolve<EventPinballDataManager>().ClearData();
Debug.Log("--- PinballDataClear ok");
}
private static void PinballFirePellet(float force)
{
FishingPinballAct.Publish(new EventPinballLaunchPelletData()
{
Force = force
});
Debug.Log("--- PinballFirePellet ok, force:" + force);
}
private static void ScratchTicketDataClear()
{
GContext.container.Resolve<EventScratchTicketDataManager>().ClearData();
Debug.Log("--- Scratch Ticket Data Clear ok");
}
private static void ShootingRangeDebug(int n)
{
GContext.Publish(new EventShootingRangeDebug { StageIdx = n });
Debug.Log($"Switch to {n}.");
}
private static void EventPartnerDebugActivate()
{
// var d = GContext.container.Resolve<EventPartnerData>();
// if (d is null)
// {
// Debug.Log( $"<color=#2d7cee>[EventPartner] No data found, cannot activate.</color>");
// return;
// }
// _ = d.LoadDataDebug();
Debug.Log($"<color=#2d7cee>[EventPartner] This function is obsoleted for now.</color>");
}
private static void ToggleFSWave()
{
var feature = zzwater.URPHelper.FindAndCacheRendererFeature("FSWave");
if (feature == null)
Debug.LogError($"Feature FSWave not found");
else
feature.SetActive(!feature.isActive);
}
private static void SetInfiniteBuildLvl(int level)
{
var s = GContext.container.Resolve<PlayerData>().InfiniteBuildingData;
if (s == null)
{
Debug.LogError($"No ib data found.");
return;
}
var data = new InfiniteBuildingData();
data.Deserialize(s);
var delta = level - data.Lvl;
data.Lvl = level;
for (int i = 0; i < data.Record.Count; i++)
{
var r = data.Record[i];
r.Pos += Vector2.up * delta;
data.Record[i] = r;
}
data.UploadData();
Debug.Log($"Done.");
}
private static void ToggleFSBlur()
{
var feature = zzwater.URPHelper.FindAndCacheRendererFeature("FSBlur");
if (feature == null)
Debug.LogError($"Feature FSWave not found");
else
feature.SetActive(!feature.isActive);
}
private static void ShowTestBingoPanel()
{
GContext.container.Register<EventBingoModel>().AsSingleton();
GContext.container.Resolve<EventBingoModel>().InitTest();
GContext.Publish(new UnloadActToNextAct { actId = "EventBingoAct", TransitionPanel = UITypes.CloudTransitionPanel });
}
private static void TestBingoSeedPickingRng()
{
var dataList = GContext.container.Resolve<cfg.Tables>().TbEventBingoMain.DataList;
var tc = new EventBingoTableContext(40701);
int[] stat = { 0, 0, 0, 0 };
int seed, statCount = 10000;
var sb = new System.Text.StringBuilder();
for (int i = 0; i < statCount; i++)
{
seed = tc.PickSeed(roundCount: 10086);
for (int j = 0; j < 4; j++)
{
if (dataList[j].SeedID.Contains(seed))
{
stat[j]++;
break;
}
}
sb.AppendLine($"{seed}, ");
}
Debug.Log($"[EventBingo] Test Result:\n1Bingo:{stat[0] / (float)statCount * 100}%,\n2Bingo: {stat[1] / (float)statCount * 100}%,\n3Bingo: {stat[2] / (float)statCount * 100}%,\n4Bingo: {stat[3] / (float)statCount * 100}%");
Debug.Log("[EventBingo] Seeds: \n" + sb.ToString());
}
private static void TestBingoInstantBingo()
{
var model = GContext.container.Resolve<EventBingoModel>();
if (model == null)
{
Debug.Log("[EventBingo] Bingo model not found!");
return;
}
model.ActivateInstantBingo();
Debug.Log("[EventBingo] Instant Bingo activated.");
}
private static void TestRewardStashService(string cmd)
{
const string reset = "reset", upload = "upload", load = "load", flush = "flush", add = "add";
var service = GContext.container.Resolve<IDeferredRewardStashService>();
switch (cmd)
{
case reset:
service.Reset();
Debug.Log("Reset Done.");
break;
case upload:
service.UploadData();
Debug.Log("Upload Done.");
break;
case load:
service.LoadData();
Debug.Log("Load Done.");
break;
case flush:
service.Flush();
Debug.Log("Flush Done.");
break;
case add:
GContext.Publish(new DeferredRewardStashService.EventStashItem
{
Item = new ItemData(1001, 100)
});
Debug.Log("Add Done.");
break;
default:
Debug.Log("Invalid command. Available commands:\n" +
"- reset: Clear all stash data\n" +
"- add: Add 1001 * 100\n" +
"- upload: Upload stash data to playfab\n" +
"- load: Load stash data from playfab\n" +
"- flush: Process and clear all pending rewards");
break;
}
}
static void ClearGuide()
{
GContext.container.Resolve<GuideDataCenter>().GMClearGuide();
UIManager.Instance.DestroyUI(UITypes.GuidancePanel);
}
}