Skip to content

Commit 1da704e

Browse files
authored
Merge pull request #719 from starfi5h/pr-tip
Sync UIReferenceSpeedTip and bump to v0.9.12
2 parents d8fb4b5 + bb31f4c commit 1da704e

File tree

8 files changed

+502
-5
lines changed

8 files changed

+502
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## Changelog
22

3+
0.9.12:
4+
- Compatible with game version 0.10.31.24697
5+
- @starfi5h: Client can now use metadata to unlock tech. Sandbox unlock by client is now synced
6+
- @starfi5h: Remove metadata requirement for blueprint tech due to client can't get metadata in MP
7+
- @starfi5h: The right part of logistics control panel (I) is available for loaded planet
8+
- @starfi5h: Sync Reference rate, Import/Export storage, Storage amount in production statistics panel
9+
310
0.9.11:
411
- @starfi5h: Fix half-growth dark fog bases keep regenerating
512
- @starfi5h: Fix combat drones doesn't increase ground base threat
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace NebulaModel.Packets.Statistics;
2+
3+
public class StatisticsReferenceSpeedTipPacket
4+
{
5+
public StatisticsReferenceSpeedTipPacket() { }
6+
7+
public StatisticsReferenceSpeedTipPacket(int itemId, int astroFilter, int itemCycle, int productionProtoId, byte[] binaryData)
8+
{
9+
ItemId = itemId;
10+
AstroFilter = astroFilter;
11+
ItemCycle = itemCycle;
12+
ProductionProtoId = productionProtoId;
13+
BinaryData = binaryData;
14+
}
15+
16+
public int ItemId { get; set; }
17+
public int AstroFilter { get; set; }
18+
public int ItemCycle { get; set; }
19+
public int ProductionProtoId { get; set; }
20+
public byte[] BinaryData { get; set; }
21+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#region
2+
3+
using System;
4+
using System.IO;
5+
using NebulaAPI.Packets;
6+
using NebulaModel.Logger;
7+
using NebulaModel.Networking;
8+
using NebulaModel.Packets;
9+
using NebulaModel.Packets.Statistics;
10+
using NebulaWorld;
11+
12+
#endregion
13+
14+
namespace NebulaNetwork.PacketProcessors.Statistics;
15+
16+
[RegisterPacketProcessor]
17+
internal class StatisticsReferenceSpeedTipProcessor : PacketProcessor<StatisticsReferenceSpeedTipPacket>
18+
{
19+
protected override void ProcessPacket(StatisticsReferenceSpeedTipPacket packet, NebulaConnection conn)
20+
{
21+
if (IsHost)
22+
{
23+
try
24+
{
25+
using var writer = new BinaryUtils.Writer();
26+
Multiplayer.Session.Statistics.GetReferenceSpeedTip(writer.BinaryWriter, packet.ItemId, packet.AstroFilter, packet.ItemCycle, packet.ProductionProtoId);
27+
packet.BinaryData = writer.CloseAndGetBytes();
28+
conn.SendPacket(packet);
29+
}
30+
catch (Exception ex)
31+
{
32+
Log.Warn("StatisticsReferenceSpeedTipPacket request error!");
33+
Log.Warn(ex);
34+
}
35+
}
36+
if (IsClient)
37+
{
38+
try
39+
{
40+
using var reader = new BinaryUtils.Reader(packet.BinaryData);
41+
Multiplayer.Session.Statistics.SetReferenceSpeedTip(reader.BinaryReader, packet.ItemId, packet.AstroFilter, packet.ItemCycle, packet.ProductionProtoId);
42+
}
43+
catch (Exception ex)
44+
{
45+
Log.Warn("StatisticsReferenceSpeedTipPacket response error!");
46+
Log.Warn(ex);
47+
}
48+
}
49+
}
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#region
2+
3+
using System;
4+
using HarmonyLib;
5+
using NebulaModel.Packets.Statistics;
6+
using NebulaWorld;
7+
#pragma warning disable IDE0301 // Simplify collection initialization
8+
9+
#endregion
10+
11+
namespace NebulaPatcher.Patches.Dynamic;
12+
13+
[HarmonyPatch(typeof(UIReferenceSpeedTip))]
14+
internal class UIReferenceSpeedTip_Patch
15+
{
16+
[HarmonyPrefix]
17+
[HarmonyPatch(nameof(UIReferenceSpeedTip.AddEntryDataWithFactory))]
18+
public static bool AddEntryDataWithFactory_Prefix()
19+
{
20+
// Client will use server response to update loadedEntryDatas and loadedSubTipDatas
21+
return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost;
22+
}
23+
24+
[HarmonyPrefix]
25+
[HarmonyPatch(nameof(UIReferenceSpeedTip.SetTip))]
26+
public static void SetTip_Prefix(UIReferenceSpeedTip __instance, int _itemId, int _astroFilter, UIReferenceSpeedTip.EItemCycle _itemCycle)
27+
{
28+
if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) return;
29+
30+
// Client: Send request to server when setting a new tip
31+
if (__instance.itemId == _itemId && __instance.astroFilter == _astroFilter && __instance.itemCycle == _itemCycle) return;
32+
Multiplayer.Session.Network.SendPacket(new StatisticsReferenceSpeedTipPacket(
33+
_itemId, _astroFilter, (int)_itemCycle, 0, Array.Empty<byte>()));
34+
}
35+
36+
[HarmonyPrefix]
37+
[HarmonyPatch(nameof(UIReferenceSpeedTip.SetSubTip))]
38+
public static void SetSubTip_Prefix(UIReferenceSpeedTip __instance, int _productionProtoId)
39+
{
40+
if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) return;
41+
42+
// Client: Send request to server when setting a valid subtip
43+
if (_productionProtoId == 0) return;
44+
Multiplayer.Session.Network.SendPacket(new StatisticsReferenceSpeedTipPacket(
45+
__instance.itemId, __instance.astroFilter, (int)__instance.itemCycle, _productionProtoId, Array.Empty<byte>()));
46+
}
47+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#region
2+
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection.Emit;
6+
using HarmonyLib;
7+
using NebulaModel.Logger;
8+
9+
#endregion
10+
11+
namespace NebulaPatcher.Patches.Transpilers;
12+
13+
[HarmonyPatch(typeof(UIReferenceSpeedTip))]
14+
public static class UIReferenceSpeedTip_Transpiler
15+
{
16+
[HarmonyTranspiler]
17+
[HarmonyPatch(nameof(UIReferenceSpeedTip.RefreshSubEntries))]
18+
private static IEnumerable<CodeInstruction> RefreshSubEntries_Transpiler(IEnumerable<CodeInstruction> instructions)
19+
{
20+
//Remove planetData.factory != null condiction check
21+
//Change: if (planetData != null && planetData.factory != null && this.loadedSubTipDatas[planetData.astroId].astroId == planetData.astroId)
22+
//To: if (planetData != null && this.loadedSubTipDatas[planetData.astroId].astroId == planetData.astroId)
23+
var codeInstructions = instructions as CodeInstruction[] ?? instructions.ToArray();
24+
try
25+
{
26+
return new CodeMatcher(instructions)
27+
.MatchForward(true,
28+
new CodeMatch(OpCodes.Ldfld,
29+
AccessTools.Field(typeof(PlanetData), nameof(PlanetData.factory))),
30+
new CodeMatch(OpCodes.Brfalse)
31+
)
32+
.Repeat(matcher => matcher
33+
.SetAndAdvance(OpCodes.Pop, null)
34+
)
35+
.InstructionEnumeration();
36+
}
37+
catch
38+
{
39+
Log.Error("Transpiler UIReferenceSpeedTip.RefreshSubEntries failed. Reference speed tip may not work properly.");
40+
return codeInstructions;
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)