Skip to content

Commit d4efc90

Browse files
authored
Merge pull request #40 from InfinaMii/linux-support
Fix file directories on Linux
2 parents 031b7f5 + e153fb5 commit d4efc90

File tree

7 files changed

+51
-15
lines changed

7 files changed

+51
-15
lines changed

Plugins/CafeLibrary/Bfres/Editing/ModelConversion/BfresModelImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ private static VertexBuffer GenerateVertexBuffer(ResFile resFile, IOMesh mesh, S
837837
binormal = System.Numerics.Vector3.TransformNormal(binormal, transform);
838838
}
839839
//Reset rigid skinning types to local space
840-
if (fshp.VertexSkinCount == 1)
840+
if (fshp.VertexSkinCount == 1 && vertex.Envelope.Weights.Count > 0)
841841
{
842842
int index = Array.FindIndex(fskl.Bones.Values.ToArray(), x => x.Name == vertex.Envelope.Weights[0].BoneName);
843843
if (index != -1)

Plugins/CafeLibrary/Bfres/PresetDumpScript/MaterialPresetDumper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public static void ExportMaterials(string gamePath)
2424

2525
//Just check for a mk8d specific asset
2626
bool isMK8D = File.Exists(Path.Combine(gamePath, "RaceCommon", "TS_PolicePackun", "TS_PolicePackun.bfres"));
27-
28-
string game_folder = gamePath;
27+
2928
dir = isMK8D ? Path.Combine(dir, "MK8D") : Path.Combine(dir, "MK8U");
3029

3130
if (Directory.Exists(dir))
@@ -72,7 +71,7 @@ public static void ExportMaterials(string gamePath)
7271

7372
//Dump each preset into the preset folder
7473
foreach (var preset in presets)
75-
DumpBfresMaterials(Path.Combine(game_folder, preset.Key), preset.Value.ToArray());
74+
DumpBfresMaterials(Path.Combine(gamePath, preset.Key), preset.Value.ToArray());
7675

7776
ProcessLoading.Instance.Update(100, 100, "Dumping game material presets!");
7877
ProcessLoading.Instance.IsLoading = false;

Plugins/DirectXTexLibrary/TextureDecoder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,16 @@ public static unsafe byte[] DecompressBlock(Byte[] data, int width, int height,
101101
{
102102
long inputRowPitch;
103103
long inputSlicePitch;
104-
TexHelper.Instance.ComputePitch((DXGI_FORMAT)format, width, height, out inputRowPitch, out inputSlicePitch, CP_FLAGS.NONE);
104+
105+
try
106+
{
107+
TexHelper.Instance.ComputePitch((DXGI_FORMAT)format, width, height, out inputRowPitch, out inputSlicePitch, CP_FLAGS.NONE);
108+
}
109+
catch (Exception e)
110+
{
111+
Console.WriteLine(e);
112+
return null;
113+
}
105114

106115
DXGI_FORMAT FormatDecompressed;
107116

Plugins/TurboLibrary/FileData/Muunt/MapObj/Obj.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,18 @@ public static string GetResourceName(int objectID)
462462
public static string FindFilePath(string resName)
463463
{
464464
//Common path for common race objects like coins
465-
string raceObjects = GlobalSettings.GetContentPath(System.IO.Path.Combine("race_common",resName,$"{resName}.bfres"));
466465
string raceObjectsDX = GlobalSettings.GetContentPath(System.IO.Path.Combine("RaceCommon",resName,$"{resName}.bfres"));
467-
466+
if (File.Exists(raceObjectsDX)) return raceObjectsDX;
467+
468468
//The typical path for the base game map objects
469-
string mapObjects = GlobalSettings.GetContentPath(System.IO.Path.Combine("mapobj",resName,$"{resName}.bfres"));
470469
string mapObjectsDX = GlobalSettings.GetContentPath(System.IO.Path.Combine("MapObj",resName,$"{resName}.bfres"));
471-
472-
if (File.Exists(raceObjects)) return raceObjects;
473-
if (File.Exists(raceObjectsDX)) return raceObjectsDX;
474470
if (File.Exists(mapObjectsDX)) return mapObjectsDX;
471+
472+
//Same as above, but for MK8U
473+
string raceObjects = GlobalSettings.GetContentPath(System.IO.Path.Combine("race_common",resName,$"{resName}.bfres"));
474+
if (File.Exists(raceObjects)) return raceObjects;
475+
476+
string mapObjects = GlobalSettings.GetContentPath(System.IO.Path.Combine("mapobj",resName,$"{resName}.bfres"));
475477
if (File.Exists(mapObjects)) return mapObjects;
476478

477479
return string.Empty;

Plugins/TurboLibrary/GlobalSettings.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.IO;
5+
using System.Runtime.InteropServices;
46
using System.Text;
57
using System.Threading.Tasks;
68
using OpenTK;
@@ -55,6 +57,21 @@ public static void LoadDataBase()
5557
/// </summary>
5658
public static string GetContentPath(string relativePath)
5759
{
60+
//if using linux, change directory case for MK8D
61+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && IsMK8D)
62+
{
63+
var dirs = relativePath.Split('/');
64+
relativePath = "";
65+
for (int i = 0; i < dirs.Length - 1; i++)
66+
relativePath +=
67+
(char.IsLower(dirs[i][0])
68+
? dirs[i].Substring(1, dirs[i].Length - 1)
69+
.Insert(0, char.ToUpper(dirs[i][0]).ToString())
70+
: dirs[i])
71+
+ "/";
72+
relativePath += dirs[^1];
73+
}
74+
5875
//Update first then base package.
5976
if (File.Exists(System.IO.Path.Combine(ModOutputPath,relativePath))) return System.IO.Path.Combine(ModOutputPath,relativePath);
6077
if (File.Exists(System.IO.Path.Combine(UpdatePath,relativePath))) return System.IO.Path.Combine(UpdatePath,relativePath);

Plugins/TurboLibrary/PluginConfig.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
using System.Linq;
44
using System.Numerics;
55
using System.IO;
6+
using System.Runtime.InteropServices;
67
using Newtonsoft.Json;
78
using ImGuiNET;
89
using MapStudio.UI;
910
using Toolbox.Core;
11+
using Toolbox.Core.IO;
1012

1113
namespace TurboLibrary
1214
{
@@ -85,16 +87,23 @@ public void Save() {
8587
Reload();
8688
}
8789

90+
public static bool IsValidGamePath(string path)
91+
{
92+
if (File.Exists(System.IO.Path.Combine(path,"data","objflow.byaml"))) return true;
93+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && File.Exists(System.IO.Path.Combine(path,"Data","objflow.byaml"))) return true;
94+
return false;
95+
}
96+
8897
/// <summary>
8998
/// Called when the config file has been loaded or saved.
9099
/// </summary>
91100
public void Reload()
92101
{
93102
TurboLibrary.GlobalSettings.GamePath = MK8DGamePath;
94-
HasValidMK8DPath = File.Exists(System.IO.Path.Combine(MK8DGamePath,"Data","objflow.byaml"));
95-
103+
HasValidMK8DPath = IsValidGamePath(MK8DGamePath);
104+
96105
TurboLibrary.GlobalSettings.UpdatePath = MK8DUpdatePath;
97-
HasValidMK8UpdatePath = File.Exists(System.IO.Path.Combine(MK8DUpdatePath,"Data","objflow.byaml"));
106+
HasValidMK8UpdatePath = IsValidGamePath(MK8DUpdatePath);
98107

99108
TurboLibrary.GlobalSettings.AOCPath = MK8AOCPath;
100109
HasValidMK8AOCPath = Directory.Exists(System.IO.Path.Combine(MK8AOCPath,"0013","course")); //Just check one of the dlc folders

0 commit comments

Comments
 (0)