Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - JackQW

#1
Help / Re: Writing custom code
March 18, 2014, 06:08:12 PM
Hey Mark,
In Alpha 2 there are problems with compiled code mods.
With quite a bit of effort, you may be able to use the approach used in the RWSandboxMod sample I posted to modify the AIKing and related AI namespaced components.
I suggest using ILSpy or Reflector to examine the dlls in the Managed directory, and get familiar with the 'analyze' function to examine inheritance of the various components.
I tried to generate a class diagram and failed... but you can start at the 'Find' class.
Might be easier to wait for Alpha 3.
#2
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 15, 2014, 11:31:17 PM
Just FYI, you'll be able to do this without having to compile a dll in Alpha 3, you'll be able to do everything with Xml files, including the C# code, with the tiniest bit of help from an extension mod I'm making... I used your case specifically for testing. :)
#3
DLL files are storage for logic.

Xml files are storage for logic.

Allow me to quote some of the errors possible in loading Xml in RimWorld;
"Tried to load ", this.asset, " while loading ", XmlLoader.loadingAsset, ". This will corrupt the internal state of DataLoader."
"Exception parsing ", xmlRoot.OuterXml, " to type ", typeof(T), ": ", exception.Message
"Could not load class " + attribute2.Value + " from node " + xmlRoot.OuterXml

Of the things that can be parsed, Types are among them.
It's not too far fetched to load a System.Net.HttpListener or WebClient or SmtpClient or just TcpClient or Udp client, or make use of UnityEngine.WWW...
Just because not every part of Xml is executed, doesn't mean it's invulnerable.
Just because most of a DLL is executed, doesn't mean it can't be safe.


But you should leave the naivete behind, mitigating risk is better done with firewalls, virtualization, learning who/what to trust, and being able to investigate.
If you want to eliminate the risk, then it's virtualization all the way...
There's no reason this game couldn't be ported to Google's NaCl, Unity specifically supports it, then we could mod core files all day long...

Until then or thence similar, you're going to have to decompile and dissect every little thing with wide eyes and tragic distrust. :)

Just wait until you see the crazy shit I'm doing with Xml files for Alpha 3. :D
#4
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 13, 2014, 08:37:59 AM
Shame... I'll try to get it to work in Alpha 2, but that works in Alpha 3...
#5
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 13, 2014, 12:19:25 AM
Ah screw it, I went ahead and fixed it up.
A few Xml changes, added some logging statements for good measure...

Each one gives 0 to 170w of power. It's easy to add a custom field to that building class to have it parse minimum and maximum power outputs, I'll demonstrate that later I think...

You can mash the .cs files into 1 .cs file called 'Mod.cs', then get rid of ModSolar.dll in Assemblies and use that build.cmd file on it, if you plan on rolling your own that way...
In a day or two though, I might release a project I'm working on that enables building mods like this w/o much effort.

You might can handle it from here. :)

[attachment deleted by admin: too old]
#6
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 12, 2014, 10:54:00 PM
Can you upload your mod w/ the DLL in it? I'll try to help debug it.
#7
How sure are you that current mods can't be viruses?  :o
#8
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 12, 2014, 09:27:54 AM
Ok, good.

It should have placed C:\Users\Kirid\Desktop\modding\rimworldmodding\RimworldTest\
RimWorld363Win\Mods\AModSolars\Assemblies\Mod.dll ...

Now the Xml change followed by activating the mod should be all you need to do.
#9
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 11, 2014, 10:54:11 PM
Pause should cause the command prompt to stay open. I updated the previous post again with instructions.
I think I posted that update while you were posting again...

Copy and paste or screenshot the output of that console in the forum, so I can see what the ending is.
#10
Ideas / Re: Mod menu scroll bar
March 11, 2014, 10:25:20 PM
Until that happens, you can go to
[Your User Directory]\AppData\LocalLow\Ludeon Studios\RimWorld\ and edit ModConfig.xml
You can activate mods by duplicating the lines like <li>Core</li> and changing the folder name.
#11
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 11, 2014, 10:20:39 PM
^ Edited post, sorry.

You should see output like this;

X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>set
_64=
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>if
"AMD64" == "AMD64" set _64=64
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>set
tools=C:\Windows\Microsoft.NET\Framework64\v2.0.50727\
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>for
/F "usebackq delims=." %n in (`dir /a /b "..\..\..\*.exe"`) do set refs=..\..\.
.\%~n_Data\Managed
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>set
refs=..\..\..\RimWorld376WinDev_Data\Managed
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>C:\
Windows\Microsoft.NET\Framework64\v2.0.50727\csc.exe /nologo /noconfig /target:l
ibrary /out:..\Assemblies\Mod.dll Mod.cs /nostdlib /lib:..\..\..\RimWorld376WinD
ev_Data\Managed /r:"mscorlib.dll" /r:"System.dll" /r:"System.Core.dll" /r:"Syste
m.Security.dll" /r:"System.Configuration.dll" /r:"System.Xml.dll" /r:"System.Xml
.Linq.dll" /r:"UnityEngine.dll" /r:"UnityScript.Lang.dll" /r:"Mono.Posix.dll" /r
:"Mono.Security.dll" /r:"Boo.Lang.dll" /r:"Assembly-UnityScript-firstpass.dll" /
r:"Assembly-CSharp-firstpass.dll" /r:"Assembly-CSharp.dll"
X:\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\RimWorld376WinDev\Mods\ModSolars\Source>pau
se
Press any key to continue . . .
#12
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 11, 2014, 10:16:59 PM
You have to run build.cmd
It'll run the .NET v2 (v3.5) framework compiler on Mod.cs, referencing the managed (Mono) libraries in the game directory, and build Mod.dll in the Assemblies folder.

