Skip to content

Commit cf3caca

Browse files
committed
Add Project files
1 parent 942a9b0 commit cf3caca

File tree

6 files changed

+406
-1
lines changed

6 files changed

+406
-1
lines changed

.gitattributes

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
1-
# Auto detect text files and perform LF normalization
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
24
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*
2+
!/**/
3+
!*.cs
4+
!*.csproj
5+
!DSP_AssemblerUI.sln
6+
7+
!.gitignore
8+
!README.md
9+
.NETFramework,Version=v4.8.AssemblyAttributes.cs
10+
11+
bin/
12+
obj/

DSP_AssemblerUI.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31005.135
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DSP_AssemblerUI", "DSP_AssemblerUI\DSP_AssemblerUI.csproj", "{7EDE0BA0-773B-43C0-8F28-A448A54DCA31}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{7EDE0BA0-773B-43C0-8F28-A448A54DCA31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7EDE0BA0-773B-43C0-8F28-A448A54DCA31}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7EDE0BA0-773B-43C0-8F28-A448A54DCA31}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7EDE0BA0-773B-43C0-8F28-A448A54DCA31}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {D7956B9B-ADB4-4F47-A126-471F88215A6E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
using BepInEx;
2+
using BepInEx.Logging;
3+
using HarmonyLib;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Reflection;
8+
using System.Reflection.Emit;
9+
using System.Security;
10+
using System.Security.Permissions;
11+
using System.Text;
12+
using UnityEngine;
13+
using UnityEngine.UI;
14+
15+
[module: UnverifiableCode]
16+
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
17+
namespace DSP_AssemblerUI.AssemblerSpeedUI
18+
{
19+
[BepInPlugin("dsp.assemblerUI.speedMod", "Assembler UI Speed Info Mod", "1.0.0.0")]
20+
public class AssemblerSpeedUIMod : BaseUnityPlugin
21+
{
22+
public new static ManualLogSource Logger;
23+
24+
internal void Awake()
25+
{
26+
27+
//Adding the Logger
28+
Logger = new ManualLogSource("AssemblerSpeedUIMod");
29+
BepInEx.Logging.Logger.Sources.Add(Logger);
30+
31+
Harmony.CreateAndPatchAll(typeof(AssemblerSpeedUIMod));
32+
}
33+
34+
35+
36+
internal class ItemSpeedInfoLabel
37+
{
38+
public GameObject gameObject;
39+
public Text value;
40+
}
41+
42+
internal static Dictionary<string, ItemSpeedInfoLabel> speedInfos = new Dictionary<string, ItemSpeedInfoLabel>();
43+
44+
static readonly string TEXT_PATH = "UI Root/Overlay Canvas/In Game/Windows/Assembler Window/produce/speed/speed-text";
45+
46+
public static readonly string[] itemKeys = { "assembler-speed-item0", "assembler-speed-item1", "assembler-speed-item2" };
47+
48+
public static float[][] xLookup = new float[][]{ new float[]{ -60f }, new float[]{ -125f, -60f }, new float[] { -190f, -125f, -60f } };
49+
public static Vector3? ogPos = null;
50+
51+
[HarmonyPostfix, HarmonyPatch(typeof(UIAssemblerWindow), "OnAssemblerIdChange")]
52+
public static void OnAssemblerIdChangePostfix(UIAssemblerWindow __instance)
53+
{
54+
SetupLabels(__instance);
55+
}
56+
57+
[HarmonyPostfix, HarmonyPatch(typeof(UIAssemblerWindow), "OnRecipePickerReturn")]
58+
public static void OnRecipePickerReturnPostfix(UIAssemblerWindow __instance)
59+
{
60+
SetupLabels(__instance);
61+
}
62+
63+
public static void SetupLabels(UIAssemblerWindow window)
64+
{
65+
int? productCount = window.factorySystem?.assemblerPool[window.assemblerId].products?.Length;
66+
if (!productCount.HasValue)
67+
{
68+
return;
69+
}
70+
int loopCap = Math.Min(productCount.Value, itemKeys.Length);
71+
72+
for (int cnt = 0; cnt < loopCap; cnt++)
73+
{
74+
if (!speedInfos.ContainsKey(itemKeys[cnt]))
75+
{
76+
AddSpeedLabel(itemKeys[cnt], cnt, loopCap);
77+
}
78+
}
79+
80+
string perMinuteString = "每分钟".Translate();
81+
82+
for (int cnt2 = 0; cnt2 < speedInfos.Count; cnt2++)
83+
{
84+
if (cnt2 < productCount)
85+
{
86+
speedInfos[itemKeys[cnt2]].gameObject.SetActive(true);
87+
speedInfos[itemKeys[cnt2]].value.text = "0.0" + perMinuteString;
88+
PositionSpeedLabel(speedInfos[itemKeys[cnt2]].gameObject, cnt2, loopCap);
89+
}
90+
else
91+
{
92+
speedInfos[itemKeys[cnt2]].gameObject.SetActive(false);
93+
}
94+
}
95+
}
96+
97+
public static void AddSpeedLabel(string id, int num, int ofNum)
98+
{
99+
var originalDetailLabel = GameObject.Find(TEXT_PATH);
100+
if (originalDetailLabel == null)
101+
{
102+
throw new InvalidOperationException("Assembler speed base entry is not present");
103+
}
104+
105+
GameObject gameObject = null;
106+
var originalDetailLabelText = originalDetailLabel.GetComponent<Text>();
107+
108+
gameObject = Instantiate(originalDetailLabel, originalDetailLabel.transform.position, Quaternion.identity);
109+
Destroy(gameObject.GetComponentInChildren<Localizer>());
110+
111+
gameObject.name = id;
112+
gameObject.transform.SetParent(originalDetailLabel.transform.parent);
113+
114+
var textComponents = gameObject.GetComponentsInChildren<Text>();
115+
var value = textComponents[0];
116+
117+
if (!ogPos.HasValue)
118+
{
119+
ogPos = originalDetailLabel.transform.localPosition;
120+
}
121+
122+
gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
123+
PositionSpeedLabel(gameObject, num, ofNum);
124+
gameObject.transform.right = originalDetailLabel.transform.right;
125+
126+
ItemSpeedInfoLabel newItemSpeedInfo = new ItemSpeedInfoLabel()
127+
{
128+
gameObject = gameObject,
129+
value = value
130+
};
131+
speedInfos.Add(id, newItemSpeedInfo);
132+
}
133+
134+
public static void PositionSpeedLabel(GameObject gameObject, int num, int ofNum)
135+
{
136+
137+
Logger.LogDebug($"OgPosition:{gameObject.transform.localPosition}");
138+
Vector3 shiftVector = getPosShift(num, ofNum);
139+
Logger.LogDebug($"ShiftedBy:{shiftVector}");
140+
141+
gameObject.transform.localPosition = ogPos.Value + shiftVector;
142+
}
143+
144+
public static Vector3 getPosShift(int num, int ofNum)
145+
{
146+
return new Vector3(xLookup[ofNum - 1][num], -50f, 0f);
147+
}
148+
149+
public static void UpdateSpeedLabel(string id, float value)
150+
{
151+
string perMinuteString = "每分钟".Translate();
152+
speedInfos[id].value.text = value.ToString("0.0") + perMinuteString;
153+
}
154+
155+
public static void UpdateSpeedLabels(float baseSpeed, int[] productCounts)
156+
{
157+
for(int cnt = 0; cnt < Math.Min(productCounts.Length, itemKeys.Length); cnt++)
158+
{
159+
UpdateSpeedLabel(itemKeys[cnt], productCounts[cnt]*baseSpeed);
160+
}
161+
}
162+
163+
164+
[HarmonyTranspiler, HarmonyPatch(typeof(UIAssemblerWindow), "_OnUpdate")]
165+
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
166+
{
167+
Logger.LogDebug("UiTextTranspiler started!");
168+
CodeMatcher matcher = new CodeMatcher(instructions);
169+
//find -->
170+
//ldloc.s 18
171+
//ldloc.s 19
172+
//mul
173+
//stloc.s 18
174+
//<-- endFind
175+
Logger.LogDebug($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
176+
matcher.MatchForward(
177+
true,
178+
new CodeMatch(i => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder lb && lb.LocalIndex == 18),
179+
new CodeMatch(i => i.opcode == OpCodes.Ldloc_S && i.operand is LocalBuilder lb && lb.LocalIndex == 19),
180+
new CodeMatch(OpCodes.Mul),
181+
new CodeMatch(i => i.opcode == OpCodes.Stloc_S && i.operand is LocalBuilder lb && lb.LocalIndex == 18)
182+
);
183+
184+
Logger.LogDebug($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
185+
matcher.Advance(1); //move from last match to next element
186+
//insert-->
187+
//ldloc.s 18
188+
//ldloca.s 0 //AssemblerComponent local var
189+
//ldfld int32[] AssemblerComponent::productCounts
190+
//call update
191+
//<-- endInsert
192+
Logger.LogDebug($"UiTextTranspiler Matcher Codes Count: {matcher.Instructions().Count}, Matcher Pos: {matcher.Pos}!");
193+
matcher.InsertAndAdvance(
194+
new CodeInstruction(OpCodes.Ldloc_S, (byte)18),
195+
new CodeInstruction(OpCodes.Ldloca_S, (byte)0),
196+
new CodeInstruction(OpCodes.Ldfld, typeof(AssemblerComponent).GetField("productCounts")),
197+
new CodeInstruction(OpCodes.Call, typeof(AssemblerSpeedUIMod).GetMethod("UpdateSpeedLabels"))
198+
);
199+
200+
return matcher.InstructionEnumeration();
201+
}
202+
}
203+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{7EDE0BA0-773B-43C0-8F28-A448A54DCA31}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>DSP_AssemblerUI</RootNamespace>
11+
<AssemblyName>DSP_AssemblerUI</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="0Harmony">
36+
<HintPath>..\Libs\0Harmony.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Assembly-CSharp.refstub">
39+
<HintPath>..\Libs\Assembly-CSharp.refstub.dll</HintPath>
40+
</Reference>
41+
<Reference Include="BepInEx">
42+
<HintPath>..\Libs\BepInEx.dll</HintPath>
43+
</Reference>
44+
<Reference Include="BepInEx.Harmony">
45+
<HintPath>..\Libs\BepInEx.Harmony.dll</HintPath>
46+
</Reference>
47+
<Reference Include="System" />
48+
<Reference Include="System.Core" />
49+
<Reference Include="System.Xml.Linq" />
50+
<Reference Include="System.Data.DataSetExtensions" />
51+
<Reference Include="System.Data" />
52+
<Reference Include="System.Xml" />
53+
<Reference Include="UnityEngine.CoreModule">
54+
<HintPath>..\Libs\UnityEngine.CoreModule.dll</HintPath>
55+
</Reference>
56+
<Reference Include="UnityEngine.refstub">
57+
<HintPath>..\Libs\UnityEngine.refstub.dll</HintPath>
58+
</Reference>
59+
<Reference Include="UnityEngine.UI">
60+
<HintPath>..\Libs\UnityEngine.UI.dll</HintPath>
61+
</Reference>
62+
</ItemGroup>
63+
<ItemGroup>
64+
<Compile Include="AssemblerSpeedUI\AssemblerSpeedUIMod.cs" />
65+
<Compile Include="Properties\AssemblyInfo.cs" />
66+
</ItemGroup>
67+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
68+
</Project>

0 commit comments

Comments
 (0)