private void OnEnable()
 {
     terrain       = GameObject.FindObjectOfType <VigTerrain>();
     gameManager   = GameObject.FindObjectOfType <GameManager>();
     bitmap        = serializedObject.FindProperty("bitmapID");
     defaultVertex = serializedObject.FindProperty("defaultVertex");
     defaultTile   = serializedObject.FindProperty("defaultTile");
     chunkNum      = serializedObject.FindProperty("zoneCount");
     tileXZ        = serializedObject.FindProperty("tileXZ");
     tileY         = serializedObject.FindProperty("tileY");
 }
Esempio n. 2
0
    public static void LoadAsset(string assetPath, string savePath)
    {
        using (BinaryReader reader = new BinaryReader(File.Open(assetPath, FileMode.Open)))
        {
            int          iVar1;
            LevelManager levelManager = GameObject.FindObjectOfType <LevelManager>();
            VigTerrain   terrain      = GameObject.FindObjectOfType <VigTerrain>();
            string       relativePath = savePath;

            if (savePath.StartsWith(Application.dataPath))
            {
                relativePath = "Assets" + savePath.Substring(Application.dataPath.Length);
            }

            iVar1 = reader.ReadInt32BE();
            reader.ReadInt32();
            string bmpApsolute = savePath + "/XBGM" + 0.ToString().PadLeft(2, '0') + ".bmp";
            string bmpRelative = relativePath + "/XBGM" + 0.ToString().PadLeft(2, '0') + ".bmp";
            string matPath     = relativePath + "/XBGM" + 0.ToString().PadLeft(2, '0') + ".mat";
            IMP_TIM.LoadTIM(reader, bmpApsolute);
            Material newMaterial = null;
#if UNITY_EDITOR
            AssetDatabase.Refresh();
            newMaterial             = new Material(AssetDatabase.LoadAssetAtPath(relativePath + "/default.mat", typeof(Material)) as Material);
            newMaterial.mainTexture = AssetDatabase.LoadAssetAtPath(bmpRelative, typeof(Texture2D)) as Texture2D;
            Utilities.SaveObjectToFile(newMaterial, matPath);
#endif
            levelManager.DAT_DD0   = newMaterial;
            levelManager.DAT_6398A = (short)(iVar1 << 4);
            levelManager.DAT_63972 = (short)((iVar1 - levelManager.DAT_DD0.mainTexture.height) * 16);
            levelManager.DAT_6397A = levelManager.DAT_63972;
            levelManager.DAT_63982 = levelManager.DAT_63972;
            levelManager.DAT_63992 = levelManager.DAT_6398A;
            levelManager.DAT_6399A = levelManager.DAT_6398A;

            if (levelManager.DAT_E48 == null)
            {
                levelManager.DAT_E48 = levelManager.DAT_DD0;
            }

#if UNITY_EDITOR
            levelManager.DAT_E58 = AssetDatabase.LoadAssetAtPath("Assets/SHELL/glow.mat", typeof(Material)) as Material;
            EditorUtility.SetDirty(levelManager.gameObject);
#endif
        }
    }
Esempio n. 3
0
    //FUN_78CC (LOAD.DLL)
    private static void FUN_78CC(MemoryStream param1, MemoryStream param2, MemoryStream param3, MemoryStream param4)
    {
        int        iVar1;
        Vector3Int local_8;
        long       param1_pos = param1.Position;
        long       param2_pos = param2.Position;
        long       param3_pos = param3.Position;
        long       param4_pos = param4.Position;
        VigTerrain terrain    = GameObject.FindObjectOfType <VigTerrain>();

        using (BinaryReader reader = new BinaryReader(param3, Encoding.Default, true))
            local_8 = Utilities.FUN_23F58(new Vector3Int(reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16()));

        if (local_8.x < 0)
        {
            local_8.x += 0xffff;
        }

        if (local_8.z < 0)
        {
            local_8.z += 0xffff;
        }

        iVar1 = terrain.vertices[((local_8.z >> 16 & 0x3fU) * 2 + (local_8.x >> 16 & 0x3fU) * 128) / 2 + 4096 *
                                 terrain.chunks[(((uint)(local_8.z >> 16) >> 6) * 4 +
                                                 ((uint)(local_8.x >> 16) >> 6) * 128) / 4]] >> 11;

        using (BinaryWriter writer = new BinaryWriter(param1, Encoding.Default, true))
        {
            writer.Write(terrain.DAT_B9370[iVar1].r);
            writer.Write(terrain.DAT_B9370[iVar1].g);
            writer.Write(terrain.DAT_B9370[iVar1].b);
        }

        param2.Seek(param2_pos, SeekOrigin.Begin);
        param3.Seek(param3_pos, SeekOrigin.Begin);
        param4.Seek(param4_pos, SeekOrigin.Begin);
    }
