Merge pull request 'Rewrite mod in c# using patches' (#1) from x8c8r/PoppingBottles:main into main

Reviewed-on: #1
This commit is contained in:
Lyssa Pierce 2024-11-03 13:44:54 -05:00
commit 4fad7bc08f
7 changed files with 144 additions and 4686 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.idea/
.vs/
*.user
/local
bin/
obj/

16
PoppingBottles.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoppingBottles", "PoppingBottles\PoppingBottles.csproj", "{1A273855-C2D0-40BB-B22C-CE17AA4D0A9B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1A273855-C2D0-40BB-B22C-CE17AA4D0A9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A273855-C2D0-40BB-B22C-CE17AA4D0A9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A273855-C2D0-40BB-B22C-CE17AA4D0A9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A273855-C2D0-40BB-B22C-CE17AA4D0A9B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

76
PoppingBottles/Mod.cs Normal file
View File

@ -0,0 +1,76 @@
using GDWeave;
using GDWeave.Godot;
using GDWeave.Godot.Variants;
using GDWeave.Modding;
namespace PoppingBottles;
public class Mod : IMod {
public Mod(IModInterface modInterface) {
modInterface.Logger.Information("Loaded PoppingBottles!");
modInterface.RegisterScriptMod(new Patch());
}
public void Dispose() {
// Cleanup anything you do here
}
}
public class Patch : IScriptMod
{
public bool ShouldRun(string path) => path == "res://Scenes/Entities/Player/player.gdc";
public IEnumerable<Token> Modify(string path, IEnumerable<Token> tokens)
{
var functionWaiter = new FunctionWaiter("_consume_item");
var growthWaiter = new MultiTokenWaiter([
t => t is ConstantToken { Value: StringVariant { Value: "growth" } },
t => t.Type is TokenType.Colon,
t => t is IdentifierToken { Name: "player_scale" },
t => t.Type is TokenType.OpAssign,
t => t.Type is TokenType.BuiltInFunc,
t => t.Type is TokenType.ParenthesisOpen,
t => t is IdentifierToken { Name: "player_scale" },
t => t.Type is TokenType.OpAdd,
t => t is ConstantToken { Value: RealVariant { Value: 0.1 } },
t => t.Type is TokenType.Comma,
t => t is ConstantToken { Value: RealVariant { Value: 0.7 } },
t => t.Type is TokenType.Comma,
t => t is ConstantToken { Value: RealVariant { Value: 1.3 } },
], true, true);
var shrinkWaiter = new MultiTokenWaiter([
t => t is ConstantToken { Value: StringVariant { Value: "shrink" } },
t => t.Type is TokenType.Colon,
t => t is IdentifierToken { Name: "player_scale" },
t => t.Type is TokenType.OpAssign,
t => t.Type is TokenType.BuiltInFunc,
t => t.Type is TokenType.ParenthesisOpen,
t => t is IdentifierToken { Name: "player_scale" },
t => t.Type is TokenType.OpSub,
t => t is ConstantToken { Value: RealVariant { Value: 0.1 } },
t => t.Type is TokenType.Comma,
t => t is ConstantToken { Value: RealVariant { Value: 0.7 } },
t => t.Type is TokenType.Comma,
t => t is ConstantToken { Value: RealVariant { Value: 1.3 } },
], true, true);
foreach (var token in tokens)
{
if (functionWaiter.Check(token))
{
growthWaiter.SetReady();
shrinkWaiter.SetReady();
}
if (growthWaiter.Check(token) || shrinkWaiter.Check(token))
{
yield return new ConstantToken(new RealVariant(100.0));
}
else yield return token;
}
}
}

View File

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblySearchPaths>$(AssemblySearchPaths);$(GDWeavePath)/core</AssemblySearchPaths>
<Version>1.0.0.0</Version>
</PropertyGroup>
<ItemGroup>
<Reference Include="GDWeave" Private="false"/>
<Reference Include="Serilog" Private="false"/>
</ItemGroup>
<ItemGroup>
<None Include="manifest.json" CopyToOutputDirectory="PreserveNewest"/>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(GDWeavePath)' != ''">
<PropertyGroup>
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))'">true</IsWindows>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">true</IsLinux>
</PropertyGroup>
<Exec
Command="xcopy /Y /I &quot;$(TargetDir)&quot; &quot;$(GDWeavePath)/mods/$(AssemblyName)&quot;"
Condition="'$(IsWindows)' == 'true'"
/>
<Exec
Command="cp -r $(TargetDir) '$(GDWeavePath)/mods/$(AssemblyName)/'"
Condition="'$(IsLinux)' == 'true'"
/>
</Target>
</Project>

View File

@ -0,0 +1,10 @@
{
"Id": "PoppingBottles",
"AssemblyPath": "PoppingBottles.dll",
"Metadata": {
"Name": "PoppingBottles",
"Author": "uncreativeCultist",
"Version": "1.0.0",
"Description": "Mod that uncaps the limit on size sodas."
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff