Skip to content

Commit

Permalink
Merge pull request #453 from PhantomGamers/patch-libs
Browse files Browse the repository at this point in the history
DSP 0.8.22.8915 Compatibility + Misc Changes
  • Loading branch information
PhantomGamers authored Sep 30, 2021
2 parents 7e52caa + 3a55428 commit c53d636
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 78 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog

0.6.2:

- Fixed error when loading saves that were created before 0.6.0. **WARNING: All previous client inventory and position data will be lost!**
- Improved compatibility with GigaStations mod (thanks to @kremnev8)
- Removed extraneous dlls that were mistakenly included in the previous release
- Now supports DSP version 0.8.22.8915+ (thanks to @starfi5h!)

0.6.1:

- Fixed statistics syncing (thanks to @starfi5h)
Expand Down
20 changes: 8 additions & 12 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,18 @@

<!-- Shared Items -->
<ItemGroup Label="NuGets">
<PackageReference Include="Microsoft.Unity.Analyzers" Version="1.11.0" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.205" PrivateAssets="all" />
<PackageReference Include="Microsoft.Unity.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.*" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Label="NuGetsMain" Condition=" '$(MSBuildProjectName)' != 'NebulaAPI' ">
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.2.12" />
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.*" />
</ItemGroup>

<ItemGroup Label="BepInEx">
<PackageReference Include="BepInEx.Core" Version="5.4.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Analyzers" Version="1.0.*" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Label="Dyson Sphere Program">
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" PrivateAssets="all" ExcludeAssets="runtime" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" PrivateAssets="all" ExcludeAssets="runtime" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.UI.dll" Private="false" SpecificVersion="true" />
<ItemGroup Label="Core">
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" PrivateAssets="all" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" IncludeAssets="compile" />
</ItemGroup>
</Project>
Binary file removed Libs/UnityEngine.UI.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions NebulaAPI/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

1.1.1:

- Removed extraneous dll that was mistakenly included in the previous release

1.1.0:

