Skip to content
Draft
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
24 changes: 12 additions & 12 deletions ArcherLoaderMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<OutputPath Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">D:\Games\TowerFall-FortRise\Mods\$(AssemblyName)</OutputPath>
<OutputPath Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">D:\Games\TowerFall-FortRise\Mods\$(AssemblyName)-Debug</OutputPath>
<OutputPath Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">..\..\Mods\$(AssemblyName)</OutputPath>
<OutputPath Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">..\..\Mods\$(AssemblyName)-Debug</OutputPath>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,28 +30,28 @@


<ItemGroup>
<Reference Include="0Harmony, Version=2.2.2.0, Culture=neutral, PublicKeyToken=null">
<HintPath>D:\Games\TowerFall-FortRise\0Harmony.dll</HintPath>
<Reference Include="0Harmony">
<HintPath>..\..\0Harmony.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="FNA, Version=20.12.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>D:\Games\TowerFall-FortRise\FNA.dll</HintPath>
<Reference Include="FNA">
<HintPath>..\..\FNA.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="MMHOOK_TowerFall">
<HintPath>D:\Games\TowerFall-FortRise\MMHOOK_TowerFall.dll</HintPath>
<HintPath>..\..\MMHOOK_TowerFall.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="MonoMod.RuntimeDetour, Version=22.7.31.1, Culture=neutral, PublicKeyToken=null">
<HintPath>D:\Games\TowerFall-FortRise\MonoMod.RuntimeDetour.dll</HintPath>
<Reference Include="MonoMod.RuntimeDetour">
<HintPath>..\..\MonoMod.RuntimeDetour.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="MonoMod.Utils, Version=22.7.31.1, Culture=neutral, PublicKeyToken=null">
<HintPath>D:\Games\TowerFall-FortRise\MonoMod.Utils.dll</HintPath>
<Reference Include="MonoMod.Utils">
<HintPath>..\..\MonoMod.Utils.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="TowerFall">
<HintPath>D:\Games\TowerFall-FortRise\TowerFall.exe</HintPath>
<HintPath>..\..\TowerFall.exe</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
Expand Down
18 changes: 0 additions & 18 deletions FortEntrance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@ private void OnPreInitialize()
}
}

// Harmony can be supported

//[HarmonyPatch(typeof(MainMenu), "BoolToString")]
//public class MyPatcher
//{
// static void Postfix(ref string __result)
// {
// if (__result == "ON")
// {
// __result = "ENABLED";
// return;
// }

// __result = "DISABLED";
// }
//}


