Skip to content

Commit ba462c7

Browse files
committed
fix the silly
0 parents  commit ba462c7

14 files changed

+610
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bin/
2+
obj/
3+
/packages/
4+
riderModule.iml
5+
/_ReSharper.Caches/
6+
.idea
7+
*.user

modweaver.api.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "modweaver.api", "modweaver.api\modweaver.api.csproj", "{92CBA23E-4FE7-4282-9FFD-5CABA00CD0AF}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{92CBA23E-4FE7-4282-9FFD-5CABA00CD0AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{92CBA23E-4FE7-4282-9FFD-5CABA00CD0AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{92CBA23E-4FE7-4282-9FFD-5CABA00CD0AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{92CBA23E-4FE7-4282-9FFD-5CABA00CD0AF}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

modweaver.api/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bin/
2+
obj/
3+
/packages/
4+
riderModule.iml
5+
/_ReSharper.Caches/
6+
.idea
7+
*.user

modweaver.api/API/CustomWeapon.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using UnityEngine;
2+
using static modweaver.api.API.NewWeaponsManager;
3+
4+
namespace modweaver.api.API {
5+
public class CustomWeapon {
6+
7+
public WeaponType Type;
8+
public GameObject WeaponObject;
9+
public string Name;
10+
public CustomWeapon(string name, WeaponType inheritFrom) {
11+
Name = name;
12+
Type = inheritFrom;
13+
}
14+
15+
}
16+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
using HarmonyLib;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using TMPro;
6+
using Unity.Netcode;
7+
using UnityEngine.UI;
8+
using UnityEngine;
9+
10+
namespace modweaver.api.API {
11+
public static class NewWeaponsManager {
12+
private static uint _prefabHandlerId = 7777; //TODO: fix possible collision
13+
public static List<Weapon> NewWeapons = new List<Weapon>();
14+
private static List<CustomWeapon> _newUserWeapons = new List<CustomWeapon>();
15+
private static bool _weaponsAdded = false;
16+
17+
public delegate void CallbackDelegate();
18+
public static event CallbackDelegate OnInitCompleted;
19+
20+
public static void AddNewWeapon(CustomWeapon weapon) {
21+
_newUserWeapons.Add(weapon);
22+
}
23+
24+
25+
[HarmonyPatch(typeof(SelectedCustomTierScreen), nameof(SelectedCustomTierScreen.Awake))] //TODO: make it dynamicly fit screen
26+
public static class FixWeaponsVisualPatch {
27+
[HarmonyPostfix]
28+
public static void Postfix(ref SelectedCustomTierScreen __instance) {
29+
GameObject grid = GameObject.Find("View - VersusWeapons/Grid");
30+
var gridLayout = grid.GetComponent<GridLayoutGroup>();
31+
gridLayout.spacing = new Vector2(5, 15);
32+
gridLayout.constraintCount = 8;
33+
gridLayout.cellSize = new Vector2(76, 40);
34+
}
35+
}
36+
37+
[HarmonyPatch(typeof(CustomMapUI), "Awake")]
38+
public static class AddWeaponsPatch1 {
39+
[HarmonyPrefix]
40+
public static void Prefix() {
41+
AddWeapons();
42+
}
43+
}
44+
[HarmonyPatch(typeof(CustomTiersScreen), "Awake")]
45+
public static class AddWeaponsPatch2 {
46+
[HarmonyPrefix]
47+
public static void Prefix() {
48+
AddWeapons();
49+
}
50+
}
51+
[HarmonyPatch(typeof(SelectedCustomTierScreen), "Awake")]
52+
public static class AddWeaponsPatch3 {
53+
[HarmonyPrefix]
54+
public static void Prefix() {
55+
AddWeapons();
56+
}
57+
}
58+
59+
[HarmonyPatch(typeof(CustomMapEditor), "Awake")]
60+
public static class AddWeaponsPatch5 {
61+
[HarmonyPrefix]
62+
public static void Prefix() {
63+
AddWeapons();
64+
}
65+
}
66+
67+
[HarmonyPatch(typeof(CustomTierWavesScreen), "Setup")]
68+
public static class AddWeaponsPatch6 {
69+
[HarmonyPrefix]
70+
public static void Prefix() {
71+
AddWeapons();
72+
}
73+
}
74+
[HarmonyPatch(typeof(VersusMode), "Awake")]
75+
public static class AddWeaponsPatch7 {
76+
[HarmonyPostfix]
77+
public static void Postfix(ref VersusMode __instance) {
78+
AddWeapons();
79+
__instance.weapons.AddRange(NewWeapons.Select(x => new SpawnableWeapon(x, 3)));
80+
}
81+
}
82+
83+
[HarmonyPatch(typeof(CustomTierWeaponButton), "Setup")]
84+
public static class FixNewWeaponName {
85+
[HarmonyPostfix]
86+
public static void Postfix(ref CustomTierWeaponButton __instance) {//TODO: save original translation
87+
AccessTools.FieldRefAccess<CustomTierWeaponButton, TextMeshProUGUI>("titleText")(__instance).text =
88+
AccessTools.FieldRefAccess<CustomTierWeaponButton, Weapon>("_weaponObj")(__instance).name;
89+
}
90+
}
91+
92+
static void AddWeapons() {
93+
var tmp = Resources.FindObjectsOfTypeAll<ElementLists>();
94+
95+
if (tmp.Length == 0 || _weaponsAdded) {
96+
return;
97+
}
98+
99+
ElementLists list = tmp[0];
100+
SerializationWeaponName maxName = (SerializationWeaponName)Enum.GetValues(typeof(SerializationWeaponName)).Cast<int>().Max();
101+
NewWeapons.AddRange(list.allWeapons);
102+
List<Weapon> tmpList = new List<Weapon>();
103+
104+
foreach (var weapon in _newUserWeapons) {
105+
Weapon newWeapon = NewWeapons[(int)weapon.Type];
106+
GameObject copiedWeapon = UnityEngine.Object.Instantiate(newWeapon.gameObject);
107+
GameObject.DontDestroyOnLoad(copiedWeapon.gameObject);
108+
copiedWeapon.SetActive(false);
109+
weapon.WeaponObject = copiedWeapon;
110+
111+
newWeapon = copiedWeapon.GetComponent<Weapon>();
112+
newWeapon.serializationWeaponName = ++maxName;
113+
newWeapon.name = weapon.Name;
114+
newWeapon.usedInCustomTiers = true;
115+
116+
}
117+
OnInitCompleted?.Invoke();
118+
foreach (var weapon in _newUserWeapons) {
119+
var no = weapon.WeaponObject.GetComponent<NetworkObject>();
120+
var handler = new WeaponNetworkPrefabInstanceHandler(_prefabHandlerId++, no);
121+
NetworkManager.Singleton.PrefabHandler.AddHandler(handler.Id, handler);
122+
123+
weapon.WeaponObject.transform.TransformPoint(9999 + tmpList.Count * 1000, 9999, 9999);
124+
tmpList.Add(weapon.WeaponObject.GetComponent<Weapon>());
125+
}
126+
NewWeapons = tmpList;
127+
list.allWeapons.AddRange(NewWeapons);
128+
_weaponsAdded = true;
129+
}
130+
131+
[HarmonyPatch(typeof(WeaponSpawner), nameof(WeaponSpawner.SpawnWeapon))]
132+
public static class SpawnWeaponFix {//this just in case there will be timer weapon to live
133+
134+
[HarmonyPrefix]
135+
public static void Prefix(ref WeaponSpawner __instance) {
136+
foreach (var w in NewWeapons) {
137+
w.gameObject.SetActive(true);
138+
}
139+
}
140+
[HarmonyPostfix]
141+
public static void Postfix(ref WeaponSpawner __instance) {
142+
foreach (var w in NewWeapons) {
143+
w.gameObject.SetActive(false);
144+
}
145+
}
146+
}
147+
public enum WeaponType {
148+
BigGrenade,
149+
BigParticleBlade,
150+
BurstLauncher,
151+
DeathRay,
152+
DoubleParticleBlade,
153+
DoubleRailvolver,
154+
GrenadeLauncher,
155+
GrenadeParkour,
156+
Grenade,
157+
HeckSaw,
158+
KhepriStaff,
159+
LaserCannonParkour,
160+
LaserCannon,
161+
LaserCube,
162+
Mine,
163+
MineParkour,
164+
MiniShotgun,
165+
BeachBall,
166+
FireworkLauncherParkour,
167+
FireworkLauncher,
168+
Flare,
169+
Flashlight,
170+
ParticleBladeLauncher,
171+
ParticleBladeParkour,
172+
ParticleBlade,
173+
ParticleSpearParkour,
174+
ParticleSpearVariant,
175+
PreArmedGrenade,
176+
PreArmedParticleBlade,
177+
Railvolver,
178+
RailvolverParkour,
179+
RocketLauncher,
180+
RocketLauncherParkour,
181+
Shotgun,
182+
ShotgunParkour,
183+
AutoShotgun,
184+
GravityGrenade,
185+
GravitySaw,
186+
BoomStick,
187+
DeathCube,
188+
Snowball,
189+
}
190+
}
191+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using NLog;
2+
3+
namespace modweaver.api.Internal
4+
{
5+
public class InternalUtils
6+
{
7+
internal static Logger Logger;
8+
public static void init()
9+
{
10+
// call any setup here
11+
Logger.Info("InternalUtils initialized!");
12+
}
13+
}
14+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using HarmonyLib;
2+
using Unity.Netcode;
3+
using UnityEngine;
4+
5+
//dont forget: id must be same on client and server
6+
internal class WeaponNetworkPrefabInstanceHandler : INetworkPrefabInstanceHandler {
7+
8+
public readonly uint Id;
9+
public NetworkObject No;
10+
11+
public WeaponNetworkPrefabInstanceHandler(uint id, NetworkObject no) {
12+
Id = id;
13+
No = no;
14+
15+
AccessTools.FieldRefAccess<NetworkObject, uint>("GlobalObjectIdHash")(No) = Id;
16+
}
17+
public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation) {
18+
var tmp = NetworkObject.Instantiate(No, position, rotation);
19+
20+
tmp.gameObject.SetActive(true);
21+
22+
return tmp;
23+
}
24+
public void Destroy(NetworkObject networkObject) {
25+
GameObject.Destroy(networkObject.gameObject);
26+
}
27+
}

modweaver.api/ModMain.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using HarmonyLib;
2+
using modweaver.api.Internal;
3+
using modweaver.core;
4+
5+
namespace modweaver.api
6+
{
7+
[ModMainClass]
8+
public class ModweaverAPI : Mod
9+
{
10+
public override void Init()
11+
{
12+
InternalUtils.Logger = Logger;
13+
InternalUtils.init();
14+
// your manifest is the mw.mod.toml file
15+
// use Metadata to access the values you provided in the manifest. Manifest is also available, and provides the other data such as your dependencies and incompats
16+
Logger.Info("Loading {0} v{1} by {2}!", Metadata.title, Metadata.version,
17+
string.Join(", ", Metadata.authors));
18+
19+
Logger.Debug("Setting up patcher...");
20+
Harmony harmony = new Harmony(Metadata.id);
21+
Logger.Debug("Patching...");
22+
harmony.PatchAll();
23+
}
24+
25+
public override void Ready()
26+
{
27+
Logger.Info("Loaded {0}!", Metadata.title);
28+
}
29+
30+
public override void OnGUI(ModsMenuPopup ui)
31+
{
32+
// you can add data to your mods page here
33+
// we recommend if you are going to add ui here, put
34+
// ui.CreateDivider() first
35+
// you'll see why :3
36+
}
37+
}
38+
39+
// no more laser cubes! this stops laser cubes from firing their beams. you can do whatever you want with this.
40+
//[HarmonyPatch(typeof(LaserCube), nameof(LaserCube.ActivateBeams))]
41+
//public static class NoMoreLaserCubes
42+
//{
43+
// public static bool Prefix()
44+
// {
45+
// return false; // this stops the original code from running!
46+
// }
47+
//}
48+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("modweaver_template")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("modweaver_template")]
12+
[assembly: AssemblyCopyright("Copyright © 2023")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("92CBA23E-4FE7-4282-9FFD-5CABA00CD0AF")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)