Skip to content

Commit ae6198a

Browse files
committed
1.8.2
- Fixed a bug where the scale of the `barrelOffset` of guns created using MTG API was set to `(0.9, 0.9, 0.9)` - Fixed a bug where two mods trying to replace the same sprite of certain collections would break the game. - Fixed a bug where trying to add a large sprite would break the game.
1 parent 0849f03 commit ae6198a

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
lines changed

ModTheGungeonAPI/ETGMod/Assets/Assets.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static void SetupSprites(Dictionary<string, Texture2D> sheetReplacements,
122122
if (!unprocessedReplacements.TryGetValue(cname, out var dfs) || dfs == null)
123123
unprocessedReplacements[cname] = dfs = new();
124124

125-
dfs.AddRange(kvp.Value);
125+
dfs.SetRange(kvp.Value);
126126

127127
continue;
128128
}
@@ -147,7 +147,7 @@ public static void SetupSprites(Dictionary<string, Texture2D> sheetReplacements,
147147
if (!unprocessedJsons.TryGetValue(cname, out var dfs) || dfs == null)
148148
unprocessedJsons[cname] = dfs = new();
149149

150-
dfs.AddRange(kvp.Value);
150+
dfs.SetRange(kvp.Value);
151151

152152
continue;
153153
}
@@ -571,15 +571,18 @@ public static void SetupSpritesFromAssembly(Assembly asmb, string path)
571571
/// <param name="pack">Does nothing, only exists for backwards compatibility.</param>
572572
public static void ReplaceTexture(tk2dSpriteDefinition frame, Texture2D replacement, bool pack = true)
573573
{
574+
var segment = Packer.Pack(replacement);
575+
576+
if (segment == null)
577+
return;
578+
574579
frame.flipped = tk2dSpriteDefinition.FlipMode.None;
575580
frame.materialInst = new Material(frame.material);
576581
frame.texelSize = replacement.texelSize;
577582
frame.extractRegion = true;
578-
RuntimeAtlasSegment segment = Packer.Pack(replacement);
579583
frame.materialInst.mainTexture = segment.texture;
580584
frame.uvs = segment.uvs;
581585
}
582-
583586
}
584587

585588
/// <summary>

ModTheGungeonAPI/ETGMod/Assets/RuntimeAtlas.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public RuntimeAtlasSegment Pack(Texture2D tex, bool apply = false)
3737
{
3838
RuntimeAtlasSegment segment;
3939

40+
var paddingAddition = Padding * 2;
41+
42+
if((tex.width + paddingAddition) > RuntimeAtlasPage.DefaultSize || (tex.height + paddingAddition) > RuntimeAtlasPage.DefaultSize)
43+
{
44+
var size = NextPowerOfTwo(Mathf.Max(tex.width, tex.height) + paddingAddition);
45+
46+
if (size <= 0)
47+
return null;
48+
49+
return CustomNewPage(size, size).Pack(tex, apply);
50+
}
51+
4052
for (int i = 0; i < Pages.Count; i++)
4153
{
4254
if ((segment = Pages[i].Pack(tex, apply)) != null)
@@ -48,13 +60,38 @@ public RuntimeAtlasSegment Pack(Texture2D tex, bool apply = false)
4860
return NewPage().Pack(tex, apply);
4961
}
5062

63+
private static int NextPowerOfTwo(int i)
64+
{
65+
if (i > 65535)
66+
return 0;
67+
68+
var n = RuntimeAtlasPage.DefaultSize * 2;
69+
70+
while (n < i)
71+
n *= 2;
72+
73+
return n;
74+
}
75+
5176
public Action<RuntimeAtlasPage> OnNewPage;
5277

5378
public RuntimeAtlasPage NewPage()
5479
{
5580
var page = new RuntimeAtlasPage(Width, Height, Format, Padding);
81+
5682
Pages.Add(page);
5783
OnNewPage?.Invoke(page);
84+
85+
return page;
86+
}
87+
88+
public RuntimeAtlasPage CustomNewPage(int width, int height)
89+
{
90+
var page = new RuntimeAtlasPage(width, height, Format, Padding);
91+
92+
Pages.Add(page);
93+
OnNewPage?.Invoke(page);
94+
5895
return page;
5996
}
6097

ModTheGungeonAPI/ETGMod/Databases/ItemDB.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ public Gun NewGun(string gunName, Gun baseGun, string gunNameShort = null)
255255
gun.SetBaseMaxAmmo(300);
256256
gun.reloadTime = 0.625f;
257257

258+
gun.barrelOffset.transform.localScale = Vector3.one;
259+
258260
Gungeon.Game.Items.Add($"outdated_gun_mods:{gunName.ToID()}", gun);
259261

260262
return gun;

ModTheGungeonAPI/ETGMod/Extensions/Extensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,13 @@ public static T AtOr<T>(this T[] a, int i, T or)
202202
public static void AddRange(this IDictionary to, IDictionary from)
203203
{
204204
foreach (DictionaryEntry entry in from)
205-
{
206205
to.Add(entry.Key, entry.Value);
207-
}
206+
}
207+
208+
public static void SetRange(this IDictionary to, IDictionary from)
209+
{
210+
foreach (DictionaryEntry entry in from)
211+
to[entry.Key] = entry.Value;
208212
}
209213

210214
public static void ForEach<T>(this BindingList<T> list, Action<T> a)

ModTheGungeonAPI/ETGModMainBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ETGModMainBehaviour : BaseUnityPlugin
2424
/// <summary>
2525
/// The current version of the MTG API.
2626
/// </summary>
27-
public const string VERSION = "1.8.0";
27+
public const string VERSION = "1.8.2";
2828
/// <summary>
2929
/// Current instance of the MTG API behaviour.
3030
/// </summary>

ModTheGungeonAPI/ModTheGungeonAPI.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<package >
33
<metadata>
44
<id>EtG.ModTheGungeonAPI</id>
5-
<version>1.8.1</version>
5+
<version>1.8.2</version>
66
<title>EtG.ModTheGungeonAPI</title>
77
<authors>ModTheGungeonAPI</authors>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>
99
<license type="expression">MIT</license>
10-
<iconUrl>https://gcdn.thunderstore.io/live/repository/icons/MtG_API-Mod_the_Gungeon_API-1.8.1.png.256x256_q95_crop.png</iconUrl>
10+
<iconUrl>https://gcdn.thunderstore.io/live/repository/icons/MtG_API-Mod_the_Gungeon_API-1.8.2.png.256x256_q95_crop.png</iconUrl>
1111
<projectUrl>https://github.com/SpecialAPI/ModTheGungeonAPI</projectUrl>
1212
<description>An API for Enter the Gungeon that brings the good parts of MtG (Mod the Gungeon) to BepInEx as a plugin.</description>
1313
<releaseNotes></releaseNotes>

0 commit comments

Comments
 (0)