Skip to content

Commit

Permalink
Various fixes and improvements for Packaged environments
Browse files Browse the repository at this point in the history
  • Loading branch information
MadDeCoDeR committed Jun 26, 2023
1 parent eaeed1b commit 5947b45
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CRBDL/Arguments/ArgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,19 @@ public static string ParseArgsFromSettings(Stream stream)
}
return hargs + args;
}

public static bool IsNewArgument(string arg)
{
bool result = arg.Equals("+set");
if (!result )
{
if (arg.Length> 1)
{
result = arg[0] == '-' && int.TryParse(arg.Substring(1), out int test);
}
}

return result;
}
}
}
14 changes: 14 additions & 0 deletions CRBDL/CDL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace CDL
{
Expand Down Expand Up @@ -129,5 +130,18 @@ public void LaunchGame(string args)
crbd.StartInfo.Arguments = args; // if you need some
this.isRunning = crbd.Start();
}

public void LaunchAndWaitGame(string args)
{
this.LaunchGame(args);
Task task = Task.Run(() => {
while (this.isRunning)
{
Thread.Sleep(4000);
}
});

Task.WaitAny(task);
}
}
}
24 changes: 21 additions & 3 deletions CRBDL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,34 @@ static void Main(string[] args)
string path = "";
if (pathIndex != -1)
{
path = eargs[pathIndex + 1];
int index = 1;
while (!ArgParser.IsNewArgument(eargs[pathIndex + index]))
{
path += " " + eargs[pathIndex + index];
index++;
if ((pathIndex + index) >= eargs.Length)
{
break;
}
}
path = path.Trim().Replace('\"', ' ').Trim();
}
CDL.CDL cdl = new CDL.CDL(new UFS(true, path));
UFS ufs = new UFS(true, path);
CDL.CDL cdl = new CDL.CDL(ufs);
if (cdl.CheckFiles() == 0)
{
Console.WriteLine("Main Executable not found");
throw new Exception("Main Executable not found");
}
Console.WriteLine(largs);
cdl.LaunchGame(largs);
if (ufs.isRunningPackaged())
{
cdl.LaunchAndWaitGame(largs);
}
else
{
cdl.LaunchGame(largs);
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions CRBDL/filesystem/UFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public UFS(bool waitThread = false, string selectedPath = "")
if (selectedPath.Length > 0)
{
this.selectedPath = selectedPath;
this.paths.Add(selectedPath);
string filePath = selectedPath + GetPathSeparator() + "base" + GetPathSeparator() + "_common.resources";
byte[] data = File.ReadAllBytes(filePath);
string fileSha256 = BitConverter.ToString(sHA256.ComputeHash(data)).ToUpper().Replace("-", "");
if (fileSha256.Equals(SHA256s[0]) )
{
BFGPaths.Add(selectedPath);
}
else if (fileSha256.Equals(SHA256s[1]))
{
NewD3Paths.Add(selectedPath);
}
}
else
{
Expand Down

0 comments on commit 5947b45

Please sign in to comment.