NPCs In C Entity (NICE)

Feb 20, 2015 at 11:17 PM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Aug 2, 2014
Location: inactivity.
Posts: 115
I gave this(EDIT: To be specific, a early version which only supported 1 NPC. That changed quickly.) to QuoteHax and Noxid, and Noxid decided it might be useful and that I should make a forum post for it.
The name was basically made up on the spot.
This is a project to allow making Cave Story NPC replacements in C.
It's pretty incomplete, but there's enough templates that anyone good with ASM should be able to add the rest for you. (same way as Noxid's defines.txt became standard)
I've added a modified Debug Cat to use as a test, but the code for a normal Debug Cat is in the comment above the code for the modified one.
It works by replacing the "goto NPC pointer" code with "goto NPC216".
Then, NPC216 calls upon game.dll, which contains your code. If a NPC isn't handled by game.dll, the included code will fall back on the NPC pointer table(although this can be disabled)
Because of that, this should be compatible with all of your Doukutsu Assembler NPCs, as long as they don't use NPC216. If they do, just rewrite them in C.
Also, this only messes with NPC216 and the "jump to npc" code, so you can just apply it along with all your other various Doukutsu Assembler.
The included NPC is mostly a test/joke. Only 2 Cave Story functions work for now(CreateNPC and CreateBullet) and CreateBullet hasn't been tested.
Talking of which, this won't help you modify bullets-just NPCs for now.
Maybe Noxid can add it in-he knows Cave Story better.
Have fun with it.(I've licensed all the files I can-meaning the Doukutsu Assembler files and my C header and file-under Public Domain.)

EDIT2: Just thought to mention: game_dll is the source to game.dll, that's where you do the NPC modification. The VC++ project is already setup to compile into the Cave Story folder.

Big thanks to Noxid, defines.txt was really helpful, along with another document he gave me(see his profile feed)
http://dl.dropboxusercontent.com/u/21184720/CaveStoryMod-TestCMod.7z
 
Feb 21, 2015 at 12:01 AM
Stoned Member
"All your forum are belong to us!"
Join Date: Sep 22, 2012
Location: Hell
Posts: 557
p194155-0-90b475fd7216db6b2e27aa338bdf31d180991ee02a6ba7ebacb757c8f78e2ce8.jpg
 
Feb 21, 2015 at 12:06 AM
2dbro
"Big Joe Tire and Battery Restaurant! Opening Soon! Eat at Big Joes!"
Join Date: Jan 10, 2014
Location: yes
Posts: 477
Age: 20
I got level 3 before polar star

best test mod 10/10
 
Feb 21, 2015 at 12:08 AM
War criminal
"Life begins and ends with Nu."
Join Date: Jun 27, 2013
Location: Phoenix
Posts: 2758
Age: 29
I have once wondered what'll happen to get EXP before getting a weapon. It won't reach the level cap though after Level 3.
 
Feb 21, 2015 at 12:09 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Aug 2, 2014
Location: inactivity.
Posts: 115
That's just the test entity. This is mostly important to the ASM modding community versus anything else.
 
Feb 21, 2015 at 5:15 AM
The TideWalker
Modding Community Discord Founder
"That dog!"
Join Date: Apr 5, 2013
Location: In my mind and of my body.
Posts: 1640
Age: 26
This is great theory, but I think there's still plenty of room in CS to optimize stuff, so it's practicality is low.


now if we could get this to work on WAVs, then I would be more interested.
 
Feb 21, 2015 at 5:16 AM
In my body, in my head
Forum Moderator
"Life begins and ends with Nu."
Join Date: Aug 28, 2009
Location: The Purple Zone
Posts: 5998
it can work on whatever you want, it's arbitrary code execution
I dont think you really understand the implications here
 
Feb 21, 2015 at 7:51 AM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Aug 2, 2014
Location: inactivity.
Posts: 115
Basically, to make it work for a given set (EDIT3:Bullets, weapons-Basically anything with a pointer table to a set of functions), you just have to adapt the "Load a DLL and call a function" code in universalnpc1.txt, then make sure universalnpc1.txt gets called(the purpose of universalnpc2.txt). (EDIT4:And you'll probably want to have a way of calling back into Cave Story in case you didn't override anything,see NPCT in game_dll for how this is done with NPCs).
(EDIT6:And you should also be able to replace any Cave Story function with a function in your DLL, come to think of it. Just make sure you pass all the arguments, which is the reason for the "setpointer/push ecx" line)
EDIT:Also, I believe Noxid's referring to (EDIT7: What I just described in EDIT6,so this is now redundant)
EDIT5:...I see...It's not about the lack of room in the CS executable,BTW. It's simply because if I had to choose C over ASM for doing anything complex, I would choose C.

Sorry about the swarm of edits, I keep forgetting little details.
 
Feb 21, 2015 at 2:26 PM
Um... Chosen One? Yeah that'll work. : P
"..."
Join Date: Aug 3, 2014
Location: worm hole
Posts: 362
Age: 22
First people heading towards a colony on Mars in a few years, and now this?
The future is now.
 
Feb 21, 2015 at 3:21 PM
In my body, in my head
Forum Moderator
"Life begins and ends with Nu."
Join Date: Aug 28, 2009
Location: The Purple Zone
Posts: 5998
you could use this to rewrite the map renderer and the tile loader to make multi-layer maps a possibility

or rewrite the music player to play .ogg files (if someone uses WAV I will stab them I s2g)

or overhaul the rendering engine although I don't actually know what the limits of what you can do with it are at the moment

you just gotta know a spot of C/C++, you could even use C# if you wanted to I think, or any other language with the tools to build a native DLL.
 
Feb 21, 2015 at 5:48 PM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Aug 2, 2014
Location: inactivity.
Posts: 115
Noxid said:
you could use this to rewrite the map renderer and the tile loader to make multi-layer maps a possibility

or rewrite the music player to play .ogg files (if someone uses WAV I will stab them I s2g)

or overhaul the rendering engine although I don't actually know what the limits of what you can do with it are at the moment

you just gotta know a spot of C/C++, you could even use C# if you wanted to I think, or any other language with the tools to build a native DLL.
I don't think multi-layer maps are really possible without doing quite a lot of work anyway, but it might be possible.

This doesn't really enable anything that can't be done in ASM-it just makes it a lot easier, since you're working in a sensible language instead of patching over old code in a somewhat messy way-furthermore, it should be a lot simpler to take any given C function Pixel's written and replace it:

Step 1:Make copy of Universalnpc1.txt
Step 2:Edit address for target function.
Step 3:Ensure that *ALL* the arguments given to the function are given to the DLL.
Step 4:Edit data statement at npct label to decide which function gets called.(_ must stay, and the @4 must be changed to arguments multiplied by 4. There's more rules to it, but these should work for most cases.)
Step 5:Write a C function in dllmain.c that COMPLETELY replaces the old function.
Feel free to add functions the old function calls into cavestory.h so you can call them.

I'm focusing on NPCs because that's one of the main things ASM modded(and quite rightly so-by now people are probably getting tired of the variations on the same basic "blue bouncy thing in first cave" AI...)

EDIT: And remember, there's nothing stopping you performing the steps above for yourself- I don't mind derivative versions or anything. As written in "Gamemanj-readme.txt":
gamemanj-readme.txt said:
As always, the 2 Doukutsu Assembler files included (universalnpc1.txt and universalnpc2.txt),
game.dll,and the game_dll folder, I release into the Public Domain.
 
Feb 21, 2015 at 5:55 PM
In my body, in my head
Forum Moderator
"Life begins and ends with Nu."
Join Date: Aug 28, 2009
Location: The Purple Zone
Posts: 5998
I already have the file format and editor for multiple layers, you'd just need to rewrite the function that loads the file and the one that draws the map.
 
Feb 21, 2015 at 5:58 PM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Aug 2, 2014
Location: inactivity.
Posts: 115
Noxid said:
I already have the file format and editor for multiple layers, you'd just need to rewrite the function that loads the file and the one that draws the map.
Yes... I know. I found...EVIDENCE(a configuration file)... of Boosters Lab in Rip. (EDIT2:no point off topic)
EDIT:(Also, "nxm" is a bit of a giveaway. Sorry to ruin the surprise...)
 
Feb 21, 2015 at 6:02 PM
In my body, in my head
Forum Moderator
"Life begins and ends with Nu."
Join Date: Aug 28, 2009
Location: The Purple Zone
Posts: 5998
I'm pretty sure the game's credits flat-out say that Booster's Lab was the editor used
 
Feb 21, 2015 at 6:08 PM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Aug 2, 2014
Location: inactivity.
Posts: 115
...I already knew by then, so this is the discovery method I remember.(EDIT2:Also,where's the fun in that?)
(EDIT:What I wrote before I edited it out was redundant, so...)
(EDIT3:...Also,I should stop derailing my own thread.)
 
Feb 21, 2015 at 7:12 PM
Professional Whatever
"Life begins and ends with Nu."
Join Date: Jan 13, 2011
Location: Lasagna
Posts: 4481
Holy fucking shit
 
Feb 21, 2015 at 7:14 PM
Banned
"Wacka-Wacka-Wacka-Wacka-Wacka-Wacka-Wacka-Wacka-BLEIUP"
Join Date: Aug 19, 2010
Location: South of Nowhere
Posts: 304
Petition for gamemanj to ascend to Moderator
he's earned it
 
Feb 21, 2015 at 8:10 PM
Senior Member
"This is the greatest handgun ever made! You have to ask yourself, do I feel lucky?"
Join Date: Aug 2, 2014
Location: inactivity.
Posts: 115
bobbyis said:
Petition for gamemanj to ascend to Moderator
he's earned it
Uh, I don't think this is grounds for earning Moderator.
Besides, nobody's actually used it yet.
(EDIT:If you have, then I'd like to see. Note that the discussion with Noxid about replacing the rendering system & such is purely theoretical, but probably possible. And Noxid would've beat me to it ages ago if not for a lack of knowledge of LoadLibraryA, I presume.)
 
Feb 22, 2015 at 12:05 AM
The TideWalker
Modding Community Discord Founder
"That dog!"
Join Date: Apr 5, 2013
Location: In my mind and of my body.
Posts: 1640
Age: 26
Noxid said:
it can work on whatever you want, it's arbitrary code execution
I dont think you really understand the implications here

So wait, we can write our code in C/C++ and place a branch to it anywhere inside the exe?
 
Feb 22, 2015 at 1:00 AM
Senior Member
"Ha! Ha! Ha! Mega Man is no match for my Mimiga Man!"
Join Date: Jul 29, 2009
Location: The Surface
Posts: 246
Question: is it possible to write the code in something like Python and compile that to C, or will that sort of C not work with this?
 
Top