Author Topic: Building a custom .dll file to use with RPG Maker...  (Read 3476 times)

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #20 on: June 22, 2016, 11:37:11 AM »
Yay!  I got garbage to be displayed, then crash!  Well, at least I got somewhere...  :facepalm:

--

Okay, source code so far.  It has some nasty problems tho.

dllmain.cpp
(click to show/hide)

When rotated, I get a TON of garbage when angles are not 90s.  The box looking thing is supposed to be SOLID without all the noise.



First - CRASH - when the angle hits exactly 270.0 degrees, game just stops.  Non informative errors.  I figure division by 0 somewhere, but not sure exactly where.  I dont use the dll at all when the angle is 0.

Next, I cant quite figure out the math to center the image correctly.

Next, totally looks like shit.  Cant use for quality production.  I know there are better algorithms out there, but hey, its as far as I have gotten so far.  Im still quite confusitated by so much crap in c++ like, what the hell is "   void(*dmark) (void*); void(*dfree) (void*); "

Anyone wanna take a crack at making things look better?
« Last Edit: June 23, 2016, 01:13:51 AM by Heretic86 »
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #21 on: June 22, 2016, 01:33:40 PM »
You'll need the Light Script also where I plan to use the DLL file.  Too much code for one post and I will remove this post later due to code version being in an unstable Prototype Stage.

STANDALONE LIGHT SCRIPT - PROTOTYPE - NOT STABLE - NOT LEGAL FOR RELEASE OR DISTRIBUTION

Legal crap aside, here is how to use this so far.

INSTRUCTIONS
(click to show/hide)

Script has some documentation but is not complete at this point.

I also have a ton of DEBUG stuff in there.  When Bitmaps are rotated, I am drawing a border around them so I can see the dimensions and position of the Bitmap that I use for creating the Light Sources.  Ignore the border.  Rotated Image is really looks like crap and I need advice.

If a Demo is needed, I'll upload one so I can get this stupid DLL part of this script out of the way.  10 edits later, I think Im done editing this post.  :P
« Last Edit: June 22, 2016, 01:53:42 PM by Heretic86 »
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2900
  • LV: 365
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #22 on: June 24, 2016, 12:44:32 AM »
Nice triple bro

Providing a demo would be better (and faster) for us. But seeing those screenshots, I don't really think there's any merit in even trying it.
I just started looking into making a DLL yesterday and got moderate progress using an abandoned project that I believe you looked at:
https://github.com/scanti/RPG-Maker-Bitmap-Functions
...which I just now realized Thallion worked on this.

Going to look into centering the axis of rotation and transferring the pixel data to a secondary bitmap and see where that takes me.

Regarding the "garbage", your C++ is looping through the source bitmap pixels when it should be the destination bitmap. That's why it's producing all these holes in your image.

For the crashes, it might be you are requesting pixel data for a coordinate outside of the bitmap. Maybe try moving the setting of sourceRGBA and canvasRGBA inside the posX/Y if statement.

For the weird things inside the structs, ignore them. You can think of the bitmap objects you are passing into the DLL as an array of various data. Once you do
Code: [Select]
((RGSSBITMAP*)(src_object << 1))it kinda looks like
Code: [Select]
[flags, class_type, unknown_thing, another_unknown_thing, *bm]Have you even tried removing the voids and seeing what happens to your DLL? I'm pretty sure it will crash since your *bm would be assigned to the address stored in 'unknown_thing', which should not be holding a BITMAPSTRUCT.



(click to show/hide)
NNID: KK20-CP

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #23 on: June 24, 2016, 04:45:52 AM »
I was working on the Demo, just took longer to put together than I expected due to constant interruptions.

http://downloads.chaos-project.com/heretic86/LightDLL.zip

Havent changed any of the source code yet, but I'll try what you suggested. 

