Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using HSGameEngine.GameEngine.Common;
- using HSGameEngine.GameEngine.Logic;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using System.Xml;
- using System.Xml.Linq;
- using UnityEngine;
- public class VOBinOperator
- {
- private const bool USING_ANSI3 = false;
- private const char packc = '\u0019';
- private static Dictionary<Type, VOBinOperator> opDic = new Dictionary<Type, VOBinOperator>();
- private VOBinOperator op;
- private byte[] buffer;
- private static GoodVO preGoodVO = null;
- private static GoodVO curGoodVO = null;
- private static MonsterVO preMonsterVO = null;
- private static MonsterVO curMonsterVO = null;
- private static NPCInfoVO preNPCInfoVO = null;
- private static NPCInfoVO curNPCInfoVO = null;
- private static TaskVO preTaskVO = null;
- private static TaskVO curTaskVO = null;
- private static TrdGoodVOPairs preGoodVOPairs;
- private static TrdGoodVOPairs curGoodVOPairs;
- protected static int MinZhangJieID
- {
- get;
- private set;
- }
- protected static int MaxZhangJieID
- {
- get;
- private set;
- }
- public static VOBinOperator Instance(Type type)
- {
- if (VOBinOperator.opDic.ContainsKey(type))
- {
- return VOBinOperator.opDic[type];
- }
- VOBinOperator vOBinOperator = new VOBinOperator();
- VOBinOperator.opDic.Add(type, vOBinOperator);
- vOBinOperator.op = vOBinOperator;
- return vOBinOperator;
- }
- public void SetBuffer(byte[] blst)
- {
- this.buffer = blst;
- }
- public void ClearBuffer()
- {
- this.buffer = null;
- }
- public static List<byte> GoodsVOToBinLst(object vo)
- {
- if (vo.GetType() == typeof(GoodVO))
- {
- VOBinOperator.preGoodVO = VOBinOperator.curGoodVO;
- VOBinOperator.curGoodVO = (vo as GoodVO);
- return (vo as GoodVO).ToByteLst(VOBinOperator.preGoodVO, VOBinOperator.curGoodVO);
- }
- if (vo.GetType() == typeof(MonsterVO))
- {
- VOBinOperator.preMonsterVO = VOBinOperator.curMonsterVO;
- VOBinOperator.curMonsterVO = (vo as MonsterVO);
- return (vo as MonsterVO).ToByteLst(VOBinOperator.preMonsterVO, VOBinOperator.curMonsterVO);
- }
- if (vo.GetType() == typeof(NPCInfoVO))
- {
- VOBinOperator.preNPCInfoVO = VOBinOperator.curNPCInfoVO;
- VOBinOperator.curNPCInfoVO = (vo as NPCInfoVO);
- return (vo as NPCInfoVO).ToByteLst(VOBinOperator.preNPCInfoVO, VOBinOperator.curNPCInfoVO);
- }
- if (vo.GetType() == typeof(TaskVO))
- {
- VOBinOperator.preTaskVO = VOBinOperator.curTaskVO;
- VOBinOperator.curTaskVO = (vo as TaskVO);
- return (vo as TaskVO).ToByteLst(VOBinOperator.preTaskVO, VOBinOperator.curTaskVO);
- }
- return null;
- }
- public static void Clear()
- {
- VOBinOperator.preGoodVO = null;
- VOBinOperator.curGoodVO = null;
- VOBinOperator.preMonsterVO = null;
- VOBinOperator.curMonsterVO = null;
- VOBinOperator.preNPCInfoVO = null;
- VOBinOperator.curNPCInfoVO = null;
- VOBinOperator.preTaskVO = null;
- VOBinOperator.curTaskVO = null;
- }
- public static object RedefineType(object obj)
- {
- return obj;
- }
- public static void VOMemberToBinLst(List<byte> blst, int nMemberIndex, object preValue, object curValue)
- {
- if (curValue.GetType().Equals(typeof(int)))
- {
- bool isSameWithPre = preValue != null && (int)preValue == (int)curValue;
- VOBinOperator.VOMemberToBinLst(blst, nMemberIndex, true, isSameWithPre, (int)curValue, string.Empty);
- }
- else if (curValue.GetType().Equals(typeof(string)))
- {
- bool isSameWithPre = preValue != null && (string)preValue == (string)curValue;
- VOBinOperator.VOMemberToBinLst(blst, nMemberIndex, false, isSameWithPre, 0, (string)curValue);
- }
- else
- {
- bool isSameWithPre = preValue != null && preValue.ToString() == curValue.ToString();
- VOBinOperator.VOMemberToBinLst(blst, nMemberIndex, false, isSameWithPre, 0, curValue.ToString());
- }
- }
- public static void VOMemberToBinLst(List<byte> blst, int nMemberIndex, bool isInt, bool isSameWithPre = false, int nValue = 0, string sValue = "")
- {
- if (isSameWithPre)
- {
- blst.Add(240);
- blst.Add((byte)nMemberIndex);
- return;
- }
- if (isInt)
- {
- if (nValue == -1)
- {
- blst.Add(255);
- blst.Add((byte)nMemberIndex);
- }
- else if (nValue == 0)
- {
- blst.Add(0);
- blst.Add((byte)nMemberIndex);
- }
- else
- {
- blst.Add(1);
- blst.Add((byte)nMemberIndex);
- byte item = (byte)(((long)nValue & (long)((ulong)-16777216)) >> 24);
- byte item2 = (byte)((nValue & 16711680) >> 16);
- byte item3 = (byte)((nValue & 65280) >> 8);
- byte item4 = (byte)(nValue & 255);
- blst.Add(item);
- blst.Add(item2);
- blst.Add(item3);
- blst.Add(item4);
- }
- }
- else if (string.IsNullOrEmpty(sValue))
- {
- blst.Add(16);
- blst.Add((byte)nMemberIndex);
- }
- else
- {
- blst.Add(17);
- blst.Add((byte)nMemberIndex);
- byte[] bytes = Text.Encoding.UTF8.GetBytes(sValue);
- byte item5 = (byte)((bytes.Length & 16711680) >> 16);
- byte item6 = (byte)((bytes.Length & 65280) >> 8);
- byte item7 = (byte)(bytes.Length & 255);
- blst.Add(item5);
- blst.Add(item6);
- blst.Add(item7);
- for (int i = 0; i < bytes.Length; i++)
- {
- blst.Add(bytes[i]);
- }
- }
- }
- private int _GetBufferInt(int i)
- {
- int result = 0;
- if (this.buffer[i] == 255)
- {
- result = -1;
- }
- else if (this.buffer[i] == 0)
- {
- result = 0;
- }
- else if (this.buffer[i] == 1)
- {
- result = ((int)this.buffer[i + 2] << 24 | (int)this.buffer[i + 3] << 16 | (int)this.buffer[i + 4] << 8 | (int)this.buffer[i + 5]);
- }
- return result;
- }
- private string _GetBufferStr(int i)
- {
- string result = string.Empty;
- if (this.buffer[i] != 16)
- {
- if (this.buffer[i] == 17)
- {
- int num = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
- byte[] array = new byte[num];
- Array.ConstrainedCopy(this.buffer, i + 5, array, 0, num);
- result = Text.Encoding.UTF8.GetString(array);
- }
- }
- return result;
- }
- private byte[] _GetBufferStrBytes(int i)
- {
- if (this.buffer[i] == 16)
- {
- return null;
- }
- if (this.buffer[i] == 17)
- {
- int num = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
- byte[] array = new byte[num];
- Array.ConstrainedCopy(this.buffer, i + 5, array, 0, num);
- return array;
- }
- return null;
- }
- private void SetMemberIntValueByTrd(int bufIndex, bool isInt = true, bool isSame = false)
- {
- byte b = this.buffer[bufIndex + 1];
- if (isSame)
- {
- VOBinOperator.curGoodVOPairs.PairValueLst[(int)b] = VOBinOperator.preGoodVOPairs.PairValueLst[(int)b];
- return;
- }
- if (isInt)
- {
- VOBinOperator.curGoodVOPairs.PairValueLst[(int)b].nValue = this._GetBufferInt(bufIndex);
- }
- else
- {
- VOBinOperator.curGoodVOPairs.PairValueLst[(int)b].sValue = this._GetBufferStr(bufIndex);
- }
- VOBinOperator.preGoodVOPairs.PairValueLst[(int)b] = VOBinOperator.curGoodVOPairs.PairValueLst[(int)b];
- }
- public void ParseBinToVOofGoodVO_ByTrdPairs()
- {
- VOBinOperator.preGoodVO = null;
- VOBinOperator.curGoodVO = null;
- VOBinOperator.preGoodVOPairs = new TrdGoodVOPairs(GoodVO.PropertyIndexDict);
- VOBinOperator.curGoodVOPairs = new TrdGoodVOPairs(GoodVO.PropertyIndexDict);
- Dictionary<int, GoodVO> goodsXmlNodeDict = ConfigGoods.GoodsXmlNodeDict;
- lock (goodsXmlNodeDict)
- {
- VOBinOperator.curGoodVO = new GoodVO();
- int num = 0;
- int num2 = 0;
- int i = 0;
- while (i < this.buffer.Length)
- {
- byte b = this.buffer[i];
- if (this.buffer[i] == 240)
- {
- this.SetMemberIntValueByTrd(i, true, true);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 255)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 0)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 1)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 6;
- num2++;
- }
- else if (this.buffer[i] == 16)
- {
- this.SetMemberIntValueByTrd(i, false, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 17)
- {
- this.SetMemberIntValueByTrd(i, false, false);
- int num3 = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
- i += 5 + num3;
- num2++;
- }
- else if (this.buffer[i] == 32)
- {
- VOBinOperator.curGoodVO.CopyFrom(VOBinOperator.curGoodVOPairs);
- ConfigGoods.GoodsXmlNodeDict[VOBinOperator.curGoodVO.ID] = VOBinOperator.curGoodVO;
- VOBinOperator.preGoodVO = VOBinOperator.curGoodVO;
- VOBinOperator.curGoodVO = new GoodVO();
- i++;
- num++;
- num2 = 0;
- }
- else
- {
- MUDebug.LogError<string>(new string[]
- {
- "ERROR"
- });
- }
- }
- }
- this.ClearBuffer();
- }
- public void ParseBinToVOofMonsterVO_ByTrdPairs()
- {
- VOBinOperator.preMonsterVO = null;
- VOBinOperator.curMonsterVO = null;
- VOBinOperator.preGoodVOPairs = new TrdGoodVOPairs(MonsterVO.PropertyIndexDict);
- VOBinOperator.curGoodVOPairs = new TrdGoodVOPairs(MonsterVO.PropertyIndexDict);
- VOBinOperator.curMonsterVO = new MonsterVO();
- Dictionary<int, MonsterVO> monsterXmlNode = ConfigMonsters.MonsterXmlNode;
- Dictionary<int, MonsterVO> obj = monsterXmlNode;
- lock (obj)
- {
- int num = 0;
- int num2 = 0;
- int i = 0;
- while (i < this.buffer.Length)
- {
- byte b = this.buffer[i];
- if (this.buffer[i] == 240)
- {
- this.SetMemberIntValueByTrd(i, true, true);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 255)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 0)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 1)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 6;
- num2++;
- }
- else if (this.buffer[i] == 16)
- {
- this.SetMemberIntValueByTrd(i, false, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 17)
- {
- this.SetMemberIntValueByTrd(i, false, false);
- int num3 = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
- i += 5 + num3;
- num2++;
- }
- else if (this.buffer[i] == 32)
- {
- VOBinOperator.curMonsterVO.CopyFrom(VOBinOperator.curGoodVOPairs);
- monsterXmlNode[VOBinOperator.curMonsterVO.ID] = VOBinOperator.curMonsterVO;
- VOBinOperator.preMonsterVO = VOBinOperator.curMonsterVO;
- VOBinOperator.curMonsterVO = new MonsterVO();
- i++;
- num++;
- num2 = 0;
- }
- else
- {
- MUDebug.LogError<string>(new string[]
- {
- "ERROR"
- });
- }
- }
- }
- this.ClearBuffer();
- }
- public void ParseBinToVOofNPCInfoVO_ByTrdPairs()
- {
- VOBinOperator.preNPCInfoVO = null;
- VOBinOperator.curNPCInfoVO = null;
- VOBinOperator.preGoodVOPairs = new TrdGoodVOPairs(NPCInfoVO.PropertyIndexDict);
- VOBinOperator.curGoodVOPairs = new TrdGoodVOPairs(NPCInfoVO.PropertyIndexDict);
- VOBinOperator.curNPCInfoVO = new NPCInfoVO();
- Dictionary<int, NPCInfoVO> nPCVODict = ConfigNPCs.NPCVODict;
- Dictionary<int, NPCInfoVO> obj = nPCVODict;
- lock (obj)
- {
- int num = 0;
- int num2 = 0;
- int i = 0;
- while (i < this.buffer.Length)
- {
- byte b = this.buffer[i];
- if (this.buffer[i] == 240)
- {
- this.SetMemberIntValueByTrd(i, true, true);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 255)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 0)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 1)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 6;
- num2++;
- }
- else if (this.buffer[i] == 16)
- {
- this.SetMemberIntValueByTrd(i, false, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 17)
- {
- this.SetMemberIntValueByTrd(i, false, false);
- int num3 = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
- i += 5 + num3;
- num2++;
- }
- else if (this.buffer[i] == 32)
- {
- VOBinOperator.curNPCInfoVO.CopyFrom(VOBinOperator.curGoodVOPairs);
- nPCVODict[VOBinOperator.curNPCInfoVO.ID] = VOBinOperator.curNPCInfoVO;
- VOBinOperator.preNPCInfoVO = VOBinOperator.curNPCInfoVO;
- VOBinOperator.curNPCInfoVO = new NPCInfoVO();
- i++;
- num++;
- num2 = 0;
- }
- else
- {
- MUDebug.LogError<string>(new string[]
- {
- "ERROR"
- });
- }
- }
- }
- this.ClearBuffer();
- }
- public void ParseBinToVOofTaskVO_ByTrdPairs()
- {
- VOBinOperator.preTaskVO = null;
- VOBinOperator.curTaskVO = null;
- VOBinOperator.preGoodVOPairs = new TrdGoodVOPairs(TaskVO.PropertyIndexDict);
- VOBinOperator.curGoodVOPairs = new TrdGoodVOPairs(TaskVO.PropertyIndexDict);
- VOBinOperator.curTaskVO = new TaskVO();
- Dictionary<int, TaskVO> taskXmlNodeDict = ConfigTasks.TaskXmlNodeDict;
- Dictionary<int, TaskVO> obj = taskXmlNodeDict;
- lock (obj)
- {
- int num = 0;
- int num2 = 0;
- int i = 0;
- while (i < this.buffer.Length)
- {
- byte b = this.buffer[i];
- if (this.buffer[i] == 240)
- {
- this.SetMemberIntValueByTrd(i, true, true);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 255)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 0)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 1)
- {
- this.SetMemberIntValueByTrd(i, true, false);
- i += 6;
- num2++;
- }
- else if (this.buffer[i] == 16)
- {
- this.SetMemberIntValueByTrd(i, false, false);
- i += 2;
- num2++;
- }
- else if (this.buffer[i] == 17)
- {
- this.SetMemberIntValueByTrd(i, false, false);
- int num3 = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
- i += 5 + num3;
- num2++;
- }
- else if (this.buffer[i] == 32)
- {
- VOBinOperator.curTaskVO.CopyFrom(VOBinOperator.curGoodVOPairs);
- taskXmlNodeDict[VOBinOperator.curTaskVO.ID] = VOBinOperator.curTaskVO;
- VOBinOperator.preTaskVO = VOBinOperator.curTaskVO;
- VOBinOperator.curTaskVO = new TaskVO();
- i++;
- num++;
- num2 = 0;
- }
- else
- {
- MUDebug.LogError<string>(new string[]
- {
- "ERROR"
- });
- }
- }
- }
- this.ClearBuffer();
- }
- public static void TestXMLDicWithBinDic()
- {
- }
- public static void ParaseGoodXMLToBin()
- {
- VOBinOperator.Clear();
- VOBinOperator.XMLToBin<GoodVO>(new GoodVO(), false);
- VOBinOperator.XMLToBin<MonsterVO>(new MonsterVO(), false);
- VOBinOperator.XMLToBin<NPCInfoVO>(new NPCInfoVO(), false);
- VOBinOperator.XMLToBin<TaskVO>(new TaskVO(), false);
- }
- public static object XMLToBin<VO>(VO vo, bool retDicTrueOrBlst)
- {
- string text = string.Empty;
- string path = string.Empty;
- string newroot = string.Empty;
- if (vo.GetType() == typeof(GoodVO))
- {
- newroot = "Item";
- text = Application.dataPath + "/UIResources/Config/GameRes/Config/Goods.Xml";
- path = Application.dataPath + "/UIResources/Config/GameRes/Config/GoodsBin.txt";
- }
- else if (vo.GetType() == typeof(MonsterVO))
- {
- newroot = "Monster";
- text = Application.dataPath + "/UIResources/Config/GameRes/Config/Monsters.Xml";
- path = Application.dataPath + "/UIResources/Config/GameRes/Config/MonstersBin.txt";
- }
- else if (vo.GetType() == typeof(NPCInfoVO))
- {
- newroot = "NPC";
- text = Application.dataPath + "/UIResources/Config/GameRes/Config/npcs.Xml";
- path = Application.dataPath + "/UIResources/Config/GameRes/Config/npcsBin.txt";
- }
- else if (vo.GetType() == typeof(TaskVO))
- {
- newroot = "Task";
- text = Application.dataPath + "/UIResources/Config/ServerRes/1/IsolateRes/Config/SystemTasks.Xml";
- path = Application.dataPath + "/UIResources/Config/ServerRes/1/IsolateRes/Config/SystemTasksBin.txt";
- }
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.Load(text);
- XElement xElement = VOBinOperator.ToXElement(xmlDocument.DocumentElement);
- if (xElement == null)
- {
- GError.AddErrMsg(string.Format(Global.GetLang("解析: {0} 失败"), text));
- return null;
- }
- List<XElement> xElementList = Global.GetXElementList(xElement, newroot);
- if (xElementList == null || xElementList.Count <= 0)
- {
- GError.AddErrMsg(string.Format(Global.GetLang("解析: {0} 失败"), text));
- return null;
- }
- List<List<byte>> list = new List<List<byte>>();
- if (vo.GetType() == typeof(GoodVO))
- {
- Dictionary<int, GoodVO> dictionary = new Dictionary<int, GoodVO>();
- Dictionary<int, GoodVO> obj = dictionary;
- lock (obj)
- {
- int count = xElementList.Count;
- for (int i = 0; i < count; i++)
- {
- GoodVO goodVO = new GoodVO();
- goodVO.CopyFrom(xElementList[i]);
- dictionary[goodVO.ID] = goodVO;
- if (!retDicTrueOrBlst)
- {
- List<byte> item = VOBinOperator.GoodsVOToBinLst(goodVO);
- list.Add(item);
- }
- }
- }
- if (retDicTrueOrBlst)
- {
- return dictionary as Dictionary<int, VO>;
- }
- }
- else if (vo.GetType() == typeof(MonsterVO))
- {
- Dictionary<int, MonsterVO> dictionary2 = new Dictionary<int, MonsterVO>();
- Dictionary<int, MonsterVO> obj2 = dictionary2;
- lock (obj2)
- {
- int count2 = xElementList.Count;
- for (int j = 0; j < count2; j++)
- {
- MonsterVO monsterVO = new MonsterVO();
- monsterVO.CopyFrom(xElementList[j]);
- dictionary2[monsterVO.ID] = monsterVO;
- if (!retDicTrueOrBlst)
- {
- List<byte> item2 = VOBinOperator.GoodsVOToBinLst(monsterVO);
- list.Add(item2);
- }
- }
- }
- if (retDicTrueOrBlst)
- {
- return dictionary2 as Dictionary<int, VO>;
- }
- }
- else if (vo.GetType() == typeof(NPCInfoVO))
- {
- Dictionary<int, NPCInfoVO> dictionary3 = new Dictionary<int, NPCInfoVO>();
- Dictionary<int, NPCInfoVO> obj3 = dictionary3;
- lock (obj3)
- {
- int count3 = xElementList.Count;
- for (int k = 0; k < count3; k++)
- {
- NPCInfoVO nPCInfoVO = new NPCInfoVO();
- nPCInfoVO.CopyFrom(xElementList[k]);
- dictionary3[nPCInfoVO.ID] = nPCInfoVO;
- if (!retDicTrueOrBlst)
- {
- List<byte> item3 = VOBinOperator.GoodsVOToBinLst(nPCInfoVO);
- list.Add(item3);
- }
- }
- }
- if (retDicTrueOrBlst)
- {
- return dictionary3 as Dictionary<int, VO>;
- }
- }
- else if (vo.GetType() == typeof(TaskVO))
- {
- Dictionary<int, TaskVO> dictionary4 = new Dictionary<int, TaskVO>();
- Dictionary<int, TaskZhangJieVO> dictionary5 = new Dictionary<int, TaskZhangJieVO>();
- VOBinOperator.PreCacheTaskZhangJieXmlNodes(dictionary5);
- int l = 0;
- TaskZhangJieVO taskZhangJieVO = null;
- foreach (KeyValuePair<int, TaskZhangJieVO> current in dictionary5)
- {
- int key = current.Key;
- taskZhangJieVO = current.Value;
- while (l < xElementList.Count)
- {
- TaskVO taskVO = new TaskVO();
- taskVO.CopyFrom(xElementList[l]);
- dictionary4[taskVO.ID] = taskVO;
- if (taskVO.TaskClass == 0)
- {
- if (taskVO.ID > taskZhangJieVO.EndTaskID)
- {
- break;
- }
- taskVO.TaskZhangJieID = key;
- taskVO.TaskIndexOfZhangJie = taskZhangJieVO.TaskCount;
- taskZhangJieVO.TaskCount++;
- }
- l++;
- }
- }
- while (l < xElementList.Count)
- {
- TaskVO taskVO = new TaskVO();
- taskVO.CopyFrom(xElementList[l]);
- if (taskVO.TaskClass == 0 && taskZhangJieVO != null)
- {
- taskVO.TaskIndexOfZhangJie = taskZhangJieVO.TaskCount;
- taskVO.TaskZhangJieID = taskZhangJieVO.ID;
- }
- dictionary4[taskVO.ID] = taskVO;
- l++;
- }
- if (retDicTrueOrBlst)
- {
- return dictionary4 as Dictionary<int, VO>;
- }
- foreach (TaskVO current2 in dictionary4.Values)
- {
- List<byte> item4 = VOBinOperator.GoodsVOToBinLst(current2);
- list.Add(item4);
- }
- }
- if (IO.File.Exists(text))
- {
- }
- if (IO.File.Exists(path))
- {
- IO.File.Delete(path);
- }
- IO.FileStream fileStream = new IO.FileStream(path, IO.FileMode.Create);
- for (int m = 0; m < list.Count; m++)
- {
- List<byte> list2 = list[m];
- foreach (byte current3 in list2)
- {
- fileStream.WriteByte(current3);
- }
- }
- fileStream.Close();
- return null;
- }
- private static void PreCacheTaskZhangJieXmlNodes(Dictionary<int, TaskZhangJieVO> TaskZhangJieXmlNodeDict)
- {
- TaskZhangJieXmlNodeDict.Clear();
- string text = Application.dataPath + "/UIResources/Config/ServerRes/1/IsolateRes/Config/TaskZhangJie.Xml";
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.Load(text);
- XElement xElement = VOBinOperator.ToXElement(xmlDocument.DocumentElement);
- if (xElement == null)
- {
- GError.AddErrMsg(string.Format(Global.GetLang("解析: {0} 失败"), text));
- return;
- }
- List<XElement> xElementList = Global.GetXElementList(xElement, "ZhangJie");
- if (xElementList == null || xElementList.Count <= 0)
- {
- GError.AddErrMsg(string.Format(Global.GetLang("解析: {0} 失败"), text));
- return;
- }
- for (int i = 0; i < xElementList.Count; i++)
- {
- TaskZhangJieVO taskZhangJieVO = new TaskZhangJieVO();
- taskZhangJieVO.CopyFrom(xElementList[i]);
- TaskZhangJieXmlNodeDict[taskZhangJieVO.ID] = taskZhangJieVO;
- if (VOBinOperator.MinZhangJieID == 0)
- {
- VOBinOperator.MinZhangJieID = taskZhangJieVO.ID;
- }
- if (VOBinOperator.MaxZhangJieID < taskZhangJieVO.ID)
- {
- VOBinOperator.MaxZhangJieID = taskZhangJieVO.ID;
- }
- }
- }
- private static XmlElement ToXmlElement(XElement xElement)
- {
- if (xElement == null)
- {
- return null;
- }
- XmlElement result = null;
- XmlReader xmlReader = null;
- try
- {
- xmlReader = xElement.CreateReader();
- XmlDocument xmlDocument = new XmlDocument();
- result = (xmlDocument.ReadNode(xElement.CreateReader()) as XmlElement);
- }
- catch
- {
- }
- finally
- {
- if (xmlReader != null)
- {
- xmlReader.Close();
- }
- }
- return result;
- }
- private static XElement ToXElement(XmlElement xmlElement)
- {
- if (xmlElement == null)
- {
- return null;
- }
- XElement result = null;
- try
- {
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.AppendChild(xmlDocument.ImportNode(xmlElement, true));
- result = XElement.Parse(xmlDocument.InnerXml);
- }
- catch
- {
- }
- return result;
- }
- private static string _PackArrayString(string[] strArr)
- {
- if (strArr == null || strArr.Length <= 0)
- {
- return string.Empty;
- }
- char c = '\u0019';
- string text = ((char)strArr.Length).ToString() + c.ToString();
- for (int i = 0; i < strArr.Length; i++)
- {
- if (!ConvertExt.SafeConvertToDouble(strArr[i]).Equals(0.0))
- {
- string text2 = text;
- text = string.Concat(new string[]
- {
- text2,
- ((char)(i + 26)).ToString(),
- c.ToString(),
- strArr[i],
- c.ToString()
- });
- }
- }
- text = text.Substring(0, text.Length - 1);
- return Text.Encoding.UTF8.GetString(Text.Encoding.UTF8.GetBytes(text));
- }
- public static string PackArray<T>(T[] Arr)
- {
- string[] array = new string[Arr.Length];
- for (int i = 0; i < Arr.Length; i++)
- {
- array[i] = Arr[i].ToString();
- }
- return VOBinOperator._PackArrayString(array);
- }
- public static string[] UnPackArrayString(string str)
- {
- if (string.IsNullOrEmpty(str))
- {
- MUDebug.LogError<string>(new string[]
- {
- "UnPackArrayDouble Error! Owesome Error!"
- });
- return new string[0];
- }
- char c = '\u0019';
- string[] array = str.Split(new char[]
- {
- c
- });
- if (array.Length > 1)
- {
- int num = (int)array[0].charAt(0);
- string[] array2 = new string[num];
- for (int i = 2; i < array.Length; i += 2)
- {
- int num2 = (int)(array[i - 1].charAt(0) - '\u001a');
- array2[num2] = array[i];
- }
- return array2;
- }
- if (array.Length == 1)
- {
- int num3 = (int)array[0].charAt(0);
- return new string[num3];
- }
- MUDebug.LogError<string>(new string[]
- {
- "UnPackArrayDouble Error! Owesome Error!"
- });
- return new string[0];
- }
- public static double[] UnPackArrayDouble(string str)
- {
- if (string.IsNullOrEmpty(str))
- {
- MUDebug.LogError<string>(new string[]
- {
- "UnPackArrayDouble Error! Owesome Error!"
- });
- return new double[0];
- }
- char c = '\u0019';
- string[] array = str.Split(new char[]
- {
- c
- });
- if (array.Length > 1)
- {
- int num = (int)array[0].charAt(0);
- double[] array2 = new double[num];
- for (int i = 2; i < array.Length; i += 2)
- {
- int num2 = (int)(array[i - 1].charAt(0) - '\u001a');
- array2[num2] = ConvertExt.SafeConvertToDouble(array[i]);
- }
- return array2;
- }
- if (array.Length == 1)
- {
- int num3 = (int)array[0].charAt(0);
- return new double[num3];
- }
- MUDebug.LogError<string>(new string[]
- {
- "UnPackArrayDouble Error! Owesome Error!"
- });
- return new double[0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment