log
This commit is contained in:
+38
-29734
File diff suppressed because one or more lines are too long
@@ -70,7 +70,7 @@ namespace PerfectWorld.Scripts.Task
|
||||
pOffs = AAssit.ReadArrayFromBinary<uint>(fs, (int)tph.item_count, ref readBytes);
|
||||
|
||||
|
||||
for (int i = 0; i < 3; i++) //TODO: tph.item_count
|
||||
for (int i = 0; i < 1; i++) //TODO: tph.item_count
|
||||
{
|
||||
fs.Seek(pOffs[i], SeekOrigin.Begin);
|
||||
|
||||
|
||||
+563
-546
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,8 @@
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using BrewMonster;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -28,6 +30,73 @@ namespace PerfectWorld.Scripts.Task
|
||||
var size = Marshal.SizeOf(typeof(ATaskTemplFixedData));
|
||||
BMLogger.Log("Size of ATaskTemplFixedData: " + size);
|
||||
}
|
||||
[ContextMenu("🧾 Log Struct Field Sizes (ATaskTemplFixedData)")]
|
||||
private void LogStructFieldSizes()
|
||||
{
|
||||
Type structType = typeof(ATaskTemplFixedData);
|
||||
FieldInfo[] fields = structType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
Debug.Log($"===== Struct: {structType.Name} =====");
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
string name = field.Name;
|
||||
Type fieldType = field.FieldType;
|
||||
|
||||
int sizeInBytes = -1;
|
||||
string note = "";
|
||||
|
||||
// 🟢 1. Nếu field có [MarshalAs], lấy SizeConst
|
||||
var marshalAttr = field.GetCustomAttribute<MarshalAsAttribute>();
|
||||
if (marshalAttr != null && marshalAttr.SizeConst > 0)
|
||||
{
|
||||
int elemSize = GetElementSize(fieldType);
|
||||
sizeInBytes = elemSize * marshalAttr.SizeConst;
|
||||
note = $"(ByValArray × {marshalAttr.SizeConst})";
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
sizeInBytes = Marshal.SizeOf(fieldType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
note = "(reference type / variable size)";
|
||||
}
|
||||
}
|
||||
|
||||
string sizeText = sizeInBytes >= 0 ? $"{sizeInBytes} bytes" : "unknown size";
|
||||
Debug.Log($"{name,-40} | {fieldType.Name,-25} | {sizeText} {note}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int total = Marshal.SizeOf(structType);
|
||||
Debug.Log($"===== Total Struct Size: {total} bytes =====");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log($"⚠️ Struct {structType.Name} contains non-blittable fields; total size unknown.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tính kích thước phần tử cơ bản của mảng blittable
|
||||
/// </summary>
|
||||
private int GetElementSize(Type type)
|
||||
{
|
||||
if (type.IsArray)
|
||||
{
|
||||
Type elemType = type.GetElementType();
|
||||
if (elemType != null)
|
||||
{
|
||||
try { return Marshal.SizeOf(elemType); }
|
||||
catch { return 1; } // fallback
|
||||
}
|
||||
}
|
||||
return Marshal.SizeOf(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user