Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DesertBoss committed Mar 22, 2023
1 parent 1990329 commit 142b384
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 100 deletions.
37 changes: 37 additions & 0 deletions Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using UnityEngine;

namespace SandSpace
{
public static class Extensions
{
public static float Distance (this Vector3 vector1, Vector3 vector2)
{
return (vector1 - vector2).magnitude;
}

public static T RemoveFirst<T> (this List<T> list)
{
if (list == null || list.Count == 0)
return default;

var index = 0;
var result = list[index];
list.RemoveAt (index);

return result;
}

public static T RemoveLast<T> (this List<T> list)
{
if (list == null || list.Count == 0)
return default;

var index = list.Count - 1;
var result = list[index];
list.RemoveAt (index);

return result;
}
}
}
4 changes: 2 additions & 2 deletions Patches/BigShipsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class Engine_GetDrag_Patch
{
internal static void Postfix (ref float __result)
{
__result = __result * SandSpaceMod.Settings.engineDragMult;
__result = __result * SandSpaceMod.Settings.engineLinearDragMult;
}
}

Expand All @@ -20,7 +20,7 @@ internal static class Engine_GetRotateAngularDrag_Patch
{
internal static void Postfix (ref float __result)
{
__result = __result * SandSpaceMod.Settings.engineRotateDragMult;
__result = __result * SandSpaceMod.Settings.engineAngularDragMult;
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion Patches/ResourcesPatces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class ResourcesPatces
// Патч с настройкой колличества Реза добываемого с астероидов
internal static class PickupRez_OnPickedUp_Patch
{
internal static bool Prefix (ref PickupRez __instance)
internal static bool Prefix (ref PickupRez __instance, ref PickupGrabber grabber)
{
var newValue = __instance.pickupOverrideValue;
if (newValue > 0)
Expand All @@ -22,6 +22,12 @@ internal static bool Prefix (ref PickupRez __instance)
{
newValue = Mathf.FloorToInt (newValue * SandSpaceMod.Settings.rezGlobalDropMult);
}
if (SandSpaceMod.Settings.rezDropMultFromLevel)
{
var playerLevel = grabber.GetShipControls ().GetBattleEntity ().GetCurrentLevel ();
newValue *= playerLevel;
}

__instance.pickupOverrideValue = newValue;

return true;
Expand Down
33 changes: 31 additions & 2 deletions Patches/ShipPartsPatches.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using HarmonyLib;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using HarmonyLib;
using UnityEngine;

namespace SandSpace.Patches
namespace SandSpace
{
internal class ShipPartsPatches
{
Expand All @@ -18,5 +21,31 @@ private static void Postfix (ref ItemBuildInfo __instance, ref int __result)
__result = Mathf.FloorToInt (__result * SandSpaceMod.Settings.shipPartsBoosterMult);
}
}

// Фикс цены деталей при изменении множителя характеристик
//[HarmonyPatch (typeof (ShipPartDatabase), nameof (ShipPartDatabase.GetBuildInfoScrapPrice))]
internal static class ShipPartDatabase_GetBuildInfoScrapPrice_Patch
{
internal static IEnumerable<CodeInstruction> Transpiler (IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);

for (var i = 0; i < codes.Count; i++)
{
if (codes[i].opcode == OpCodes.Ldloc_S &&
((LocalBuilder)codes[i].operand).LocalIndex == 5 &&
codes[i + 1].opcode == OpCodes.Add &&
codes[i + 2].opcode == OpCodes.Stloc_S &&
((LocalBuilder)codes[i + 2].operand).LocalIndex == 9)
{
codes[i].opcode = OpCodes.Nop;
codes[i + 1].opcode = OpCodes.Nop;
break;
}
}

return codes.AsEnumerable ();
}
}
}
}
2 changes: 1 addition & 1 deletion Patches/StrikeCraftPatches.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HarmonyLib;

namespace SandSpace.Patches
namespace SandSpace
{
internal class StrikeCraftPatches
{
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SandSpace
This is a mod for the game "SPAZ 2" which uses the Unity Mod Manager to work.
This is a mod for the game "SPAZ 2" which uses the Unity Mod Manager to work. (final version)

## Features
- Changing number of active hangars
Expand All @@ -8,12 +8,8 @@ This is a mod for the game "SPAZ 2" which uses the Unity Mod Manager to work.
- Changing perk bonuses after max player level
- Changing the strength and size of explosions
- Changing amount of Rez drop from asteroids
- Sandbox settings menu for company mode (need new game)

## In developing (maybe)
- Block rarity bonus settings
- Add more turrets to support ships depending on their size
- Add more turrets to blocks
- Changing block bonus stats from rarity
- Sandbox settings menu when starting new campaign

## Installation
- Mod requires [Unity Mod Manager](https://www.nexusmods.com/site/mods/21) to work.
Expand Down
93 changes: 17 additions & 76 deletions SandSpace.csproj
Original file line number Diff line number Diff line change
@@ -1,84 +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')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4BFDFA3C-6EA6-4BB7-B82A-B6C55ECF1DE5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SandSpace</RootNamespace>
<AssemblyName>SandSpace</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<TargetFramework>net35</TargetFramework>
<OutputPath>$(SolutionDir)bin\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\lib\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\lib\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine">
<HintPath>..\lib\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\lib\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityModManager">
<HintPath>..\lib\UnityModManager.dll</HintPath>
<Private>False</Private>
<Reference Include="..\lib\*.dll">
<Private>false</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Hooks\GameStartOrLoadHook.cs" />
<Compile Include="Patches\BigShipsPatches.cs" />
<Compile Include="Patches\HangarsPatches.cs" />
<Compile Include="Patches\HazardPatches.cs" />
<Compile Include="Hooks\MainMenuHook.cs" />
<Compile Include="Patches\NewGamePatches.cs" />
<Compile Include="Patches\ResourcesPatces.cs" />
<Compile Include="Patches\ShipPartsPatches.cs" />
<Compile Include="Patches\StrikeCraftPatches.cs" />
<Compile Include="PatchingExtension.cs" />
<Compile Include="SandSpaceMod.cs" />
<Compile Include="Patches\PerkPatches.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetDir)$(ProjectName).dll" "D:\Steam\steamapps\common\SPAZ2\Mods\SandSpace\$(ProjectName).dll"</PostBuildEvent>
<PostBuildEvent>copy /Y "$(OutputPath)$(AssemblyName).dll" "D:\Steam\steamapps\common\SPAZ2\Mods\SandSpace\$(AssemblyName).dll"</PostBuildEvent>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>portable</DebugType>
</PropertyGroup>
</Project>
</Project>
8 changes: 7 additions & 1 deletion SandSpaceMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SandSpace
{
public class SandSpaceMod
{
public const string version = "0.5.1";
public const string version = "0.5.2";

public static UnityModManager.ModEntry ModEntry { get; private set; }
public static Settings Settings { get; private set; }
Expand Down Expand Up @@ -99,6 +99,12 @@ private static void DynamicPathes ()
transpiler: new HarmonyMethod (typeof (NewGamePatches.SinglePlayerMenu_windowFunc_Patch), "Transpiler")
);
}

if (Settings.enablePartCostPatch)
Harmony.Patch (
AccessTools.Method (typeof (ShipPartDatabase), nameof (ShipPartDatabase.GetBuildInfoScrapPrice)),
transpiler: new HarmonyMethod (typeof (ShipPartsPatches.ShipPartDatabase_GetBuildInfoScrapPrice_Patch), "Transpiler")
);
}

private static void ReloadHarmonyPatches ()
Expand Down
34 changes: 24 additions & 10 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class Settings : UnityModManager.ModSettings, IDrawable
public bool enableShockwaveExplosionsPatch = true;

[Draw ("┣━ Change size by multiplier", Min = 0.01, Max = 1000, VisibleOn = "enableShockwaveExplosionsPatch|true")]
public float hazardsShockwaveSizeMult = 8.0f;
public float hazardsShockwaveSizeMult = 4.0f;

[Draw ("┣━ Change damage by multiplier", Min = 0.01, Max = 1000, VisibleOn = "enableShockwaveExplosionsPatch|true")]
public float hazardsShockwaveDamageMult = 0.2f;
Expand All @@ -99,7 +99,10 @@ public class Settings : UnityModManager.ModSettings, IDrawable
public float rezMinDropMult = 1.0f;

[Draw ("┣━━ Max amount of Rez from asteroids multiplier", Min = 0.01, Max = 1000, VisibleOn = "enableRezDropPatch|true")]
public float rezMaxDropMult = 5.0f;
public float rezMaxDropMult = 2.0f;

[Draw ("┣━━ Enable player level as multiplier of Rez from asteroids")]
public bool rezDropMultFromLevel = false;

[Draw ("┗━━ Global multiplier of Rez drop", Min = 0.01, Max = 1000, VisibleOn = "enableRezDropPatch|true")]
public float rezGlobalDropMult = 1.0f;
Expand All @@ -111,22 +114,25 @@ public class Settings : UnityModManager.ModSettings, IDrawable

[Header ("┏ Experimental"), Space (25f)]

[Draw ("┣━━ Enable sandbox settings menu for company mode (need new game)")]
[Draw ("┣━━ Enable sandbox settings menu when starting new campaign")]
public bool enableSandboxCampaign = false;

[Draw ("┣━━ Drag factor in outer space", Min = 0.01, Max = 1000)]
public float engineDragMult = 0.5f;
[Draw ("┣━━ Linear drag factor in outer space", Min = 0.01, Max = 1000)]
public float engineLinearDragMult = 0.75f;

[Draw ("┣━━ Rotation drag factor in outer space", Min = 0.01, Max = 1000)]
public float engineRotateDragMult = 1.0f;
[Draw ("┣━━ Angular drag factor in outer space", Min = 0.01, Max = 1000)]
public float engineAngularDragMult = 1.0f;

[Draw ("┣━━ Extra stats multiplier for ship parts", Min = 0.01, Max = 1000)]
[Draw ("┣━━ Extra stats multiplier from rarity for ship parts", Min = 0.01, Max = 1000)]
public float shipPartsBoosterMult = 1.0f;

[Draw ("┣━━ Extra stats multiplier for station parts", Min = 0.01, Max = 1000)]
[Draw ("┣━━ Extra stats multiplier from rarity for station parts", Min = 0.01, Max = 1000)]
public float stationPartsBoosterMult = 1.0f;

[Draw ("┗━━ Extra stats multiplier for strike crafts depending their skill", Min = 0.01, Max = 1000)]
[Draw ("┣━━ Enable price fix for ship parts if applyed extra stats multiplier")]
public bool enablePartCostPatch = false;

[Draw ("┗━━ Extra stats multiplier from rarity for strike crafts", Min = 0.01, Max = 1000)]
public float strikeCraftsStrengthMult = 1.0f;

public override void Save (UnityModManager.ModEntry modEntry)
Expand Down Expand Up @@ -202,6 +208,14 @@ private void SetDefaults ()
rezMaxDropMult = def.rezMaxDropMult;
rezGlobalDropMult = def.rezGlobalDropMult;

enableSandboxCampaign = def.enableSandboxCampaign;
engineLinearDragMult = def.engineLinearDragMult;
engineAngularDragMult = def.engineAngularDragMult;
shipPartsBoosterMult = def.shipPartsBoosterMult;
stationPartsBoosterMult = def.stationPartsBoosterMult;
enablePartCostPatch = def.enablePartCostPatch;
strikeCraftsStrengthMult = def.strikeCraftsStrengthMult;

PerkPatches.SetDefaults ();
}
}
Expand Down
Loading

0 comments on commit 142b384

Please sign in to comment.