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 6 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
46 changes: 39 additions & 7 deletions BetterStats/BetterStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
using UnityEngine;
using UnityEngine.UI;
using System.Globalization;
using System.Linq;
using DefaultNamespace;

namespace BetterStats
{
// TODO: button to next producer/consumer
[BepInPlugin("com.brokenmass.plugin.DSP.BetterStats", "BetterStats", "1.3.2")]
[BepInPlugin("com.brokenmass.plugin.DSP.BetterStats", PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class BetterStats : BaseUnityPlugin
{
public class EnhancedUIProductEntryElements
Expand Down Expand Up @@ -514,8 +515,8 @@ public static void UIProductEntry__OnUpdate_Postfix(UIProductEntry __instance)

if (!isTotalTimeWindow)
{
originalProductValue = originalProductValue / divider;
originalConsumeValue = originalConsumeValue / divider;
originalProductValue /= divider;
originalConsumeValue /= divider;


originalProductText = $"{FormatMetric(originalProductValue)}";
Expand Down Expand Up @@ -615,6 +616,8 @@ public static void AddPlanetFactoryData(PlanetFactory planetFactory)
var transport = planetFactory.transport;
var veinPool = planetFactory.planet.factory.veinPool;
var miningSpeedScale = (double)GameMain.history.miningSpeedScale;
var maxProductivityIncrease = ResearchTechHelper.GetMaxProductivityIncrease();
var maxSpeedIncrease = ResearchTechHelper.GetMaxSpeedIncrease();

for (int i = 1; i < factorySystem.minerCursor; i++)
{
Expand Down Expand Up @@ -650,11 +653,21 @@ public static void AddPlanetFactoryData(PlanetFactory planetFactory)
{
production = frequency * speed * (float)((double)veinPool[veinId].amount * (double)VeinData.oilSpeedMultiplier);
}

// flag to tell us if it's one of the advanced miners they added in the 20-Jan-2022 release
var isAdvancedMiner = false;
if (factorySystem.minerPool[i].type == EMinerType.Vein)
{
production = frequency * speed * miner.veinCount;
var minerEntity = factorySystem.factory.entityPool[miner.entityId];
isAdvancedMiner = minerEntity.stationId > 0 && minerEntity.minerId > 0;
}

// advanced miners aren't limited by belts
if (!isAdvancedMiner)
{
production = Math.Min(BELT_MAX_ITEMS_PER_MINUTE, production);
}
production = Math.Min(BELT_MAX_ITEMS_PER_MINUTE, production);

counter[productId].production += production;
counter[productId].producers++;
Expand All @@ -665,7 +678,17 @@ public static void AddPlanetFactoryData(PlanetFactory planetFactory)
if (assembler.id != i || assembler.recipeId == 0) continue;

var frequency = 60f / (float)((double)assembler.timeSpend / 600000.0);
var speed = (float)(0.0001 * (double)assembler.speed);
var speed = (float)(0.0001 * Math.Max(assembler.speedOverride, assembler.speed));

// forceAccMode is true when Production Speedup is selected
if (assembler.forceAccMode)
{
speed += speed * maxSpeedIncrease;
}
else
{
frequency += frequency * maxProductivityIncrease;
mattsemar marked this conversation as resolved.
Show resolved Hide resolved
}

for (int j = 0; j < assembler.requires.Length; j++)
{
Expand Down Expand Up @@ -733,7 +756,16 @@ public static void AddPlanetFactoryData(PlanetFactory planetFactory)
{
var lab = factorySystem.labPool[i];
if (lab.id != i) continue;
float frequency = 60f / (float)((double)lab.timeSpend / 600000.0);
// lab timeSpend is in game ticks, here we are figuring out the same number shown in lab window, example: 2.5 / m
// when we are in Production Speedup mode `speedOverride` is juiced. Otherwise we need to bump the frequency to account
// for the extra product produced after `extraTimeSpend` game ticks
var labSpeed = lab.forceAccMode ? (int)(lab.speed * (1.0 + maxSpeedIncrease) + 0.1) : lab.speed;
float frequency = (float)(1f / (lab.timeSpend / GameMain.tickPerSec / (60f * labSpeed)));

if (!lab.forceAccMode)
{
frequency += frequency * maxProductivityIncrease;
mattsemar marked this conversation as resolved.
Show resolved Hide resolved
}

if (lab.matrixMode)
{
Expand Down
139 changes: 25 additions & 114 deletions BetterStats/BetterStats.csproj
Original file line number Diff line number Diff line change
@@ -1,114 +1,25 @@
<?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>
</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>
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>
32 changes: 0 additions & 32 deletions BetterStats/Properties/AssemblyInfo.cs

This file was deleted.

8 changes: 5 additions & 3 deletions BetterStats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ Inspired by https://docs.bepinex.dev/master/articles/dev_guide/plugin_tutorial/1
### Setup visual studio

- Install Visual Studio (not visual studio code)
- In Visual Studio, create a new blank project and there choose "add more tools" and add .Net developpement support
- In Visual Studio, create a new blank project and there choose "add more tools" and add .Net development support
- Install .Net Framework 3.5 (be careful to choose "Framework")

### project setup

- In Visual Studio, choose import and then select "BetterStats.csproj"
- In the right tree, right click references and then select "add references" and add the requered references (most of them located in C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\DSPGAME_Data\Managed ; others are from BepinEx)
- You will find the last DLL "Assembly-CSharp.refstub.dll" in https://discord.com/channels/806549677209944084/806556447885623336/809241758323572766
- Game libraries should be loaded from NuGet

### Create a release
- From a PowerShell prompt run `.\package -vertype ` with either major, minor, patch or 'none'. 'none' will not increment the version number
- Uploadable zip file will be placed in .\tmp_release
<div>Icon made by <a href="https://www.freepik.com" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></div>
66 changes: 66 additions & 0 deletions BetterStats/ResearchTechHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Linq;

namespace DefaultNamespace
{
public static class ResearchTechHelper
{
private static TechProto _sprayLevel3Proto;
private static TechProto _sprayLevel2Proto;
private static TechProto _sprayLevel1Proto;

public static float GetMaxProductivityIncrease()
{
var highestProliferatorTechUnlocked = GetMaxIncIndex();
return (float)Cargo.incTableMilli[highestProliferatorTechUnlocked];
}

public static float GetMaxSpeedIncrease()
{
var highestProliferatorTechUnlocked = GetMaxIncIndex();
return (float)Cargo.accTableMilli[highestProliferatorTechUnlocked];
}

private static int GetMaxIncIndex()
{
InitTechProtos();
if (GameMain.history.techStates[_sprayLevel3Proto.ID].unlocked)
return 4;
if (GameMain.history.techStates[_sprayLevel2Proto.ID].unlocked)
return 2;
if (GameMain.history.techStates[_sprayLevel1Proto.ID].unlocked)
return 1;
return 0;
}

private static void InitTechProtos()
{
if (_sprayLevel3Proto == null)
{
var proliferatorProtos = LDB.techs.dataArray.ToList().FindAll(t => t.Name.Contains("增产剂"));
proliferatorProtos.Sort((p1, p2) =>
{
if (p1.PreTechs.Contains(p2.ID))
{
// sorting high to low
return -1;
}

if (p2.PreTechs.Contains(p1.ID))
{
return 1;
}

return p1.ID.CompareTo(p2.ID);
});
if (proliferatorProtos.Count >= 3)
{
// if more are added, add them here
_sprayLevel3Proto = proliferatorProtos[0];
_sprayLevel2Proto = proliferatorProtos[1];
_sprayLevel1Proto = proliferatorProtos[2];
}
}
}
}
}
Loading