-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1a1ff27
Showing
9 changed files
with
420 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bin/ | ||
obj/ | ||
/packages/ | ||
riderModule.iml | ||
/_ReSharper.Caches/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using System; | ||
using System.Xml.Linq; | ||
using HarmonyLib; | ||
using UnityEngine; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
public class Core : IModApi | ||
{ | ||
private static Mod ModInstance; | ||
private static XDocument configDoc; | ||
private const string ConfigFileName = "versioncheck.xml"; | ||
private static bool versionMismatchShown = false; | ||
|
||
public void InitMod(Mod modInstance) | ||
{ | ||
ModInstance = modInstance; | ||
if (LoadConfig()) | ||
{ | ||
Harmony.CreateAndPatchAll(typeof(Core).Assembly); | ||
ModEvents.GameStartDone.RegisterHandler(OnGameStartDone); | ||
|
||
if (GetConfigBool("DisableNewsScreen")) | ||
{ | ||
XUiC_MainMenu.shownNewsScreenOnce = true; | ||
} | ||
} | ||
else | ||
{ | ||
Debug.LogError($"[VersionCheckMod] Failed to load configuration file: {ConfigFileName}"); | ||
} | ||
} | ||
|
||
private static bool LoadConfig() | ||
{ | ||
string configPath = FindConfigFile(); | ||
if (string.IsNullOrEmpty(configPath)) | ||
{ | ||
return false; | ||
} | ||
|
||
try | ||
{ | ||
configDoc = XDocument.Load(configPath); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.LogError($"[VersionCheckMod] Error loading configuration file: {ex.Message}"); | ||
return false; | ||
} | ||
} | ||
|
||
private static string FindConfigFile() | ||
{ | ||
// Search for the config file in all possible mod directories | ||
foreach (string modPath in ModManager.GetLoadedMods().Select(mod => mod.Path)) | ||
{ | ||
string fullPath = Path.Combine(modPath, ConfigFileName); | ||
if (File.Exists(fullPath)) | ||
{ | ||
return fullPath; | ||
} | ||
} | ||
|
||
Debug.LogWarning($"[VersionCheckMod] Configuration file {ConfigFileName} not found in any mod directory."); | ||
return null; | ||
} | ||
|
||
private static string GetConfigString(string key) | ||
{ | ||
return configDoc.Root.Element("Settings").Element(key)?.Value ?? string.Empty; | ||
} | ||
|
||
private static bool GetConfigBool(string key) | ||
{ | ||
return bool.TryParse(GetConfigString(key), out bool result) && result; | ||
} | ||
|
||
private static void OnGameStartDone() | ||
{ | ||
CheckVersions(); | ||
} | ||
|
||
[HarmonyPatch(typeof(XUiC_MainMenu))] | ||
[HarmonyPatch("OnOpen")] | ||
public class XUiC_MainMenu_OnOpen_Patch | ||
{ | ||
static void Postfix(XUiC_MainMenu __instance) | ||
{ | ||
CheckVersions(__instance.xui); | ||
} | ||
} | ||
|
||
private static void CheckVersions(XUi xui = null) | ||
{ | ||
if (versionMismatchShown) | ||
{ | ||
return; | ||
} | ||
|
||
string gameVersion = GetGameVersion(); | ||
string modVersion = GetConfigString("ModVersion"); | ||
|
||
if (gameVersion != modVersion && xui != null) | ||
{ | ||
DisplayVersionMismatchMessage(xui, gameVersion, modVersion); | ||
versionMismatchShown = true; | ||
} | ||
} | ||
|
||
private static string GetGameVersion() | ||
{ | ||
return $"{Constants.cVersionMajor}.{Constants.cVersionMinor}.{Constants.cVersionBuild}"; | ||
} | ||
|
||
private static void DisplayVersionMismatchMessage(XUi xui, string gameVersion, string modVersion) | ||
{ | ||
string title = configDoc.Root.Element("Settings")?.Element("ErrorMessage")?.Element("Title")?.Value | ||
?? "Version Mismatch Detected"; | ||
string descriptionFormat = configDoc.Root.Element("Settings")?.Element("ErrorMessage")?.Element("Description")?.Value | ||
?? "The game version ({0}) does not match the mod version ({1}). This may cause issues."; | ||
|
||
string message = string.Format(descriptionFormat, gameVersion, modVersion); | ||
|
||
XUiC_MessageBoxWindowGroup.ShowMessageBox( | ||
xui, | ||
title, | ||
message, | ||
XUiC_MessageBoxWindowGroup.MessageBoxTypes.Ok, | ||
() => { | ||
// Return to main menu | ||
xui.playerUI.windowManager.CloseAllOpenWindows(); | ||
xui.playerUI.windowManager.Open("mainmenu", true); | ||
}, | ||
null, | ||
false, | ||
false | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("VersionChecker")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("VersionChecker")] | ||
[assembly: AssemblyCopyright("Copyright © 2024")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("89DB494E-A585-48EE-A426-2D9A8992B886")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Version Check Mod for 7 Days to Die | ||
|
||
This mod for 7 Days to Die checks for version mismatches between the game and the mod, and provides optional features to enhance the game experience. | ||
|
||
## Features | ||
|
||
- Version mismatch detection: Compares the game version with the mod version and displays a warning if they don't match. | ||
- Configurable error messages: Customize the title and description of the version mismatch warning. | ||
- Option to disable the news screen: Skip the news screen on game startup. | ||
|
||
## Installation | ||
|
||
1. Download the latest release of the mod from the [Releases](https://github.com/yourusername/versioncheckmod/releases) page. | ||
2. Extract the contents of the zip file into your 7 Days to Die Mods folder. | ||
3. Ensure that the `versioncheck.xml` file is present in the mod folder. | ||
|
||
## Configuration | ||
|
||
The mod is configured using the `versioncheck.xml` file. You can customize the following settings: | ||
|
||
- `ModVersion`: Set this to the version of the game that the mod is designed for. | ||
- `DisableNewsScreen`: Set to `true` to skip the news screen on game startup. | ||
- `ErrorMessage`: | ||
- `Title`: Customize the title of the version mismatch warning. | ||
- `Description`: Customize the description of the version mismatch warning. | ||
|
||
Example configuration: | ||
|
||
```xml | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xml> | ||
<!-- Configuration for the Version Check --> | ||
<Settings> | ||
<!-- Set this to the version of the game you're modding --> | ||
<!-- This should match the version in the game's build version which is visible in the main menu (top right) --> | ||
<!-- Example: b316 would be <ModVersion>1.0.316</ModVersion> --> | ||
<ModVersion>1.0.316</ModVersion> | ||
|
||
<!-- Set to true to disable the news screen on game start --> | ||
<!-- Set to false to keep the default behavior --> | ||
<DisableNewsScreen>false</DisableNewsScreen> | ||
|
||
<!-- Customize the version mismatch error message --> | ||
<ErrorMessage> | ||
<!-- Title of the error message box --> | ||
<Title>Version Mismatch Detected</Title> | ||
<!-- Description of the error. Use {0} for game version and {1} for mod version --> | ||
<Description>The game version ({0}) does not match the mod version ({1}). This may cause issues.</Description> | ||
</ErrorMessage> | ||
</Settings> | ||
</xml> | ||
``` | ||
|
||
## Usage | ||
|
||
1. Start 7 Days to Die with the mod installed. | ||
2. If there's a version mismatch between the game and the mod, you'll see a warning message when entering the main menu. | ||
3. The news screen will be skipped if you've set `DisableNewsScreen` to `true` in the configuration. | ||
|
||
## Compatibility | ||
|
||
This mod is designed to work with 7 Days to Die version 1.0. It may work with other versions, but compatibility is not guaranteed. | ||
You're free to modify this to work with your mod. It should require little if any changes between game versions. | ||
|
||
|
||
# TODO | ||
|
||
Localization | ||
|
||
XML conditional version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" | ||
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{89DB494E-A585-48EE-A426-2D9A8992B886}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>VersionChecker</RootNamespace> | ||
<AssemblyName>VersionChecker</AssemblyName> | ||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<LangVersion>default</LangVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="0Harmony"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\Mods\0_TFP_Harmony\0Harmony.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\Assembly-CSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp-firstpass"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System"/> | ||
<Reference Include="System.ComponentModel.Composition"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.ComponentModel.Composition.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Configuration"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Configuration.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Configuration.Install"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Configuration.Install.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Core"/> | ||
<Reference Include="System.Data"/> | ||
<Reference Include="System.Data.DataSetExtensions"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Data.DataSetExtensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Drawing"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Drawing.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.EnterpriseServices"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.EnterpriseServices.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.IO.Compression"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.IO.Compression.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.IO.Compression.FileSystem"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.IO.Compression.FileSystem.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Net.Http"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Net.Http.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Numerics"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Numerics.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Runtime"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Runtime.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Runtime.CompilerServices.Unsafe"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Runtime.CompilerServices.Unsafe.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Runtime.Serialization"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Runtime.Serialization.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Security"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Security.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.ServiceModel.Internals"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.ServiceModel.Internals.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.ServiceProcess"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.ServiceProcess.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Transactions"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Transactions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Windows.Forms"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Windows.Forms.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Xml"/> | ||
<Reference Include="System.Xml.Linq"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Xml.Linq.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\UnityEngine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule"> | ||
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\UnityEngine.CoreModule.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Core.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="Readme.md" /> | ||
<Content Include="versioncheck.xml" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
|
||
</Project> |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.