|
-
I implemented a quick transfer of all things from the MobContainer into the inventory of the hero (as like as Gothic3). But I am a little confused by its implementation. It works fine, but the suspicion (that simple).
Code:
func void player_hotkey_lame_heal()
{
//This code will go to a reaction from the drawn button.
var oCNpc her; her = Hlp_GetNpc(hero);
var oCMobContainer mobContainer;
if(Hlp_Is_oCMobContainer(her.focus_vob))
{
mobContainer = _^(her.focus_vob);
};
List_ConcatS(her.inventory2_inventory_next,mobContainer.containList_next);
mobContainer.containList_next = 0;
};
Save/Load are fine (without switching off the game; and with the switching off and on the game.).
Is this the normal way?
Geändert von redleha (07.06.2013 um 10:10 Uhr)
-
Through this code you will take just 1 item (first), will you? You may use a loop to take all items with one click.
...unless you call the function every frame.
-
Zitat von Rantragon
Through this code you will take just 1 item (first), will you? You may use a loop to take all items with one click.
...unless you call the function every frame.
No, he's concatenating both lists.
However, I'm not sure whether Gothic will sort the hero's inventory, because you might have just added an item the hero already possesses. Then there might be two stacks instead of one with a higher amount, you should test that.
Besides that I can't see anything wrong with your code though.
-
Zitat von Lehona
However, I'm not sure whether Gothic will sort the hero's inventory, because you might have just added an item the hero already possesses. Then there might be two stacks instead of one with a higher amount, you should test that.
Besides that I can't see anything wrong with your code though.
I have in the inventory: the sword, 10 arrows, scroll. Add 150 arrows and 100 coins from the chest.
Automatic inventory becomes a hero: a sword, 160 arrows, scroll, 100 coins. (And it was done without open inventory and when you open your inventory.)
I think when you talk about sort, do you mean this?
Yes, and more. When I tried to remove the object from the zCListSort with List_DeleteS, it was a mistake. I think the problem is to remove the object, which is the last. I think that MEM_Free gives mistake. But I'm not 100% sure, I'll still test.
Geändert von redleha (07.06.2013 um 13:35 Uhr)
-
Zitat von redleha
I have in the inventory: the sword, 10 arrows, scroll. Add 150 arrows and 100 coins from the chest.
Automatic inventory becomes a hero: a sword, 160 arrows, scroll, 100 coins. (And it was done without open inventory and when you open your inventory.)
I think when you talk about sort, do you mean this?
Yes, and more. When I tried to remove the object from the zCListSort with List_DeleteS, it was a mistake. I think the problem is to remove the object, which is the last. I think that MEM_Free gives mistake. But I'm not 100% sure, I'll still test.
Good, then that's not a problem.
You can't just free the memory of the item, you have to call the destructor and hope there aren't any more references etc. The easiest thing to remove an item from a chest is to just add it to an NPCs inventory (similar to the way you've done it) and then use NPC_RemoveInvItem. MEM_Free() should be working properly, doubt there's any problem with it. Post your code and the error messages you get if you need any help
-
-
Hello again.
I had such a small problem. As I tried to do the following (lay out in short):
Code:
var oCNpc her; her = Hlp_GetNpc(hero);
var oCMobContainer mobContainer;
var int listPtr;
if(Hlp_Is_oCMobContainer(her.focus_vob))
{
mobContainer = _^(her.focus_vob);
};
listPtr = mobContainer.containList_next;
mobContainer.containList_next = 0;
List_DestroyS(listPtr); //Once this function causes an error.
I even moved the function List_DestroyS(listPtr) to other function.
Each time the game crashes with an error (Q: ....).
Geändert von redleha (17.06.2013 um 15:49 Uhr)
-
You give me the error message, I try to help you. I won't go fishing the dark without that (You can copy part of zSpy into your clipboard, there's a button for that).
-
This is log:
I saw on screen last meesage in MessageBox.
-
I'm not a 100% sure but you really shouldn't be freeing memory you don't own / haven't allocated yourself. Why do you want to do this anyway? There is no reason to. Wanna delete an item? Switch the node to an NPC and use Npc_RemoveInvItems().
Technically the game shouldn't have access to the list anymore (you NULL'd the reference), but you never know.
If you can explain the reason you're doing this I will see if I can do something, but as of now the crash is not caused by a bug in List_DestroyS() and probably related to what I've written above.
-
I do not know, maybe I'm wrong. But when we separated the inventory to the chest, all that remained in the memory. That's right there was probably clear the debris memory. Or is it not necessary to do?
P.S. I thought that the function lets you work with any list of games.
Geändert von redleha (17.06.2013 um 18:03 Uhr)
-
Concatenating a list shouldn't copy it, it's literally appended. Just delete the reference (ie mobContainer.containList_next = 0;) and you should be fine, you won't be leaking any memory.
Well, you're correct and the function is working perfectly fine. It's just that for some reason freeing the memory causes a crash. I don't really know why but it's working as intended. Don't free memory unless you know you're "allowed" to free it.
-
Maybe you do not understand.
In this example, I do not give inventory Hero, I just wanted to remove the entire inventory chest. At all.
-
Zitat von redleha
Maybe you do not understand.
In this example, I do not give inventory Hero, I just wanted to remove the entire inventory chest. At all.
Move the chest inventory to a helper NPC (I think Ikarus provides one anyways, otherwise create your own), null the reference in the chest, clear the npc's inventory. That's how you do it.
-
Workarounds that I would find. I probably just did not understand the work function ListDestroyS. I think that you can just wipe and free memory space occupied by the object class ListSort.
-
Zitat von redleha
Workarounds that I would find. I probably just did not understand the work function ListDestroyS. I think that you can just wipe and free memory space occupied by the object class ListSort.
You can. The problem is: The the list "belongs" to the engine. So you just wipe the memory, but the engine thinks it's still there, tries to act on it and crashes. That's at least what could happen - the crash occurs directly in MEM_Free(), so I assume the memory is somehow protected from being free'd? I don't know. Just don't do it in this case because it's not necessary and will in most cases lead to bad and uncontrolled behaviour.
-
Thank you. I just wanted to hear the answer.
I have another question arose. How to get a reference (pointer) to an object of class oCStealContainer?
As I understand the object of this class is generated based on the inventory of the victim, but a direct connection with it is not (checked by robbing people). Apparently, there is a double deletion (from the visual container and at the same time from the inventory of the victim).
I guess it is the same there is a combination of fields such as:
• / / zCListSort <oCItem> {
•• var int inventory2_inventory_Compare; / / 0x0710 int (_cdecl *) (oCItem *, oCItem *)
•• var int inventory2_inventory_data; / / 0x0714 oCItem *
•• var int inventory2_inventory_next; / / 0x0718 zCListSort <oCItem> *
Or as an option - how to make a visual update of the oCStealContainer, if the removal of items come from outside (through list management (oCNpc.inventory2_inventory_next)).
-
Hello! That was the question.
I did a hook on the function:
Code:
func void InstallHook_oCInfoManOnChoice()
{
//void __fastcall oCInformationManager::OnChoice(int) 0x00662780
//void __fastcall oCInformationManager::OnChoice(oCInfoChoice *) 0x006629A0
const int oCInformationManager__OnChoice = 6694784; //0x00662780
const int oCInformationManager__OnChoice_2 = 6695328;//0x006629A0
HookEngineF(oCInformationManager__OnChoice, 8, InstallHook_oCInfoManOnChoice__1);
HookEngineF(oCInformationManager__OnChoice_2, 8, InstallHook_oCInfoManOnChoice__1);
};
func void InstallHook_oCInfoManOnChoice__1()
{
var int x;
//[...] ????
MEM_Warn("HOOK");
};
How do I get these values of type Int and oСInfoСhoice*
And the second question.
How to get the name of the functions inside the function?
Example:
Code:
func string ABCDEF()
{
var string funcName;
//[...CODE]
return funcName; // = "ABCDEF"
};
In fact, the way to read something that will be enough to determine this function? (symbol number in symbolTable, address in memory, or something else)
Geändert von redleha (25.06.2013 um 15:40 Uhr)
-
If you hook right at the beginning of the function (ie literally the first bytes), then this should do:
Code:
var int param; param = MEM_ReadInt(ESP+4);
Code:
var int symbID; symbID = MEM_GetFuncIDByOffset(MEM_StackPos.position);
should get you the symbol of the function.
-
Thanks, Lehona.
And could you somehow a way to explain the mechanism of passing parameters to a function and retrieve them?
Or is it not so easy to explain?
Maybe if you brought a couple of examples, and work with these ESP, EAX, ECX...
Edit:
Right so:
Code:
var int param; param = MEM_ReadInt(ESP-4);
Geändert von redleha (26.06.2013 um 07:51 Uhr)
Grund: update 26/06/2013
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- Anhänge hochladen: Nein
- Beiträge bearbeiten: Nein
|
|