Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DFUVR/DFUVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<Compile Include="MenuTransition.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Sheath.cs" />
<Compile Include="SheathCollision.cs" />
<Compile Include="SnapTurnProvider.cs" />
Expand Down
24 changes: 13 additions & 11 deletions DFUVR/MenuTransition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ public static void Done()
Var.fStartMenu = false;
turnStyle = Var.turnOptionsText.text;
dominantHand = Var.handOptionsText.text;
string filePath = Path.Combine(Paths.PluginPath, "Settings.txt");
string[] lines = File.ReadAllLines(filePath);
lines[5] = "false";

var settings = Settings.LoadFromFile();
settings.showStartMenu = false;
Plugin.LoggerInstance.LogInfo("Reached saving part");
lines[6] = string.Format(CultureInfo.InvariantCulture, dominantHand);
lines[7] = string.Format(CultureInfo.InvariantCulture, turnStyle);
settings.dominantHand = string.Format(CultureInfo.InvariantCulture, dominantHand);
settings.turnStyle = string.Format(CultureInfo.InvariantCulture, turnStyle);
Plugin.LoggerInstance.LogInfo($"Saving part ended with {dominantHand} and {turnStyle}");
File.WriteAllLines(filePath, lines);
settings.SaveToFile();

Application.Quit();
}
public static void SaveButtonClick(GameObject currentMenu, GameObject nextMenu, bool mainMenuC, bool mainMenuM)
Expand All @@ -109,11 +110,12 @@ public static void SaveButtonClick(GameObject currentMenu, GameObject nextMenu,
{
cType = GameObject.Find("CLabel").GetComponent<Text>().text;
refresh_rate = GameObject.Find("HzLabel").GetComponent<Text>().text;
string filePath = Path.Combine(Paths.PluginPath, "Settings.txt");
string[] lines = File.ReadAllLines(filePath);
lines[2] = string.Format(CultureInfo.InvariantCulture, cType);
lines[1] = string.Format(CultureInfo.InvariantCulture, refresh_rate);
File.WriteAllLines(filePath, lines);

var settings = Settings.LoadFromFile();
settings.headsetType = string.Format(CultureInfo.InvariantCulture, cType);
settings.headsetRefreshRate = int.Parse(refresh_rate, CultureInfo.InvariantCulture);
settings.SaveToFile();

MenuTransition(currentMenu, nextMenu, mainMenuC, mainMenuM);
}
catch(Exception e) { Plugin.LoggerInstance.LogError(e); }
Expand Down
90 changes: 90 additions & 0 deletions DFUVR/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using BepInEx;
using DaggerfallWorkshop;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DFUVR
{
internal class Settings
{
public double heightOffset = -0.989447891712189;
public int headsetRefreshRate = 90;
public string headsetType = "Oculus/Meta";
public string sheathOffset = "-0.1195223,0.07885736,-0.02833132";
public int connectedJoysticks = 0;
public bool showStartMenu = true;
public string dominantHand = "right";
public string turnStyle = "snap";
public bool toggleRun = true;

public static Settings LoadFromFile()
{
try
{
string filePath = Path.Combine(Paths.PluginPath, "Settings.txt");
if (!File.Exists(filePath))
{
Plugin.LoggerInstance.LogWarning("Settings file not found, creating default settings file and setting default values.");
var defaultSettings = new Settings();
defaultSettings.SaveToFile();

return defaultSettings;
}

string[] lines = File.ReadAllLines(filePath);

Settings settings = new Settings();
settings.heightOffset = double.Parse(lines[0].Trim());
settings.headsetRefreshRate = int.Parse(lines[1].Trim());
settings.headsetType = lines[2].Trim();
settings.sheathOffset = lines[3].Trim();
settings.connectedJoysticks = int.Parse(lines[4].Trim());
settings.showStartMenu = bool.Parse(lines[5].Trim());
settings.dominantHand = lines[6].Trim();
settings.turnStyle = lines[7].Trim();
if (lines.Length > 8)
settings.toggleRun = bool.Parse(lines[8].Trim());

return settings;
}
catch (Exception ex)
{
Plugin.LoggerInstance.LogError($"Failed to load Settings.txt: {ex.Message}");
return new Settings();
}
}

public bool SaveToFile()
{
string[] lines = new string[]
{
heightOffset.ToString(),
headsetRefreshRate.ToString(),
headsetType,
sheathOffset,
connectedJoysticks.ToString(),
showStartMenu.ToString(),
dominantHand,
turnStyle,
toggleRun.ToString()
};

string filePath = Path.Combine(Paths.PluginPath, "Settings.txt");
try
{
File.WriteAllLines(filePath, lines);
}
catch (Exception ex)
{
Plugin.LoggerInstance.LogError($"Failed to save Settings.txt: {ex.Message}");
return false;
}

return true;
}
}
}
53 changes: 25 additions & 28 deletions DFUVR/Var.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,18 @@ public static void Initialize()

try //to read the Settings.txt file
{
string fileContent = FileReader.ReadFromFile(filePath);
string[] lines = fileContent.Split('\n');
Debug.Log(lines[2].Trim());
var settings = Settings.LoadFromFile();
Debug.Log(settings.headsetType);

//using only a bool makes the settings file too hard to understand for most people
//bool.TryParse(lines[6], out leftHanded);
if (lines[6].Trim() == "left") { Var.leftHanded = true; }
if (settings.dominantHand == "left") { Var.leftHanded = true; }

//Set the bindings to the default Oculus Touch bindings
//This is not necessary. The default values are already set up for the Touch Controllers
//only if the player ist left handed, change the grip buttons
if (lines[2].Trim() == "Oculus/Meta")
string headset = settings.headsetType;
if (headset == "Oculus/Meta")
{
if (Var.leftHanded)
{
Expand All @@ -256,7 +257,7 @@ public static void Initialize()

}
//Set the bindings to the default HTC Vive Wand bindings
if (lines[2].Trim() == "HTC Vive Wands")
if (headset == "HTC Vive Wands")
{
left2Button = KeyCode.JoystickButton4;
left1Button = KeyCode.JoystickButton2;
Expand All @@ -273,7 +274,7 @@ public static void Initialize()

}
//FOr everything else, we try to let Unity figure it out. Doesn't work very well though and manual controller profiles are necessary for a playable experience
else if (lines[2].Trim() == "Other")
else if (headset == "Other")
{
isNotOculus = true;

Expand All @@ -296,19 +297,18 @@ public static void Initialize()
float targetTimeStep;
try
{
fileContent = FileReader.ReadFromFile(filePath);
//lines = fileContent.Split('\n');
Debug.Log("Line1:" + lines[0].Trim());
Debug.Log("Line2:" + lines[1].Trim());
Var.heightOffset = float.Parse(lines[0].Trim(),CultureInfo.InvariantCulture);
Plugin.LoggerInstance.LogInfo(Var.heightOffset);
targetTimeStep = 1f / float.Parse(lines[1].Trim());
Debug.Log("Line1:" + settings.heightOffset.ToString(CultureInfo.InvariantCulture));
Debug.Log("Line2:" + settings.headsetRefreshRate);
heightOffset = settings.heightOffset;
Plugin.LoggerInstance.LogInfo(heightOffset);
targetTimeStep = 1f / settings.headsetRefreshRate;
Plugin.LoggerInstance.LogInfo(targetTimeStep);

}
catch (Exception e)//if it doesn't work, set it to an emergency default value
{
Plugin.LoggerInstance.LogError("Made a fucky wucky while reading the file, oopsie! Error: " + e);
Plugin.LoggerInstance.LogError("Made a fucky wucky while reading the file, oopsie! Error: " + e.Message);
targetTimeStep = 1f / 90f;
}
try
Expand All @@ -331,21 +331,20 @@ public static void Initialize()
Time.fixedDeltaTime = targetTimeStep;
Plugin.LoggerInstance.LogInfo(Time.fixedDeltaTime);

string rawLine3 = lines[3].Trim();
Plugin.LoggerInstance.LogInfo(rawLine3);
string[] sheathVector = rawLine3.Split(',');
Plugin.LoggerInstance.LogInfo(settings.sheathOffset);
string[] sheathVector = settings.sheathOffset.Split(',');
float x = float.Parse(sheathVector[0], CultureInfo.InvariantCulture);
float y = float.Parse(sheathVector[1], CultureInfo.InvariantCulture);
float z = float.Parse(sheathVector[2], CultureInfo.InvariantCulture);
Plugin.LoggerInstance.LogInfo(x);
Var.sheathOffset=new Vector3(x,y,z);
bool.TryParse(lines[5], out fStartMenu);
fStartMenu = settings.showStartMenu;
//bool.TryParse(lines[6],out leftHanded);
Plugin.LoggerInstance.LogInfo("Offsett: "+Var.sheathOffset.ToString());
if (lines[7].Trim() == "smooth") { Var.smoothTurn = true;}
if (settings.turnStyle == "smooth") { Var.smoothTurn = true;}
Plugin.LoggerInstance.LogInfo("Smooth turn: "+Var.smoothTurn);
if (lines[7].Trim() == "none") { Var.noTurn = true; }
bool.TryParse(lines[8],out toggleRun);
if (settings.turnStyle == "none") { Var.noTurn = true; }
toggleRun = settings.toggleRun;


}
Expand All @@ -358,14 +357,12 @@ public static void Initialize()
//THis saves the players height in Settings.txt. Gets called after exiting calibration mode
public static void SaveHeight()
{
string filePath = Path.Combine(Paths.PluginPath, "Settings.txt");
string[] lines = File.ReadAllLines(filePath);
Settings settings = Settings.LoadFromFile();
settings.heightOffset = heightOffset;//Var.heightOffset.ToString();
settings.sheathOffset = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", sphereObject.transform.localPosition.x, sphereObject.transform.localPosition.y, sphereObject.transform.localPosition.z);//Var.sphereObject.transform.localPosition.ToString();//Var.sheathOffset.ToString();
settings.connectedJoysticks = connectedJoysticks;

lines[0] = string.Format(CultureInfo.InvariantCulture,"{0}", Var.heightOffset);//Var.heightOffset.ToString();
lines[3] = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", Var.sphereObject.transform.localPosition.x, Var.sphereObject.transform.localPosition.y, Var.sphereObject.transform.localPosition.z);//Var.sphereObject.transform.localPosition.ToString();//Var.sheathOffset.ToString();
lines[4] = connectedJoysticks.ToString();

File.WriteAllLines(filePath, lines);
settings.SaveToFile();
}
//deprecated. Ignore.
public static void SaveAxis()
Expand Down