Thanks!
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2900
  • LV: 365
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #24 on: June 24, 2016, 08:41:39 AM »
My Result
(click to show/hide)
DLL:
(click to show/hide)
Note I still just pass in one bitmap object. I figured it's easier that way and less coding for me in the long run.

Ruby Test (place anywhere above Main, left/right to spin):
(click to show/hide)

Graphic used:



(click to show/hide)
NNID: KK20-CP

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #25 on: June 24, 2016, 10:16:57 AM »
If I were a girl, Id offer to have your babies!

Can I just use your dll and give you credit instead?
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2900
  • LV: 365
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #26 on: June 24, 2016, 06:55:24 PM »
Also give credit to scanti and TD. I also forgot to test rectangles, so better check that first.

Is there anything in the code you need clarification on?
« Last Edit: June 24, 2016, 07:27:13 PM by KK20 »



(click to show/hide)
NNID: KK20-CP

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #27 on: June 24, 2016, 11:20:26 PM »
I'll give them credit too.

Rectangles get clipped.  Tried it.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Building a custom .dll file to use with RPG Maker...
« Reply #28 on: June 25, 2016, 07:36:52 AM »
So you were finally able to get it done? :)
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2900
  • LV: 365
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #29 on: June 25, 2016, 10:00:31 AM »
Rectangles are fine. Just needed a couple tweaks to the Ruby test to get it working:
Code: [Select]
def new_bitmap(width, height, sin, cos)
  sin = sin.abs
  cos = cos.abs
 
  w = [(width * cos + height * sin).to_i, width].max
  h = [(width * sin + height * cos).to_i, height].max
 
  Bitmap.new(w, h)
end

class Float < Numeric
  def approx
    target = self.round
    return target if (self + 0.00001 >= target && self - 0.00001 <= target)
    return self
  end
end

 

RotateBitmap = Win32API.new('RotateBitmap','Transform33','lp','i')

s = Sprite.new
s.x = 200
s.y = 200
src = RPG::Cache.picture('rectangle')
bw = src.rect.width
bh = src.rect.height
s.bitmap = Bitmap.new(bw,bh)
s.bitmap.blt(0, 0, src, Rect.new(0,0,bw,bh))
angle = 0

while true
  Graphics.update
  Input.update
  s.update
  old_angle = angle
 
  if Input.repeat?(Input::RIGHT)
    angle += 5
  elsif Input.repeat?(Input::LEFT)
    angle -= 5
  end
 
  if old_angle != angle
    angle %= 360
   
    rads = Math::PI * angle / 180
    sin = Math.sin(rads).approx.to_f
    cos = Math.cos(rads).approx.to_f
           
    arr = [cos, -sin, 0.0,
           sin, cos,  0.0,
           0.0, 0.0,  1.0]
           
    s.bitmap.clear
    s.bitmap.dispose
    s.bitmap = new_bitmap(bw, bh, sin, cos)
   
    x = s.bitmap.rect.width - bw
    y = s.bitmap.rect.height - bh
   
    s.bitmap.blt(x/2, y/2, src, Rect.new(0,0,bw,bh))
    s.ox = x/2
    s.oy = y/2
   
    RotateBitmap.call(s.bitmap.object_id, arr.pack("F*"))

  end
 
end
So using that as a guide, it shouldn't be hard to incorporate it into the script now.



(click to show/hide)
NNID: KK20-CP

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #30 on: June 25, 2016, 02:42:46 PM »
So you were finally able to get it done? :)

Im close.  Very close.  Lot of commenting needs to be done, a few features, cleanup, etc.  Other than a bit of trouble with a "Spotlight" feature, and like KK20 mentioned, Rectangles, its coming along very nicely.  Im fairly certain the DLL itself is done.  I had no choice but to use KK20's code for the DLL so gotta give credit where credit is due for all this help you guys are providing me with.

This looks kind of cool, right?

(Animated Gif, give it a moment...)

Aside from the nightmare I had with that dll stuff, Im now working on tying a couple of scripts together.  I already wrote a Rotate, Zoom, and Pendulum script so Im tying a bunch of features of that script together with the Light stuff so I dont end up rewriting the same code with the same features.

