Skip to content
Merged
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
Binary file added Assets/DownloadsIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/FullLikeIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions BloonFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using BloonFactory.UI;
using BTD_Mod_Helper;
using BTD_Mod_Helper.Api;
using FactoryCore.UI;

Check failure on line 6 in BloonFactory.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'FactoryCore' could not be found (are you missing a using directive or an assembly reference?)
using Il2CppAssets.Scripts.Models;
using Il2CppAssets.Scripts.Models.Bloons;
using MelonLoader;
Expand All @@ -26,13 +26,6 @@
ValueColors.ColorByLinkType[typeof(Trigger)] = Color.magenta;
ValueColors.ColorByLinkType[typeof(Visuals)] = Color.cyan;
}
public override void OnUpdate()
{
if (Input.GetKeyDown(KeyCode.K))
{
ModGameMenu.Open<EditSelectorUI>();
}
}
public override void OnNewGameModel(GameModel result)
{
foreach (var bloon in CustomBloon.Bloons)
Expand Down
3 changes: 3 additions & 0 deletions BloonFactory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<Reference Include="FactoryCore">
<HintPath>..\..\SteamLibrary\steamapps\common\BloonsTD6\Mods\FactoryCore.dll</HintPath>
</Reference>
<Reference Include="Il2CppNinjaKiwi.LiNK">
<HintPath>..\..\SteamLibrary\steamapps\common\BloonsTD6\MelonLoader\Il2CppAssemblies\Il2CppNinjaKiwi.LiNK.dll</HintPath>
</Reference>
</ItemGroup>

<Import Project="..\btd6.targets" />
Expand Down
1 change: 1 addition & 0 deletions CustomBloon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using BloonFactory.Modules.Display;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Bloons;
using FactoryCore.API;

Check failure on line 6 in CustomBloon.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'FactoryCore' could not be found (are you missing a using directive or an assembly reference?)
using Il2CppAssets.Scripts.Models.Bloons;
using Il2CppAssets.Scripts.Models.Rounds;
using Il2CppNinjaKiwi.Common.ResourceUtils;
Expand Down Expand Up @@ -73,6 +73,7 @@
}

DamageStateDisplayModule.DamageStateFix(model);

}
public override IEnumerable<ModContent> Load()
{
Expand Down
2 changes: 1 addition & 1 deletion ModuleProperties/BloonTextureModuleProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override ModHelperPanel GetVisual(ModHelperPanel root)
TaskScheduler.ScheduleTask(() =>
{
UpdateImage(image);
}, ScheduleType.WaitForFrames, 5);
});

