Skip to content

Commit 3eeb148

Browse files
Add some more comments
1 parent c710b84 commit 3eeb148

11 files changed

Lines changed: 72 additions & 56 deletions

File tree

src/Constants.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace PolyMod;
2+
3+
/// <summary>
4+
/// useful constant values.
5+
/// </summary>
6+
public partial class Constants
7+
{
8+
/// <summary>
9+
/// path of the mods folder
10+
/// </summary>
11+
public static readonly string MODS_PATH = Path.Combine(BASE_PATH, "Mods");
12+
internal static readonly string CONFIG_PATH = Path.Combine(BASE_PATH, "PolyMod.json");
13+
internal static readonly string DISCORD_LINK = "https://discord.gg/eWPdhWtfVy";
14+
internal const int AUTOIDX_STARTS_FROM = 1000;
15+
internal static readonly List<string> LOG_MESSAGES_IGNORE = new()
16+
{
17+
"Failed to find atlas",
18+
"Could not find sprite",
19+
"Couldn't find prefab for type",
20+
"MARKET: id:",
21+
"Missing name for value",
22+
};
23+
/// <summary>
24+
/// Path of the polytopia folder
25+
/// </summary>
26+
public static readonly string BASE_PATH = Path.Combine(BepInEx.Paths.BepInExRootPath, "..");
27+
/// <summary>
28+
/// Filename of the dumped data
29+
/// </summary>
30+
public static readonly string DUMPED_DATA_PATH = Path.Combine(BASE_PATH, "DumpedData");
31+
internal static readonly string CHECKSUM_PATH
32+
= Path.Combine(BASE_PATH, "CHECKSUM");
33+
internal const string INCOMPATIBILITY_WARNING_LAST_VERSION_KEY
34+
= "INCOMPATIBILITY_WARNING_LAST_VERSION";
35+
}

src/Loader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace PolyMod;
2121

