Bigger Item Graphics

Started by Kellion, April 21, 2017, 03:15:02 PM

Previous topic - Next topic

Kellion

So... I've been hammering at this issue for the past few days, I made some progress but it's still a little difficult. After slamming against way too many brick walls. I come to the forums for help, for I am currently lost...

The Issue: I want to make a bigger gun than 1x1. Since the game auto scales them down to 1x1, I have to make a DLL that overrides that behavior to give the gun the correct size.

What I did so far: I go the gun to have the correct size on the ground, however as soon as its hauled, it returns to the 1x1 size which then turns back to 3x3 once its placed back down. Holding and aiming also rescales it to 1x1.
I got a very off-the-shelf DLL making environment, it works tho. I also have ILSpy, dug through the code but can't find the Item rescaler class.

My Horrible, horrible code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using Verse.AI;
using Verse.Sound;
using RimWorld;

namespace projectNexusAssembliesCorp
{
    class BFGModifiers : Verse.ThingWithComps
    {
        public override void Draw()
        {
            Matrix4x4 matrix = default(Matrix4x4);
            Vector3 s = new Vector3(3f, 1f, 3f);
            matrix.SetTRS(DrawPos + Altitudes.AltIncVect, Quaternion.identity, s);
            Graphics.DrawMesh(MeshPool.plane10, matrix, this.Graphic.MatAt(this.Rotation, null), 0);
            Graphic.drawSize = new Vector2(3, 3);
        //    Graphic.
            //IntVec2.Two;
            //A.Size = new Vector2(3, 3);
        }

    }
}


And the XML for the weapon:

<?xml version="1.0" encoding="utf-8" ?>
<ThingDefs>

  <ThingDef ParentName="BaseBullet">
    <defName>20Kg_MAG_SuperMagnum</defName>
    <label>SuperMagnum Blast</label>
    <graphicData>
      <texPath>Things/Projectile/Bullet_Shotgun</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <projectile>
      <damageDef>Bullet</damageDef>
      <damageAmountBase>52</damageAmountBase>
      <speed>55</speed>
    </projectile>
  </ThingDef>
  <ThingDef ParentName="BaseHumanGun">
    <defName>Mag_Mossberg_Five_Hundred</defName>
    <label>MAG Mossberg 500</label>
    <description>A Mag Sized Mossberg 500 pump shotgun. It is loaded with 20Kg SuperMagnum slugs, known to desintegrate any target it hits.</description>
    <thingClass>projectNexusAssembliesCorp.BFGModifiers</thingClass>
<graphicData>
      <texPath>Things/Items/Weapons/MAG_Shotgun</texPath>
      <graphicClass>Graphic_Single</graphicClass>
  <drawSize>3,3</drawSize>
    </graphicData>
    <soundInteract>InteractShotgun</soundInteract>
<equippedStatOffsets>
<MoveSpeed>-0.25</MoveSpeed>
</equippedStatOffsets>
<Size>(3,3)</Size>

<weaponTags>
<li>MAG_Gun</li>
</weaponTags>

    <statBases>
      <WorkToMake>30000</WorkToMake>
      <Mass>16</Mass>
      <AccuracyTouch>0.60</AccuracyTouch>
      <AccuracyShort>0.90</AccuracyShort>
      <AccuracyMedium>0.40</AccuracyMedium>
      <AccuracyLong>0.14</AccuracyLong>
      <RangedWeapon_Cooldown>1.8</RangedWeapon_Cooldown>
    </statBases>
    <costList>
      <Steel>60</Steel>
      <Component>3</Component>
    </costList>
    <verbs>
      <li>
    <burstShotCount>16</burstShotCount>