/*
Example of interppting with libraries
Learn more: https://github.com/MonoMod/MonoMod/blob/master/README-ModInterop.md
Expand Down
119 changes: 77 additions & 42 deletions Mod.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection;
using System.Xml;
using ArcherLoaderMod.Ghost;
using ArcherLoaderMod.Hair;
Expand All @@ -17,6 +12,7 @@
using ArcherLoaderMod.Teams;
using ArcherLoaderMod.Wings;
using FortRise;
using FortRise.IO;
using Monocle;
using MonoMod.ModInterop;
using MonoMod.Utils;
Expand Down Expand Up @@ -86,11 +82,11 @@ public static void Load()
PortraitLayerPatch.Load();
PrismaticPatcher.Load();
TeamsPatcher.Load();
RiseCore.Events.OnAfterModdedLoadContent += OnAfterLoadContent;

HandleQuickStart();
}


private static void HandleQuickStart()
{
if (!FortEntrance.Settings.QuickStart) return;
Expand Down Expand Up @@ -141,19 +137,24 @@ void OnMainMenuOnUpdate(On.TowerFall.MainMenu.orig_Update orig, MainMenu self)

On.TowerFall.MainMenu.Update += OnMainMenuOnUpdate;
}
public static void LoadArcherContents()

private static void OnAfterLoadContent(FortContent content)
{
allCustomArchers.AddRange(LoadContentAtPath($"{Calc.LOADPATH}{_contentCustomArchersPath}", ContentAccess.Content));
var contentPath = Content.GetContentPath("");
allCustomArchers.AddRange(LoadContentAtPath(contentPath+$"/{_customArchersPath}", ContentAccess.ModContent));
allCustomArchers.AddRange(LoadContentAtPath($"{_customArchersPath}", ContentAccess.Root));
allCustomArchers.AddRange(LoadContentAtPath(contentPath.Replace("/Content", "")+$"/{_customArchersPath}", ContentAccess.Root));
// allCustomArchers.AddRange(LoadContentAtPath(Content.GetContentPath("").Replace("/Content", ""), ContentAccess.Root));

string archerFolder = Path.Combine(content.MetadataPath, "Content", "Archers");

if (ModIO.IsDirectoryOrFileExists(archerFolder))
{
List<ArcherCustomData> archerData = LoadContentAtPath(content, archerFolder, ContentAccess.ModContent, true);
allCustomArchers.AddRange(archerData);
}
}

public static void Start()
{
allCustomArchers.AddRange(LoadContentAtPath(null, $"{Calc.LOADPATH}{_contentCustomArchersPath}", ContentAccess.Content));
allCustomArchers.AddRange(LoadContentAtPath(null, $"{_customArchersPath}", ContentAccess.Root));

var newNormalCustom = allCustomArchers.FindAll(a => a.ArcherType == ArcherData.ArcherTypes.Normal);
var newAltCustom = allCustomArchers.FindAll(a => a.ArcherType == ArcherData.ArcherTypes.Alt);
var newSecretCustom = allCustomArchers.FindAll(a => a.ArcherType == ArcherData.ArcherTypes.Secret);
Expand Down Expand Up @@ -363,24 +364,30 @@ private static void LoadAltArcher(List<ArcherCustomData> newAltCustom, Dictionar
}
}

private static List<ArcherCustomData> LoadContentAtPath(string path, ContentAccess contentAccess, bool warnNotFound = true)
private static List<ArcherCustomData> LoadContentAtPath(FortContent content, string path, ContentAccess contentAccess, bool warnNotFound = true)
{
var allCustomArchers = new List<ArcherCustomData>();
if (!Directory.Exists(path))
if (!ModIO.IsDirectoryOrFileExists(path))
{
if(warnNotFound)
Console.WriteLine($"\nNo Archer Found in \"{path}\" Folder");
return allCustomArchers;
}

var customArchersFound = Directory.GetDirectories(path);
var customArchersFound = ModIO.GetDirectories(path);

foreach (var directory in customArchersFound)
{
// if(directory.EndsWith("Content"))
// continue;

if (contentAccess == ContentAccess.ModContent)
{
allCustomArchers.AddRange(LoadContent(content, directory, contentAccess, contentAccess == ContentAccess.Content));
continue;
}

allCustomArchers.AddRange(LoadContent(Content, directory, contentAccess, contentAccess == ContentAccess.Content));
allCustomArchers.AddRange(LoadContent(null, directory, contentAccess, contentAccess == ContentAccess.Content));
}

if (warnNotFound && allCustomArchers.Count == 0)
Expand Down Expand Up @@ -409,34 +416,50 @@ private static List<ArcherCustomData> LoadContentAtPath(string path, ContentAcce
private static List<ArcherCustomData> LoadContent(FortContent content, string directory, ContentAccess contentAccess, bool addContentPrefix = false)
{
var newArchers = new List<ArcherCustomData>();
newArchers.AddRange(LoadContentAtPath(directory, contentAccess, false));

var archerName = directory.Split(Convert.ToChar(_separator)).Last();
var path = $"{directory}{_separator}".Replace($"Content{_separator}", $"");
var pathModContentFolder = false;
if (contentAccess == ContentAccess.ModContent)
{
path = path.Replace(Content.GetContentPath(), "");
path = Content.GetContentPath() + path;
contentAccess = ContentAccess.Root;
}

var pathWithContentPrefix = addContentPrefix ? Calc.LOADPATH + path : path;
var path = directory + "/";


Atlas atlas = null;
if (File.Exists($"{pathWithContentPrefix}atlas.xml") && File.Exists($"{pathWithContentPrefix}atlas.png"))
if (ModIO.IsDirectoryOrFileExists($"{path}atlas.xml") &&
ModIO.IsDirectoryOrFileExists($"{path}atlas.png"))
{
atlas = content.CreateAtlas($"{path}atlas.xml", $"{path}atlas.png", true, contentAccess);
atlas = AtlasExt.CreateAtlas($"{path}atlas.xml", $"{path}atlas.png");
customAtlasList.Add(atlas);
}
else
{
// we fallback to the main atlas, incase the user uses the standard mod pathing.
atlas = TFGame.Atlas;
customAtlasList.Add(atlas);
}

if (!File.Exists($"{pathWithContentPrefix}spriteData.xml") || atlas == null)
// we'll need to provide a fallback for SpriteData as well, but due to how differs
// the spriteData is on ArcherLoader, this is not possible.
SpriteData spriteData;
SpriteData spriteData2;
if (!ModIO.IsDirectoryOrFileExists($"{path}spriteData.xml"))
{
// So, we might need to load it separately if it exists
var archerSpriteDataPath = Path.Combine(content.MetadataPath, "Content", "Atlas", "SpriteData", "spriteData.xml");
if (ModIO.IsDirectoryOrFileExists(archerSpriteDataPath))
{
spriteData = SpriteDataExt.CreateSpriteData(archerSpriteDataPath, atlas);
spriteData2 = TFGame.SpriteData;
}
else
{
// Well, everything's invalid anyway
return newArchers;
}
}
else
{
return newArchers;
spriteData = SpriteDataExt.CreateSpriteData($"{path}spriteData.xml", atlas);
spriteData2 = spriteData;
}

var spriteData = content.CreateSpriteData($"{path}spriteData.xml", atlas, contentAccess);
var sprites = DynamicData.For(spriteData).Get<Dictionary<string, XmlElement>>("sprites");

if (sprites.Count > 0)
Expand Down Expand Up @@ -469,20 +492,30 @@ private static List<ArcherCustomData> LoadContent(FortContent content, string di

var atlasArcherMenu = atlas;
SpriteData spriteDataMenu = spriteData;
if (File.Exists($"{pathWithContentPrefix}menuAtlas.xml") &&
File.Exists($"{pathWithContentPrefix}menuAtlas.png"))
if (ModIO.IsDirectoryOrFileExists($"{path}menuAtlas.xml") &&
ModIO.IsDirectoryOrFileExists($"{path}menuAtlas.png"))
{
atlasArcherMenu = content.CreateAtlas($"{path}menuAtlas.xml", $"{path}menuAtlas.png", true, contentAccess);
atlasArcherMenu = AtlasExt.CreateAtlas($"{path}menuAtlas.xml", $"{path}menuAtlas.png");
customAtlasList.Add(atlasArcherMenu);
spriteDataMenu = content.CreateSpriteData($"{path}menuSpriteData.xml", atlasArcherMenu, contentAccess);
spriteDataMenu = SpriteDataExt.CreateSpriteData($"{path}menuSpriteData.xml", atlasArcherMenu);
customSpriteDataList.Add(spriteDataMenu);
customSpriteDataPath.Add(spriteDataMenu, $"{path}menuSpriteData.xml");
}
else
{
// we fallback if atlas does not exists incase if the user uses the standard mod loading.
// we would likely need to fallback the spriteData correctly since this is tied to the
// menuAtlas.png but for now, this should work
atlasArcherMenu = TFGame.MenuAtlas;
customAtlasList.Add(atlasArcherMenu);
spriteDataMenu = TFGame.MenuSpriteData;
customSpriteDataList.Add(spriteDataMenu);
}

var filePath = $"{pathWithContentPrefix}archerData.xml";
if (!File.Exists(filePath)) return newArchers;
var filePath = $"{path}archerData.xml";
if (!ModIO.IsDirectoryOrFileExists(filePath)) return newArchers;
var newArchersFromPack =
InitializeArcherData(pathWithContentPrefix, atlas, atlasArcherMenu, spriteData, spriteDataMenu, archerName.ToUpper());
InitializeArcherData(path, atlas, atlasArcherMenu, spriteData2, spriteDataMenu, archerName.ToUpper());
return newArchersFromPack;
}

Expand Down Expand Up @@ -615,6 +648,8 @@ public static void Unload()
PortraitLayerPatch.Unload();
PrismaticPatcher.Unload();
TeamsPatcher.Unload();

RiseCore.Events.OnAfterModdedLoadContent -= OnAfterLoadContent;
}

public static void OnVariantsRegister(VariantManager variants, bool noPerPlayer = false)
Expand Down
11 changes: 4 additions & 7 deletions Source/ArcherCustomData/ArcherCustomData.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml;
using ArcherLoaderMod.Hair;
using ArcherLoaderMod.Layer;
using ArcherLoaderMod.Layers;
using ArcherLoaderMod.Particles;
using ArcherLoaderMod.Source.Layers.PortraitLayers;
using FortRise;
using Microsoft.Xna.Framework;
using Monocle;
using TowerFall;

namespace ArcherLoaderMod
{
public class ArcherCustomData
public class ArcherCustomData
{
public string ID;
public int Order;
Expand Down Expand Up @@ -503,7 +500,7 @@ public void HandleSFX(XmlElement xml, ArcherData archerData = null)
}

var originalAudiosPath = Audio.LOAD_PREFIX;
Audio.LOAD_PREFIX = $"{FolderPath}SFX{Path.DirectorySeparatorChar.ToString()}";
Audio.LOAD_PREFIX = $"{FolderPath}SFX{Path.DirectorySeparatorChar}";
CharacterSounds = new CharacterSounds(sfxName, Sounds.Characters[SFXID]);
Mod.customSFXList.Add(CharacterSounds);
victory = CharacterSounds.Load("VICTORY");
Expand Down
9 changes: 4 additions & 5 deletions Source/ArcherCustomData/ArcherCustomManager.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml;
using FortRise.IO;
using Monocle;
using TowerFall;

namespace ArcherLoaderMod
{
public class ArcherCustomManager
public class ArcherCustomManager
{
public static ArcherCustomDataValidator validator;

public static List<ArcherCustomData> Initialize(string path, Atlas atlas, Atlas menuAtlas, SpriteData spriteData, SpriteData menuSpriteData, string archerId, bool validate = false)
{
var filePath = $"{path}archerData.xml";
var xmlDocument = Calc.LoadXML(filePath);
var xmlDocument = ModIO.LoadXml(filePath);
var archers = xmlDocument["Archers"];
var archersArray = new List<ArcherCustomData>();
validator ??= new ArcherCustomDataValidator();
Expand Down
1 change: 0 additions & 1 deletion Source/Patch/ContentLoaderPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static void Unload()

private static void OnArcherDataOnInitialize(On.TowerFall.ArcherData.orig_Initialize orig)
{
Mod.LoadArcherContents();
orig();
Mod.Start();
}
Expand Down
6 changes: 2 additions & 4 deletions Source/Taunt/TauntVariant.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using FortRise;
using FortRise.IO;
using Microsoft.Xna.Framework.Input;
using Monocle;
using MonoMod.RuntimeDetour;
Expand Down Expand Up @@ -696,7 +694,7 @@ public static SFXVaried LoadVaried(string name)

public static SFXLooped LoadLooped(string name) => Exists(name) ? new SFXLooped(name) : (SFXLooped) null;

private static bool Exists(string name) => File.Exists(Audio.LOAD_PREFIX + name + ".wav");
private static bool Exists(string name) => ModIO.IsFileExists(Audio.LOAD_PREFIX + name + ".wav");

private static string VariedSuffix(int num)
{
Expand Down
Loading