22-
public static class Loader
22+
internal static class Loader
2323
{
2424
internal static Dictionary<string, Type> typeMappings = new()
2525
{
@@ -138,10 +138,10 @@ public record GameModeButtonsInformation(int gameModeIndex, UIButtonBase.ButtonA
138138

139139
internal static bool RegisterMods(Dictionary<string, Mod> mods)
140140
{
141-
Directory.CreateDirectory(Plugin.MODS_PATH);
142-
string[] modContainers = Directory.GetDirectories(Plugin.MODS_PATH)
143-
.Union(Directory.GetFiles(Plugin.MODS_PATH, "*.polymod"))
144-
.Union(Directory.GetFiles(Plugin.MODS_PATH, "*.zip"))
141+
Directory.CreateDirectory(Constants.MODS_PATH);
142+
string[] modContainers = Directory.GetDirectories(Constants.MODS_PATH)
143+
.Union(Directory.GetFiles(Constants.MODS_PATH, "*.polymod"))
144+
.Union(Directory.GetFiles(Constants.MODS_PATH, "*.zip"))
145145
.ToArray();
146146
foreach (var modContainer in modContainers)
147147
{

src/Managers/Config.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public class Config<T> where T : class
1111
private T? currentConfig;
1212
private readonly string modName;
1313
private readonly ConfigTypes configType;
14-
private static readonly string ExposedConfigPath = Path.Combine(Plugin.BASE_PATH, "mods.json");
14+
private static readonly string ExposedConfigPath = Path.Combine(Constants.BASE_PATH, "mods.json");
1515
private readonly string perModConfigPath;
1616
private T? defaultConfig;
1717
public Config(string modName, ConfigTypes configType)
1818
{
1919
this.modName = modName;
2020
this.configType = configType;
21-
perModConfigPath = Path.Combine(Plugin.MODS_PATH, $"{modName}.json");
21+
perModConfigPath = Path.Combine(Constants.MODS_PATH, $"{modName}.json");
2222
Load();
2323
}
2424

src/Managers/GLDConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PolyMod.Managers;
77

88
internal class GldConfigTemplate
99
{
10-
private static readonly string ConfigPath = Path.Combine(Plugin.BASE_PATH, "mods.json");
10+
private static readonly string ConfigPath = Path.Combine(Constants.BASE_PATH, "mods.json");
1111

1212
private readonly string templateText;
1313
private JsonObject currentConfig = new();

src/Patches/AutoUpdate.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ void Update()
5656
{
5757
Time.timeScale = 0;
5858
File.WriteAllBytes(
59-
Path.Combine(Plugin.BASE_PATH, "PolyMod.new.dll"),
59+
Path.Combine(Constants.BASE_PATH, "PolyMod.new.dll"),
6060
client.GetAsync(latest?.GetProperty("assets")[0].GetProperty("browser_download_url").GetString()!).UnwrapAsync()
6161
.Content.ReadAsByteArrayAsync().UnwrapAsync()
6262
);
6363
using ZipArchive bepinex = new(client.GetAsync(bepinex_url).UnwrapAsync().Content.ReadAsStream());
64-
bepinex.ExtractToDirectory(Path.Combine(Plugin.BASE_PATH, "New"), overwriteFiles: true);
64+
bepinex.ExtractToDirectory(Path.Combine(Constants.BASE_PATH, "New"), overwriteFiles: true);
6565
ProcessStartInfo info = new()
6666
{
67-
WorkingDirectory = Path.Combine(Plugin.BASE_PATH),
67+
WorkingDirectory = Path.Combine(Constants.BASE_PATH),
6868
CreateNoWindow = true,
6969
};
7070
if (Application.platform == RuntimePlatform.WindowsPlayer)
7171
{
72-
string batchPath = Path.Combine(Plugin.BASE_PATH, "update.bat");
72+
string batchPath = Path.Combine(Constants.BASE_PATH, "update.bat");
7373
File.WriteAllText(batchPath, $@"
7474
@echo off
7575
echo Waiting for Polytopia.exe to exit...
@@ -93,13 +93,13 @@ echo Launching game...
9393
");
9494
info.FileName = "cmd.exe";
9595
info.Arguments = $"/C start \"\" \"{batchPath}\"";
96-
info.WorkingDirectory = Plugin.BASE_PATH;
96+
info.WorkingDirectory = Constants.BASE_PATH;
9797
info.CreateNoWindow = true;
9898
info.UseShellExecute = false;
9999
}
100100
if (Application.platform == RuntimePlatform.LinuxPlayer || Application.platform == RuntimePlatform.OSXPlayer)
101101
{
102-
string bashPath = Path.Combine(Plugin.BASE_PATH, "update.sh");
102+
string bashPath = Path.Combine(Constants.BASE_PATH, "update.sh");
103103
File.WriteAllText(bashPath, $@"
104104
#!/bin/bash
105105
@@ -130,7 +130,7 @@ exit 0
130130

131131
info.FileName = "/bin/bash";
132132
info.Arguments = $"\"{bashPath}\"";
133-
info.WorkingDirectory = Plugin.BASE_PATH;
133+
info.WorkingDirectory = Constants.BASE_PATH;
134134
info.CreateNoWindow = true;
135135
info.UseShellExecute = false;
136136
}

src/Patches/Compatibility.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ private static void StartScreen_Start()
6868
string lastChecksum = checksum;
6969
try
7070
{
71-
lastChecksum = new(File.ReadAllText(Plugin.CHECKSUM_PATH));
71+
lastChecksum = new(File.ReadAllText(Constants.CHECKSUM_PATH));
7272
}
7373
catch (FileNotFoundException) { }
7474

7575
File.WriteAllText(
76-
Plugin.CHECKSUM_PATH,
76+
Constants.CHECKSUM_PATH,
7777
checksum
7878
);
7979
if (lastChecksum != checksum)
@@ -82,13 +82,13 @@ private static void StartScreen_Start()
8282
}
8383

8484
Version incompatibilityWarningLastVersion = new(PlayerPrefs.GetString(
85-
Plugin.INCOMPATIBILITY_WARNING_LAST_VERSION_KEY,
85+
Constants.INCOMPATIBILITY_WARNING_LAST_VERSION_KEY,
8686
Plugin.POLYTOPIA_VERSION.CutRevision().ToString()
8787
));
8888
if (VersionManager.SemanticVersion.Cast().CutRevision() > incompatibilityWarningLastVersion)
8989
{
9090
PlayerPrefs.SetString(
91-
Plugin.INCOMPATIBILITY_WARNING_LAST_VERSION_KEY,
91+
Constants.INCOMPATIBILITY_WARNING_LAST_VERSION_KEY,
9292
VersionManager.SemanticVersion.Cast().CutRevision().ToString()
9393
);
9494
PlayerPrefs.Save();

src/Patches/Hub.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static void PolyModHubButtonClicked(int buttonId, BaseEventData eventData)
143143
new(
144144
"polymod.hub.discord",
145145
callback: (UIButtonBase.ButtonAction)((_, _) =>
146-
NativeHelpers.OpenURL(Plugin.DISCORD_LINK, false))
146+
NativeHelpers.OpenURL(Constants.DISCORD_LINK, false))
147147
),
148148
new(
149149
"polymod.hub.config",
@@ -159,18 +159,18 @@ static void PolyModHubButtonClicked(int buttonId, BaseEventData eventData)
159159
"polymod.hub.dump",
160160
callback: (UIButtonBase.ButtonAction)((_, _) =>
161161
{
162-
Directory.CreateDirectory(Plugin.DUMPED_DATA_PATH);
162+
Directory.CreateDirectory(Constants.DUMPED_DATA_PATH);
163163
File.WriteAllTextAsync(
164-
Path.Combine(Plugin.DUMPED_DATA_PATH, "gameLogicData.json"),
164+
Path.Combine(Constants.DUMPED_DATA_PATH, "gameLogicData.json"),
165165
PolytopiaDataManager.provider.LoadGameLogicData(VersionManager.GameLogicDataVersion)
166166
);
167167
File.WriteAllTextAsync(
168-
Path.Combine(Plugin.DUMPED_DATA_PATH, "avatarData.json"),
168+
Path.Combine(Constants.DUMPED_DATA_PATH, "avatarData.json"),
169169
PolytopiaDataManager.provider.LoadAvatarData(1337)
170170
);
171171
foreach (var category in LocalizationManager.Sources[0].GetCategories())
172172
File.WriteAllTextAsync(
173-
Path.Combine(Plugin.DUMPED_DATA_PATH, $"localization_{category}.csv"),
173+
Path.Combine(Constants.DUMPED_DATA_PATH, $"localization_{category}.csv"),
174174
LocalizationManager.Sources[0].Export_CSV(category)
175175
);
176176
foreach (KeyValuePair<string, Mod> entry in Registry.mods)
@@ -179,7 +179,7 @@ static void PolyModHubButtonClicked(int buttonId, BaseEventData eventData)
179179
{
180180
if (Path.GetFileName(file.name) == "sprites.json")
181181
{
182-
File.WriteAllBytes(Path.Combine(Plugin.DUMPED_DATA_PATH, $"sprites_{entry.Key}.json"), file.bytes);
182+
File.WriteAllBytes(Path.Combine(Constants.DUMPED_DATA_PATH, $"sprites_{entry.Key}.json"), file.bytes);
183183
}
184184
}
185185
}
@@ -208,7 +208,7 @@ static void PolyModHubButtonClicked(int buttonId, BaseEventData eventData)
208208
}
209209
}
210210
File.WriteAllTextAsync(
211-
Path.Combine(Plugin.DUMPED_DATA_PATH, $"preview_{type}.json"),
211+
Path.Combine(Constants.DUMPED_DATA_PATH, $"preview_{type}.json"),
212212
JsonSerializer.Serialize(previewTiles, new JsonSerializerOptions { WriteIndented = true })
213213
);
214214
}
@@ -262,9 +262,9 @@ private static void GameManager_Update()
262262
internal static void UpdateSpriteInfos()
263263
{
264264
string message = string.Empty;
265-
Directory.CreateDirectory(Plugin.DUMPED_DATA_PATH);
265+
Directory.CreateDirectory(Constants.DUMPED_DATA_PATH);
266266

267-
foreach (var file in Directory.GetFiles(Plugin.DUMPED_DATA_PATH))
267+
foreach (var file in Directory.GetFiles(Constants.DUMPED_DATA_PATH))
268268
{
269269
string? name = Path.GetFileNameWithoutExtension(file);
270270
List<string> subnames = new();

src/Patches/Loc.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static class Loc
1313
[HarmonyPatch(typeof(SelectTribePopup), nameof(SelectTribePopup.SetDescription))]
1414
private static void SetDescription(SelectTribePopup __instance)
1515
{
16-
if ((int)__instance.SkinType >= Plugin.AUTOIDX_STARTS_FROM)
16+
if ((int)__instance.SkinType >= Constants.AUTOIDX_STARTS_FROM)
1717
{
1818
string description = Localization.Get(__instance.SkinType.GetLocalizationDescriptionKey());
1919
if (description == __instance.SkinType.GetLocalizationDescriptionKey())
@@ -42,7 +42,7 @@ private static bool Localization_Get(ref string key, Il2CppReferenceArray<Il2Cpp
4242
{
4343
if (int.TryParse(item, out int parsedIdx))
4444
{
45-
if (parsedIdx >= Plugin.AUTOIDX_STARTS_FROM)
45+
if (parsedIdx >= Constants.AUTOIDX_STARTS_FROM)
4646
{
4747
idx = parsedIdx;
4848
}

src/Patches/Main.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ private static void GameLogicData_Parse(GameLogicData __instance, JObject rootOb
110110
[HarmonyPatch(typeof(PurchaseManager), nameof(PurchaseManager.IsSkinUnlockedInternal))]
111111
private static bool PurchaseManager_IsSkinUnlockedInternal(ref bool __result, SkinType skinType)
112112
{
113-
__result = (int)skinType >= Plugin.AUTOIDX_STARTS_FROM && skinType != SkinType.Test;
113+
__result = (int)skinType >= Constants.AUTOIDX_STARTS_FROM && skinType != SkinType.Test;
114114
return !__result;
115115
}
116116

117117
[HarmonyPostfix]
118118
[HarmonyPatch(typeof(PurchaseManager), nameof(PurchaseManager.IsTribeUnlocked))]
119119
private static void PurchaseManager_IsTribeUnlocked(ref bool __result, TribeData.Type type)
120120
{
121-
__result = (int)type >= Plugin.AUTOIDX_STARTS_FROM || __result;
121+
__result = (int)type >= Constants.AUTOIDX_STARTS_FROM || __result;
122122
}
123123

124124
[HarmonyPostfix]
@@ -135,7 +135,7 @@ private static void PurchaseManager_GetUnlockedTribes(
135135
[HarmonyPatch(typeof(IL2CPPUnityLogSource), nameof(IL2CPPUnityLogSource.UnityLogCallback))]
136136
private static bool IL2CPPUnityLogSource_UnityLogCallback(string logLine, string exception, LogType type)
137137
{
138-
foreach (string stringToIgnore in Plugin.LOG_MESSAGES_IGNORE)
138+
foreach (string stringToIgnore in Constants.LOG_MESSAGES_IGNORE)
139139
{
140140
if (logLine.Contains(stringToIgnore))
141141
return false;

src/Plugin.cs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,14 @@
99
namespace PolyMod;
1010

1111
[BepInPlugin("com.polymod", "PolyMod", VERSION)]
12-
public partial class Plugin : BepInEx.Unity.IL2CPP.BasePlugin
12+
internal partial class Plugin : BepInEx.Unity.IL2CPP.BasePlugin
1313
{
1414
internal record PolyConfig(
1515
bool debug = false,
1616
bool autoUpdate = true,
1717
bool updatePrerelease = false
1818
);
1919

20-
internal const int AUTOIDX_STARTS_FROM = 1000;
21-
internal const string INCOMPATIBILITY_WARNING_LAST_VERSION_KEY
22-
= "INCOMPATIBILITY_WARNING_LAST_VERSION";
23-
public static readonly string BASE_PATH = Path.Combine(BepInEx.Paths.BepInExRootPath, "..");
24-
public static readonly string MODS_PATH = Path.Combine(BASE_PATH, "Mods");
25-
public static readonly string DUMPED_DATA_PATH = Path.Combine(BASE_PATH, "DumpedData");
26-
internal static readonly string CONFIG_PATH = Path.Combine(BASE_PATH, "PolyMod.json");
27-
internal static readonly string CHECKSUM_PATH
28-
= Path.Combine(BASE_PATH, "CHECKSUM");
29-
internal static readonly string DISCORD_LINK = "https://discord.gg/eWPdhWtfVy";
30-
internal static readonly List<string> LOG_MESSAGES_IGNORE = new()
31-
{
32-
"Failed to find atlas",
33-
"Could not find sprite",
34-
"Couldn't find prefab for type",
35-
"MARKET: id:",
36-
"Missing name for value",
37-
};
38-
3920

4021
#pragma warning disable CS8618
4122
internal static PolyConfig config;
@@ -46,7 +27,7 @@ public override void Load()
4627
{
4728
try
4829
{
49-
config = JsonSerializer.Deserialize<PolyConfig>(File.ReadAllText(CONFIG_PATH))!;
30+
config = JsonSerializer.Deserialize<PolyConfig>(File.ReadAllText(Constants.CONFIG_PATH))!;
5031
}
5132
catch
5233
{
@@ -77,7 +58,7 @@ internal static Stream GetResource(string id)
7758

7859
internal static void WriteConfig()
7960
{
80-
File.WriteAllText(CONFIG_PATH, JsonSerializer.Serialize(config));
61+
File.WriteAllText(Constants.CONFIG_PATH, JsonSerializer.Serialize(config));
8162
}
8263

8364
internal static void UpdateConsole()

0 commit comments

Comments
 (0)