diff options
-rw-r--r-- | StardewModdingAPI/Program.cs | 44 | ||||
-rw-r--r-- | StardewModdingAPI/StardewModdingAPI.csproj | 20 | ||||
-rw-r--r-- | TrainerMod/TrainerMod.csproj | 133 |
3 files changed, 110 insertions, 87 deletions
diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index a7065c69..e7169bde 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -144,6 +144,10 @@ namespace StardewModdingAPI //Load in that assembly. Also, ignore security :D StardewAssembly = Assembly.UnsafeLoadFrom(ExecutionPath + "\\Stardew Valley.exe"); + //This will load the injector before anything else if it sees it + //It doesn't matter though + //I'll leave it as a feature in case anyone in the community wants to tinker with it + //All you need is a DLL that inherits from mod and is called StardewInjector.dll with an Entry() method foreach (string ModPath in ModPaths) { foreach (String s in Directory.GetFiles(ModPath, "StardewInjector.dll")) @@ -153,11 +157,11 @@ namespace StardewModdingAPI { Assembly mod = Assembly.UnsafeLoadFrom(s); //to combat internet-downloaded DLLs - if (mod.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) > 0) + if (mod.DefinedTypes.Count(x => x.BaseType == typeof (Mod)) > 0) { LogColour(ConsoleColor.Green, "Loading Injector DLL..."); - TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof(Mod)); - Mod m = (Mod)mod.CreateInstance(tar.ToString()); + TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof (Mod)); + Mod m = (Mod) mod.CreateInstance(tar.ToString()); Console.WriteLine("LOADED: {0} by {1} - Version {2} | Description: {3}", m.Name, m.Authour, m.Version, m.Description); m.Entry(false); StardewInjectorLoaded = true; @@ -178,7 +182,9 @@ namespace StardewModdingAPI StardewProgramType = StardewAssembly.GetType("StardewValley.Program", true); StardewGameInfo = StardewProgramType.GetField("gamePtr"); + #region deprecated /* + * Lol no. I tried though. if (File.Exists(ExecutionPath + "\\Stardew_Injector.exe")) { //Stardew_Injector Mode @@ -211,6 +217,7 @@ namespace StardewModdingAPI //Now go back and load Stardew through SMAPI } */ + #endregion //Change the game's version LogInfo("Injecting New SDV Version..."); @@ -327,17 +334,24 @@ namespace StardewModdingAPI ready = true; - if (StardewInjectorLoaded) + StardewGameInfo.SetValue(StardewProgramType, gamePtr); + gamePtr.Run(); + + #region deprecated + if (false) { + //Nope, I can't get it to work. I depend on Game1 being an SGame, and can't cast a parent to a child + //I'm leaving this here in case the community is interested //StardewInjectorMod.Entry(true); - StardewAssembly.EntryPoint.Invoke(null, new object[] {new string[0]}); - StardewGameInfo.SetValue(StardewProgramType, gamePtr); - } - else - { + Type gt = StardewAssembly.GetType("StardewValley.Game1", true); + gamePtr = (SGame)Activator.CreateInstance(gt); + + ready = true; + StardewGameInfo.SetValue(StardewProgramType, gamePtr); gamePtr.Run(); } + #endregion } catch (Exception ex) { @@ -348,10 +362,14 @@ namespace StardewModdingAPI static void StardewForm_Closing(object sender, CancelEventArgs e) { e.Cancel = true; - gamePtr.Exit(); - gamePtr.Dispose(); - StardewForm.Hide(); - ready = false; + + if (true || MessageBox.Show("Are you sure you would like to quit Stardew Valley?\nUnsaved progress will be lost!", "Confirm Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) + { + gamePtr.Exit(); + gamePtr.Dispose(); + StardewForm.Hide(); + ready = false; + } } public static void LoadMods() diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index 7d3e129c..35a17272 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -11,10 +11,14 @@ <AssemblyName>StardewModdingAPI</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
- <SccProjectName>SAK</SccProjectName>
- <SccLocalPath>SAK</SccLocalPath>
- <SccAuxPath>SAK</SccAuxPath>
- <SccProvider>SAK</SccProvider>
+ <SccProjectName>
+ </SccProjectName>
+ <SccLocalPath>
+ </SccLocalPath>
+ <SccAuxPath>
+ </SccAuxPath>
+ <SccProvider>
+ </SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -53,7 +57,7 @@ <Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Stardew Valley, Version=1.0.5900.38427, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
+ <HintPath>D:\Games\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
<Private>False</Private>
</Reference>
@@ -68,7 +72,7 @@ <Reference Include="System.Xml" />
<Reference Include="xTile, Version=2.0.4.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\..\Games\SteamLibrary\steamapps\common\Stardew Valley\xTile.dll</HintPath>
+ <HintPath>D:\Games\steamapps\common\Stardew Valley\xTile.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
@@ -94,9 +98,7 @@ </ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
- <Content Include="steam_appid.txt">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </Content>
+ <Content Include="steam_appid.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
diff --git a/TrainerMod/TrainerMod.csproj b/TrainerMod/TrainerMod.csproj index a4a246b7..841491ad 100644 --- a/TrainerMod/TrainerMod.csproj +++ b/TrainerMod/TrainerMod.csproj @@ -1,74 +1,77 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{28480467-1A48-46A7-99F8-236D95225359}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>TrainerMod</RootNamespace> - <AssemblyName>TrainerMod</AssemblyName> - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> +<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{28480467-1A48-46A7-99F8-236D95225359}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>TrainerMod</RootNamespace>
+ <AssemblyName>TrainerMod</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
- </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> - <Private>False</Private> - </Reference> - <Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86"> - <Private>False</Private> - </Reference> - <Reference Include="Stardew Valley"> - <HintPath>Z:\Games\Stardew Valley\Stardew Valley.exe</HintPath> - </Reference> - <Reference Include="System" /> - <Reference Include="System.Core" /> - <Reference Include="System.Windows.Forms" /> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="TrainerMod.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\StardewModdingAPI\StardewModdingAPI.csproj"> - <Project>{f1a573b0-f436-472c-ae29-0b91ea6b9f8f}</Project> - <Name>StardewModdingAPI</Name> - </ProjectReference> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <PropertyGroup> + </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Stardew Valley">
+ <HintPath>D:\Games\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="xTile">
+ <HintPath>D:\Games\steamapps\common\Stardew Valley\xTile.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="TrainerMod.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\StardewModdingAPI\StardewModdingAPI.csproj">
+ <Project>{f1a573b0-f436-472c-ae29-0b91ea6b9f8f}</Project>
+ <Name>StardewModdingAPI</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)Release\Mods\" -copy /y "$(SolutionDir)$(ProjectName)\$(OutDir)TrainerMod.dll" "$(SolutionDir)Release\Mods\"</PostBuildEvent> - </PropertyGroup> +copy /y "$(SolutionDir)$(ProjectName)\$(OutDir)TrainerMod.dll" "$(SolutionDir)Release\Mods\"</PostBuildEvent>
+ </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> - --> + -->
</Project>
\ No newline at end of file |