Skip to content

Commit 1a1ff27

Browse files
committed
Initial
0 parents  commit 1a1ff27

9 files changed

Lines changed: 420 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bin/
2+
obj/
3+
/packages/
4+
riderModule.iml
5+
/_ReSharper.Caches/

Core.cs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using System;
2+
using System.Xml.Linq;
3+
using HarmonyLib;
4+
using UnityEngine;
5+
using System.IO;
6+
using System.Linq;
7+
8+
public class Core : IModApi
9+
{
10+
private static Mod ModInstance;
11+
private static XDocument configDoc;
12+
private const string ConfigFileName = "versioncheck.xml";
13+
private static bool versionMismatchShown = false;
14+
15+
public void InitMod(Mod modInstance)
16+
{
17+
ModInstance = modInstance;
18+
if (LoadConfig())
19+
{
20+
Harmony.CreateAndPatchAll(typeof(Core).Assembly);
21+
ModEvents.GameStartDone.RegisterHandler(OnGameStartDone);
22+
23+
if (GetConfigBool("DisableNewsScreen"))
24+
{
25+
XUiC_MainMenu.shownNewsScreenOnce = true;
26+
}
27+
}
28+
else
29+
{
30+
Debug.LogError($"[VersionCheckMod] Failed to load configuration file: {ConfigFileName}");
31+
}
32+
}
33+
34+
private static bool LoadConfig()
35+
{
36+
string configPath = FindConfigFile();
37+
if (string.IsNullOrEmpty(configPath))
38+
{
39+
return false;
40+
}
41+
42+
try
43+
{
44+
configDoc = XDocument.Load(configPath);
45+
return true;
46+
}
47+
catch (Exception ex)
48+
{
49+
Debug.LogError($"[VersionCheckMod] Error loading configuration file: {ex.Message}");
50+
return false;
51+
}
52+
}
53+
54+
private static string FindConfigFile()
55+
{
56+
// Search for the config file in all possible mod directories
57+
foreach (string modPath in ModManager.GetLoadedMods().Select(mod => mod.Path))
58+
{
59+
string fullPath = Path.Combine(modPath, ConfigFileName);
60+
if (File.Exists(fullPath))
61+
{
62+
return fullPath;
63+
}
64+
}
65+
66+
Debug.LogWarning($"[VersionCheckMod] Configuration file {ConfigFileName} not found in any mod directory.");
67+
return null;
68+
}
69+
70+
private static string GetConfigString(string key)
71+
{
72+
return configDoc.Root.Element("Settings").Element(key)?.Value ?? string.Empty;
73+
}
74+
75+
private static bool GetConfigBool(string key)
76+
{
77+
return bool.TryParse(GetConfigString(key), out bool result) && result;
78+
}
79+
80+
private static void OnGameStartDone()
81+
{
82+
CheckVersions();
83+
}
84+
85+
[HarmonyPatch(typeof(XUiC_MainMenu))]
86+
[HarmonyPatch("OnOpen")]
87+
public class XUiC_MainMenu_OnOpen_Patch
88+
{
89+
static void Postfix(XUiC_MainMenu __instance)
90+
{
91+
CheckVersions(__instance.xui);
92+
}
93+
}
94+
95+
private static void CheckVersions(XUi xui = null)
96+
{
97+
if (versionMismatchShown)
98+
{
99+
return;
100+
}
101+
102+
string gameVersion = GetGameVersion();
103+
string modVersion = GetConfigString("ModVersion");
104+
105+
if (gameVersion != modVersion && xui != null)
106+
{
107+
DisplayVersionMismatchMessage(xui, gameVersion, modVersion);
108+
versionMismatchShown = true;
109+
}
110+
}
111+
112+
private static string GetGameVersion()
113+
{
114+
return $"{Constants.cVersionMajor}.{Constants.cVersionMinor}.{Constants.cVersionBuild}";
115+
}
116+
117+
private static void DisplayVersionMismatchMessage(XUi xui, string gameVersion, string modVersion)
118+
{
119+
string title = configDoc.Root.Element("Settings")?.Element("ErrorMessage")?.Element("Title")?.Value
120+
?? "Version Mismatch Detected";
121+
string descriptionFormat = configDoc.Root.Element("Settings")?.Element("ErrorMessage")?.Element("Description")?.Value
122+
?? "The game version ({0}) does not match the mod version ({1}). This may cause issues.";
123+
124+
string message = string.Format(descriptionFormat, gameVersion, modVersion);
125+
126+
XUiC_MessageBoxWindowGroup.ShowMessageBox(
127+
xui,
128+
title,
129+
message,
130+
XUiC_MessageBoxWindowGroup.MessageBoxTypes.Ok,
131+
() => {
132+
// Return to main menu
133+
xui.playerUI.windowManager.CloseAllOpenWindows();
134+
xui.playerUI.windowManager.Open("mainmenu", true);
135+
},
136+
null,
137+
false,
138+
false
139+
);
140+
}
141+
}

