Files
test/Assets/PerfectWorld/Scripts/Debug/TestByteNumber.cs
2026-03-12 13:50:41 +07:00

94 lines
3.9 KiB
C#

using System;
using System.Runtime.InteropServices;
using BrewMonster.UI;
using EditorAttributes;
// using NaughtyAttributes;
using UnityEngine;
namespace BrewMonster
{
public class TestByteNumber : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
[ContextMenu(" Size of USER_LAYOUT")]
public void SizeOfUserLayer()
{
var sizeClass = Marshal.SizeOf(typeof(USER_LAYOUT));
var sizeFlat = Marshal.SizeOf<USER_LAYOUT_Flat>();
BMLogger.Log($" USER_LAYOUT (class): {sizeClass} bytes, USER_LAYOUT_Flat (struct): {sizeFlat} bytes, expected: {EC_GameUIMan_Constants.USER_LAYOUT_SIZE}");
}
[ContextMenu("Test")]
public void Test()
{
var origin = Marshal.SizeOf<EC_COMPUTER_AIDED_SETTING>();
var diff = Marshal.SizeOf<EC_GAME_SETTING>() - Marshal.SizeOf<EC_GAME_SETTING_TEST>();
BMLogger.Log($" Origin : {origin } - diff = {diff}"); // 255
}
[ContextMenu(" TestCompress")]
public void TestCompress()
{
int value = 123456;
byte[] src = BitConverter.GetBytes(value);
int dstLen = 10000;
byte[] dst = new byte[dstLen];
int res = AFilePackage.Compress( src, 0, src.Length, dst, 0, ref dstLen);
BMLogger.Log($" Res : {res} - srcLen = {src.Length} - dstLen = {dstLen} - compressed data: {BitConverter.ToString(dst, 0, dstLen)}");
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct EC_GAME_SETTING_TEST
{
[MarshalAs(UnmanagedType.U1)] public bool bNoTeamRequest;
[MarshalAs(UnmanagedType.U1)] public bool bNoTradeRequest;
[MarshalAs(UnmanagedType.U1)] public bool bTurnaround;
[MarshalAs(UnmanagedType.U1)] public bool bReverseWheel;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = EC_ConfigConstants.EC_USERCHANNEL_NUM * 15,
ArraySubType = UnmanagedType.I1)] // GP_CHAT_MAX = 15; I1 = 1 byte per bool to match C++ bool[6][15]
public byte[] bChannel;
[MarshalAs(UnmanagedType.U1)]
public bool bAutoReply;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = EC_ConfigConstants.EC_AUTOREPLY_LEN + 1)]
public string szAutoReply;
[MarshalAs(UnmanagedType.U1)] public float fCamTurnSpeed;
public float fCamZoomSpeed;
public byte nFontSize;
[MarshalAs(UnmanagedType.U1)] public bool bAtk_Player;
[MarshalAs(UnmanagedType.U1)] public bool bAtk_NoMafia;
[MarshalAs(UnmanagedType.U1)] public bool bAtk_NoWhite;
[MarshalAs(UnmanagedType.U1)] public bool bFontBold;
[MarshalAs(UnmanagedType.U1)] public bool bBls_NoRed;
[MarshalAs(UnmanagedType.U1)] public bool bBls_NoMafia;
[MarshalAs(UnmanagedType.U1)] public bool bBls_Self;
[MarshalAs(UnmanagedType.U1)] public bool bBlsRefuse_Neutral;
[MarshalAs(UnmanagedType.U1)] public bool bHideAutoGuide;
[MarshalAs(UnmanagedType.U1)] public bool bAtk_NoAlliance;
[MarshalAs(UnmanagedType.U1)] public bool bBls_NoAlliance;
[MarshalAs(UnmanagedType.U1)] public bool bBlsRefuse_NonTeammate;
[MarshalAs(UnmanagedType.U1)] public bool bAtk_NoForce;
[MarshalAs(UnmanagedType.U1)] public bool bBls_NoForce;
[MarshalAs(UnmanagedType.U1)] public bool bLockQuickBar;
[MarshalAs(UnmanagedType.U1)] public bool bPetAutoSkill;
[MarshalAs(UnmanagedType.U1)] public bool bAutoTeamForTask;
[MarshalAs(UnmanagedType.U1)] public bool bDisableAutoWikiHelp;
[MarshalAs(UnmanagedType.U1)] public bool bExclusiveAwardMode;
[MarshalAs(UnmanagedType.U1)] public bool bHideIceThunderBall;
}
}