Focusing on the future

xEnt

Retired Staff
Retired Staff
Sep 6, 2014
48
17
8
anyone started work on the experimental server yet? i forked fougerite and attempted to port it to the experimental branch, only to realize theres too much that has changed. so i made a quick new mod & patcher, found a new area to add a bootstrap and did a basic hello world on join. couldn't re-use any fougerite code really.

so whats your plans for this? legacy wont matter soon and experimental is almost at the play point
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
wow, may I ask from what you have inherited your class and where you have added it to be able to add the bootstrap? I tried to inherit it from Monobehaviour and tried to call my bootstarp from their Bootstrap class and also from the ServerMgr class, but no luck. (I have never patched any program before)
 

xEnt

Retired Staff
Retired Staff
Sep 6, 2014
48
17
8
use UnityEngine.MonoBehaviour instead of Facepunch.MonoBehaviour (which no longer exists?). also since they don't have a ServerInit class anymore, i just used the 'Bootstrap' class and a random method like Initialize, added a call to a fougerite method to force the rust server to load the fougerite assembly and not destroy it.

as for the inheriting, there might be a way to get the rust server to load our dll naturally, but i inserted an instruction in Assembly-CSharp.dll to load it instead (like the current Magma patcher does) - using Mono.Cecil
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
I tried that first and it doesn't worked for me. :O
 

xEnt

Retired Staff
Retired Staff
Sep 6, 2014
48
17
8
what version are you compiling with? try .NET 4.0 / Mono. also use dotPeek after you have patched to see if theres even a reference to your mod, if there is, then check the method and see if it tries to load your code
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
http://pastie.org/private/yj2jdwobf1ep8xib9zeg
I edited the Fougerite.Patcher, checked in dotPeek, it's there and it's called as you can see in the log. I built it for mono/net3.5 and I realized I was trying it on an older version of experimental. I will try it with new serverfiles and building it for fx 4.0 soon.
 

xEnt

Retired Staff
Retired Staff
Sep 6, 2014
48
17
8
http://pastie.org/private/yj2jdwobf1ep8xib9zeg
I edited the Fougerite.Patcher, checked in dotPeek, it's there and it's called as you can see in the log. I built it for mono/net3.5 and I realized I was trying it on an older version of experimental. I will try it with new serverfiles and building it for fx 4.0 soon.
good idea, if you still have problems, try creating a whole new project, add a bootstrap and call that - then work from there. a lot of the fougerite/magma stuff wont be compatible without a lot of work, and may simply cause reference/library issues
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
Still not working. For the bootstrap I created a new project, I only edited the patcher, removed the hooks from it and changed the BootstrapAttachPatch() function in the patcher to insert my ExpBootstrap() function into Bootstrap.Initialization() instead ServerInit.Awake().
 

xEnt

Retired Staff
Retired Staff
Sep 6, 2014
48
17
8
edit what i said, misread you!
 
Last edited:

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
No problem, take your time. Thanks for trying to help me out here. :)
But still no go. Tried moving around my AttachBootstrap() in the Assembly-CSharp.dll, checked in dotPeek, it's always there, in the right spot. If I insert it in Bootstrap.Initialization() before [0x00] instruction, I see the "Hello World!" msg so the AttachBootstrap is executed.

Here are the projects:
https://drive.google.com/folderview?id=0B78qGo9UKeRXeS1QRlVISTlnYzg&usp=sharing

My bootstrap.cs:
C#:
using System;
using UnityEngine;

namespace xMod {
    public class Bootstrap : MonoBehaviour {

        public static void AttachBootstrap() {
            try
            {
                Bootstrap bootstrap = new Bootstrap();
                bootstrap.gameObject.AddComponent(bootstrap.GetType());
                //new GameObject(bootstrap.GetType().FullName).AddComponent(bootstrap.GetType());
                Debug.Log("Hello World!");
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                Debug.Log("argh!");
            }
        }

        public void Awake() {
            try {
                DontDestroyOnLoad(gameObject);
            } catch (Exception ex) {
                Debug.LogException(ex);
                Debug.Log("Crap!");
            }
        }
    }
}
and the Patcher.cs:
C#:
using System;
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace xMod.Patcher {
    class MainClass {

        private static AssemblyDefinition xModAssembly;
        private static AssemblyDefinition rustAssembly;
        private static string version = "1.0.0.0";

        private static void BootstrapAttachPatch() {
            try {
                TypeDefinition xModBootstrap = xModAssembly.MainModule.GetType("xMod.Bootstrap");
                TypeDefinition serverInit = rustAssembly.MainModule.GetType("Bootstrap");
                MethodDefinition attachBootstrap = xModBootstrap.GetMethod("AttachBootstrap");
                MethodDefinition awake = serverInit.GetMethod("Start");
                awake.Body.GetILProcessor().InsertAfter(awake.Body.Instructions[0x01], Instruction.Create(OpCodes.Call, rustAssembly.MainModule.Import(attachBootstrap)));
            } catch (Exception ex) {
                Console.WriteLine("Error at: " + ex.TargetSite.Name);
                Console.WriteLine("Error msg: " + ex.Message);
            }
        }

        public static void Main(string[] args) {
            rustAssembly = AssemblyDefinition.ReadAssembly("Assembly-CSharp.dll");
            xModAssembly = AssemblyDefinition.ReadAssembly("xMod.dll");

            bool success = true;

            BootstrapAttachPatch();

            try {
                TypeReference type = AssemblyDefinition.ReadAssembly("mscorlib.dll").MainModule.GetType("System.String");
                TypeDefinition item = new TypeDefinition("", "xMod_Patched", TypeAttributes.AnsiClass | TypeAttributes.Public);
                rustAssembly.MainModule.Types.Add(item);
                TypeReference fieldType = rustAssembly.MainModule.Import(type);
                FieldDefinition definition3 = new FieldDefinition("Version", FieldAttributes.CompilerControlled | FieldAttributes.FamANDAssem | FieldAttributes.Family, fieldType);
                definition3.HasConstant = true;
                definition3.Constant = version;
                rustAssembly.MainModule.GetType("xMod_Patched").Fields.Add(definition3);
                rustAssembly.Write("Assembly-CSharp.dll");
            } catch (Exception ex) {
                Console.WriteLine("Error at: " + ex.TargetSite.Name);
                Console.WriteLine("Error msg: " + ex.Message);
                success = false;
            }

            if (success) {
                Console.WriteLine("Yay!");
                Console.ReadKey();
            } else {
                Console.WriteLine("Darn!");
                Console.ReadKey();
            }
        }
    }
}
 

xEnt

Retired Staff
Retired Staff
Sep 6, 2014
48
17
8
so if your seeing the Hello, World, inst that all you need?