Upload from upload_mods.ps1

This commit is contained in:
Nathaniel Cosford
2025-06-04 16:44:53 +09:30
commit f1fbbe67bb
1722 changed files with 165268 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using JetBrains.Annotations;
using VersionEnforcer.Scripts;
namespace VersionEnforcer.Harmony
{
[UsedImplicitly]
public class Harmony_GameManager
{
[HarmonyPatch(typeof(GameManager), "ShowMessagePlayerDenied")]
public class GameManager_ShowMessagePlayerDeniedPatch
{
[UsedImplicitly]
public static bool Prefix(GameManager __instance, GameUtils.KickPlayerData _kickData)
{
string text;
string kickReason;
if (_kickData.reason == (GameUtils.EKickReason)500)
{
kickReason = "Mod versions do not match server";
text = string.Format(Localization.Get("auth_ModVersionMismatch"), _kickData.customReason);
}
else
{
kickReason = _kickData.ToString();
text = _kickData.LocalizedMessage();
}
var guiWindowManager = Traverse.Create(__instance).Field("windowManager")?.GetValue() as GUIWindowManager;
if (guiWindowManager == null)
{
Log.Warning($"{Globals.LOG_TAG} Unable to find windowManager");
return true;
}
var messageBoxWindowGroupController =
((XUiWindowGroup)(guiWindowManager).GetWindow(XUiC_MessageBoxWindowGroup.ID)).Controller as
XUiC_MessageBoxWindowGroup;
if (messageBoxWindowGroupController == null)
{
Log.Warning($"{Globals.LOG_TAG} Unable to get window with ID {XUiC_MessageBoxWindowGroup.ID}");
return true;
}
Log.Out($"[NET] Kicked from server: {kickReason}");
messageBoxWindowGroupController.ShowMessage(Localization.Get("auth_messageTitle"), text);
return false;
}
}
}
}

View File

