Skip to content

Commit

Permalink
Switch to using publicized stubs as references
Browse files Browse the repository at this point in the history
This will allow us to:

* See private members in code directly.
* Get notified by the IDE when a name is changed after an update.
* Allow CI instances that do not have the game installed to build Nebula (so that we can use the Github CIs)

Included is a .github\scripts\stub.js file that when ran from the project root will generate all of the references listed in references.txt.

TODO:

* Parse DevEnv.targets if it exists and use that for the DSP directory path.
* Fix PlanetData.onLoaded ambiguity error in PlanetDataRequestProcessor.cs
  • Loading branch information
PhantomGamers committed Jul 30, 2021
1 parent 1403934 commit 6810ceb
Show file tree
Hide file tree
Showing 57 changed files with 283 additions and 187 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esversion": 8
}
11 changes: 11 additions & 0 deletions .github/scripts/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"sourceMap": true,
"lib": [
"ESNext"
]
},
}
8 changes: 8 additions & 0 deletions .github/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "module",
"dependencies": {
"child_process": "^1.0.2",
"fs": "^0.0.1-security",
"path": "^0.12.7"
}
}
95 changes: 95 additions & 0 deletions .github/scripts/stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env node

import { existsSync, fstat, mkdirSync, readFileSync } from "fs";
import { basename, dirname, extname, join, resolve } from "path";
import child_process from "child_process";

const DSP_DIR =
"C:\\Program Files (x86)\\Steam\\steamapps\\common\\Dyson Sphere Program\\";
const BEPINEX_DIR = join(DSP_DIR, "BepInEx\\core\\");
const DSP_ASSEMBLY_DIR = join(DSP_DIR, "DSPGAME_Data\\Managed\\");

const refFile = readReferenceFile();

function main() {
if (!existsSync("Libs")) {
mkdirSync("Libs");
}
publicizeReferenceAssemblies(getReferencePaths());
stubAssemblies(getReferencePaths());
}

function readReferenceFile() {
const refFile = readFileSync("references.txt", "utf8");

if (!refFile) {
throw "Could not read references.txt";
}

return refFile;
}

function getReferenceNames() {
return refFile
.replaceAll("$(BepInExDir)", "")
.replaceAll("$(DSPAssemblyDir)", "")
.replaceAll(".dll", "")
.trim()
.split("\n");
}

function getReferencePaths() {
return refFile
.replaceAll("$(BepInExDir)", BEPINEX_DIR)
.replaceAll("$(DSPAssemblyDir)", DSP_ASSEMBLY_DIR)
.trim()
.split("\n");
}

function publicizeReferenceAssemblies(refPaths) {
const ASSEMBLYPUBLICIZER_PATH = resolve(
"Libs\\AssemblyPublicizer\\AssemblyPublicizer.exe"
);
Array.from(refPaths).forEach((line) => {
child_process.execSync(
'cd "' +
dirname(line) +
'" && "' +
ASSEMBLYPUBLICIZER_PATH +
'" "' +
line +
'"'
);
});
}

function stubAssemblies(refPaths) {
const REFASMER_PATH =
'"' + resolve("Libs\\Refasmer.net461\\RefasmerExe.exe") + '"';
const LIBS_PATH = '"' + resolve("Libs\\") + '"';
Array.from(refPaths).forEach((line) => {
const PUBLICIZED_ASSEMBLIES_PATH =
'"' + dirname(line) + '\\publicized_assemblies\\"';
const PUBLICIZED_ASSEMBLY_PATH =
'"' +
dirname(line) +
"\\publicized_assemblies\\" +
basename(line).slice(0, basename(line).length - extname(line).length) +
"_publicized" +
extname(line);
const cmd =
"cd " +
PUBLICIZED_ASSEMBLIES_PATH +
" && " +
REFASMER_PATH +
" " +
PUBLICIZED_ASSEMBLY_PATH +
'" && move ' +
PUBLICIZED_ASSEMBLY_PATH +
'.refasm.dll" ' +
LIBS_PATH;
child_process.execSync(cmd);
});
}

