Skip to content

Commit

Permalink
Added ForcesModLoader
Browse files Browse the repository at this point in the history
Updated ForcesCodeLoader to v4.0 which Adds a ModLoader
Removed PrepareCPK
Added code to remove wars_mods.cpk, As its nolonger needed
  • Loading branch information
thesupersonic16 committed Dec 9, 2017
1 parent 917f2d0 commit 8a03d55
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 103 deletions.
Binary file modified HedgeModManager/res/codes/ForcesCodeLoader.dll
Binary file not shown.
101 changes: 2 additions & 99 deletions HedgeModManager/src/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,108 +197,11 @@ public void SaveModDB()
CodeLoader.SaveCodesAndPatches(ModsDb, LoadedCodes);
// Saves and refreshes the mod list
ModsDb.SaveModsDb(ModsDbPath);
// TODO
if (Program.CurrentGame == Games.SonicForces)
{
string CPKMakerDLLExecPath = Path.Combine(Program.StartDirectory, "CpkMaker.dll");
string CPKMakerDLLDiskPath = Path.Combine($@"{Program.StartDirectory}\..\..\..\..\image\x64\disk\", "CpkMaker.dll");
CPK cpk = null;
if (File.Exists(CPKMakerDLLExecPath) || File.Exists(CPKMakerDLLDiskPath))
cpk = new CPKMakerCRI(File.Exists(CPKMakerDLLExecPath) ? CPKMakerDLLExecPath : CPKMakerDLLDiskPath);
else
cpk = new CPKSAL();

PrepareCPK(cpk);
if (cpk.FileCount > 0)
{
LogFile.AddMessage($@"Writing CPK to {Program.StartDirectory}\..\..\..\..\image\x64\disk\wars_mods.cpk");
cpk.Pack($@"{Program.StartDirectory}\..\..\..\..\image\x64\disk\wars_mods.cpk");
}else
{
if (File.Exists($@"{Program.StartDirectory}\..\..\..\..\image\x64\disk\wars_mods.cpk"))
File.Delete($@"{Program.StartDirectory}\..\..\..\..\image\x64\disk\wars_mods.cpk");
}
}
if (File.Exists($@"{Program.StartDirectory}\..\..\..\..\image\x64\disk\wars_mods.cpk"))
File.Delete($@"{Program.StartDirectory}\..\..\..\..\image\x64\disk\wars_mods.cpk");
RefreshModsList();
}

// Sonic Forces Prepare CPK
public void PrepareCPK(CPK cpk)
{
// wars_0
for (int i = 0; i < ModsList.CheckedItems.Count; ++i)
{
var mod = ModsList.CheckedItems[i].Tag as Mod;
string dir = $@"{Program.StartDirectory}/mods/{Path.GetFileName(mod.RootDirectory)}/disk/wars_0";
if (!Directory.Exists(dir))
continue;
cpk.AddFilesFromDirectory(dir);
}
// wars_1
for (int i = 0; i < ModsList.CheckedItems.Count; ++i)
{
var mod = ModsList.CheckedItems[i].Tag as Mod;
string dir = $@"{Program.StartDirectory}/mods/{Path.GetFileName(mod.RootDirectory)}/disk/wars_1";
if (!Directory.Exists(dir))
continue;
cpk.AddFilesFromDirectory(dir);
}
// wars_patch
for (int i = 0; i < ModsList.CheckedItems.Count; ++i)
{
var mod = ModsList.CheckedItems[i].Tag as Mod;
string dir = $@"{Program.StartDirectory}/mods/{Path.GetFileName(mod.RootDirectory)}/disk/wars_patch";
if (!Directory.Exists(dir))
continue;
cpk.AddFilesFromDirectory(dir);
}

for (int i = 0; i < ModsList.CheckedItems.Count; ++i)
{
var mod = ModsList.CheckedItems[i].Tag as Mod;
var ini = mod.GetIniFile();
if (!ini.ContainsGroup("CPKs"))
continue;
for (int ii = 0; ii < ini["CPKs"].ParameterCount; ++ii)
{
// Don't really need this.
string cpkPath = Path.Combine($@"{Program.StartDirectory}\..\..\..\..\",
Path.ChangeExtension(ini["CPKs"][ii].Value, ".cpk"));
string iniPath = Path.Combine($@"{Program.StartDirectory}\mods\{Path.GetFileName(mod.RootDirectory)}\", ini["CPKs"][ii].Value);
var cpkIni = new IniFile(iniPath);

// Commands stuff
var commands = new Dictionary<string, string>();
var main = cpkIni["Main"];
int commandCount = int.Parse(main["CommandCount"]);
for (int iii = 0; iii < commandCount; ++iii)
{
string value = main[$"Command{iii}"];
commands.Add(value.Split(':')[1], value.Split(':')[0]);
}

// TODO
foreach (var pair in commands)
{
var group = cpkIni[pair.Key];
for (int iiii = 0; iiii < group.ParameterCount; ++iiii)
{
if (pair.Value == "Add")
{
string modRootPath = $@"{Program.StartDirectory}\mods\{Path.GetFileName(mod.RootDirectory)}\";
string filePath = Path.Combine($@"{Program.StartDirectory}\mods\{Path.GetFileName(mod.RootDirectory)}\", group[iiii].Key);
if (Path.HasExtension(filePath))
cpk.AddFile(modRootPath, filePath);
else
cpk.AddFilesFromDirectory(new DirectoryInfo(filePath).Parent.FullName);
}
}
}
}

}
}

public void LoadConfig()
{
// Writes "cpkredir.ini" if it doesn't exists as HedgeModManager uses it to store its config
Expand Down
7 changes: 4 additions & 3 deletions HedgeModManager/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Input;

namespace HedgeModManager
{
Expand All @@ -18,7 +19,7 @@ internal static class Program
public static Game CurrentGame = Games.Unknown;
public const string ProgramName = "Hedge Mod Manager";
public const string ProgramNameShort = "HedgeModManager";
public const string VersionString = "6.1-013";
public const string VersionString = "6.1-014";
public const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36";
public static bool Restart = false;

Expand Down Expand Up @@ -85,9 +86,9 @@ private static void Main(string[] args)
LogFile.Initialize();
LogFile.AddMessage($"Starting {ProgramName} (v{VersionString})...");

#if DEBUG
#if DEBUG
StartDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\SonicForces\build\main\projects\exec";
#endif
#endif

LogFile.AddMessage($"Running {ProgramName} in {StartDirectory}");

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '6.1-013_r{build}'
version: '6.1-014_r{build}'

environment:
matrix:
Expand Down

0 comments on commit 8a03d55

Please sign in to comment.