Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
add assembly generator
Browse files Browse the repository at this point in the history
get dev to build against e1.4.1
  • Loading branch information
Tyler-IN committed May 15, 2020
1 parent 8c3dbc5 commit 23eb015
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/CommunityPatch/.idea/.idea.CommunityPatch/riderModule.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/CommunityPatch/CommunityPatch.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=battanian/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Convo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Debuff/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Eviscerator/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UserDictionary/Words/=explainer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=khuzait/@EntryIndexedValue">True</s:Boolean>
Expand Down
5 changes: 4 additions & 1 deletion src/CommunityPatch/CommunityPatchSubModule.Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ internal static bool DontGroupThirdPartyMenuOptions {
internal static bool QuartermasterIsClanWide {
get => Options.Get<bool>(nameof(QuartermasterIsClanWide));
set => Options.Set(nameof(QuartermasterIsClanWide), value);

}

internal void ShowOptions() {
Expand Down Expand Up @@ -89,7 +88,11 @@ internal void ShowOptions() {
null,
elements,
true,
#if AFTER_E1_4_1
1,
#else
true,
#endif
new TextObject("{=BAaS5Dkc}Apply").ToString(),
null,
HandleOptionChoice,
Expand Down
36 changes: 20 additions & 16 deletions src/CommunityPatch/Patches/GroupEscapeMenuOptionsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,27 @@ public static void Postfix(EscapeMenuVM __instance, ref MBBindingList<EscapeMenu
null,
options,
true,
#if AFTER_E1_4_1
1,
#else
true,
new TextObject("{=Open}Open").ToString(),
null,
selection => {
var picked = selection.FirstOrDefault()?.Identifier;
if (picked == GroupEscMenuOptsKey) {
CommunityPatchSubModule.Current.ShowOptions();
return;
}

if (picked is EscapeMenuItemVM vm)
SynchronizationContext.Current.Post(_ => {
vm.ExecuteAction();
}, null);
},
null
), true);
#endif
new TextObject("{=Open}Open").ToString(),
null,
selection => {
var picked = selection.FirstOrDefault()?.Identifier;
if (picked == GroupEscMenuOptsKey) {
CommunityPatchSubModule.Current.ShowOptions();
return;
}

if (picked is EscapeMenuItemVM vm)
SynchronizationContext.Current.Post(_ => {
vm.ExecuteAction();
}, null);
},
null
), true);
}, "MoreOptions", false));

____menuItems = newList;
Expand Down
32 changes: 19 additions & 13 deletions src/CommunityPatch/Patches/GroupMainMenuOptionsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ private readonly struct InitialMenuItemInfo {

public readonly InitialStateOption Item;


public readonly bool IsMod;

public readonly ModuleInfo? Mod;
Expand Down Expand Up @@ -125,6 +124,7 @@ internal static void CleanUpMainMenu() {
}).FirstOrDefault() ?? item.ToString();
if (action == null)
return new InitialMenuItemInfo(item, false, null, MergablePropertyAttribute.No, name);

var method = action.Method;
var type = method.DeclaringType;
var isMod = PathHelpers.IsModuleAssembly(type?.Assembly, out var mod);
Expand Down Expand Up @@ -281,18 +281,24 @@ internal static void ShowOptions(List<InitialStateOption> moreOptions) {
throw new ArgumentNullException(nameof(moreOptions));

InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData(new TextObject("{=MoreOptions}More Options").ToString(), null, moreOptions.Where(x => x != null)
.Select(x => new InquiryElement(x.Id, x.Name.ToString(), null))
.Where(x => !string.IsNullOrWhiteSpace(x.Title))
.ToList(), true, true, new TextObject("{=Open}Open").ToString(), null, picked => {
var item = picked.FirstOrDefault();
if (item == null)
return;

SynchronizationContext.Current.Post(_ => {
moreOptions.FirstOrDefault(x => string.Equals(x.Id, (string) item.Identifier, StringComparison.Ordinal))
?.DoAction();
}, null);
}, null));
.Select(x => new InquiryElement(x.Id, x.Name.ToString(), null))
.Where(x => !string.IsNullOrWhiteSpace(x.Title))
.ToList(), true,
#if AFTER_E1_4_1
1,
#else
true,
#endif
new TextObject("{=Open}Open").ToString(), null, picked => {
var item = picked.FirstOrDefault();
if (item == null)
return;

SynchronizationContext.Current.Post(_ => {
moreOptions.FirstOrDefault(x => string.Equals(x.Id, (string) item.Identifier, StringComparison.Ordinal))
?.DoAction();
}, null);
}, null));
}

