Skip to content
This repository was archived by the owner on Apr 21, 2024. It is now read-only.

Commit e65b85d

Browse files
author
BuildTools
committed
merged dev
2 parents d172228 + 4e1f4be commit e65b85d

9 files changed

+88
-18
lines changed

Config.cs

+2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ internal struct SplotchConfigStruct
1717
public bool splotchEnabled;
1818
public bool consoleEnabled;
1919
public bool verboseLoggingEnabled;
20+
public bool nightly; // I touched it (;
2021
}
2122

2223
internal static SplotchConfigStruct LoadedSplotchConfig = new SplotchConfigStruct
2324
{
2425
splotchEnabled = true,
2526
consoleEnabled = true,
2627
verboseLoggingEnabled = true,
28+
nightly = false,
2729
};
2830

2931
internal struct SplotchConfigCont

Event.cs

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ namespace Splotch.Event
1414
public static class EventManager
1515
{
1616
public static Dictionary<Type, List<MethodInfo>> registeredEventHandlers = new Dictionary<Type, List<MethodInfo>>();
17+
/// <summary>
18+
/// Registers a static event listener class containing functions tagged with <c>[EventHandler]</c>
19+
/// </summary>
20+
/// <param name="eventListener">The class</param>
1721
public static void RegisterEventListener(Type eventListener)
1822
{
1923
foreach (MethodInfo eventHandler in eventListener.GetMethods())

GuiModifications.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal static void RunMainMenuModifications()
4040
// set the text to the version info
4141
AssemblyName name = Assembly.GetExecutingAssembly().GetName();
4242

43-
textComponent.text = $"{ModManager.GetLoadedModsInfoText()}\n{name.Name} version {name.Version}";
43+
textComponent.text = $"{ModManager.GetLoadedModsInfoText()}\n{name.Name} version {VersionChecker.currentVersionString}";
4444

4545
// change settings
4646
textComponent.font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);

Loader.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public static void OnEnterScene(Scene scene, LoadSceneMode loadSceneMode)
3131
{
3232
Logger.InitLogger();
3333

34-
AssemblyName name = Assembly.GetExecutingAssembly().GetName();
35-
Logger.Log($"Entering main menu on version {name.Version}");
36-
34+
Logger.Log($"Entering main menu on version {VersionChecker.currentVersionString}");
3735

3836
enteredScene = true;
3937
Patcher.DoPatching();

Logger.cs

+28-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
using System;
1+
using Splotch.Loader;
2+
using System;
23
using System.Diagnostics;
34
using System.IO;
5+
using System.Reflection;
6+
using System.Runtime.InteropServices;
7+
using System.Threading;
48
using UnityEngine;
59

610

@@ -38,30 +42,47 @@ private static string GetCallingClass()
3842
/// </summary>
3943
internal static void InitLogger()
4044
{
45+
VersionChecker.RunVersionChecker();
46+
4147
// Create a new process
4248
Process process = new Process();
4349
process.StartInfo.FileName = "cmd.exe";
4450
process.StartInfo.RedirectStandardInput = true;
4551
process.StartInfo.RedirectStandardOutput = true;
4652
process.StartInfo.UseShellExecute = false;
47-
process.StartInfo.CreateNoWindow = !Splotch.Config.LoadedSplotchConfig.consoleEnabled; // Set this to true if you want to hide the window (Might be how we disable the window)
53+
process.StartInfo.CreateNoWindow = !Splotch.Config.LoadedSplotchConfig.consoleEnabled && !VersionChecker.updateNeeded; // Set this to true if you want to hide the window (Might be how we disable the window)
4854

4955
// Start the process
5056
process.Start();
51-
// It breaks if this isn't here.
52-
System.Threading.Thread.Sleep(1000);
57+
58+
// It breaks if this isn't here
59+
Thread.Sleep(1000);
5360

5461
// Connects the console window to bopl
5562
AttachConsole((uint) process.Id);
5663

5764
// Sets the output to the console window thing
58-
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
59-
sw.AutoFlush = true;
65+
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
6066
Console.SetOut(sw);
6167

68+
// Set the title of the window
69+
Console.Title = $"Splotch Log version {VersionChecker.currentVersionString}";
6270

6371
Application.logMessageReceived += HandleUnityLogs;
6472

73+
if (VersionChecker.updateNeeded)
74+
{
75+
Console.WriteLine($"Update {VersionChecker.targetVersionString} needed! The current installed version is {VersionChecker.currentVersionString} Press [P] to open the download page or any other key to continue");
76+
77+
ConsoleKeyInfo key = Console.ReadKey();
78+
if (key.KeyChar == 'p')
79+
{
80+
Process.Start("https://github.com/commandblox/Splotch/releases");
81+
}
82+
83+
if (!Splotch.Config.LoadedSplotchConfig.consoleEnabled)
84+
process.Close();
85+
}
6586

6687
Logger.Log("Log test");
6788
Logger.Warning("Warn test");
@@ -215,6 +236,6 @@ public static void Debug(string message, bool doublestack = false)
215236
}
216237

217238
// AttachConsole lets me "hook" the logger into the thing
218-
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
239+
[DllImport("kernel32.dll")]
219240
private static extern bool AttachConsole(uint dwProcessId);
220241
}

Properties/AssemblyInfo.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System.Reflection;
22
using System.Runtime.InteropServices;
3-
using UnityEngine;
43

54
// General Information about an assembly is controlled through the following
65
// set of attributes. Change these attribute values to modify the information
76
// associated with an assembly.
8-
[assembly: AssemblyDescription("Splotch mod loader for bopl battle")]
7+
[assembly: AssemblyDescription("Splotch mod loader for Bopl Battle")]
98
[assembly: AssemblyCopyright("Copyright © 2024")]
109
[assembly: AssemblyTrademark("")]
1110
[assembly: AssemblyCulture("")]
@@ -37,4 +36,4 @@
3736
// X: major versions
3837
// Y: feature addition/ removal
3938
// Z: small patch/ bugfix
40-
[assembly: AssemblyVersion("0.2.0")]
39+
[assembly: AssemblyVersion("0.2.1")]

Splotch.csproj

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -50,6 +50,7 @@
5050
<Compile Include="ModManager.cs" />
5151
<Compile Include="Properties\AssemblyInfo.cs" />
5252
<Compile Include="SplotchMod.cs" />
53+
<Compile Include="VersionChecker.cs" />
5354
</ItemGroup>
5455
<ItemGroup>
5556
<WCFMetadata Include="Connected Services\" />
@@ -58,6 +59,7 @@
5859
<None Include="app.config" />
5960
<None Include="packages.config" />
6061
<None Include="README.md" />
62+
<None Include="version" />
6163
</ItemGroup>
6264
<ItemGroup>
6365
<Reference Include="0Harmony, Version=2.10.2.0, Culture=neutral, processorArchitecture=MSIL">
@@ -467,4 +469,4 @@
467469
</Reference>
468470
</ItemGroup>
469471
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
470-
</Project>
472+
</Project>

VersionChecker.cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Net;
3+
using System.Reflection;
4+
5+
namespace Splotch.Loader
6+
{
7+
internal static class VersionChecker
8+
{
9+
public static void RunVersionChecker()
10+
{
11+
Version currentVersion = Assembly.GetCallingAssembly().GetName().Version;
12+
currentVersionString = currentVersion.ToString();
13+
currentVersionString = currentVersionString.Remove(currentVersionString.Length - 2);
14+
15+
try
16+
{
17+
RetrieveVersionInfo();
18+
Version targetVersion = new Version((Config.LoadedSplotchConfig.nightly ? nightly : version) + ".0");
19+
updateNeeded = targetVersion > currentVersion;
20+
21+
targetVersionString = targetVersion.ToString();
22+
targetVersionString = targetVersionString.Remove(targetVersionString.Length - 2);
23+
} catch (Exception) { }
24+
}
25+
26+
private static string version;
27+
private static string nightly;
28+
29+
public static string currentVersionString;
30+
public static string targetVersionString;
31+
public static bool updateNeeded = false;
32+
33+
public static void RetrieveVersionInfo()
34+
{
35+
string result;
36+
using (WebClient client = new WebClient())
37+
result = client.DownloadString("https://raw.githubusercontent.com/commandblox/Splotch/master/version");
38+
39+
string[] lines = result.Replace("\n\r", "\n").Replace("\r\n", "\n").Split('\n');
40+
version = lines[0].Split('=')[1];
41+
nightly = lines[1].Split('=')[1];
42+
}
43+
}
44+
}

version

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
latest=0.2.0
2-
latestNightly=0.2.0
1+
latest=0.2.1
2+
latestNightly=0.2.1

0 commit comments

Comments
 (0)