diff --git a/CHANGELOG.md b/CHANGELOG.md index 52126dc21..efc915f4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ ## Changelog -0.6.3: +0.7.0: -- Fixed instance where error would trigger by loading saves made on earlier Nebula versions. **WARNING: All previous client inventory and position data will be lost!** (should be for the last time!) -- Fixed error that was triggered by the client loading a planet after traveling to a different planetary system +- @phantomgamers: Fixed instance where error would trigger by loading saves made on earlier Nebula versions. **WARNING: All previous client inventory and position data will be lost!** (should be for the last time!) +- @phantomgamers: Fixed error that was triggered by the client loading a planet after traveling to a different planetary system +- @phantomgamers: Fixed error that was triggered by the client warping outside of a planetary system +- @starfi5h: Added syncing of solar sails and rockets when client does not have the planet they originated from loaded. +- @sp00ktober: Implemented smooth loading of factories for clients (fixed clients phasing through planet when flying too fast) 0.6.2: diff --git a/NebulaPatcher/Patches/Transpilers/ACH_BroadcastStar_Transpiler.cs b/NebulaPatcher/Patches/Transpilers/ACH_BroadcastStar_Transpiler.cs new file mode 100644 index 000000000..eb9fd55a9 --- /dev/null +++ b/NebulaPatcher/Patches/Transpilers/ACH_BroadcastStar_Transpiler.cs @@ -0,0 +1,66 @@ +using HarmonyLib; +using NebulaWorld; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Reflection.Emit; + +namespace NebulaPatcher.Patches.Transpilers +{ + [HarmonyPatch(typeof(ACH_BroadcastStar))] + internal class ACH_BroadcastStar_Transpiler + { + /* + * Returns early if + * instance.gameData.factories[factoryId]?.powerSystem?.genPool[generatorId] == null || instance.gameData.factories[factoryId].index == -1 + * while in a multiplayer session as a client + */ + [HarmonyTranspiler] + [HarmonyPatch(nameof(ACH_BroadcastStar.OnGameTick))] + private static IEnumerable OnGameTick_Transpiler(IEnumerable instructions, ILGenerator il) + { + try + { + CodeMatcher codeMatcher = new CodeMatcher(instructions, il) + .MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(i => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "gameData"), + new CodeMatch(i => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "factories"), + new CodeMatch(i => i.IsLdloc()), + new CodeMatch(OpCodes.Ldelem_Ref) + ); + + CodeInstruction factoryIdInstruction = codeMatcher.InstructionAt(3); + CodeInstruction generatorIdInstruction = codeMatcher.InstructionAt(7); + + return codeMatcher + .CreateLabel(out Label label) + .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) + .InsertAndAdvance(factoryIdInstruction) + .InsertAndAdvance(generatorIdInstruction) + .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate>((instance, factoryId, generatorId) => + { + if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) + { + return true; + } + + if (instance.gameData.factories[factoryId]?.powerSystem?.genPool[generatorId] == null || instance.gameData.factories[factoryId].index == -1) + { + return false; + } + + return true; + })) + .InsertAndAdvance(new CodeInstruction(OpCodes.Brtrue, label)) + .InsertAndAdvance(new CodeInstruction(OpCodes.Ret)) + .InstructionEnumeration(); + } + catch + { + NebulaModel.Logger.Log.Error("ACH_BroadcastStar.OnGameTick_Transpiler failed. Mod version not compatible with game version."); + return instructions; + } + } + } +} \ No newline at end of file diff --git a/version.json b/version.json index 5e76c326d..0ff53a043 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "0.6.3", + "version": "0.7.0", "assemblyVersion": { "precision": "build" },