private static bool EnableVROptions(string path) { AssetsManager assetsManager = new AssetsManager(); AssetsFileInstance assetsFileInstance = assetsManager.LoadAssetsFile(path, false, ""); assetsManager.LoadClassDatabase(Path.Combine(VREnabler.VRPatcherPath, "cldb.dat")); int num = 0; while ((long)num < (long)((ulong)assetsFileInstance.table.assetFileInfoCount)) { try { AssetFileInfoEx assetInfo = assetsFileInstance.table.GetAssetInfo((long)num); AssetTypeInstance ati = assetsManager.GetATI(assetsFileInstance.file, assetInfo, false); AssetTypeValueField assetTypeValueField = (ati != null) ? ati.GetBaseField(0) : null; AssetTypeValueField assetTypeValueField2 = (assetTypeValueField != null) ? assetTypeValueField.Get("enabledVRDevices") : null; if (assetTypeValueField2 != null) { AssetTypeValueField assetTypeValueField3 = assetTypeValueField2.Get("Array"); if (assetTypeValueField3 != null) { AssetTypeValueField assetTypeValueField4 = ValueBuilder.DefaultValueFieldFromArrayTemplate(assetTypeValueField3); assetTypeValueField4.GetValue().Set("Oculus"); AssetTypeValueField assetTypeValueField5 = ValueBuilder.DefaultValueFieldFromArrayTemplate(assetTypeValueField3); assetTypeValueField5.GetValue().Set("OpenVR"); AssetTypeValueField assetTypeValueField6 = ValueBuilder.DefaultValueFieldFromArrayTemplate(assetTypeValueField3); assetTypeValueField6.GetValue().Set("None"); assetTypeValueField3.SetChildrenList(new AssetTypeValueField[] { assetTypeValueField6, assetTypeValueField4, assetTypeValueField5 }); byte[] array; using (MemoryStream memoryStream = new MemoryStream()) { using (AssetsFileWriter assetsFileWriter = new AssetsFileWriter(memoryStream)) { assetsFileWriter.bigEndian = false; AssetWriters.Write(assetTypeValueField, assetsFileWriter, 0); array = memoryStream.ToArray(); } } List <AssetsReplacer> list = new List <AssetsReplacer> { new AssetsReplacerFromMemory(0, (long)num, (int)assetInfo.curFileType, ushort.MaxValue, array) }; using (MemoryStream memoryStream2 = new MemoryStream()) { using (AssetsFileWriter assetsFileWriter2 = new AssetsFileWriter(memoryStream2)) { assetsFileInstance.file.Write(assetsFileWriter2, 0UL, list, 0U, null); assetsFileInstance.stream.Close(); File.WriteAllBytes(path, memoryStream2.ToArray()); } } return(true); } } } catch { } num++; } VREnabler.Logger.LogError("VR enable location not found!"); return(false); }
public void WriteTo(AssetTypeValueField baseField) { AssetTypeValueField tempField; baseField.Get("m_Name").GetValue().Set(m_Name); if (!(tempField = baseField.Get("m_ForcedFallbackFormat")).IsDummy()) { tempField.GetValue().Set(m_ForcedFallbackFormat); } if (!(tempField = baseField.Get("m_DownscaleFallback")).IsDummy()) { tempField.GetValue().Set(m_DownscaleFallback); } baseField.Get("m_Width").GetValue().Set(m_Width); baseField.Get("m_Height").GetValue().Set(m_Height); if (!(tempField = baseField.Get("m_CompleteImageSize")).IsDummy()) { tempField.GetValue().Set(m_CompleteImageSize); } baseField.Get("m_TextureFormat").GetValue().Set(m_TextureFormat); if (!(tempField = baseField.Get("m_MipCount")).IsDummy()) { tempField.GetValue().Set(m_MipCount); } if (!(tempField = baseField.Get("m_MipMap")).IsDummy()) { tempField.GetValue().Set(m_MipMap); } baseField.Get("m_IsReadable").GetValue().Set(m_IsReadable); if (!(tempField = baseField.Get("m_ReadAllowed")).IsDummy()) { tempField.GetValue().Set(m_ReadAllowed); } if (!(tempField = baseField.Get("m_StreamingMipmaps")).IsDummy()) { tempField.GetValue().Set(m_StreamingMipmaps); } if (!(tempField = baseField.Get("m_StreamingMipmapsPriority")).IsDummy()) { tempField.GetValue().Set(m_StreamingMipmapsPriority); } baseField.Get("m_ImageCount").GetValue().Set(m_ImageCount); baseField.Get("m_TextureDimension").GetValue().Set(m_TextureDimension); AssetTypeValueField textureSettings = baseField.Get("m_TextureSettings"); textureSettings.Get("m_FilterMode").GetValue().Set(m_TextureSettings.m_FilterMode); textureSettings.Get("m_Aniso").GetValue().Set(m_TextureSettings.m_Aniso); textureSettings.Get("m_MipBias").GetValue().Set(m_TextureSettings.m_MipBias); if (!(tempField = textureSettings.Get("m_WrapMode")).IsDummy()) { tempField.GetValue().Set(m_TextureSettings.m_WrapMode); } if (!(tempField = textureSettings.Get("m_WrapU")).IsDummy()) { tempField.GetValue().Set(m_TextureSettings.m_WrapU); } if (!(tempField = textureSettings.Get("m_WrapV")).IsDummy()) { tempField.GetValue().Set(m_TextureSettings.m_WrapV); } if (!(tempField = textureSettings.Get("m_WrapW")).IsDummy()) { tempField.GetValue().Set(m_TextureSettings.m_WrapW); } if (!(tempField = baseField.Get("m_LightmapFormat")).IsDummy()) { tempField.GetValue().Set(m_LightmapFormat); } if (!(tempField = baseField.Get("m_ColorSpace")).IsDummy()) { tempField.GetValue().Set(m_ColorSpace); } AssetTypeValueField imageData = baseField.Get("image data"); if (imageData.templateField.valueType == EnumValueTypes.ByteArray) { imageData.GetValue().Set(pictureData); } else { imageData.GetValue().Set(new AssetTypeArray(pictureData.Length)); AssetTypeValueField[] children = new AssetTypeValueField[pictureData.Length]; for (int i = 0; i < pictureData.Length; i++) { AssetTypeValueField child = ValueBuilder.DefaultValueFieldFromArrayTemplate(imageData); child.GetValue().Set(pictureData[i]); children[i] = child; } imageData.SetChildrenList(children); } AssetTypeValueField streamData; if (!(streamData = baseField.Get("m_StreamData")).IsDummy()) { streamData.Get("offset").GetValue().Set(m_StreamData.offset); streamData.Get("size").GetValue().Set(m_StreamData.size); streamData.Get("path").GetValue().Set(m_StreamData.path); } }
private static bool PatchVROptions(bool UnPatch = false) { string path = Path.Combine(ManagedPath, "../globalgamemanagers"); AssetsManager am = new AssetsManager(); AssetsFileInstance afi = am.LoadAssetsFile(path, false); am.LoadClassDatabase(Path.Combine(VRPatcherPath, "cldb.dat")); for (int i = 0; i < afi.table.assetFileInfoCount; i++) { try { AssetFileInfoEx info = afi.table.GetAssetInfo(i); AssetTypeInstance ati = am.GetATI(afi.file, info); AssetTypeValueField baseField = ati?.GetBaseField(); AssetTypeValueField enabledVRDevicesField = baseField?.Get("enabledVRDevices"); if (enabledVRDevicesField is null) { continue; } AssetTypeValueField vrArrayField = enabledVRDevicesField.Get("Array"); if (vrArrayField is null) { continue; } AssetTypeValueField OpenVR = ValueBuilder.DefaultValueFieldFromArrayTemplate(vrArrayField); OpenVR.GetValue().Set("OpenVR"); AssetTypeValueField Oculus = ValueBuilder.DefaultValueFieldFromArrayTemplate(vrArrayField); Oculus.GetValue().Set("Oculus"); AssetTypeValueField None = ValueBuilder.DefaultValueFieldFromArrayTemplate(vrArrayField); None.GetValue().Set("None"); if (!UnPatch) { vrArrayField.SetChildrenList(new AssetTypeValueField[] { None, OpenVR, Oculus }); Logger.LogMessage("Patching GGM"); } else { vrArrayField.SetChildrenList(new AssetTypeValueField[] { None }); Logger.LogMessage("UnPatching GGM"); } byte[] vrAsset; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { writer.bigEndian = false; baseField.Write(writer); vrAsset = memStream.ToArray(); } List <AssetsReplacer> rep = new List <AssetsReplacer>() { new AssetsReplacerFromMemory(0, i, (int)info.curFileType, 0xFFFF, vrAsset) }; using (MemoryStream memStream = new MemoryStream()) using (AssetsFileWriter writer = new AssetsFileWriter(memStream)) { afi.file.Write(writer, 0, rep, 0); afi.stream.Close(); File.WriteAllBytes(path, memStream.ToArray()); } return(true); } catch { } } Logger.LogError("VR enable location not found!"); return(false); }