Search Unity

"With" Keyword not supported with Structs except on Preview mode?

Discussion in 'Scripting' started by Mashimaro7, Jan 18, 2022.

  1. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    I have a strange error, I'm using a fairly old project, from 2017, this is a project I was asked to get working... I upgraded it to 2020, but it has a slough of errors saying "; expected" and it seems the issue is being caused by a bunch of "With" keywords in the code, as in this screenshot,


    It says it's not supported because it's a preview feature? Why is this? What is the preview version? Haha, I'm so confused. I have about 850 similar errors, is this a keyword that used to be supported? Or did the person who made this project have a preview version of Visual Studio and use a lot of with keywords for some reason?

    Any help would be appreciated! Thanks
     
  2. MelvMay likes this.
  3. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Now that I looked into it more, it was decompiled from a .exe file... Do I have to change out ALL these with keywords and... How so? lol

    It's strange, the errors disappear sometimes, I've... almost been able to run the project, there's some errors with the "AspectRatioFitter" for some reason, but besides that I've gotten it down to 4 errors, then these 850 errors pop up from time to time lol
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Bunny83 likes this.
  5. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Ah, I didn't decompile it, my client sent me this after asking me to decompile it and i was like oh... it already was decompiled?? lol

    I'm assuming it was, anyway, because this is on the top of all the scripts,
    Code (CSharp):
    1. // Decompiled with JetBrains decompiler
    2. // Type: Robot_Pushbot
    3. // Assembly: Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    4. // MVID: CAF5CC1D-7384-442D-BD63-2B15CA6E7486
    5. // Assembly location: C:\Program Files (x86)\xRC Simulator\xRC Simulator_Data\Managed\Assembly-CSharp.dll
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Right. They'll have to do it again with a different target or yes, you'll have to replace all that unsupported stuff.
     
    Mashimaro7 likes this.
  7. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Okay, got it. I'll just ask them to do that, or do it myself. But just curious, if i was to go through the huge amount of effort to replace it all, what... does "with" do? lol
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    See the doc link posted above, explains it pretty well.
     
  9. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    I didn't notice that... But after reading it I'm still very confused as to what the "with" keyword does lol. Maybe I'll decompile it myself, if I can figure out how to use Jetbrains...
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Jetbrains is the company, it's likely they used dotPeek which is free. They might've used Rider which I believe comes with dotPeek built-in too. It's a very nice product too.
     
    Mashimaro7 likes this.
  11. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Oh, I have Dotpeek. I'll see if i can just do it with the free trial of rider, because I can't figure out dotpeek lol. Thanks.
     
  12. Essentially what it does is allow you to copy over values from one struct to another but in the mean time you can override some values non-destructively.
    Essentially it does what it says in English: "Let A equal to B with these { modification list }". Roughly.
     
    Mashimaro7 likes this.
  13. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Ahh, I got it now, thanks. I wonder why the decompiler added 850 with keywords though? lol, is it some micro optimization when a project is built or something?
     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    If you've ever used Jetbrains products you'll know they're constantly reminding you that the latest language specification allows you to do X even if you don't like it so you end up turning some of those hints off. Likely the decompiler used that as it was somehow more expressive.
     
    Owen-Reynolds likes this.
  15. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Huh, interesting. I actually haven't really used any Jetbrains products before :p but I am looking into expanding my repertoire I need to level up beyond basic "unity" developer... lol
     
    MelvMay likes this.
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Rider is an awesome product for C# devs, especially when using Unity and you can easily lean on it and learn all sorts of new syntactical sugar that's available but in the recent months I've moved away from it for my Unity dev and I'm using VS2022 which I love.

    Rider is still great for lots of devs though.
     
    Mashimaro7 likes this.
  17. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Sorry to bump again, and I know this isn't really a Unity question, but how does one go about converting a built game back into a Unity project? I was able to find a video on how to use IL spyer and Asset studio to get all the data, but of course, it just gives a chunk of files. I don't know where to get the scenes or anything... How do you do this in Rider? There's not really any guides i could find... I don't care if I have to reconstruct a bit of it, just wondering how i would go about making it back into a somewhat functional Unity project haha
     
  18. Sorry for my bluntness, but so you accepted a job you have zero idea how to do?
     
  19. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    He's a regular client who I've done 3 jobs for now, he just randomly offered this job, and I was honest and said "I'll try, don't know how to do it so no promises, but I'll try to figure it out" lol.

    I actually just figured it out within the last 30 minutes, so disregard my question haha
     
    Lurking-Ninja likes this.
  20. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,006
    Yep, the used decompiler is a quite bad one as well. It seems to be very strict when it comes to proper code generation. ILSpy produced this for the same part:
    Code (CSharp):
    1.         bool flag = false;
    2.         if (gamepad1_left_trigger > 0f)
    3.         {
    4.             JointMotor motor = platform_wheel.motor;
    5.             motor.targetVelocity = -1f * gamepad1_left_trigger * platform_wheel_speed * turning_scaler;
    6.             platform_wheel.motor = motor;
    7.             flag = true;
    8.         }
    9.         else if (gamepad1_right_trigger > 0f)
    10.         {
    11.             JointMotor motor2 = platform_wheel.motor;
    12.             motor2.targetVelocity = gamepad1_right_trigger * platform_wheel_speed * turning_scaler;
    13.             platform_wheel.motor = motor2;
    14.             flag = true;
    15.         }
    16.         else
    17.         {
    18.             JointMotor motor3 = platform_wheel.motor;
    19.             motor3.targetVelocity = 0f;
    20.             platform_wheel.motor = motor3;
    21.         }
    which is most likely closer to the actual source code. Well "flag" was probably called something else and "motor" / "motor2" ... was probably just something like
    var tmp
    . Though local variable names are not preserved in compiled CIL.

    Though what confuses me the most is the cast of the "gamepad1_left_trigger" to double. since the variable seems to be a float this is really bad code generation. Likewise the line a bit further up that turns out as this

    Code (CSharp):
    1.  if (!doing_reset && gamepad1_dpad_right && slide_last.targetPosition.x > 0.35f)
    with ILSpy while the above code again casted both to double and ended up with this long double constant ^^.

    The developer(s) of ILSpy put a lot of efford into getting back C# code that is as close as possible to the original code. A lot of code analysis goes into that.

    I'm just wondering. I just downloaded the latest game version from the official website. Though it "seems" the latest build was created 04.01.2022 so just about 15 days ago. How did they loose their source code / project in that time? :) Sounds a bit strange, but hey it's your business.
     
  21. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Weird lol, i wonder if they used Dotpeek? I'll see if my client knows anything... Yeah, that's at least a little more sensical than the above scripts haha.

    I tried decompiling in Utiny and it produced a completely unusable project with methodless scripts lol. I used ILSpy to get the scripts, but is there an easy way to produce a project out of this? I might just see if i can reuse the scripts and make the game, the scripts i got from ILSpy seem to be mostly functional, i just dont know how to get scene data really lol. So i got a project from Utiny and the scripts from ilspy, but it doesn't know which scripts go where, so i have a ton of objects with "missing" scripts...Some objects are working, but most are not...

    As for the "source code"... actually to be honest, when I said they lost the source code, i honestly have no idea what happened, he told me they asked him to decompile the code from this version, and that's what I'm trying to do haha. I was just guessing when i said they "lost the source code" because the github repo they shared with me was also decompiled, just completely broken... That's where the above screenshot is from. He doesn't know anything about coding, so i know he didn't decompile this himself haha. I have no idea, he's a teacher, not sure what he teaches since he seems to know 0 about coding lol, but this project is presumably for his students.

    Edit: Weird, sorry to keep updating, but I seem to have successfully decompiled it with UTiny. It produced no usable scripts the first time, but I ran it a second time now it's almost perfect (???) lol, just one missing script... From a very important object in the menu... But I asked the client about it. So, lesson here, if it doesn't decompile very well... try again? lol
     
    Last edited: Jan 19, 2022