123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text.RegularExpressions;
- using UnityEngine;
- namespace CrossgateToolkit
- {
-
- public class GraphicInfoData
- {
-
-
- public uint Index;
-
- public uint Addr;
-
- public uint Length;
-
- public int OffsetX;
-
- public int OffsetY;
-
- public uint Width;
-
- public uint Height;
-
- public int East;
-
- public int South;
-
- public bool Blocked;
-
- public bool AsGround;
-
- public byte[] Unknow;
-
- public uint Serial;
-
-
-
- public BinaryReader GraphicReader;
-
- public int[] UnpackedPaletIndex;
- }
- public class GraphicInfo:MonoBehaviour
- {
-
- private static readonly Dictionary<uint,GraphicInfoData> _cache = new Dictionary<uint, GraphicInfoData>();
-
-
- private static readonly Dictionary<string,Dictionary<uint,GraphicInfoData>> _indexCache = new Dictionary<string, Dictionary<uint, GraphicInfoData>>();
- public static void Init(string Version,FileInfo graphicInfoFile,FileInfo graphicFile)
- {
- if(!_indexCache.ContainsKey(Version)) _indexCache.Add(Version,new Dictionary<uint, GraphicInfoData>());
-
- FileStream fileStream = graphicInfoFile.OpenRead();
- BinaryReader fileReader = new BinaryReader(fileStream);
-
- FileStream graphicFileStream = graphicFile.OpenRead();
- BinaryReader graphicFileReader = new BinaryReader(graphicFileStream);
-
-
-
- long DataLength = fileStream.Length/40;
- for (int i = 0; i < DataLength; i++)
- {
- GraphicInfoData graphicInfoData = new GraphicInfoData();
- graphicInfoData.Index = BitConverter.ToUInt32(fileReader.ReadBytes(4),0);
- graphicInfoData.Addr = BitConverter.ToUInt32(fileReader.ReadBytes(4),0);
- graphicInfoData.Length = BitConverter.ToUInt32(fileReader.ReadBytes(4),0);
- graphicInfoData.OffsetX = BitConverter.ToInt32(fileReader.ReadBytes(4),0);
- graphicInfoData.OffsetY = BitConverter.ToInt32(fileReader.ReadBytes(4),0);
- graphicInfoData.Width = BitConverter.ToUInt32(fileReader.ReadBytes(4),0);
- graphicInfoData.Height = BitConverter.ToUInt32(fileReader.ReadBytes(4),0);
- graphicInfoData.East = fileReader.ReadByte();
- graphicInfoData.South = fileReader.ReadByte();
- graphicInfoData.Blocked = fileReader.ReadByte() == 0;
- graphicInfoData.AsGround = fileReader.ReadByte() == 1;
- graphicInfoData.Unknow = fileReader.ReadBytes(4);
- graphicInfoData.Serial = BitConverter.ToUInt32(fileReader.ReadBytes(4),0);
- graphicInfoData.GraphicReader = graphicFileReader;
-
- _indexCache[Version][graphicInfoData.Index] = graphicInfoData;
-
-
- if (graphicInfoData.Serial != 0) _cache[graphicInfoData.Serial] = graphicInfoData;
-
-
-
-
-
-
-
-
-
-
- }
- Debug.Log("[CGTool] 加载GraphicInfo - 文件: " + graphicInfoFile.Name + " 贴图总量: " + DataLength);
- }
-
-
- public static GraphicInfoData GetGraphicInfoData(uint Serial)
- {
- _cache.TryGetValue(Serial, out var graphicInfoData);
- return graphicInfoData;
- }
-
- public static GraphicInfoData GetGraphicInfoDataByIndex(string Version,uint Index)
- {
- _indexCache.TryGetValue(Version, out var indexDict);
- if(indexDict == null) throw new Exception("找不到对应版本的GraphicInfo数据");
- indexDict.TryGetValue(Index, out var graphicInfoData);
- return graphicInfoData;
- }
- }
- }
|