-
Notifications
You must be signed in to change notification settings - Fork 0
/
voidItem.cs
executable file
·111 lines (100 loc) · 4.18 KB
/
voidItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash -e
# * compile instructions: put this file in
# * `steamapps/common/Dyson Sphere Program/CustomMod`
# * folder, open a terminal in the same folder, and execute:
# *
# * ```
# * chmod +x powerFull.cs
# * ./powerFull.cs
# * ```
# *
# * then the mod will be compiled automatically.
# *
# * Here we wrote a shebang like file, which is correct
# * in my computer (Manjaro XFCE), if such script do not work
# * in your computer, you could just try the instructions below :
if [ -z "$__DOTNET_CSC" ]; then
export __DOTNET_CSC="`find /usr/share/dotnet -type f -name dotnet` `find /usr/share/dotnet -name csc.dll`"
echo '$'"__DOTNET_CSC not set yet, you should execute"
echo "export __DOTNET_CSC='$__DOTNET_CSC'"
echo "manually, or this alert will occur each time you execute this script."
fi
__MODE_VERBOSE=56 # may be modified, check it carefully.
__MODE_DEBUG__=57
__MODE_RELEASE=58
case $1 in
V) _MODE__SELECT_=$__MODE_VERBOSE ;;
v) _MODE__SELECT_=$__MODE_VERBOSE ;;
VERBOSE) _MODE__SELECT_=$__MODE_VERBOSE ;;
verbose) _MODE__SELECT_=$__MODE_VERBOSE ;;
D) _MODE__SELECT_=$__MODE_DEBUG__ ;;
d) _MODE__SELECT_=$__MODE_DEBUG__ ;;
DEBUG) _MODE__SELECT_=$__MODE_DEBUG__ ;;
debug) _MODE__SELECT_=$__MODE_DEBUG__ ;;
*) _MODE__SELECT_=$__MODE_RELEASE ;;
esac
FILE_NAME=$0
# ( yes "" | head -n $_MODE__SELECT_ | head -n-1 ; tail $FILE_NAME -n+$_MODE__SELECT_ ) | head -n 55
( yes "" | head -n $_MODE__SELECT_ | head -n-1 ; tail $FILE_NAME -n+$_MODE__SELECT_ ) | $__DOTNET_CSC -nologo -t:library \
-r:'../BepInEx/core/BepInEx.dll' \
-r:'../BepInEx/core/0Harmony.dll' \
-r:'../DSPGAME_Data/Managed/System.dll' \
-r:'../DSPGAME_Data/Managed/UnityEngine.dll' \
-r:'../DSPGAME_Data/Managed/UnityEngine.CoreModule.dll' \
-r:'../DSPGAME_Data/Managed/mscorlib.dll' \
-r:'../DSPGAME_Data/Managed/Assembly-CSharp.dll' \
-out:'../BepInEx/plugins/'"${FILE_NAME%.*}".dll \
-optimize \
-
exit
#define VERBOSE
#define DEBUG
using System;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections.Generic;
namespace VoidItem
{
[BepInPlugin("Neutron3529.VoidItem", "VoidItem", "0.1.1")]
public class VoidItem : BaseUnityPlugin {
#if DEBUG
public static Action<string> logger;
#endif
void Start() {
var harmony=new Harmony("Neutron3529.VoidItem");
harmony.PatchAll(typeof(StorageComponentTakeTailItemsPatch));
/*var m=typeof(StorageComponent).GetMethods();
MethodInfo method_to_patch=m[0];
foreach(var i in m)if(i.Name=="TakeTailItems" && i.ReturnType==typeof(void)){
method_to_patch=i;
break;
}
if(method_to_patch.Name!="TakeTailItems" || method_to_patch.ReturnType!=typeof(void)){return;}
var prefix = typeof(StorageComponentTakeTailItemsPatch).GetMethod("Prefix");
harmony.Patch(method_to_patch, new HarmonyMethod(prefix));*/
#if DEBUG
logger=Logger.LogInfo;
logger("VoidItem加载完成");
#if VERBOSE
//这是一个关于随机数的测试,因为我发现mono自带的System.Random生成的随机数跟我从游戏里复制的随机数函数不一样
System.Random random = new System.Random(123);
for(int i=0;i<100;i++)logger(String.Format("{0}",random.Next()));
//测试log的第一行是[Info : VoidItem] 1774931281
//最后一行是[Info : VoidItem] 2060550224
//这与Rust程序给出的结果一致
#endif
#endif
}
//[HarmonyPatch(typeof(StorageComponent), "TakeTailItems",new Type[]{typeof(int) ,ref typeof(int),typeof(bool)})]
[HarmonyPatch(typeof(StorageComponent), "TakeTailItems",new Type[]{typeof(int) ,typeof(int),typeof(bool)},new ArgumentType[]{ArgumentType.Ref,ArgumentType.Ref,ArgumentType.Normal})]
class StorageComponentTakeTailItemsPatch{
public static bool Prefix(int count, int itemId) {
return count==0 || itemId==0;
}
}
}
}