main();
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# Nebula-specific files
Libs/*
!Libs/DowngradeDll.exe
Libs/AssemblyPublicizer
Libs/Refasmer.net461
DevEnv.targets
dist

Expand Down
32 changes: 17 additions & 15 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
<BepInExDir>$(DSPGameDir)BepInEx\core\</BepInExDir>
<DSPAssemblyDir>$(DSPGameDir)DSPGAME_Data\Managed\</DSPAssemblyDir>
<PluginOutputDirectory>$(DSPGameDir)BepInEx\plugins\Nebula\</PluginOutputDirectory>
<PropSheetPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</PropSheetPath>
</PropertyGroup>

<PropertyGroup Label="Common Properties">
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<OutputPath Condition="Exists('$(DSPGameDir)')">$(PluginOutputDirectory)</OutputPath>
<OutDir>$(OutputPath)</OutDir>
Expand All @@ -41,23 +43,23 @@
</ItemGroup>

<ItemGroup Label="BepInEx">
<Reference Include="$(BepInExDir)0Harmony.dll" Private="false" SpecificVersion="false" />
<Reference Include="$(BepInExDir)BepInEx.dll" Private="false" SpecificVersion="false" />
<Reference Include="$(BepInExDir)BepInEx.Harmony.dll" Private="false" SpecificVersion="false" />
<Reference Include="$(PropsheetPath)\Libs\0Harmony_publicized.dll.refasm.dll" Private="false" SpecificVersion="false" />
<Reference Include="$(PropsheetPath)\Libs\BepInEx_publicized.dll.refasm.dll" Private="false" SpecificVersion="false" />
<Reference Include="$(PropsheetPath)\Libs\BepInEx.Harmony_publicized.dll.refasm.dll" Private="false" SpecificVersion="false" />
</ItemGroup>

<ItemGroup Label="Dyson Sphere Program">
<Reference Include="$(DSPAssemblyDir)Assembly-CSharp.dll" Private="false" SpecificVersion="true" />

<Reference Include="$(DSPAssemblyDir)UnityEngine.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.AnimationModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.CoreModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.IMGUIModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.ParticleSystemModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.PhysicsModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.TextRenderingModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.UI.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.UIElementsModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(DSPAssemblyDir)UnityEngine.UIModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\Assembly-CSharp_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />

<Reference Include="$(PropsheetPath)\Libs\UnityEngine_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.AnimationModule_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.CoreModule_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.IMGUIModule_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.ParticleSystemModule_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.PhysicsModule_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.TextRenderingModule_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.UI_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.UIElementsModule_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.UIModule_publicized.dll.refasm.dll" Private="false" SpecificVersion="true" />
</ItemGroup>
</Project>
Binary file added Libs/0Harmony_publicized.dll.refasm.dll
Binary file not shown.
Binary file added Libs/Assembly-CSharp_publicized.dll.refasm.dll
Binary file not shown.
Binary file added Libs/BepInEx.Harmony_publicized.dll.refasm.dll
Binary file not shown.
Binary file added Libs/BepInEx_publicized.dll.refasm.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Libs/UnityEngine.UI_publicized.dll.refasm.dll
Binary file not shown.
Binary file added Libs/UnityEngine_publicized.dll.refasm.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void ProcessPacket(StorageSyncResponsePacket packet, NebulaConne
StorageManager.ActiveUIStorageGrid._Free();
StorageManager.ActiveUIStorageGrid._Init(storageComponent);
StorageManager.ActiveStorageComponent = storageComponent;
MethodInvoker.GetHandler(AccessTools.Method(typeof(UIStorageGrid), "SetStorageData")).Invoke(StorageManager.ActiveUIStorageGrid, StorageManager.ActiveStorageComponent);
StorageManager.ActiveUIStorageGrid.SetStorageData(StorageManager.ActiveStorageComponent);
StorageManager.ActiveUIStorageGrid._Open();
StorageManager.ActiveUIStorageGrid.OnStorageDataChanged();
StorageManager.ActiveBansSlider.maxValue = (float)storageComponent.size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override void ProcessPacket(StationUIInitialSync packet, NebulaConnection
StationUIManager.UIIsSyncedStage++;
stationWindow._Free();
stationWindow._Init(stationComponent);
AccessTools.Field(typeof(UIStationWindow), "_stationId").SetValue(stationWindow, stationComponent.id);
stationWindow._stationId = stationComponent.id;
stationWindow._Open();
stationWindow._Update();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ class StatisticsPlanetDataProcessor : PacketProcessor<StatisticsPlanetDataPacket
{
public override void ProcessPacket(StatisticsPlanetDataPacket packet, NebulaConnection conn)
{
var property = AccessTools.DeclaredProperty(typeof(PlanetFactory), "planet");
for (int i = 0; i < packet.PlanetsIds.Length; i++)
{
if (GameMain.data.factories[i] == null)
{
GameMain.data.factories[i] = new PlanetFactory();
PlanetData pd = GameMain.galaxy.PlanetById(packet.PlanetsIds[i]);
pd.factoryIndex = i;
property.SetValue(GameMain.data.factories[i], pd, null);
GameMain.data.factories[i].planet = pd;
}
if (GameMain.statistics.production.factoryStatPool[i] == null)
{
Expand Down
6 changes: 3 additions & 3 deletions NebulaNetwork/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ static void HandleAutoSave()
{
string str1 = GameConfig.gameSaveFolder + GameSave.AutoSaveTmp + FILE_EXTENSION;
string str2 = GameConfig.gameSaveFolder + GameSave.AutoSave0 + FILE_EXTENSION;
string str3 = GameConfig.gameSaveFolder + AccessTools.Field(typeof(GameSave), "AutoSave1").GetValue(null) + FILE_EXTENSION;
string str4 = GameConfig.gameSaveFolder + AccessTools.Field(typeof(GameSave), "AutoSave2").GetValue(null) + FILE_EXTENSION;
string str5 = GameConfig.gameSaveFolder + AccessTools.Field(typeof(GameSave), "AutoSave3").GetValue(null) + FILE_EXTENSION;
string str3 = GameConfig.gameSaveFolder + GameSave.AutoSave1 + FILE_EXTENSION;
string str4 = GameConfig.gameSaveFolder + GameSave.AutoSave2 + FILE_EXTENSION;
string str5 = GameConfig.gameSaveFolder + GameSave.AutoSave3 + FILE_EXTENSION;

if (File.Exists(str1))
{
Expand Down
4 changes: 2 additions & 2 deletions NebulaPatcher/Patches/Dynamic/EntitySignRenderer_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static void Init_Postfix()
return;
}

AccessTools.StaticFieldRefAccess<bool>(typeof(EntitySignRenderer), "showIcon") = Config.Options.BuildingIconEnabled;
AccessTools.StaticFieldRefAccess<bool>(typeof(EntitySignRenderer), "showSign") = Config.Options.BuildingWarningEnabled;
EntitySignRenderer.showIcon = Config.Options.BuildingIconEnabled;
EntitySignRenderer.showSign = Config.Options.BuildingWarningEnabled;
}
}
}
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static bool OnActivePlanetFactoryLoaded_Prefix(GameData __instance, Plane
InitLandingPlace(__instance, planet);
}
// now set localPlanet and planetId
AccessTools.Property(typeof(GameData), "localPlanet").SetValue(GameMain.data, planet, null);
GameMain.data.localPlanet = planet;
__instance.mainPlayer.planetId = planet.id;

planet.onFactoryLoaded -= __instance.OnActivePlanetFactoryLoaded;
Expand Down
4 changes: 2 additions & 2 deletions NebulaPatcher/Patches/Dynamic/PlanetModelingManager_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public static bool RequestLoadPlanetFactory_Prefix(PlanetData planet)
// we only need to request the full factory if we never received it before
if (planet.factory != null)
{
AccessTools.Field(typeof(PlanetModelingManager), "currentFactingPlanet").SetValue(null, planet);
AccessTools.Field(typeof(PlanetModelingManager), "currentFactingStage").SetValue(null, 0);
PlanetModelingManager.currentFactingPlanet = planet;
PlanetModelingManager.currentFactingStage = 0;
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void Start_Postfix(UIGameMenu __instance)
return;
}

AccessTools.StaticFieldRefAccess<bool>(typeof(PostEffectController), "headlight") = Config.Options.GuidingLightEnabled;
PostEffectController.headlight = Config.Options.GuidingLightEnabled;
}
}
}
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/PowerSystemRenderer_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void Init_Postfix(UIGameMenu __instance)
return;
}

AccessTools.StaticFieldRefAccess<bool>(typeof(PowerSystemRenderer), "powerGraphOn") = Config.Options.PowerGridEnabled;
PowerSystemRenderer.powerGraphOn = Config.Options.PowerGridEnabled;
}
}
}
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/UIAssemblerWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void OnAssemblerIdChange_Prefix(UIAssemblerWindow __instance)
}

int[] update = new int[__instance.factorySystem.assemblerPool[__instance.assemblerId].served.Length];
StorageComponent assemblerStorage = (StorageComponent)AccessTools.Field(typeof(UIAssemblerWindow), "servingStorage").GetValue(__instance);
StorageComponent assemblerStorage = __instance.servingStorage;
for (int i = 0; i < update.Length; i++)
{
update[i] = assemblerStorage.grids[i].count;
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/UIAutoSave_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UIAutoSave_Patch
public static void _OnOpen_Postfix(UIAutoSave __instance)
{
// Hide AutoSave failed message on clients, since client cannot save in multiplayer
CanvasGroup contentCanvas = AccessTools.Field(__instance.GetType(), "contentCanvas").GetValue(__instance) as CanvasGroup;
CanvasGroup contentCanvas = __instance.contentCanvas;
contentCanvas?.gameObject.SetActive(!SimulatedWorld.Initialized || LocalPlayer.IsMasterClient);
Log.Warn($"UIAutoSave active: {contentCanvas?.gameObject.activeSelf}");
}
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/UIEjectorWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void OnManualServingContentChange_Postfix(UIEjectorWindow __instan
//Notify about manual bullet inserting / withdrawing change
if (SimulatedWorld.Initialized)
{
StorageComponent storage = (StorageComponent)AccessTools.Field(typeof(UIEjectorWindow), "servingStorage").GetValue(__instance);
StorageComponent storage = __instance.servingStorage;
LocalPlayer.SendPacketToLocalStar(new EjectorStorageUpdatePacket(__instance.ejectorId, storage.grids[0].count, GameMain.localPlanet?.id ?? -1));
}
}
Expand Down
4 changes: 2 additions & 2 deletions NebulaPatcher/Patches/Dynamic/UIEscMenu_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class UIEscMenu_Patch
public static void _OnOpen_Prefix(UIEscMenu __instance)
{
// Disable save game button if you are a client in a multiplayer session
Button saveGameWindowButton = AccessTools.Field(typeof(UIEscMenu), "button2").GetValue(__instance) as Button;
Button saveGameWindowButton = __instance.button2;
SetButtonEnableState(saveGameWindowButton, !SimulatedWorld.Initialized || LocalPlayer.IsMasterClient);

// Disable load game button if in a multiplayer session
Button loadGameWindowButton = AccessTools.Field(typeof(UIEscMenu), "button3").GetValue(__instance) as Button;
Button loadGameWindowButton = __instance.button3;
SetButtonEnableState(loadGameWindowButton, !SimulatedWorld.Initialized);
}

Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/UIGalaxySelect_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static bool EnterGame_Prefix(UIGalaxySelect __instance)
var session = NebulaBootstrapper.Instance.CreateMultiplayerHostSession();
session.StartServer(Config.Options.HostPort);

GameDesc gameDesc = AccessTools.Field(__instance.GetType(), "gameDesc").GetValue(__instance) as GameDesc;
GameDesc gameDesc = __instance.gameDesc;
DSPGame.StartGameSkipPrologue(gameDesc);
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions NebulaPatcher/Patches/Dynamic/UIGameMenu_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void OnDfIconButtonClick_Postfix(UIGameMenu __instance)
return;
}

Config.Options.BuildingIconEnabled = (bool)AccessTools.StaticFieldRefAccess<bool>(typeof(EntitySignRenderer), "showIcon");
Config.Options.BuildingIconEnabled = EntitySignRenderer.showIcon;
Config.SaveOptions();
}

Expand All @@ -46,7 +46,7 @@ public static void OnDfLightButtonClick_Postfix(UIGameMenu __instance)
return;
}

Config.Options.GuidingLightEnabled = (bool)AccessTools.StaticFieldRefAccess<bool>(typeof(PowerSystemRenderer), "powerGraphOn");
Config.Options.GuidingLightEnabled = PowerSystemRenderer.powerGraphOn;
Config.SaveOptions();
}

Expand All @@ -59,7 +59,7 @@ public static void OnDfPowerButtonClick_Postfix(UIGameMenu __instance)
return;
}

Config.Options.PowerGridEnabled = (bool)AccessTools.StaticFieldRefAccess<bool>(typeof(PostEffectController), "headlight");
Config.Options.PowerGridEnabled = PostEffectController.headlight;
Config.SaveOptions();
}

Expand All @@ -72,7 +72,7 @@ public static void OnDfSignButtonClick_Postfix(UIGameMenu __instance)
return;
}

Config.Options.BuildingWarningEnabled = (bool)AccessTools.StaticFieldRefAccess<bool>(typeof(EntitySignRenderer), "showSign");
Config.Options.BuildingWarningEnabled = EntitySignRenderer.showSign;
Config.SaveOptions();
}

Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/UILabWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void OnItemButtonClick_Prefix(UILabWindow __instance, int index)
if (GameMain.mainPlayer.inhandItemId > 0 && GameMain.mainPlayer.inhandItemCount > 0)
{
//Notify about depositing source cubes
ItemProto[] matrixProtos = (ItemProto[])AccessTools.Field(typeof(UILabWindow), "matrixProtos").GetValue(__instance);
ItemProto[] matrixProtos = __instance.matrixProtos;
int id = matrixProtos[index].ID;
if (GameMain.mainPlayer.inhandItemId == id)
{
Expand Down
Loading

0 comments on commit 6810ceb

Please sign in to comment.