If you run it by double clicking, it'll all happen very fast... add "pause" on a new line to the end to make it stay open.
If it still closes too fast, you have to open a command prompt, and enter "cd /d C:\PathToModFolderHere\", then "build", and paste the output in a reply.
#13
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 11, 2014, 09:03:58 PM
Code (build.cmd) Select

set _64=
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set _64=64
set tools=%WinDir%\Microsoft.NET\Framework%_64%\v2.0.50727\
for /f "usebackq delims=." %%n in (`dir /a /b "..\..\..\*.exe"`) do set refs=..\..\..\%%~n_Data\Managed
%tools%csc.exe /nologo /noconfig /target:library /out:..\Assemblies\Mod.dll Mod.cs /nostdlib /lib:%refs% /r:"mscorlib.dll" /r:"System.dll" /r:"System.Core.dll" /r:"System.Security.dll" /r:"System.Configuration.dll" /r:"System.Xml.dll" /r:"System.Xml.Linq.dll" /r:"UnityEngine.dll" /r:"UnityScript.Lang.dll" /r:"Mono.Posix.dll" /r:"Mono.Security.dll" /r:"Boo.Lang.dll" /r:"Assembly-UnityScript-firstpass.dll" /r:"Assembly-CSharp-firstpass.dll" /r:"Assembly-CSharp.dll"

Code (Mod.cs) Select

using System;
using System.Reflection;
using UnityEngine;

public static class Reflect<T> { // basic reflection helper
const BindingFlags staticField =
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Static |
BindingFlags.GetField |
BindingFlags.GetProperty;
public static TResult GetStatic<TResult>(string name) {
return (TResult)typeof(T).InvokeMember(name, staticField, null, null, null);
}
}


public class Building_PowerPlantSimpleSolar : Building_PowerPlant {
    readonly float FullSunPower = Reflect<Building_PowerPlantSolar>.GetStatic<float>("FullSunPower");
    readonly float NightPower = Reflect<Building_PowerPlantSolar>.GetStatic<float>("NightPower");
   
    public override void Tick() {
        base.Tick();

        powerComp.powerOutput =
Find.RoofGrid.Roofed(Position)
? NightPower
: Mathf.Lerp(NightPower, FullSunPower, SkyManager.curSkyGlowPercent);
    }
}


Attached above as a zip file.

Extract to <RimWorldGameDir>\Mods\ModSolar\Source (create the Source folder).
Create a folder <RimWorldGameDir>\Mods\ModSolar\Assemblies


This is a single-file style somewhat auto-config mod for you...
You still have to change the Xml, and you can play with the C# Mod.cs file...

[attachment deleted by admin: too old]
#14
Outdated / Re: [MOD] (Alpha 2) Modular Solar Panels
March 11, 2014, 08:29:03 PM
Nah I didn't want to go through all the project setup stuff to make a seperate one, I was investigating with other bits of craziness...


It might work though. Do you know how to create your own project, and throw that in? I'd be happy to help. :)

If you really want me to, I can make the project and add it to your mod, then send it to you... but then you'd have nothing much to do on your own. :P
#15
Mods / Re: What makes thing targetable?
March 11, 2014, 07:41:26 PM
Guess that'd be TargetingParameters.CanTarget... ?

A 'TargetPack' must be valid according to the TargetingParameter's validator, then there's a bunch of hard coded scenarios...
If it's not a thing, the TargetingParameters must specify canTargetLocations, etc..
It's used by the FloatMenuMaker.ChoicesAtFor (the choice menu)...
If all the checks pass, it eventually gives a choice for "Fire at blah..."

Then the resulting action actually issues the attack order, which appears to issue a new AI.Job...

If you create your own action, maybe you can issue a Job of JobDefOf.AttackMelee or JobDefOf.AttackStatic ...

Things implicitly cast to a TargetPack, so... If you want to force a pawn to attack;
`YourPawn`.MindHumanoid.TakeOrderedJob(new AI.Job(JobDefOf.AttackStatic, `SomeThing`))

There appears to be several ways to allow or force something to get attacked by a pawn...
I don't see a way to add your own FloatMenuOption though...