<ticksBetweenBurstShots>0</ticksBetweenBurstShots>
        <verbClass>Verb_Shoot</verbClass>
        <hasStandardCommand>true</hasStandardCommand>
        <projectileDef>20Kg_MAG_SuperMagnum</projectileDef>
        <warmupTime>1.8</warmupTime>
        <range>52</range>
        <soundCast>ShotShotgun</soundCast>
        <soundCastTail>GunTail_Heavy</soundCastTail>
        <muzzleFlashScale>20</muzzleFlashScale>
      </li>
    </verbs>
  </ThingDef>
</ThingDefs>


That about covers it, I don't know what else I can do. Thanks for reading! :)

minimurgle

Unfortunately I can't really be of much help here, but I would recommend looking through things with dnspy too. It seems that ilspy sometimes misses things dnspy picks up and vice versa. Or I could be crazy.
Don't mind the questions. I'm probably just confused.

Kellion

I'm supposed to modify a class that not even IlSpy can find? Whoa, I'm really in a difficult position here, I think my problem is that the code base is pretty vast, and I simply didn't bump into that class. Would it even be possible? Or would I be overwriting the class for every other item in the game, that would be problematic... :S

minimurgle

I'm not sure it or not but the method your looking to add that would be patching (I think). As for why I suggested dnspy, that's because it finds things that ilspy misses. In the same way ilspy finds things that dnspy misses. Hence why I'd reccomend trying both. Of course it is completely possible you missed something. I do all the time.
Don't mind the questions. I'm probably just confused.

RawCode

use dnspy with options enabled
tokens
compiler generated code
in case of emergency switch to IL layer

if code if present, it will be "visible".
(code is always visible, but decompiler trying to recover syntax sugar and mess things up, use IL layer in such cases)

dnspy is best tool around, ever surpassing commercial decompilers.

note:
game DLL do not have any rendering code, all rendering routines are implemented as natives inside unity engine, you can't modify real renderer without native level injections

protip
make invalid texture, that cannot be rendered and let game throw exception, it will allow you to see stacktrace and get information about codeflow almost instantly, without any need of debugger.

you can inject unconditional throw with code injection to get information about caller of specific method without performing tracing.

Kellion

Quote from: RawCode on April 23, 2017, 12:00:25 AM
use dnspy with options enabled
tokens
compiler generated code
in case of emergency switch to IL layer

if code if present, it will be "visible".
(code is always visible, but decompiler trying to recover syntax sugar and mess things up, use IL layer in such cases)

dnspy is best tool around, ever surpassing commercial decompilers.

note:
game DLL do not have any rendering code, all rendering routines are implemented as natives inside unity engine, you can't modify real renderer without native level injections

protip
make invalid texture, that cannot be rendered and let game throw exception, it will allow you to see stacktrace and get information about codeflow almost instantly, without any need of debugger.

you can inject unconditional throw with code injection to get information about caller of specific method without performing tracing.

Ok, I'll take a look with DNSpy with "options enabled" whatever that means.

Also that protip with the invalid texture sounds like a great idea! I need to seriously try that and see if it works/helps. Also when I mentioned the rendering stuff, I mean the way the game scales it. The Rimworld code itself must be responsible for calling that rescale. What I want is to Override that method, not the actual Unity Internals. (That's just a bad idea).

Shinzy

Heyoo Kelly! Cpt. Ohu has done a mod that allows weapon sizing
https://ludeon.com/forums/index.php?topic=27459.0
Quote from: Cpt.Ohu...Additionally I'm detouring DrawEquipmentAiming to alter the drawing mesh size.

Kellion

#7
Quote from: Shinzy on April 23, 2017, 07:58:38 AM
Heyoo Kelly! Cpt. Ohu has done a mod that allows weapon sizing
https://ludeon.com/forums/index.php?topic=27459.0
Quote from: Cpt.Ohu...Additionally I'm detouring DrawEquipmentAiming to alter the drawing mesh size.

Isn't this awesome...? Thanks so much! :D

Edit: I tried it, and it works great! There's a few other issues but I'm sure I can sort these out myself. Thanks :)