Properties/AssemblyInfo.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("VersionChecker")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("VersionChecker")]
12+
[assembly: AssemblyCopyright("Copyright © 2024")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("89DB494E-A585-48EE-A426-2D9A8992B886")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

Readme.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Version Check Mod for 7 Days to Die
2+
3+
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.
4+
5+
## Features
6+
7+
- Version mismatch detection: Compares the game version with the mod version and displays a warning if they don't match.
8+
- Configurable error messages: Customize the title and description of the version mismatch warning.
9+
- Option to disable the news screen: Skip the news screen on game startup.
10+
11+
## Installation
12+
13+
1. Download the latest release of the mod from the [Releases](https://github.com/yourusername/versioncheckmod/releases) page.
14+
2. Extract the contents of the zip file into your 7 Days to Die Mods folder.
15+
3. Ensure that the `versioncheck.xml` file is present in the mod folder.
16+
17+
## Configuration
18+
19+
The mod is configured using the `versioncheck.xml` file. You can customize the following settings:
20+
21+
- `ModVersion`: Set this to the version of the game that the mod is designed for.
22+
- `DisableNewsScreen`: Set to `true` to skip the news screen on game startup.
23+
- `ErrorMessage`:
24+
- `Title`: Customize the title of the version mismatch warning.
25+
- `Description`: Customize the description of the version mismatch warning.
26+
27+
Example configuration:
28+
29+
```xml
30+
<?xml version="1.0" encoding="UTF-8"?>
31+
<xml>
32+
<!-- Configuration for the Version Check -->
33+
<Settings>
34+
<!-- Set this to the version of the game you're modding -->
35+
<!-- This should match the version in the game's build version which is visible in the main menu (top right) -->
36+
<!-- Example: b316 would be <ModVersion>1.0.316</ModVersion> -->
37+
<ModVersion>1.0.316</ModVersion>
38+
39+
<!-- Set to true to disable the news screen on game start -->
40+
<!-- Set to false to keep the default behavior -->
41+
<DisableNewsScreen>false</DisableNewsScreen>
42+
43+
<!-- Customize the version mismatch error message -->
44+
<ErrorMessage>
45+
<!-- Title of the error message box -->
46+
<Title>Version Mismatch Detected</Title>
47+
<!-- Description of the error. Use {0} for game version and {1} for mod version -->
48+
<Description>The game version ({0}) does not match the mod version ({1}). This may cause issues.</Description>
49+
</ErrorMessage>
50+
</Settings>
51+
</xml>
52+
```
53+
54+
## Usage
55+
56+
1. Start 7 Days to Die with the mod installed.
57+
2. If there's a version mismatch between the game and the mod, you'll see a warning message when entering the main menu.
58+
3. The news screen will be skipped if you've set `DisableNewsScreen` to `true` in the configuration.
59+
60+
## Compatibility
61+
62+
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.
63+
You're free to modify this to work with your mod. It should require little if any changes between game versions.
64+
65+
66+
# TODO
67+
68+
Localization
69+
70+
XML conditional version

VersionChecker.csproj

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
4+
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{89DB494E-A585-48EE-A426-2D9A8992B886}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>VersionChecker</RootNamespace>
12+
<AssemblyName>VersionChecker</AssemblyName>
13+
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<LangVersion>default</LangVersion>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="0Harmony">
38+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\Mods\0_TFP_Harmony\0Harmony.dll</HintPath>
39+
</Reference>
40+
<Reference Include="Assembly-CSharp">
41+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\Assembly-CSharp.dll</HintPath>
42+
</Reference>
43+
<Reference Include="Assembly-CSharp-firstpass">
44+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
45+
</Reference>
46+
<Reference Include="System"/>
47+
<Reference Include="System.ComponentModel.Composition">
48+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.ComponentModel.Composition.dll</HintPath>
49+
</Reference>
50+
<Reference Include="System.Configuration">
51+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Configuration.dll</HintPath>
52+
</Reference>
53+
<Reference Include="System.Configuration.Install">
54+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Configuration.Install.dll</HintPath>
55+
</Reference>
56+
<Reference Include="System.Core"/>
57+
<Reference Include="System.Data"/>
58+
<Reference Include="System.Data.DataSetExtensions">
59+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Data.DataSetExtensions.dll</HintPath>
60+
</Reference>
61+
<Reference Include="System.Drawing">
62+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Drawing.dll</HintPath>
63+
</Reference>
64+
<Reference Include="System.EnterpriseServices">
65+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.EnterpriseServices.dll</HintPath>
66+
</Reference>
67+
<Reference Include="System.IO.Compression">
68+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.IO.Compression.dll</HintPath>
69+
</Reference>
70+
<Reference Include="System.IO.Compression.FileSystem">
71+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.IO.Compression.FileSystem.dll</HintPath>
72+
</Reference>
73+
<Reference Include="System.Net.Http">
74+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Net.Http.dll</HintPath>
75+
</Reference>
76+
<Reference Include="System.Numerics">
77+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Numerics.dll</HintPath>
78+
</Reference>
79+
<Reference Include="System.Runtime">
80+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Runtime.dll</HintPath>
81+
</Reference>
82+
<Reference Include="System.Runtime.CompilerServices.Unsafe">
83+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
84+
</Reference>
85+
<Reference Include="System.Runtime.Serialization">
86+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Runtime.Serialization.dll</HintPath>
87+
</Reference>
88+
<Reference Include="System.Security">
89+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Security.dll</HintPath>
90+
</Reference>
91+
<Reference Include="System.ServiceModel.Internals">
92+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.ServiceModel.Internals.dll</HintPath>
93+
</Reference>
94+
<Reference Include="System.ServiceProcess">
95+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.ServiceProcess.dll</HintPath>
96+
</Reference>
97+
<Reference Include="System.Transactions">
98+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Transactions.dll</HintPath>
99+
</Reference>
100+
<Reference Include="System.Windows.Forms">
101+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Windows.Forms.dll</HintPath>
102+
</Reference>
103+
<Reference Include="System.Xml"/>
104+
<Reference Include="System.Xml.Linq">
105+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\System.Xml.Linq.dll</HintPath>
106+
</Reference>
107+
<Reference Include="UnityEngine">
108+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\UnityEngine.dll</HintPath>
109+
</Reference>
110+
<Reference Include="UnityEngine.CoreModule">
111+
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\7 Days To Die\7DaysToDie_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
112+
</Reference>
113+
</ItemGroup>
114+
<ItemGroup>
115+
<Compile Include="Core.cs" />
116+
<Compile Include="Properties\AssemblyInfo.cs"/>
117+
</ItemGroup>
118+
<ItemGroup>
119+
<Content Include="Readme.md" />
120+
<Content Include="versioncheck.xml" />
121+
</ItemGroup>
122+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
123+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
124+
Other similar extension points exist, see Microsoft.Common.targets.
125+
<Target Name="BeforeBuild">
126+
</Target>
127+
<Target Name="AfterBuild">
128+
</Target>
129+
-->
130+
131+
</Project>

VersionChecker.dll

8.5 KB
Binary file not shown.

VersionChecker.pdb

19.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)