Esempio n. 4
0
    public static void LoadAsset(string assetPath)
    {
        VigTerrain terr = GameObject.FindObjectOfType <VigTerrain>();

        using (BinaryReader reader = new BinaryReader(File.Open(assetPath, FileMode.Open)))
        {
            terr.chunks = new ushort[32 * 32];

            int iVar1 = 0;        //r10
            int iVar2 = 0x400000; //r9

            terr.DAT_DEC = 0x8000000;
            terr.DAT_DE4 = 0x8000000;
            terr.DAT_DE8 = 0;
            terr.DAT_DF0 = 0;

            do
            {
                int  iVar3      = 0;          //r7
                uint uVar3      = 0x400000;   //r6
                int  arrayIndex = iVar1 << 2; //r8

                do
                {
                    uint uVar1 = reader.ReadUInt16(); //r2
                    uint uVar2 = uVar1 >> 8;          //r4
                    uVar1  = (uVar1 & 0xFF) << 8;
                    uVar2 |= uVar1;
                    uVar1  = uVar2 << 2;
                    int zoneIndex = (int)uVar2;
                    terr.chunks[arrayIndex / 4] = (ushort)zoneIndex;

                    if (uVar2 != 0)
                    {
                        uVar2 = (uint)iVar3 << 22;

                        if (terr.DAT_DE4 < uVar2)
                        {
                            uVar2 = (uint)terr.DAT_DE4;
                        }

                        terr.DAT_DE4 = (int)uVar2;
                        int iVar = (int)uVar3;

                        if (uVar3 < terr.DAT_DE8)
                        {
                            iVar = terr.DAT_DE8;
                        }

                        terr.DAT_DE8 = iVar;
                        uVar2        = (uint)iVar1 << 22;

                        if (terr.DAT_DEC < uVar2)
                        {
                            uVar2 = (uint)terr.DAT_DEC;
                        }

                        terr.DAT_DEC = (int)uVar2;
                        iVar         = iVar2;

                        if (iVar2 < terr.DAT_DF0)
                        {
                            iVar = terr.DAT_DF0;
                        }

                        terr.DAT_DF0 = iVar;
                    }

                    uint uVar = 0x400000; //r3
                    uVar3 += uVar;
                    iVar3++;
                    arrayIndex += 128;
                } while (iVar3 < 32);

                iVar1++;
                iVar2 += 0x400000;
            } while (iVar1 < 32);
        }
    }
