Fix some more float parsing bugs
This commit is contained in:
parent
29ac927b95
commit
175a569ea4
6 changed files with 108 additions and 16 deletions
|
@ -52,7 +52,7 @@ namespace CLre
|
|||
Fixes.MiniScreenHelper.Init();
|
||||
Fixes.UnderStructureCollider.Init();
|
||||
Fixes.TerrainModifyReset.Init();
|
||||
Fixes.FloatLanguageFix.Init();
|
||||
//Fixes.FloatLanguageFix.Init();
|
||||
|
||||
// API init
|
||||
API.Synergy.ClientHandshakeEngine.Init();
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace CLre.Fixes
|
|||
NumberFormatInfo.InvariantInfo, out result);
|
||||
|
||||
#if DEBUG
|
||||
API.Utility.Logging.Log($"Parsed \"{s}\" into {result}");
|
||||
API.Utility.Logging.Log($"Parsed \"{s}\" into {result} (successfully? {__result})\n{Environment.StackTrace}");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
using System;
|
||||
/*using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CLre.Fixes
|
||||
|
@ -22,6 +23,8 @@ namespace CLre.Fixes
|
|||
|| File.Exists("whateverFloatsYourBoat"))
|
||||
{
|
||||
Enabled = true;
|
||||
API.Utility.Logging.LogWarning("AntiStupidFloats fix enabled, this may cause issues");
|
||||
API.Utility.Logging.MetaLog(args.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -41,30 +44,48 @@ namespace CLre.Fixes
|
|||
[Bugfix(name = "AntiStupidFloats",
|
||||
description = "Force language-agnostic float->string behaviour internally, like all programs should (DISABLED BY DEFAULT)",
|
||||
component = BugfixType.HarmonyPatch, id = 10)]
|
||||
[HarmonyPatch(typeof(float), "ToString", new Type[] { })]
|
||||
[HarmonyPatch]
|
||||
class Float_ToString0_Patch
|
||||
{
|
||||
[HarmonyPostfix] // prefix causes a crash for some reason...
|
||||
public static void AfterMethodCall(float __instance, ref string __result)
|
||||
public static void AfterMethodCall(ref float __instance, ref string __result)
|
||||
{
|
||||
#if DEBUG
|
||||
API.Utility.Logging.MetaLog("Float_ToString0_Patch");
|
||||
#endif
|
||||
if (!FloatLanguageFix.Enabled) return;
|
||||
API.Utility.Logging.LogWarning($"Intercepting float.ToString() to InvariantCulture equivalent\nStackTrace: {Environment.StackTrace}");
|
||||
__result = __instance.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
[HarmonyTargetMethod]
|
||||
public static MethodBase Target()
|
||||
{
|
||||
return AccessTools.Method(typeof(float), "ToString");
|
||||
}
|
||||
|
||||
[Bugfix(name = "EnchantmentTableFloatParseFix",
|
||||
description = "Make all float parsing culture-invariant",
|
||||
component = BugfixType.HarmonyPatch, id = 1)]
|
||||
[HarmonyPatch(typeof(float), "ToString", new Type[] { typeof(string)})]
|
||||
}
|
||||
|
||||
[Bugfix(name = "AntiStupidFloats",
|
||||
description = "Force language-agnostic float->string behaviour internally, like all programs should (DISABLED BY DEFAULT)",
|
||||
component = BugfixType.HarmonyPatch, id = 10)]
|
||||
[HarmonyPatch]
|
||||
class Float_ToString1_Patch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void AfterMethodCall(string format, float __instance, ref string __result)
|
||||
public static void AfterMethodCall(ref string format, ref float __instance, ref string __result)
|
||||
{
|
||||
#if DEBUG
|
||||
API.Utility.Logging.MetaLog("Float_ToString1_Patch");
|
||||
#endif
|
||||
if (!FloatLanguageFix.Enabled) return;
|
||||
API.Utility.Logging.LogWarning($"Intercepting float.ToString(\"{format}\") to InvariantCulture equivalent\nStackTrace: {Environment.StackTrace}");
|
||||
__result = __instance.ToString(format, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
[HarmonyTargetMethod]
|
||||
public static MethodBase Target()
|
||||
{
|
||||
return AccessTools.Method(typeof(float), "ToString", new[] {typeof(string)});
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
|
@ -22,7 +22,7 @@ namespace CLre.Fixes
|
|||
CustomLoggerThread_CreateGameObject_Patch.allowed = true;
|
||||
CustomLoggerThread.CreateGameObject();
|
||||
CustomLoggerThread_CreateGameObject_Patch.allowed = false;
|
||||
API.Utility.Logging.Log($"Completed early log init");
|
||||
API.Utility.Logging.Log("Completed early log init");
|
||||
//System.IO.File.WriteAllText("InitLogSooner.log", $"Done at " + System.DateTime.Now.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -65,10 +65,12 @@ namespace CLre.Fixes
|
|||
FieldInfo quitThreadField = AccessTools.Field(typeof(CustomLoggerThread), "_quitThread");
|
||||
|
||||
MethodInfo flushLoggerMethod = AccessTools.Method(typeof(CustomLoggerThread), "FlushLogger");
|
||||
Flusher flushLogger = (Flusher) Delegate.CreateDelegate(typeof(Action), null, flushLoggerMethod);
|
||||
Flusher flushLogger = API.Utility.Reflection.BuildDelegate<Flusher>(flushLoggerMethod, null);
|
||||
//Flusher flushLogger = (Flusher) Delegate.CreateDelegate(typeof(Action), null, flushLoggerMethod);
|
||||
|
||||
MethodInfo forceFlushMethod = AccessTools.Method("CustomLogger:ForceFlush");
|
||||
Flusher forceFlush = (Flusher) Delegate.CreateDelegate(typeof(Action), null, forceFlushMethod);
|
||||
Flusher forceFlush = API.Utility.Reflection.BuildDelegate<Flusher>(forceFlushMethod, null);
|
||||
//Flusher forceFlush = (Flusher) Delegate.CreateDelegate(typeof(Action), null, forceFlushMethod);
|
||||
|
||||
Thread.MemoryBarrier();
|
||||
IsLogStarted = true;
|
||||
|
|
69
CLre/Fixes/OfflineGameTimeSavingFloatFix.cs
Normal file
69
CLre/Fixes/OfflineGameTimeSavingFloatFix.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using SQL;
|
||||
using Svelto.DataStructures;
|
||||
|
||||
namespace CLre.Fixes
|
||||
{
|
||||
public class OfflineGameTimeSavingFloatFix
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Bugfix(name = "OfflineGameTimeSavingFloatFix",
|
||||
description = "Make game time save properly for everyone, even when floats contain a comma",
|
||||
component = BugfixType.HarmonyPatch, id = 11)]
|
||||
[HarmonyPatch]
|
||||
class OfflineSaveServerGameTimeRequest_DoRequest_Patch
|
||||
{
|
||||
private const string QUERY = "INSERT OR REPLACE INTO gametime (gameId, gameTime) VALUES (@GameId, @GameTime)";
|
||||
|
||||
[HarmonyPrefix]
|
||||
public static bool BeforeMethodCall(object __instance, ref object ____dependency)
|
||||
{
|
||||
//API.Utility.Logging.Log("Intercepting OfflineSaveServerGameTimeRequest.DoRequest");
|
||||
//if (____dependency == null) return true;
|
||||
#if DEBUG
|
||||
API.Utility.Logging.Log(
|
||||
"Replacing OfflineSaveServerGameTimeRequest.DoRequest SQL query with safer alternative");
|
||||
#endif
|
||||
// TODO optimise
|
||||
ISQL sql = Traverse.Create(__instance).Property<ISQL>("sql").Value;
|
||||
Traverse dep = Traverse.Create(____dependency);
|
||||
// populate params
|
||||
FasterList<SQLParam> sqlParams = new FasterList<SQLParam>();
|
||||
sqlParams.Add(new SQLParam("@GameId", dep.Field<long>("gameId").Value));
|
||||
sqlParams.Add(new SQLParam("@GameTime", dep.Field<double>("gameTime").Value));
|
||||
// actually perform query
|
||||
sql.ExecuteSaveQuery(QUERY, OnComplete, OnError, sqlParams);
|
||||
#if DEBUG
|
||||
API.Utility.Logging.Log("Executed corrected game time saving SQL query");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void OnComplete(int numberRowsEdited)
|
||||
{
|
||||
#if DEBUG
|
||||
API.Utility.Logging.Log(
|
||||
$"Completed OfflineSaveServerGameTimeRequest_DoRequest_Patch SQL Query ({numberRowsEdited} rows)");
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void OnError(Exception e)
|
||||
{
|
||||
#if DEBUG
|
||||
API.Utility.Logging.LogError(
|
||||
$"Error in OfflineSaveServerGameTimeRequest_DoRequest_Patch SQL Query: {e}\n{e.StackTrace}");
|
||||
#endif
|
||||
}
|
||||
|
||||
[HarmonyTargetMethod]
|
||||
public static MethodBase Target()
|
||||
{
|
||||
return AccessTools.Method(
|
||||
"Requests.ServerSaving.ServerLoginTime.OfflineSaveServerGameTimeRequest:DoRequest");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ namespace CLre.Fixes
|
|||
[HarmonyPrefix]
|
||||
public static bool BeforeMethodCall(object __instance, object ____dependency)
|
||||
{
|
||||
API.Utility.Logging.Log("Intercepting OfflineSavePlayerSpawnPointRequest.DoRequest");
|
||||
//API.Utility.Logging.Log("Intercepting OfflineSavePlayerSpawnPointRequest.DoRequest");
|
||||
if (____dependency == null) return true;
|
||||
#if DEBUG
|
||||
API.Utility.Logging.Log("Replacing OfflineSavePlayerSpawnPointRequest.DoRequest SQL squery with safer alternative");
|
||||
|
|
Loading…
Reference in a new issue