Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Lake1059 authored Mar 21, 2024
1 parent d79bfb3 commit 43c375e
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 deletions.
25 changes: 25 additions & 0 deletions StardewAutoGC_NET6/StardewAutoGC_NET6.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "StardewAutoGC", "StardewAutoGC_NET6\StardewAutoGC.vbproj", "{66E1CE56-E202-4CE8-9A55-697F09552161}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{66E1CE56-E202-4CE8-9A55-697F09552161}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66E1CE56-E202-4CE8-9A55-697F09552161}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66E1CE56-E202-4CE8-9A55-697F09552161}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66E1CE56-E202-4CE8-9A55-697F09552161}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC88A806-ED4B-43FC-B15C-F093078975D2}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions StardewAutoGC_NET6/StardewAutoGC_NET6/ModConfig.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Imports StardewModdingAPI

Public Class ModConfig

Public Property ManualButton As SButton = SButton.RightAlt

End Class
80 changes: 80 additions & 0 deletions StardewAutoGC_NET6/StardewAutoGC_NET6/ModEntry.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Imports System.Runtime.InteropServices
Imports StardewModdingAPI
Imports StardewModdingAPI.Events
Imports StardewValley

Public Class ModEntry
Inherits [Mod]

Dim 用户配置 As ModConfig

Public Overrides Sub Entry(helper As IModHelper)

用户配置 = helper.ReadConfig(Of ModConfig)()

AddHandler helper.Events.GameLoop.DayEnding, AddressOf Me.每天结束事件
AddHandler helper.Events.Input.ButtonPressed, AddressOf Me.按钮按下事件
End Sub

Public Sub 每天结束事件(sender As Object, e As DayEndingEventArgs)
Dim a As Long = Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024
GC.Collect()
GC.WaitForPendingFinalizers()
Dim b As Long = Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024

Dim T1 As String = Helper.Translation.Get("Auto.Part1")
Dim T2 As String = Helper.Translation.Get("Auto.Part2")
Dim T3 As String = Helper.Translation.Get("Auto.Part3")
Dim c As String
If a > 1024 Then
c = T1 & T2 & Format(a / 1024, "0.00") & " GB " & T3 & Format(b / 1024, "0.00") & " GB "
Else
c = T1 & T2 & a & " MB " & T3 & b & " MB"
End If

Me.Monitor.Log(c, LogLevel.Debug)

Game1.addHUDMessage(New HUDMessage(c, 1))
End Sub

Public Sub 按钮按下事件(sender As Object, e As ButtonPressedEventArgs)
If e.Button = 用户配置.ManualButton Then
Dim a As Long = Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024
ClearMemory()
Dim b As Long = Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024

Dim T1 As String = Helper.Translation.Get("Manual.Part1")
Dim T2 As String = Helper.Translation.Get("Manual.Part2")
Dim T3 As String = Helper.Translation.Get("Manual.Part3")
Dim c As String
If a > 1024 Then
c = T1 & T2 & Format(a / 1024, "0.00") & " GB " & T3 & Format(b / 1024, "0.00") & " GB "
Else
c = T1 & T2 & a & " MB " & T3 & b & " MB"
End If
Me.Monitor.Log(c, LogLevel.Info)
Game1.addHUDMessage(New HUDMessage(c, 1))
End If
End Sub

''' <summary>
'''设置线程工作的空间
''' </summary>
''' <param name="process">线程</param>
''' <param name="minSize">最小空间</param>
''' <param name="maxSize">最大空间</param>
''' <returns></returns>
<DllImport("kernel32.dll", EntryPoint:="SetProcessWorkingSetSize")>
Public Shared Function SetProcessWorkingSetSize(process As IntPtr, minSize As Integer, maxSize As Integer) As Integer
End Function

Public Shared Sub ClearMemory()
GC.Collect()
GC.WaitForPendingFinalizers()
If Environment.OSVersion.Platform = PlatformID.Win32NT Then
Dim unused = SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
End If
End Sub


End Class
10 changes: 10 additions & 0 deletions StardewAutoGC_NET6/StardewAutoGC_NET6/My Project/Application.myapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>true</MySubMain>
<MainForm>Form1</MainForm>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>
20 changes: 20 additions & 0 deletions StardewAutoGC_NET6/StardewAutoGC_NET6/StardewAutoGC.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>StardewAutoGC</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<Version>2.0.0</Version>
<AssemblyName>StardewAutoGC</AssemblyName>
<AssemblyVersion>3.0.0</AssemblyVersion>
<FileVersion>3.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions StardewAutoGC_NET6/StardewAutoGC_NET6/i18n/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Auto.Part1": "Auto GC Complete. ",
"Auto.Part2": "RAM from ",
"Auto.Part3": "reduce to ",

"Manual.Part1": "Manual GC Complete. ",
"Manual.Part2": "RAM from ",
"Manual.Part3": "reduce to ",
}
9 changes: 9 additions & 0 deletions StardewAutoGC_NET6/StardewAutoGC_NET6/i18n/zh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Auto.Part1": "自动回收内存完成。",
"Auto.Part2": "RAM 从 ",
"Auto.Part3": "降低至 ",

"Manual.Part1": "手动回收内存完成。",
"Manual.Part2": "RAM 从 ",
"Manual.Part3": "降低至 ",
}
8 changes: 8 additions & 0 deletions StardewAutoGC_NET6/StardewAutoGC_NET6/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Name": "StardewAutoGC",
"Author": "Lake1059",
"Version": "3.1",
"UniqueID": "Lake1059.StardewAutoGC",
"EntryDll": "StardewAutoGC_NET6.dll",
"UpdateKeys": [ "Nexus:9293", "Github:Lake1059/StardewAutoGC" ]
}

0 comments on commit 43c375e

Please sign in to comment.