Esempio n. 5
0
    //FUN_7FE0 (LOAD.DLL)
    public static void LoadAsset(string assetPath)
    {
        using (BinaryReader reader = new BinaryReader(File.Open(assetPath, FileMode.Open)))
        {
            int          iVar1;
            Color32[]    puVar2;
            int          iVar3;
            int          iVar4;
            long         lVar5;
            LevelManager levelManager = GameObject.FindObjectOfType <LevelManager>();
            VigTerrain   terrain      = GameObject.FindObjectOfType <VigTerrain>();

            iVar3 = 0;
            unchecked { lVar5 = (int)0x84210843; }
            levelManager.DAT_E08 = new Color32
                                       (reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            levelManager.DAT_DA4 = new Color32
                                       (reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            levelManager.DAT_DDC = new Color32
                                       (reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), 0x30);
            reader.BaseStream.Seek(1, SeekOrigin.Current);
            levelManager.DAT_E04 = new Color32
                                       (reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            puVar2 = terrain.DAT_B9370;
            levelManager.DAT_DAC = new Color32
                                       (reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            levelManager.DAT_DBC = new Color32
                                       (reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            levelManager.DAT_D98 = new Color32
                                       (reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            levelManager.DAT_DE0 = new Color32
                                       (reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());

            do
            {
                iVar1           = (levelManager.DAT_DAC.r - levelManager.DAT_E04.r) * iVar3; //v1
                iVar4           = (int)(iVar1 * lVar5 >> 32) + iVar1 >> 4;                   //v0
                iVar4          -= iVar1 >> 31;
                iVar4           = iVar4 + levelManager.DAT_E04.r + (int)((uint)(iVar1 >> 31) << 31);
                puVar2[iVar3].r = (byte)(iVar4 >> 1);
                iVar1           = (levelManager.DAT_DAC.g - levelManager.DAT_E04.g) * iVar3; //v1
                iVar4           = (int)(iVar1 * lVar5 >> 32) + iVar1 >> 4;                   //v0
                iVar4          -= iVar1 >> 31;
                iVar4           = iVar4 + levelManager.DAT_E04.g + (int)((uint)(iVar1 >> 31) << 31);
                puVar2[iVar3].g = (byte)(iVar4 >> 1);
                iVar1           = (levelManager.DAT_DAC.b - levelManager.DAT_E04.b) * iVar3; //v1
                iVar4           = (int)(iVar1 * lVar5 >> 32) + iVar1 >> 4;                   //v0
                iVar4          -= iVar1 >> 31;
                iVar4           = iVar4 + levelManager.DAT_E04.b + (int)((uint)(iVar1 >> 31) << 31);
                puVar2[iVar3].b = (byte)(iVar4 >> 1);
                puVar2[iVar3].a = 0;
                iVar3++;
            } while (iVar3 < 32);

            levelManager.DAT_738 = new Matrix3x3()
            {
                V00 = (short)((levelManager.DAT_DAC.r - levelManager.DAT_E04.r) * 16),
                V01 = 0,
                V02 = 0,
                V10 = (short)((levelManager.DAT_DAC.g - levelManager.DAT_E04.g) * 16),
                V11 = 0,
                V12 = 0,
                V20 = (short)((levelManager.DAT_DAC.b - levelManager.DAT_E04.b) * 16),
                V21 = 0,
                V22 = 0
            };

            terrain.DAT_B9314 = new Color32[]
            {
                levelManager.DAT_E08,
                levelManager.DAT_E08
            };

            terrain.DAT_B932C = new Color32[]
            {
                levelManager.DAT_DA4,
                levelManager.DAT_DA4
            };

#if UNITY_EDITOR
            EditorUtility.SetDirty(levelManager.gameObject);
            EditorUtility.SetDirty(terrain.gameObject);
#endif
        }
    }
Esempio n. 6
0
    public RSEG_DB[] DAT_1C;  //0x1C

    //FUN_79A0 (LOAD.DLL)
    public bool LoadDB(string assetPath)
    {
        byte         bVar1;
        short        sVar2;
        int          iVar3;
        int          iVar4;
        int          iVar5;
        int          iVar7;
        VigMesh      pbVar8;
        MemoryStream psVar9;
        short        sVar12;
        MemoryStream psVar13;
        uint         uVar14;
        short        sVar15;
        short        sVar16;
        short        sVar17;

        byte[]        aVar18;
        DELEGATE_79A0 dVar18;
        VigTransform  auStack72;

        LevelManager levelManager = GameObject.FindObjectOfType <LevelManager>();

        using (BinaryReader reader = new BinaryReader(File.Open(assetPath, FileMode.Open)))
        {
            if (reader == null)
            {
                return(false);
            }

            long       length  = reader.BaseStream.Length;
            VigTerrain terrain = GameObject.FindObjectOfType <VigTerrain>();
            iVar3    = reader.ReadInt32BE();
            iVar4    = reader.ReadInt32BE();
            bVar1    = reader.ReadByte();
            iVar5    = reader.ReadByte();
            DAT_00.x = iVar3;
            DAT_00.z = iVar4;
            DAT_10   = bVar1;
            DAT_11   = (byte)iVar5;

            if ((bVar1 & 0x40) == 0)
            {
                DAT_12 = 0;
            }
            else
            {
                sVar2   = reader.ReadInt16BE();
                DAT_12  = sVar2;
                length -= 2;
            }

            if ((bVar1 & 2) == 0)
            {
                iVar7    = terrain.FUN_1B750((uint)iVar3, (uint)iVar4);
                DAT_00.y = iVar7;
            }
            else
            {
                iVar7    = reader.ReadInt32BE();
                DAT_00.y = iVar7 - 0x100000;
                length  -= 4;
            }

            iVar7 = 0;

            if (0 < iVar5)
            {
                DAT_1C = new RSEG_DB[iVar5];

                do
                {
                    DAT_1C[iVar7] = null;
                    iVar7++;
                } while (iVar7 < iVar5);
            }

            if (length < 11)
            {
                DAT_18 = null;
            }
            else
            {
                iVar5               = reader.ReadInt16BE();
                DAT_0C              = levelManager.xobfList[iVar5 + 42];
                sVar2               = reader.ReadInt16BE();
                DAT_14              = sVar2;
                sVar2               = reader.ReadInt16BE();
                DAT_16              = sVar2;
                pbVar8              = DAT_0C.FUN_2CB74(gameObject, (ushort)DAT_14, false);
                pbVar8.xobf         = DAT_0C;
                pbVar8.initAtStart  = true;
                DAT_18              = pbVar8;
                pbVar8.DAT_00       = (byte)(pbVar8.DAT_00 & 0xfe | 4);
                psVar13             = new MemoryStream(DAT_18.vertexStream);
                aVar18              = new byte[DAT_18.vertices << 3];
                psVar9              = new MemoryStream(aVar18);
                bVar1               = DAT_18.DAT_01;
                DAT_18.DAT_02       = 16;
                DAT_18.vertexStream = aVar18;
                uVar14              = 16 - (uint)bVar1;

                if (0 < DAT_18.vertices)
                {
                    using (BinaryReader reader2 = new BinaryReader(psVar13, Encoding.Default, true))
                    {
                        using (BinaryWriter writer = new BinaryWriter(psVar9, Encoding.Default, true))
                        {
                            for (int i = 0; i < DAT_18.vertices; i++)
                            {
                                iVar7  = ((ushort)DAT_16 & 0xfff) * 2;
                                sVar15 = reader2.ReadInt16();
                                reader2.BaseStream.Seek(2, SeekOrigin.Current);
                                sVar16 = reader2.ReadInt16();
                                iVar7  = GameManager.DAT_65C90[iVar7 + 1] * sVar15 +
                                         GameManager.DAT_65C90[iVar7] * sVar16;

                                if (iVar7 < 0)
                                {
                                    iVar7 += 4095;
                                }

                                sVar17 = (short)(iVar7 >> 12);
                                writer.Write(sVar17);
                                iVar7 = ((ushort)DAT_16 & 0xfff) * 2;
                                iVar7 = -GameManager.DAT_65C90[iVar7] * sVar15 +
                                        GameManager.DAT_65C90[iVar7 + 1] * sVar16;

                                if (iVar7 < 0)
                                {
                                    iVar7 += 4095;
                                }

                                sVar12 = (short)(iVar7 >> 12);
                                iVar7  = terrain.FUN_1B750((uint)(DAT_00.x + (sVar17 << (int)(uVar14 & 31))),
                                                           (uint)(DAT_00.z + (sVar12 << (int)(uVar14 & 31))));
                                reader2.BaseStream.Seek(2, SeekOrigin.Current);
                                writer.Write((short)(iVar7 - DAT_00.y >> (int)(uVar14 & 31)));
                                writer.Write(sVar12);
                                writer.Write((short)0);
                            }
                        }
                    }
                }

                auStack72 = GameManager.FUN_2A39C();
                Utilities.SetRotMatrix(auStack72.rotation);
                Coprocessor.translationVector._trx = iVar3;
                Coprocessor.translationVector._try = DAT_00.y;
                Coprocessor.translationVector._trz = iVar4;
                dVar18 = new DELEGATE_79A0(FUN_78CC);
                DAT_18.FUN_39A8(dVar18);
            }
        }

        levelManager.juncList.Add(this);
#if UNITY_EDITOR
        EditorUtility.SetDirty(gameObject);
        EditorUtility.SetDirty(levelManager.gameObject);
        PrefabUtility.RecordPrefabInstancePropertyModifications(gameObject);
#endif
        return(true);
    }
Esempio n. 7
0
    public static void LoadAsset(string assetPath)
    {
        VigTerrain terr = GameObject.FindObjectOfType <VigTerrain>();
        string     name = Path.GetFileNameWithoutExtension(assetPath);
        int        zone = (name[4] - '0') + (name[5] - '0') + (name[6] - '0') + (name[7] - '0');

        zone++;

        /*using (BinaryReader reader = new BinaryReader(File.Open(assetPath, FileMode.Open)))
         * {
         *  int iVar1 = 0; //r10
         *
         *  do
         *  {
         *      int iVar2 = 0; //r8
         *      int iVar3 = iVar1 << 6; //r12
         *      int verticesIndex = iVar1 << 7; //r9
         *      long chunkEnd = reader.BaseStream.Position + 3; //r7
         *
         *      do
         *      {
         *          uint uVar2 = reader.ReadUInt16(); //r3
         *          long chunkNext = reader.BaseStream.Position + 2;
         *          int tilesIndex = iVar2 + iVar3; //r6
         *          iVar2++;
         *          reader.BaseStream.Seek(chunkEnd - 1, SeekOrigin.Begin);
         *          uint uVar1 = (uint)reader.ReadByte() >> 3; //r4
         *          uint uVar3 = uVar2 >> 8; //r2
         *          uVar2 = (uVar2 & 0xFF) << 8;
         *          uVar3 |= uVar2;
         *          uVar3 -= 512;
         *          uVar1 = uVar1 << 11;
         *          uVar3 |= uVar1;
         *          terr.vertices[zone * 4096 + verticesIndex / 2] = (ushort)uVar3;
         *          reader.BaseStream.Seek(chunkEnd, SeekOrigin.Begin);
         *          uVar2 = reader.ReadByte();
         *          chunkEnd += 4;
         *          terr.tiles[zone * 4096 + tilesIndex] = (byte)uVar2;
         *          verticesIndex += 2;
         *      } while (iVar2 < 64);
         *
         *      iVar1++;
         *  } while (iVar1 < 64);
         * }*/

        using (BinaryReader reader = new BinaryReader(File.Open(assetPath, FileMode.Open)))
        {
            byte   bVar1;
            ushort uVar2;
            long   puVar5;
            int    iVar4;
            int    iVar6;
            int    iVar7;
            int    iVar8;

            iVar8 = 0;

            do
            {
                iVar6  = 0;
                iVar7  = iVar8 << 6;
                puVar5 = reader.BaseStream.Position + 3;

                do
                {
                    uVar2 = reader.ReadUInt16(0);
                    iVar4 = iVar6 + iVar8 * 64;
                    iVar6++;
                    terr.vertices[zone * 4096 + iVar7] =
                        (ushort)((uVar2 >> 8 | (ushort)((uVar2 & 0xff) << 8)) - 0x200 |
                                 (ushort)((uint)reader.ReadByte(2) >> 3) << 11);
                    bVar1   = reader.ReadByte(3);
                    puVar5 += 4;
                    reader.BaseStream.Seek(4, SeekOrigin.Current);
                    terr.tiles[zone * 4096 + iVar4] = bVar1;
                    iVar7++;
                } while (iVar6 < 64);

                iVar8++;
            } while (iVar8 < 64);
        }
    }
Esempio n. 8
0
    /*public static List<TileData> LoadAsset(string assetPath1)
     * {
     *  List<TileData> output = new List<TileData>();
     *  LevelManager levelManager = GameObject.FindObjectOfType<LevelManager>();
     *  VigTerrain terrain = GameObject.FindObjectOfType<VigTerrain>();
     *
     *  using (BinaryReader reader = new BinaryReader(File.Open(assetPath1, FileMode.Open)))
     *  {
     *      int iVar1 = 0; //r6
     *      byte[] aVar1 = BYTES;
     *
     *      do
     *      {
     *          int iVar = 0; //r5
     *          int arrayIndex = iVar1 << 3; //r4
     *
     *          do
     *          {
     *              int iVar3; //r2
     *
     *              if (aVar1[arrayIndex] == 0)
     *                  iVar3 = 0;
     *              else
     *                  iVar3 = levelManager.DAT_DBA - 1;
     *
     *              aVar1[arrayIndex] = (byte)iVar3;
     *              iVar3 = aVar1[arrayIndex + 1];
     *
     *              if (iVar3 == 0)
     *                  iVar3 = 0;
     *              else
     *                  iVar3 = levelManager.DAT_DBA - 1;
     *
     *              aVar1[arrayIndex + 1] = (byte)iVar3;
     *              arrayIndex += 2;
     *          }
     *          while (++iVar < 4);
     *      } while (++iVar1 < 8);
     *
     *      long chunkEnd = reader.BaseStream.Position + 34;
     *      long chunkStart = reader.BaseStream.Position;
     *      int iVar2 = 0; //r21
     *
     *      do
     *      {
     *          reader.BaseStream.Seek(chunkEnd - 32, SeekOrigin.Begin);
     *          uint uVar1 = reader.ReadByte(); //r6
     *          int iVar4 = (int)(uVar1 & 15) * levelManager.DAT_DBA; //r9
     *          uVar1 = (uint)((int)(uVar1 >> 4) * levelManager.DAT_DBA);
     *          reader.BaseStream.Seek(chunkEnd - 31, SeekOrigin.Begin);
     *          int iVar5 = reader.ReadByte(); //r20
     *          int arrayIndex = (iVar5 & 7) << 3; //r5
     *          int uv_y = aVar1[arrayIndex + 1]; //r2
     *          int uv = aVar1[arrayIndex]; //r3
     *          int iVar6 = iVar4 & 127; //r8
     *          uv += iVar6;
     *          uv_y = uv_y + (int)uVar1 << 8;
     *          uv |= uv_y;
     *          reader.BaseStream.Seek(chunkStart, SeekOrigin.Begin);
     *          uint uVar2 = reader.ReadUInt16(); //r7
     *
     *          TileData newTile = new TileData();
     *          newTile.uv1_x = uv & 0xFF;
     *          newTile.uv1_y = uv >> 8;
     *          uv = (aVar1[arrayIndex + 2] + iVar6) | (aVar1[arrayIndex + 3] + (int)uVar1 << 8);
     *          newTile.uv2_x = uv & 0xFF;
     *          newTile.uv2_y = uv >> 8;
     *          uv = (aVar1[arrayIndex + 4] + iVar6) | (aVar1[arrayIndex + 5] + (int)uVar1 << 8);
     *          newTile.uv3_x = uv & 0xFF;
     *          newTile.uv3_y = uv >> 8;
     *          uv = (aVar1[arrayIndex + 6] + iVar6) | (aVar1[arrayIndex + 7] + (int)uVar1 << 8);
     *          newTile.uv4_x = uv & 0xFF;
     *          newTile.uv4_y = uv >> 8;
     *
     *          uint uVar3 = uVar2 >> 8;
     *          uVar2 = (uVar2 & 0xFF) << 8;
     *          uint uVar4 = uVar3 | uVar2; //r17
     *          uint uVar7 = 0;
     *
     *          if ((uVar4 & 16) == 0)
     *          {
     *              uVar7 = (uint)iVar4 >> 7;
     *              int iVar = (terrain.bitmapID & 3) + 5;
     *              uVar7 = uVar7 << iVar;
     *              uVar7 = (uVar7 / 64) * 128; // need to test if the scale is right
     *              newTile.uv4_x += (int)uVar7;
     *          }
     *
     *          uint uVar5 = uVar4 >> 4 & 1;
     *          uint uVar6 = ((uint)iVar5 & 18) >> 2;
     *          uVar5 |= uVar6;
     *          uVar2 = 0;
     *          long bufferPos = chunkStart;
     *          arrayIndex = iVar2;
     *          newTile.unk1 = (byte)uVar2;
     *          newTile.uv1_x += (int)uVar7;
     *          newTile.uv2_x += (int)uVar7;
     *          newTile.uv3_x += (int)uVar7;
     *
     *          newTile.unk2 = new short[6];
     *
     *          do
     *          {
     *              reader.BaseStream.Seek(bufferPos + 4, SeekOrigin.Begin);
     *              uVar5 = reader.ReadUInt16();
     *              bufferPos += 2;
     *              arrayIndex += 2;
     *              uVar2++;
     *              uVar6 = uVar5 >> 8;
     *              uVar5 &= 0xFF;
     *              uVar6 |= uVar5;
     *              newTile.unk2[arrayIndex / 2 - 1] = (short)uVar6;
     *          } while (uVar2 < 6);
     *
     *          reader.BaseStream.Seek(chunkEnd - 2, SeekOrigin.Begin);
     *          newTile.unk3 = reader.ReadByte();
     *          reader.BaseStream.Seek(chunkEnd - 1, SeekOrigin.Begin);
     *          newTile.unk4 = reader.ReadByte();
     *          reader.BaseStream.Seek(chunkEnd, SeekOrigin.Begin);
     *          newTile.unk5 = reader.ReadByte();
     *          iVar1 += 32;
     *          chunkStart += 36;
     *          chunkEnd += 36;
     *          output.Add(newTile);
     *      } while (output.Count < 256);
     *  }
     *
     *  return output;
     * }*/

    public static void LoadAsset(string assetPath)
    {
        using (BinaryReader reader = new BinaryReader(File.Open(assetPath, FileMode.Open)))
        {
            int          puVar1;
            byte         bVar2;
            ushort       uVar3;
            ushort       uVar4;
            sbyte        sVar5;
            short        sVar6;
            uint         uVar6;
            int          iVar7;
            int          iVar8;
            int          iVar9;
            int          puVar10;
            int          puVar11;
            TileData     psVar12;
            uint         uVar13;
            LevelManager levelManager = GameObject.FindObjectOfType <LevelManager>();
            VigTerrain   terrain      = GameObject.FindObjectOfType <VigTerrain>();

            byte[] BYTES =
            {
                0x00, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x1F, 0x00, 0x1F, 0x1F,
                0x00, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F,
                0x1F, 0x00, 0x1F, 0x1F, 0x00, 0x1F, 0x00, 0x00, 0x1F, 0x1F,
                0x1F, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x00, 0x1F,
                0x00, 0x00, 0x1F, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
                0x1F, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x1F, 0x00, 0x1F, 0x1F,
                0x00, 0x00, 0x00, 0x1F
            };

            iVar9 = 0;

            if (terrain.tileData == null)
            {
                terrain.tileData = new List <TileData>();
            }

            terrain.tileData.Clear();

            do
            {
                iVar8 = 0;
                iVar7 = iVar9 << 3;

                do
                {
                    if (BYTES[iVar7] == 0)
                    {
                        sVar5 = 0;
                    }
                    else
                    {
                        sVar5 = (sbyte)((byte)levelManager.DAT_DBA - 1);
                    }

                    BYTES[iVar7] = (byte)sVar5;

                    if (BYTES[iVar7 + 1] == 0)
                    {
                        sVar5 = 0;
                    }
                    else
                    {
                        sVar5 = (sbyte)((byte)levelManager.DAT_DBA - 1);
                    }

                    BYTES[iVar7 + 1] = (byte)sVar5;
                    iVar8++;
                    iVar7 += 2;
                } while (iVar8 < 4);

                iVar9++;
            } while (iVar9 < 8);

            puVar11 = (int)(reader.BaseStream.Position + 0x22);
            iVar9   = 0;

            do
            {
                uVar13  = (uint)(reader.ReadByte(puVar11 - 0x20) & 15) * (ushort)levelManager.DAT_DBA;
                sVar6   = (short)(((uint)reader.ReadByte(puVar11 - 0x20) >> 4) * (ushort)levelManager.DAT_DBA);
                bVar2   = reader.ReadByte(puVar11 - 0x1f);
                iVar7   = (bVar2 & 7) * 8;
                uVar4   = (ushort)(uVar13 & 0x7f);
                uVar3   = reader.ReadUInt16(puVar11 - 0x22);
                psVar12 = new TileData();
                terrain.tileData.Add(psVar12);
                psVar12.uv1_x = BYTES[iVar7] + uVar4;
                psVar12.uv1_y = BYTES[iVar7 + 1] + sVar6;
                psVar12.uv2_x = BYTES[iVar7 + 2] + uVar4;
                psVar12.uv2_y = BYTES[iVar7 + 3] + sVar6;
                psVar12.uv3_x = BYTES[iVar7 + 4] + uVar4;
                psVar12.uv3_y = BYTES[iVar7 + 5] + sVar6;
                psVar12.uv4_x = BYTES[iVar7 + 6] + uVar4;
                psVar12.uv4_y = BYTES[iVar7 + 7] + sVar6;

                if ((uVar3 >> 8 & 16) == 0)
                {
                    uVar6          = (uVar13 >> 7) << (terrain.bitmapID & 3) + 5;
                    uVar6          = (uVar6 / 64) * 128;
                    psVar12.uv4_x += (int)uVar6;
                }
                else
                {
                    uVar6 = 0;
                }

                iVar8          = 0;
                psVar12.flags  = (byte)((byte)((uint)uVar3 >> 12) & 1 | (byte)((uint)(bVar2 & 0x18) >> 2));
                psVar12.uv3_x += (int)uVar6;
                psVar12.uv2_x += (int)uVar6;
                psVar12.uv1_x += (int)uVar6;
                puVar10        = puVar11 - 0x22;
                psVar12.DAT_10 = new short[6];

                do
                {
                    puVar1   = puVar10 + 4;
                    puVar10 += 2;
                    psVar12.DAT_10[iVar8] = (short)((uint)reader.ReadUInt16(puVar1) >> 8 | (uint)((reader.ReadUInt16(puVar1) & 0xff) << 8));
                    iVar8++;
                } while (iVar8 < 6);

                iVar9         += 0x20;
                psVar12.DAT_1C = reader.ReadByte(puVar11 - 2);
                psVar12.DAT_1D = reader.ReadByte(puVar11 - 1);
                psVar12.DAT_1E = reader.ReadByte(puVar11);
                puVar11       += 0x24;
            } while (iVar9 < 0x2000);
        }
    }
    private Mesh GenerateMesh()
    {
        Mesh           mesh         = new Mesh();
        List <Vector3> newVertices  = new List <Vector3>();
        List <Vector2> newUV        = new List <Vector2>();
        List <int>     newTriangles = new List <int>();

        terrain = GameObject.FindObjectOfType <VigTerrain>();
        Material mat       = terrain.GetComponent <MeshRenderer>().sharedMaterial;
        int      vertIndex = 0;

        mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

        for (int i = 0; i < terrain.chunks.Length; i++)
        {
            int tFactor = GameManager.instance.translateFactor;
            int tileXZ  = terrain.tileXZ;
            int tileY   = terrain.tileY;

            if (terrain.chunks[i] == 0 || terrain.zoneCount <= terrain.chunks[i])
            {
                continue;
            }

            int zone = terrain.chunks[i];

            for (int x = 0; x < 64; x++)
            {
                for (int y = 0; y < 64; y++)
                {
                    float vert1_x = Utilities.MoveDecimal((long)x * tileXZ + (long)tileXZ * 64 * (i / 32), tFactor);
                    float vert1_y = -Utilities.MoveDecimal((long)((int)((short)terrain.vertices[zone * 4096 + x * 64 + y] & 0x7FF)) * tileY, tFactor);
                    float vert1_z = Utilities.MoveDecimal((long)y * tileXZ + (long)tileXZ * 64 * (i % 32), tFactor);
                    newVertices.Add(new Vector3(vert1_x, vert1_y, vert1_z));

                    float vert2_x  = Utilities.MoveDecimal((long)(x + 1) * tileXZ + (long)tileXZ * 64 * (i / 32), tFactor);
                    int   nextZone = x + 1 < 64 ? zone : terrain.chunks[i + 32];
                    int   nextX    = x + 1 < 64 ? x + 1 : 0;
                    float vert2_y  = -Utilities.MoveDecimal((long)((int)((short)terrain.vertices[nextZone * 4096 + nextX * 64 + y] & 0x7FF)) * tileY, tFactor);
                    float vert2_z  = Utilities.MoveDecimal((long)y * tileXZ + (long)tileXZ * 64 * (i % 32), tFactor);
                    newVertices.Add(new Vector3(vert2_x, vert2_y, vert2_z));

                    float vert3_x = Utilities.MoveDecimal((long)x * tileXZ + (long)tileXZ * 64 * (i / 32), tFactor);
                    nextZone = y + 1 < 64 ? zone : terrain.chunks[i + 1];
                    int   nextY   = y + 1 < 64 ? y + 1 : 0;
                    float vert3_y = -Utilities.MoveDecimal((long)((int)((short)terrain.vertices[nextZone * 4096 + x * 64 + nextY] & 0x7FF)) * tileY, tFactor);
                    float vert3_z = Utilities.MoveDecimal((long)(y + 1) * tileXZ + (long)tileXZ * 64 * (i % 32), tFactor);
                    newVertices.Add(new Vector3(vert3_x, vert3_y, vert3_z));

                    float vert4_x = Utilities.MoveDecimal((long)(x + 1) * tileXZ + (long)tileXZ * 64 * (i / 32), tFactor);
                    if (x + 1 >= 64 && y + 1 >= 64)
                    {
                        nextZone = terrain.chunks[i + 33];
                        nextX    = 0;
                        nextY    = 0;
                    }
                    else if (x + 1 >= 64)
                    {
                        nextZone = terrain.chunks[i + 32];
                        nextX    = 0;
                        nextY    = y + 1;
                    }
                    else if (y + 1 >= 64)
                    {
                        nextZone = terrain.chunks[i + 1];
                        nextX    = x + 1;
                        nextY    = 0;
                    }
                    else
                    {
                        nextZone = zone;
                        nextX    = x + 1;
                        nextY    = y + 1;
                    }
                    float vert4_y = -Utilities.MoveDecimal((long)((int)((short)terrain.vertices[nextZone * 4096 + nextX * 64 + nextY] & 0x7FF)) * tileY, tFactor);
                    float vert4_z = Utilities.MoveDecimal((long)(y + 1) * tileXZ + (long)tileXZ * 64 * (i % 32), tFactor);
                    newVertices.Add(new Vector3(vert4_x, vert4_y, vert4_z));

                    int tileIndex = zone * 4096 + x * 64 + y;

                    float uv1_x = (float)terrain.tileData[terrain.tiles[tileIndex]].uv1_x / (mat.mainTexture.width - 1);
                    float uv1_y = 1.0f - (float)terrain.tileData[terrain.tiles[tileIndex]].uv1_y / (mat.mainTexture.height - 1);

                    float uv2_x = (float)terrain.tileData[terrain.tiles[tileIndex]].uv2_x / (mat.mainTexture.width - 1);
                    float uv2_y = 1.0f - (float)terrain.tileData[terrain.tiles[tileIndex]].uv2_y / (mat.mainTexture.height - 1);

                    float uv3_x = (float)terrain.tileData[terrain.tiles[tileIndex]].uv3_x / (mat.mainTexture.width - 1);
                    float uv3_y = 1.0f - (float)terrain.tileData[terrain.tiles[tileIndex]].uv3_y / (mat.mainTexture.height - 1);

                    float uv4_x = (float)terrain.tileData[terrain.tiles[tileIndex]].uv4_x / (mat.mainTexture.width - 1);
                    float uv4_y = 1.0f - (float)terrain.tileData[terrain.tiles[tileIndex]].uv4_y / (mat.mainTexture.height - 1);

                    newUV.Add(new Vector2(uv1_x, uv1_y));
                    newUV.Add(new Vector2(uv2_x, uv2_y));
                    newUV.Add(new Vector2(uv3_x, uv3_y));
                    newUV.Add(new Vector2(uv4_x, uv4_y));

                    newTriangles.Add(vertIndex + 2);
                    newTriangles.Add(vertIndex + 1);
                    newTriangles.Add(vertIndex + 0);
                    newTriangles.Add(vertIndex + 3);
                    newTriangles.Add(vertIndex + 1);
                    newTriangles.Add(vertIndex + 2);

                    vertIndex += 4;
                }
            }
        }

        mesh.SetVertices(newVertices);
        mesh.SetUVs(0, newUV);
        mesh.SetTriangles(newTriangles, 0);

        return(mesh);
    }