Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Some Guy committed Nov 9, 2022
1 parent 0c3dda5 commit f05b8b2
Show file tree
Hide file tree
Showing 14 changed files with 337 additions and 0 deletions.
Binary file added 1.4/Assemblies/NoTrapFF.dll
Binary file not shown.
11 changes: 11 additions & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetaData>
<name>No Trap Friendly Fire</name>
<author>Windows XP</author>
<supportedVersions>
<li>1.4</li>
</supportedVersions>
<url></url>
<description>There is for some reason no trap friendly fire disabler mod anywhere on the workshop so I made one.</description>
<packageId>WindowsXP.NoTrapFriendlyFire</packageId>
</ModMetaData>
Binary file added About/Preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<loadFolders>
<v1.4>
<li>/</li>
<li>1.4</li>
</v1.4>
</loadFolders>
25 changes: 25 additions & 0 deletions Source/TrapFF/NoTrapFF/.vs/NoTrapFF/xs/UserPrefs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Properties>
<MonoDevelop.Ide.Workbench ActiveDocument="NoTrapFF/NoTrapFFMainLoader.cs">
<Files>
<File FileName="NoTrapFF/NoTrapFFMainLoader.cs" Line="31" Column="43" />
</Files>
<Pads>
<Pad Id="ProjectPad">
<State name="__root__">
<Node name="NoTrapFF" expanded="True">
<Node name="NoTrapFF" expanded="True">
<Node name="References" expanded="True" />
<Node name="NoTrapFFMainLoader.cs" selected="True" />
</Node>
</Node>
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MultiItemStartupConfigurations />
</Properties>
17 changes: 17 additions & 0 deletions Source/TrapFF/NoTrapFF/NoTrapFF.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoTrapFF", "NoTrapFF\NoTrapFF.csproj", "{A5C4ED26-D933-4755-8F93-B4E7F0BD12B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A5C4ED26-D933-4755-8F93-B4E7F0BD12B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5C4ED26-D933-4755-8F93-B4E7F0BD12B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5C4ED26-D933-4755-8F93-B4E7F0BD12B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5C4ED26-D933-4755-8F93-B4E7F0BD12B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
53 changes: 53 additions & 0 deletions Source/TrapFF/NoTrapFF/NoTrapFF/NoTrapFF.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A5C4ED26-D933-4755-8F93-B4E7F0BD12B7}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>NoTrapFF</RootNamespace>
<AssemblyName>NoTrapFF</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\..\1.4\Assemblies</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>..\..\..\..\1.4\Assemblies</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="0Harmony">
<HintPath>..\..\..\..\..\..\..\..\workshop\content\294100\2009463077\Current\Assemblies\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="NoTrapFFMainLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
186 changes: 186 additions & 0 deletions Source/TrapFF/NoTrapFF/NoTrapFF/NoTrapFFMainLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
using System.Collections.Generic;
using RimWorld;
using Verse;
using HarmonyLib;
using UnityEngine;