- Float3 IPlayerData.MechaColor has been changed to Float4[] IPlayerData.MechaColors in line with changes introduced in DSP version 0.8.21.8562.
Expand Down
2 changes: 1 addition & 1 deletion NebulaAPI/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.1.0",
"version": "1.1.1",
"assemblyVersion": {
"precision": "build"
},
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static void GameTick_Postfix(GameData __instance, long time)
if (stationComponent != null && stationComponent.isStellar)
{
//Debug.Log("enter " + stationComponent.gid + " (" + GameMain.galaxy.PlanetById(stationComponent.planetId).displayName + ")");
StationComponent_Transpiler.ILSUpdateShipPos(stationComponent, timeGene, dt, shipSailSpeed, shipWarpSpeed, shipCarries, gStationPool, astroPoses, relativePos, relativeRot, starmap, null);
StationComponent_Transpiler.ILSUpdateShipPos(stationComponent, GameMain.galaxy.PlanetById(stationComponent.planetId).factory, timeGene, dt, shipSailSpeed, shipWarpSpeed, shipCarries, gStationPool, astroPoses, relativePos, relativeRot, starmap, null);
}
}
}
Expand Down
92 changes: 29 additions & 63 deletions NebulaPatcher/Patches/Transpilers/StationComponent_Transpiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -892,16 +892,16 @@ public static IEnumerable<CodeInstruction> InternalTickRemote_Transpiler(IEnumer

[HarmonyReversePatch]
[HarmonyPatch(nameof(StationComponent.InternalTickRemote))]
public static void ILSUpdateShipPos(StationComponent stationComponent, int timeGene, double dt, float shipSailSpeed, float shipWarpSpeed, int shipCarries, StationComponent[] gStationPool, AstroPose[] astroPoses, VectorLF3 relativePos, Quaternion relativeRot, bool starmap, int[] consumeRegister)
public static void ILSUpdateShipPos(StationComponent stationComponent, PlanetFactory factory, int timeGene, double dt, float shipSailSpeed, float shipWarpSpeed, int shipCarries, StationComponent[] gStationPool, AstroPose[] astroPoses, VectorLF3 relativePos, Quaternion relativeRot, bool starmap, int[] consumeRegister)
{

IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{

// find begin of ship movement computation, c# 428 IL 2075
int origShipUpdateCodeBeginPos = new CodeMatcher(instructions)
// find begin of ship movement computation, c# 436 IL 2090
CodeMatcher matcher = new CodeMatcher(instructions);
int origShipUpdateCodeBeginPos = matcher
.MatchForward(false,
new CodeMatch(OpCodes.Ldarg_3),
new CodeMatch(i => i.IsLdarg()),
new CodeMatch(OpCodes.Ldc_R4),
new CodeMatch(OpCodes.Div),
new CodeMatch(i => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "Sqrt"),
Expand All @@ -912,80 +912,55 @@ IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instruction
new CodeMatch(OpCodes.Ldc_R4),
new CodeMatch(OpCodes.Ble_Un))
.Pos;

// cut out only that part of original function, but keep the first 5 IL lines (they create the 'bool flag' which is needed)
CodeMatcher matcher = new CodeMatcher(instructions);
for (int i = 0; i < matcher.Length; i++)
for (matcher.Start().Advance(6); matcher.Pos < origShipUpdateCodeBeginPos;)
{
if (matcher.Pos < origShipUpdateCodeBeginPos && matcher.Pos > 5)
{
matcher.SetAndAdvance(OpCodes.Nop, null);
}
else
{
matcher.Advance(1);
}
matcher.SetAndAdvance(OpCodes.Nop, null);
}
instructions = matcher.InstructionEnumeration();

// remove c# 470 - 493 IL 2201 - 2353 (which is just after the first addItem() call)
int origTempBlockIndexStart = new CodeMatcher(instructions)
// remove c# 478 - 501 IL 2215 - 2367 (which is just after the first addItem() call)
int indexStart = matcher.Start()
.MatchForward(true,
new CodeMatch(i => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "AddItem"),
new CodeMatch(OpCodes.Pop))
.Pos;
int origTempBlockIndexEnd = new CodeMatcher(instructions)
.MatchForward(true,
new CodeMatch(i => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "AddItem"))
.Pos + 1;
int indexEnd = matcher
.MatchForward(false,
new CodeMatch(OpCodes.Br))
.Pos;

matcher.Start()
.Advance(origTempBlockIndexStart + 1);
for (; matcher.Pos < origTempBlockIndexEnd;)
for (matcher.Start().Advance(indexStart); matcher.Pos < indexEnd;)
{
matcher.SetAndAdvance(OpCodes.Nop, null);
}
instructions = matcher.InstructionEnumeration();

// remove c# 937 - 1014 IL 4548 - 4921 (TODO: and fetch data from server)
origTempBlockIndexStart = new CodeMatcher(instructions)
indexStart = matcher.Start()
.MatchForward(true,
new CodeMatch(i => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "AddItem"),
new CodeMatch(OpCodes.Pop),
new CodeMatch(OpCodes.Ldloca_S),
new CodeMatch(OpCodes.Ldc_I4_0),
new CodeMatch(OpCodes.Stfld),
new CodeMatch(OpCodes.Ldarg_0))
.Pos - 3; // to also remove 'shipData.itemCount = 0;'
origTempBlockIndexEnd = new CodeMatcher(instructions)
.Advance(origTempBlockIndexStart)
new CodeMatch(OpCodes.Pop))
.Pos + 1;
indexEnd = matcher
.MatchForward(false,
new CodeMatch(OpCodes.Br))
.Pos;

matcher.Start()
.Advance(origTempBlockIndexStart);
for (; matcher.Pos < origTempBlockIndexEnd;)
for (matcher.Start().Advance(indexStart); matcher.Pos < indexEnd;)
{
matcher.SetAndAdvance(OpCodes.Nop, null);
}

// remove addItem() calls
instructions = new CodeMatcher(instructions)
matcher.Start()
.MatchForward(false,
new CodeMatch(i => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "AddItem"))
.SetAndAdvance(OpCodes.Pop, null)
.InsertAndAdvance(new CodeInstruction(OpCodes.Pop))
.MatchForward(false,
new CodeMatch(i => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "AddItem"))
.SetAndAdvance(OpCodes.Pop, null)
.InsertAndAdvance(new CodeInstruction(OpCodes.Pop))
.InstructionEnumeration();
.InsertAndAdvance(new CodeInstruction(OpCodes.Pop));

// remove c# 1019 - 1049 IL 4923 - 5069 (TODO: and fetch data from server) (NOTE: this does also remove the TakeItem() call)
origTempBlockIndexStart = new CodeMatcher(instructions)
indexStart = matcher.Start()
.MatchForward(false,
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Ldfld),
Expand All @@ -997,8 +972,7 @@ IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instruction
new CodeMatch(OpCodes.Ldloca_S),
new CodeMatch(i => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "TakeItem"))
.Pos + 1; // to exclude the Br opcode from vanishing
origTempBlockIndexEnd = new CodeMatcher(instructions)
.Advance(origTempBlockIndexStart)
indexEnd = matcher
.MatchForward(true,
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Ldelema),
Expand All @@ -1010,35 +984,30 @@ IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instruction
new CodeMatch(OpCodes.Stind_I4))
.Advance(1)
.Pos;

