Skip to content

Commit

Permalink
Merge pull request #10 from n1neb4ll/master
Browse files Browse the repository at this point in the history
Fixed hardcoded file locations to be mac friendly!
  • Loading branch information
Morphyum authored Jun 5, 2018
2 parents 08c5f89 + 70382da commit 31fa277
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
12 changes: 7 additions & 5 deletions ClassLibrary2/CommanderPortraitLoader.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

namespace CommanderPortraitLoader {
public static class CommanderPortraitLoader {
internal static string ModDirectory;

public static void Init() {
public static void Init(string directory, string settingsJSON) {
var harmony = HarmonyInstance.Create("de.morphyum.CommanderPortraitLoader");
var original = typeof(PilotRepresentation).GetMethod("PlayPilotVO");
var genericMethod = original.MakeGenericMethod(new Type[] { typeof(AudioSwitch_dialog_lines_pilots) });
var transpiler = typeof(PilotRepresentation_PlayPilotVO_Patch).GetMethod("Transpiler");
harmony.Patch(genericMethod, null, null, new HarmonyMethod(transpiler));
harmony.PatchAll(Assembly.GetExecutingAssembly());
ModDirectory = directory;
CreateJsons();
AddOrUpdateJSONToManifest();
HBS.SceneSingletonBehavior<WwiseManager>.Instance.LoadBank((AudioBankList)Enum.Parse(typeof(AudioBankList), "vo_f_kamea", true));
Expand All @@ -27,7 +29,7 @@ public static void Init() {

public static void CreateJsons() {
try {
string filePath = "mods/CommanderPortraitLoader/Portraits/";
string filePath = $"{ CommanderPortraitLoader.ModDirectory}/Portraits/";
DirectoryInfo d1 = new DirectoryInfo(filePath);
FileInfo[] f1 = d1.GetFiles("*.png");
foreach (FileInfo info in f1) {
Expand All @@ -53,8 +55,8 @@ public static void CreateJsons() {

private static void AddOrUpdateJSONToManifest() {
try {
string filePath = "mods/CommanderPortraitLoader/Portraits/";
VersionManifest manifest = VersionManifestUtilities.ManifestFromCSV("mods/CommanderPortraitLoader/VersionManifest.csv");
string filePath = $"{ CommanderPortraitLoader.ModDirectory}/Portraits/";
VersionManifest manifest = VersionManifestUtilities.ManifestFromCSV($"{ CommanderPortraitLoader.ModDirectory}/VersionManifest.csv");
DirectoryInfo d1 = new DirectoryInfo(filePath);
FileInfo[] f1 = d1.GetFiles("*.png");
foreach (VersionManifestEntry entry in manifest.Entries) {
Expand All @@ -75,7 +77,7 @@ private static void AddOrUpdateJSONToManifest() {
}
manifest.AddOrUpdate(preset.Description.Id, info.FullName, "PortraitSettings", DateTime.Now, null, false);
}
VersionManifestUtilities.ManifestToCSV(manifest, "mods/CommanderPortraitLoader/VersionManifest.csv");
VersionManifestUtilities.ManifestToCSV(manifest, $"{ CommanderPortraitLoader.ModDirectory}/VersionManifest.csv");
}
catch (Exception e) {
Logger.LogError(e);
Expand Down
2 changes: 1 addition & 1 deletion ClassLibrary2/Helper.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static List<string> GetAbilityDefsForSkill(string[][] abilityDefConsts, i
{
try
{
using (StreamReader r = new StreamReader("mods/CommanderPortraitLoader/settings.json"))
using (StreamReader r = new StreamReader($"{ CommanderPortraitLoader.ModDirectory}/settings.json"))
{
string json = r.ReadToEnd();
return JsonConvert.DeserializeObject<Settings>(json);
Expand Down
Empty file modified ClassLibrary2/HolderClasses.cs
100644 → 100755
Empty file.
7 changes: 3 additions & 4 deletions ClassLibrary2/Logger.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

namespace CommanderPortraitLoader {
public class Logger {
static string filePath = $"{CommanderPortraitLoader.ModDirectory}/Log.txt";
public static void LogError(Exception ex) {
string filePath = "mods/CommanderPortraitLoader/Log.txt";
using (StreamWriter writer = new StreamWriter(filePath, true)) {
using (var writer = new StreamWriter(filePath, true)) {
writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
"" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
}
}

public static void LogLine(String line) {
string filePath = "mods/CommanderPortraitLoader/Log.txt";
using (StreamWriter writer = new StreamWriter(filePath, true)) {
using (var writer = new StreamWriter(filePath, true)) {
writer.WriteLine(line + Environment.NewLine + "Date :" + DateTime.Now.ToString());
writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
}
Expand Down
8 changes: 4 additions & 4 deletions ClassLibrary2/Patch.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void Postfix(RenderedPortraitResult __instance, ref Texture2D __result) {
if (!string.IsNullOrEmpty(__instance.settings.Description.Icon)) {
try {
Texture2D texture2D = new Texture2D(2, 2);
byte[] array = File.ReadAllBytes("mods/CommanderPortraitLoader/Portraits/" + __instance.settings.Description.Icon + ".png");
byte[] array = File.ReadAllBytes($"{ CommanderPortraitLoader.ModDirectory}/Portraits/" + __instance.settings.Description.Icon + ".png");
texture2D.LoadImage(array);
__result = texture2D;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ static void Postfix(ref PilotDef __instance, ref Sprite __result) {
try {
if (__result == null) {
Texture2D texture2D2 = new Texture2D(2, 2);
byte[] data = File.ReadAllBytes("mods/CommanderPortraitLoader/Portraits/" + __instance.Description.Icon + ".png");
byte[] data = File.ReadAllBytes($"{ CommanderPortraitLoader.ModDirectory}/Portraits/" + __instance.Description.Icon + ".png");
texture2D2.LoadImage(data);
Sprite sprite = new Sprite();
sprite = Sprite.Create(texture2D2, new Rect(0f, 0f, (float)texture2D2.width, (float)texture2D2.height), new Vector2(0f, 0f), 100f);
Expand All @@ -98,7 +98,7 @@ static void Postfix(ref PilotDef __instance, ref Sprite __result) {
try {
if (__result == null) {
Texture2D texture2D2 = new Texture2D(2, 2);
byte[] data = File.ReadAllBytes("mods/CommanderPortraitLoader/Portraits/" + __instance.Description.Icon + ".png");
byte[] data = File.ReadAllBytes($"{ CommanderPortraitLoader.ModDirectory}/Portraits/" + __instance.Description.Icon + ".png");
texture2D2.LoadImage(data);
Sprite sprite = new Sprite();
sprite = Sprite.Create(texture2D2, new Rect(0f, 0f, (float)texture2D2.width, (float)texture2D2.height), new Vector2(0f, 0f), 100f);
Expand All @@ -115,7 +115,7 @@ static void Postfix(ref PilotDef __instance, ref Sprite __result) {
public static class VersionManifestUtilitiesPatch {
public static void Postfix(ref VersionManifest __result) {
try {
var addendum = VersionManifestUtilities.ManifestFromCSV("mods/CommanderPortraitLoader/VersionManifest.csv");
var addendum = VersionManifestUtilities.ManifestFromCSV($"{ CommanderPortraitLoader.ModDirectory}/VersionManifest.csv");
foreach (var entry in addendum.Entries) {
__result.AddOrUpdate(entry.Id, entry.FilePath, entry.Type, entry.AddedOn, entry.AssetBundleName, entry.IsAssetBundlePersistent);
}
Expand Down
Empty file modified ClassLibrary2/ReflectionHelper.cs
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Name": "CommanderPortraitLoader",
"Enabled": true,

"Version": "0.6.3",
"Description": "Loads your custom PNGs as a Commander avatar and allows voice selection.",
"Author": "Morphyum & Callyste",
"Website": "https://github.com/Morphyum/CommanderPortraitLoader",
"Contact": "",

"DLL": "CommanderPortraitLoader.dll",
}

0 comments on commit 31fa277

Please sign in to comment.