Skip to content

Commit

Permalink
Updated to EXILED 7.2
Browse files Browse the repository at this point in the history
Note that this is an old version, and likely won't work now.
This has been sitting on my computer for a while and I want to publish it.
I won't be updating it to the latest version unless I feel like it.
Also, intercom stuff has been removed, but could be added back.
  • Loading branch information
PintTheDragon committed Nov 12, 2023
1 parent 6cf1009 commit 3e71afb
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 349 deletions.
55 changes: 33 additions & 22 deletions Images/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@ public static class API
{
private static Image GetBitmapFromURL(string url)
{
var ms = new MemoryStream();

var stream = WebRequest.Create(url)?.GetResponse()?.GetResponseStream();
if (stream == null) return null;

stream.CopyTo(ms);
ms.Position = 0;
using (var client = new WebClient())
{
var data = client.DownloadData(url);

Image image = Image.FromStream(ms);

stream.Flush();
stream.Dispose();

return image;
using (var mem = new MemoryStream(data))
{
return Image.FromStream(mem);
}
}
}

private static Image GetBitmapFromFile(string path)
{
Expand Down Expand Up @@ -107,27 +102,40 @@ private static IEnumerator<float> _BitmapToText(Image image, Action<FrameData> h
var time = DateTime.Now;

image.SelectActiveFrame(dim, index);

if(image.Size.Height * image.Size.Width > 10000) throw new Exception("The image was too large. Please use an image with less that 10,000 pixels. Your image doesn't need to be more than 100x100.");

if (image.Size.Height * image.Size.Width > 10000)
{
handle(new FrameData(null)
{
Last = true,
Error = new Exception(
"The image was too large. Please use an image with less that 10,000 pixels. Your image doesn't need to be more than 100x100.")
});
yield break;
}

if (size == 0f)
{
size = Convert.ToInt32(scale == 0f ? Math.Floor((-.47*(((image.Size.Width+image.Size.Height)/2 > 60 ? 45 : (image.Width+image.Height)/2)))+28.72) : scale);
}

var lineHeight = 100 - size;

var sizeStr = "<size=" + size + "%><line-height=" + lineHeight + "%>";

Bitmap bitmap;
if(shapeCorrection) bitmap = new Bitmap(image, new Size(Convert.ToInt32(image.Size.Width*(1+.03*size)), image.Size.Height));
else bitmap = new Bitmap(image);

var text = "<size=" + size + "%>";
var text = sizeStr;

var pastPixel = new Color();

var threshold = 0f;

while ((System.Text.Encoding.Unicode.GetByteCount(text) > 32768 || text == "<size=" + size + "%>") && threshold < 5f)
while ((System.Text.Encoding.Unicode.GetByteCount(text) > 32768 || text == sizeStr) && threshold < 5f)
{
text = "<size=" + size + "%>";
text = sizeStr;

//I need to figure out how to use bitmap data, but GetPixel is fine for now
for (var i = 0; i < bitmap.Height; i++)
Expand Down Expand Up @@ -170,7 +178,7 @@ private static IEnumerator<float> _BitmapToText(Image image, Action<FrameData> h

if (!text.EndsWith("</color>\\n") && !text.EndsWith("</color>")) text += "</color>";

text += "</size>";
text += "</line-height></size>";

threshold += .5f;

Expand All @@ -197,10 +205,13 @@ private static IEnumerator<float> _BitmapToText(Image image, Action<FrameData> h

image.Dispose();

handle(new FrameData(null) {Last = true});
Log.Info("fails " + fails);

Exception error = null;
if(frames == 1 && fails > 0) error = new Exception("The image is too large to display.");
else if(fails > 0) error = new Exception(fails+" frames have been dropped while attempting to display this image.");

if(frames == 1 && fails > 0) throw new Exception("The image is too large to display.");
if(fails > 0) throw new Exception(fails+" frames have been dropped while attempting to display this image.");
handle(new FrameData(null) {Last = true, Error = error});
}
}
}
1 change: 1 addition & 0 deletions Images/Commands/IBroadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Images.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class IBroadcast : ICommand
{
public string Command => "ibroadcast";
Expand Down
8 changes: 5 additions & 3 deletions Images/Commands/IHint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Images.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class IHint : ICommand
{
public string Command => "ihint";
Expand Down Expand Up @@ -58,7 +59,7 @@ private IEnumerator<float> ShowHint(HandleCommandObject obj)

foreach (var player in Player.List)
{
player.ShowHint(newText, 2f);
player.ShowHint(newText, 1f);
}
}, obj.image["name"].Trim().ToLower(), obj.image["isURL"] == "true", obj.scale, false, .4f, obj.compress);
Images.Singleton.Coroutines.Add(handle);
Expand All @@ -78,16 +79,17 @@ private IEnumerator<float> ShowHint(HandleCommandObject obj)
{
foreach (var player in Player.List)
{
player.ShowHint(frames[0], obj.duration-2f);
player.ShowHint(frames[0], obj.duration-1f);
}
}
yield break;
}
Log.Info("frames: " + frames.Count);
while (DateTime.UtcNow - startTime < TimeSpan.FromSeconds(obj.duration))
{
foreach (var player in Player.List)
{
player.ShowHint(frames[cur % frames.Count], 2f);
player.ShowHint(frames[cur % frames.Count], 1f);
}

yield return Timing.WaitForSeconds(.4f);
Expand Down
73 changes: 0 additions & 73 deletions Images/Commands/IIntercom.cs

This file was deleted.

15 changes: 2 additions & 13 deletions Images/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace Images
{
public class Config : IConfig
{
[Description("Should the plugin be enabled or not.")]
public bool IsEnabled { get; set; } = true;

public bool Debug { get; set; } = false;

[Description("This is the list of every image. You need to add your image here before it can be used ingame. Also, if you're using a url, make sure to set \"isURL\" to \"true\"!")]
public List<Dictionary<string, string>> Images { get; set; } = new List<Dictionary<string, string>>(
Expand All @@ -33,18 +34,6 @@ public class Config : IConfig
[Description("Should you need a specific permission to use a specific image. Permission: images.image.IMAGE_NAME")]
public bool PerImagePermissions { get; set; } = false;

[Description("This will override the default intercom with a specific image. If you want this, put the image name below, otherwise, set it to \"none\".")]
public string DefaultIntercomImage { get; set; } = "none";

[Description("This will override the default intercom with a specific image, but only when someone is speaking. If you want this, put the image name below, otherwise, set it to \"none\".")]
public string DefaultIntercomImageSpeaking { get; set; } = "none";

[Description("This will override the default intercom with a specific image, but only when the intercom is on cooldown. If you want this, put the image name below, otherwise, set it to \"none\".")]
public string DefaultIntercomImageCooldown { get; set; } = "none";

[Description("This will override the default intercom with a specific image, but only when the intercom is ready. If you want this, put the image name below, otherwise, set it to \"none\".")]
public string DefaultIntercomImageReady { get; set; } = "none";

[Description("How many images should be cached. Caching helps reduce load on the server but will increase RAM usage. If too much RAM is being used, lower this, and if sending images takes too much time, increase this. Set it to 0 to disable caching.")]
public int CacheSize { get; set; } = 20;

Expand Down
5 changes: 4 additions & 1 deletion Images/FrameData.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace Images
using System;

namespace Images
{
public class FrameData
{
public string Data;
public bool Last = false;
public Exception Error = null;

public FrameData(string data)
{
Expand Down
Loading

0 comments on commit 3e71afb

Please sign in to comment.