matcher = new CodeMatcher(instructions)
.Advance(origTempBlockIndexStart);
for (; matcher.Pos < origTempBlockIndexEnd;)
for (matcher.Start().Advance(indexStart); matcher.Pos < indexEnd;)
{
matcher.SetAndAdvance(OpCodes.Nop, null);
}
instructions = matcher.InstructionEnumeration();

// remove weird code thats left over after cut out from above
matcher.Advance(2);
for (int i = 0; i < 4; i++)
{
matcher.SetAndAdvance(OpCodes.Nop, null);
}
instructions = matcher.InstructionEnumeration();

// remove c# 928 - 932 (adding warper from station to ship)
//matcher3.Start();
CodeMatcher matcher3 = new CodeMatcher(instructions, il);
int indexStart = matcher3.MatchForward(false,
indexStart = matcher.Start()
.MatchForward(false,
new CodeMatch(OpCodes.Ldarg_S),
new CodeMatch(OpCodes.Stloc_S),
new CodeMatch(OpCodes.Ldc_I4_0),
new CodeMatch(OpCodes.Stloc_S),
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Ldloca_S))
.Pos;
int indexEnd = matcher3.MatchForward(true,
indexEnd = matcher.Start()
.MatchForward(true,
new CodeMatch(OpCodes.Stind_I4),
new CodeMatch(OpCodes.Leave),
new CodeMatch(OpCodes.Ldloc_S),
Expand All @@ -1047,15 +1016,12 @@ IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instruction
new CodeMatch(OpCodes.Call),
new CodeMatch(OpCodes.Endfinally))
.Pos;
matcher3.Start();
matcher3.Advance(indexStart);
for (; matcher3.Pos < indexEnd;)
for (matcher.Start().Advance(indexStart); matcher.Pos < indexEnd;)
{
matcher3.SetAndAdvance(OpCodes.Nop, null);
matcher.SetAndAdvance(OpCodes.Nop, null);
}
instructions = matcher3.InstructionEnumeration();

return instructions;
return matcher.InstructionEnumeration();
}

_ = Transpiler(null, null);
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "0.6.1",
"version": "0.6.2",
"assemblyVersion": {
"precision": "build"
},
Expand Down

0 comments on commit c53d636

Please sign in to comment.