Example #1
0
    public static void BeginLevel()
    {
        FogOfWar.DisableShaderFogFunction();
        if (FogOfWar.enable)
        {
            GC.Collect();
            GameObject gameObject = GameObject.Find("Design/Field");
            if (gameObject != null && gameObject.activeInHierarchy)
            {
                FieldObj component = gameObject.GetComponent <FieldObj>();
                if (component != null)
                {
                    if (!Singleton <WatchController> .get_instance().IsWatching)
                    {
                        FogOfWar.EnableShaderFogFunction();
                    }
                    component.InitField();
                    int inFakeSightRange = 0;
                    component.UnrealToGridX(Horizon.QueryMainActorFakeSightRadius(), out inFakeSightRange);
                    Singleton <GameFowManager> .get_instance().InitSurface(true, component, inFakeSightRange);

                    if (Singleton <GameFowManager> .get_instance().LoadPrecomputeData())
                    {
                        FogOfWar.Reset(component.FieldX, component.FieldY, component.NumX, component.NumY, (int)GameDataMgr.globalInfoDatabin.GetDataByKey(56u).dwConfValue);
                        FogOfWar.ClearAllFog(true);
                        float num  = Mathf.Max((float)component.FieldX / 1000f, 1f);
                        float num2 = Mathf.Max((float)component.FieldY / 1000f, 1f);
                        Shader.SetGlobalVector("_InvSceneSize", new Vector4(1f / num, 1f / num2, num, num2));
                    }
                }
            }
        }
    }
    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);
    }