Other than that, it is just a matter of focusing on any other Features that users may want.  Hopefully as user friendly as I can make it!  Best of all, super high compatability, even with other Screen Resolution scripts!  I havent had a chance to test that out but since its a simple sprite that covers the screen to create the whole Light effect, just setting the size of that sprite in the Script Config as a variable should let it be compatible.  I mean, within reason.  If they get rid of the Event classes, not much I can do there.
« Last Edit: June 25, 2016, 02:45:49 PM by Heretic86 »
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Building a custom .dll file to use with RPG Maker...
« Reply #31 on: June 25, 2016, 04:28:19 PM »
Looks pretty good. :)
BTW, in my XPA_Window implementation there is a WriteLinear() method in the DLL which basically does zooming using linear interpolation. Feel free to use it.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #32 on: June 27, 2016, 10:58:49 AM »
@Blizz - I doubt Im good enough to do that yet.

DLL still gives me crashes.  KK20 suspects trying to draw outside the bitmap.

I am doing some specific things that I thought would work that always exist when the crash occurs.  For the "spotlight" effect, Im using stretch_blt to put the original source image into a Bitmap Canvas to rotate.  Just creating a Bitmap.new(new_w, new_h) also causes a crash with to blt or stretch.  The unaltered New Bitmap also crashes upon rotation.  "Ordinary" rotating doesnt cause crashes, but stretching does cause random crashes.

KK20rotate.cpp
(click to show/hide)

I dont have a clue how to debug this.  When the game crashes, it just crashes.  No debug, no line number, no specific error, just "Stopped Working".

Thoughts?
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Building a custom .dll file to use with RPG Maker...
« Reply #33 on: June 27, 2016, 11:37:19 AM »
It would be best if you set up some debug code with fprintf() that writes stuff to a file so you can see step by step what's going on.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2900
  • LV: 365
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #34 on: June 28, 2016, 07:53:35 AM »
Just a head's up, the +0.0001 should really be a minus (I don't know why you changed it). When using the square graphic in my example, if you remove the addition entirely, it was drawing the wrong row of pixels at every 90, 180, or 270 degrees. Watch the edges of the square and you will see the error.
(click to show/hide)

Since cx and cy essentially cut the graphic width/height in half, you would get 48 for the 96x96 square graphic. Assuming 90 degrees, sin would be 1 and cos would be 0. If our loop variables (x,y) are (0,0), we multiply -48 (subtracted by cx and cy) to sin and cos and get transx and transy to be 48 and -48 respectively. Add cx and cy back to them and you get the pixel coordinate (96, 0), which is just outside of the bitmap.

If we made cx and cy to be barely 48 (hence subtract by 0.0001), we can still ensure that, at the end, we get (95,0).

And I realized that it can't be out of bounds since the if-statement at the end ensures we are always in bounds. Definitely suggest the printing to a text file if you know the DLL is truly causing it.
« Last Edit: June 28, 2016, 07:56:14 AM by KK20 »



(click to show/hide)
NNID: KK20-CP

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #35 on: June 28, 2016, 09:09:34 AM »
Oops, I forgot to put that back in...

This is what I got when monkeying with attaching the debugger to game.exe

Code: [Select]
The thread 0xf84 has exited with code 0 (0x0).
Unhandled exception at 0x10003A70 in Game.exe: 0xC0000005: Access violation reading location 0x10003A70.

Exception thrown at 0x10003A70 in Game.exe: 0xC0000005: Access violation executing location 0x10003A70.

Unhandled exception at 0x10003A70 in Game.exe: 0xC0000005: Access violation reading location 0x10003A70.

Exception thrown at 0x10003A70 in Game.exe: 0xC0000005: Access violation executing location 0x10003A70.

Donut have a clue.  All greek.  Doesnt point at anything in either source code.

---