@@ -0,0 +1,147 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using VersionEnforcer.Scripts;
namespace VersionEnforcer.Harmony
{
[UsedImplicitly]
public class Harmony_NetPackagePlayerLogin
{
private const string DELIMITER = ":::";
private static int lastCustomFieldsByteSize;
[HarmonyPatch(typeof(NetPackagePlayerLogin), "read")]
public class NetPackagePlayerLogin_ReadPatch
{
[UsedImplicitly]
private static bool Prefix(NetPackagePlayerLogin __instance, PooledBinaryReader _br,
ref string ___playerName,
ref ValueTuple<PlatformUserIdentifierAbs, string> ___platformUserAndToken,
ref ValueTuple<PlatformUserIdentifierAbs, string> ___crossplatformUserAndToken,
ref string ___version,
ref string ___compVersion
)
{
var instanceTraverse = Traverse.Create(__instance);
Log.Out("NPPL.Read");
// Vanilla Fields
/*___playerName = _br.ReadString();
___platformUserAndToken = new ValueTuple<PlatformUserIdentifierAbs, string>(PlatformUserIdentifierAbs.FromStream(_br, false, true), _br.ReadString());
___crossplatformUserAndToken = new ValueTuple<PlatformUserIdentifierAbs, string>(PlatformUserIdentifierAbs.FromStream(_br, false, true), _br.ReadString());
___version = _br.ReadString();
___compVersion = _br.ReadString();*/
instanceTraverse.Field("playerName")?.SetValue(_br.ReadString());
instanceTraverse.Field("platformUserAndToken")?.SetValue((
PlatformUserIdentifierAbs.FromStream(_br, _inclCustomData: true), _br.ReadString()));
instanceTraverse.Field("crossplatformUserAndToken")?.SetValue((
PlatformUserIdentifierAbs.FromStream(_br, _inclCustomData: true), _br.ReadString()));
instanceTraverse.Field("version")?.SetValue(_br.ReadString());
instanceTraverse.Field("compVersion")?.SetValue(_br.ReadString());
// Modded Fields
var numMods = _br.ReadInt32();
var mods = new List<CustomVersionAuthorizer.ModVersionInfo>();
var strLen = 0;
for (int i = 0; i < numMods; i++)
{
var str = _br.ReadString();
strLen += str.Length;
string[] modInfo = str.Split(new[] { DELIMITER }, StringSplitOptions.None);
if (modInfo.Length < 2) continue;
mods.Add(new CustomVersionAuthorizer.ModVersionInfo { ModName = modInfo[0], ModVersion = modInfo[1] });
}
lastCustomFieldsByteSize = sizeof(Int32) + strLen * 2;
var platformUserAndToken =
// ReSharper disable once PossibleNullReferenceException
((PlatformUserIdentifierAbs userId, string token))instanceTraverse.Field("platformUserAndToken")
?.GetValue();
if (CustomVersionAuthorizer.PlatformUserIdToProvidedCustomVersion.ContainsKey(platformUserAndToken.userId
.ReadablePlatformUserIdentifier))
{
CustomVersionAuthorizer.PlatformUserIdToProvidedCustomVersion[
platformUserAndToken.userId.ReadablePlatformUserIdentifier] = mods;
}
else
{
CustomVersionAuthorizer.PlatformUserIdToProvidedCustomVersion.Add(
platformUserAndToken.userId.ReadablePlatformUserIdentifier, mods);
}
return false;
}
}
[HarmonyPatch(typeof(NetPackagePlayerLogin), "write")]
public class NetPackagePlayerLogin_WritePatch
{
[UsedImplicitly]
private static bool Prefix(NetPackagePlayerLogin __instance, PooledBinaryWriter _bw)
{
var instanceTraverse = Traverse.Create(__instance);
var playerName = instanceTraverse.Field("playerName")?.GetValue() as string;
// ReSharper disable once PossibleNullReferenceException
var platformUserAndToken =
((PlatformUserIdentifierAbs userId, string token))instanceTraverse.Field("platformUserAndToken")
?.GetValue();
// ReSharper disable once PossibleNullReferenceException
var crossplatformUserAndToken =
((PlatformUserIdentifierAbs userId, string token))instanceTraverse
.Field("crossplatformUserAndToken")?.GetValue();
var version = instanceTraverse.Field("version")?.GetValue() as string;
var compVersion = instanceTraverse.Field("compVersion")?.GetValue() as string;
// Vanilla Fields
Log.Out("NPPL.Write");
#region base.write(_bw) equivalent replacement
_bw.Write((byte)__instance.PackageId);
#endregion
// ReSharper disable once AssignNullToNotNullAttribute
_bw.Write(playerName);
platformUserAndToken.userId.ToStream(_bw, true);
_bw.Write(platformUserAndToken.token ?? "");
crossplatformUserAndToken.userId.ToStream(_bw, true);
_bw.Write(crossplatformUserAndToken.token ?? "");
// ReSharper disable once AssignNullToNotNullAttribute
_bw.Write(version);
// ReSharper disable once AssignNullToNotNullAttribute
_bw.Write(compVersion);
// Modded
var loadedMods = ModManager.GetLoadedMods();
var mods = new List<string>();
foreach (var mod in loadedMods)
{
mods.Add($"{mod.Name}{DELIMITER}{mod.VersionString}");
}
_bw.Write(loadedMods.Count);
foreach (var str in mods)
{
_bw.Write(str);
}
return false;
}
}
[HarmonyPatch(typeof(NetPackagePlayerLogin), "GetLength")]
public class NetPackagePlayerLogin_GetLengthPatch
{
[UsedImplicitly]
// ReSharper disable once RedundantAssignment
private static bool Prefix(NetPackagePlayerLogin __instance, ref int __result)
{
__result = __instance.GetLength() + lastCustomFieldsByteSize;
return false;
}
}
}
}