-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cs
More file actions
90 lines (79 loc) · 2.91 KB
/
Main.cs
File metadata and controls
90 lines (79 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.IO;
using MelonLoader;
using MelonLoader.Utils;
namespace ML_OpenVR_FSR
{
public static class BuildInfo
{
public const string Name = "ML_OpenVR_FSR";
public const string Description = "Loads the OpenVR FSR Mod at Runtime.";
public const string Author = "Herp Derpinstine";
public const string Company = "Lava Gang";
public const string Version = "1.1.0";
public const string DownloadLink = "https://github.com/LavaGang/ML_OpenVR_FSR";
}
public class ML_OpenVR_FSR : MelonPlugin
{
private static string fsrFilePath = null;
private static NativeLibrary fsrLib = null;
unsafe public override void OnApplicationEarlyStart()
{
ExtractResources();
MelonLogger.Msg("Loading FSR Mod ahead of OpenVR...");
fsrLib = NativeLibrary.Load(fsrFilePath);
if (fsrLib == null)
return;
MelonLogger.Msg("Initialized!");
}
private static void ExtractResources()
{
string fsr_folder = Path.Combine(MelonEnvironment.UserDataDirectory, BuildInfo.Name);
if (!Directory.Exists(fsr_folder))
{
Directory.CreateDirectory(fsr_folder);
MelonLogger.Msg("UserData Folder Created!");
}
try
{
string fsr_log = Path.Combine(fsr_folder, "openvr_mod.log");
if (File.Exists(fsr_log))
{
MelonLogger.Msg("Removing Existing Log File...");
File.Delete(fsr_log);
}
}
catch (Exception ex)
{
MelonDebug.Error(ex.ToString());
MelonDebug.Error($"Failed to Remove Existing Log File! Ignoring...");
}
string fsr_cfg = Path.Combine(fsr_folder, "openvr_mod.cfg");
if (!File.Exists(fsr_cfg))
{
MelonLogger.Msg("Extracting Default Config File...");
File.WriteAllBytes(fsr_cfg, Properties.Resources.openvr_mod_cfg);
}
fsrFilePath = Path.Combine(fsr_folder, "openvr_api.dll");
try
{
if (File.Exists(fsrFilePath))
{
MelonLogger.Msg("Removing Existing FSR Mod DLL...");
File.Delete(fsrFilePath);
}
}
catch (Exception ex)
{
MelonDebug.Error(ex.ToString());
MelonDebug.Error($"Failed to Extract FSR Mod DLL! Ignoring...");
return;
}
MelonLogger.Msg("Extracting FSR Mod DLL...");
File.WriteAllBytes(fsrFilePath,
//MelonUtils.IsGame32Bit()
//? Properties.Resources.openvr_mod_x86_dll :
Properties.Resources.openvr_mod_dll);
}
}
}