Would RPG Maker dll versions have anything to do with it?  Im running on the 102e.dll by the way...
« Last Edit: June 28, 2016, 09:14:58 AM by Heretic86 »
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Building a custom .dll file to use with RPG Maker...
« Reply #36 on: June 28, 2016, 02:41:15 PM »
Most likely accessing data outside of the allowed rect.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 724
  • LV: 29
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #37 on: July 01, 2016, 11:44:48 PM »
Since this is related to the C++ part of the dynamic lighting, I'll ask in this thread.

Although I have heard the terms "linear interpolation", "bilinear interpolation" and "nearest neighbor", as far as the code goes (which I have not seen), what is the difference between these methods?
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Lexima Warrior
  • ****
  • Posts: 2900
  • LV: 365
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Building a custom .dll file to use with RPG Maker...
« Reply #38 on: July 02, 2016, 12:20:09 AM »
So given the destination coordinate (x,y), you throw this into your rotation algorithm and receive the coordinate (x1,y1). What you do with this new coordinate now depends on what interpolation you want to use.

Nearest neighbor, as is present in the current DLL, takes the pixel in the source image that is at the specified coordinates you calculated. If the coordinate is a float, it is usually rounded to the nearest integer, but the DLL currently ignores anything after the decimal point (it's up to you if you want N.5 to return N or N+1).

Meanwhile, Bi-linear interpolation keeps the float in your coordinate. Rather than taking a pixel from your source directly, it uses a "system of averages" to generate an entirely new pixel color based on the surrounding pixels.

If you could imagine (0,0) being the top left pixel of your image, (0.5,0) would be the right half of (0,0) and the left half of (1,0). You take the colors of these two pixels, average them out, and assign this to your destination bitmap.

Linear interpolation doesn't make sense in this case since we're dealing with 2D graphics. It's more for mathematical graphs. But there are many kinds of n-linear interpolations out there that we just group them all up under the same name.



(click to show/hide)
NNID: KK20-CP

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Building a custom .dll file to use with RPG Maker...
« Reply #39 on: July 02, 2016, 10:00:33 AM »
Yeah, I was gonna say that. In 2D it's actually called bi-linear interpolation, because you interpolate on the X and Y axises. But the idea is basically the same.

Let's say we have 2 pixels: green and white. Or better said, we have 2x1 image with the values (0, 255, 0) and (255, 255, 255). Now, if would stretch that to 4 pixels, depending on the algorithm used, you will get a different result. Nearest neighbor will give you (0, 255, 0), (0, 255, 0), (255, 255, 255), (255, 255, 255) while lerp will give you (0, 255, 0), (85, 255, 85), (170, 255, 170), (255, 255, 255). Since the two pixels in between don't exist in the initial image, their values need to be calculated in a certain way. Nearest neighbor just takes a copy of the "nearest pixel" while lerp calculates the values as an average between the "extremes" (which are the original 2 pixels), depending on their distance from these extremes. So the second pixel will be a slightly brighter shade of green and the third a much brighter shade of green.

There are a few minor problems with bi-linear interpolation since you have to decide how to treat the image. Applying lerp to an image where you consider the "center of the pixel" as the reference point will yield difference results than if you consider the "top-left corner of the pixel" as reference point. And this also makes a lot of sense in terms of pixel data when working with floats. If you take the first pixel, its index is 0. The second one is 1. But logically you can still go to a coordinate like 1.99999999 which is virtually the top-right corner of the second pixel. I took this into account when writing my algorithm in XPA_Window which is why I keep suggesting you use it. xD I had to adjust the values and parameters for hours until I finally got it right. The trickiest part in this was to make sure that both upscaling and downscaling work properly since there seem to be logical differences in how you're supposed to treat the pixels. But once I actually got the algorithm right, the problem vanished by itself which also kinda confirmed that I finally did it right. xD
« Last Edit: July 02, 2016, 10:09:19 AM by Blizzard »
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.