Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build to load from NuGet and update theoretical max amounts to consider Proliferator Points #125

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
!.editorconfig
!.gitignore
!*.md
!*.ps1
!*.psm1
!NuGet.Config

bin/
obj/
tmp_release
.idea
.vs
176 changes: 156 additions & 20 deletions BetterStats/BetterStats.cs

Large diffs are not rendered by default.

140 changes: 26 additions & 114 deletions BetterStats/BetterStats.csproj
Original file line number Diff line number Diff line change
@@ -1,114 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F415C8D1-768D-407C-86AE-4D2EEAC179F1}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>DSM.BetterStats</RootNamespace>
<AssemblyName>BetterStats</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.2.0</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Compile Include="BetterStats.cs" />
<Compile Include="ACPublic.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp_publicized, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\publicized_assemblies\Assembly-CSharp_publicized.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="BepInEx.Harmony">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\core\BepInEx.Harmony.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\core\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="netstandard">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\netstandard.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\DowngradedAssemblies\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.JSONSerializeModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.JSONSerializeModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy $(TargetPath) "C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\scripts\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Description>Add more information to the production stats panel</Description>
<AssemblyName>BetterStats</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Version>1.3.3</Version>
<LangVersion>9</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package creates a temporary PluginInfo file with the plugin version coming from the csproj file and that can be referenced from the Plugin code.

https://github.com/BepInEx/BepInEx.Templates/tree/master/BepInEx.PluginInfoProps

<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!-- <Exec Command="COPY $(TargetPath) 'C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\scripts\'" />-->
</Target>
</Project>
165 changes: 165 additions & 0 deletions BetterStats/ItemCalculationMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using static BetterStats.BetterStats;

namespace BetterStats
{
public enum ItemCalculationMode
{
None,
Normal,
ForceSpeed,
ForceProductivity
}

/// <summary>
/// Manages currently selected proliferator calculation options for each item
/// </summary>
public class ItemCalculationRuntimeSetting
{
public static readonly ItemCalculationRuntimeSetting None = new(0)
{
_enabled = false,
_mode = ItemCalculationMode.None,
};
private ItemCalculationMode _mode = ItemCalculationMode.Normal;
private bool _enabled;

public readonly int productId;

private ConfigEntry<string> _configEntry;
private static readonly Dictionary<int, ConfigEntry<string>> ConfigEntries = new();
private static readonly Dictionary<int, ItemCalculationRuntimeSetting> Pool = new();
private static ConfigFile configFile;
private readonly ItemProto _itemProto;
private ItemCalculationRuntimeSetting(int productId)
{
this.productId = productId;
var proto = LDB.items.Select(productId);
if (proto != null)
{
_itemProto = proto;
}
}

public ItemCalculationMode Mode
{
get => _mode;
set
{
_mode = value;
Pool[productId]._mode = value;
Save();
}
}

public bool Enabled
{
get => _enabled;
set
{
_enabled = value;
Pool[productId]._enabled = value;
Save();
}
}

public bool SpeedSupported => _itemProto is { recipes: { Count: > 0 } };

public bool ProductivitySupported
{
get { return SpeedSupported && _itemProto.recipes.Any(r => r.productive); }
}

private void Save()
{
_configEntry.Value = Serialize();
Log.LogDebug($"saved {productId} entry {_configEntry.Value}");
}

private static ItemCalculationRuntimeSetting Deserialize(string strVal)
{
var serializableRuntimeState = JsonUtility.FromJson<SerializableRuntimeState>(strVal);

return new ItemCalculationRuntimeSetting(serializableRuntimeState.productId)
{
_enabled = serializableRuntimeState.enabled,
_mode = (ItemCalculationMode)serializableRuntimeState.mode,
};
}

private string Serialize()
{
return JsonUtility.ToJson(SerializableRuntimeState.From(this));
}

public static void InitConfig()
{
configFile = new ConfigFile($"{Paths.ConfigPath}/{PluginInfo.PLUGIN_NAME}/CustomProductSettings.cfg", true);

foreach (var itemProto in LDB.items.dataArray)
{
var defaultValue = new ItemCalculationRuntimeSetting(itemProto.ID)
{
_enabled = true,
_mode = ItemCalculationMode.Normal
};

var configEntry = configFile.Bind("Internal", $"ProliferatorStatsSetting_{itemProto.ID}",
defaultValue.Serialize(),
"For internal use only");
ConfigEntries[itemProto.ID] = configEntry;

Pool[itemProto.ID] = Deserialize(ConfigEntries[itemProto.ID].Value);
Pool[itemProto.ID]._configEntry = configEntry;
}
}

public static ItemCalculationRuntimeSetting ForItemId(int itemId)
{
if (disableProliferatorCalc.Value)
return None;
if (Pool.ContainsKey(itemId))
return Pool[itemId];

var defaultValue = new ItemCalculationRuntimeSetting(itemId)
{
_enabled = true,
_mode = ItemCalculationMode.Normal
};

var configEntry = configFile.Bind("Internal", $"ProliferatorStatsSetting_{itemId}",
defaultValue.Serialize(),
"For internal use only");
ConfigEntries[itemId] = configEntry;

Pool[itemId] = Deserialize(ConfigEntries[itemId].Value);
Pool[itemId]._configEntry = configEntry;
return Pool[itemId];
}
}

[Serializable]
public class SerializableRuntimeState
{
[SerializeField] public int mode;
[SerializeField] public bool enabled;
[SerializeField] public int productId;

public SerializableRuntimeState(int productId, bool enabled, ItemCalculationMode mode)
{
this.productId = productId;
this.enabled = enabled;
this.mode = (int)mode;
}

public static SerializableRuntimeState From(ItemCalculationRuntimeSetting setting)
{
return new SerializableRuntimeState(setting.productId, setting.Enabled, setting.Mode);
}
}
}
6 changes: 6 additions & 0 deletions BetterStats/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
</packageSources>
</configuration>
Loading