namespace NoTrapFF
{
[StaticConstructorOnStartup]
public static class NoTrapFFMainLoader
{
public static bool staticEnablePrisonerFF = false;
public static bool staticEnableSlaveFF = false;

public static bool staticTrapsForAllAnimals = false;
public static bool staticTrapEverythingElse = false;
static NoTrapFFMainLoader()
{
//Log.Message("Animals Can Do Drugs startup success");

var harmony = new Harmony("NoTrapFriendlyFire");
harmony.PatchAll();
Log.Message("[NoTrapFriendlyFire]patched harmony assembly. Startup success.");

}
}

public class NoTrapFFSettings : ModSettings
{
public bool enablePrisonerFF = false;
public bool enableSlaveFF = false;
public bool trapsForAllAnimals = false;
public bool trapEverythingElse = false;

public override void ExposeData()
{

Scribe_Values.Look(ref enablePrisonerFF, "enablePrisonerFF", false, true);
NoTrapFFMainLoader.staticEnablePrisonerFF = enablePrisonerFF;

Scribe_Values.Look(ref enableSlaveFF, "enableSlaveFF", false, true);
NoTrapFFMainLoader.staticEnableSlaveFF = enableSlaveFF;

Scribe_Values.Look(ref enableSlaveFF, "enableSlaveFF", false, true);
NoTrapFFMainLoader.staticEnableSlaveFF = enableSlaveFF;

Scribe_Values.Look(ref enableSlaveFF, "enableSlaveFF", false, true);
NoTrapFFMainLoader.staticEnableSlaveFF = enableSlaveFF;
base.ExposeData();
}

}


public class NoTrapFF : Mod
{

public static Vector2 scrollPosition;

/// <summary>
/// A reference to our settings.
/// </summary>
public NoTrapFFSettings settings;

/// <summary>
/// A mandatory constructor which resolves the reference to our settings.
/// </summary>
/// <param name="content"></param>
public NoTrapFF(ModContentPack content) : base(content)
{
this.settings = GetSettings<NoTrapFFSettings>();
}

/// <summary>
/// The (optional) GUI part to set your settings.
/// </summary>
/// <param name="inRect">A Unity Rect with the size of the settings window.</param>
public override void DoSettingsWindowContents(Rect inRect)
{

Rect viewRect = new Rect(0f, 0f, inRect.width - 26f, inRect.height);
Rect outRect = new Rect(0f, 30f, inRect.width, inRect.height - 30f);
Listing_Standard listingStandard = new Listing_Standard();
//Widgets.BeginScrollView(outRect, ref scrollPosition, viewRect);
listingStandard.Begin(viewRect);
listingStandard.Gap(24); //add a gap so that it will look right
listingStandard.CheckboxLabeled("enable trap friendly fire for prisoners of same faction", ref settings.enablePrisonerFF, "Enables or disables trap friendly fire when dealing with a prisoner of your own faction");
listingStandard.CheckboxLabeled("enable trap friendly fire for slaves of same faction", ref settings.enableSlaveFF, "Enables or disables trap friendly fire when dealing with a slave of your own faction");
listingStandard.GapLine(24);
listingStandard.Label("the following settings only effect traps placed by the player");
listingStandard.CheckboxLabeled("trap all factionless pawns and animals", ref settings.trapsForAllAnimals, "Checking this makes it so that any time a pawn (including humanlikes and normal animals) that doesn't belong a faction touches a trap, the trap will activate regardless of if that pawn is in aggro or not");
listingStandard.CheckboxLabeled("trap all non-player faction pawns of any kind", ref settings.trapEverythingElse, "Checking this makes it so that any time ANYTHING that doesn't belong to the player faction touches one of the player's traps, it will activate");
listingStandard.Label("No restart is required for changes to take effect.");
//Widgets.EndScrollView();
listingStandard.End();

NoTrapFFMainLoader.staticEnablePrisonerFF = settings.enablePrisonerFF;
NoTrapFFMainLoader.staticEnableSlaveFF = settings.enableSlaveFF;
NoTrapFFMainLoader.staticTrapsForAllAnimals = settings.trapsForAllAnimals;
NoTrapFFMainLoader.staticTrapEverythingElse = settings.trapEverythingElse;

base.DoSettingsWindowContents(inRect);
}

/// <summary>
/// Override SettingsCategory to show up in the list of settings.
/// Using .Translate() is optional, but does allow for localisation.
/// </summary>
/// <returns>The (translated) mod name.</returns>
public override string SettingsCategory()
{
//return "MyExampleModName".Translate();
return "No Trap Friendly Fire";
}

//i'm making a function to return the mouseover description string since pasting this in the function in the CheckboxLavel in DoSettingsWindowContents would get too cluttered

}

//pretty similar to the way ED Enhanced does it
[HarmonyPatch(typeof(Building_Trap), "CheckSpring")]
static class harmonyPatchThatDisablesTrapFriendlyFire
{
static bool Prefix(Pawn p, ref Building_Trap __instance)
{
//it doesn't matter what you're doing, you ALWAYS have to check for nulls
if (p == null)
{
return true;
}

//if pawn is a pawn type that doesnt have a faction or faction is otherwise invalid or absent, gtfo
if (p.Faction == null && !NoTrapFFMainLoader.staticTrapsForAllAnimals)
{
return true;
}
else if (p.Faction == null && NoTrapFFMainLoader.staticTrapsForAllAnimals && __instance.Faction == Faction.OfPlayer)
{
//if this happens, there is probably an animal on the trap
Log.Message("a pawn with no faction is on a trap. NoTrapFF configured setting of 'TrapsForAllAnimals = true' says to activate the trap right now.");
__instance.Spring(p); //activate the trap now
return false;
}

//the player faction is included as being friendly to itself. We can abuse this mechanic to easily figure out if the trap should be triggered or not based on this alone instead of a bigger, more grandiose buggy workaround
//if (!FactionUtility.HostileTo(p.Faction, Faction.OfPlayer))
if (__instance.Faction != null && __instance.Faction == p.Faction)
{
//a friendly unit is on trap. Return false to abort the usual CheckSpring() behavior, forcing the game to not trigger the trap regardless of what the random friendly fire chance says to do
//if same faction AND is prisoner AND prisoner friendly fire enabled
if (p.IsPrisoner && NoTrapFFMainLoader.staticEnablePrisonerFF)
{
Log.Message("pawn is prisoner and prisoner friendly fire is enabled");
__instance.Spring(p);
return false;
}

if (p.IsSlave && NoTrapFFMainLoader.staticEnableSlaveFF)
{
Log.Message("pawn is slave and slave friendly fire is enabled");
__instance.Spring(p);
return false;
}

return false;
}
else if (__instance.Faction != null && NoTrapFFMainLoader.staticTrapEverythingElse && __instance.Faction != p.Faction && __instance.Faction == Faction.OfPlayer)
{
//if trap everything is enabled and trap owner faction is different from pawn on trap, spring the trap
Log.Message("trap everything enabled. Springing trap");
__instance.Spring(p);
return false;
}

//if none of the aboive criteria happened, continue to run the CheckSpring() method normally
return true;

}

//static bool doTrappingIfSettingsSaySo()
//{
// if (NoTrapFFMainLoader.)
//}
}

}
26 changes: 26 additions & 0 deletions Source/TrapFF/NoTrapFF/NoTrapFF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("NoTrapFF")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("${AuthorCopyright}")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dfa129bc18c8c67181d4fc2bb190823ac43770ee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/home/scott/.local/share/Steam/steamapps/common/RimWorld/Mods/SkimpyBikini/1.4/Assemblies/NoTrapFF.dll
/home/scott/.local/share/Steam/steamapps/common/RimWorld/Mods/SkimpyBikini/TrapFF/TrapFF/NoTrapFF/NoTrapFF/obj/Release/NoTrapFF.csprojAssemblyReference.cache
/home/scott/.local/share/Steam/steamapps/common/RimWorld/Mods/SkimpyBikini/TrapFF/TrapFF/NoTrapFF/NoTrapFF/obj/Release/NoTrapFF.csproj.CoreCompileInputs.cache
/home/scott/.local/share/Steam/steamapps/common/RimWorld/Mods/SkimpyBikini/TrapFF/TrapFF/NoTrapFF/NoTrapFF/obj/Release/NoTrapFF.dll
/home/scott/.local/share/Steam/steamapps/common/RimWorld/Mods/NoTrapFF/1.4/Assemblies/NoTrapFF.dll
/home/scott/.local/share/Steam/steamapps/common/RimWorld/Mods/NoTrapFF/Source/TrapFF/NoTrapFF/NoTrapFF/obj/Release/NoTrapFF.csproj.CoreCompileInputs.cache
/home/scott/.local/share/Steam/steamapps/common/RimWorld/Mods/NoTrapFF/Source/TrapFF/NoTrapFF/NoTrapFF/obj/Release/NoTrapFF.dll
Binary file not shown.

0 comments on commit f05b8b2

Please sign in to comment.