Skip to content

Commit 0adba6b

Browse files
committed
Add project files.
1 parent ea2bcc5 commit 0adba6b

15 files changed

+361
-0
lines changed

AntiLock.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26730.16
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AntiLock", "AntiLock\AntiLock.csproj", "{008F5D92-3F12-4851-9EF3-19F9086C51E9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{008F5D92-3F12-4851-9EF3-19F9086C51E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{008F5D92-3F12-4851-9EF3-19F9086C51E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{008F5D92-3F12-4851-9EF3-19F9086C51E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{008F5D92-3F12-4851-9EF3-19F9086C51E9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2E265139-00EF-4C5B-B0A5-34699DB195A8}
24+
EndGlobalSection
25+
EndGlobal

AntiLock/AntiLock.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Harmony;
2+
using Rocket.Core.Logging;
3+
using Rocket.Core.Plugins;
4+
using SDG.Unturned;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Reflection;
9+
using System.Text;
10+
using Rocket.API.Collections;
11+
12+
namespace ExtraConcentratedJuice.AntiLock
13+
{
14+
public class AntiLock : RocketPlugin<AntiLockConfiguration>
15+
{
16+
public static AntiLock instance;
17+
18+
protected override void Load()
19+
{
20+
instance = this;
21+
22+
HarmonyInstance harmony = HarmonyInstance.Create("pw.cirno.extraconcentratedjuice");
23+
24+
var orig = typeof(VehicleManager).GetMethod("askVehicleLock", BindingFlags.Instance | BindingFlags.Public);
25+
var pre = typeof(AskVehicleLockOverride).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic);
26+
var post = typeof(AskVehicleLockOverride).GetMethod("Postfix", BindingFlags.Static | BindingFlags.Public);
27+
28+
harmony.Patch(orig, new HarmonyMethod(pre), new HarmonyMethod(post));
29+
}
30+
31+
public override TranslationList DefaultTranslations =>
32+
new TranslationList
33+
{
34+
{ "clear_success_other", "You've unlocked all of {0}'s vehicles. ({1} in total.)" },
35+
{ "clear_success", "You've unlocked all of your vehicles. ({0} in total.)" },
36+
{ "player_not_found", "The specified player was not found." },
37+
{ "max_locked_notice", "You have reached your allocated number of vehicle locks. ({0})" },
38+
{ "locked_notice", "You have locked a vehicle. ({0}/{1} locks remaining.)" }
39+
};
40+
}
41+
}

AntiLock/AntiLock.csproj

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{008F5D92-3F12-4851-9EF3-19F9086C51E9}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ExtraConcentratedJuice.AntiLock</RootNamespace>
11+
<AssemblyName>AntiLock</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="0Harmony">
34+
<HintPath>..\Libraries\0Harmony.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Assembly-CSharp">
37+
<HintPath>..\Libraries\Assembly-CSharp.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Assembly-CSharp-firstpass">
40+
<HintPath>..\Libraries\Assembly-CSharp-firstpass.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Rocket.API">
43+
<HintPath>..\Libraries\Rocket.API.dll</HintPath>
44+
</Reference>
45+
<Reference Include="Rocket.Core">
46+
<HintPath>..\Libraries\Rocket.Core.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Rocket.Unturned">
49+
<HintPath>..\Libraries\Rocket.Unturned.dll</HintPath>
50+
</Reference>
51+
<Reference Include="System" />
52+
<Reference Include="System.Core" />
53+
<Reference Include="System.Xml.Linq" />
54+
<Reference Include="System.Data.DataSetExtensions" />
55+
<Reference Include="System.Data" />
56+
<Reference Include="System.Xml" />
57+
<Reference Include="UnityEngine">
58+
<HintPath>..\Libraries\UnityEngine.dll</HintPath>
59+
</Reference>
60+
</ItemGroup>
61+
<ItemGroup>
62+
<Compile Include="AntiLock.cs" />
63+
<Compile Include="AntiLockConfiguration.cs" />
64+
<Compile Include="AskVehicleLockOverride.cs" />
65+
<Compile Include="CommandClearLocks.cs" />
66+
<Compile Include="LockGroup.cs" />
67+
<Compile Include="Properties\AssemblyInfo.cs" />
68+
</ItemGroup>
69+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
70+
</Project>

AntiLock/AntiLockConfiguration.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Rocket.API;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace ExtraConcentratedJuice.AntiLock
8+
{
9+
public class AntiLockConfiguration : IRocketPluginConfiguration
10+
{
11+
public int defaultLocks;
12+
public bool ignoreAdmins;
13+
public bool displayMaxlocksNotice;
14+
public bool displayLockNotice;
15+
public List<LockGroup> lockGroups;
16+
17+
public void LoadDefaults()
18+
{
19+
defaultLocks = 0;
20+
ignoreAdmins = true;
21+
displayMaxlocksNotice = true;
22+
displayLockNotice = true;
23+
24+
lockGroups = new List<LockGroup>
25+
{
26+
new LockGroup
27+
{
28+
MaxLocks = 5,
29+
Permission = "antilock.lock"
30+
},
31+
new LockGroup
32+
{
33+
MaxLocks = 10,
34+
Permission = "antilock.biglock"
35+
}
36+
};
37+
}
38+
}
39+
}

AntiLock/AskVehicleLockOverride.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Rocket.API;
2+
using Rocket.Unturned.Chat;
3+
using Rocket.Unturned.Player;
4+
using SDG.Unturned;
5+
using Steamworks;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using UnityEngine;
11+
12+
namespace ExtraConcentratedJuice.AntiLock
13+
{
14+
internal static class AskVehicleLockOverride
15+
{
16+
internal static bool Prefix(CSteamID steamID)
17+
{
18+
UnturnedPlayer player = UnturnedPlayer.FromCSteamID(steamID);
19+
20+
if (player == null)
21+
return false;
22+
23+
if (player.IsAdmin && AntiLock.instance.Configuration.Instance.ignoreAdmins)
24+
return true;
25+
26+
InteractableVehicle vehicle = player.Player.movement.getVehicle();
27+
28+
if (vehicle == null || !vehicle.checkDriver(steamID))
29+
return false;
30+
31+
if (vehicle.isLocked)
32+
return true;
33+
34+
LockGroup group = AntiLock.instance.Configuration.Instance.lockGroups
35+
.Where(x => player.HasPermission(x.Permission))
36+
.OrderByDescending(x => x.MaxLocks)
37+
.FirstOrDefault();
38+
39+
int max = group == null ? AntiLock.instance.Configuration.Instance.defaultLocks : group.MaxLocks;
40+
int count = VehicleManager.vehicles.Count(x => x.lockedOwner == steamID && x.isLocked);
41+
42+
if (count >= max)
43+
{
44+
if (AntiLock.instance.Configuration.Instance.displayMaxlocksNotice)
45+
UnturnedChat.Say(player, AntiLock.instance.Translate("max_locked_notice", max), Color.red);
46+
47+
return false;
48+
}
49+
50+
UnturnedChat.Say(player, AntiLock.instance.Translate("locked_notice", max - count - 1, max));
51+
52+
return true;
53+
}
54+
55+
internal static void Postfix() { /* lol */}
56+
}
57+
}

AntiLock/CommandClearLocks.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System.Collections.Generic;
2+
using Rocket.API;
3+
using Rocket.Unturned.Chat;
4+
using UnityEngine;
5+
using Rocket.Core;
6+
using Rocket.Unturned.Player;
7+
using SDG.Unturned;
8+
9+
namespace ExtraConcentratedJuice.AntiLock
10+
{
11+
public class CommandClearLocks : IRocketCommand
12+
{
13+
#region Properties
14+
15+
public AllowedCaller AllowedCaller => AllowedCaller.Player;
16+
17+
public string Name => "clearlocks";
18+
19+
public string Help => "Clears all of the caller's locks, or another player's lock if an argument is passed.";
20+
21+
public string Syntax => "/clearlocks <player [optional]>";
22+
23+
public List<string> Aliases => new List<string> { "unlockall" };
24+
25+
public List<string> Permissions => new List<string> { "antilock.clearlocks" };
26+
27+
#endregion
28+
29+
public void Execute(IRocketPlayer caller, string[] args)
30+
{
31+
if (args.Length == 1)
32+
{
33+
if (!caller.HasPermission("antilock.clearlocks.other"))
34+
{
35+
UnturnedChat.Say(caller, R.Translate("command_no_permission"), Color.red);
36+
return;
37+
}
38+
39+
UnturnedPlayer other = UnturnedPlayer.FromName(args[0]);
40+
41+
if (other == null)
42+
{
43+
UnturnedChat.Say(caller, AntiLock.instance.Translate("player_not_found"), Color.red);
44+
return;
45+
}
46+
47+
int count = ClearLocks(other);
48+
UnturnedChat.Say(caller, AntiLock.instance.Translate("clear_success_other", other.DisplayName, count));
49+
}
50+
else
51+
{
52+
int count = ClearLocks((UnturnedPlayer)caller);
53+
UnturnedChat.Say(caller, AntiLock.instance.Translate("clear_success", count));
54+
}
55+
}
56+
57+
private int ClearLocks(UnturnedPlayer p)
58+
{
59+
if (p == null || p.CSteamID == null)
60+
return 0;
61+
62+
int count = 0;
63+
64+
foreach (InteractableVehicle v in VehicleManager.vehicles)
65+
if (v.lockedOwner == p.CSteamID && v.isLocked)
66+
{
67+
VehicleManager.instance.channel.send("tellVehicleLock", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
68+
{
69+
v.instanceID,
70+
p.CSteamID,
71+
p.Player.quests.groupID,
72+
!v.isLocked
73+
});
74+
count++;
75+
}
76+
77+
return count;
78+
}
79+
}
80+
}

AntiLock/LockGroup.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace ExtraConcentratedJuice.AntiLock
7+
{
8+
public class LockGroup
9+
{
10+
public string Permission { get; set; }
11+
public int MaxLocks { get; set; }
12+
}
13+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("AntiLock")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("AntiLock")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("008f5d92-3f12-4851-9ef3-19f9086c51e9")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Libraries/0Harmony.dll

64 KB
Binary file not shown.
399 KB
Binary file not shown.

0 commit comments

Comments
 (0)