public static void TestByteIntArrTrans() { int[] array = new int[] { 3333, 77777777 }; byte[] array2 = FOGameFowOfflineSerializer.IntArrToByteArr(array); DebugHelper.Assert(array2.Length == 8); int[] array3 = FOGameFowOfflineSerializer.ByteArrToIntArr(array2); DebugHelper.Assert(array3.Length == array.Length); DebugHelper.Assert(array3[0] == array[0]); DebugHelper.Assert(array3[1] == array[1]); uint[] array4 = new uint[] { 50005u, 9999999u }; array[0] = (int)array4[0]; array[1] = (int)array4[1]; byte[] array5 = FOGameFowOfflineSerializer.IntArrToByteArr(array); DebugHelper.Assert(array5.Length == 8); uint[] array6 = FOGameFowOfflineSerializer.ByteArrToUIntArr(array5); DebugHelper.Assert(array6.Length == array4.Length); DebugHelper.Assert(array6[0] == array4[0]); DebugHelper.Assert(array6[1] == array4[1]); }
public bool TryLoad(FieldObj inFieldObj) { DebugHelper.Assert(inFieldObj != null); if (inFieldObj.fowOfflineData == null || inFieldObj.fowOfflineData.Length == 0) { return(false); } MemoryStream memoryStream = new MemoryStream(inFieldObj.fowOfflineData); BinaryReader binaryReader = new BinaryReader(memoryStream); uint num = binaryReader.ReadUInt32(); uint num2 = binaryReader.ReadUInt32(); uint num3 = binaryReader.ReadUInt32(); if (num != this.VerificationCode || this.Version != num2) { return(false); } int num4 = inFieldObj.NumX * inFieldObj.NumY; int num5 = binaryReader.ReadInt32(); if (num4 != num5) { return(false); } GameFowManager.InitSurfCellsArray(num4); GameFowManager.InitLevelGrid(num4, inFieldObj.LevelGrid.GridInfo.CellNumX, inFieldObj.LevelGrid.GridInfo.CellNumY, inFieldObj.LevelGrid.GridInfo.CellSizeX, inFieldObj.LevelGrid.GridInfo.CellSizeY, inFieldObj.LevelGrid.GridInfo.GridPos.x, inFieldObj.LevelGrid.GridInfo.GridPos.y); int num6 = 0; inFieldObj.UnrealToGridX(Horizon.QueryGlobalSight(), out num6); for (int i = 0; i < num4; i++) { int gridCellX = inFieldObj.LevelGrid.GetGridCellX(i); int gridCellY = inFieldObj.LevelGrid.GetGridCellY(i); int xMin = Mathf.Max(0, gridCellX - num6); int xMax = Mathf.Min(inFieldObj.NumX - 1, gridCellX + num6); int yMin = Mathf.Max(0, gridCellY - num6); int yMax = Mathf.Min(inFieldObj.NumY - 1, gridCellY + num6); int num7 = binaryReader.ReadInt32(); if (num7 > 0) { byte[] array = new byte[num7]; binaryReader.Read(array, 0, num7); uint[] array2 = FOGameFowOfflineSerializer.ByteArrToUIntArr(array); DebugHelper.Assert(array2.Length == num7 / 4); GameFowManager.InitSurfCell(i, xMin, xMax, yMin, yMax, true); IntPtr intPtr = Marshal.AllocHGlobal(num7); Marshal.Copy(array, 0, intPtr, num7); GameFowManager.SetSurfCellData(i, intPtr); Marshal.FreeHGlobal(intPtr); } else { GameFowManager.InitSurfCell(i, xMin, xMax, yMin, yMax, false); } FieldObj.SViewBlockAttr sViewBlockAttr = default(FieldObj.SViewBlockAttr); inFieldObj.QueryAttr(gridCellX, gridCellY, out sViewBlockAttr); GameFowManager.InitLevelGridCell(i, (int)sViewBlockAttr.BlockType, (int)sViewBlockAttr.LightType); } int num8 = binaryReader.ReadInt32(); if (num8 != 987654321) { } binaryReader.Close(); memoryStream.Close(); return(true); }