private static readonly AccessTools.FieldRef<InitialStateOption, Action> InitOptActGetter = AccessTools.FieldRefAccess<InitialStateOption, Action>("_action");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using HarmonyLib;
using TaleWorlds.CampaignSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,28 @@ public override void Apply(Game game) {

// ReSharper disable once InconsistentNaming

public static void Postfix(AgentMoraleInteractionLogic __instance, Agent affectedAgent, Agent affectorAgent, AgentState agentState) {
public static void Postfix(AgentMoraleInteractionLogic __instance, Agent affectedAgent, Agent affectorAgent, AgentState agentState,
KillingBlow killingBlow) {
var affectorCharacter = (CharacterObject) affectorAgent?.Character;
var affectorLeaderCharacter = (CharacterObject) affectorAgent?.Team?.Leader?.Character;

if (affectorCharacter == null) return;
if (affectorLeaderCharacter?.GetPerkValue(ActivePatch.Perk) != true) return;
if (!affectorAgent.HasMount) return;

var perk = ActivePatch.Perk;
if (affectorLeaderCharacter?.GetPerkValue(perk) != true) return;

if (affectedAgent.Character == null) return;
if (affectedAgent.Team == null) return;
if (agentState != AgentState.Killed && agentState != AgentState.Unconscious) return;

#if AFTER_E1_4_1
var skill = WeaponComponentData.GetRelevantSkillFromWeaponClass((WeaponClass) killingBlow.ItmClass);
var moralChangesTuple = MissionGameModels.Current.BattleMoraleModel.CalculateMoraleChangeAfterAgentKilled
(affectedAgent, affectorCharacter, skill);
#else
var moralChangesTuple = MissionGameModels.Current.BattleMoraleModel.CalculateMoraleChangeAfterAgentKilled(affectedAgent);
var moralChangeFriend = moralChangesTuple.Item1 * ActivePatch.Perk.PrimaryBonus;
#endif
var moralChangeFriend = moralChangesTuple.Item1 * perk!.PrimaryBonus;

__instance.ApplyAoeMoraleEffect(
affectedAgent.GetWorldPosition(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,30 @@ public override void Apply(Game game) {

// ReSharper disable once InconsistentNaming

public static bool Prefix(AgentMoraleInteractionLogic __instance, Agent affectedAgent, Agent affectorAgent, AgentState agentState) {
public static bool Prefix(AgentMoraleInteractionLogic __instance, Agent affectedAgent, Agent affectorAgent, AgentState agentState,
KillingBlow killingBlow) {
var affectorCharacter = (CharacterObject) affectorAgent?.Character;

if (affectorCharacter == null) return false;
if (affectedAgent.Character == null) return false;
if (agentState != AgentState.Killed && agentState != AgentState.Unconscious) return false;
if (affectedAgent.Team == null) return false;

#if AFTER_E1_4_1
var skill = WeaponComponentData.GetRelevantSkillFromWeaponClass((WeaponClass) killingBlow.ItmClass);
var moralChangesTuple = MissionGameModels.Current.BattleMoraleModel.CalculateMoraleChangeAfterAgentKilled
(affectedAgent, affectorCharacter, skill);
#else
var moralChangesTuple = MissionGameModels.Current.BattleMoraleModel.CalculateMoraleChangeAfterAgentKilled(affectedAgent);
#endif
var moralChangeFriend = moralChangesTuple.Item1;
var moralChangeEnemy = moralChangesTuple.Item2;

if (!AnyMoralChanges(moralChangeEnemy, moralChangeFriend)) return false;

if (affectorCharacter.GetPerkValue(ActivePatch.Perk))
moralChangeFriend += moralChangeFriend * ActivePatch.Perk.PrimaryBonus / -100;
var perk = ActivePatch.Perk;
if (affectorCharacter.GetPerkValue(perk))
moralChangeFriend += moralChangeFriend * perk!.PrimaryBonus / -100;

__instance.ApplyAoeMoraleEffect(
affectedAgent.GetWorldPosition(),
Expand Down
2 changes: 2 additions & 0 deletions tools/ReferenceAssemblyGenerator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ref-*/
*.7z
90 changes: 90 additions & 0 deletions tools/ReferenceAssemblyGenerator/7za-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
7-Zip
~~~~~
License for use and distribution
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

7-Zip Copyright (C) 1999-2020 Igor Pavlov.

The licenses for files are:

1) 7z.dll:
- The "GNU LGPL" as main license for most of the code
- The "GNU LGPL" with "unRAR license restriction" for some code
- The "BSD 3-clause License" for some code
2) All other files: the "GNU LGPL".

Redistributions in binary form must reproduce related license information from this file.

Note:
You can use 7-Zip on any computer, including a computer in a commercial
organization. You don't need to register or pay for 7-Zip.


GNU LGPL information
--------------------

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You can receive a copy of the GNU Lesser General Public License from
http://www.gnu.org/




BSD 3-clause License
--------------------

The "BSD 3-clause License" is used for the code in 7z.dll that implements LZFSE data decompression.
That code was derived from the code in the "LZFSE compression library" developed by Apple Inc,
that also uses the "BSD 3-clause License":

----
Copyright (c) 2015-2016, Apple Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder(s) nor the names of any contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----




unRAR license restriction
-------------------------

The decompression engine for RAR archives was developed using source
code of unRAR program.
All copyrights to original unRAR code are owned by Alexander Roshal.

The license for original unRAR code has the following restriction:

The unRAR sources cannot be used to re-create the RAR compression algorithm,
which is proprietary. Distribution of modified unRAR sources in separate form
or as a part of other software is permitted, provided that it is clearly
stated in the documentation and source comments that the code may
not be used to develop a RAR (WinRAR) compatible archiver.


--
Igor Pavlov
Binary file added tools/ReferenceAssemblyGenerator/7za.exe
Binary file not shown.
3 changes: 3 additions & 0 deletions tools/ReferenceAssemblyGenerator/CommandLine.dll
Git LFS file not shown
6 changes: 6 additions & 0 deletions tools/ReferenceAssemblyGenerator/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MIT Licensed

Original Author: Enes Sadık Özbek <esozbek.me>

Source: https://github.com/ImperialPlugins/ReferenceAssemblyGenerator

Binary file not shown.
3 changes: 3 additions & 0 deletions tools/ReferenceAssemblyGenerator/dnlib.dll
Git LFS file not shown
20 changes: 20 additions & 0 deletions tools/ReferenceAssemblyGenerator/generate.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off && cd /d "%~dp0"

mkdir "ref-%~1"
for /f "usebackq delims=" %%a in (
`dir /a /b "..\..\..\..\bin\Win64_Shipping_Client\TaleWorlds*.dll" "..\..\..\..\bin\Win64_Shipping_Client\TaleWorlds*.exe" "..\..\..\..\bin\Win64_Shipping_Client\Bannerlord.exe"`
) do (
ReferenceAssemblyGenerator -f -o "ref-%~1\%%~a" "..\..\..\..\bin\Win64_Shipping_Client\%%~a"
)

for %%m in ("Native" "SandBoxCore" "SandBox" "CustomBattle" "StoryMode") do (
for /f "usebackq delims=" %%a in (
`dir /a /b "..\..\..\%%~m\bin\Win64_Shipping_Client\*.dll" "..\..\..\%%~m\bin\Win64_Shipping_Client\*.exe"`
) do (
ReferenceAssemblyGenerator -f -o "ref-%~1\%%~a" "..\..\..\%%~m\bin\Win64_Shipping_Client\%%~a"
)
)

pushd "ref-%~1"
..\7za a -bd -ssw -t7z -m0=lzma -mx=9 -mfb=256 -md=256m -ms=on "..\ref-%~1.7z" *
popd

0 comments on commit 23eb015

Please sign in to comment.