return panel;
}
Expand Down
10 changes: 9 additions & 1 deletion Modules/Display/BloonDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using Il2CppAssets.Scripts.Models.GenericBehaviors;
using Il2CppAssets.Scripts.Unity.Display;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace BloonFactory.Modules.Display
{
internal class BloonDisplay : ModDisplay2D
{
private static Dictionary<string, Texture2D> Cache = new Dictionary<string, Texture2D>();
protected override string TextureName => "BaseBloon";
public override DisplayCategory DisplayCategory => DisplayCategory.Bloon;
public override string BaseDisplay => "9d3c0064c3ace7448bf8fefa4a97a70f";
Expand All @@ -20,7 +22,7 @@
public string Guid;
public const int Width = 250;
public const int Height = 250;
public const float PixelsPerUnit = 20;

Check warning on line 25 in Modules/Display/BloonDisplay.cs

View workflow job for this annotation

GitHub Actions / build

'BloonDisplay.PixelsPerUnit' hides inherited member 'ModDisplay.PixelsPerUnit'. Use the new keyword if hiding was intended.

Check warning on line 25 in Modules/Display/BloonDisplay.cs

View workflow job for this annotation

GitHub Actions / build

'BloonDisplay.PixelsPerUnit' hides inherited member 'ModDisplay.PixelsPerUnit'. Use the new keyword if hiding was intended.

public Func<Texture2D> GenerateTexture;

Expand All @@ -36,7 +38,13 @@
}
public override void ModifyDisplayNode(UnityDisplayNode node)
{
var sprite = Sprite.Create(GenerateTexture.Invoke(), new Rect(0, 0, Width, Height), new Vector2(0.5f, 0.5f), PixelsPerUnit);
if (!Cache.TryGetValue(Guid, out var cachedTexture) || cachedTexture == null)
{
var texture = GenerateTexture?.Invoke();
Cache.Add(Guid, texture);
cachedTexture = texture;
}
var sprite = Sprite.Create(cachedTexture, new Rect(0, 0, Width, Height), new Vector2(0.5f, 0.5f), PixelsPerUnit);
node.GetRenderer<SpriteRenderer>().sprite = sprite;
node.isSprite = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Patches/BloonMenu_CreateBloonButtons_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void Prefix(BloonMenu __instance, Il2CppSystem.Collections.Generic
{
foreach (var bloon in CustomBloon.Bloons)
{
if (!sortedBloons.Any(a => a.id == bloon.BloonTemplate.TemplateId))
if (!sortedBloons.Any(a => a.id == bloon.BloonTemplate.TemplateId) && !bloon.BloonTemplate.IsQueueForDeletion)
{
sortedBloons.Add(Game.instance.model.GetBloon(bloon.BloonTemplate.TemplateId));
}
Expand Down
22 changes: 22 additions & 0 deletions SerializationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ internal static void EnsureFolderExists()
if (!Directory.Exists(FolderDirectory))
Directory.CreateDirectory(FolderDirectory);
}
internal static void SaveTemplate(BloonTemplate template, string path)
{
EnsureFolderExists();

var content = JsonConvert.SerializeObject(template, Settings);
File.WriteAllText(path + FileExtention, content);
}
internal static void SaveTemplate(BloonTemplate template)
{
EnsureFolderExists();
Expand All @@ -41,6 +48,21 @@ internal static bool ContainGuid(Guid guid)
{
return Templates.Any(a => a.Guid == guid);
}
internal static bool TryLoadTemplate(BloonTemplate template)
{
EnsureFolderExists();

if (ContainGuid(template.Guid))
{
MelonLogger.Msg("File already exists");
return false;
}

template.IsLoaded = false;
SaveTemplate(template);
Templates.Add(template);
return true;
}
internal static BloonTemplate GetTemplateFromPath(string path)
{
EnsureFolderExists();
Expand Down
129 changes: 129 additions & 0 deletions ServerHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@

using BTD_Mod_Helper.Extensions;
using Il2CppAssets.Scripts.Unity;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using JetBrains.Annotations;
using MelonLoader;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Octokit;
using Octokit.Internal;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using static BloonFactory.UI.BloonBrowserMenuPanel;

namespace BloonFactory
{
internal static class ServerHandler
{
public const string URL = "https://server.bloonfactory.org/";
private static HttpClient client = new HttpClient();
internal static async Task<PageUpdateRequest> RequestPageUpdate()
{
HttpResponseMessage response = await client.GetAsync(URL + "getPage");
response.EnsureSuccessStatusCode();
byte[] bytes = await response.Content.ReadAsByteArrayAsync();

var obj = JsonConvert.DeserializeObject<PageUpdateRequest>(Encoding.UTF8.GetString(bytes), new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.None });
return obj;
}
internal static async Task<BloonTemplate> DownloadTemplate(Guid guid)
{
HttpResponseMessage response = await client.GetAsync(URL + $"getTemplate={guid.ToString()}");
MelonLogger.Msg($"Requested template from server ({guid.ToString()})");
response.EnsureSuccessStatusCode();
byte[] bytes = await response.Content.ReadAsByteArrayAsync();

var obj = JsonConvert.DeserializeObject<BloonTemplate>(Encoding.UTF8.GetString(bytes), SerializationHandler.Settings);
return obj;
}
internal static async Task<(bool success, string errorCode)> UploadTemplate(BloonTemplate template, BloonCategory category, string description)
{
string creator = Game.Player.LiNKAccount?.DisplayName;
if (string.IsNullOrEmpty(creator))
{
MelonLogger.Msg("You must be logged into a NK account to upload a template.");
return (false, "You must be logged into a NK account to upload a template.");
}
MelonLogger.Msg($"Uploading template to server ({template.Name})");
UploadTemplateRequest request = new UploadTemplateRequest()
{
Name = template.Name,
Guid = template.Guid,
Creator = creator,
Category = (byte)category,
Description = description,
TemplateJson = JsonConvert.SerializeObject(template, SerializationHandler.Settings)
};

HttpResponseMessage response = await client.PostAsync(URL + "uploadTemplate", new StringContent(JsonConvert.SerializeObject(request)));

if (!response.IsSuccessStatusCode)
{
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
return (false, Encoding.UTF8.GetString(bytes));
}
return (true, "");
}
}
public class PageUpdateRequest
{
public List<BloonBrowserEntry> Data;
}
public class UploadTemplateRequest
{
public string Name;
public Guid Guid;
public string Creator;
public byte Category;
public string Description;

public string TemplateJson;
}
public class BloonBrowserEntry
{
public string Name;
public Guid Guid;
public string Creator;
public byte Category;
public string Description;

public DateTime UploadTime = DateTime.Now;
public int Downloads = 0;

[JsonIgnore]
public BloonCategory CategoryEnum => (BloonCategory)Category;
}
public enum BloonCategory : byte
{
Boss,
VanillaPlus,
Modded
}
public static class CategoryExtensions
{
public static string[] BloonCategoryNames =
[
"Boss",
"Vanilla+",
"Modded"
];
public static string ToFriendlyString(this BloonCategory category)
{
return category switch
{
BloonCategory.Boss => "Boss",
BloonCategory.VanillaPlus => "Vanilla+",
BloonCategory.Modded => "Modded",
_ => "Unknown",
};
}
}
}
Loading
Loading