Skip to content

Commit

Permalink
Merge pull request #1 from CWolfs/develop
Browse files Browse the repository at this point in the history
v0.1.0
  • Loading branch information
Richard Griffiths authored Jul 27, 2018
2 parents 82a821d + aafc56f commit 7e1cf4d
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
obj
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/TestMod.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"D:/Modding/Battletech/ExtendedConversations/src/ExtendedConversations.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Extended Conversations

Extended Conversations is a HBS' BattleTech conversation-based utility mod. It extends the conversation system to provide more actions, conditions and more.

Use [ConverseTek - Sim Conversation Editor](https://github.com/CWolfs/ConverseTek) for support with the additional functionality that this mod provides.

Some of the actions and conditions added will be usable by the events system too.

## Contents

### Conditions

* `Evaluate Tag for Current System` - This allows you to check if the current system has the tag specified.
17 changes: 17 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Name": "ExtendedConversations",
"Enabled": true,

"Version": "0.1.0",
"Description": "Extended Conversations is a utility mod to provide more conversation conditions, actions and other functionality",
"Author": "CWolf",
"Website": "https://github.com/CWolfs/ExtendedConversations/",
"Contact": "[email protected]",

"DLL": "ExtendedConversations.dll",
"DLLEntryPoint": "ExtendedConversations.Main.Init",
"Settings": {
"DoCoolStuff": true,
"BadStuffToAvoid": 1000
}
}
41 changes: 41 additions & 0 deletions src/Core/ConversationUpgrades.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using UnityEngine;
using System;
using Harmony;

using BattleTech;
using TScript;
using TScript.Ops;
using HBS.Logging;
using HBS.Collections;

using ExtendedConversations;

namespace ExtendedConversations.Core {
public class ConversationUpgrades {
public static void Declare(TsEnvironment env) {
Main.Logger.Log("Declaring conversation updates");

TsType boolType = env.GetType("bool");
TsType HasOrHasNotType = env.GetType("HasOrHasNot");
TsType SenseTagListType = env.GetType("SenseTagList");

Main.Logger.Log("Declaring 'Evaluate Tag for Current System' condition operation");
TsOp tsOp = env.DeclareOp("ConditionFunction", "Evaluate Tag for Current System", boolType, new TsOp.EvalDelegate(ConversationUpgrades.EvaluateTagForCurrentSystem));
tsOp.DeclareInput("comp", HasOrHasNotType);
tsOp.DeclareInput("tagName", SenseTagListType);

Main.Logger.Log("Finished declaring conversation upgrades");
}

/* OPERATIONS */
public static object EvaluateTagForCurrentSystem(TsEnvironment env, object[] inputs) {
Main.Logger.Log("EvaluateTagForCurrentSystem triggered");
bool flag = env.ToBool(inputs[0]);
string value = env.ToString(inputs[1]);
TagSet currentSystemTags = UnityGameInstance.BattleTechGame.Simulation.CurSystem.Tags;
bool flag2 = currentSystemTags.Contains(value) == flag;
Main.Logger.Log("EvaluateTagForCurrentSystem finished with result of " + flag2);
return flag2;
}
}
}
21 changes: 21 additions & 0 deletions src/ExtendedConversations.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net452</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Reference Include="0Harmony">
<HintPath>D:\Program Files (x86)\Steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\Program Files (x86)\Steam\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\..\Program Files (x86)\Steam\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>

</Project>
40 changes: 40 additions & 0 deletions src/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using HBS.Logging;
using Harmony;
using Newtonsoft.Json;
using System.Reflection;

using ExtendedConversations.Utils;

namespace ExtendedConversations {
public class Main {
public static ILog Logger;
private static Settings settings;

public static void InitLogger(string modDirectory) {
Dictionary<string, LogLevel> logLevels = new Dictionary<string, LogLevel> {
["ExtendedConversations"] = LogLevel.Debug
};
LogManager.Setup(modDirectory + "/output.log", logLevels);
Logger = LogManager.GetLogger("ExtendedConversations");
}

// Entry point into the mod, specified in the `mod.json`
public static void Init(string modDirectory, string modSettings) {
try {
InitLogger(modDirectory);

Logger.Log("Loading ExtendedConversations settings");
settings = JsonConvert.DeserializeObject<Settings>(modSettings);
} catch (Exception e) {
Logger.LogError(e);
Logger.Log("Error loading mod settings - using defaults.");
settings = new Settings();
}

HarmonyInstance harmony = HarmonyInstance.Create("co.uk.cwolf.ExtendedConversations");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
}
}
17 changes: 17 additions & 0 deletions src/Patches/TsEnvironmentPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;
using System;
using Harmony;
using TScript;
using HBS.Logging;

using ExtendedConversations;
using ExtendedConversations.Core;

namespace ExtendedConversations {
[HarmonyPatch(typeof(TsEnvironment))]
public class TsEnvironmentPatch {
static void Postfix(TsEnvironment __instance) {
ConversationUpgrades.Declare(__instance);
}
}
}
6 changes: 6 additions & 0 deletions src/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ExtendedConversations {
public class Settings {
public bool doCoolStuff = false;
public int badStuffToAvoid = 0;
}
}
52 changes: 52 additions & 0 deletions src/Util/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using HBS.Logging;

/* Thanks to CptMoore for his Logger */
namespace ExtendedConversations.Utils {
public static class ILogExtensions {
public static void SetLevel(this ILog @this, LogLevel level) {
Logger.SetLoggerLevel(@this.Name, level);
}

public static LogLevel GetLogLevel(this ILog @this) {
Logger.GetLoggerLevel(@this.Name, out var logLevel);
return logLevel;
}
}

public static class LogManager {
private static readonly Dictionary<string, ILog> Loggers = new Dictionary<string, ILog>();
private static Dictionary<string, LogLevel> LoggerLevels;
private static FileLogAppender LogAppender;

public static ILog GetLogger(string name) {
if (Loggers.TryGetValue(name, out var logger)) {
return logger;
}

logger = Logger.GetLogger(name);
SetupLogger(name);
Loggers[name] = logger;
return logger;
}

private static void SetupLogger(string name) {
if (LoggerLevels == null || LogAppender == null) {
return;
}

Logger.AddAppender(name, LogAppender);
if (LoggerLevels.TryGetValue(name, out var level)) {
Logger.SetLoggerLevel(name, level);
}
}

public static void Setup(string logFilePath, Dictionary<string, LogLevel> loggerLevels) {
LogAppender = new FileLogAppender(logFilePath, FileLogAppender.WriteMode.INSTANT);
LoggerLevels = loggerLevels;
foreach (var logger in Loggers) {
SetupLogger(logger.Key);
}
}
}
}

0 comments on commit 7e1cf4d

Please sign in to comment.