Guest User

Untitled

a guest
May 3rd, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 24.95 KB | None | 0 0
  1. using HSGameEngine.GameEngine.Common;
  2. using HSGameEngine.GameEngine.Logic;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Text;
  7. using System.Xml;
  8. using System.Xml.Linq;
  9. using UnityEngine;
  10.  
  11. public class VOBinOperator
  12. {
  13.     private const bool USING_ANSI3 = false;
  14.  
  15.     private const char packc = '\u0019';
  16.  
  17.     private static Dictionary<Type, VOBinOperator> opDic = new Dictionary<Type, VOBinOperator>();
  18.  
  19.     private VOBinOperator op;
  20.  
  21.     private byte[] buffer;
  22.  
  23.     private static GoodVO preGoodVO = null;
  24.  
  25.     private static GoodVO curGoodVO = null;
  26.  
  27.     private static MonsterVO preMonsterVO = null;
  28.  
  29.     private static MonsterVO curMonsterVO = null;
  30.  
  31.     private static NPCInfoVO preNPCInfoVO = null;
  32.  
  33.     private static NPCInfoVO curNPCInfoVO = null;
  34.  
  35.     private static TaskVO preTaskVO = null;
  36.  
  37.     private static TaskVO curTaskVO = null;
  38.  
  39.     private static TrdGoodVOPairs preGoodVOPairs;
  40.  
  41.     private static TrdGoodVOPairs curGoodVOPairs;
  42.  
  43.     protected static int MinZhangJieID
  44.     {
  45.         get;
  46.         private set;
  47.     }
  48.  
  49.     protected static int MaxZhangJieID
  50.     {
  51.         get;
  52.         private set;
  53.     }
  54.  
  55.     public static VOBinOperator Instance(Type type)
  56.     {
  57.         if (VOBinOperator.opDic.ContainsKey(type))
  58.         {
  59.             return VOBinOperator.opDic[type];
  60.         }
  61.         VOBinOperator vOBinOperator = new VOBinOperator();
  62.         VOBinOperator.opDic.Add(type, vOBinOperator);
  63.         vOBinOperator.op = vOBinOperator;
  64.         return vOBinOperator;
  65.     }
  66.  
  67.     public void SetBuffer(byte[] blst)
  68.     {
  69.         this.buffer = blst;
  70.     }
  71.  
  72.     public void ClearBuffer()
  73.     {
  74.         this.buffer = null;
  75.     }
  76.  
  77.     public static List<byte> GoodsVOToBinLst(object vo)
  78.     {
  79.         if (vo.GetType() == typeof(GoodVO))
  80.         {
  81.             VOBinOperator.preGoodVO = VOBinOperator.curGoodVO;
  82.             VOBinOperator.curGoodVO = (vo as GoodVO);
  83.             return (vo as GoodVO).ToByteLst(VOBinOperator.preGoodVO, VOBinOperator.curGoodVO);
  84.         }
  85.         if (vo.GetType() == typeof(MonsterVO))
  86.         {
  87.             VOBinOperator.preMonsterVO = VOBinOperator.curMonsterVO;
  88.             VOBinOperator.curMonsterVO = (vo as MonsterVO);
  89.             return (vo as MonsterVO).ToByteLst(VOBinOperator.preMonsterVO, VOBinOperator.curMonsterVO);
  90.         }
  91.         if (vo.GetType() == typeof(NPCInfoVO))
  92.         {
  93.             VOBinOperator.preNPCInfoVO = VOBinOperator.curNPCInfoVO;
  94.             VOBinOperator.curNPCInfoVO = (vo as NPCInfoVO);
  95.             return (vo as NPCInfoVO).ToByteLst(VOBinOperator.preNPCInfoVO, VOBinOperator.curNPCInfoVO);
  96.         }
  97.         if (vo.GetType() == typeof(TaskVO))
  98.         {
  99.             VOBinOperator.preTaskVO = VOBinOperator.curTaskVO;
  100.             VOBinOperator.curTaskVO = (vo as TaskVO);
  101.             return (vo as TaskVO).ToByteLst(VOBinOperator.preTaskVO, VOBinOperator.curTaskVO);
  102.         }
  103.         return null;
  104.     }
  105.  
  106.     public static void Clear()
  107.     {
  108.         VOBinOperator.preGoodVO = null;
  109.         VOBinOperator.curGoodVO = null;
  110.         VOBinOperator.preMonsterVO = null;
  111.         VOBinOperator.curMonsterVO = null;
  112.         VOBinOperator.preNPCInfoVO = null;
  113.         VOBinOperator.curNPCInfoVO = null;
  114.         VOBinOperator.preTaskVO = null;
  115.         VOBinOperator.curTaskVO = null;
  116.     }
  117.  
  118.     public static object RedefineType(object obj)
  119.     {
  120.         return obj;
  121.     }
  122.  
  123.     public static void VOMemberToBinLst(List<byte> blst, int nMemberIndex, object preValue, object curValue)
  124.     {
  125.         if (curValue.GetType().Equals(typeof(int)))
  126.         {
  127.             bool isSameWithPre = preValue != null && (int)preValue == (int)curValue;
  128.             VOBinOperator.VOMemberToBinLst(blst, nMemberIndex, true, isSameWithPre, (int)curValue, string.Empty);
  129.         }
  130.         else if (curValue.GetType().Equals(typeof(string)))
  131.         {
  132.             bool isSameWithPre = preValue != null && (string)preValue == (string)curValue;
  133.             VOBinOperator.VOMemberToBinLst(blst, nMemberIndex, false, isSameWithPre, 0, (string)curValue);
  134.         }
  135.         else
  136.         {
  137.             bool isSameWithPre = preValue != null && preValue.ToString() == curValue.ToString();
  138.             VOBinOperator.VOMemberToBinLst(blst, nMemberIndex, false, isSameWithPre, 0, curValue.ToString());
  139.         }
  140.     }
  141.  
  142.     public static void VOMemberToBinLst(List<byte> blst, int nMemberIndex, bool isInt, bool isSameWithPre = false, int nValue = 0, string sValue = "")
  143.     {
  144.         if (isSameWithPre)
  145.         {
  146.             blst.Add(240);
  147.             blst.Add((byte)nMemberIndex);
  148.             return;
  149.         }
  150.         if (isInt)
  151.         {
  152.             if (nValue == -1)
  153.             {
  154.                 blst.Add(255);
  155.                 blst.Add((byte)nMemberIndex);
  156.             }
  157.             else if (nValue == 0)
  158.             {
  159.                 blst.Add(0);
  160.                 blst.Add((byte)nMemberIndex);
  161.             }
  162.             else
  163.             {
  164.                 blst.Add(1);
  165.                 blst.Add((byte)nMemberIndex);
  166.                 byte item = (byte)(((long)nValue & (long)((ulong)-16777216)) >> 24);
  167.                 byte item2 = (byte)((nValue & 16711680) >> 16);
  168.                 byte item3 = (byte)((nValue & 65280) >> 8);
  169.                 byte item4 = (byte)(nValue & 255);
  170.                 blst.Add(item);
  171.                 blst.Add(item2);
  172.                 blst.Add(item3);
  173.                 blst.Add(item4);
  174.             }
  175.         }
  176.         else if (string.IsNullOrEmpty(sValue))
  177.         {
  178.             blst.Add(16);
  179.             blst.Add((byte)nMemberIndex);
  180.         }
  181.         else
  182.         {
  183.             blst.Add(17);
  184.             blst.Add((byte)nMemberIndex);
  185.             byte[] bytes = Text.Encoding.UTF8.GetBytes(sValue);
  186.             byte item5 = (byte)((bytes.Length & 16711680) >> 16);
  187.             byte item6 = (byte)((bytes.Length & 65280) >> 8);
  188.             byte item7 = (byte)(bytes.Length & 255);
  189.             blst.Add(item5);
  190.             blst.Add(item6);
  191.             blst.Add(item7);
  192.             for (int i = 0; i < bytes.Length; i++)
  193.             {
  194.                 blst.Add(bytes[i]);
  195.             }
  196.         }
  197.     }
  198.  
  199.     private int _GetBufferInt(int i)
  200.     {
  201.         int result = 0;
  202.         if (this.buffer[i] == 255)
  203.         {
  204.             result = -1;
  205.         }
  206.         else if (this.buffer[i] == 0)
  207.         {
  208.             result = 0;
  209.         }
  210.         else if (this.buffer[i] == 1)
  211.         {
  212.             result = ((int)this.buffer[i + 2] << 24 | (int)this.buffer[i + 3] << 16 | (int)this.buffer[i + 4] << 8 | (int)this.buffer[i + 5]);
  213.         }
  214.         return result;
  215.     }
  216.  
  217.     private string _GetBufferStr(int i)
  218.     {
  219.         string result = string.Empty;
  220.         if (this.buffer[i] != 16)
  221.         {
  222.             if (this.buffer[i] == 17)
  223.             {
  224.                 int num = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
  225.                 byte[] array = new byte[num];
  226.                 Array.ConstrainedCopy(this.buffer, i + 5, array, 0, num);
  227.                 result = Text.Encoding.UTF8.GetString(array);
  228.             }
  229.         }
  230.         return result;
  231.     }
  232.  
  233.     private byte[] _GetBufferStrBytes(int i)
  234.     {
  235.         if (this.buffer[i] == 16)
  236.         {
  237.             return null;
  238.         }
  239.         if (this.buffer[i] == 17)
  240.         {
  241.             int num = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
  242.             byte[] array = new byte[num];
  243.             Array.ConstrainedCopy(this.buffer, i + 5, array, 0, num);
  244.             return array;
  245.         }
  246.         return null;
  247.     }
  248.  
  249.     private void SetMemberIntValueByTrd(int bufIndex, bool isInt = true, bool isSame = false)
  250.     {
  251.         byte b = this.buffer[bufIndex + 1];
  252.         if (isSame)
  253.         {
  254.             VOBinOperator.curGoodVOPairs.PairValueLst[(int)b] = VOBinOperator.preGoodVOPairs.PairValueLst[(int)b];
  255.             return;
  256.         }
  257.         if (isInt)
  258.         {
  259.             VOBinOperator.curGoodVOPairs.PairValueLst[(int)b].nValue = this._GetBufferInt(bufIndex);
  260.         }
  261.         else
  262.         {
  263.             VOBinOperator.curGoodVOPairs.PairValueLst[(int)b].sValue = this._GetBufferStr(bufIndex);
  264.         }
  265.         VOBinOperator.preGoodVOPairs.PairValueLst[(int)b] = VOBinOperator.curGoodVOPairs.PairValueLst[(int)b];
  266.     }
  267.  
  268.     public void ParseBinToVOofGoodVO_ByTrdPairs()
  269.     {
  270.         VOBinOperator.preGoodVO = null;
  271.         VOBinOperator.curGoodVO = null;
  272.         VOBinOperator.preGoodVOPairs = new TrdGoodVOPairs(GoodVO.PropertyIndexDict);
  273.         VOBinOperator.curGoodVOPairs = new TrdGoodVOPairs(GoodVO.PropertyIndexDict);
  274.         Dictionary<int, GoodVO> goodsXmlNodeDict = ConfigGoods.GoodsXmlNodeDict;
  275.         lock (goodsXmlNodeDict)
  276.         {
  277.             VOBinOperator.curGoodVO = new GoodVO();
  278.             int num = 0;
  279.             int num2 = 0;
  280.             int i = 0;
  281.             while (i < this.buffer.Length)
  282.             {
  283.                 byte b = this.buffer[i];
  284.                 if (this.buffer[i] == 240)
  285.                 {
  286.                     this.SetMemberIntValueByTrd(i, true, true);
  287.                     i += 2;
  288.                     num2++;
  289.                 }
  290.                 else if (this.buffer[i] == 255)
  291.                 {
  292.                     this.SetMemberIntValueByTrd(i, true, false);
  293.                     i += 2;
  294.                     num2++;
  295.                 }
  296.                 else if (this.buffer[i] == 0)
  297.                 {
  298.                     this.SetMemberIntValueByTrd(i, true, false);
  299.                     i += 2;
  300.                     num2++;
  301.                 }
  302.                 else if (this.buffer[i] == 1)
  303.                 {
  304.                     this.SetMemberIntValueByTrd(i, true, false);
  305.                     i += 6;
  306.                     num2++;
  307.                 }
  308.                 else if (this.buffer[i] == 16)
  309.                 {
  310.                     this.SetMemberIntValueByTrd(i, false, false);
  311.                     i += 2;
  312.                     num2++;
  313.                 }
  314.                 else if (this.buffer[i] == 17)
  315.                 {
  316.                     this.SetMemberIntValueByTrd(i, false, false);
  317.                     int num3 = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
  318.                     i += 5 + num3;
  319.                     num2++;
  320.                 }
  321.                 else if (this.buffer[i] == 32)
  322.                 {
  323.                     VOBinOperator.curGoodVO.CopyFrom(VOBinOperator.curGoodVOPairs);
  324.                     ConfigGoods.GoodsXmlNodeDict[VOBinOperator.curGoodVO.ID] = VOBinOperator.curGoodVO;
  325.                     VOBinOperator.preGoodVO = VOBinOperator.curGoodVO;
  326.                     VOBinOperator.curGoodVO = new GoodVO();
  327.                     i++;
  328.                     num++;
  329.                     num2 = 0;
  330.                 }
  331.                 else
  332.                 {
  333.                     MUDebug.LogError<string>(new string[]
  334.                     {
  335.                         "ERROR"
  336.                     });
  337.                 }
  338.             }
  339.         }
  340.         this.ClearBuffer();
  341.     }
  342.  
  343.     public void ParseBinToVOofMonsterVO_ByTrdPairs()
  344.     {
  345.         VOBinOperator.preMonsterVO = null;
  346.         VOBinOperator.curMonsterVO = null;
  347.         VOBinOperator.preGoodVOPairs = new TrdGoodVOPairs(MonsterVO.PropertyIndexDict);
  348.         VOBinOperator.curGoodVOPairs = new TrdGoodVOPairs(MonsterVO.PropertyIndexDict);
  349.         VOBinOperator.curMonsterVO = new MonsterVO();
  350.         Dictionary<int, MonsterVO> monsterXmlNode = ConfigMonsters.MonsterXmlNode;
  351.         Dictionary<int, MonsterVO> obj = monsterXmlNode;
  352.         lock (obj)
  353.         {
  354.             int num = 0;
  355.             int num2 = 0;
  356.             int i = 0;
  357.             while (i < this.buffer.Length)
  358.             {
  359.                 byte b = this.buffer[i];
  360.                 if (this.buffer[i] == 240)
  361.                 {
  362.                     this.SetMemberIntValueByTrd(i, true, true);
  363.                     i += 2;
  364.                     num2++;
  365.                 }
  366.                 else if (this.buffer[i] == 255)
  367.                 {
  368.                     this.SetMemberIntValueByTrd(i, true, false);
  369.                     i += 2;
  370.                     num2++;
  371.                 }
  372.                 else if (this.buffer[i] == 0)
  373.                 {
  374.                     this.SetMemberIntValueByTrd(i, true, false);
  375.                     i += 2;
  376.                     num2++;
  377.                 }
  378.                 else if (this.buffer[i] == 1)
  379.                 {
  380.                     this.SetMemberIntValueByTrd(i, true, false);
  381.                     i += 6;
  382.                     num2++;
  383.                 }
  384.                 else if (this.buffer[i] == 16)
  385.                 {
  386.                     this.SetMemberIntValueByTrd(i, false, false);
  387.                     i += 2;
  388.                     num2++;
  389.                 }
  390.                 else if (this.buffer[i] == 17)
  391.                 {
  392.                     this.SetMemberIntValueByTrd(i, false, false);
  393.                     int num3 = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
  394.                     i += 5 + num3;
  395.                     num2++;
  396.                 }
  397.                 else if (this.buffer[i] == 32)
  398.                 {
  399.                     VOBinOperator.curMonsterVO.CopyFrom(VOBinOperator.curGoodVOPairs);
  400.                     monsterXmlNode[VOBinOperator.curMonsterVO.ID] = VOBinOperator.curMonsterVO;
  401.                     VOBinOperator.preMonsterVO = VOBinOperator.curMonsterVO;
  402.                     VOBinOperator.curMonsterVO = new MonsterVO();
  403.                     i++;
  404.                     num++;
  405.                     num2 = 0;
  406.                 }
  407.                 else
  408.                 {
  409.                     MUDebug.LogError<string>(new string[]
  410.                     {
  411.                         "ERROR"
  412.                     });
  413.                 }
  414.             }
  415.         }
  416.         this.ClearBuffer();
  417.     }
  418.  
  419.     public void ParseBinToVOofNPCInfoVO_ByTrdPairs()
  420.     {
  421.         VOBinOperator.preNPCInfoVO = null;
  422.         VOBinOperator.curNPCInfoVO = null;
  423.         VOBinOperator.preGoodVOPairs = new TrdGoodVOPairs(NPCInfoVO.PropertyIndexDict);
  424.         VOBinOperator.curGoodVOPairs = new TrdGoodVOPairs(NPCInfoVO.PropertyIndexDict);
  425.         VOBinOperator.curNPCInfoVO = new NPCInfoVO();
  426.         Dictionary<int, NPCInfoVO> nPCVODict = ConfigNPCs.NPCVODict;
  427.         Dictionary<int, NPCInfoVO> obj = nPCVODict;
  428.         lock (obj)
  429.         {
  430.             int num = 0;
  431.             int num2 = 0;
  432.             int i = 0;
  433.             while (i < this.buffer.Length)
  434.             {
  435.                 byte b = this.buffer[i];
  436.                 if (this.buffer[i] == 240)
  437.                 {
  438.                     this.SetMemberIntValueByTrd(i, true, true);
  439.                     i += 2;
  440.                     num2++;
  441.                 }
  442.                 else if (this.buffer[i] == 255)
  443.                 {
  444.                     this.SetMemberIntValueByTrd(i, true, false);
  445.                     i += 2;
  446.                     num2++;
  447.                 }
  448.                 else if (this.buffer[i] == 0)
  449.                 {
  450.                     this.SetMemberIntValueByTrd(i, true, false);
  451.                     i += 2;
  452.                     num2++;
  453.                 }
  454.                 else if (this.buffer[i] == 1)
  455.                 {
  456.                     this.SetMemberIntValueByTrd(i, true, false);
  457.                     i += 6;
  458.                     num2++;
  459.                 }
  460.                 else if (this.buffer[i] == 16)
  461.                 {
  462.                     this.SetMemberIntValueByTrd(i, false, false);
  463.                     i += 2;
  464.                     num2++;
  465.                 }
  466.                 else if (this.buffer[i] == 17)
  467.                 {
  468.                     this.SetMemberIntValueByTrd(i, false, false);
  469.                     int num3 = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
  470.                     i += 5 + num3;
  471.                     num2++;
  472.                 }
  473.                 else if (this.buffer[i] == 32)
  474.                 {
  475.                     VOBinOperator.curNPCInfoVO.CopyFrom(VOBinOperator.curGoodVOPairs);
  476.                     nPCVODict[VOBinOperator.curNPCInfoVO.ID] = VOBinOperator.curNPCInfoVO;
  477.                     VOBinOperator.preNPCInfoVO = VOBinOperator.curNPCInfoVO;
  478.                     VOBinOperator.curNPCInfoVO = new NPCInfoVO();
  479.                     i++;
  480.                     num++;
  481.                     num2 = 0;
  482.                 }
  483.                 else
  484.                 {
  485.                     MUDebug.LogError<string>(new string[]
  486.                     {
  487.                         "ERROR"
  488.                     });
  489.                 }
  490.             }
  491.         }
  492.         this.ClearBuffer();
  493.     }
  494.  
  495.     public void ParseBinToVOofTaskVO_ByTrdPairs()
  496.     {
  497.         VOBinOperator.preTaskVO = null;
  498.         VOBinOperator.curTaskVO = null;
  499.         VOBinOperator.preGoodVOPairs = new TrdGoodVOPairs(TaskVO.PropertyIndexDict);
  500.         VOBinOperator.curGoodVOPairs = new TrdGoodVOPairs(TaskVO.PropertyIndexDict);
  501.         VOBinOperator.curTaskVO = new TaskVO();
  502.         Dictionary<int, TaskVO> taskXmlNodeDict = ConfigTasks.TaskXmlNodeDict;
  503.         Dictionary<int, TaskVO> obj = taskXmlNodeDict;
  504.         lock (obj)
  505.         {
  506.             int num = 0;
  507.             int num2 = 0;
  508.             int i = 0;
  509.             while (i < this.buffer.Length)
  510.             {
  511.                 byte b = this.buffer[i];
  512.                 if (this.buffer[i] == 240)
  513.                 {
  514.                     this.SetMemberIntValueByTrd(i, true, true);
  515.                     i += 2;
  516.                     num2++;
  517.                 }
  518.                 else if (this.buffer[i] == 255)
  519.                 {
  520.                     this.SetMemberIntValueByTrd(i, true, false);
  521.                     i += 2;
  522.                     num2++;
  523.                 }
  524.                 else if (this.buffer[i] == 0)
  525.                 {
  526.                     this.SetMemberIntValueByTrd(i, true, false);
  527.                     i += 2;
  528.                     num2++;
  529.                 }
  530.                 else if (this.buffer[i] == 1)
  531.                 {
  532.                     this.SetMemberIntValueByTrd(i, true, false);
  533.                     i += 6;
  534.                     num2++;
  535.                 }
  536.                 else if (this.buffer[i] == 16)
  537.                 {
  538.                     this.SetMemberIntValueByTrd(i, false, false);
  539.                     i += 2;
  540.                     num2++;
  541.                 }
  542.                 else if (this.buffer[i] == 17)
  543.                 {
  544.                     this.SetMemberIntValueByTrd(i, false, false);
  545.                     int num3 = (int)this.buffer[i + 2] << 16 | (int)this.buffer[i + 3] << 8 | (int)this.buffer[i + 4];
  546.                     i += 5 + num3;
  547.                     num2++;
  548.                 }
  549.                 else if (this.buffer[i] == 32)
  550.                 {
  551.                     VOBinOperator.curTaskVO.CopyFrom(VOBinOperator.curGoodVOPairs);
  552.                     taskXmlNodeDict[VOBinOperator.curTaskVO.ID] = VOBinOperator.curTaskVO;
  553.                     VOBinOperator.preTaskVO = VOBinOperator.curTaskVO;
  554.                     VOBinOperator.curTaskVO = new TaskVO();
  555.                     i++;
  556.                     num++;
  557.                     num2 = 0;
  558.                 }
  559.                 else
  560.                 {
  561.                     MUDebug.LogError<string>(new string[]
  562.                     {
  563.                         "ERROR"
  564.                     });
  565.                 }
  566.             }
  567.         }
  568.         this.ClearBuffer();
  569.     }
  570.  
  571.     public static void TestXMLDicWithBinDic()
  572.     {
  573.     }
  574.  
  575.     public static void ParaseGoodXMLToBin()
  576.     {
  577.         VOBinOperator.Clear();
  578.         VOBinOperator.XMLToBin<GoodVO>(new GoodVO(), false);
  579.         VOBinOperator.XMLToBin<MonsterVO>(new MonsterVO(), false);
  580.         VOBinOperator.XMLToBin<NPCInfoVO>(new NPCInfoVO(), false);
  581.         VOBinOperator.XMLToBin<TaskVO>(new TaskVO(), false);
  582.     }
  583.  
  584.     public static object XMLToBin<VO>(VO vo, bool retDicTrueOrBlst)
  585.     {
  586.         string text = string.Empty;
  587.         string path = string.Empty;
  588.         string newroot = string.Empty;
  589.         if (vo.GetType() == typeof(GoodVO))
  590.         {
  591.             newroot = "Item";
  592.             text = Application.dataPath + "/UIResources/Config/GameRes/Config/Goods.Xml";
  593.             path = Application.dataPath + "/UIResources/Config/GameRes/Config/GoodsBin.txt";
  594.         }
  595.         else if (vo.GetType() == typeof(MonsterVO))
  596.         {
  597.             newroot = "Monster";
  598.             text = Application.dataPath + "/UIResources/Config/GameRes/Config/Monsters.Xml";
  599.             path = Application.dataPath + "/UIResources/Config/GameRes/Config/MonstersBin.txt";
  600.         }
  601.         else if (vo.GetType() == typeof(NPCInfoVO))
  602.         {
  603.             newroot = "NPC";
  604.             text = Application.dataPath + "/UIResources/Config/GameRes/Config/npcs.Xml";
  605.             path = Application.dataPath + "/UIResources/Config/GameRes/Config/npcsBin.txt";
  606.         }
  607.         else if (vo.GetType() == typeof(TaskVO))
  608.         {
  609.             newroot = "Task";
  610.             text = Application.dataPath + "/UIResources/Config/ServerRes/1/IsolateRes/Config/SystemTasks.Xml";
  611.             path = Application.dataPath + "/UIResources/Config/ServerRes/1/IsolateRes/Config/SystemTasksBin.txt";
  612.         }
  613.         XmlDocument xmlDocument = new XmlDocument();
  614.         xmlDocument.Load(text);
  615.         XElement xElement = VOBinOperator.ToXElement(xmlDocument.DocumentElement);
  616.         if (xElement == null)
  617.         {
  618.             GError.AddErrMsg(string.Format(Global.GetLang("解析: {0} 失败"), text));
  619.             return null;
  620.         }
  621.         List<XElement> xElementList = Global.GetXElementList(xElement, newroot);
  622.         if (xElementList == null || xElementList.Count <= 0)
  623.         {
  624.             GError.AddErrMsg(string.Format(Global.GetLang("解析: {0} 失败"), text));
  625.             return null;
  626.         }
  627.         List<List<byte>> list = new List<List<byte>>();
  628.         if (vo.GetType() == typeof(GoodVO))
  629.         {
  630.             Dictionary<int, GoodVO> dictionary = new Dictionary<int, GoodVO>();
  631.             Dictionary<int, GoodVO> obj = dictionary;
  632.             lock (obj)
  633.             {
  634.                 int count = xElementList.Count;
  635.                 for (int i = 0; i < count; i++)
  636.                 {
  637.                     GoodVO goodVO = new GoodVO();
  638.                     goodVO.CopyFrom(xElementList[i]);
  639.                     dictionary[goodVO.ID] = goodVO;
  640.                     if (!retDicTrueOrBlst)
  641.                     {
  642.                         List<byte> item = VOBinOperator.GoodsVOToBinLst(goodVO);
  643.                         list.Add(item);
  644.                     }
  645.                 }
  646.             }
  647.             if (retDicTrueOrBlst)
  648.             {
  649.                 return dictionary as Dictionary<int, VO>;
  650.             }
  651.         }
  652.         else if (vo.GetType() == typeof(MonsterVO))
  653.         {
  654.             Dictionary<int, MonsterVO> dictionary2 = new Dictionary<int, MonsterVO>();
  655.             Dictionary<int, MonsterVO> obj2 = dictionary2;
  656.             lock (obj2)
  657.             {
  658.                 int count2 = xElementList.Count;
  659.                 for (int j = 0; j < count2; j++)
  660.                 {
  661.                     MonsterVO monsterVO = new MonsterVO();
  662.                     monsterVO.CopyFrom(xElementList[j]);
  663.                     dictionary2[monsterVO.ID] = monsterVO;
  664.                     if (!retDicTrueOrBlst)
  665.                     {
  666.                         List<byte> item2 = VOBinOperator.GoodsVOToBinLst(monsterVO);
  667.                         list.Add(item2);
  668.                     }
  669.                 }
  670.             }
  671.             if (retDicTrueOrBlst)
  672.             {
  673.                 return dictionary2 as Dictionary<int, VO>;
  674.             }
  675.         }
  676.         else if (vo.GetType() == typeof(NPCInfoVO))
  677.         {
  678.             Dictionary<int, NPCInfoVO> dictionary3 = new Dictionary<int, NPCInfoVO>();
  679.             Dictionary<int, NPCInfoVO> obj3 = dictionary3;
  680.             lock (obj3)
  681.             {
  682.                 int count3 = xElementList.Count;
  683.                 for (int k = 0; k < count3; k++)
  684.                 {
  685.                     NPCInfoVO nPCInfoVO = new NPCInfoVO();
  686.                     nPCInfoVO.CopyFrom(xElementList[k]);
  687.                     dictionary3[nPCInfoVO.ID] = nPCInfoVO;
  688.                     if (!retDicTrueOrBlst)
  689.                     {
  690.                         List<byte> item3 = VOBinOperator.GoodsVOToBinLst(nPCInfoVO);
  691.                         list.Add(item3);
  692.                     }
  693.                 }
  694.             }
  695.             if (retDicTrueOrBlst)
  696.             {
  697.                 return dictionary3 as Dictionary<int, VO>;
  698.             }
  699.         }
  700.         else if (vo.GetType() == typeof(TaskVO))
  701.         {
  702.             Dictionary<int, TaskVO> dictionary4 = new Dictionary<int, TaskVO>();
  703.             Dictionary<int, TaskZhangJieVO> dictionary5 = new Dictionary<int, TaskZhangJieVO>();
  704.             VOBinOperator.PreCacheTaskZhangJieXmlNodes(dictionary5);
  705.             int l = 0;
  706.             TaskZhangJieVO taskZhangJieVO = null;
  707.             foreach (KeyValuePair<int, TaskZhangJieVO> current in dictionary5)
  708.             {
  709.                 int key = current.Key;
  710.                 taskZhangJieVO = current.Value;
  711.                 while (l < xElementList.Count)
  712.                 {
  713.                     TaskVO taskVO = new TaskVO();
  714.                     taskVO.CopyFrom(xElementList[l]);
  715.                     dictionary4[taskVO.ID] = taskVO;
  716.                     if (taskVO.TaskClass == 0)
  717.                     {
  718.                         if (taskVO.ID > taskZhangJieVO.EndTaskID)
  719.                         {
  720.                             break;
  721.                         }
  722.                         taskVO.TaskZhangJieID = key;
  723.                         taskVO.TaskIndexOfZhangJie = taskZhangJieVO.TaskCount;
  724.                         taskZhangJieVO.TaskCount++;
  725.                     }
  726.                     l++;
  727.                 }
  728.             }
  729.             while (l < xElementList.Count)
  730.             {
  731.                 TaskVO taskVO = new TaskVO();
  732.                 taskVO.CopyFrom(xElementList[l]);
  733.                 if (taskVO.TaskClass == 0 && taskZhangJieVO != null)
  734.                 {
  735.                     taskVO.TaskIndexOfZhangJie = taskZhangJieVO.TaskCount;
  736.                     taskVO.TaskZhangJieID = taskZhangJieVO.ID;
  737.                 }
  738.                 dictionary4[taskVO.ID] = taskVO;
  739.                 l++;
  740.             }
  741.             if (retDicTrueOrBlst)
  742.             {
  743.                 return dictionary4 as Dictionary<int, VO>;
  744.             }
  745.             foreach (TaskVO current2 in dictionary4.Values)
  746.             {
  747.                 List<byte> item4 = VOBinOperator.GoodsVOToBinLst(current2);
  748.                 list.Add(item4);
  749.             }
  750.         }
  751.         if (IO.File.Exists(text))
  752.         {
  753.         }
  754.         if (IO.File.Exists(path))
  755.         {
  756.             IO.File.Delete(path);
  757.         }
  758.         IO.FileStream fileStream = new IO.FileStream(path, IO.FileMode.Create);
  759.         for (int m = 0; m < list.Count; m++)
  760.         {
  761.             List<byte> list2 = list[m];
  762.             foreach (byte current3 in list2)
  763.             {
  764.                 fileStream.WriteByte(current3);
  765.             }
  766.         }
  767.         fileStream.Close();
  768.         return null;
  769.     }
  770.  
  771.     private static void PreCacheTaskZhangJieXmlNodes(Dictionary<int, TaskZhangJieVO> TaskZhangJieXmlNodeDict)
  772.     {
  773.         TaskZhangJieXmlNodeDict.Clear();
  774.         string text = Application.dataPath + "/UIResources/Config/ServerRes/1/IsolateRes/Config/TaskZhangJie.Xml";
  775.         XmlDocument xmlDocument = new XmlDocument();
  776.         xmlDocument.Load(text);
  777.         XElement xElement = VOBinOperator.ToXElement(xmlDocument.DocumentElement);
  778.         if (xElement == null)
  779.         {
  780.             GError.AddErrMsg(string.Format(Global.GetLang("解析: {0} 失败"), text));
  781.             return;
  782.         }
  783.         List<XElement> xElementList = Global.GetXElementList(xElement, "ZhangJie");
  784.         if (xElementList == null || xElementList.Count <= 0)
  785.         {
  786.             GError.AddErrMsg(string.Format(Global.GetLang("解析: {0} 失败"), text));
  787.             return;
  788.         }
  789.         for (int i = 0; i < xElementList.Count; i++)
  790.         {
  791.             TaskZhangJieVO taskZhangJieVO = new TaskZhangJieVO();
  792.             taskZhangJieVO.CopyFrom(xElementList[i]);
  793.             TaskZhangJieXmlNodeDict[taskZhangJieVO.ID] = taskZhangJieVO;
  794.             if (VOBinOperator.MinZhangJieID == 0)
  795.             {
  796.                 VOBinOperator.MinZhangJieID = taskZhangJieVO.ID;
  797.             }
  798.             if (VOBinOperator.MaxZhangJieID < taskZhangJieVO.ID)
  799.             {
  800.                 VOBinOperator.MaxZhangJieID = taskZhangJieVO.ID;
  801.             }
  802.         }
  803.     }
  804.  
  805.     private static XmlElement ToXmlElement(XElement xElement)
  806.     {
  807.         if (xElement == null)
  808.         {
  809.             return null;
  810.         }
  811.         XmlElement result = null;
  812.         XmlReader xmlReader = null;
  813.         try
  814.         {
  815.             xmlReader = xElement.CreateReader();
  816.             XmlDocument xmlDocument = new XmlDocument();
  817.             result = (xmlDocument.ReadNode(xElement.CreateReader()) as XmlElement);
  818.         }
  819.         catch
  820.         {
  821.         }
  822.         finally
  823.         {
  824.             if (xmlReader != null)
  825.             {
  826.                 xmlReader.Close();
  827.             }
  828.         }
  829.         return result;
  830.     }
  831.  
  832.     private static XElement ToXElement(XmlElement xmlElement)
  833.     {
  834.         if (xmlElement == null)
  835.         {
  836.             return null;
  837.         }
  838.         XElement result = null;
  839.         try
  840.         {
  841.             XmlDocument xmlDocument = new XmlDocument();
  842.             xmlDocument.AppendChild(xmlDocument.ImportNode(xmlElement, true));
  843.             result = XElement.Parse(xmlDocument.InnerXml);
  844.         }
  845.         catch
  846.         {
  847.         }
  848.         return result;
  849.     }
  850.  
  851.     private static string _PackArrayString(string[] strArr)
  852.     {
  853.         if (strArr == null || strArr.Length <= 0)
  854.         {
  855.             return string.Empty;
  856.         }
  857.         char c = '\u0019';
  858.         string text = ((char)strArr.Length).ToString() + c.ToString();
  859.         for (int i = 0; i < strArr.Length; i++)
  860.         {
  861.             if (!ConvertExt.SafeConvertToDouble(strArr[i]).Equals(0.0))
  862.             {
  863.                 string text2 = text;
  864.                 text = string.Concat(new string[]
  865.                 {
  866.                     text2,
  867.                     ((char)(i + 26)).ToString(),
  868.                     c.ToString(),
  869.                     strArr[i],
  870.                     c.ToString()
  871.                 });
  872.             }
  873.         }
  874.         text = text.Substring(0, text.Length - 1);
  875.         return Text.Encoding.UTF8.GetString(Text.Encoding.UTF8.GetBytes(text));
  876.     }
  877.  
  878.     public static string PackArray<T>(T[] Arr)
  879.     {
  880.         string[] array = new string[Arr.Length];
  881.         for (int i = 0; i < Arr.Length; i++)
  882.         {
  883.             array[i] = Arr[i].ToString();
  884.         }
  885.         return VOBinOperator._PackArrayString(array);
  886.     }
  887.  
  888.     public static string[] UnPackArrayString(string str)
  889.     {
  890.         if (string.IsNullOrEmpty(str))
  891.         {
  892.             MUDebug.LogError<string>(new string[]
  893.             {
  894.                 "UnPackArrayDouble Error! Owesome Error!"
  895.             });
  896.             return new string[0];
  897.         }
  898.         char c = '\u0019';
  899.         string[] array = str.Split(new char[]
  900.         {
  901.             c
  902.         });
  903.         if (array.Length > 1)
  904.         {
  905.             int num = (int)array[0].charAt(0);
  906.             string[] array2 = new string[num];
  907.             for (int i = 2; i < array.Length; i += 2)
  908.             {
  909.                 int num2 = (int)(array[i - 1].charAt(0) - '\u001a');
  910.                 array2[num2] = array[i];
  911.             }
  912.             return array2;
  913.         }
  914.         if (array.Length == 1)
  915.         {
  916.             int num3 = (int)array[0].charAt(0);
  917.             return new string[num3];
  918.         }
  919.         MUDebug.LogError<string>(new string[]
  920.         {
  921.             "UnPackArrayDouble Error! Owesome Error!"
  922.         });
  923.         return new string[0];
  924.     }
  925.  
  926.     public static double[] UnPackArrayDouble(string str)
  927.     {
  928.         if (string.IsNullOrEmpty(str))
  929.         {
  930.             MUDebug.LogError<string>(new string[]
  931.             {
  932.                 "UnPackArrayDouble Error! Owesome Error!"
  933.             });
  934.             return new double[0];
  935.         }
  936.         char c = '\u0019';
  937.         string[] array = str.Split(new char[]
  938.         {
  939.             c
  940.         });
  941.         if (array.Length > 1)
  942.         {
  943.             int num = (int)array[0].charAt(0);
  944.             double[] array2 = new double[num];
  945.             for (int i = 2; i < array.Length; i += 2)
  946.             {
  947.                 int num2 = (int)(array[i - 1].charAt(0) - '\u001a');
  948.                 array2[num2] = ConvertExt.SafeConvertToDouble(array[i]);
  949.             }
  950.             return array2;
  951.         }
  952.         if (array.Length == 1)
  953.         {
  954.             int num3 = (int)array[0].charAt(0);
  955.             return new double[num3];
  956.         }
  957.         MUDebug.LogError<string>(new string[]
  958.         {
  959.             "UnPackArrayDouble Error! Owesome Error!"
  960.         });
  961.         return new double[0];
  962.     }
  963. }
Advertisement
Add Comment
Please, Sign In to add comment